@joshuafolkken/kit 1.1136.0 → 1.1166.0

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 (165) hide show
  1. package/.claude/settings.json +4 -4
  2. package/.claude/skills/epic-commands/SKILL.md +27 -239
  3. package/.claude/skills/epic-commands/epic-bundle.md +115 -0
  4. package/.claude/skills/epic-commands/execution-waves.md +126 -0
  5. package/.claude/skills/workflow-commands/SKILL.md +48 -194
  6. package/.claude/skills/workflow-commands/background-commands.md +1 -1
  7. package/.claude/skills/workflow-commands/backlogrun-child.md +12 -123
  8. package/.claude/skills/workflow-commands/backlogrun-lanes.md +11 -60
  9. package/.claude/skills/workflow-commands/backlogrun-park.md +10 -8
  10. package/.claude/skills/workflow-commands/backlogrun-progress.md +17 -173
  11. package/.claude/skills/workflow-commands/backlogrun-recovery.md +155 -0
  12. package/.claude/skills/workflow-commands/backlogrun-steps.md +64 -144
  13. package/.claude/skills/workflow-commands/backlogrun.md +5 -4
  14. package/.claude/skills/workflow-commands/chain-rule.md +3 -2
  15. package/.claude/skills/workflow-commands/delegation.md +2 -2
  16. package/.claude/skills/workflow-commands/entry-sequence.md +62 -0
  17. package/.claude/skills/workflow-commands/followup.md +104 -181
  18. package/.claude/skills/workflow-commands/fullrun-steps.md +8 -9
  19. package/.claude/skills/workflow-commands/fullrun.md +16 -73
  20. package/.claude/skills/workflow-commands/halfrun.md +10 -36
  21. package/.claude/skills/workflow-commands/into-target.md +4 -4
  22. package/.claude/skills/workflow-commands/issue-comments.md +7 -8
  23. package/.claude/skills/workflow-commands/issue-scout.md +6 -6
  24. package/.claude/skills/workflow-commands/kickoff.md +6 -6
  25. package/.claude/skills/workflow-commands/needs-human-review.md +6 -6
  26. package/.claude/skills/workflow-commands/observation-filing.md +21 -172
  27. package/.claude/skills/workflow-commands/observation-ledger.md +150 -0
  28. package/.claude/skills/workflow-commands/pre-gate-cut.md +33 -93
  29. package/.claude/skills/workflow-commands/prerequisite.md +6 -6
  30. package/.claude/skills/workflow-commands/progress-watcher.md +90 -0
  31. package/.claude/skills/workflow-commands/prrun.md +5 -5
  32. package/.claude/skills/workflow-commands/retrospective.md +9 -9
  33. package/.claude/skills/workflow-commands/split-assessment.md +2 -2
  34. package/.claude/skills/workflow-commands/target-repository.md +2 -2
  35. package/.claude/skills/workflow-commands/working-tree-hold.md +7 -5
  36. package/.codex/hooks.json +4 -4
  37. package/AGENTS.md +1 -6
  38. package/CLAUDE.md +58 -120
  39. package/GEMINI.md +1 -6
  40. package/dist/CLAUDE.md +58 -120
  41. package/dist/hooks/batch-guard.js +4 -4
  42. package/dist/hooks/{chunk-NFZGFGOR.js → chunk-5KTCMCOT.js} +14 -1
  43. package/dist/hooks/{chunk-LJBLGHEH.js → chunk-A6P7PN7P.js} +4 -6
  44. package/dist/hooks/{chunk-FO2I7UT7.js → chunk-ANJ2WGFD.js} +1 -1
  45. package/dist/hooks/{chunk-GDU26K3J.js → chunk-DYAVAM6S.js} +563 -126
  46. package/dist/hooks/{chunk-RFWWUI5F.js → chunk-ENA7P5FB.js} +3 -3
  47. package/dist/hooks/{chunk-KBXZLMRH.js → chunk-GU5MATVE.js} +213 -65
  48. package/dist/hooks/chunk-GYNGP7HI.js +56 -0
  49. package/dist/hooks/{chunk-HBKZLITF.js → chunk-URJA6XY4.js} +4 -4
  50. package/dist/hooks/{chunk-KOKOAV6D.js → chunk-V2BTOZHT.js} +6 -4
  51. package/dist/hooks/{chunk-JKKTVDAG.js → chunk-ZDZ555YH.js} +100 -20
  52. package/dist/hooks/codex-hook-adapter.js +10 -10
  53. package/dist/hooks/duplicate-read-guard.js +5 -5
  54. package/dist/hooks/format-edited.js +2 -2
  55. package/dist/hooks/inputs.json +193 -192
  56. package/dist/hooks/investigation-guard.js +5 -5
  57. package/dist/hooks/pretool-guard.js +11 -10
  58. package/dist/hooks/stop-guard.js +5 -5
  59. package/dist/josh.js +25 -2
  60. package/dist/version/index.js +5 -1
  61. package/package.json +2 -1
  62. package/prompts/collaboration-workflow/file-edits.md +11 -10
  63. package/prompts/collaboration-workflow/gh-rest.md +2 -4
  64. package/prompts/collaboration-workflow/glossary.md +1 -1
  65. package/prompts/collaboration-workflow/issue-citation.md +5 -9
  66. package/prompts/collaboration-workflow/issue-template.md +40 -115
  67. package/prompts/collaboration-workflow/operating-rules.md +4 -5
  68. package/prompts/collaboration-workflow/output-bounds.md +12 -78
  69. package/prompts/collaboration-workflow/overview.md +7 -13
  70. package/prompts/collaboration-workflow/plan-comment.md +11 -39
  71. package/prompts/collaboration-workflow/principles.md +3 -4
  72. package/prompts/collaboration-workflow/report-format.md +28 -74
  73. package/prompts/collaboration-workflow/residency.md +12 -109
  74. package/prompts/collaboration-workflow/rule-delivery.md +98 -97
  75. package/prompts/collaboration-workflow/shell-body.md +3 -13
  76. package/prompts/collaboration-workflow/turn-batching.md +14 -88
  77. package/prompts/collaboration-workflow/upstream-interrupt.md +12 -14
  78. package/prompts/collaboration-workflow/wip-cap.md +6 -45
  79. package/prompts/collaboration-workflow.md +1 -13
  80. package/prompts/review-rubric.md +8 -71
  81. package/prompts/review.md +25 -55
  82. package/prompts/testing-guide.md +18 -67
  83. package/scripts/agent/agent-role-profile.ts +1 -1
  84. package/scripts/agent/codex-hooks.ts +3 -12
  85. package/scripts/backlog/backlog-budget.ts +1 -1
  86. package/scripts/backlog/backlog-drive-cli.ts +4 -3
  87. package/scripts/backlog/backlog-drive-offer-argv.ts +10 -1
  88. package/scripts/backlog/backlog-offer.ts +6 -6
  89. package/scripts/behavior/behavior-rules.ts +11 -4
  90. package/scripts/delegation/investigation-reads.ts +5 -5
  91. package/scripts/discovery/repo-discovery.ts +21 -7
  92. package/scripts/discovery/repo-origin.ts +26 -0
  93. package/scripts/discovery/repo-party.ts +42 -1
  94. package/scripts/document/backlogrun-parent-read-set.ts +14 -15
  95. package/scripts/document/document-byte-budget.ts +34 -20
  96. package/scripts/document/entry-read-budget.ts +21 -9
  97. package/scripts/document/lane-child-read-set.ts +12 -14
  98. package/scripts/document/read-set-cli.ts +4 -4
  99. package/scripts/document/read-set-point-of-use.ts +10 -2
  100. package/scripts/document/resident-budget.ts +47 -0
  101. package/scripts/epic/epic-shape.ts +10 -13
  102. package/scripts/epic/epic-solo.ts +1 -1
  103. package/scripts/exports/unused-members-cli.ts +7 -3
  104. package/scripts/gh/git-gh-api-path.ts +7 -0
  105. package/scripts/hooks/pretool-guard-cli.ts +2 -2
  106. package/scripts/hooks/pretool-guard.ts +45 -2
  107. package/scripts/hooks/run-hook.sh +41 -0
  108. package/scripts/init/hook-command-rewrite.ts +18 -35
  109. package/scripts/init/hook-launch.ts +21 -32
  110. package/scripts/issue/issue-auto-ok.ts +95 -0
  111. package/scripts/issue/issue-file-cli.ts +53 -7
  112. package/scripts/issue/issue-file.ts +28 -5
  113. package/scripts/issue/issue-labels.ts +12 -12
  114. package/scripts/issue/issue-rank.ts +1 -1
  115. package/scripts/issue/issue-read-cli.ts +3 -3
  116. package/scripts/issue/issue-read.ts +2 -2
  117. package/scripts/issue/issue-scout-cli.ts +2 -2
  118. package/scripts/issue/issue-state-cli.ts +1 -1
  119. package/scripts/issue/issue-state.ts +2 -2
  120. package/scripts/issue/issue-wip.ts +70 -0
  121. package/scripts/josh/hook-decision.ts +17 -0
  122. package/scripts/josh/josh-commands-development.ts +10 -0
  123. package/scripts/josh/josh-commands-issue.ts +2 -2
  124. package/scripts/lines/bytes-command.ts +29 -6
  125. package/scripts/observations/observation-ledger-line.ts +1 -1
  126. package/scripts/release/release-progress.ts +167 -0
  127. package/scripts/release/release-publish.ts +19 -8
  128. package/scripts/release/release-tag.ts +22 -8
  129. package/scripts/rules/decision-oracle-stage.ts +1 -1
  130. package/scripts/rules/decision-oracle.ts +6 -6
  131. package/scripts/rules/delivered-rules.ts +11 -11
  132. package/scripts/rules/direct-pr-create.ts +110 -0
  133. package/scripts/rules/file-body.ts +98 -42
  134. package/scripts/rules/filing-cap.ts +2 -2
  135. package/scripts/rules/filing-offer.ts +1 -1
  136. package/scripts/rules/gh-api.ts +18 -1
  137. package/scripts/rules/implementation-cut.ts +3 -1
  138. package/scripts/rules/lane-background.ts +67 -10
  139. package/scripts/rules/permission-guards.ts +10 -2
  140. package/scripts/rules/stop-rules.ts +4 -4
  141. package/scripts/rules/test-declared-commit.ts +1 -1
  142. package/scripts/rules/third-party-write.ts +56 -12
  143. package/scripts/run/run-cut-handoff.ts +21 -1
  144. package/scripts/run/run-entry-cli.ts +11 -3
  145. package/scripts/run/run-hold-cli.ts +16 -2
  146. package/scripts/run/run-label.ts +50 -0
  147. package/scripts/run/run-merge-steps.ts +8 -3
  148. package/scripts/run/run-merge.ts +1 -1
  149. package/scripts/run/run-prep-cli.ts +6 -2
  150. package/scripts/run/run-prep.ts +17 -0
  151. package/scripts/run/run-ship-preflight.ts +34 -3
  152. package/scripts/run/run-ship-review-steps.ts +1 -1
  153. package/scripts/run/run-ship-review.ts +26 -5
  154. package/scripts/run/run-step-cli.ts +20 -7
  155. package/scripts/run/run-wake-driver.ts +24 -1
  156. package/scripts/run/run-wake-session.ts +2 -1
  157. package/scripts/test/test-declared-logic.ts +1 -1
  158. package/scripts/time-runtime/time-batch-guard.ts +52 -16
  159. package/scripts/time-runtime/time-density-hook.ts +20 -2
  160. package/scripts/time-runtime/time-density.ts +4 -3
  161. package/scripts/time-runtime/time-markers.ts +15 -4
  162. package/scripts/version/npm-registry.ts +11 -1
  163. package/templates/workflows/ci.yml +9 -1
  164. package/.claude/skills/workflow-commands/followup-reference.md +0 -118
  165. package/dist/hooks/chunk-HANSKHES.js +0 -464
@@ -48,15 +48,15 @@ const POINT_OF_USE_LABEL = '-- read at the point of use, not at the entry --'
48
48
  const LANE_CHILD_NOTE: ReadonlyArray<string> = [
49
49
  ' a dispatched lane child (`JOSH_LANE_CHILD`) reads this trimmed set:',
50
50
  ' - skips the point-of-use documents the parent owns — child dispatch, lane opening, the progress watcher and the hand-off',
51
- ' - omits SKILL.md §0/§2a/§2b/§2c/§2e/§2i/§3 — dispatch already authorized the run and a leaf child never uses them',
51
+ ' - omits SKILL.md §0/§3 — dispatch already authorized the run and a leaf child edits no rule',
52
52
  ]
53
53
  // **The `backlogrun` parent reads a trimmed set of its own** — a scheduler that never implements, so
54
54
  // the implementer-only `SKILL.md` sections are read section by section rather than whole
55
- // (joshuafolkken/kit#2256). A *different* trim from the lane child's: the parent keeps §0/§2b/§2c/§2e/
56
- // §2i, which are the scheduler's own, and drops no point-of-use document.
55
+ // (joshuafolkken/kit#2256). A *different* trim from the lane child's: the parent keeps §0, which is the
56
+ // scheduler's own, and drops no point-of-use document.
57
57
  const BACKLOGRUN_PARENT_NOTE: ReadonlyArray<string> = [
58
58
  ' the backlogrun parent (scheduler) reads this trimmed set:',
59
- ' - omits SKILL.md §2a/§2f/§2g/§3 — the parent never implements, so it claims no tree and files no `into` target',
59
+ ' - omits SKILL.md §3 — the parent edits no rule mid-run',
60
60
  ' - keeps every point-of-use document — the parent is the one dispatching children and running lanes',
61
61
  ]
62
62
  const FETCH_RULE =
@@ -15,7 +15,7 @@
15
15
  // is joshuafolkken/kit#1856's addition**: it governs the `/code-review` → `followup` chain, which in
16
16
  // `fullrun` / `queue` / `epicrun` / `backlogrun` runs *after* the first edit, so its 7,396 tokens
17
17
  // were resident from the entry for no run that had yet reached a review.
18
- // **`background-commands.md` is joshuafolkken/kit#1873's**: it was §2h's resident body, governing the
18
+ // **`background-commands.md` is joshuafolkken/kit#1873's**: it was `background-commands.md`'s resident body, governing the
19
19
  // background execution of the gate, the push and the merge tail — all after the first edit — so it
20
20
  // left `SKILL.md` for the point-of-use list. `SKILL.md` → §1, "Four documents are read at the point
21
21
  // of use", is the single source.
@@ -32,18 +32,26 @@
32
32
  // cut, a step every implementing run — and every dispatched lane child — reaches after the entry, so
33
33
  // its read is a point-of-use read the count was silently omitting. Measured on the backlogrun of
34
34
  // 2026-09-21, the lane children read it 21 times across 13 runs — the largest single document read,
35
- // and the one the point-of-use list had no row for.
35
+ // and the one the point-of-use list had no row for. Only a lane child reaches it (joshuafolkken/kit#3172):
36
+ // `fullrun.md` no longer names it, so it is charged to the lane child's role alone.
37
+ // **`progress-watcher.md` joins them** (joshuafolkken/kit#3172): the heartbeat every implementing run
38
+ // starts once its hold is claimed, split out of `backlogrun-progress.md` so a single-issue run stops
39
+ // paying for the batch's hand-off and waiting procedure to read it.
36
40
  const POINT_OF_USE_FILES: ReadonlySet<string> = new Set([
37
41
  'latest-gate.md',
38
42
  'followup.md',
39
43
  'chain-rule.md',
40
44
  'background-commands.md',
41
45
  'pre-gate-cut.md',
46
+ 'progress-watcher.md',
42
47
  'backlogrun-child.md',
43
48
  'backlogrun-lanes.md',
44
49
  'backlogrun-progress.md',
45
50
  'backlogrun-park.md',
46
51
  'backlogrun-steps.md',
52
+ // Read only when a delegated unit goes silent or a lane's pull request conflicts with `main` — a
53
+ // failure path, so a run in which nothing fails never reads it (joshuafolkken/kit#3175).
54
+ 'backlogrun-recovery.md',
47
55
  // Read only when `run:step` prints `pnpm josh retrospective` at a run's stop position — the very
48
56
  // end of a run, never the entry (joshuafolkken/kit#2328). Kept out of every entry's read for the
49
57
  // same reason the phase documents above are: no run that never drains its backlog reaches it.
@@ -0,0 +1,47 @@
1
+ import { document_reachability } from './document-reachability'
2
+
3
+ // The byte budget of the always-resident document — `CLAUDE.md`, loaded on every request. It is held
4
+ // here rather than in `document-byte-budget.ts` because a resident document is covered by every entry
5
+ // total and must not carry a per-document block entry as well (joshuafolkken/kit#2257); it is held here
6
+ // rather than inside `workflow-skills.test.ts` so `josh bytes CLAUDE.md` counts against the same number
7
+ // the suite enforces (joshuafolkken/kit#3171). Loosening any of the three constants is Tier C —
8
+ // `prompts/collaboration-workflow/residency.md`.
9
+
10
+ // The documents sat at ~83 KB each before the joshuafolkken/kit#854 split, crept back to ~56 KB, and
11
+ // were cut below 30 KB by joshuafolkken/kit#1924. joshuafolkken/kit#3171 cut `CLAUDE.md` to ~14 KB —
12
+ // triggers and pointers only — and lowered this ceiling with it, so the document cannot creep back. It
13
+ // is a guard against re-inlining, not a budget to tune prose against.
14
+ const RESIDENT_CEILING_BYTES = 18_000
15
+
16
+ // joshuafolkken/kit#951: the ceiling alone stops the wrong thing. Reached, it does not block the
17
+ // next rule — it makes that rule pay for itself by deleting a neighboring sentence, and the
18
+ // sentence chosen is whichever one no marker pinned rather than whichever one matters least. A
19
+ // required margin turns "at the limit" into a failure while there is still room to write the fix,
20
+ // which is the only point at which moving a procedure into a skill is still a choice.
21
+ const RESIDENT_HEADROOM_BYTES = 2000
22
+
23
+ // joshuafolkken/kit#1275: a floor under the room left once the procedures are out, so a wholesale
24
+ // re-inlining fails by name instead of silently returning the document to a few bytes of headroom.
25
+ const RE_INLINE_GUARD_HEADROOM_BYTES = 1000
26
+
27
+ const EFFECTIVE_CEILING_BYTES = RESIDENT_CEILING_BYTES - RESIDENT_HEADROOM_BYTES
28
+
29
+ // The size a resident document must stay below — the effective ceiling minus the re-inline floor. The
30
+ // suite fails at it, and `josh bytes` counts the headroom against it.
31
+ const RESIDENT_LIMIT_BYTES = EFFECTIVE_CEILING_BYTES - RE_INLINE_GUARD_HEADROOM_BYTES
32
+
33
+ // The limit for a resident document, or undefined for any other path.
34
+ function limit_bytes_for(relative_path: string): number | undefined {
35
+ return document_reachability.RESIDENT_BASE.includes(relative_path)
36
+ ? RESIDENT_LIMIT_BYTES
37
+ : undefined
38
+ }
39
+
40
+ const resident_budget = {
41
+ EFFECTIVE_CEILING_BYTES,
42
+ RE_INLINE_GUARD_HEADROOM_BYTES,
43
+ RESIDENT_LIMIT_BYTES,
44
+ limit_bytes_for,
45
+ }
46
+
47
+ export { resident_budget }
@@ -5,7 +5,7 @@ import { to_issue_reference } from './epic-reference'
5
5
  // Whether an issue is an epic this repository's writers may edit, and why it is not when it is not.
6
6
  //
7
7
  // Both `josh epic --add` and `josh epic --remove` ask exactly this before they compute anything: the
8
- // label, the absence of a cross-repository child, a task list to place rows in, and a declaration
8
+ // label, a task list to place rows in, and a declaration
9
9
  // their edit can be relative to. It lives in one module rather than in each of them, because the two
10
10
  // commands must refuse the same inputs for the same reasons — a second copy is where one comes to
11
11
  // accept an epic the other refuses (joshuafolkken/kit#1712).
@@ -40,18 +40,15 @@ function promote_remedy(epic_number: number): string {
40
40
  // The label and the task list are checked separately from the declaration because they fail
41
41
  // differently: without rows there is nowhere to put a new one, and without a declaration there is
42
42
  // nothing for an edit to be relative to.
43
- function find_epic_shape_error(subject: EpicShapeSubject, body: string): string | undefined {
44
- const reference = to_issue_reference(subject.epic_number)
45
-
46
- if (!subject.labels.includes(EPIC_LABEL)) {
47
- return `${reference} does not carry the \`${EPIC_LABEL}\` label, so it is not an epic. ${promote_remedy(subject.epic_number)}`
48
- }
49
-
50
- if (epic_parse.has_external_task_list_entry(body)) {
51
- return `${reference} tracks a child in another repository; editing the declared order of a cross-repository epic is joshuafolkken/kit#864's scope, not this command's.`
52
- }
43
+ //
44
+ // **A child in another repository is not a refusal** (joshuafolkken/kit#3161). The declaration names
45
+ // bare numbers only, so neither command can write an order across repositories — such an order lives
46
+ // in the native relations alone (`epic_graph.child_links`), which these edits never read or drop — and
47
+ // the rewrite leaves a row it does not recognize exactly where it stood.
48
+ function find_epic_shape_error(subject: EpicShapeSubject): string | undefined {
49
+ if (subject.labels.includes(EPIC_LABEL)) return undefined
53
50
 
54
- return undefined
51
+ return `${to_issue_reference(subject.epic_number)} does not carry the \`${EPIC_LABEL}\` label, so it is not an epic. ${promote_remedy(subject.epic_number)}`
55
52
  }
56
53
 
57
54
  function find_subject_error(
@@ -60,7 +57,7 @@ function find_subject_error(
60
57
  ): string | undefined {
61
58
  const reference = to_issue_reference(subject.epic_number)
62
59
  if (subject.body === undefined) return `Could not read the body of ${reference}.`
63
- const shape_error = find_epic_shape_error(subject, subject.body)
60
+ const shape_error = find_epic_shape_error(subject)
64
61
  if (shape_error !== undefined) return shape_error
65
62
 
66
63
  if (tracked.length === 0) {
@@ -6,7 +6,7 @@ import { epic_report, type EpicNextResult } from './epic-report'
6
6
 
7
7
  // The `run:solo` gate on what a run is offered (joshuafolkken/kit#2776).
8
8
  //
9
- // `wip-cap.md`'s run-alone section says an issue whose defect reaches the verification path runs
9
+ // `backlogrun-lanes.md`'s run-alone rule says an issue whose defect reaches the verification path runs
10
10
  // alone, and until this gate that was a judgement made at dispatch — the offer handed such an issue
11
11
  // out beside others and `backlog:drive` launched every number it was given. The label records the
12
12
  // judgement once; this applies it to every ask, so it holds without an agent in the loop.
@@ -9,7 +9,11 @@ const CHECK = 'exports'
9
9
  const FAIL_EXIT_CODE = 1
10
10
  // A consumer's namespaces are read from `.svelte` files and routes a TypeScript program over its
11
11
  // `tsconfig.json` does not see, so every member they use would read as unused. The check is kit's own.
12
- const CONSUMER_SKIP_REASON = 'checks only the kit repository itself, not a consumer project'
12
+ //
13
+ // **Not a skip notice** (joshuafolkken/kit#3162). `SKIP_MARKER` means "a check passed without running",
14
+ // and the gate withholds its green record on it — so a consumer, where this notice prints on every
15
+ // run, never got a green record. Out of scope by design is not unverified, so the marker stays out.
16
+ const CONSUMER_NOTICE = `josh ${CHECK}: checks only the kit repository itself — nothing to check in a consumer project.`
13
17
 
14
18
  function format_member(root: string, member: NamespaceMember): string {
15
19
  return `${path.relative(root, member.file)}:${String(member.line)} ${member.namespace}.${member.member}`
@@ -26,7 +30,7 @@ function report(root: string, members: ReadonlyArray<NamespaceMember>): string {
26
30
 
27
31
  async function run_unused_members(root: string): Promise<number> {
28
32
  if (doctor_consumer.is_kit_consumer(root)) {
29
- console.info(project_checks.skip_notice(CHECK, CONSUMER_SKIP_REASON))
33
+ console.info(CONSUMER_NOTICE)
30
34
 
31
35
  return 0
32
36
  }
@@ -48,6 +52,6 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
48
52
  process.exitCode = await run_unused_members(project_checks.project_root(process.cwd()))
49
53
  }
50
54
 
51
- const unused_members_cli = { run_unused_members }
55
+ const unused_members_cli = { run_unused_members, CONSUMER_NOTICE }
52
56
 
53
57
  export { unused_members_cli }
@@ -97,10 +97,17 @@ function tag_reference_api_path(tag: string, repo?: string): string {
97
97
  return `${repo_api_path(repo)}/git/ref/tags/${tag}`
98
98
  }
99
99
 
100
+ // The GitHub Release published for one tag. REST answers 404 until `publish.yml`'s `create-release`
101
+ // job has run, which is what the release command's progress watch asks (joshuafolkken/kit#3193).
102
+ function release_by_tag_api_path(tag: string, repo?: string): string {
103
+ return `${repo_api_path(repo)}/releases/tags/${tag}`
104
+ }
105
+
100
106
  const git_gh_api_path = {
101
107
  FULL_PAGE_QUERY,
102
108
  repo_api_path,
103
109
  tag_ref_api_path: tag_reference_api_path,
110
+ release_by_tag_api_path,
104
111
  issues_api_path,
105
112
  issue_api_path,
106
113
  blocked_by_api_path,
@@ -2,7 +2,7 @@
2
2
  import { text } from 'node:stream/consumers'
3
3
  import { fileURLToPath } from 'node:url'
4
4
  import { hook_decision } from '#scripts/josh/hook-decision'
5
- import { pretool_outcome_async } from './pretool-guard'
5
+ import { pretool_guard, pretool_outcome_async } from './pretool-guard'
6
6
 
7
7
  // The `PreToolUse` hook's entry, kept apart from the composition in `pretool-guard.ts`
8
8
  // (joshuafolkken/kit#2922). The hook bundles are built with `splitting: true`, which moves a module
@@ -16,6 +16,6 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
16
16
  const raw_payload = await text(process.stdin)
17
17
 
18
18
  hook_decision.load_environment_file()
19
- hook_decision.emit_outcome(await pretool_outcome_async(raw_payload))
19
+ pretool_guard.emit(raw_payload, await pretool_outcome_async(raw_payload))
20
20
  }
21
21
  }
@@ -1,9 +1,11 @@
1
1
  import { duplicate_read_outcome } from '#scripts/delegation/duplicate-read-guard'
2
2
  import { investigation_refusal } from '#scripts/delegation/investigation-guard'
3
- import type { GuardOutcome } from '#scripts/josh/hook-decision'
3
+ import { hook_decision, type GuardOutcome } from '#scripts/josh/hook-decision'
4
4
  import { delivered_rules } from '#scripts/rules/delivered-rules'
5
+ import { lane_background } from '#scripts/rules/lane-background'
5
6
  import { run_parent_cut_hook } from '#scripts/run/run-parent-cut-hook'
6
7
  import { run_watcher_hook } from '#scripts/run/run-watcher-hook'
8
+ import type { GuardedCall } from '#scripts/time-runtime/time-batch-guard'
7
9
  import { batch_outcome } from './batch-guard'
8
10
  import { step_zero_notice } from './step-zero-notice'
9
11
 
@@ -108,6 +110,47 @@ async function pretool_outcome_async(raw_payload: string): Promise<GuardOutcome>
108
110
  return with_step_zero_notice(base, raw_payload)
109
111
  }
110
112
 
111
- const pretool_guard = { combine_outcomes, pretool_outcome }
113
+ function guarded_call(raw_payload: string): GuardedCall | undefined {
114
+ try {
115
+ const payload = hook_decision.parse_hook_payload(raw_payload)
116
+
117
+ return payload === undefined
118
+ ? undefined
119
+ : { name: payload.tool_name, input: payload.tool_input }
120
+ } catch {
121
+ return undefined
122
+ }
123
+ }
124
+
125
+ // The envelope that replaces the outcome's own when a lane child backgrounded `josh ship` alone
126
+ // (joshuafolkken/kit#3154): the call is run in the foreground instead of being refused. A refusal from
127
+ // any guard still wins, and a notice the outcome carried rides along in the same context.
128
+ function foreground_rewrite(
129
+ outcome: GuardOutcome,
130
+ raw_payload: string,
131
+ is_lane_child?: () => boolean,
132
+ ): string | undefined {
133
+ if (outcome.reason !== undefined) return undefined
134
+
135
+ const call = guarded_call(raw_payload)
136
+ const input =
137
+ call === undefined ? undefined : lane_background.foreground_input(call, is_lane_child)
138
+
139
+ if (input === undefined) return undefined
140
+
141
+ const context = [lane_background.FOREGROUND_NOTE, outcome.notice ?? outcome.fault]
142
+
143
+ return hook_decision.rewrite_envelope(input, context.filter(Boolean).join('\n\n'))
144
+ }
145
+
146
+ // The hook's one write: the foreground rewrite where it applies, the outcome's own envelope otherwise.
147
+ function emit(raw_payload: string, outcome: GuardOutcome): void {
148
+ const rewrite = foreground_rewrite(outcome, raw_payload)
149
+
150
+ if (rewrite === undefined) hook_decision.emit_outcome(outcome)
151
+ else process.stdout.write(`${rewrite}\n`)
152
+ }
153
+
154
+ const pretool_guard = { combine_outcomes, emit, foreground_rewrite, pretool_outcome }
112
155
 
113
156
  export { pretool_guard, pretool_outcome, pretool_outcome_async }
@@ -0,0 +1,41 @@
1
+ #!/bin/sh
2
+ # Launch one kit hook by name: `sh scripts/hooks/run-hook.sh <name> [arguments...]`
3
+ # (joshuafolkken/kit#3184).
4
+ #
5
+ # A hook command in `.claude/settings.json` / `.codex/hooks.json` only moves to the project root
6
+ # (`scripts/init/hook-launch.ts`) and calls this script, so everything every hook shares lives here once:
7
+ #
8
+ # - The git location variables a git hook exports are cleared when the root resolves without them, so
9
+ # the hook's own git calls act on the checkout it stands in. They are kept when the checkout needs
10
+ # them — git metadata outside the work tree.
11
+ # - The pre-built bundle `dist/hooks/<name>.js` runs once its gate passes; otherwise the live source
12
+ # runs through josh, whose command is the name with its first `-` turned into `:`
13
+ # (`pretool-guard` → `pretool:guard`).
14
+ # - In kit's own checkout the gate is `hook-bundle-ready.ts`, which rebuilds stale bundles
15
+ # (joshuafolkken/kit#2984). In an installed package it is a presence check: the published bundles
16
+ # cannot be stale against a source the consumer never edits, and Node strips no types under
17
+ # `node_modules`.
18
+ # - An `if`/`else`, never `&&`/`||`: a guard's refusal is a non-zero exit, and a chain would read it as
19
+ # a missing bundle and run the hook twice.
20
+
21
+ location_variables='GIT_ALTERNATE_OBJECT_DIRECTORIES GIT_COMMON_DIR GIT_DIR GIT_INDEX_FILE GIT_NAMESPACE GIT_OBJECT_DIRECTORY GIT_WORK_TREE'
22
+ unset_options=''
23
+ for variable in $location_variables; do unset_options="$unset_options -u $variable"; done
24
+ # shellcheck disable=SC2086
25
+ if env $unset_options git rev-parse --show-toplevel >/dev/null 2>&1; then unset $location_variables; fi
26
+
27
+ hook_name=$1
28
+ shift
29
+ hooks_dir=$(dirname "$0")
30
+ package_dir="$hooks_dir/../.."
31
+ bundle="$package_dir/dist/hooks/$hook_name.js"
32
+ josh_command="${hook_name%%-*}:${hook_name#*-}"
33
+
34
+ case $0 in
35
+ *node_modules/*)
36
+ if [ -d "$package_dir/dist/hooks" ]; then node "$bundle" "$@"; else node "$package_dir/dist/josh.js" "$josh_command" "$@"; fi
37
+ ;;
38
+ *)
39
+ if node --disable-warning=ExperimentalWarning "$hooks_dir/hook-bundle-ready.ts"; then node "$bundle" "$@"; else pnpm josh "$josh_command" "$@"; fi
40
+ ;;
41
+ esac
@@ -3,60 +3,43 @@ import { hook_launch } from './hook-launch'
3
3
 
4
4
  // The consumer's `.claude/settings.json` runs its hooks off the published package directly, not
5
5
  // through `pnpm josh` (joshuafolkken/kit#1930, joshuafolkken/kit#2023). Two paths inside a hook
6
- // command are rebased onto the installed package: the per-hook bundle `dist/hooks/<name>.js` a hook
7
- // prefers, and the `pnpm josh <command>` fallback it drops to when that bundle is missing — which for
8
- // a consumer becomes the `dist/josh.js` dispatcher, since the published package always ships `dist`
9
- // and a `pnpm` launch would only add the wrapper this exists to remove.
6
+ // command are rebased onto the installed package: the hook launcher `scripts/hooks/run-hook.sh`
7
+ // (joshuafolkken/kit#3184), which picks the bundle or the dispatcher from where it is installed, and a
8
+ // plain `pnpm josh <command>`, which becomes the `dist/josh.js` dispatcher — the published package
9
+ // always ships `dist`, and a `pnpm` launch would only add the wrapper this exists to remove.
10
10
  //
11
- // kit's own settings file keeps the `pnpm josh` fallback (`tsx scripts/josh/josh.ts` against live
12
- // source), so a fresh clone with no `dist/` still runs the current guards. The rewrite is gated on the
13
- // copy destination, exactly as the plugin injection is — kit's source tree is never transformed in
14
- // place.
11
+ // kit's own settings file keeps the launcher's live-source fallback (`pnpm josh` against
12
+ // `scripts/josh/josh.ts`), so a fresh clone with no `dist/` still runs the current guards. The rewrite
13
+ // is gated on the copy destination, exactly as the plugin injection is — kit's source tree is never
14
+ // transformed in place.
15
15
 
16
16
  const PNPM_JOSH_PREFIX = 'pnpm josh '
17
- const CODEX_ADAPTER_SOURCE = 'pnpm exec tsx scripts/hooks/codex-hook-adapter.ts'
18
17
  // Relative to the consumer's project root, which hook commands select before using this path.
19
18
  // The path is the plugin marketplace's `node_modules` location plus the built entry `bin.josh` names.
20
19
  const BUNDLE_INVOCATION = `node ${claude_plugin_config.MARKETPLACE_PATH}/dist/josh.js `
21
- // The per-hook bundle directory a fresh clone builds, and where it lives inside the installed package.
22
- const HOOK_BUNDLE_DIR = `${hook_launch.HOOK_DIST_DIR}/`
23
- const CONSUMER_HOOK_BUNDLE_DIR = `${claude_plugin_config.MARKETPLACE_PATH}/${HOOK_BUNDLE_DIR}`
20
+ // Anchored on the `sh ` that launches it: the installed path still ends in the source path, so only the
21
+ // anchor keeps a second pass from rebasing an already-rebased launcher onto itself.
22
+ const RUN_HOOK_INVOCATION = `sh ${hook_launch.RUN_HOOK_SCRIPT} `
23
+ const CONSUMER_RUN_HOOK_INVOCATION = `sh ${claude_plugin_config.MARKETPLACE_PATH}/${hook_launch.RUN_HOOK_SCRIPT} `
24
24
  const CONSUMER_PACKAGE_MANIFEST = `${claude_plugin_config.MARKETPLACE_PATH}/package.json`
25
25
  const MISSING_INSTALL_NOTICE = 'kit hooks inactive: run pnpm install, then reread CLAUDE.md'
26
26
  const MISSING_INSTALL_GUARD = `if [ ! -f ${CONSUMER_PACKAGE_MANIFEST} ]; then echo '${MISSING_INSTALL_NOTICE}' >&2; exit 0; fi; `
27
- const CODEX_ADAPTER_BUNDLE = `node ${CONSUMER_HOOK_BUNDLE_DIR}codex-hook-adapter.js`
28
27
  const CODEX_HOOKS_DESTINATION = '.codex/hooks.json'
29
28
  // The values below are matched inside raw JSON text, so the root prefix is taken in its escaped form.
30
29
  const PROJECT_ROOT_PREFIX = JSON.stringify(hook_launch.PROJECT_ROOT_PREFIX).slice(1, -1)
31
- // The installed package ships its bundles built, so they cannot be stale against a source the consumer
32
- // never has: the ready gate kit's own commands pass (joshuafolkken/kit#2984) becomes a presence check.
33
- const CONSUMER_READY_GATE = `[ -d ${CONSUMER_HOOK_BUNDLE_DIR} ]`
34
30
  // Capture the value of every `"command"` field, escapes and all, so the rewrites below touch command
35
31
  // values alone — never an echo reminder's prose or a `"description"` that merely mentions the string.
36
32
  const COMMAND_FIELD = /("command":\s*")((?:[^"\\]|\\.)*)(")/gu
37
33
 
38
- // Idempotent on its own: `CONSUMER_HOOK_BUNDLE_DIR` still contains `HOOK_BUNDLE_DIR`, so a blind
39
- // second pass would rebase an already-rebased path onto itself. A value already targeting the
40
- // installed package is left untouched, restoring the idempotency the earlier `pnpm josh`-anchored
41
- // rewrite had for free.
42
- function rebase_bundle_directory(value: string): string {
43
- return value.includes(CONSUMER_HOOK_BUNDLE_DIR)
44
- ? value
45
- : value.split(HOOK_BUNDLE_DIR).join(CONSUMER_HOOK_BUNDLE_DIR)
46
- }
47
-
48
- // Rebase both paths a hook command can carry: the bundle it prefers, then the `pnpm josh` fallback.
49
- // The bundle rewrite runs first — its replacement never contains `pnpm josh`, so the two are
50
- // independent whichever order they run. The fallback rewrite is idempotent too (`BUNDLE_INVOCATION`
51
- // holds no `pnpm josh `), so the whole rewrite is safe to run more than once.
34
+ // Rebase both paths a hook command can carry: the launcher, then a plain `pnpm josh`. Neither
35
+ // replacement contains the other's anchor, so the two are independent whichever order they run, and
36
+ // the whole rewrite is safe to run more than once.
52
37
  function rewrite_command_value(value: string): string {
53
- const rewritten = rebase_bundle_directory(value)
54
- .split(hook_launch.BUNDLE_READY_GATE)
55
- .join(CONSUMER_READY_GATE)
38
+ const rewritten = value
39
+ .split(RUN_HOOK_INVOCATION)
40
+ .join(CONSUMER_RUN_HOOK_INVOCATION)
56
41
  .split(PNPM_JOSH_PREFIX)
57
42
  .join(BUNDLE_INVOCATION)
58
- .split(CODEX_ADAPTER_SOURCE)
59
- .join(CODEX_ADAPTER_BUNDLE)
60
43
 
61
44
  if (!rewritten.includes(claude_plugin_config.MARKETPLACE_PATH)) return rewritten
62
45
  if (rewritten.includes(MISSING_INSTALL_GUARD)) return rewritten
@@ -7,51 +7,40 @@ import { GIT_LOCATION_VARIABLES } from '#scripts/git/git-location-environment'
7
7
  //
8
8
  // **The command starts from the project root, never from wherever the session happens to be**
9
9
  // (joshuafolkken/kit#2984). Every path after the prefix is relative, so a hook fired from a
10
- // subdirectory would otherwise miss its bundle. The root is git's, with the location variables a git
11
- // hook exports cleared first — the same resolution the consumer rewrite (`hook-command-rewrite.ts`)
12
- // applies, so both sides stay one mechanism for Claude Code and Codex alike.
10
+ // subdirectory would otherwise miss its script. The root is git's, resolved with the location
11
+ // variables a git hook exports cleared first, and resolved with them only when that fails — git
12
+ // metadata outside the work tree. The consumer rewrite (`hook-command-rewrite.ts`) keeps this prefix,
13
+ // so both sides stay one mechanism for Claude Code and Codex alike.
13
14
  //
14
- // **The bundle runs only once the ready gate passes** (`scripts/hooks/hook-bundle-ready.ts`): it
15
- // rebuilds `dist/hooks/` when the source beside it has changed, so an edited guard is never shadowed by
16
- // its old bundle. The gate failing — a checkout that cannot build — drops to the fallback, the live
17
- // source. **An `if`/`else`, never `&&`/`||`**: a guard's refusal is a non-zero exit, and a
18
- // `node … || pnpm josh …` chain would read that refusal as a missing bundle and run the hook twice.
15
+ // **Everything after the root is one script** (`scripts/hooks/run-hook.sh`, joshuafolkken/kit#3184):
16
+ // clearing the location variables for the hook itself, the bundle-ready gate and the live-source
17
+ // fallback live there once, so each hook command names only its hook.
19
18
 
20
19
  const HOOK_DIST_DIR = 'dist/hooks'
20
+ const RUN_HOOK_SCRIPT = 'scripts/hooks/run-hook.sh'
21
21
  const UNSET_OPTIONS = GIT_LOCATION_VARIABLES.map((name) => `-u ${name}`).join(' ')
22
- const PROJECT_ROOT_PREFIX = `if project_root="$(env ${UNSET_OPTIONS} git rev-parse --show-toplevel 2>/dev/null)"; then unset ${GIT_LOCATION_VARIABLES.join(' ')}; else project_root="$(git rev-parse --show-toplevel)" || exit 1; fi; cd "$project_root" && `
23
- // Plain `node` runs the gate's TypeScript directly; the flag keeps Node 22's type-stripping notice off
24
- // every hook's stderr.
25
- const BUNDLE_READY_GATE =
26
- 'node --disable-warning=ExperimentalWarning scripts/hooks/hook-bundle-ready.ts'
22
+ const ROOT_LOOKUP = 'git rev-parse --show-toplevel'
23
+ const PROJECT_ROOT_PREFIX = `project_root="$(env ${UNSET_OPTIONS} ${ROOT_LOOKUP} 2>/dev/null || ${ROOT_LOOKUP})" && cd "$project_root" && `
27
24
 
28
- // Run `primary_command` when `gate` exits 0, else `fallback_command` — both verbatim. Kept generic so
29
- // a test can exercise the branch selection with stub commands rather than real hooks.
30
- function launch_command(gate: string, primary_command: string, fallback_command: string): string {
31
- return `if ${gate}; then ${primary_command}; else ${fallback_command}; fi`
25
+ // `name` is the hook's bundle under `dist/hooks` without `.js` (e.g. `pretool-guard`), followed by any
26
+ // arguments it takes (e.g. `codex-hook-adapter pretool`).
27
+ function hook_launch_command(name: string): string {
28
+ return `${PROJECT_ROOT_PREFIX}sh ${RUN_HOOK_SCRIPT} ${name}`
32
29
  }
33
30
 
34
- // `invocation` is the hook's file under `dist/hooks` plus any arguments (e.g. `pretool-guard.js`);
35
- // `fallback_command` runs the same hook from source.
36
- function bundle_launch_command(invocation: string, fallback_command: string): string {
37
- const primary = `node ${HOOK_DIST_DIR}/${invocation}`
38
-
39
- return `${PROJECT_ROOT_PREFIX}${launch_command(BUNDLE_READY_GATE, primary, fallback_command)}`
40
- }
41
-
42
- // `bundle` is the hook's file under `dist/hooks` (e.g. `pretool-guard.js`); `command` is the josh
43
- // subcommand the fallback runs (e.g. `pretool:guard`).
44
- function hook_launch_command(bundle: string, command: string): string {
45
- return bundle_launch_command(bundle, `pnpm josh ${command}`)
31
+ // The josh subcommand the launcher falls back to for hook `name`: its first `-` becomes `:`
32
+ // (`pretool-guard` → `pretool:guard`). The launcher derives it in shell; this is that rule for the tests
33
+ // that hold every wired hook to a subcommand josh has.
34
+ function fallback_command(name: string): string {
35
+ return name.replace('-', ':')
46
36
  }
47
37
 
48
38
  const hook_launch = {
49
- BUNDLE_READY_GATE,
50
- bundle_launch_command,
39
+ fallback_command,
51
40
  HOOK_DIST_DIR,
52
41
  hook_launch_command,
53
- launch_command,
54
42
  PROJECT_ROOT_PREFIX,
43
+ RUN_HOOK_SCRIPT,
55
44
  }
56
45
 
57
46
  export { hook_launch }
@@ -0,0 +1,95 @@
1
+ import { git_branch } from '#scripts/git/git-branch'
2
+ import { git_command } from '#scripts/git/git-command'
3
+ import { run_carry } from '#scripts/run/run-carry'
4
+ import { issue_file } from './issue-file'
5
+ import { AUTO_OK_LABEL, has_label_name } from './issue-labels'
6
+ import { issue_state_cli } from './issue-state-cli'
7
+
8
+ // Whether `josh issue:file` applies `auto-ok` to the Issue it files (joshuafolkken/kit#3213). Work
9
+ // found during an unattended run used to wait in the backlog until a person labelled it, so the
10
+ // filing now computes the answer instead of leaving it to the agent's memory: an Issue filed while a
11
+ // `backlogrun` carry record is live, or from a branch whose Issue carries `auto-ok`, is opted in by
12
+ // default. `--no-auto-ok` is the one exception, declared for an Issue that needs a person's judgement
13
+ // (a Tier B toss-up or a Tier C action). A filing to another repository is never opted in: that
14
+ // repository's own `backlogrun` would implement and merge it though nobody opted that repository in.
15
+
16
+ interface AutoOkSignals {
17
+ is_opted_out: boolean
18
+ is_carried: boolean
19
+ // The labels of the Issue the current branch names; `undefined` when the branch names none or the
20
+ // Issue could not be read.
21
+ branch_labels: ReadonlyArray<string> | undefined
22
+ }
23
+
24
+ interface AutoOkDecision {
25
+ is_applied: boolean
26
+ reason: string
27
+ }
28
+
29
+ const OPTED_OUT: AutoOkDecision = { is_applied: false, reason: '--no-auto-ok declared' }
30
+ const CROSS_REPOSITORY: AutoOkDecision = {
31
+ is_applied: false,
32
+ reason: 'the Issue is filed to another repository',
33
+ }
34
+ const CARRIED: AutoOkDecision = { is_applied: true, reason: 'a backlogrun carry record is live' }
35
+ const BRANCH_OPTED_IN: AutoOkDecision = {
36
+ is_applied: true,
37
+ reason: 'the Issue this branch works on carries auto-ok',
38
+ }
39
+ const NOT_OPTED_IN: AutoOkDecision = {
40
+ is_applied: false,
41
+ reason: 'no backlogrun carry record is live and the branch names no auto-ok Issue',
42
+ }
43
+
44
+ // The opt-out wins over every signal, then the carry record, then the branch's Issue.
45
+ function decide(signals: AutoOkSignals): AutoOkDecision {
46
+ if (signals.is_opted_out) return OPTED_OUT
47
+ if (signals.is_carried) return CARRIED
48
+ if (has_label_name(signals.branch_labels ?? [], AUTO_OK_LABEL)) return BRANCH_OPTED_IN
49
+
50
+ return NOT_OPTED_IN
51
+ }
52
+
53
+ function line_of(decision: AutoOkDecision): string {
54
+ return `auto-ok: ${decision.is_applied ? 'applied' : 'not applied'} — ${decision.reason}`
55
+ }
56
+
57
+ // Read from the common git directory, so a lane sees the record its batch wrote in the main tree.
58
+ async function is_carried(): Promise<boolean> {
59
+ const directory = await run_carry.repository_directory()
60
+
61
+ if (directory === undefined) return false
62
+
63
+ return run_carry.read_carry(run_carry.carry_path(directory)).kind === 'carried'
64
+ }
65
+
66
+ // An unreadable Issue is read as no labels: the filing goes on without `auto-ok` rather than failing.
67
+ // The branch names an Issue of `current`, read there by name: a filing to another repository has
68
+ // already pointed `GH_REPO` at its target, which would otherwise answer with the target's Issue.
69
+ async function branch_labels(current: string): Promise<ReadonlyArray<string> | undefined> {
70
+ const issue_number = git_branch.issue_from_branch(await git_command.branch())
71
+
72
+ if (issue_number === undefined) return undefined
73
+ const read = await issue_state_cli.read_issue(String(issue_number), current)
74
+
75
+ return read.kind === 'state' ? read.state.labels : undefined
76
+ }
77
+
78
+ // Each read is skipped once an earlier signal has already decided the answer; a cross-repository
79
+ // filing is refused before any signal is read.
80
+ async function resolve(
81
+ is_opted_out: boolean,
82
+ target: string,
83
+ current: string,
84
+ ): Promise<AutoOkDecision> {
85
+ if (is_opted_out) return OPTED_OUT
86
+ if (!issue_file.is_same_repository(target, current)) return CROSS_REPOSITORY
87
+ if (await is_carried()) return CARRIED
88
+
89
+ return decide({ is_opted_out, is_carried: false, branch_labels: await branch_labels(current) })
90
+ }
91
+
92
+ const issue_auto_ok = { decide, line_of, resolve }
93
+
94
+ export type { AutoOkDecision, AutoOkSignals }
95
+ export { issue_auto_ok }