@warpgogol/forge 9.4.0 → 9.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +4 -2
- package/README.uk.md +10 -8
- package/dist/os/flow/dirty-classify.d.ts +4 -1
- package/dist/os/flow/dirty-classify.d.ts.map +1 -1
- package/dist/os/flow/dirty-classify.js +2 -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 +27 -2
- package/dist/os/flow/flow.module.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 +118 -40
- package/dist/os/flow/handlers/flow-integrate.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 +2 -0
- package/dist/os/flow/index.d.ts.map +1 -1
- package/dist/os/flow/index.js +4 -1
- 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 +46 -3
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +196 -44
- package/dist/os/flow/preflight.js.map +1 -1
- 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/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/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/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/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/os/flow/dirty-classify.ts +8 -0
- package/os/flow/flow.module.ts +29 -2
- package/os/flow/handlers/flow-cut.ts +28 -11
- package/os/flow/handlers/flow-integrate.ts +177 -50
- package/os/flow/handlers/flow-peers.ts +142 -0
- package/os/flow/index.ts +5 -1
- package/os/flow/ops-registry.ts +194 -0
- package/os/flow/preflight.ts +262 -51
- 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 +8 -4
- package/os/flow/tests/flow-integrate.test.ts +366 -16
- package/os/flow/tests/ops-registry.test.ts +136 -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/handlers/list-create.test.ts +44 -0
- package/os/rfc/handlers/list-create.ts +30 -3
- 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 +1 -1
- package/skills/fo/fo-session-retro/SKILL.md +9 -3
- package/src/onboarding/prettierignore.ts +2 -0
- package/src/tests/prettierignore-manage.test.ts +11 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Shared operation-claims registry (RFC-1543) — long-running ops that
|
|
4
|
+
write git-visible state in a checkout they do not own journal a
|
|
5
|
+
`forge/op-claim@1` record under the shared git dir before mutating, so
|
|
6
|
+
`classifyDirt` can attribute otherwise-foreign dirt to a live holder instead
|
|
7
|
+
of refusing blind. Liveness (pid alive on this host+bootId, heartbeat
|
|
8
|
+
≤5×cadence), not deletion, is authoritative — a crashed op's record is
|
|
9
|
+
reclaimed by the next reader, never trusted.</purpose>
|
|
10
|
+
<non-goals>
|
|
11
|
+
<item>No cross-host coordination — claims are machine-local, same trust model as integrate.lock.</item>
|
|
12
|
+
<item>No mutation authority — readers may sweep dead records; they never edit claims or block on them directly.</item>
|
|
13
|
+
</non-goals>
|
|
14
|
+
</MODULE_CONTRACT>
|
|
15
|
+
<KEY_DECISIONS>
|
|
16
|
+
<item>Claims live at <git-common-dir>/forge/ops/<opId>.yaml — worktrees share one git dir, so a claim written from a session worktree is visible to the primary by construction.</item>
|
|
17
|
+
<item>Claim-write failure degrades to unclaimed behavior (fail-safe): the op proceeds and classification keeps the old refusal semantics — a registry outage must never become a write blocker.</item>
|
|
18
|
+
</KEY_DECISIONS>
|
|
19
|
+
<CHANGE_SUMMARY>
|
|
20
|
+
<item>RFC-1543: op-claim registry — claim/release/liveClaims, pid+bootId+heartbeat liveness, lazy dead-record sweep</item>
|
|
21
|
+
<item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
|
|
22
|
+
</CHANGE_SUMMARY>
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { hostname } from "node:os";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
import { parse as yamlParse, stringify as yamlStringify } from "yaml";
|
|
28
|
+
import type { WorkspaceIO } from "../../src/types.ts";
|
|
29
|
+
import { currentBootId, holderIsDead } from "../core/lock-holder.ts";
|
|
30
|
+
import { git } from "./git.ts";
|
|
31
|
+
|
|
32
|
+
export const OP_CLAIM_SCHEMA = "forge/op-claim@1";
|
|
33
|
+
/** Expected heartbeat write cadence — a claim goes stale at 5× this age. */
|
|
34
|
+
export const HEARTBEAT_CADENCE_MS = 30_000;
|
|
35
|
+
|
|
36
|
+
export interface OpClaim {
|
|
37
|
+
schema: typeof OP_CLAIM_SCHEMA;
|
|
38
|
+
opId: string;
|
|
39
|
+
command: string;
|
|
40
|
+
pid: number;
|
|
41
|
+
host: string;
|
|
42
|
+
bootId?: string;
|
|
43
|
+
startedAt: string;
|
|
44
|
+
heartbeatAt: string;
|
|
45
|
+
workspaceRoot: string;
|
|
46
|
+
/** Exact paths or directory prefixes the op legitimately dirties. */
|
|
47
|
+
paths: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `<git-common-dir>/forge/ops` — shared across linked worktrees. */
|
|
51
|
+
async function opsDir(repo: string, io: WorkspaceIO): Promise<string | null> {
|
|
52
|
+
let r;
|
|
53
|
+
try {
|
|
54
|
+
r = await git(repo, io, ["rev-parse", "--git-common-dir"]);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (r.exitCode !== 0) return null;
|
|
59
|
+
const dir = r.stdout.trim();
|
|
60
|
+
return join(dir.startsWith("/") ? dir : join(repo, dir), "forge", "ops");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Liveness (AC-2): pid alive on this host+bootId AND heartbeat ≤5×cadence. */
|
|
64
|
+
export function isClaimLive(claim: OpClaim, now: number = Date.now()): boolean {
|
|
65
|
+
if (holderIsDead(claim, currentBootId())) return false;
|
|
66
|
+
const beat = Date.parse(claim.heartbeatAt);
|
|
67
|
+
if (!Number.isFinite(beat) || now - beat > 5 * HEARTBEAT_CADENCE_MS) return false;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** True when `path` equals or sits under a declared claim path/prefix. */
|
|
72
|
+
export function claimCoversPath(claim: OpClaim, path: string): boolean {
|
|
73
|
+
return claim.paths.some((p) => {
|
|
74
|
+
const prefix = p.endsWith("/") ? p : `${p}/`;
|
|
75
|
+
return path === p || path.startsWith(prefix);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Write a claim before the op's first shared-checkout mutation — best-effort. */
|
|
80
|
+
export async function claimOp(
|
|
81
|
+
repo: string,
|
|
82
|
+
io: WorkspaceIO,
|
|
83
|
+
claim: Omit<OpClaim, "schema" | "pid" | "host" | "bootId" | "startedAt" | "heartbeatAt"> & {
|
|
84
|
+
startedAt?: string;
|
|
85
|
+
},
|
|
86
|
+
): Promise<boolean> {
|
|
87
|
+
const dir = await opsDir(repo, io);
|
|
88
|
+
if (dir === null) return false;
|
|
89
|
+
const now = new Date().toISOString();
|
|
90
|
+
const record: OpClaim = {
|
|
91
|
+
schema: OP_CLAIM_SCHEMA,
|
|
92
|
+
pid: process.pid,
|
|
93
|
+
host: hostname(),
|
|
94
|
+
bootId: currentBootId(),
|
|
95
|
+
heartbeatAt: now,
|
|
96
|
+
startedAt: claim.startedAt ?? now,
|
|
97
|
+
...claim,
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
await io.mkdir(dir);
|
|
101
|
+
await io.writeFile(join(dir, `${record.opId}.yaml`), yamlStringify(record));
|
|
102
|
+
return true;
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Refresh a live claim's heartbeat — best-effort, same path. */
|
|
109
|
+
export async function heartbeatOp(repo: string, io: WorkspaceIO, opId: string): Promise<void> {
|
|
110
|
+
const dir = await opsDir(repo, io);
|
|
111
|
+
if (dir === null) return;
|
|
112
|
+
const file = join(dir, `${opId}.yaml`);
|
|
113
|
+
try {
|
|
114
|
+
const parsed = yamlParse(await io.readFile(file)) as Partial<OpClaim> | null;
|
|
115
|
+
if (!parsed || parsed.schema !== OP_CLAIM_SCHEMA) return;
|
|
116
|
+
parsed.heartbeatAt = new Date().toISOString();
|
|
117
|
+
await io.writeFile(file, yamlStringify(parsed));
|
|
118
|
+
} catch {
|
|
119
|
+
/* best-effort */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Best-effort removal — liveness, not deletion, is authoritative. */
|
|
124
|
+
export async function releaseOp(repo: string, io: WorkspaceIO, opId: string): Promise<void> {
|
|
125
|
+
const dir = await opsDir(repo, io);
|
|
126
|
+
if (dir === null) return;
|
|
127
|
+
try {
|
|
128
|
+
await io.rm(join(dir, `${opId}.yaml`));
|
|
129
|
+
} catch {
|
|
130
|
+
/* already gone */
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseClaim(raw: string): OpClaim | null {
|
|
135
|
+
let parsed: unknown;
|
|
136
|
+
try {
|
|
137
|
+
parsed = yamlParse(raw);
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
142
|
+
const c = parsed as Partial<OpClaim>;
|
|
143
|
+
if (
|
|
144
|
+
c.schema !== OP_CLAIM_SCHEMA ||
|
|
145
|
+
typeof c.opId !== "string" ||
|
|
146
|
+
typeof c.command !== "string" ||
|
|
147
|
+
typeof c.pid !== "number" ||
|
|
148
|
+
typeof c.host !== "string" ||
|
|
149
|
+
typeof c.startedAt !== "string" ||
|
|
150
|
+
typeof c.heartbeatAt !== "string" ||
|
|
151
|
+
typeof c.workspaceRoot !== "string" ||
|
|
152
|
+
!Array.isArray(c.paths)
|
|
153
|
+
) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return c as OpClaim;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Live claims for `repo`, sweeping dead/stale records lazily as a side
|
|
161
|
+
* effect. Malformed files sweep too — a record we cannot read cannot be
|
|
162
|
+
* liveness-checked and must never grant tolerance.
|
|
163
|
+
*/
|
|
164
|
+
async function readClaims(repo: string, io: WorkspaceIO): Promise<{ live: OpClaim[]; dead: string[] }> {
|
|
165
|
+
const dir = await opsDir(repo, io);
|
|
166
|
+
if (dir === null || !(await io.exists(dir))) return { live: [], dead: [] };
|
|
167
|
+
const files = (await io.glob("*.yaml", { cwd: dir })).filter((f) => !f.endsWith("/"));
|
|
168
|
+
const live: OpClaim[] = [];
|
|
169
|
+
const dead: string[] = [];
|
|
170
|
+
for (const f of files) {
|
|
171
|
+
const abs = join(dir, f);
|
|
172
|
+
const claim = parseClaim(await io.readFile(abs));
|
|
173
|
+
if (claim !== null && isClaimLive(claim)) live.push(claim);
|
|
174
|
+
else dead.push(abs);
|
|
175
|
+
}
|
|
176
|
+
return { live, dead };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Read-only variant for surfaces that must not mutate (flow.peers). */
|
|
180
|
+
export async function liveClaimsReadOnly(repo: string, io: WorkspaceIO): Promise<OpClaim[]> {
|
|
181
|
+
return (await readClaims(repo, io)).live;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function liveClaims(repo: string, io: WorkspaceIO): Promise<OpClaim[]> {
|
|
185
|
+
const { live, dead } = await readClaims(repo, io);
|
|
186
|
+
for (const abs of dead) {
|
|
187
|
+
try {
|
|
188
|
+
await io.rm(abs);
|
|
189
|
+
} catch {
|
|
190
|
+
/* sweep is best-effort */
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return live;
|
|
194
|
+
}
|
package/os/flow/preflight.ts
CHANGED
|
@@ -14,14 +14,12 @@ 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-1528: initial — classifyLockfileDiff + runIntegratePreflight (FLOW-INT-01/03 classification, FLOW-INT-12/13/14 validator refusals).</item>
|
|
18
|
-
<item>RFC-1528: flow.integrate bounded preflight before rebase and gate
|
|
19
|
-
|
|
20
|
-
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>
|
|
21
|
-
<item>RFC-1528: close review findings — manifest-union command inventory for regen/preflight</item>
|
|
22
|
-
<item>RFC-1537: regenerable dirt classifier (importer-materialize, skill-twin-sync), cheap-first open-mission check (WT-GATE-01), toleratedState surfacing</item>
|
|
23
|
-
<item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
|
|
24
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
|
+
<item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
|
|
21
|
+
<item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
|
|
22
|
+
<history>RFC-1528, RFC-1537, RFC-1538</history>
|
|
25
23
|
</CHANGE_SUMMARY>
|
|
26
24
|
*/
|
|
27
25
|
|
|
@@ -35,11 +33,7 @@ import type {
|
|
|
35
33
|
WorkspaceIO,
|
|
36
34
|
} from "../../src/types.ts";
|
|
37
35
|
import { loadLiveCommandInventory } from "../../src/utils/command-inventory.ts";
|
|
38
|
-
import {
|
|
39
|
-
isGeneratedContent,
|
|
40
|
-
isGeneratedPathName,
|
|
41
|
-
REGEN_FLAGS,
|
|
42
|
-
} from "../core/archive-regen.ts";
|
|
36
|
+
import { isGeneratedContent, isGeneratedPathName, REGEN_FLAGS } from "../core/archive-regen.ts";
|
|
43
37
|
import { openMissionsIn } from "../mission/open-missions.ts";
|
|
44
38
|
import {
|
|
45
39
|
classifyDirtyPath,
|
|
@@ -47,17 +41,21 @@ import {
|
|
|
47
41
|
type ClassifiedDirtyEntry,
|
|
48
42
|
type DirtyClass,
|
|
49
43
|
} from "./dirty-classify.ts";
|
|
50
|
-
import { currentBranch, git, statusTracked } from "./git.ts";
|
|
44
|
+
import { currentBranch, git, statusTracked, worktreeList } from "./git.ts";
|
|
45
|
+
import { canonicalRepoDir } from "../../src/utils/repo-path.ts";
|
|
46
|
+
import { claimCoversPath, liveClaims, type OpClaim } from "./ops-registry.ts";
|
|
51
47
|
|
|
52
48
|
export type LockfileClassification = "importer-prune-only" | "other";
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
51
|
* Strict match for the pnpm-prune shape: ONLY removed lines, every one either
|
|
56
52
|
* a `missions/<id>/workpiece:` importer key or a deeper-indented member of
|
|
57
|
-
* such a key's block.
|
|
58
|
-
*
|
|
53
|
+
* such a key's block. Returns the sorted pruned mission ids on match, null
|
|
54
|
+
* otherwise — any added line, any other removed line, or a diff with no
|
|
55
|
+
* removals is ambiguous and stays an ordinary refusal.
|
|
59
56
|
*/
|
|
60
|
-
export function
|
|
57
|
+
export function classifyLockfilePruneIds(diffText: string): string[] | null {
|
|
58
|
+
const ids = new Set<string>();
|
|
61
59
|
let sawImporterKey = false;
|
|
62
60
|
let openBlockIndent: number | null = null;
|
|
63
61
|
for (const raw of diffText.split("\n")) {
|
|
@@ -72,7 +70,7 @@ export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
|
72
70
|
if (raw.startsWith("@@")) openBlockIndent = null;
|
|
73
71
|
continue;
|
|
74
72
|
}
|
|
75
|
-
if (raw.startsWith("+")) return
|
|
73
|
+
if (raw.startsWith("+")) return null;
|
|
76
74
|
const line = raw.slice(1);
|
|
77
75
|
if (raw[0] === " ") {
|
|
78
76
|
const indent = line.length - line.trimStart().length;
|
|
@@ -84,19 +82,25 @@ export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
|
84
82
|
if (raw[0] !== "-") continue;
|
|
85
83
|
if (line.trim().length === 0) {
|
|
86
84
|
// A blank removed line only tolerates inside an open importer block.
|
|
87
|
-
if (openBlockIndent === null) return
|
|
85
|
+
if (openBlockIndent === null) return null;
|
|
88
86
|
continue;
|
|
89
87
|
}
|
|
90
88
|
const indent = line.length - line.trimStart().length;
|
|
91
|
-
|
|
89
|
+
const key = /^\s*missions\/([^\s/]+)\/workpiece:\s*$/.exec(line);
|
|
90
|
+
if (key) {
|
|
92
91
|
sawImporterKey = true;
|
|
92
|
+
ids.add(key[1]);
|
|
93
93
|
openBlockIndent = indent;
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
96
|
if (openBlockIndent !== null && indent > openBlockIndent) continue;
|
|
97
|
-
return
|
|
97
|
+
return null;
|
|
98
98
|
}
|
|
99
|
-
return sawImporterKey ?
|
|
99
|
+
return sawImporterKey ? [...ids].sort() : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function classifyLockfileDiff(diffText: string): LockfileClassification {
|
|
103
|
+
return classifyLockfilePruneIds(diffText) !== null ? "importer-prune-only" : "other";
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
@@ -172,12 +176,79 @@ export type { DirtyClass } from "./dirty-classify.ts";
|
|
|
172
176
|
export interface ToleratedEntry {
|
|
173
177
|
path: string;
|
|
174
178
|
class: DirtyClass;
|
|
179
|
+
/** RFC-1544: pruned mission ids for the lockfile importer classes. */
|
|
180
|
+
missionIds?: string[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* RFC-1544: referent state for one pruned `missions/<id>/workpiece` importer
|
|
185
|
+
* — where the directory still exists and whether its mission is open. The
|
|
186
|
+
* classifier stays pure: referents are injected by the caller.
|
|
187
|
+
*/
|
|
188
|
+
export interface ImporterReferent {
|
|
189
|
+
missionId: string;
|
|
190
|
+
/** `missions/<id>/workpiece` exists in the checkout being classified. */
|
|
191
|
+
existsHere: boolean;
|
|
192
|
+
/** Other registered worktrees where the directory exists. */
|
|
193
|
+
existsInCheckout: string[];
|
|
194
|
+
/** An open `missions/<id>/mission.yaml` exists in any registered checkout. */
|
|
195
|
+
missionOpen: boolean;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Default referent resolver — `git worktree list` for the checkout set and
|
|
200
|
+
* `openMissionsIn` per checkout for mission state (the same enumeration
|
|
201
|
+
* `flow.status` performs; never cwd-relative guesses).
|
|
202
|
+
*/
|
|
203
|
+
export async function resolveImporterReferents(
|
|
204
|
+
repo: string,
|
|
205
|
+
io: WorkspaceIO,
|
|
206
|
+
missionIds: string[],
|
|
207
|
+
): Promise<ImporterReferent[]> {
|
|
208
|
+
const worktrees = await worktreeList(repo, io);
|
|
209
|
+
const here = canonicalRepoDir(repo);
|
|
210
|
+
const others = worktrees.filter((w) => w.path !== here).map((w) => w.path);
|
|
211
|
+
const openCache = new Map<string, Set<string>>();
|
|
212
|
+
const openIn = async (dir: string): Promise<Set<string>> => {
|
|
213
|
+
let set = openCache.get(dir);
|
|
214
|
+
if (set === undefined) {
|
|
215
|
+
try {
|
|
216
|
+
set = new Set(await openMissionsIn(dir, io));
|
|
217
|
+
} catch {
|
|
218
|
+
set = new Set();
|
|
219
|
+
}
|
|
220
|
+
openCache.set(dir, set);
|
|
221
|
+
}
|
|
222
|
+
return set;
|
|
223
|
+
};
|
|
224
|
+
const out: ImporterReferent[] = [];
|
|
225
|
+
for (const missionId of missionIds) {
|
|
226
|
+
const rel = join("missions", missionId, "workpiece");
|
|
227
|
+
const existsHere = await io.exists(join(repo, rel));
|
|
228
|
+
const existsInCheckout: string[] = [];
|
|
229
|
+
for (const dir of others) {
|
|
230
|
+
if (await io.exists(join(dir, rel))) existsInCheckout.push(dir);
|
|
231
|
+
}
|
|
232
|
+
let missionOpen = (await openIn(repo)).has(missionId);
|
|
233
|
+
for (const dir of others) {
|
|
234
|
+
if (!missionOpen && (await openIn(dir)).has(missionId)) missionOpen = true;
|
|
235
|
+
}
|
|
236
|
+
out.push({ missionId, existsHere, existsInCheckout: existsInCheckout.sort(), missionOpen });
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
175
239
|
}
|
|
176
240
|
|
|
177
241
|
export interface DirtVerdict {
|
|
178
242
|
tolerated: ToleratedEntry[];
|
|
179
243
|
/** Porcelain lines that match no declared regenerable shape — still refuse. */
|
|
180
244
|
unattributed: string[];
|
|
245
|
+
/**
|
|
246
|
+
* RFC-1543: unattributed paths covered by a LIVE op-claim — class
|
|
247
|
+
* `in-flight-foreign`. They never block silently: the caller either waits
|
|
248
|
+
* for the holder or refuses FLOW-INT-03 naming it. Resolved only for the
|
|
249
|
+
* primary checkout — worktrees are single-owner.
|
|
250
|
+
*/
|
|
251
|
+
foreignInFlight: { path: string; holder: OpClaim }[];
|
|
181
252
|
}
|
|
182
253
|
|
|
183
254
|
const TWIN_ROOT = ".agents/skills/";
|
|
@@ -236,9 +307,12 @@ export async function classifyDirt(
|
|
|
236
307
|
io: WorkspaceIO,
|
|
237
308
|
entries: string[],
|
|
238
309
|
deps: { runGit: typeof git } = { runGit: git },
|
|
310
|
+
claims: OpClaim[] = [],
|
|
311
|
+
resolveReferents?: (missionIds: string[]) => Promise<ImporterReferent[]>,
|
|
239
312
|
): Promise<DirtVerdict> {
|
|
240
313
|
const tolerated: ToleratedEntry[] = [];
|
|
241
314
|
const unattributed: string[] = [];
|
|
315
|
+
const foreignInFlight: { path: string; holder: OpClaim }[] = [];
|
|
242
316
|
const byPath = new Map<string, string[]>();
|
|
243
317
|
for (const line of entries) {
|
|
244
318
|
const p = line.slice(3).trim();
|
|
@@ -256,8 +330,36 @@ export async function classifyDirt(
|
|
|
256
330
|
outer: for (const [path, lines] of byPath) {
|
|
257
331
|
if (path === "pnpm-lock.yaml") {
|
|
258
332
|
const diff = await deps.runGit(repo, io, ["diff", "HEAD", "--", "pnpm-lock.yaml"]);
|
|
259
|
-
|
|
260
|
-
|
|
333
|
+
const pruneIds = classifyLockfilePruneIds(diff.stdout);
|
|
334
|
+
if (pruneIds !== null) {
|
|
335
|
+
// RFC-1544: the pruned importer's referent decides the class — a
|
|
336
|
+
// foreign checkout's open mission (foreign-open-mission, auto-
|
|
337
|
+
// restored by flow.integrate), dead residue (importer-prune-stale,
|
|
338
|
+
// accepted cleanup), or anything else (importer-prune, unchanged).
|
|
339
|
+
// An unresolvable referent set (no exec/ io capability) degrades to
|
|
340
|
+
// the inert importer-prune — "couldn't resolve" is not "resolved to
|
|
341
|
+
// nothing".
|
|
342
|
+
let referents: ImporterReferent[] | undefined;
|
|
343
|
+
if (resolveReferents !== undefined) {
|
|
344
|
+
try {
|
|
345
|
+
referents = await resolveReferents(pruneIds);
|
|
346
|
+
} catch {
|
|
347
|
+
referents = undefined;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (
|
|
351
|
+
referents !== undefined &&
|
|
352
|
+
referents.every((r) => !r.existsHere && r.missionOpen && r.existsInCheckout.length > 0)
|
|
353
|
+
) {
|
|
354
|
+
tolerated.push({ path, class: "foreign-open-mission", missionIds: pruneIds });
|
|
355
|
+
} else if (
|
|
356
|
+
referents !== undefined &&
|
|
357
|
+
referents.every((r) => !r.existsHere && r.existsInCheckout.length === 0 && !r.missionOpen)
|
|
358
|
+
) {
|
|
359
|
+
tolerated.push({ path, class: "importer-prune-stale", missionIds: pruneIds });
|
|
360
|
+
} else {
|
|
361
|
+
tolerated.push({ path, class: "importer-prune", missionIds: pruneIds });
|
|
362
|
+
}
|
|
261
363
|
continue;
|
|
262
364
|
}
|
|
263
365
|
const ids = classifyLockfileMaterialize(diff.stdout);
|
|
@@ -346,7 +448,20 @@ export async function classifyDirt(
|
|
|
346
448
|
}
|
|
347
449
|
unattributed.push(...lines);
|
|
348
450
|
}
|
|
349
|
-
|
|
451
|
+
// RFC-1543 AC-3: unattributed paths covered by a live claim reclassify as
|
|
452
|
+
// in-flight-foreign — every other unattributed path stays work-class.
|
|
453
|
+
if (claims.length > 0) {
|
|
454
|
+
const stillUnattributed: string[] = [];
|
|
455
|
+
for (const line of unattributed) {
|
|
456
|
+
const path = line.slice(3).trim();
|
|
457
|
+
const holder = claims.find((c) => claimCoversPath(c, path));
|
|
458
|
+
if (holder !== undefined) foreignInFlight.push({ path, holder });
|
|
459
|
+
else stillUnattributed.push(line);
|
|
460
|
+
}
|
|
461
|
+
unattributed.length = 0;
|
|
462
|
+
unattributed.push(...stillUnattributed);
|
|
463
|
+
}
|
|
464
|
+
return { tolerated, unattributed, foreignInFlight };
|
|
350
465
|
}
|
|
351
466
|
|
|
352
467
|
/**
|
|
@@ -367,6 +482,9 @@ export async function classifyDirtyEntries(
|
|
|
367
482
|
path: t.path,
|
|
368
483
|
class: t.class,
|
|
369
484
|
}));
|
|
485
|
+
for (const f of verdict.foreignInFlight) {
|
|
486
|
+
out.push({ path: f.path, class: "in-flight-foreign" });
|
|
487
|
+
}
|
|
370
488
|
for (const line of verdict.unattributed) {
|
|
371
489
|
const path = line.slice(3).trim();
|
|
372
490
|
out.push({ path, class: classifyDirtyPath(path) });
|
|
@@ -416,6 +534,12 @@ export async function runIntegratePreflight(
|
|
|
416
534
|
/** Already-computed statusDirty() of the branch worktree. */
|
|
417
535
|
worktreeDirty: { entries: string[]; toleratedState: string[] };
|
|
418
536
|
invoke?: ForgeInvokeCommand;
|
|
537
|
+
/**
|
|
538
|
+
* RFC-1543 AC-4: seconds to wait for live foreign claim-holders before
|
|
539
|
+
* FLOW-INT-03 refuses — default 600, 0 restores fail-fast.
|
|
540
|
+
*/
|
|
541
|
+
waitForeignSeconds?: number;
|
|
542
|
+
onProgress?: (line: string) => void;
|
|
419
543
|
commandRegistry?: CommandRegistry;
|
|
420
544
|
/** Test seam — overrides the live inventory union (registry + command manifest). */
|
|
421
545
|
commands?: ForgeRegisteredCommandInfo[];
|
|
@@ -452,7 +576,8 @@ export async function runIntegratePreflight(
|
|
|
452
576
|
refuse: {
|
|
453
577
|
ruleId: "WT-GATE-01",
|
|
454
578
|
message: `worktree has ${openMissions.length} open mission(s): ${openMissions.join(", ")}`,
|
|
455
|
-
fixHint:
|
|
579
|
+
fixHint:
|
|
580
|
+
"close or abort the mission(s) in the worktree before integrating or tearing down",
|
|
456
581
|
data: { openMissions },
|
|
457
582
|
},
|
|
458
583
|
};
|
|
@@ -465,9 +590,16 @@ export async function runIntegratePreflight(
|
|
|
465
590
|
// regenerable classes journal as tolerated (RFC-1537).
|
|
466
591
|
checked.push("worktree-dirty");
|
|
467
592
|
if (opts.worktreeDirty.entries.length > 0) {
|
|
468
|
-
const verdict = await classifyDirt(
|
|
469
|
-
|
|
470
|
-
|
|
593
|
+
const verdict = await classifyDirt(
|
|
594
|
+
opts.branchWorktree,
|
|
595
|
+
io,
|
|
596
|
+
opts.worktreeDirty.entries,
|
|
597
|
+
{
|
|
598
|
+
runGit: deps.runGit,
|
|
599
|
+
},
|
|
600
|
+
[],
|
|
601
|
+
(ids) => resolveImporterReferents(opts.branchWorktree, io, ids),
|
|
602
|
+
);
|
|
471
603
|
tolerated.push(...verdict.tolerated);
|
|
472
604
|
if (verdict.unattributed.length > 0) {
|
|
473
605
|
const lockfile = await classifyDirtyLockfile(
|
|
@@ -521,19 +653,57 @@ export async function runIntegratePreflight(
|
|
|
521
653
|
// classification; the post-gate check stays (primary can dirty mid-gate).
|
|
522
654
|
checked.push("primary-dirty");
|
|
523
655
|
const primaryBranch = await deps.runCurrentBranch(opts.primary, io);
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
656
|
+
// RFC-1543 AC-4: primary-side foreign claims get a bounded wait — the poll
|
|
657
|
+
// re-reads both dirt and claims (≤30s cadence) until they clear or the
|
|
658
|
+
// budget expires; unattributed work refuses instantly as before.
|
|
659
|
+
const waitForeignMs = Math.max(0, (opts.waitForeignSeconds ?? 600) * 1000);
|
|
660
|
+
const foreignDeadline = Date.now() + waitForeignMs;
|
|
661
|
+
let primaryClean = false;
|
|
662
|
+
for (;;) {
|
|
663
|
+
const primaryDirty = await deps.runStatusTracked(opts.primary, io);
|
|
664
|
+
if (primaryDirty.entries.length === 0) {
|
|
665
|
+
primaryClean = true;
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
const verdict = await classifyDirt(
|
|
669
|
+
opts.primary,
|
|
670
|
+
io,
|
|
671
|
+
primaryDirty.entries,
|
|
672
|
+
{ runGit: deps.runGit },
|
|
673
|
+
await liveClaims(opts.primary, io),
|
|
674
|
+
(ids) => resolveImporterReferents(opts.primary, io, ids),
|
|
675
|
+
);
|
|
529
676
|
tolerated.push(...verdict.tolerated);
|
|
530
|
-
|
|
677
|
+
const foreignOnly =
|
|
678
|
+
verdict.unattributed.length === 0 &&
|
|
679
|
+
verdict.foreignInFlight.length > 0 &&
|
|
680
|
+
primaryBranch === "develop";
|
|
681
|
+
if (foreignOnly && Date.now() < foreignDeadline) {
|
|
682
|
+
const holders = verdict.foreignInFlight.map(
|
|
683
|
+
(f) =>
|
|
684
|
+
`${f.holder.command} ${f.holder.opId} (pid ${f.holder.pid}, started ${f.holder.startedAt})`,
|
|
685
|
+
);
|
|
686
|
+
opts.onProgress?.(
|
|
687
|
+
`primary held by foreign op(s): ${holders.join("; ")} — waiting up to ${Math.ceil((foreignDeadline - Date.now()) / 1000)}s`,
|
|
688
|
+
);
|
|
689
|
+
await new Promise((r) => setTimeout(r, Math.min(30_000, foreignDeadline - Date.now())));
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
if (
|
|
693
|
+
primaryBranch !== "develop" ||
|
|
694
|
+
verdict.unattributed.length > 0 ||
|
|
695
|
+
verdict.foreignInFlight.length > 0
|
|
696
|
+
) {
|
|
531
697
|
const lockfile = await classifyDirtyLockfile(
|
|
532
698
|
opts.primary,
|
|
533
699
|
io,
|
|
534
700
|
verdict.unattributed,
|
|
535
701
|
deps.runGit,
|
|
536
702
|
);
|
|
703
|
+
const holderNote =
|
|
704
|
+
verdict.foreignInFlight.length > 0
|
|
705
|
+
? ` — in-flight holder(s): ${verdict.foreignInFlight.map((f) => `${f.holder.command} ${f.holder.opId} (pid ${f.holder.pid})`).join("; ")}`
|
|
706
|
+
: "";
|
|
537
707
|
return {
|
|
538
708
|
ok: false,
|
|
539
709
|
checked,
|
|
@@ -544,7 +714,10 @@ export async function runIntegratePreflight(
|
|
|
544
714
|
message:
|
|
545
715
|
(primaryBranch !== "develop"
|
|
546
716
|
? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
|
|
547
|
-
:
|
|
717
|
+
: verdict.unattributed.length > 0
|
|
718
|
+
? `primary worktree has ${verdict.unattributed.length} uncommitted change(s)`
|
|
719
|
+
: `primary worktree held by ${verdict.foreignInFlight.length} in-flight foreign op(s)`) +
|
|
720
|
+
holderNote +
|
|
548
721
|
(verdict.tolerated.length > 0
|
|
549
722
|
? ` — tolerated regenerable state: ${verdict.tolerated.map((t) => `${t.path} (${t.class})`).join(", ")}`
|
|
550
723
|
: "") +
|
|
@@ -556,13 +729,23 @@ export async function runIntegratePreflight(
|
|
|
556
729
|
const path = line.slice(3).trim();
|
|
557
730
|
return { path, class: classifyDirtyPath(path) };
|
|
558
731
|
}),
|
|
732
|
+
foreignHolders: verdict.foreignInFlight.map((f) => ({
|
|
733
|
+
path: f.path,
|
|
734
|
+
opId: f.holder.opId,
|
|
735
|
+
command: f.holder.command,
|
|
736
|
+
pid: f.holder.pid,
|
|
737
|
+
startedAt: f.holder.startedAt,
|
|
738
|
+
})),
|
|
559
739
|
toleratedDirt: verdict.tolerated,
|
|
560
740
|
...(lockfile !== null ? { lockfileClassification: lockfile } : {}),
|
|
561
741
|
},
|
|
562
742
|
},
|
|
563
743
|
};
|
|
564
744
|
}
|
|
565
|
-
|
|
745
|
+
primaryClean = true;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
if (!primaryClean && primaryBranch !== "develop") {
|
|
566
749
|
return {
|
|
567
750
|
ok: false,
|
|
568
751
|
checked,
|
|
@@ -577,24 +760,17 @@ export async function runIntegratePreflight(
|
|
|
577
760
|
};
|
|
578
761
|
}
|
|
579
762
|
|
|
580
|
-
// (3) ecosystem.manifest.validate — stale generated manifest
|
|
763
|
+
// (3) ecosystem.manifest.validate — stale generated manifest is a
|
|
764
|
+
// recoverable violation (RFC-1546): the failure is recorded and the
|
|
765
|
+
// remaining checks still run. Only when the drift is the SOLE violation
|
|
766
|
+
// does the owner command regenerate in place and the validator re-run —
|
|
767
|
+
// a coexisting refusal below must skip the regeneration entirely.
|
|
768
|
+
let manifestDrift: { summary?: string; exitCode?: number } | undefined;
|
|
581
769
|
if (resolvable("ecosystem.manifest.validate")) {
|
|
582
770
|
checked.push("ecosystem.manifest.validate");
|
|
583
771
|
const result = await opts.invoke!("ecosystem.manifest.validate", {});
|
|
584
772
|
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
|
-
};
|
|
773
|
+
manifestDrift = { summary: result.summary, exitCode: result.exitCode };
|
|
598
774
|
}
|
|
599
775
|
} else {
|
|
600
776
|
skipped.push({
|
|
@@ -680,6 +856,41 @@ export async function runIntegratePreflight(
|
|
|
680
856
|
});
|
|
681
857
|
}
|
|
682
858
|
|
|
859
|
+
// RFC-1546: every other check passed — the manifest drift is the sole
|
|
860
|
+
// violation, so the owner command regenerates in place and the validator
|
|
861
|
+
// re-runs. A coexisting violation already refused above without ever
|
|
862
|
+
// reaching the regeneration.
|
|
863
|
+
if (manifestDrift !== undefined) {
|
|
864
|
+
if (resolvable("ecosystem.manifest.generate")) {
|
|
865
|
+
const regen = await opts.invoke!(
|
|
866
|
+
"ecosystem.manifest.generate",
|
|
867
|
+
REGEN_FLAGS["ecosystem.manifest.generate"] ?? {},
|
|
868
|
+
);
|
|
869
|
+
if (regen.ok !== false && (regen.exitCode === undefined || regen.exitCode === 0)) {
|
|
870
|
+
checked.push("ecosystem.manifest.generate", "ecosystem.manifest.validate");
|
|
871
|
+
const result = await opts.invoke!("ecosystem.manifest.validate", {});
|
|
872
|
+
if (result.ok !== false && (result.exitCode === undefined || result.exitCode === 0)) {
|
|
873
|
+
manifestDrift = undefined;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (manifestDrift !== undefined) {
|
|
878
|
+
return {
|
|
879
|
+
ok: false,
|
|
880
|
+
checked,
|
|
881
|
+
skipped,
|
|
882
|
+
tolerated,
|
|
883
|
+
refuse: {
|
|
884
|
+
ruleId: "FLOW-INT-12",
|
|
885
|
+
message: `preflight: ecosystem.manifest.validate refused — ${manifestDrift.summary ?? `exit ${manifestDrift.exitCode}`}`,
|
|
886
|
+
fixHint:
|
|
887
|
+
"regenerate the manifest via `pnpm exec werkstatt run ecosystem.manifest.generate`, commit, then re-run flow.integrate",
|
|
888
|
+
data: { command: "ecosystem.manifest.validate", summary: manifestDrift.summary },
|
|
889
|
+
},
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
683
894
|
return { ok: true, checked, skipped, tolerated };
|
|
684
895
|
}
|
|
685
896
|
|
|
@@ -699,7 +910,7 @@ export interface RebaseConflictVerdict {
|
|
|
699
910
|
}
|
|
700
911
|
|
|
701
912
|
/** `.generated.` basenames whose owner command is fixed by convention. */
|
|
702
|
-
const GENERATED_BASENAME_OWNERS: Record<string, string> = {
|
|
913
|
+
export const GENERATED_BASENAME_OWNERS: Record<string, string> = {
|
|
703
914
|
"ecosystem.generated.yaml": "ecosystem.manifest.generate",
|
|
704
915
|
"command-manifest.generated.yaml": "command.manifest.generate",
|
|
705
916
|
};
|