<?xml version="1.0" encoding="UTF-8"?>
<spec xmlns="https://vibevm.org/spec/1">
  <title>vibe prefs — the settings TUI (PROP-041) visual sign-off</title>
  <p p="1"><fact id="purpose" status="impl/done">**Purpose.** `vibe prefs ui` is the TUI surface over `vibe-settings` (PROP-040):
a page tree, per-type edit forms, provenance, validation feedback, lint, and
search — built on the `vibe tree` TUI's component library + theme (Шаг 3) and
driven by `vibe.prefs` actions. The automated suite (347 vibe-cli tests,
`self-check` all green) proves the model + the rendering fns; it cannot drive a
real terminal and confirm the surface *reads right* — the page tree aligns, the
form fields edit, the provenance shows the winning layer, the validation
warnings land inline. That is what a human signs off here.</fact></p>
  <p p="2"><fact id="settings-mutation-note" status="impl/done">This TUI writes user settings (`~/.vibe/`, the vibe-settings system) — palette/
tier/mode/sort/shape/static-first persist. Back them up or accept the delta.</fact></p>
  <section title="Preconditions">
    <list ordered="false" p="3">
      <item><fact id="PRE-TTY" status="impl/done">A real interactive terminal (tty), ideally truecolor.</fact></item>
      <item><fact id="PRE-BINARY" status="impl/done">`cargo build -p vibe-cli` (invoke `./target/debug/vibe`).</fact></item>
      <item><fact id="PRE-CONTEXT" status="impl/done">Run from the vibevm repo root (a project context → L1+L2+L3; elsewhere L1 only).</fact></item>
    </list>
  </section>
  <section title="Steps">
    <list ordered="true" p="4">
      <item><fact id="STEP-1-LAUNCH" status="impl/done">**Launch + the page tree.**</fact></item>
    </list>
    <fence p="5">   ./target/debug/vibe prefs ui</fence>
    <p p="6"><fact id="S1-PAGE-TREE" status="impl/done">Left pane: the page hierarchy (Appearance / Tree groups → the palette/tier/
   mode/sort/shape/static-first pages) through the same visual language as the
   tree TUI (`│├└─`, `▾`/`▸` fold, theme colours). `↑`/`↓` move, `←`/`→` fold.</fact></p>
    <list ordered="true" p="7">
      <item><fact id="STEP-2-EDIT-FORM" status="impl/done">**Open a page + the edit form (§4).** `Enter` on a page → the right pane
   shows the form: per-type fields (bool→toggle, enum/closed-set→selection,
   int/string→text), each with an `applies` badge + a write-layer selector at
   the bottom. `↑`/`↓` field focus, `Space`/`Enter` toggle/select, typing edits a
   text field, `Tab` cycles the write-layer (L3 project / L1 no-project).</fact></item>
    </list>
    <list ordered="true" p="8">
      <item><fact id="STEP-3-APPLY-RESET" status="impl/done">**Apply / reset (§4 Configurable lifecycle).** Edit a field → the form is
   modified; `a` applies (writes through `vibe-settings` to the chosen layer;
   a scope-forbidden layer is refused with the reason), `r` resets. Quit +
   relaunch — the change persisted.</fact></item>
    </list>
    <list ordered="true" p="9">
      <item><fact id="STEP-4-PROVENANCE" status="impl/done">**Provenance (§5).** `?` on a focused field → an inline block: the resolved
   value + each layer's contribution (default/L1/L2/L3/cli/env), the winning
   layer marked, shadowed layers dimmed. `x` clears the focused write-layer for
   that key → the value falls back to the layer beneath.</fact></item>
    </list>
    <list ordered="true" p="10">
      <item><fact id="STEP-5-VALIDATION-LINT" status="impl/done">**Validation + lint (§6).** Type a wrong-type value → an inline warning line
   under the field (gold, rule cited); `apply` is blocked. `c` opens the lint
   modal — `schema::validate` across L1/L2/L3 as a flat warning list; selecting
   a warning jumps to the owning page focused on that field.</fact></item>
    </list>
    <list ordered="true" p="11">
      <item><fact id="STEP-6-SEARCH" status="impl/done">**Search (§7).** `/` or `F1` → the Search Everywhere window (the same engine
   the tree TUI uses): match by key / display name / description / synonyms;
   selecting opens the owning page focused on the field. Deprecated keys surface
   their `replaced_by`.</fact></item>
    </list>
    <list ordered="true" p="12">
      <item><fact id="STEP-7-ACTIONS-FOOTER" status="impl/done">**Actions + footer (§8).** The footer lists the enabled `vibe.prefs` actions
   for the current context (open/apply/reset/search/lint/layer/provenance/quit),
   keymap-bound. `Esc` pops the modal stack (provenance → page).</fact></item>
    </list>
    <list ordered="true" p="13">
      <item><fact id="STEP-8-THEME-SWITCH" status="impl/done">**Theme switch (the live Theme, §1 `#built-on-tree-tui`).** Change
   `vibe.tree.palette` in the form (or `~/.vibe/settings.toml`) → the whole
   prefs UI re-skins to match the tree TUI.</fact></item>
    </list>
  </section>
  <section title="Pass">
    <p p="14"><fact id="pass-criteria" status="impl/done">Every step reads as described: the page tree aligns, the form edits + applies +
persists, the provenance shows the winning layer, validation lands inline, the
lint + search work, and the footer lists the live actions. The owner signs the
date below.</fact></p>
  </section>
  <section title="Sign-off">
    <list ordered="false" p="15">
      <item><fact id="SIGNOFF-OWNER" status="impl/work">[ ] Owner visual sign-off (date / initials): ______</fact></item>
    </list>
  </section>
</spec>
