pi-spine 1.2.0 → 1.3.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 (60) hide show
  1. package/README.md +4 -4
  2. package/bin/spine-cli/verify.mjs +3 -0
  3. package/bin/spine-plan.mjs +49 -1
  4. package/bin/spine-worker-runner.mjs +136 -4
  5. package/package.json +1 -1
  6. package/skills/create-spine-tasks/SKILL.md +7 -2
  7. package/skills/create-spine-tasks/references/contract-template.md +95 -3
  8. package/src/batch/attached-runner.mjs +81 -5
  9. package/src/batch/contract-stub-delivery.mjs +110 -0
  10. package/src/batch/contract-task-start.mjs +204 -0
  11. package/src/batch/contract-verify.mjs +55 -8
  12. package/src/batch/detached-start.mjs +72 -2
  13. package/src/batch/diagnosis-launch-failure.mjs +114 -0
  14. package/src/batch/diagnosis-primary-failure.mjs +89 -0
  15. package/src/batch/diagnosis-tail-state.mjs +57 -0
  16. package/src/batch/diagnosis.mjs +22 -113
  17. package/src/batch/engine-lanes/commit.mjs +145 -0
  18. package/src/batch/engine-lanes/review.mjs +67 -87
  19. package/src/batch/engine-lanes.mjs +21 -79
  20. package/src/batch/engine.mjs +46 -0
  21. package/src/batch/heartbeat.mjs +2 -2
  22. package/src/batch/integrate-assert.mjs +69 -0
  23. package/src/batch/integrate-worktree.mjs +354 -0
  24. package/src/batch/integrate.mjs +195 -102
  25. package/src/batch/journal-rebuild.mjs +48 -2
  26. package/src/batch/journal.mjs +63 -0
  27. package/src/batch/lane-dirty-check.mjs +437 -0
  28. package/src/batch/limbo-detect.mjs +34 -0
  29. package/src/batch/macro-phase.mjs +76 -0
  30. package/src/batch/metrics.mjs +2 -0
  31. package/src/batch/pause.mjs +18 -7
  32. package/src/batch/post-merge-limbo.mjs +3 -28
  33. package/src/batch/reconcile.mjs +79 -9
  34. package/src/batch/resume-common.mjs +27 -0
  35. package/src/batch/resume-multi-lanes.mjs +11 -0
  36. package/src/batch/resume-multi.mjs +2 -0
  37. package/src/batch/resume.mjs +8 -1
  38. package/src/batch/retry.mjs +41 -10
  39. package/src/batch/rules-manifest-drift.mjs +43 -2
  40. package/src/batch/sequence-state.mjs +290 -0
  41. package/src/batch/sequence.mjs +113 -51
  42. package/src/batch/state.mjs +16 -0
  43. package/src/batch/worker-host.mjs +1 -0
  44. package/src/cli/sequence.mjs +14 -1
  45. package/src/cli/settings-set.mjs +33 -3
  46. package/src/config/model-id.mjs +103 -0
  47. package/src/config/spine-init-constants.mjs +1 -0
  48. package/src/config/spine-preflight-lib.mjs +23 -1
  49. package/src/dashboard/public/dashboard.js +14 -3
  50. package/src/dashboard/running-tail-state.mjs +31 -0
  51. package/src/dashboard/server.mjs +4 -0
  52. package/src/dashboard/snapshot.mjs +260 -28
  53. package/src/dashboard/view.mjs +112 -2
  54. package/src/doctor/agent-models.mjs +53 -0
  55. package/src/doctor/batch-size-guidance.mjs +30 -2
  56. package/src/doctor/pi-extension-conflict.mjs +169 -0
  57. package/src/doctor/run-doctor-checks.mjs +6 -0
  58. package/src/planner/scope.mjs +5 -1
  59. package/src/tasks/packet/parse-prompt.mjs +31 -1
  60. package/src/tasks/packet/validate-contract.mjs +108 -0
@@ -5,10 +5,19 @@
5
5
  import path from "node:path";
6
6
 
7
7
  import { writeJsonAtomic } from "../fs/atomic-write.mjs";
8
+ import { normalizeModelId } from "../config/model-id.mjs";
8
9
  import { parseSettingPath, validateSettingValue } from "../config/settings-fields.mjs";
9
10
  import { validateSpineConfig } from "../config/spine-config-load.mjs";
10
11
  import { getValueAtPath } from "./settings-show.mjs";
11
12
 
13
+ const MODEL_FIELD_PATHS = new Set([
14
+ "agents.worker.model",
15
+ "agents.reviewer.model",
16
+ "agents.reviewer.plan.model",
17
+ "agents.reviewer.code.model",
18
+ "agents.reviewer.final.model",
19
+ ]);
20
+
12
21
  /**
13
22
  * @param {object} config
14
23
  * @param {string} dottedPath
@@ -93,8 +102,29 @@ export function runSettingsSetOperation(config, { path, rawValue, dryRun = false
93
102
  };
94
103
  }
95
104
 
105
+ let settingValue = validated.normalizedValue;
106
+ if (MODEL_FIELD_PATHS.has(parsed.path) && typeof settingValue === "string" && settingValue !== "") {
107
+ const modelResult = normalizeModelId(settingValue);
108
+ if (!modelResult.ok) {
109
+ const message = modelResult.error;
110
+ if (json) {
111
+ return {
112
+ exitCode: 1,
113
+ output: `${JSON.stringify({ error: message }, null, 2)}\n`,
114
+ error: message,
115
+ };
116
+ }
117
+ return {
118
+ exitCode: 1,
119
+ output: `Error: ${message}\n`,
120
+ error: message,
121
+ };
122
+ }
123
+ settingValue = modelResult.value;
124
+ }
125
+
96
126
  const previousValue = getValueAtPath(config, parsed.path);
97
- const nextConfig = applySetting(config, parsed.path, validated.normalizedValue);
127
+ const nextConfig = applySetting(config, parsed.path, settingValue);
98
128
  const validationError = validateSpineConfig(nextConfig);
99
129
  if (validationError) {
100
130
  const message = validationError.message;
@@ -118,7 +148,7 @@ export function runSettingsSetOperation(config, { path, rawValue, dryRun = false
118
148
  const payload = {
119
149
  path: parsed.path,
120
150
  previousValue,
121
- newValue: validated.normalizedValue,
151
+ newValue: settingValue,
122
152
  dryRun,
123
153
  wrote,
124
154
  };
@@ -134,7 +164,7 @@ export function runSettingsSetOperation(config, { path, rawValue, dryRun = false
134
164
 
135
165
  return {
136
166
  exitCode: 0,
137
- output: `Updated ${parsed.path}: ${formatValue(previousValue)} → ${formatValue(validated.normalizedValue)}${dryRun ? " (dry run)" : ""}\n`,
167
+ output: `Updated ${parsed.path}: ${formatValue(previousValue)} → ${formatValue(settingValue)}${dryRun ? " (dry run)" : ""}\n`,
138
168
  ...payload,
139
169
  config: nextConfig,
140
170
  };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Model id validation and normalization (SP-422 / #76).
3
+ * Canonical pi model id format: `provider/model` (e.g. `google/gemini-3.1-pro-preview`).
4
+ * Pi TUI display labels use `model [provider]` (e.g. `gemini-3.1-pro-preview [google]`).
5
+ */
6
+
7
+ const DISPLAY_LABEL_RE = /^([a-z0-9][a-z0-9._-]*)\s+\[([a-z0-9][a-z0-9._-]*)\]$/i;
8
+ const CANONICAL_RE = /^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*$/i;
9
+ const SPECIAL_VALUES = new Set(["inherit", ""]);
10
+
11
+ /**
12
+ * @param {string} value
13
+ * @returns {boolean}
14
+ */
15
+ export function isDisplayLabel(value) {
16
+ if (typeof value !== "string") return false;
17
+ return DISPLAY_LABEL_RE.test(value.trim());
18
+ }
19
+
20
+ /**
21
+ * Convert a pi TUI display label (`model [provider]`) to canonical `provider/model`.
22
+ * Returns null when the input does not match the display label pattern.
23
+ *
24
+ * @param {string} value
25
+ * @returns {string|null}
26
+ */
27
+ export function displayLabelToCanonical(value) {
28
+ if (typeof value !== "string") return null;
29
+ const match = value.trim().match(DISPLAY_LABEL_RE);
30
+ if (!match) return null;
31
+ return `${match[2]}/${match[1]}`;
32
+ }
33
+
34
+ /**
35
+ * @param {string} value
36
+ * @returns {boolean}
37
+ */
38
+ export function isCanonicalModelId(value) {
39
+ if (typeof value !== "string") return false;
40
+ return CANONICAL_RE.test(value.trim());
41
+ }
42
+
43
+ /**
44
+ * Normalize a model id for `spine settings set`.
45
+ * Display labels are converted to canonical form; canonical ids pass through;
46
+ * special values (`inherit`, empty) pass through.
47
+ *
48
+ * @param {string} value
49
+ * @returns {{ ok: true, value: string } | { ok: false, error: string }}
50
+ */
51
+ export function normalizeModelId(value) {
52
+ if (typeof value !== "string") {
53
+ return { ok: false, error: "Model id must be a string" };
54
+ }
55
+
56
+ const trimmed = value.trim();
57
+ if (SPECIAL_VALUES.has(trimmed)) {
58
+ return { ok: true, value: trimmed };
59
+ }
60
+
61
+ if (isCanonicalModelId(trimmed)) {
62
+ return { ok: true, value: trimmed };
63
+ }
64
+
65
+ const canonical = displayLabelToCanonical(trimmed);
66
+ if (canonical) {
67
+ return { ok: true, value: canonical };
68
+ }
69
+
70
+ return {
71
+ ok: false,
72
+ error: `Invalid model id "${trimmed}". Use canonical provider/model format (e.g. google/gemini-3.1-pro-preview). Run \`pi --list-models\` for available ids.`,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Validate that a model id already stored in config is canonical.
78
+ * Used by doctor checks — flags display labels and unrecognized formats.
79
+ *
80
+ * @param {string} value
81
+ * @returns {{ ok: true } | { ok: false, error: string, canonical?: string, suggestedCommand?: string }}
82
+ */
83
+ export function validateModelIdFormat(value) {
84
+ if (typeof value !== "string") return { ok: true };
85
+ const trimmed = value.trim();
86
+ if (SPECIAL_VALUES.has(trimmed)) return { ok: true };
87
+
88
+ if (isCanonicalModelId(trimmed)) return { ok: true };
89
+
90
+ const canonical = displayLabelToCanonical(trimmed);
91
+ if (canonical) {
92
+ return {
93
+ ok: false,
94
+ error: `display label "${trimmed}" — use canonical id ${canonical}`,
95
+ canonical,
96
+ };
97
+ }
98
+
99
+ return {
100
+ ok: false,
101
+ error: `invalid model id "${trimmed}" — expected provider/model format`,
102
+ };
103
+ }
@@ -40,6 +40,7 @@ export const SPINE_INIT_TESTING_COMMAND = "npm run typecheck && npm test";
40
40
  export const SPINE_INIT_COVERAGE_COMMAND = "npm run coverage:check";
41
41
 
42
42
  export const SPINE_GITIGNORE_ENTRIES = [
43
+ ".pi/",
43
44
  ".spine/runtime/",
44
45
  ".spine/batch-state.json",
45
46
  ".spine/batch-history.json",
@@ -36,6 +36,24 @@ export const ORCH_MULTI_FILE_MERGE_RISK_PATHS = Object.freeze([
36
36
  const LIMBO_DIAGNOSES = new Set(["limbo_stale", "completed_manual"]);
37
37
  const DEPENDENCIES_SCHEMA_VERSION = 1;
38
38
  const TASK_ID_PATTERN = /^[A-Z]{2,}-\d{3,}$/;
39
+ const PI_SESSION_METADATA_PREFIX = ".pi/";
40
+
41
+ /**
42
+ * Pi session metadata under `.pi/` is not project source (issue #81).
43
+ *
44
+ * @param {string} relPath
45
+ */
46
+ export function isPiSessionMetadataPath(relPath) {
47
+ const normalized = String(relPath).replace(/\\/g, "/").replace(/^\.\/+/, "");
48
+ return normalized === ".pi" || normalized.startsWith(PI_SESSION_METADATA_PREFIX);
49
+ }
50
+
51
+ /**
52
+ * @param {string[]} dirtyPaths
53
+ */
54
+ export function filterPiSessionDirtyPaths(dirtyPaths) {
55
+ return dirtyPaths.filter((relPath) => !isPiSessionMetadataPath(relPath));
56
+ }
39
57
 
40
58
  /**
41
59
  * @param {object} ctx
@@ -177,12 +195,16 @@ export function checkGitClean(ctx) {
177
195
  });
178
196
  }
179
197
 
180
- const dirtyPaths = output
198
+ const allDirtyPaths = output
181
199
  .split(/\r?\n/)
182
200
  .filter(Boolean)
183
201
  .map((line) => line.slice(3).trim() || line.trim());
202
+ const dirtyPaths = filterPiSessionDirtyPaths(allDirtyPaths);
184
203
 
185
204
  if (dirtyPaths.length === 0) {
205
+ if (allDirtyPaths.length > 0) {
206
+ return makeCheck("git-clean", true, "working tree clean (.pi/ session metadata ignored)");
207
+ }
186
208
  return makeCheck("git-clean", true, "working tree clean");
187
209
  }
188
210
 
@@ -194,8 +194,8 @@ function appendLaneTextCell(td, text, className, ariaLabel) {
194
194
  td.setAttribute("aria-label", ariaLabel);
195
195
  }
196
196
 
197
- /** @param {ReturnType<typeof buildDashboardViewModel>["lanes"]} lanes @param {ReturnType<typeof buildDashboardViewModel>["laneTableSummary"]} laneTableSummary @param {string|null} expandedLaneId */
198
- function renderLanes(lanes, laneTableSummary, expandedLaneId) {
197
+ /** @param {ReturnType<typeof buildDashboardViewModel>["lanes"]} lanes @param {ReturnType<typeof buildDashboardViewModel>["laneTableSummary"]} laneTableSummary @param {ReturnType<typeof buildDashboardViewModel>["tailActivity"]} tailActivity @param {string|null} expandedLaneId */
198
+ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
199
199
  const tbody = $("lane-table-body");
200
200
  tbody.replaceChildren();
201
201
  const columnCount = 11;
@@ -311,6 +311,17 @@ function renderLanes(lanes, laneTableSummary, expandedLaneId) {
311
311
  });
312
312
  tbody.appendChild(tr);
313
313
  }
314
+ if (tailActivity?.visible && tailActivity.tailActivityLabel) {
315
+ const tr = document.createElement("tr");
316
+ tr.className = "lane-table-tail-activity";
317
+ const td = document.createElement("td");
318
+ td.colSpan = columnCount;
319
+ td.className = "empty-hint lane-tail-activity";
320
+ td.textContent = tailActivity.tailActivityLabel;
321
+ td.setAttribute("aria-label", `Batch activity: ${tailActivity.tailActivityLabel}`);
322
+ tr.appendChild(td);
323
+ tbody.appendChild(tr);
324
+ }
314
325
  }
315
326
 
316
327
  /** @param {ReturnType<typeof buildDashboardViewModel>["lanes"][number]} lane */
@@ -485,7 +496,7 @@ export function renderSnapshot(snapshot) {
485
496
  if (!vm.idle) {
486
497
  renderBatch(vm.batch);
487
498
  renderWaves(vm.waves);
488
- renderLanes(vm.lanes, vm.laneTableSummary, expandedLaneIdState);
499
+ renderLanes(vm.lanes, vm.laneTableSummary, vm.tailActivity, expandedLaneIdState);
489
500
  renderJournalLaneFilter(vm.journalLaneFilterOptions);
490
501
  renderJournal(vm.journal);
491
502
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Running tail-state detection for dashboard + batch headlines (GitHub #68).
3
+ * Browser-safe — no Node or batch-layer imports.
4
+ */
5
+
6
+ /**
7
+ * @param {object} ctx
8
+ * @returns {boolean}
9
+ */
10
+ export function isRunningWithoutActiveWorkers(ctx = {}) {
11
+ if (ctx.hasRunningTasks === true || ctx.hasPendingTasks === true) {
12
+ return false;
13
+ }
14
+ if ((ctx.pendingTaskCount ?? 0) > 0) {
15
+ return false;
16
+ }
17
+ const totalTasks = ctx.totalTasks ?? 0;
18
+ if (totalTasks <= 0) {
19
+ return false;
20
+ }
21
+ const succeededTasks = ctx.succeededTasks ?? 0;
22
+ const failedTasks = ctx.failedTasks ?? 0;
23
+ if (succeededTasks + failedTasks < totalTasks) {
24
+ return false;
25
+ }
26
+ const phase = ctx.phase ?? "";
27
+ if (phase !== "running" && phase !== "merging") {
28
+ return false;
29
+ }
30
+ return true;
31
+ }
@@ -25,6 +25,10 @@ const STATIC_ROUTES = {
25
25
  file: path.join("..", "lane-throughput.mjs"),
26
26
  contentType: "text/javascript; charset=utf-8",
27
27
  },
28
+ "/running-tail-state.mjs": {
29
+ file: path.join("..", "running-tail-state.mjs"),
30
+ contentType: "text/javascript; charset=utf-8",
31
+ },
28
32
  };
29
33
 
30
34
  /**