pi-spine 1.0.2 → 1.2.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.
Files changed (129) hide show
  1. package/README.md +61 -489
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +162 -51
  4. package/bin/spine-cli/batch.mjs +3 -3
  5. package/bin/spine-cli/lane-logs.mjs +24 -0
  6. package/bin/spine-cli/scenarios.mjs +298 -0
  7. package/bin/spine-cli/wait.mjs +30 -0
  8. package/bin/spine-cli/watch.mjs +27 -0
  9. package/bin/spine-config.mjs +1 -212
  10. package/bin/spine-doctor.mjs +2 -418
  11. package/bin/spine-init.mjs +1 -398
  12. package/bin/spine-issue.mjs +196 -0
  13. package/bin/spine-journal.mjs +1 -0
  14. package/bin/spine-preflight.mjs +1 -700
  15. package/bin/spine-review-step.mjs +6 -4
  16. package/bin/spine-run.mjs +30 -0
  17. package/bin/spine-status.mjs +19 -1
  18. package/bin/spine-tasks.mjs +112 -13
  19. package/bin/spine-worker-runner.mjs +24 -14
  20. package/bin/spine.mjs +52 -2
  21. package/extensions/spine/worker-tools.ts +14 -12
  22. package/package.json +5 -2
  23. package/skills/create-spine-tasks/SKILL.md +135 -6
  24. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  25. package/skills/create-spine-tasks/references/contract-template.md +19 -0
  26. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  27. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  28. package/src/batch/abort.mjs +3 -12
  29. package/src/batch/agent-session-worker.mjs +45 -5
  30. package/src/batch/attached-engine-handoff.mjs +188 -0
  31. package/src/batch/attached-runner.mjs +312 -0
  32. package/src/batch/contract-prelanded.mjs +180 -0
  33. package/src/batch/contract-verify.mjs +140 -2
  34. package/src/batch/detached-start.mjs +105 -7
  35. package/src/batch/diagnosis-alternatives.mjs +46 -0
  36. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  37. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  38. package/src/batch/diagnosis-stub.mjs +109 -0
  39. package/src/batch/diagnosis-task-done.mjs +110 -0
  40. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  41. package/src/batch/diagnosis.mjs +174 -62
  42. package/src/batch/engine-lanes/merge.mjs +168 -77
  43. package/src/batch/engine-lanes/queue.mjs +4 -1
  44. package/src/batch/engine-lanes/review.mjs +32 -74
  45. package/src/batch/engine-lanes/watch.mjs +29 -0
  46. package/src/batch/engine-lanes.mjs +1 -0
  47. package/src/batch/engine-scope.mjs +42 -5
  48. package/src/batch/engine.mjs +115 -68
  49. package/src/batch/evidence.mjs +81 -17
  50. package/src/batch/gate.mjs +46 -17
  51. package/src/batch/git-helpers.mjs +96 -0
  52. package/src/batch/heartbeat.mjs +73 -7
  53. package/src/batch/integrate.mjs +3 -5
  54. package/src/batch/journal.mjs +25 -0
  55. package/src/batch/lane-commit.mjs +90 -5
  56. package/src/batch/lifecycle.mjs +131 -4
  57. package/src/batch/macro-phase.mjs +226 -0
  58. package/src/batch/merge/adoption-doc-merge.mjs +243 -0
  59. package/src/batch/merge/wave-merge-state.mjs +108 -0
  60. package/src/batch/metrics.mjs +74 -5
  61. package/src/batch/orphan-detect.mjs +74 -0
  62. package/src/batch/pause.mjs +223 -0
  63. package/src/batch/post-merge-limbo.mjs +345 -17
  64. package/src/batch/reconcile.mjs +473 -50
  65. package/src/batch/resume-common.mjs +6 -2
  66. package/src/batch/resume-engine.mjs +58 -1
  67. package/src/batch/resume-lane-reviews.mjs +16 -0
  68. package/src/batch/resume-multi-lanes.mjs +56 -1
  69. package/src/batch/resume-multi-validate.mjs +148 -8
  70. package/src/batch/resume-multi.mjs +45 -44
  71. package/src/batch/resume.mjs +64 -47
  72. package/src/batch/retry.mjs +56 -5
  73. package/src/batch/review-shared.mjs +196 -0
  74. package/src/batch/review-spawn.mjs +326 -0
  75. package/src/batch/review.mjs +178 -212
  76. package/src/batch/rules-manifest-drift.mjs +157 -0
  77. package/src/batch/salvage.mjs +2 -1
  78. package/src/batch/sequence.mjs +454 -0
  79. package/src/batch/state.mjs +18 -3
  80. package/src/batch/status-json.mjs +67 -0
  81. package/src/batch/task-stall-budget.mjs +94 -10
  82. package/src/batch/worker-host.mjs +185 -37
  83. package/src/batch/worker-output.mjs +196 -3
  84. package/src/batch/worktree.mjs +10 -0
  85. package/src/cli/handoff.mjs +1 -1
  86. package/src/cli/issue-draft.mjs +180 -0
  87. package/src/cli/journal-follow.mjs +239 -0
  88. package/src/cli/lane-logs.mjs +291 -0
  89. package/src/cli/rules.mjs +1 -1
  90. package/src/cli/sequence.mjs +108 -0
  91. package/src/cli/settings-set.mjs +3 -22
  92. package/src/cli/settings-slash.mjs +27 -5
  93. package/src/cli/wait.mjs +187 -0
  94. package/src/cli/watch.mjs +160 -0
  95. package/src/config/agent-model-resolve.mjs +48 -0
  96. package/src/config/cursor-rules/discover.mjs +3 -21
  97. package/src/config/defaults.mjs +7 -1
  98. package/src/config/settings-fields.mjs +48 -0
  99. package/src/config/spine-config-load.mjs +221 -0
  100. package/src/config/spine-init-constants.mjs +424 -0
  101. package/src/config/spine-preflight-lib.mjs +1180 -0
  102. package/src/dashboard/lane-throughput.mjs +351 -0
  103. package/src/dashboard/public/dashboard.css +25 -1
  104. package/src/dashboard/public/dashboard.js +224 -40
  105. package/src/dashboard/public/index.html +15 -9
  106. package/src/dashboard/server.mjs +4 -0
  107. package/src/dashboard/snapshot.mjs +387 -6
  108. package/src/dashboard/view.mjs +170 -15
  109. package/src/doctor/agent-model-inherit.mjs +61 -6
  110. package/src/doctor/run-doctor-checks.mjs +483 -0
  111. package/src/doctor/sequence-safety.mjs +57 -0
  112. package/src/doctor/stale-path.mjs +22 -0
  113. package/src/doctor/stale-worktrees.mjs +102 -0
  114. package/src/fixtures/scenario-registry.mjs +194 -0
  115. package/src/fs/atomic-write.mjs +49 -0
  116. package/src/migrate/taskplane-config.mjs +1 -1
  117. package/src/planner/file-scope.mjs +246 -0
  118. package/src/planner/format-plan.mjs +9 -7
  119. package/src/planner/index.mjs +6 -2
  120. package/src/planner/pending.mjs +92 -1
  121. package/src/planner/wave-scope.mjs +136 -0
  122. package/src/planner/waves.mjs +133 -0
  123. package/src/tasks/analyze/index.mjs +453 -0
  124. package/src/tasks/packet/index.mjs +1 -0
  125. package/src/tasks/packet/parse-prompt.mjs +42 -1
  126. package/src/tasks/packet/validate-prompt.mjs +124 -0
  127. package/src/util/command-exists.mjs +19 -0
  128. package/templates/docs/constitution.md +61 -0
  129. package/templates/spine-config.json +9 -2
@@ -46,6 +46,7 @@ export { mergeDeps, mergeTaskDeps, loadDependenciesJson } from "./merge-deps.mjs
46
46
  export {
47
47
  assertValidTaskPacket,
48
48
  collectPromptValidationFailure,
49
+ collectStaleFileScopeMustChangeWarnings,
49
50
  formatPromptValidationFailures,
50
51
  validatePrompt,
51
52
  } from "./validate-prompt.mjs";
@@ -23,6 +23,8 @@ export const CONTRACT_FIELD_NAMES = Object.freeze([
23
23
  "fileScopeMustNotChange",
24
24
  "minLineCoverage",
25
25
  "artifactsMustExist",
26
+ "stallTimeoutMinutes",
27
+ "extendGraceOnFileScope",
26
28
  ]);
27
29
 
28
30
  const CONTRACT_KNOWN_FIELDS = new Set(CONTRACT_FIELD_NAMES);
@@ -32,7 +34,15 @@ const CONTRACT_TABLE_ROW_RE = /^\|\s*([^|]+?)\s*\|\s*([^|]+?)\s*\|$/;
32
34
  const TEST_COMMAND_MAX_LENGTH = 500;
33
35
  export const SEE_FILE_SCOPE_RE = /^see\s+file\s+scope$/i;
34
36
  const CONTRACT_EM_DASH_PLACEHOLDER_RE = /^[—\-]$/;
35
- const CONTRACT_NONE_VALUES = new Set(["—", "-", "none", "n/a", "na"]);
37
+ const CONTRACT_NONE_VALUES = new Set([
38
+ "—",
39
+ "-",
40
+ "none",
41
+ "n/a",
42
+ "na",
43
+ "(none beyond tests)",
44
+ "none beyond tests",
45
+ ]);
36
46
 
37
47
  /**
38
48
  * @param {string} markdown PROMPT.md contents
@@ -113,6 +123,8 @@ export function validatePrompt(markdown) {
113
123
  * fileScopeMustNotChange: string[],
114
124
  * minLineCoverage: number | null,
115
125
  * artifactsMustExist: string[],
126
+ * stallTimeoutMinutes: number | null,
127
+ * extendGraceOnFileScope: boolean | null,
116
128
  * rawTableValid: boolean,
117
129
  * errors: string[],
118
130
  * unknownFields: string[],
@@ -133,6 +145,8 @@ export function parseContract(markdown) {
133
145
  fileScopeMustNotChange: [],
134
146
  minLineCoverage: null,
135
147
  artifactsMustExist: [],
148
+ stallTimeoutMinutes: null,
149
+ extendGraceOnFileScope: null,
136
150
  rawTableValid: false,
137
151
  errors: [],
138
152
  unknownFields: [],
@@ -276,6 +290,33 @@ function applyContractField(parsed, field, rawValue) {
276
290
  parsed.minLineCoverage = numeric;
277
291
  return;
278
292
  }
293
+ case "stallTimeoutMinutes": {
294
+ const minutes = parseContractScalar(value);
295
+ if (!/^\d+(\.\d+)?$/.test(minutes)) {
296
+ parsed.errors.push("Contract stallTimeoutMinutes must be a positive number");
297
+ return;
298
+ }
299
+ const numeric = Number(minutes);
300
+ if (numeric <= 0) {
301
+ parsed.errors.push("Contract stallTimeoutMinutes must be a positive number");
302
+ return;
303
+ }
304
+ parsed.stallTimeoutMinutes = numeric;
305
+ return;
306
+ }
307
+ case "extendGraceOnFileScope": {
308
+ const flag = parseContractScalar(value).toLowerCase();
309
+ if (flag === "true") {
310
+ parsed.extendGraceOnFileScope = true;
311
+ return;
312
+ }
313
+ if (flag === "false") {
314
+ parsed.extendGraceOnFileScope = false;
315
+ return;
316
+ }
317
+ parsed.errors.push("Contract extendGraceOnFileScope must be true or false");
318
+ return;
319
+ }
279
320
  default:
280
321
  return;
281
322
  }
@@ -2,6 +2,9 @@
2
2
  * Shared fail-loud PROMPT validation helpers (planner, preflight, rules CLI, batch engine).
3
3
  */
4
4
 
5
+ import { execFileSync } from "node:child_process";
6
+
7
+ import { matchesContractPattern } from "../../batch/contract-verify.mjs";
5
8
  import { CONTRACT_DEFAULTS } from "../../config/defaults.mjs";
6
9
  import {
7
10
  parseContract,
@@ -10,6 +13,10 @@ import {
10
13
  } from "./parse-prompt.mjs";
11
14
  import { validateContract } from "./validate-contract.mjs";
12
15
 
16
+ /** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
17
+ export const STALE_FILE_SCOPE_AMENDMENT_HINT =
18
+ "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)";
19
+
13
20
  /**
14
21
  * Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
15
22
  *
@@ -97,3 +104,120 @@ export function assertValidTaskPacket(packet, taskId) {
97
104
  function formatErrorLines(errors) {
98
105
  return errors.map((error) => ` - ${error}`).join("\n");
99
106
  }
107
+
108
+ /**
109
+ * @param {string} projectRoot
110
+ * @param {string} relPath
111
+ */
112
+ function gitFirstCommitTouchingPath(projectRoot, relPath) {
113
+ try {
114
+ const output = execFileSync("git", ["log", "--reverse", "--format=%H", "--", relPath], {
115
+ cwd: projectRoot,
116
+ encoding: "utf-8",
117
+ stdio: ["ignore", "pipe", "pipe"],
118
+ timeout: 10_000,
119
+ }).trim();
120
+ return output.split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? null;
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @param {string} projectRoot
128
+ * @param {string} [baseRef]
129
+ */
130
+ function resolveComparisonBaseRef(projectRoot, baseRef = "main") {
131
+ try {
132
+ execFileSync("git", ["rev-parse", "--verify", baseRef], {
133
+ cwd: projectRoot,
134
+ stdio: "ignore",
135
+ timeout: 5000,
136
+ });
137
+ return baseRef;
138
+ } catch {
139
+ return "HEAD";
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @param {string} projectRoot
145
+ * @param {string} sinceCommit
146
+ * @param {string} baseRef
147
+ * @param {string} pattern
148
+ */
149
+ function listPathsChangedSinceCommit(projectRoot, sinceCommit, baseRef, pattern) {
150
+ try {
151
+ const output = execFileSync(
152
+ "git",
153
+ ["diff", "--name-only", `${sinceCommit}..${baseRef}`, "--", pattern],
154
+ {
155
+ cwd: projectRoot,
156
+ encoding: "utf-8",
157
+ stdio: ["ignore", "pipe", "pipe"],
158
+ timeout: 10_000,
159
+ },
160
+ );
161
+ return output
162
+ .split(/\r?\n/)
163
+ .map((line) => line.trim())
164
+ .filter(Boolean);
165
+ } catch {
166
+ return [];
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Warn when fileScopeMustChange paths were already modified on main after the task PROMPT was introduced.
172
+ *
173
+ * @param {string} projectRoot
174
+ * @param {ReturnType<typeof parseContract>} parsedContract
175
+ * @param {string} promptRelPath Path to PROMPT.md relative to projectRoot
176
+ * @param {{ baseRef?: string }} [options]
177
+ * @returns {string[]}
178
+ */
179
+ export function collectStaleFileScopeMustChangeWarnings(
180
+ projectRoot,
181
+ parsedContract,
182
+ promptRelPath,
183
+ options = {},
184
+ ) {
185
+ const patterns = parsedContract?.fileScopeMustChange ?? [];
186
+ if (patterns.length === 0) {
187
+ return [];
188
+ }
189
+
190
+ const introCommit = gitFirstCommitTouchingPath(projectRoot, promptRelPath);
191
+ if (!introCommit) {
192
+ return [];
193
+ }
194
+
195
+ const baseRef = resolveComparisonBaseRef(projectRoot, options.baseRef ?? "main");
196
+ /** @type {string[]} */
197
+ const stalePatterns = [];
198
+
199
+ for (const pattern of patterns) {
200
+ const changedPaths = listPathsChangedSinceCommit(
201
+ projectRoot,
202
+ introCommit,
203
+ baseRef,
204
+ pattern,
205
+ );
206
+ const matching = changedPaths.filter((filePath) =>
207
+ matchesContractPattern(filePath, pattern),
208
+ );
209
+ if (matching.length > 0) {
210
+ stalePatterns.push(pattern);
211
+ }
212
+ }
213
+
214
+ if (stalePatterns.length === 0) {
215
+ return [];
216
+ }
217
+
218
+ const preview = stalePatterns.slice(0, 5).join(", ");
219
+ const suffix = stalePatterns.length > 5 ? ` (+${stalePatterns.length - 5} more)` : "";
220
+ return [
221
+ `Contract fileScopeMustChange path(s) (${preview}${suffix}) already changed on ${baseRef} since task was added — implementation may be pre-landed and will not diff in a new lane. ${STALE_FILE_SCOPE_AMENDMENT_HINT}`,
222
+ ];
223
+ }
@@ -0,0 +1,19 @@
1
+ import { spawnSync } from "node:child_process";
2
+
3
+ /**
4
+ * @param {string} cmd
5
+ * @returns {boolean}
6
+ */
7
+ export function commandExists(cmd) {
8
+ let result;
9
+ try {
10
+ result = spawnSync("which", [cmd], {
11
+ encoding: "utf-8",
12
+ stdio: ["ignore", "pipe", "pipe"],
13
+ });
14
+ } catch {
15
+ return false;
16
+ }
17
+
18
+ return Boolean(result && !result.error && result.status === 0);
19
+ }
@@ -0,0 +1,61 @@
1
+ # {{PROJECT_TITLE}} — Constitution
2
+
3
+ **Last Updated:** {{LAST_UPDATED}}
4
+
5
+ Upstream principles for this project. Edit this file before decomposing work into spine task packets. Agents load it via `referenceDocs` in `.spine/spine-config.json`.
6
+
7
+ ---
8
+
9
+ ## Mission
10
+
11
+ Describe what this project delivers and who it serves. One or two sentences.
12
+
13
+ ---
14
+
15
+ ## Guiding principles
16
+
17
+ ### Simplicity
18
+
19
+ Prefer the smallest change that satisfies the requirement. Delete before you abstract.
20
+
21
+ ### Testing
22
+
23
+ - Every behavior change includes a test or explicit verification step in the task contract.
24
+ - Run the project's test command before marking work complete.
25
+ - Do not claim tests pass without evidence.
26
+
27
+ ### User experience
28
+
29
+ - Optimize for the operator and end-user path, not internal convenience.
30
+ - Failures must be visible, actionable, and safe by default.
31
+
32
+ ### Performance
33
+
34
+ - Avoid I/O in loops; batch reads and writes.
35
+ - Measure before optimizing hot paths.
36
+
37
+ ### Security
38
+
39
+ - No secrets in source control.
40
+ - Validate untrusted input at system boundaries.
41
+
42
+ ---
43
+
44
+ ## Non-negotiable rules
45
+
46
+ 1. **Scope discipline** — Task workers stay within PROMPT File Scope unless the operator amends the packet.
47
+ 2. **No silent failures** — Errors propagate with context; do not swallow exceptions.
48
+ 3. **Honest verification** — Build and test claims require output or "verification pending."
49
+ 4. **Reversibility** — Prefer changes that can be reverted without data loss.
50
+
51
+ ---
52
+
53
+ ## How this file is used
54
+
55
+ | Consumer | Usage |
56
+ |----------|-------|
57
+ | Task authoring | Mission and "Context to Read First" in `PROMPT.md` |
58
+ | Workers | Injected when listed in `referenceDocs` (not in `neverLoad`) |
59
+ | Reviewers | Principles inform plan/code review; reviewers do not auto-load `referenceDocs` |
60
+
61
+ Optional: align with [spec-kit](https://github.com/github/spec-kit) `.specify/memory/constitution.md` if you use Path 4 upstream authoring. pi-spine does not require spec-kit.
@@ -15,7 +15,11 @@
15
15
  },
16
16
  "agents": {
17
17
  "worker": { "model": "cursor/auto", "thinking": "high" },
18
- "reviewer": { "model": "cursor/auto", "thinking": "medium" },
18
+ "reviewer": {
19
+ "model": "cursor/auto",
20
+ "thinking": "medium",
21
+ "plan": { "model": "google/gemini-flash-latest", "thinking": "low" }
22
+ },
19
23
  "supervisor": { "model": "inherit", "thinking": "off" }
20
24
  },
21
25
  "lanes": {
@@ -25,9 +29,12 @@
25
29
  "workerOutputMaxBytes": 262144,
26
30
  "workerOutputTailLines": 200,
27
31
  "retainWorkerOutputOnSuccess": false,
32
+ "streamWorkerOutputLive": false,
33
+ "workerLiveLogMaxBytes": 262144,
28
34
  "stallTimeoutMinutes": 120,
29
35
  "stallGraceAfterProgressMinutes": 30,
30
36
  "heartbeatIntervalMinutes": 10,
37
+ "progressSnapshotIntervalMinutes": 2,
31
38
  "checkpointWarningMinutes": 10,
32
39
  "extendGraceOnFileScope": false,
33
40
  "autoCommitOnStall": false
@@ -58,7 +65,7 @@
58
65
  },
59
66
  "worktreeSetupHook": "",
60
67
  "worktreeSetupIgnorePaths": [],
61
- "referenceDocs": [],
68
+ "referenceDocs": ["docs/constitution.md"],
62
69
  "standards": [],
63
70
  "neverLoad": []
64
71
  }