@gobing-ai/spur 0.4.2 → 0.4.3

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 (133) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/config/decisions/maker-liveness.yaml +39 -0
  3. package/config/plugin-scripts.json +0 -4
  4. package/config/rules/README.md +1 -0
  5. package/config/rules/docs/sourced-api-claims.yaml +56 -12
  6. package/config/rules/strict/runtime-boundaries.yaml +7 -0
  7. package/config/script-placement-baseline.json +1 -19
  8. package/config/workflows/feature-lifecycle.yaml +46 -1
  9. package/config/workflows/feature-verification.yaml +11 -0
  10. package/package.json +9 -9
  11. package/plugins/sp/README.md +22 -16
  12. package/plugins/sp/agents/super-reviewer.md +43 -0
  13. package/plugins/sp/bunfig.toml +8 -5
  14. package/plugins/sp/hooks/careful-guard.ts +1 -1
  15. package/plugins/sp/hooks/context-post-tool.ts +7 -427
  16. package/plugins/sp/hooks/context-session-start.ts +5 -213
  17. package/plugins/sp/hooks/context-session-stop.ts +5 -191
  18. package/plugins/sp/hooks/pi/guard-extension.ts +6 -5
  19. package/plugins/sp/hooks/task-write-guard.ts +1 -1
  20. package/plugins/sp/{hooks → lib}/agent-hint.ts +1 -1
  21. package/plugins/sp/lib/context-post-tool.ts +432 -0
  22. package/plugins/sp/lib/context-session-start.ts +214 -0
  23. package/plugins/sp/lib/context-session-stop.ts +196 -0
  24. package/plugins/sp/lib/dogfood-pipeline.ts +265 -0
  25. package/plugins/sp/lib/dogfood-report.ts +278 -0
  26. package/plugins/sp/lib/idea-handoff.generated.mjs +3 -3
  27. package/plugins/sp/lib/inline-run-app.ts +40 -0
  28. package/plugins/sp/lib/inline-run.generated.d.mts +3 -3
  29. package/plugins/sp/lib/inline-run.generated.mjs +1347 -90
  30. package/plugins/sp/lib/plan-projection.generated.d.mts +150 -0
  31. package/plugins/sp/lib/plan-projection.generated.mjs +591 -1
  32. package/plugins/sp/lib/quality-gate.generated.mjs +38 -25
  33. package/plugins/sp/lib/residual-scan.generated.d.mts +7 -1
  34. package/plugins/sp/lib/residual-scan.generated.mjs +71 -6
  35. package/plugins/sp/lib/run-summary-core.ts +34 -370
  36. package/plugins/sp/lib/transcript.ts +37 -228
  37. package/plugins/sp/plugin.json +1 -1
  38. package/plugins/sp/scripts/batch-plan.mjs +586 -0
  39. package/plugins/sp/scripts/batch-preflight.mjs +23 -1
  40. package/plugins/sp/scripts/batch-preflight.ts +35 -295
  41. package/plugins/sp/scripts/daily-summary/daily-summary.mjs +108 -87
  42. package/plugins/sp/scripts/daily-summary/daily-summary.ts +111 -104
  43. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +2 -1
  44. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +7 -265
  45. package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +3 -0
  46. package/plugins/sp/scripts/dogfood-testing/validate-report.ts +6 -272
  47. package/plugins/sp/scripts/feature-verification-steps.mjs +7 -123
  48. package/plugins/sp/scripts/feature-verification-steps.ts +29 -181
  49. package/plugins/sp/scripts/inline-run-dispatch.mjs +27 -26
  50. package/plugins/sp/scripts/inline-run-dispatch.ts +1 -21
  51. package/plugins/sp/scripts/inline-run-setup.mjs +149 -122
  52. package/plugins/sp/scripts/inline-run-setup.ts +1 -21
  53. package/plugins/sp/scripts/quality-gate.mjs +14 -2
  54. package/plugins/sp/scripts/residual-scan.mjs +73 -6
  55. package/plugins/sp/scripts/residual-scan.ts +8 -5
  56. package/plugins/sp/scripts/run-summary.mjs +151 -97
  57. package/plugins/sp/scripts/run-summary.ts +7 -5
  58. package/plugins/sp/scripts/session-timeline.mjs +46 -19
  59. package/plugins/sp/scripts/task-diffstat.mjs +11 -1
  60. package/plugins/sp/scripts/task-diffstat.ts +8 -39
  61. package/plugins/sp/skills/code-implementation/SKILL.md +7 -1
  62. package/plugins/sp/skills/code-verification/references/secu-review.md +2 -1
  63. package/plugins/sp/skills/code-verification/references/verdict-schema.md +4 -0
  64. package/plugins/sp/skills/dogfood-testing/SKILL.md +2 -2
  65. package/plugins/sp/skills/next-feature/SKILL.md +1 -1
  66. package/plugins/sp/skills/parallel-execution/references/dispatch-surface.md +1 -1
  67. package/plugins/sp/skills/source-driven-development/SKILL.md +7 -4
  68. package/plugins/sp/skills/spur-cli/references/builder.md +3 -2
  69. package/plugins/sp/skills/spur-cli/references/decision.md +32 -7
  70. package/plugins/sp/skills/spur-cli/references/features.md +46 -5
  71. package/plugins/sp/skills/spur-dev/references/execution-batch-report.md +1 -1
  72. package/plugins/sp/skills/spur-dev/references/execution-batch.md +13 -3
  73. package/plugins/sp/skills/spur-dev/references/execution-worktree-landing.md +22 -0
  74. package/plugins/sp/skills/spur-dev/references/execution-worktree-setup.md +14 -0
  75. package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +29 -12
  76. package/spur.js +80681 -79296
  77. package/web/_astro/{BoardApp.B3GQZvj8.js → BoardApp.5IIl2O-z.js} +1 -1
  78. package/web/_astro/{BoardApp.BT7L2kSb.js → BoardApp.Drnx-KeM.js} +150 -150
  79. package/web/_astro/{TaskDetail.Cxov1_N_.js → TaskDetail.Ci4LNn9S.js} +1 -1
  80. package/web/_astro/{arc.vaT7tPOB.js → arc.j2EVkYVd.js} +1 -1
  81. package/web/_astro/{architectureDiagram-3BPJPVTR.DRMmTjkN.js → architectureDiagram-3BPJPVTR.DZWSFqEG.js} +1 -1
  82. package/web/_astro/{blockDiagram-GPEHLZMM.cla0LO_q.js → blockDiagram-GPEHLZMM.DE6GpXCN.js} +1 -1
  83. package/web/_astro/{c4Diagram-AAUBKEIU.D4YAIBKn.js → c4Diagram-AAUBKEIU.DoVR1G6B.js} +1 -1
  84. package/web/_astro/channel.DmdDxGsq.js +1 -0
  85. package/web/_astro/{chunk-2J33WTMH.BrSJbMRZ.js → chunk-2J33WTMH.Do6-Gbyf.js} +1 -1
  86. package/web/_astro/{chunk-4BX2VUAB.CuLMgKF5.js → chunk-4BX2VUAB.BYV1HGHx.js} +1 -1
  87. package/web/_astro/{chunk-55IACEB6.zkvgu54F.js → chunk-55IACEB6.CvI1zkrc.js} +1 -1
  88. package/web/_astro/{chunk-727SXJPM.DxWkACh8.js → chunk-727SXJPM.DNGSCRlX.js} +1 -1
  89. package/web/_astro/{chunk-AQP2D5EJ.42XrmIlH.js → chunk-AQP2D5EJ.DXhhgT5z.js} +1 -1
  90. package/web/_astro/{chunk-FMBD7UC4.Bao2wMK9.js → chunk-FMBD7UC4.dzkRKP2u.js} +1 -1
  91. package/web/_astro/{chunk-ND2GUHAM.BhydojD1.js → chunk-ND2GUHAM.DujGLeEf.js} +1 -1
  92. package/web/_astro/{chunk-QZHKN3VN.CmZ82g-H.js → chunk-QZHKN3VN.BWtIT3ZU.js} +1 -1
  93. package/web/_astro/{classDiagram-4FO5ZUOK.Blr83Gt_.js → classDiagram-4FO5ZUOK.DyApg0Nn.js} +1 -1
  94. package/web/_astro/{classDiagram-v2-Q7XG4LA2.Blr83Gt_.js → classDiagram-v2-Q7XG4LA2.DyApg0Nn.js} +1 -1
  95. package/web/_astro/{cose-bilkent-S5V4N54A.qmfv0SPn.js → cose-bilkent-S5V4N54A.DJQB-u_l.js} +1 -1
  96. package/web/_astro/{cynefin-OW5HDTMX.BtELhXPR.js → cynefin-OW5HDTMX.bi3D_siV.js} +1 -1
  97. package/web/_astro/{dagre-BM42HDAG.AWmaAvXo.js → dagre-BM42HDAG.C-f7TrRg.js} +1 -1
  98. package/web/_astro/{diagram-2AECGRRQ.DdH34KDi.js → diagram-2AECGRRQ.DrPfjHQB.js} +1 -1
  99. package/web/_astro/{diagram-5GNKFQAL.BmNPix1k.js → diagram-5GNKFQAL.C9S4WUHO.js} +1 -1
  100. package/web/_astro/{diagram-KO2AKTUF.BNQd_Ppo.js → diagram-KO2AKTUF.Dzzye8QH.js} +1 -1
  101. package/web/_astro/{diagram-LMA3HP47.BAPgDi0e.js → diagram-LMA3HP47.DX-LRiof.js} +1 -1
  102. package/web/_astro/{diagram-OG6HWLK6.DZ4zyLdC.js → diagram-OG6HWLK6.Z-kAKwIz.js} +1 -1
  103. package/web/_astro/{erDiagram-TEJ5UH35.Q1TySMmw.js → erDiagram-TEJ5UH35.D6dyClSv.js} +1 -1
  104. package/web/_astro/{flowDiagram-I6XJVG4X.BXhFBicG.js → flowDiagram-I6XJVG4X.Cx3q2cxD.js} +1 -1
  105. package/web/_astro/{ganttDiagram-6RSMTGT7.vHSgcuo2.js → ganttDiagram-6RSMTGT7.DU3gH6CT.js} +1 -1
  106. package/web/_astro/{gitGraphDiagram-PVQCEYII.Bi1f73C7.js → gitGraphDiagram-PVQCEYII.ISmCnJ87.js} +1 -1
  107. package/web/_astro/index.Do2lLdgo.css +1 -0
  108. package/web/_astro/{infoDiagram-5YYISTIA.DPvXZEWm.js → infoDiagram-5YYISTIA.DR6_iNOK.js} +1 -1
  109. package/web/_astro/{ishikawaDiagram-YF4QCWOH.Cz829fsV.js → ishikawaDiagram-YF4QCWOH.D7wY-ZGA.js} +1 -1
  110. package/web/_astro/{journeyDiagram-JHISSGLW.enRnB9Me.js → journeyDiagram-JHISSGLW.DkP9-WK8.js} +1 -1
  111. package/web/_astro/{kanban-definition-UN3LZRKU.DnTNk6d2.js → kanban-definition-UN3LZRKU.wtgY98M2.js} +1 -1
  112. package/web/_astro/{linear.BzGnBwNL.js → linear.CI6djNi7.js} +1 -1
  113. package/web/_astro/{mermaid.core.CSbTpIVz.js → mermaid.core.CuQPxS8b.js} +4 -4
  114. package/web/_astro/{mindmap-definition-RKZ34NQL.DGJDy8zT.js → mindmap-definition-RKZ34NQL.5HNIEG7R.js} +1 -1
  115. package/web/_astro/{pieDiagram-4H26LBE5.HSPdi5_8.js → pieDiagram-4H26LBE5.CchhDFjE.js} +1 -1
  116. package/web/_astro/{quadrantDiagram-W4KKPZXB.6Gv8mz2Y.js → quadrantDiagram-W4KKPZXB.PYXXJPSJ.js} +1 -1
  117. package/web/_astro/{requirementDiagram-4Y6WPE33.CnBCtFwa.js → requirementDiagram-4Y6WPE33.cUQuNAKU.js} +1 -1
  118. package/web/_astro/{sankeyDiagram-5OEKKPKP.5M8VWAu8.js → sankeyDiagram-5OEKKPKP.BO7MnRIA.js} +1 -1
  119. package/web/_astro/{sequenceDiagram-3UESZ5HK.DN41XN-U.js → sequenceDiagram-3UESZ5HK.D9bElyD6.js} +1 -1
  120. package/web/_astro/{stateDiagram-AJRCARHV.ErOO3W8j.js → stateDiagram-AJRCARHV.DhGdRz7I.js} +1 -1
  121. package/web/_astro/{stateDiagram-v2-BHNVJYJU.B_ZHICM-.js → stateDiagram-v2-BHNVJYJU.5GvLeAoL.js} +1 -1
  122. package/web/_astro/{timeline-definition-PNZ67QCA.CWdosr07.js → timeline-definition-PNZ67QCA.LtAT9haM.js} +1 -1
  123. package/web/_astro/{vennDiagram-CIIHVFJN.BHzYjNV5.js → vennDiagram-CIIHVFJN.DRth1yLA.js} +1 -1
  124. package/web/_astro/{wardleyDiagram-YWT4CUSO.h8x4IwPX.js → wardleyDiagram-YWT4CUSO.h9MlZfcr.js} +1 -1
  125. package/web/_astro/{xychartDiagram-2RQKCTM6.RTapW2X8.js → xychartDiagram-2RQKCTM6.DHqy9DYA.js} +1 -1
  126. package/web/index.html +2 -2
  127. package/config/proportional-route-table.ts +0 -155
  128. package/plugins/sp/scripts/daily-summary/logger.ts +0 -28
  129. package/web/_astro/channel.D4nG9YLf.js +0 -1
  130. package/web/_astro/index.BhSwN8yY.css +0 -1
  131. /package/plugins/sp/{hooks → lib}/context-owner.ts +0 -0
  132. /package/plugins/sp/{hooks → lib}/destructive-policy.ts +0 -0
  133. /package/plugins/sp/{hooks → lib}/task-file-policy.ts +0 -0
@@ -1,377 +1,43 @@
1
1
  /**
2
- * run-summary core — the measurement and rendering behind the `run-summary` CLI (task 1146).
2
+ * run-summary core — the rendering and host IO behind the `run-summary` CLI (task 1146; task 1178 R2).
3
3
  *
4
4
  * Split out of `plugins/sp/scripts/run-summary.ts` when the actor split and the batch roll-up pushed
5
- * that script past the ADR-130 glue budget: the script keeps argv parsing and dispatch, this module
6
- * keeps the logic. `plugins/sp/lib/transcript.ts` is the same shape of shared plugin-side module.
7
- * Node builtins plus relative imports only; `import type` for the app projection it is handed.
5
+ * that script past the ADR-130 glue budget. The PURE aggregation and its types now live in
6
+ * `packages/app/src/workflow/run-summary.ts`, reached through the generated pure plan-projection
7
+ * entry; this module keeps only what belongs to the host: the close-step callback, the receipt read,
8
+ * Markdown rendering and durable/scratch report writing. Node builtins plus relative imports only;
9
+ * `import type` for the app projection it is handed.
8
10
  */
9
11
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
10
12
  import { join } from 'node:path';
11
13
  import type { WorkflowProgressProjection } from '@gobing-ai/spur-app';
14
+ import { getEnvVars } from './env';
12
15
  import {
13
- accumulate,
14
- type Block,
16
+ type ActorSplit,
17
+ buildRunSummary,
15
18
  formatDuration,
16
19
  formatTokenSplit,
17
- isCompaction,
18
- newAcc,
19
- parseRows,
20
- promptText,
21
- resolveTranscript,
22
- type Row,
23
- type Span,
24
- sumSpans,
20
+ type GateTime,
21
+ type Progress,
22
+ type RunSummary,
23
+ type SummaryRow,
25
24
  sumTokens,
26
- type Tokens,
27
25
  zeroTokens,
28
- } from './transcript';
29
- import { getEnvVars } from './env';
30
-
31
- interface ProgressAttempt {
32
- startedAt?: string;
33
- completedAt?: string;
34
- }
35
-
36
- /**
37
- * The subset of the progress projection the summary windows over. The close path hands over the
38
- * full `WorkflowProgressProjection`; the extra fields are ignored here, so the reader stays a
39
- * narrow structural view of it rather than a second copy of the contract.
40
- */
41
- export interface Progress {
42
- runId: string;
43
- workflow?: string;
44
- status?: string;
45
- states?: { state: string; visit?: number; status?: string; actions?: { attempts?: ProgressAttempt[] }[] }[];
46
- }
47
-
48
- /** A stage row; `toolCalls`/`tokens` are null when the window holds no host transcript record. */
49
- export interface SummaryRow {
50
- stage: string;
51
- status: string;
52
- workMs: number;
53
- waitMs: number;
54
- toolCalls: number | null;
55
- tokens: Tokens | null;
56
- time: string;
57
- wait: string;
58
- token: string;
59
- }
60
-
61
- /** 1146 R4: how the total window is spent, by actor. Rows sum exactly to the window. */
62
- export interface ActorSplit {
63
- operatorMs: number;
64
- /** The longest single operator wait, so a total is not read as one stall. */
65
- longestOperatorWaitMs: number;
66
- modelMs: number;
67
- shellMs: number;
68
- subagentMs: number;
69
- otherToolMs: number;
70
- idleMs: number;
71
- compactions: number;
72
- subagentErrors: number;
73
- }
74
-
75
- /** A gate-receipt measurement, or the reason there is none (1146 R4: never a fabricated 0). */
76
- export type GateTime = { ms: number } | { ms: null; reason: string };
77
-
78
- export interface RunSummary {
79
- available: true;
80
- transcript?: string;
81
- rows: SummaryRow[];
82
- total: SummaryRow;
83
- actors: ActorSplit;
84
- gate: GateTime;
85
- skippedLines: number;
86
- }
87
-
88
- /** A gap at or above this is idle, not work (1146 R4, closed decision: fixed, no flag). */
89
- const IDLE_GAP_MS = 300_000;
90
- const SHELL_TOOLS = new Set(['bash', 'shell', 'exec', 'exec_command', 'run_command', 'command']);
91
- const SUBAGENT_TOOLS = new Set(['agent', 'task', 'invoke_subagent', 'subagent', 'dispatch_agent']);
92
- const OPERATOR_TOOLS = new Set(['askuserquestion', 'ask_user_question']);
93
-
94
- type Actor = 'operator' | 'subagent' | 'shell' | 'other';
95
- /** Overlap is counted once, and subagent outranks shell outranks other tools (1146 AC4). */
96
- const ACTOR_PRECEDENCE: Actor[] = ['operator', 'subagent', 'shell', 'other'];
97
-
98
- function actorOf(tool: string): Actor {
99
- const t = tool.toLowerCase().replace(/[^a-z_]/g, '');
100
- if (OPERATOR_TOOLS.has(t)) return 'operator';
101
- if (SUBAGENT_TOOLS.has(t)) return 'subagent';
102
- if (SHELL_TOOLS.has(t)) return 'shell';
103
- return 'other';
104
- }
105
-
106
- interface Call {
107
- id: string;
108
- actor: Actor;
109
- ts: number;
110
- }
111
-
112
- /** One resolved tool span: [start, end] attributed to one actor. */
113
- interface Resolved extends Call {
114
- end: number;
115
- }
116
-
117
- /** Union length of a set of intervals, clipped to [start, end]. */
118
- function unionMs(spans: Array<[number, number]>, start: number, end: number): number {
119
- const clipped = spans
120
- .map(([a, b]) => [Math.max(a, start), Math.min(b, end)] as [number, number])
121
- .filter(([a, b]) => b > a)
122
- .sort((x, y) => x[0] - y[0]);
123
- let total = 0;
124
- let cursor = Number.NaN;
125
- let openUntil = Number.NaN;
126
- for (const [a, b] of clipped) {
127
- if (!Number.isFinite(cursor)) {
128
- cursor = a;
129
- openUntil = b;
130
- continue;
131
- }
132
- if (a > openUntil) {
133
- total += openUntil - cursor;
134
- cursor = a;
135
- openUntil = b;
136
- } else {
137
- openUntil = Math.max(openUntil, b);
138
- }
139
- }
140
- if (Number.isFinite(cursor)) total += openUntil - cursor;
141
- return total;
142
- }
143
-
144
- /** Subtract already-claimed intervals from a candidate set, returning the still-free part. */
145
- function subtract(spans: Array<[number, number]>, claimed: Array<[number, number]>): Array<[number, number]> {
146
- let free = spans;
147
- for (const [ca, cb] of claimed) {
148
- const next: Array<[number, number]> = [];
149
- for (const [a, b] of free) {
150
- if (cb <= a || ca >= b) {
151
- next.push([a, b]);
152
- continue;
153
- }
154
- if (ca > a) next.push([a, ca]);
155
- if (cb < b) next.push([cb, b]);
156
- }
157
- free = next;
158
- }
159
- return free;
160
- }
161
-
162
- /**
163
- * 1146 R4: partition the window [start, end] by actor. Tool calls are paired with their results
164
- * (either host shape); overlaps resolve by `ACTOR_PRECEDENCE`, counted once; unclaimed gaps at or
165
- * above IDLE_GAP_MS are idle; the remainder is model time, so the rows always sum to the window.
166
- */
167
- export function actorSplit(rows: [Row, number][], start: number, end: number): ActorSplit {
168
- const empty: ActorSplit = {
169
- operatorMs: 0,
170
- longestOperatorWaitMs: 0,
171
- modelMs: 0,
172
- shellMs: 0,
173
- subagentMs: 0,
174
- otherToolMs: 0,
175
- idleMs: 0,
176
- compactions: 0,
177
- subagentErrors: 0,
178
- };
179
- const window = end - start;
180
- if (window <= 0) return empty;
181
-
182
- const calls = new Map<string, Call>();
183
- const results = new Map<string, { ts: number; isError: boolean }>();
184
- const eventTs: number[] = [];
185
- let compactions = 0;
186
-
187
- for (const [row, ts] of rows) {
188
- if (ts < start || ts > end) continue;
189
- eventTs.push(ts);
190
- if (isCompaction(row)) compactions++;
191
- const blocks = Array.isArray(row.message?.content) ? (row.message?.content as Block[]) : [];
192
- if (row.message?.role === 'toolResult' && row.message.toolCallId !== undefined) {
193
- results.set(row.message.toolCallId, { ts, isError: row.message.isError === true });
194
- }
195
- for (const b of blocks) {
196
- if ((b.type === 'tool_use' || b.type === 'toolCall') && b.id !== undefined && b.name !== undefined) {
197
- calls.set(b.id, { id: b.id, actor: actorOf(b.name), ts });
198
- } else if (b.type === 'tool_result' && b.tool_use_id !== undefined) {
199
- results.set(b.tool_use_id, { ts, isError: b.is_error === true });
200
- }
201
- }
202
- }
203
-
204
- let subagentErrors = 0;
205
- const resolved: Resolved[] = [];
206
- for (const call of calls.values()) {
207
- const result = results.get(call.id);
208
- if (result?.isError === true && call.actor === 'subagent') subagentErrors++;
209
- resolved.push({ ...call, end: Math.min(result?.ts ?? end, end) });
210
- }
211
-
212
- const claimed: Array<[number, number]> = [];
213
- const byActor = new Map<Actor, number>();
214
- for (const actor of ACTOR_PRECEDENCE) {
215
- const mine = resolved.filter((r) => r.actor === actor).map((r) => [r.ts, r.end] as [number, number]);
216
- const free = subtract(mine, claimed);
217
- for (const span of free) claimed.push(span);
218
- const ms = unionMs(free, start, end);
219
- byActor.set(actor, ms);
220
- if (actor === 'operator') {
221
- empty.longestOperatorWaitMs = Math.max(0, ...mine.map(([a, b]) => b - a));
222
- }
223
- }
224
-
225
- // Idle: unclaimed gaps between consecutive event boundaries, at or above the threshold.
226
- const boundaries = [...new Set([start, end, ...eventTs, ...claimed.flat()])].sort((a, b) => a - b);
227
- const claimedSorted = [...claimed].sort((a, b) => a[0] - b[0]);
228
- let idleMs = 0;
229
- for (let i = 0; i < boundaries.length - 1; i++) {
230
- const a = boundaries[i] as number;
231
- const b = boundaries[i + 1] as number;
232
- if (b - a < IDLE_GAP_MS) continue;
233
- if (claimedSorted.some(([ca, cb]) => ca < b && cb > a)) continue;
234
- idleMs += b - a;
235
- }
236
-
237
- const accounted =
238
- (byActor.get('operator') ?? 0) +
239
- (byActor.get('subagent') ?? 0) +
240
- (byActor.get('shell') ?? 0) +
241
- (byActor.get('other') ?? 0) +
242
- idleMs;
243
- return {
244
- ...empty,
245
- operatorMs: byActor.get('operator') ?? 0,
246
- subagentMs: byActor.get('subagent') ?? 0,
247
- shellMs: byActor.get('shell') ?? 0,
248
- otherToolMs: byActor.get('other') ?? 0,
249
- idleMs,
250
- modelMs: Math.max(0, window - accounted),
251
- compactions,
252
- subagentErrors,
253
- };
254
- }
255
-
256
- interface Window {
257
- stage: string;
258
- status: string;
259
- start: number;
260
- end: number;
261
- }
262
-
263
- function attemptWindow(attempts: ProgressAttempt[]): [number, number] | undefined {
264
- const starts = attempts.map((a) => Date.parse(a.startedAt ?? '')).filter((n) => !Number.isNaN(n));
265
- const ends = attempts.map((a) => Date.parse(a.completedAt ?? '')).filter((n) => !Number.isNaN(n));
266
- return starts.length && ends.length ? [Math.min(...starts), Math.max(...ends)] : undefined;
267
- }
268
-
269
- function summaryRow(stage: string, status: string, span: Span, measured: boolean): SummaryRow {
270
- return {
271
- stage,
272
- status,
273
- workMs: span.workMs,
274
- waitMs: span.waitMs,
275
- toolCalls: measured ? span.toolCalls : null,
276
- tokens: measured ? span.tokens : null,
277
- time: formatDuration(span.workMs),
278
- wait: formatDuration(span.waitMs),
279
- token: formatTokenSplit(measured ? span.tokens : null),
280
- };
281
- }
282
-
283
- /**
284
- * dev-run / dev-runall execution summary. One progress file → one row per state visit; several →
285
- * one row per run. Each window spans its first attempt start → last completion (inclusive) and
286
- * slices the host transcript; work = window − AskUserQuestion answer time.
287
- */
288
- export function buildRunSummary(
289
- lines: string[],
290
- inputs: { label?: string; progress: Progress }[],
291
- since?: string,
292
- until?: string,
293
- ): RunSummary {
294
- const windows: Window[] = [];
295
- for (const { label, progress } of inputs) {
296
- const states = (progress.states ?? []).flatMap((s) => {
297
- const w = attemptWindow((s.actions ?? []).flatMap((a) => a.attempts ?? []));
298
- return w ? [{ s, w }] : [];
299
- });
300
- if (!states.length) throw new Error(`progress for run ${progress.runId} has no timed attempts`);
301
- if (inputs.length === 1) {
302
- for (const { s, w } of states) {
303
- const stage = (s.visit ?? 1) > 1 ? `${s.state} (visit ${s.visit})` : s.state;
304
- windows.push({ stage, status: s.status ?? '', start: w[0], end: w[1] });
305
- }
306
- } else {
307
- const stage = label ?? `${progress.workflow ?? 'run'} ${progress.runId.slice(0, 8)}`;
308
- const start = Math.min(...states.map(({ w }) => w[0]));
309
- windows.push({
310
- stage,
311
- status: progress.status ?? '',
312
- start,
313
- end: Math.max(...states.map(({ w }) => w[1])),
314
- });
315
- }
316
- }
317
- windows.sort((a, b) => a.start - b.start);
318
-
319
- const { rows, skippedLines } = parseRows(lines);
320
- const measure = (start: number, end: number): { span: Span; measured: boolean } => {
321
- const acc = newAcc(start);
322
- for (const [row, ts] of rows)
323
- if (ts >= start && ts <= end && promptText(row) === undefined) accumulate(acc, row, ts);
324
- const span = {
325
- workMs: end - start - acc.askMs,
326
- waitMs: acc.askMs,
327
- toolCalls: acc.toolIds.size,
328
- tokens: sumTokens([...acc.messages.values()]),
329
- };
330
- return { span, measured: acc.toolIds.size > 0 || acc.messages.size > 0 };
331
- };
332
-
333
- const sinceMs = since ? Date.parse(since) : Number.NaN;
334
- const totalStart = Number.isNaN(sinceMs) ? Math.min(...windows.map((w) => w.start)) : sinceMs;
335
- let totalEnd = Math.max(...windows.map((w) => w.end));
336
- // With --since the total runs to the latest host activity, so setup/close work lands in overhead.
337
- if (!Number.isNaN(sinceMs)) for (const [, ts] of rows) if (ts >= sinceMs) totalEnd = Math.max(totalEnd, ts);
338
- // 1146 R1: the close passes its own completion instant, which caps the window exactly.
339
- const untilMs = until ? Date.parse(until) : Number.NaN;
340
- if (!Number.isNaN(untilMs) && untilMs > totalStart) totalEnd = untilMs;
341
-
342
- const stageRows = windows.map((w) => {
343
- const { span, measured } = measure(w.start, w.end);
344
- return summaryRow(w.stage, w.status, span, measured);
345
- });
346
- const totalMeasure = measure(totalStart, totalEnd);
347
- const statuses = [...new Set(inputs.map((i) => i.progress.status ?? ''))].join('/');
348
- const total = summaryRow('Total', statuses, totalMeasure.span, totalMeasure.measured);
349
-
350
- // Parallel runs overlap, so their rows cannot partition the total: no overhead row then.
351
- const overlaps = windows.some((w, i) => i > 0 && w.start < (windows[i - 1]?.end ?? 0));
352
- const sum = sumSpans(
353
- stageRows.map((r) => ({ ...r, toolCalls: r.toolCalls ?? 0, tokens: r.tokens ?? zeroTokens() })),
354
- );
355
- const overhead: Span = {
356
- workMs: total.workMs - sum.workMs,
357
- waitMs: total.waitMs - sum.waitMs,
358
- toolCalls: (total.toolCalls ?? 0) - sum.toolCalls,
359
- tokens: Object.fromEntries(
360
- (Object.keys(sum.tokens) as (keyof Tokens)[]).map((k) => [k, (total.tokens?.[k] ?? 0) - sum.tokens[k]]),
361
- ) as Tokens,
362
- };
363
- if (!overlaps && overhead.workMs > 0)
364
- stageRows.push(summaryRow('driver overhead', '', overhead, totalMeasure.measured));
365
-
366
- return {
367
- available: true,
368
- rows: stageRows,
369
- total,
370
- actors: actorSplit(rows, totalStart, totalEnd),
371
- gate: { ms: null, reason: 'no matching check receipt' },
372
- skippedLines,
373
- };
374
- }
26
+ } from './plan-projection.generated.mjs';
27
+ import { parseRows, resolveTranscript } from './transcript';
28
+
29
+ // Task 1178 R2: the pure aggregation moved to `packages/app/src/workflow/run-summary.ts`. Re-export
30
+ // it from here so the adapter's existing surface (the `run-summary` script and its tests) keeps one
31
+ // import path; the implementation is delegated, never duplicated.
32
+ export {
33
+ type ActorSplit,
34
+ actorSplit,
35
+ buildRunSummary,
36
+ type GateTime,
37
+ type Progress,
38
+ type RunSummary,
39
+ type SummaryRow,
40
+ } from './plan-projection.generated.mjs';
375
41
 
376
42
  export function renderSummaryMarkdown(summary: RunSummary): string {
377
43
  const line = (r: SummaryRow, bold = false) => {
@@ -516,13 +182,12 @@ export function writeCloseSummary(
516
182
  if (run.startedAt === undefined) return na('run row has no started_at');
517
183
  const resolved = resolveTranscript(opts.env ?? getEnvVars(), opts.projectsRoot);
518
184
  if (!resolved.ok) return na(resolved.reason);
519
- const lines = readFileSync(resolved.path, 'utf8').split('\n');
520
- const summary = buildRunSummary(
521
- lines,
522
- [{ progress: run.progress as unknown as Progress }],
523
- run.startedAt,
524
- run.completedAt,
525
- );
185
+ const { rows, skippedLines } = parseRows(readFileSync(resolved.path, 'utf8').split('\n'));
186
+ const summary = buildRunSummary(rows, [{ progress: run.progress as unknown as Progress }], {
187
+ since: run.startedAt,
188
+ until: run.completedAt,
189
+ skippedLines,
190
+ });
526
191
  if (summary.rows.length === 0) return na('no timed attempts');
527
192
  mkdirSync(runDir, { recursive: true });
528
193
  writeFileSync(abs, `${renderSummaryMarkdown(summary)}\n`);
@@ -558,4 +223,3 @@ export function gateFromReceipt(cwd: string, runId: string): GateTime {
558
223
  return { ms: null, reason: 'check receipt is unreadable' };
559
224
  }
560
225
  }
561
-