pi-spine 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +563 -0
- package/bin/get-version.mjs +35 -0
- package/bin/spine-batch.mjs +425 -0
- package/bin/spine-cli/batch.mjs +47 -0
- package/bin/spine-cli/gate.mjs +10 -0
- package/bin/spine-cli/integrate.mjs +10 -0
- package/bin/spine-cli/plan.mjs +12 -0
- package/bin/spine-cli/shared.mjs +73 -0
- package/bin/spine-cli/status.mjs +18 -0
- package/bin/spine-cli/verify.mjs +199 -0
- package/bin/spine-config.mjs +212 -0
- package/bin/spine-dashboard.mjs +178 -0
- package/bin/spine-deps.mjs +69 -0
- package/bin/spine-doctor.mjs +468 -0
- package/bin/spine-gate.mjs +137 -0
- package/bin/spine-init.mjs +398 -0
- package/bin/spine-integrate.mjs +77 -0
- package/bin/spine-journal.mjs +198 -0
- package/bin/spine-migrate-from-taskplane.mjs +136 -0
- package/bin/spine-plan.mjs +83 -0
- package/bin/spine-preflight.mjs +700 -0
- package/bin/spine-report-progress.d.mts +28 -0
- package/bin/spine-report-progress.mjs +126 -0
- package/bin/spine-review-step.d.mts +24 -0
- package/bin/spine-review-step.mjs +124 -0
- package/bin/spine-rules.mjs +35 -0
- package/bin/spine-settings.mjs +186 -0
- package/bin/spine-state.mjs +110 -0
- package/bin/spine-status.mjs +79 -0
- package/bin/spine-tasks.mjs +293 -0
- package/bin/spine-worker-runner.mjs +314 -0
- package/bin/spine.mjs +404 -0
- package/extensions/spine/settings-slash.ts +20 -0
- package/extensions/spine/slash-commands.ts +806 -0
- package/extensions/spine/worker-tools.ts +279 -0
- package/extensions/spine-orchestrator.ts +12 -0
- package/package.json +72 -0
- package/skills/.gitkeep +0 -0
- package/skills/create-spine-tasks/SKILL.md +375 -0
- package/skills/create-spine-tasks/references/context-template.md +25 -0
- package/skills/create-spine-tasks/references/contract-template.md +98 -0
- package/skills/create-spine-tasks/references/explore-template.md +63 -0
- package/skills/create-spine-tasks/references/prompt-template.md +276 -0
- package/src/batch/abort.mjs +272 -0
- package/src/batch/agent-session-worker.mjs +297 -0
- package/src/batch/batch-state-io.mjs +53 -0
- package/src/batch/contract-verify.mjs +310 -0
- package/src/batch/detached-start.mjs +778 -0
- package/src/batch/diagnosis.mjs +378 -0
- package/src/batch/engine-lanes/merge.mjs +632 -0
- package/src/batch/engine-lanes/queue.mjs +208 -0
- package/src/batch/engine-lanes/review.mjs +970 -0
- package/src/batch/engine-lanes.mjs +388 -0
- package/src/batch/engine-scope.mjs +251 -0
- package/src/batch/engine.mjs +445 -0
- package/src/batch/evidence-command.mjs +157 -0
- package/src/batch/evidence.mjs +203 -0
- package/src/batch/gate.mjs +359 -0
- package/src/batch/git-commit-env.mjs +46 -0
- package/src/batch/git-exec.mjs +26 -0
- package/src/batch/heartbeat.mjs +430 -0
- package/src/batch/integrate.mjs +414 -0
- package/src/batch/journal-rebuild.mjs +388 -0
- package/src/batch/journal.mjs +373 -0
- package/src/batch/lane-commit.mjs +153 -0
- package/src/batch/lifecycle.mjs +364 -0
- package/src/batch/metrics.mjs +265 -0
- package/src/batch/orphan-detect.mjs +210 -0
- package/src/batch/post-merge-limbo.mjs +80 -0
- package/src/batch/postmortem.mjs +296 -0
- package/src/batch/readers/spine-state.mjs +95 -0
- package/src/batch/readers/taskplane-state.mjs +136 -0
- package/src/batch/reconcile.mjs +729 -0
- package/src/batch/resume-common.mjs +104 -0
- package/src/batch/resume-engine.mjs +66 -0
- package/src/batch/resume-multi-lanes.mjs +479 -0
- package/src/batch/resume-multi-validate.mjs +187 -0
- package/src/batch/resume-multi.mjs +254 -0
- package/src/batch/resume.mjs +475 -0
- package/src/batch/retry.mjs +257 -0
- package/src/batch/review-scope.mjs +136 -0
- package/src/batch/review.mjs +1045 -0
- package/src/batch/salvage.mjs +332 -0
- package/src/batch/state.mjs +680 -0
- package/src/batch/task-stall-budget.mjs +88 -0
- package/src/batch/worker-host.mjs +683 -0
- package/src/batch/worker-output.mjs +253 -0
- package/src/batch/worker-prompt.mjs +84 -0
- package/src/batch/worktree.mjs +290 -0
- package/src/cli/deps.mjs +141 -0
- package/src/cli/handoff.mjs +364 -0
- package/src/cli/rules.mjs +429 -0
- package/src/cli/settings-set.mjs +171 -0
- package/src/cli/settings-show.mjs +140 -0
- package/src/cli/settings-slash.mjs +107 -0
- package/src/config/contract.mjs +56 -0
- package/src/config/cursor-rules/discover.mjs +416 -0
- package/src/config/cursor-rules/index.mjs +39 -0
- package/src/config/cursor-rules/match-globs.mjs +132 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
- package/src/config/cursor-rules/priority.mjs +26 -0
- package/src/config/cursor-rules/profile.mjs +403 -0
- package/src/config/cursor-rules/select.mjs +259 -0
- package/src/config/defaults.mjs +36 -0
- package/src/config/env-overrides.mjs +207 -0
- package/src/config/merge-defaults.mjs +47 -0
- package/src/config/pi-spine-root.mjs +93 -0
- package/src/config/reviewer-context.mjs +243 -0
- package/src/config/settings-fields.mjs +265 -0
- package/src/config/worker-backend.mjs +116 -0
- package/src/config/worker-context.mjs +402 -0
- package/src/config/worker-launch-script.mjs +130 -0
- package/src/config/worktree-setup-hook.mjs +122 -0
- package/src/dashboard/public/dashboard.css +77 -0
- package/src/dashboard/public/dashboard.js +349 -0
- package/src/dashboard/public/index.html +80 -0
- package/src/dashboard/server.mjs +155 -0
- package/src/dashboard/snapshot.mjs +414 -0
- package/src/dashboard/sse.mjs +15 -0
- package/src/dashboard/view.mjs +292 -0
- package/src/doctor/agent-model-inherit.mjs +101 -0
- package/src/doctor/batch-size-guidance.mjs +72 -0
- package/src/doctor/coexistence.mjs +312 -0
- package/src/doctor/rules-manifest.mjs +133 -0
- package/src/doctor/stale-path.mjs +156 -0
- package/src/doctor/stall-config.mjs +108 -0
- package/src/doctor/suggest-max-parallel.mjs +53 -0
- package/src/doctor/task-packet-size.mjs +110 -0
- package/src/doctor/worktree-health.mjs +71 -0
- package/src/migrate/taskplane-config.mjs +116 -0
- package/src/planner/cycles.mjs +63 -0
- package/src/planner/format-plan.mjs +132 -0
- package/src/planner/graph.mjs +99 -0
- package/src/planner/index.mjs +125 -0
- package/src/planner/lanes.mjs +111 -0
- package/src/planner/pending.mjs +39 -0
- package/src/planner/scope.mjs +142 -0
- package/src/process/liveness.mjs +21 -0
- package/src/tasks/packet/discover.mjs +40 -0
- package/src/tasks/packet/index.mjs +81 -0
- package/src/tasks/packet/merge-deps.mjs +79 -0
- package/src/tasks/packet/parse-prompt.mjs +445 -0
- package/src/tasks/packet/parse-status.mjs +118 -0
- package/src/tasks/packet/validate-contract.mjs +115 -0
- package/src/tasks/packet/validate-prompt.mjs +99 -0
- package/src/worker-tools/report-progress.d.mts +18 -0
- package/src/worker-tools/report-progress.mjs +59 -0
- package/src/worker-tools/request-gate.d.mts +17 -0
- package/src/worker-tools/request-gate.mjs +54 -0
- package/templates/agents/reviewer.md +123 -0
- package/templates/agents/supervisor.md +59 -0
- package/templates/agents/worker.md +122 -0
- package/templates/rules-profile.json +27 -0
- package/templates/spine-config.json +64 -0
- package/templates/tasks/CONTEXT.md +30 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const HEADER_FIELD_RE = /^\*\*([^*]+):\*\*\s*(.+)$/gm;
|
|
2
|
+
const STEP_SECTION_RE = /^### Step (\d+): (.+)$/gm;
|
|
3
|
+
const CHECKBOX_RE = /^-\s+\[([ xX])\]\s+(.+)$/gm;
|
|
4
|
+
const STEP_STATUS_RE = /^\*\*Status:\*\*\s*(.+)$/m;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} markdown STATUS.md contents
|
|
8
|
+
*/
|
|
9
|
+
export function parseStatus(markdown) {
|
|
10
|
+
const header = {};
|
|
11
|
+
let match;
|
|
12
|
+
HEADER_FIELD_RE.lastIndex = 0;
|
|
13
|
+
while ((match = HEADER_FIELD_RE.exec(markdown)) !== null) {
|
|
14
|
+
header[match[1].trim()] = match[2].trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const steps = [];
|
|
18
|
+
const stepMatches = [...markdown.matchAll(STEP_SECTION_RE)];
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < stepMatches.length; i++) {
|
|
21
|
+
const number = Number(stepMatches[i][1]);
|
|
22
|
+
const title = stepMatches[i][2].trim();
|
|
23
|
+
const start = stepMatches[i].index + stepMatches[i][0].length;
|
|
24
|
+
const end = i + 1 < stepMatches.length ? stepMatches[i + 1].index : markdown.length;
|
|
25
|
+
const body = markdown.slice(start, end);
|
|
26
|
+
|
|
27
|
+
const statusMatch = STEP_STATUS_RE.exec(body);
|
|
28
|
+
const status = statusMatch?.[1]?.trim() ?? "";
|
|
29
|
+
const checkboxes = parseCheckboxes(body);
|
|
30
|
+
|
|
31
|
+
steps.push({
|
|
32
|
+
number,
|
|
33
|
+
title,
|
|
34
|
+
status,
|
|
35
|
+
statusKind: classifyStepStatus(status),
|
|
36
|
+
checkboxes,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { header, steps };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {ReturnType<typeof parseStatus>} status
|
|
45
|
+
*/
|
|
46
|
+
export function getStepProgress(status) {
|
|
47
|
+
let total = 0;
|
|
48
|
+
let completed = 0;
|
|
49
|
+
const steps = [];
|
|
50
|
+
|
|
51
|
+
for (const step of status.steps) {
|
|
52
|
+
const stepTotal = step.checkboxes.length;
|
|
53
|
+
const stepCompleted = step.checkboxes.filter((cb) => cb.checked).length;
|
|
54
|
+
total += stepTotal;
|
|
55
|
+
completed += stepCompleted;
|
|
56
|
+
steps.push({
|
|
57
|
+
number: step.number,
|
|
58
|
+
title: step.title,
|
|
59
|
+
statusKind: step.statusKind,
|
|
60
|
+
total: stepTotal,
|
|
61
|
+
completed: stepCompleted,
|
|
62
|
+
complete: stepTotal > 0 && stepCompleted === stepTotal,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
total,
|
|
68
|
+
completed,
|
|
69
|
+
percent: total === 0 ? 0 : Math.round((completed / total) * 100),
|
|
70
|
+
steps,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {ReturnType<typeof parseStatus>} status
|
|
76
|
+
*/
|
|
77
|
+
export function listIncompleteSteps(status) {
|
|
78
|
+
const incomplete = [];
|
|
79
|
+
|
|
80
|
+
for (const step of status.steps) {
|
|
81
|
+
const unchecked = step.checkboxes.filter((cb) => !cb.checked);
|
|
82
|
+
if (unchecked.length === 0) continue;
|
|
83
|
+
incomplete.push({
|
|
84
|
+
number: step.number,
|
|
85
|
+
title: step.title,
|
|
86
|
+
unchecked: unchecked.map((cb) => ({ text: cb.text })),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return incomplete;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} body
|
|
95
|
+
*/
|
|
96
|
+
function parseCheckboxes(body) {
|
|
97
|
+
const checkboxes = [];
|
|
98
|
+
let match;
|
|
99
|
+
CHECKBOX_RE.lastIndex = 0;
|
|
100
|
+
while ((match = CHECKBOX_RE.exec(body)) !== null) {
|
|
101
|
+
checkboxes.push({
|
|
102
|
+
checked: match[1].toLowerCase() === "x",
|
|
103
|
+
text: match[2].trim(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return checkboxes;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {string} statusText
|
|
111
|
+
* @returns {'complete' | 'in-progress' | 'not-started'}
|
|
112
|
+
*/
|
|
113
|
+
function classifyStepStatus(statusText) {
|
|
114
|
+
const lower = statusText.toLowerCase();
|
|
115
|
+
if (statusText.includes("✅") || lower.includes("complete")) return "complete";
|
|
116
|
+
if (statusText.includes("🟨") || lower.includes("progress")) return "in-progress";
|
|
117
|
+
return "not-started";
|
|
118
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate-time checks for PROMPT.md `## Contract` tables (handoff §4.4).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import micromatch from "micromatch";
|
|
6
|
+
|
|
7
|
+
const GLOB_PROBE = "__probe__.mjs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolve effective contract validation mode (handoff §3.1).
|
|
11
|
+
*
|
|
12
|
+
* @param {{ mode?: string, taskId?: string | null, legacyTaskIdPrefixes?: string[] }} [options]
|
|
13
|
+
* @returns {"required" | "optional" | "legacy"}
|
|
14
|
+
*/
|
|
15
|
+
export function resolveContractMode(options = {}) {
|
|
16
|
+
const globalMode = options.mode ?? "optional";
|
|
17
|
+
if (globalMode === "legacy") {
|
|
18
|
+
return "legacy";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const taskId = options.taskId ?? null;
|
|
22
|
+
const legacyPrefixes = options.legacyTaskIdPrefixes ?? [];
|
|
23
|
+
if (taskId && legacyPrefixes.some((prefix) => taskId.startsWith(prefix))) {
|
|
24
|
+
return "legacy";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return globalMode === "required" ? "required" : "optional";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {ReturnType<import("./parse-prompt.mjs").parseContract>} parsed
|
|
32
|
+
* @param {{ mode?: string, taskId?: string | null, legacyTaskIdPrefixes?: string[] }} [options]
|
|
33
|
+
* @returns {{ ok: boolean, errors: string[], warnings: string[], mode: "required" | "optional" | "legacy" }}
|
|
34
|
+
*/
|
|
35
|
+
export function validateContract(parsed, options = {}) {
|
|
36
|
+
const mode = resolveContractMode(options);
|
|
37
|
+
const errors = [...(parsed.errors ?? [])];
|
|
38
|
+
const warnings = [];
|
|
39
|
+
|
|
40
|
+
if (mode === "legacy") {
|
|
41
|
+
return { ok: errors.length === 0, errors, warnings, mode };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!parsed.hasSection) {
|
|
45
|
+
if (mode === "required") {
|
|
46
|
+
errors.push("Missing ## Contract section");
|
|
47
|
+
} else if (mode === "optional") {
|
|
48
|
+
warnings.push("Missing ## Contract section");
|
|
49
|
+
}
|
|
50
|
+
return { ok: errors.length === 0, errors, warnings, mode };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!parsed.rawTableValid) {
|
|
54
|
+
return { ok: errors.length === 0, errors, warnings, mode };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const field of parsed.unknownFields ?? []) {
|
|
58
|
+
warnings.push(`Unknown contract field: ${field}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isContractTableEmpty(parsed) && mode === "required") {
|
|
62
|
+
errors.push("Contract table is empty");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const placeholderIssue of parsed.placeholderIssues ?? []) {
|
|
66
|
+
if (mode === "required") {
|
|
67
|
+
errors.push(placeholderIssue);
|
|
68
|
+
} else {
|
|
69
|
+
warnings.push(placeholderIssue);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const field of ["fileScopeMustChange", "fileScopeMustNotChange", "artifactsMustExist"]) {
|
|
74
|
+
for (const pattern of parsed[field] ?? []) {
|
|
75
|
+
if (!isValidContractGlob(pattern)) {
|
|
76
|
+
errors.push(`Contract ${field}: invalid glob pattern "${pattern}"`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { ok: errors.length === 0, errors, warnings, mode };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {ReturnType<import("./parse-prompt.mjs").parseContract>} parsed
|
|
86
|
+
*/
|
|
87
|
+
function isContractTableEmpty(parsed) {
|
|
88
|
+
return (
|
|
89
|
+
parsed.testCommand === null &&
|
|
90
|
+
parsed.fileScopeMustChange.length === 0 &&
|
|
91
|
+
parsed.fileScopeMustNotChange.length === 0 &&
|
|
92
|
+
parsed.minLineCoverage === null &&
|
|
93
|
+
parsed.artifactsMustExist.length === 0 &&
|
|
94
|
+
(parsed.unknownFields?.length ?? 0) === 0
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} pattern
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
function isValidContractGlob(pattern) {
|
|
103
|
+
const trimmed = String(pattern ?? "").trim();
|
|
104
|
+
if (!trimmed || trimmed.includes("\n")) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
micromatch.isMatch(GLOB_PROBE, trimmed);
|
|
110
|
+
micromatch.isMatch(trimmed, GLOB_PROBE);
|
|
111
|
+
return true;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared fail-loud PROMPT validation helpers (planner, preflight, rules CLI, batch engine).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CONTRACT_DEFAULTS } from "../../config/defaults.mjs";
|
|
6
|
+
import {
|
|
7
|
+
parseContract,
|
|
8
|
+
parsePrompt,
|
|
9
|
+
validatePrompt as validatePromptStructure,
|
|
10
|
+
} from "./parse-prompt.mjs";
|
|
11
|
+
import { validateContract } from "./validate-contract.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
|
|
15
|
+
*
|
|
16
|
+
* @param {string} markdown PROMPT.md contents
|
|
17
|
+
* @param {{ mode?: string, legacyTaskIdPrefixes?: string[], contract?: { mode?: string, legacyTaskIdPrefixes?: string[] } }} [options]
|
|
18
|
+
* @returns {{ ok: boolean, errors: string[], warnings: string[], prompt: ReturnType<typeof parsePrompt>, contract: ReturnType<typeof parseContract> }}
|
|
19
|
+
*/
|
|
20
|
+
export function validatePrompt(markdown, options = {}) {
|
|
21
|
+
const structure = validatePromptStructure(markdown);
|
|
22
|
+
const errors = [...structure.errors];
|
|
23
|
+
const mode =
|
|
24
|
+
options.mode ??
|
|
25
|
+
options.contract?.mode ??
|
|
26
|
+
"optional";
|
|
27
|
+
const legacyTaskIdPrefixes =
|
|
28
|
+
options.legacyTaskIdPrefixes ??
|
|
29
|
+
options.contract?.legacyTaskIdPrefixes ??
|
|
30
|
+
[...CONTRACT_DEFAULTS.legacyTaskIdPrefixes];
|
|
31
|
+
|
|
32
|
+
const contract = parseContract(markdown);
|
|
33
|
+
const contractValidation = validateContract(contract, {
|
|
34
|
+
mode,
|
|
35
|
+
taskId: structure.prompt.taskId,
|
|
36
|
+
legacyTaskIdPrefixes,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
errors.push(...contractValidation.errors);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
ok: errors.length === 0,
|
|
43
|
+
errors,
|
|
44
|
+
warnings: contractValidation.warnings,
|
|
45
|
+
prompt: structure.prompt,
|
|
46
|
+
contract,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {{ validation?: { ok?: boolean, errors?: string[] }, promptPath?: string }} packet
|
|
52
|
+
* @param {string} taskId
|
|
53
|
+
* @returns {{ taskId: string, promptPath?: string, errors: string[] } | null}
|
|
54
|
+
*/
|
|
55
|
+
export function collectPromptValidationFailure(packet, taskId) {
|
|
56
|
+
if (packet.validation?.ok) return null;
|
|
57
|
+
return {
|
|
58
|
+
taskId,
|
|
59
|
+
promptPath: packet.promptPath,
|
|
60
|
+
errors: packet.validation?.errors ?? ["Unknown PROMPT validation failure"],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Array<{ taskId: string, promptPath?: string, errors: string[] }>} failures
|
|
66
|
+
*/
|
|
67
|
+
export function formatPromptValidationFailures(failures) {
|
|
68
|
+
if (failures.length === 0) return "PROMPT validation failed";
|
|
69
|
+
if (failures.length === 1) {
|
|
70
|
+
const [failure] = failures;
|
|
71
|
+
const location = failure.promptPath ? ` (${failure.promptPath})` : "";
|
|
72
|
+
return `Invalid PROMPT for ${failure.taskId}${location}:\n${formatErrorLines(failure.errors)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const lines = [`PROMPT validation failed for ${failures.length} task(s):`];
|
|
76
|
+
for (const failure of failures) {
|
|
77
|
+
const location = failure.promptPath ? ` (${failure.promptPath})` : "";
|
|
78
|
+
lines.push(`${failure.taskId}${location}:`);
|
|
79
|
+
lines.push(formatErrorLines(failure.errors));
|
|
80
|
+
}
|
|
81
|
+
return lines.join("\n");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {{ validation?: { ok?: boolean, errors?: string[] }, promptPath?: string }} packet
|
|
86
|
+
* @param {string} taskId
|
|
87
|
+
*/
|
|
88
|
+
export function assertValidTaskPacket(packet, taskId) {
|
|
89
|
+
const failure = collectPromptValidationFailure(packet, taskId);
|
|
90
|
+
if (!failure) return;
|
|
91
|
+
throw new Error(formatPromptValidationFailures([failure]));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {string[]} errors
|
|
96
|
+
*/
|
|
97
|
+
function formatErrorLines(errors) {
|
|
98
|
+
return errors.map((error) => ` - ${error}`).join("\n");
|
|
99
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ReportTaskProgressResult {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
eventId?: string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function reportTaskProgress(params: {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
batchId: string;
|
|
10
|
+
taskId: string;
|
|
11
|
+
laneNumber?: number;
|
|
12
|
+
laneId?: string;
|
|
13
|
+
step: number;
|
|
14
|
+
checkboxesComplete?: number;
|
|
15
|
+
checkboxesTotal?: number;
|
|
16
|
+
correlationId?: string;
|
|
17
|
+
journal?: { projectRoot: string; batchId: string; append?: Function };
|
|
18
|
+
}): ReportTaskProgressResult;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker progress reporter — journal task.step_completed (PRD §14.5, §18.4).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { appendJournalEvent } from "../batch/journal.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} params
|
|
9
|
+
* @param {string} params.projectRoot
|
|
10
|
+
* @param {string} params.batchId
|
|
11
|
+
* @param {string} params.taskId
|
|
12
|
+
* @param {number} [params.laneNumber]
|
|
13
|
+
* @param {string} [params.laneId]
|
|
14
|
+
* @param {number} params.step
|
|
15
|
+
* @param {number} [params.checkboxesComplete]
|
|
16
|
+
* @param {number} [params.checkboxesTotal]
|
|
17
|
+
* @param {string} [params.correlationId]
|
|
18
|
+
* @param {{ projectRoot: string, batchId: string, append?: Function }} [params.journal]
|
|
19
|
+
*/
|
|
20
|
+
export function reportTaskProgress({
|
|
21
|
+
projectRoot,
|
|
22
|
+
batchId,
|
|
23
|
+
taskId,
|
|
24
|
+
laneNumber,
|
|
25
|
+
laneId,
|
|
26
|
+
step,
|
|
27
|
+
checkboxesComplete,
|
|
28
|
+
checkboxesTotal,
|
|
29
|
+
correlationId,
|
|
30
|
+
journal,
|
|
31
|
+
}) {
|
|
32
|
+
if (!projectRoot || !batchId) {
|
|
33
|
+
return { ok: false, error: "batch context required (projectRoot and batchId)" };
|
|
34
|
+
}
|
|
35
|
+
if (!taskId) {
|
|
36
|
+
return { ok: false, error: "taskId required" };
|
|
37
|
+
}
|
|
38
|
+
if (step == null || Number.isNaN(Number(step))) {
|
|
39
|
+
return { ok: false, error: "step required" };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const append = journal?.append ?? appendJournalEvent;
|
|
43
|
+
const root = journal?.projectRoot ?? projectRoot;
|
|
44
|
+
const id = journal?.batchId ?? batchId;
|
|
45
|
+
|
|
46
|
+
/** @type {Record<string, unknown>} */
|
|
47
|
+
const options = {
|
|
48
|
+
taskId,
|
|
49
|
+
step: Number(step),
|
|
50
|
+
};
|
|
51
|
+
if (laneNumber != null) options.laneNumber = laneNumber;
|
|
52
|
+
if (laneId) options.laneId = laneId;
|
|
53
|
+
if (correlationId) options.correlationId = correlationId;
|
|
54
|
+
if (checkboxesComplete != null) options.checkboxesComplete = Number(checkboxesComplete);
|
|
55
|
+
if (checkboxesTotal != null) options.checkboxesTotal = Number(checkboxesTotal);
|
|
56
|
+
|
|
57
|
+
const entry = append(root, id, "task.step_completed", options);
|
|
58
|
+
return { ok: true, eventId: entry.eventId };
|
|
59
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface RequestWorkerGateResult {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
notSupported?: boolean;
|
|
4
|
+
limitation?: string;
|
|
5
|
+
reason?: string;
|
|
6
|
+
headline?: string;
|
|
7
|
+
suggestedCommand?: string;
|
|
8
|
+
alternatives?: string[];
|
|
9
|
+
error?: string;
|
|
10
|
+
gate?: object | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function requestWorkerGate(params: {
|
|
14
|
+
projectRoot: string;
|
|
15
|
+
batchId: string;
|
|
16
|
+
reason?: string;
|
|
17
|
+
}): RequestWorkerGateResult;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker gate request — v2.2 permanent not_supported (FR-SHIP-13 / SP-241).
|
|
3
|
+
* Integrate gates are operator-managed and open automatically at batch completion.
|
|
4
|
+
* Manual and conflict gate kinds have no worker-initiated open path in v2.2.
|
|
5
|
+
* Operators approve integrate gates from the host: `spine gate approve`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { loadGateRecord } from "../batch/gate.mjs";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {object} params
|
|
12
|
+
* @param {string} params.projectRoot
|
|
13
|
+
* @param {string} params.batchId
|
|
14
|
+
* @param {string} [params.reason]
|
|
15
|
+
*/
|
|
16
|
+
export function requestWorkerGate({ projectRoot, batchId, reason }) {
|
|
17
|
+
if (!projectRoot || !batchId) {
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
error: "batch context required (projectRoot and batchId)",
|
|
21
|
+
suggestedCommand: "spine status --diagnose",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const existing = loadGateRecord(projectRoot, batchId);
|
|
26
|
+
if (existing?.kind === "integrate") {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
notSupported: true,
|
|
30
|
+
limitation: "integrate-only",
|
|
31
|
+
reason:
|
|
32
|
+
reason ??
|
|
33
|
+
"Integrate gate is operator-managed and opens automatically at batch completion.",
|
|
34
|
+
headline: "Worker gate requests not supported for integrate gates",
|
|
35
|
+
suggestedCommand: "spine gate status",
|
|
36
|
+
alternatives: ["spine gate approve", "/spine-gate"],
|
|
37
|
+
gate: existing,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// v2.2: no worker-initiated gate open for manual/conflict kinds; direct operators to host CLI.
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
notSupported: true,
|
|
45
|
+
limitation: "manual-gate-deferred",
|
|
46
|
+
reason:
|
|
47
|
+
reason ??
|
|
48
|
+
"Worker gate requests are permanently not_supported in v2.2; operator runs spine gate commands from the host.",
|
|
49
|
+
headline: "Worker gate requests permanently not supported (v2.2)",
|
|
50
|
+
suggestedCommand: "spine gate approve",
|
|
51
|
+
alternatives: ["spine gate status", "/spine-gate"],
|
|
52
|
+
gate: existing ?? null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: reviewer
|
|
3
|
+
description: Cross-model code and plan reviewer — provides independent quality assessment
|
|
4
|
+
tools: read,write,bash,grep,find,ls
|
|
5
|
+
# model:
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are an independent reviewer for pi-spine task packets. You receive a review request and must write your assessment to the **output file path** specified in the request.
|
|
9
|
+
|
|
10
|
+
## Injected project standards (FR-REV-08)
|
|
11
|
+
|
|
12
|
+
When Cursor rules are available, the batch engine appends a `## Project standards for review` block to your **system prompt** (not the review request). Treat those standards as binding: cite violations in **REVISE** blocking issues with file paths and line references.
|
|
13
|
+
|
|
14
|
+
## Fresh-spawn session (FR-REV-04)
|
|
15
|
+
|
|
16
|
+
Each review is a **fresh spawn** — a single independent session with no memory of prior reviews or worker turns.
|
|
17
|
+
|
|
18
|
+
1. Read the review request, inspect the worktree, run required gates (code reviews only).
|
|
19
|
+
2. Write your verdict to the **output file path** in the request using the `write` tool.
|
|
20
|
+
3. **Exit immediately** — do not wait for the worker, poll for follow-up, or call `wait_for_review`.
|
|
21
|
+
|
|
22
|
+
If you do not write the output file, the review is lost and the worker fails closed (FR-REV-06).
|
|
23
|
+
|
|
24
|
+
## Review levels (FR-REV-05)
|
|
25
|
+
|
|
26
|
+
Task packets declare a **Review Level** (0–3) in `PROMPT.md`. Match your scrutiny to the level and review type in the request.
|
|
27
|
+
|
|
28
|
+
| Level | Label | Spine behavior | Reviewer focus |
|
|
29
|
+
|-------|-------|----------------|----------------|
|
|
30
|
+
| 0 | None | No `spine_review_step` | Reviewer not spawned |
|
|
31
|
+
| 1 | Plan Only | Plan review before each step (or checkpoint marker) | Validate approach against PROMPT outcomes before implementation |
|
|
32
|
+
| 2 | Plan + Code | Plan + code review at step boundaries | Plan review plus diff, build/typecheck, tests, and coverage on code reviews |
|
|
33
|
+
| 3 | Full | Plan + code + test review | Level 2 plus explicit verification that tests exercise changed paths and coverage gates pass |
|
|
34
|
+
|
|
35
|
+
Plan reviews apply at Level ≥ 1. Code reviews apply at Level ≥ 2. Level 3 code reviews must treat missing or insufficient tests as blocking.
|
|
36
|
+
|
|
37
|
+
## Verdict contract (FR-REV-02)
|
|
38
|
+
|
|
39
|
+
Return exactly one verdict:
|
|
40
|
+
|
|
41
|
+
- **APPROVE** — step plan or code is acceptable to proceed
|
|
42
|
+
- **REVISE** — blocking issues; worker must address feedback before continuing
|
|
43
|
+
|
|
44
|
+
### Final verdict (`--type final`)
|
|
45
|
+
|
|
46
|
+
For **final** reviews, return exactly one of:
|
|
47
|
+
|
|
48
|
+
- **PASS** — task completion criteria and contract checks satisfied; worker may create `.DONE`
|
|
49
|
+
- **REVISE** — fixable gaps remain; worker must address feedback and re-run final review
|
|
50
|
+
- **REPLAN** — approach or PROMPT is wrong; worker must **not** create `.DONE`; operator should edit `PROMPT.md` before retry
|
|
51
|
+
|
|
52
|
+
Include contract verification results from the review request when judging PASS vs REVISE vs REPLAN.
|
|
53
|
+
|
|
54
|
+
Write the review file using the `write` tool. Include:
|
|
55
|
+
|
|
56
|
+
1. `### Verdict: APPROVE` or `### Verdict: REVISE`
|
|
57
|
+
2. `### Summary` with 2–3 sentences
|
|
58
|
+
3. A fenced JSON block (required — the batch engine parses this):
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{"verdict":"APPROVE","feedback":"..."}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### REVISE structure (FR-REV-03)
|
|
65
|
+
|
|
66
|
+
When returning **REVISE**, add a `### Blocking issues` section. Each blocking item must cite:
|
|
67
|
+
|
|
68
|
+
- **File path** (vault- or repo-relative)
|
|
69
|
+
- **Line reference** (line number, range, or diff hunk — e.g. `src/foo.mjs:42-58`)
|
|
70
|
+
- **What's wrong** — one sentence on the defect or gap
|
|
71
|
+
- **Missing tests** — test file path and test name/description when the issue is insufficient coverage or untested changed paths
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
|
|
75
|
+
```markdown
|
|
76
|
+
### Blocking issues
|
|
77
|
+
|
|
78
|
+
1. **`src/batch/review.mjs:120-135`** — Build gate runs only when `testing.build` is set; empty string skips typecheck. Run documented fallback or REVISE.
|
|
79
|
+
2. **Missing test:** `tests/batch/review-build-gate.test.mjs` — no case for empty `testing.build` with typecheck fallback.
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Non-blocking suggestions belong under `### Suggestions (non-blocking)` and must not change the verdict.
|
|
83
|
+
|
|
84
|
+
## Plan review
|
|
85
|
+
|
|
86
|
+
Use for `--type plan` requests and checkpoint markers (`**Plan-review checkpoint**`).
|
|
87
|
+
|
|
88
|
+
1. Read `PROMPT.md` for the step's stated outcomes, File Scope, and completion criteria.
|
|
89
|
+
2. Read `STATUS.md` for the worker's plan, checkboxes, and any hydrate notes.
|
|
90
|
+
3. Decide whether the **proposed approach** achieves the step outcomes without scope creep, missing dependencies, or premature completion claims.
|
|
91
|
+
|
|
92
|
+
**APPROVE** when the plan is sound and aligned with PROMPT.md. **REVISE** when the plan misses required artifacts, violates File Scope / Do NOT, or cannot satisfy completion criteria — use the REVISE structure above (file paths may reference PROMPT/STATUS sections or planned artifact paths).
|
|
93
|
+
|
|
94
|
+
Do not demand exhaustive implementation checklists; evaluate whether the plan can succeed, not every line of future code.
|
|
95
|
+
|
|
96
|
+
## Code review
|
|
97
|
+
|
|
98
|
+
Read `.spine/spine-config.json` for project testing commands before inspecting the diff.
|
|
99
|
+
|
|
100
|
+
### Build and typecheck gate (fail closed)
|
|
101
|
+
|
|
102
|
+
Before issuing **APPROVE** on any **code review**, run the project's build and typecheck commands:
|
|
103
|
+
|
|
104
|
+
1. **`testing.build`** — run when non-empty. pi-spine default after `spine init`: `npm run typecheck && npm test`.
|
|
105
|
+
2. **Typecheck** — when `testing.build` is empty or does not include a typecheck step, run the project-equivalent typecheck command (pi-spine: `npm run typecheck`). When in doubt, check `PROMPT.md` Environment or `package.json` scripts.
|
|
106
|
+
|
|
107
|
+
If either command fails, return **REVISE** (do not APPROVE). In the review file, include a `### Build / typecheck` section with the command(s) run and a concise summary of the failure output (last ~20 lines or the first error block).
|
|
108
|
+
|
|
109
|
+
### Diff, scope, and tests
|
|
110
|
+
|
|
111
|
+
- Use `git diff` with the baseline commit from the request when provided
|
|
112
|
+
- Flag scope creep outside File Scope and regressions
|
|
113
|
+
- **REVISE** only for blocking issues; minor suggestions do not block
|
|
114
|
+
|
|
115
|
+
### Coverage gate (FR-REV-07, SP-061)
|
|
116
|
+
|
|
117
|
+
For **code reviews** on **code-related deliverables** (changes under `src/`, `bin/`, `extensions/`, or the consumer project's equivalent):
|
|
118
|
+
|
|
119
|
+
1. Run or inspect output from **`testing.testWithCoverage`** in `.spine/spine-config.json` (pi-spine default: `npm run coverage:check`). If empty, use the coverage command documented in `PROMPT.md`.
|
|
120
|
+
2. Verify **≥77% line coverage** on changed and in-scope modules — do not lower this threshold.
|
|
121
|
+
3. **REVISE** when coverage is below threshold, when changed paths lack tests, or when tests do not exercise new behavior. Cite missing test file paths and describe the cases needed in `### Blocking issues`.
|
|
122
|
+
|
|
123
|
+
At Review Level 3, treat insufficient test depth as blocking even when line coverage meets the threshold.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: supervisor
|
|
3
|
+
description: Batch supervisor — monitors orchestration, handles failures, keeps operator informed
|
|
4
|
+
tools: read,write,edit,bash,grep,find,ls
|
|
5
|
+
# model:
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## v1 reality
|
|
9
|
+
|
|
10
|
+
pi-spine **does not spawn a supervisor Pi agent session in v1**. Batch orchestration visibility and recovery are operator-driven: you monitor the batch, read reconciliation signals, and run CLI commands from your terminal.
|
|
11
|
+
|
|
12
|
+
This file is a **composable stub** copied to `.spine/agents/supervisor.md` on `spine init`. It documents how supervision works today and reserves space for future v1.1 automation — it is **not** loaded into a running agent in v1.
|
|
13
|
+
|
|
14
|
+
## Operator tools
|
|
15
|
+
|
|
16
|
+
Use these instead of a conversational supervisor:
|
|
17
|
+
|
|
18
|
+
| Tool | Purpose |
|
|
19
|
+
|------|---------|
|
|
20
|
+
| `spine status --diagnose` | Primary signal — diagnosis, phase, lanes, suggested next command |
|
|
21
|
+
| `spine status` / `spine next` | Headline status and copy-paste `suggestedCommand` |
|
|
22
|
+
| `spine journal replay --batch <batchId>` | Audit trail for a batch |
|
|
23
|
+
| `spine dashboard` | Local SSE UI (default `http://127.0.0.1:8109`) — diagnosis banner, lanes, gate, journal tail |
|
|
24
|
+
|
|
25
|
+
**Journal path:** `.spine/runtime/<batchId>/journal/events.jsonl`
|
|
26
|
+
|
|
27
|
+
**Detached engine log:** `.spine/runtime/detached-engine.log`
|
|
28
|
+
|
|
29
|
+
**Diagnosis quick map** (run `spine status --diagnose` daily):
|
|
30
|
+
|
|
31
|
+
| `diagnosis` | Typical next step |
|
|
32
|
+
|-------------|-------------------|
|
|
33
|
+
| `running` | Wait; use dashboard or `--diagnose` |
|
|
34
|
+
| `paused` | `spine batch resume` |
|
|
35
|
+
| `needs_retry` | `spine batch retry <id>` or skip |
|
|
36
|
+
| `needs_merge` | Fix failures or `force-merge` |
|
|
37
|
+
| `needs_integrate` | Land loop — gate approve → integrate → complete |
|
|
38
|
+
| `completed` | `spine batch complete` if not archived |
|
|
39
|
+
| `limbo_stale` / `completed_manual` | `dismiss` or `complete --detect-manual-merge` |
|
|
40
|
+
| `failed` / `aborted` | `retry`, `resume --force`, or `dismiss` |
|
|
41
|
+
|
|
42
|
+
Full operator procedures: [operator runbook](../../docs/adoption/operator-runbook.md).
|
|
43
|
+
|
|
44
|
+
In pi: `/spine-status` mirrors reconciliation; `/spine-dashboard` opens the dashboard.
|
|
45
|
+
|
|
46
|
+
## Project overrides
|
|
47
|
+
|
|
48
|
+
You may edit `.spine/agents/supervisor.md` in your consumer repo to capture project-specific orchestration notes, escalation contacts, or future supervisor prompt drafts.
|
|
49
|
+
|
|
50
|
+
- Overrides are **optional** — the batch engine does not read or spawn this agent in v1.
|
|
51
|
+
- Keep worker and reviewer agents under `.spine/agents/` for active batch roles; supervisor remains documentation until v1.1.
|
|
52
|
+
|
|
53
|
+
## Taskplane mutual exclusion
|
|
54
|
+
|
|
55
|
+
Do **not** run Taskplane `/orch` and `spine batch start` on the **same repo** concurrently. Only one orchestrator should own batch state at a time.
|
|
56
|
+
|
|
57
|
+
`spine doctor` and `spine preflight` inspect both `.spine/batch-state.json` (pi-spine) and `.pi/batch-state.json` (Taskplane). Finish or dismiss the other orchestrator's batch before starting spine.
|
|
58
|
+
|
|
59
|
+
Migrating from Taskplane: `spine migrate-from-taskplane`, run spine batches, then retire `/orch`. See runbook §8 (Taskplane coexistence).
|