@krysoworks/kryso 0.0.2 → 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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -6
  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 +55 -22
  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
  163. package/bin/kryso.js +0 -11
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "default",
3
+ "description": "Today's pass: claim, build, prove, PR, reconcile, merge or park, and close out. The build runs diagnosing-bugs, implement, tdd when the seam call is tdd, and code-review, and each step names the ledger events it leaves. tdd and implement are pinned to the engineering playbook's commits.",
4
+ "stages": [
5
+ { "id": "claim", "kind": "claim" },
6
+ {
7
+ "id": "build",
8
+ "kind": "judgement",
9
+ "steps": [
10
+ { "skill": "diagnosing-bugs" },
11
+ { "skill": "implement", "pin": { "source": "jv-k/engineering-playbook", "path": "skills/implement", "commit": "26128618ab33ac8ac8de9237b0f67209100d91bd" }, "evidence": { "events": [{ "stage": "build", "outcome": "committed" }] } },
12
+ { "skill": "tdd", "pin": { "source": "jv-k/engineering-playbook", "path": "skills/tdd", "commit": "dad4119dcf00936222b770fa5acd10e9665e0c23" }, "when": { "seam": "tdd" } },
13
+ { "skill": "code-review", "evidence": { "events": [{ "stage": "review", "outcome": "recorded" }, { "stage": "review", "outcome": "triaged" }] } }
14
+ ]
15
+ },
16
+ { "id": "prove", "kind": "prove" },
17
+ { "id": "pr", "kind": "pr" },
18
+ { "id": "reconcile", "kind": "reconcile" },
19
+ { "id": "merge", "kind": "merge" },
20
+ { "id": "closeout", "kind": "closeout" }
21
+ ]
22
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "ralph",
3
+ "description": "A spec taken whole: the default pass with the build replaced by the slice loop, which the ralph tickets build.",
4
+ "stages": [
5
+ { "id": "claim", "kind": "claim" },
6
+ { "id": "build", "kind": "slice-loop" },
7
+ { "id": "prove", "kind": "prove" },
8
+ { "id": "pr", "kind": "pr" },
9
+ { "id": "reconcile", "kind": "reconcile" },
10
+ { "id": "merge", "kind": "merge" },
11
+ { "id": "closeout", "kind": "closeout" }
12
+ ]
13
+ }
@@ -0,0 +1,100 @@
1
+ ---
2
+ name: kryso-watch
3
+ description: "Run one watch over a repository's tracker: triage new issues, post the calls it cannot make on the decision report, run a shift over the ready queue, and close the open issues the base already satisfies, each stage behind its switch, leaving one entry on the watch log. Also runs a nightly schedule of watches over several repositories and installs its launchd agent. Use to dry-run or start a watch or a schedule, to install the scheduler, to answer the decision report, or to read what the last watch left."
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # kryso-watch
8
+
9
+ A watch is a driver, not a model session. The scheduler or a person starts it, it runs its stages in shell, and each stage that needs judgement gets one fresh model context per issue. Policy stays in shell, in [warden.sh](warden.sh) and its stage bodies under [stages/](stages/): what is eligible, how many, when to stop, and what counts as evidence. [base-refs.sh](base-refs.sh) holds the one rule for whether a cited commit or pull request is on the base.
10
+
11
+ This skill is the front end for running `warden.sh` from a session. The script runs from a plain terminal with no session at all, which is how the scheduler runs it. It calls `kryso-shift` for its shift and changes nothing in it.
12
+
13
+ ## What a watch does
14
+
15
+ The config is validated, the lock is taken, the preflight runs, the base is fetched, and the manifest is written, all before anything is spent. Then four stages run in order. The config switches triage, the shift and settlement on and off, and the report runs when triage does.
16
+
17
+ | Stage | What it does | Detail |
18
+ | --- | --- | --- |
19
+ | Triage | Gives each open issue nobody has evaluated one fresh context running the triage skill, told never to ask. The driver applies a valid outcome: the state label, the acceptance criteria, the brief, and Priority and Size on the board. An outcome that needs a person's call parks the issue `needs-info` with its decisions. | [triage.md](reference/triage.md) |
20
+ | Decision report | Posts the parked decisions on one open report issue, reads a person's answers, and once every item an issue waits on is answered, rewrites its brief and moves it to `ready-for-agent`. | [report.md](reference/report.md) |
21
+ | Shift | Queues the open `ready-for-agent` issues a pass could take on the configured base, by board Priority then age, up to `caps.shift`, and runs `ship-loop.sh` once over them. It starts no model context of its own. | [shift.md](reference/shift.md) |
22
+ | Settlement | Reads the base's commits and merged pull requests since the settled sha, gives each open issue they cite or touch one fresh context, and closes an issue only when every acceptance criterion has a commit or pull request on the base. | [settlement.md](reference/settlement.md) |
23
+
24
+ Once settlement is done, the report posts any items the shift and settlement left. One bounded entry lands on the Watch log, the summary is written, and the driver exits with a stop state from [How a watch ends](#how-a-watch-ends).
25
+
26
+ ## Running it
27
+
28
+ The commands name the canonical project install, `.agents/skills/kryso-watch/`. In the playbook checkout it is `skills/kryso-watch/`. The driver needs `kryso-shift` and `kryso` and finds each beside it, under `.agents/skills`, or under the `.claude/skills` compatibility path.
29
+
30
+ 1. Dry-run the watch and show the user what it would do:
31
+
32
+ ```sh
33
+ bash .agents/skills/kryso-watch/warden.sh --dry-run
34
+ ```
35
+
36
+ That validates the config, runs the preflight, fetches the base, and prints the resolved config, which stages would run, the caps, the worst case in fresh model contexts, and each stage's candidates in order with every exclusion and its reason, down to the exact `ship-loop.sh` command. It starts no context, writes nothing to the tracker or the state file and takes no lock. With the second reader on, the one ask it makes for settlement's probabilities is the dry run's one spend. `--read-only` with it fetches nothing and spends nothing, as [config.md](reference/config.md#options) says.
37
+
38
+ 2. Run one watch in the current repository, or `--repo DIR` for another:
39
+
40
+ ```sh
41
+ bash .agents/skills/kryso-watch/warden.sh
42
+ ```
43
+
44
+ The options, `--second-reader` among them, are in [config.md](reference/config.md#options).
45
+
46
+ 3. Report from the `summary.json` the last line names: the stop state and reason, the counts per stage, and the log entry's URL. Do not paste the manifest, the preflight receipt or the log entry into the chat. They are on disk and the summary names them.
47
+
48
+ ## The schedule
49
+
50
+ `warden.sh --schedule` runs one watch in each repository listed in `~/.config/kryso/repos`, and `warden.sh --schedule --dry-run` runs each one's dry run. [warden.launchd.plist](warden.launchd.plist) is the launchd agent that starts a schedule every night. How a schedule reads its list, runs its watches and exits, how to fill and load the agent, what a schedule writes under `~/.local/state/kryso/`, and how a watch records who started it are in [scheduler.md](reference/scheduler.md).
51
+
52
+ ## The config
53
+
54
+ Each repository commits `.kryso/watch.json` beside its other kryso files. The watch reads `docs/agents/kryso.json`, its old place, where it is absent, until 3.0.0, with a warning. It is validated against [warden.schema.json](warden.schema.json), which also holds every default, so an absent file and an absent key resolve the same way. An invalid file stops the watch as `environment` before the preflight, naming the failing path, with nothing written to the tracker.
55
+
56
+ A repository writes only the keys it changes. This one sets a base, an area and a standing note, and takes the schema's defaults for the rest:
57
+
58
+ ```json
59
+ {
60
+ "base": "develop",
61
+ "areas": { "area:skills": ["skills/**"] },
62
+ "note": "keep each diff small"
63
+ }
64
+ ```
65
+
66
+ What each key means, the Deferred signal among them, and what the preflight checks are in [config.md](reference/config.md).
67
+
68
+ ## Answering the Decision report
69
+
70
+ The Decision report is the one open issue carrying the report label. Answer its items in comments on it, one answer per line, and the next watch applies the answers. The forms it reads, and how it applies them, are in [report.md](reference/report.md#answering).
71
+
72
+ ## What it may write
73
+
74
+ Every tracker write goes through `tracker_write` in [tracker.sh](tracker.sh). Its state lives under `.claude/kryso-watch/`, and the passes its shift starts follow `kryso`'s rules. What the guard lets through, what the watch never does, the state file, the lock and the Watch log are in [outputs.md](reference/outputs.md).
75
+
76
+ ## How a watch ends
77
+
78
+ | Stop | Exit | When |
79
+ | --- | --- | --- |
80
+ | `frontier-empty` | 0 | No stage found anything to act on |
81
+ | `complete` | 0 | Every stage finished what it found |
82
+ | `review-ready` | 0 | Something is left for a person, such as an open PR or a report item |
83
+ | `failed` | 1 | The shift failed. Settlement still runs after it. No other stage can fail |
84
+ | `rate-limited` | 2 | A stage hit a rate limit. The watch ends there, except after the shift, where settlement still runs, and the log still hears it |
85
+ | `environment` | 3 | A tool or a file of the install is missing, the repository, the schedule's list or the state cannot be read or written, the config is invalid, a lock is held, an isolated kryso run is working the repository, the preflight or the base fetch failed, a stage's environment check or the log write failed, or a stage body printed something other than one result. The stop line names the check, and so does the summary once the watch has a directory |
86
+
87
+ A dry run exits 0, or 3 on an `environment` stop. A usage error exits before any watch starts, as [config.md](reference/config.md#options) says, and a schedule exits as [scheduler.md](reference/scheduler.md) says.
88
+
89
+ ## Where the detail lives
90
+
91
+ | File | Read it when |
92
+ | --- | --- |
93
+ | [scheduler.md](reference/scheduler.md) | installing or changing the launchd agent, or reading a schedule's output |
94
+ | [config.md](reference/config.md) | writing `.kryso/watch.json`, or the preflight stopped a watch |
95
+ | [triage.md](reference/triage.md) | an issue was triaged, parked or left out, or a triage outcome was refused |
96
+ | [report.md](reference/report.md) | an answer was not applied, or an issue did not come back from the report |
97
+ | [shift.md](reference/shift.md) | an issue was not queued, the base rule parked one, or the shift stage stopped the watch |
98
+ | [settlement.md](reference/settlement.md) | an issue was closed, not closed, parked as superseded, or screened by the second reader |
99
+ | [outputs.md](reference/outputs.md) | a file in the watch directory, the state file, the lock or the Watch log needs explaining |
100
+ | [shim-limits.md](reference/shim-limits.md) | checking by hand what the tests cannot prove, before the first watch in a repository |
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/krysoworks/kryso/skills/kryso-watch/answer.schema.json",
4
+ "title": "the outcome one context returns for an issue whose decisions a person answered",
5
+ "description": "The context requests, the driver authorises. The driver writes the criteria into the issue body, posts the brief, and puts the issue back in the queue.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["brief", "acceptance_criteria", "reason"],
9
+ "properties": {
10
+ "brief": {
11
+ "description": "The agent brief as markdown, rewritten to follow the answers. Posted as a comment.",
12
+ "type": "string",
13
+ "minLength": 1
14
+ },
15
+ "acceptance_criteria": {
16
+ "description": "Every acceptance criterion, updated to follow the answers, one testable criterion per item. Written into the issue body.",
17
+ "type": "array",
18
+ "minItems": 1,
19
+ "items": { "type": "string" }
20
+ },
21
+ "reason": { "description": "One paragraph: what the answers changed.", "type": "string" }
22
+ }
23
+ }
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # base-refs.sh: the one rule for whether a commit or a pull request is on the base. Sourced,
3
+ # never run, by the stage bodies that let a context's citation authorise a close. A commit is
4
+ # on the base when it is an ancestor of the fetched base ref; a pull request is when it is
5
+ # merged and its merge commit is.
6
+
7
+ # ref_on_base <base-ref> <kind> <ref>: the commit or merged pull request on the base the ref
8
+ # names, as "commit <sha>" or "pull request #<n> (<merge sha>)", or nothing and status 1. The
9
+ # kind is commit, for a sha of 7 to 40 hex digits, or pr, for a ref whose first number is the
10
+ # pull request's.
11
+ ref_on_base() {
12
+ local base="$1" kind="$2" ref="$3" full pr oid n
13
+ case "$kind" in
14
+ commit)
15
+ [[ "$ref" =~ ^[0-9a-fA-F]{7,40}$ ]] || return 1
16
+ full="$(git rev-parse --verify --quiet "$ref^{commit}" 2>/dev/null)" || return 1
17
+ git merge-base --is-ancestor "$full" "$base" 2>/dev/null || return 1
18
+ echo "commit $full" ;;
19
+ pr)
20
+ n="$(grep -oE '[0-9]+' <<< "$ref" | head -1)"
21
+ [[ -n "$n" ]] || return 1
22
+ pr="$(gh pr view "$n" --json number,state,mergeCommit 2>/dev/null)" || return 1
23
+ [[ "$(jq -r .state <<< "$pr")" == MERGED ]] || return 1
24
+ oid="$(jq -r '.mergeCommit.oid // empty' <<< "$pr")"
25
+ [[ -n "$oid" ]] && git merge-base --is-ancestor "$oid" "$base" 2>/dev/null || return 1
26
+ echo "pull request #$n ($oid)" ;;
27
+ *) return 1 ;;
28
+ esac
29
+ }
30
+
31
+ # base_refs_in <base-ref> <text>: every commit and merged pull request on the base that free
32
+ # text names, one line each in ref_on_base's words, the commits first. A sha is 7 to 40 lowercase
33
+ # hex digits, and a pull request is a number after #, pull/ or "pr ". At most 20 shas and 10
34
+ # numbers are tried, so a long text costs a bounded number of reads.
35
+ base_refs_in() {
36
+ local base="$1" text="$2" sha n
37
+ for sha in $(grep -oE '[0-9a-f]{7,40}' <<< "$text" | sort -u | head -20); do
38
+ ref_on_base "$base" commit "$sha"
39
+ done
40
+ for n in $(grep -oiE '(#|pull/|pr )[0-9]+' <<< "$text" | grep -oE '[0-9]+' | sort -un | head -10); do
41
+ ref_on_base "$base" pr "$n"
42
+ done
43
+ return 0
44
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck disable=SC2034 # BOARD_WRITES, BOARD_SKIPPED and BOARD_ERR are read by the stage bodies that source this file
3
+ # board.sh: the one way a stage body sets a single-select field on an issue's cards. Sourced,
4
+ # never run, by the stage bodies that write to a board, after tracker.sh. board_set calls the
5
+ # body's write, the recorded tracker write each body keeps, so the body defines it before the
6
+ # first call.
7
+
8
+ # The project list, read once per stage on the first board_set that needs it.
9
+ BOARD_PROJECTS=""
10
+
11
+ # board_set <issue> <card-titles> <field>=<option>...: each named field set to the named
12
+ # option on every board the issue is a card on, the project, field, option and item ids read
13
+ # live. The titles are the boards the issue's cards are on, one a line, as the tracker lists
14
+ # them. A board whose fields hold none of the pairs is skipped before its items are read.
15
+ # Leaves the number of field writes in BOARD_WRITES and why each board or field was passed
16
+ # over in BOARD_SKIPPED, both empty when the issue is on no board. A failed read or a refused
17
+ # write leaves the reason in BOARD_ERR and returns 1. The writes go through the body's own
18
+ # write, so they are recorded with the rest of the stage's, and a body without one is refused
19
+ # before any read.
20
+ board_set() {
21
+ local n="$1" titles="$2" owner title number pid fields items item pair name value field option
22
+ local -a pairs=("${@:3}") edits=()
23
+ BOARD_WRITES=0; BOARD_SKIPPED=(); BOARD_ERR=""
24
+ [[ -n "$titles" ]] || return 0
25
+ declare -F write >/dev/null || { BOARD_ERR="board.sh needs the stage body's write function"; return 1; }
26
+ owner="$(git remote get-url origin 2>/dev/null | sed -nE 's#.*github\.com[:/]([^/]+)/.*#\1#p')"
27
+ [[ -n "$BOARD_PROJECTS" ]] || BOARD_PROJECTS="$(gh project list --owner "$owner" --format json 2>&1)" \
28
+ || { BOARD_ERR="cannot list the projects: $(head -1 <<< "$BOARD_PROJECTS")"; BOARD_PROJECTS=""; return 1; }
29
+ while IFS= read -r title; do
30
+ number=""; pid=""
31
+ IFS=$'\t' read -r number pid < <(jq -r --arg t "$title" \
32
+ '[.projects[] | select(.title == $t)] | first // empty | "\(.number)\t\(.id)"' <<< "$BOARD_PROJECTS")
33
+ [[ -n "$number" ]] || { BOARD_SKIPPED+=("no project titled $title"); continue; }
34
+ fields="$(gh project field-list "$number" --owner "$owner" --format json 2>&1)" \
35
+ || { BOARD_ERR="cannot read the fields of $title: $(head -1 <<< "$fields")"; return 1; }
36
+ # Each pair as "<name>\t<field id>\t<option id>", once the board is known to hold it.
37
+ edits=()
38
+ for pair in ${pairs[@]+"${pairs[@]}"}; do
39
+ name="${pair%%=*}"; value="${pair#*=}"
40
+ field="$(jq -r --arg f "$name" '.fields[] | select(.name == $f and (.options | type) == "array") | .id' <<< "$fields" | head -1)"
41
+ [[ -n "$field" ]] || { BOARD_SKIPPED+=("$title has no $name field"); continue; }
42
+ option="$(jq -r --arg f "$name" --arg v "$value" '.fields[] | select(.name == $f) | .options[] | select(.name == $v) | .id' <<< "$fields" | head -1)"
43
+ [[ -n "$option" ]] || { BOARD_SKIPPED+=("$title's $name field has no $value option"); continue; }
44
+ edits+=("$name"$'\t'"$field"$'\t'"$option")
45
+ done
46
+ [[ "${#edits[@]}" -gt 0 ]] || continue
47
+ items="$(gh project item-list "$number" --owner "$owner" --format json --limit 1000 2>&1)" \
48
+ || { BOARD_ERR="cannot read the items of $title: $(head -1 <<< "$items")"; return 1; }
49
+ item="$(jq -r --argjson n "$n" '.items[] | select(.content.number == $n) | .id' <<< "$items" | head -1)"
50
+ [[ -n "$item" ]] || { BOARD_SKIPPED+=("#$n is not an item on $title"); continue; }
51
+ for pair in "${edits[@]}"; do
52
+ IFS=$'\t' read -r name field option <<< "$pair"
53
+ write project item-edit --project-id "$pid" --id "$item" --field-id "$field" --single-select-option-id "$option" \
54
+ || { BOARD_ERR="the $name write on $title was refused"; return 1; }
55
+ BOARD_WRITES=$(( BOARD_WRITES + 1 ))
56
+ done
57
+ done <<< "$titles"
58
+ }
@@ -0,0 +1,23 @@
1
+ # The config and the preflight
2
+
3
+ Every key of `.kryso/watch.json`, what the preflight checks before a watch spends anything, and the options `warden.sh` takes and refuses.
4
+
5
+ ## The config
6
+
7
+ The file, its schema and an example are in [SKILL.md](../SKILL.md#the-config). Until 3.0.0 a repository that still commits the file under its old name, `docs/agents/warden.json`, is read from it with a warning, and the watch never renames a tracked file for you.
8
+
9
+ The base defaults to the repository's default branch, read from GitHub or from `origin/HEAD`, and is always read from the fetched remote. The driver never checks out or edits the main working tree. The profile is `kryso-shift`'s execution profile. The report stage batches the calls triage could not make, so it runs when triage does, and `caps.triage` also caps how many answered issues it puts back in the queue a watch.
10
+
11
+ The `deferred` label and a card in a board's Deferred column are the one Deferred signal: an issue carrying either is invisible to triage, the shift and settlement until a person brings it back. The report stage does not read the signal, so an answer to a Deferred issue's report item is applied like any other, and the shift still leaves the issue out. Triage's P0, P1 and P2 are the first three entries of `priority_order`, so a board whose options are named otherwise lists them there. The areas map is empty until a repository fills it: each key is a label, each value the path globs it owns, and Settlement reads it to reach issues no commit cites. `**` crosses directories, `*` and `?` stay inside one, and `**/` also matches no directory at all. `settlement.jev_floor`, 0 to 1 and 0.1 by default, is the probability below which the second reader screens a settlement candidate, applied to whichever backend answered. A floor of 0 orders the candidates by probability and screens none.
12
+
13
+ ## The preflight
14
+
15
+ The preflight first stops the watch as `environment`, check `isolated`, when a `kryso --isolate docker` run is working the repository, because that run holds its locks inside Docker Desktop's VM where this host cannot see them ([playbook ADR 0039](../../../docs/adr/0039-isolated-runs-are-guarded-by-a-pid-file-because-kernel-locks-do-not-cross-docker-desktops-vm.md)). Then it runs `ship-loop.sh --dry-run` under the configured profile and shift cap, so `kryso-shift`'s checks run unchanged: `gh` auth and the `project` scope, the host login for the profile, the ready label, the print-mode permission warnings, and the CI runner and queue health. A budget the config names is passed on too, so a profile with no dollar cap refuses it in `kryso-shift`'s words. Then the watch requires a GitHub remote and the configured `deferred`, report and log labels. Any failure is an `environment` stop that names the check, and `kryso-shift`'s warnings are passed on without stopping the watch.
16
+
17
+ ## Options
18
+
19
+ `--second-reader off|on|jev|llm` sets the second reader for one run, over the repository's `kryso.secondReader`. The value is exported as `PLAYBOOK_SECOND_READER`, the variable `kryso-shift`'s reader already reads, so every stage body and every `ship-loop.sh` call in the watch sees it, and a schedule hands it to each watch. Anything else is refused as exit 64 before a watch starts.
20
+
21
+ `--read-only` makes a dry run change nothing at all, so `kryso doctor` can run it ([playbook ADR 0044](../../../docs/adr/0044-kryso-doctor-only-reads-and-kryso-cleanup-removes-evidence-only-when-asked-by-name.md)). It reads the base on origin with `git ls-remote` instead of fetching it, names a stale isolation file instead of removing it, and runs the stages with the second reader off, so nothing is spent. The stages read `refs/remotes/origin/<base>` as it is on this machine, with a warning when origin's tip differs. A base this machine never fetched has no copy to read, so the shift and settlement dry runs are skipped with a warning.
22
+
23
+ `warden.sh` exits 64, which is no stop, on an option it does not know, `--repo`, `--schedule-id` or `--second-reader` with no value, `--schedule` with `--repo` or `--schedule-id`, `--by-scheduler` with neither `--schedule` nor `--schedule-id`, `--read-only` without `--dry-run`, or a schedule id that is not a UTC timestamp like `20261004T020000Z`, with or without a numeric suffix such as `-2`. Each is refused before any watch starts.
@@ -0,0 +1,30 @@
1
+ # What a watch leaves and may write
2
+
3
+ The state a watch keeps on disk, the Watch log, and every write it can make to the tracker.
4
+
5
+ ## What it leaves
6
+
7
+ Durable state lives under `.claude/kryso-watch/`, excluded through the common git directory's `info/exclude` the way `.claude/kryso/` is. A watch moves the `.claude/warden/` an older warden left there first, and leaves a link at the old name. It holds three things:
8
+
9
+ - `state.json`: the schema version, the last watch's id, stop and exit, the settled branch and sha with the issues read against the range that starts there, and the settle backlog. Nothing the tracker already holds.
10
+ - `lock`: the pid of the watch holding the repository. While it exists, a second watch ends as `environment` with nothing written anywhere. A lock whose pid has died still holds, and the stop says so. Clearing it automatically would race a second watch clearing it too, so a person removes the file.
11
+ - One directory per watch, named by its start time, holding `manifest.json`, `preflight.log`, `log-entry.md` and `summary.json`, and once the stages have run, `triage/`, any `report-items.json`, `report/`, `shift.json` and `shift/`, and `settle/`, where the second reader's request log and the LLM backend's result sit beside the settlement records. Each stage that ran also leaves `stage-<stage>.log`, its body's stderr, which the summary lists under `stage_logs`.
12
+
13
+ The manifest is written before the first stage runs: the schedule that started the watch, or `null`, the resolved config, the base sha at the start, which stages run and which are skipped, and one section per stage that its slice fills. The summary is bounded: the stop state, reason, exit code and failing check, the schedule that started the watch, or `null`, the counts per stage, the issues each stage touched with their new state, the report items added and answers applied, the pull requests waiting for review, the log issue and comment, and the paths to every artefact, the shift's pointer and summary among them. It holds no transcript, result text or log tail.
14
+
15
+ ## The Watch log
16
+
17
+ The Watch log is one open issue per repository carrying the log label, found live by the label and created on first use with the title Watch log. One opened under its old title, Warden log, keeps its number. Each watch that got past the preflight and the base fetch leaves exactly one comment on it: the stop state and reason, how the watch started, the counts per stage, and the watch directory. That includes an `environment` stop raised inside a stage. An `environment` stop at the config, the lock, the preflight or the base fetch writes nothing to the tracker, and a log comment that does not land is itself an `environment` stop, with the stages' own stop in the reason.
18
+
19
+ ## What it may write
20
+
21
+ Every tracker write goes through one function, `tracker_write` in [tracker.sh](../tracker.sh), which the driver and each stage body source. Before `gh` runs, it refuses anything but a comment, a label or body edit, a close that carries a comment, a board item edit, and a new issue carrying the report or log label, so no merge, push, delete, assignment or comment edit can reach GitHub through it. The guard checks the kind of write, and the stage bodies keep within this list:
22
+
23
+ - Labels, added and removed: a triage state, `area:` labels the repository has, `needs-info` on an issue parked on the report, and `wontfix` on a confirmed out-of-scope close.
24
+ - Comments: triage notes and briefs, parking comments, answers copied from the report, out-of-scope hand-offs, close comments, the report's own comments and the log entries. It never edits or deletes a comment, its own included.
25
+ - An issue's body: the acceptance criteria of an issue triaged or released from the report, and the report's items.
26
+ - A close that carries a comment: a `wontfix` with its evidence, a confirmed out-of-scope `wontfix` linking its ledger file, a settled issue with its evidence, and a report whose every item is applied.
27
+ - Board edits: Priority and Size after triage, and a settled issue's card moved to Done.
28
+ - A new issue, only when it carries the report label or the log label.
29
+
30
+ On disk, a watch writes under `.claude/kryso-watch/` in the repository, adds that directory to the common git directory's `info/exclude` once, and moves `refs/remotes/origin/<base>` with its fetch, as a dry run does too, except one with `--read-only`, which fetches nothing. A schedule also writes under `~/.local/state/kryso/`. Both directories are described above. The watch never merges, pushes, force-pushes, deletes, assigns, edits another author's comment, checks out or edits the main working tree, or reads or writes host or shell configuration. The passes its shift starts are `kryso-shift`'s, with their evidence under `.claude/kryso/`: they cut worktrees, push branches and open pull requests under `kryso`'s rules, which merge into a base other than the default branch and leave a pull request on the default branch open for a person.
@@ -0,0 +1,29 @@
1
+ # The Decision report
2
+
3
+ The one tracker issue where the calls a watch could not make wait for a person: how items are posted, how answers are read, and how an answered issue goes back in the queue.
4
+
5
+ The Decision report is the open issue carrying the report label, found live by the label on every watch and never by a number an earlier watch kept. At most one is open. The stage runs after triage and before the shift, so an issue answered overnight can enter the same watch's queue. [stages/report.sh](../stages/report.sh) is its body, and it starts no context unless an answer needs one.
6
+
7
+ Each item sits under a numbered heading, `Q1`, `Q2` and on, with the parked issue's link, the question and the reason a person has to make the call, lettered options each with its consequence, and the recommended letter. A hidden marker under the heading carries the item whole, so the body is the report's only state. A watch whose triage parked an issue appends its items to the open report, numbering on from the highest number there, and posts one comment naming how many it added, so one notification arrives. With no report open it opens one, and the new issue is that notification. Numbers are never reused within a report. Once the items are posted, each parked issue gets a comment whose marker names the report and the items' numbers, `<!-- warden:parked watch=<id> items=13.1,13.2 report=61 q=1,2 -->`, since the watch edits no comment it posted before. An issue waiting on the report stays `needs-info`: a report item is not a sixth triage role.
8
+
9
+ ## Answering
10
+
11
+ A person answers in comments on the report, one answer per line:
12
+
13
+ - `yes to all` takes the recommended letter for every item that is still unanswered and was on the report when the comment was written.
14
+ - `Q3: b` or `3: b` answers one item.
15
+ - `Q3: other` followed by words, on the same line or the lines after it, records the words as the answer.
16
+
17
+ Comments are read in order and a later one overrides an earlier one, across watches too, until the item's issue is back in the queue. After that a new answer to it is refused and the log says so. Only a person's comments count. The watch posts as the person's own login, so a comment is an agent's when it carries a `warden:` marker or opens with any agent header, the triage disclaimer or another procedure's, and a bot's login never counts either. [The convention](https://github.com/jv-k/engineering-playbook/blob/main/conventions/agent-friendly-repos.md) has the header, and [playbook ADR 0030](../../../docs/adr/0030-a-persons-comment-is-one-with-no-agent-header-and-a-triage-note-keeps-the-full-line.md) the reason the two reads differ. Each watch reads only the comments made since the last watch read the report. Anything else is left alone and the item stays open: a letter that is not an option, a number with no item, `other` with no words after it, a line like `Q3 b` that names an item in some other form, or a comment with no answer in it. The log entry names each of these.
18
+
19
+ An answered item is marked answered in the report body, and its answer is posted as a comment on its parked issue. Once every item an issue waits on is answered, that issue gets one fresh context through `kryso-shift`'s runner, running the triage skill with the answers and [answer.schema.json](../answer.schema.json) as its outcome schema. It rewrites the brief and the acceptance criteria to follow the answers. The driver validates the outcome, writes the criteria into the issue body, posts the brief with a release marker, and moves the issue from `needs-info` to `ready-for-agent`. A refused outcome leaves the issue parked and the next watch tries again. A closed issue is left as it is.
20
+
21
+ An item that carries an out-of-scope file, answered with `close it as wontfix`, is the exception: no context starts and the state label stays. The issue gets a hand-off comment naming the file and ending in `<!-- warden:wontfix-confirmed report=61 q=4 file=.out-of-scope/<name>.md -->`, the item is marked applied, and settlement closes the issue. The hand-off costs no context, so `caps.triage` does not count it. Any other answer to that item releases the issue the usual way. Once every item is answered and applied, the report is closed with a closing comment, and the next unanswered decision opens a new one, numbered from `Q1`. A watch that added no items posts nothing else on the report.
22
+
23
+ ## The shift's and settlement's items
24
+
25
+ The shift's base rule and settlement park issues on the report too, and both run after the report stage, so once settlement is done the report body runs once more in its post mode: it posts the items the two left, appended to the open report or as a new one, with one comment on the report and the marker on each parked issue, and applies no answers. It runs whenever they left items, a failed or rate-limited shift included. Those items join the report stage's row in the manifest, the summary and the log entry, whichever switches were on, since the report is the one place for the calls a watch cannot make.
26
+
27
+ ## What it leaves
28
+
29
+ The watch directory's `report/` holds the answers parsed and what could not be read (`answers.json`), the answers applied (`applied.json`), the items added (`added.json`), and per released issue the host's result and the driver's record. The manifest, the summary and the log entry name the items added and the answers applied.
@@ -0,0 +1,32 @@
1
+ # The scheduler
2
+
3
+ How `warden.sh --schedule` runs a watch in each listed repository, how a watch records who started it, and how to install the launchd agent that starts a schedule every night.
4
+
5
+ `warden.sh --schedule` runs one Schedule, whether the scheduler's clock starts it or a person does. It reads the repositories from `~/.config/kryso/repos` (under `$XDG_CONFIG_HOME` when that is set), one absolute path per line, where blank lines and lines starting with `#` are skipped and a leading `~/` is the home directory. Until 3.0.0 a list only at its old path, `~/.config/warden/repos`, is read with a warning, and a schedule moves an old `~/.local/state/warden/` to the new state directory, leaving a link at the old name. It runs one watch in each, in the file's order, one after another, under one scheduler lock, for the reason [playbook ADR 0004](../../../docs/adr/0004-warden-is-a-scheduled-driver-over-the-tracker.md) gives. A missing or empty list, or a relative path in it, stops the schedule as `environment` before any watch starts.
6
+
7
+ Each watch is `warden.sh --repo <path>`, so the repository's own config, preflight and lock apply unchanged. Two watches never run in one repository at once: whichever starts second, the schedule's or one a person started, ends as `environment` with nothing written, and the schedule goes on to its next repository. A watch that stops early never stops the schedule: the next repository runs, and the schedule exits with the highest exit code among its repositories. A held scheduler lock exits as `environment` with nothing started, and like the per-repo lock it holds after its process dies, until a person removes the file.
8
+
9
+ The scheduler prints one line per repository, `warden: schedule: <path>: stop <stop>, exit <code>, watch <dir>, started by <who>`, where the watch directory is `none` for a stop before the watch had one, and closes with `warden: schedule: exit <code>, the highest of <n> repositories, started by <who>`. `<who>` is `the scheduler` or `a person`, as [How a watch started](#how-a-watch-started) says. Outside the repositories it writes only under `~/.local/state/kryso/` (or `$XDG_STATE_HOME/kryso/`): the lock, and one directory per schedule under `runs/` holding each watch's own output as `<n>-<name>.log`. Each schedule that takes the lock keeps the last 30 schedules' directories, its own among them, and removes the older ones, leaving any name under `runs/` that is not a schedule's id. It also rotates `launchd.log` once that reaches 1 MB: the file is copied to `launchd.log.1`, over the rotation before, and emptied in place, because launchd holds it open. Each says what it did in one line, `warden: schedule: removed <n> schedule directories older than the last 30 in <dir>` and `warden: schedule: rotated <file> to launchd.log.1 at <bytes> bytes`, and says nothing when there was nothing to do. A dry run does neither.
10
+
11
+ `warden.sh --schedule --dry-run` lists the repositories in order and runs each one's dry run, printing it as it would print alone. It takes no lock, writes nothing, and exits with the highest code among the dry runs. Its lines carry the same `started by <who>`, and each repository's dry run prints the `start:` line its watch would record, with the id a schedule started at that moment would take.
12
+
13
+ ## How a watch started
14
+
15
+ Every watch records how it started, in three cases: a schedule the scheduler started, a schedule a person ran by hand, or no schedule at all. The record is the `schedule` key of the watch's `manifest.json` and `summary.json`, `{id, started_by}` with `started_by` either `scheduler` or `person`, or `null` for a watch started directly. The watch's `start:` line and its Watch log entry say the same in words. The schedule's id is the name of its directory under `runs/` in the state directory, so the entry names the place the watch's own log is kept. The schedule's own lines end with who started it. None of this changes a stage, a cap or a stop: a watch does the same work whoever starts it.
16
+
17
+ "The scheduler" means the installed launchd agent, and the only thing that marks a schedule as its own is the `--by-scheduler` argument in the agent's `ProgramArguments`. A schedule run from a terminal leaves it off, so it is recorded as started by a person. What the mark proves is that the agent's arguments started the schedule. It cannot say whether the clock fired or someone ran `launchctl kickstart`, since launchd runs the same arguments for both, and it does not try to detect the calendar firing, which comes late, on wake, when the machine was asleep at the hour. Nor is it a signature: someone who types `--by-scheduler` themselves is recorded as the scheduler. A schedule hands each watch `--schedule-id <id>`, with `--by-scheduler` when it carries the mark. Neither is for a watch started by hand.
18
+
19
+ ## Installing the scheduler
20
+
21
+ [warden.launchd.plist](../warden.launchd.plist) is a launchd user agent that starts a schedule, `warden.sh --schedule --by-scheduler`, at 02:00 every night under `caffeinate -i -s`, which keeps the machine from idle sleep, and from system sleep on mains power, until the schedule exits. It does not wake a sleeping machine: if the machine is asleep at 02:00, launchd runs the job once when it next wakes. Schedule a wake with `pmset repeat wakeorpoweron` if it has to run on time. Fill the template's three placeholders and load it:
22
+
23
+ ```sh
24
+ warden="$HOME/.agents/skills/kryso-watch/warden.sh" # the warden.sh the scheduler runs
25
+ state="${XDG_STATE_HOME:-$HOME/.local/state}/kryso"
26
+ mkdir -p "$state" ~/Library/LaunchAgents
27
+ sed -e "s#@WARDEN@#$warden#" -e "s#@PATH@#$PATH#" -e "s#@STATE@#$state#" \
28
+ "$(dirname "$warden")/warden.launchd.plist" > ~/Library/LaunchAgents/io.github.krysoworks.kryso-watch.plist
29
+ launchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/io.github.krysoworks.kryso-watch.plist
30
+ ```
31
+
32
+ Run the `sed` from the shell whose `PATH` finds `gh`, `jq`, `git` and the model CLIs, because launchd's own is `/usr/bin:/bin:/usr/sbin:/sbin`. To change the hour, edit `StartCalendarInterval` in the installed file and load it again. `launchctl bootout "gui/$(id -u)/io.github.krysoworks.kryso-watch"` removes it. The agent's own output goes to `launchd.log` in the state directory, and each watch's to its log in the schedule's directory.
@@ -0,0 +1,29 @@
1
+ # Settlement
2
+
3
+ The last stage: how candidates are chosen from the base's new commits, how the second reader screens them, and the rule that closes an issue.
4
+
5
+ Settlement is the check that finds open issues the base already satisfies and closes them with the evidence. It runs last. The range read runs only when the fetched base's sha differs from the settled sha in the state file, and the driver never checks the base out: the range is read from the fetched ref. [stages/settle.sh](../stages/settle.sh) is its body, and the shape is [playbook ADR 0004](../../../docs/adr/0004-warden-is-a-scheduled-driver-over-the-tracker.md)'s: the candidates and the close rule are the driver's, and one fresh context per candidate reads and returns a verdict. It is not `kryso`'s reconcile, which is that skill's stage 5 over one pull request. Settlement reads a range of the base against the tracker.
6
+
7
+ The candidates are chosen in shell. The range is the settled sha to the base as it stands: its commits with their messages, the paths it touched, and the merged pull requests whose merge commit is in it, listed by `gh pr list --state merged --base`. An open issue is reached when a commit message or a merged pull request in the range cites it by number, or when it carries a label in the config's `areas` map whose globs meet a touched path. Reached issues that are the Watch log or the Decision report, Deferred, parked on a report item, or already read against this range are excluded with their reason. The rest go oldest first, the backlog the last watch carried ahead of them, and `caps.settle` takes the first of them. The manifest records each candidate with the citation or path match that selected it, and each exclusion.
8
+
9
+ The `areas` labels are the only path match. A board's Component field is not read, which [playbook ADR 0016](../../../docs/adr/0016-settlement-matches-paths-by-area-labels-not-the-board-component-field.md) records as a narrowing of playbook ADR 0004.
10
+
11
+ ## Confirmed out-of-scope closes
12
+
13
+ Before it reads the settled sha, settlement closes the issues the report handed over, on every watch, moved base or not. An open issue whose last parking, release, confirmation or confirmed close comment is a `warden:wontfix-confirmed` marker is labelled `wontfix` and closed with a comment linking the marker's file at the base's sha. The Watch log, the report and Deferred issues are left out, and an issue a person reopens after that close is not closed again. When the base does not have that file, nothing is closed. The issue is parked the way a superseded verdict parks one, with one report item, `#n's ledger file is gone: release it, or close it by hand?`, recommending `release it`, and it is recorded as unproven, which counts as left for a person. The item carries no file, so either answer releases the issue with the answer on it and none hands it back to settlement. The watch closes nothing on it, and `close it by hand` leaves the close to a person, and the parking marker keeps a later watch from asking again. No context starts for either. The watch never adds the issue under the file's "Prior requests": that is a person's step, and the close comment says so. The dry run prints each close it would make and each it cannot, with the report item it would park instead.
14
+
15
+ ## The second reader screens the candidates
16
+
17
+ When the repository's Second reader is on (`kryso.secondReader`, or `--second-reader` for the run), settlement asks it once per watch, after the candidates are chosen and before any context starts, through `kryso-shift`'s `reader.sh`. The ask carries the range as the contexts see it, the commit subjects, the titles of the merged pull requests and the touched paths with no diff, and per candidate its title, body and numbered acceptance criteria, and it asks one boolean question per issue: do the range's commits and merged pull requests satisfy every acceptance criterion? The reader batches the questions in series when the state is over its budget, and Jev's key comes from `AI_GATEWAY_API_KEY` or, when that is unset, from the macOS Keychain service `kryso.jevKeychain` names, since a watch launchd starts sources no profile. The key is held in the shell and handed to `curl` on stdin, and it reaches no log, argv or file. [Playbook ADR 0017](../../../docs/adr/0017-a-second-reader-is-opt-in-answers-through-jev-first-and-decides-nothing.md) records the reader's decision and its limits.
18
+
19
+ A candidate whose probability is below `settlement.jev_floor` is screened: recorded in the manifest and the saved record with its probability and backend, read by no context, and counted as read when the settled sha advances. Nothing is written for it, since only a context's verdict authorises a close or a report item, and the reader never adds either. The rest are ordered by probability, highest first, the previous order breaking ties, and then `caps.settle` takes the first of them as before. Jev failing or skipping hands the same questions to the LLM backend, and both failing sends every candidate to a context in the oldest-first order with the reader's failure recorded. The summary, the log entry and the dry run count the screened candidates and name the backend and the cost, and the request log is `settle/reader.jsonl` in the watch directory.
20
+
21
+ Each candidate's context is started the way triage starts one, through `kryso-shift`'s runner under the configured profile with [settle.schema.json](../settle.schema.json) as the outcome schema. Its prompt carries the issue with its acceptance criteria, numbered as the body lists them, and its comments, the range's commit list and touched paths, and the merged pull requests in the range, bounded to 300 commits and 500 paths with a `git` command for the rest. It is told to read only and never to ask a person. The outcome is a verdict, `shipped`, `superseded` or `open`, with evidence rows each naming a criterion by its words or its number, a kind of `commit` or `pr` and a ref, the unmet criteria and a reason. The saved prompt sits beside the host's result under the watch directory's `settle/`.
22
+
23
+ The driver closes an issue only when the verdict is `shipped`, every acceptance criterion in the body has an evidence row, and every row's ref resolves to a commit that is an ancestor of the fetched base or a pull request merged into it. The close comment lists each criterion with the commit or pull request that satisfies it and ends in a marker naming the range, and the card moves to Done on each board the issue is a card on, with the field, option and item ids read live, as a no-op on a repository without a board or a board without a Status field or a Done option. Anything short of that rule is recorded as unproven, with the criterion that has no row or the ref that is on no base, and nothing is written: a wrong close needs a wrong citation, so a verdict alone closes nothing. An issue with no acceptance criteria section cannot be closed this way either.
24
+
25
+ A `superseded` verdict is a person's call. The issue is parked the way triage parks one: `needs-info`, a comment with the verdict and the marker, and one report item, `Close #n as superseded?`, recommending `wontfix`. An `open` verdict records the unmet criteria and changes nothing. An outcome that fails the schema is refused, and the issue is recorded as read.
26
+
27
+ The settled sha advances only once every candidate for a range has been read. A cap that leaves candidates unread carries them to the settle backlog in the state file, with the settled sha where it was and the issues read against it, so the next watch reads the same range again, starts with the backlog and skips what was read. A rate limit ends the watch the same way, with the unread candidates carried. On a first watch, or when the settled sha is on another branch or is not in the repository, the watch fixes the settled sha at the base as it stands and reads nothing, since a range before it has no start.
28
+
29
+ The summary and the log entry name each candidate with its verdict, the range read, the backlog carried and what the second reader did. Superseded and unproven issues count as left for a person, so a watch that found either stops `review-ready`, and a screened issue does not. The dry run prints the range, the candidates with what selected each and, with the reader on, their probabilities, the screened candidates, and every exclusion.
@@ -0,0 +1,44 @@
1
+ # The shift
2
+
3
+ The one stage that ships: how the queue is built, the base rule, the `ship-loop.sh` command it runs, and what it reads back.
4
+
5
+ The shift is the one stage that ships, and it starts no model context of its own. [stages/shift.sh](../stages/shift.sh) builds the queue in shell and hands it to `kryso-shift` as a Workset, so the watch's one Shift runs one Pass per queued issue, each in a fresh process of its own, the way `kryso-shift` runs any shift. It runs after the report stage, so an issue a person's answer put back in the queue overnight can ship in the same watch.
6
+
7
+ ## The queue
8
+
9
+ The candidates are the open issues carrying the `ready-for-agent` label, read live, and [`kryso`'s stage-1 candidate rule](../../kryso/reference/stage-1-claim.md) drops the ones a pass could not take, each with its reason. Each pass then runs [stage 1's gates](../../kryso/reference/stage-1-claim.md#gates) itself, and the shift names its queue to `kryso-shift` with `--issues`, so a pass a gate refuses labels the issue `agent:blocked` and says why on it. The filter applies gate 3 before that, so a watch does not name an issue the pass would refuse there, and a later watch does not post a second note on it. An open pull request that closes the issue, through GitHub's link or a closing keyword before `#<n>` in its body, keeps the issue out when a collaborator opened it, whatever its branch is called. A collaborator check gh cannot answer keeps it out as well, and so does a pull request that names no author, because the pass would refuse on either and write the same note. The gate reads every open pull request, as the pass does, up to the pass's limit of 1000. More than that stops the shift, because the pass would refuse every issue on it. A wayfinder child is read two ways, as an issue whose parent carries `wayfinder:map` or one carrying a `wayfinder:` type label, which is how [issue-tracker.md](../../../docs/agents/issue-tracker.md) marks a map's ticket where sub-issues are off. The watch then drops its own log and report issues, Deferred issues and issues parked on a report item. It also drops any issue a commit message or a merged pull request cites by number in the unsettled range, the settled sha in the state file to the fetched base, which is read the way settlement reads it. Settlement runs after the shift and reads those issues next, and a pass on one could repeat work the base already has. With no settled sha on this base there is no range and nothing is dropped for it. Every exclusion goes into the manifest with its reason.
10
+
11
+ What survives is ordered by the board's Priority field, in the order `board.priority_order` gives, with an unset value or one outside that list last, then oldest created first. The values are read live off each board a surviving issue is a card on. A queue with no card on any board is ordered by age alone, and no board is read. `caps.shift` takes the head of that order, and the rest are excluded as over the cap, so a later watch reaches them.
12
+
13
+ ## The base rule
14
+
15
+ The shift works on the configured base alone, so an issue that points anywhere else is not queued. It trips the rule in two ways. Its body or its brief, the latest comment with an "Agent brief" line, names a branch other than the base on a `Base branch: <name>` or `Base: <name>` line, the name in backticks or alone on the line. Or one of its closed blockers has a pull request that is still open or was merged somewhere other than the base, where a blocker's pull request is one whose branch ends in `-<blocker>` or whose title or body closes it with one of GitHub's closing keywords. A pull request closed without a merge carries nothing and is passed over. The pull requests are read once a watch, the newest 500.
16
+
17
+ An issue the rule holds becomes a report item and is parked the way settlement parks one: its state label moves to `needs-info`, one comment names what held it and ends in the parking marker, and one item, `<n>.base`, asks "Work #n on the base?" with two options. Holding it for a person is the recommendation, and working it on the base anyway is the other. When a person answers and the report puts the issue back in the queue, the shift reads the answer off the issue's answer comment. Work it on the base, and the rule no longer holds it. Any other answer leaves it out of the queue with the answer as the reason for as long as the rule would still hold it, so a later watch never asks the same question twice.
18
+
19
+ ## The command
20
+
21
+ The shift runs `ship-loop.sh` once:
22
+
23
+ ```sh
24
+ bash .agents/skills/kryso-shift/ship-loop.sh --issues "<queue>" --base <base> --profile <profile> \
25
+ --max <caps.shift> --budget <caps.budget> --note "<note>" --sweeps <caps.sweeps>
26
+ ```
27
+
28
+ `--budget` is passed only where the profile's host bills by the dollar, which is Claude and not Codex. `--note` is passed only when the config has one, and `--sweeps` only when the queue holds two or more issues, because `kryso-shift` refuses sweeps over a workset of one. An empty queue skips the shift: nothing runs, and the manifest and the summary say why.
29
+
30
+ Stacking is off: `--stack` is never passed, so a dependant waits for a person to merge its blocker's pull request, and the base rule parks one whose blocker's work is not on the base yet. Nothing in this stage passes `--stack`, so turning stacking on is a reviewed change to this stage.
31
+
32
+ ## What the watch reads
33
+
34
+ Before `kryso-shift` starts, `shift.json` in the watch directory records the queue and the exact command. `kryso-shift`'s own output goes to `shift/ship-loop.log`, and the closing line [playbook ADR 0006](../../../docs/adr/0006-styled-output-is-a-gum-layer-over-frozen-plain-output.md) freezes for a background run names its `summary.json`, so `shift.json` then gains the exit code and the pointer to the shift's own directory under `.claude/kryso/`. The watch reads that exit code and that summary, and never a pass's saved result or a line of the log.
35
+
36
+ | The shift | The shift stage | The watch |
37
+ | --- | --- | --- |
38
+ | exit 0 with a summary | `ran`, with the outcomes the summary's rows give | goes on |
39
+ | exit 1 with a summary | `failed` | stops `failed`, exit 1, after settlement runs |
40
+ | exit 2 with a summary | `rate-limited` | stops `rate-limited`, exit 2, after settlement runs |
41
+ | no summary, whatever the exit | `environment`, check `shift`: `kryso-shift` stopped in its own preflight | stops `environment` there |
42
+ | any other exit | `environment`, check `shift` | stops `environment` there |
43
+
44
+ The summary and the log entry name each queued issue with its outcome and pull request, one the summary has no row for as `not-reached`, and the pull requests waiting for review. What `kryso-shift`'s summary leaves for a person counts as left for a person here too, its pull requests waiting for review and its exceptions, and so does each issue the base rule parked, so a shift that left either stops `review-ready`. An issue not reached is not left for anyone: it is still `ready-for-agent`, and the next watch queues it.
@@ -0,0 +1,22 @@
1
+ # What the shim tests cannot prove
2
+
3
+ What `test-warden.sh` covers, and the checks by hand for what it cannot.
4
+
5
+ `pnpm test` runs [test-warden.sh](../test-warden.sh) against shim `claude`, `codex` and `gh` binaries with the real `ship-loop.sh` beneath the driver, a sandbox repository and a bare origin. It observes the exit code, the watch directory's files, the host commands the shims were started with, and the tracker writes the `gh` shim recorded. Triage runs its real body over a fixture tracker with canned outcomes, under both profiles. The report runs its real body over a fixture report whose thread holds every answer form, a malformed one, the watch's own comment and an AI comment. Settlement runs its real body over a commit range on the bare origin whose messages cite issues and whose paths meet an areas map, with one pull request merged in the range and one outside it, and canned outcomes whose evidence resolves or does not. The shift runs its real body with the real `ship-loop.sh` beneath it, over a fixture tracker with board Priority values, a range with citations, merged, open and abandoned pull requests, and issues that name another branch, and canned passes that ship, park, fail and hit a rate limit under both profiles. The stop states a real body is hard to drive to, such as a body that prints something other than one result, are driven by fixture bodies in an installed copy of the skill.
6
+
7
+ It cannot prove the items below. Each says what the shim stands in for, what a real failure looks like, and the check by hand that covers it. Most of the checks are a dry run before the first watch or a read of the first watch's evidence.
8
+
9
+ - A live login. The host login and the `gh` auth and `project` scope are `kryso-shift`'s checks, run here against shims that answer yes or no. A real expired token, a missing scope or a Codex login on another account is read live, and shows up as an `environment` stop whose check is `preflight`, naming `kryso-shift`'s failed check. Check: run `warden.sh --dry-run` in each listed repository from the shell whose `PATH` went into the launchd template, and again after any login changes. Its preflight runs the same checks against the real host and `gh`.
10
+ - A real board's field names. The shim's board has fields named `Priority` and `Size` with options named `P0` and `M`, and a `Status` field with a `Done` option. A board named otherwise shows up as an ignored write, or a card move that did not happen, with its reason in the saved result. Check: before the first watch, compare `gh project field-list <number> --owner <owner> --format json` with the config's `board`: a single-select field for each of `priority_field` and `size_field`, the Priority options that `priority_order` lists, Size options XS to XL, and a `Status` field with a `Done` option. After the first watch, the board record in each triaged issue's `triage/<n>.json` says it was written, or names the field or option it could not find.
11
+ - A real answer thread. The fixture's comments are written the way the forms above say. What a person types on a phone, and how GitHub stores it, shows up in `report/answers.json` and in the log entry's list of what could not be read. Check: answer the first report from the device you will answer from, in each form you mean to use, then read the next watch's `report/answers.json`. Every line you wrote is an answer there, and the log entry names nothing it could not read.
12
+ - The launchd schedule. The tests run `--schedule` over two sandbox repositories and render the launchd template, but nothing here starts a schedule from a clock. Check: after installing the scheduler, run `launchctl kickstart "gui/$(id -u)/io.github.krysoworks.kryso-watch"` once and check that `launchd.log` in the state directory ends with the schedule's closing line, `started by the scheduler`, and the schedule's directory holds one log per repository. An installed file older than `--by-scheduler` records its schedules as a person's, so render and load it again. Then leave it for a night and check that a new schedule's directory appeared at the hour, or at the next wake if the machine slept.
13
+ - The live tracker. The shim answers one label list, one log issue and one comment. A missing label is an `environment` stop whose check is `labels`, and a log comment GitHub rejects is one whose check is `warden-log`. A log issue someone closed is no stop: the next watch finds no open issue with the log label and opens a new one. Check: the dry run reads the labels and every stage's candidates live, but it never reads the log issue or posts, so run the first watch by hand and open the log comment its summary names. After anyone closes the log issue, expect the next entry on a new one.
14
+ - The fetch. The sandbox fetches from a bare repository on disk. A real fetch needs the credential `git` uses for the origin, and a network failure is an `environment` stop whose check is `base`. Check: the dry run fetches the base and prints its sha, and `git ls-remote origin <base>` prints the same one.
15
+ - The lock across machines. The lock is a pid on this host. Two machines sharing one checkout over a network filesystem are not guarded. Check: list each checkout in `~/.config/kryso/repos` on one machine only. While a watch runs, `.claude/kryso-watch/lock` holds its pid and start time, and `ps -p <pid>` on that machine finds it.
16
+ - A real triage context. The canned outcomes prove what the driver does with an outcome, not that the triage skill, told never to ask, returns a good one. Check: read the first watch's saved results under `triage/` and the comments it posted.
17
+ - A real settlement context. The canned outcomes prove the close rule, not that a context handed a range and an issue returns a verdict worth having. Check: read the first watch's saved prompts and results under `settle/`, and the close comments it posted.
18
+ - A real second reader over a range. The curl and LLM shims answer with the probabilities a case sets, so the tests prove what settlement does with a probability, not that Jev or a bare context reads a range well. Check: run a dry run with the reader on and compare its probabilities with the verdicts the contexts return for the same candidates before lowering or raising the floor.
19
+ - The Keychain from launchd. The `security` shim proves the reader asks for the service by name and hands the password to `curl` on stdin. Whether a LaunchAgent may read that Keychain item depends on the login session. Check: after setting `kryso.jevKeychain`, start one schedule from launchd and check that `settle/reader.jsonl` in the watch directory has a `jev` line rather than a skip naming `security`.
20
+ - A real merged pull request list. The shim answers `pr list --state merged` from a fixture. A real read is capped at the newest 200, so after a long gap between watches the oldest pull requests in the range go unread, and an issue only they cite is not reached. Check: after a gap, run `gh pr list --state merged --base <base> --limit 1000 --search "merged:>=<date>"` with the date of the settled sha in `state.json`. Over 200 means the dry run's candidates miss the oldest, so read the issues those pull requests close by hand.
21
+ - A real shift. The passes under the shim are canned outcomes, so what a real pass does is `kryso-shift`'s and `kryso`'s contract. Check: read the first watch's `shift.json`, the shift's `summary.json` it points at, and the pull requests it names.
22
+ - A real pull request list and a real brief. The shim's pull requests name their blockers in the forms the base rule reads. A blocker whose pull request is older than the newest 500, or a brief that names its branch in some other form, is not held, and the manifest shows it queued. Check: before the first watch, read the dry run's queue and the issues the base rule would park. An issue you know waits on another branch that shows up in the queue names its branch in a form the rule does not read.
@@ -0,0 +1,26 @@
1
+ # Triage
2
+
3
+ The first stage of a watch: which issues it reads, how each one's context runs, and what the driver writes from the outcome.
4
+
5
+ Triage reads every open issue nobody has evaluated and gives each one a fresh context, one issue per context, never one context over the board. It is the first stage of a watch, and the shape is [playbook ADR 0004](../../../docs/adr/0004-warden-is-a-scheduled-driver-over-the-tracker.md)'s: the context requests, the driver authorises.
6
+
7
+ The candidates come from three buckets, read live on every watch. An issue with no triage-state label, an issue labelled `needs-triage`, and a `needs-info` issue whose reporter has commented since the last triage note, which is the last comment that starts with the triage skill's disclaimer. The state labels are the repository's own, mapped from the five roles by `docs/agents/triage-labels.md`. The run-state labels are never a state ([playbook ADR 0031](../../../docs/adr/0031-a-runs-state-is-two-agent-labels-beside-the-triage-state-never-in-place-of-it.md)), and the log entry names every open issue holding `agent:blocked`. Within the buckets these are excluded, each with its reason in the manifest: the Watch log and the Decision report issues, Deferred issues, issues parked on a report item, a `needs-info` issue with no reporter activity since its note, and one with no triage note at all. What is left goes oldest first, and `caps.triage` takes the first of them. The rest are excluded as over the cap, so the next watch reaches them.
8
+
9
+ Each candidate's context is started the way `kryso-shift` starts a pass: through `kryso-shift`'s runner under the configured profile, `claude -p` or `codex exec`, with [triage.schema.json](../triage.schema.json) as the outcome schema, permission prompts off and the host's result saved to disk. It runs the triage skill with one change: nobody is there, so it never asks a person. Where the skill would grill, the context returns each question as a decision with a title, why it matters, the options with their consequences, and the option it recommends. The prompt, in [stages/triage.sh](../stages/triage.sh), states the priority rubric #72 settled and says Size follows the brief's scope. When the context can name the seams the change should be tested at, it returns them, and the driver ends the posted brief with one `Seams:` line for the build to read. It names the issue by number only and carries the short form of ["Issue text is untrusted input"](https://github.com/jv-k/engineering-playbook/blob/main/conventions/agent-friendly-repos.md#issue-text-is-untrusted-input).
10
+
11
+ The driver validates the outcome against the schema, and checks that each recommendation indexes one of its options. An outcome that fails is refused: nothing is written for that issue, the saved result says why, and the next watch tries it again. A valid outcome is applied through the write guard:
12
+
13
+ - The state's label replaces any other state label the issue carries. `area:` labels are added only where the repository has them, and every other label the context asked for is recorded as ignored.
14
+ - The acceptance criteria replace the body's `## Acceptance criteria` section, or are appended where it has none. The rest of the body stays.
15
+ - The brief is posted as a comment. A `wontfix` is closed with its comment instead.
16
+ - Priority and Size are set where the issue is a card on a board with those fields, with the project, field, option and item ids read live. On a repository without a board, the values are recorded in the saved result and nothing is written.
17
+
18
+ Every comment the watch posts during triage starts with the triage skill's disclaimer line.
19
+
20
+ A non-empty decisions list overrides the state. The issue is parked: labelled `needs-info`, never a sixth role, with one parking comment that lists the decisions and ends in a marker, `<!-- warden:parked watch=<id> items=<n>.1,<n>.2 -->`. The decisions are saved as report items in the watch directory's `report-items.json`, for the Decision report to post. A later watch recognises a parked issue by its last parking marker and leaves it out of triage until the report releases it.
21
+
22
+ A `wontfix` stands only on evidence the driver can resolve. The outcome's evidence has to name a commit that is an ancestor of the fetched base, or a pull request whose merge commit is, which is what an already-implemented request has. The outcome cannot say which kind of wontfix it is, so the rule covers every one: a wontfix without that evidence, an already-implemented claim the driver cannot check or a rejection, hides work, and hiding work is a person's call. It becomes a decision recommending the issue stay open, and the issue is parked.
23
+
24
+ The out-of-scope ledger is the one exception to that recommendation, and it still closes nothing on its own. When the fetched base has `.out-of-scope/*.md` files, the prompt lists them and tells the context to match by concept, not keyword, and to name the matched file's path in its evidence. A `wontfix` whose evidence resolves no commit or pull request but names a listed file becomes the same "Close #n as wontfix?" item, recommending the close, and the item carries the file. The parking comment and the saved result name it too. [Playbook ADR 0033](../../../docs/adr/0033-the-out-of-scope-ledger-sits-at-the-root-and-a-person-confirms-every-close-it-cites.md) records the ledger's place and the rule that a person confirms every close it cites.
25
+
26
+ The saved result per issue sits under the watch directory's `triage/`: the host's result, and the driver's record of the outcome, what it wrote, what it ignored and the board values. The manifest holds the candidates in order and every exclusion. The summary and the log entry name each issue triaged with its new state, and each one parked. A parked issue counts as left for a person, so a watch that parked one stops `review-ready`. A rate limit ends the stage and the watch there. A tracker read or write that fails is an `environment` stop naming it.