The agent-run client in `flow/` is reached as `valley flow <args>`, and no name it writes carries `klaus`. Operator decisions: the command is `valley flow`; state lives under `.valley` (flow's files under `.valley/flow/`), not `.klaus`; the Unix account a deployment runs it under is out of scope. Design, after a cross-model critique against the code: - `valley` stays stdlib-only. `valley flow` execs a separate program `valley-flow` found on PATH (not beside the binary: the packaged `valley` is wrapped, and the helper updates independently), passing the arguments after `flow`, stdio and exit status through. - Stage 1 is additive. The package attribute `klaus` and `bin/klaus` stay, because the installed self-update builds that attribute and runs that binary, live panes embed a later `klaus _finalize`, and dashboards restart onto `klaus` on PATH. The same package gains `bin/valley-flow`. Flow names itself by how it was invoked. Nothing persistent changes. - Stage 2, text: docs, prompts and messages say `valley flow`, once consumers carry a `valley` that dispatches it. - Stage 3, persistent names, each with its own rule rather than a blanket read-old/write-new: - config and prompt files fall back per file, keeping host/project precedence; - sessions are enumerated from both roots and an existing session keeps its directory (records hold absolute worktree, log and clone paths; memory has absolute symlinks), so no bare move of the old directory; - locks keep one path for as long as old and new processes can coexist; - the conversation ref falls back per requested blob, and a new ref name needs the host to authorize it first (the hook rejects `refs/the-valley/*` pushes today, and finalize discards that push error); - readers of new environment names, labels and trailers ship before writers of them; - also to cover: `klaus_exit`, the `klaus-check-completed:` stream line, `.git/klaus`, `klaus-continue.lock`, the hook file `klaus.config` and its keys, the default temporary worktree root. - Stage 4, consumers switch and the old names with nothing left to read are removed; trailer and conversation-ref reads stay. Removal accounts for rollback and for machines that skip releases. Each stage needs an old-session → update → finalize and dashboard restart → rollback test through the packaged entry points.
Stage 3 design (persistent names), part 1 of 3: names table, first half. Authored by an independent model against main at 30e24c8. Rows marked keep are proposals awaiting the operator. Moving declarations and newly created state to `.valley/flow` gives flow a coherent namespace without relocating live work. A reader-first rollout can preserve running sessions and rollback while leaving costly historical protocols stable. This is proposed behaviour, not built. R means the reader bridge, W the writer cutover, and P the publication-error fix. Existing records and conversations are never rewritten merely to replace a name. | Old name | New name or decision | Writers → readers; evidence at HEAD | Compatibility, order and retirement | |---|---|---|---| | `~/.klaus/config.json` | `~/.valley/flow/config.json` | `init` and operator → commands, including updater. `flow/internal/config/config.go:533`; `flow/internal/cmd/self_update.go:77` | R reads new file first, falling back only when absent. Preserve host/project precedence and host-only settings. W scaffolds new files; migrate an existing complete file only after old config readers are retired. Keep fallback while supported installations retain it. | | `~/.klaus/projects.json` | `~/.valley/flow/projects.json` | Project commands and scaffolding → project resolution and sync. `flow/internal/project/registry.go:25`; `flow/internal/project/registry.go:102`; `flow/internal/cmd/new.go:154` | One writable registry, never two copies. R remembers and writes the selected location. Existing registry stays there until its writers are stopped for cutover. Refuse independent registries at both paths rather than silently losing updates. | | `~/.klaus/sessions/**` | `~/.valley/flow/sessions/**` for new sessions | Coordinator, launch, finalize, dashboard, watches, jobs and consults → their corresponding readers. `flow/internal/run/homedir_store.go:25`; `flow/internal/cmd/watch.go:242`; `flow/internal/cmd/report.go:114` | R enumerates both roots and resolves each session ID to one directory. Every child file stays with that directory, including runs, logs, events, prompts, workspaces, jobs, consults, ledgers, scratch and locks. W creates new sessions under the new root. Old-session writes continue for that session’s lifetime, including later resumes. Remove legacy discovery only when no retained session needs it. | | Persisted paths inside session/run records | Keep their values | Launch/coordinator → resume, finalize, cleanup and replay. `flow/internal/run/run.go:23`; `flow/internal/run/run.go:33`; `flow/internal/cmd/session.go:193`; `flow/internal/cmd/replay.go:68` | Never substitute `.klaus` inside stored paths. Worktrees, logs, clones and backend conversation locations have identities beyond the directory spelling. No retirement through this rename. | | `~/.klaus/memory/` | `~/.valley/flow/memory/` | Backend memory writers; flow creates links → coordinators. `flow/internal/config/config.go:1155`; `flow/internal/config/config.go:1188` | Keep one shared directory while coordinators coexist. R selects the existing directory. Move it only with memory writers stopped; preserve the old target as an alias until persisted backend links are repaired. Do not start a second empty memory directory. | | `~/.klaus/consult-snapshots/` | `~/.valley/flow/consult-snapshots/` | One-shot consult → backend and cleanup using returned paths. `flow/internal/cmd/consult_snapshot.go:69` | W changes allocation only. In-flight consults finish and clean up their original paths. No fallback search or migration is needed for this transient allocation root. | | `~/.klaus/sync.log` | `~/.valley/flow/sync.log` | Background and explicit sync → operator; code appends. `flow/internal/projectsync/log.go:25` | W appends new invocations to the new file. Old producers may finish appending to the old file. Document both during coexistence; do not concatenate or duplicate records automatically. Retain old history independently of executable removal. | | `~/.klaus/locks/` | Keep the legacy coordination path | Reviews → other reviews. `flow/internal/cmd/review.go:195`; `flow/internal/review/lock.go:16` | All versions use the same lock files. Do not apply state-root fallback to locks. Keeping this small compatibility anchor permanently costs less than another lock-transition protocol. Session-local locks remain inside their pinned session directories. | | `$XDG_STATE_HOME/klaus/self-update.json`, otherwise `~/.local/state/klaus/self-update.json` | `~/.valley/flow/self-update.json` | Update, pin and rollback → subsequent updater invocations. `flow/internal/selfupdate/selfupdate.go:77`; `flow/internal/selfupdate/selfupdate.go:190`; `flow/internal/selfupdate/selfupdate.go:283` | R reads either location and preserves `current`, `previous`, `failed` and `pinned`. Keep one writable state file. Resolve its location after acquiring the shared updater lock. Move only after pre-R updater invocations and fallback installations are retired; R must support rollback after that move. | | Legacy `self-update.lock` | Keep its current XDG-derived path | Every updater operation → competing updater operations. `flow/internal/selfupdate/selfupdate.go:479` | Separate lock location from JSON location. All versions retain the same lock inode/path; never delete or relocate a held lock. Keep permanently as a coordination anchor. | | `.git/klaus/{runs,logs,prompts}` | Keep | Project scaffolding → its state/log consumers. `flow/internal/cmd/new.go:175`; `flow/internal/run/store.go:113`; `flow/internal/cmd/new.go:185` | This is a separate `GitDirStore`, not a home session. Moving it into home storage requires a standalone-run storage design. Retain this bounded exception rather than inventing repository identities for a cosmetic rename. | | `<project>/.klaus/config.json` | `<project>/.valley/flow/config.json` | `init` and project author → config loader. `flow/internal/config/config.go:441`; `flow/internal/config/config.go:506` | R reads new-first per file, then old. Keep defaults → host → project precedence and the host-only `forbidden_terms` boundary. W changes scaffolding after readers ship. Project migration is a source change; retain fallback for older project revisions and supported clients. | | `<project>/.klaus/prompt.md` | `<project>/.valley/flow/prompt.md` | `init`/project author → worker prompt renderer. `flow/internal/config/config.go:501`; `flow/internal/config/config.go:523` | R reads both, new-first only on file presence; malformed/unreadable new files are errors. W scaffolds the new location without overwriting an existing custom template. Old reads remain while supported checkouts use them. | | `<project>/.klaus/pr-fix-prompt.md` | `<project>/.valley/flow/pr-fix-prompt.md` | Project author → follow-up prompt renderer. `flow/internal/config/config.go:635`; `flow/internal/config/config.go:1338` | Same per-file reader-first rule. Existing agents retain their already-rendered prompts; no rewrite of saved prompts. | | `<project>/.klaus/session-prompt.md` | `<project>/.valley/flow/session-prompt.md` | Project author → coordinator prompt renderer. `flow/internal/config/config.go:1032` | R before project writer migration. Existing coordinator instructions remain valid through the retained command aliases. Keep old reads for retained project versions. | | `<project>/.klaus/principles.md` | `<project>/.valley/flow/principles.md` | Project author → scaffolding. `flow/internal/config/config.go:1326`; `flow/internal/cmd/new.go:29` | R reads both before projects move it. Missing files retain the existing built-in default; a bad new file must not silently select old principles. | | `~/.klaus/prompt.md`; project `context.md` | No new flow interface | There is no dedicated global-prompt or `context.md` discovery interface in the audited code. The prompt loader uses a supplied repository root and named template file. `flow/internal/config/config.go:1338` | Do not invent migration code for these proposed rows. External includes or tools must be audited in consuming projects and moved by their owners. | | `refs/klaus/data` | Keep permanently | Finalize/`push-log` → replay; optionally the remote host. `flow/internal/cmd/hidden.go:1189`; `flow/internal/cmd/pushlog.go:67`; `flow/internal/cmd/replay.go:269` | P fixes publication diagnostics. Keep the existing default and honour explicit `data_ref` unchanged. Avoid parallel histories, dual pushes and permanent per-blob fallback solely for spelling. Host authorization is discussed below. | | `refs/klaus/client` | No production name to migrate | The occurrence is the test ref `refs/klaus/client-test`. `flow/internal/git/client_test.go:45` | Do not create a production compatibility promise from a fixture. The test ref may become `refs/test/client` with its test. | | `Klaus-Run:` | Keep permanently | Provenance helper and installed commit hook → audit readers. `flow/internal/git/git.go:717`; `flow/internal/git/git.go:767` | Immutable history and installed hooks already carry this contract. No host parser for this trailer was found in the audited tree. Avoid dual trailers and an unsupported claim that all external readers have upgraded. | | `KLAUS_SESSION_ID` | `VALLEY_FLOW_SESSION_ID` | Coordinator/pane command → session store, dashboard, watch and launch. `flow/internal/cmd/session.go:399`; `flow/internal/cmd/store_helper.go:15`; `flow/internal/cmd/launch.go:1633` | R reads both; W exports both with identical values. Retire old exports only after every reachable helper understands the new variable. Retire old reads only after old coordinators, panes and external launchers stop exporting it. | | `KLAUS_RUN_ID` | `VALLEY_FLOW_RUN_ID` | Local/remote pane command → stream and pre-review event attribution. `flow/internal/cmd/runevents.go:25`; `flow/internal/cmd/runevents.go:37`; `flow/internal/cmd/runevents.go:297` | R reads both; W exports both. Preserve attribution when an old formatter remains alive. Retirement includes sandbox helpers and old pane command strings. | | `KLAUS_RUN_EVENTS` | `VALLEY_FLOW_RUN_EVENTS` | Remote launch → pre-review output routing. `flow/internal/cmd/runevents.go:32`; `flow/internal/cmd/runevents.go:43`; `flow/internal/cmd/pre_review.go:215` | R reads both; W exports both. Keep the value `output` unchanged. Remove old exports/reads only after both remote producers and local stream consumers have crossed R. | | `KLAUS_BACKEND` | `VALLEY_FLOW_BACKEND` | Coordinator/worker launch → consult selection and review author identification. `flow/internal/cmd/session.go:453`; `flow/internal/cmd/launch.go:1369`; `flow/internal/cmd/consult.go:265`; `flow/internal/cmd/pre_review.go:124` | R reads both; W exports both. Explicit new values override inherited old values; child environments must contain matching aliases. Keep old reads while old backend processes can launch helpers. | | `KLAUS_AGENT_BACKEND` | `VALLEY_FLOW_AGENT_BACKEND` | Coordinator → worker-backend resolver. `flow/internal/cmd/session.go:453`; `flow/internal/cmd/backend.go:13` | R reads both without changing flag/saved-state/environment/config precedence. W exports both. Retirement requires old coordinators and launch scripts to be gone. |Stage 3 design amendment, part 2 of 3: exit path per kept name, second half. | Current → eventual name | What R prepares; present cost | Condition for switching writers | When the old reader can go | |---|---|---|---| | `klaus.config`; `klaus.run`, `.changeid`, `.chaindir`, `.format` → `flow.config`; corresponding `flow.*` keys | Support both hook/config generations. While bridging, preserve the legacy file and write equivalent key sets; generate matching scripts in Go and replace files atomically. Cost: duplicate small configuration data and two template variants. Scripts currently hard-code the filename and namespace; installation removes and rebuilds the config (`flow/internal/git/git.go:726`, `:753`, `:790`, `:864`). | **W2:** every retained hook installation is identified and supports the new configuration. Keep legacy files for scripts still using them. **W1’s trailer change separately requires refreshed commit hooks.** | No installed or executing hook references the legacy file or keys. Do not add shell fallback logic. | | `<!-- klaus-agent-reply -->`, `<!-- klaus-actionable -->`, `<!-- klaus-cross-review … -->` → corresponding `flow-*` markers | Recognize both everywhere: reply exclusion, opt-in, trusted-review detection and round counting. Count each review once. Cost: three marker aliases. These markers affect dispatch and repetition limits (`flow/internal/cmd/review_check.go:16`, `:25`, `:100`; `flow/internal/review/pr.go:176`). | **W2:** every review detector is R-capable; generated prompts then request the new markers. Existing workers may finish using their original prompts. | **Never:** historical comments require these bounded marker aliases. | | `/klaus fix` → `/flow fix` | Accept both with the existing first-line, whitespace and quotation boundaries. Cost: one command alias (`flow/internal/cmd/review_check.go:25`). | **W2:** all comment consumers accept both; instructions switch to `/flow fix`. | **Never:** old comments must retain their meaning. Humans may continue using the alias. | | `<git-common-dir>/klaus/{runs,logs,…}` → `<git-common-dir>/valley/flow/{runs,logs,…}` | Discover both stores, retain each existing run’s actual store, reject conflicting duplicate identities. Cost: another store locator. Current paths are hard-coded and used by scaffolding (`flow/internal/run/store.go:108`, `flow/internal/cmd/new.go:176`). | **W2:** standalone run readers and writers are R-capable. New runs use the new store; existing runs finish in their original store. | After retained legacy records are deliberately migrated or removed and no process uses that store. | | Executable `klaus` → `valley-flow` | Updater smoke tests and dashboard restart support either executable, preserving the selected profile rather than finding an unrelated fallback. Cost: two-name lookup. Both executables already ship, but smoke tests require `klaus`; dashboard fallback is specifically toward `klaus` (`nix/packages.nix:1273`, `flow/internal/selfupdate/selfupdate.go:385`, `flow/internal/cmd/dashboard_restart.go:104`). | New internal invocations switch in **W2**. Executable removal waits for the final-removal conditions below. | No live pane, supported updater, timer, script or rollback target requires `bin/klaus`. | | Embedded `klaus _finalize`, `_format-stream`, `dashboard` → `valley-flow …` | Prepare generation-selected command construction and record which helper/build created the session. Cost: command selection and session metadata. These commands are embedded now (`flow/internal/cmd/launch.go:1370`, `:1413`; `flow/internal/cmd/session.go:399`). | **W2:** both executable names are present on every relevant local and sandbox PATH. Only newly constructed pane commands change. | When all panes containing the old commands have finished. Changing PATH does not rewrite their shell commands. | | Flake attribute `klaus` → `valley-flow` | Export both on Linux and Darwin; updater understands both. Preserve the legacy attribute’s legacy package identity, using a thin compatibility package around the same compiled program if necessary. Cost: one compatibility output, not another Go build. The updater currently builds exactly `.klaus` (`flow/internal/selfupdate/selfupdate.go:38`, `:465`); Darwin exports derive from `clientPrograms` (`flake.nix:176`, `nix/packages.nix:54`). | **W2:** R-capable updaters select `valley-flow`. Old updaters can still bootstrap through `klaus` until final removal. | All supported updater installations and consumers use the new attribute, including machines returning after being offline. Otherwise retain the cheap compatibility attribute. | | Profile element `klaus` → `valley-flow` | Match either element, record the actual element and store path, and restore either during rollback. Refuse ambiguous ownership. Cost: two-name matching and optional metadata. Current lookup/removal only uses `klaus` (`flow/internal/selfupdate/selfupdate.go:355`, `:410`). | **W2:** the active updater and its rollback target understand both identities. | Neither the installed element nor supported rollback requires legacy matching. Historical store paths remain valid strings. | | Nix derivation names `klaus`, `klaus-go-modules`, `klaus-flow-checker`, `klaus-${name}`, `klaus-flow-build` → `valley-flow`, `valley-flow-go-modules`, `flow-checker`, `flow-${name}`, `flow-build` | Prepare the canonical package plus legacy compatibility output. Build-only names need no runtime readers. Cost: changed derivations/cache identities (`nix/packages.nix:1248`, `:1267`; `nix/checks/flow.nix:17`, `:37`, `:81`). | Build-only names can change in **W1**; installation identity follows the package protocol in **W2**. Keep public required-check names unchanged. | No reader shim for build-only labels. Never rewrite existing store paths; retire the legacy compatibility derivation with its attribute. | | `Klaus-Run:` → `Flow-Run:` | Preserve interpretation of either trailer wherever provenance is consumed; prepare both Go and hook writers. Cost: two recognized keys, without rewriting history. Both writers currently emit `Klaus-Run:` (`flow/internal/git/git.go:717`, `:767`). | **W1:** commit-producing helpers and installed commit hooks are upgraded; in-flight legacy hook executions have drained before declaring cutover complete. | **Never:** retain the legacy trailer key for historical commits. |