@quolu/lattice 0.79.4 → 0.80.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/bin/lattice-dashboard.mjs +6 -5
- package/bin/lattice-mcp.mjs +2 -1
- package/docs/bridge-setup.md +8 -0
- package/docs/schemas/lattice.plan_create_input.v4.schema.json +8 -4
- package/docs/schemas/lattice.todo_extraction.v3.schema.json +5 -3
- package/docs/schemas/lattice.todo_extraction.v4.schema.json +5 -3
- package/package.json +1 -1
- package/sensor/dist/mcp/index.d.ts +3 -1
- package/sensor/dist/mcp/index.d.ts.map +1 -1
- package/sensor/dist/mcp/index.js +7 -2
- package/sensor/dist/mcp/index.js.map +1 -1
- package/sensor/dist/mcp/proxy.d.ts +2 -0
- package/sensor/dist/mcp/proxy.d.ts.map +1 -1
- package/sensor/dist/mcp/proxy.js +9 -3
- package/sensor/dist/mcp/proxy.js.map +1 -1
- package/sensor/dist/mcp/session.d.ts +7 -0
- package/sensor/dist/mcp/session.d.ts.map +1 -1
- package/sensor/dist/mcp/session.js +4 -1
- package/sensor/dist/mcp/session.js.map +1 -1
- package/sensor/dist/mcp/transport.d.ts +5 -5
- package/sensor/dist/mcp/transport.d.ts.map +1 -1
- package/sensor/dist/mcp/transport.js +14 -6
- package/sensor/dist/mcp/transport.js.map +1 -1
- package/src/dashboard-lifecycle-journal.mjs +3 -1
- package/src/fs-publish.mjs +9 -0
- package/src/mcp-startup-receipt.mjs +99 -0
- package/src/project-cli.mjs +2 -2
- package/src/runtime-os-observation.mjs +18 -1
- package/src/setup-config.mjs +7 -3
- package/src/store-lock.mjs +250 -0
- package/src/todo-cli.mjs +6 -0
- package/src/todo-contracts.mjs +95 -50
- package/src/todo-migration.mjs +35 -10
- package/src/todo-note-store.mjs +45 -12
- package/src/todo-readiness.mjs +154 -0
- package/src/todo-status.mjs +4 -33
- package/src/todo-store-cache.mjs +50 -6
- package/src/todo-store-git-transaction.mjs +11 -6
- package/src/todo-store-view.mjs +47 -0
- package/src/todo-store.mjs +597 -398
- package/src/artifact-contracts-v2.mjs +0 -325
- package/src/boundary-compiler.mjs +0 -712
- package/src/bounded-seam.mjs +0 -230
- package/src/control-compiler.mjs +0 -532
- package/src/rc1-black-box-oracle.mjs +0 -906
- package/src/rc1-comparison.mjs +0 -154
- package/src/rc1-evidence-bundle.mjs +0 -456
- package/src/rc1-v4-campaign.mjs +0 -708
- package/src/rc1-v4-transform.mjs +0 -467
- package/src/rc1-v5-artifact-set.mjs +0 -855
- package/src/rc1-v5-behavior-evidence.mjs +0 -594
- package/src/rc1-v5-campaign.mjs +0 -797
- package/src/rc1-v5-transform.mjs +0 -421
- package/src/rc1-v6-artifact-set.mjs +0 -807
- package/src/rc1-v6-behavior-evidence.mjs +0 -273
- package/src/rc1-v6-campaign.mjs +0 -623
- package/src/rc1-v6-causal-binding.mjs +0 -473
- package/src/rc1-v6-measurement.mjs +0 -313
- package/src/rc2-artifact-set.mjs +0 -1584
- package/src/rc2-campaign.mjs +0 -1495
- package/src/rc2-delivery-policy-front-end.mjs +0 -1079
- package/src/rc2-delivery-policy-oracle.mjs +0 -134
- package/src/rc2-delivery-policy-transform.mjs +0 -1127
- package/src/rc2-rc1-transfer-front-end.mjs +0 -511
- package/src/rc3-actual-dogfood.mjs +0 -652
- package/src/rc3-dogfood-scaffold.mjs +0 -315
- package/src/rc3-scripted-campaign.mjs +0 -1383
- package/src/rc4-stage1-dogfood.mjs +0 -673
- package/src/runtime-scripted-executor.mjs +0 -163
- package/src/runtime-worktree-executor.mjs +0 -199
- package/src/seam-transform.mjs +0 -554
- package/src/treatment-compiler.mjs +0 -728
- package/src/treatment-runner.mjs +0 -656
|
@@ -67,7 +67,7 @@ export interface JsonRpcTransport {
|
|
|
67
67
|
send(response: JsonRpcResponse): void;
|
|
68
68
|
notify(method: string, params?: unknown): void;
|
|
69
69
|
request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
70
|
-
sendResult(id: string | number, result: unknown): void;
|
|
70
|
+
sendResult(id: string | number, result: unknown, onWritten?: () => void): void;
|
|
71
71
|
sendError(id: string | number | null, code: number, message: string, data?: unknown): void;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -85,7 +85,7 @@ declare abstract class LineBasedJsonRpcTransport implements JsonRpcTransport {
|
|
|
85
85
|
protected nextRequestId: number;
|
|
86
86
|
protected stopped: boolean;
|
|
87
87
|
abstract start(handler: MessageHandler): void;
|
|
88
|
-
protected abstract write(line: string): void;
|
|
88
|
+
protected abstract write(line: string, onWritten?: () => void): void;
|
|
89
89
|
protected abstract idPrefix(): string;
|
|
90
90
|
abstract stop(): void;
|
|
91
91
|
/**
|
|
@@ -99,7 +99,7 @@ declare abstract class LineBasedJsonRpcTransport implements JsonRpcTransport {
|
|
|
99
99
|
request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
100
100
|
send(response: JsonRpcResponse): void;
|
|
101
101
|
notify(method: string, params?: unknown): void;
|
|
102
|
-
sendResult(id: string | number, result: unknown): void;
|
|
102
|
+
sendResult(id: string | number, result: unknown, onWritten?: () => void): void;
|
|
103
103
|
sendError(id: string | number | null, code: number, message: string, data?: unknown): void;
|
|
104
104
|
/**
|
|
105
105
|
* Fail any in-flight server-initiated requests so their awaiters don't hang.
|
|
@@ -150,7 +150,7 @@ export declare class StdioTransport extends LineBasedJsonRpcTransport {
|
|
|
150
150
|
constructor(opts?: StdioTransportOptions);
|
|
151
151
|
start(handler: MessageHandler): void;
|
|
152
152
|
stop(): void;
|
|
153
|
-
protected write(line: string): void;
|
|
153
|
+
protected write(line: string, onWritten?: () => void): void;
|
|
154
154
|
protected idPrefix(): string;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -180,7 +180,7 @@ export declare class SocketTransport extends LineBasedJsonRpcTransport {
|
|
|
180
180
|
* hello/handshake line that precedes the JSON-RPC stream.
|
|
181
181
|
*/
|
|
182
182
|
writeRaw(line: string): void;
|
|
183
|
-
protected write(line: string): void;
|
|
183
|
+
protected write(line: string, onWritten?: () => void): void;
|
|
184
184
|
protected idPrefix(): string;
|
|
185
185
|
private handleSocketClose;
|
|
186
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/mcp/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAGD,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9F;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IACrC,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,CAAC,Q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,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAK3D,SAAS,CAAC,QAAQ,IAAI,MAAM;CAG7B;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,yBAAyB;IAIhD,OAAO,CAAC,MAAM;IAAU,OAAO,CAAC,MAAM;IAHlD,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,aAAa,CAAyB;gBAE1B,MAAM,EAAE,MAAM,EAAU,MAAM,GAAE,MAAkB;IAItE;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAIlC,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAoCpC,IAAI,IAAI,IAAI;IAUZ;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM5B,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAO3D,SAAS,CAAC,QAAQ,IAAI,MAAM;IAI5B,OAAO,CAAC,iBAAiB;CAS1B"}
|
|
@@ -102,8 +102,8 @@ class LineBasedJsonRpcTransport {
|
|
|
102
102
|
const notification = { jsonrpc: '2.0', method, params };
|
|
103
103
|
this.write(JSON.stringify(notification));
|
|
104
104
|
}
|
|
105
|
-
sendResult(id, result) {
|
|
106
|
-
this.
|
|
105
|
+
sendResult(id, result, onWritten) {
|
|
106
|
+
this.write(JSON.stringify({ jsonrpc: '2.0', id, result }), onWritten);
|
|
107
107
|
}
|
|
108
108
|
sendError(id, code, message, data) {
|
|
109
109
|
this.send({ jsonrpc: '2.0', id, error: { code, message, data } });
|
|
@@ -264,8 +264,12 @@ class StdioTransport extends LineBasedJsonRpcTransport {
|
|
|
264
264
|
this.rl = null;
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
write(line) {
|
|
268
|
-
|
|
267
|
+
write(line, onWritten) {
|
|
268
|
+
if (onWritten)
|
|
269
|
+
process.stdout.write(line + '\n', error => { if (!error)
|
|
270
|
+
onWritten(); });
|
|
271
|
+
else
|
|
272
|
+
process.stdout.write(line + '\n');
|
|
269
273
|
}
|
|
270
274
|
idPrefix() {
|
|
271
275
|
return 'cg-srv';
|
|
@@ -351,9 +355,13 @@ class SocketTransport extends LineBasedJsonRpcTransport {
|
|
|
351
355
|
this.socket.write(line.endsWith('\n') ? line : line + '\n');
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
|
-
write(line) {
|
|
358
|
+
write(line, onWritten) {
|
|
355
359
|
if (!this.socket.destroyed) {
|
|
356
|
-
|
|
360
|
+
if (onWritten)
|
|
361
|
+
this.socket.write(line + '\n', error => { if (!error)
|
|
362
|
+
onWritten(); });
|
|
363
|
+
else
|
|
364
|
+
this.socket.write(line + '\n');
|
|
357
365
|
}
|
|
358
366
|
}
|
|
359
367
|
idPrefix() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/mcp/transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mDAAqC;AAyCrC,gCAAgC;AACnB,QAAA,UAAU,GAAG;IACxB,UAAU,EAAE,CAAC,KAAK;IAClB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,aAAa,EAAE,CAAC,KAAK;IACrB,aAAa,EAAE,CAAC,KAAK;CACb,CAAC;AAmBX;;;;;GAKG;AACH,MAAe,yBAAyB;IAC5B,cAAc,GAA0B,IAAI,CAAC;IACvD,2EAA2E;IAC3E,4DAA4D;IAClD,OAAO,GAAG,IAAI,GAAG,EAGvB,CAAC;IACK,aAAa,GAAG,CAAC,CAAC;IAClB,OAAO,GAAG,KAAK,CAAC;IAO1B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAc,EAAE,MAAgB,EA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|
|
9
9
|
const PHASES = new Set(['spawn', 'import', 'registry', 'store', 'listen', 'ready',
|
|
10
10
|
'periodic_sync', 'empty_shutdown', 'shutdown_request', 'sync_failed', 'store_read_failed',
|
|
11
|
+
'store_manifest_missing', 'store_root_missing', 'store_access_denied', 'store_io_failed',
|
|
12
|
+
'store_manifest_invalid', 'store_artifact_missing',
|
|
11
13
|
'cleanup_failed', 'close_failed', 'close', 'closed']);
|
|
12
14
|
const RUN_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u;
|
|
13
15
|
const WINDOWS_REPLACE_WAIT_MS = 500;
|
|
@@ -164,7 +166,7 @@ export function recordLifecyclePhase(run, phase) {
|
|
|
164
166
|
}
|
|
165
167
|
const at = new Date().toISOString();
|
|
166
168
|
if (phase === 'ready' && run.ready_at === null) run.ready_at = at;
|
|
167
|
-
if (
|
|
169
|
+
if (phase.startsWith('store_') || ['sync_failed', 'cleanup_failed', 'close_failed'].includes(phase)) {
|
|
168
170
|
run.last_failure_observed = { at, phase };
|
|
169
171
|
}
|
|
170
172
|
run.events.push({ at, phase });
|
package/src/fs-publish.mjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { rename } from 'node:fs/promises';
|
|
2
2
|
import { setTimeout } from 'node:timers/promises';
|
|
3
3
|
|
|
4
|
+
/** Same file-sync policy for Store artifacts and transient ownership records. */
|
|
5
|
+
export async function syncPublishedFile(handle, absolute, { platform = process.platform } = {}) {
|
|
6
|
+
try { await handle.sync(); }
|
|
7
|
+
catch (error) {
|
|
8
|
+
if (!(platform === 'linux' && /^\/mnt\//u.test(absolute) && error?.code === 'EIO')) throw error;
|
|
9
|
+
process.stderr.write(`lattice: fsync skipped (WSL2/NTFS EIO) ${absolute}\n`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
/** Windowsは読み手が開いている宛先へのrenameを一時的にEPERMで拒否する。
|
|
5
14
|
* 同じatomic renameを待って再実行し、恒久的な拒否は元のエラーで返す。 */
|
|
6
15
|
export async function renamePublishedFile(source, destination, {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { lstatSync, mkdirSync, openSync, writeFileSync, closeSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { ensureSafeDir, ensureSafeFile, replaceStoreFile } from './runtime-errors.mjs';
|
|
7
|
+
import { observeDashboardProcess } from './dashboard-process-control.mjs';
|
|
8
|
+
import { isAclScratchName } from './windows-owner-only.mjs';
|
|
9
|
+
|
|
10
|
+
const VERSION = /^[a-zA-Z0-9.+-]{1,128}$/u;
|
|
11
|
+
const PHASES = new Set(['initialize_received', 'initialize_response_written']);
|
|
12
|
+
export const MCP_RECEIPT_SLOTS = 64;
|
|
13
|
+
export const MCP_RECEIPT_BYTES = 4096;
|
|
14
|
+
|
|
15
|
+
/** No filesystem or process-identity work on the MCP response event loop. */
|
|
16
|
+
export function createMcpStartupReceipt(wrapperVersion) {
|
|
17
|
+
let worker;
|
|
18
|
+
const posted = new Set();
|
|
19
|
+
const post = message => { try { worker?.postMessage(message); } catch { /* observation only */ } };
|
|
20
|
+
const phase = name => {
|
|
21
|
+
if (!worker || posted.has(name)) return;
|
|
22
|
+
posted.add(name); post({ phase: name, at: new Date().toISOString() });
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
setMode(mode, sensorVersion) {
|
|
26
|
+
if (!['direct', 'proxy'].includes(mode) || !VERSION.test(wrapperVersion) || !VERSION.test(sensorVersion)) return;
|
|
27
|
+
if (!worker) {
|
|
28
|
+
try {
|
|
29
|
+
worker = new Worker(new URL(import.meta.url), { workerData: {
|
|
30
|
+
receipt: true, home: homedir(), wrapperVersion, pid: process.pid,
|
|
31
|
+
runId: randomUUID(), startedAt: new Date().toISOString(),
|
|
32
|
+
}, stdout: true, stderr: true });
|
|
33
|
+
worker.stdout.resume(); worker.stderr.resume();
|
|
34
|
+
worker.on('error', () => {});
|
|
35
|
+
worker.unref();
|
|
36
|
+
} catch { return; }
|
|
37
|
+
}
|
|
38
|
+
if (!posted.has(mode)) { posted.add(mode); post({ mode, sensorVersion }); }
|
|
39
|
+
},
|
|
40
|
+
initializeReceived() { phase('initialize_received'); },
|
|
41
|
+
initializeWritten() { phase('initialize_response_written'); },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!isMainThread && workerData?.receipt === true) {
|
|
46
|
+
// Parent messages carry fixed observations only, never JSON-RPC data.
|
|
47
|
+
let queue = Promise.resolve();
|
|
48
|
+
let slot = null;
|
|
49
|
+
let disabled = false;
|
|
50
|
+
let record = null;
|
|
51
|
+
const root = path.join(workerData.home, '.lattice', 'mcp-startup');
|
|
52
|
+
async function prepare() {
|
|
53
|
+
const parent = path.dirname(root);
|
|
54
|
+
try { mkdirSync(parent, { mode: 0o700 }); } catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
55
|
+
const info = lstatSync(parent);
|
|
56
|
+
if (!info.isDirectory() || info.isSymbolicLink()
|
|
57
|
+
|| process.platform !== 'win32' && (info.uid !== process.getuid() || (info.mode & 0o022) !== 0)) throw Error('unsafe');
|
|
58
|
+
ensureSafeDir(root);
|
|
59
|
+
if (readdirSync(root).some(name => !/^slot-(?:[0-9]|[1-5][0-9]|6[0-3])$/u.test(name)
|
|
60
|
+
&& !(process.platform === 'win32' && isAclScratchName(name)))) throw Error('unexpected entry');
|
|
61
|
+
for (let index = 0; index < MCP_RECEIPT_SLOTS; index++) {
|
|
62
|
+
const candidate = path.join(root, `slot-${index}`);
|
|
63
|
+
try { mkdirSync(candidate, { mode: 0o700 }); slot = candidate; break; }
|
|
64
|
+
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
65
|
+
}
|
|
66
|
+
if (!slot) throw Error('capacity');
|
|
67
|
+
ensureSafeDir(slot);
|
|
68
|
+
const identity = await observeDashboardProcess(workerData.pid);
|
|
69
|
+
record = { schema: 'lattice.mcp_startup.v1', run_id: workerData.runId,
|
|
70
|
+
pid: workerData.pid, birth: identity?.birth ?? null,
|
|
71
|
+
wrapper_version: workerData.wrapperVersion, sensor_version: null, mode: null,
|
|
72
|
+
events: [{ phase: 'started', at: workerData.startedAt }] };
|
|
73
|
+
}
|
|
74
|
+
async function receive(message) {
|
|
75
|
+
if (disabled) return;
|
|
76
|
+
if (!record) await prepare();
|
|
77
|
+
if (['direct', 'proxy'].includes(message.mode) && VERSION.test(message.sensorVersion)) {
|
|
78
|
+
record.mode = message.mode; record.sensor_version = message.sensorVersion;
|
|
79
|
+
} else if (PHASES.has(message.phase) && typeof message.at === 'string'
|
|
80
|
+
&& Number.isFinite(Date.parse(message.at)) && !record.events.some(e => e.phase === message.phase)) {
|
|
81
|
+
if (message.phase === 'initialize_response_written'
|
|
82
|
+
&& !record.events.some(e => e.phase === 'initialize_received')) return;
|
|
83
|
+
record.events.push({ phase: message.phase, at: message.at });
|
|
84
|
+
} else return;
|
|
85
|
+
if (!record.mode) return;
|
|
86
|
+
const bytes = JSON.stringify(record) + '\n';
|
|
87
|
+
if (Buffer.byteLength(bytes) > MCP_RECEIPT_BYTES) throw Error('capacity');
|
|
88
|
+
ensureSafeDir(root); ensureSafeDir(slot);
|
|
89
|
+
const temporary = path.join(slot, 'pending.json'), target = path.join(slot, 'receipt.json');
|
|
90
|
+
try { ensureSafeFile(target, slot); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
91
|
+
const fd = openSync(temporary, 'wx', 0o600);
|
|
92
|
+
try { writeFileSync(fd, bytes); } finally { closeSync(fd); }
|
|
93
|
+
ensureSafeFile(temporary, slot);
|
|
94
|
+
replaceStoreFile(temporary, target);
|
|
95
|
+
}
|
|
96
|
+
parentPort.on('message', message => {
|
|
97
|
+
queue = queue.then(() => receive(message)).catch(() => { disabled = true; parentPort.close(); });
|
|
98
|
+
});
|
|
99
|
+
}
|
package/src/project-cli.mjs
CHANGED
|
@@ -583,11 +583,11 @@ function describeCreateInputViolation(value) {
|
|
|
583
583
|
...(decoupledPhaseInput ? { phase_accept_dependencies: value.phase_accept_dependencies } : {}),
|
|
584
584
|
});
|
|
585
585
|
} catch (error) {
|
|
586
|
-
//
|
|
586
|
+
// Author-specific fields keep their existing diagnostic priority.
|
|
587
587
|
const shape = describePlanShapeViolation(value, { phaseInput });
|
|
588
588
|
if (shape !== null) return shape;
|
|
589
589
|
return {
|
|
590
|
-
violation_kind: error?.reason ?? error?.code ?? 'topology_invalid',
|
|
590
|
+
violation_kind: error?.detail?.violation_kind ?? error?.reason ?? error?.code ?? 'topology_invalid',
|
|
591
591
|
pointer: error?.detail?.pointer ?? '/',
|
|
592
592
|
expected: error?.detail?.expected ?? { schema: value.schema },
|
|
593
593
|
actual: error?.detail?.actual ?? { message: String(error?.message ?? error) },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import { readFile, readlink, realpath } from 'node:fs/promises';
|
|
3
3
|
import { promisify } from 'node:util';
|
|
4
4
|
|
|
5
5
|
const execFileAsync = promisify(execFile);
|
|
@@ -16,6 +16,23 @@ const WINDOWS_TICKS_PER_MILLISECOND = 10_000n;
|
|
|
16
16
|
// 非ASCIIを可逆に表現するため、この劣化は起きない。
|
|
17
17
|
export function osObservationEnvironment() { return { ...process.env, LC_ALL: 'C' }; }
|
|
18
18
|
|
|
19
|
+
/** Host/PID domain for local ownership checks; never a hostname or public actor. */
|
|
20
|
+
export async function observeProcessHostIdentityRaw() {
|
|
21
|
+
if (process.platform === 'linux') {
|
|
22
|
+
const [boot, namespace] = await Promise.all([
|
|
23
|
+
readFile('/proc/sys/kernel/random/boot_id', 'utf8'), readlink('/proc/self/ns/pid'),
|
|
24
|
+
]);
|
|
25
|
+
return `${boot.trim()}:${namespace}`;
|
|
26
|
+
}
|
|
27
|
+
const executable = process.platform === 'win32' ? 'pwsh.exe' : '/usr/sbin/sysctl';
|
|
28
|
+
const args = process.platform === 'win32'
|
|
29
|
+
? ['-NoProfile', '-NonInteractive', '-Command',
|
|
30
|
+
"[Microsoft.Win32.Registry]::GetValue('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography','MachineGuid',$null)"]
|
|
31
|
+
: ['-n', 'kern.bootsessionuuid'];
|
|
32
|
+
const { stdout } = await execFileAsync(executable, args, { encoding: 'utf8', env: osObservationEnvironment() });
|
|
33
|
+
return stdout.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
/** processのstart identity(darwin/linuxはps lstart、win32はPowerShell StartTime Ticks)の生文字列を返す。 */
|
|
20
37
|
export async function observeStartIdentityRaw(pid) {
|
|
21
38
|
const executable = process.platform === 'win32' ? 'pwsh.exe' : '/bin/ps';
|
package/src/setup-config.mjs
CHANGED
|
@@ -107,13 +107,17 @@ export async function writeSetupFile(target, before, text) {
|
|
|
107
107
|
if (text === before.text) return 'unchanged';
|
|
108
108
|
await mkdir(path.dirname(target), { recursive: true });
|
|
109
109
|
const current = await readSetupFile(target);
|
|
110
|
-
if (current.text !== before.text || current.exists !== before.exists) throw setupError('CONFIG_CHANGED', '設定が同時に変更されました');
|
|
110
|
+
if (current.text !== before.text || current.exists !== before.exists || current.mode !== before.mode) throw setupError('CONFIG_CHANGED', '設定が同時に変更されました');
|
|
111
111
|
const temporary = `${target}.lattice-${randomUUID()}`;
|
|
112
112
|
try {
|
|
113
113
|
const handle = await open(temporary, 'wx', before.mode);
|
|
114
|
-
try {
|
|
114
|
+
try {
|
|
115
|
+
await handle.writeFile(text);
|
|
116
|
+
await handle.chmod(before.mode);
|
|
117
|
+
await handle.sync();
|
|
118
|
+
} finally { await handle.close(); }
|
|
115
119
|
const latest = await readSetupFile(target);
|
|
116
|
-
if (latest.text !== before.text || latest.exists !== before.exists) throw setupError('CONFIG_CHANGED', '設定が同時に変更されました');
|
|
120
|
+
if (latest.text !== before.text || latest.exists !== before.exists || latest.mode !== before.mode) throw setupError('CONFIG_CHANGED', '設定が同時に変更されました');
|
|
117
121
|
if (before.exists) await copyFile(target, `${temporary}.backup`);
|
|
118
122
|
await rename(temporary, target);
|
|
119
123
|
if ((await readSetupFile(target)).text !== text) throw setupError('CONFIG_READBACK_FAILED', '設定の読戻しが一致しません');
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { link, lstat, mkdir, open, readFile, readdir, rm, rmdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fsyncDirectory } from './fs-dir-sync.mjs';
|
|
5
|
+
import { syncPublishedFile } from './fs-publish.mjs';
|
|
6
|
+
import { observeStartIdentityRaw, observeProcessHostIdentityRaw } from './runtime-os-observation.mjs';
|
|
7
|
+
|
|
8
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
9
|
+
const CLAIM = /^([0-9a-f]{64})-([1-9][0-9]*)-([0-9a-f]{64})-([0-9a-f]{16})$/u;
|
|
10
|
+
let ownStart;
|
|
11
|
+
let ownHost;
|
|
12
|
+
|
|
13
|
+
export class StoreLockError extends Error {
|
|
14
|
+
constructor(reason, lockPath, detail = {}) {
|
|
15
|
+
super(reason);
|
|
16
|
+
this.name = 'StoreLockError';
|
|
17
|
+
this.reason = reason;
|
|
18
|
+
this.detail = {
|
|
19
|
+
lock_path: lockPath,
|
|
20
|
+
next_action: reason === 'lock_owner_unidentified'
|
|
21
|
+
? `Confirm no writer is running, then manually remove the unidentified lock: ${lockPath}`
|
|
22
|
+
: `Retry after the owner releases ${lockPath}; if it cannot, confirm no writer on the recorded host before manually clearing the abandoned lock.`,
|
|
23
|
+
...detail,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function identified(owner) {
|
|
29
|
+
return owner !== null && typeof owner === 'object'
|
|
30
|
+
&& Object.keys(owner).sort().join(',') === 'host,pid,process_start'
|
|
31
|
+
&& Number.isSafeInteger(owner.pid) && owner.pid > 0
|
|
32
|
+
&& typeof owner.host === 'string' && owner.host.length > 0 && owner.host.length <= 255
|
|
33
|
+
&& owner.process_start !== null && typeof owner.process_start === 'object'
|
|
34
|
+
&& Object.keys(owner.process_start).sort().join(',') === 'identity,platform'
|
|
35
|
+
&& typeof owner.process_start.platform === 'string' && owner.process_start.platform.length > 0
|
|
36
|
+
&& typeof owner.process_start.identity === 'string'
|
|
37
|
+
&& owner.process_start.identity.length > 0 && owner.process_start.identity.length <= 1024;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function processIsDead(pid, startDigest) {
|
|
41
|
+
try {
|
|
42
|
+
const observed = await observeStartIdentityRaw(pid);
|
|
43
|
+
if (observed) return hash(`${process.platform}:${observed}`) !== startDigest;
|
|
44
|
+
} catch {
|
|
45
|
+
// A failed observation cannot turn an existing PID into a dead owner.
|
|
46
|
+
}
|
|
47
|
+
try { process.kill(pid, 0); return false; }
|
|
48
|
+
catch (error) { return error?.code === 'ESRCH'; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function readOwner(lockPath) {
|
|
52
|
+
try {
|
|
53
|
+
const info = await lstat(lockPath);
|
|
54
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 8192) {
|
|
55
|
+
throw new StoreLockError('lock_owner_unidentified', lockPath);
|
|
56
|
+
}
|
|
57
|
+
let owner;
|
|
58
|
+
try { owner = JSON.parse(await readFile(lockPath, 'utf8')); }
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error?.code === 'ENOENT') return null;
|
|
61
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
62
|
+
throw new StoreLockError('lock_owner_unidentified', lockPath);
|
|
63
|
+
}
|
|
64
|
+
if (!identified(owner)) throw new StoreLockError('lock_owner_unidentified', lockPath);
|
|
65
|
+
return owner;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error?.code === 'ENOENT') return null;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function ownerIsDead(owner, host) {
|
|
73
|
+
return owner.host === host && owner.process_start.platform === process.platform
|
|
74
|
+
&& processIsDead(owner.pid,
|
|
75
|
+
hash(`${owner.process_start.platform}:${owner.process_start.identity}`));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function removeDeadTemporaries(lockPath, hostDigest) {
|
|
79
|
+
const prefix = `${path.basename(lockPath)}.`;
|
|
80
|
+
for (const name of await readdir(path.dirname(lockPath))) {
|
|
81
|
+
if (!name.startsWith(prefix) || !name.endsWith('.tmp')) continue;
|
|
82
|
+
const parsed = name.slice(prefix.length, -4).match(CLAIM);
|
|
83
|
+
if (parsed && parsed[1] === hostDigest && Number.isSafeInteger(Number(parsed[2]))
|
|
84
|
+
&& await processIsDead(Number(parsed[2]), parsed[3])) {
|
|
85
|
+
const temporary = path.join(path.dirname(lockPath), name);
|
|
86
|
+
const info = await lstat(temporary).catch((error) => {
|
|
87
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
88
|
+
return null;
|
|
89
|
+
});
|
|
90
|
+
if (info?.isFile() && !info.isSymbolicLink()) await rm(temporary, { force: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function recoveryClaim(claimsPath, owner, lockPath) {
|
|
96
|
+
const hostDigest = hash(owner.host);
|
|
97
|
+
const name = `${hostDigest}-${owner.pid}-${hash(`${owner.process_start.platform}:${owner.process_start.identity}`)}-${randomBytes(8).toString('hex')}`;
|
|
98
|
+
const claimPath = path.join(claimsPath, name);
|
|
99
|
+
// A releasing claimant may remove the empty parent between these mkdir calls.
|
|
100
|
+
for (;;) {
|
|
101
|
+
await mkdir(claimsPath, { recursive: true, mode: 0o700 });
|
|
102
|
+
const parent = await lstat(claimsPath);
|
|
103
|
+
if (!parent.isDirectory() || parent.isSymbolicLink()) throw new StoreLockError('store_locked', lockPath);
|
|
104
|
+
try { await mkdir(claimPath, { mode: 0o700 }); break; }
|
|
105
|
+
catch (error) { if (error?.code !== 'ENOENT') throw error; }
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
await removeDeadClaims(claimsPath, hostDigest, lockPath);
|
|
109
|
+
// All claimants publish before inspection; only a sole claimant may recover.
|
|
110
|
+
// Timestamp ordering could let a delayed earlier publisher enter twice.
|
|
111
|
+
const candidates = await readdir(claimsPath);
|
|
112
|
+
if (candidates.length === 1 && candidates[0] === name) return claimPath;
|
|
113
|
+
throw new StoreLockError('store_locked', lockPath, {
|
|
114
|
+
recovery_claims_path: claimsPath,
|
|
115
|
+
next_action: `Retry after recovery claimants exit; for foreign or unidentified claims, confirm no writer on their recorded host before clearing only abandoned entries in ${claimsPath}`,
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
await rmdir(claimPath);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function removeDeadClaims(claimsPath, hostDigest, lockPath) {
|
|
124
|
+
const state = await lstat(claimsPath).catch((error) => {
|
|
125
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
126
|
+
return null;
|
|
127
|
+
});
|
|
128
|
+
if (state === null) return;
|
|
129
|
+
if (!state.isDirectory() || state.isSymbolicLink()) {
|
|
130
|
+
throw new StoreLockError('store_locked', lockPath, { recovery_claims_path: claimsPath });
|
|
131
|
+
}
|
|
132
|
+
for (const entry of await readdir(claimsPath, { withFileTypes: true })) {
|
|
133
|
+
const parsed = entry.name.match(CLAIM);
|
|
134
|
+
if (entry.isDirectory() && parsed && parsed[1] === hostDigest
|
|
135
|
+
&& Number.isSafeInteger(Number(parsed[2]))
|
|
136
|
+
&& await processIsDead(Number(parsed[2]), parsed[3])) {
|
|
137
|
+
try { await rmdir(path.join(claimsPath, entry.name)); }
|
|
138
|
+
catch (error) { if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error?.code)) throw error; }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function removeClaim(claimPath, claimsPath) {
|
|
144
|
+
try { await rmdir(claimPath); }
|
|
145
|
+
catch (error) { if (error?.code !== 'ENOENT') throw error; }
|
|
146
|
+
try { await rmdir(claimsPath); }
|
|
147
|
+
catch (error) { if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error?.code)) throw error; }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Complete ownership is linked atomically; recovery never removes a live owner. */
|
|
151
|
+
export async function withStoreLock({ lockPath, recoveryClaimsPath = `${lockPath}.recovery`,
|
|
152
|
+
onRecoveryClaim = null, createParent = true, releasePath = () => lockPath }, callback) {
|
|
153
|
+
if (createParent) await mkdir(path.dirname(lockPath), { recursive: true });
|
|
154
|
+
ownStart ??= observeStartIdentityRaw(process.pid).catch((error) => { ownStart = undefined; throw error; });
|
|
155
|
+
ownHost ??= observeProcessHostIdentityRaw().then((value) => {
|
|
156
|
+
if (!value) throw new Error('process host domain unavailable');
|
|
157
|
+
return `${process.platform}:${hash(value)}`;
|
|
158
|
+
}).catch((error) => { ownHost = undefined; throw error; });
|
|
159
|
+
let identity;
|
|
160
|
+
let host;
|
|
161
|
+
try { [identity, host] = await Promise.all([ownStart, ownHost]); }
|
|
162
|
+
catch {
|
|
163
|
+
throw new StoreLockError('store_locked', lockPath, {
|
|
164
|
+
cause: 'lock_identity_unavailable',
|
|
165
|
+
next_action: `Restore platform host-domain and process-start observation, then retry ${lockPath}`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const owner = { pid: process.pid,
|
|
169
|
+
process_start: { platform: process.platform, identity }, host };
|
|
170
|
+
if (!identified(owner)) throw new StoreLockError('store_locked', lockPath, {
|
|
171
|
+
cause: 'lock_identity_unavailable',
|
|
172
|
+
next_action: `Restore platform host-domain and process-start observation, then retry ${lockPath}`,
|
|
173
|
+
});
|
|
174
|
+
const ownerBytes = `${JSON.stringify(owner)}\n`;
|
|
175
|
+
const temporary = `${lockPath}.${hash(host)}-${owner.pid}-${hash(`${owner.process_start.platform}:${owner.process_start.identity}`)}-${randomBytes(8).toString('hex')}.tmp`;
|
|
176
|
+
let claimPath = null;
|
|
177
|
+
let acquired = false;
|
|
178
|
+
let fileIdentity = null;
|
|
179
|
+
let callbackEntered = false;
|
|
180
|
+
try {
|
|
181
|
+
await removeDeadTemporaries(lockPath, hash(host));
|
|
182
|
+
for (const claimsPath of new Set([recoveryClaimsPath, `${lockPath}.recovery`])) {
|
|
183
|
+
await removeDeadClaims(claimsPath, hash(host), lockPath);
|
|
184
|
+
try { await rmdir(claimsPath); }
|
|
185
|
+
catch (error) { if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error?.code)) throw error; }
|
|
186
|
+
}
|
|
187
|
+
const handle = await open(temporary, 'wx', 0o600);
|
|
188
|
+
try {
|
|
189
|
+
await handle.writeFile(ownerBytes); await syncPublishedFile(handle, lockPath);
|
|
190
|
+
fileIdentity = await handle.stat();
|
|
191
|
+
}
|
|
192
|
+
finally { await handle.close(); }
|
|
193
|
+
for (;;) {
|
|
194
|
+
try { await link(temporary, lockPath); acquired = true; break; }
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'EXDEV', 'ENOSYS'].includes(error?.code)) {
|
|
197
|
+
throw new StoreLockError('store_locked', lockPath, {
|
|
198
|
+
cause: 'lock_publication_unavailable',
|
|
199
|
+
next_action: `Use a filesystem permitting atomic hard-link publication for ${lockPath}, then retry`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (error?.code !== 'EEXIST') throw error;
|
|
203
|
+
}
|
|
204
|
+
const existing = await readOwner(lockPath);
|
|
205
|
+
if (existing === null) continue;
|
|
206
|
+
if (!await ownerIsDead(existing, host)) throw new StoreLockError('store_locked', lockPath);
|
|
207
|
+
if (claimPath === null) {
|
|
208
|
+
claimPath = await recoveryClaim(recoveryClaimsPath, owner, lockPath);
|
|
209
|
+
if (onRecoveryClaim) await onRecoveryClaim();
|
|
210
|
+
}
|
|
211
|
+
const fresh = await readOwner(lockPath);
|
|
212
|
+
if (fresh !== null) {
|
|
213
|
+
if (!await ownerIsDead(fresh, host)) throw new StoreLockError('store_locked', lockPath);
|
|
214
|
+
await rm(lockPath);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
await rm(temporary);
|
|
218
|
+
await fsyncDirectory(path.dirname(lockPath));
|
|
219
|
+
callbackEntered = true;
|
|
220
|
+
return await callback();
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (!callbackEntered && error?.code === 'ENOENT') {
|
|
223
|
+
throw new StoreLockError('store_locked', lockPath, {
|
|
224
|
+
cause: 'lock_parent_missing',
|
|
225
|
+
next_action: `Retry after initialization or recovery finishes publishing ${path.dirname(lockPath)}`,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
} finally {
|
|
230
|
+
try {
|
|
231
|
+
const currentLockPath = await releasePath();
|
|
232
|
+
const currentIdentity = currentLockPath === null ? null : await lstat(currentLockPath).catch((error) => {
|
|
233
|
+
if (error?.code === 'ENOENT') return null;
|
|
234
|
+
throw error;
|
|
235
|
+
});
|
|
236
|
+
if (acquired && currentIdentity?.isFile() && !currentIdentity.isSymbolicLink()
|
|
237
|
+
&& currentIdentity.dev === fileIdentity.dev && currentIdentity.ino === fileIdentity.ino
|
|
238
|
+
&& await readFile(currentLockPath, 'utf8').catch((error) => {
|
|
239
|
+
if (error?.code === 'ENOENT') return null;
|
|
240
|
+
throw error;
|
|
241
|
+
}) === ownerBytes) {
|
|
242
|
+
await rm(currentLockPath);
|
|
243
|
+
await fsyncDirectory(path.dirname(currentLockPath));
|
|
244
|
+
}
|
|
245
|
+
} finally {
|
|
246
|
+
await rm(temporary, { force: true });
|
|
247
|
+
if (claimPath !== null) await removeClaim(claimPath, recoveryClaimsPath);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
package/src/todo-cli.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateProspectiveEvent } from './todo-readiness.mjs';
|
|
1
2
|
import { cliCommandKind } from './cli-command-kind.mjs';
|
|
2
3
|
import { cliFailureClass } from './cli-failure-class.mjs';
|
|
3
4
|
import { readTaskBackchainContext } from './plan-backchain.mjs';
|
|
@@ -666,6 +667,7 @@ async function mutate({
|
|
|
666
667
|
eventPayload = { done_mode: 'evidence_promotion', evidence };
|
|
667
668
|
}
|
|
668
669
|
const { event, snapshot, plan, phases } = await appendTodoEvent({
|
|
670
|
+
validateProspectiveEvent,
|
|
669
671
|
repoRoot,
|
|
670
672
|
writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
671
673
|
planKey,
|
|
@@ -1078,6 +1080,7 @@ async function phaseDecisionFromEvidence({ repoRoot, env, planKey, phaseId, outc
|
|
|
1078
1080
|
|
|
1079
1081
|
async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload }) {
|
|
1080
1082
|
const { event, snapshot, phases } = await appendTodoEvent({
|
|
1083
|
+
validateProspectiveEvent,
|
|
1081
1084
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
|
|
1082
1085
|
event: { kind, phase_id: phaseId, actor: mutationActor(env), payload },
|
|
1083
1086
|
});
|
|
@@ -1105,6 +1108,7 @@ async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload })
|
|
|
1105
1108
|
*/
|
|
1106
1109
|
async function independenceMode({ repoRoot, env, planKey, mode, reason }) {
|
|
1107
1110
|
const { event } = await appendTodoEvent({
|
|
1111
|
+
validateProspectiveEvent,
|
|
1108
1112
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
|
|
1109
1113
|
event: { kind: 'coordination_mode', actor: mutationActor(env), payload: { mode, reason } },
|
|
1110
1114
|
});
|
|
@@ -1158,6 +1162,7 @@ async function dependencyConnect({
|
|
|
1158
1162
|
expected_topology_digest: target.plan.topology_digest,
|
|
1159
1163
|
};
|
|
1160
1164
|
const { event } = await appendTodoEvent({
|
|
1165
|
+
validateProspectiveEvent,
|
|
1161
1166
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey: toPlanKey,
|
|
1162
1167
|
event: {
|
|
1163
1168
|
kind: 'cross_plan_dependency', actor: mutationActor(env), payload: { from, to, reason },
|
|
@@ -1195,6 +1200,7 @@ async function dependencyDisconnect({
|
|
|
1195
1200
|
const owner = store.members.find((member) => (member.plan_scoped?.events ?? [])
|
|
1196
1201
|
.some((event) => event.event_digest === target.event_digest));
|
|
1197
1202
|
const { event } = await appendTodoEvent({
|
|
1203
|
+
validateProspectiveEvent,
|
|
1198
1204
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey: owner.plan.plan_key,
|
|
1199
1205
|
tolerateStaleBindings: true,
|
|
1200
1206
|
event: {
|