pi-spine 2.27.1 → 2.28.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/bin/spine-batch.mjs +46 -4
- package/bin/spine-tasks.mjs +1 -0
- package/bin/spine-worker-runner.mjs +16 -3
- package/package.json +1 -1
- package/skills/create-spine-tasks/references/prompt-template.md +5 -0
- package/skills/spine-release-operator/SKILL.md +14 -2
- package/src/batch/contract-task-start.mjs +23 -1
- package/src/batch/diagnosis-handoff-packet.mjs +18 -0
- package/src/batch/engine-lanes/quota-fallback-run.mjs +11 -0
- package/src/batch/engine-lanes/quota-fallback-state.mjs +155 -8
- package/src/batch/engine-lanes/review-code.mjs +20 -0
- package/src/batch/engine-lanes/review-final.mjs +10 -2
- package/src/batch/engine-lanes/review-poll.mjs +33 -0
- package/src/batch/engine-lanes/task-agent-profile.mjs +324 -0
- package/src/batch/engine-lanes.mjs +18 -17
- package/src/batch/journal.mjs +5 -3
- package/src/batch/metrics-rollup.mjs +98 -4
- package/src/batch/metrics.mjs +134 -9
- package/src/batch/provider-quota.mjs +155 -6
- package/src/batch/quota-fallback.mjs +87 -6
- package/src/batch/resume-lane-reviews.mjs +11 -10
- package/src/batch/retry-profile.mjs +77 -0
- package/src/batch/retry.mjs +32 -1
- package/src/batch/review-step-run.mjs +4 -0
- package/src/batch/review-step.mjs +1 -0
- package/src/batch/worker-heartbeat.mjs +10 -2
- package/src/batch/worker-host.mjs +1 -1
- package/src/batch/worker-prompt.mjs +4 -5
- package/src/cli/deps.mjs +3 -2
- package/src/config/agent-model-resolve.mjs +144 -8
- package/src/config/model-family.mjs +60 -0
- package/src/config/preflight/discovery.mjs +1 -0
- package/src/config/settings-fields.mjs +6 -0
- package/src/config/spine-config-schema.mjs +49 -0
- package/src/doctor/agent-model-inherit.mjs +78 -1
- package/src/doctor/run-doctor-checks.mjs +4 -1
- package/src/metrics/quota-cli.mjs +16 -0
- package/src/metrics/quota-probes.mjs +228 -31
- package/src/metrics/quota-snapshot.mjs +21 -2
- package/src/planner/graph.mjs +7 -5
- package/src/planner/pending.mjs +2 -2
- package/src/planner/scope.mjs +3 -3
- package/src/tasks/packet/parse-prompt.mjs +47 -0
- package/src/tasks/packet/validate-prompt.mjs +156 -1
- package/templates/agents/reviewer.md +3 -1
- package/templates/agents/worker.md +15 -19
|
@@ -13,17 +13,164 @@ import {
|
|
|
13
13
|
} from "./parse-prompt.mjs";
|
|
14
14
|
import { validateContract } from "./validate-contract.mjs";
|
|
15
15
|
import { collectExecuteReviewLevelWarnings } from "../validate-contract-warn.mjs";
|
|
16
|
+
import { resolveEffectiveReviewer } from "../../config/agent-model-resolve.mjs";
|
|
17
|
+
import { isSameModelFamily } from "../../config/model-family.mjs";
|
|
18
|
+
import { PROMPT_PROFILE_NAME_RE } from "./parse-prompt.mjs";
|
|
16
19
|
import { parseReviewLevel } from "../../batch/review-shared.mjs";
|
|
17
20
|
|
|
18
21
|
/** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
|
|
19
22
|
export const STALE_FILE_SCOPE_AMENDMENT_HINT =
|
|
20
23
|
"Amend PROMPT.md ## Contract before batch start (e.g. point fileScopeMustChange at delivery artifacts such as STATUS.md, or add an ## Amendments note documenting pre-landed implementation)";
|
|
21
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @param {unknown} value
|
|
27
|
+
* @returns {value is Record<string, any>}
|
|
28
|
+
*/
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Per-type reviewer model pin (type-specific wins over top-level; `inherit` is no pin).
|
|
35
|
+
*
|
|
36
|
+
* @param {Record<string, any>} reviewer
|
|
37
|
+
* @param {"plan"|"code"|"final"} reviewType
|
|
38
|
+
* @returns {string|null}
|
|
39
|
+
*/
|
|
40
|
+
function pickReviewerModel(reviewer, reviewType) {
|
|
41
|
+
for (const candidate of [reviewer[reviewType]?.model, reviewer.model]) {
|
|
42
|
+
if (typeof candidate === "string" && candidate !== "" && candidate !== "inherit") {
|
|
43
|
+
return candidate;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Warnings for per-task agent fields on `**Type:** execute` tasks (no LLM worker/reviewer).
|
|
51
|
+
*
|
|
52
|
+
* @param {ReturnType<typeof validatePromptStructure>["prompt"]} prompt
|
|
53
|
+
* @returns {string[]}
|
|
54
|
+
*/
|
|
55
|
+
function collectExecuteAgentFieldWarnings(prompt) {
|
|
56
|
+
if (prompt.type !== "execute") return [];
|
|
57
|
+
/** @type {string[]} */
|
|
58
|
+
const warnings = [];
|
|
59
|
+
for (const [label, value] of [
|
|
60
|
+
["Profile", prompt.profile],
|
|
61
|
+
["Thinking", prompt.thinking],
|
|
62
|
+
["Reviewer Profile", prompt.reviewerProfile],
|
|
63
|
+
]) {
|
|
64
|
+
if (value !== null) {
|
|
65
|
+
warnings.push(
|
|
66
|
+
`**${label}:** is ignored on a **Type:** execute task (no LLM worker or reviewer to configure)`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return warnings;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Config-aware checks of `**Profile:**` / `**Reviewer Profile:**` against `agents` (SP-833 / #355).
|
|
75
|
+
* Skipped by callers when no `agents` option is supplied (planner, queue).
|
|
76
|
+
*
|
|
77
|
+
* @param {ReturnType<typeof validatePromptStructure>["prompt"]} prompt
|
|
78
|
+
* @param {Record<string, any>} agents Effective `config.agents`
|
|
79
|
+
* @returns {{ errors: string[], warnings: string[] }}
|
|
80
|
+
*/
|
|
81
|
+
function collectAgentProfileFindings(prompt, agents) {
|
|
82
|
+
/** @type {string[]} */
|
|
83
|
+
const errors = [];
|
|
84
|
+
/** @type {string[]} */
|
|
85
|
+
const warnings = [];
|
|
86
|
+
if (prompt.type === "execute") return { errors, warnings };
|
|
87
|
+
if (prompt.profile === null && prompt.reviewerProfile === null) return { errors, warnings };
|
|
88
|
+
|
|
89
|
+
const profiles = isRecord(agents.profiles) ? agents.profiles : {};
|
|
90
|
+
const definedNames = Object.keys(profiles);
|
|
91
|
+
const known = (name) => PROMPT_PROFILE_NAME_RE.test(name) && Object.hasOwn(profiles, name);
|
|
92
|
+
const hint = definedNames.length > 0 ? ` (defined: ${definedNames.join(", ")})` : " (none defined)";
|
|
93
|
+
|
|
94
|
+
const wellFormed = (name) => name === null || PROMPT_PROFILE_NAME_RE.test(name);
|
|
95
|
+
let resolvable = true;
|
|
96
|
+
if (prompt.profile !== null && wellFormed(prompt.profile) && !known(prompt.profile)) {
|
|
97
|
+
errors.push(`**Profile:** "${prompt.profile}" is not defined in agents.profiles${hint}`);
|
|
98
|
+
resolvable = false;
|
|
99
|
+
}
|
|
100
|
+
if (prompt.reviewerProfile !== null && wellFormed(prompt.reviewerProfile)) {
|
|
101
|
+
if (!known(prompt.reviewerProfile)) {
|
|
102
|
+
errors.push(
|
|
103
|
+
`**Reviewer Profile:** "${prompt.reviewerProfile}" is not defined in agents.profiles${hint}`,
|
|
104
|
+
);
|
|
105
|
+
resolvable = false;
|
|
106
|
+
} else if (!isRecord(profiles[prompt.reviewerProfile]?.reviewer)) {
|
|
107
|
+
warnings.push(
|
|
108
|
+
`**Reviewer Profile:** "${prompt.reviewerProfile}" has no reviewer block; it falls back to the next reviewer precedence level`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Malformed names already fail structural validation; unknown names already errored above.
|
|
114
|
+
if (!resolvable || !wellFormed(prompt.profile) || !wellFormed(prompt.reviewerProfile)) {
|
|
115
|
+
return { errors, warnings };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const workerModel =
|
|
119
|
+
(prompt.profile !== null ? profiles[prompt.profile]?.worker?.model : null) ??
|
|
120
|
+
agents.worker?.model ??
|
|
121
|
+
null;
|
|
122
|
+
/** @type {Array<"plan"|"code"|"final">} */
|
|
123
|
+
const reviewTypes = [];
|
|
124
|
+
/** @type {Set<string>} */
|
|
125
|
+
const models = new Set();
|
|
126
|
+
let subject = "effective reviewer";
|
|
127
|
+
const reviewerBlock =
|
|
128
|
+
prompt.reviewerProfile !== null ? profiles[prompt.reviewerProfile]?.reviewer : null;
|
|
129
|
+
if (prompt.reviewerProfile !== null && isRecord(reviewerBlock)) {
|
|
130
|
+
// The named profile itself must be cross-family; fallback candidates do not rescue it.
|
|
131
|
+
subject = `**Reviewer Profile:** "${prompt.reviewerProfile}"`;
|
|
132
|
+
for (const reviewType of ["plan", "code", "final"]) {
|
|
133
|
+
const model = pickReviewerModel(reviewerBlock, reviewType);
|
|
134
|
+
if (isSameModelFamily(model, workerModel)) {
|
|
135
|
+
reviewTypes.push(reviewType);
|
|
136
|
+
models.add(model);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
const resolved = resolveEffectiveReviewer(
|
|
141
|
+
{ agents },
|
|
142
|
+
{
|
|
143
|
+
promptReviewerProfile: prompt.reviewerProfile,
|
|
144
|
+
workerProfile: prompt.profile,
|
|
145
|
+
workerModel,
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
for (const entry of resolved.blocked) {
|
|
149
|
+
if (entry.reason === "same_model_family") {
|
|
150
|
+
reviewTypes.push(entry.reviewType);
|
|
151
|
+
models.add(resolved[entry.reviewType].model);
|
|
152
|
+
} else if (entry.reason === "unknown_reviewer_profile") {
|
|
153
|
+
errors.push(
|
|
154
|
+
"Reviewer profile resolution failed: a referenced reviewerProfile is not defined in agents.profiles",
|
|
155
|
+
);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (reviewTypes.length > 0) {
|
|
161
|
+
errors.push(
|
|
162
|
+
`${subject} uses model "${[...models].join(", ")}" in the same model family as the worker model "${workerModel}" (${reviewTypes.join(", ")} review); pick a cross-family reviewer`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return { errors, warnings };
|
|
166
|
+
}
|
|
167
|
+
|
|
22
168
|
/**
|
|
23
169
|
* Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
|
|
24
170
|
*
|
|
25
171
|
* @param {string} markdown PROMPT.md contents
|
|
26
|
-
* @param {{ mode?: string, legacyTaskIdPrefixes?: string[], contract?: { mode?: string, legacyTaskIdPrefixes?: string[] } }} [options]
|
|
172
|
+
* @param {{ mode?: string, legacyTaskIdPrefixes?: string[], contract?: { mode?: string, legacyTaskIdPrefixes?: string[] }, agents?: Record<string, any> }} [options]
|
|
173
|
+
* `agents` (effective `config.agents`) enables profile-name and reviewer-family checks (SP-833).
|
|
27
174
|
* @returns {{ ok: boolean, errors: string[], warnings: string[], prompt: ReturnType<typeof parsePrompt>, contract: ReturnType<typeof parseContract> }}
|
|
28
175
|
*/
|
|
29
176
|
export function validatePrompt(markdown, options = {}) {
|
|
@@ -56,6 +203,14 @@ export function validatePrompt(markdown, options = {}) {
|
|
|
56
203
|
}),
|
|
57
204
|
);
|
|
58
205
|
|
|
206
|
+
warnings.push(...collectExecuteAgentFieldWarnings(structure.prompt));
|
|
207
|
+
|
|
208
|
+
if (isRecord(options.agents)) {
|
|
209
|
+
const findings = collectAgentProfileFindings(structure.prompt, options.agents);
|
|
210
|
+
errors.push(...findings.errors);
|
|
211
|
+
warnings.push(...findings.warnings);
|
|
212
|
+
}
|
|
213
|
+
|
|
59
214
|
return {
|
|
60
215
|
ok: errors.length === 0,
|
|
61
216
|
errors,
|
|
@@ -53,7 +53,7 @@ Include contract verification results from the review request when judging PASS
|
|
|
53
53
|
|
|
54
54
|
Write the review file using the `write` tool. Include:
|
|
55
55
|
|
|
56
|
-
1. `### Verdict: APPROVE` or `### Verdict: REVISE`
|
|
56
|
+
1. `### Verdict: APPROVE` or `### Verdict: REVISE` (plan/code); `### Verdict: PASS`, `### Verdict: REVISE`, or `### Verdict: REPLAN` (final)
|
|
57
57
|
2. `### Summary` with 2–3 sentences
|
|
58
58
|
3. A fenced JSON block (required — the batch engine parses this):
|
|
59
59
|
|
|
@@ -61,6 +61,8 @@ Write the review file using the `write` tool. Include:
|
|
|
61
61
|
{"verdict":"APPROVE","feedback":"..."}
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
Final reviews use `{"verdict":"PASS","feedback":"..."}` (or `REVISE` / `REPLAN`). The engine rejects `APPROVE` on a final review.
|
|
65
|
+
|
|
64
66
|
### REVISE structure (FR-REV-03)
|
|
65
67
|
|
|
66
68
|
When returning **REVISE**, add a `### Blocking issues` section. Each blocking item must cite:
|
|
@@ -53,7 +53,7 @@ Spine documents honest `.DONE` + lane auto-commit behavior below — `.DONE` mea
|
|
|
53
53
|
|
|
54
54
|
| Tool | When to use |
|
|
55
55
|
|------|-------------|
|
|
56
|
-
| `spine_review_step` |
|
|
56
|
+
| `spine_review_step` | Engine-run in real-pi batches; in-worker calls are skipped (do not call it from the worker) |
|
|
57
57
|
| `spine_report_progress` | After completing a step — emits `task.step_completed` for stall detection |
|
|
58
58
|
| `spine_request_gate` | Rare — request operator attention (v1.1 returns `not_supported`; integrate gates are automatic) |
|
|
59
59
|
|
|
@@ -66,40 +66,36 @@ Task packets declare a **Review Level** (0–3) in `PROMPT.md`. Read it at task
|
|
|
66
66
|
| Level | Label | When to call `spine_review_step` |
|
|
67
67
|
|-------|-------|----------------------------------|
|
|
68
68
|
| 0 | None | Never — reviewer is not spawned |
|
|
69
|
-
| 1 | Plan Only |
|
|
70
|
-
| 2 | Plan + Code |
|
|
71
|
-
| 3 | Full |
|
|
69
|
+
| 1 | Plan Only | Never from the worker — the engine runs plan review (and final review) after `.DONE` |
|
|
70
|
+
| 2 | Plan + Code | Never from the worker — the engine runs plan + code review after `.DONE` |
|
|
71
|
+
| 3 | Full | Never from the worker — the engine runs plan, code, and final review after `.DONE` |
|
|
72
72
|
|
|
73
|
-
**FR-WORK-07:** when Review Level ≥ 1,
|
|
73
|
+
**FR-WORK-07:** when Review Level ≥ 1, plan, code (Level ≥ 2), and final reviews run in the **batch engine** after you create `.DONE` (SP-194/SP-195/SP-695). **Do not** call `spine_review_step` / `spine review step` from inside the worker — in real-pi batches every in-worker call is skipped.
|
|
74
74
|
|
|
75
|
-
Checkpoint markers in PROMPT (`**Plan-review checkpoint**`, `**Code review checkpoint**`)
|
|
75
|
+
Checkpoint markers in PROMPT (`**Plan-review checkpoint**`, `**Code review checkpoint**`) tell the engine which step to review; they are not instructions to call the review tool yourself.
|
|
76
76
|
|
|
77
|
-
##
|
|
77
|
+
## Order of operations
|
|
78
78
|
|
|
79
|
-
For tasks at **Review Level ≥
|
|
79
|
+
For tasks at **Review Level ≥ 1**, complete **each step** in this strict order:
|
|
80
80
|
|
|
81
81
|
1. **Finish step work** — all outcomes for this step in PROMPT.
|
|
82
82
|
2. **Update outcome checkboxes** in `STATUS.md` as each outcome completes (immediate checkbox rule).
|
|
83
83
|
3. **Commit** step work on the lane branch: `feat(TASK-ID): complete Step N — {step title}`
|
|
84
|
-
4. **
|
|
85
|
-
5. **
|
|
84
|
+
4. **Do not request review from the worker** — the engine reviews after `.DONE`.
|
|
85
|
+
5. **Mark the step complete** — set the step **Status** to complete in `STATUS.md`, advance `Current Step`, then call **`spine_report_progress`**.
|
|
86
86
|
|
|
87
|
-
**
|
|
87
|
+
**On REVISE (FR-REV-03):** the engine re-runs the worker with feedback in `{taskFolder}/.reviews/`; address it, re-commit, and recreate `.DONE`.
|
|
88
88
|
|
|
89
|
-
**
|
|
90
|
-
|
|
91
|
-
**On review spawn failure (FR-REV-06):** exit with a **non-zero** status — fail closed. Do not mark the step complete, advance `Current Step`, or create `.DONE`.
|
|
92
|
-
|
|
93
|
-
For **Review Level 0**, skip `spine_review_step`. For **Level 1**, follow PROMPT plan-review markers; still commit at step boundaries and mark step **Status** complete only after plan review **APPROVE** when a review was required for that step.
|
|
89
|
+
For **Review Level 0**, no reviewer runs. For **Level 1+**, still commit at step boundaries; reviews happen on the engine after `.DONE`.
|
|
94
90
|
|
|
95
91
|
## Checkpoint discipline
|
|
96
92
|
|
|
97
93
|
1. Update `STATUS.md` **before starting** each step (`Current Step`, step status → in progress).
|
|
98
94
|
2. Mark **outcome** checkboxes **immediately** when each outcome completes (see Checkbox discipline).
|
|
99
95
|
3. **Commit** at step boundaries when you change files: `feat(TASK-ID): complete Step N — {step title}`
|
|
100
|
-
4.
|
|
101
|
-
5. On **REVISE
|
|
102
|
-
6. Call **`spine_report_progress`** after the step is marked complete
|
|
96
|
+
4. Follow the **order of operations** above (finish → checkboxes → commit → mark step Status complete). Do **not** call `spine_review_step` from the worker; the engine reviews after `.DONE`.
|
|
97
|
+
5. On **REVISE** feedback from a resumed run, fix it before recreating `.DONE`.
|
|
98
|
+
6. Call **`spine_report_progress`** after the step is marked complete.
|
|
103
99
|
7. Run **`./scripts/worker-verify.sh`** (or `npm run typecheck && SPINE_WORKER_STUB=1 npm test`) before creating `.DONE`.
|
|
104
100
|
8. Create `.DONE` only when every completion criterion in PROMPT is satisfied (tests pass, STATUS current). The **engine** runs contract verification, code review (RL ≥ 2), and final review (RL ≥ 1) **after** `.DONE` — do not spawn those reviewers yourself.
|
|
105
101
|
9. **After `.DONE`:** exit immediately. No further tool calls, commits, or reviewer spawns (prevents SP-190-class wedges).
|