@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
@@ -1,464 +0,0 @@
1
- import {
2
- lane_child_marker
3
- } from "./chunk-NFZGFGOR.js";
4
- import {
5
- time_bundle_call,
6
- time_format,
7
- time_round_trips,
8
- time_spans,
9
- time_transcript_line
10
- } from "./chunk-GDU26K3J.js";
11
-
12
- // scripts/lane/lane-guard-policy.ts
13
- var DEFAULT_MODE = "refuse";
14
- var OFF_MODE = "off";
15
- var LANE_GUARD_POLICY = [
16
- {
17
- id: "investigation",
18
- mode_in_lane_child: "notice",
19
- because: 'a refusal ends a child turn so it cannot fire as one (kit#2138), which is why it was `off` from #2138 to #2382. The exemption reason \u2014 "the child is itself the delegated unit, so it cannot dispatch a sub-unit to read its own edit targets" \u2014 did not hold in measurement: kit#2382 re-measured the six lane children after #2347 (#2366 #2370 #2371 #2372 #2374 #2375) and every one dispatched sub-agents (10 launches, 2 of them investigation fan-outs) and read 4\u201317 files it never edited, all six over the threshold of 3. So the reading the guard exists to send out was there to send. It takes `notice`, not `off`: the child is nudged to delegate rather than killed, on the `additionalContext` path batching and duplicate-read already use, and the notice names the concrete unedited files this run read (the #2276 precedent) rather than the generic "delegate" #2164 \u2192 #2178 measured not to move the number. The density is a genuine experiment \u2014 re-measured on the next backlogrun, and a notice that still does not move it is redesigned rather than kept'
20
- },
21
- {
22
- id: "batching",
23
- mode_in_lane_child: "off",
24
- because: "a refusal ends a child turn so it cannot fire as one (kit#2138); kit#2164 replaced it with a notice, kit#2178 took that notice off after it did not move the density, and kit#2276 restored it \u2014 naming the concrete recent calls and recurring every single-call turn \u2014 as a genuine experiment to be redesigned rather than kept if the next backlogrun still missed 1.40. kit#2405 is that re-measurement, and it cuts the notice off (`off`). `josh time:density` read 1.13 calls per round trip over the ten most recent lanes (1.04 in the Issue\u2019s per-message frame), short of the 1.40 target as every advisory attempt before it was (kit#1304/#1329/#1337/#1390/#2164/#2276). The cause is structural rather than wording: a `PreToolUse` hook cannot see the turn it is in \u2014 a turn\u2019s later `tool_use` lines arrive 1.4\u201315s after its first \u2014 so it judges only closed turns, and a notice at turn close still asks for the parallel `tool_use` blocks the model resists. The one lever measured to move the density is a composite command the model emits in a single call (`read:files`/`edit:files`, kit#2202/#2311), which needs no notice. So per the issue\u2019s instruction to discontinue advisory means when the target is missed, the notice is cut off rather than rewritten a seventh time; the density stays readable through `josh time:density`"
25
- },
26
- {
27
- id: "duplicate-read",
28
- mode_in_lane_child: "notice",
29
- because: "a refusal ends a child turn so it cannot fire as one (kit#2138), and the unchanged re-reads the guard catches are measured in lane children above all (kit#2298 baseline: 8.0 per lane run) \u2014 so silencing it there (`off`) would neuter it exactly where the count lives. It takes `notice` instead: the child is nudged to scroll up to the earlier read rather than killed. The mode is a genuine experiment, as the batching notice is \u2014 a notice that does not reduce the duplicate reads on the next backlogrun is redesigned rather than kept"
30
- },
31
- {
32
- id: "rule",
33
- mode_in_lane_child: "refuse",
34
- because: "it carries the lane-only rules a child depends on (`pre-gate-cut`, `implementation-cut`, `lane-park`) and the safety rules a child must still obey (`shell-body`, `piped-verification`); a blanket suppression would disarm exactly the guards written for the child. `implementation-cut` (joshuafolkken/kit#2310) needs `refuse` for the same reason the pre-gate cut does \u2014 kit#1864 and kit#2310 both measured a cut carried as prose firing 0 times, so a notice, being prose in front of the run, would drop enforcement without a procedural replacement. The pre-gate-cut refusal does collateral a sibling call batched in the same turn \u2014 a `PreToolUse` deny cancels the turn's other parallel calls, which is the harness behavior kit#2177 measured on #2160 (gate refused, its batched `review:brief` cancelled) \u2014 and that collateral is not avoidable at the guard level. `notice` was considered for the pre-gate-cut point and rejected: kit#1864 measured the cut taken 0 times while it was carried as prose, and a notice is prose in front of the run (kit#2178 measured a lane-child notice not moving the number), so a notice would drop enforcement without a procedural replacement. kit#2177 supplies that replacement in the procedure instead \u2014 the chain orders the cut before the gate, so the cut is issued on its own (its `cut` verdict ends the turn, batching with nothing) and the gate runs in the fresh process where the carried cut keeps this guard silent; the refusal therefore stays `refuse` as insurance and the collateral is gone from the default path rather than from the guard"
35
- }
36
- ];
37
- var KNOWN_GUARD_IDS = LANE_GUARD_POLICY.map((entry) => entry.id);
38
- function entry_for(id) {
39
- return LANE_GUARD_POLICY.find((entry) => entry.id === id.trim());
40
- }
41
- function mode_in_lane_child(id) {
42
- return entry_for(id)?.mode_in_lane_child ?? DEFAULT_MODE;
43
- }
44
- function mode_here(id, directory = process.cwd(), source = process.env) {
45
- const lane_mode = mode_in_lane_child(id);
46
- if (lane_mode === DEFAULT_MODE) return DEFAULT_MODE;
47
- return lane_child_marker.is_child_of(directory, source) ? lane_mode : DEFAULT_MODE;
48
- }
49
- function is_suppressed_here(id, directory = process.cwd(), source = process.env) {
50
- return mode_here(id, directory, source) === OFF_MODE;
51
- }
52
- var lane_guard_policy = {
53
- LANE_GUARD_POLICY,
54
- KNOWN_GUARD_IDS,
55
- entry_for,
56
- mode_in_lane_child,
57
- mode_here,
58
- is_suppressed_here
59
- };
60
-
61
- // scripts/time-runtime/time-agent-bundles.ts
62
- var NONE = 0;
63
- var ONE = 1;
64
- var MIN_GROUP = 2;
65
- function is_launch(span) {
66
- return span.category === time_spans.TOOL_CATEGORY && !span.is_continuation && time_bundle_call.is_launch_tool(span.label);
67
- }
68
- function new_walk() {
69
- return { closed: [], open: NONE, wrote_since: false, turn_id: time_spans.NO_MESSAGE_ID };
70
- }
71
- function close_group(walk) {
72
- if (walk.open >= MIN_GROUP) walk.closed.push(walk.open);
73
- walk.open = NONE;
74
- }
75
- function is_same_turn(walk, span) {
76
- return span.message_id !== time_spans.NO_MESSAGE_ID && span.message_id === walk.turn_id;
77
- }
78
- function open_turn(walk, span) {
79
- if (walk.wrote_since || span.has_prior_reference) close_group(walk);
80
- walk.open += ONE;
81
- walk.turn_id = span.message_id;
82
- walk.wrote_since = false;
83
- }
84
- function step(walk, span) {
85
- if (span.is_writing) {
86
- walk.wrote_since = true;
87
- return;
88
- }
89
- if (!is_launch(span) || is_same_turn(walk, span)) return;
90
- open_turn(walk, span);
91
- }
92
- function agent_bundles(spans) {
93
- const walk = new_walk();
94
- for (const span of time_round_trips.in_time_order(spans)) step(walk, span);
95
- close_group(walk);
96
- return walk.closed;
97
- }
98
- var time_agent_bundles = { agent_bundles };
99
-
100
- // scripts/time-runtime/time-bundles.ts
101
- var { unmeasured_row } = time_format;
102
- var HEADING = "Bundling:";
103
- var SEQUENCE_LABEL = "bundleable sequences";
104
- var RECOVERABLE_LABEL = "recoverable round trips";
105
- var SAVING_LABEL = "recoverable wait";
106
- var BY_TOOL_LABEL = "recoverable by tool";
107
- var AGENT_ROW_LABEL = "Agent";
108
- var ROW_INDENT = " ";
109
- var MIN_SEQUENCE = 2;
110
- var ONE_CALL = 1;
111
- var NONE2 = 0;
112
- var PATH_SEPARATOR = "/";
113
- var FIRST_CALL = 1;
114
- var NO_LABEL = "";
115
- var NO_BUNDLES = {
116
- sequence_count: 0,
117
- longest_sequence: 0,
118
- recoverable_round_trips: 0,
119
- by_tool: [],
120
- unattributed_round_trips: 0,
121
- is_measured: false
122
- };
123
- function contains_segments(whole, part) {
124
- if (whole.startsWith(`${part}${PATH_SEPARATOR}`)) return true;
125
- return whole.endsWith(`${PATH_SEPARATOR}${part}`) || whole.includes(`${PATH_SEPARATOR}${part}${PATH_SEPARATOR}`);
126
- }
127
- function is_related(left, right) {
128
- if (left === right) return true;
129
- return contains_segments(left, right) || contains_segments(right, left);
130
- }
131
- function shares_target(left, right) {
132
- return left.some((one) => right.some((other) => is_related(one, other)));
133
- }
134
- function is_dependent(earlier, later) {
135
- if (earlier.is_writing && later.is_writing) return false;
136
- return shares_target(earlier.targets, later.targets);
137
- }
138
- function conflicts(span, sequence) {
139
- return sequence.some((earlier) => is_dependent(earlier, span));
140
- }
141
- function is_call(span) {
142
- return span.category === time_spans.TOOL_CATEGORY && !span.is_continuation;
143
- }
144
- function is_turn_boundary(span) {
145
- return span.category === time_spans.MODEL_CATEGORY;
146
- }
147
- function new_walk2() {
148
- return { pending: [], sequence: [], closed: [] };
149
- }
150
- function flush(walk) {
151
- if (walk.sequence.length >= MIN_SEQUENCE) walk.closed.push(walk.sequence);
152
- walk.sequence = [];
153
- }
154
- function extend(walk, span) {
155
- if (conflicts(span, walk.sequence)) flush(walk);
156
- walk.sequence.push(span);
157
- }
158
- function close_trip(walk) {
159
- const [only] = walk.pending;
160
- if (walk.pending.length === ONE_CALL && only?.is_bundleable === true) extend(walk, only);
161
- else if (walk.pending.length > NONE2) flush(walk);
162
- walk.pending = [];
163
- }
164
- function is_same_turn2(span, pending) {
165
- const [first] = pending;
166
- if (first === void 0 || span.is_continuation || span.message_id === time_spans.NO_MESSAGE_ID) {
167
- return false;
168
- }
169
- return span.message_id === first.message_id;
170
- }
171
- function step2(walk, span) {
172
- if (is_call(span)) {
173
- walk.pending.push(span);
174
- return;
175
- }
176
- if (is_same_turn2(span, walk.pending)) return;
177
- close_trip(walk);
178
- if (!is_turn_boundary(span)) flush(walk);
179
- }
180
- function longest_of(sizes) {
181
- return sizes.length === NONE2 ? NONE2 : Math.max(...sizes);
182
- }
183
- function recoverable_of(sizes) {
184
- return sizes.reduce((sum, size) => sum + size - ONE_CALL, NONE2);
185
- }
186
- function sizes_of(closed) {
187
- return closed.map((sequence) => sequence.length);
188
- }
189
- function tally_for(tallies, label) {
190
- const found = tallies.get(label);
191
- if (found !== void 0) return found;
192
- const created = { sequence_count: NONE2, recoverable_round_trips: NONE2 };
193
- tallies.set(label, created);
194
- return created;
195
- }
196
- function count_trip(tallies, counted, label) {
197
- const tally = tally_for(tallies, label);
198
- tally.recoverable_round_trips += ONE_CALL;
199
- if (!counted.has(label)) tally.sequence_count += ONE_CALL;
200
- counted.add(label);
201
- }
202
- function tally_sequence(tallies, sequence) {
203
- const counted = /* @__PURE__ */ new Set();
204
- for (const span of sequence.slice(FIRST_CALL)) {
205
- if (span.label !== NO_LABEL) count_trip(tallies, counted, span.label);
206
- }
207
- }
208
- function by_weight(left, right) {
209
- if (left.recoverable_round_trips !== right.recoverable_round_trips) {
210
- return right.recoverable_round_trips - left.recoverable_round_trips;
211
- }
212
- return left.label.localeCompare(right.label);
213
- }
214
- function tool_rows(closed) {
215
- const tallies = /* @__PURE__ */ new Map();
216
- for (const sequence of closed) tally_sequence(tallies, sequence);
217
- return [...tallies].map(([label, tally]) => ({ label, ...tally })).toSorted(by_weight);
218
- }
219
- function attributed_of(rows) {
220
- return rows.reduce((sum, row) => sum + row.recoverable_round_trips, NONE2);
221
- }
222
- function with_agent_row(rows, agent_sizes) {
223
- const recoverable_round_trips = recoverable_of(agent_sizes);
224
- if (recoverable_round_trips === NONE2) return [...rows];
225
- const row = {
226
- label: AGENT_ROW_LABEL,
227
- sequence_count: agent_sizes.length,
228
- recoverable_round_trips
229
- };
230
- return [...rows, row].toSorted(by_weight);
231
- }
232
- function build_bundles(spans) {
233
- const walk = new_walk2();
234
- for (const span of time_round_trips.in_time_order(spans)) step2(walk, span);
235
- close_trip(walk);
236
- flush(walk);
237
- const sizes = sizes_of(walk.closed);
238
- const agent_sizes = time_agent_bundles.agent_bundles(spans);
239
- const by_tool = with_agent_row(tool_rows(walk.closed), agent_sizes);
240
- const recoverable_round_trips = recoverable_of(sizes) + recoverable_of(agent_sizes);
241
- return {
242
- sequence_count: sizes.length + agent_sizes.length,
243
- longest_sequence: Math.max(longest_of(sizes), longest_of(agent_sizes)),
244
- recoverable_round_trips,
245
- by_tool,
246
- unattributed_round_trips: recoverable_round_trips - attributed_of(by_tool),
247
- is_measured: time_spans.has_transcript_data(spans.length)
248
- };
249
- }
250
- function open_sequence(spans) {
251
- const walk = new_walk2();
252
- for (const span of time_round_trips.in_time_order(spans)) step2(walk, span);
253
- return walk.sequence;
254
- }
255
- function sequence_suffix(totals) {
256
- return `longest ${String(totals.longest_sequence)} turn(s)`;
257
- }
258
- function recoverable_suffix(totals, round_trip_count) {
259
- const share = time_format.format_share(totals.recoverable_round_trips, round_trip_count);
260
- return `${share} of ${String(round_trip_count)} round trip(s)`;
261
- }
262
- function saving_line(totals, model_ms_per_round_trip) {
263
- const saved_ms = totals.recoverable_round_trips * model_ms_per_round_trip;
264
- const rate = `at ${time_format.format_seconds(model_ms_per_round_trip)} model time per round trip`;
265
- return time_format.format_row(SAVING_LABEL, saved_ms, rate);
266
- }
267
- function by_tool_suffix(totals) {
268
- const attributed = totals.recoverable_round_trips - totals.unattributed_round_trips;
269
- return `${String(attributed)} of ${String(totals.recoverable_round_trips)} attributed`;
270
- }
271
- function tool_row(row) {
272
- return time_format.format_columns(
273
- `${ROW_INDENT}${row.label}`,
274
- String(row.recoverable_round_trips),
275
- `in ${String(row.sequence_count)} sequence(s)`
276
- );
277
- }
278
- function by_tool_lines(totals) {
279
- const heading = time_format.format_columns(
280
- BY_TOOL_LABEL,
281
- String(totals.by_tool.length),
282
- by_tool_suffix(totals)
283
- );
284
- const rows = totals.by_tool.slice(NONE2, time_format.MAX_ROWS).map((row) => tool_row(row));
285
- return [heading, ...rows, ...time_format.overflow_line(totals.by_tool.length)];
286
- }
287
- function measured_lines(totals, price) {
288
- return [
289
- time_format.format_columns(
290
- SEQUENCE_LABEL,
291
- String(totals.sequence_count),
292
- sequence_suffix(totals)
293
- ),
294
- time_format.format_columns(
295
- RECOVERABLE_LABEL,
296
- String(totals.recoverable_round_trips),
297
- recoverable_suffix(totals, price.round_trip_count)
298
- ),
299
- saving_line(totals, price.model_ms_per_round_trip),
300
- ...by_tool_lines(totals)
301
- ];
302
- }
303
- var LABELS = [SEQUENCE_LABEL, RECOVERABLE_LABEL, SAVING_LABEL, BY_TOOL_LABEL];
304
- function no_divisor_lines() {
305
- return LABELS.map((label) => time_format.format_columns(label, "", time_format.NO_CALLS));
306
- }
307
- function bundle_lines(totals, price) {
308
- const heading = ["", HEADING];
309
- if (!totals.is_measured) return [...heading, ...LABELS.map((label) => unmeasured_row(label))];
310
- if (price.round_trip_count === NONE2) return [...heading, ...no_divisor_lines()];
311
- return [...heading, ...measured_lines(totals, price)];
312
- }
313
- var time_bundles = {
314
- HEADING,
315
- BY_TOOL_LABEL,
316
- NO_BUNDLES,
317
- build_bundles,
318
- bundle_lines,
319
- is_dependent,
320
- open_sequence,
321
- shares_target
322
- };
323
-
324
- // scripts/time-runtime/time-command-key.ts
325
- var UNNAMED_KEY = "";
326
- function command_key(span) {
327
- if (span.label === time_spans.UNKNOWN_TOOL) return UNNAMED_KEY;
328
- return span.josh_command === "" ? span.label : span.josh_command;
329
- }
330
- var time_command_key = { UNNAMED_KEY, command_key };
331
-
332
- // scripts/time-runtime/time-call-identity.ts
333
- var IDENTITY_SEPARATOR = "\0";
334
- function identity_of(call) {
335
- return [
336
- time_command_key.command_key(call),
337
- call.check_key,
338
- [...call.targets].toSorted((left, right) => left.localeCompare(right)).join(",")
339
- ].join(IDENTITY_SEPARATOR);
340
- }
341
- var time_call_identity = { identity_of };
342
-
343
- // scripts/time-runtime/time-batch-guard.ts
344
- var CONSECUTIVE_LIMIT = 3;
345
- var REFIRE_EVERY = CONSECUTIVE_LIMIT;
346
- var ONE_TURN = 1;
347
- var NONE3 = 0;
348
- var NOTICE_REFIRE_EVERY = ONE_TURN;
349
- var NAMED_CANDIDATE_COUNT = 3;
350
- var SEQUENCE_BEFORE_LIMIT = CONSECUTIVE_LIMIT - ONE_TURN;
351
- var REASON = `\u26D4 batching: the last ${String(SEQUENCE_BEFORE_LIMIT)} turns each issued a single tool call, so this one would make ${String(CONSECUTIVE_LIMIT)} in a row. Reissue it in one turn together with the calls meant to follow it that do not need its result. **The criterion is whether this call's input needs another call's result, not what kind of call it is** \u2014 edits are covered exactly as reads are, and it never authorizes weakening a verification gate or a review: fewer turns, never less work. The measured cost and the rejected mechanisms are in \`prompts/collaboration-workflow/turn-batching.md\`. If this turn was already batching, or the call genuinely has nothing to go beside it, reissue it as it was: this fires once per run of single-call turns and cannot repeat on the call in hand.`;
352
- var NOTICE = `\u{1F4A1} batching: the last ${String(SEQUENCE_BEFORE_LIMIT)} turns each issued a single tool call, so this Write makes ${String(CONSECUTIVE_LIMIT)} in a row. This is a notice, not a refusal \u2014 the write proceeds. Where the writes meant to follow it do not need its result, issue them in one turn together. **The criterion is whether a call's input needs another call's result, not what kind of call it is** \u2014 it never authorizes weakening a verification gate or a review: fewer turns, never less work. The measured cost and the rejected mechanisms are in \`prompts/collaboration-workflow/turn-batching.md\`. If this run was already batching, or the write genuinely has nothing to go beside it, carry on: this recurs every ${String(NOTICE_REFIRE_EVERY)} further single-call turn(s).`;
353
- var LANE_NOTICE = `\u{1F4A1} batching: the last ${String(SEQUENCE_BEFORE_LIMIT)} turns each issued a single tool call, so this one makes ${String(CONSECUTIVE_LIMIT)} in a row. This is a notice, not a refusal \u2014 the call proceeds, because a dispatched lane child ends its turn on a denial. Where the calls meant to follow it do not need its result, issue them in one turn together. **The criterion is whether a call's input needs another call's result, not what kind of call it is** \u2014 it never authorizes weakening a verification gate or a review: fewer turns, never less work. The measured cost and the rejected mechanisms are in \`prompts/collaboration-workflow/turn-batching.md\`. If this run was already batching, or the call genuinely has nothing to go beside it, carry on: this recurs every ${String(NOTICE_REFIRE_EVERY)} further single-call turn(s).`;
354
- var WHOLE_FILE_WRITE_TOOL = "Write";
355
- var EDIT_TOOL = "Edit";
356
- function is_guarded_call(call) {
357
- if (call.name === WHOLE_FILE_WRITE_TOOL) return false;
358
- return time_bundle_call.call_facts(call.name, call.input).is_bundleable;
359
- }
360
- function is_notice_call(call) {
361
- return call.name === WHOLE_FILE_WRITE_TOOL;
362
- }
363
- function is_read_only_call(call) {
364
- const facts = time_bundle_call.call_facts(call.name, call.input);
365
- return facts.is_bundleable && !facts.may_write;
366
- }
367
- function depends_on_sequence(sequence, facts) {
368
- return sequence.some((span) => time_bundles.shares_target(span.targets, facts.targets));
369
- }
370
- function sequence_started_ms(sequence) {
371
- return sequence[0]?.ended_ms ?? NONE3;
372
- }
373
- function turns_since(sequence, last_fired_ms) {
374
- return sequence.filter((span) => span.ended_ms > last_fired_ms).length;
375
- }
376
- function is_sequence_at_limit(sequence, facts, last_fired_ms, refire_every) {
377
- if (sequence.length < SEQUENCE_BEFORE_LIMIT || depends_on_sequence(sequence, facts)) return false;
378
- if (last_fired_ms < sequence_started_ms(sequence)) return true;
379
- return turns_since(sequence, last_fired_ms) >= refire_every;
380
- }
381
- function is_at_limit(spans, call, last_fired_ms, refire_every) {
382
- return is_sequence_at_limit(
383
- time_bundles.open_sequence(spans),
384
- time_bundle_call.call_facts(call.name, call.input),
385
- last_fired_ms,
386
- refire_every
387
- );
388
- }
389
- var GUARD_LABEL = time_transcript_line.guard_from_refusal(REASON);
390
- function is_reissued_refusal(spans, call) {
391
- const identity = time_call_identity.identity_of(
392
- time_spans.to_tool_call(call.name, call.input, time_spans.NO_MESSAGE_ID)
393
- );
394
- return spans.some(
395
- (span) => span.refusal_guard === GUARD_LABEL && time_call_identity.identity_of(span) === identity
396
- );
397
- }
398
- function should_block(text, call, refused_at_ms, refire_every = REFIRE_EVERY) {
399
- if (!is_guarded_call(call)) return false;
400
- const { spans } = time_spans.parse_timeline(text);
401
- if (is_reissued_refusal(spans, call)) return false;
402
- return is_at_limit(spans, call, refused_at_ms, refire_every);
403
- }
404
- function should_notify(text, call, notified_at_ms) {
405
- if (!is_notice_call(call)) return false;
406
- const { spans } = time_spans.parse_timeline(text);
407
- return is_at_limit(spans, call, notified_at_ms, NOTICE_REFIRE_EVERY);
408
- }
409
- function describe_span(span) {
410
- const target = span.targets[0] ?? "";
411
- if (target === "" || span.label.includes(target)) return span.label;
412
- return `${span.label} ${target}`;
413
- }
414
- var FOLD_MINIMUM = 2;
415
- function read_targets(sequence) {
416
- const paths = sequence.filter((span) => span.is_bundleable && !span.is_writing).map((span) => span.targets[0] ?? "").filter((path) => path !== "" && time_bundle_call.has_extension(path));
417
- return [...new Set(paths)];
418
- }
419
- function read_fold_directive(sequence) {
420
- const paths = read_targets(sequence);
421
- if (paths.length < FOLD_MINIMUM) return "";
422
- return ` Fold them into one call: \`pnpm josh read:files ${paths.join(" ")}\`.`;
423
- }
424
- function write_targets(sequence) {
425
- const paths = sequence.filter((span) => span.label === EDIT_TOOL).map((span) => span.targets[0] ?? "").filter((path) => path !== "" && time_bundle_call.has_extension(path));
426
- return [...new Set(paths)];
427
- }
428
- function write_fold_directive(sequence) {
429
- const paths = write_targets(sequence);
430
- if (paths.length < FOLD_MINIMUM) return "";
431
- return ` Fold them into one \`pnpm josh edit:files\` call with a plan over: ${paths.join(" ")}.`;
432
- }
433
- function recent_candidates(tail) {
434
- const recent = time_bundles.open_sequence(time_spans.parse_timeline(tail).spans).slice(-NAMED_CANDIDATE_COUNT);
435
- if (recent.length === NONE3) return "";
436
- const named = recent.map((span) => describe_span(span)).join(", ");
437
- const folds = `${read_fold_directive(recent)}${write_fold_directive(recent)}`;
438
- return ` Just issued one per turn, so at least these could have shared a turn: ${named}.${folds}`;
439
- }
440
- var STAMP_PREFIX = "josh-batch-guard-";
441
- var NOTICE_STAMP_PREFIX = "josh-batch-guard-notice-";
442
- var time_batch_guard = {
443
- CONSECUTIVE_LIMIT,
444
- GUARD_LABEL,
445
- LANE_NOTICE,
446
- NOTICE,
447
- NOTICE_REFIRE_EVERY,
448
- NOTICE_STAMP_PREFIX,
449
- REASON,
450
- REFIRE_EVERY,
451
- SEQUENCE_BEFORE_LIMIT,
452
- STAMP_PREFIX,
453
- is_guarded_call,
454
- is_notice_call,
455
- is_read_only_call,
456
- recent_candidates,
457
- should_block,
458
- should_notify
459
- };
460
-
461
- export {
462
- lane_guard_policy,
463
- time_batch_guard
464
- };