@warpgogol/forge 9.4.0 → 9.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/CHANGELOG.md +30 -0
- package/README.md +4 -2
- package/README.uk.md +10 -8
- package/bin/cli.ts +152 -11
- package/dist/bin/cli.js +125 -5
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/flow/dirty-classify.d.ts +11 -1
- package/dist/os/flow/dirty-classify.d.ts.map +1 -1
- package/dist/os/flow/dirty-classify.js +13 -0
- package/dist/os/flow/dirty-classify.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +29 -3
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-check.js +9 -9
- package/dist/os/flow/handlers/flow-check.js.map +1 -1
- package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-cut.js +22 -8
- package/dist/os/flow/handlers/flow-cut.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts +6 -0
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +155 -44
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-open.js +14 -19
- package/dist/os/flow/handlers/flow-open.js.map +1 -1
- package/dist/os/flow/handlers/flow-peers.d.ts +24 -0
- package/dist/os/flow/handlers/flow-peers.d.ts.map +1 -0
- package/dist/os/flow/handlers/flow-peers.js +99 -0
- package/dist/os/flow/handlers/flow-peers.js.map +1 -0
- package/dist/os/flow/index.d.ts +3 -0
- package/dist/os/flow/index.d.ts.map +1 -1
- package/dist/os/flow/index.js +9 -4
- package/dist/os/flow/index.js.map +1 -1
- package/dist/os/flow/ops-registry.d.ts +33 -0
- package/dist/os/flow/ops-registry.d.ts.map +1 -0
- package/dist/os/flow/ops-registry.js +177 -0
- package/dist/os/flow/ops-registry.js.map +1 -0
- package/dist/os/flow/preflight.d.ts +70 -3
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +545 -49
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/registry.d.ts +2 -2
- package/dist/os/flow/standalone-invoke.d.ts +11 -0
- package/dist/os/flow/standalone-invoke.d.ts.map +1 -0
- package/dist/os/flow/standalone-invoke.js +75 -0
- package/dist/os/flow/standalone-invoke.js.map +1 -0
- package/dist/os/gate-run/detach.d.ts +27 -0
- package/dist/os/gate-run/detach.d.ts.map +1 -0
- package/dist/os/gate-run/detach.js +85 -0
- package/dist/os/gate-run/detach.js.map +1 -0
- package/dist/os/gate-run/gate-run.module.d.ts +3 -0
- package/dist/os/gate-run/gate-run.module.d.ts.map +1 -0
- package/dist/os/gate-run/gate-run.module.js +23 -0
- package/dist/os/gate-run/gate-run.module.js.map +1 -0
- package/dist/os/gate-run/index.d.ts +7 -0
- package/dist/os/gate-run/index.d.ts.map +1 -0
- package/dist/os/gate-run/index.js +5 -0
- package/dist/os/gate-run/index.js.map +1 -0
- package/dist/os/gate-run/record.d.ts +47 -0
- package/dist/os/gate-run/record.d.ts.map +1 -0
- package/dist/os/gate-run/record.js +157 -0
- package/dist/os/gate-run/record.js.map +1 -0
- package/dist/os/gate-run/status.d.ts +41 -0
- package/dist/os/gate-run/status.d.ts.map +1 -0
- package/dist/os/gate-run/status.js +142 -0
- package/dist/os/gate-run/status.js.map +1 -0
- package/dist/os/gate-run/types.d.ts +47 -0
- package/dist/os/gate-run/types.d.ts.map +1 -0
- package/dist/os/gate-run/types.js +24 -0
- package/dist/os/gate-run/types.js.map +1 -0
- package/dist/os/mission/handlers/archive.d.ts.map +1 -1
- package/dist/os/mission/handlers/archive.js +12 -8
- package/dist/os/mission/handlers/archive.js.map +1 -1
- package/dist/os/mission/importer-block.d.ts +19 -0
- package/dist/os/mission/importer-block.d.ts.map +1 -0
- package/dist/os/mission/importer-block.js +124 -0
- package/dist/os/mission/importer-block.js.map +1 -0
- package/dist/os/mission/lockfile.d.ts +17 -0
- package/dist/os/mission/lockfile.d.ts.map +1 -1
- package/dist/os/mission/lockfile.js +38 -0
- package/dist/os/mission/lockfile.js.map +1 -1
- package/dist/os/rfc/evidence-annotation.d.ts +26 -0
- package/dist/os/rfc/evidence-annotation.d.ts.map +1 -0
- package/dist/os/rfc/evidence-annotation.js +52 -0
- package/dist/os/rfc/evidence-annotation.js.map +1 -0
- package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -1
- package/dist/os/rfc/handlers/fixed-inputs.js +7 -1
- package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +21 -28
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
- package/dist/os/rfc/handlers/list-create.js +25 -3
- package/dist/os/rfc/handlers/list-create.js.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.js +127 -7
- package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
- package/dist/os/rfc/rfc.module.d.ts.map +1 -1
- package/dist/os/rfc/rfc.module.js +3 -2
- package/dist/os/rfc/rfc.module.js.map +1 -1
- package/dist/os/rfc/types.d.ts +9 -2
- package/dist/os/rfc/types.d.ts.map +1 -1
- package/dist/os/rfc/types.js +2 -2
- package/dist/os/rfc/types.js.map +1 -1
- package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -1
- package/dist/os/system/handlers/system-task-collect.js +11 -5
- package/dist/os/system/handlers/system-task-collect.js.map +1 -1
- package/dist/src/cli-flags.d.ts.map +1 -1
- package/dist/src/cli-flags.js +6 -0
- package/dist/src/cli-flags.js.map +1 -1
- package/dist/src/onboarding/prettierignore.d.ts.map +1 -1
- package/dist/src/onboarding/prettierignore.js +2 -0
- package/dist/src/onboarding/prettierignore.js.map +1 -1
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +2 -8
- package/dist/src/types.js.map +1 -1
- package/os/flow/dirty-classify.ts +21 -0
- package/os/flow/flow.module.ts +31 -3
- package/os/flow/handlers/flow-check.ts +17 -18
- package/os/flow/handlers/flow-cut.ts +28 -11
- package/os/flow/handlers/flow-integrate.ts +229 -62
- package/os/flow/handlers/flow-open.ts +24 -31
- package/os/flow/handlers/flow-peers.ts +142 -0
- package/os/flow/index.ts +10 -8
- package/os/flow/ops-registry.ts +194 -0
- package/os/flow/preflight.ts +608 -55
- package/os/flow/standalone-invoke.ts +85 -0
- package/os/flow/tests/dirty-classify.test.ts +139 -4
- package/os/flow/tests/flow-cut.test.ts +21 -0
- package/os/flow/tests/flow-integrate.preflight.test.ts +34 -9
- package/os/flow/tests/flow-integrate.test.ts +433 -17
- package/os/flow/tests/lockfile-induced.test.ts +328 -0
- package/os/flow/tests/ops-registry.test.ts +136 -0
- package/os/gate-run/detach.ts +106 -0
- package/os/gate-run/gate-run.module.ts +25 -0
- package/os/gate-run/index.ts +16 -0
- package/os/gate-run/record.ts +194 -0
- package/os/gate-run/status.ts +168 -0
- package/os/gate-run/tests/gate-run-detach.test.ts +144 -0
- package/os/gate-run/tests/gate-run-record.test.ts +200 -0
- package/os/gate-run/types.ts +73 -0
- package/os/mission/handlers/archive.ts +22 -14
- package/os/mission/importer-block.ts +119 -0
- package/os/mission/lockfile.ts +41 -0
- package/os/rfc/evidence-annotation.ts +61 -0
- package/os/rfc/handlers/fixed-inputs.test.ts +70 -0
- package/os/rfc/handlers/fixed-inputs.ts +11 -1
- package/os/rfc/handlers/implement-stamp.ts +25 -28
- package/os/rfc/handlers/list-create.test.ts +58 -5
- package/os/rfc/handlers/list-create.ts +30 -3
- package/os/rfc/handlers/validate-evidence-shape.test.ts +218 -0
- package/os/rfc/handlers/validate-probe-meta.test.ts +71 -0
- package/os/rfc/handlers/validate-rules.ts +169 -17
- package/os/rfc/handlers/validate-transient-probes.test.ts +222 -0
- package/os/rfc/rfc-0000-template.md +10 -10
- package/os/rfc/rfc.module.ts +3 -2
- package/os/rfc/types.ts +5 -2
- package/os/system/handlers/system-task-collect.ts +11 -5
- package/os/system/tests/system-task-collect.test.ts +16 -0
- package/package.json +17 -1
- package/skills/fo/fo-session-retro/SKILL.md +12 -4
- package/src/cli-flags.ts +7 -0
- package/src/onboarding/prettierignore.ts +2 -0
- package/src/tests/prettierignore-manage.test.ts +11 -0
- package/src/types.ts +9 -8
package/os/flow/preflight.ts
CHANGED
|
@@ -14,18 +14,17 @@ closed by the RFC: adding a check requires an amendment.</purpose>
|
|
|
14
14
|
</non-goals>
|
|
15
15
|
</MODULE_CONTRACT>
|
|
16
16
|
<CHANGE_SUMMARY>
|
|
17
|
-
<item>RFC-
|
|
18
|
-
<item>RFC-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<item>RFC-
|
|
22
|
-
<
|
|
23
|
-
<item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
|
|
24
|
-
<item>RFC-1531: shared DirtyClass enum via dirty-classify.ts (Q-4), classified FLOW-INT-01/03 data.entries, classifyDirtyEntries for the remediation flags</item>
|
|
17
|
+
<item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
|
|
18
|
+
<item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
|
|
19
|
+
<item>ADR-0130: induced-change lockfile classifiers — BFS reachability for optional-flag removals, collapse pairs, induced packages/snapshots additions</item>
|
|
20
|
+
<item>ADR-0129: F-0186/F-0187 — FLOW-INT-03 names paths + three-way remedy, FLOW-OPEN-01 same hint, forge CLI kernel-command hint</item>
|
|
21
|
+
<item>RFC-0000: skip rfc-0000 template in integrate preflight id extraction; regen ecosystem manifest; file F-0207</item>
|
|
22
|
+
<history>RFC-1528, RFC-1531, RFC-1537, RFC-1538, RFC-1545, RFC-1546</history>
|
|
25
23
|
</CHANGE_SUMMARY>
|
|
26
24
|
*/
|
|
27
25
|
|
|
28
26
|
import { basename, dirname, join } from "node:path";
|
|
27
|
+
import { parse as parseYaml } from "yaml";
|
|
29
28
|
|
|
30
29
|
import type {
|
|
31
30
|
CommandRegistry,
|
|
@@ -35,29 +34,30 @@ import type {
|
|
|
35
34
|
WorkspaceIO,
|
|
36
35
|
} from "../../src/types.ts";
|
|
37
36
|
import { loadLiveCommandInventory } from "../../src/utils/command-inventory.ts";
|
|
38
|
-
import {
|
|
39
|
-
isGeneratedContent,
|
|
40
|
-
isGeneratedPathName,
|
|
41
|
-
REGEN_FLAGS,
|
|
42
|
-
} from "../core/archive-regen.ts";
|
|
37
|
+
import { isGeneratedContent, isGeneratedPathName, REGEN_FLAGS } from "../core/archive-regen.ts";
|
|
43
38
|
import { openMissionsIn } from "../mission/open-missions.ts";
|
|
44
39
|
import {
|
|
45
40
|
classifyDirtyPath,
|
|
41
|
+
FOREIGN_PRIMARY_DIRT_HINT,
|
|
46
42
|
summarizeClasses,
|
|
47
43
|
type ClassifiedDirtyEntry,
|
|
48
44
|
type DirtyClass,
|
|
49
45
|
} from "./dirty-classify.ts";
|
|
50
|
-
import { currentBranch, git, statusTracked } from "./git.ts";
|
|
46
|
+
import { currentBranch, git, statusTracked, worktreeList } from "./git.ts";
|
|
47
|
+
import { canonicalRepoDir } from "../../src/utils/repo-path.ts";
|
|
48
|
+
import { claimCoversPath, liveClaims, type OpClaim } from "./ops-registry.ts";
|
|
51
49
|
|
|
52
50
|
export type LockfileClassification = "importer-prune-only" | "other";
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Strict match for the pnpm-prune shape: ONLY removed lines, every one either
|
|
56
54
|
* a `missions/<id>/workpiece:` importer key or a deeper-indented member of
|
|
57
|
-
* such a key's block.
|
|
58
|
-
*
|
|
55
|
+
* such a key's block. Returns the sorted pruned mission ids on match, null
|
|
56
|
+
* otherwise — any added line, any other removed line, or a diff with no
|
|
57
|
+
* removals is ambiguous and stays an ordinary refusal.
|
|
59
58
|
*/
|
|
60
|
-
export function
|
|
59
|
+
export function classifyLockfilePruneIds(diffText: string): string[] | null {
|
|
60
|
+
const ids = new Set<string>();
|
|
61
61
|
let sawImporterKey = false;
|
|
62
62
|
let openBlockIndent: number | null = null;
|
|
63
63
|
for (const raw of diffText.split("\n")) {
|
|
@@ -72,7 +72,7 @@ export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
|
72
72
|
if (raw.startsWith("@@")) openBlockIndent = null;
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
|
-
if (raw.startsWith("+")) return
|
|
75
|
+
if (raw.startsWith("+")) return null;
|
|
76
76
|
const line = raw.slice(1);
|
|
77
77
|
if (raw[0] === " ") {
|
|
78
78
|
const indent = line.length - line.trimStart().length;
|
|
@@ -84,19 +84,25 @@ export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
|
84
84
|
if (raw[0] !== "-") continue;
|
|
85
85
|
if (line.trim().length === 0) {
|
|
86
86
|
// A blank removed line only tolerates inside an open importer block.
|
|
87
|
-
if (openBlockIndent === null) return
|
|
87
|
+
if (openBlockIndent === null) return null;
|
|
88
88
|
continue;
|
|
89
89
|
}
|
|
90
90
|
const indent = line.length - line.trimStart().length;
|
|
91
|
-
|
|
91
|
+
const key = /^\s*missions\/([^\s/]+)\/workpiece:\s*$/.exec(line);
|
|
92
|
+
if (key) {
|
|
92
93
|
sawImporterKey = true;
|
|
94
|
+
ids.add(key[1]);
|
|
93
95
|
openBlockIndent = indent;
|
|
94
96
|
continue;
|
|
95
97
|
}
|
|
96
98
|
if (openBlockIndent !== null && indent > openBlockIndent) continue;
|
|
97
|
-
return
|
|
99
|
+
return null;
|
|
98
100
|
}
|
|
99
|
-
return sawImporterKey ?
|
|
101
|
+
return sawImporterKey ? [...ids].sort() : null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
105
|
+
return classifyLockfilePruneIds(diffText) !== null ? "importer-prune-only" : "other";
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
/**
|
|
@@ -150,6 +156,302 @@ export function classifyLockfileMaterialize(diffText: string): string[] | null {
|
|
|
150
156
|
return sawImporterKey ? [...ids].sort() : null;
|
|
151
157
|
}
|
|
152
158
|
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// ADR-0130 (F-0201): induced-change lockfile shapes
|
|
161
|
+
//
|
|
162
|
+
// A `pnpm install` against a lockfile whose `importers:` list includes open
|
|
163
|
+
// mission workpieces produces diffs that are never pure block additions or
|
|
164
|
+
// removals — the dependency-graph write also adds/drops `optional: true`
|
|
165
|
+
// flags, collapses `key:\n optional: true` pairs to `key: {}`, and adds or
|
|
166
|
+
// removes `packages:`/`snapshots:` members. The strict one-shape classifiers
|
|
167
|
+
// above see the extra hunks and degrade to `work`, which is the ping-pong the
|
|
168
|
+
// ADR stops. These extended classifiers accept the strict shape first and
|
|
169
|
+
// then the induced shape, bounded by where each hunk anchors in the HEAD
|
|
170
|
+
// lockfile.
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
const DIFF_HEADER = /^(diff |index |--- |\+\+\+ |@@ )/;
|
|
174
|
+
const TOP_LEVEL_KEY = /^(\S[^:]*):\s*$/;
|
|
175
|
+
const IMPORTER_KEY = /^\s*missions\/([^\s/]+)\/workpiece:\s*$/;
|
|
176
|
+
const OPTIONAL_TRUE = /^\s*optional: true\s*$/;
|
|
177
|
+
|
|
178
|
+
interface DiffLine {
|
|
179
|
+
kind: "add" | "del" | "ctx" | "hunk";
|
|
180
|
+
text: string;
|
|
181
|
+
oldLine: number; // anchor position in the HEAD file (for `add`: line after which it inserts)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Parse `git diff` output into positioned lines (single-file diffs only). */
|
|
185
|
+
function parseDiffLines(diffText: string): DiffLine[] {
|
|
186
|
+
const lines: DiffLine[] = [];
|
|
187
|
+
let oldCursor = 0;
|
|
188
|
+
for (const raw of diffText.split("\n")) {
|
|
189
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+\d+(?:,\d+)? @@/.exec(raw);
|
|
190
|
+
if (hunk) {
|
|
191
|
+
oldCursor = Number(hunk[1]);
|
|
192
|
+
lines.push({ kind: "hunk", text: raw, oldLine: oldCursor });
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (DIFF_HEADER.test(raw) || raw === "") continue;
|
|
196
|
+
if (raw.startsWith("+")) {
|
|
197
|
+
lines.push({ kind: "add", text: raw.slice(1), oldLine: oldCursor });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (raw.startsWith("-")) {
|
|
201
|
+
lines.push({ kind: "del", text: raw.slice(1), oldLine: oldCursor });
|
|
202
|
+
oldCursor += 1;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
lines.push({ kind: "ctx", text: raw.slice(1), oldLine: oldCursor });
|
|
206
|
+
oldCursor += 1;
|
|
207
|
+
}
|
|
208
|
+
return lines;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Top-level (`key:`) section containing old-file line `n` (1-based). */
|
|
212
|
+
function topLevelSectionAt(headLines: string[], n: number): string | null {
|
|
213
|
+
let section: string | null = null;
|
|
214
|
+
for (let i = 0; i < Math.min(n, headLines.length); i++) {
|
|
215
|
+
const m = TOP_LEVEL_KEY.exec(headLines[i]);
|
|
216
|
+
if (m) section = m[1];
|
|
217
|
+
}
|
|
218
|
+
return section;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Second-level `key:` (one-indent) enclosing old-file line `n` inside `section`. */
|
|
222
|
+
function secondLevelKeyAt(headLines: string[], n: number, section: string): string | null {
|
|
223
|
+
let inSection = false;
|
|
224
|
+
let key: string | null = null;
|
|
225
|
+
for (let i = 0; i < Math.min(n, headLines.length); i++) {
|
|
226
|
+
const line = headLines[i];
|
|
227
|
+
const top = TOP_LEVEL_KEY.exec(line);
|
|
228
|
+
if (top) {
|
|
229
|
+
inSection = top[1] === section;
|
|
230
|
+
key = null;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (!inSection || line.trim() === "") continue;
|
|
234
|
+
const m = /^ {2}('?[^:]*'?):\s*(?:\{\})?\s*$/.exec(line);
|
|
235
|
+
if (m) key = m[1].replace(/^'|'$/g, "");
|
|
236
|
+
}
|
|
237
|
+
return key;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Snapshot keys reachable from `missionIds` in the working lockfile — BFS
|
|
242
|
+
* from each `missions/<id>/workpiece` importer through `dependencies`,
|
|
243
|
+
* `devDependencies` and `optionalDependencies` version specifiers, then
|
|
244
|
+
* through each reached snapshot's own dependency maps. Specifiers that are
|
|
245
|
+
* not registry resolutions (`link:`, `workspace:`, `file:`) have no snapshot
|
|
246
|
+
* entry and are ignored.
|
|
247
|
+
*/
|
|
248
|
+
export function reachableSnapshotKeys(lockText: string, missionIds: string[]): Set<string> {
|
|
249
|
+
const reachable = new Set<string>();
|
|
250
|
+
let parsed: unknown;
|
|
251
|
+
try {
|
|
252
|
+
parsed = parseYaml(lockText);
|
|
253
|
+
} catch {
|
|
254
|
+
return reachable;
|
|
255
|
+
}
|
|
256
|
+
const root = parsed as Record<string, unknown> | null;
|
|
257
|
+
const importers = (root?.importers ?? {}) as Record<string, unknown>;
|
|
258
|
+
const snapshots = (root?.snapshots ?? {}) as Record<string, Record<string, unknown>>;
|
|
259
|
+
const depMaps = (entry: Record<string, unknown>): string[] => {
|
|
260
|
+
const out: string[] = [];
|
|
261
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
262
|
+
const deps = entry[field] as Record<string, unknown> | undefined;
|
|
263
|
+
if (!deps) continue;
|
|
264
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
265
|
+
const version =
|
|
266
|
+
typeof spec === "string" ? spec : ((spec as Record<string, unknown>)?.version as string);
|
|
267
|
+
if (typeof version !== "string") continue;
|
|
268
|
+
if (/^(link|workspace|file):/.test(version)) continue;
|
|
269
|
+
// pnpm strips the name for plain resolutions inside importers
|
|
270
|
+
// (version only) but snapshot keys carry `name@version`.
|
|
271
|
+
out.push(version.startsWith(`${name}@`) ? version : `${name}@${version}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
};
|
|
276
|
+
const queue: string[] = [];
|
|
277
|
+
for (const id of missionIds) {
|
|
278
|
+
const entry = importers[`missions/${id}/workpiece`] as Record<string, unknown> | undefined;
|
|
279
|
+
if (entry) queue.push(...depMaps(entry));
|
|
280
|
+
}
|
|
281
|
+
while (queue.length > 0) {
|
|
282
|
+
const key = queue.shift()!;
|
|
283
|
+
if (reachable.has(key)) continue;
|
|
284
|
+
reachable.add(key);
|
|
285
|
+
const snap = snapshots[key];
|
|
286
|
+
if (snap) queue.push(...depMaps(snap));
|
|
287
|
+
}
|
|
288
|
+
return reachable;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* ADR-0130 criterion (b)+(c): materialize shape extended with induced
|
|
293
|
+
* changes. Removed lines must be `optional: true` on snapshots reachable
|
|
294
|
+
* from the added mission importers, or `key:` lines paired with an added
|
|
295
|
+
* `key: {}` collapse. Added lines outside mission importer blocks must
|
|
296
|
+
* anchor under `packages:` or `snapshots:` in the HEAD file.
|
|
297
|
+
*/
|
|
298
|
+
export function classifyLockfileMaterializeExtended(
|
|
299
|
+
diffText: string,
|
|
300
|
+
headText: string,
|
|
301
|
+
workText: string,
|
|
302
|
+
): string[] | null {
|
|
303
|
+
const strict = classifyLockfileMaterialize(diffText);
|
|
304
|
+
if (strict !== null) return strict;
|
|
305
|
+
const headLines = headText.split("\n");
|
|
306
|
+
const lines = parseDiffLines(diffText);
|
|
307
|
+
const missionIds = new Set<string>();
|
|
308
|
+
const collapsedKeys = new Set<string>();
|
|
309
|
+
const optionalRemovedOn = new Set<string>();
|
|
310
|
+
let importerBlockIndent: number | null = null;
|
|
311
|
+
let sawDiff = false;
|
|
312
|
+
for (const line of lines) {
|
|
313
|
+
if (line.kind === "hunk") {
|
|
314
|
+
importerBlockIndent = null;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (line.kind === "ctx") {
|
|
318
|
+
const indent = line.text.length - line.text.trimStart().length;
|
|
319
|
+
if (
|
|
320
|
+
line.text.trim().length > 0 &&
|
|
321
|
+
importerBlockIndent !== null &&
|
|
322
|
+
indent <= importerBlockIndent
|
|
323
|
+
) {
|
|
324
|
+
importerBlockIndent = null;
|
|
325
|
+
}
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
sawDiff = true;
|
|
329
|
+
if (line.kind === "add") {
|
|
330
|
+
const text = line.text;
|
|
331
|
+
const indent = text.length - text.trimStart().length;
|
|
332
|
+
const key = IMPORTER_KEY.exec(text);
|
|
333
|
+
if (key) {
|
|
334
|
+
missionIds.add(key[1]);
|
|
335
|
+
importerBlockIndent = indent;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (importerBlockIndent !== null && (indent > importerBlockIndent || text.trim() === "")) {
|
|
339
|
+
continue; // member of an open importer block
|
|
340
|
+
}
|
|
341
|
+
if (indent <= (importerBlockIndent ?? indent)) importerBlockIndent = null;
|
|
342
|
+
// Non-importer additions must anchor inside the dependency-graph
|
|
343
|
+
// sections — the induced write never touches anything else.
|
|
344
|
+
const section = topLevelSectionAt(headLines, line.oldLine);
|
|
345
|
+
if (section === "packages" || section === "snapshots") continue;
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
// removed line
|
|
349
|
+
const text = line.text;
|
|
350
|
+
if (OPTIONAL_TRUE.test(text)) {
|
|
351
|
+
const owner = secondLevelKeyAt(headLines, line.oldLine, "snapshots");
|
|
352
|
+
if (owner === null) return null;
|
|
353
|
+
optionalRemovedOn.add(owner);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const removedKey = /^(\s*'?[^:]*'?):\s*$/.exec(text);
|
|
357
|
+
if (removedKey) {
|
|
358
|
+
// allowed only as the `key:` → `key: {}` collapse — an added
|
|
359
|
+
// `key: {}` must appear somewhere in the diff.
|
|
360
|
+
collapsedKeys.add(removedKey[1].trim());
|
|
361
|
+
const owner = removedKey[1].trim().replace(/^'|'$/g, "");
|
|
362
|
+
const section = topLevelSectionAt(headLines, line.oldLine);
|
|
363
|
+
if (section !== "snapshots") return null;
|
|
364
|
+
optionalRemovedOn.add(owner);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
if (!sawDiff || missionIds.size === 0) return null;
|
|
370
|
+
// every removed `key:` must be matched by an added `key: {}` — an
|
|
371
|
+
// unmatched one is a real snapshot removal, not a collapse.
|
|
372
|
+
for (const key of collapsedKeys) {
|
|
373
|
+
const hasPair = lines.some((l) => l.kind === "add" && l.text.trim() === `${key}: {}`);
|
|
374
|
+
if (!hasPair) return null;
|
|
375
|
+
}
|
|
376
|
+
const reachable = reachableSnapshotKeys(workText, [...missionIds]);
|
|
377
|
+
for (const owner of optionalRemovedOn) {
|
|
378
|
+
if (!reachable.has(owner)) return null;
|
|
379
|
+
}
|
|
380
|
+
return [...missionIds].sort();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* ADR-0130 prune direction: removed lines must still be importer-block
|
|
385
|
+
* members (strict rule); added lines are tolerated only when they anchor
|
|
386
|
+
* inside `packages:`/`snapshots:` — the inverse induced write (`optional:
|
|
387
|
+
* true` re-additions, `transitivePeerDependencies`, snapshot entries).
|
|
388
|
+
*/
|
|
389
|
+
export function classifyLockfilePruneIdsExtended(
|
|
390
|
+
diffText: string,
|
|
391
|
+
headText: string,
|
|
392
|
+
): string[] | null {
|
|
393
|
+
const strict = classifyLockfilePruneIds(diffText);
|
|
394
|
+
if (strict !== null) return strict;
|
|
395
|
+
const headLines = headText.split("\n");
|
|
396
|
+
const lines = parseDiffLines(diffText);
|
|
397
|
+
const ids = new Set<string>();
|
|
398
|
+
const expandedKeys = new Set<string>();
|
|
399
|
+
let sawImporterKey = false;
|
|
400
|
+
let openBlockIndent: number | null = null;
|
|
401
|
+
for (const line of lines) {
|
|
402
|
+
if (line.kind === "hunk") {
|
|
403
|
+
openBlockIndent = null;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (line.kind === "ctx") {
|
|
407
|
+
const indent = line.text.length - line.text.trimStart().length;
|
|
408
|
+
if (line.text.trim().length > 0 && openBlockIndent !== null && indent <= openBlockIndent) {
|
|
409
|
+
openBlockIndent = null;
|
|
410
|
+
}
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (line.kind === "add") {
|
|
414
|
+
const section = topLevelSectionAt(headLines, line.oldLine);
|
|
415
|
+
if (section === "packages" || section === "snapshots") continue;
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
const text = line.text;
|
|
419
|
+
if (text.trim().length === 0) {
|
|
420
|
+
if (openBlockIndent === null) return null;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
// inverse of the materialize collapse — the prune re-expands
|
|
424
|
+
// `key: {}` into `key:` + `optional: true` children.
|
|
425
|
+
const emptyEntry = /^(\s*'?[^:]*'?):\s*\{\}\s*$/.exec(text);
|
|
426
|
+
if (emptyEntry) {
|
|
427
|
+
const section = topLevelSectionAt(headLines, line.oldLine);
|
|
428
|
+
if (section === "snapshots" || section === "packages") {
|
|
429
|
+
expandedKeys.add(emptyEntry[1].trim());
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
const indent = text.length - text.trimStart().length;
|
|
435
|
+
const key = IMPORTER_KEY.exec(text);
|
|
436
|
+
if (key) {
|
|
437
|
+
sawImporterKey = true;
|
|
438
|
+
ids.add(key[1]);
|
|
439
|
+
openBlockIndent = indent;
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (openBlockIndent !== null && indent > openBlockIndent) continue;
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
if (!sawImporterKey) return null;
|
|
446
|
+
// every removed `key: {}` must pair with an added `key:` — an unmatched
|
|
447
|
+
// one is a real snapshot removal, not a re-expansion.
|
|
448
|
+
for (const key of expandedKeys) {
|
|
449
|
+
const hasPair = lines.some((l) => l.kind === "add" && l.text.trim() === `${key}:`);
|
|
450
|
+
if (!hasPair) return null;
|
|
451
|
+
}
|
|
452
|
+
return [...ids].sort();
|
|
453
|
+
}
|
|
454
|
+
|
|
153
455
|
/** Classify the pnpm-lock.yaml diff of `repo` when the lockfile is dirty. */
|
|
154
456
|
async function classifyDirtyLockfile(
|
|
155
457
|
repo: string,
|
|
@@ -172,12 +474,79 @@ export type { DirtyClass } from "./dirty-classify.ts";
|
|
|
172
474
|
export interface ToleratedEntry {
|
|
173
475
|
path: string;
|
|
174
476
|
class: DirtyClass;
|
|
477
|
+
/** RFC-1544: pruned mission ids for the lockfile importer classes. */
|
|
478
|
+
missionIds?: string[];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* RFC-1544: referent state for one pruned `missions/<id>/workpiece` importer
|
|
483
|
+
* — where the directory still exists and whether its mission is open. The
|
|
484
|
+
* classifier stays pure: referents are injected by the caller.
|
|
485
|
+
*/
|
|
486
|
+
export interface ImporterReferent {
|
|
487
|
+
missionId: string;
|
|
488
|
+
/** `missions/<id>/workpiece` exists in the checkout being classified. */
|
|
489
|
+
existsHere: boolean;
|
|
490
|
+
/** Other registered worktrees where the directory exists. */
|
|
491
|
+
existsInCheckout: string[];
|
|
492
|
+
/** An open `missions/<id>/mission.yaml` exists in any registered checkout. */
|
|
493
|
+
missionOpen: boolean;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Default referent resolver — `git worktree list` for the checkout set and
|
|
498
|
+
* `openMissionsIn` per checkout for mission state (the same enumeration
|
|
499
|
+
* `flow.status` performs; never cwd-relative guesses).
|
|
500
|
+
*/
|
|
501
|
+
export async function resolveImporterReferents(
|
|
502
|
+
repo: string,
|
|
503
|
+
io: WorkspaceIO,
|
|
504
|
+
missionIds: string[],
|
|
505
|
+
): Promise<ImporterReferent[]> {
|
|
506
|
+
const worktrees = await worktreeList(repo, io);
|
|
507
|
+
const here = canonicalRepoDir(repo);
|
|
508
|
+
const others = worktrees.filter((w) => w.path !== here).map((w) => w.path);
|
|
509
|
+
const openCache = new Map<string, Set<string>>();
|
|
510
|
+
const openIn = async (dir: string): Promise<Set<string>> => {
|
|
511
|
+
let set = openCache.get(dir);
|
|
512
|
+
if (set === undefined) {
|
|
513
|
+
try {
|
|
514
|
+
set = new Set(await openMissionsIn(dir, io));
|
|
515
|
+
} catch {
|
|
516
|
+
set = new Set();
|
|
517
|
+
}
|
|
518
|
+
openCache.set(dir, set);
|
|
519
|
+
}
|
|
520
|
+
return set;
|
|
521
|
+
};
|
|
522
|
+
const out: ImporterReferent[] = [];
|
|
523
|
+
for (const missionId of missionIds) {
|
|
524
|
+
const rel = join("missions", missionId, "workpiece");
|
|
525
|
+
const existsHere = await io.exists(join(repo, rel));
|
|
526
|
+
const existsInCheckout: string[] = [];
|
|
527
|
+
for (const dir of others) {
|
|
528
|
+
if (await io.exists(join(dir, rel))) existsInCheckout.push(dir);
|
|
529
|
+
}
|
|
530
|
+
let missionOpen = (await openIn(repo)).has(missionId);
|
|
531
|
+
for (const dir of others) {
|
|
532
|
+
if (!missionOpen && (await openIn(dir)).has(missionId)) missionOpen = true;
|
|
533
|
+
}
|
|
534
|
+
out.push({ missionId, existsHere, existsInCheckout: existsInCheckout.sort(), missionOpen });
|
|
535
|
+
}
|
|
536
|
+
return out;
|
|
175
537
|
}
|
|
176
538
|
|
|
177
539
|
export interface DirtVerdict {
|
|
178
540
|
tolerated: ToleratedEntry[];
|
|
179
541
|
/** Porcelain lines that match no declared regenerable shape — still refuse. */
|
|
180
542
|
unattributed: string[];
|
|
543
|
+
/**
|
|
544
|
+
* RFC-1543: unattributed paths covered by a LIVE op-claim — class
|
|
545
|
+
* `in-flight-foreign`. They never block silently: the caller either waits
|
|
546
|
+
* for the holder or refuses FLOW-INT-03 naming it. Resolved only for the
|
|
547
|
+
* primary checkout — worktrees are single-owner.
|
|
548
|
+
*/
|
|
549
|
+
foreignInFlight: { path: string; holder: OpClaim }[];
|
|
181
550
|
}
|
|
182
551
|
|
|
183
552
|
const TWIN_ROOT = ".agents/skills/";
|
|
@@ -236,9 +605,12 @@ export async function classifyDirt(
|
|
|
236
605
|
io: WorkspaceIO,
|
|
237
606
|
entries: string[],
|
|
238
607
|
deps: { runGit: typeof git } = { runGit: git },
|
|
608
|
+
claims: OpClaim[] = [],
|
|
609
|
+
resolveReferents?: (missionIds: string[]) => Promise<ImporterReferent[]>,
|
|
239
610
|
): Promise<DirtVerdict> {
|
|
240
611
|
const tolerated: ToleratedEntry[] = [];
|
|
241
612
|
const unattributed: string[] = [];
|
|
613
|
+
const foreignInFlight: { path: string; holder: OpClaim }[] = [];
|
|
242
614
|
const byPath = new Map<string, string[]>();
|
|
243
615
|
for (const line of entries) {
|
|
244
616
|
const p = line.slice(3).trim();
|
|
@@ -256,11 +628,70 @@ export async function classifyDirt(
|
|
|
256
628
|
outer: for (const [path, lines] of byPath) {
|
|
257
629
|
if (path === "pnpm-lock.yaml") {
|
|
258
630
|
const diff = await deps.runGit(repo, io, ["diff", "HEAD", "--", "pnpm-lock.yaml"]);
|
|
259
|
-
|
|
260
|
-
|
|
631
|
+
// ADR-0130: the induced-change shapes need the HEAD and working
|
|
632
|
+
// contents — fetched lazily, only when the strict shapes miss.
|
|
633
|
+
let headLock: string | null = null;
|
|
634
|
+
let workLock: string | null = null;
|
|
635
|
+
const lockContents = async (): Promise<{ head: string; work: string } | null> => {
|
|
636
|
+
if (headLock === null || workLock === null) {
|
|
637
|
+
const head = await deps.runGit(repo, io, ["show", "HEAD:pnpm-lock.yaml"]);
|
|
638
|
+
if (head.exitCode !== 0) return null;
|
|
639
|
+
let work: string;
|
|
640
|
+
try {
|
|
641
|
+
work = await io.readFile(join(repo, "pnpm-lock.yaml"));
|
|
642
|
+
} catch {
|
|
643
|
+
return null; // reduced io — degrade to the strict-shape verdict
|
|
644
|
+
}
|
|
645
|
+
headLock = head.stdout;
|
|
646
|
+
workLock = work;
|
|
647
|
+
}
|
|
648
|
+
return { head: headLock, work: workLock };
|
|
649
|
+
};
|
|
650
|
+
let pruneIds = classifyLockfilePruneIds(diff.stdout);
|
|
651
|
+
if (pruneIds === null) {
|
|
652
|
+
const contents = await lockContents();
|
|
653
|
+
if (contents !== null) {
|
|
654
|
+
pruneIds = classifyLockfilePruneIdsExtended(diff.stdout, contents.head);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (pruneIds !== null) {
|
|
658
|
+
// RFC-1544: the pruned importer's referent decides the class — a
|
|
659
|
+
// foreign checkout's open mission (foreign-open-mission, auto-
|
|
660
|
+
// restored by flow.integrate), dead residue (importer-prune-stale,
|
|
661
|
+
// accepted cleanup), or anything else (importer-prune, unchanged).
|
|
662
|
+
// An unresolvable referent set (no exec/ io capability) degrades to
|
|
663
|
+
// the inert importer-prune — "couldn't resolve" is not "resolved to
|
|
664
|
+
// nothing".
|
|
665
|
+
let referents: ImporterReferent[] | undefined;
|
|
666
|
+
if (resolveReferents !== undefined) {
|
|
667
|
+
try {
|
|
668
|
+
referents = await resolveReferents(pruneIds);
|
|
669
|
+
} catch {
|
|
670
|
+
referents = undefined;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (
|
|
674
|
+
referents !== undefined &&
|
|
675
|
+
referents.every((r) => !r.existsHere && r.missionOpen && r.existsInCheckout.length > 0)
|
|
676
|
+
) {
|
|
677
|
+
tolerated.push({ path, class: "foreign-open-mission", missionIds: pruneIds });
|
|
678
|
+
} else if (
|
|
679
|
+
referents !== undefined &&
|
|
680
|
+
referents.every((r) => !r.existsHere && r.existsInCheckout.length === 0 && !r.missionOpen)
|
|
681
|
+
) {
|
|
682
|
+
tolerated.push({ path, class: "importer-prune-stale", missionIds: pruneIds });
|
|
683
|
+
} else {
|
|
684
|
+
tolerated.push({ path, class: "importer-prune", missionIds: pruneIds });
|
|
685
|
+
}
|
|
261
686
|
continue;
|
|
262
687
|
}
|
|
263
|
-
|
|
688
|
+
let ids = classifyLockfileMaterialize(diff.stdout);
|
|
689
|
+
if (ids === null) {
|
|
690
|
+
const contents = await lockContents();
|
|
691
|
+
if (contents !== null) {
|
|
692
|
+
ids = classifyLockfileMaterializeExtended(diff.stdout, contents.head, contents.work);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
264
695
|
if (ids !== null) {
|
|
265
696
|
const open = await openMissionIds();
|
|
266
697
|
if (ids.every((id) => open.has(id))) {
|
|
@@ -346,7 +777,20 @@ export async function classifyDirt(
|
|
|
346
777
|
}
|
|
347
778
|
unattributed.push(...lines);
|
|
348
779
|
}
|
|
349
|
-
|
|
780
|
+
// RFC-1543 AC-3: unattributed paths covered by a live claim reclassify as
|
|
781
|
+
// in-flight-foreign — every other unattributed path stays work-class.
|
|
782
|
+
if (claims.length > 0) {
|
|
783
|
+
const stillUnattributed: string[] = [];
|
|
784
|
+
for (const line of unattributed) {
|
|
785
|
+
const path = line.slice(3).trim();
|
|
786
|
+
const holder = claims.find((c) => claimCoversPath(c, path));
|
|
787
|
+
if (holder !== undefined) foreignInFlight.push({ path, holder });
|
|
788
|
+
else stillUnattributed.push(line);
|
|
789
|
+
}
|
|
790
|
+
unattributed.length = 0;
|
|
791
|
+
unattributed.push(...stillUnattributed);
|
|
792
|
+
}
|
|
793
|
+
return { tolerated, unattributed, foreignInFlight };
|
|
350
794
|
}
|
|
351
795
|
|
|
352
796
|
/**
|
|
@@ -367,6 +811,9 @@ export async function classifyDirtyEntries(
|
|
|
367
811
|
path: t.path,
|
|
368
812
|
class: t.class,
|
|
369
813
|
}));
|
|
814
|
+
for (const f of verdict.foreignInFlight) {
|
|
815
|
+
out.push({ path: f.path, class: "in-flight-foreign" });
|
|
816
|
+
}
|
|
370
817
|
for (const line of verdict.unattributed) {
|
|
371
818
|
const path = line.slice(3).trim();
|
|
372
819
|
out.push({ path, class: classifyDirtyPath(path) });
|
|
@@ -416,6 +863,12 @@ export async function runIntegratePreflight(
|
|
|
416
863
|
/** Already-computed statusDirty() of the branch worktree. */
|
|
417
864
|
worktreeDirty: { entries: string[]; toleratedState: string[] };
|
|
418
865
|
invoke?: ForgeInvokeCommand;
|
|
866
|
+
/**
|
|
867
|
+
* RFC-1543 AC-4: seconds to wait for live foreign claim-holders before
|
|
868
|
+
* FLOW-INT-03 refuses — default 600, 0 restores fail-fast.
|
|
869
|
+
*/
|
|
870
|
+
waitForeignSeconds?: number;
|
|
871
|
+
onProgress?: (line: string) => void;
|
|
419
872
|
commandRegistry?: CommandRegistry;
|
|
420
873
|
/** Test seam — overrides the live inventory union (registry + command manifest). */
|
|
421
874
|
commands?: ForgeRegisteredCommandInfo[];
|
|
@@ -452,7 +905,8 @@ export async function runIntegratePreflight(
|
|
|
452
905
|
refuse: {
|
|
453
906
|
ruleId: "WT-GATE-01",
|
|
454
907
|
message: `worktree has ${openMissions.length} open mission(s): ${openMissions.join(", ")}`,
|
|
455
|
-
fixHint:
|
|
908
|
+
fixHint:
|
|
909
|
+
"close or abort the mission(s) in the worktree before integrating or tearing down",
|
|
456
910
|
data: { openMissions },
|
|
457
911
|
},
|
|
458
912
|
};
|
|
@@ -465,9 +919,16 @@ export async function runIntegratePreflight(
|
|
|
465
919
|
// regenerable classes journal as tolerated (RFC-1537).
|
|
466
920
|
checked.push("worktree-dirty");
|
|
467
921
|
if (opts.worktreeDirty.entries.length > 0) {
|
|
468
|
-
const verdict = await classifyDirt(
|
|
469
|
-
|
|
470
|
-
|
|
922
|
+
const verdict = await classifyDirt(
|
|
923
|
+
opts.branchWorktree,
|
|
924
|
+
io,
|
|
925
|
+
opts.worktreeDirty.entries,
|
|
926
|
+
{
|
|
927
|
+
runGit: deps.runGit,
|
|
928
|
+
},
|
|
929
|
+
[],
|
|
930
|
+
(ids) => resolveImporterReferents(opts.branchWorktree, io, ids),
|
|
931
|
+
);
|
|
471
932
|
tolerated.push(...verdict.tolerated);
|
|
472
933
|
if (verdict.unattributed.length > 0) {
|
|
473
934
|
const lockfile = await classifyDirtyLockfile(
|
|
@@ -521,19 +982,57 @@ export async function runIntegratePreflight(
|
|
|
521
982
|
// classification; the post-gate check stays (primary can dirty mid-gate).
|
|
522
983
|
checked.push("primary-dirty");
|
|
523
984
|
const primaryBranch = await deps.runCurrentBranch(opts.primary, io);
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
985
|
+
// RFC-1543 AC-4: primary-side foreign claims get a bounded wait — the poll
|
|
986
|
+
// re-reads both dirt and claims (≤30s cadence) until they clear or the
|
|
987
|
+
// budget expires; unattributed work refuses instantly as before.
|
|
988
|
+
const waitForeignMs = Math.max(0, (opts.waitForeignSeconds ?? 600) * 1000);
|
|
989
|
+
const foreignDeadline = Date.now() + waitForeignMs;
|
|
990
|
+
let primaryClean = false;
|
|
991
|
+
for (;;) {
|
|
992
|
+
const primaryDirty = await deps.runStatusTracked(opts.primary, io);
|
|
993
|
+
if (primaryDirty.entries.length === 0) {
|
|
994
|
+
primaryClean = true;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
const verdict = await classifyDirt(
|
|
998
|
+
opts.primary,
|
|
999
|
+
io,
|
|
1000
|
+
primaryDirty.entries,
|
|
1001
|
+
{ runGit: deps.runGit },
|
|
1002
|
+
await liveClaims(opts.primary, io),
|
|
1003
|
+
(ids) => resolveImporterReferents(opts.primary, io, ids),
|
|
1004
|
+
);
|
|
529
1005
|
tolerated.push(...verdict.tolerated);
|
|
530
|
-
|
|
1006
|
+
const foreignOnly =
|
|
1007
|
+
verdict.unattributed.length === 0 &&
|
|
1008
|
+
verdict.foreignInFlight.length > 0 &&
|
|
1009
|
+
primaryBranch === "develop";
|
|
1010
|
+
if (foreignOnly && Date.now() < foreignDeadline) {
|
|
1011
|
+
const holders = verdict.foreignInFlight.map(
|
|
1012
|
+
(f) =>
|
|
1013
|
+
`${f.holder.command} ${f.holder.opId} (pid ${f.holder.pid}, started ${f.holder.startedAt})`,
|
|
1014
|
+
);
|
|
1015
|
+
opts.onProgress?.(
|
|
1016
|
+
`primary held by foreign op(s): ${holders.join("; ")} — waiting up to ${Math.ceil((foreignDeadline - Date.now()) / 1000)}s`,
|
|
1017
|
+
);
|
|
1018
|
+
await new Promise((r) => setTimeout(r, Math.min(30_000, foreignDeadline - Date.now())));
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
if (
|
|
1022
|
+
primaryBranch !== "develop" ||
|
|
1023
|
+
verdict.unattributed.length > 0 ||
|
|
1024
|
+
verdict.foreignInFlight.length > 0
|
|
1025
|
+
) {
|
|
531
1026
|
const lockfile = await classifyDirtyLockfile(
|
|
532
1027
|
opts.primary,
|
|
533
1028
|
io,
|
|
534
1029
|
verdict.unattributed,
|
|
535
1030
|
deps.runGit,
|
|
536
1031
|
);
|
|
1032
|
+
const holderNote =
|
|
1033
|
+
verdict.foreignInFlight.length > 0
|
|
1034
|
+
? ` — in-flight holder(s): ${verdict.foreignInFlight.map((f) => `${f.holder.command} ${f.holder.opId} (pid ${f.holder.pid})`).join("; ")}`
|
|
1035
|
+
: "";
|
|
537
1036
|
return {
|
|
538
1037
|
ok: false,
|
|
539
1038
|
checked,
|
|
@@ -544,25 +1043,49 @@ export async function runIntegratePreflight(
|
|
|
544
1043
|
message:
|
|
545
1044
|
(primaryBranch !== "develop"
|
|
546
1045
|
? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
|
|
547
|
-
:
|
|
1046
|
+
: verdict.unattributed.length > 0
|
|
1047
|
+
? // ADR-0129 (F-0186): name the paths — the remedy differs by
|
|
1048
|
+
// whose work each one is.
|
|
1049
|
+
`primary worktree has ${verdict.unattributed.length} uncommitted change(s): ${verdict.unattributed
|
|
1050
|
+
.slice(0, 20)
|
|
1051
|
+
.map((line) => line.slice(3).trim())
|
|
1052
|
+
.join(", ")}` +
|
|
1053
|
+
(verdict.unattributed.length > 20
|
|
1054
|
+
? ` (+${verdict.unattributed.length - 20} more)`
|
|
1055
|
+
: "")
|
|
1056
|
+
: `primary worktree held by ${verdict.foreignInFlight.length} in-flight foreign op(s)`) +
|
|
1057
|
+
holderNote +
|
|
548
1058
|
(verdict.tolerated.length > 0
|
|
549
1059
|
? ` — tolerated regenerable state: ${verdict.tolerated.map((t) => `${t.path} (${t.class})`).join(", ")}`
|
|
550
1060
|
: "") +
|
|
551
1061
|
(lockfile === "importer-prune-only" ? ` — pnpm-lock.yaml${LOCKFILE_PRUNE_HINT}` : ""),
|
|
552
1062
|
fixHint:
|
|
553
|
-
|
|
1063
|
+
primaryBranch !== "develop"
|
|
1064
|
+
? "switch the primary to develop and commit or revert its tracked changes, then re-run — the branch stays rebased"
|
|
1065
|
+
: `${FOREIGN_PRIMARY_DIRT_HINT}, then re-run`,
|
|
554
1066
|
data: {
|
|
1067
|
+
unattributed: verdict.unattributed.map((line) => line.slice(3).trim()),
|
|
555
1068
|
entries: verdict.unattributed.map((line) => {
|
|
556
1069
|
const path = line.slice(3).trim();
|
|
557
1070
|
return { path, class: classifyDirtyPath(path) };
|
|
558
1071
|
}),
|
|
1072
|
+
foreignHolders: verdict.foreignInFlight.map((f) => ({
|
|
1073
|
+
path: f.path,
|
|
1074
|
+
opId: f.holder.opId,
|
|
1075
|
+
command: f.holder.command,
|
|
1076
|
+
pid: f.holder.pid,
|
|
1077
|
+
startedAt: f.holder.startedAt,
|
|
1078
|
+
})),
|
|
559
1079
|
toleratedDirt: verdict.tolerated,
|
|
560
1080
|
...(lockfile !== null ? { lockfileClassification: lockfile } : {}),
|
|
561
1081
|
},
|
|
562
1082
|
},
|
|
563
1083
|
};
|
|
564
1084
|
}
|
|
565
|
-
|
|
1085
|
+
primaryClean = true;
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
if (!primaryClean && primaryBranch !== "develop") {
|
|
566
1089
|
return {
|
|
567
1090
|
ok: false,
|
|
568
1091
|
checked,
|
|
@@ -577,24 +1100,17 @@ export async function runIntegratePreflight(
|
|
|
577
1100
|
};
|
|
578
1101
|
}
|
|
579
1102
|
|
|
580
|
-
// (3) ecosystem.manifest.validate — stale generated manifest
|
|
1103
|
+
// (3) ecosystem.manifest.validate — stale generated manifest is a
|
|
1104
|
+
// recoverable violation (RFC-1546): the failure is recorded and the
|
|
1105
|
+
// remaining checks still run. Only when the drift is the SOLE violation
|
|
1106
|
+
// does the owner command regenerate in place and the validator re-run —
|
|
1107
|
+
// a coexisting refusal below must skip the regeneration entirely.
|
|
1108
|
+
let manifestDrift: { summary?: string; exitCode?: number } | undefined;
|
|
581
1109
|
if (resolvable("ecosystem.manifest.validate")) {
|
|
582
1110
|
checked.push("ecosystem.manifest.validate");
|
|
583
1111
|
const result = await opts.invoke!("ecosystem.manifest.validate", {});
|
|
584
1112
|
if (result.ok === false || (result.exitCode !== undefined && result.exitCode !== 0)) {
|
|
585
|
-
|
|
586
|
-
ok: false,
|
|
587
|
-
checked,
|
|
588
|
-
skipped,
|
|
589
|
-
tolerated,
|
|
590
|
-
refuse: {
|
|
591
|
-
ruleId: "FLOW-INT-12",
|
|
592
|
-
message: `preflight: ecosystem.manifest.validate refused — ${result.summary ?? `exit ${result.exitCode}`}`,
|
|
593
|
-
fixHint:
|
|
594
|
-
"regenerate the manifest via `pnpm exec werkstatt run ecosystem.manifest.generate`, commit, then re-run flow.integrate",
|
|
595
|
-
data: { command: "ecosystem.manifest.validate", summary: result.summary },
|
|
596
|
-
},
|
|
597
|
-
};
|
|
1113
|
+
manifestDrift = { summary: result.summary, exitCode: result.exitCode };
|
|
598
1114
|
}
|
|
599
1115
|
} else {
|
|
600
1116
|
skipped.push({
|
|
@@ -622,7 +1138,9 @@ export async function runIntegratePreflight(
|
|
|
622
1138
|
l.trim(),
|
|
623
1139
|
)?.[1],
|
|
624
1140
|
)
|
|
625
|
-
.
|
|
1141
|
+
// rfc-0000-template.md is corpus-excluded (listRfcFiles) — it is a
|
|
1142
|
+
// template, not a validateable RFC.
|
|
1143
|
+
.filter((m): m is string => m !== undefined && m !== "0000")
|
|
626
1144
|
.map((n) => `RFC-${n.padStart(4, "0")}`),
|
|
627
1145
|
),
|
|
628
1146
|
];
|
|
@@ -680,6 +1198,41 @@ export async function runIntegratePreflight(
|
|
|
680
1198
|
});
|
|
681
1199
|
}
|
|
682
1200
|
|
|
1201
|
+
// RFC-1546: every other check passed — the manifest drift is the sole
|
|
1202
|
+
// violation, so the owner command regenerates in place and the validator
|
|
1203
|
+
// re-runs. A coexisting violation already refused above without ever
|
|
1204
|
+
// reaching the regeneration.
|
|
1205
|
+
if (manifestDrift !== undefined) {
|
|
1206
|
+
if (resolvable("ecosystem.manifest.generate")) {
|
|
1207
|
+
const regen = await opts.invoke!(
|
|
1208
|
+
"ecosystem.manifest.generate",
|
|
1209
|
+
REGEN_FLAGS["ecosystem.manifest.generate"] ?? {},
|
|
1210
|
+
);
|
|
1211
|
+
if (regen.ok !== false && (regen.exitCode === undefined || regen.exitCode === 0)) {
|
|
1212
|
+
checked.push("ecosystem.manifest.generate", "ecosystem.manifest.validate");
|
|
1213
|
+
const result = await opts.invoke!("ecosystem.manifest.validate", {});
|
|
1214
|
+
if (result.ok !== false && (result.exitCode === undefined || result.exitCode === 0)) {
|
|
1215
|
+
manifestDrift = undefined;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (manifestDrift !== undefined) {
|
|
1220
|
+
return {
|
|
1221
|
+
ok: false,
|
|
1222
|
+
checked,
|
|
1223
|
+
skipped,
|
|
1224
|
+
tolerated,
|
|
1225
|
+
refuse: {
|
|
1226
|
+
ruleId: "FLOW-INT-12",
|
|
1227
|
+
message: `preflight: ecosystem.manifest.validate refused — ${manifestDrift.summary ?? `exit ${manifestDrift.exitCode}`}`,
|
|
1228
|
+
fixHint:
|
|
1229
|
+
"regenerate the manifest via `pnpm exec werkstatt run ecosystem.manifest.generate`, commit, then re-run flow.integrate",
|
|
1230
|
+
data: { command: "ecosystem.manifest.validate", summary: manifestDrift.summary },
|
|
1231
|
+
},
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
683
1236
|
return { ok: true, checked, skipped, tolerated };
|
|
684
1237
|
}
|
|
685
1238
|
|
|
@@ -699,7 +1252,7 @@ export interface RebaseConflictVerdict {
|
|
|
699
1252
|
}
|
|
700
1253
|
|
|
701
1254
|
/** `.generated.` basenames whose owner command is fixed by convention. */
|
|
702
|
-
const GENERATED_BASENAME_OWNERS: Record<string, string> = {
|
|
1255
|
+
export const GENERATED_BASENAME_OWNERS: Record<string, string> = {
|
|
703
1256
|
"ecosystem.generated.yaml": "ecosystem.manifest.generate",
|
|
704
1257
|
"command-manifest.generated.yaml": "command.manifest.generate",
|
|
705
1258
|
};
|