@quolu/lattice 0.81.0 → 0.83.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-bridge-supervisor.mjs +18 -3
- package/bin/lattice-dashboard.mjs +3 -18
- package/bin/lattice-mcp.mjs +6 -3
- package/bin/lattice.mjs +29 -1
- package/docs/schemas/lattice.plan_create_input.v5.schema.json +375 -0
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +35 -0
- package/package.json +4 -2
- package/sensor/dist/db/index.d.ts +1 -0
- package/sensor/dist/db/index.d.ts.map +1 -1
- package/sensor/dist/db/index.js +13 -0
- package/sensor/dist/db/index.js.map +1 -1
- package/sensor/dist/index.d.ts.map +1 -1
- package/sensor/dist/index.js +12 -2
- package/sensor/dist/index.js.map +1 -1
- package/sensor/dist/mcp/answer-freshness.js +1 -1
- package/sensor/dist/mcp/answer-freshness.js.map +1 -1
- package/sensor/dist/mcp/engine.d.ts +11 -0
- package/sensor/dist/mcp/engine.d.ts.map +1 -1
- package/sensor/dist/mcp/engine.js +83 -4
- package/sensor/dist/mcp/engine.js.map +1 -1
- package/sensor/dist/mcp/index-repair.d.ts +7 -0
- package/sensor/dist/mcp/index-repair.d.ts.map +1 -0
- package/sensor/dist/mcp/index-repair.js +93 -0
- package/sensor/dist/mcp/index-repair.js.map +1 -0
- package/sensor/dist/mcp/index.d.ts.map +1 -1
- package/sensor/dist/mcp/index.js +12 -7
- package/sensor/dist/mcp/index.js.map +1 -1
- package/sensor/dist/mcp/tools.d.ts +4 -0
- package/sensor/dist/mcp/tools.d.ts.map +1 -1
- package/sensor/dist/mcp/tools.js +29 -9
- package/sensor/dist/mcp/tools.js.map +1 -1
- package/src/bridge-cli.mjs +16 -4
- package/src/bridge-detached-supervisor.mjs +204 -0
- package/src/bridge-hub-server.mjs +46 -9
- package/src/bridge-startup-folder.mjs +7 -4
- package/src/cli-help.mjs +5 -2
- package/src/dashboard-lifecycle-journal.mjs +42 -20
- package/src/plan-backchain.mjs +31 -12
- package/src/plan-binding-carry.mjs +60 -0
- package/src/plan-revise.mjs +276 -0
- package/src/project-cli.mjs +50 -22
- package/src/project-identity.mjs +14 -0
- package/src/runtime-cli.mjs +31 -18
- package/src/runtime-control-store.mjs +22 -1
- package/src/runtime-decision-verifier.mjs +27 -8
- package/src/runtime-engine.mjs +34 -5
- package/src/runtime-hold-recompile.mjs +19 -15
- package/src/runtime-kept-worktree.mjs +136 -0
- package/src/runtime-lifecycle-lock.mjs +118 -30
- package/src/runtime-managed-supervisor.mjs +10 -10
- package/src/runtime-os-observation.mjs +39 -1
- package/src/runtime-pull-intake.mjs +87 -43
- package/src/store-lock.mjs +146 -59
- package/src/todo-authoring-input.mjs +57 -2
- package/src/todo-cli.mjs +173 -45
- package/src/todo-contracts.mjs +22 -6
- package/src/todo-dashboard-registry.mjs +31 -4
- package/src/todo-gantt-display.mjs +260 -0
- package/src/todo-gantt-html-independence.mjs +8 -1
- package/src/todo-gantt-html-shared.mjs +2 -1
- package/src/todo-gantt-html.mjs +4 -2
- package/src/todo-gantt-layout.mjs +7 -36
- package/src/todo-gantt-live.mjs +6 -3
- package/src/todo-note-store.mjs +13 -5
- package/src/todo-readiness.mjs +29 -8
- package/src/todo-revision.mjs +9 -8
- package/src/todo-split.mjs +6 -3
- package/src/todo-status.mjs +53 -9
- package/src/todo-store-cache.mjs +1 -1
- package/src/todo-store-view.mjs +21 -2
- package/src/todo-store.mjs +642 -172
package/src/bridge-cli.mjs
CHANGED
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
describeBridgeStartupFolder, disableBridgeStartupFolder, installBridgeStartupFolder,
|
|
27
27
|
restoreBridgeStartupFolder, snapshotBridgeStartupFolder,
|
|
28
28
|
} from './bridge-startup-folder.mjs';
|
|
29
|
+
import {
|
|
30
|
+
describeBridgeDetachedSupervisor, disableBridgeDetachedSupervisor, installBridgeDetachedSupervisor,
|
|
31
|
+
restoreBridgeDetachedSupervisor, snapshotBridgeDetachedSupervisor,
|
|
32
|
+
} from './bridge-detached-supervisor.mjs';
|
|
29
33
|
|
|
30
34
|
// v2 adds the liveness fields. `enabled` only says the configuration is on;
|
|
31
35
|
// it never said the bridge could actually be reached, which let a DHCP lease
|
|
@@ -86,16 +90,24 @@ async function bridgeLiveness(config, { interfaces = networkInterfaces(), probe
|
|
|
86
90
|
// what lets `lattice bridge setup` on Windows persist via the Startup folder
|
|
87
91
|
// exactly the way it persists via a LaunchAgent on macOS, with no separate
|
|
88
92
|
// command or manual step (see bridge-startup-folder.mjs's module doc for why
|
|
89
|
-
// Task Scheduler's ONLOGON trigger could not be used instead).
|
|
93
|
+
// Task Scheduler's ONLOGON trigger could not be used instead). Every other OS
|
|
94
|
+
// (Linux seats in containers) gets the detached supervisor: the adapter is the
|
|
95
|
+
// only code that touches its OS tool, so `dashboard ensure` on Linux never
|
|
96
|
+
// probes launchctl (docs/architecture/dfd-bridge-persistence.md).
|
|
90
97
|
function platformLaunchAgent() {
|
|
91
98
|
if (process.platform === 'win32') {
|
|
92
99
|
return { snapshot: snapshotBridgeStartupFolder, install: installBridgeStartupFolder,
|
|
93
100
|
disable: disableBridgeStartupFolder, restore: restoreBridgeStartupFolder,
|
|
94
101
|
describe: describeBridgeStartupFolder };
|
|
95
102
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
if (process.platform === 'darwin') {
|
|
104
|
+
return { snapshot: snapshotBridgeLaunchAgent, install: installBridgeLaunchAgent,
|
|
105
|
+
disable: disableBridgeLaunchAgent, restore: restoreBridgeLaunchAgent,
|
|
106
|
+
describe: describeBridgeLaunchAgent };
|
|
107
|
+
}
|
|
108
|
+
return { snapshot: snapshotBridgeDetachedSupervisor, install: installBridgeDetachedSupervisor,
|
|
109
|
+
disable: disableBridgeDetachedSupervisor, restore: restoreBridgeDetachedSupervisor,
|
|
110
|
+
describe: describeBridgeDetachedSupervisor };
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
const UNREADABLE_PERSISTENCE = Object.freeze({ loaded: null, node_path: null, node_exists: false,
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge persistence for Linux and any other OS without launchd or a Startup
|
|
3
|
+
* folder: the third adapter behind `bridge-cli.mjs`'s `platformLaunchAgent`,
|
|
4
|
+
* with the same contract (`snapshot`/`describe`/`install`/`disable`/`restore`)
|
|
5
|
+
* as `bridge-launch-agent.mjs` (macOS) and `bridge-startup-folder.mjs`
|
|
6
|
+
* (Windows). State is a supervisor descriptor plus pidfile under
|
|
7
|
+
* `<seat root>/bridge-linux/`; `install` spawns `bin/lattice-bridge-supervisor.mjs`
|
|
8
|
+
* detached, and that supervisor restarts a crashed bridge. Nothing here runs
|
|
9
|
+
* another OS's tool, so `lattice todo dashboard ensure` on a Linux seat no
|
|
10
|
+
* longer probes `/bin/launchctl` inside delivery recovery.
|
|
11
|
+
*
|
|
12
|
+
* shortcut: no boot/login persistence on Linux (a BellTeam seat is a container
|
|
13
|
+
* whose setup re-runs `bridge reconfigure` after restart), upgrade to a
|
|
14
|
+
* `systemd --user` unit when a seat runs on a host with a user session manager.
|
|
15
|
+
* Flow: docs/architecture/dfd-bridge-persistence.md.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { spawn } from 'node:child_process';
|
|
19
|
+
import { randomBytes } from 'node:crypto';
|
|
20
|
+
import { mkdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
import { BridgeConfigError, bridgeConfigPaths } from './bridge-config.mjs';
|
|
24
|
+
import { DEFAULT_BRIDGE_PATH, DEFAULT_SUPERVISOR_PATH } from './bridge-executable.mjs';
|
|
25
|
+
import { observeDashboardProcess } from './dashboard-process-control.mjs';
|
|
26
|
+
import { supervisorDescriptor, waitForBridgeStartupReady } from './bridge-startup-folder.mjs';
|
|
27
|
+
|
|
28
|
+
const START_FAILED = 'BRIDGE_DETACHED_SUPERVISOR_START_FAILED';
|
|
29
|
+
const STOP_TIMEOUT_MS = 10_000;
|
|
30
|
+
const SOCKET_TIMEOUT_MS = 3_000;
|
|
31
|
+
|
|
32
|
+
function fail(code, message, cause = undefined) {
|
|
33
|
+
return new BridgeConfigError(code, message, undefined, cause);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function bridgeDetachedSupervisorPaths(env = process.env) {
|
|
37
|
+
const directory = path.join(bridgeConfigPaths(env).root, 'bridge-linux');
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
directory,
|
|
40
|
+
descriptor: path.join(directory, 'descriptor.json'),
|
|
41
|
+
pidfile: path.join(directory, 'supervisor.pid'),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function optionalFile(ref) {
|
|
46
|
+
try { return await readFile(ref, 'utf8'); } catch (error) {
|
|
47
|
+
if (error?.code === 'ENOENT') return null;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function atomicFile(ref, content) {
|
|
53
|
+
const temporary = `${ref}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`;
|
|
54
|
+
try {
|
|
55
|
+
await writeFile(temporary, content, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
56
|
+
await rename(temporary, ref);
|
|
57
|
+
} finally {
|
|
58
|
+
await rm(temporary, { force: true });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function present(ref) {
|
|
63
|
+
if (typeof ref !== 'string') return false;
|
|
64
|
+
try { await stat(ref); return true; } catch { return false; }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function executablePath(ref, label) {
|
|
68
|
+
if (typeof ref !== 'string' || !path.isAbsolute(ref)) {
|
|
69
|
+
throw fail('BRIDGE_DETACHED_SUPERVISOR_EXECUTABLE_INVALID', `${label} path must be absolute`);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const resolved = await realpath(ref);
|
|
73
|
+
if (!(await stat(resolved)).isFile()) throw new Error('not a file');
|
|
74
|
+
return resolved;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw fail('BRIDGE_DETACHED_SUPERVISOR_EXECUTABLE_INVALID', `${label} is unavailable`, error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function healthHost(address) {
|
|
81
|
+
if (address === '0.0.0.0') return '127.0.0.1';
|
|
82
|
+
if (address === '::') return '[::1]';
|
|
83
|
+
return address.includes(':') ? `[${address}]` : address;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The old bridge must have released its socket before the new one binds it. */
|
|
87
|
+
async function defaultWaitStopped({ listen, timeoutMs = SOCKET_TIMEOUT_MS }) {
|
|
88
|
+
if (!listen) return;
|
|
89
|
+
const deadline = Date.now() + timeoutMs;
|
|
90
|
+
while (Date.now() < deadline) {
|
|
91
|
+
try {
|
|
92
|
+
await fetch(`http://${healthHost(listen.address)}:${listen.port}/__lattice/bridge-health`,
|
|
93
|
+
{ signal: AbortSignal.timeout(300) });
|
|
94
|
+
} catch { return; }
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
96
|
+
}
|
|
97
|
+
throw fail('BRIDGE_DETACHED_SUPERVISOR_STOP_FAILED', 'bridge socket did not stop');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function stopRunning({ refs, listen, waitStopped, observeProcess = observeDashboardProcess }) {
|
|
101
|
+
// shortcut: live numeric-only supervisors require owner-authenticated retirement before upgrading.
|
|
102
|
+
const content = await optionalFile(refs.pidfile);
|
|
103
|
+
let identity;
|
|
104
|
+
let stopped = false;
|
|
105
|
+
try { identity = JSON.parse(content); } catch {}
|
|
106
|
+
if (Number.isSafeInteger(identity?.pid) && identity.pid > 0
|
|
107
|
+
&& typeof identity.birth === 'string' && identity.birth.length > 0) {
|
|
108
|
+
const observe = async () => {
|
|
109
|
+
try { return await observeProcess(identity.pid); }
|
|
110
|
+
catch { return { pid: identity.pid, birth: null }; }
|
|
111
|
+
};
|
|
112
|
+
if ((await observe())?.birth === identity.birth) {
|
|
113
|
+
try { process.kill(identity.pid, 'SIGTERM'); } catch (error) {
|
|
114
|
+
if (error?.code !== 'ESRCH') throw error;
|
|
115
|
+
}
|
|
116
|
+
const deadline = Date.now() + STOP_TIMEOUT_MS;
|
|
117
|
+
let observed = await observe();
|
|
118
|
+
while (observed?.birth === identity.birth && Date.now() < deadline) {
|
|
119
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
120
|
+
observed = await observe();
|
|
121
|
+
}
|
|
122
|
+
if (observed?.birth === identity.birth) {
|
|
123
|
+
throw fail('BRIDGE_DETACHED_SUPERVISOR_STOP_FAILED', 'bridge supervisor did not stop');
|
|
124
|
+
}
|
|
125
|
+
stopped = observed === null || (typeof observed?.birth === 'string' && observed.birth.length > 0);
|
|
126
|
+
if (stopped) await waitStopped({ listen });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
await rm(refs.pidfile, { force: true });
|
|
130
|
+
return stopped;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function defaultDetachedLaunch({ nodePath, supervisorPath, descriptorPath, env }) {
|
|
134
|
+
const child = spawn(nodePath, [supervisorPath, descriptorPath], { env, detached: true, stdio: 'ignore' });
|
|
135
|
+
child.unref();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function snapshotBridgeDetachedSupervisor({ env = process.env } = {}) {
|
|
139
|
+
const refs = bridgeDetachedSupervisorPaths(env);
|
|
140
|
+
await mkdir(refs.directory, { recursive: true, mode: 0o700 });
|
|
141
|
+
const descriptorContent = await optionalFile(refs.descriptor);
|
|
142
|
+
return Object.freeze({ installed: descriptorContent !== null, split: false,
|
|
143
|
+
launcherContent: null, descriptorContent });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function describeBridgeDetachedSupervisor({ snapshot } = {}) {
|
|
147
|
+
if (snapshot?.installed !== true) return null;
|
|
148
|
+
const descriptor = JSON.parse(snapshot.descriptorContent);
|
|
149
|
+
const nodePath = typeof descriptor.nodePath === 'string' ? descriptor.nodePath : null;
|
|
150
|
+
return { node_path: nodePath, node_exists: await present(nodePath),
|
|
151
|
+
bridge_path: descriptor.bridgePath, bridge_exists: await present(descriptor.bridgePath) };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function installBridgeDetachedSupervisor({ config, env = process.env,
|
|
155
|
+
nodePath = process.execPath, bridgePath = DEFAULT_BRIDGE_PATH, supervisorPath = DEFAULT_SUPERVISOR_PATH,
|
|
156
|
+
launch = defaultDetachedLaunch, waitReady = waitForBridgeStartupReady,
|
|
157
|
+
waitStopped = defaultWaitStopped, previousListen = null } = {}) {
|
|
158
|
+
if (config?.enabled !== true) throw fail('BRIDGE_DISABLED', 'bridge is disabled');
|
|
159
|
+
const refs = bridgeDetachedSupervisorPaths(env);
|
|
160
|
+
await mkdir(refs.directory, { recursive: true, mode: 0o700 });
|
|
161
|
+
const resolvedNode = await executablePath(nodePath, 'node executable');
|
|
162
|
+
const resolvedBridge = await executablePath(bridgePath, 'bridge executable');
|
|
163
|
+
const resolvedSupervisor = await executablePath(supervisorPath, 'supervisor executable');
|
|
164
|
+
const instanceToken = randomBytes(32).toString('hex');
|
|
165
|
+
const descriptorContent = supervisorDescriptor({
|
|
166
|
+
bridgePath: resolvedBridge, pidfile: refs.pidfile, instanceToken, env, nodePath: resolvedNode,
|
|
167
|
+
});
|
|
168
|
+
await stopRunning({ refs, listen: previousListen, waitStopped });
|
|
169
|
+
await atomicFile(refs.descriptor, descriptorContent);
|
|
170
|
+
await launch({ nodePath: resolvedNode, supervisorPath: resolvedSupervisor, descriptorPath: refs.descriptor, env });
|
|
171
|
+
return waitReady({ config, instanceToken, env, failureCode: START_FAILED });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function disableBridgeDetachedSupervisor({ snapshot, listen, env = process.env,
|
|
175
|
+
waitStopped = defaultWaitStopped, observeProcess = observeDashboardProcess } = {}) {
|
|
176
|
+
if (!snapshot || typeof snapshot.installed !== 'boolean') {
|
|
177
|
+
throw new TypeError('bridge detached supervisor snapshot required');
|
|
178
|
+
}
|
|
179
|
+
const refs = bridgeDetachedSupervisorPaths(env);
|
|
180
|
+
const stopped = snapshot.installed ? await stopRunning({ refs, listen, waitStopped, observeProcess }) : false;
|
|
181
|
+
await rm(refs.descriptor, { force: true });
|
|
182
|
+
await rm(refs.pidfile, { force: true });
|
|
183
|
+
return { removed: snapshot.installed, stopped };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function restoreBridgeDetachedSupervisor({ snapshot, listen = null, env = process.env,
|
|
187
|
+
launch = defaultDetachedLaunch, waitStopped = defaultWaitStopped, config = undefined,
|
|
188
|
+
supervisorPath = DEFAULT_SUPERVISOR_PATH, waitReady = waitForBridgeStartupReady } = {}) {
|
|
189
|
+
if (!snapshot || typeof snapshot.installed !== 'boolean'
|
|
190
|
+
|| (snapshot.installed && typeof snapshot.descriptorContent !== 'string')) {
|
|
191
|
+
throw new TypeError('bridge detached supervisor snapshot required');
|
|
192
|
+
}
|
|
193
|
+
const refs = bridgeDetachedSupervisorPaths(env);
|
|
194
|
+
await mkdir(refs.directory, { recursive: true, mode: 0o700 });
|
|
195
|
+
await stopRunning({ refs, listen, waitStopped });
|
|
196
|
+
if (!snapshot.installed) return;
|
|
197
|
+
await atomicFile(refs.descriptor, snapshot.descriptorContent);
|
|
198
|
+
const descriptor = JSON.parse(snapshot.descriptorContent);
|
|
199
|
+
await launch({ nodePath: descriptor.nodePath ?? process.execPath, supervisorPath, descriptorPath: refs.descriptor, env });
|
|
200
|
+
if (config !== undefined) {
|
|
201
|
+
await waitReady({ config, instanceToken: descriptor.env?.LATTICE_BRIDGE_INSTANCE_TOKEN, env,
|
|
202
|
+
failureCode: 'BRIDGE_DETACHED_SUPERVISOR_ROLLBACK_FAILED' });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -26,7 +26,7 @@ import { isIP } from 'node:net';
|
|
|
26
26
|
import { randomBytes } from 'node:crypto';
|
|
27
27
|
import { homedir } from 'node:os';
|
|
28
28
|
import {
|
|
29
|
-
mkdir, open, readFile, rename, rm, writeFile,
|
|
29
|
+
mkdir, open, readdir, readFile, rename, rm, writeFile,
|
|
30
30
|
} from 'node:fs/promises';
|
|
31
31
|
import path from 'node:path';
|
|
32
32
|
import { domainToASCII } from 'node:url';
|
|
@@ -373,12 +373,40 @@ export async function readBridgeHubPublicVisibility({ env = process.env } = {})
|
|
|
373
373
|
};
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
const QUARANTINE_KEEP = 3;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* u03 D20: an unreadable registry is moved aside (`terminals.json.invalid-<UTC>`, newest 3
|
|
380
|
+
* kept) and read as empty, so the hub keeps serving and terminals register again. A failed
|
|
381
|
+
* move leaves the file; the next read retries.
|
|
382
|
+
*/
|
|
383
|
+
async function quarantineRegistry(ref) {
|
|
384
|
+
// The random tail keeps two moves in the same millisecond from overwriting each other.
|
|
385
|
+
const stamp = `${new Date().toISOString().replace(/[:.]/gu, '-')}-${randomBytes(4).toString('hex')}`;
|
|
386
|
+
try { await rename(ref, `${ref}.invalid-${stamp}`); } catch { return; }
|
|
387
|
+
process.emitWarning(`hub registry was invalid and moved aside: ${ref}.invalid-${stamp}`,
|
|
388
|
+
{ code: 'LATTICE_BRIDGE_HUB_REGISTRY_QUARANTINED' });
|
|
389
|
+
const prefix = `${path.basename(ref)}.invalid-`;
|
|
390
|
+
const names = (await readdir(path.dirname(ref)).catch(() => []))
|
|
391
|
+
.filter((name) => name.startsWith(prefix)).sort().reverse();
|
|
392
|
+
for (const name of names.slice(QUARANTINE_KEEP)) {
|
|
393
|
+
await rm(path.join(path.dirname(ref), name), { force: true }).catch(() => {});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
376
397
|
/** Read the persisted registry. A missing file is an empty registry, not an error. */
|
|
377
398
|
export async function readBridgeHubRegistry({ env = process.env } = {}) {
|
|
378
399
|
const refs = hubRuntimePaths(env);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
400
|
+
let document;
|
|
401
|
+
try {
|
|
402
|
+
document = await readJsonDocument(refs.registry, { schema: HUB_REGISTRY_DOCUMENT_SCHEMA, entries: [] });
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (error?.code !== 'BRIDGE_HUB_REGISTRY_FILE_INVALID') throw error;
|
|
405
|
+
document = null;
|
|
406
|
+
}
|
|
407
|
+
if (document === null || !validRegistryDocument(document)) {
|
|
408
|
+
await quarantineRegistry(refs.registry);
|
|
409
|
+
return [];
|
|
382
410
|
}
|
|
383
411
|
return document.entries;
|
|
384
412
|
}
|
|
@@ -482,14 +510,22 @@ export async function startBridgeHubServer({
|
|
|
482
510
|
return;
|
|
483
511
|
}
|
|
484
512
|
const entries = await store.read();
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
513
|
+
let visibility;
|
|
514
|
+
try { visibility = await readBridgeHubPublicVisibility({ env }); } catch (error) {
|
|
515
|
+
if (error?.code !== 'BRIDGE_HUB_VISIBILITY_FILE_INVALID') throw error;
|
|
516
|
+
// u03 D20: the operator's hide list is unreadable. Never publish what it may hide, never
|
|
517
|
+
// stop the hub: list nothing until the file is fixed (hot-read, no restart needed).
|
|
518
|
+
process.emitWarning(`hub public-visibility file is invalid; the listing is empty until it is fixed`,
|
|
519
|
+
{ code: 'LATTICE_BRIDGE_HUB_VISIBILITY_INVALID' });
|
|
520
|
+
visibility = null;
|
|
521
|
+
}
|
|
522
|
+
const hiddenProjects = new Set(visibility?.hidden_project_ids ?? []);
|
|
523
|
+
const hiddenTerminals = new Set(visibility?.hidden_terminal_ids ?? []);
|
|
488
524
|
// The visibility filter applies to the listing only (both HTML and JSON);
|
|
489
525
|
// `/projects/<hidden>/` keeps proxying — hidden is not private (ADR 0164
|
|
490
526
|
// Decision 3, deliberately: smoke tests fetch their own page, operators
|
|
491
527
|
// keep the direct URL).
|
|
492
|
-
const projected = projectBridgeHubRegistry({ registry: entries, now: now(), ttlMs })
|
|
528
|
+
const projected = visibility === null ? [] : projectBridgeHubRegistry({ registry: entries, now: now(), ttlMs })
|
|
493
529
|
.filter((entry) => !hiddenProjects.has(entry.project_id) && !hiddenTerminals.has(entry.terminal_id));
|
|
494
530
|
// Only the fields humans need for the public index are exposed; internal
|
|
495
531
|
// routing fields (terminal_id, address, port) stay server-side, matching
|
|
@@ -517,7 +553,8 @@ export async function startBridgeHubServer({
|
|
|
517
553
|
response.end(`${JSON.stringify(view)}\n`);
|
|
518
554
|
return;
|
|
519
555
|
}
|
|
520
|
-
const html = renderBridgeHubLanding({ projects: view, lang,
|
|
556
|
+
const html = renderBridgeHubLanding({ projects: view, lang,
|
|
557
|
+
displayNames: visibility?.display_names ?? EMPTY_VISIBILITY.display_names });
|
|
521
558
|
response.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store',
|
|
522
559
|
'x-content-type-options': 'nosniff' });
|
|
523
560
|
response.end(html);
|
|
@@ -161,7 +161,8 @@ function launcherScript({ nodePath, supervisorPath, descriptorPath }) {
|
|
|
161
161
|
return `Set shell = CreateObject("WScript.Shell")\r\nshell.Run ${command}, 0, False\r\n`;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
/** Shared with `bridge-detached-supervisor.mjs`; `nodePath` is recorded only where no launcher file holds it. */
|
|
165
|
+
export function supervisorDescriptor({ bridgePath, pidfile, instanceToken, env, nodePath = undefined }) {
|
|
165
166
|
const forwarded = { LATTICE_BRIDGE_INSTANCE_TOKEN: instanceToken };
|
|
166
167
|
if (env.LATTICE_CONFIG_DIR !== undefined) {
|
|
167
168
|
if (typeof env.LATTICE_CONFIG_DIR !== 'string' || !path.isAbsolute(env.LATTICE_CONFIG_DIR)) {
|
|
@@ -177,7 +178,8 @@ function supervisorDescriptor({ bridgePath, pidfile, instanceToken, env }) {
|
|
|
177
178
|
forwarded.LATTICE_BRIDGE_REGISTRAR_SSH_HOST = registrar.host;
|
|
178
179
|
forwarded.LATTICE_BRIDGE_REGISTRAR_SCRIPT = registrar.script;
|
|
179
180
|
}
|
|
180
|
-
return JSON.stringify({ schema: DESCRIPTOR_SCHEMA, bridgePath, pidPath: pidfile, env: forwarded
|
|
181
|
+
return JSON.stringify({ schema: DESCRIPTOR_SCHEMA, bridgePath, pidPath: pidfile, env: forwarded,
|
|
182
|
+
...(nodePath === undefined ? {} : { nodePath }) });
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
export async function defaultStartupRunner(args) {
|
|
@@ -198,7 +200,8 @@ function healthHost(address) {
|
|
|
198
200
|
return address.includes(':') ? `[${address}]` : address;
|
|
199
201
|
}
|
|
200
202
|
|
|
201
|
-
export async function waitForBridgeStartupReady({ config, instanceToken, env, timeoutMs = START_TIMEOUT_MS
|
|
203
|
+
export async function waitForBridgeStartupReady({ config, instanceToken, env, timeoutMs = START_TIMEOUT_MS,
|
|
204
|
+
failureCode = 'BRIDGE_STARTUP_FOLDER_START_FAILED' }) {
|
|
202
205
|
const deadline = Date.now() + timeoutMs;
|
|
203
206
|
while (Date.now() < deadline) {
|
|
204
207
|
const descriptor = await readBridgeDaemonDescriptor({ env });
|
|
@@ -217,7 +220,7 @@ export async function waitForBridgeStartupReady({ config, instanceToken, env, ti
|
|
|
217
220
|
}
|
|
218
221
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
219
222
|
}
|
|
220
|
-
throw fail(
|
|
223
|
+
throw fail(failureCode, 'bridge startup process did not become healthy');
|
|
221
224
|
}
|
|
222
225
|
|
|
223
226
|
async function defaultWaitStopped({ listen, timeoutMs = STOP_TIMEOUT_MS }) {
|
package/src/cli-help.mjs
CHANGED
|
@@ -28,8 +28,10 @@ Commands:
|
|
|
28
28
|
create --input <file> [--serialization-reviewed]
|
|
29
29
|
# 結果へdispatch_shapeを載せる。--serialization-reviewedは互換のため受理するだけで門ではない
|
|
30
30
|
create --schema --json # 既定は最新版(v4)のJSON Schemaを返す
|
|
31
|
-
create --schema-version <1|2|3|4> --json
|
|
31
|
+
create --schema-version <1|2|3|4|5> --json
|
|
32
32
|
backchain --schema --json # 最終成果から必要な機能を逆算する入力契約
|
|
33
|
+
revise --input <file> [--dry-run] --json # 工程の全体と明示した状態移行から改訂する
|
|
34
|
+
revise --schema --json
|
|
33
35
|
backchain --input <file> [--dry-run] --json
|
|
34
36
|
# 各工程の必要・提供機能を照合し、初回又は既存storeへのplan登録まで行う
|
|
35
37
|
show <plan_key> --json # task・依存・phase・状態をplan本体から1コマンドで投影する
|
|
@@ -231,10 +233,11 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
231
233
|
'setup status': 'setup status [--host <claude|codex|grok|cursor|all>] [--json]',
|
|
232
234
|
status: 'status --json',
|
|
233
235
|
'session-context': 'session-context --json',
|
|
234
|
-
'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4> --json',
|
|
236
|
+
'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4|5> --json',
|
|
235
237
|
'plan show': 'plan show <plan_key> --json',
|
|
236
238
|
'plan scope-review': 'plan scope-review --plan-input <plan-create-or-extraction.json> --review <scope-review.json> --json | --schema --json',
|
|
237
239
|
'plan backchain': 'plan backchain --input <file> [--dry-run] --json | --schema --json',
|
|
240
|
+
'plan revise': 'plan revise --input <file> [--dry-run] --json | --schema --json',
|
|
238
241
|
'plan compile': 'plan compile --request <request.json> | --schema --json',
|
|
239
242
|
'plan verify': 'plan verify --request <request.json> --plan <plan.json>',
|
|
240
243
|
'run start': 'run start --request <request.json> --executor <adapter>'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
|
-
import { lstat, mkdir, open, readdir,
|
|
3
|
+
import { lstat, mkdir, open, readdir, rename, rm } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
const SCHEMA = 'lattice.dashboard_lifecycle.v1';
|
|
@@ -64,6 +64,40 @@ export async function prepareLifecycleDirectory(root) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
const QUARANTINE_KEEP = 8;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* u03 D-lifecycle: an unreadable record is diagnostic history, never a reason to stop the
|
|
71
|
+
* dashboard. Move it aside as `<name>.invalid` (newest QUARANTINE_KEEP kept) and go on.
|
|
72
|
+
* A failed move only leaves the file in place; the next read tries again.
|
|
73
|
+
*/
|
|
74
|
+
async function quarantineLifecycleRecord(ref) {
|
|
75
|
+
try { await rename(ref, `${ref}.invalid`); } catch { return; }
|
|
76
|
+
process.emitWarning(`dashboard lifecycle record was invalid and moved aside: ${ref}.invalid`,
|
|
77
|
+
{ code: 'LATTICE_DASHBOARD_LIFECYCLE_QUARANTINED' });
|
|
78
|
+
const parent = path.dirname(ref);
|
|
79
|
+
const kept = [];
|
|
80
|
+
for (const name of await readdir(parent).catch(() => [])) {
|
|
81
|
+
if (!name.endsWith('.json.invalid')) continue;
|
|
82
|
+
const info = await lstat(path.join(parent, name)).catch(() => null);
|
|
83
|
+
if (info?.isFile()) kept.push({ name, mtime: info.mtimeMs });
|
|
84
|
+
}
|
|
85
|
+
kept.sort((a, b) => b.mtime - a.mtime);
|
|
86
|
+
for (const { name } of kept.slice(QUARANTINE_KEEP)) await rm(path.join(parent, name), { force: true }).catch(() => {});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function readLifecycleRecord(ref, valid) {
|
|
90
|
+
const info = await checkOwned(ref, 'file');
|
|
91
|
+
let value = null;
|
|
92
|
+
if (info.size <= LIFECYCLE_MAX_BYTES) {
|
|
93
|
+
const handle = await open(ref, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
94
|
+
try { value = JSON.parse(await handle.readFile('utf8')); } catch { value = null; } finally { await handle.close(); }
|
|
95
|
+
}
|
|
96
|
+
if (value !== null && valid(value)) return value;
|
|
97
|
+
await quarantineLifecycleRecord(ref);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
67
101
|
export async function readLifecycleRuns(root) {
|
|
68
102
|
try { await checkOwned(directory(root), 'directory'); } catch (error) {
|
|
69
103
|
if (error.code === 'ENOENT') return [];
|
|
@@ -72,19 +106,11 @@ export async function readLifecycleRuns(root) {
|
|
|
72
106
|
const runs = [];
|
|
73
107
|
for (const name of (await readdir(directory(root))).sort()) {
|
|
74
108
|
if (!name.endsWith('.json') || !RUN_ID.test(name.slice(0, -5))) continue;
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
try { value = JSON.parse(await handle.readFile('utf8')); }
|
|
81
|
-
catch { throw lifecycleError('DASHBOARD_LIFECYCLE_INVALID'); }
|
|
82
|
-
finally { await handle.close(); }
|
|
83
|
-
if (value?.schema !== SCHEMA || value.run_id !== name.slice(0, -5)
|
|
84
|
-
|| !['active', 'closed', 'supervisor_lost'].includes(value.state)) {
|
|
85
|
-
throw lifecycleError('DASHBOARD_LIFECYCLE_INVALID');
|
|
86
|
-
}
|
|
87
|
-
runs.push(value);
|
|
109
|
+
const value = await readLifecycleRecord(path.join(directory(root), name), (record) =>
|
|
110
|
+
record?.schema === SCHEMA && record.run_id === name.slice(0, -5)
|
|
111
|
+
&& typeof record.started_at === 'string'
|
|
112
|
+
&& ['active', 'closed', 'supervisor_lost'].includes(record.state));
|
|
113
|
+
if (value !== null) runs.push(value);
|
|
88
114
|
}
|
|
89
115
|
return runs.sort((a, b) => a.started_at.localeCompare(b.started_at));
|
|
90
116
|
}
|
|
@@ -224,12 +250,8 @@ export async function readDashboardLifecycleStatus(root) {
|
|
|
224
250
|
terminationTime(a).localeCompare(terminationTime(b)));
|
|
225
251
|
let ensure = null;
|
|
226
252
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (info.size > LIFECYCLE_MAX_BYTES) throw lifecycleError('DASHBOARD_LIFECYCLE_INVALID');
|
|
230
|
-
try { ensure = JSON.parse(await readFile(ref, 'utf8')); }
|
|
231
|
-
catch { throw lifecycleError('DASHBOARD_LIFECYCLE_INVALID'); }
|
|
232
|
-
if (ensure.schema !== 'lattice.dashboard_ensure.v1') throw lifecycleError('DASHBOARD_LIFECYCLE_INVALID');
|
|
253
|
+
ensure = await readLifecycleRecord(path.join(directory(root), 'ensure.json'),
|
|
254
|
+
(record) => record?.schema === 'lattice.dashboard_ensure.v1');
|
|
233
255
|
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
234
256
|
return { schema: 'lattice.dashboard_lifecycle_status.v1',
|
|
235
257
|
last_ensure: ensure, active: runs.filter((run) => run.state === 'active'),
|
package/src/plan-backchain.mjs
CHANGED
|
@@ -342,11 +342,27 @@ async function verifyExistingFeatureReferences(repoRoot, chain) {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
|
|
345
|
+
const DONE_CONDITION_PLAN_SCHEMA = 'lattice.todo_plan.v8';
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* authoring(create入力またはplan本体)から後継planの種を作る。
|
|
349
|
+
* 作る版: v5入力か先行planがv8ならv8(v8→v7へ戻さない)、それ以外はv7。
|
|
350
|
+
* v8でdone_conditionを書いていないtask(v4入力)は、先行planの同じtaskの値を引き継ぐ
|
|
351
|
+
* (書き換えも消去もしていないので意味を変えない)。新規taskはnull。
|
|
352
|
+
*/
|
|
353
|
+
export function planSeed(authoring, predecessorPlanDigest, predecessorPlan = null) {
|
|
354
|
+
const v8 = authoring.schema === 'lattice.plan_create_input.v5'
|
|
355
|
+
|| authoring.schema === DONE_CONDITION_PLAN_SCHEMA
|
|
356
|
+
|| predecessorPlan?.schema === DONE_CONDITION_PLAN_SCHEMA;
|
|
357
|
+
const inherited = new Map(predecessorPlan?.schema === DONE_CONDITION_PLAN_SCHEMA
|
|
358
|
+
? predecessorPlan.tasks.map(({ task_id: id, done_condition: value }) => [id, value]) : []);
|
|
346
359
|
return {
|
|
347
|
-
schema: 'lattice.todo_plan.v7', project_id: authoring.project_id,
|
|
360
|
+
schema: v8 ? DONE_CONDITION_PLAN_SCHEMA : 'lattice.todo_plan.v7', project_id: authoring.project_id,
|
|
348
361
|
plan_key: authoring.plan_key, predecessor_plan_digest: predecessorPlanDigest,
|
|
349
|
-
tasks: authoring.tasks
|
|
362
|
+
tasks: v8 ? authoring.tasks.map((task) => ({ ...task,
|
|
363
|
+
done_condition: Object.hasOwn(task, 'done_condition')
|
|
364
|
+
? task.done_condition : inherited.get(task.task_id) ?? null })) : authoring.tasks,
|
|
365
|
+
phases: authoring.phases,
|
|
350
366
|
hard_dependencies: authoring.hard_dependencies, joins: authoring.joins,
|
|
351
367
|
phase_accept_dependencies: authoring.phase_accept_dependencies,
|
|
352
368
|
};
|
|
@@ -408,7 +424,7 @@ function compileTaskMigration(previousPlan, oldChain, desiredSeed, newChain) {
|
|
|
408
424
|
}).sort((left, right) => left.from_task_id.localeCompare(right.from_task_id));
|
|
409
425
|
}
|
|
410
426
|
|
|
411
|
-
function compilePhaseMigration(previousPlan, desiredSeed, taskMigration) {
|
|
427
|
+
export function compilePhaseMigration(previousPlan, desiredSeed, taskMigration) {
|
|
412
428
|
const nextPhases = new Map(desiredSeed.phases.map((phase) => [phase.phase_id, phase]));
|
|
413
429
|
const oldPhases = new Set(previousPlan.phases.map(({ phase_id: id }) => id));
|
|
414
430
|
const affected = new Set(taskMigration.filter(({ state_policy }) =>
|
|
@@ -434,7 +450,7 @@ function compilePhaseMigration(previousPlan, desiredSeed, taskMigration) {
|
|
|
434
450
|
}
|
|
435
451
|
|
|
436
452
|
async function compileBackchainRevision({ repoRoot, member, chain, authoring }) {
|
|
437
|
-
if (
|
|
453
|
+
if (!['lattice.todo_plan.v7', DONE_CONDITION_PLAN_SCHEMA].includes(member.plan.schema)) {
|
|
438
454
|
fail('predecessor_plan_schema_unsupported', '/plan_key', {
|
|
439
455
|
actual: member.plan.schema, next_action: 'author_a_new_backchain_plan',
|
|
440
456
|
});
|
|
@@ -447,7 +463,7 @@ async function compileBackchainRevision({ repoRoot, member, chain, authoring })
|
|
|
447
463
|
journal_head_digest: member.journal.events.at(-1).event_digest,
|
|
448
464
|
plan_version: member.plan.plan_version,
|
|
449
465
|
};
|
|
450
|
-
const seed = planSeed(amended, predecessor.plan_digest);
|
|
466
|
+
const seed = planSeed(amended, predecessor.plan_digest, member.plan);
|
|
451
467
|
const taskMigration = compileTaskMigration(member.plan, previousChain, seed, chain);
|
|
452
468
|
const phaseMigration = compilePhaseMigration(member.plan, seed, taskMigration);
|
|
453
469
|
const version = phaseTodoRevisionPlanVersion({
|
|
@@ -477,12 +493,13 @@ async function compileBackchainRevision({ repoRoot, member, chain, authoring })
|
|
|
477
493
|
}
|
|
478
494
|
|
|
479
495
|
async function activeIntentUnchanged({ repoRoot, member, chain, authoring }) {
|
|
480
|
-
if (
|
|
496
|
+
if (!['lattice.todo_plan.v7', DONE_CONDITION_PLAN_SCHEMA].includes(member.plan.schema)) return false;
|
|
481
497
|
const binding = await readPlanBackchainBinding({ repoRoot, plan: member.plan });
|
|
482
498
|
if (binding === null || featureGraphDigest(binding.chain) !== featureGraphDigest(chain)) return false;
|
|
483
499
|
const amended = attachBackchainMemos(chain, authoring, { previousChain: binding.chain });
|
|
484
|
-
|
|
485
|
-
|
|
500
|
+
const seed = planSeed(amended, null, member.plan);
|
|
501
|
+
return seed.schema === member.plan.schema && canonicalizeTodoArtifact({
|
|
502
|
+
tasks: seed.tasks, phases: amended.phases,
|
|
486
503
|
hard_dependencies: amended.hard_dependencies, joins: amended.joins,
|
|
487
504
|
phase_accept_dependencies: amended.phase_accept_dependencies,
|
|
488
505
|
}) === canonicalizeTodoArtifact({
|
|
@@ -492,7 +509,9 @@ async function activeIntentUnchanged({ repoRoot, member, chain, authoring }) {
|
|
|
492
509
|
});
|
|
493
510
|
}
|
|
494
511
|
|
|
495
|
-
async function rebindCarriedWork({ repoRoot, planKey, env
|
|
512
|
+
export async function rebindCarriedWork({ repoRoot, planKey, env,
|
|
513
|
+
reason = 'ゴール変更後のplan versionへ作業中ToDoを結び直す',
|
|
514
|
+
failureCode = 'BACKCHAIN_REBIND_PENDING' }) {
|
|
496
515
|
const store = await readTodoStore({ repoRoot });
|
|
497
516
|
const member = store.members.find(({ plan }) => plan.plan_key === planKey);
|
|
498
517
|
const rebound = [];
|
|
@@ -503,9 +522,9 @@ async function rebindCarriedWork({ repoRoot, planKey, env }) {
|
|
|
503
522
|
const { rebindStart } = await import('./todo-cli.mjs');
|
|
504
523
|
try {
|
|
505
524
|
await rebindStart({ repoRoot, env, planKey, taskId: state.task_id,
|
|
506
|
-
reason
|
|
525
|
+
reason });
|
|
507
526
|
} catch (error) {
|
|
508
|
-
throw new TodoStoreError(
|
|
527
|
+
throw new TodoStoreError(failureCode, 'carried_task_rebind_failed', undefined, {
|
|
509
528
|
task_id: state.task_id, plan_version: member.plan.plan_version,
|
|
510
529
|
cause_code: error?.code ?? 'unknown',
|
|
511
530
|
next_action: `lattice todo start --plan ${planKey} --task ${state.task_id} --rebind --reason <text>`,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Plan-owned continuity semantics for incoming cross-plan connections whose source
|
|
2
|
+
// plan was revised (Snow White coordination decision 2026-11-07, w1b first use).
|
|
3
|
+
// Pure: no I/O, no Store mutation. Store's rebindTodoCrossPlanDependencies calls it
|
|
4
|
+
// under lock with the active source member, the live dependencies to carry and the
|
|
5
|
+
// retained predecessor plan's identity, and only rebinds when it answers ok.
|
|
6
|
+
const CARRIED_POLICIES = new Set(['carry', 'carry_reconciled_metadata']);
|
|
7
|
+
|
|
8
|
+
export function validateBindingCarry({ store, source, dependencies, predecessor }) {
|
|
9
|
+
// Refusal shape is Store's typed refusal: code = error class, detail.reason = rule.
|
|
10
|
+
const refuse = (code, reason, detail = {}) => ({ ok: false, code, detail: { reason, ...detail } });
|
|
11
|
+
const { plan, revision } = source;
|
|
12
|
+
// shortcut: only the immediate predecessor hop is carried; a connection two or more
|
|
13
|
+
// revisions behind needs a chained check, add it when such a store actually exists.
|
|
14
|
+
if (revision?.predecessor?.plan_version !== predecessor.plan_version
|
|
15
|
+
|| revision?.predecessor?.plan_digest !== predecessor.plan_digest) {
|
|
16
|
+
return refuse('DEPENDENCY_STALE', 'binding_carry_hop_unlinked', { predecessor,
|
|
17
|
+
revision_predecessor: revision?.predecessor ?? null });
|
|
18
|
+
}
|
|
19
|
+
if (revision.desired_plan?.topology_digest !== plan.topology_digest) {
|
|
20
|
+
return refuse('DEPENDENCY_STALE', 'binding_carry_successor_mismatch', { plan_version: plan.plan_version });
|
|
21
|
+
}
|
|
22
|
+
const migration = new Map(revision.task_migration.map((row) => [row.from_task_id, row]));
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const rebound = [];
|
|
25
|
+
for (const dependency of dependencies) {
|
|
26
|
+
const { from, to } = dependency;
|
|
27
|
+
const edge = { from_task_id: from.task_id, to: { plan_key: to.plan_key, task_id: to.task_id } };
|
|
28
|
+
if (from.project_id !== plan.project_id || from.plan_key !== plan.plan_key) {
|
|
29
|
+
return refuse('DEPENDENCY_INVALID', 'binding_carry_source_mismatch', edge);
|
|
30
|
+
}
|
|
31
|
+
if (from.expected_topology_digest !== predecessor.topology_digest) {
|
|
32
|
+
return refuse('DEPENDENCY_STALE', 'binding_carry_predecessor_mismatch', { ...edge,
|
|
33
|
+
expected_topology_digest: from.expected_topology_digest });
|
|
34
|
+
}
|
|
35
|
+
const row = migration.get(from.task_id) ?? null;
|
|
36
|
+
if (row === null || row.to_task_id !== from.task_id || !CARRIED_POLICIES.has(row.state_policy)) {
|
|
37
|
+
return refuse('DEPENDENCY_INVALID', 'binding_carry_task_not_carried', { ...edge, migration: row });
|
|
38
|
+
}
|
|
39
|
+
if (!plan.tasks.some(({ task_id: taskId }) => taskId === from.task_id)) {
|
|
40
|
+
return refuse('DEPENDENCY_INVALID', 'binding_carry_task_missing', edge);
|
|
41
|
+
}
|
|
42
|
+
const owner = store.members.find((member) => member.plan.project_id === to.project_id
|
|
43
|
+
&& member.plan.plan_key === to.plan_key) ?? null;
|
|
44
|
+
if (owner === null || !owner.plan.tasks.some(({ task_id: taskId }) => taskId === to.task_id)) {
|
|
45
|
+
return refuse('DEPENDENCY_INVALID', 'binding_carry_target_missing', edge);
|
|
46
|
+
}
|
|
47
|
+
if (to.expected_topology_digest !== owner.plan.topology_digest) {
|
|
48
|
+
return refuse('DEPENDENCY_STALE', 'binding_carry_target_changed', { ...edge,
|
|
49
|
+
expected_topology_digest: to.expected_topology_digest,
|
|
50
|
+
actual_topology_digest: owner.plan.topology_digest });
|
|
51
|
+
}
|
|
52
|
+
const key = `${from.task_id}\0${to.project_id}\0${to.plan_key}\0${to.task_id}`;
|
|
53
|
+
if (seen.has(key)) return refuse('DEPENDENCY_INVALID', 'binding_carry_duplicate', edge);
|
|
54
|
+
seen.add(key);
|
|
55
|
+
rebound.push({ event_digest: dependency.event_digest ?? null, ...edge,
|
|
56
|
+
predecessor_topology_digest: from.expected_topology_digest, successor_topology_digest: plan.topology_digest });
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, detail: { plan_version: plan.plan_version,
|
|
59
|
+
successor_topology_digest: plan.topology_digest, rebound } };
|
|
60
|
+
}
|