gunk-dev/the-valley

valley

source499d9e61dfeemain's published tip history
78.9 KiB
1#!/usr/bin/env bash
2# valley — the S1 integrator's verbs, as a plain shell script.
3#
4# EVICTION CLAUSE (owner-ratified; the decision node is
5# archive/.the-valley/decisions/dcr-74c3158-valley-cli-lifecycle.md).
6# This tool is deliberately a shell script: it runs from any checkout with
7# nothing but git and coreutils — no machinery, the portability stance of
8# ida-b9f646c. It GRADUATES to its own repo and a real language the moment
9# ANY tripwire is crossed:
10# - it grows past ~300 lines;
11# - it needs persistent state, config, or a daemon
12# (CROSSED by review's notes, which outlive the session in
13# $XDG_STATE_HOME/valley/notes.);
14# - it needs dependencies beyond git + coreutils
15# (CROSSED by Phase 1's tail/replay, which need the nats CLI, and again
16# by checks, which needs the cue CLI, again by review's [a]pprove, which
17# needs the attest helper, and again by status, ready, unready and
18# withdraw, which are a Go program (status/) this script runs —
19# graduation is now due; recording the decision node is part of taking it.);
20# - its behavior gets subtle enough to need real tests
21# (CROSSED by checks: glob matching is pinned by the policy-deriver
22# flake check, not by reading the code.);
23# - it needs nontrivial parsing or concurrency
24# (CROSSED by checks: glob-to-regex translation and -z diff parsing.).
25# The size tripwire (~300 lines) is crossed too. Which way to take the
26# graduation is dcr-2aa1a12, still `proposed`.
27# Graduation is a deliberate act, recorded as a decision node.
28
29set -euo pipefail
30
31# Every verb reads the repository's own objects. A replacement ref makes one
32# object stand in for another wherever git looks it up, so a fetched or
33# planted refs/replace/* could change the diff a reviewer reads, the policy
34# a derivation composes, and the tree a request is filed for. git is told
35# to ignore them, whatever configuration says, and the variables that point
36# it at other objects or at another replacement namespace are dropped. What
37# chooses the repository and the person's own configuration are kept: a
38# fetch of the owning valley needs that configuration, and neither changes
39# what an object id reads as once replacement refs are off.
40export GIT_NO_REPLACE_OBJECTS=1
41unset GIT_REPLACE_REF_BASE GIT_GRAFT_FILE GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES
42
43# The version the package stamped on this script when nix built it
44# (nix/packages.nix): the CLI's version and the commit it was built from.
45# A script run straight from a checkout has none. It is taken here and
46# unset, so no program this script runs inherits a stamp that is not its
47# own; self-update is handed it explicitly.
48VALLEY_STAMP="${VALLEY_VERSION:-}"
49unset VALLEY_VERSION
50
51# When this invocation started, in microseconds, for its command record
52# (valley help telemetry). Reading the clock starts no process.
53TEL_T0="${EPOCHREALTIME/[.,]/}"
54
55die() {
56 printf 'valley: %s\n' "$*" >&2
57 exit 1
58}
59
60usage() {
61 cat <<'EOF'
62usage: valley <verb> [args]
63
64valley — S1 integrator verbs for a valley project: author, review, approve, and
65track changes and the plan graph.
66
67Authoring and updating changes:
68 ready mark a branch head ready as a new version of its change
69 unready pause a ready change by marking it a draft
70 withdraw mark a ready or draft change withdrawn
71 rebase rebase a change and its stack onto origin/main
72 checks print the checks the composed policy requires of a diff
73
74Reviewing, approving, and inspecting changes:
75 pending list what needs an approval, in landing order, and what moves
76 review page through a change or stack to approve, rebase, or reject
77 approve run required checks and file an integration request
78 status read a change's integration request and last outcome
79 changes print every recorded change as valley-changes/v1 JSON
80
81Planning work:
82 plan show the project's plan graph as a milestone tree
83 knot read and write knots in the plan graph at refs/the-valley/knots
84
85Bus and client maintenance:
86 tail watch NATS bus events scroll by
87 replay publish ref-updated events for the current refs of a repo
88 self-update build, test, and install the tip of a branch of the-valley
89 telemetry read a valley host's diagnostics over ssh (observe grant)
90
91A change is named by its 32-letter change id, its handle (shortest unique
92prefix, at least 4 letters, or <repo>:<handle>), or its branch name.
93Runs from any checkout; nix run .#valley bundles git, valley-go, attest, cue,
94less, and natscli (self-update also needs nix). Judgment stays with the human:
95nothing here writes main.
96
97`valley --version` prints the package's version and commit (e.g. 0.1.0-97db597,
98with -dirty for uncommitted changes, -unknown when nix knew no commit, or
99unstamped when run straight from a checkout).
100Run `valley help <verb>` (or `valley <verb> --help`) for a verb's flags and
101rules. See docs/reference.md for the full CLI, ref, and schema reference.
102EOF
103}
104
105help_naming() {
106 cat <<'EOF'
107
108A change is named by its full change id, by its handle — the shortest
109prefix of the id, four letters at least, that no other change recorded on
110origin shares, written <repo>:<handle> too, with this repository's name —
111or by its branch. A name written origin/<branch> is always
112a branch. A handle that is also a branch on origin is refused unless the
113change is on that branch. review, approve and rebase read a branch name,
114written either way, against every record on origin: when exactly one
115record's active version is on the branch, the name is that change, as if
116its id were given, and when more than one's is, the verb refuses and lists
117their ids. A change that has landed as any version — its head is on
118main's first-parent history with no merge above it, or the integrator's
119outcome record and verified transfer statement record that exact head
120landing — is skipped, unless its active version was made on that landing, so a branch can be used again once its change has
121landed. unready, withdraw and status read a branch the same way. A
122branch no record's active version is on is acted on as a branch. A
123change with a record is reviewed, approved and rebased at the
124head its active version records, never at its branch's tip: review shows
125that head and its [a]pprove approves it, and rebase and review's
126[r]eject refuse, naming both, when the branch's tip on origin is another
127commit. approve approves the head bound to it, wherever the branch is.
128[r]eject deletes the branch under a lease on the recorded head. approve,
129and rebase refuse a change whose record is not ready, naming its state,
130and review offers neither [a]pprove nor [r]eject for a change that is not
131ready when it shows it. approve and rebase read the record again just
132before they act, and again before approve files or rebase pushes, and
133refuse when the change is not ready. review reads the change again before
134its [a]pprove or [r]eject acts. When the change has moved since review
135showed it, returned to draft, withdrawn, given a new version or landed,
136review says so in one line and moves on, without asking again. rebase also refuses when the change's
137record has changed at all since it began, and approve when the head it
138approves is not a version's. A name that read as a plain branch is
139read again before approve files or rebase pushes. If it names a change by
140then, rebase refuses, and approve files only while the change is ready at
141the head it began with. An approval already past that last check can
142still file if the change is unreadied or withdrawn in the moment before
143its push; the integrator refuses to land it, since it lands no request
144that would bring a version of a change that is not ready, whatever the
145request is named.
146The integrator reads the records last just before it moves main, so a
147change paused in that moment can still land at the head the operator
148approved, and never at any other.
149EOF
150}
151
152help_runtime() {
153 cat <<'EOF'
154
155Runs from any checkout of the project; needs only git and coreutils,
156except tail and replay, which also need the nats CLI (natscli), checks,
157which also needs the cue CLI, review's notes, which need less, approve
158and review's [a]pprove, which need both the cue CLI and the attest
159helper, and status, ready, unready, withdraw, review, approve and rebase,
160which need the valley-go helper, as pending, changes, knot, plan and
161self-update do. nix run .#valley bundles all of them. self-update also
162needs nix. Deriving a policy fetches the owning valley's repository, so
163checks and approving also need whatever reaching it takes.
164No config but valley.principal, which ready, rebase, knot and plan read,
165and valley.selfUpdate.repo and .branch, which self-update reads; no batch
166mode; and no state but the notes file, the handle cache pending and
167changes write for completion, and self-update's record of what it
168installed — the judgment stays with the human.
169EOF
170}
171
172help_unready_withdraw_requests() {
173 cat <<'EOF'
174 the integrator lands no request that would bring a
175 version of a change that is not ready, so unready and
176 withdraw both stop a
177 pending integration request, under c-<change id> or a
178 branch's request name. each says so when origin holds
179 one. a draft's request stands and lands once the change
180 is ready again. withdrawing voids the request: the
181 integrator deletes it on its next pass while the change
182 is still withdrawn. withdraw warns, since a ready before
183 then leaves the request standing: only a holder of the
184 approve grant (also accepted as request) may touch a
185 request ref, so the operator must drop it then.
186EOF
187}
188
189help_pending() {
190 cat <<'EOF'
191usage: valley pending [--all] [--repo <name>] [--checks] [--drafts] [--branches] [--json] [-v] [--known-signers <file>] [--integrator-name <name>]
192
193 pending [--all] [--repo <name>] [--checks] [--drafts] [--branches]
194 [--json] [-v] [--known-signers <file>] [--integrator-name <name>]
195 list what waits on you and what is moving. one line
196 on main's state comes first for each project whose
197 policy declares follow checks: clear, clearing or
198 muddy. needs you holds the ready changes that wait on
199 an approval, one numbered row each in landing order:
200 oldest ready first, as the check worker builds them,
201 then by project and change id. a row gives the
202 handle and active version, its checks as passed out of
203 required (or how many are pending), and how long it
204 has been ready, with its title under it. a stack of
205 such changes is one row, its top's, saying `stack of
206 N`: approving the top lands every layer. moving holds
207 the ready changes that need no approval now, one line
208 each: ◐ approved, waiting on checks and the
209 integrator; ✗ a check failed, named; ✗ or ◇ a restack
210 holds it. older versions are never listed. a last line
211 counts the drafts and the branches no change is on.
212 lines fit the terminal, or 80 columns off one; titles
213 are cut short with …, names never. names are bold and
214 glyphs coloured on a terminal unless NO_COLOR is set.
215 --all every project the serving host
216 publishes, as one listing: each line
217 names its project, and the rows of
218 every project share one landing order
219 (see valley help changes)
220 --repo NAME that one project
221 --checks add to each row the checks the policy
222 requires of it, by cost, as checks
223 derives them, and its full check state,
224 naming the checks that failed and what
225 they cost the host's check worker to
226 build. with --json, give each pending
227 change its checks object
228 --drafts list the drafts in full, in place of
229 their count
230 --branches list the branches no change is on in
231 full, in place of their count. each
232 draft and branch is a block: its name
233 with its head's age and author, its
234 title, then the commits and the diff
235 it adds to the nearest listed entry
236 its head contains, or to main. a stack
237 is its top, then every entry the top
238 contains, at one indentation; an entry
239 not on the one listed after it says
240 `on <base>`
241 --json print valley-pending/v1: the
242 valley-changes/v1 shape, with the
243 pending changes in changes, each
244 marked approved or not, and the
245 drafts in drafts
246 -v follow each row with its block, its
247 stack drawn in full, with what its
248 head includes, `uncertain` when it may
249 have landed without its evidence
250 stored, and its full check state; and
251 warn on stderr when a plan graph is
252 missing or unreadable
253 --known-signers FILE, --integrator-name NAME
254 what a transfer statement is verified
255 with (see changes below)
256 reading the checks costs seconds for each project
257 with a ready change. needs the valley-go helper.
258EOF
259 help_runtime
260}
261
262help_changes() {
263 cat <<'EOF'
264usage: valley changes --json [--all] [--repo <name>] [--checks] [-v] [--known-signers <file>] [--integrator-name <name>]
265
266 changes --json [--all] [--repo <name>] [--checks] [-v]
267 [--known-signers <file>] [--integrator-name <name>]
268 print every change origin holds a record of, in every
269 state, as one JSON object, valley-changes/v1, for front
270 ends to read (docs/architecture.md): each version's
271 head, title and branch, how far it has landed
272 (landed, landed-recorded, uncertain or not-landed),
273 its pending request and its last outcome, the knots in
274 refs/the-valley/knots that link it
275 (valley:<project>/<change id>, active first), and
276 the branches no change is on. -v warns on stderr when a
277 plan graph is missing or unreadable. --checks adds
278 checks to the active version of each ready change that
279 has not landed: each check the policy requires of it,
280 passed, failed or pending by the note the integrator
281 would judge it by on origin, and other for a check the
282 host's worker does not run (docs/reference.md). each nix
283 check also gives its build time for this version, and
284 the median of its recent builds, from the host's
285 worker telemetry; when that cannot be read, those
286 fields are left out and stderr says why. it costs a
287 few seconds for each project with such a change.
288 handles are unique across
289 everything listed: a change id recorded in more than
290 one repository listed has the handle <repo>:<prefix>
291 in each. without --all it covers this
292 repository. --all covers every project the serving
293 host lists at refs/the-valley/projects in its instance
294 repository, which policy/valley names at main's tip on
295 origin; each project's URL is the instance's with its
296 last path segment replaced, and is read through a clone
297 kept under $XDG_CACHE_HOME/valley/repos. a url that
298 opens with a dash, names a <transport>:: helper such
299 as ext::, or has a scheme other than ssh, git, https or
300 file is refused. a repository that cannot be read is
301 listed with its error. --repo limits it to one
302 project. landed means on main's first-parent history
303 with no merge above it. landed-recorded needs a landed
304 commit with one parent and the integrator's transfer
305 statement for the version's request name, verified;
306 the integrator's outcome record for that name saying
307 land at the version's head; and the integrator's merge
308 of the head onto the landed commit's parent giving the
309 landed tree. attest verifies the statement with the
310 registry's known-signers file and the integrator's
311 signing name. each is taken from the first of these
312 that gives it: --known-signers FILE or
313 --integrator-name NAME; VALLEY_KNOWN_SIGNERS or
314 VALLEY_INTEGRATOR_SIGNER; what the serving host
315 publishes at refs/the-valley/signers in its instance
316 repository, read only when a statement needs
317 verifying. a file that does not read, or holds no key
318 under the name, is reported on stderr, and then no
319 statement is verified.
320 needs the valley-go helper.
321EOF
322 help_runtime
323}
324
325help_review() {
326 cat <<'EOF'
327usage: valley review [-v] [--build-here] <change>
328 valley review [-v] [--build-here] [--repo <name>]
329
330 review [-v] [--build-here] [--repo <name>]
331 with no change, review each change that needs you, as
332 valley pending --all lists them, in landing order, or
333 those of the project --repo names. each step opens
334 with `[1/3] <project> · <handle> v<N> · <checks>` and
335 is the review below, run where the project is read:
336 this checkout, or the clone valley keeps of another
337 project, lent this checkout's valley.principal,
338 user.name and user.email. a change that landed, is
339 not ready or has no branch since is not reviewed; one
340 at a new version is reviewed at it. the walk ends with
341 each change's outcome and what still needs you. a
342 project that did not read is said first and last. a
343 change in a project whose main names another valley
344 ends in error: review it from that valley's checkout.
345 ctrl-c or SIGTERM ends the walk with what it walked,
346 exit 130.
347
348 review [-v] [--build-here] <change>
349 page through the change's branch: its log, with each
350 commit's whole message, and diff vs origin/main, or a
351 stack layer by layer (below). above
352 each change's diff, review shows every knot in the plan
353 graph that links the change, as `does oc-6335749 (open):
354 <title>` (valley-go does). a missing or unreadable graph
355 shows no knots; -v warns on stderr. before the prompt, a
356 ready change shows the state of its checks and what
357 they cost the host's check worker to build, as pending
358 --checks shows it: `checks: 21 passed in 9m10s (eval
359 24s); worker-e2e 431s, +100s against its recent 331s`.
360 review reads them while it shows the diff and never
361 waits for them: a line not read by the prompt is not
362 shown, unless VALLEY_REVIEW_CHECKS_WAIT=<seconds> says
363 how long to wait for it. checks that cannot be read show no line; -v
364 warns on stderr. the prompt is one header line, the
365 change and its state, `nqyw v3 · checks: 4 passed ·
366 behind main (integrator merges)`, then the keys it
367 takes; a change that can't be approved says why in the
368 header and is not offered [a]pprove. -v also passes -v
369 to approve. then choose:
370 [a]pprove file an integration request for the
371 head shown, as approve does (valley
372 help approve). it reuses the evidence
373 origin holds for the checks the
374 composed policy requires of this
375 change. when a required nix check has
376 none, it files the request at once
377 all the same, builds nothing, and
378 names the check. when evidence is
379 published, the integrator considers
380 the request again; it may never be
381 published. given
382 --build-here, review's [a]pprove builds
383 those nix checks here instead. it runs
384 the command checks, and any nix check
385 it builds, over a throwaway worktree of
386 that head, signs each result as an
387 attestation, and publishes the evidence
388 and the request ref to origin in ONE
389 atomic push. this files the request;
390 it does not wait for integration or
391 update your local checkout. use status
392 to read the result. the policy comes
393 from the target's tip and the owning
394 valley's, as checks describes (valley
395 help checks), so your checkout
396 can be on any branch. a change the policy
397 requires no check of is filed too, as a
398 request with no evidence, and says so.
399 approving a change already requested is
400 how it is filed again. at a head rebased
401 onto a moved main it replaces the request
402 ref under a lease and names the head it
403 replaced; at the same head it leaves the
404 ref alone and publishes only the new
405 evidence, which origin refuses when
406 this signer has already attested that
407 tree: approve publishes a signer's
408 evidence for a tree once (bd-7b7d58f). every write of the request
409 ref is leased, filing included, so an
410 approval that lost a race is refused
411 rather than clobbering the one that won.
412 needs the attest helper whenever a
413 check is required, and
414 VALLEY_ATTEST_KEY, the ed25519 key this
415 host signs with, whenever a check runs
416 here; VALLEY_ATTEST_NAME is the name it
417 signs under, defaulting to this host's.
418 [v]iew full diff
419 page the change's whole diff, with
420 notes taken as below, and ask again
421 [r]eject delete the remote branch (confirmed first)
422 [s]kip do nothing
423 a change with a record is first set against its
424 approved version: the greatest version below the one
425 shown whose exact head an integration request or a
426 land, stale or reject outcome on origin names, under
427 c-<change id> or a branch name of the change that
428 nothing else maps to (valley-go compare). with none,
429 or an ambiguous one, review pages the whole diff. its
430 first line says what changed since you approved v<m>:
431 `<change> v<n> at <head>: rebased since you approved
432 v<m> at <old head>, with the same file changes.`
433 each version's diff from its merge base with main
434 changes the same files the same way (valley-delta-v1).
435 review prints the commits main landed between the
436 bases, and pages nothing.
437 `... rebased since you approved v<m> at <old head>.`
438 the commits are the same patches, messages and
439 authors, but main also edited files the change edits.
440 review pages each file whose change differs, with the
441 landings that edited it, then the shown version's diff
442 of those files.
443 `... edited since you approved v<m> at <old head>.`
444 a commit's patch, message or author differs. review
445 pages how many commits changed, the files whose change
446 differs with the landings that edited them, git
447 range-diff of the two versions, and the shown
448 version's diff of those files, or prints a changed
449 message or author when the files are the same. -v adds
450 each file's mode and SHA-256 in each version. on a
451 terminal, unless NO_COLOR is set, the title, the
452 section headings and the hashes are styled; the buffer
453 the editor opens is plain. this is information only:
454 it files nothing and skips no check.
455 when [a]pprove's checks fail, the prompt says approving
456 needs a new head and stops offering [a]pprove until the
457 change has one. any other refusal keeps the prompt as
458 it was.
459 [a]pprove files the head shown, for a branch no record
460 is on too: it refuses, naming both heads, when the
461 branch on origin has moved off that head since.
462 [a]pprove is the only way a change reaches main from
463 here, and approve (valley help approve) is the same act
464 without the pager.
465 Nothing in review writes the protected ref: the
466 integrator does, having judged the request.
467 a change behind main (one that does not fast-forward
468 from it) is asked the same prompt, under one line:
469 `<branch> is behind main; the integrator lands it
470 onto main as main stands (no rebase needed).`
471 the integrator applies the change's delta onto main as
472 it stands, and the host's restacker rebases ready
473 changes itself, so review asks nothing more of it.
474 while the restacker reports a conflict for the change,
475 the line says `<branch> conflicts with main; its owner
476 is resolving it.` instead. [a]pprove is still offered,
477 and the integrator decides whether the change applies.
478 to rebase a change of your own, use valley rebase.
479 a change whose record is not ready says so above its
480 diff, and again in place of the prompt, which then
481 offers only [v]iew full diff and [s]kip:
482 `<change> v<n> is a draft: its owner (<owner>) hasn't
483 marked it ready, so it can't be approved yet.`
484 `<change> is withdrawn: there is nothing to approve.`
485 a draft is often a change an agent is still working on.
486 [a]pprove would be refused. [r]eject records nothing
487 on the change: it would only delete a branch its owner
488 may still be working on.
489 before [a]pprove or [r]eject acts, review reads the
490 change again. when it moved while you read it, review
491 says what changed in one line, and acts on nothing
492 unless you approve a new version it offers:
493 `<change> changed while you were reviewing: it was
494 returned to draft (since <time>), so there is
495 nothing to approve now. It comes back when it is
496 ready again.`
497 `<change> changed while you were reviewing: it was
498 withdrawn (since <time>), so there is nothing to
499 approve.`
500 `<change> moved to v<n> while you were reviewing
501 (<why>) · [a]pprove v<n>, [v]iew what changed
502 since v<m>, [s]kip?`
503 `<change> landed as v<n> while you were reviewing;
504 there is nothing left to approve.`
505 <time> is when the record last changed, in UTC.
506 a new version with the same changes and commits, such
507 as a restack the carry mode allows, keeps the answer:
508 `<change> moved to v<n> while you were reviewing.
509 v<n> is v<m> rebased onto the new main with no
510 other changes, so your approval covers it.`
511 and [a]pprove files v<m>, the head shown. its verdict
512 names v<n>, which lands, with v<n>'s checks. otherwise
513 <why> says whether the change's commits changed or
514 only main moved under them, and why the answer does
515 not carry. with its commits unchanged, [a]pprove v<n>
516 is offered at once; with a commit changed, only after
517 [v]iew. [a] files v<n>'s head, and is refused if the
518 change moves again first.
519 a branch no record is on has no state, and is offered
520 the usual prompt.
521 while paging, press v: less opens the diff in $EDITOR.
522 every line you insert there is a note. it is anchored to
523 the file and new-side line it sits on — to the file alone
524 when it sits above the first hunk. range-diff gives no
525 line numbers, so set against an approved version a
526 note keeps its file and line only in the section
527 headed `── v<n>'s diff of these files against main`. each note is then appended to
528 $XDG_STATE_HOME/valley/notes/<branch>.md (default
529 ~/.local/state) and printed after the verdict. notes
530 survive a stack's [b]ase onto main. lines you change
531 or delete instead of inserting are ignored, with a
532 warning.
533 a change whose active version names no branch is
534 refused, since notes and [r]eject act on a branch;
535 approve files its head without one.
536 a stack is reviewed one layer at a time, bottom first.
537 a layer below the top that is approved, as pending
538 lists it, is named in the list and not paged: it asks
539 nothing of you. the top is always paged.
540 its layers are what pending lists under the change: the
541 changes not landed and the branches no record is on
542 that its head contains (valley-go stack). review first
543 lists them, warns of a lower layer that is a draft or
544 withdrawn, since the integrator lands nothing above it,
545 and says how the review goes: [n] through the layers,
546 and approving the top lands them all. a stack whose
547 bottom does not fast-forward from main is then asked,
548 before any layer is paged, under `<top> · stack of <n>
549 · behind main`:
550 [b]ase onto main
551 rebase the whole stack onto origin/main,
552 as rebase does (valley help rebase), then
553 list it again and page the rebased layers,
554 so the heads paged are the heads approved
555 [v]iew diff page the top's whole diff against main
556 [s]kip end the review; nothing done
557 a rebase that is refused or left unfinished says what
558 happened, and then only [v]iew diff and [s]kip are
559 offered.
560 it then shows each layer, headed `change <k> of <n>:
561 <name> on <below>`, as a change alone is shown: set
562 against its own change's approved version, or its log
563 and diff against the layer below it paged, with notes
564 kept under that layer's branch.
565 after each lower layer it asks, naming the layer and
566 its place, as in `two, 2 of 3:`:
567 [n]ext layer go on to the layer above; the usual
568 answer
569 [a]pprove approve that layer at the head shown,
570 as review of it would. this lands it
571 and every layer under it, which the
572 prompt names (`one alone`, `one and
573 two`, `the <k> up to <name>`), and
574 ends the review
575 [v]iew full diff
576 page that layer's log and diff against
577 the layer below it, and ask again
578 [s]top end the review; nothing done
579 after the top it asks, as in `three, 3 of 3:`:
580 [a]pprove all <n>
581 approve the top at the head shown,
582 which lands every layer
583 [v]iew full diff
584 page the top's log and diff against
585 the layer below it, and ask again
586 [r]eject <name>
587 delete the top's branch (confirmed
588 first)
589 [s]top end the review; nothing done
590 only the top is offered [r]eject. when a layer's checks
591 fail, its prompt says approving needs a new head and
592 stops offering [a]pprove, as for any change. a layer
593 that is not ready says so as a change alone does, under
594 its heading and in its prompt. neither it nor any layer
595 above it is offered [a]pprove, since approving one would
596 land it: each prompt above it says `it would bring
597 <name>, change <k> of <n>, which is a draft` (or
598 withdrawn) in its place. a top that is not ready is not
599 offered [r]eject either. every layer's notes are printed
600 at the end.
601EOF
602 help_naming
603 help_runtime
604}
605
606help_approve() {
607 cat <<'EOF'
608usage: valley approve [-v] [--head <sha>] [--build-here] <change>
609
610 approve [-v] [--head <sha>] [--build-here] <change>
611 do what review's [a]pprove does for the change, without
612 paging it: the same checks, the same refusals, the same
613 leased request write and the same output. exits non-zero
614 when it refuses. a change with a record is approved at
615 exactly one head, and its request is filed as
616 refs/the-valley/integration-requests/main/c-<change id>,
617 at that head:
618 --head SHA approve exactly this head, which must be
619 one of the record's version heads,
620 active or not. a front end passes the
621 head it showed, so a record that moves
622 after review cannot change what lands.
623 without --head, approve shows the active version's head
624 and title and asks to confirm them, on a terminal; off
625 one it refuses. a branch no record is on is approved at
626 its tip on origin, which --head must name if it is
627 given (review's [a]pprove files the head it showed, and
628 refuses once the branch on origin has moved off it), under
629 the branch's request name: the branch with
630 each / replaced by -. a branch whose request name would
631 be c-<change id> is refused, since that name is the
632 change's.
633 approve first reads the evidence origin holds for that
634 head's tree, refs/the-valley/attestations/<tree>/*, byte
635 for byte. it judges each required nix check by the note
636 the integrator judges it by: the first, in ref order,
637 that attest verify accepts under the known-signers file
638 the host publishes. it reuses that note when it is pure
639 evidence for the check's name and flake attribute and
640 says it passed. VALLEY_KNOWN_SIGNERS, when set, must
641 accept it too: it can narrow what is reused, never widen
642 it. a required nix check whose judged note records a
643 failure refuses the approval, since the integrator
644 judges the check by that note. a command check is never
645 reused. a listing or a fetch of
646 origin's evidence that fails is refused, and nothing is
647 run.
648 a required nix check that origin holds no evidence for
649 does not stop the approval. approve files the request at
650 once, with the evidence origin holds, builds nothing,
651 and publishes no evidence for that check. required
652 command checks still run first, and a missing signing
653 key, a failed check, or a refused push still fails the
654 approval. approve says the approval is recorded and
655 how many checks it waits for. the integrator keeps the
656 request and considers it again when evidence is
657 published. landing still requires a clean apply and
658 acceptable evidence for every required check. an
659 enabled worker that serves the project attempts the nix
660 checks of a ready change's active version, but cannot
661 add checks to its own existing evidence ref for the
662 same tree, and a failed build publishes nothing. waiting
663 does not ensure the evidence will be published. no
664 worker builds a branch no record is on, or a version
665 that is not the active one, and approve says so and
666 offers --build-here. the
667 evidence of an approval that ran a command check
668 occupies this signer's ref for the tree, so use
669 --build-here on the initial approval.
670 --build-here build those nix checks on this
671 machine instead, and publish their
672 evidence with the request.
673 approve runs every command check, and every nix check
674 it builds, over a throwaway worktree of that head, signs
675 each result as an attestation, and publishes the new
676 evidence and the request ref to origin in ONE atomic
677 push. when every required check is reused, nothing
678 runs, no signing key is needed, and the push carries
679 the request alone.
680 this files the request; it does not wait for
681 integration or update your local checkout. use status to
682 read the result. the policy comes from the target's tip
683 and the owning valley's, as checks describes (valley help
684 checks), so your checkout can be on any branch. a change
685 the policy requires no check of is filed too, as a
686 request with no evidence, and says so. approving a
687 change already requested is how it is filed again: at a
688 head rebased onto a moved main it replaces the request
689 ref under a lease and names the head it replaced; at the
690 same head it leaves the ref alone and publishes only the
691 new evidence. origin already holding this signer's
692 evidence for that tree, without a check that still has
693 to run, is refused before anything runs: approve
694 publishes a signer's evidence for a tree once, as a
695 ref of the new notes alone, and origin keeps every
696 note the ref holds (bd-7b7d58f). every
697 write of the request ref
698 is leased, filing included, so an approval that lost a
699 race is refused rather than clobbering the one that won.
700 needs the attest helper whenever a check is required,
701 and VALLEY_ATTEST_KEY, the ed25519 key this host signs
702 with, whenever a check has to run here;
703 VALLEY_ATTEST_NAME is the name it signs under,
704 defaulting to this host's. approve never writes the
705 protected ref: the integrator does, having judged the
706 request.
707 approve refuses, before any check runs, a head that does
708 not fast-forward from main and would bring a version of
709 another change that has not landed: a layer above the
710 bottom of a stale stack. the refusal names the command
711 that rebases the stack, valley rebase <change>. this is
712 the project's choice, not a rule the integrator needs:
713 approved as it is, the stack would land as one commit
714 recorded against this request alone, so the changes
715 under it would have no landing record of their own, and
716 the checks would run over a head that has to be rebased
717 anyway. a stale head with no change under it, such as
718 the bottom layer of a stack or a change alone, is
719 approved as it is, and the integrator merges it onto
720 main.
721 approve ends in one verdict line: the change, whether
722 it was approved, and what happens next, with one
723 indented line under it only when you must act:
724 ✓ nqyw v3 approved · checks passed · landing on main
725 ◐ nqyw v3 approved · lands when 3 checks pass (1/4 passed)
726 ◇ nqyw v3 approved · waiting for 2 checks (no worker building)
727 run: valley approve --build-here nqyw
728 ⊘ nqyw v3 not approved · change is a draft
729 run: valley ready --change <id> <branch>
730 a refusal goes to stderr. checks built here show one
731 line of progress, and a failed check's log. the glyphs
732 are in colour on a terminal unless NO_COLOR is set.
733 -v, --verbose also print what approve read and
734 published: the checks it reuses and who
735 signed them, the tree's digest, the
736 evidence and request refs, and the
737 checks' own output and timings.
738 approve times each required check it runs, and
739 appends one JSON line per check to the timing log,
740 $XDG_STATE_HOME/valley/timings.jsonl (default
741 ~/.local/state/valley/timings.jsonl). the log stays on
742 this machine and is not evidence; a log that cannot be
743 written is a warning, and approving goes on.
744EOF
745 help_naming
746 help_runtime
747}
748
749help_rebase() {
750 cat <<'EOF'
751usage: valley rebase [--known-signers <file>] [--integrator-name <name>] <change>
752
753 rebase [--known-signers <file>] [--integrator-name <name>] <change>
754 rebase the change's whole stack onto origin/main, as
755 review's [b]ase onto main does: the layers valley-go stack
756 lists under the change, and the change itself. in a
757 throwaway worktree, bottom first, each layer's own commits
758 go onto the rebased layer below it, and the bottom's onto
759 origin/main, so each layer keeps its own diff. commits
760 under the bottom that a lower change landed through the
761 integrator drop out, since main holds them; that landing
762 is read as changes reads it, with the signers its two
763 flags, VALLEY_KNOWN_SIGNERS and VALLEY_INTEGRATOR_SIGNER,
764 or the host's publication give. one atomic
765 push then moves every layer's branch, each leased on the
766 tip read: every branch moves, or none does. last, bottom
767 first, each change gains its rebased head as a new
768 version, as valley.principal names, the way ready
769 --if-active does: only while the change is still ready
770 at the head the rebase began with.
771 it refuses, with nothing changed, a stack holding a
772 change that is not ready, records no branch, or whose
773 branch is missing on origin or is not at its recorded
774 head; a plain branch that is the branch of a change not
775 in the stack; two layers on one branch; a merge among the
776 commits to be rebased, or a version head of a change
777 that is not ready or not in the stack, since a rebase
778 gives each commit a new id; and a stack holding a change
779 while git config valley.principal names no one. a
780 conflict in any layer pushes nothing, records nothing
781 and names the layer.
782 a change alone prints its new head. a
783 stack prints a manifest: one line for each layer, with
784 its old and new head, whether its branch was pushed, and
785 whether a version was added. then, for each change left
786 unfinished, the valley ready command that finishes it,
787 and the exit status is non-zero. rebasing again refuses
788 a change whose branch holds a head no version records,
789 and prints the same command. last, it names each ready
790 change or branch outside the stack that is left on an
791 old head of a layer, such as a second stack on a lower
792 layer, with the rebase that moves it; it does not move
793 it. rebase does not re-review the result. a stack that
794 already fast-forwards from main is left as it is.
795EOF
796 help_naming
797 help_runtime
798}
799
800help_status() {
801 cat <<'EOF'
802usage: valley status [--json] [-v] [--known-signers <file>] [--integrator-name <name>] <change>
803
804 status [--json] [-v] [--known-signers <file>] [--integrator-name <name>]
805 <change>
806 read the request and the integrator's last decision from
807 origin. distinguish waiting, a decision that needs
808 attention, and a change integrated into origin/main.
809 a change with a record is read at its active version's
810 head, under c-<change id>, and the status says the
811 version, its title, the owner, and how far the version
812 has landed, as changes reads it. a change that landed
813 as an older version is read at that version's head. a refusal for a record
814 that is not ready, or for a merge in the change's
815 commits, is a state of its own.
816 after integration, show how to update the local checkout.
817 fetches objects without moving local branches or files;
818 no checks run and no request is filed.
819 --json print the status as one JSON object,
820 valley-status/v1, for front ends to read
821 (docs/architecture.md), with the knots
822 in the plan graph that link the change.
823 an error prints no object: it goes to
824 stderr and the exit status is non-zero.
825 -v with --json, warn on stderr when the plan
826 graph is missing or unreadable
827 --known-signers FILE, --integrator-name NAME
828 what a transfer statement is verified
829 with, as changes reads them
830 needs the valley-go helper.
831EOF
832 help_naming
833 help_runtime
834}
835
836help_ready() {
837 cat <<'EOF'
838usage: valley ready [--head <sha>] [--change <id>] [--if-active <sha>] [--stamp] [<branch>]
839
840 ready [--head <sha>] [--change <id>] [--if-active <sha>] [--stamp] [<branch>]
841 mark a head of the branch ready, as a new version of its
842 change, in the change's record on origin:
843 refs/the-valley/changes/main/<change id>. the branch
844 defaults to the current one. the head is --head, or else
845 origin/<branch>, and it must be on origin already. the
846 first ready of a change makes v1; each later one adds
847 the next version, at a head other than the active
848 version's. a draft or a withdrawn change comes back this
849 way: at the active version's head, it is ready again at
850 that version, and at another head it gains the next
851 version. prints the handle and version, e.g.
852 `app nxvp v2 ready`.
853 the change id is --change, else the head commit's jj
854 change-id header, else a Change-Id: trailer in its
855 message, else a new one, which is printed. a header and
856 a trailer that disagree are refused. so is a change
857 whose commits from its merge base with origin/main hold
858 a merge, or that has more than one merge base.
859 --if-active SHA
860 add the version only while the change
861 is ready at an active version whose head
862 is SHA. the record ref is leased on the
863 record read, so nothing comes between
864 that check and the write. rebase readies
865 the head it rebased this way.
866 --stamp amend the head of your local branch to
867 carry the id as a Change-Id: trailer and
868 push the branch, leased, before marking it
869 ready. it only starts a new change: it
870 is refused for a change that has a
871 record on origin already, and for a head
872 already on origin.
873 the record names the principal your key pushes as, read
874 from git config valley.principal; the host refuses one
875 naming anyone else. the record ref is pushed leased on
876 the value read. a new change is owned by the principal
877 that readies it, and a later version may come from its
878 owner, the operator, or a restack holder while the
879 change is ready.
880 a record never makes anything land, and approve is
881 still the only way to main. the integrator reads
882 records only to refuse: it lands no request that would
883 bring a version of a change that is not ready.
884 needs the valley-go helper.
885EOF
886 help_naming
887 help_runtime
888}
889
890help_unready() {
891 cat <<'EOF'
892usage: valley unready <change>
893
894 unready <change>
895 make a ready change a draft in its record on origin, as
896 its owner or the operator. a draft is a pause: it voids
897 nothing, and approvals of its active version stand when
898 it is readied again. ready brings it back. prints e.g.
899 `app nxvp v2 draft`. needs the valley-go helper.
900EOF
901 help_unready_withdraw_requests
902 help_naming
903 help_runtime
904}
905
906help_withdraw() {
907 cat <<'EOF'
908usage: valley withdraw <change>
909
910 withdraw <change>
911 mark a ready change or a draft withdrawn in its record
912 on origin, as its owner or the operator. withdrawing
913 voids everything outstanding on the change: its
914 integration requests, and the approvals and reviews of
915 every version, so a change brought back needs fresh
916 approvals. ready brings it back, at the same version
917 or a new one. prints e.g. `app nxvp v2 withdrawn`.
918 needs the valley-go helper.
919EOF
920 help_unready_withdraw_requests
921 help_naming
922 help_runtime
923}
924
925help_knot() {
926 cat <<'EOF'
927usage: valley knot <verb> [args]
928
929 knot <verb> [args]
930 read and write the project's plan graph: knots, at
931 refs/the-valley/knots on origin. a knot is an outcome,
932 a bug, an idea or a question; `knot schema` prints the
933 types, their statuses, active and terminal, the fields
934 and the edges. a write is one commit on the ref, made
935 without a checkout and pushed with a lease on the tip
936 it was made on; no review is involved. a write that
937 loses the lease is made again on the new tip, up to 5
938 tries. every verb takes --project NAME, another
939 project on the same host, and --json. exit status 3
940 is a conflict. needs the valley-go helper, and
941 git config valley.principal for every write.
942 new <type> <title> [--parent ID] [--blocked-by ID]...
943 [--owner P] [--target PROJECT] [--body -]
944 make a knot. its id is the type's prefix
945 and 7 hex digits of the sha-256 of the
946 title's slug.
947 show <id> [--at COMMIT] [--json]
948 its fields, body and comments, each
949 comment with its id, and the edges both
950 ways. --at shows the knot at a commit of
951 the graph; claim age uses the current
952 clock, and other projects' knots use
953 their current tips.
954 log <id> [--json]
955 every commit of the graph that touched
956 the knot or its comments, newest first:
957 time, committer, operation, and the
958 files it added, changed or deleted
959 list [--type T] [--status S] [--owner P] [--ready]
960 every knot. --status takes a status,
961 active or terminal. --ready lists the
962 active, unclaimed knots whose blockers
963 are all terminal.
964 set <id> <field>=<value>... [--if <field>=<value>]...
965 [--force]
966 change status, title, source, owner,
967 target or graduated_into. a field that
968 another write changed meanwhile is a
969 conflict unless --force. --if requires
970 a field to hold a value first.
971 link <id> (--blocked-by ID | --parent ID | --change X)...
972 unlink <id> (--blocked-by ID | --parent ID | --change X)...
973 add or drop an edge. a change is
974 valley:<project>/<change id> or a github
975 pull request url. outcomes and bugs link
976 the changes that do the work, and a
977 question links the change that records
978 its answer in the source.
979 edit <id> --body -
980 replace the body with stdin
981 comment <id> (-m TEXT | --body -) [--edit COMMENT-ID]
982 add a comment. --edit replaces the body
983 of the comment with that id; its author
984 and file stay, and it records who edited
985 it and when. only the comment's author
986 or a holder of the approve grant may
987 edit it. a comment that another edit
988 changed meanwhile is a conflict.
989 comments are never deleted; log and
990 show --at read every earlier text.
991 claim <id> --run RUN
992 claim an active outcome or bug for a
993 run; an open outcome becomes
994 in-progress. a knot claimed already is
995 a conflict.
996 unclaim <id>
997 release the claim. a claim that
998 changes before the release lands is
999 a conflict.
1000 schema [--json]
1001 print the model
1002EOF
1003 help_runtime
1004}
1005
1006help_plan() {
1007 cat <<'EOF'
1008usage: valley plan [--project NAME | --all] [--owner P] [--json] [--known-signers <file>] [--integrator-name <name>]
1009
1010 plan [--project NAME | --all] [--owner P] [--json]
1011 [--known-signers <file>] [--integrator-name <name>]
1012 show the project's plan graph as a tree, to see where
1013 things stand. the roots are the outcomes with no
1014 parent, the milestones, each with its progress: its
1015 descendants that are terminal and not abandoned, out
1016 of those not abandoned, as a count and a bar. under
1017 each come its children, indented, in the order they
1018 were created, then by title. each knot has a glyph for
1019 its state (○ ready, ◐ in progress, ⊘ blocked, ◇
1020 active, ✓ done, ✗ abandoned), its id and title, and,
1021 while active, its claim and the claim's age (marked
1022 stale past a day), its owner, and what blocks it. a
1023 blocker that ended abandoned, discarded, superseded or
1024 dropped clears the knot, and is marked with how it
1025 ended. a reference to another project's knot,
1026 <project>:<id>, is marked dangling when that
1027 project's graph cannot be read or holds no such knot.
1028 a root whose descendants are all terminal is one
1029 line. three sections follow. waiting on you: the
1030 active outcomes and bugs and the open questions the
1031 operator owns, then the changes ready for
1032 approval, as pending lists them. in flight: the
1033 claimed knots, oldest claim first. open residuals:
1034 the open bugs, under their parent. the operator is
1035 git config valley.principal, or --owner. lines fit
1036 the terminal as pending's do; glyphs are coloured on
1037 a terminal unless NO_COLOR is set.
1038 --project NAME another project on the same host
1039 --all every project the serving host
1040 publishes, each under its name, as
1041 pending --all reads them. a project
1042 that cannot be read is reported in
1043 its own section
1044 --owner P read P as the operator
1045 --json print valley-plan/v1: every knot with
1046 what the graph derives of it, and the
1047 three sections (docs/architecture.md)
1048 --known-signers FILE, --integrator-name NAME
1049 what a transfer statement is verified
1050 with, for the changes ready for
1051 approval, as changes reads them
1052 needs the valley-go helper.
1053EOF
1054 help_runtime
1055}
1056
1057help_checks() {
1058 cat <<'EOF'
1059usage: valley checks [--schema FILE] [--instance DIR] [--project DIR] [--names [--cost COST] | --json] [<base> [<head>]]
1060
1061 checks [<base> [<head>]]
1062 print the check names the composed verification policy
1063 (dcr-f41f718) requires of the change between two
1064 commits, which class made each one required, and the
1065 change's carry mode: how far an approval of it carries
1066 across a rebase, the strictest of exact, same-class and
1067 same-paths among the classes it matched. It prints: no
1068 check is run, nothing is gated, nothing is written.
1069 base defaults to the merge base with main, head to HEAD.
1070 by default both layers come from the target's tip
1071 (origin/main), never from your checkout: the project's
1072 own layer is policy/project there, and the owning valley
1073 is named one line at policy/valley there, fetched and
1074 read at policy/instance in that repository's integrated
1075 tip. a valley's own config repository carries
1076 policy/instance and uses it. a target carrying no
1077 policy/project is derived under the floor alone; a floor
1078 that is not there is refused. this is what the
1079 integrator reads, so the answer is the same from any
1080 branch, however stale. an option overrides each layer,
1081 which is the only way to derive against a layer that
1082 does not govern — the worked example under
1083 examples/policy/, say:
1084 --schema FILE default $VALLEY_VERIFICATION_SCHEMA
1085 --instance DIR default the owning valley's floor
1086 --project DIR default policy/project at the target
1087 naming a layer stops this reading the source it
1088 replaced. the schema is the shape a policy is written
1089 in rather than a layer, so it ships with this tool: the
1090 package sets VALLEY_VERIFICATION_SCHEMA to its own copy.
1091 with that unset, as when this script runs straight from
1092 a the-valley checkout, it is schema/verification.cue in
1093 the checkout.
1094 a class's globs match bytes, whatever your locale
1095 is: `?` is one byte, so `?.md` does not match
1096 é.md, whose é is two.
1097 after the report, two lines group the required checks
1098 by the cost the policy declares, `quick` or `slow`. a
1099 slow check takes minutes or needs special hardware. the
1100 cost changes nothing required: approving runs every
1101 required check whatever its cost, and the integrator
1102 requires evidence for every one.
1103 --names print only the required check names,
1104 one per line
1105 --cost COST with --names, only the quick or
1106 the slow ones, e.g.
1107 `valley checks --names --cost slow`
1108 --json print the valley-checks/v1 document
1109 instead of the report
1110EOF
1111 help_runtime
1112}
1113
1114help_tail() {
1115 cat <<'EOF'
1116usage: valley tail [subject]
1117
1118 tail [subject] watch bus events scroll by (default subject: valley.>);
1119 the server comes from the nats CLI's own config
1120 (NATS_URL or a nats context; default localhost)
1121EOF
1122 help_runtime
1123}
1124
1125help_replay() {
1126 cat <<'EOF'
1127usage: valley replay [dir]
1128
1129 replay [dir] publish one ref-updated event per current ref of the
1130 repo at dir (default: .) — rebuilds the stream's
1131 projection, e.g. after nats stream purge valley
1132EOF
1133 help_runtime
1134}
1135
1136help_telemetry() {
1137 cat <<'EOF'
1138usage: valley telemetry [--remote <remote>] [--json] <operation> [flags]
1139
1140 sources every source the host declares, and its state:
1141 disabled, unavailable, failed, stale, active or
1142 idle, with its units, its records and how far its
1143 journal reaches
1144 snapshot sources, with each producer's exported state and
1145 its open and latest runs
1146 read [--source <name>] [--since <cursor>] [--limit <n>] [--logs]
1147 records after the cursor (default: the newest
1148 --limit, 200, at most 1000); a source's systemd
1149 lifecycle from the journal; with --logs, its own
1150 output and the tail of its build logs, marked
1151 untrusted
1152 follow [--source <name>] [--since <cursor>] [--seconds <n>] [--logs]
1153 records as they are stored, and with --logs build
1154 output as it is written, for --seconds (default
1155 60, at most 300); ends with a cursor to resume from
1156 flush send this workstation's spooled records now
1157
1158Reading needs a key whose principal holds the host's observe grant. The
1159remote is the checkout's valley.telemetry.remote, else origin, or the one
1160--remote names (a remote, an ssh URL, or user@host:path); its URL is read
1161and never run. --json prints the valley-telemetry/v1 answer lines as they
1162come. A gap, a cut-short answer or an error is said; an answer that does
1163not end exits 1.
1164
1165With `git config valley.telemetry true`, every valley command records a
1166command record: its verb (and knot's or telemetry's subverb), the names of
1167the flags it was given, its project, its exit status and its wall time,
1168and for pending and status the milliseconds and processes each phase took.
1169It never records an argument's value, a path, a title or a body. Every
1170approval attempt, from approve or from review, also records its steps and
1171its checks' progress. Records go to an owner-only spool for the
1172destination the checkout's telemetry remote names, under
1173$XDG_STATE_HOME/valley/telemetry/spools. A background flusher sends each
1174spool to its own destination, with the report grant; flush does the same
1175now, and --remote limits it to that remote's spool. Telemetry never fails
1176or holds up a command, and changes nothing it prints.
1177EOF
1178}
1179
1180help_self_update() {
1181 if command -v valley-go > /dev/null 2>&1; then
1182 valley-go self-update --help
1183 printf '\n'
1184 else
1185 cat <<'EOF'
1186usage: valley self-update [-v] [--retry | --rollback | --pin | --unpin]
1187 [--repo <url>] [--branch <name>]
1188
1189EOF
1190 fi
1191 cat <<'EOF'
1192 self-update [-v] [--retry | --rollback | --pin | --unpin]
1193 [--repo <url>] [--branch <name>]
1194 install the tip of a branch of the-valley into your
1195 default nix profile, in place of its valley element,
1196 once that exact commit builds and passes a smoke test.
1197 a commit that fails is skipped until the branch moves,
1198 or until --retry. it is off until --repo or
1199 git config valley.selfUpdate.repo names the
1200 repository; the branch is valley.selfUpdate.branch,
1201 or main. --rollback reinstalls the previous build, and
1202 --pin and --unpin freeze and release the install.
1203 `valley-go self-update --help` gives every step. needs
1204 the valley-go helper and nix.
1205
1206 --version print this valley's version: the package's version and
1207 the commit it was built from, e.g. 0.1.0-97db597, with
1208 -dirty after it for a tree with uncommitted changes and
1209 -unknown in its place when nix knew no commit. run
1210 straight from a checkout, it says it is unstamped.
1211EOF
1212 help_runtime
1213}
1214
1215fetch_origin() {
1216 git fetch --prune --quiet origin
1217}
1218
1219# pending is valley-go's (status/pending.go). The fetch first keeps this
1220# checkout's remote-tracking branches current, as pending always has.
1221cmd_pending() {
1222 command -v valley-go > /dev/null 2>&1 \
1223 || die "pending needs the valley-go helper; nix run .#valley bundles it"
1224 fetch_origin
1225 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" \
1226 exec valley-go pending "$@"
1227}
1228
1229# tel_command <status>: the command record of a verb this script runs
1230# itself, handed to valley-go as the script exits, once. valley-go decides
1231# whether telemetry is on; the verbs this script execs it for it records
1232# itself.
1233TEL_ARGS=()
1234tel_command() {
1235 [ ${#TEL_ARGS[@]} -gt 0 ] || return 0
1236 local -a args=("${TEL_ARGS[@]}")
1237 TEL_ARGS=()
1238 valley-go telemetry command --since "$TEL_T0" --version "$VALLEY_STAMP" --status "$1" \
1239 -- "${args[@]}" < /dev/null > /dev/null 2>&1 || true
1240}
1241
1242# status, ready, unready and withdraw are a Go program, valley-go
1243# (status/). status reads a change's request and outcome from origin,
1244# because what front ends read from it is a JSON contract, and because the
1245# read is subtle enough to want a real parser: an outcome record it does
1246# not recognise must read as unknown, never as success. It writes nothing
1247# and moves no local branch. ready, unready and withdraw write a change's
1248# record, in the one format the push hook reads it in (change/). knot
1249# reads and writes the plan graph at refs/the-valley/knots, in the one
1250# form the push hook validates (knot/), and plan shows that graph as a
1251# view.
1252cmd_go() {
1253 command -v valley-go > /dev/null 2>&1 \
1254 || die "$1 needs the valley-go helper; nix run .#valley bundles it"
1255 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" exec valley-go "$@"
1256}
1257
1258# review is valley-go's (status/review.go). With no change it walks what
1259# needs the operator, reviewing each change in the same process
1260# (status/walk.go).
1261cmd_review() {
1262 command -v valley-go > /dev/null 2>&1 \
1263 || die "review needs the valley-go helper; nix run .#valley bundles it"
1264 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" \
1265 exec valley-go review "$@"
1266}
1267
1268# approve is review's [a]pprove without the pager, for a front end that
1269# has shown the change its own way: valley-go approve (status/approve.go),
1270# the code the key runs, so the verb and the key cannot drift apart. It
1271# resolves the change before the fetch, as review does.
1272cmd_approve() {
1273 command -v valley-go > /dev/null 2>&1 \
1274 || die "approve needs the valley-go helper; nix run .#valley bundles it"
1275 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" \
1276 exec valley-go approve "$@"
1277}
1278
1279# rebase is review's [b]ase onto main without the pager. It runs the code
1280# its key runs, valley-go rebase, and reads a change's name as review
1281# reads it. The two flags that say what a transfer
1282# statement is verified with are valley-go's, and pass through to it
1283# untouched.
1284cmd_rebase() {
1285 local usage="usage: valley rebase [--known-signers <file>] [--integrator-name <name>] <change>"
1286 local name="" verify=()
1287 while [ $# -gt 0 ]; do
1288 case "$1" in
1289 --known-signers | --integrator-name)
1290 [ $# -ge 2 ] || die "$usage"
1291 verify+=("$1" "$2")
1292 shift 2
1293 ;;
1294 --known-signers=* | --integrator-name=*)
1295 verify+=("$1")
1296 shift
1297 ;;
1298 -*) die "$usage" ;;
1299 *)
1300 [ -z "$name" ] || die "$usage"
1301 name="$1"
1302 shift
1303 ;;
1304 esac
1305 done
1306 [ -n "$name" ] || die "$usage"
1307 command -v valley-go > /dev/null 2>&1 \
1308 || die "review, approve and rebase read the change's record with the valley-go helper; nix run .#valley bundles it"
1309 fetch_origin
1310 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" \
1311 exec valley-go rebase "${verify[@]}" "$name"
1312}
1313
1314# tail and replay are thin wrappers over the nats CLI — anything they do,
1315# plain nats and git can do. They are the only verbs needing more than git
1316# and coreutils.
1317need_nats() {
1318 command -v nats >/dev/null 2>&1 \
1319 || die "this verb needs the nats CLI (natscli); nix run .#valley bundles it"
1320}
1321
1322cmd_tail() {
1323 [ $# -le 1 ] || die "usage: valley tail [subject]"
1324 need_nats
1325 exec nats sub "${1:-valley.>}"
1326}
1327
1328# One ref-updated event per existing ref, from git for-each-ref alone. A
1329# ref's prior value is not derivable from the repository, so `old` is the
1330# all-zero id — the same payload a push creating the ref would produce.
1331# The payload construction mirrors the host module's publisher hook
1332# (nix/valley-host.nix); change one only with the other.
1333cmd_replay() {
1334 [ $# -le 1 ] || die "usage: valley replay [repo-dir]"
1335 need_nats
1336 local dir="${1:-.}" repo sha ref event count=0
1337 git -C "$dir" rev-parse --git-dir >/dev/null 2>&1 \
1338 || die "not a git repository: $dir"
1339 if [ "$(git -C "$dir" rev-parse --is-bare-repository)" = true ]; then
1340 repo="$(basename "$(git -C "$dir" rev-parse --absolute-git-dir)" .git)"
1341 else
1342 repo="$(basename "$(git -C "$dir" rev-parse --show-toplevel)")"
1343 fi
1344 while read -r sha ref; do
1345 # " is the only JSON-significant character a refname can contain (git
1346 # forbids \ and control characters); names and object ids are safe.
1347 event="$(printf '{"event":"ref-updated","repo":"%s","ref":"%s","old":"%s","new":"%s"}' \
1348 "$repo" "${ref//\"/\\\"}" "${sha//?/0}" "$sha")"
1349 nats pub "valley.git.$repo.ref-updated" "$event" >/dev/null
1350 count=$((count + 1))
1351 done < <(git -C "$dir" for-each-ref --format='%(objectname) %(refname)')
1352 echo "replayed $count refs of $repo onto the bus"
1353}
1354
1355# ----------------------------------------------------------------------
1356# checks — the checks the verification policy requires of a change, and
1357# the classes requiring each. The verb is valley-go's (status/checks.go):
1358# it reads the policy's layers and derives with the Go deriver (derive/).
1359cmd_checks() {
1360 command -v valley-go > /dev/null 2>&1 \
1361 || die "checks needs the valley-go helper; nix run .#valley bundles it"
1362 VALLEY_TELEMETRY_SINCE="$TEL_T0" VALLEY_TELEMETRY_VERSION="$VALLEY_STAMP" \
1363 exec valley-go checks "$@"
1364}
1365
1366# self-update installs the tip of a branch of the-valley into the user's
1367# nix profile (status/selfupdate.go). It is told this valley's stamp, which
1368# says what is installed until it has installed something itself.
1369cmd_self_update() {
1370 export VALLEY_VERSION="$VALLEY_STAMP"
1371 cmd_go self-update "$@"
1372}
1373
1374cmd_version() {
1375 printf 'valley %s\n' "${VALLEY_STAMP:-unstamped (run from a checkout, not built by nix)}"
1376}
1377
1378cmd_help() {
1379 [ $# -le 1 ] || die "usage: valley help [<verb>]"
1380 local out
1381 case "${1:-}" in
1382 '' | help | -h | --help) out="$(usage)" ;;
1383 pending) out="$(help_pending)" ;;
1384 changes) out="$(help_changes)" ;;
1385 review) out="$(help_review)" ;;
1386 approve) out="$(help_approve)" ;;
1387 rebase) out="$(help_rebase)" ;;
1388 status) out="$(help_status)" ;;
1389 ready) out="$(help_ready)" ;;
1390 unready) out="$(help_unready)" ;;
1391 withdraw) out="$(help_withdraw)" ;;
1392 knot) out="$(help_knot)" ;;
1393 plan) out="$(help_plan)" ;;
1394 checks) out="$(help_checks)" ;;
1395 tail) out="$(help_tail)" ;;
1396 replay) out="$(help_replay)" ;;
1397 self-update) out="$(help_self_update)" ;;
1398 telemetry) out="$(help_telemetry)" ;;
1399 *) die "unknown help topic: $1 (try 'valley help')" ;;
1400 esac
1401 printf '%s\n' "$out" 2> /dev/null || true
1402}
1403
1404main() {
1405 local verb="${1:-help}"
1406 if [ $# -gt 0 ]; then shift; fi
1407 # The verb set is mirrored in completions/ (valley.bash, _valley) —
1408 # update both when it changes.
1409 case "$verb" in
1410 pending | changes | review | approve | rebase | status | ready | unready | withdraw | knot | plan | checks | tail | replay | self-update | telemetry)
1411 if [ $# -eq 1 ] && { [ "$1" = -h ] || [ "$1" = --help ]; }; then
1412 cmd_help "$verb"
1413 return
1414 fi
1415 ;;
1416 esac
1417 case "$verb" in
1418 checks | tail | replay)
1419 TEL_ARGS=("$verb" "$@")
1420 trap 'tel_command $?' EXIT
1421 ;;
1422 esac
1423 case "$verb" in
1424 pending) cmd_pending "$@" ;;
1425 review) cmd_review "$@" ;;
1426 approve) cmd_approve "$@" ;;
1427 rebase) cmd_rebase "$@" ;;
1428 status | ready | unready | withdraw | changes | knot | plan) cmd_go "$verb" "$@" ;;
1429 checks) cmd_checks "$@" ;;
1430 tail) cmd_tail "$@" ;;
1431 replay) cmd_replay "$@" ;;
1432 self-update) cmd_self_update "$@" ;;
1433 telemetry) cmd_go telemetry "$@" ;;
1434 --version) cmd_version ;;
1435 help | -h | --help) cmd_help "$@" ;;
1436 *)
1437 printf 'valley: unknown verb: %s\n\n' "$verb" >&2
1438 usage >&2
1439 exit 1
1440 ;;
1441 esac
1442}
1443
1444main "$@"