@gobing-ai/spur 0.4.1 → 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 (159) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/config/config.global.yaml +4 -2
  3. package/config/decisions/maker-liveness.yaml +39 -0
  4. package/config/plugin-scripts.json +0 -4
  5. package/config/rules/README.md +1 -0
  6. package/config/rules/docs/sourced-api-claims.yaml +56 -12
  7. package/config/rules/strict/runtime-boundaries.yaml +7 -0
  8. package/config/script-placement-baseline.json +1 -19
  9. package/config/templates/AGENTS.md +1 -1
  10. package/config/workflows/feature-lifecycle.yaml +46 -1
  11. package/config/workflows/feature-verification.yaml +11 -0
  12. package/config/workflows/wrapup-pipeline.yaml +1 -1
  13. package/package.json +10 -10
  14. package/plugins/sp/README.md +23 -18
  15. package/plugins/sp/agents/super-planner.md +5 -6
  16. package/plugins/sp/agents/super-reviewer.md +43 -0
  17. package/plugins/sp/bunfig.toml +8 -5
  18. package/plugins/sp/commands/dev-review-session.md +2 -1
  19. package/plugins/sp/commands/dev-runall.md +18 -9
  20. package/plugins/sp/hooks/careful-guard.ts +1 -1
  21. package/plugins/sp/hooks/context-post-tool.ts +7 -404
  22. package/plugins/sp/hooks/context-session-start.ts +6 -192
  23. package/plugins/sp/hooks/context-session-stop.ts +6 -91
  24. package/plugins/sp/hooks/pi/guard-extension.ts +26 -12
  25. package/plugins/sp/hooks/task-write-guard.ts +1 -1
  26. package/plugins/sp/{hooks → lib}/agent-hint.ts +1 -1
  27. package/plugins/sp/lib/context-owner.ts +56 -0
  28. package/plugins/sp/lib/context-post-tool.ts +432 -0
  29. package/plugins/sp/lib/context-session-start.ts +214 -0
  30. package/plugins/sp/lib/context-session-stop.ts +196 -0
  31. package/plugins/sp/lib/dogfood-pipeline.ts +265 -0
  32. package/plugins/sp/lib/dogfood-report.ts +278 -0
  33. package/plugins/sp/lib/idea-handoff.generated.mjs +6 -4
  34. package/plugins/sp/lib/inline-run-app.ts +40 -0
  35. package/plugins/sp/lib/inline-run.generated.d.mts +3 -3
  36. package/plugins/sp/lib/inline-run.generated.mjs +1361 -87
  37. package/plugins/sp/lib/plan-projection.generated.d.mts +169 -0
  38. package/plugins/sp/lib/plan-projection.generated.mjs +704 -1
  39. package/plugins/sp/lib/quality-gate.generated.d.mts +0 -12
  40. package/plugins/sp/lib/quality-gate.generated.mjs +62 -231
  41. package/plugins/sp/lib/residual-scan.generated.d.mts +7 -1
  42. package/plugins/sp/lib/residual-scan.generated.mjs +71 -6
  43. package/plugins/sp/lib/run-summary-core.ts +34 -370
  44. package/plugins/sp/lib/transcript.ts +37 -200
  45. package/plugins/sp/plugin.json +1 -1
  46. package/plugins/sp/references/roles.md +1 -1
  47. package/plugins/sp/scripts/batch-plan.mjs +740 -1
  48. package/plugins/sp/scripts/batch-plan.ts +48 -3
  49. package/plugins/sp/scripts/batch-preflight.mjs +23 -1
  50. package/plugins/sp/scripts/batch-preflight.ts +35 -295
  51. package/plugins/sp/scripts/daily-summary/daily-summary.mjs +108 -87
  52. package/plugins/sp/scripts/daily-summary/daily-summary.ts +111 -104
  53. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +2 -1
  54. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +7 -265
  55. package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +3 -0
  56. package/plugins/sp/scripts/dogfood-testing/validate-report.ts +6 -272
  57. package/plugins/sp/scripts/feature-verification-steps.mjs +7 -123
  58. package/plugins/sp/scripts/feature-verification-steps.ts +29 -181
  59. package/plugins/sp/scripts/inline-run-dispatch.mjs +27 -26
  60. package/plugins/sp/scripts/inline-run-dispatch.ts +1 -21
  61. package/plugins/sp/scripts/inline-run-setup.mjs +158 -120
  62. package/plugins/sp/scripts/inline-run-setup.ts +1 -21
  63. package/plugins/sp/scripts/pr-reviewing.mjs +19 -5
  64. package/plugins/sp/scripts/pr-reviewing.ts +34 -9
  65. package/plugins/sp/scripts/quality-gate.mjs +38 -208
  66. package/plugins/sp/scripts/residual-scan.mjs +73 -6
  67. package/plugins/sp/scripts/residual-scan.ts +8 -5
  68. package/plugins/sp/scripts/run-summary.mjs +160 -95
  69. package/plugins/sp/scripts/run-summary.ts +7 -5
  70. package/plugins/sp/scripts/session-timeline.mjs +57 -29
  71. package/plugins/sp/scripts/session-timeline.ts +4 -18
  72. package/plugins/sp/scripts/task-diffstat.mjs +43 -30
  73. package/plugins/sp/scripts/task-diffstat.ts +40 -71
  74. package/plugins/sp/skills/code-implementation/SKILL.md +7 -1
  75. package/plugins/sp/skills/code-verification/references/secu-review.md +2 -1
  76. package/plugins/sp/skills/code-verification/references/verdict-schema.md +4 -0
  77. package/plugins/sp/skills/dogfood-testing/SKILL.md +2 -2
  78. package/plugins/sp/skills/indexed-context/SKILL.md +14 -7
  79. package/plugins/sp/skills/next-feature/SKILL.md +1 -1
  80. package/plugins/sp/skills/parallel-execution/SKILL.md +2 -2
  81. package/plugins/sp/skills/parallel-execution/references/dispatch-surface.md +2 -2
  82. package/plugins/sp/skills/parallel-execution/references/fan-out-patterns.md +2 -2
  83. package/plugins/sp/skills/pr-reviewing/SKILL.md +7 -3
  84. package/plugins/sp/skills/session-review/SKILL.md +5 -3
  85. package/plugins/sp/skills/source-driven-development/SKILL.md +7 -4
  86. package/plugins/sp/skills/spur-cli/references/builder.md +3 -2
  87. package/plugins/sp/skills/spur-cli/references/decision.md +40 -8
  88. package/plugins/sp/skills/spur-cli/references/features.md +46 -5
  89. package/plugins/sp/skills/spur-cli/references/projects.md +7 -5
  90. package/plugins/sp/skills/spur-dev/SKILL.md +2 -0
  91. package/plugins/sp/skills/spur-dev/references/ac-style-guide.md +27 -0
  92. package/plugins/sp/skills/spur-dev/references/dev-operations.md +2 -3
  93. package/plugins/sp/skills/spur-dev/references/execution-batch-report.md +6 -1
  94. package/plugins/sp/skills/spur-dev/references/execution-batch.md +56 -7
  95. package/plugins/sp/skills/spur-dev/references/execution-parallel-isolation.md +4 -1
  96. package/plugins/sp/skills/spur-dev/references/execution-worktree-landing.md +22 -0
  97. package/plugins/sp/skills/spur-dev/references/execution-worktree-setup.md +14 -0
  98. package/plugins/sp/skills/spur-dev/references/flag-glossary.md +13 -11
  99. package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +37 -25
  100. package/spur.js +89792 -76992
  101. package/web/_astro/{BoardApp.D66k_s_T.js → BoardApp.5IIl2O-z.js} +1 -1
  102. package/web/_astro/BoardApp.Drnx-KeM.js +324 -0
  103. package/web/_astro/TaskDetail.Ci4LNn9S.js +1 -0
  104. package/web/_astro/{arc._BUadrdH.js → arc.j2EVkYVd.js} +1 -1
  105. package/web/_astro/{architectureDiagram-3BPJPVTR.Dh7xS1Pp.js → architectureDiagram-3BPJPVTR.DZWSFqEG.js} +1 -1
  106. package/web/_astro/{blockDiagram-GPEHLZMM.DFDVpfXm.js → blockDiagram-GPEHLZMM.DE6GpXCN.js} +1 -1
  107. package/web/_astro/{c4Diagram-AAUBKEIU.V7_3_glh.js → c4Diagram-AAUBKEIU.DoVR1G6B.js} +1 -1
  108. package/web/_astro/channel.DmdDxGsq.js +1 -0
  109. package/web/_astro/{chunk-2J33WTMH.De1yx7Jz.js → chunk-2J33WTMH.Do6-Gbyf.js} +1 -1
  110. package/web/_astro/{chunk-4BX2VUAB.BDhHFuxx.js → chunk-4BX2VUAB.BYV1HGHx.js} +1 -1
  111. package/web/_astro/{chunk-55IACEB6.DDLkWnmC.js → chunk-55IACEB6.CvI1zkrc.js} +1 -1
  112. package/web/_astro/{chunk-727SXJPM.CwfiLnA7.js → chunk-727SXJPM.DNGSCRlX.js} +1 -1
  113. package/web/_astro/{chunk-AQP2D5EJ.CtGDmUnM.js → chunk-AQP2D5EJ.DXhhgT5z.js} +1 -1
  114. package/web/_astro/{chunk-FMBD7UC4.BOLjpw73.js → chunk-FMBD7UC4.dzkRKP2u.js} +1 -1
  115. package/web/_astro/{chunk-ND2GUHAM.BDhQls6O.js → chunk-ND2GUHAM.DujGLeEf.js} +1 -1
  116. package/web/_astro/{chunk-QZHKN3VN.76qBynDF.js → chunk-QZHKN3VN.BWtIT3ZU.js} +1 -1
  117. package/web/_astro/{classDiagram-4FO5ZUOK.N0mpPHT0.js → classDiagram-4FO5ZUOK.DyApg0Nn.js} +1 -1
  118. package/web/_astro/{classDiagram-v2-Q7XG4LA2.N0mpPHT0.js → classDiagram-v2-Q7XG4LA2.DyApg0Nn.js} +1 -1
  119. package/web/_astro/{cose-bilkent-S5V4N54A.CKknFfjB.js → cose-bilkent-S5V4N54A.DJQB-u_l.js} +1 -1
  120. package/web/_astro/{cynefin-OW5HDTMX.Cw3ZWBAh.js → cynefin-OW5HDTMX.bi3D_siV.js} +1 -1
  121. package/web/_astro/{dagre-BM42HDAG.D3yIKCRD.js → dagre-BM42HDAG.C-f7TrRg.js} +1 -1
  122. package/web/_astro/{diagram-2AECGRRQ.D51dO83Z.js → diagram-2AECGRRQ.DrPfjHQB.js} +1 -1
  123. package/web/_astro/{diagram-5GNKFQAL.Bb-FViDj.js → diagram-5GNKFQAL.C9S4WUHO.js} +1 -1
  124. package/web/_astro/{diagram-KO2AKTUF.D3mN8S6x.js → diagram-KO2AKTUF.Dzzye8QH.js} +1 -1
  125. package/web/_astro/{diagram-LMA3HP47.dMMyPcbJ.js → diagram-LMA3HP47.DX-LRiof.js} +1 -1
  126. package/web/_astro/{diagram-OG6HWLK6.AzbvzY4C.js → diagram-OG6HWLK6.Z-kAKwIz.js} +1 -1
  127. package/web/_astro/{erDiagram-TEJ5UH35.BR5I4OZb.js → erDiagram-TEJ5UH35.D6dyClSv.js} +1 -1
  128. package/web/_astro/{flowDiagram-I6XJVG4X.DFqvhGkn.js → flowDiagram-I6XJVG4X.Cx3q2cxD.js} +1 -1
  129. package/web/_astro/{ganttDiagram-6RSMTGT7.ByJbhH6J.js → ganttDiagram-6RSMTGT7.DU3gH6CT.js} +1 -1
  130. package/web/_astro/{gitGraphDiagram-PVQCEYII.CInHjQR3.js → gitGraphDiagram-PVQCEYII.ISmCnJ87.js} +1 -1
  131. package/web/_astro/index.Do2lLdgo.css +1 -0
  132. package/web/_astro/{infoDiagram-5YYISTIA.Cm0dGVjJ.js → infoDiagram-5YYISTIA.DR6_iNOK.js} +1 -1
  133. package/web/_astro/{ishikawaDiagram-YF4QCWOH.C3nOP6Sj.js → ishikawaDiagram-YF4QCWOH.D7wY-ZGA.js} +1 -1
  134. package/web/_astro/{journeyDiagram-JHISSGLW.4IvLa2MW.js → journeyDiagram-JHISSGLW.DkP9-WK8.js} +1 -1
  135. package/web/_astro/{kanban-definition-UN3LZRKU.DS87Cl-k.js → kanban-definition-UN3LZRKU.wtgY98M2.js} +1 -1
  136. package/web/_astro/{linear.MzmRrNER.js → linear.CI6djNi7.js} +1 -1
  137. package/web/_astro/{mermaid.core.fK-WNswS.js → mermaid.core.CuQPxS8b.js} +4 -4
  138. package/web/_astro/{mindmap-definition-RKZ34NQL.BqipOHhY.js → mindmap-definition-RKZ34NQL.5HNIEG7R.js} +1 -1
  139. package/web/_astro/{pieDiagram-4H26LBE5.0nBiPqFG.js → pieDiagram-4H26LBE5.CchhDFjE.js} +1 -1
  140. package/web/_astro/{quadrantDiagram-W4KKPZXB.Szj7Zpx5.js → quadrantDiagram-W4KKPZXB.PYXXJPSJ.js} +1 -1
  141. package/web/_astro/{requirementDiagram-4Y6WPE33.D4UR6TWo.js → requirementDiagram-4Y6WPE33.cUQuNAKU.js} +1 -1
  142. package/web/_astro/{sankeyDiagram-5OEKKPKP.DAE7BdOs.js → sankeyDiagram-5OEKKPKP.BO7MnRIA.js} +1 -1
  143. package/web/_astro/{sequenceDiagram-3UESZ5HK.BP9ZVq25.js → sequenceDiagram-3UESZ5HK.D9bElyD6.js} +1 -1
  144. package/web/_astro/{stateDiagram-AJRCARHV.BQW7mIxk.js → stateDiagram-AJRCARHV.DhGdRz7I.js} +1 -1
  145. package/web/_astro/{stateDiagram-v2-BHNVJYJU.PbK4nDih.js → stateDiagram-v2-BHNVJYJU.5GvLeAoL.js} +1 -1
  146. package/web/_astro/{timeline-definition-PNZ67QCA.Ci_GvUpo.js → timeline-definition-PNZ67QCA.LtAT9haM.js} +1 -1
  147. package/web/_astro/{vennDiagram-CIIHVFJN.DNw1Y5qx.js → vennDiagram-CIIHVFJN.DRth1yLA.js} +1 -1
  148. package/web/_astro/{wardleyDiagram-YWT4CUSO.CwlkaaNe.js → wardleyDiagram-YWT4CUSO.h9MlZfcr.js} +1 -1
  149. package/web/_astro/{xychartDiagram-2RQKCTM6.MI6ZuiH_.js → xychartDiagram-2RQKCTM6.DHqy9DYA.js} +1 -1
  150. package/web/index.html +2 -2
  151. package/config/proportional-route-table.ts +0 -155
  152. package/plugins/sp/commands/dev-parallel.md +0 -37
  153. package/plugins/sp/scripts/daily-summary/logger.ts +0 -28
  154. package/web/_astro/BoardApp.D6sjAJr_.js +0 -324
  155. package/web/_astro/TaskDetail.BynLnMNc.js +0 -1
  156. package/web/_astro/channel.DZVfto-r.js +0 -1
  157. package/web/_astro/index.COh_kBxN.css +0 -1
  158. /package/plugins/sp/{hooks → lib}/destructive-policy.ts +0 -0
  159. /package/plugins/sp/{hooks → lib}/task-file-policy.ts +0 -0
@@ -1,3 +1,573 @@
1
+ // packages/app/src/services/planning-admission.ts
2
+ var NON_ABORTING_PREFLIGHT_CODES = new Set([
3
+ "L4.scenario-unverified",
4
+ "L4.verifying-incomplete-tasks"
5
+ ]);
6
+ function classifyFeaturePreflightFindings(findings) {
7
+ const aborting = [];
8
+ const nonAborting = [];
9
+ for (const f of findings) {
10
+ if (f.severity === "error") {
11
+ if (NON_ABORTING_PREFLIGHT_CODES.has(f.code)) {
12
+ nonAborting.push(f);
13
+ } else {
14
+ aborting.push(f);
15
+ }
16
+ } else {
17
+ nonAborting.push(f);
18
+ }
19
+ }
20
+ return {
21
+ aborting,
22
+ nonAborting,
23
+ shouldAbort: aborting.length > 0
24
+ };
25
+ }
26
+ function quickReadiness(input) {
27
+ const status = (input.status ?? "").toLowerCase();
28
+ const operation = input.operation;
29
+ if (operation !== "run" && operation !== "refine" && operation !== "verify") {
30
+ return {
31
+ action: "invalid",
32
+ code: "IV",
33
+ reason: `quick-readiness: unknown operation '${operation}' (${input.wbs})`
34
+ };
35
+ }
36
+ if (input.filteredCount !== undefined) {
37
+ if (input.filteredCount < 0) {
38
+ return {
39
+ action: "invalid",
40
+ code: "IV",
41
+ reason: `quick-readiness: invalid negative filtered count '${input.filteredCount}' (${input.wbs})`
42
+ };
43
+ }
44
+ if (input.filteredCount === 0) {
45
+ return {
46
+ action: "skipped",
47
+ code: "EMPTY",
48
+ reason: `quick-readiness: empty status-filtered set — nothing to ${operation} (${input.wbs})`
49
+ };
50
+ }
51
+ }
52
+ if (status === "cancelled" || status === "done") {
53
+ if (operation === "verify" && input.force === true) {
54
+ return {
55
+ action: "runnable",
56
+ code: "FORCE",
57
+ reason: `quick-readiness: verify --force re-verification of ${status} task ${input.wbs}`
58
+ };
59
+ }
60
+ return {
61
+ action: "skipped",
62
+ code: status === "done" ? "DONE" : "CANCELLED",
63
+ reason: `quick-readiness: already ${status} — no ${operation} hop (${input.wbs})`
64
+ };
65
+ }
66
+ if (status === "blocked") {
67
+ return {
68
+ action: "blocked",
69
+ code: "BLK",
70
+ reason: `quick-readiness: blocked — human/handover first (${input.wbs})`
71
+ };
72
+ }
73
+ if (operation === "run" && input.dependencies && input.dependencies.length > 0) {
74
+ const unmet = input.dependencies.filter((d) => (input.depStatuses?.[d] ?? "missing").toLowerCase() !== "done");
75
+ if (unmet.length > 0) {
76
+ return {
77
+ action: "blocked",
78
+ code: "DEP",
79
+ reason: `quick-readiness: unmet deps — ${unmet.join(", ")} (${input.wbs})`,
80
+ unmetDeps: unmet
81
+ };
82
+ }
83
+ }
84
+ const required = input.requiredSections ?? [];
85
+ const present = input.presentSections ?? [];
86
+ const gaps = required.filter((s) => {
87
+ const finding = input.sectionFindings?.[s];
88
+ return !present.includes(s) || finding !== undefined && finding !== "";
89
+ });
90
+ if (operation === "refine") {
91
+ if (status !== "backlog" && status !== "todo") {
92
+ return {
93
+ action: "skipped",
94
+ code: "NONPLAN",
95
+ reason: `quick-readiness: refine targets backlog/todo only, not '${status}' (${input.wbs})`
96
+ };
97
+ }
98
+ return {
99
+ action: "runnable",
100
+ code: "OK",
101
+ reason: `quick-readiness: refine ready for ${input.wbs} (${gaps.length} planning gap(s) to fill)`
102
+ };
103
+ }
104
+ if (operation === "verify") {
105
+ if (status !== "testing" && status !== "wip") {
106
+ return {
107
+ action: "invalid",
108
+ code: "NOVERIFY",
109
+ reason: `quick-readiness: verify needs testing/wip, not '${status}' (${input.wbs})`
110
+ };
111
+ }
112
+ return {
113
+ action: "runnable",
114
+ code: "OK",
115
+ reason: `quick-readiness: verify ready for ${input.wbs}`
116
+ };
117
+ }
118
+ if (status !== "todo" && status !== "wip" && status !== "testing") {
119
+ return {
120
+ action: "invalid",
121
+ code: "NORUN",
122
+ reason: `quick-readiness: run needs todo/wip/testing, not '${status}' (${input.wbs})`
123
+ };
124
+ }
125
+ if (gaps.length > 0) {
126
+ return {
127
+ action: "needs-refinement",
128
+ code: "REFINE",
129
+ reason: `quick-readiness: implementation sections incomplete (${input.wbs})`,
130
+ gaps
131
+ };
132
+ }
133
+ return {
134
+ action: "runnable",
135
+ code: "OK",
136
+ reason: `quick-readiness: run ready for ${input.wbs}`
137
+ };
138
+ }
139
+ function preflightTask(input) {
140
+ const status = (input.status ?? "").toLowerCase();
141
+ const deps = input.dependencies ?? [];
142
+ const depStatuses = input.depStatuses ?? {};
143
+ if (status === "cancelled") {
144
+ return {
145
+ action: "skip",
146
+ code: "A9",
147
+ reason: `dev-next: cancelled — nothing to advance (${input.wbs})`
148
+ };
149
+ }
150
+ if (status === "done") {
151
+ return {
152
+ action: "skip",
153
+ code: "A8",
154
+ reason: `dev-next: already done — batch does not auto-wrap (${input.wbs})`
155
+ };
156
+ }
157
+ if (status === "blocked") {
158
+ return {
159
+ action: "skip",
160
+ code: "A7",
161
+ reason: `dev-next: blocked — do not launch pipeline; human/handover first (${input.wbs})`
162
+ };
163
+ }
164
+ if (status === "todo" || status === "backlog") {
165
+ const unmet = deps.filter((d) => {
166
+ const st = (depStatuses[d] ?? "missing").toLowerCase();
167
+ return st !== "done";
168
+ });
169
+ if (unmet.length > 0) {
170
+ return {
171
+ action: "skip",
172
+ code: "A2",
173
+ reason: `dev-next: blocked by deps — unmet: ${unmet.join(", ")} (${input.wbs})`,
174
+ unmetDeps: unmet
175
+ };
176
+ }
177
+ }
178
+ return { action: "run", code: "OK", reason: `preflight clear — launch task-pipeline for ${input.wbs}` };
179
+ }
180
+ // packages/app/src/workflow/run-summary.ts
181
+ var zeroTokens = () => ({ input: 0, cacheCreate: 0, cacheRead: 0, output: 0 });
182
+ function formatDuration(ms) {
183
+ const s = Math.round(ms / 1000);
184
+ const h = Math.floor(s / 3600);
185
+ const m = Math.floor(s % 3600 / 60);
186
+ const ss = String(s % 60).padStart(2, "0");
187
+ return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
188
+ }
189
+ function formatTokens(n) {
190
+ if (n >= 999500)
191
+ return `${(n / 1e6).toFixed(1)}M`;
192
+ return n >= 1000 ? `${Math.round(n / 1000)}k` : String(n);
193
+ }
194
+ function formatTokenSplit(t) {
195
+ if (!t)
196
+ return "n/a";
197
+ const nonCached = t.input + t.cacheCreate + t.output;
198
+ return `${formatTokens(nonCached + t.cacheRead)} / ${formatTokens(nonCached)}`;
199
+ }
200
+ var OPERATOR_TOOLS = new Set(["AskUserQuestion", "ask_user_question"]);
201
+ function isCompaction(row) {
202
+ return row.type === "compaction" || row.type === "system" && row.subtype === "compact_boundary";
203
+ }
204
+ function firstTextContent(row) {
205
+ const content = row.message?.content;
206
+ if (typeof content === "string")
207
+ return content;
208
+ if (!Array.isArray(content))
209
+ return;
210
+ return content.find((b) => b.type === "text")?.text;
211
+ }
212
+ function skillInvocationPrompt(text) {
213
+ const name = /^\s*<skill name="([^"]+)"/.exec(text)?.[1];
214
+ if (name === undefined)
215
+ return;
216
+ const close = text.lastIndexOf("</skill>");
217
+ const args = close < 0 ? "" : text.slice(close + "</skill>".length).trim();
218
+ return args === "" ? `/${name}` : `/${name} ${args}`;
219
+ }
220
+ function promptText(row) {
221
+ if (row.type === "custom_message") {
222
+ if (row.display === false)
223
+ return;
224
+ const text = typeof row.content === "string" ? row.content.trim() : "";
225
+ return text === "" ? undefined : text;
226
+ }
227
+ if (row.type === "message") {
228
+ if (row.message?.role !== "user")
229
+ return;
230
+ const text = firstTextContent(row);
231
+ if (text === undefined)
232
+ return;
233
+ return skillInvocationPrompt(text) ?? text;
234
+ }
235
+ if (row.type !== "user" || row.isMeta || row.isCompactSummary)
236
+ return;
237
+ const content = row.message?.content;
238
+ if (typeof content === "string")
239
+ return content;
240
+ if (!Array.isArray(content) || content.some((b) => b.type === "tool_result"))
241
+ return;
242
+ return content.find((b) => b.type === "text")?.text;
243
+ }
244
+ function sumTokens(all) {
245
+ const total = zeroTokens();
246
+ for (const t of all)
247
+ for (const k of Object.keys(total))
248
+ total[k] += t[k];
249
+ return total;
250
+ }
251
+ function sumSpans(spans) {
252
+ return {
253
+ workMs: spans.reduce((n, s) => n + s.workMs, 0),
254
+ waitMs: spans.reduce((n, s) => n + s.waitMs, 0),
255
+ toolCalls: spans.reduce((n, s) => n + s.toolCalls, 0),
256
+ tokens: sumTokens(spans.map((s) => s.tokens))
257
+ };
258
+ }
259
+ var newAcc = (ts) => ({
260
+ last: ts,
261
+ askMs: 0,
262
+ asks: new Map,
263
+ toolIds: new Set,
264
+ messages: new Map,
265
+ compactions: 0
266
+ });
267
+ function accumulate(acc, row, ts) {
268
+ acc.last = Math.max(acc.last, ts);
269
+ if (row.type === "message") {
270
+ const m = row.message;
271
+ if (m?.role === "assistant") {
272
+ const blocks2 = Array.isArray(m.content) ? m.content : [];
273
+ for (const b of blocks2) {
274
+ if (b.type === "toolCall" && b.id) {
275
+ acc.toolIds.add(b.id);
276
+ if (b.name && OPERATOR_TOOLS.has(b.name))
277
+ acc.asks.set(b.id, ts);
278
+ }
279
+ }
280
+ const u2 = m.usage;
281
+ if (u2 && row.id)
282
+ acc.messages.set(row.id, {
283
+ input: u2.input ?? 0,
284
+ cacheCreate: u2.cacheWrite ?? 0,
285
+ cacheRead: u2.cacheRead ?? 0,
286
+ output: u2.output ?? 0
287
+ });
288
+ } else if (m?.role === "toolResult" && m.toolCallId && acc.asks.has(m.toolCallId)) {
289
+ acc.askMs += ts - (acc.asks.get(m.toolCallId) ?? ts);
290
+ }
291
+ return;
292
+ }
293
+ if (row.type === "compaction")
294
+ acc.compactions++;
295
+ const blocks = Array.isArray(row.message?.content) ? row.message.content : [];
296
+ for (const b of blocks) {
297
+ if (b.type === "tool_use" && b.id) {
298
+ acc.toolIds.add(b.id);
299
+ if (b.name && OPERATOR_TOOLS.has(b.name))
300
+ acc.asks.set(b.id, ts);
301
+ } else if (b.type === "tool_result" && b.tool_use_id && acc.asks.has(b.tool_use_id)) {
302
+ acc.askMs += ts - (acc.asks.get(b.tool_use_id) ?? ts);
303
+ }
304
+ }
305
+ const u = row.message?.usage;
306
+ if (row.type === "assistant" && u && row.message?.id) {
307
+ acc.messages.set(row.message.id, {
308
+ input: u.input_tokens ?? 0,
309
+ cacheCreate: u.cache_creation_input_tokens ?? 0,
310
+ cacheRead: u.cache_read_input_tokens ?? 0,
311
+ output: u.output_tokens ?? 0
312
+ });
313
+ }
314
+ }
315
+ var IDLE_GAP_MS = 300000;
316
+ var SHELL_TOOLS = new Set(["bash", "shell", "exec", "exec_command", "run_command", "command"]);
317
+ var SUBAGENT_TOOLS = new Set(["agent", "task", "invoke_subagent", "subagent", "dispatch_agent"]);
318
+ var LOWERCASE_OPERATOR_TOOLS = new Set(["askuserquestion", "ask_user_question"]);
319
+ var ACTOR_PRECEDENCE = ["operator", "subagent", "shell", "other"];
320
+ function actorOf(tool) {
321
+ const t = tool.toLowerCase().replace(/[^a-z_]/g, "");
322
+ if (LOWERCASE_OPERATOR_TOOLS.has(t))
323
+ return "operator";
324
+ if (SUBAGENT_TOOLS.has(t))
325
+ return "subagent";
326
+ if (SHELL_TOOLS.has(t))
327
+ return "shell";
328
+ return "other";
329
+ }
330
+ function unionMs(spans, start, end) {
331
+ const clipped = spans.map(([a, b]) => [Math.max(a, start), Math.min(b, end)]).filter(([a, b]) => b > a).sort((x, y) => x[0] - y[0]);
332
+ let total = 0;
333
+ let cursor = Number.NaN;
334
+ let openUntil = Number.NaN;
335
+ for (const [a, b] of clipped) {
336
+ if (!Number.isFinite(cursor)) {
337
+ cursor = a;
338
+ openUntil = b;
339
+ continue;
340
+ }
341
+ if (a > openUntil) {
342
+ total += openUntil - cursor;
343
+ cursor = a;
344
+ openUntil = b;
345
+ } else {
346
+ openUntil = Math.max(openUntil, b);
347
+ }
348
+ }
349
+ if (Number.isFinite(cursor))
350
+ total += openUntil - cursor;
351
+ return total;
352
+ }
353
+ function subtract(spans, claimed) {
354
+ let free = spans;
355
+ for (const [ca, cb] of claimed) {
356
+ const next = [];
357
+ for (const [a, b] of free) {
358
+ if (cb <= a || ca >= b) {
359
+ next.push([a, b]);
360
+ continue;
361
+ }
362
+ if (ca > a)
363
+ next.push([a, ca]);
364
+ if (cb < b)
365
+ next.push([cb, b]);
366
+ }
367
+ free = next;
368
+ }
369
+ return free;
370
+ }
371
+ function actorSplit(rows, start, end) {
372
+ const empty = {
373
+ operatorMs: 0,
374
+ longestOperatorWaitMs: 0,
375
+ modelMs: 0,
376
+ shellMs: 0,
377
+ subagentMs: 0,
378
+ otherToolMs: 0,
379
+ idleMs: 0,
380
+ compactions: 0,
381
+ subagentErrors: 0
382
+ };
383
+ const window = end - start;
384
+ if (window <= 0)
385
+ return empty;
386
+ const calls = new Map;
387
+ const results = new Map;
388
+ const eventTs = [];
389
+ let compactions = 0;
390
+ for (const [row, ts] of rows) {
391
+ if (ts < start || ts > end)
392
+ continue;
393
+ eventTs.push(ts);
394
+ if (isCompaction(row))
395
+ compactions++;
396
+ const blocks = Array.isArray(row.message?.content) ? row.message?.content : [];
397
+ if (row.message?.role === "toolResult" && row.message.toolCallId !== undefined) {
398
+ results.set(row.message.toolCallId, { ts, isError: row.message.isError === true });
399
+ }
400
+ for (const b of blocks) {
401
+ if ((b.type === "tool_use" || b.type === "toolCall") && b.id !== undefined && b.name !== undefined) {
402
+ calls.set(b.id, { id: b.id, actor: actorOf(b.name), ts });
403
+ } else if (b.type === "tool_result" && b.tool_use_id !== undefined) {
404
+ results.set(b.tool_use_id, { ts, isError: b.is_error === true });
405
+ }
406
+ }
407
+ }
408
+ let subagentErrors = 0;
409
+ const resolved = [];
410
+ for (const call of calls.values()) {
411
+ const result = results.get(call.id);
412
+ if (result?.isError === true && call.actor === "subagent")
413
+ subagentErrors++;
414
+ resolved.push({ ...call, end: Math.min(result?.ts ?? end, end) });
415
+ }
416
+ const claimed = [];
417
+ const byActor = new Map;
418
+ for (const actor of ACTOR_PRECEDENCE) {
419
+ const mine = resolved.filter((r) => r.actor === actor).map((r) => [r.ts, r.end]);
420
+ const free = subtract(mine, claimed);
421
+ for (const span of free)
422
+ claimed.push(span);
423
+ const ms = unionMs(free, start, end);
424
+ byActor.set(actor, ms);
425
+ if (actor === "operator") {
426
+ empty.longestOperatorWaitMs = Math.max(0, ...mine.map(([a, b]) => b - a));
427
+ }
428
+ }
429
+ const boundaries = [...new Set([start, end, ...eventTs, ...claimed.flat()])].sort((a, b) => a - b);
430
+ const claimedSorted = [...claimed].sort((a, b) => a[0] - b[0]);
431
+ let idleMs = 0;
432
+ for (let i = 0;i < boundaries.length - 1; i++) {
433
+ const a = boundaries[i];
434
+ const b = boundaries[i + 1];
435
+ if (b - a < IDLE_GAP_MS)
436
+ continue;
437
+ if (claimedSorted.some(([ca, cb]) => ca < b && cb > a))
438
+ continue;
439
+ idleMs += b - a;
440
+ }
441
+ const accounted = (byActor.get("operator") ?? 0) + (byActor.get("subagent") ?? 0) + (byActor.get("shell") ?? 0) + (byActor.get("other") ?? 0) + idleMs;
442
+ return {
443
+ ...empty,
444
+ operatorMs: byActor.get("operator") ?? 0,
445
+ subagentMs: byActor.get("subagent") ?? 0,
446
+ shellMs: byActor.get("shell") ?? 0,
447
+ otherToolMs: byActor.get("other") ?? 0,
448
+ idleMs,
449
+ modelMs: Math.max(0, window - accounted),
450
+ compactions,
451
+ subagentErrors
452
+ };
453
+ }
454
+ function attemptWindow(attempts) {
455
+ const starts = attempts.map((a) => Date.parse(a.startedAt ?? "")).filter((n) => !Number.isNaN(n));
456
+ const ends = attempts.map((a) => Date.parse(a.completedAt ?? "")).filter((n) => !Number.isNaN(n));
457
+ return starts.length && ends.length ? [Math.min(...starts), Math.max(...ends)] : undefined;
458
+ }
459
+ function summaryRow(stage, status, span, measured) {
460
+ return {
461
+ stage,
462
+ status,
463
+ workMs: span.workMs,
464
+ waitMs: span.waitMs,
465
+ toolCalls: measured ? span.toolCalls : null,
466
+ tokens: measured ? span.tokens : null,
467
+ time: formatDuration(span.workMs),
468
+ wait: formatDuration(span.waitMs),
469
+ token: formatTokenSplit(measured ? span.tokens : null)
470
+ };
471
+ }
472
+ function buildRunSummary(rows, inputs, opts = {}) {
473
+ const { since, until } = opts;
474
+ const windows = [];
475
+ for (const { label, progress } of inputs) {
476
+ const states = (progress.states ?? []).flatMap((s) => {
477
+ const w = attemptWindow((s.actions ?? []).flatMap((a) => a.attempts ?? []));
478
+ return w ? [{ s, w }] : [];
479
+ });
480
+ if (!states.length)
481
+ throw new Error(`progress for run ${progress.runId} has no timed attempts`);
482
+ if (inputs.length === 1) {
483
+ for (const { s, w } of states) {
484
+ const stage = (s.visit ?? 1) > 1 ? `${s.state} (visit ${s.visit})` : s.state;
485
+ windows.push({ stage, status: s.status ?? "", start: w[0], end: w[1] });
486
+ }
487
+ } else {
488
+ const stage = label ?? `${progress.workflow ?? "run"} ${progress.runId.slice(0, 8)}`;
489
+ const start = Math.min(...states.map(({ w }) => w[0]));
490
+ windows.push({
491
+ stage,
492
+ status: progress.status ?? "",
493
+ start,
494
+ end: Math.max(...states.map(({ w }) => w[1]))
495
+ });
496
+ }
497
+ }
498
+ windows.sort((a, b) => a.start - b.start);
499
+ const measure = (start, end) => {
500
+ const acc = newAcc(start);
501
+ for (const [row, ts] of rows)
502
+ if (ts >= start && ts <= end && promptText(row) === undefined)
503
+ accumulate(acc, row, ts);
504
+ const span = {
505
+ workMs: end - start - acc.askMs,
506
+ waitMs: acc.askMs,
507
+ toolCalls: acc.toolIds.size,
508
+ tokens: sumTokens([...acc.messages.values()])
509
+ };
510
+ return { span, measured: acc.toolIds.size > 0 || acc.messages.size > 0 };
511
+ };
512
+ const sinceMs = since ? Date.parse(since) : Number.NaN;
513
+ const totalStart = Number.isNaN(sinceMs) ? Math.min(...windows.map((w) => w.start)) : sinceMs;
514
+ let totalEnd = Math.max(...windows.map((w) => w.end));
515
+ if (!Number.isNaN(sinceMs)) {
516
+ for (const [, ts] of rows)
517
+ if (ts >= sinceMs)
518
+ totalEnd = Math.max(totalEnd, ts);
519
+ }
520
+ const untilMs = until ? Date.parse(until) : Number.NaN;
521
+ if (!Number.isNaN(untilMs) && untilMs > totalStart)
522
+ totalEnd = untilMs;
523
+ const stageRows = windows.map((w) => {
524
+ const { span, measured } = measure(w.start, w.end);
525
+ return summaryRow(w.stage, w.status, span, measured);
526
+ });
527
+ const totalMeasure = measure(totalStart, totalEnd);
528
+ const statuses = [...new Set(inputs.map((i) => i.progress.status ?? ""))].join("/");
529
+ const total = summaryRow("Total", statuses, totalMeasure.span, totalMeasure.measured);
530
+ const overlaps = windows.some((w, i) => i > 0 && w.start < (windows[i - 1]?.end ?? 0));
531
+ const sum = sumSpans(stageRows.map((r) => ({ ...r, toolCalls: r.toolCalls ?? 0, tokens: r.tokens ?? zeroTokens() })));
532
+ const overhead = {
533
+ workMs: total.workMs - sum.workMs,
534
+ waitMs: total.waitMs - sum.waitMs,
535
+ toolCalls: (total.toolCalls ?? 0) - sum.toolCalls,
536
+ tokens: Object.fromEntries(Object.keys(sum.tokens).map((k) => [k, (total.tokens?.[k] ?? 0) - sum.tokens[k]]))
537
+ };
538
+ if (!overlaps && overhead.workMs > 0)
539
+ stageRows.push(summaryRow("driver overhead", "", overhead, totalMeasure.measured));
540
+ return {
541
+ available: true,
542
+ rows: stageRows,
543
+ total,
544
+ actors: actorSplit(rows, totalStart, totalEnd),
545
+ gate: { ms: null, reason: "no matching check receipt" },
546
+ skippedLines: opts.skippedLines ?? 0
547
+ };
548
+ }
549
+ // packages/app/src/workflow/task-triage.ts
550
+ var SENSITIVE_PREFIXES = ["drizzle/", "packages/config/", ".github/", "plugins/sp/hooks/"];
551
+ var SENSITIVE_GLOBS = ["apps/server/src/**/auth*", "**/*secret*", "**/*.sql"];
552
+ function globToRegex(glob) {
553
+ const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("**/", "\x00").replaceAll("**", "\x01").replaceAll("*", "[^/]*").replaceAll("\x00", "(?:.*/)?").replaceAll("\x01", ".*");
554
+ return new RegExp(`^${escaped}$`, "s");
555
+ }
556
+ var SENSITIVE_MATCHERS = [
557
+ ...SENSITIVE_PREFIXES.map((prefix) => ({
558
+ label: prefix,
559
+ test: (path) => path.startsWith(prefix)
560
+ })),
561
+ ...SENSITIVE_GLOBS.map((glob) => {
562
+ const regex = globToRegex(glob);
563
+ return { label: glob, test: (path) => regex.test(path) };
564
+ })
565
+ ];
566
+ function sensitiveReasonForPath(path) {
567
+ const match = SENSITIVE_MATCHERS.find((entry) => entry.test(path));
568
+ return match ? `matches sensitive pattern ${match.label}` : null;
569
+ }
570
+
1
571
  // packages/app/src/workflow/plan-projection.ts
2
572
  function planLetter(index) {
3
573
  if (!Number.isInteger(index) || index < 0 || index > 25) {
@@ -216,6 +786,118 @@ function buildBatchPlan(tasks) {
216
786
  }
217
787
  return waves;
218
788
  }
789
+ var byWbs = (a, b) => a.localeCompare(b, "en", { numeric: true });
790
+ function kahnOrder(nodes, preds) {
791
+ const indegree = new Map(nodes.map((n) => [n, preds.get(n)?.size ?? 0]));
792
+ const succ = new Map(nodes.map((n) => [n, []]));
793
+ for (const [n, ps] of preds)
794
+ for (const p of ps)
795
+ succ.get(p)?.push(n);
796
+ const ready = nodes.filter((n) => indegree.get(n) === 0).sort(byWbs);
797
+ const order = [];
798
+ for (let n = ready.shift();n !== undefined; n = ready.shift()) {
799
+ order.push(n);
800
+ for (const s of succ.get(n) ?? []) {
801
+ const d = (indegree.get(s) ?? 0) - 1;
802
+ indegree.set(s, d);
803
+ if (d === 0) {
804
+ ready.push(s);
805
+ ready.sort(byWbs);
806
+ }
807
+ }
808
+ }
809
+ return order;
810
+ }
811
+ function findCycle(remaining, preds) {
812
+ const state = new Map;
813
+ const stack = [];
814
+ const visit = (n) => {
815
+ state.set(n, "visiting");
816
+ stack.push(n);
817
+ for (const p of [...preds.get(n) ?? []].sort(byWbs)) {
818
+ if (!remaining.has(p))
819
+ continue;
820
+ if (state.get(p) === "visiting")
821
+ return [...stack.slice(stack.indexOf(p)), p];
822
+ if (!state.has(p)) {
823
+ const cycle = visit(p);
824
+ if (cycle)
825
+ return cycle;
826
+ }
827
+ }
828
+ stack.pop();
829
+ state.set(n, "done");
830
+ return null;
831
+ };
832
+ for (const n of [...remaining].sort(byWbs)) {
833
+ if (state.has(n))
834
+ continue;
835
+ const cycle = visit(n);
836
+ if (cycle)
837
+ return cycle;
838
+ }
839
+ return [];
840
+ }
841
+ function scheduleBatch(tasks, opts = {}) {
842
+ const byId = new Map;
843
+ for (const t of tasks)
844
+ if (!byId.has(t.wbs))
845
+ byId.set(t.wbs, t);
846
+ const nodes = [...byId.keys()].sort(byWbs);
847
+ const preds = new Map(nodes.map((n) => [n, new Set((byId.get(n)?.dependencies ?? []).filter((d) => byId.has(d)))]));
848
+ const depOrder = kahnOrder(nodes, preds);
849
+ if (depOrder.length < nodes.length) {
850
+ const cycle = findCycle(new Set(nodes.filter((n) => !depOrder.includes(n))), preds);
851
+ return {
852
+ order: [],
853
+ waves: [],
854
+ cycle,
855
+ overlaps: [],
856
+ mode: "sequential",
857
+ reason: `dependency cycle ${cycle.join(" → ")}`
858
+ };
859
+ }
860
+ const files = new Map(nodes.map((n) => [n, new Set((byId.get(n)?.files ?? []).map(normalizeTaskPath))]));
861
+ const overlaps = [];
862
+ for (let i = 0;i < depOrder.length; i++) {
863
+ const before = depOrder[i];
864
+ const beforeFiles = files.get(before) ?? new Set;
865
+ for (const after of depOrder.slice(i + 1)) {
866
+ const shared = [...beforeFiles].filter((f) => files.get(after)?.has(f)).sort();
867
+ if (shared.length === 0)
868
+ continue;
869
+ overlaps.push({ before, after, files: shared });
870
+ preds.get(after)?.add(before);
871
+ }
872
+ }
873
+ const order = kahnOrder(nodes, preds);
874
+ const level = new Map;
875
+ for (const n of order) {
876
+ let l = 0;
877
+ for (const p of preds.get(n) ?? [])
878
+ l = Math.max(l, (level.get(p) ?? 0) + 1);
879
+ level.set(n, l);
880
+ }
881
+ const waves = [];
882
+ for (const n of order) {
883
+ const l = level.get(n) ?? 0;
884
+ waves[l] = [...waves[l] ?? [], n].sort(byWbs);
885
+ }
886
+ const widest = Math.max(0, ...waves.map((w) => w.length));
887
+ const concurrency = opts.concurrency ?? 2;
888
+ let reason = `widest wave holds ${widest} independent tasks`;
889
+ if (nodes.length < 2)
890
+ reason = "fewer than two tasks";
891
+ else if (concurrency < 2)
892
+ reason = "concurrency is 1";
893
+ else if (widest < 2)
894
+ reason = "every wave holds one task (dependency or file-overlap chain)";
895
+ const mode = nodes.length >= 2 && concurrency >= 2 && widest >= 2 ? "parallel" : "sequential";
896
+ return { order, waves, cycle: null, overlaps, mode, reason };
897
+ }
898
+ function normalizeTaskPath(path) {
899
+ return path.trim().replace(/^\.\//, "");
900
+ }
219
901
  function taskPhaseChildren(taskLetter, plan) {
220
902
  if (!Array.isArray(plan))
221
903
  return [];
@@ -243,13 +925,34 @@ function hostText(item) {
243
925
  return hostDecided ? `${item.text} [${item.outcome}]` : item.text;
244
926
  }
245
927
  export {
928
+ zeroTokens,
246
929
  validatePhaseTable,
247
930
  taskPhaseChildren,
931
+ sumTokens,
932
+ sumSpans,
933
+ skillInvocationPrompt,
934
+ sensitiveReasonForPath,
935
+ scheduleBatch,
936
+ quickReadiness,
937
+ promptText,
938
+ preflightTask,
248
939
  planLetter,
249
940
  planChild,
941
+ newAcc,
942
+ isCompaction,
250
943
  insertOnEntry,
251
944
  hostText,
252
945
  hostStatus,
946
+ formatTokens,
947
+ formatTokenSplit,
948
+ formatDuration,
949
+ classifyFeaturePreflightFindings,
950
+ buildRunSummary,
253
951
  buildPhasedPlan,
254
- buildBatchPlan
952
+ buildBatchPlan,
953
+ actorSplit,
954
+ accumulate,
955
+ SENSITIVE_PREFIXES,
956
+ SENSITIVE_GLOBS,
957
+ NON_ABORTING_PREFLIGHT_CODES
255
958
  };