pi-spine 2.26.0 → 2.27.1
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.
- package/README.md +1 -1
- package/bin/spine-review-step.mjs +8 -1
- package/bin/spine-worker-runner.mjs +15 -1
- package/package.json +3 -3
- package/skills/create-spine-tasks/SKILL.md +60 -33
- package/skills/create-spine-tasks/references/authoring-evidence.md +58 -0
- package/skills/create-spine-tasks/references/contract-template.md +52 -7
- package/skills/create-spine-tasks/references/prompt-template.md +72 -8
- package/skills/spine-release-operator/SKILL.md +33 -51
- package/skills/spine-release-operator/references/issue-intake-checklist.md +3 -1
- package/skills/spine-release-operator/references/pi-async-orchestration.md +13 -9
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +8 -1
- package/skills/spine-release-operator/references/publish-recovery.md +62 -0
- package/src/batch/batch-meta-reconstruct.mjs +3 -0
- package/src/batch/contract-exec.mjs +2 -2
- package/src/batch/contract-parse.mjs +2 -2
- package/src/batch/contract-prelanded.mjs +2 -2
- package/src/batch/diagnosis-alternatives.mjs +16 -1
- package/src/batch/diagnosis-handoff-packet.mjs +74 -0
- package/src/batch/diagnosis-pending-lane.mjs +52 -1
- package/src/batch/diagnosis-review-infra.mjs +144 -0
- package/src/batch/diagnosis-suggested-command.mjs +9 -0
- package/src/batch/diagnosis.mjs +19 -20
- package/src/batch/engine-lanes/merge.mjs +0 -8
- package/src/batch/engine-lanes/quota-fallback-run.mjs +153 -0
- package/src/batch/engine-lanes/quota-fallback-state.mjs +202 -0
- package/src/batch/engine-lanes/review-code.mjs +1 -0
- package/src/batch/engine-lanes/review-final.mjs +83 -46
- package/src/batch/engine-lanes/review-plan.mjs +22 -2
- package/src/batch/engine-lanes/review-poll.mjs +51 -2
- package/src/batch/engine-lanes.mjs +6 -8
- package/src/batch/gate-posture-approve.mjs +154 -15
- package/src/batch/integrate-path-delete.mjs +85 -0
- package/src/batch/integrate-worktree.mjs +20 -27
- package/src/batch/journal.mjs +15 -0
- package/src/batch/metrics.mjs +13 -1
- package/src/batch/provider-quota.mjs +220 -0
- package/src/batch/quota-fallback.mjs +319 -0
- package/src/batch/reconcile-diagnosis-context.mjs +22 -0
- package/src/batch/reconcile-diagnosis.mjs +24 -77
- package/src/batch/resume-multi-queue.mjs +25 -10
- package/src/batch/review-artifacts.mjs +96 -17
- package/src/batch/review-level-effective.mjs +19 -0
- package/src/batch/review-spawn-retry.mjs +106 -0
- package/src/batch/review-spawn.mjs +60 -3
- package/src/batch/review-step-run.mjs +110 -8
- package/src/batch/reviewer-output.mjs +162 -0
- package/src/batch/reviewer-provider-error.mjs +153 -0
- package/src/batch/worker-host.mjs +49 -3
- package/src/batch/worker-prompt.mjs +5 -2
- package/src/config/cursor-rules/discover.mjs +40 -3
- package/src/config/cursor-rules/match-globs.mjs +6 -4
- package/src/config/env-overrides.mjs +41 -4
- package/src/config/settings-fields.mjs +11 -0
- package/src/config/spine-config-schema.mjs +62 -0
- package/src/doctor/pi-extension-hooks.mjs +322 -0
- package/src/doctor/quota-risk.mjs +45 -0
- package/src/doctor/run-doctor-checks.mjs +14 -1
- package/src/planner/file-scope.mjs +6 -6
- package/src/tasks/packet/validate-contract.mjs +3 -3
- package/src/tasks/packet/validate-prompt.mjs +11 -1
- package/src/tasks/validate-contract-warn.mjs +16 -0
- package/templates/spine-config.json +1 -1
|
@@ -86,6 +86,11 @@ export const SETTINGS_FIELDS = Object.freeze([
|
|
|
86
86
|
type: "enum",
|
|
87
87
|
enum: ["off", "low", "medium", "high", "inherit"],
|
|
88
88
|
},
|
|
89
|
+
{
|
|
90
|
+
path: "agents.reviewer.loadUserExtensions",
|
|
91
|
+
label: "Reviewer loads user pi extensions",
|
|
92
|
+
type: "boolean",
|
|
93
|
+
},
|
|
89
94
|
{
|
|
90
95
|
path: "agents.reviewer.plan.model",
|
|
91
96
|
label: "Plan reviewer model",
|
|
@@ -151,6 +156,12 @@ export const SETTINGS_FIELDS = Object.freeze([
|
|
|
151
156
|
type: "string",
|
|
152
157
|
optional: true,
|
|
153
158
|
},
|
|
159
|
+
{
|
|
160
|
+
path: "agents.quotaFallbackProfile",
|
|
161
|
+
label: "Quota fallback agent model profile",
|
|
162
|
+
type: "string",
|
|
163
|
+
optional: true,
|
|
164
|
+
},
|
|
154
165
|
{
|
|
155
166
|
path: "dashboard.port",
|
|
156
167
|
label: "Dashboard port",
|
|
@@ -235,6 +235,31 @@ function validateAgentSectionModelTypes(agents, label) {
|
|
|
235
235
|
return null;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* SP-819 / #334: type-check `reviewer.loadUserExtensions` (boolean, default false) wherever
|
|
240
|
+
* a reviewer section appears: the base `agents.reviewer` and any
|
|
241
|
+
* `agents.profiles.<name>.reviewer`. Absent values are valid (defaults to false).
|
|
242
|
+
*
|
|
243
|
+
* @param {any} reviewer A reviewer-shaped section (may be undefined or a non-object).
|
|
244
|
+
* @param {string} label Dotted path used in the error message.
|
|
245
|
+
* @param {string} suggestedCommand Repair hint shown to the operator.
|
|
246
|
+
* @returns {null | { code: string; message: string; suggestedCommand: string }}
|
|
247
|
+
*/
|
|
248
|
+
function validateReviewerLoadUserExtensions(reviewer, label, suggestedCommand) {
|
|
249
|
+
if (
|
|
250
|
+
isPlainObject(reviewer) &&
|
|
251
|
+
reviewer.loadUserExtensions != null &&
|
|
252
|
+
typeof reviewer.loadUserExtensions !== "boolean"
|
|
253
|
+
) {
|
|
254
|
+
return {
|
|
255
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
256
|
+
message: `${label}.loadUserExtensions must be a boolean when set`,
|
|
257
|
+
suggestedCommand,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
238
263
|
/**
|
|
239
264
|
* Validate `agents.profiles`, `agents.activeProfile`, and `agents.escalatePolicy`.
|
|
240
265
|
*
|
|
@@ -251,6 +276,13 @@ export function validateAgentProfilesConfig(config) {
|
|
|
251
276
|
return null;
|
|
252
277
|
}
|
|
253
278
|
|
|
279
|
+
const reviewerLoadError = validateReviewerLoadUserExtensions(
|
|
280
|
+
agents.reviewer,
|
|
281
|
+
"agents.reviewer",
|
|
282
|
+
"spine settings set agents.reviewer.loadUserExtensions false",
|
|
283
|
+
);
|
|
284
|
+
if (reviewerLoadError) return reviewerLoadError;
|
|
285
|
+
|
|
254
286
|
const profiles = agents.profiles;
|
|
255
287
|
if (profiles != null) {
|
|
256
288
|
if (!isPlainObject(profiles)) {
|
|
@@ -270,6 +302,12 @@ export function validateAgentProfilesConfig(config) {
|
|
|
270
302
|
}
|
|
271
303
|
const shapeError = validateAgentSectionModelTypes(profile, `agents.profiles.${name}`);
|
|
272
304
|
if (shapeError) return shapeError;
|
|
305
|
+
const profileReviewerError = validateReviewerLoadUserExtensions(
|
|
306
|
+
profile.reviewer,
|
|
307
|
+
`agents.profiles.${name}.reviewer`,
|
|
308
|
+
"spine init --force",
|
|
309
|
+
);
|
|
310
|
+
if (profileReviewerError) return profileReviewerError;
|
|
273
311
|
}
|
|
274
312
|
}
|
|
275
313
|
|
|
@@ -296,6 +334,30 @@ export function validateAgentProfilesConfig(config) {
|
|
|
296
334
|
}
|
|
297
335
|
}
|
|
298
336
|
|
|
337
|
+
// SP-805 / #329: profile used when quota fallback kicks in; same membership rule as activeProfile.
|
|
338
|
+
const quotaFallbackProfile = agents.quotaFallbackProfile;
|
|
339
|
+
if (quotaFallbackProfile != null) {
|
|
340
|
+
if (typeof quotaFallbackProfile !== "string") {
|
|
341
|
+
return {
|
|
342
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
343
|
+
message: "agents.quotaFallbackProfile must be a string when set",
|
|
344
|
+
suggestedCommand: "spine settings set agents.quotaFallbackProfile default",
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const fallbackTarget = quotaFallbackProfile.trim();
|
|
348
|
+
// An empty string unsets the fallback profile; otherwise it must name a real profile.
|
|
349
|
+
if (
|
|
350
|
+
fallbackTarget !== "" &&
|
|
351
|
+
(!isPlainObject(profiles) || !Object.prototype.hasOwnProperty.call(profiles, fallbackTarget))
|
|
352
|
+
) {
|
|
353
|
+
return {
|
|
354
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
355
|
+
message: `agents.quotaFallbackProfile "${fallbackTarget}" does not match a defined agents.profiles entry`,
|
|
356
|
+
suggestedCommand: "spine settings set agents.quotaFallbackProfile default",
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
299
361
|
const escalatePolicy = agents.escalatePolicy;
|
|
300
362
|
if (escalatePolicy != null) {
|
|
301
363
|
if (!isPlainObject(escalatePolicy)) {
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect context-rewriting pi extension hooks (SP-822).
|
|
3
|
+
*
|
|
4
|
+
* Batch workers can pass `pi -ne` to skip user extension discovery, and per
|
|
5
|
+
* SP-819 reviewers do the same unless spine config opts in with
|
|
6
|
+
* `agents.reviewer.loadUserExtensions: true`. When that opt-in is set, a pi
|
|
7
|
+
* package that registers a context-rewriting hook (`context`,
|
|
8
|
+
* `context_with_system`, `before_provider_request`) can silently rewrite what
|
|
9
|
+
* reviewers see. This scanner reports which installed packages register such
|
|
10
|
+
* hooks so doctor can surface an advisory warning. It never hard-fails:
|
|
11
|
+
* extensions are a legitimate feature, so the check is informational with an
|
|
12
|
+
* opt-out config key.
|
|
13
|
+
*
|
|
14
|
+
* Scan scope stays bounded: only packages declared in pi `settings.json`
|
|
15
|
+
* `packages` arrays are inspected (that is the set pi actually loads), and
|
|
16
|
+
* within each package only the entry files named in `package.json` →
|
|
17
|
+
* `pi.extensions` — or, when the manifest declares none, the conventional
|
|
18
|
+
* `extensions/` directory plus root `index.{ts,js,mjs}` files that pi
|
|
19
|
+
* discovers for manifest-less packages.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import fs from "node:fs";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
readPiPackageSources,
|
|
27
|
+
resolvePiAgentDir,
|
|
28
|
+
resolvePiPackageSourcePath,
|
|
29
|
+
} from "./pi-extension-conflict.mjs";
|
|
30
|
+
|
|
31
|
+
/** Hooks that can rewrite the context a reviewer model sees. */
|
|
32
|
+
export const PI_CONTEXT_HOOK_NAMES = Object.freeze([
|
|
33
|
+
"context",
|
|
34
|
+
"context_with_system",
|
|
35
|
+
"before_provider_request",
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/** Max installed packages scanned per run (bounded scan). */
|
|
39
|
+
export const MAX_PI_PACKAGES_SCANNED = 50;
|
|
40
|
+
|
|
41
|
+
/** Max extension entry files scanned per package (bounded scan). */
|
|
42
|
+
export const MAX_PI_EXTENSION_ENTRIES_PER_PACKAGE = 20;
|
|
43
|
+
|
|
44
|
+
/** Max bytes read from a single extension entry file (bounded scan). */
|
|
45
|
+
export const MAX_PI_EXTENSION_SOURCE_BYTES = 512 * 1024;
|
|
46
|
+
|
|
47
|
+
/** File extensions pi treats as extension entry files. */
|
|
48
|
+
const EXTENSION_ENTRY_FILE_PATTERN = /\.(?:ts|js|mjs)$/;
|
|
49
|
+
|
|
50
|
+
/** Conventional root entry files pi discovers when no manifest list exists. */
|
|
51
|
+
const FALLBACK_ROOT_ENTRIES = Object.freeze(["index.ts", "index.js", "index.mjs"]);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Patterns that indicate a context hook registration in an extension source
|
|
55
|
+
* file. All three hooks register through `pi.on("<event>", ...)`, so the
|
|
56
|
+
* patterns match the `.on("<event>"` / `.on('<event>'` call shape (see
|
|
57
|
+
* pi-coding-agent docs/extensions.md, "Events and concurrency"). Matching the
|
|
58
|
+
* call shape avoids false positives on unrelated identifiers that merely
|
|
59
|
+
* mention the event names.
|
|
60
|
+
*
|
|
61
|
+
* @type {ReadonlyArray<{ hook: string, pattern: RegExp }>}
|
|
62
|
+
*/
|
|
63
|
+
const HOOK_PATTERNS = Object.freeze([
|
|
64
|
+
{ hook: "context", pattern: /\.on\(\s*["']context["']/ },
|
|
65
|
+
{ hook: "context_with_system", pattern: /\.on\(\s*["']context_with_system["']/ },
|
|
66
|
+
{ hook: "before_provider_request", pattern: /\.on\(\s*["']before_provider_request["']/ },
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Detect which context-rewriting hooks an extension source registers.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} sourceText Extension entry file contents.
|
|
73
|
+
* @returns {string[]} Hook names in canonical PI_CONTEXT_HOOK_NAMES order.
|
|
74
|
+
*/
|
|
75
|
+
export function scanPiExtensionSourceForContextHooks(sourceText) {
|
|
76
|
+
const text = String(sourceText ?? "");
|
|
77
|
+
const found = new Set();
|
|
78
|
+
for (const { hook, pattern } of HOOK_PATTERNS) {
|
|
79
|
+
if (pattern.test(text)) found.add(hook);
|
|
80
|
+
}
|
|
81
|
+
return PI_CONTEXT_HOOK_NAMES.filter((hook) => found.has(hook));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* List the conventional entry files pi discovers when the manifest declares
|
|
86
|
+
* no `pi.extensions`: files in `extensions/` plus root `index.{ts,js,mjs}`.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} packageDir Absolute path to the package root.
|
|
89
|
+
* @returns {string[]} Entry paths relative to the package root, sorted and
|
|
90
|
+
* capped at MAX_PI_EXTENSION_ENTRIES_PER_PACKAGE.
|
|
91
|
+
*/
|
|
92
|
+
function discoverFallbackExtensionEntries(packageDir) {
|
|
93
|
+
/** @type {string[]} */
|
|
94
|
+
const entries = [];
|
|
95
|
+
const extensionsDir = path.join(packageDir, "extensions");
|
|
96
|
+
try {
|
|
97
|
+
for (const fileName of fs.readdirSync(extensionsDir).sort()) {
|
|
98
|
+
if (!EXTENSION_ENTRY_FILE_PATTERN.test(fileName)) continue;
|
|
99
|
+
if (!fs.statSync(path.join(extensionsDir, fileName)).isFile()) continue;
|
|
100
|
+
entries.push(path.join("extensions", fileName));
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
// No readable extensions/ directory — fall through to root entries.
|
|
104
|
+
}
|
|
105
|
+
for (const rootEntry of FALLBACK_ROOT_ENTRIES) {
|
|
106
|
+
try {
|
|
107
|
+
if (fs.statSync(path.join(packageDir, rootEntry)).isFile()) {
|
|
108
|
+
entries.push(rootEntry);
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
// Missing root entry — skip.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return entries.slice(0, MAX_PI_EXTENSION_ENTRIES_PER_PACKAGE);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Resolve the extension entry files for an installed package: the
|
|
119
|
+
* `package.json` → `pi.extensions` list when present, else the conventional
|
|
120
|
+
* `extensions/` directory and root `index.{ts,js,mjs}` files pi discovers.
|
|
121
|
+
*
|
|
122
|
+
* @param {string} packageDir Absolute path to the package root.
|
|
123
|
+
* @returns {{ name: string, entries: string[] } | null} Null when the package
|
|
124
|
+
* has no extension entries to scan.
|
|
125
|
+
*/
|
|
126
|
+
function readPackageExtensionEntries(packageDir) {
|
|
127
|
+
const manifestPath = path.join(packageDir, "package.json");
|
|
128
|
+
let manifest;
|
|
129
|
+
try {
|
|
130
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
131
|
+
} catch {
|
|
132
|
+
manifest = null;
|
|
133
|
+
}
|
|
134
|
+
const name = typeof manifest?.name === "string" && manifest.name.trim()
|
|
135
|
+
? manifest.name.trim()
|
|
136
|
+
: path.basename(packageDir);
|
|
137
|
+
const rawEntries = manifest?.pi?.extensions;
|
|
138
|
+
if (Array.isArray(rawEntries) && rawEntries.length > 0) {
|
|
139
|
+
const entries = rawEntries
|
|
140
|
+
.map((entry) => String(entry ?? "").trim())
|
|
141
|
+
.filter(Boolean)
|
|
142
|
+
.slice(0, MAX_PI_EXTENSION_ENTRIES_PER_PACKAGE);
|
|
143
|
+
return entries.length > 0 ? { name, entries } : null;
|
|
144
|
+
}
|
|
145
|
+
const entries = discoverFallbackExtensionEntries(packageDir);
|
|
146
|
+
return entries.length > 0 ? { name, entries } : null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Read at most MAX_PI_EXTENSION_SOURCE_BYTES bytes from a file without ever
|
|
151
|
+
* allocating more than the cap, regardless of the file size on disk.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} filePath
|
|
154
|
+
* @returns {string | null} Null when the file cannot be opened or read.
|
|
155
|
+
*/
|
|
156
|
+
function readBoundedText(filePath) {
|
|
157
|
+
let fd;
|
|
158
|
+
try {
|
|
159
|
+
fd = fs.openSync(filePath, "r");
|
|
160
|
+
const stat = fs.fstatSync(fd);
|
|
161
|
+
const length = Math.min(stat.size, MAX_PI_EXTENSION_SOURCE_BYTES);
|
|
162
|
+
const buffer = Buffer.alloc(length);
|
|
163
|
+
const bytesRead = fs.readSync(fd, buffer, 0, length, 0);
|
|
164
|
+
return buffer.toString("utf-8", 0, bytesRead);
|
|
165
|
+
} catch {
|
|
166
|
+
return null;
|
|
167
|
+
} finally {
|
|
168
|
+
if (fd !== undefined) {
|
|
169
|
+
try {
|
|
170
|
+
fs.closeSync(fd);
|
|
171
|
+
} catch {
|
|
172
|
+
// Close errors must not mask read results.
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Scan settings-declared pi packages for context-rewriting extension hooks.
|
|
180
|
+
* Missing or unreadable paths are skipped and noted in `skipped`; nothing is
|
|
181
|
+
* ever thrown.
|
|
182
|
+
*
|
|
183
|
+
* @param {object} [options]
|
|
184
|
+
* @param {string} [options.projectRoot]
|
|
185
|
+
* @param {string} [options.agentDir]
|
|
186
|
+
* @returns {{ packages: Array<{ source: string, hooks: string[] }>, packagesScanned: number, skipped: Array<{ source: string, reason: string }> }}
|
|
187
|
+
*/
|
|
188
|
+
export function findContextRewritingExtensions({
|
|
189
|
+
projectRoot = process.cwd(),
|
|
190
|
+
agentDir = resolvePiAgentDir(),
|
|
191
|
+
} = {}) {
|
|
192
|
+
/** @type {Array<{ source: string, settingsDir: string }>} */
|
|
193
|
+
const declared = [];
|
|
194
|
+
|
|
195
|
+
const userSettings = path.join(agentDir, "settings.json");
|
|
196
|
+
for (const source of readPiPackageSources(userSettings)) {
|
|
197
|
+
declared.push({ source, settingsDir: agentDir });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const projectSettings = path.join(projectRoot, ".pi", "settings.json");
|
|
201
|
+
for (const source of readPiPackageSources(projectSettings)) {
|
|
202
|
+
declared.push({ source, settingsDir: path.dirname(projectSettings) });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** @type {Set<string>} */
|
|
206
|
+
const seenPackages = new Set();
|
|
207
|
+
/** @type {Array<{ source: string, hooks: string[] }>} */
|
|
208
|
+
const packages = [];
|
|
209
|
+
/** @type {Array<{ source: string, reason: string }>} */
|
|
210
|
+
const skipped = [];
|
|
211
|
+
let packagesScanned = 0;
|
|
212
|
+
|
|
213
|
+
for (const { source, settingsDir } of declared) {
|
|
214
|
+
const packageDir = resolvePiPackageSourcePath(source, settingsDir, agentDir);
|
|
215
|
+
if (!packageDir) {
|
|
216
|
+
skipped.push({ source: String(source), reason: "unresolvable package source" });
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const resolvedDir = path.resolve(packageDir);
|
|
220
|
+
if (seenPackages.has(resolvedDir)) continue;
|
|
221
|
+
seenPackages.add(resolvedDir);
|
|
222
|
+
if (packagesScanned >= MAX_PI_PACKAGES_SCANNED) {
|
|
223
|
+
skipped.push({ source: String(source), reason: "package scan cap reached" });
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (!fs.existsSync(resolvedDir)) {
|
|
227
|
+
skipped.push({ source: String(source), reason: "package path not found" });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
packagesScanned++;
|
|
231
|
+
|
|
232
|
+
const parsed = readPackageExtensionEntries(resolvedDir);
|
|
233
|
+
if (!parsed) continue;
|
|
234
|
+
|
|
235
|
+
/** @type {Set<string>} */
|
|
236
|
+
const packageHooks = new Set();
|
|
237
|
+
for (const entry of parsed.entries) {
|
|
238
|
+
const entryPath = path.resolve(resolvedDir, entry);
|
|
239
|
+
if (entryPath !== resolvedDir && !entryPath.startsWith(resolvedDir + path.sep)) {
|
|
240
|
+
// Manifest entry escapes the package directory — never read outside it.
|
|
241
|
+
skipped.push({
|
|
242
|
+
source: String(source),
|
|
243
|
+
reason: `entry escapes package directory: ${entry}`,
|
|
244
|
+
});
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const text = readBoundedText(entryPath);
|
|
248
|
+
if (text === null) {
|
|
249
|
+
skipped.push({ source: String(source), reason: `unreadable entry: ${entry}` });
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const hook of scanPiExtensionSourceForContextHooks(text)) {
|
|
253
|
+
packageHooks.add(hook);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (packageHooks.size > 0) {
|
|
257
|
+
packages.push({
|
|
258
|
+
source: String(source),
|
|
259
|
+
hooks: PI_CONTEXT_HOOK_NAMES.filter((hook) => packageHooks.has(hook)),
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return { packages, packagesScanned, skipped };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @param {Array<{ source: string, hooks: string[] }>} packages
|
|
269
|
+
* @returns {string}
|
|
270
|
+
*/
|
|
271
|
+
function summarizeFindings(packages) {
|
|
272
|
+
return packages
|
|
273
|
+
.map((pkg) => `${pkg.source} (${pkg.hooks.join(", ")})`)
|
|
274
|
+
.join("; ");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Advisory doctor check: warn when installed pi packages register
|
|
279
|
+
* context-rewriting hooks while reviewers load user extensions (SP-822).
|
|
280
|
+
*
|
|
281
|
+
* Never hard-fails (`ok` stays true); a `warning: true` check surfaces in
|
|
282
|
+
* doctor output without blocking batch start.
|
|
283
|
+
*
|
|
284
|
+
* @param {object} [options]
|
|
285
|
+
* @param {string} [options.projectRoot]
|
|
286
|
+
* @param {string} [options.agentDir]
|
|
287
|
+
* @param {Record<string, any> | null} [options.config] Loaded spine config.
|
|
288
|
+
* @returns {{ label: string, ok: true, warning?: boolean, detail: string, suggestedCommand?: string }}
|
|
289
|
+
*/
|
|
290
|
+
export function buildContextHookExtensionDoctorCheck({
|
|
291
|
+
projectRoot = process.cwd(),
|
|
292
|
+
agentDir = resolvePiAgentDir(),
|
|
293
|
+
config,
|
|
294
|
+
} = {}) {
|
|
295
|
+
const label = "pi extensions rewriting reviewer context";
|
|
296
|
+
const { packages, packagesScanned } = findContextRewritingExtensions({ projectRoot, agentDir });
|
|
297
|
+
|
|
298
|
+
if (packages.length === 0) {
|
|
299
|
+
return {
|
|
300
|
+
label,
|
|
301
|
+
ok: true,
|
|
302
|
+
detail: `no context-rewriting hooks found in ${packagesScanned} installed pi package(s)`,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const summary = summarizeFindings(packages);
|
|
307
|
+
if (config?.agents?.reviewer?.loadUserExtensions === true) {
|
|
308
|
+
return {
|
|
309
|
+
label,
|
|
310
|
+
ok: true,
|
|
311
|
+
warning: true,
|
|
312
|
+
detail: `${summary} register context-rewriting hook(s) and reviewers load user extensions (agents.reviewer.loadUserExtensions=true); these hooks can rewrite reviewer context`,
|
|
313
|
+
suggestedCommand: "spine settings set agents.reviewer.loadUserExtensions false",
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
label,
|
|
319
|
+
ok: true,
|
|
320
|
+
detail: `${packages.length} package(s) register context hooks (${summary}); reviewers isolated (pi -ne)`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
@@ -71,6 +71,17 @@ export function collectQuotaPinTargets(config = {}) {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// SP-810: the quota fallback profile worker is a fallback-path pin — when
|
|
75
|
+
// the engine falls back to it, its pool must have headroom too.
|
|
76
|
+
const fallbackProfile =
|
|
77
|
+
typeof agents.quotaFallbackProfile === "string" ? agents.quotaFallbackProfile.trim() : "";
|
|
78
|
+
if (fallbackProfile && agents.profiles?.[fallbackProfile]) {
|
|
79
|
+
candidates.push({
|
|
80
|
+
model: agents.profiles[fallbackProfile]?.worker?.model,
|
|
81
|
+
source: `agents.profiles.${fallbackProfile}.worker.model (quota fallback)`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
/** @type {QuotaPinTarget[]} */
|
|
75
86
|
const targets = [];
|
|
76
87
|
const seen = new Set();
|
|
@@ -88,6 +99,37 @@ export function collectQuotaPinTargets(config = {}) {
|
|
|
88
99
|
return targets;
|
|
89
100
|
}
|
|
90
101
|
|
|
102
|
+
/**
|
|
103
|
+
* SP-810: detect a quota fallback profile pinned to the same provider pool
|
|
104
|
+
* as the active worker. Falling back within one exhausted pool can never
|
|
105
|
+
* help, so surface it as an advisory. Advisory only — never fails preflight.
|
|
106
|
+
*
|
|
107
|
+
* @param {object} [config]
|
|
108
|
+
* @returns {string | null}
|
|
109
|
+
*/
|
|
110
|
+
export function detectSamePoolQuotaFallback(config = {}) {
|
|
111
|
+
const agents = config?.agents;
|
|
112
|
+
if (!agents || typeof agents !== "object") return null;
|
|
113
|
+
|
|
114
|
+
const fallbackProfile =
|
|
115
|
+
typeof agents.quotaFallbackProfile === "string" ? agents.quotaFallbackProfile.trim() : "";
|
|
116
|
+
if (!fallbackProfile || !agents.profiles?.[fallbackProfile]) return null;
|
|
117
|
+
|
|
118
|
+
const fallbackModel = agents.profiles[fallbackProfile]?.worker?.model;
|
|
119
|
+
// The active worker is the active profile's worker pin when set, else the
|
|
120
|
+
// base worker pin — mirroring how the engine resolves the worker model.
|
|
121
|
+
const activeProfile = typeof agents.activeProfile === "string" ? agents.activeProfile.trim() : "";
|
|
122
|
+
const activeModel =
|
|
123
|
+
(activeProfile && agents.profiles?.[activeProfile]?.worker?.model) || agents.worker?.model;
|
|
124
|
+
if (typeof fallbackModel !== "string" || typeof activeModel !== "string") return null;
|
|
125
|
+
|
|
126
|
+
const fallbackPool = resolvePoolId(fallbackModel.trim());
|
|
127
|
+
const activePool = resolvePoolId(activeModel.trim());
|
|
128
|
+
if (fallbackPool === "unknown" || fallbackPool !== activePool) return null;
|
|
129
|
+
|
|
130
|
+
return `agents.quotaFallbackProfile ${fallbackProfile} uses the same quota pool (${fallbackPool}) as the active worker — fallback can never help`;
|
|
131
|
+
}
|
|
132
|
+
|
|
91
133
|
/**
|
|
92
134
|
* Evaluate headroom evidence for one pool from an optional probe result.
|
|
93
135
|
* Degrades closed: absent probes/auth mean "no headroom evidence", never an
|
|
@@ -207,6 +249,9 @@ export function buildQuotaRiskDoctorCheck({ config = {}, probeResults, metricsLi
|
|
|
207
249
|
const signals = detectQuotaRiskSignals(metricsLines, { now });
|
|
208
250
|
risks.push(...signals);
|
|
209
251
|
|
|
252
|
+
const samePoolAdvisory = detectSamePoolQuotaFallback(config);
|
|
253
|
+
if (samePoolAdvisory) risks.push(samePoolAdvisory);
|
|
254
|
+
|
|
210
255
|
if (risks.length === 0) {
|
|
211
256
|
const detail =
|
|
212
257
|
targets.length === 0
|
|
@@ -31,6 +31,7 @@ import { buildAgentModelInheritDoctorCheck, buildReviewerPerTypePinsDoctorCheck
|
|
|
31
31
|
import { buildInheritProviderAuthDoctorCheck } from "./agents-model-inherit.mjs";
|
|
32
32
|
import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
|
|
33
33
|
import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
|
|
34
|
+
import { buildContextHookExtensionDoctorCheck } from "./pi-extension-hooks.mjs";
|
|
34
35
|
import { buildSupervisorConfigDoctorCheck } from "./supervisor.mjs";
|
|
35
36
|
import { buildAttachedOrphanRiskDoctorCheck } from "./attached-orphan-risk.mjs";
|
|
36
37
|
import { buildQuotaRiskDoctorCheck } from "./quota-risk.mjs";
|
|
@@ -343,7 +344,20 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
343
344
|
projectRoot,
|
|
344
345
|
}),
|
|
345
346
|
);
|
|
347
|
+
// Load config once here so the advisory SP-822 check (pushed right after
|
|
348
|
+
// the extension-conflict check) and the config-driven checks below share it.
|
|
349
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
346
350
|
checks.push(buildPiExtensionConflictDoctorCheck({ projectRoot }));
|
|
351
|
+
// Advisory only (SP-822): warn when installed pi packages register
|
|
352
|
+
// context-rewriting hooks (context, context_with_system,
|
|
353
|
+
// before_provider_request) while reviewers load user extensions
|
|
354
|
+
// (agents.reviewer.loadUserExtensions). Never hard-fails.
|
|
355
|
+
checks.push(
|
|
356
|
+
buildContextHookExtensionDoctorCheck({
|
|
357
|
+
projectRoot,
|
|
358
|
+
config: configResult.config,
|
|
359
|
+
}),
|
|
360
|
+
);
|
|
347
361
|
checks.push(buildAttachedOrphanRiskDoctorCheck());
|
|
348
362
|
|
|
349
363
|
const piVersionText = getVersion("pi");
|
|
@@ -404,7 +418,6 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
404
418
|
warning: modelCheck.warning,
|
|
405
419
|
});
|
|
406
420
|
|
|
407
|
-
const configResult = loadSpineConfig(projectRoot);
|
|
408
421
|
if (configResult.error) {
|
|
409
422
|
record(".spine/spine-config.json valid", false, {
|
|
410
423
|
detail: configResult.error.message,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* parallel lane assignment would risk merge conflicts.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import picomatch from 'picomatch';
|
|
10
10
|
|
|
11
11
|
/** Synthetic basename used when expanding globs into concrete probe paths. */
|
|
12
12
|
const PROBE_BASENAME = '__probe__';
|
|
@@ -36,7 +36,7 @@ const SYNTHETIC_PROBE_EXTENSIONS = Object.freeze([
|
|
|
36
36
|
const MAX_BRACE_EXPANSIONS = 32;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Expand `{a,b}` brace groups into concrete entry variants (
|
|
39
|
+
* Expand `{a,b}` brace groups into concrete entry variants (picomatch-style).
|
|
40
40
|
* Nested groups are expanded recursively; expansion stops at
|
|
41
41
|
* MAX_BRACE_EXPANSIONS so probe generation stays bounded.
|
|
42
42
|
*
|
|
@@ -264,18 +264,18 @@ export function fileScopePatternsOverlap(leftPattern, rightPattern) {
|
|
|
264
264
|
const matchOpts = { dot: true };
|
|
265
265
|
|
|
266
266
|
for (const probe of leftProbes) {
|
|
267
|
-
if (
|
|
267
|
+
if (picomatch(rightEntry, matchOpts)(probe)) return true;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
for (const probe of rightProbes) {
|
|
271
|
-
if (
|
|
271
|
+
if (picomatch(leftEntry, matchOpts)(probe)) return true;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
if (!patternHasGlobMeta(leftEntry) &&
|
|
274
|
+
if (!patternHasGlobMeta(leftEntry) && picomatch(rightEntry, matchOpts)(leftEntry)) {
|
|
275
275
|
return true;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
if (!patternHasGlobMeta(rightEntry) &&
|
|
278
|
+
if (!patternHasGlobMeta(rightEntry) && picomatch(leftEntry, matchOpts)(rightEntry)) {
|
|
279
279
|
return true;
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Validate-time checks for PROMPT.md `## Contract` tables (handoff §4.4).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import picomatch from "picomatch";
|
|
7
7
|
|
|
8
8
|
import { matchesContractPattern } from "../../batch/contract-verify.mjs";
|
|
9
9
|
import {
|
|
@@ -235,8 +235,8 @@ function isValidContractGlob(pattern) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
try {
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
picomatch(trimmed)(GLOB_PROBE);
|
|
239
|
+
picomatch(GLOB_PROBE)(trimmed);
|
|
240
240
|
return true;
|
|
241
241
|
} catch {
|
|
242
242
|
return false;
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
validatePrompt as validatePromptStructure,
|
|
13
13
|
} from "./parse-prompt.mjs";
|
|
14
14
|
import { validateContract } from "./validate-contract.mjs";
|
|
15
|
+
import { collectExecuteReviewLevelWarnings } from "../validate-contract-warn.mjs";
|
|
16
|
+
import { parseReviewLevel } from "../../batch/review-shared.mjs";
|
|
15
17
|
|
|
16
18
|
/** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
|
|
17
19
|
export const STALE_FILE_SCOPE_AMENDMENT_HINT =
|
|
@@ -46,10 +48,18 @@ export function validatePrompt(markdown, options = {}) {
|
|
|
46
48
|
|
|
47
49
|
errors.push(...contractValidation.errors);
|
|
48
50
|
|
|
51
|
+
const warnings = [...contractValidation.warnings];
|
|
52
|
+
warnings.push(
|
|
53
|
+
...collectExecuteReviewLevelWarnings({
|
|
54
|
+
type: structure.prompt.type,
|
|
55
|
+
reviewLevel: parseReviewLevel(markdown),
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
|
|
49
59
|
return {
|
|
50
60
|
ok: errors.length === 0,
|
|
51
61
|
errors,
|
|
52
|
-
warnings
|
|
62
|
+
warnings,
|
|
53
63
|
prompt: structure.prompt,
|
|
54
64
|
contract,
|
|
55
65
|
};
|
|
@@ -22,6 +22,22 @@ export const TEST_COMMAND_LINT_MISSING_FIX_HINT =
|
|
|
22
22
|
const PATCH_TASK_SIZES = new Set(["S", "M"]);
|
|
23
23
|
const LINT_IN_TEST_COMMAND_RE = /\b(?:lint|eslint|analyze)\b/;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Warn when an execute packet declares a Review Level above 0 (SP-827 / #336):
|
|
27
|
+
* execute tasks run no reviewers, so the declared level is misleading.
|
|
28
|
+
*
|
|
29
|
+
* @param {{ type: string, reviewLevel: number }} options
|
|
30
|
+
* @returns {string[]}
|
|
31
|
+
*/
|
|
32
|
+
export function collectExecuteReviewLevelWarnings({ type, reviewLevel }) {
|
|
33
|
+
if (type !== "execute" || reviewLevel <= 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return [
|
|
37
|
+
`Type: execute task declares Review Level ${reviewLevel}; execute tasks run no reviewers — set Review Level 0.`,
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
/**
|
|
26
42
|
* @param {string | null | undefined} testCommand
|
|
27
43
|
* @returns {boolean}
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"workerOutputMaxBytes": 262144,
|
|
37
37
|
"workerOutputTailLines": 200,
|
|
38
38
|
"retainWorkerOutputOnSuccess": false,
|
|
39
|
-
"streamWorkerOutputLive":
|
|
39
|
+
"streamWorkerOutputLive": true,
|
|
40
40
|
"workerLiveLogMaxBytes": 262144,
|
|
41
41
|
"stallTimeoutMinutes": 120,
|
|
42
42
|
"stallGraceAfterProgressMinutes": 30,
|