@gobing-ai/spur 0.4.7 → 0.4.9
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/config/pipeline-budgets.json +2 -2
- package/config/rules/boundary/config-loading-ownership.yaml +1 -0
- package/config/rules/boundary/sp-plugin-standalone.yaml +1 -1
- package/config/rules/boundary/sp-script-placement.yaml +1 -1
- package/config/rules/docs/sourced-api-claims.yaml +45 -7
- package/config/rules/strict/runtime-boundaries.yaml +40 -1
- package/config/rules/structure/protected-files.yaml +1 -1
- package/config/rules/surface/check-cli-surface.yaml +33 -0
- package/config/rules/typescript/no-debugger.yaml +3 -0
- package/config/workflow-candidates.json +2 -2
- package/config/workflows/feature-verification.yaml +6 -11
- package/config/workflows/history-anatomy.yaml +14 -28
- package/config/workflows/idea-pipeline.yaml +6 -19
- package/config/workflows/pr-review.yaml +9 -16
- package/config/workflows/task-pipeline.yaml +16 -23
- package/config/workflows/wrapup-pipeline.yaml +21 -63
- package/package.json +3 -3
- package/plugins/sp/README.md +70 -37
- package/plugins/sp/agents/super-planner.md +5 -5
- package/plugins/sp/agents/super-reviewer.md +2 -2
- package/plugins/sp/commands/dev-changelog.md +1 -1
- package/plugins/sp/commands/dev-daily.md +1 -1
- package/plugins/sp/commands/dev-pr-review.md +1 -1
- package/plugins/sp/commands/dev-review-session.md +1 -1
- package/plugins/sp/commands/dev-runall.md +4 -4
- package/plugins/sp/commands/dev-verify.md +4 -6
- package/plugins/sp/commands/dev-verifyall.md +4 -5
- package/plugins/sp/hooks/hooks.json +11 -1
- package/plugins/sp/lib/context-post-tool.ts +1 -1
- package/plugins/sp/lib/context-session-start.ts +1 -1
- package/plugins/sp/lib/context-session-stop.ts +1 -1
- package/plugins/sp/lib/destructive-policy.ts +65 -1
- package/plugins/sp/plugin.json +2 -5
- package/plugins/sp/{hooks → scripts/hooks}/agent-lifecycle.ts +1 -1
- package/plugins/sp/scripts/hooks/careful-guard.ts +94 -0
- package/plugins/sp/{hooks → scripts/hooks}/context-post-tool.ts +2 -2
- package/plugins/sp/{hooks → scripts/hooks}/context-session-start.ts +1 -1
- package/plugins/sp/{hooks → scripts/hooks}/context-session-stop.ts +1 -1
- package/plugins/sp/{hooks → scripts/hooks}/fleet-guest-stop.ts +6 -4
- package/plugins/sp/{hooks → scripts/hooks}/task-write-guard.ts +38 -21
- package/plugins/sp/skills/code-implementation/SKILL.md +1 -1
- package/plugins/sp/skills/code-verification/SKILL.md +8 -8
- package/plugins/sp/skills/code-verification/references/secu-review.md +4 -3
- package/plugins/sp/skills/code-verification/references/verdict-schema.md +9 -1
- package/plugins/sp/skills/daily-summary/SKILL.md +4 -5
- package/plugins/sp/skills/dogfood-testing/SKILL.md +9 -9
- package/plugins/sp/skills/dogfood-testing/references/report-template.md +1 -1
- package/plugins/sp/skills/history-anatomy/references/modes.md +2 -2
- package/plugins/sp/skills/next-router/references/routing-table.md +1 -1
- package/plugins/sp/skills/parallel-execution/SKILL.md +1 -1
- package/plugins/sp/skills/pr-reviewing/SKILL.md +14 -15
- package/plugins/sp/skills/session-review/SKILL.md +3 -3
- package/plugins/sp/skills/source-driven-development/SKILL.md +7 -4
- package/plugins/sp/skills/spur-check/SKILL.md +14 -13
- package/plugins/sp/skills/spur-cli/SKILL.md +1 -1
- package/plugins/sp/skills/spur-cli/references/agent.md +12 -0
- package/plugins/sp/skills/spur-cli/references/builder.md +27 -6
- package/plugins/sp/skills/spur-cli/references/features.md +6 -1
- package/plugins/sp/skills/spur-cli/references/history.md +3 -0
- package/plugins/sp/skills/spur-cli/references/self.md +5 -3
- package/plugins/sp/skills/spur-cli/references/tasks/verbs.md +3 -0
- package/plugins/sp/skills/spur-cli/references/tasks.md +13 -3
- package/plugins/sp/skills/spur-cli/references/workflows.md +36 -1
- package/plugins/sp/skills/spur-dev/SKILL.md +1 -1
- package/plugins/sp/skills/spur-dev/references/cross-cutting.md +1 -1
- package/plugins/sp/skills/spur-dev/references/dev-operations.md +12 -12
- package/plugins/sp/skills/spur-dev/references/execution-batch-report.md +10 -11
- package/plugins/sp/skills/spur-dev/references/execution-batch.md +16 -17
- package/plugins/sp/skills/spur-dev/references/execution-parallel-isolation.md +1 -1
- package/plugins/sp/skills/spur-dev/references/execution-worktree-landing.md +8 -11
- package/plugins/sp/skills/spur-dev/references/execution-worktree-setup.md +6 -8
- package/plugins/sp/skills/spur-dev/references/gate-checklists.md +1 -1
- package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +33 -40
- package/plugins/sp/skills/spur-dev/references/structured-trace-emission.md +24 -24
- package/plugins/sp/skills/spur-doctor/SKILL.md +5 -4
- package/spur.js +41901 -30598
- package/config/plugin-scripts.json +0 -116
- package/config/script-placement-baseline.json +0 -33
- package/plugins/sp/hooks/careful-guard.ts +0 -74
- package/plugins/sp/hooks/pi/guard-extension.ts +0 -304
- package/plugins/sp/lib/dogfood-pipeline.ts +0 -265
- package/plugins/sp/lib/dogfood-report.ts +0 -278
- package/plugins/sp/lib/history-anatomy.generated.d.mts +0 -112
- package/plugins/sp/lib/history-anatomy.generated.mjs +0 -691
- package/plugins/sp/lib/idea-handoff.generated.d.mts +0 -17
- package/plugins/sp/lib/idea-handoff.generated.mjs +0 -1446
- package/plugins/sp/lib/inline-run-app.ts +0 -68
- package/plugins/sp/lib/inline-run.generated.d.mts +0 -37
- package/plugins/sp/lib/inline-run.generated.mjs +0 -3103
- package/plugins/sp/lib/plan-projection.generated.d.mts +0 -197
- package/plugins/sp/lib/plan-projection.generated.mjs +0 -982
- package/plugins/sp/lib/quality-gate.generated.d.mts +0 -139
- package/plugins/sp/lib/quality-gate.generated.mjs +0 -30510
- package/plugins/sp/lib/residual-scan.generated.d.mts +0 -93
- package/plugins/sp/lib/residual-scan.generated.mjs +0 -383
- package/plugins/sp/lib/run-summary-core.ts +0 -225
- package/plugins/sp/lib/spur-bin.ts +0 -36
- package/plugins/sp/lib/step-profile.generated.d.mts +0 -71
- package/plugins/sp/lib/step-profile.generated.mjs +0 -174
- package/plugins/sp/lib/transcript.ts +0 -112
- package/plugins/sp/scripts/batch-plan.mjs +0 -1096
- package/plugins/sp/scripts/batch-plan.ts +0 -145
- package/plugins/sp/scripts/batch-preflight.mjs +0 -423
- package/plugins/sp/scripts/batch-preflight.ts +0 -270
- package/plugins/sp/scripts/commit-guard.mjs +0 -226
- package/plugins/sp/scripts/commit-guard.ts +0 -248
- package/plugins/sp/scripts/daily-summary/daily-summary.mjs +0 -626
- package/plugins/sp/scripts/daily-summary/daily-summary.ts +0 -855
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +0 -211
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +0 -110
- package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +0 -282
- package/plugins/sp/scripts/dogfood-testing/validate-report.ts +0 -98
- package/plugins/sp/scripts/feature-verification-steps.mjs +0 -82
- package/plugins/sp/scripts/feature-verification-steps.ts +0 -164
- package/plugins/sp/scripts/history-anatomy-cache.mjs +0 -931
- package/plugins/sp/scripts/history-anatomy-cache.ts +0 -247
- package/plugins/sp/scripts/idea-handoff.mjs +0 -32
- package/plugins/sp/scripts/idea-handoff.ts +0 -47
- package/plugins/sp/scripts/inline-run-dispatch.mjs +0 -131
- package/plugins/sp/scripts/inline-run-dispatch.ts +0 -115
- package/plugins/sp/scripts/inline-run-setup.mjs +0 -746
- package/plugins/sp/scripts/inline-run-setup.ts +0 -198
- package/plugins/sp/scripts/persist-out-check.mjs +0 -217
- package/plugins/sp/scripts/persist-out-check.ts +0 -249
- package/plugins/sp/scripts/pr-reviewing.mjs +0 -712
- package/plugins/sp/scripts/pr-reviewing.ts +0 -952
- package/plugins/sp/scripts/quality-gate.mjs +0 -30491
- package/plugins/sp/scripts/quality-gate.ts +0 -80
- package/plugins/sp/scripts/residual-scan.mjs +0 -634
- package/plugins/sp/scripts/residual-scan.ts +0 -248
- package/plugins/sp/scripts/run-summary.mjs +0 -758
- package/plugins/sp/scripts/run-summary.ts +0 -107
- package/plugins/sp/scripts/script-root.mjs +0 -129
- package/plugins/sp/scripts/script-root.ts +0 -199
- package/plugins/sp/scripts/session-timeline.mjs +0 -359
- package/plugins/sp/scripts/session-timeline.ts +0 -190
- package/plugins/sp/scripts/task-diffstat.mjs +0 -181
- package/plugins/sp/scripts/task-diffstat.ts +0 -219
- package/plugins/sp/scripts/workflow-step-profile.mjs +0 -338
- package/plugins/sp/scripts/workflow-step-profile.ts +0 -165
- package/plugins/sp/scripts/wrapup-drift-probe.mjs +0 -190
- package/plugins/sp/scripts/wrapup-drift-probe.ts +0 -261
- package/plugins/sp/scripts/wrapup-steps.mjs +0 -627
- package/plugins/sp/scripts/wrapup-steps.ts +0 -891
|
@@ -1,1096 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// @bun
|
|
3
|
-
|
|
4
|
-
// plugins/sp/scripts/batch-plan.ts
|
|
5
|
-
import { readFileSync } from "fs";
|
|
6
|
-
|
|
7
|
-
// plugins/sp/lib/plan-projection.generated.mjs
|
|
8
|
-
function isTaskFrozen(status) {
|
|
9
|
-
return status?.toLowerCase() === "deprecated";
|
|
10
|
-
}
|
|
11
|
-
function undeprecateTaskCommand(wbs) {
|
|
12
|
-
return `spur task update ${wbs} todo`;
|
|
13
|
-
}
|
|
14
|
-
var NON_ABORTING_PREFLIGHT_CODES = new Set([
|
|
15
|
-
"L4.scenario-unverified",
|
|
16
|
-
"L4.verifying-incomplete-tasks"
|
|
17
|
-
]);
|
|
18
|
-
function classifyFeaturePreflightFindings(findings) {
|
|
19
|
-
const aborting = [];
|
|
20
|
-
const nonAborting = [];
|
|
21
|
-
for (const f of findings) {
|
|
22
|
-
if (f.severity === "error") {
|
|
23
|
-
if (NON_ABORTING_PREFLIGHT_CODES.has(f.code)) {
|
|
24
|
-
nonAborting.push(f);
|
|
25
|
-
} else {
|
|
26
|
-
aborting.push(f);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
nonAborting.push(f);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
aborting,
|
|
34
|
-
nonAborting,
|
|
35
|
-
shouldAbort: aborting.length > 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function quickReadiness(input) {
|
|
39
|
-
const status = (input.status ?? "").toLowerCase();
|
|
40
|
-
const operation = input.operation;
|
|
41
|
-
if (operation !== "run" && operation !== "refine" && operation !== "verify") {
|
|
42
|
-
return {
|
|
43
|
-
action: "invalid",
|
|
44
|
-
code: "IV",
|
|
45
|
-
reason: `quick-readiness: unknown operation '${operation}' (${input.wbs})`
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (input.filteredCount !== undefined) {
|
|
49
|
-
if (input.filteredCount < 0) {
|
|
50
|
-
return {
|
|
51
|
-
action: "invalid",
|
|
52
|
-
code: "IV",
|
|
53
|
-
reason: `quick-readiness: invalid negative filtered count '${input.filteredCount}' (${input.wbs})`
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (input.filteredCount === 0) {
|
|
57
|
-
return {
|
|
58
|
-
action: "skipped",
|
|
59
|
-
code: "EMPTY",
|
|
60
|
-
reason: `quick-readiness: empty status-filtered set — nothing to ${operation} (${input.wbs})`
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (isTaskFrozen(status)) {
|
|
65
|
-
return {
|
|
66
|
-
action: "skipped",
|
|
67
|
-
code: "DEPRECATED",
|
|
68
|
-
reason: `quick-readiness: deprecated (frozen) — no ${operation} hop; un-deprecate with \`${undeprecateTaskCommand(input.wbs)}\` (${input.wbs})`
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (status === "cancelled" || status === "done") {
|
|
72
|
-
if (operation === "verify" && input.force === true) {
|
|
73
|
-
return {
|
|
74
|
-
action: "runnable",
|
|
75
|
-
code: "FORCE",
|
|
76
|
-
reason: `quick-readiness: verify --force re-verification of ${status} task ${input.wbs}`
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
action: "skipped",
|
|
81
|
-
code: status === "done" ? "DONE" : "CANCELLED",
|
|
82
|
-
reason: `quick-readiness: already ${status} — no ${operation} hop (${input.wbs})`
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (status === "blocked") {
|
|
86
|
-
return {
|
|
87
|
-
action: "blocked",
|
|
88
|
-
code: "BLK",
|
|
89
|
-
reason: `quick-readiness: blocked — human/handover first (${input.wbs})`
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (operation === "run" && input.dependencies && input.dependencies.length > 0) {
|
|
93
|
-
const unmet = input.dependencies.filter((d) => (input.depStatuses?.[d] ?? "missing").toLowerCase() !== "done");
|
|
94
|
-
if (unmet.length > 0) {
|
|
95
|
-
const frozen = unmet.filter((d) => isTaskFrozen(input.depStatuses?.[d]));
|
|
96
|
-
const hint = frozen.length > 0 ? ` — ${frozen.map((d) => `${d} deprecated (frozen); re-point the edge or un-deprecate: \`${undeprecateTaskCommand(d)}\``).join("; ")}` : "";
|
|
97
|
-
return {
|
|
98
|
-
action: "blocked",
|
|
99
|
-
code: "DEP",
|
|
100
|
-
reason: `quick-readiness: unmet deps — ${unmet.join(", ")} (${input.wbs})${hint}`,
|
|
101
|
-
unmetDeps: unmet
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const required = input.requiredSections ?? [];
|
|
106
|
-
const present = input.presentSections ?? [];
|
|
107
|
-
const gaps = required.filter((s) => {
|
|
108
|
-
const finding = input.sectionFindings?.[s];
|
|
109
|
-
return !present.includes(s) || finding !== undefined && finding !== "";
|
|
110
|
-
});
|
|
111
|
-
if (operation === "refine") {
|
|
112
|
-
if (status !== "backlog" && status !== "todo") {
|
|
113
|
-
return {
|
|
114
|
-
action: "skipped",
|
|
115
|
-
code: "NONPLAN",
|
|
116
|
-
reason: `quick-readiness: refine targets backlog/todo only, not '${status}' (${input.wbs})`
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
action: "runnable",
|
|
121
|
-
code: "OK",
|
|
122
|
-
reason: `quick-readiness: refine ready for ${input.wbs} (${gaps.length} planning gap(s) to fill)`
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (operation === "verify") {
|
|
126
|
-
if (status !== "testing" && status !== "wip") {
|
|
127
|
-
return {
|
|
128
|
-
action: "invalid",
|
|
129
|
-
code: "NOVERIFY",
|
|
130
|
-
reason: `quick-readiness: verify needs testing/wip, not '${status}' (${input.wbs})`
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
action: "runnable",
|
|
135
|
-
code: "OK",
|
|
136
|
-
reason: `quick-readiness: verify ready for ${input.wbs}`
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (status !== "todo" && status !== "wip" && status !== "testing") {
|
|
140
|
-
return {
|
|
141
|
-
action: "invalid",
|
|
142
|
-
code: "NORUN",
|
|
143
|
-
reason: `quick-readiness: run needs todo/wip/testing, not '${status}' (${input.wbs})`
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
if (gaps.length > 0) {
|
|
147
|
-
return {
|
|
148
|
-
action: "needs-refinement",
|
|
149
|
-
code: "REFINE",
|
|
150
|
-
reason: `quick-readiness: implementation sections incomplete (${input.wbs})`,
|
|
151
|
-
gaps
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
action: "runnable",
|
|
156
|
-
code: "OK",
|
|
157
|
-
reason: `quick-readiness: run ready for ${input.wbs}`
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function preflightTask(input) {
|
|
161
|
-
const status = (input.status ?? "").toLowerCase();
|
|
162
|
-
const deps = input.dependencies ?? [];
|
|
163
|
-
const depStatuses = input.depStatuses ?? {};
|
|
164
|
-
if (status === "cancelled") {
|
|
165
|
-
return {
|
|
166
|
-
action: "skip",
|
|
167
|
-
code: "A9",
|
|
168
|
-
reason: `dev-next: cancelled — nothing to advance (${input.wbs})`
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (status === "done") {
|
|
172
|
-
return {
|
|
173
|
-
action: "skip",
|
|
174
|
-
code: "A8",
|
|
175
|
-
reason: `dev-next: already done — batch does not auto-wrap (${input.wbs})`
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
if (status === "blocked") {
|
|
179
|
-
return {
|
|
180
|
-
action: "skip",
|
|
181
|
-
code: "A7",
|
|
182
|
-
reason: `dev-next: blocked — do not launch pipeline; human/handover first (${input.wbs})`
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
if (isTaskFrozen(status)) {
|
|
186
|
-
return {
|
|
187
|
-
action: "skip",
|
|
188
|
-
code: "DEPRECATED",
|
|
189
|
-
reason: `dev-next: deprecated (frozen) — un-deprecate first: ${undeprecateTaskCommand(input.wbs)} (${input.wbs})`
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (status === "todo" || status === "backlog") {
|
|
193
|
-
const unmet = deps.filter((d) => {
|
|
194
|
-
const st = (depStatuses[d] ?? "missing").toLowerCase();
|
|
195
|
-
return st !== "done";
|
|
196
|
-
});
|
|
197
|
-
if (unmet.length > 0) {
|
|
198
|
-
return {
|
|
199
|
-
action: "skip",
|
|
200
|
-
code: "A2",
|
|
201
|
-
reason: `dev-next: blocked by deps — unmet: ${unmet.join(", ")} (${input.wbs})`,
|
|
202
|
-
unmetDeps: unmet
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return { action: "run", code: "OK", reason: `preflight clear — launch task-pipeline for ${input.wbs}` };
|
|
207
|
-
}
|
|
208
|
-
var zeroTokens = () => ({ input: 0, cacheCreate: 0, cacheRead: 0, output: 0 });
|
|
209
|
-
function formatDuration(ms) {
|
|
210
|
-
const s = Math.round(ms / 1000);
|
|
211
|
-
const h = Math.floor(s / 3600);
|
|
212
|
-
const m = Math.floor(s % 3600 / 60);
|
|
213
|
-
const ss = String(s % 60).padStart(2, "0");
|
|
214
|
-
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
|
|
215
|
-
}
|
|
216
|
-
function formatTokens(n) {
|
|
217
|
-
if (n >= 999500)
|
|
218
|
-
return `${(n / 1e6).toFixed(1)}M`;
|
|
219
|
-
return n >= 1000 ? `${Math.round(n / 1000)}k` : String(n);
|
|
220
|
-
}
|
|
221
|
-
function formatTokenSplit(t) {
|
|
222
|
-
if (!t)
|
|
223
|
-
return "n/a";
|
|
224
|
-
const nonCached = t.input + t.cacheCreate + t.output;
|
|
225
|
-
return `${formatTokens(nonCached + t.cacheRead)} / ${formatTokens(nonCached)}`;
|
|
226
|
-
}
|
|
227
|
-
var OPERATOR_TOOLS = new Set(["AskUserQuestion", "ask_user_question"]);
|
|
228
|
-
function isCompaction(row) {
|
|
229
|
-
return row.type === "compaction" || row.type === "system" && row.subtype === "compact_boundary";
|
|
230
|
-
}
|
|
231
|
-
function firstTextContent(row) {
|
|
232
|
-
const content = row.message?.content;
|
|
233
|
-
if (typeof content === "string")
|
|
234
|
-
return content;
|
|
235
|
-
if (!Array.isArray(content))
|
|
236
|
-
return;
|
|
237
|
-
return content.find((b) => b.type === "text")?.text;
|
|
238
|
-
}
|
|
239
|
-
function skillInvocationPrompt(text) {
|
|
240
|
-
const name = /^\s*<skill name="([^"]+)"/.exec(text)?.[1];
|
|
241
|
-
if (name === undefined)
|
|
242
|
-
return;
|
|
243
|
-
const close = text.lastIndexOf("</skill>");
|
|
244
|
-
const args = close < 0 ? "" : text.slice(close + "</skill>".length).trim();
|
|
245
|
-
return args === "" ? `/${name}` : `/${name} ${args}`;
|
|
246
|
-
}
|
|
247
|
-
function promptText(row) {
|
|
248
|
-
if (row.type === "custom_message") {
|
|
249
|
-
if (row.display === false)
|
|
250
|
-
return;
|
|
251
|
-
const text = typeof row.content === "string" ? row.content.trim() : "";
|
|
252
|
-
return text === "" ? undefined : text;
|
|
253
|
-
}
|
|
254
|
-
if (row.type === "message") {
|
|
255
|
-
if (row.message?.role !== "user")
|
|
256
|
-
return;
|
|
257
|
-
const text = firstTextContent(row);
|
|
258
|
-
if (text === undefined)
|
|
259
|
-
return;
|
|
260
|
-
return skillInvocationPrompt(text) ?? text;
|
|
261
|
-
}
|
|
262
|
-
if (row.type !== "user" || row.isMeta || row.isCompactSummary)
|
|
263
|
-
return;
|
|
264
|
-
const content = row.message?.content;
|
|
265
|
-
if (typeof content === "string")
|
|
266
|
-
return content;
|
|
267
|
-
if (!Array.isArray(content) || content.some((b) => b.type === "tool_result"))
|
|
268
|
-
return;
|
|
269
|
-
return content.find((b) => b.type === "text")?.text;
|
|
270
|
-
}
|
|
271
|
-
function sumTokens(all) {
|
|
272
|
-
const total = zeroTokens();
|
|
273
|
-
for (const t of all)
|
|
274
|
-
for (const k of Object.keys(total))
|
|
275
|
-
total[k] += t[k];
|
|
276
|
-
return total;
|
|
277
|
-
}
|
|
278
|
-
function sumSpans(spans) {
|
|
279
|
-
return {
|
|
280
|
-
workMs: spans.reduce((n, s) => n + s.workMs, 0),
|
|
281
|
-
waitMs: spans.reduce((n, s) => n + s.waitMs, 0),
|
|
282
|
-
toolCalls: spans.reduce((n, s) => n + s.toolCalls, 0),
|
|
283
|
-
tokens: sumTokens(spans.map((s) => s.tokens))
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
var newAcc = (ts) => ({
|
|
287
|
-
last: ts,
|
|
288
|
-
askMs: 0,
|
|
289
|
-
asks: new Map,
|
|
290
|
-
toolIds: new Set,
|
|
291
|
-
messages: new Map,
|
|
292
|
-
compactions: 0
|
|
293
|
-
});
|
|
294
|
-
function accumulate(acc, row, ts) {
|
|
295
|
-
acc.last = Math.max(acc.last, ts);
|
|
296
|
-
if (row.type === "message") {
|
|
297
|
-
const m = row.message;
|
|
298
|
-
if (m?.role === "assistant") {
|
|
299
|
-
const blocks = Array.isArray(m.content) ? m.content : [];
|
|
300
|
-
for (const b of blocks) {
|
|
301
|
-
if (b.type === "toolCall" && b.id) {
|
|
302
|
-
acc.toolIds.add(b.id);
|
|
303
|
-
if (b.name && OPERATOR_TOOLS.has(b.name))
|
|
304
|
-
acc.asks.set(b.id, ts);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const u = m.usage;
|
|
308
|
-
if (u && row.id)
|
|
309
|
-
acc.messages.set(row.id, {
|
|
310
|
-
input: u.input ?? 0,
|
|
311
|
-
cacheCreate: u.cacheWrite ?? 0,
|
|
312
|
-
cacheRead: u.cacheRead ?? 0,
|
|
313
|
-
output: u.output ?? 0
|
|
314
|
-
});
|
|
315
|
-
} else if (m?.role === "toolResult" && m.toolCallId && acc.asks.has(m.toolCallId)) {
|
|
316
|
-
acc.askMs += ts - (acc.asks.get(m.toolCallId) ?? ts);
|
|
317
|
-
}
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (row.type === "compaction")
|
|
321
|
-
acc.compactions++;
|
|
322
|
-
const blocks = Array.isArray(row.message?.content) ? row.message.content : [];
|
|
323
|
-
for (const b of blocks) {
|
|
324
|
-
if (b.type === "tool_use" && b.id) {
|
|
325
|
-
acc.toolIds.add(b.id);
|
|
326
|
-
if (b.name && OPERATOR_TOOLS.has(b.name))
|
|
327
|
-
acc.asks.set(b.id, ts);
|
|
328
|
-
} else if (b.type === "tool_result" && b.tool_use_id && acc.asks.has(b.tool_use_id)) {
|
|
329
|
-
acc.askMs += ts - (acc.asks.get(b.tool_use_id) ?? ts);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const u = row.message?.usage;
|
|
333
|
-
if (row.type === "assistant" && u && row.message?.id) {
|
|
334
|
-
acc.messages.set(row.message.id, {
|
|
335
|
-
input: u.input_tokens ?? 0,
|
|
336
|
-
cacheCreate: u.cache_creation_input_tokens ?? 0,
|
|
337
|
-
cacheRead: u.cache_read_input_tokens ?? 0,
|
|
338
|
-
output: u.output_tokens ?? 0
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
var IDLE_GAP_MS = 300000;
|
|
343
|
-
var SHELL_TOOLS = new Set(["bash", "shell", "exec", "exec_command", "run_command", "command"]);
|
|
344
|
-
var SUBAGENT_TOOLS = new Set(["agent", "task", "invoke_subagent", "subagent", "dispatch_agent"]);
|
|
345
|
-
var LOWERCASE_OPERATOR_TOOLS = new Set(["askuserquestion", "ask_user_question"]);
|
|
346
|
-
var ACTOR_PRECEDENCE = ["operator", "subagent", "shell", "other"];
|
|
347
|
-
function actorOf(tool) {
|
|
348
|
-
const t = tool.toLowerCase().replace(/[^a-z_]/g, "");
|
|
349
|
-
if (LOWERCASE_OPERATOR_TOOLS.has(t))
|
|
350
|
-
return "operator";
|
|
351
|
-
if (SUBAGENT_TOOLS.has(t))
|
|
352
|
-
return "subagent";
|
|
353
|
-
if (SHELL_TOOLS.has(t))
|
|
354
|
-
return "shell";
|
|
355
|
-
return "other";
|
|
356
|
-
}
|
|
357
|
-
function unionMs(spans, start, end) {
|
|
358
|
-
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]);
|
|
359
|
-
let total = 0;
|
|
360
|
-
let cursor = Number.NaN;
|
|
361
|
-
let openUntil = Number.NaN;
|
|
362
|
-
for (const [a, b] of clipped) {
|
|
363
|
-
if (!Number.isFinite(cursor)) {
|
|
364
|
-
cursor = a;
|
|
365
|
-
openUntil = b;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (a > openUntil) {
|
|
369
|
-
total += openUntil - cursor;
|
|
370
|
-
cursor = a;
|
|
371
|
-
openUntil = b;
|
|
372
|
-
} else {
|
|
373
|
-
openUntil = Math.max(openUntil, b);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (Number.isFinite(cursor))
|
|
377
|
-
total += openUntil - cursor;
|
|
378
|
-
return total;
|
|
379
|
-
}
|
|
380
|
-
function subtract(spans, claimed) {
|
|
381
|
-
let free = spans;
|
|
382
|
-
for (const [ca, cb] of claimed) {
|
|
383
|
-
const next = [];
|
|
384
|
-
for (const [a, b] of free) {
|
|
385
|
-
if (cb <= a || ca >= b) {
|
|
386
|
-
next.push([a, b]);
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
if (ca > a)
|
|
390
|
-
next.push([a, ca]);
|
|
391
|
-
if (cb < b)
|
|
392
|
-
next.push([cb, b]);
|
|
393
|
-
}
|
|
394
|
-
free = next;
|
|
395
|
-
}
|
|
396
|
-
return free;
|
|
397
|
-
}
|
|
398
|
-
function actorSplit(rows, start, end) {
|
|
399
|
-
const empty = {
|
|
400
|
-
operatorMs: 0,
|
|
401
|
-
longestOperatorWaitMs: 0,
|
|
402
|
-
modelMs: 0,
|
|
403
|
-
shellMs: 0,
|
|
404
|
-
subagentMs: 0,
|
|
405
|
-
otherToolMs: 0,
|
|
406
|
-
idleMs: 0,
|
|
407
|
-
compactions: 0,
|
|
408
|
-
subagentErrors: 0
|
|
409
|
-
};
|
|
410
|
-
const window = end - start;
|
|
411
|
-
if (window <= 0)
|
|
412
|
-
return empty;
|
|
413
|
-
const calls = new Map;
|
|
414
|
-
const results = new Map;
|
|
415
|
-
const eventTs = [];
|
|
416
|
-
let compactions = 0;
|
|
417
|
-
for (const [row, ts] of rows) {
|
|
418
|
-
if (ts < start || ts > end)
|
|
419
|
-
continue;
|
|
420
|
-
eventTs.push(ts);
|
|
421
|
-
if (isCompaction(row))
|
|
422
|
-
compactions++;
|
|
423
|
-
const blocks = Array.isArray(row.message?.content) ? row.message?.content : [];
|
|
424
|
-
if (row.message?.role === "toolResult" && row.message.toolCallId !== undefined) {
|
|
425
|
-
results.set(row.message.toolCallId, { ts, isError: row.message.isError === true });
|
|
426
|
-
}
|
|
427
|
-
for (const b of blocks) {
|
|
428
|
-
if ((b.type === "tool_use" || b.type === "toolCall") && b.id !== undefined && b.name !== undefined) {
|
|
429
|
-
calls.set(b.id, { id: b.id, actor: actorOf(b.name), ts });
|
|
430
|
-
} else if (b.type === "tool_result" && b.tool_use_id !== undefined) {
|
|
431
|
-
results.set(b.tool_use_id, { ts, isError: b.is_error === true });
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
let subagentErrors = 0;
|
|
436
|
-
const resolved = [];
|
|
437
|
-
for (const call of calls.values()) {
|
|
438
|
-
const result = results.get(call.id);
|
|
439
|
-
if (result?.isError === true && call.actor === "subagent")
|
|
440
|
-
subagentErrors++;
|
|
441
|
-
resolved.push({ ...call, end: Math.min(result?.ts ?? end, end) });
|
|
442
|
-
}
|
|
443
|
-
const claimed = [];
|
|
444
|
-
const byActor = new Map;
|
|
445
|
-
for (const actor of ACTOR_PRECEDENCE) {
|
|
446
|
-
const mine = resolved.filter((r) => r.actor === actor).map((r) => [r.ts, r.end]);
|
|
447
|
-
const free = subtract(mine, claimed);
|
|
448
|
-
for (const span of free)
|
|
449
|
-
claimed.push(span);
|
|
450
|
-
const ms = unionMs(free, start, end);
|
|
451
|
-
byActor.set(actor, ms);
|
|
452
|
-
if (actor === "operator") {
|
|
453
|
-
empty.longestOperatorWaitMs = Math.max(0, ...mine.map(([a, b]) => b - a));
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
const boundaries = [...new Set([start, end, ...eventTs, ...claimed.flat()])].sort((a, b) => a - b);
|
|
457
|
-
const claimedSorted = [...claimed].sort((a, b) => a[0] - b[0]);
|
|
458
|
-
let idleMs = 0;
|
|
459
|
-
for (let i = 0;i < boundaries.length - 1; i++) {
|
|
460
|
-
const a = boundaries[i];
|
|
461
|
-
const b = boundaries[i + 1];
|
|
462
|
-
if (b - a < IDLE_GAP_MS)
|
|
463
|
-
continue;
|
|
464
|
-
if (claimedSorted.some(([ca, cb]) => ca < b && cb > a))
|
|
465
|
-
continue;
|
|
466
|
-
idleMs += b - a;
|
|
467
|
-
}
|
|
468
|
-
const accounted = (byActor.get("operator") ?? 0) + (byActor.get("subagent") ?? 0) + (byActor.get("shell") ?? 0) + (byActor.get("other") ?? 0) + idleMs;
|
|
469
|
-
return {
|
|
470
|
-
...empty,
|
|
471
|
-
operatorMs: byActor.get("operator") ?? 0,
|
|
472
|
-
subagentMs: byActor.get("subagent") ?? 0,
|
|
473
|
-
shellMs: byActor.get("shell") ?? 0,
|
|
474
|
-
otherToolMs: byActor.get("other") ?? 0,
|
|
475
|
-
idleMs,
|
|
476
|
-
modelMs: Math.max(0, window - accounted),
|
|
477
|
-
compactions,
|
|
478
|
-
subagentErrors
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
function attemptWindow(attempts) {
|
|
482
|
-
const starts = attempts.map((a) => Date.parse(a.startedAt ?? "")).filter((n) => !Number.isNaN(n));
|
|
483
|
-
const ends = attempts.map((a) => Date.parse(a.completedAt ?? "")).filter((n) => !Number.isNaN(n));
|
|
484
|
-
return starts.length && ends.length ? [Math.min(...starts), Math.max(...ends)] : undefined;
|
|
485
|
-
}
|
|
486
|
-
function summaryRow(stage, status, span, measured) {
|
|
487
|
-
return {
|
|
488
|
-
stage,
|
|
489
|
-
status,
|
|
490
|
-
workMs: span.workMs,
|
|
491
|
-
waitMs: span.waitMs,
|
|
492
|
-
toolCalls: measured ? span.toolCalls : null,
|
|
493
|
-
tokens: measured ? span.tokens : null,
|
|
494
|
-
time: formatDuration(span.workMs),
|
|
495
|
-
wait: formatDuration(span.waitMs),
|
|
496
|
-
token: formatTokenSplit(measured ? span.tokens : null)
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function buildRunSummary(rows, inputs, opts = {}) {
|
|
500
|
-
const { since, until } = opts;
|
|
501
|
-
const windows = [];
|
|
502
|
-
for (const { label, progress } of inputs) {
|
|
503
|
-
const states = (progress.states ?? []).flatMap((s) => {
|
|
504
|
-
const w = attemptWindow((s.actions ?? []).flatMap((a) => a.attempts ?? []));
|
|
505
|
-
return w ? [{ s, w }] : [];
|
|
506
|
-
});
|
|
507
|
-
if (!states.length)
|
|
508
|
-
throw new Error(`progress for run ${progress.runId} has no timed attempts`);
|
|
509
|
-
if (inputs.length === 1) {
|
|
510
|
-
for (const { s, w } of states) {
|
|
511
|
-
const stage = (s.visit ?? 1) > 1 ? `${s.state} (visit ${s.visit})` : s.state;
|
|
512
|
-
windows.push({ stage, status: s.status ?? "", start: w[0], end: w[1] });
|
|
513
|
-
}
|
|
514
|
-
} else {
|
|
515
|
-
const stage = label ?? `${progress.workflow ?? "run"} ${progress.runId.slice(0, 8)}`;
|
|
516
|
-
const start = Math.min(...states.map(({ w }) => w[0]));
|
|
517
|
-
windows.push({
|
|
518
|
-
stage,
|
|
519
|
-
status: progress.status ?? "",
|
|
520
|
-
start,
|
|
521
|
-
end: Math.max(...states.map(({ w }) => w[1]))
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
windows.sort((a, b) => a.start - b.start);
|
|
526
|
-
const measure = (start, end) => {
|
|
527
|
-
const acc = newAcc(start);
|
|
528
|
-
for (const [row, ts] of rows)
|
|
529
|
-
if (ts >= start && ts <= end && promptText(row) === undefined)
|
|
530
|
-
accumulate(acc, row, ts);
|
|
531
|
-
const span = {
|
|
532
|
-
workMs: end - start - acc.askMs,
|
|
533
|
-
waitMs: acc.askMs,
|
|
534
|
-
toolCalls: acc.toolIds.size,
|
|
535
|
-
tokens: sumTokens([...acc.messages.values()])
|
|
536
|
-
};
|
|
537
|
-
return { span, measured: acc.toolIds.size > 0 || acc.messages.size > 0 };
|
|
538
|
-
};
|
|
539
|
-
const sinceMs = since ? Date.parse(since) : Number.NaN;
|
|
540
|
-
const totalStart = Number.isNaN(sinceMs) ? Math.min(...windows.map((w) => w.start)) : sinceMs;
|
|
541
|
-
let totalEnd = Math.max(...windows.map((w) => w.end));
|
|
542
|
-
if (!Number.isNaN(sinceMs)) {
|
|
543
|
-
for (const [, ts] of rows)
|
|
544
|
-
if (ts >= sinceMs)
|
|
545
|
-
totalEnd = Math.max(totalEnd, ts);
|
|
546
|
-
}
|
|
547
|
-
const untilMs = until ? Date.parse(until) : Number.NaN;
|
|
548
|
-
if (!Number.isNaN(untilMs) && untilMs > totalStart)
|
|
549
|
-
totalEnd = untilMs;
|
|
550
|
-
const stageRows = windows.map((w) => {
|
|
551
|
-
const { span, measured } = measure(w.start, w.end);
|
|
552
|
-
return summaryRow(w.stage, w.status, span, measured);
|
|
553
|
-
});
|
|
554
|
-
const totalMeasure = measure(totalStart, totalEnd);
|
|
555
|
-
const statuses = [...new Set(inputs.map((i) => i.progress.status ?? ""))].join("/");
|
|
556
|
-
const total = summaryRow("Total", statuses, totalMeasure.span, totalMeasure.measured);
|
|
557
|
-
const overlaps = windows.some((w, i) => i > 0 && w.start < (windows[i - 1]?.end ?? 0));
|
|
558
|
-
const sum = sumSpans(stageRows.map((r) => ({ ...r, toolCalls: r.toolCalls ?? 0, tokens: r.tokens ?? zeroTokens() })));
|
|
559
|
-
const overhead = {
|
|
560
|
-
workMs: total.workMs - sum.workMs,
|
|
561
|
-
waitMs: total.waitMs - sum.waitMs,
|
|
562
|
-
toolCalls: (total.toolCalls ?? 0) - sum.toolCalls,
|
|
563
|
-
tokens: Object.fromEntries(Object.keys(sum.tokens).map((k) => [k, (total.tokens?.[k] ?? 0) - sum.tokens[k]]))
|
|
564
|
-
};
|
|
565
|
-
if (!overlaps && overhead.workMs > 0)
|
|
566
|
-
stageRows.push(summaryRow("driver overhead", "", overhead, totalMeasure.measured));
|
|
567
|
-
return {
|
|
568
|
-
available: true,
|
|
569
|
-
rows: stageRows,
|
|
570
|
-
total,
|
|
571
|
-
actors: actorSplit(rows, totalStart, totalEnd),
|
|
572
|
-
gate: { ms: null, reason: "no matching check receipt" },
|
|
573
|
-
skippedLines: opts.skippedLines ?? 0
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
var SENSITIVE_PREFIXES = ["drizzle/", "packages/config/", ".github/", "plugins/sp/hooks/"];
|
|
577
|
-
var SENSITIVE_GLOBS = ["apps/server/src/**/auth*", "**/*secret*", "**/*.sql"];
|
|
578
|
-
function globToRegex(glob) {
|
|
579
|
-
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("**/", "\x00").replaceAll("**", "\x01").replaceAll("*", "[^/]*").replaceAll("\x00", "(?:.*/)?").replaceAll("\x01", ".*");
|
|
580
|
-
return new RegExp(`^${escaped}$`, "s");
|
|
581
|
-
}
|
|
582
|
-
var SENSITIVE_MATCHERS = [
|
|
583
|
-
...SENSITIVE_PREFIXES.map((prefix) => ({
|
|
584
|
-
label: prefix,
|
|
585
|
-
test: (path) => path.startsWith(prefix)
|
|
586
|
-
})),
|
|
587
|
-
...SENSITIVE_GLOBS.map((glob) => {
|
|
588
|
-
const regex = globToRegex(glob);
|
|
589
|
-
return { label: glob, test: (path) => regex.test(path) };
|
|
590
|
-
})
|
|
591
|
-
];
|
|
592
|
-
function sensitiveReasonForPath(path) {
|
|
593
|
-
const match = SENSITIVE_MATCHERS.find((entry) => entry.test(path));
|
|
594
|
-
return match ? `matches sensitive pattern ${match.label}` : null;
|
|
595
|
-
}
|
|
596
|
-
function planLetter(index) {
|
|
597
|
-
if (!Number.isInteger(index) || index < 0 || index > 25) {
|
|
598
|
-
throw new Error(`plan letter out of range: ${index} (expected 0..25)`);
|
|
599
|
-
}
|
|
600
|
-
return String.fromCharCode(65 + index);
|
|
601
|
-
}
|
|
602
|
-
function planChild(parent, index) {
|
|
603
|
-
if (!Number.isInteger(index) || index < 0 || index > 8) {
|
|
604
|
-
throw new Error(`plan child index out of range: ${index} (expected 0..8 under ${parent})`);
|
|
605
|
-
}
|
|
606
|
-
if (parent.length !== 1 || !/[A-Z]/.test(parent)) {
|
|
607
|
-
throw new Error(`plan child parent must be a single letter: ${parent}`);
|
|
608
|
-
}
|
|
609
|
-
return `${parent}${index + 1}`;
|
|
610
|
-
}
|
|
611
|
-
var PREPARE_ID = "prepare";
|
|
612
|
-
var REPORT_ID = "report";
|
|
613
|
-
var PHASE_ID_PREFIX = "phase.";
|
|
614
|
-
var TASK_ID_PREFIX = "task.";
|
|
615
|
-
var WAVE_SIZE = 24;
|
|
616
|
-
var TITLE_CAP = 60;
|
|
617
|
-
function isStateMachine(def) {
|
|
618
|
-
return def.kind !== "transition-flow" && def.kind !== "dag";
|
|
619
|
-
}
|
|
620
|
-
function hasDisplay(s) {
|
|
621
|
-
return s.display !== undefined;
|
|
622
|
-
}
|
|
623
|
-
function resolvePhaseTitle(states, phase) {
|
|
624
|
-
for (const s of states) {
|
|
625
|
-
if (s.display?.phase === phase && s.display.phaseTitle !== undefined)
|
|
626
|
-
return s.display.phaseTitle;
|
|
627
|
-
}
|
|
628
|
-
return phase;
|
|
629
|
-
}
|
|
630
|
-
function childText(label, title, id) {
|
|
631
|
-
return id.startsWith("prepare.") || id.startsWith("task.") || id === PREPARE_ID || id === REPORT_ID ? `${label} ${title}` : `${label} ${title} · ${id}`;
|
|
632
|
-
}
|
|
633
|
-
function buildPhasedPlan(def) {
|
|
634
|
-
if (!isStateMachine(def))
|
|
635
|
-
return null;
|
|
636
|
-
const annotated = def.states.filter(hasDisplay);
|
|
637
|
-
if (annotated.length === 0)
|
|
638
|
-
return null;
|
|
639
|
-
const items = [
|
|
640
|
-
{ label: "A", id: PREPARE_ID, outcome: "pending", title: "Prepare", text: "A Prepare" },
|
|
641
|
-
{
|
|
642
|
-
label: "A1",
|
|
643
|
-
id: "prepare.1",
|
|
644
|
-
outcome: "pending",
|
|
645
|
-
parent: "A",
|
|
646
|
-
title: "Quick readiness",
|
|
647
|
-
text: "A1 Quick readiness"
|
|
648
|
-
},
|
|
649
|
-
{ label: "A2", id: "prepare.2", outcome: "pending", parent: "A", title: "Prepare Git", text: "A2 Prepare Git" },
|
|
650
|
-
{
|
|
651
|
-
label: "A3",
|
|
652
|
-
id: "prepare.3",
|
|
653
|
-
outcome: "pending",
|
|
654
|
-
parent: "A",
|
|
655
|
-
title: "Publish plan",
|
|
656
|
-
text: "A3 Publish plan"
|
|
657
|
-
}
|
|
658
|
-
];
|
|
659
|
-
const phases = [];
|
|
660
|
-
for (const s of def.states) {
|
|
661
|
-
if (s.display !== undefined && !phases.includes(s.display.phase))
|
|
662
|
-
phases.push(s.display.phase);
|
|
663
|
-
}
|
|
664
|
-
for (const [phaseIndex, phase] of phases.entries()) {
|
|
665
|
-
const letter = planLetter(phaseIndex + 1);
|
|
666
|
-
const phaseTitle = resolvePhaseTitle(def.states, phase);
|
|
667
|
-
items.push({
|
|
668
|
-
label: letter,
|
|
669
|
-
id: `${PHASE_ID_PREFIX}${phase}`,
|
|
670
|
-
outcome: "pending",
|
|
671
|
-
title: phaseTitle,
|
|
672
|
-
text: `${letter} ${phaseTitle}`
|
|
673
|
-
});
|
|
674
|
-
let childIndex = 0;
|
|
675
|
-
for (const s of def.states) {
|
|
676
|
-
if (s.display?.phase !== phase || s.display.show === "on-entry")
|
|
677
|
-
continue;
|
|
678
|
-
const label = planChild(letter, childIndex++);
|
|
679
|
-
const title = s.display.title ?? s.id;
|
|
680
|
-
items.push({
|
|
681
|
-
label,
|
|
682
|
-
id: s.id,
|
|
683
|
-
outcome: "pending",
|
|
684
|
-
parent: letter,
|
|
685
|
-
title,
|
|
686
|
-
text: childText(label, title, s.id)
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
return items;
|
|
691
|
-
}
|
|
692
|
-
function validatePhaseTable(def) {
|
|
693
|
-
if (!isStateMachine(def))
|
|
694
|
-
return [];
|
|
695
|
-
const annotated = def.states.filter(hasDisplay);
|
|
696
|
-
if (annotated.length === 0)
|
|
697
|
-
return [];
|
|
698
|
-
const errors = [];
|
|
699
|
-
const terminals = new Set(def.terminalStates ?? []);
|
|
700
|
-
for (const s of def.states) {
|
|
701
|
-
if (s.display === undefined && !terminals.has(s.id)) {
|
|
702
|
-
errors.push(`state "${s.id}" has no display phase — every non-terminal state must declare display when any state does`);
|
|
703
|
-
}
|
|
704
|
-
if (s.display !== undefined && terminals.has(s.id)) {
|
|
705
|
-
errors.push(`terminal state "${s.id}" must not declare display`);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
const phases = [];
|
|
709
|
-
for (const s of annotated) {
|
|
710
|
-
if (!phases.includes(s.display.phase))
|
|
711
|
-
phases.push(s.display.phase);
|
|
712
|
-
}
|
|
713
|
-
if (phases.length > 25) {
|
|
714
|
-
errors.push(`${phases.length} phases exceed the 25 plan letters (B-Z); split the workflow or drop phase rows`);
|
|
715
|
-
}
|
|
716
|
-
for (const phase of phases) {
|
|
717
|
-
const members = annotated.filter((s) => s.display.phase === phase);
|
|
718
|
-
if (members.length > 9) {
|
|
719
|
-
errors.push(`phase "${phase}" has ${members.length} states — at most 9 digit children fit under one letter`);
|
|
720
|
-
}
|
|
721
|
-
const titles = [...new Set(members.map((s) => s.display.phaseTitle).filter((t) => t !== undefined))];
|
|
722
|
-
if (titles.length > 1) {
|
|
723
|
-
errors.push(`phase "${phase}" has conflicting phaseTitle values: ${titles.map((t) => `"${t}"`).join(", ")}`);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
return errors;
|
|
727
|
-
}
|
|
728
|
-
function insertOnEntry(items, stateId, def) {
|
|
729
|
-
if (!isStateMachine(def))
|
|
730
|
-
return items;
|
|
731
|
-
if (items.some((i) => i.id === stateId))
|
|
732
|
-
return items;
|
|
733
|
-
const display = def.states.find((s) => s.id === stateId)?.display;
|
|
734
|
-
if (display === undefined || (def.terminalStates ?? []).includes(stateId))
|
|
735
|
-
return items;
|
|
736
|
-
const phaseRow = items.find((i) => i.id === `${PHASE_ID_PREFIX}${display.phase}`);
|
|
737
|
-
if (phaseRow === undefined)
|
|
738
|
-
return items;
|
|
739
|
-
const children = items.filter((i) => i.parent === phaseRow.label);
|
|
740
|
-
const label = planChild(phaseRow.label, children.length);
|
|
741
|
-
const title = display.title ?? stateId;
|
|
742
|
-
const item = {
|
|
743
|
-
label,
|
|
744
|
-
id: stateId,
|
|
745
|
-
outcome: "pending",
|
|
746
|
-
parent: phaseRow.label,
|
|
747
|
-
title,
|
|
748
|
-
text: childText(label, title, stateId)
|
|
749
|
-
};
|
|
750
|
-
const last = children.at(-1) ?? phaseRow;
|
|
751
|
-
const at = items.indexOf(last) + 1;
|
|
752
|
-
return [...items.slice(0, at), item, ...items.slice(at)];
|
|
753
|
-
}
|
|
754
|
-
function truncateTitle(name) {
|
|
755
|
-
if (name.length <= TITLE_CAP)
|
|
756
|
-
return name;
|
|
757
|
-
return `${name.slice(0, TITLE_CAP - 1).replace(/[\uD800-\uDBFF]$/, "")}…`;
|
|
758
|
-
}
|
|
759
|
-
function buildBatchPlan(tasks) {
|
|
760
|
-
const waves = [];
|
|
761
|
-
for (let offset = 0;offset < tasks.length; offset += WAVE_SIZE) {
|
|
762
|
-
const items = [
|
|
763
|
-
{ label: "A", id: PREPARE_ID, outcome: "pending", title: "Prepare batch", text: "A Prepare batch" },
|
|
764
|
-
{
|
|
765
|
-
label: "A1",
|
|
766
|
-
id: "prepare.1",
|
|
767
|
-
outcome: "pending",
|
|
768
|
-
parent: "A",
|
|
769
|
-
title: "Resolve and freeze task set",
|
|
770
|
-
text: "A1 Resolve and freeze task set"
|
|
771
|
-
},
|
|
772
|
-
{
|
|
773
|
-
label: "A2",
|
|
774
|
-
id: "prepare.2",
|
|
775
|
-
outcome: "pending",
|
|
776
|
-
parent: "A",
|
|
777
|
-
title: "Order by dependencies",
|
|
778
|
-
text: "A2 Order by dependencies"
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
label: "A3",
|
|
782
|
-
id: "prepare.3",
|
|
783
|
-
outcome: "pending",
|
|
784
|
-
parent: "A",
|
|
785
|
-
title: "Prepare Git",
|
|
786
|
-
text: "A3 Prepare Git"
|
|
787
|
-
},
|
|
788
|
-
{
|
|
789
|
-
label: "A4",
|
|
790
|
-
id: "prepare.4",
|
|
791
|
-
outcome: "pending",
|
|
792
|
-
parent: "A",
|
|
793
|
-
title: "Publish plan",
|
|
794
|
-
text: "A4 Publish plan"
|
|
795
|
-
}
|
|
796
|
-
];
|
|
797
|
-
tasks.slice(offset, offset + WAVE_SIZE).forEach((task, i) => {
|
|
798
|
-
const label = planLetter(i + 1);
|
|
799
|
-
const title = `${task.wbs} ${truncateTitle(task.name)}`;
|
|
800
|
-
items.push({
|
|
801
|
-
label,
|
|
802
|
-
id: `${TASK_ID_PREFIX}${task.wbs}`,
|
|
803
|
-
outcome: "pending",
|
|
804
|
-
title,
|
|
805
|
-
text: `${label} ${title}`
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
items.push({ label: "Z", id: REPORT_ID, outcome: "pending", title: "Batch report", text: "Z Batch report" });
|
|
809
|
-
waves.push(items);
|
|
810
|
-
}
|
|
811
|
-
return waves;
|
|
812
|
-
}
|
|
813
|
-
var byWbs = (a, b) => a.localeCompare(b, "en", { numeric: true });
|
|
814
|
-
function kahnOrder(nodes, preds) {
|
|
815
|
-
const indegree = new Map(nodes.map((n) => [n, preds.get(n)?.size ?? 0]));
|
|
816
|
-
const succ = new Map(nodes.map((n) => [n, []]));
|
|
817
|
-
for (const [n, ps] of preds)
|
|
818
|
-
for (const p of ps)
|
|
819
|
-
succ.get(p)?.push(n);
|
|
820
|
-
const ready = nodes.filter((n) => indegree.get(n) === 0).sort(byWbs);
|
|
821
|
-
const order = [];
|
|
822
|
-
for (let n = ready.shift();n !== undefined; n = ready.shift()) {
|
|
823
|
-
order.push(n);
|
|
824
|
-
for (const s of succ.get(n) ?? []) {
|
|
825
|
-
const d = (indegree.get(s) ?? 0) - 1;
|
|
826
|
-
indegree.set(s, d);
|
|
827
|
-
if (d === 0) {
|
|
828
|
-
ready.push(s);
|
|
829
|
-
ready.sort(byWbs);
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
return order;
|
|
834
|
-
}
|
|
835
|
-
function findCycle(remaining, preds) {
|
|
836
|
-
const state = new Map;
|
|
837
|
-
const stack = [];
|
|
838
|
-
const visit = (n) => {
|
|
839
|
-
state.set(n, "visiting");
|
|
840
|
-
stack.push(n);
|
|
841
|
-
for (const p of [...preds.get(n) ?? []].sort(byWbs)) {
|
|
842
|
-
if (!remaining.has(p))
|
|
843
|
-
continue;
|
|
844
|
-
if (state.get(p) === "visiting")
|
|
845
|
-
return [...stack.slice(stack.indexOf(p)), p];
|
|
846
|
-
if (!state.has(p)) {
|
|
847
|
-
const cycle = visit(p);
|
|
848
|
-
if (cycle)
|
|
849
|
-
return cycle;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
stack.pop();
|
|
853
|
-
state.set(n, "done");
|
|
854
|
-
return null;
|
|
855
|
-
};
|
|
856
|
-
for (const n of [...remaining].sort(byWbs)) {
|
|
857
|
-
if (state.has(n))
|
|
858
|
-
continue;
|
|
859
|
-
const cycle = visit(n);
|
|
860
|
-
if (cycle)
|
|
861
|
-
return cycle;
|
|
862
|
-
}
|
|
863
|
-
return [];
|
|
864
|
-
}
|
|
865
|
-
function scheduleBatch(tasks, opts = {}) {
|
|
866
|
-
const byId = new Map;
|
|
867
|
-
for (const t of tasks)
|
|
868
|
-
if (!byId.has(t.wbs))
|
|
869
|
-
byId.set(t.wbs, t);
|
|
870
|
-
const nodes = [...byId.keys()].sort(byWbs);
|
|
871
|
-
const preds = new Map(nodes.map((n) => [n, new Set((byId.get(n)?.dependencies ?? []).filter((d) => byId.has(d)))]));
|
|
872
|
-
const depOrder = kahnOrder(nodes, preds);
|
|
873
|
-
if (depOrder.length < nodes.length) {
|
|
874
|
-
const cycle = findCycle(new Set(nodes.filter((n) => !depOrder.includes(n))), preds);
|
|
875
|
-
return {
|
|
876
|
-
order: [],
|
|
877
|
-
waves: [],
|
|
878
|
-
cycle,
|
|
879
|
-
overlaps: [],
|
|
880
|
-
mode: "sequential",
|
|
881
|
-
reason: `dependency cycle ${cycle.join(" → ")}`
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
const files = new Map(nodes.map((n) => [n, new Set((byId.get(n)?.files ?? []).map(normalizeTaskPath))]));
|
|
885
|
-
const overlaps = [];
|
|
886
|
-
for (let i = 0;i < depOrder.length; i++) {
|
|
887
|
-
const before = depOrder[i];
|
|
888
|
-
const beforeFiles = files.get(before) ?? new Set;
|
|
889
|
-
for (const after of depOrder.slice(i + 1)) {
|
|
890
|
-
const shared = [...beforeFiles].filter((f) => files.get(after)?.has(f)).sort();
|
|
891
|
-
if (shared.length === 0)
|
|
892
|
-
continue;
|
|
893
|
-
overlaps.push({ before, after, files: shared });
|
|
894
|
-
preds.get(after)?.add(before);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
const order = kahnOrder(nodes, preds);
|
|
898
|
-
const level = new Map;
|
|
899
|
-
for (const n of order) {
|
|
900
|
-
let l = 0;
|
|
901
|
-
for (const p of preds.get(n) ?? [])
|
|
902
|
-
l = Math.max(l, (level.get(p) ?? 0) + 1);
|
|
903
|
-
level.set(n, l);
|
|
904
|
-
}
|
|
905
|
-
const waves = [];
|
|
906
|
-
for (const n of order) {
|
|
907
|
-
const l = level.get(n) ?? 0;
|
|
908
|
-
waves[l] = [...waves[l] ?? [], n].sort(byWbs);
|
|
909
|
-
}
|
|
910
|
-
const widest = Math.max(0, ...waves.map((w) => w.length));
|
|
911
|
-
const concurrency = opts.concurrency ?? 2;
|
|
912
|
-
let reason = `widest wave holds ${widest} independent tasks`;
|
|
913
|
-
if (nodes.length < 2)
|
|
914
|
-
reason = "fewer than two tasks";
|
|
915
|
-
else if (concurrency < 2)
|
|
916
|
-
reason = "concurrency is 1";
|
|
917
|
-
else if (widest < 2)
|
|
918
|
-
reason = "every wave holds one task (dependency or file-overlap chain)";
|
|
919
|
-
const mode = nodes.length >= 2 && concurrency >= 2 && widest >= 2 ? "parallel" : "sequential";
|
|
920
|
-
return { order, waves, cycle: null, overlaps, mode, reason };
|
|
921
|
-
}
|
|
922
|
-
function normalizeTaskPath(path) {
|
|
923
|
-
return path.trim().replace(/^\.\//, "");
|
|
924
|
-
}
|
|
925
|
-
function taskPhaseChildren(taskLetter, plan) {
|
|
926
|
-
if (!Array.isArray(plan))
|
|
927
|
-
return [];
|
|
928
|
-
return plan.filter((i) => i.id.startsWith(PHASE_ID_PREFIX) && i.label.length === 1).map((row, i) => {
|
|
929
|
-
const label = planChild(taskLetter, i);
|
|
930
|
-
return {
|
|
931
|
-
label,
|
|
932
|
-
id: row.id,
|
|
933
|
-
outcome: row.outcome,
|
|
934
|
-
parent: taskLetter,
|
|
935
|
-
title: row.title,
|
|
936
|
-
text: `${label} ${row.title}`
|
|
937
|
-
};
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
function hostStatus(outcome) {
|
|
941
|
-
if (outcome === "completed")
|
|
942
|
-
return "completed";
|
|
943
|
-
if (outcome === "active")
|
|
944
|
-
return "in_progress";
|
|
945
|
-
return "pending";
|
|
946
|
-
}
|
|
947
|
-
function hostText(item) {
|
|
948
|
-
const hostDecided = item.outcome === "skipped" || item.outcome === "failed" || item.outcome === "unattempted" || item.outcome === "blocked";
|
|
949
|
-
return hostDecided ? `${item.text} [${item.outcome}]` : item.text;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
// plugins/sp/scripts/batch-plan.ts
|
|
953
|
-
var BATCH_PLAN_USAGE = "usage: batch-plan.ts waves --tasks <tasks.json> | order --tasks <tasks.json> [--concurrency <n>] | task-children --letter <A-Z> --plan <plan.json>";
|
|
954
|
-
function readJsonFile(path) {
|
|
955
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
956
|
-
}
|
|
957
|
-
function isBatchTask(value) {
|
|
958
|
-
return typeof value === "object" && value !== null && typeof value.wbs === "string" && typeof value.name === "string";
|
|
959
|
-
}
|
|
960
|
-
function isStringArray(value) {
|
|
961
|
-
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
962
|
-
}
|
|
963
|
-
function isScheduleTask(value) {
|
|
964
|
-
if (typeof value !== "object" || value === null)
|
|
965
|
-
return false;
|
|
966
|
-
const t = value;
|
|
967
|
-
return typeof t.wbs === "string" && (t.dependencies === undefined || isStringArray(t.dependencies)) && (t.files === undefined || isStringArray(t.files));
|
|
968
|
-
}
|
|
969
|
-
function main(argv) {
|
|
970
|
-
const mode = argv[0];
|
|
971
|
-
if (mode === "waves") {
|
|
972
|
-
if (argv[1] !== "--tasks" || argv[2] === undefined) {
|
|
973
|
-
process.stderr.write(`${BATCH_PLAN_USAGE}
|
|
974
|
-
`);
|
|
975
|
-
return 2;
|
|
976
|
-
}
|
|
977
|
-
let tasks;
|
|
978
|
-
try {
|
|
979
|
-
tasks = readJsonFile(argv[2]);
|
|
980
|
-
} catch (error) {
|
|
981
|
-
process.stderr.write(`batch-plan: cannot read ${argv[2]} \u2014 ${error instanceof Error ? error.message : String(error)}
|
|
982
|
-
`);
|
|
983
|
-
return 1;
|
|
984
|
-
}
|
|
985
|
-
if (!Array.isArray(tasks) || !tasks.every(isBatchTask)) {
|
|
986
|
-
process.stderr.write(`batch-plan: --tasks file must be a JSON array of {wbs, name}
|
|
987
|
-
`);
|
|
988
|
-
return 1;
|
|
989
|
-
}
|
|
990
|
-
process.stdout.write(`${JSON.stringify({ waves: buildBatchPlan(tasks) })}
|
|
991
|
-
`);
|
|
992
|
-
return 0;
|
|
993
|
-
}
|
|
994
|
-
if (mode === "order") {
|
|
995
|
-
let tasksPath = "";
|
|
996
|
-
let concurrency = 2;
|
|
997
|
-
for (let i = 1;i + 1 < argv.length; i += 2) {
|
|
998
|
-
if (argv[i] === "--tasks")
|
|
999
|
-
tasksPath = argv[i + 1] ?? "";
|
|
1000
|
-
else if (argv[i] === "--concurrency")
|
|
1001
|
-
concurrency = Number(argv[i + 1]);
|
|
1002
|
-
}
|
|
1003
|
-
if (tasksPath === "" || !Number.isInteger(concurrency) || concurrency < 1) {
|
|
1004
|
-
process.stderr.write(`${BATCH_PLAN_USAGE}
|
|
1005
|
-
`);
|
|
1006
|
-
return 2;
|
|
1007
|
-
}
|
|
1008
|
-
let tasks;
|
|
1009
|
-
try {
|
|
1010
|
-
tasks = readJsonFile(tasksPath);
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
process.stderr.write(`batch-plan: cannot read ${tasksPath} \u2014 ${error instanceof Error ? error.message : String(error)}
|
|
1013
|
-
`);
|
|
1014
|
-
return 1;
|
|
1015
|
-
}
|
|
1016
|
-
if (!Array.isArray(tasks) || !tasks.every(isScheduleTask)) {
|
|
1017
|
-
process.stderr.write(`batch-plan: --tasks file must be a JSON array of {wbs, dependencies?, files?}
|
|
1018
|
-
`);
|
|
1019
|
-
return 1;
|
|
1020
|
-
}
|
|
1021
|
-
process.stdout.write(`${JSON.stringify(scheduleBatch(tasks, { concurrency }))}
|
|
1022
|
-
`);
|
|
1023
|
-
return 0;
|
|
1024
|
-
}
|
|
1025
|
-
if (mode === "task-children") {
|
|
1026
|
-
let letter = "";
|
|
1027
|
-
let planPath = "";
|
|
1028
|
-
for (let i = 1;i + 1 < argv.length; i += 2) {
|
|
1029
|
-
if (argv[i] === "--letter")
|
|
1030
|
-
letter = argv[i + 1] ?? "";
|
|
1031
|
-
else if (argv[i] === "--plan")
|
|
1032
|
-
planPath = argv[i + 1] ?? "";
|
|
1033
|
-
}
|
|
1034
|
-
if (!/^[A-Z]$/.test(letter) || planPath === "") {
|
|
1035
|
-
process.stderr.write(`${BATCH_PLAN_USAGE}
|
|
1036
|
-
`);
|
|
1037
|
-
return 2;
|
|
1038
|
-
}
|
|
1039
|
-
let payload;
|
|
1040
|
-
try {
|
|
1041
|
-
payload = readJsonFile(planPath);
|
|
1042
|
-
} catch (error) {
|
|
1043
|
-
process.stderr.write(`batch-plan: cannot read ${planPath} \u2014 ${error instanceof Error ? error.message : String(error)}
|
|
1044
|
-
`);
|
|
1045
|
-
return 1;
|
|
1046
|
-
}
|
|
1047
|
-
const plan = Array.isArray(payload) ? payload : payload.plan;
|
|
1048
|
-
if (!Array.isArray(plan)) {
|
|
1049
|
-
process.stderr.write("batch-plan: --plan file must be a plan array or a todo --json payload with a `plan` field\n");
|
|
1050
|
-
return 1;
|
|
1051
|
-
}
|
|
1052
|
-
process.stdout.write(`${JSON.stringify(taskPhaseChildren(letter, plan))}
|
|
1053
|
-
`);
|
|
1054
|
-
return 0;
|
|
1055
|
-
}
|
|
1056
|
-
process.stderr.write(`${BATCH_PLAN_USAGE}
|
|
1057
|
-
`);
|
|
1058
|
-
return 2;
|
|
1059
|
-
}
|
|
1060
|
-
{
|
|
1061
|
-
process.exit(main(process.argv.slice(2)));
|
|
1062
|
-
}
|
|
1063
|
-
export {
|
|
1064
|
-
BATCH_PLAN_USAGE,
|
|
1065
|
-
NON_ABORTING_PREFLIGHT_CODES,
|
|
1066
|
-
SENSITIVE_GLOBS,
|
|
1067
|
-
SENSITIVE_PREFIXES,
|
|
1068
|
-
accumulate,
|
|
1069
|
-
actorSplit,
|
|
1070
|
-
buildBatchPlan,
|
|
1071
|
-
buildPhasedPlan,
|
|
1072
|
-
buildRunSummary,
|
|
1073
|
-
classifyFeaturePreflightFindings,
|
|
1074
|
-
formatDuration,
|
|
1075
|
-
formatTokenSplit,
|
|
1076
|
-
formatTokens,
|
|
1077
|
-
hostStatus,
|
|
1078
|
-
hostText,
|
|
1079
|
-
insertOnEntry,
|
|
1080
|
-
isCompaction,
|
|
1081
|
-
main,
|
|
1082
|
-
newAcc,
|
|
1083
|
-
planChild,
|
|
1084
|
-
planLetter,
|
|
1085
|
-
preflightTask,
|
|
1086
|
-
promptText,
|
|
1087
|
-
quickReadiness,
|
|
1088
|
-
scheduleBatch,
|
|
1089
|
-
sensitiveReasonForPath,
|
|
1090
|
-
skillInvocationPrompt,
|
|
1091
|
-
sumSpans,
|
|
1092
|
-
sumTokens,
|
|
1093
|
-
taskPhaseChildren,
|
|
1094
|
-
validatePhaseTable,
|
|
1095
|
-
zeroTokens
|
|
1096
|
-
};
|