@krysoworks/kryso 0.0.0-stage → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -2
  3. package/bin/kryso +31 -0
  4. package/bin/ship-it-status +14 -0
  5. package/bin/ship-ledger +14 -0
  6. package/bin/ship-loop +14 -0
  7. package/bin/ship-pass +14 -0
  8. package/bin/warden +14 -0
  9. package/dist/answer.d.ts +38 -0
  10. package/dist/answer.js +48 -0
  11. package/dist/bytes.d.ts +5 -0
  12. package/dist/bytes.js +35 -0
  13. package/dist/cleanup.d.ts +1 -0
  14. package/dist/cleanup.js +629 -0
  15. package/dist/commands.d.ts +48 -0
  16. package/dist/commands.js +293 -0
  17. package/dist/completions.d.ts +24 -0
  18. package/dist/completions.js +239 -0
  19. package/dist/daemon.d.ts +15 -0
  20. package/dist/daemon.js +23 -0
  21. package/dist/diagnose.d.ts +47 -0
  22. package/dist/diagnose.js +314 -0
  23. package/dist/doctor.d.ts +1 -0
  24. package/dist/doctor.js +241 -0
  25. package/dist/env.d.ts +9 -0
  26. package/dist/env.js +17 -0
  27. package/dist/evidence.d.ts +39 -0
  28. package/dist/evidence.js +327 -0
  29. package/dist/home.d.ts +3 -0
  30. package/dist/home.js +27 -0
  31. package/dist/install.d.ts +59 -0
  32. package/dist/install.js +137 -0
  33. package/dist/isolate.d.ts +28 -0
  34. package/dist/isolate.js +402 -0
  35. package/dist/leftovers.d.ts +5 -0
  36. package/dist/leftovers.js +156 -0
  37. package/dist/machine.d.ts +6 -0
  38. package/dist/machine.js +185 -0
  39. package/dist/palette.d.ts +147 -0
  40. package/dist/palette.js +167 -0
  41. package/dist/plan.d.ts +1 -0
  42. package/dist/plan.js +133 -0
  43. package/dist/proc.d.ts +23 -0
  44. package/dist/proc.js +23 -0
  45. package/dist/read.d.ts +1 -0
  46. package/dist/read.js +297 -0
  47. package/dist/readiness.d.ts +5 -0
  48. package/dist/readiness.js +64 -0
  49. package/dist/remote.d.ts +6 -0
  50. package/dist/remote.js +85 -0
  51. package/dist/self-update.d.ts +1 -0
  52. package/dist/self-update.js +224 -0
  53. package/dist/semver.d.ts +7 -0
  54. package/dist/semver.js +42 -0
  55. package/dist/style.d.ts +71 -0
  56. package/dist/style.js +187 -0
  57. package/dist/update.d.ts +47 -0
  58. package/dist/update.js +190 -0
  59. package/dist/work.d.ts +25 -0
  60. package/dist/work.js +449 -0
  61. package/dist/workflows.d.ts +4 -0
  62. package/dist/workflows.js +73 -0
  63. package/docker/entrypoint.sh +44 -0
  64. package/docker/runner.Dockerfile +39 -0
  65. package/package.json +65 -4
  66. package/scripts/install-skills.sh +607 -0
  67. package/skills/code-review/SKILL.md +231 -0
  68. package/skills/kryso/SKILL.md +107 -0
  69. package/skills/kryso/golden/help.rounded.ansi +23 -0
  70. package/skills/kryso/golden/help.square.ansi +23 -0
  71. package/skills/kryso/golden/help.txt +23 -0
  72. package/skills/kryso/golden/table-narrow.json +11 -0
  73. package/skills/kryso/golden/table-narrow.rounded.ansi +4 -0
  74. package/skills/kryso/golden/table-narrow.square.ansi +4 -0
  75. package/skills/kryso/golden/table.ansi +5 -0
  76. package/skills/kryso/golden/table.json +11 -0
  77. package/skills/kryso/ledger.sh +2146 -0
  78. package/skills/kryso/palette.json +57 -0
  79. package/skills/kryso/reference/resuming.md +30 -0
  80. package/skills/kryso/reference/routing.md +23 -0
  81. package/skills/kryso/reference/stage-1-claim.md +79 -0
  82. package/skills/kryso/reference/stage-2-build.md +133 -0
  83. package/skills/kryso/reference/stage-3-prove.md +51 -0
  84. package/skills/kryso/reference/stage-4-pr.md +76 -0
  85. package/skills/kryso/reference/stage-5-reconcile.md +81 -0
  86. package/skills/kryso/reference/stage-6-merge-or-park.md +73 -0
  87. package/skills/kryso/reference/stage-7-close-out.md +62 -0
  88. package/skills/kryso/reference/terminal.md +7 -0
  89. package/skills/kryso/ship-it-status.sh +1503 -0
  90. package/skills/kryso/ui.py +274 -0
  91. package/skills/kryso/ui.sh +609 -0
  92. package/skills/kryso-build/SKILL.md +168 -0
  93. package/skills/kryso-shift/SKILL.md +167 -0
  94. package/skills/kryso-shift/archive.py +2784 -0
  95. package/skills/kryso-shift/archive_checker.py +462 -0
  96. package/skills/kryso-shift/archive_checker_lambda.py +155 -0
  97. package/skills/kryso-shift/archive_health.py +364 -0
  98. package/skills/kryso-shift/archive_launchd.py +140 -0
  99. package/skills/kryso-shift/archive_remote.py +990 -0
  100. package/skills/kryso-shift/archiving-checker.md +140 -0
  101. package/skills/kryso-shift/archiving-keep.md +115 -0
  102. package/skills/kryso-shift/archiving-recovery.md +112 -0
  103. package/skills/kryso-shift/archiving-remote.md +166 -0
  104. package/skills/kryso-shift/archiving.md +146 -0
  105. package/skills/kryso-shift/coverage.schema.json +225 -0
  106. package/skills/kryso-shift/deadline.sh +254 -0
  107. package/skills/kryso-shift/feedback.schema.json +35 -0
  108. package/skills/kryso-shift/feedback.sh +228 -0
  109. package/skills/kryso-shift/history-manifest.schema.json +331 -0
  110. package/skills/kryso-shift/keep-after.sh +55 -0
  111. package/skills/kryso-shift/measure.sh +611 -0
  112. package/skills/kryso-shift/merge-ready.sh +207 -0
  113. package/skills/kryso-shift/outcome.schema.json +16 -0
  114. package/skills/kryso-shift/pass-rules.md +8 -0
  115. package/skills/kryso-shift/profile.schema.json +42 -0
  116. package/skills/kryso-shift/reader.sh +692 -0
  117. package/skills/kryso-shift/reads.sh +151 -0
  118. package/skills/kryso-shift/reference/allowance.md +21 -0
  119. package/skills/kryso-shift/reference/driver.md +95 -0
  120. package/skills/kryso-shift/reference/measuring.md +67 -0
  121. package/skills/kryso-shift/reference/outputs.md +21 -0
  122. package/skills/kryso-shift/reference/pass-script.md +115 -0
  123. package/skills/kryso-shift/reference/reconcile-and-merge.md +55 -0
  124. package/skills/kryso-shift/reference/second-reader.md +9 -0
  125. package/skills/kryso-shift/reference/sweeps.md +83 -0
  126. package/skills/kryso-shift/repair.schema.json +14 -0
  127. package/skills/kryso-shift/report-template.html +679 -0
  128. package/skills/kryso-shift/report.py +389 -0
  129. package/skills/kryso-shift/report_fixture.py +65 -0
  130. package/skills/kryso-shift/reporting.md +58 -0
  131. package/skills/kryso-shift/result.sh +91 -0
  132. package/skills/kryso-shift/runner.sh +1178 -0
  133. package/skills/kryso-shift/ship-loop.sh +3977 -0
  134. package/skills/kryso-shift/ship-pass.sh +4987 -0
  135. package/skills/kryso-shift/steps.jq +19 -0
  136. package/skills/kryso-shift/workflow.mjs +830 -0
  137. package/skills/kryso-shift/workflows/default.json +22 -0
  138. package/skills/kryso-shift/workflows/ralph.json +13 -0
  139. package/skills/kryso-watch/SKILL.md +100 -0
  140. package/skills/kryso-watch/answer.schema.json +23 -0
  141. package/skills/kryso-watch/base-refs.sh +44 -0
  142. package/skills/kryso-watch/board.sh +58 -0
  143. package/skills/kryso-watch/reference/config.md +23 -0
  144. package/skills/kryso-watch/reference/outputs.md +30 -0
  145. package/skills/kryso-watch/reference/report.md +29 -0
  146. package/skills/kryso-watch/reference/scheduler.md +32 -0
  147. package/skills/kryso-watch/reference/settlement.md +29 -0
  148. package/skills/kryso-watch/reference/shift.md +44 -0
  149. package/skills/kryso-watch/reference/shim-limits.md +22 -0
  150. package/skills/kryso-watch/reference/triage.md +26 -0
  151. package/skills/kryso-watch/schema.jq +40 -0
  152. package/skills/kryso-watch/settle.schema.json +36 -0
  153. package/skills/kryso-watch/stage-common.sh +187 -0
  154. package/skills/kryso-watch/stages/report.sh +525 -0
  155. package/skills/kryso-watch/stages/settle.sh +722 -0
  156. package/skills/kryso-watch/stages/shift.sh +466 -0
  157. package/skills/kryso-watch/stages/triage.sh +379 -0
  158. package/skills/kryso-watch/tracker.sh +27 -0
  159. package/skills/kryso-watch/triage.schema.json +77 -0
  160. package/skills/kryso-watch/warden.launchd.plist +50 -0
  161. package/skills/kryso-watch/warden.schema.json +98 -0
  162. package/skills/kryso-watch/warden.sh +1004 -0
@@ -0,0 +1,146 @@
1
+ # Archiving a pass
2
+
3
+ `archive.py` keeps shipping evidence after its worktrees and shift directories are gone, and puts it back somewhere else. `collect` copies one native attempt. `history` discovers the saved history across repositories. `verify` checks an archive against its hashes, and `restore` rebuilds one snapshot under an empty root. The local verbs read evidence and write only inside the archive or the restore root, except that a restore also creates any missing directories above its root and stages beside it; a failed restore removes both. They start no model, call no tracker and use no network. Python 3.10 or newer is required.
4
+
5
+ This page is the local archive. Encrypted upload to a private bucket, remote verification and restore from it are in [archiving-remote.md](archiving-remote.md), and scheduled and post-shift collection with health snapshots is in [archiving-keep.md](archiving-keep.md). The monthly restore check, and what to do when a restore is needed, the key is lost or the disk fills, are in [archiving-recovery.md](archiving-recovery.md). None of them changes anything below.
6
+
7
+ ## Collect
8
+
9
+ ```sh
10
+ python3 ~/.agents/skills/kryso-shift/archive.py collect \
11
+ --archive ~/ship-archive --repo "$PWD" --attempt 278-20261003T035322Z-4242 \
12
+ --input prices.json --input manifest.json
13
+ ```
14
+
15
+ `--attempt` is the pass record's `attempt_id`, which the outcome block also carries. Only an attempt with a native identity can be collected: one whose `ship-pass-record/1`, `/2`, `/3` or `/4` record names it, in a retained worktree under `.claude/worktrees/*/.kryso/pass/logs/` or in the shipped copy under `.claude/kryso/shipped/*/.kryso/pass/logs/`. Any other attempt is refused with exit 1, and nothing is written.
16
+
17
+ Collection reads only these evidence roots:
18
+
19
+ - every `.kryso/pass/` directory whose logs hold a record for the attempt: the ledger, the checkpoint, the brief, the reviews, the receipts, the records, the fork results and the ledger module
20
+ - in the shift directory whose `pass-<n>.json` names the attempt, that pass's own files (`pass-<n>.json`, `.final.json`, `.json.raw`, `.err`, `.done`, `ratelimit-<n>-*.json`, `report-<n>.json`, `report-<n>-*.json` and `report-<n>.err`) and the shift's own (`shift.log`, `shift.json`, `summary.json`, `sweep-*.json`)
21
+ - each file named with `--input`, such as a price table, a PR snapshot or a frozen measurement manifest
22
+
23
+ Nothing else in the repository is walked. Inside a root, a symlink is never followed and is listed as excluded, with whether it escapes the root. A named input is a root of one file under the same rules: a symlink or a credential file named with `--input` is excluded, not read. Environment files and credential stores (`.env*`, `*.env`, `.netrc`, `.npmrc`, `.pypirc`, `.git-credentials`, `credentials*`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, SSH keys, `.secrets`) are excluded by name, a directory with everything under it, and their bytes never reach the archive. Another pass's files in the same shift directory are excluded as another attempt's evidence.
24
+
25
+ Some directories are left out of every root with everything under them, and each is listed once under `excluded` with its reason. `.git` and `node_modules` are left out by name. A Postgres data directory is left out wherever a gate put it, known by the `PG_VERSION` file at its top rather than by its name, because the same directory turns up as `pg`, `pgdata` or `pg-gate`. Its rows are no record of what a pass did, and a row can hold a seeded token or a password hash that no file name gives away. A [keep configuration](archiving-keep.md#the-keep-configuration) can name more directories for one repository. Everything else under a ledger directory is collected, browser-test output and downloaded CI artefacts included, unless the keep configuration names it. A remote is immutable, so whatever a capture takes is kept for good: a pass keeps the state that is not evidence outside `.kryso/pass/`, as the [prove stage](../kryso/reference/stage-3-prove.md#state-that-is-not-evidence) says.
26
+
27
+ The command prints one JSON line: whether the snapshot was `created` or already there (`unchanged`), its id, its completeness and the manifest path. Exit 0 is a complete snapshot, 2 a partial one, 1 a refusal and 64 a usage error. The source files are only read.
28
+
29
+ ## Collect a saved history
30
+
31
+ ```sh
32
+ python3 ~/.agents/skills/kryso-shift/archive.py history \
33
+ --archive ~/ship-archive \
34
+ --repo ~/Dev/iran-monitor \
35
+ --repo ~/Dev/kryso \
36
+ --repo ~/Dev/jv-k/5g-hub-monitor \
37
+ --repo ~/Dev/jv-k/macup \
38
+ --repo ~/Dev/jv-k/automations \
39
+ --repo ~/Dev/jv-k/deslopper \
40
+ --claude-projects ~/.claude/projects \
41
+ --codex-sessions ~/.codex/sessions \
42
+ --input prices.json --input tracker-snapshot.json
43
+ ```
44
+
45
+ Each `--repo` is an explicit boundary. The command discovers dated shifts, retained `.claude/worktrees/*/.kryso/pass` ledgers and `.claude/kryso/shipped/*/.kryso/pass` copies below those roots. It keeps native records, legacy pass results, separate rate-limit files, empty and malformed results, supplied reports, frozen manifests, price tables and tracker snapshots. It does not walk repository source.
46
+
47
+ A native attempt keeps its recorded `attempt_id`. A legacy source gets an id from its repository directory name, shift and path below the repository. The issue number is metadata and never part of the identity on its own. Byte-identical pass results at two source paths remain two sources. The later one names the first in `copy_of`. Rate-limit files stay with their source attempt and count as retries, not copies. Entry hashes are the versions inside a history capture. A later append or truncation produces another immutable capture instead of changing the earlier one.
48
+
49
+ The command associates host sessions only by a recorded session id. `--claude-projects` admits exact `<project>/<session id>.jsonl` matches and their saved `subagents` transcripts and metadata. `--codex-sessions` admits JSONL files whose `session_meta.payload.id` matches. No match is `absent`. More than one is `ambiguous`. Both states appear in `gaps`, and an ambiguous candidate is preserved without being chosen. Unrelated sessions are not copied. Symlinks are never followed.
50
+
51
+ Every file is copied to a staging file and checked against its source size and modification time. A source that changes is read up to three times. If it never settles, the manifest lists the error, marks collection `partial` and exits 2. Whether an attempt is `active` or `finished` is separate. A complete history capture may hold an active pass, and a partial capture does not change its delivery outcome.
52
+
53
+ The `ship-history-manifest/1` inventory reports repositories, attempts, files, bytes, roles, file conditions and coverage of shifts, retained worktrees and shipped archives. `host_totals` contains inclusive totals reported by attempts and counts an exact copy once. `transcripts` contains exclusive usage reconstructed from surviving transcript messages and counts each transcript source once. Missing and ambiguous associations stay in `gaps`. They are never filled from an issue number or a nearby timestamp.
54
+
55
+ Issue #94 predates this archive and may have overwritten an earlier report body. A history containing its surviving retry result without a report gets a `report-body-unavailable` gap. The history capture preserves the surviving bytes. It does not claim to recover the overwritten body.
56
+
57
+ A capture compares itself with the last history capture this archive made of each repository it names, which `<archive>/history/latest.json` records. That is the capture last named, so one that named an older snapshot again because the evidence went back to it counts. An attempt the previous capture held and this one no longer finds is a `vanished-attempt` gap. The gap's `last_seen` names the capture that still holds the attempt's bytes, because a restore of that capture can read them, and nothing of the attempt is reconstructed. The gap is carried into every later capture while the attempt stays gone, so unchanged evidence still names the same snapshot, and it drops out when the source comes back. Repositories are compared by identity, their directory name, so capturing a repository with another name into the archive reports none of this one's attempts as vanished. A moved pass that keeps its identity has not vanished. A recorded capture that is missing, or does not match its identity, is not compared with. Evidence removed before any capture saw it leaves nothing to compare, and no capture can report it.
58
+
59
+ ## The coverage report
60
+
61
+ ```sh
62
+ python3 archive.py coverage --archive ~/ship-archive --snapshot <history capture id>
63
+ python3 archive.py coverage --manifest ~/ship-restore/restored/archive-manifest.json
64
+ ```
65
+
66
+ `coverage` reads one history capture's manifest and prints a `ship-archive-coverage/1` report on one JSON line. [coverage.schema.json](coverage.schema.json) owns the format. It reads nothing but the manifest, so the report over a restored `archive-manifest.json` is the same as the one over the archive it came from. A single attempt's snapshot is refused, because only a history capture discovers sources. The exit is 0 whatever the report finds, and 1 when there is no such snapshot, it is not a history capture, or it records a gap kind the report has no reason for, which is refused rather than left out.
67
+
68
+ The schema names every field and its type. What it cannot say is how three of them count. `attempts` keeps copies in its `total` and leaves them out of `counted`, and a counted attempt with no outcome reads `unknown`. `sessions.unrecorded` counts the counted attempts that name no session at all. Each gap's `why` is the sentence that says what is missing or unknown and why.
69
+
70
+ A copy is the same bytes saved at a second path. It keeps its row and is counted once, so its gaps are its original's and are not listed again. The gap kinds:
71
+
72
+ | Kind | What it means |
73
+ | --- | --- |
74
+ | `malformed-attempt` | A pass result that is empty or not valid JSON, so no attempt can be read from it. Its bytes are kept. |
75
+ | `report-body-unavailable` | #94's retry result survives and its report body does not. |
76
+ | `missing-input` | A named input was not there. The capture is partial. |
77
+ | `absent-session` | An attempt names a session and no transcript with that id was found. |
78
+ | `ambiguous-session` | More than one transcript has the id. All are kept and none is chosen. |
79
+ | `capture-error` | A file was there and could not be captured: unreadable, or still changing after three reads. The capture is partial. |
80
+ | `invalid-file` | Any other kept file that is not valid JSON, or a `.json` or `.jsonl` file that is empty. |
81
+ | `missing-result` | A shift kept files of a pass, its stderr or a rate-limit file say, and no result for it, so they belong to no attempt. |
82
+ | `active-attempt` | The pass was still running, so its later evidence is only in a later capture. |
83
+ | `unknown-outcome`, `unknown-issue` | No outcome, or no issue number, is recorded. Neither is guessed. |
84
+ | `unrecorded-session` | The attempt names no session, so no transcript can be associated. |
85
+ | `unknown-cost` | No host total is recorded, so the cost is unknown rather than zero. |
86
+ | `vanished-attempt` | An earlier capture held the attempt and this one no longer finds it. It is not reconstructed. |
87
+
88
+ A failed attempt is not a gap: it is counted under `outcomes`, and a rate-limited one under `rate_limited` and `retries`. What the report does not explain is the gap between this inventory and a report's denominator, which depends on the report's own inclusion rules.
89
+
90
+ ## The archive layout
91
+
92
+ ```
93
+ <archive>/objects/<first two hex>/<sha256> the bytes of each file, once, read-only
94
+ <archive>/snapshots/<snapshot id>.json one manifest per snapshot, read-only
95
+ <archive>/history/latest.json the last history capture of each repository, replaced by each capture
96
+ ```
97
+
98
+ Objects are content-addressed, so files shared between snapshots are stored once. Neither an object nor a manifest is ever rewritten. A collection checks every object and the snapshot the archive already holds before it writes anything, and one with other bytes than its name says makes it refuse with the archive unchanged.
99
+
100
+ ## The manifest
101
+
102
+ Schema `ship-archive-manifest/1` describes one native attempt. [history-manifest.schema.json](history-manifest.schema.json) owns the `ship-history-manifest/1` contract for a discovered history. The pass record's schema is unchanged by either.
103
+
104
+ | Field | What it holds |
105
+ | --- | --- |
106
+ | `snapshot` | `id` and `captured_at`, the time of the first collection that produced it. |
107
+ | `repository` | `name`, the directory name the restore uses, `slug` from the record, and `source`, the original root. |
108
+ | `shift` | `id`, the shift directory's name, and its original `source`, or `null` when no pass result names the attempt. |
109
+ | `attempt` | `id`, `identity` (`native`), `issue`, `outcome` as the record states it, and `record`, its archive path. |
110
+ | `collection` | `completeness` (`complete` or `partial`) and `errors`, one per file that could not be read or kept changing over three reads. |
111
+ | `entries` | One per file: `path` relative to the restore root, `source` (its original absolute path), `role`, `bytes`, `sha256` and `condition`. |
112
+ | `missing` | Expected evidence that was not there: the ledger, the checkpoint, the brief, the review, any receipt, the shift's pass result, or a named input. |
113
+ | `excluded` | Each path seen and not collected, with the reason. |
114
+
115
+ An entry's `condition` is `valid-json`, `invalid-json`, `empty` or `present`. An empty or unparseable file is kept with its condition, never dropped. The roles are `ledger`, `checkpoint`, `brief`, `review`, `receipt`, `record`, `result`, `module`, `host-stderr`, `shift`, `measurement-input` and `other`.
116
+
117
+ Three things stay apart. `missing` is evidence that did not exist when the collector looked, and does not make a snapshot partial. `collection.errors` is evidence that existed and could not be captured, and makes it partial. `attempt.outcome` is whether the pass shipped, parked or failed, and says nothing about the archive. A parked pass can have a complete snapshot, and a shipped one a partial snapshot.
118
+
119
+ The snapshot id is the SHA-256 of the manifest without its `snapshot` field, serialised as JSON with sorted keys and no whitespace (`separators=(",", ":")`). Collecting the same evidence again produces the same id and writes nothing. Evidence that changed, such as a ledger line appended, produces a new snapshot, and the earlier one stays. The attempt id is the identity across snapshots, never the content hash.
120
+
121
+ ## Verify
122
+
123
+ ```sh
124
+ python3 archive.py verify --archive ~/ship-archive [--snapshot <id>]
125
+ ```
126
+
127
+ Recomputes every manifest's id and every object's hash and size, and rejects an object that is a symlink or resolves outside the archive. It prints `{snapshots, objects, problems}` and exits 1 when any problem is listed.
128
+
129
+ ## Restore
130
+
131
+ ```sh
132
+ python3 archive.py restore --archive ~/ship-archive --snapshot <id> --to ~/ship-restore/restored
133
+ python3 archive.py restore --archive ~/ship-archive --manifest ~/ship-restore/restored/archive-manifest.json --to ~/ship-restore/again
134
+ ```
135
+
136
+ The root must be absent or an empty directory. Before any file is written, the restore checks the manifest against its id and every path for traversal (an absolute path, `..`, `.`, an empty part or a backslash) and for collisions. Each file is then read, checked against its hash and size, written to a staging directory beside the root and re-hashed. The staging directory is renamed into place only once all of them are in. Any failure exits 1 and leaves the root as it was, with no directory created above it. The manifest is copied to `archive-manifest.json` at the root.
137
+
138
+ The layout under the root is `<repository name>/<path below the original repository>` and `inputs/<file name>`, so the report and the measurement run over it as they ran over the original, with no original absolute path:
139
+
140
+ ```sh
141
+ python3 report.py --repo ~/ship-restore/restored/<name> --prices ~/ship-restore/restored/inputs/prices.json --output ~/ship-restore/report
142
+ bash measure.sh analyze ~/ship-restore/restored/inputs/manifest.json --root ~/ship-restore/restored/<name> \
143
+ --prices ~/ship-restore/restored/inputs/prices.json
144
+ ```
145
+
146
+ The report's runs, outcomes, costs and exclusions match the original's for every record the snapshot holds, with only the source paths changed. A resumed pass keeps each attempt's record in the same `.kryso/pass/logs/`, so a snapshot of the later attempt carries the earlier record too, and the restored report shows both runs, as the original did. A frozen measurement manifest names its sources relative to the directory its sources file sat in, so freeze with the sources file at the repository root and pass `--root` as above. The `source` fields in the manifest keep the original paths as provenance, and nothing reads them to restore.
@@ -0,0 +1,225 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/krysoworks/kryso/skills/kryso-shift/coverage.schema.json",
4
+ "title": "History capture coverage report",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "schema",
9
+ "snapshot",
10
+ "inventory",
11
+ "repositories",
12
+ "attempts",
13
+ "sessions",
14
+ "files",
15
+ "sources",
16
+ "gaps",
17
+ "excluded"
18
+ ],
19
+ "properties": {
20
+ "schema": { "const": "ship-archive-coverage/1" },
21
+ "snapshot": {
22
+ "type": "object",
23
+ "additionalProperties": false,
24
+ "required": ["id", "captured_at", "completeness"],
25
+ "properties": {
26
+ "id": { "$ref": "#/$defs/hash" },
27
+ "captured_at": { "type": ["string", "null"] },
28
+ "completeness": { "enum": ["complete", "partial", null] }
29
+ }
30
+ },
31
+ "inventory": {
32
+ "type": "object",
33
+ "additionalProperties": false,
34
+ "required": ["repositories", "attempts", "files", "bytes", "excluded", "errors", "locations", "gaps", "gap_kinds"],
35
+ "properties": {
36
+ "repositories": { "$ref": "#/$defs/count" },
37
+ "attempts": { "$ref": "#/$defs/count" },
38
+ "files": { "$ref": "#/$defs/count" },
39
+ "bytes": { "$ref": "#/$defs/count" },
40
+ "excluded": { "$ref": "#/$defs/count" },
41
+ "errors": { "$ref": "#/$defs/count" },
42
+ "locations": {
43
+ "type": "object",
44
+ "additionalProperties": false,
45
+ "required": ["retained_worktrees", "shifts", "shipped_archives"],
46
+ "properties": {
47
+ "retained_worktrees": { "$ref": "#/$defs/count" },
48
+ "shifts": { "$ref": "#/$defs/count" },
49
+ "shipped_archives": { "$ref": "#/$defs/count" }
50
+ }
51
+ },
52
+ "gaps": { "$ref": "#/$defs/count" },
53
+ "gap_kinds": { "$ref": "#/$defs/tally" }
54
+ }
55
+ },
56
+ "repositories": {
57
+ "type": "array",
58
+ "items": {
59
+ "type": "object",
60
+ "additionalProperties": false,
61
+ "required": ["name", "source", "files", "bytes", "errors", "attempts", "gaps"],
62
+ "properties": {
63
+ "name": { "type": "string" },
64
+ "source": { "type": "string" },
65
+ "files": { "$ref": "#/$defs/count" },
66
+ "bytes": { "$ref": "#/$defs/count" },
67
+ "errors": { "$ref": "#/$defs/count" },
68
+ "attempts": { "$ref": "#/$defs/count" },
69
+ "gaps": { "$ref": "#/$defs/count" }
70
+ }
71
+ }
72
+ },
73
+ "attempts": {
74
+ "type": "object",
75
+ "additionalProperties": false,
76
+ "required": ["total", "counted", "copies", "identity", "outcomes", "activity", "rate_limited", "retries"],
77
+ "properties": {
78
+ "total": { "$ref": "#/$defs/count" },
79
+ "counted": { "$ref": "#/$defs/count" },
80
+ "copies": { "$ref": "#/$defs/count" },
81
+ "identity": { "$ref": "#/$defs/tally" },
82
+ "outcomes": { "$ref": "#/$defs/tally" },
83
+ "activity": { "$ref": "#/$defs/tally" },
84
+ "rate_limited": { "$ref": "#/$defs/count" },
85
+ "retries": { "$ref": "#/$defs/count" }
86
+ }
87
+ },
88
+ "sessions": {
89
+ "type": "object",
90
+ "additionalProperties": false,
91
+ "required": ["associated", "ambiguous", "absent", "unrecorded"],
92
+ "properties": {
93
+ "associated": { "$ref": "#/$defs/count" },
94
+ "ambiguous": { "$ref": "#/$defs/count" },
95
+ "absent": { "$ref": "#/$defs/count" },
96
+ "unrecorded": { "$ref": "#/$defs/count" }
97
+ }
98
+ },
99
+ "files": {
100
+ "type": "object",
101
+ "additionalProperties": false,
102
+ "required": ["conditions", "roles"],
103
+ "properties": {
104
+ "conditions": { "$ref": "#/$defs/tally" },
105
+ "roles": { "$ref": "#/$defs/tally" }
106
+ }
107
+ },
108
+ "sources": {
109
+ "type": "array",
110
+ "items": { "$ref": "#/$defs/source" }
111
+ },
112
+ "gaps": {
113
+ "type": "array",
114
+ "items": { "$ref": "#/$defs/gap" }
115
+ },
116
+ "excluded": {
117
+ "type": "array",
118
+ "items": {
119
+ "type": "object",
120
+ "additionalProperties": false,
121
+ "required": ["source", "reason"],
122
+ "properties": {
123
+ "source": { "type": "string" },
124
+ "reason": { "type": "string" }
125
+ }
126
+ }
127
+ }
128
+ },
129
+ "$defs": {
130
+ "hash": {
131
+ "type": "string",
132
+ "pattern": "^[0-9a-f]{64}$"
133
+ },
134
+ "count": {
135
+ "type": "integer",
136
+ "minimum": 0
137
+ },
138
+ "tally": {
139
+ "type": "object",
140
+ "additionalProperties": { "type": "integer", "minimum": 0 }
141
+ },
142
+ "nullableString": {
143
+ "type": ["string", "null"]
144
+ },
145
+ "source": {
146
+ "type": "object",
147
+ "additionalProperties": false,
148
+ "required": [
149
+ "attempt",
150
+ "identity",
151
+ "repository",
152
+ "issue",
153
+ "outcome",
154
+ "activity",
155
+ "shift",
156
+ "source",
157
+ "copy_of",
158
+ "retries",
159
+ "reported_usd",
160
+ "sessions",
161
+ "gaps"
162
+ ],
163
+ "properties": {
164
+ "attempt": { "type": "string" },
165
+ "identity": { "enum": ["native", "legacy"] },
166
+ "repository": { "type": "string" },
167
+ "issue": { "$ref": "#/$defs/nullableString" },
168
+ "outcome": { "$ref": "#/$defs/nullableString" },
169
+ "activity": { "enum": ["active", "finished", "unknown"] },
170
+ "shift": { "$ref": "#/$defs/nullableString" },
171
+ "source": { "type": "string" },
172
+ "copy_of": { "$ref": "#/$defs/nullableString" },
173
+ "retries": { "$ref": "#/$defs/count" },
174
+ "reported_usd": { "type": ["number", "null"], "minimum": 0 },
175
+ "sessions": {
176
+ "type": "array",
177
+ "items": {
178
+ "type": "object",
179
+ "additionalProperties": false,
180
+ "required": ["id", "status"],
181
+ "properties": {
182
+ "id": { "type": "string" },
183
+ "status": { "enum": ["associated", "ambiguous", "absent"] }
184
+ }
185
+ }
186
+ },
187
+ "gaps": {
188
+ "type": "array",
189
+ "items": { "$ref": "#/$defs/gapKind" },
190
+ "uniqueItems": true
191
+ }
192
+ }
193
+ },
194
+ "gapKind": {
195
+ "enum": [
196
+ "malformed-attempt",
197
+ "report-body-unavailable",
198
+ "missing-input",
199
+ "absent-session",
200
+ "ambiguous-session",
201
+ "capture-error",
202
+ "invalid-file",
203
+ "missing-result",
204
+ "active-attempt",
205
+ "unknown-outcome",
206
+ "unknown-issue",
207
+ "unrecorded-session",
208
+ "unknown-cost",
209
+ "vanished-attempt"
210
+ ]
211
+ },
212
+ "gap": {
213
+ "type": "object",
214
+ "additionalProperties": false,
215
+ "required": ["kind", "subject", "repository", "attempts", "why"],
216
+ "properties": {
217
+ "kind": { "$ref": "#/$defs/gapKind" },
218
+ "subject": { "type": "string" },
219
+ "repository": { "$ref": "#/$defs/nullableString" },
220
+ "attempts": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
221
+ "why": { "type": "string", "minLength": 1 }
222
+ }
223
+ }
224
+ }
225
+ }
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env bash
2
+ # deadline.sh: one command under an active-execution allowance, stopped with everything it
3
+ # started when the allowance runs out, and nothing else stopped. Sourced by ship-loop.sh and
4
+ # ship-pass.sh: it defines deadline_valid, deadline_run, deadline_interrupted and their
5
+ # _deadline_* helpers, prints nothing when sourced and changes no option it does not put back.
6
+ #
7
+ # deadline_valid <value>: status 0 for a positive whole number of seconds.
8
+ #
9
+ # deadline_run [--active <check...> --] <allowance> <grace> <report> <command...>: runs the
10
+ # command, its stdin from /dev/null, and returns its exit, or 124 when the allowance ran out
11
+ # first. The check runs up to the first --, so a check cannot take -- as an argument, and an
12
+ # --active with no check or no -- returns 64, the usage refusal ledger.sh gives, without running
13
+ # anything. Then a watchdog
14
+ # lists the command's process tree, sends TERM to the tree and, when the command runs in a
15
+ # process group of its own, to that group, waits up to <grace> seconds for every one of them to
16
+ # end, and sends KILL to whatever is left. Only that tree and that group are signalled, so a
17
+ # receipt another pass holds the repository's gate lock with is never touched: it is not the
18
+ # command's descendant. The stop is confirmed when no process of the tree or the group is left
19
+ # and, when the caller gave an --active check, that check reports the pass's authority free by
20
+ # a non-zero exit, which ledger.sh's `active` gives for a tree that inherited it. <report> gets
21
+ # one JSON object either way: expired, allowance, grace, elapsed, signal (none, TERM or KILL)
22
+ # and stopped (exited, confirmed or unconfirmed). The command gets a process group of its own
23
+ # only when no descriptor of the caller is a terminal, because a background group that touches
24
+ # a terminal is stopped by it, and a person at the terminal stops a run with ctrl+c anyway.
25
+ # An INT or a TERM to the caller while the command runs ends the allowance at once, so the command
26
+ # is stopped the way an allowance's end stops it, with the same report and the same 124, and
27
+ # DEADLINE_INTERRUPT names the signal (empty when nothing interrupted the run). That is how a ctrl+c
28
+ # at a driver's terminal, and `kryso attach`'s stop, reach a pass's processes and its ledger. The
29
+ # caller's own traps for the two signals are put back before it returns.
30
+ # Needs bash, pgrep and jq, and deadline_interrupted needs ledger.sh sourced as well.
31
+
32
+ deadline_valid() { [[ "${1:-}" =~ ^[0-9]+$ ]] && (( 10#$1 > 0 )); }
33
+
34
+ # _deadline_now <var>: epoch seconds into the named variable. Bash 5 has them as EPOCHSECONDS,
35
+ # which starts no process. Older bash asks date.
36
+ if [[ "${BASH_VERSINFO[0]}" -ge 5 ]]; then
37
+ _deadline_now() { printf -v "$1" '%s' "$EPOCHSECONDS"; }
38
+ else
39
+ _deadline_now() { printf -v "$1" '%s' "$(date -u +%s)"; }
40
+ fi
41
+
42
+ # _deadline_tree <pid>: the pid and every process under it, one per line, parents first.
43
+ _deadline_tree() {
44
+ local child
45
+ printf '%s\n' "$1"
46
+ for child in $(pgrep -P "$1" 2>/dev/null); do _deadline_tree "$child"; done
47
+ }
48
+
49
+ # _deadline_alive <group> <pid>...: status 0 while any process of the group (when there is one)
50
+ # or of the listed pids is still running. A zombie is not running: its parent is gone or will
51
+ # reap it, and it holds nothing.
52
+ _deadline_alive() {
53
+ local group="$1" p state
54
+ shift
55
+ if [[ -n "$group" ]] && kill -0 -- "-$group" 2>/dev/null; then
56
+ for p in $(pgrep -g "$group" 2>/dev/null); do
57
+ state="$(ps -o stat= -p "$p" 2>/dev/null)"
58
+ [[ -z "$state" || "$state" == Z* ]] || return 0
59
+ done
60
+ fi
61
+ for p in "$@"; do
62
+ state="$(ps -o stat= -p "$p" 2>/dev/null)"
63
+ [[ -z "$state" || "$state" == Z* ]] || return 0
64
+ done
65
+ return 1
66
+ }
67
+
68
+ # _deadline_signal <signal> <group> <pid>...: the signal to the group and to each pid still there.
69
+ _deadline_signal() {
70
+ local sig="$1" group="$2" p
71
+ shift 2
72
+ [[ -z "$group" ]] || kill "-$sig" -- "-$group" 2>/dev/null
73
+ for p in "$@"; do kill "-$sig" "$p" 2>/dev/null; done
74
+ return 0
75
+ }
76
+
77
+ # _deadline_watch <pid> <group> <allowance> <grace> <mark>: the watchdog. It sleeps out the
78
+ # allowance in a child it kills when it is told to stand down, so a command that ends in time
79
+ # leaves nothing behind. Past the allowance it writes the signal it used to <mark>, and times
80
+ # the grace the same way, in a `sleep <grace>` child. The test sandbox's shim-expire ends an
81
+ # allowance early by killing that `sleep <allowance>` child, so a watchdog that waits some
82
+ # other way must change shim-expire with it. The grace's child is never the one it finds: the
83
+ # shim kills one sleep and exits before the grace starts.
84
+ _deadline_watch() {
85
+ local pid="$1" group="$2" allowance="$3" grace="$4" mark="$5" s tree end
86
+ trap 'kill "$s" 2>/dev/null; exit 0' TERM
87
+ sleep "$allowance" & s=$!
88
+ wait "$s"
89
+ trap - TERM
90
+ # The tree is read before anything is signalled, so a child whose parent dies first is still
91
+ # on the list after it has been handed to init.
92
+ tree="$(_deadline_tree "$pid" | tr '\n' ' ')"
93
+ echo TERM > "$mark"
94
+ # shellcheck disable=SC2086 # the tree is a list of pids
95
+ _deadline_signal TERM "$group" $tree
96
+ # The grace is timed by a `sleep <grace>` child, not by counting checks, because each check
97
+ # reads the process table and a loaded machine makes those reads slow. The check in flight
98
+ # when the sleep ends, and the tenth of a second after it, can run past the grace, and
99
+ # nothing else does. SECONDS is a backstop, a second coarse, for a sleep whose pid was reaped
100
+ # and handed to another process, which `kill -0` would go on finding.
101
+ end=$(( SECONDS + grace + 1 ))
102
+ sleep "$grace" & s=$!
103
+ trap 'kill "$s" 2>/dev/null; exit 0' TERM
104
+ while kill -0 "$s" 2>/dev/null && (( SECONDS < end )); do
105
+ # shellcheck disable=SC2086
106
+ _deadline_alive "$group" $tree || { kill "$s" 2>/dev/null; wait "$s" 2>/dev/null; return 0; }
107
+ sleep 0.1
108
+ done
109
+ kill "$s" 2>/dev/null
110
+ wait "$s" 2>/dev/null
111
+ trap - TERM
112
+ echo KILL > "$mark"
113
+ # shellcheck disable=SC2086,SC2046 # lists of pids, split on purpose
114
+ _deadline_signal KILL "$group" $tree $(for p in $tree; do _deadline_tree "$p"; done)
115
+ return 0
116
+ }
117
+
118
+ # _deadline_interrupt <signal> <watchdog> <mark>: ends the allowance now, the first time only and
119
+ # never once it has ended, by killing the `sleep <allowance>` the watchdog waits on, as the test
120
+ # sandbox's shim-expire does. A watchdog that has not started its sleep yet is given a second.
121
+ _deadline_interrupt() {
122
+ local s i
123
+ [[ -z "$DEADLINE_INTERRUPT" && ! -s "$3" ]] || return 0
124
+ DEADLINE_INTERRUPT="$1"
125
+ for (( i = 0; i < 20; i++ )); do
126
+ s="$(pgrep -P "$2" 2>/dev/null)"
127
+ # shellcheck disable=SC2086 # the watchdog's one child
128
+ [[ -z "$s" ]] || { kill $s 2>/dev/null; return 0; }
129
+ sleep 0.05
130
+ done
131
+ }
132
+
133
+ DEADLINE_INTERRUPT=""
134
+ deadline_run() {
135
+ local -a active=()
136
+ if [[ "${1:-}" == --active ]]; then
137
+ shift
138
+ while [[ $# -gt 0 && "$1" != -- ]]; do active+=("$1"); shift; done
139
+ [[ $# -gt 0 && ${#active[@]} -gt 0 ]] || return 64
140
+ shift
141
+ fi
142
+ local allowance="$1" grace="$2" report="$3" t0 pid group="" dog code expired=false signal=none stopped=exited
143
+ local mark="$report.signal" monitor=0 i tree traps
144
+ shift 3
145
+ [[ ! -e "$mark" && ! -L "$mark" ]] || rm -f "$mark"
146
+ _deadline_now t0
147
+ if [[ ! -t 0 && ! -t 1 && ! -t 2 ]]; then
148
+ [[ "$-" == *m* ]] && monitor=1
149
+ set -m
150
+ "$@" < /dev/null &
151
+ pid=$!
152
+ [[ "$monitor" -eq 1 ]] || set +m
153
+ group="$pid"
154
+ else
155
+ "$@" < /dev/null &
156
+ pid=$!
157
+ fi
158
+ _deadline_watch "$pid" "$group" "$allowance" "$grace" "$mark" &
159
+ dog=$!
160
+ DEADLINE_INTERRUPT=""
161
+ traps="$(trap -p INT TERM)"
162
+ # shellcheck disable=SC2064 # the watchdog and the mark are fixed for this run
163
+ trap "_deadline_interrupt INT $dog '$mark'" INT
164
+ # shellcheck disable=SC2064
165
+ trap "_deadline_interrupt TERM $dog '$mark'" TERM
166
+ # A trapped signal ends the wait early while the command still runs, until the watchdog stops it.
167
+ while :; do
168
+ wait "$pid" 2>/dev/null
169
+ code=$?
170
+ [[ -n "$DEADLINE_INTERRUPT" ]] && kill -0 "$pid" 2>/dev/null || break
171
+ done
172
+ if [[ -s "$mark" ]]; then
173
+ # The allowance ran out: the watchdog finishes its grace and its KILL before the stop is
174
+ # judged, and the tree is read once more for anything the command left behind.
175
+ wait "$dog" 2>/dev/null
176
+ expired=true
177
+ signal="$(cat "$mark")"
178
+ stopped=confirmed
179
+ tree="$(_deadline_tree "$pid" | tr '\n' ' ')"
180
+ # shellcheck disable=SC2086
181
+ if _deadline_alive "$group" $tree; then stopped=unconfirmed; fi
182
+ if [[ "$stopped" == confirmed && ${#active[@]} -gt 0 ]]; then
183
+ # The kernel frees the authority when the last holder closes it, a moment after the exit.
184
+ stopped=unconfirmed
185
+ for (( i = 0; i < 30; i++ )); do
186
+ "${active[@]}" >/dev/null 2>&1 || { stopped=confirmed; break; }
187
+ sleep 0.1
188
+ done
189
+ fi
190
+ code=124
191
+ else
192
+ kill "$dog" 2>/dev/null
193
+ wait "$dog" 2>/dev/null
194
+ fi
195
+ [[ ! -e "$mark" && ! -L "$mark" ]] || rm -f "$mark"
196
+ local now; _deadline_now now
197
+ # The report is the line jq -c prints. Every field is a word or a whole number, so the shell
198
+ # writes it, unless an allowance or a grace is a number jq would print another way. A report
199
+ # that cannot be written leaves the shell's own error on stderr, as the jq line below does.
200
+ if [[ "$allowance" =~ ^(0|[1-9][0-9]*)$ && "$grace" =~ ^(0|[1-9][0-9]*)$ ]]; then
201
+ printf '{"expired":%s,"allowance":%s,"grace":%s,"elapsed":%s,"signal":"%s","stopped":"%s"}\n' \
202
+ "$expired" "$allowance" "$grace" "$(( now - t0 ))" "$signal" "$stopped" > "$report"
203
+ else
204
+ jq -nc --argjson expired "$expired" --argjson allowance "$allowance" --argjson grace "$grace" \
205
+ --argjson elapsed "$(( now - t0 ))" --arg signal "$signal" --arg stopped "$stopped" \
206
+ '{expired: $expired, allowance: $allowance, grace: $grace, elapsed: $elapsed, signal: $signal, stopped: $stopped}' > "$report" 2>/dev/null
207
+ fi
208
+ trap - INT TERM
209
+ eval "$traps"
210
+ return "$code"
211
+ }
212
+
213
+ # deadline_interrupted <report> <consumed> <allowance> <repo> <issue> [evidence...]: what both
214
+ # engines do once deadline_run has returned 124 for a pass. The issue's worktree, when it has
215
+ # one, gets the interruption through ledger.sh's `interrupt`, at the stage its ledger places
216
+ # the pass, the evidence after signal=<signal>. One JSON object is printed: deadline, the
217
+ # report with the pass's <allowance>, the seconds consumed (<consumed>, what the attempts
218
+ # before this one spent, plus this one's elapsed), the stage (claim with no worktree) and the
219
+ # worktree (null with none); the branch and pr off the ledger, none with no worktree; and
220
+ # reason, the outcome's sentence, which a caller may add to. An empty issue is a pass from the
221
+ # column, which has no worktree. When the ledger refused the interruption, its refusal is on
222
+ # stderr, the reason says the interruption is not recorded and to repair the ledger before a
223
+ # resume, and the status is 1, so both engines report the pass interrupted either way.
224
+ # <report> is the one deadline_run wrote. When DEADLINE_INTERRUPT names a signal, the reason says
225
+ # the pass was interrupted by it in place of its allowance running out, and the ledger's line adds
226
+ # interrupt=<signal>.
227
+ deadline_interrupted() {
228
+ local report="$1" before="$2" allowance="$3" repo="$4" issue="$5" wt="" doc="{}" stage=claim
229
+ local stopped signal consumed code=0 who how words
230
+ shift 5
231
+ stopped="$(jq -r .stopped "$report")"
232
+ signal="$(jq -r .signal "$report")"
233
+ consumed=$(( 10#$before + $(jq -r '.elapsed // 0' "$report") ))
234
+ if [[ -n "$issue" ]] && wt="$(ledger worktree "$repo" "$issue" 2>/dev/null)" && [[ -n "$wt" ]]; then
235
+ ledger interrupt "$wt" "$consumed" "$allowance" "$stopped" "signal=$signal${DEADLINE_INTERRUPT:+ interrupt=$DEADLINE_INTERRUPT}${*:+ $*}" >/dev/null || code=1
236
+ doc="$(ledger read "$wt" 2>/dev/null)" || doc=""
237
+ jq -e 'type == "object"' <<< "$doc" >/dev/null 2>&1 || doc="{}"
238
+ stage="$(jq -r '.stage.name // "build"' <<< "$doc" 2>/dev/null)" || stage=build
239
+ else
240
+ wt=""
241
+ fi
242
+ who="${issue:+#$issue}"
243
+ how="ran out of its ${allowance}s allowance"
244
+ [[ -z "${DEADLINE_INTERRUPT:-}" ]] || how="was interrupted by SIG$DEADLINE_INTERRUPT"
245
+ words="stopped with everything it started"
246
+ [[ "$stopped" == confirmed ]] || words="not confirmed stopped, so nothing may continue it until its processes have exited"
247
+ words+=" (signal $signal)."
248
+ [[ "$code" -eq 0 ]] || words+=" Its ledger at $wt refused the interruption, so its run.md does not record it. Repair the ledger as its error says, then --resume."
249
+ jq -c --argjson doc "$doc" --arg stage "$stage" --arg wt "$wt" --argjson allowance "$allowance" --argjson consumed "$consumed" \
250
+ --arg reason "${who:-The pass} $how at $stage after ${consumed}s and was $words" \
251
+ '{deadline: (. + {allowance: $allowance, consumed: $consumed, stage: $stage, worktree: (if $wt == "" then null else $wt end)}),
252
+ branch: ($doc.header.branch // "none"), pr: ($doc.pr // "none"), reason: $reason}' "$report"
253
+ return "$code"
254
+ }