@quolu/lattice 0.80.0 → 0.82.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 +8 -3
- package/bin/lattice.mjs +28 -0
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +32 -0
- package/package.json +3 -2
- package/src/bridge-cli.mjs +16 -4
- package/src/bridge-config.mjs +6 -7
- package/src/bridge-detached-supervisor.mjs +204 -0
- package/src/bridge-startup-folder.mjs +7 -4
- package/src/cli-help.mjs +3 -0
- package/src/plan-backchain.mjs +11 -8
- package/src/plan-binding-carry.mjs +60 -0
- package/src/plan-revise.mjs +175 -0
- package/src/project-cli.mjs +28 -12
- package/src/runtime-multi-epoch-store.mjs +53 -13
- package/src/runtime-os-observation.mjs +39 -1
- package/src/seat-identity.mjs +23 -0
- package/src/store-lock.mjs +4 -2
- package/src/todo-authoring-input.mjs +1 -0
- package/src/todo-cli.mjs +5 -3
- package/src/todo-note-store.mjs +7 -2
- package/src/todo-revision.mjs +7 -5
- package/src/todo-store-view.mjs +58 -0
- package/src/todo-store.mjs +107 -68
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Windows bridge supervisor (bh6 prep). Startup-folder items only run once at
|
|
3
|
+
* Windows/Linux bridge supervisor (bh6 prep). Startup-folder items only run once at
|
|
4
4
|
* logon — nothing like launchd's KeepAlive exists to restart a crashed
|
|
5
5
|
* process. This script is that supervision, written in JS instead of a batch
|
|
6
6
|
* GOTO loop because a loop's own process (and therefore its killability) is
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* The descriptor supplies the environment `lattice-bridge.mjs` needs (it is
|
|
11
11
|
* never inherited from the Startup-folder launch context) and the path to
|
|
12
12
|
* write this supervisor's own pid to, so `bridge-startup-folder.mjs` can find
|
|
13
|
-
* and stop the whole tree later via `taskkill /T /F`.
|
|
13
|
+
* and stop the whole tree later via `taskkill /T /F`. Linux records process
|
|
14
|
+
* birth alongside the PID so its detached adapter can reject PID reuse.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import { spawn } from 'node:child_process';
|
|
@@ -18,6 +19,8 @@ import { writeFile } from 'node:fs/promises';
|
|
|
18
19
|
import { readFileSync } from 'node:fs';
|
|
19
20
|
import path from 'node:path';
|
|
20
21
|
|
|
22
|
+
import { observeDashboardProcess } from '../src/dashboard-process-control.mjs';
|
|
23
|
+
|
|
21
24
|
const RESTART_DELAY_MS = 3_000;
|
|
22
25
|
|
|
23
26
|
const descriptorPath = process.argv[2];
|
|
@@ -33,7 +36,9 @@ if (descriptor?.schema !== 'lattice.bridge_supervisor_descriptor.v1'
|
|
|
33
36
|
process.exit(2);
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
const identity = process.platform === 'win32' ? String(process.pid)
|
|
40
|
+
: JSON.stringify(await observeDashboardProcess(process.pid) ?? { pid: process.pid, birth: null });
|
|
41
|
+
await writeFile(descriptor.pidPath, identity, { encoding: 'utf8', flag: 'w', mode: 0o600 });
|
|
37
42
|
|
|
38
43
|
let stopping = false;
|
|
39
44
|
let child = null;
|
package/bin/lattice.mjs
CHANGED
|
@@ -112,6 +112,34 @@ if (help !== null) {
|
|
|
112
112
|
} catch (error) {
|
|
113
113
|
process.exitCode = projectCliFailure(process.stderr, error);
|
|
114
114
|
}
|
|
115
|
+
} else if (args.length === 4 && args[0] === 'plan' && args[1] === 'revise'
|
|
116
|
+
&& args[2] === '--schema' && args[3] === '--json') {
|
|
117
|
+
const { planReviseSchema } = await import('../src/plan-revise.mjs');
|
|
118
|
+
const { projectCliFailure } = await import('../src/project-cli.mjs');
|
|
119
|
+
try {
|
|
120
|
+
process.stdout.write(`${JSON.stringify(await planReviseSchema())}\n`);
|
|
121
|
+
process.exitCode = 0;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
process.exitCode = projectCliFailure(process.stderr, error);
|
|
124
|
+
}
|
|
125
|
+
} else if (args[0] === 'plan' && args[1] === 'revise') {
|
|
126
|
+
const { matchFlagCommand } = await import('../src/todo-authoring-input.mjs');
|
|
127
|
+
const flags = matchFlagCommand(args, ['plan', 'revise'], {
|
|
128
|
+
known: ['input', 'dry-run', 'json'], required: ['input'], booleans: ['dry-run', 'json'],
|
|
129
|
+
});
|
|
130
|
+
if (flags === null || flags.json !== true) {
|
|
131
|
+
process.stderr.write(`lattice: unsupported command or arguments: ${args.join(' ')}\n`);
|
|
132
|
+
process.exitCode = 2;
|
|
133
|
+
} else {
|
|
134
|
+
const { runPlanRevise } = await import('../src/plan-revise.mjs');
|
|
135
|
+
const { projectCliFailure } = await import('../src/project-cli.mjs');
|
|
136
|
+
try {
|
|
137
|
+
process.exitCode = await runPlanRevise({ cwd: process.cwd(), inputRef: flags.input,
|
|
138
|
+
dryRun: flags['dry-run'] === true, stdout: process.stdout, env: process.env });
|
|
139
|
+
} catch (error) {
|
|
140
|
+
process.exitCode = projectCliFailure(process.stderr, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
115
143
|
} else if (args.length === 4 && args[0] === 'plan' && args[1] === 'backchain'
|
|
116
144
|
&& args[2] === '--schema' && args[3] === '--json') {
|
|
117
145
|
const { backchainSchema } = await import('../src/plan-backchain.mjs');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/kitepon/Lattice/blob/main/docs/schemas/lattice.plan_revise_input.v1.schema.json",
|
|
4
|
+
"title": "lattice.plan_revise_input.v1",
|
|
5
|
+
"description": "工程全体のdesired stateと、全ての旧taskの明示的な状態移行。predecessor/CAS/digest/後継versionは機械が算出する。旧版は保持し、作業の意味が同じかを暗黙に推定しない。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["schema", "desired", "continuity"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"schema": { "const": "lattice.plan_revise_input.v1" },
|
|
11
|
+
"desired": {
|
|
12
|
+
"$ref": "lattice.plan_create_input.v4.schema.json",
|
|
13
|
+
"description": "同じproject_idとplan_keyのcreate-v4入力。input_digestは通常のauthoring正規化で補う。plan_versionは入力形を保つために記載し、後継versionは機械算出値に置き換える。新taskはpending。消すtaskへの参照も明示的に取り除く。"
|
|
14
|
+
},
|
|
15
|
+
"continuity": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"minItems": 1,
|
|
18
|
+
"maxItems": 512,
|
|
19
|
+
"description": "旧task全件をtask_idごとに一度ずつ選ぶ。新taskへのentryは書かない。配列の順序は問わない。carryは既存Storeの意味・依存整合チェックを保ち、resetはpendingへ戻し、retireはdesiredに存在しないtaskだけに使う。各判断の理由をreasonに記録する。",
|
|
20
|
+
"items": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"required": ["task_id", "policy", "reason"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"task_id": { "type": "string", "pattern": "^[0-9A-Za-z](?:[0-9A-Za-z._-]{0,127})$" },
|
|
26
|
+
"policy": { "enum": ["carry", "reset", "retire"] },
|
|
27
|
+
"reason": { "type": "string", "minLength": 1, "pattern": "\\S" }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"description": "Schedulability compiler for multi-agent development: observe real code boundaries, refactor the conflicting seam, recompile the plan for parallel execution",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Quo / クオ at kitepon.dev",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"docs/schemas/lattice.plan_create_input.v2.schema.json",
|
|
30
30
|
"docs/schemas/lattice.plan_create_input.v3.schema.json",
|
|
31
31
|
"docs/schemas/lattice.plan_create_input.v4.schema.json",
|
|
32
|
+
"docs/schemas/lattice.plan_revise_input.v1.schema.json",
|
|
32
33
|
"docs/schemas/lattice.plan_scope_review.v1.schema.json",
|
|
33
34
|
"docs/schemas/lattice.plan_backchain.v1.schema.json",
|
|
34
35
|
"docs/schemas/lattice.todo_revision.v2.schema.json",
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
"test:profile": "npm --prefix sensor ci && npm --prefix sensor run build && node scripts/run-product-tests.mjs",
|
|
85
86
|
"test:sensor": "npm --prefix sensor test",
|
|
86
87
|
"check": "node scripts/check-syntax.mjs",
|
|
87
|
-
"ci": "
|
|
88
|
+
"ci": "node scripts/run-ci.mjs",
|
|
88
89
|
"verify:todo-store": "node bin/lattice.mjs todo verify --json",
|
|
89
90
|
"check:cli-surface": "node scripts/verify-cli-surface.mjs",
|
|
90
91
|
"check:open-questions": "node scripts/verify-open-questions.mjs",
|
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,
|
package/src/bridge-config.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
2
|
import { randomBytes, randomInt } from 'node:crypto';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
3
|
import { isIP } from 'node:net';
|
|
5
4
|
import {
|
|
6
5
|
chmod, lstat, mkdir, open, readFile, rename, rm, writeFile,
|
|
@@ -9,6 +8,8 @@ import path from 'node:path';
|
|
|
9
8
|
import { domainToASCII } from 'node:url';
|
|
10
9
|
import { parseTree } from 'jsonc-parser';
|
|
11
10
|
|
|
11
|
+
import { resolveSeatIdentity } from './seat-identity.mjs';
|
|
12
|
+
|
|
12
13
|
export const BRIDGE_CONFIG_SCHEMA = 'lattice.bridge_config.v1';
|
|
13
14
|
export const BRIDGE_PORT_MIN = 49_152;
|
|
14
15
|
export const BRIDGE_PORT_MAX = 65_535;
|
|
@@ -36,13 +37,11 @@ function exact(value, keys) {
|
|
|
36
37
|
|
|
37
38
|
function configRoot(env) {
|
|
38
39
|
const configured = env.LATTICE_CONFIG_DIR;
|
|
39
|
-
if (configured !== undefined) {
|
|
40
|
-
|
|
41
|
-
throw new BridgeConfigError('BRIDGE_CONFIG_DIR_INVALID', 'LATTICE_CONFIG_DIR must be absolute');
|
|
42
|
-
}
|
|
43
|
-
return configured;
|
|
40
|
+
if (configured !== undefined && (typeof configured !== 'string' || !path.isAbsolute(configured))) {
|
|
41
|
+
throw new BridgeConfigError('BRIDGE_CONFIG_DIR_INVALID', 'LATTICE_CONFIG_DIR must be absolute');
|
|
44
42
|
}
|
|
45
|
-
|
|
43
|
+
// 席ごとの置き場は seat-identity が導く(LATTICE_CONFIG_DIR > LATTICE_SEAT_ID > ~/.lattice)。
|
|
44
|
+
return resolveSeatIdentity(env).state_dir;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
export function bridgeConfigPaths(env = process.env) {
|
|
@@ -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
|
+
}
|
|
@@ -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
|
@@ -30,6 +30,8 @@ Commands:
|
|
|
30
30
|
create --schema --json # 既定は最新版(v4)のJSON Schemaを返す
|
|
31
31
|
create --schema-version <1|2|3|4> --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コマンドで投影する
|
|
@@ -235,6 +237,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
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>'
|
package/src/plan-backchain.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
digestTodoArtifact, todoSelfDigest,
|
|
8
8
|
} from './todo-contracts.mjs';
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
appendAuthoredTodoPlan, applyPhaseTodoRevision, buildTodoPlan, createTodoStoreWriter,
|
|
11
11
|
readTodoStore, TodoStoreError,
|
|
12
12
|
} from './todo-store.mjs';
|
|
13
13
|
import { gitSync } from './git-process.mjs';
|
|
@@ -342,7 +342,7 @@ async function verifyExistingFeatureReferences(repoRoot, chain) {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
function planSeed(authoring, predecessorPlanDigest) {
|
|
345
|
+
export function planSeed(authoring, predecessorPlanDigest) {
|
|
346
346
|
return {
|
|
347
347
|
schema: 'lattice.todo_plan.v7', project_id: authoring.project_id,
|
|
348
348
|
plan_key: authoring.plan_key, predecessor_plan_digest: predecessorPlanDigest,
|
|
@@ -408,7 +408,7 @@ function compileTaskMigration(previousPlan, oldChain, desiredSeed, newChain) {
|
|
|
408
408
|
}).sort((left, right) => left.from_task_id.localeCompare(right.from_task_id));
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
function compilePhaseMigration(previousPlan, desiredSeed, taskMigration) {
|
|
411
|
+
export function compilePhaseMigration(previousPlan, desiredSeed, taskMigration) {
|
|
412
412
|
const nextPhases = new Map(desiredSeed.phases.map((phase) => [phase.phase_id, phase]));
|
|
413
413
|
const oldPhases = new Set(previousPlan.phases.map(({ phase_id: id }) => id));
|
|
414
414
|
const affected = new Set(taskMigration.filter(({ state_policy }) =>
|
|
@@ -492,7 +492,9 @@ async function activeIntentUnchanged({ repoRoot, member, chain, authoring }) {
|
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
async function rebindCarriedWork({ repoRoot, planKey, env
|
|
495
|
+
export async function rebindCarriedWork({ repoRoot, planKey, env,
|
|
496
|
+
reason = 'ゴール変更後のplan versionへ作業中ToDoを結び直す',
|
|
497
|
+
failureCode = 'BACKCHAIN_REBIND_PENDING' }) {
|
|
496
498
|
const store = await readTodoStore({ repoRoot });
|
|
497
499
|
const member = store.members.find(({ plan }) => plan.plan_key === planKey);
|
|
498
500
|
const rebound = [];
|
|
@@ -503,9 +505,9 @@ async function rebindCarriedWork({ repoRoot, planKey, env }) {
|
|
|
503
505
|
const { rebindStart } = await import('./todo-cli.mjs');
|
|
504
506
|
try {
|
|
505
507
|
await rebindStart({ repoRoot, env, planKey, taskId: state.task_id,
|
|
506
|
-
reason
|
|
508
|
+
reason });
|
|
507
509
|
} catch (error) {
|
|
508
|
-
throw new TodoStoreError(
|
|
510
|
+
throw new TodoStoreError(failureCode, 'carried_task_rebind_failed', undefined, {
|
|
509
511
|
task_id: state.task_id, plan_version: member.plan.plan_version,
|
|
510
512
|
cause_code: error?.code ?? 'unknown',
|
|
511
513
|
next_action: `lattice todo start --plan ${planKey} --task ${state.task_id} --rebind --reason <text>`,
|
|
@@ -590,11 +592,12 @@ export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false,
|
|
|
590
592
|
const plan = buildTodoPlan({
|
|
591
593
|
...planSeed(amended, null), plan_version: chain.plan_version,
|
|
592
594
|
});
|
|
593
|
-
const
|
|
594
|
-
repoRoot, writer: createTodoStoreWriter({ caller: '
|
|
595
|
+
const addedStore = await appendAuthoredTodoPlan({
|
|
596
|
+
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
595
597
|
plan, genesis: { actor: authoring.actor, recorded_at: authoring.recorded_at,
|
|
596
598
|
provenance: null }, featureChain: chain,
|
|
597
599
|
});
|
|
600
|
+
const added = addedStore.members.find(({ plan: candidate }) => candidate.plan_key === plan.plan_key);
|
|
598
601
|
created = {
|
|
599
602
|
schema: 'lattice.plan_backchain_add_result.v1',
|
|
600
603
|
plan_key: added.plan.plan_key, plan_version: added.plan.plan_version,
|
|
@@ -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
|
+
}
|