pi-spine 1.7.0 → 1.8.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 (125) hide show
  1. package/package.json +2 -2
  2. package/skills/spine-autonomous-operator/SKILL.md +264 -0
  3. package/skills/spine-autonomous-operator/references/issue-template.md +45 -0
  4. package/skills/spine-orchestrate-waves/SKILL.md +1 -0
  5. package/skills/spine-release-operator/SKILL.md +44 -8
  6. package/skills/spine-release-operator/references/pi-async-orchestration.md +88 -0
  7. package/skills/spine-release-operator/scripts/collect-release-intake.sh +71 -0
  8. package/src/batch/abort.mjs +1 -0
  9. package/src/batch/agent-session-worker.mjs +1 -0
  10. package/src/batch/attached-engine-handoff.mjs +1 -0
  11. package/src/batch/attached-runner.mjs +1 -0
  12. package/src/batch/contract-prelanded.mjs +1 -0
  13. package/src/batch/contract-task-start.mjs +1 -0
  14. package/src/batch/contract-verify.mjs +1 -0
  15. package/src/batch/detached-start.mjs +1 -0
  16. package/src/batch/diagnosis-launch-failure.mjs +1 -0
  17. package/src/batch/diagnosis-merge-failure.mjs +1 -0
  18. package/src/batch/diagnosis-retry-limbo.mjs +1 -0
  19. package/src/batch/diagnosis-tail-state.mjs +1 -0
  20. package/src/batch/diagnosis-task-done.mjs +1 -0
  21. package/src/batch/diagnosis-worker-done-missing.mjs +1 -0
  22. package/src/batch/diagnosis.mjs +1 -0
  23. package/src/batch/engine-lanes/commit.mjs +1 -0
  24. package/src/batch/engine-lanes/merge.mjs +1 -0
  25. package/src/batch/engine-lanes/queue.mjs +1 -0
  26. package/src/batch/engine-lanes/review.mjs +1 -0
  27. package/src/batch/engine-lanes.mjs +1 -0
  28. package/src/batch/engine-scope.mjs +1 -0
  29. package/src/batch/engine.mjs +19 -9
  30. package/src/batch/evidence.mjs +1 -0
  31. package/src/batch/gate-evidence-collect.mjs +1 -0
  32. package/src/batch/gate-evidence-read.mjs +1 -0
  33. package/src/batch/gate.mjs +1 -0
  34. package/src/batch/git-helpers.mjs +1 -1
  35. package/src/batch/heartbeat-git-debounce.mjs +83 -0
  36. package/src/batch/heartbeat.mjs +17 -20
  37. package/src/batch/integrate-worktree.mjs +1 -0
  38. package/src/batch/integrate.mjs +1 -0
  39. package/src/batch/journal-rebuild.mjs +1 -0
  40. package/src/batch/journal.mjs +2 -1
  41. package/src/batch/lane-commit.mjs +1 -0
  42. package/src/batch/lane-dirty-check.mjs +1 -0
  43. package/src/batch/lifecycle.mjs +1 -0
  44. package/src/batch/limbo-detect.mjs +1 -0
  45. package/src/batch/macro-phase.mjs +1 -0
  46. package/src/batch/merge/adoption-doc-merge.mjs +1 -0
  47. package/src/batch/merge/wave-merge-state.mjs +1 -0
  48. package/src/batch/metrics.mjs +1 -0
  49. package/src/batch/orphan-detect.mjs +1 -0
  50. package/src/batch/pause.mjs +1 -0
  51. package/src/batch/post-merge-limbo.mjs +1 -0
  52. package/src/batch/postmortem.mjs +1 -0
  53. package/src/batch/readers/spine-state.mjs +1 -0
  54. package/src/batch/readers/taskplane-state.mjs +1 -0
  55. package/src/batch/reconcile.mjs +84 -8
  56. package/src/batch/resume-common.mjs +1 -0
  57. package/src/batch/resume-engine.mjs +1 -0
  58. package/src/batch/resume-multi-lanes.mjs +1 -0
  59. package/src/batch/resume-multi-validate.mjs +1 -0
  60. package/src/batch/resume-multi.mjs +1 -0
  61. package/src/batch/resume-validation.mjs +1 -0
  62. package/src/batch/resume.mjs +1 -0
  63. package/src/batch/retry.mjs +1 -0
  64. package/src/batch/review-shared.mjs +1 -0
  65. package/src/batch/review-spawn.mjs +1 -0
  66. package/src/batch/review.mjs +1 -0
  67. package/src/batch/rules-manifest-drift.mjs +1 -0
  68. package/src/batch/salvage.mjs +1 -0
  69. package/src/batch/sequence.mjs +5 -2
  70. package/src/batch/state.mjs +1 -0
  71. package/src/batch/supervisor-spawn.mjs +1 -0
  72. package/src/batch/task-stall-budget.mjs +3 -4
  73. package/src/batch/worker-host.mjs +31 -25
  74. package/src/batch/worker-output.mjs +1 -0
  75. package/src/batch/worker-prompt.mjs +1 -0
  76. package/src/cli/journal-follow.mjs +1 -1
  77. package/src/config/agent-model-resolve.mjs +1 -0
  78. package/src/config/contract.mjs +1 -0
  79. package/src/config/cursor-rules/discover.mjs +1 -0
  80. package/src/config/cursor-rules/match-globs.mjs +1 -0
  81. package/src/config/cursor-rules/parse-frontmatter.mjs +1 -0
  82. package/src/config/cursor-rules/profile.mjs +1 -0
  83. package/src/config/cursor-rules/select.mjs +1 -0
  84. package/src/config/env-overrides.mjs +1 -0
  85. package/src/config/pi-spine-root.mjs +1 -0
  86. package/src/config/preflight/discovery.mjs +333 -0
  87. package/src/config/preflight/git-batch.mjs +320 -0
  88. package/src/config/preflight/integrate-plan.mjs +460 -0
  89. package/src/config/reviewer-context.mjs +1 -0
  90. package/src/config/settings-fields.mjs +1 -0
  91. package/src/config/spine-config-schema.mjs +1 -0
  92. package/src/config/spine-init-constants.mjs +1 -0
  93. package/src/config/spine-preflight-lib.mjs +54 -1013
  94. package/src/config/worker-backend.mjs +1 -0
  95. package/src/config/worker-context.mjs +1 -0
  96. package/src/config/worker-launch-script.mjs +1 -0
  97. package/src/config/worktree-setup-hook.mjs +1 -0
  98. package/src/dashboard/public/dashboard.js +6 -1
  99. package/src/dashboard/running-tail-state.mjs +1 -0
  100. package/src/dashboard/server.mjs +136 -16
  101. package/src/dashboard/snapshot-lanes.mjs +479 -0
  102. package/src/dashboard/snapshot-waves.mjs +272 -0
  103. package/src/dashboard/snapshot.mjs +41 -862
  104. package/src/doctor/agent-model-inherit.mjs +1 -0
  105. package/src/doctor/agent-models.mjs +1 -0
  106. package/src/doctor/coexistence.mjs +1 -0
  107. package/src/doctor/run-doctor-checks.mjs +1 -0
  108. package/src/doctor/stale-path.mjs +1 -0
  109. package/src/doctor/stall-config.mjs +1 -0
  110. package/src/doctor/suggest-max-parallel.mjs +1 -0
  111. package/src/doctor/task-packet-size.mjs +3 -10
  112. package/src/doctor/worktree-health.mjs +1 -0
  113. package/src/planner/cycles.mjs +1 -0
  114. package/src/planner/file-scope.mjs +1 -0
  115. package/src/planner/format-plan.mjs +1 -0
  116. package/src/planner/graph.mjs +1 -0
  117. package/src/planner/scope.mjs +1 -0
  118. package/src/planner/wave-scope.mjs +1 -0
  119. package/src/planner/waves.mjs +1 -0
  120. package/src/tasks/packet/merge-deps.mjs +1 -0
  121. package/src/tasks/packet/parse-prompt.mjs +4 -3
  122. package/src/tasks/packet/parse-status.mjs +1 -0
  123. package/src/tasks/packet/size-line.mjs +12 -0
  124. package/src/tasks/packet/validate-contract.mjs +1 -0
  125. package/src/tasks/packet/validate-prompt.mjs +1 -0
@@ -0,0 +1,320 @@
1
+ // @ts-nocheck
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { execFileSync } from "node:child_process";
5
+ import { loadSpineConfig } from "../spine-config-load.mjs";
6
+ import { runReconciliationCheck } from "../../batch/reconcile.mjs";
7
+ import {
8
+ isRulesManifestGeneratedAtOnlyDrift,
9
+ RULES_MANIFEST_REL_PATH,
10
+ } from "../cursor-rules/discover.mjs";
11
+ import { isRunMetricsAppendOnlyDrift } from "../../batch/metrics.mjs";
12
+ import { METRICS_DEFAULTS } from "../defaults.mjs";
13
+
14
+ const HEALTHY_ACTIVE_PHASES = new Set(["planning", "running", "paused"]);
15
+ const LIMBO_DIAGNOSES = new Set(["limbo_stale", "completed_manual"]);
16
+ const PI_SESSION_METADATA_PREFIX = ".pi/";
17
+
18
+ function makeCheck(id, ok, message, extra = {}) {
19
+ return { id, ok, message, ...extra };
20
+ }
21
+
22
+ /**
23
+ * Pi session metadata under `.pi/` is not project source (issue #81).
24
+ *
25
+ * @param {string} relPath
26
+ */
27
+ export function isPiSessionMetadataPath(relPath) {
28
+ const normalized = String(relPath).replace(/\\/g, "/").replace(/^\.\/+/, "");
29
+ return normalized === ".pi" || normalized.startsWith(PI_SESSION_METADATA_PREFIX);
30
+ }
31
+
32
+ /**
33
+ * @param {string[]} dirtyPaths
34
+ */
35
+ export function filterPiSessionDirtyPaths(dirtyPaths) {
36
+ return dirtyPaths.filter((relPath) => !isPiSessionMetadataPath(relPath));
37
+ }
38
+
39
+ /**
40
+ * List uncommitted paths in projectRoot, excluding pi session metadata (issue #81).
41
+ *
42
+ * @param {string} projectRoot
43
+ * @returns {{ dirtyPaths: string[]; error: string | null }}
44
+ */
45
+ export function listHumanDirtyPaths(projectRoot) {
46
+ try {
47
+ const output = execFileSync("git", ["status", "--porcelain"], {
48
+ cwd: projectRoot,
49
+ encoding: "utf-8",
50
+ timeout: 5000,
51
+ });
52
+ const allDirtyPaths = output
53
+ .split(/\r?\n/)
54
+ .filter(Boolean)
55
+ .map((line) => line.slice(3).trim() || line.trim());
56
+ return { dirtyPaths: filterPiSessionDirtyPaths(allDirtyPaths), error: null };
57
+ } catch (err) {
58
+ return {
59
+ dirtyPaths: [],
60
+ error: err instanceof Error ? err.message : String(err),
61
+ };
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Resolve current git branch in projectRoot.
67
+ *
68
+ * @param {string} projectRoot
69
+ * @returns {{ branch: string | null; error: string | null }}
70
+ */
71
+ export function resolveCurrentGitBranch(projectRoot) {
72
+ try {
73
+ const branch = execFileSync("git", ["branch", "--show-current"], {
74
+ cwd: projectRoot,
75
+ encoding: "utf-8",
76
+ timeout: 5000,
77
+ }).trim();
78
+ return { branch: branch || null, error: null };
79
+ } catch (err) {
80
+ return {
81
+ branch: null,
82
+ error: err instanceof Error ? err.message : String(err),
83
+ };
84
+ }
85
+ }
86
+
87
+ function isInsideGitRepo(dir) {
88
+ try {
89
+ execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
90
+ cwd: dir,
91
+ stdio: ["ignore", "pipe", "pipe"],
92
+ timeout: 5000,
93
+ });
94
+ return true;
95
+ } catch {
96
+ return false;
97
+ }
98
+ }
99
+
100
+ function resolveBatchStatePath(projectRoot) {
101
+ const spinePath = path.join(projectRoot, ".spine", "batch-state.json");
102
+ if (fs.existsSync(spinePath)) return spinePath;
103
+
104
+ const piPath = path.join(projectRoot, ".pi", "batch-state.json");
105
+ if (fs.existsSync(piPath)) return piPath;
106
+
107
+ return null;
108
+ }
109
+
110
+ function loadBatchState(batchStatePath) {
111
+ try {
112
+ return JSON.parse(fs.readFileSync(batchStatePath, "utf-8"));
113
+ } catch (err) {
114
+ return { parseError: err.message };
115
+ }
116
+ }
117
+
118
+ function isHealthyActiveBatch(batchState) {
119
+ if (!batchState || batchState.parseError) return false;
120
+ const phase = batchState.phase ?? batchState.status;
121
+ if (phase && HEALTHY_ACTIVE_PHASES.has(String(phase))) return true;
122
+ if (batchState.endedAt == null && batchState.batchId) return true;
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * @param {object} ctx
128
+ * @param {string} ctx.projectRoot
129
+ */
130
+ export function checkGitClean(ctx) {
131
+ if (!isInsideGitRepo(ctx.projectRoot)) {
132
+ return makeCheck("git-clean", false, "not inside a git repository", {
133
+ suggestedCommand: "git init",
134
+ });
135
+ }
136
+
137
+ let output = "";
138
+ try {
139
+ output = execFileSync("git", ["status", "--porcelain"], {
140
+ cwd: ctx.projectRoot,
141
+ encoding: "utf-8",
142
+ timeout: 5000,
143
+ });
144
+ } catch (err) {
145
+ return makeCheck("git-clean", false, `git status failed: ${err.message}`, {
146
+ suggestedCommand: "git status",
147
+ });
148
+ }
149
+
150
+ const allDirtyPaths = output
151
+ .split(/\r?\n/)
152
+ .filter(Boolean)
153
+ .map((line) => line.slice(3).trim() || line.trim());
154
+ const dirtyPaths = filterPiSessionDirtyPaths(allDirtyPaths);
155
+
156
+ if (dirtyPaths.length === 0) {
157
+ if (allDirtyPaths.length > 0) {
158
+ return makeCheck("git-clean", true, "working tree clean (.pi/ session metadata ignored)");
159
+ }
160
+ return makeCheck("git-clean", true, "working tree clean");
161
+ }
162
+
163
+ const manifestDrift = isRulesManifestGeneratedAtOnlyDrift(ctx.projectRoot, dirtyPaths);
164
+ if (manifestDrift.ok) {
165
+ return makeCheck(
166
+ "git-clean",
167
+ true,
168
+ `working tree clean (${RULES_MANIFEST_REL_PATH} generatedAt-only drift ignored)`,
169
+ {
170
+ details: {
171
+ manifestGeneratedAtDrift: true,
172
+ manifestPath: manifestDrift.manifestPath,
173
+ },
174
+ },
175
+ );
176
+ }
177
+
178
+ const configResult = loadSpineConfig(ctx.projectRoot);
179
+ const metricsRelPath = configResult?.config?.metrics?.path ?? METRICS_DEFAULTS.path;
180
+ const metricsDrift = isRunMetricsAppendOnlyDrift(ctx.projectRoot, dirtyPaths, metricsRelPath);
181
+ if (metricsDrift.ok) {
182
+ return makeCheck(
183
+ "git-clean",
184
+ true,
185
+ `working tree clean (${metricsRelPath} append-only drift ignored)`,
186
+ {
187
+ details: {
188
+ metricsAppendOnlyDrift: true,
189
+ metricsPath: metricsDrift.metricsPath,
190
+ },
191
+ },
192
+ );
193
+ }
194
+
195
+ const listed = dirtyPaths.slice(0, 20);
196
+ const suffix =
197
+ dirtyPaths.length > listed.length ? ` (+${dirtyPaths.length - listed.length} more)` : "";
198
+
199
+ return makeCheck(
200
+ "git-clean",
201
+ false,
202
+ `working tree has ${dirtyPaths.length} uncommitted change(s)${suffix}`,
203
+ {
204
+ details: { dirtyPaths: listed, totalDirty: dirtyPaths.length },
205
+ suggestedCommand: "git status",
206
+ },
207
+ );
208
+ }
209
+
210
+ /**
211
+ * @param {object} ctx
212
+ * @param {string} ctx.projectRoot
213
+ * @param {typeof runReconciliationCheck} [ctx.runReconciliation]
214
+ */
215
+ export function checkNoActiveBatch(ctx) {
216
+ const batchStatePath = resolveBatchStatePath(ctx.projectRoot);
217
+ if (!batchStatePath) {
218
+ return makeCheck("no-active-batch", true, "no active batch state file");
219
+ }
220
+
221
+ const batchState = loadBatchState(batchStatePath);
222
+ if (batchState.parseError) {
223
+ return makeCheck("no-active-batch", false, `cannot parse batch state: ${batchState.parseError}`, {
224
+ details: { batchStatePath: path.relative(ctx.projectRoot, batchStatePath) },
225
+ suggestedCommand: "spine status --diagnose",
226
+ });
227
+ }
228
+
229
+ const reconcile = ctx.runReconciliation ?? runReconciliationCheck;
230
+ const reconciliation = reconcile({
231
+ projectRoot: ctx.projectRoot,
232
+ batchState,
233
+ batchStatePath,
234
+ });
235
+
236
+ if (LIMBO_DIAGNOSES.has(reconciliation.diagnosis)) {
237
+ return makeCheck(
238
+ "no-active-batch",
239
+ false,
240
+ reconciliation.headline ?? "stale batch requires dismissal",
241
+ {
242
+ details: {
243
+ batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
244
+ diagnosis: reconciliation.diagnosis,
245
+ batchId: batchState.batchId ?? batchState.id ?? null,
246
+ headline: reconciliation.headline,
247
+ },
248
+ suggestedCommand: reconciliation.suggestedCommand ?? "spine batch dismiss",
249
+ },
250
+ );
251
+ }
252
+
253
+ if (reconciliation.diagnosis === "running") {
254
+ const batchId = batchState.batchId ?? batchState.id ?? "unknown";
255
+ return makeCheck(
256
+ "no-active-batch",
257
+ false,
258
+ reconciliation.headline ?? `batch ${batchId} is running`,
259
+ {
260
+ details: {
261
+ batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
262
+ diagnosis: reconciliation.diagnosis,
263
+ batchId,
264
+ headline: reconciliation.headline,
265
+ },
266
+ suggestedCommand: reconciliation.suggestedCommand ?? "/spine-status --diagnose",
267
+ },
268
+ );
269
+ }
270
+
271
+ if (reconciliation.diagnosis === "paused") {
272
+ const batchId = batchState.batchId ?? batchState.id ?? "unknown";
273
+ return makeCheck(
274
+ "no-active-batch",
275
+ false,
276
+ reconciliation.headline ?? `batch ${batchId} is paused`,
277
+ {
278
+ details: {
279
+ batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
280
+ diagnosis: reconciliation.diagnosis,
281
+ batchId,
282
+ headline: reconciliation.headline,
283
+ },
284
+ suggestedCommand: reconciliation.suggestedCommand ?? "/spine-resume --force",
285
+ },
286
+ );
287
+ }
288
+
289
+ if (isHealthyActiveBatch(batchState)) {
290
+ const batchId = batchState.batchId ?? batchState.id ?? "unknown";
291
+ const phase = batchState.phase ?? batchState.status ?? "unknown";
292
+ return makeCheck(
293
+ "no-active-batch",
294
+ false,
295
+ `healthy active batch ${batchId} (phase: ${phase})`,
296
+ {
297
+ details: {
298
+ batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
299
+ batchId,
300
+ phase,
301
+ },
302
+ suggestedCommand: reconciliation.suggestedCommand ?? "spine status --diagnose",
303
+ },
304
+ );
305
+ }
306
+
307
+ return makeCheck(
308
+ "no-active-batch",
309
+ false,
310
+ reconciliation.headline ?? "batch state file present",
311
+ {
312
+ details: {
313
+ batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
314
+ diagnosis: reconciliation.diagnosis,
315
+ batchId: batchState.batchId ?? batchState.id ?? null,
316
+ },
317
+ suggestedCommand: reconciliation.suggestedCommand ?? "spine status --diagnose",
318
+ },
319
+ );
320
+ }