gunk-dev/the-valley

guide.md

source28abc5737165main's published tip history
22.4 KiB · Rendered
1# flow guide
2
3This guide walks the everyday journeys for flow, the agent-run client that `valley flow` runs:
4setting it up, launching agent runs, following them, and seeing their work through GitHub or a
5valley. `valley flow` runs a separate program installed with its package. Every command, flag and
6key is in the [reference](./reference.md); how the pieces fit is in the [design](./design.md).
7
8## Setup
9
101. Install flow ([README](../README.md#install)) and the programs it runs
11 ([prerequisites](../README.md#runtime-prerequisites)). Authenticate each agent CLI you select on
12 every machine that runs it, sandbox hosts included.
132. Optionally run `valley flow init`: in a repository it writes `.klaus/config.json` and the worker
14 prompt template `.klaus/prompt.md`; elsewhere it writes the host config `~/.klaus/config.json`.
15 flow works without either. The host config holds what a repository must not choose (self-update,
16 forbidden terms); a repository's `.klaus/config.json` overrides the rest
17 ([configuration](./reference.md#configuration)).
183. Register the repositories you work on, so runs and consults can name them:
19
20 ```bash
21 valley flow project add acme/widget # clone into the projects directory and register
22 valley flow project add acme/site --path . # register an existing checkout
23 valley flow project set-dir ~/src # where project add clones
24 valley flow sync # fetch and fast-forward every registered project
25 ```
26
274. If you keep rules that hold across all your projects, point `house_rules` at the file in a
28 registered project's repository; flow adds it to every worker's brief and to the reviews and
29 consults it runs ([`house_rules`](./reference.md#prompts-and-house-rules)).
30
31## Coordinator sessions
32
33Run `valley flow` inside tmux. It resumes the most recent coordinator session, or starts one;
34`valley flow new` always starts a fresh one, and `valley flow session --resume <id>` resumes a given
35one. In a repository the coordinator gets its own worktree from `origin/<default branch>`; anywhere
36else it gets a scratch workspace under `~/.klaus/sessions/<id>/`. Registered projects sync in the
37background as the session starts.
38
39The coordinator is an ordinary interactive agent with `valley` and `valley-flow` on its `PATH`. You
40plan with it; it researches and writes briefs, and launches runs for work that can proceed in
41parallel. With `valley flow target acme/widget` (or a project name), launches from a session outside
42any repository go to that repository by default. A Claude coordinator's memory directory is shared
43across sessions through `~/.klaus/memory`; launched agents start clean.
44
45### Choosing backends
46
47The coordinator and the workers are chosen independently, from `claude`, `codex` and `agy`:
48
49```bash
50valley flow new --backend codex --agent-backend agy # coordinator codex, workers agy by default
51valley flow launch --backend claude --effort high --prompt-file brief.md
52```
53
54Persistent defaults live in `default_coordinator_backend`, `default_agent_backend` and per-backend
55`backends.<name>.model`/`effort`. A resumed coordinator keeps its backend; switch with
56`valley flow new`. Budgets, budget pause and stored-trajectory replay are Claude-only; the
57[backend table](./reference.md#backends) lists what else differs.
58
59## Launching runs
60
61```bash
62valley flow launch --prompt-file /tmp/brief.md
63valley flow launch --repo acme/widget --issue 42 --prompt-file /tmp/brief.md
64```
65
66Each launch mints a run ID, `<date>-<time>-<8 hex digits>`, fetches the default branch, makes a
67worktree on a new branch, installs commit hooks, and starts the agent headless in its own tmux
68window. The agent works, runs its checks, commits and pushes; when its turn ends, flow finalizes the
69run: it records cost and outcome, stores the run on the [data ref](./reference.md#the-data-ref), and
70removes the worktree.
71
72**Write the brief to a file.** The agent has the repository but none of the conversation: the brief
73is its whole briefing. Name what changes and why, the files and functions involved, what done looks
74like, and the constraints. `--prompt-file` passes it verbatim; a brief in a shell argument is
75subject to the shell's quoting, which expands backticks and `$VARS` outside single quotes. Briefs of
76any length work.
77
78**Choose the repository** with `--repo`: a registered project name, `owner/repo` or a URL (cloned
79under `<worktree_base>/.repos/`). Without it, launch uses the current repository, then the session
80target.
81
82**Model, effort, budget.** `--model` and `--effort` override the backend defaults; `--budget` caps a
83Claude run's spend in dollars (default `default_budget`, 5.00). `--reason` labels why a run was
84dispatched, for its events and `valley flow report time`.
85
86**Branch names** are `<slug>-<run ID tail>`, the slug taken from the `--issue` title or the brief's
87first `# ` heading or line, so `# Fix the healthz timeout` becomes
88`fix-the-healthz-timeout-bd92f081`. `--branch` names it exactly.
89
90**Where agents run.** Agents run locally unless `sandbox_host` names an SSH host: then the worktree
91is synced there and the agent runs remotely, while logging and finalize stay local. `--local` and
92`--host <name>` override it per launch ([sandbox](./reference.md#sandbox-hosts)).
93
94How a run delivers follows from the repository's `origin`: on github.com the agent opens a GitHub
95pull request <!-- prose-allow: vocabulary --> and the [GitHub pipeline](#runs-on-github) takes over;
96anywhere else it pushes its branch ([direct push](#repositories-without-github)), and a repository
97that [delivers to a valley](#repositories-that-deliver-to-a-valley) marks it ready there.
98
99## Following runs
100
101### The dashboard
102
103`valley flow dashboard` is the live view. It lists rows by what they work on: the runs on one GitHub
104pull request <!-- prose-allow: vocabulary --> share its row, and the runs on one change share the
105change's row. Rows are grouped by whose move it is:
106
107| Group | What is in it |
108| ------------ | -------------------------------------------------------------------------------------------------------------------------- |
109| **yours** | runs needing attention (`ATTN`), changes to approve (`READY`) or look at, branches to submit, GitHub rows ready to approve |
110| **agents** | rows with an agent running on them |
111| **pipeline** | everything waiting on CI, review, a merge or the integrator |
112| **done** | merged, closed, integrated, withdrawn, gone, and exited agents |
113
114`j`/`k` move, `a` approves the selected GitHub row, `o` opens it in a browser, `d` drafts a message
115about it into the coordinator's pane, `h` shows hidden done rows, `x` clears finished runs, `tab`
116selects a job and `enter` reads it, `q` quits ([all keys](./reference.md#valley-flow-dashboard)).
117With `dashboard.approve_command` set, the footer shows the command that approves the selected
118`READY` change, filled in with its handle and head, for you to copy; the dashboard never runs it.
119
120The dashboard also does work: it polls GitHub (or takes webhooks), dispatches fix runs, checks
121pushed branches and valley changes every minute, reports transitions as events, and restarts itself
122onto a new binary on `PATH`.
123
124### Status, logs and jobs
125
126```bash
127valley flow status # every run: status, change, CI, conflicts, merge readiness; then jobs
128valley flow logs <run-id> # the live pane, or the formatted saved log (--raw, --replay)
129valley flow jobs # running and recent consults, reviews and prose passes
130valley flow jobs show 1a2b --answer
131valley flow notifications # events since you last asked, summarised
132```
133
134### Events for the coordinator
135
136Pipeline, valley, consult and review events go to the session's `events.jsonl`. `valley flow watch`
137streams them: a Claude coordinator arms it in its Monitor tool at startup, so a merge, a landing or
138a failed check reaches it between turns. Codex and agy coordinators run `valley flow watch --once`
139as a background task, which prints the events that arrived and a `next:` line with the command that
140waits for the following ones; starting each watch from the last one's `next:` line delivers every
141event exactly once. Wait on `change:integrated` rather than polling for a landing
142([events](./reference.md#events)).
143
144### Clearing finished runs
145
146`valley flow cleanup --done` (or `x` on the dashboard) removes the runs of finished work and the
147older runs of open work, keeping each open item's latest run, anything needing attention, and
148anything running. `valley flow cleanup <run-id>` removes one run; `--force` also removes a running
149one, discarding its uncommitted work. `valley flow cleanup --all` tears the session down. Removed
150runs still count in the session's cost.
151
152## Correcting and continuing runs
153
154Agents run headless: nothing typed into their pane reaches them. To correct one, let it finish or
155remove it, and continue its conversation in a fresh run:
156
157```bash
158valley flow launch --resume-from <run-id> --prompt-file /tmp/correction.md
159valley flow launch --pr 42 --prompt-file /tmp/review-notes.md # more commits on a GitHub branch
160valley flow launch --change nxvp --prompt-file /tmp/review-notes.md # more commits on a change
161```
162
163`--pr` and `--change` work on the existing branch and keep its change ID; `--change` is for
164repositories without GitHub. Follow-ups on an existing change or GitHub work get a default scope
165rule that the brief can override: limit edits to the brief's items, their tests, and sentences those
166edits make untrue; stop and report cost before building new mechanism; run one `_pre-review` pass on
167the final head; and report each item's status and the round's size against its starting head. A
168Claude follow-up replays the previous run's stored conversation when it is eligible
169([trajectory replay](./reference.md#trajectory-replay)). These launches refuse while another run
170works on the same branch or change, naming it; wait for it, or pass `--force-takeover`. They never
171remove a worktree that has the branch checked out, nor discard local commits that origin lacks,
172except that `--force-takeover` resets the local branch to origin's tip.
173
174## Runs on GitHub
175
176Once an agent opens its GitHub pull request, <!-- prose-allow: vocabulary --> the dashboard follows
177it through a state machine:
178
179```
180ci_pending → ci_passed → approved → merged
181 ↓ ↓ ↓
182ci_failed changes req. conflicts / behind
183 ↓ ↓ ↓
184fix agent fix agent rebase agent / branch update
185```
186
187- **CI fails**: a fix agent is dispatched onto the branch (`valley flow launch --pr <n>`).
188- **Changes requested**, or comments from a `trusted_reviewers` login: an agent addresses them.
189- **Conflicts**: a rebase agent resolves them. **Behind the base branch**: the branch is updated
190 from the base (`gh pr update-branch`) and merged once CI re-runs.
191- **Approved, CI green, no conflicts**: merged automatically when `auto_merge_on_approval` is on.
192- A merge or branch update that keeps failing moves to `stalled` after three tries and emits one
193 `pipeline:stalled`.
194
195The pipeline never dispatches while a fix run is already working on the branch.
196
197### Review, approval and merge
198
199Approval is the operator's: the coordinator never approves. Approve with `a` on the dashboard or
200`valley flow approve 40 41`, then `valley flow merge 40 41` lands them in order, waiting for CI,
201rebasing a conflicting one and verifying it (`merge_verify_command`) before its force-push. With
202`require_approval` (the default), merge skips or asks about unapproved ones; `--yes` skips them
203without asking.
204
205A comment from a `trusted_reviewers` login dispatches a fix agent even without a formal "changes
206requested". Your own conversation comments on an agent's work count only when they start with a
207`/klaus fix` line or carry `<!-- klaus-actionable -->` on a line of their own, since you and the
208agents post through the same GitHub account.
209
210Each agent requests review from `pr_reviewer`, or from a reviewer flow picks from the repository's
211collaborators ([`pr_reviewer`](./reference.md#configuration-keys)).
212
213### Webhooks
214
215Polling every 30 seconds is the default. For prompt updates, run a relay that forwards GitHub
216webhooks to the dashboard, set `webhook.relay_url` and `webhook.secret_file`, and create the hooks:
217
218```bash
219valley flow webhook check
220valley flow webhook setup # or: valley flow webhook setup widget
221```
222
223## Repositories without GitHub
224
225When `origin` is not on github.com (a plain SSH remote such as `git@192.0.2.10:widget.git`, or a
226local path), the agent pushes its branch instead of opening anything, and starts its final report
227with the run ID, the branch and its head. The run shows as `awaiting-integration`, and the dashboard
228as `SUBMIT <branch>@<short sha>` until flow sees the work on the default branch (`INTEGRATED`, or
229`INTEGRATED~` for a content match) or the branch deleted (`GONE`).
230
231A run that ends without delivering, at a session limit, with uncommitted work, or crashed, is
232salvaged: finalize commits what is left, pushes the branch without force, keeps the local branch,
233and marks the run `needs-attention` (`ATTN`). Continue it with `--resume-from`, `--pr` or
234`--change`; the run that takes the pushed work on carries the attention from then on.
235
236## Repositories that deliver to a valley
237
238A direct-push repository whose head carries `policy/valley` or a `policy/instance/` directory, with
239a `valley` on `PATH` that offers `ready` and `changes`, delivers to a valley. After the push,
240finalize marks the pushed head ready as a version of the run's change:
241
242```
243valley ready --change <change-id> --head <pushed sha> <branch>
244```
245
246The change ID is the `Change-Id` trailer flow stamps on every agent commit
247([trailers](./reference.md#commit-hooks-and-trailers)). The valley names the uploader from the
248clone's `valley.principal`, which the host sets. The run then reads `READY` (`awaiting-approval`)
249until the valley says otherwise: `APPROVED` once you approve it, `INTEGRATED` once it lands, or
250`STALE`, `REJECTED`, `CHECKS FAILED`, `CONFLICTING` and the rest
251([valley states](./reference.md#valley-change-states)). You approve on your own machine, with the
252valley's own `approve`; `dashboard.approve_command` shows the command for the selected row.
253
254### Drafts until review passes
255
256What you approve is what shows as ready, so a change should not show as ready before its review is
257done. Set `"ready_at_finalize": false` (host config, or a project's `.klaus/config.json`) and
258finalize records the version but returns the change to draft (`REVIEW`, `awaiting-review`). When the
259review passes, the coordinator marks exactly the reviewed head ready:
260
261```bash
262valley flow ready nxvp --head 1a2b3c4
263```
264
265`valley flow ready` refuses when the change has moved to another head since the review, and while
266any run is working on the change.
267
268### Follow-ups on a change
269
270Every follow-up on a change goes through `valley flow launch --change <handle|change-id|run-id>`.
271The run works on the change's branch and keeps its change ID; launch first returns the change to
272draft so nobody approves it mid-rework, and finalize marks the new head ready again as the next
273version. Because a valley lands a change as one commit under its head message, the agent amends the
274head commit (or ends with a commit describing the whole change), never merges another branch in, and
275pushes with a lease on the head it started from, so a push someone made meanwhile makes its push
276fail rather than be lost. On the dashboard the follow-up joins the change's row.
277
278### Restack conflicts
279
280After each landing the valley's restacker rebases ready changes onto main. When that conflicts on a
281change flow owns, the dashboard (or `valley flow restack-conflicts` once, without a dashboard)
282returns it to draft and dispatches a run that rebases onto `origin/main`, resolves the conflicts and
283pushes; finalize marks the result ready. It acts once per set of inputs, at most three runs per
284change until a clean restack, and never on a change it does not own or one that sits on other
285changes. When it stops short, it emits `change:restack-stalled`, and the change becomes yours.
286
287### Failed checks
288
289The valley host runs a ready change's required checks. flow shows them in the CI column (`CI …`,
290`CI ✗`, `CI ✓`), emits `change:checks-failed` and `change:checks-passed`, and dispatches a run to
291fix each failed head of a ready change flow owns, as for failing CI: the brief names the failed
292checks, says how to read the worker's build output with `valley telemetry`, and has the run build
293every check `valley checks --names origin/main HEAD` lists before it pushes. It stops after three
294failed attempts until the checks pass. `valley flow failed-checks` does the same once, without a
295dashboard.
296
297### Working a knot
298
299On a valley project, `--issue` takes a knot from the project's plan graph, by its ID (`oc-`, `bd-`,
300`ida-` or `qn-` and seven hex digits) or as `<project>:<id>` for another project on the same valley:
301
302```bash
303valley flow launch --issue <knot-id> --prompt-file /tmp/brief.md
304```
305
306Launch reads the knot, its parents and comments through `valley knot`, appends them to the brief as
307untrusted project notes, names the branch from the knot's title, and claims the knot for the run.
308Finalize links the change to the knot and releases the claim; when the dashboard sees the change
309land, it comments on the knot and closes it if nothing else keeps it open
310([knots](./reference.md#knots)).
311
312### Tracking existing work
313
314`valley flow track` adds work no agent of the session made to the dashboard and
315`valley flow status`, GitHub work and valley changes alike; `valley flow untrack` removes it:
316
317```bash
318valley flow track 405 acme/widget#406 # GitHub, by number, owner/repo#N or URL
319valley flow track site:vpkz # a valley change, by <project>:<handle>
320valley flow untrack 405 site:vpkz
321```
322
323## Cross-model review
324
325Same-family review shares blind spots, so flow reviews with another model family than the one that
326wrote the code. The `_pre-review` an agent runs before delivering already does so. For a second
327opinion on open GitHub work:
328
329```bash
330valley flow review 303 # reviewer family chosen by cross_review
331valley flow review 303 --backend codex
332valley flow review 303 --post # submit one COMMENT review
333```
334
335The reviewer reads only the diff, title and description, read-only, in an empty directory. A posted
336review is a second opinion, never an approval: its inline findings feed the trusted-review fix loop,
337and `valley flow review` refuses to post twice on one head or beyond `cross_review.max_rounds`
338([cross-model review](./reference.md#valley-flow-review)).
339
340## Prose rewrites
341
342Beside its peer review, `_pre-review` has another model family rewrite the prose a change adds (its
343Markdown, READMEs, files `pre_review.prose.paths` matches, and the head commit message), and a third
344fact-check the rewrite. It prints each rewrite with any fact-check failure and saves the passing
345ones as a patch for `git apply` and a message for `git commit --amend -F`. Nothing is applied for
346the agent, and the pass never fails `_pre-review`. Each pass is a `prose` job; finalize marks each
347rewrite applied or rejected by whether the worktree has it.
348
349## Consulting other models
350
351`valley flow consult` asks another model family a read-only question, without a worker, worktree or
352branch:
353
354```bash
355valley flow consult --role critic --file plan.md --thread auth "Critique this plan"
356valley flow consult --repo widget "Where is the retry policy decided?"
357valley flow consult --panel "Polling or webhooks for build status?"
358valley flow consult --thread design "Draft the migration plan" & # then: valley flow jobs show <id> --answer
359```
360
361Roles are `partner`, `critic`, `reviewer`, or your own system prompt. `--thread NAME` keeps a
362conversation per topic in the session. `--repo` reads a registered project as origin's default
363branch has it, through a fresh snapshot, never the clone's working tree. `--panel` asks every other
364installed family at once. Each call is a job, listed by `valley flow jobs` and the dashboard
365([details](./reference.md#valley-flow-consult)).
366
367## Budget pause and resume
368
369Budget-paused work waits in a draft GitHub pull request <!-- prose-allow: vocabulary --> labelled
370`klaus:budget-paused`. When a Claude agent reaches its `--budget`, flow commits what is uncommitted,
371pushes the branch, opens or updates the draft with a comment saying how to continue, and cleans up,
372rather than discarding the work. The dashboard shows it as budget paused, awaiting your decision. To
373resume:
374
375```bash
376valley flow launch --pr 42 "continue the work"
377```
378
379The new agent replays the paused conversation when eligible, and its finalize removes the label
380(emitting `agent:resumed`). Close the draft to abandon the work, or push commits to redirect it.
381
382## Where agent time goes
383
384```bash
385valley flow report time # the last week, every session
386valley flow report time --since 2w --repo widget
387valley flow report time --current --json
388```
389
390The report sums runs by dispatch reason, time by phase, checks by kind, idle time between a change's
391runs, time from a run to approval, follow-ups per change, consult and review time, and cost where
392known ([report fields](./reference.md#run-fields-on-events)).
393
394## Keeping flow up to date
395
396A host can follow a branch of this repository without a system rebuild. In the host config:
397
398```json
399"self_update": { "repo": "git@valley-host:~/the-valley", "branch": "main" }
400```
401
402Then run `valley flow self-update` from a timer: nothing notifies the host when the remote branch
403moves. It resolves the branch's tip, refuses (changing nothing) unless the flake at that commit
404offers `packages.<system>.klaus`, builds exactly that package, smoke-tests it, and installs it into
405your nix profile as the element `klaus`. Each step prints one line, so the timer's journal reads as
406a history. A running dashboard restarts onto the new build by itself; running agents finish on the
407build they started with.
408
409```bash
410valley flow self-update --rollback # back to the previous build; again to return
411valley flow self-update --pin # hold the current build until --unpin
412valley flow self-update --retry # rebuild a tip that failed before
413```
414
415`valley flow self-update` installs flow; `valley self-update` is the valley CLI's own command and
416does not touch flow ([self-update](./reference.md#valley-flow-self-update)).