pi-spine 2.4.0 → 2.5.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.
- package/package.json +1 -1
- package/src/batch/blocker-codes.mjs +63 -0
- package/src/batch/gate-posture-approve.mjs +345 -0
- package/src/batch/gate-posture-defaults.mjs +64 -0
- package/src/batch/gate-posture-evaluate.mjs +133 -0
- package/src/batch/gate-posture-streak.mjs +290 -0
- package/src/batch/gate-revision.mjs +95 -0
- package/src/batch/gate.mjs +89 -117
- package/src/batch/integrate.mjs +1 -0
- package/src/batch/sequence-wait.mjs +20 -6
- package/src/config/gate-posture-config.mjs +190 -0
- package/src/config/spine-config-load.mjs +7 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
6
6
|
import { DEFAULT_SEQUENCE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
7
7
|
import { isProcessAlive } from "../process/liveness.mjs";
|
|
8
|
-
import { approveIntegrateGate, loadGateRecord } from "./gate.mjs";
|
|
8
|
+
import { approveIntegrateGate, loadGateRecord, maybeAutoApproveIntegrateGate } from "./gate.mjs";
|
|
9
9
|
import { integrateOrchToBase } from "./integrate.mjs";
|
|
10
10
|
import { completeBatch } from "./lifecycle.mjs";
|
|
11
11
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
@@ -127,7 +127,14 @@ export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate
|
|
|
127
127
|
const gate = activeBatchId ? loadGateRecord(projectRoot, activeBatchId) : null;
|
|
128
128
|
|
|
129
129
|
if (gateRequired && gate?.status === "pending") {
|
|
130
|
-
|
|
130
|
+
const postureAuto = maybeAutoApproveIntegrateGate({
|
|
131
|
+
projectRoot,
|
|
132
|
+
batchId: activeBatchId,
|
|
133
|
+
config,
|
|
134
|
+
});
|
|
135
|
+
if (postureAuto.approved) {
|
|
136
|
+
// Posture opt-in allowed auto-approve; continue to integrate.
|
|
137
|
+
} else if (!autoApproveGate) {
|
|
131
138
|
return {
|
|
132
139
|
ok: false,
|
|
133
140
|
step: "gate_approve",
|
|
@@ -136,11 +143,18 @@ export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate
|
|
|
136
143
|
batchId: activeBatchId,
|
|
137
144
|
headline: "Integrate gate requires approval — pass autoApproveGate or approve manually",
|
|
138
145
|
suggestedCommand: "spine gate approve",
|
|
146
|
+
postureEvaluation: postureAuto.evaluation ?? null,
|
|
139
147
|
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
} else {
|
|
149
|
+
// Blunt --auto-approve-gate path (still gated by validateSequenceAutoApproveGate upstream).
|
|
150
|
+
const approve = approveIntegrateGate({
|
|
151
|
+
projectRoot,
|
|
152
|
+
batchId: activeBatchId,
|
|
153
|
+
decidedBy: "auto",
|
|
154
|
+
});
|
|
155
|
+
if (!approve.ok) {
|
|
156
|
+
return { ok: false, step: "gate_approve", diagnosis, batchId: activeBatchId, ...approve };
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Resolve gate postures from spine-config with fail-closed defaults (SP-629 / FR-REL250-07 / #123).
|
|
4
|
+
* Invalid or missing overlay never unlocks locked categories and never rejects whole config load.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_POSTURES,
|
|
9
|
+
GATE_CATEGORIES,
|
|
10
|
+
LOCKED_CATEGORIES,
|
|
11
|
+
POSTURES,
|
|
12
|
+
} from "../batch/gate-posture-defaults.mjs";
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").GateCategory} GateCategory */
|
|
15
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").GatePosture} GatePosture */
|
|
16
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").CategoryPostureDefault} CategoryPostureDefault */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* categories: Readonly<Record<GateCategory, Readonly<CategoryPostureDefault>>>,
|
|
21
|
+
* alwaysBreakOn: ReadonlyArray<string>,
|
|
22
|
+
* }} GatePostureConfig
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const KNOWN_POSTURES = new Set(Object.values(POSTURES));
|
|
26
|
+
const LOCKED_SET = new Set(/** @type {GateCategory[]} */ ([...LOCKED_CATEGORIES]));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {unknown} value
|
|
30
|
+
* @returns {value is Record<string, unknown>}
|
|
31
|
+
*/
|
|
32
|
+
function isPlainObject(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fail-closed locked entry used for unknown postures and locked categories.
|
|
38
|
+
* @returns {Readonly<CategoryPostureDefault>}
|
|
39
|
+
*/
|
|
40
|
+
function lockedEntry() {
|
|
41
|
+
return Object.freeze({ posture: POSTURES.LOCKED, autoApproveAfterN: null });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Clone DEFAULT_POSTURES into a mutable record for overlay.
|
|
46
|
+
* @returns {Record<GateCategory, CategoryPostureDefault>}
|
|
47
|
+
*/
|
|
48
|
+
function cloneDefaults() {
|
|
49
|
+
/** @type {Record<GateCategory, CategoryPostureDefault>} */
|
|
50
|
+
const out = /** @type {Record<GateCategory, CategoryPostureDefault>} */ ({});
|
|
51
|
+
for (const category of GATE_CATEGORIES) {
|
|
52
|
+
const entry = DEFAULT_POSTURES[category];
|
|
53
|
+
out[category] = { posture: entry.posture, autoApproveAfterN: entry.autoApproveAfterN };
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {unknown} raw
|
|
60
|
+
* @returns {Readonly<CategoryPostureDefault>}
|
|
61
|
+
*/
|
|
62
|
+
function normalizeCategoryEntry(raw) {
|
|
63
|
+
if (!isPlainObject(raw)) {
|
|
64
|
+
return lockedEntry();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const postureRaw = raw.posture;
|
|
68
|
+
if (typeof postureRaw !== "string" || !KNOWN_POSTURES.has(/** @type {GatePosture} */ (postureRaw))) {
|
|
69
|
+
return lockedEntry();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const posture = /** @type {GatePosture} */ (postureRaw);
|
|
73
|
+
if (posture === POSTURES.LOCKED) {
|
|
74
|
+
return lockedEntry();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const thresholdRaw = raw.autoApproveAfterN;
|
|
78
|
+
if (thresholdRaw === undefined) {
|
|
79
|
+
return Object.freeze({ posture, autoApproveAfterN: 0 });
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
typeof thresholdRaw !== "number" ||
|
|
83
|
+
!Number.isInteger(thresholdRaw) ||
|
|
84
|
+
thresholdRaw < 0
|
|
85
|
+
) {
|
|
86
|
+
return lockedEntry();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return Object.freeze({ posture, autoApproveAfterN: thresholdRaw });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accept string tags only; invalid shapes fail closed to [].
|
|
94
|
+
* @param {unknown} raw
|
|
95
|
+
* @returns {string[]}
|
|
96
|
+
*/
|
|
97
|
+
function normalizeAlwaysBreakOn(raw) {
|
|
98
|
+
if (raw == null) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
if (!Array.isArray(raw)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
/** @type {string[]} */
|
|
105
|
+
const tags = [];
|
|
106
|
+
for (const entry of raw) {
|
|
107
|
+
if (typeof entry === "string" && entry.trim() !== "") {
|
|
108
|
+
tags.push(entry.trim());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return tags;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Locate optional postures overlay and alwaysBreakOn from spine-config.
|
|
116
|
+
* Supports `gates.postures` map and `alwaysBreakOn` on `gates` or under `gates.postures`.
|
|
117
|
+
*
|
|
118
|
+
* @param {unknown} config
|
|
119
|
+
* @returns {{ overlay: Record<string, unknown> | null, alwaysBreakOnRaw: unknown }}
|
|
120
|
+
*/
|
|
121
|
+
function extractPostureSection(config) {
|
|
122
|
+
if (!isPlainObject(config)) {
|
|
123
|
+
return { overlay: null, alwaysBreakOnRaw: undefined };
|
|
124
|
+
}
|
|
125
|
+
const gates = config.gates;
|
|
126
|
+
if (!isPlainObject(gates)) {
|
|
127
|
+
return { overlay: null, alwaysBreakOnRaw: undefined };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const posturesRaw = gates.postures;
|
|
131
|
+
/** @type {unknown} */
|
|
132
|
+
let alwaysBreakOnRaw = gates.alwaysBreakOn;
|
|
133
|
+
|
|
134
|
+
if (posturesRaw == null) {
|
|
135
|
+
return { overlay: null, alwaysBreakOnRaw };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!isPlainObject(posturesRaw)) {
|
|
139
|
+
// Invalid postures container — fail closed: ignore overlay, keep alwaysBreakOn if present.
|
|
140
|
+
return { overlay: null, alwaysBreakOnRaw };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (alwaysBreakOnRaw === undefined && "alwaysBreakOn" in posturesRaw) {
|
|
144
|
+
alwaysBreakOnRaw = posturesRaw.alwaysBreakOn;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { overlay: posturesRaw, alwaysBreakOnRaw };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Merge optional `gates.postures` / `gates.alwaysBreakOn` over DEFAULT_POSTURES.
|
|
152
|
+
* Missing config → defaults. Unknown posture / invalid threshold → locked.
|
|
153
|
+
* destroy/auth stay locked even if config tries to relax them.
|
|
154
|
+
*
|
|
155
|
+
* @param {unknown} config Parsed spine-config (or partial with `gates`)
|
|
156
|
+
* @returns {GatePostureConfig}
|
|
157
|
+
*/
|
|
158
|
+
export function resolveGatePostureConfig(config) {
|
|
159
|
+
const { overlay, alwaysBreakOnRaw } = extractPostureSection(config);
|
|
160
|
+
const categories = cloneDefaults();
|
|
161
|
+
|
|
162
|
+
if (overlay) {
|
|
163
|
+
for (const category of GATE_CATEGORIES) {
|
|
164
|
+
if (!(category in overlay)) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (LOCKED_SET.has(category)) {
|
|
168
|
+
categories[category] = lockedEntry();
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
categories[category] = normalizeCategoryEntry(overlay[category]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Hard fail-closed: locked categories never leave locked.
|
|
176
|
+
for (const category of LOCKED_CATEGORIES) {
|
|
177
|
+
categories[category] = lockedEntry();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** @type {Record<GateCategory, Readonly<CategoryPostureDefault>>} */
|
|
181
|
+
const frozenCategories = /** @type {Record<GateCategory, Readonly<CategoryPostureDefault>>} */ ({});
|
|
182
|
+
for (const category of GATE_CATEGORIES) {
|
|
183
|
+
frozenCategories[category] = Object.freeze(categories[category]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return Object.freeze({
|
|
187
|
+
categories: Object.freeze(frozenCategories),
|
|
188
|
+
alwaysBreakOn: Object.freeze(normalizeAlwaysBreakOn(alwaysBreakOnRaw)),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
@@ -5,12 +5,15 @@ import path from "node:path";
|
|
|
5
5
|
import { applyEnvOverrides } from "./env-overrides.mjs";
|
|
6
6
|
import { applyConfigDefaults } from "./merge-defaults.mjs";
|
|
7
7
|
import { validateContractConfig } from "./contract.mjs";
|
|
8
|
+
import { resolveGatePostureConfig } from "./gate-posture-config.mjs";
|
|
8
9
|
import { validateWorkerBackendConfig } from "./worker-backend.mjs";
|
|
9
10
|
import { validateWorkerContextConfig } from "./worker-context.mjs";
|
|
10
11
|
import { validateWorkerLaunchScriptConfig } from "./worker-launch-script.mjs";
|
|
11
12
|
import { validateWorktreeSetupHookConfig } from "./worktree-setup-hook.mjs";
|
|
12
13
|
import { validateOrchestratorConfig } from "./spine-config-schema.mjs";
|
|
13
14
|
|
|
15
|
+
export { resolveGatePostureConfig } from "./gate-posture-config.mjs";
|
|
16
|
+
|
|
14
17
|
const REQUIRED_TOP_LEVEL = [
|
|
15
18
|
"configVersion",
|
|
16
19
|
"project",
|
|
@@ -107,10 +110,14 @@ export function loadSpineConfig(projectRoot) {
|
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
// Soft attach: posture merge fails closed inside the helper and never rejects load.
|
|
114
|
+
const gatePostureConfig = resolveGatePostureConfig(envResult.config);
|
|
115
|
+
|
|
110
116
|
return {
|
|
111
117
|
configPath: fileResult.configPath,
|
|
112
118
|
config: envResult.config,
|
|
113
119
|
fileConfig: config,
|
|
120
|
+
gatePostureConfig,
|
|
114
121
|
sources: envResult.sources,
|
|
115
122
|
envVars: envResult.envVars,
|
|
116
123
|
error: null,
|