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
@@ -2,6 +2,13 @@
2
2
  * Dashboard view model (PRD §16.1) — pure functions for browser + tests.
3
3
  */
4
4
 
5
+ import {
6
+ computeThroughputTasksPerHour,
7
+ emptyLaneThroughputStats,
8
+ formatElapsedMs,
9
+ formatThroughputRate,
10
+ } from "./lane-throughput.mjs";
11
+
5
12
  const DIAGNOSIS_BADGE_CLASS = {
6
13
  running: "badge-running",
7
14
  paused: "badge-paused",
@@ -129,6 +136,8 @@ export function buildBatchSummaryModel(batch) {
129
136
  return {
130
137
  batchId: batch.batchId,
131
138
  phase: batch.phase,
139
+ macroPhase: batch.macroPhase ?? null,
140
+ macroPhaseLabel: batch.macroPhaseLabel ?? null,
132
141
  baseBranch: batch.baseBranch,
133
142
  orchBranch: batch.orchBranch,
134
143
  startedAt: batch.startedAt,
@@ -149,6 +158,7 @@ export function buildWaveModel(snapshot) {
149
158
  return {
150
159
  currentWaveIndex: waves.currentWaveIndex ?? 0,
151
160
  totalWaves: waves.totalWaves ?? 0,
161
+ macroPhaseLabel: snapshot?.macroPhaseLabel ?? snapshot?.batch?.macroPhaseLabel ?? null,
152
162
  waves: (waves.waves ?? []).map((wave) => ({
153
163
  index: wave.index,
154
164
  taskIds: wave.taskIds ?? [],
@@ -166,21 +176,145 @@ export function formatLaneHeartbeatDisplay(lane) {
166
176
  return `${lane.heartbeatAgeSeconds}s`;
167
177
  }
168
178
 
179
+ /**
180
+ * @param {object} lane
181
+ */
182
+ export function buildLaneThroughputModel(lane) {
183
+ const throughput = lane?.throughput ?? emptyLaneThroughputStats();
184
+ return {
185
+ activeElapsedMs: throughput.activeElapsedMs,
186
+ completedCount: throughput.completedCount,
187
+ failedCount: throughput.failedCount,
188
+ throughputTasksPerHour: throughput.throughputTasksPerHour,
189
+ elapsedDisplay: formatElapsedMs(throughput.activeElapsedMs),
190
+ doneDisplay: throughput.completedCount > 0 ? String(throughput.completedCount) : "—",
191
+ rateDisplay:
192
+ throughput.throughputTasksPerHour == null
193
+ ? "—"
194
+ : `${formatThroughputRate(throughput.throughputTasksPerHour)} tasks/hr`,
195
+ };
196
+ }
197
+
198
+ /**
199
+ * @param {object|null|undefined} summary
200
+ */
201
+ export function buildLaneThroughputSummaryModel(summary) {
202
+ const throughput = summary ?? emptyLaneThroughputStats();
203
+ return {
204
+ elapsedDisplay: formatElapsedMs(throughput.activeElapsedMs),
205
+ doneDisplay: throughput.completedCount > 0 ? String(throughput.completedCount) : "—",
206
+ rateDisplay:
207
+ throughput.throughputTasksPerHour == null
208
+ ? "—"
209
+ : `${formatThroughputRate(throughput.throughputTasksPerHour)} tasks/hr`,
210
+ };
211
+ }
212
+
213
+ /**
214
+ * @param {object} lane
215
+ */
216
+ export function buildLaneDetailModel(lane) {
217
+ return {
218
+ recentEvents: (lane?.recentEvents ?? []).map((entry) => ({
219
+ eventId: entry.eventId,
220
+ type: entry.type,
221
+ timestamp: entry.timestamp,
222
+ summary: entry.summary,
223
+ })),
224
+ logTail: lane?.logTail ?? [],
225
+ workerLogRef: lane?.workerLogRef ?? null,
226
+ };
227
+ }
228
+
229
+ /**
230
+ * Resolve running vs queued task projection for the lane table.
231
+ * Prefers SP-379 snapshot fields; falls back to deprecated activeTaskIds.
232
+ *
233
+ * @param {object} lane
234
+ */
235
+ export function resolveLaneQueueProjection(lane) {
236
+ const runningTaskId = lane?.runningTaskId ?? null;
237
+ const queuedTaskIds = lane?.queuedTaskIds ?? null;
238
+
239
+ if (runningTaskId != null || (queuedTaskIds != null && queuedTaskIds.length > 0)) {
240
+ return {
241
+ runningTaskId: runningTaskId ?? null,
242
+ queuedTaskIds: queuedTaskIds ?? [],
243
+ };
244
+ }
245
+
246
+ const activeTaskIds = lane?.activeTaskIds ?? [];
247
+ if (activeTaskIds.length === 0) {
248
+ return { runningTaskId: null, queuedTaskIds: [] };
249
+ }
250
+
251
+ // Degraded fallback until snapshot exposes explicit queue fields (SP-379).
252
+ if (lane?.status === "running" && activeTaskIds.length >= 1) {
253
+ return {
254
+ runningTaskId: activeTaskIds[0] ?? null,
255
+ queuedTaskIds: activeTaskIds.slice(1),
256
+ };
257
+ }
258
+
259
+ return { runningTaskId: null, queuedTaskIds: [...activeTaskIds] };
260
+ }
261
+
169
262
  /**
170
263
  * @param {object} snapshot
171
264
  */
172
265
  export function buildLaneTableModel(snapshot) {
173
- return (snapshot?.lanes ?? []).map((lane) => ({
174
- laneId: lane.laneId,
175
- status: lane.status,
176
- activeTaskIds: lane.activeTaskIds ?? [],
177
- taskIds: lane.taskIds ?? [],
178
- heartbeatAgeSeconds: lane.heartbeatAgeSeconds,
179
- heartbeatKind: lane.heartbeatKind ?? null,
180
- workerPhase: lane.workerPhase ?? null,
181
- heartbeatDisplay: lane.heartbeatDisplay ?? formatLaneHeartbeatDisplay(lane),
182
- worktree: lane.worktree,
183
- }));
266
+ return (snapshot?.lanes ?? []).map((lane) => {
267
+ const queue = resolveLaneQueueProjection(lane);
268
+ return {
269
+ laneId: lane.laneId,
270
+ laneNumber: lane.laneNumber,
271
+ status: lane.status,
272
+ activeTaskIds: lane.activeTaskIds ?? [],
273
+ runningTaskId: queue.runningTaskId,
274
+ queuedTaskIds: queue.queuedTaskIds,
275
+ queuedCount: queue.queuedTaskIds.length,
276
+ taskIds: lane.taskIds ?? [],
277
+ heartbeatAgeSeconds: lane.heartbeatAgeSeconds,
278
+ heartbeatKind: lane.heartbeatKind ?? null,
279
+ workerPhase: lane.workerPhase ?? null,
280
+ heartbeatDisplay: lane.heartbeatDisplay ?? formatLaneHeartbeatDisplay(lane),
281
+ activityPhase: lane.activityPhase ?? "idle",
282
+ activityPhaseLabel: lane.activityPhaseLabel ?? "—",
283
+ worktree: lane.worktree,
284
+ laneAlert: lane.laneAlert ?? null,
285
+ throughput: buildLaneThroughputModel(lane),
286
+ detail: buildLaneDetailModel(lane),
287
+ };
288
+ });
289
+ }
290
+
291
+ /**
292
+ * @param {object} snapshot
293
+ */
294
+ export function buildLaneTableSummaryModel(snapshot) {
295
+ const lanes = snapshot?.lanes ?? [];
296
+ if (lanes.length < 2) return null;
297
+
298
+ if (snapshot?.laneThroughputSummary) {
299
+ return buildLaneThroughputSummaryModel(snapshot.laneThroughputSummary);
300
+ }
301
+
302
+ let activeElapsedMs = 0;
303
+ let completedCount = 0;
304
+ let failedCount = 0;
305
+ for (const lane of lanes) {
306
+ const throughput = lane.throughput ?? emptyLaneThroughputStats();
307
+ activeElapsedMs += throughput.activeElapsedMs;
308
+ completedCount += throughput.completedCount;
309
+ failedCount += throughput.failedCount;
310
+ }
311
+
312
+ return buildLaneThroughputSummaryModel({
313
+ activeElapsedMs,
314
+ completedCount,
315
+ failedCount,
316
+ throughputTasksPerHour: computeThroughputTasksPerHour(completedCount, activeElapsedMs),
317
+ });
184
318
  }
185
319
 
186
320
  /**
@@ -245,20 +379,39 @@ export function shouldShowGateAffordance(snapshot) {
245
379
 
246
380
  /**
247
381
  * @param {object} snapshot
382
+ * @param {{ laneFilter?: string|null }} [options]
248
383
  */
249
- export function buildJournalModel(snapshot) {
250
- return (snapshot?.journalTail ?? []).map((entry) => ({
384
+ export function buildJournalModel(snapshot, { laneFilter = null } = {}) {
385
+ let entries = snapshot?.journalTail ?? [];
386
+ if (laneFilter) {
387
+ entries = entries.filter((entry) => entry.laneId === laneFilter);
388
+ }
389
+ return entries.map((entry) => ({
251
390
  eventId: entry.eventId,
252
391
  type: entry.type,
253
392
  timestamp: entry.timestamp,
393
+ laneId: entry.laneId ?? null,
254
394
  summary: entry.summary,
255
395
  }));
256
396
  }
257
397
 
398
+ /**
399
+ * Lane ids for the optional journal panel filter.
400
+ *
401
+ * @param {object} snapshot
402
+ */
403
+ export function buildJournalLaneFilterOptions(snapshot) {
404
+ return (snapshot?.lanes ?? []).map((lane) => ({
405
+ laneId: lane.laneId,
406
+ label: lane.laneId ?? `lane-${lane.laneNumber}`,
407
+ }));
408
+ }
409
+
258
410
  /**
259
411
  * @param {object} snapshot
412
+ * @param {{ journalLaneFilter?: string|null }} [options]
260
413
  */
261
- export function buildDashboardViewModel(snapshot) {
414
+ export function buildDashboardViewModel(snapshot, { journalLaneFilter = null } = {}) {
262
415
  return {
263
416
  generatedAt: snapshot?.generatedAt ?? null,
264
417
  idle: isIdleSnapshot(snapshot),
@@ -266,10 +419,12 @@ export function buildDashboardViewModel(snapshot) {
266
419
  batch: buildBatchSummaryModel(snapshot?.batch),
267
420
  waves: buildWaveModel(snapshot),
268
421
  lanes: buildLaneTableModel(snapshot),
422
+ laneTableSummary: buildLaneTableSummaryModel(snapshot),
269
423
  gate: buildGateModel(snapshot?.gate),
270
424
  gateAffordance: buildGateAffordanceModel(snapshot),
271
425
  showGateAffordance: shouldShowGateAffordance(snapshot),
272
- journal: buildJournalModel(snapshot),
426
+ journal: buildJournalModel(snapshot, { laneFilter: journalLaneFilter }),
427
+ journalLaneFilterOptions: buildJournalLaneFilterOptions(snapshot),
273
428
  };
274
429
  }
275
430
 
@@ -1,13 +1,22 @@
1
1
  /**
2
2
  * Doctor warning when spine agents inherit pi's global model and pi defaults to LM Studio (SP-238).
3
+ * Per-type reviewer effective pins (issue #53 / SP-371).
3
4
  */
4
5
 
5
6
  import fs from "node:fs";
6
7
  import os from "node:os";
7
8
  import path from "node:path";
8
9
 
10
+ import {
11
+ resolveReviewerModelPin,
12
+ resolveReviewerThinkingPin,
13
+ } from "../config/agent-model-resolve.mjs";
14
+
9
15
  const LMSTUDIO_PROVIDER = "lmstudio";
10
16
 
17
+ /** @type {readonly ("plan"|"code"|"final")[]} */
18
+ const REVIEW_TYPES = ["plan", "code", "final"];
19
+
11
20
  /**
12
21
  * @param {string} settingsPath
13
22
  * @returns {Record<string, unknown>|null}
@@ -48,15 +57,57 @@ export function resolvePiDefaultProvider(
48
57
  return provider.trim().toLowerCase();
49
58
  }
50
59
 
60
+ /**
61
+ * @param {unknown} model
62
+ * @returns {boolean}
63
+ */
64
+ function modelUsesInherit(model) {
65
+ return !model || model === "inherit";
66
+ }
67
+
51
68
  /**
52
69
  * @param {object} [config]
53
70
  * @returns {boolean}
54
71
  */
55
72
  export function spineAgentsUseInherit(config = {}) {
56
73
  const workerModel = config.agents?.worker?.model;
57
- const reviewerModel = config.agents?.reviewer?.model;
58
- const inherits = (model) => !model || model === "inherit";
59
- return inherits(workerModel) || inherits(reviewerModel);
74
+ if (modelUsesInherit(workerModel)) {
75
+ return true;
76
+ }
77
+
78
+ for (const reviewType of REVIEW_TYPES) {
79
+ if (resolveReviewerModelPin(config, reviewType) === null) {
80
+ return true;
81
+ }
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ /**
88
+ * @param {object} [config]
89
+ * @returns {string}
90
+ */
91
+ export function formatReviewerEffectivePins(config = {}) {
92
+ return REVIEW_TYPES.map((reviewType) => {
93
+ const modelPin = resolveReviewerModelPin(config, reviewType);
94
+ const thinkingPin = resolveReviewerThinkingPin(config, reviewType);
95
+ const modelLabel = modelPin ?? "inherit";
96
+ const thinkingLabel = thinkingPin ?? "inherit";
97
+ return `${reviewType}=${modelLabel}/${thinkingLabel}`;
98
+ }).join(", ");
99
+ }
100
+
101
+ /**
102
+ * @param {object} params
103
+ * @param {object} [params.config]
104
+ */
105
+ export function buildReviewerPerTypePinsDoctorCheck({ config = {} } = {}) {
106
+ return {
107
+ label: "reviewer model pins (per-type)",
108
+ ok: true,
109
+ detail: formatReviewerEffectivePins(config),
110
+ };
60
111
  }
61
112
 
62
113
  /**
@@ -70,11 +121,13 @@ export function buildAgentModelInheritDoctorCheck({
70
121
  projectRoot = process.cwd(),
71
122
  resolveProvider,
72
123
  } = {}) {
124
+ const perTypeDetail = formatReviewerEffectivePins(config);
125
+
73
126
  if (!spineAgentsUseInherit(config)) {
74
127
  return {
75
128
  label: "agents model inherit (pi-lmstudio)",
76
129
  ok: true,
77
- detail: "worker/reviewer pinned or inherit not used",
130
+ detail: `pinned — ${perTypeDetail}`,
78
131
  };
79
132
  }
80
133
 
@@ -85,7 +138,9 @@ export function buildAgentModelInheritDoctorCheck({
85
138
  return {
86
139
  label: "agents model inherit (pi-lmstudio)",
87
140
  ok: true,
88
- detail: provider ? `pi default provider ${provider}` : "pi default provider unset",
141
+ detail: provider
142
+ ? `pi default provider ${provider} — ${perTypeDetail}`
143
+ : `pi default provider unset — ${perTypeDetail}`,
89
144
  };
90
145
  }
91
146
 
@@ -94,7 +149,7 @@ export function buildAgentModelInheritDoctorCheck({
94
149
  ok: true,
95
150
  warning: true,
96
151
  detail:
97
- "inherit + pi defaultProvider lmstudio — batch workers/reviewers may use local LM Studio; pin cursor/auto in spine-config",
152
+ `inherit + pi defaultProvider lmstudio — batch workers/reviewers may use local LM Studio; pin cursor/auto in spine-config — ${perTypeDetail}`,
98
153
  suggestedCommand:
99
154
  "spine settings set agents.worker.model cursor/auto && spine settings set agents.reviewer.model cursor/auto",
100
155
  };