@warpgogol/forge 9.4.1 → 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 +15 -0
- 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 +7 -0
- package/dist/os/flow/dirty-classify.d.ts.map +1 -1
- package/dist/os/flow/dirty-classify.js +11 -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 +3 -2
- 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-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +59 -26
- 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/index.d.ts +1 -0
- package/dist/os/flow/index.d.ts.map +1 -1
- package/dist/os/flow/index.js +5 -3
- package/dist/os/flow/index.js.map +1 -1
- package/dist/os/flow/preflight.d.ts +24 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +354 -10
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/registry.d.ts +2 -2
- 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/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/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/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/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 +13 -0
- package/os/flow/flow.module.ts +3 -2
- package/os/flow/handlers/flow-check.ts +17 -18
- package/os/flow/handlers/flow-integrate.ts +75 -35
- package/os/flow/handlers/flow-open.ts +24 -31
- package/os/flow/index.ts +5 -7
- package/os/flow/preflight.ts +351 -9
- package/os/flow/tests/flow-integrate.preflight.test.ts +26 -5
- package/os/flow/tests/flow-integrate.test.ts +68 -2
- package/os/flow/tests/lockfile-induced.test.ts +328 -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/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 +14 -5
- 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/package.json +17 -1
- package/skills/fo/fo-session-retro/SKILL.md +4 -2
- package/src/cli-flags.ts +7 -0
- package/src/types.ts +9 -8
package/os/flow/preflight.ts
CHANGED
|
@@ -14,16 +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-1531: shared DirtyClass enum via dirty-classify.ts (Q-4), classified FLOW-INT-01/03 data.entries, classifyDirtyEntries for the remediation flags</item>
|
|
18
|
-
<item>RFC-1546: derive-and-repair recoverable state across flow surfaces (AC-1..AC-5)</item>
|
|
19
|
-
<item>RFC-1545: standalone generated-conflict regeneration in flow.integrate</item>
|
|
20
17
|
<item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
|
|
21
18
|
<item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
|
|
22
|
-
<
|
|
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>
|
|
23
23
|
</CHANGE_SUMMARY>
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { basename, dirname, join } from "node:path";
|
|
27
|
+
import { parse as parseYaml } from "yaml";
|
|
27
28
|
|
|
28
29
|
import type {
|
|
29
30
|
CommandRegistry,
|
|
@@ -37,6 +38,7 @@ import { isGeneratedContent, isGeneratedPathName, REGEN_FLAGS } from "../core/ar
|
|
|
37
38
|
import { openMissionsIn } from "../mission/open-missions.ts";
|
|
38
39
|
import {
|
|
39
40
|
classifyDirtyPath,
|
|
41
|
+
FOREIGN_PRIMARY_DIRT_HINT,
|
|
40
42
|
summarizeClasses,
|
|
41
43
|
type ClassifiedDirtyEntry,
|
|
42
44
|
type DirtyClass,
|
|
@@ -154,6 +156,302 @@ export function classifyLockfileMaterialize(diffText: string): string[] | null {
|
|
|
154
156
|
return sawImporterKey ? [...ids].sort() : null;
|
|
155
157
|
}
|
|
156
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
|
+
|
|
157
455
|
/** Classify the pnpm-lock.yaml diff of `repo` when the lockfile is dirty. */
|
|
158
456
|
async function classifyDirtyLockfile(
|
|
159
457
|
repo: string,
|
|
@@ -330,7 +628,32 @@ export async function classifyDirt(
|
|
|
330
628
|
outer: for (const [path, lines] of byPath) {
|
|
331
629
|
if (path === "pnpm-lock.yaml") {
|
|
332
630
|
const diff = await deps.runGit(repo, io, ["diff", "HEAD", "--", "pnpm-lock.yaml"]);
|
|
333
|
-
|
|
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
|
+
}
|
|
334
657
|
if (pruneIds !== null) {
|
|
335
658
|
// RFC-1544: the pruned importer's referent decides the class — a
|
|
336
659
|
// foreign checkout's open mission (foreign-open-mission, auto-
|
|
@@ -362,7 +685,13 @@ export async function classifyDirt(
|
|
|
362
685
|
}
|
|
363
686
|
continue;
|
|
364
687
|
}
|
|
365
|
-
|
|
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
|
+
}
|
|
366
695
|
if (ids !== null) {
|
|
367
696
|
const open = await openMissionIds();
|
|
368
697
|
if (ids.every((id) => open.has(id))) {
|
|
@@ -715,7 +1044,15 @@ export async function runIntegratePreflight(
|
|
|
715
1044
|
(primaryBranch !== "develop"
|
|
716
1045
|
? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
|
|
717
1046
|
: verdict.unattributed.length > 0
|
|
718
|
-
?
|
|
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
|
+
: "")
|
|
719
1056
|
: `primary worktree held by ${verdict.foreignInFlight.length} in-flight foreign op(s)`) +
|
|
720
1057
|
holderNote +
|
|
721
1058
|
(verdict.tolerated.length > 0
|
|
@@ -723,8 +1060,11 @@ export async function runIntegratePreflight(
|
|
|
723
1060
|
: "") +
|
|
724
1061
|
(lockfile === "importer-prune-only" ? ` — pnpm-lock.yaml${LOCKFILE_PRUNE_HINT}` : ""),
|
|
725
1062
|
fixHint:
|
|
726
|
-
|
|
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`,
|
|
727
1066
|
data: {
|
|
1067
|
+
unattributed: verdict.unattributed.map((line) => line.slice(3).trim()),
|
|
728
1068
|
entries: verdict.unattributed.map((line) => {
|
|
729
1069
|
const path = line.slice(3).trim();
|
|
730
1070
|
return { path, class: classifyDirtyPath(path) };
|
|
@@ -798,7 +1138,9 @@ export async function runIntegratePreflight(
|
|
|
798
1138
|
l.trim(),
|
|
799
1139
|
)?.[1],
|
|
800
1140
|
)
|
|
801
|
-
.
|
|
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")
|
|
802
1144
|
.map((n) => `RFC-${n.padStart(4, "0")}`),
|
|
803
1145
|
),
|
|
804
1146
|
];
|
|
@@ -9,13 +9,11 @@ git/status/invoke seams.</purpose>
|
|
|
9
9
|
</non-goals>
|
|
10
10
|
</MODULE_CONTRACT>
|
|
11
11
|
<CHANGE_SUMMARY>
|
|
12
|
-
<item>RFC-1528: flow.integrate bounded preflight before rebase and gate
|
|
13
|
-
|
|
14
|
-
Classified lockfile diffs on FLOW-INT-01/03, early primary check, and resolvable validators (ecosystem.manifest.validate, scoped rfc.validate, friction.validate) refusing as FLOW-INT-12/13/14.</item>
|
|
15
12
|
<item>RFC-1528: close review findings — manifest-union command inventory for regen/preflight</item>
|
|
16
13
|
<item>RFC-1537: classify regenerable worktree dirt and journal integrate refusals cheapest-first</item>
|
|
17
14
|
<item>RFC-1546: derive-and-repair recoverable state across flow surfaces (AC-1..AC-5)</item>
|
|
18
15
|
<item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
|
|
16
|
+
<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>
|
|
19
17
|
<history>RFC-1528</history>
|
|
20
18
|
</CHANGE_SUMMARY>
|
|
21
19
|
*/
|
|
@@ -206,6 +204,30 @@ describe("runIntegratePreflight (RFC-1528 AC-2/AC-4)", () => {
|
|
|
206
204
|
expect(invokes).toEqual([]);
|
|
207
205
|
});
|
|
208
206
|
|
|
207
|
+
it("FLOW-INT-03 names the unattributed paths and the three-way remedy (ADR-0129 F-0186)", async () => {
|
|
208
|
+
const entries = Array.from(
|
|
209
|
+
{ length: 23 },
|
|
210
|
+
(_, i) => ` M docs/file-${String(i).padStart(2, "0")}.md`,
|
|
211
|
+
);
|
|
212
|
+
const result = await runIntegratePreflight(
|
|
213
|
+
baseOpts({
|
|
214
|
+
invoke: async () => ({ ok: true, exitCode: 0 }) as ForgeInvokeResult,
|
|
215
|
+
}),
|
|
216
|
+
stubDeps({
|
|
217
|
+
primaryDirty: { entries, toleratedState: [], vanished: false },
|
|
218
|
+
}),
|
|
219
|
+
);
|
|
220
|
+
expect(result.refuse?.ruleId).toBe("FLOW-INT-03");
|
|
221
|
+
expect(result.refuse?.message).toContain("docs/file-00.md");
|
|
222
|
+
expect(result.refuse?.message).toContain("docs/file-19.md");
|
|
223
|
+
expect(result.refuse?.message).not.toContain("docs/file-20.md");
|
|
224
|
+
expect(result.refuse?.message).toContain("(+3 more)");
|
|
225
|
+
expect(result.refuse?.fixHint).toContain("your own work");
|
|
226
|
+
expect(result.refuse?.fixHint).toContain("git show HEAD:<path> > <path>");
|
|
227
|
+
expect(result.refuse?.fixHint).toContain("another session's work in progress");
|
|
228
|
+
expect(result.refuse?.data?.unattributed).toHaveLength(23);
|
|
229
|
+
});
|
|
230
|
+
|
|
209
231
|
it("a stale manifest without a resolvable generator still refuses FLOW-INT-12 (RFC-1546: after the other checks establish sole-ness)", async () => {
|
|
210
232
|
const invokes: string[] = [];
|
|
211
233
|
const result = await runIntegratePreflight(
|
|
@@ -380,8 +402,7 @@ const ioWith = (shape: {
|
|
|
380
402
|
if (p in (shape.files ?? {})) return shape.files![p];
|
|
381
403
|
throw new Error(`ENOENT ${p}`);
|
|
382
404
|
},
|
|
383
|
-
exists: async (p: string) =>
|
|
384
|
-
p in (shape.files ?? {}) || (shape.dirs ?? []).includes(p),
|
|
405
|
+
exists: async (p: string) => p in (shape.files ?? {}) || (shape.dirs ?? []).includes(p),
|
|
385
406
|
readFileBytes: async (p: string) => {
|
|
386
407
|
if (p in (shape.files ?? {})) return new TextEncoder().encode(shape.files![p]);
|
|
387
408
|
throw new Error(`ENOENT ${p}`);
|
|
@@ -11,12 +11,12 @@ and a held integration lock is waited out.</purpose>
|
|
|
11
11
|
</non-goals>
|
|
12
12
|
</MODULE_CONTRACT>
|
|
13
13
|
<CHANGE_SUMMARY>
|
|
14
|
-
<item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
|
|
15
14
|
<item>RFC-1546: derive-and-repair recoverable state across flow surfaces (AC-1..AC-5)</item>
|
|
16
15
|
<item>RFC-1545: standalone generated-conflict regeneration in flow.integrate</item>
|
|
17
16
|
<item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
|
|
18
17
|
<item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
|
|
19
|
-
<
|
|
18
|
+
<item>ADR-0128: FLOW-INT-02 names rebase stderr tail + porcelain status when no unmerged paths; cap path list at 20 (+N more) (ADR-0128 F-0188)</item>
|
|
19
|
+
<history>RFC-1487, RFC-1515, RFC-1528, RFC-1537, RFC-1538</history>
|
|
20
20
|
</CHANGE_SUMMARY>
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -128,6 +128,72 @@ describe("flow.integrate", () => {
|
|
|
128
128
|
expect(wt.stdout.trim()).toBe("");
|
|
129
129
|
}, 20_000);
|
|
130
130
|
|
|
131
|
+
it("names the cause when the rebase fails without unmerged paths (ADR-0128, F-0188)", async () => {
|
|
132
|
+
const repo = await governedRepo();
|
|
133
|
+
const session = await openSession(repo, "blocked");
|
|
134
|
+
// the session branch needs a unique commit so the integrate actually
|
|
135
|
+
// reaches the rebase stage; without it the branch fast-forwards trivially.
|
|
136
|
+
await commitIn(session.worktree!, "session.txt", "session work\n");
|
|
137
|
+
// develop-only path whose worktree twin is tolerated dirt — the dirty
|
|
138
|
+
// preflight lets it through (FORGE_STATE_FILES) but the rebase checkout
|
|
139
|
+
// refuses on it before any unmerged path exists.
|
|
140
|
+
await mkdir(join(repo, ".forge"), { recursive: true });
|
|
141
|
+
await commitIn(repo, ".forge/knowledge-conflicts.txt", "develop content\n");
|
|
142
|
+
await mkdir(join(session.worktree!, ".forge"), { recursive: true });
|
|
143
|
+
await writeFile(
|
|
144
|
+
join(session.worktree!, ".forge/knowledge-conflicts.txt"),
|
|
145
|
+
"session-local state\n",
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const data = await integrateFlowBranch(repo, ambientIo, {
|
|
149
|
+
branch: session.branch!,
|
|
150
|
+
dryRun: false,
|
|
151
|
+
now: NOW,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
|
|
155
|
+
const message = data.diagnostics[0]?.message ?? "";
|
|
156
|
+
expect(message).toContain("failed without unmerged paths");
|
|
157
|
+
expect(message).toContain("knowledge-conflicts.txt");
|
|
158
|
+
expect(data.diagnostics[0]?.fixHint).toContain("clean the listed worktree state");
|
|
159
|
+
const details = (data.diagnostics[0] as { data?: Record<string, unknown> }).data;
|
|
160
|
+
expect(details?.conflictedPaths).toEqual([]);
|
|
161
|
+
expect((details?.rebaseStderrTail as string[]).join("\n")).toContain(
|
|
162
|
+
"knowledge-conflicts.txt",
|
|
163
|
+
);
|
|
164
|
+
expect((details?.statusPorcelain as string[]).join("\n")).toContain(".forge/");
|
|
165
|
+
}, 20_000);
|
|
166
|
+
|
|
167
|
+
it("caps the conflicted path list at 20 and reports the remainder (ADR-0128, F-0188)", async () => {
|
|
168
|
+
const repo = await governedRepo();
|
|
169
|
+
const session = await openSession(repo, "many");
|
|
170
|
+
// 22 files conflict in ONE commit each side — the rebase stops with all
|
|
171
|
+
// of them unmerged at once.
|
|
172
|
+
for (let i = 0; i < 22; i++) {
|
|
173
|
+
await writeFile(join(session.worktree!, `f${String(i).padStart(2, "0")}.txt`), "session\n");
|
|
174
|
+
}
|
|
175
|
+
await gitExec(session.worktree!, ["add", "."]);
|
|
176
|
+
await gitExec(session.worktree!, ["commit", "-m", "session adds 22 files"]);
|
|
177
|
+
for (let i = 0; i < 22; i++) {
|
|
178
|
+
await writeFile(join(repo, `f${String(i).padStart(2, "0")}.txt`), "develop\n");
|
|
179
|
+
}
|
|
180
|
+
await gitExec(repo, ["add", "."]);
|
|
181
|
+
await gitExec(repo, ["commit", "-m", "develop edits 22 files"]);
|
|
182
|
+
|
|
183
|
+
const data = await integrateFlowBranch(repo, ambientIo, {
|
|
184
|
+
branch: session.branch!,
|
|
185
|
+
dryRun: false,
|
|
186
|
+
now: NOW,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
|
|
190
|
+
const message = data.diagnostics[0]?.message ?? "";
|
|
191
|
+
expect(message).toContain("(+2 more)");
|
|
192
|
+
expect(message).not.toContain("f21.txt");
|
|
193
|
+
const details = (data.diagnostics[0] as { data?: Record<string, unknown> }).data;
|
|
194
|
+
expect((details?.conflictedPaths as string[]).length).toBe(22);
|
|
195
|
+
}, 20_000);
|
|
196
|
+
|
|
131
197
|
it("refuses FLOW-INT-05 when the primary gate fails though the branch's copy passes (AC-5)", async () => {
|
|
132
198
|
const repo = await governedRepo();
|
|
133
199
|
const session = await openSession(repo, "gate");
|