pi-spine 1.4.0 → 1.6.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 (36) hide show
  1. package/bin/spine-batch.mjs +3 -2
  2. package/bin/spine.mjs +12 -0
  3. package/extensions/spine/slash-commands.ts +170 -1
  4. package/package.json +6 -3
  5. package/skills/create-spine-tasks/SKILL.md +13 -1
  6. package/skills/create-spine-tasks/references/contract-template.md +6 -3
  7. package/skills/create-spine-tasks/references/requirements-checklist-template.md +1 -0
  8. package/skills/spine-orchestrate-waves/SKILL.md +200 -0
  9. package/skills/spine-orchestrate-waves/references/outer-loop.md +165 -0
  10. package/skills/spine-release-operator/SKILL.md +341 -0
  11. package/skills/spine-release-operator/references/issue-intake-checklist.md +107 -0
  12. package/skills/spine-release-operator/references/issue-template.md +51 -0
  13. package/skills/spine-release-operator/references/release-manifest-template.md +76 -0
  14. package/skills/spine-release-operator/references/release-profiles.md +100 -0
  15. package/src/batch/batch-state-io.mjs +137 -0
  16. package/src/batch/contract-prelanded.mjs +116 -14
  17. package/src/batch/contract-verify.mjs +48 -2
  18. package/src/batch/diagnosis-alternatives.mjs +8 -0
  19. package/src/batch/diagnosis.mjs +28 -2
  20. package/src/batch/engine-lanes/commit.mjs +6 -0
  21. package/src/batch/engine.mjs +10 -1
  22. package/src/batch/integrate-worktree.mjs +65 -15
  23. package/src/batch/lane-dirty-check.mjs +124 -0
  24. package/src/batch/lifecycle.mjs +10 -6
  25. package/src/batch/reconcile.mjs +254 -0
  26. package/src/batch/sequence-waves.mjs +221 -0
  27. package/src/batch/sequence.mjs +117 -4
  28. package/src/batch/state.mjs +18 -1
  29. package/src/cli/batch-complete.mjs +16 -0
  30. package/src/cli/sync-base.mjs +354 -0
  31. package/src/config/defaults.mjs +8 -1
  32. package/src/config/spine-preflight-lib.mjs +146 -2
  33. package/src/doctor/agents-model-inherit.mjs +318 -0
  34. package/src/doctor/run-doctor-checks.mjs +14 -0
  35. package/templates/spine-config.json +4 -0
  36. package/templates/spine-worktree-setup-flutter.sh +44 -0
@@ -0,0 +1,318 @@
1
+ /**
2
+ * Doctor check: probe pi provider credentials when spine agents inherit pi model (SP-460 / #97).
3
+ */
4
+
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { spawnSync } from "node:child_process";
8
+
9
+ import { commandExists } from "../util/command-exists.mjs";
10
+ import {
11
+ readPiSettingsFile,
12
+ resolvePiDefaultProvider,
13
+ spineAgentsUseInherit,
14
+ } from "./agent-model-inherit.mjs";
15
+
16
+ export const CURSOR_PROVIDER = "cursor";
17
+ export const LMSTUDIO_PROVIDER = "lmstudio";
18
+
19
+ const LIST_MODELS_TIMEOUT_MS = 30_000;
20
+ const AUTH_PROBE_TIMEOUT_MS = 15_000;
21
+
22
+ const SUGGESTED_PIN =
23
+ "spine settings set agents.worker.model cursor/auto && spine settings set agents.reviewer.model cursor/auto";
24
+
25
+ /** @type {readonly RegExp[]} */
26
+ const AUTH_ERROR_PATTERNS = Object.freeze([
27
+ /authentication_error/i,
28
+ /\b401\b/,
29
+ /invalid api key/i,
30
+ /no api key found/i,
31
+ /api key.*invalid/i,
32
+ /credentials.*expired/i,
33
+ /unauthorized/i,
34
+ ]);
35
+
36
+ /**
37
+ * @param {unknown} text
38
+ * @returns {boolean}
39
+ */
40
+ export function isAuthErrorText(text) {
41
+ const combined = String(text ?? "");
42
+ return AUTH_ERROR_PATTERNS.some((pattern) => pattern.test(combined));
43
+ }
44
+
45
+ /**
46
+ * @param {unknown} output
47
+ * @returns {Array<{ provider: string, id: string }>}
48
+ */
49
+ export function parsePiListModelsRows(output) {
50
+ const lines = String(output ?? "").split(/\r?\n/).filter(Boolean);
51
+ let providerCol = 0;
52
+ let modelCol = 1;
53
+ let headerSeen = false;
54
+ /** @type {Array<{ provider: string, id: string }>} */
55
+ const rows = [];
56
+
57
+ for (const line of lines) {
58
+ const trimmed = line.trim();
59
+ if (!headerSeen && /^provider\b/i.test(trimmed)) {
60
+ headerSeen = true;
61
+ const lowerHeader = trimmed.toLowerCase().split(/\s+/);
62
+ const providerIdx = lowerHeader.indexOf("provider");
63
+ const modelIdx = lowerHeader.indexOf("model");
64
+ if (providerIdx >= 0) providerCol = providerIdx;
65
+ if (modelIdx >= 0) modelCol = modelIdx;
66
+ continue;
67
+ }
68
+ if (!headerSeen) {
69
+ continue;
70
+ }
71
+
72
+ const parts = trimmed.split(/\s+/);
73
+ const provider = String(parts[providerCol] ?? parts[0] ?? "").trim().toLowerCase();
74
+ const id = String(parts[modelCol] ?? parts[1] ?? "").trim();
75
+ if (!provider || !id) {
76
+ continue;
77
+ }
78
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(provider)) {
79
+ continue;
80
+ }
81
+ if (!/^[a-z0-9][a-z0-9._@-]*$/i.test(id)) {
82
+ continue;
83
+ }
84
+ rows.push({ provider, id });
85
+ }
86
+
87
+ return rows;
88
+ }
89
+
90
+ /**
91
+ * @param {unknown} output
92
+ * @param {unknown} providerName
93
+ * @returns {Array<{ provider: string, id: string }>}
94
+ */
95
+ export function listModelsForProvider(output, providerName) {
96
+ const normalized = String(providerName ?? "").trim().toLowerCase();
97
+ return parsePiListModelsRows(output).filter((row) => row.provider === normalized);
98
+ }
99
+
100
+ /**
101
+ * @param {string} projectRoot
102
+ * @param {object} [options]
103
+ * @param {string} [options.globalSettingsPath]
104
+ * @param {string} [options.projectSettingsPath]
105
+ * @returns {string|null}
106
+ */
107
+ export function resolvePiDefaultModel(
108
+ projectRoot,
109
+ { globalSettingsPath, projectSettingsPath } = {},
110
+ ) {
111
+ const globalPath =
112
+ globalSettingsPath ?? path.join(os.homedir(), ".pi", "agent", "settings.json");
113
+ const projectPath = projectSettingsPath ?? path.join(projectRoot, ".pi", "settings.json");
114
+ const global = readPiSettingsFile(globalPath);
115
+ const project = readPiSettingsFile(projectPath);
116
+ const model = project?.defaultModel ?? global?.defaultModel;
117
+ if (typeof model !== "string" || !model.trim()) {
118
+ return null;
119
+ }
120
+ return model.trim();
121
+ }
122
+
123
+ /**
124
+ * @param {string|null} defaultModel
125
+ * @param {string} provider
126
+ * @param {Array<{ provider: string, id: string }>} listedModels
127
+ * @returns {string|null}
128
+ */
129
+ export function resolveModelIdForProvider(defaultModel, provider, listedModels) {
130
+ if (defaultModel) {
131
+ const slashIdx = defaultModel.indexOf("/");
132
+ if (slashIdx >= 0) {
133
+ const modelProvider = defaultModel.slice(0, slashIdx).toLowerCase();
134
+ const modelId = defaultModel.slice(slashIdx + 1);
135
+ if (modelProvider === provider.toLowerCase() && modelId) {
136
+ return modelId;
137
+ }
138
+ } else if (listedModels.some((entry) => entry.id === defaultModel)) {
139
+ return defaultModel;
140
+ }
141
+ }
142
+ return listedModels[0]?.id ?? null;
143
+ }
144
+
145
+ /**
146
+ * @param {string[]} args
147
+ * @param {object} [options]
148
+ * @param {typeof spawnSync} [options.spawnFn]
149
+ * @param {number} [options.timeoutMs]
150
+ */
151
+ export function runPiCommand(args, { spawnFn = spawnSync, timeoutMs = LIST_MODELS_TIMEOUT_MS } = {}) {
152
+ const result = spawnFn("pi", args, {
153
+ encoding: "utf-8",
154
+ stdio: ["ignore", "pipe", "pipe"],
155
+ timeout: timeoutMs,
156
+ });
157
+ return {
158
+ stdout: `${result?.stdout ?? ""}`,
159
+ stderr: `${result?.stderr ?? ""}`,
160
+ status: result?.status ?? 1,
161
+ error: result?.error ?? null,
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Lightweight auth probe for the pi provider spine agents inherit at worker spawn.
167
+ *
168
+ * @param {string} provider
169
+ * @param {object} [options]
170
+ * @param {string} [options.projectRoot]
171
+ * @param {typeof spawnSync} [options.spawnFn]
172
+ * @param {string} [options.globalSettingsPath]
173
+ * @param {string} [options.projectSettingsPath]
174
+ * @returns {{ ok: boolean, detail: string }}
175
+ */
176
+ export function probeInheritProviderAuth(
177
+ provider,
178
+ {
179
+ projectRoot = process.cwd(),
180
+ spawnFn = spawnSync,
181
+ globalSettingsPath,
182
+ projectSettingsPath,
183
+ } = {},
184
+ ) {
185
+ const normalizedProvider = String(provider ?? "").trim().toLowerCase();
186
+ if (!normalizedProvider) {
187
+ return { ok: false, detail: "pi default provider unset" };
188
+ }
189
+ if (normalizedProvider === CURSOR_PROVIDER) {
190
+ return { ok: true, detail: "cursor provider uses Cursor IDE auth" };
191
+ }
192
+ if (normalizedProvider === LMSTUDIO_PROVIDER) {
193
+ return { ok: true, detail: "lmstudio uses local server auth" };
194
+ }
195
+
196
+ if (!commandExists("pi")) {
197
+ return { ok: false, detail: "pi not installed" };
198
+ }
199
+
200
+ const listResult = runPiCommand(["--list-models"], { spawnFn });
201
+ const listOutput = `${listResult.stdout}\n${listResult.stderr}`;
202
+ if (listResult.error) {
203
+ return { ok: false, detail: listResult.error.message };
204
+ }
205
+
206
+ const models = listModelsForProvider(listOutput, normalizedProvider);
207
+ if (models.length === 0) {
208
+ return {
209
+ ok: false,
210
+ detail: `no authenticated models for provider ${normalizedProvider} — run pi login or configure API keys`,
211
+ };
212
+ }
213
+
214
+ const defaultModel = resolvePiDefaultModel(projectRoot, {
215
+ globalSettingsPath,
216
+ projectSettingsPath,
217
+ });
218
+ const modelId = resolveModelIdForProvider(defaultModel, normalizedProvider, models);
219
+ if (!modelId) {
220
+ return {
221
+ ok: false,
222
+ detail: `could not resolve model id for provider ${normalizedProvider}`,
223
+ };
224
+ }
225
+
226
+ const probeResult = runPiCommand(
227
+ ["--provider", normalizedProvider, "--model", modelId, "--no-session", "-p", "ok"],
228
+ { spawnFn, timeoutMs: AUTH_PROBE_TIMEOUT_MS },
229
+ );
230
+ const probeOutput = `${probeResult.stdout}\n${probeResult.stderr}`;
231
+ if (isAuthErrorText(probeOutput)) {
232
+ return {
233
+ ok: false,
234
+ detail: `provider ${normalizedProvider} credentials rejected (authentication_error)`,
235
+ };
236
+ }
237
+ if (probeResult.error) {
238
+ return { ok: false, detail: probeResult.error.message };
239
+ }
240
+ if (probeResult.status !== 0) {
241
+ return {
242
+ ok: true,
243
+ detail: `provider ${normalizedProvider}/${modelId} probe inconclusive (exit ${probeResult.status})`,
244
+ };
245
+ }
246
+
247
+ return {
248
+ ok: true,
249
+ detail: `${normalizedProvider}/${modelId} credentials OK`,
250
+ };
251
+ }
252
+
253
+ /**
254
+ * @param {object} params
255
+ * @param {object} [params.config]
256
+ * @param {string} [params.projectRoot]
257
+ * @param {() => string|null} [params.resolveProvider]
258
+ * @param {typeof probeInheritProviderAuth} [params.probeAuth]
259
+ */
260
+ export function buildInheritProviderAuthDoctorCheck({
261
+ config = {},
262
+ projectRoot = process.cwd(),
263
+ resolveProvider,
264
+ probeAuth = probeInheritProviderAuth,
265
+ } = {}) {
266
+ if (!spineAgentsUseInherit(config)) {
267
+ return {
268
+ label: "agents inherit provider auth",
269
+ ok: true,
270
+ detail: "agents pinned — inherit provider auth not applicable",
271
+ };
272
+ }
273
+
274
+ const provider = resolveProvider
275
+ ? resolveProvider()
276
+ : resolvePiDefaultProvider(projectRoot);
277
+ if (!provider) {
278
+ return {
279
+ label: "agents inherit provider auth",
280
+ ok: true,
281
+ warning: true,
282
+ detail: "inherit active but pi defaultProvider unset — workers may fail at spawn",
283
+ suggestedCommand: SUGGESTED_PIN,
284
+ };
285
+ }
286
+
287
+ if (provider === CURSOR_PROVIDER) {
288
+ return {
289
+ label: "agents inherit provider auth",
290
+ ok: true,
291
+ detail: "inherit resolves to cursor — Cursor IDE auth",
292
+ };
293
+ }
294
+
295
+ if (provider === LMSTUDIO_PROVIDER) {
296
+ return {
297
+ label: "agents inherit provider auth",
298
+ ok: true,
299
+ detail: "inherit resolves to lmstudio — see agents model inherit (pi-lmstudio) check",
300
+ };
301
+ }
302
+
303
+ const probe = probeAuth(provider, { projectRoot });
304
+ if (!probe.ok) {
305
+ return {
306
+ label: "agents inherit provider auth",
307
+ ok: false,
308
+ detail: `inherit + pi defaultProvider ${provider} — ${probe.detail}`,
309
+ suggestedCommand: `pi login (refresh ${provider} credentials) or ${SUGGESTED_PIN}`,
310
+ };
311
+ }
312
+
313
+ return {
314
+ label: "agents inherit provider auth",
315
+ ok: true,
316
+ detail: `inherit + pi defaultProvider ${provider} — ${probe.detail}`,
317
+ };
318
+ }
@@ -15,6 +15,7 @@ import {
15
15
  } from "./suggest-max-parallel.mjs";
16
16
  import { buildStalePathDoctorCheck } from "./stale-path.mjs";
17
17
  import { buildCoexistenceDoctorCheck } from "./coexistence.mjs";
18
+ import { buildConcurrentDevDoctorCheck } from "../config/spine-preflight-lib.mjs";
18
19
  import { buildTaskPacketSizeDoctorCheck } from "./task-packet-size.mjs";
19
20
  import {
20
21
  buildPiWorkerTimeoutDoctorCheck,
@@ -25,6 +26,7 @@ import { buildWorktreeHealthDoctorCheck } from "./worktree-health.mjs";
25
26
  import { buildStaleWorktreesDoctorCheck } from "./stale-worktrees.mjs";
26
27
  import { buildWorkerBackendDoctorCheck } from "../config/worker-backend.mjs";
27
28
  import { buildAgentModelInheritDoctorCheck, buildReviewerPerTypePinsDoctorCheck } from "./agent-model-inherit.mjs";
29
+ import { buildInheritProviderAuthDoctorCheck } from "./agents-model-inherit.mjs";
28
30
  import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
29
31
  import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
30
32
  import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
@@ -355,6 +357,12 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
355
357
  config: configResult.config,
356
358
  projectRoot,
357
359
  }));
360
+ const inheritAuthCheck = buildInheritProviderAuthDoctorCheck({
361
+ config: configResult.config,
362
+ projectRoot,
363
+ });
364
+ checks.push(inheritAuthCheck);
365
+ if (!inheritAuthCheck.ok) issueCount++;
358
366
  const modelIdsCheck = buildAgentModelIdsDoctorCheck({ config: configResult.config });
359
367
  checks.push(modelIdsCheck);
360
368
  if (!modelIdsCheck.ok) issueCount++;
@@ -370,6 +378,12 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
370
378
  for (const testingCheck of buildTestingEvidenceDoctorChecks(configResult.config)) {
371
379
  checks.push(testingCheck);
372
380
  }
381
+ const concurrentDevCheck = buildConcurrentDevDoctorCheck({
382
+ projectRoot,
383
+ config: configResult.config,
384
+ });
385
+ checks.push(concurrentDevCheck);
386
+ if (!concurrentDevCheck.ok) issueCount++;
373
387
  }
374
388
 
375
389
  for (const agentFile of REQUIRED_AGENT_FILES) {
@@ -47,6 +47,10 @@
47
47
  "collectBuildEvidence": true,
48
48
  "collectTestEvidence": true
49
49
  },
50
+ "integrate": {
51
+ "isolatedWorktree": true,
52
+ "allowHumanOnBaseBranch": "warn"
53
+ },
50
54
  "review": {
51
55
  "requireFinalVerdict": true,
52
56
  "maxFinalAttempts": 3
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # Optional worktreeSetupHook for Flutter repos with gitignored pubspec assets (#80)
3
+ # and build/ analyzer pollution (#78). Copy to scripts/ and customize paths.
4
+ #
5
+ # Wire in .spine/spine-config.json:
6
+ # "worktreeSetupHook": "scripts/spine-worktree-setup-flutter.sh"
7
+ #
8
+ # pi-spine runs this once per lane (cwd = lane worktree, 120s timeout).
9
+ # Last stdout line MUST be JSON: {"ok":true}
10
+
11
+ set -euo pipefail
12
+
13
+ ROOT="${SPINE_PROJECT_ROOT:?SPINE_PROJECT_ROOT unset — hook must run from spine batch engine}"
14
+ WT="$(pwd)"
15
+
16
+ # Edit: space-separated paths relative to repo root (gitignored assets in pubspec.yaml).
17
+ GITIGNORED_ASSET_PATHS=(
18
+ "assets/bundled_skins"
19
+ "assets/plugins/dye2.reaplugin"
20
+ )
21
+
22
+ # Remove stale build artifacts so flutter analyze does not scan SourcePackages pollution (#78).
23
+ CLEAN_BUILD_DIR=true
24
+
25
+ link_asset() {
26
+ local rel="$1"
27
+ local src="${ROOT}/${rel}"
28
+ local dest="${WT}/${rel}"
29
+ if [[ -e "$src" ]]; then
30
+ mkdir -p "$(dirname "$dest")"
31
+ rm -f "$dest"
32
+ ln -s "$src" "$dest"
33
+ fi
34
+ }
35
+
36
+ if [[ "$CLEAN_BUILD_DIR" == "true" ]]; then
37
+ rm -rf build
38
+ fi
39
+
40
+ for rel in "${GITIGNORED_ASSET_PATHS[@]}"; do
41
+ link_asset "$rel"
42
+ done
43
+
44
+ echo '{"ok":true}'