@quolu/lattice 0.79.5 → 0.81.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/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/src/bridge-config.mjs +6 -7
- package/src/fs-publish.mjs +9 -0
- package/src/mcp-startup-receipt.mjs +3 -3
- package/src/plan-backchain.mjs +4 -3
- package/src/project-cli.mjs +22 -10
- package/src/runtime-multi-epoch-store.mjs +53 -13
- package/src/runtime-os-observation.mjs +18 -1
- package/src/seat-identity.mjs +23 -0
- 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-revision.mjs +7 -5
- package/src/todo-status.mjs +4 -33
- package/src/todo-store-git-transaction.mjs +11 -6
- package/src/todo-store-view.mjs +105 -0
- package/src/todo-store.mjs +602 -455
- 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
|
@@ -62,21 +62,24 @@
|
|
|
62
62
|
"maxItems": 2048,
|
|
63
63
|
"items": {
|
|
64
64
|
"$ref": "#/$defs/edge"
|
|
65
|
-
}
|
|
65
|
+
},
|
|
66
|
+
"description": "from、toの順に、各参照を(project_id, plan_key, task_id)の組として辞書順に並べる。同じfrom/toの組は重複できない。expected_topology_digestは並び順に含めない。"
|
|
66
67
|
},
|
|
67
68
|
"joins": {
|
|
68
69
|
"type": "array",
|
|
69
70
|
"maxItems": 128,
|
|
70
71
|
"items": {
|
|
71
72
|
"$ref": "#/$defs/join"
|
|
72
|
-
}
|
|
73
|
+
},
|
|
74
|
+
"description": "joinをidの昇順・重複なしで並べる。各joinのafterは(project_id, plan_key, task_id)の組の辞書順・重複なしで並べ、expected_topology_digestは並び順に含めない。"
|
|
73
75
|
},
|
|
74
76
|
"phase_accept_dependencies": {
|
|
75
77
|
"type": "array",
|
|
76
78
|
"maxItems": 2048,
|
|
77
79
|
"items": {
|
|
78
80
|
"$ref": "#/$defs/phaseAcceptDependency"
|
|
79
|
-
}
|
|
81
|
+
},
|
|
82
|
+
"description": "from phase参照を(project_id, plan_key, phase_id)、to task参照を(project_id, plan_key, task_id)の組として、from、toの順に辞書順で並べる。同じfrom/toの組は重複できない。expected_topology_digestは並び順に含めない。"
|
|
80
83
|
},
|
|
81
84
|
"input_digest": {
|
|
82
85
|
"$ref": "#/$defs/authoringDigest"
|
|
@@ -341,7 +344,8 @@
|
|
|
341
344
|
"maxItems": 512,
|
|
342
345
|
"items": {
|
|
343
346
|
"$ref": "#/$defs/nodeRef"
|
|
344
|
-
}
|
|
347
|
+
},
|
|
348
|
+
"description": "参照を(project_id, plan_key, task_id)の組の辞書順・重複なしで並べる。expected_topology_digestは並び順に含めない。"
|
|
345
349
|
},
|
|
346
350
|
"before": {
|
|
347
351
|
"$ref": "#/$defs/nodeRef"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"plan_version": { "$ref": "#/$defs/identifier" },
|
|
18
18
|
"actor": { "$ref": "#/$defs/actor" },
|
|
19
19
|
"recorded_at": { "$ref": "#/$defs/strictTimestamp" },
|
|
20
|
-
"tasks": { "type": "array", "minItems": 1, "maxItems": 512, "items": { "$ref": "#/$defs/task" } },
|
|
20
|
+
"tasks": { "type": "array", "minItems": 1, "maxItems": 512, "items": { "$ref": "#/$defs/task" }, "description": "Sort by task_id ascending; task_id values must be unique." },
|
|
21
21
|
"hard_dependencies": {
|
|
22
22
|
"type": "array", "maxItems": 2048,
|
|
23
23
|
"items": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"to": { "$ref": "#/$defs/nodeRef" },
|
|
28
28
|
"reason": { "$ref": "#/$defs/text" }
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"description": "Sort by from then to ascending, comparing each reference as the tuple (project_id, plan_key, task_id). Duplicate from/to pairs are not allowed. expected_topology_digest is excluded from the sort key."
|
|
31
32
|
},
|
|
32
33
|
"joins": {
|
|
33
34
|
"type": "array", "maxItems": 128,
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
"after": { "type": "array", "minItems": 1, "maxItems": 512, "items": { "$ref": "#/$defs/nodeRef" } },
|
|
39
40
|
"before": { "$ref": "#/$defs/nodeRef" }
|
|
40
41
|
}
|
|
41
|
-
}
|
|
42
|
+
},
|
|
43
|
+
"description": "Sort joins by id ascending with no duplicate ids. In each join, sort after references by the tuple (project_id, plan_key, task_id) ascending with no duplicates; expected_topology_digest is excluded from the sort key."
|
|
42
44
|
},
|
|
43
45
|
"extraction_digest": { "$ref": "#/$defs/digest" }
|
|
44
46
|
},
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"plan_version": { "$ref": "#/$defs/identifier" },
|
|
18
18
|
"actor": { "$ref": "#/$defs/actor" },
|
|
19
19
|
"recorded_at": { "$ref": "#/$defs/strictTimestamp" },
|
|
20
|
-
"tasks": { "type": "array", "minItems": 0, "maxItems": 512, "items": { "$ref": "#/$defs/task" } },
|
|
20
|
+
"tasks": { "type": "array", "minItems": 0, "maxItems": 512, "items": { "$ref": "#/$defs/task" }, "description": "Sort by task_id ascending; task_id values must be unique." },
|
|
21
21
|
"hard_dependencies": {
|
|
22
22
|
"type": "array", "maxItems": 2048,
|
|
23
23
|
"items": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"to": { "$ref": "#/$defs/nodeRef" },
|
|
28
28
|
"reason": { "$ref": "#/$defs/text" }
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"description": "Sort by from then to ascending, comparing each reference as the tuple (project_id, plan_key, task_id). Duplicate from/to pairs are not allowed. expected_topology_digest is excluded from the sort key."
|
|
31
32
|
},
|
|
32
33
|
"joins": {
|
|
33
34
|
"type": "array", "maxItems": 128,
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
"after": { "type": "array", "minItems": 1, "maxItems": 512, "items": { "$ref": "#/$defs/nodeRef" } },
|
|
39
40
|
"before": { "$ref": "#/$defs/nodeRef" }
|
|
40
41
|
}
|
|
41
|
-
}
|
|
42
|
+
},
|
|
43
|
+
"description": "Sort joins by id ascending with no duplicate ids. In each join, sort after references by the tuple (project_id, plan_key, task_id) ascending with no duplicates; expected_topology_digest is excluded from the sort key."
|
|
42
44
|
},
|
|
43
45
|
"extraction_digest": { "$ref": "#/$defs/digest" }
|
|
44
46
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.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",
|
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) {
|
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, {
|
|
@@ -2,8 +2,8 @@ import { Worker, isMainThread, parentPort, workerData } from 'node:worker_thread
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { lstatSync, mkdirSync, openSync, writeFileSync, closeSync,
|
|
6
|
-
import { ensureSafeDir, ensureSafeFile } from './runtime-errors.mjs';
|
|
5
|
+
import { lstatSync, mkdirSync, openSync, writeFileSync, closeSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { ensureSafeDir, ensureSafeFile, replaceStoreFile } from './runtime-errors.mjs';
|
|
7
7
|
import { observeDashboardProcess } from './dashboard-process-control.mjs';
|
|
8
8
|
import { isAclScratchName } from './windows-owner-only.mjs';
|
|
9
9
|
|
|
@@ -91,7 +91,7 @@ if (!isMainThread && workerData?.receipt === true) {
|
|
|
91
91
|
const fd = openSync(temporary, 'wx', 0o600);
|
|
92
92
|
try { writeFileSync(fd, bytes); } finally { closeSync(fd); }
|
|
93
93
|
ensureSafeFile(temporary, slot);
|
|
94
|
-
|
|
94
|
+
replaceStoreFile(temporary, target);
|
|
95
95
|
}
|
|
96
96
|
parentPort.on('message', message => {
|
|
97
97
|
queue = queue.then(() => receive(message)).catch(() => { disabled = true; parentPort.close(); });
|
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';
|
|
@@ -590,11 +590,12 @@ export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false,
|
|
|
590
590
|
const plan = buildTodoPlan({
|
|
591
591
|
...planSeed(amended, null), plan_version: chain.plan_version,
|
|
592
592
|
});
|
|
593
|
-
const
|
|
594
|
-
repoRoot, writer: createTodoStoreWriter({ caller: '
|
|
593
|
+
const addedStore = await appendAuthoredTodoPlan({
|
|
594
|
+
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
595
595
|
plan, genesis: { actor: authoring.actor, recorded_at: authoring.recorded_at,
|
|
596
596
|
provenance: null }, featureChain: chain,
|
|
597
597
|
});
|
|
598
|
+
const added = addedStore.members.find(({ plan: candidate }) => candidate.plan_key === plan.plan_key);
|
|
598
599
|
created = {
|
|
599
600
|
schema: 'lattice.plan_backchain_add_result.v1',
|
|
600
601
|
plan_key: added.plan.plan_key, plan_version: added.plan.plan_version,
|
package/src/project-cli.mjs
CHANGED
|
@@ -27,9 +27,11 @@ import { ensureTodoDashboardActivity } from './todo-dashboard-registry.mjs';
|
|
|
27
27
|
import { reportProjectDashboardDelivery } from './dashboard-delivery.mjs';
|
|
28
28
|
import { resolveProjectIdentity } from './project-identity.mjs';
|
|
29
29
|
import {
|
|
30
|
+
appendAuthoredTodoPlan,
|
|
30
31
|
buildTodoPlan,
|
|
31
32
|
createTodoStoreWriter,
|
|
32
33
|
initializeAuthoredTodoStore,
|
|
34
|
+
isUninitializedTodoStore,
|
|
33
35
|
isPhaselessTodoPlanSchema,
|
|
34
36
|
readTodoIndependenceArtifact,
|
|
35
37
|
readTodoStore,
|
|
@@ -121,7 +123,7 @@ export function validateProjectStatus(value) {
|
|
|
121
123
|
&& typeof value.next_action.reason === 'string' && value.next_action.reason.length > 0;
|
|
122
124
|
}
|
|
123
125
|
return value.project !== null && isTodoIdentifier(value.project.project_id)
|
|
124
|
-
&& value.can_create_plan ===
|
|
126
|
+
&& value.can_create_plan === true && exactRecord(value.next_action, ['command', 'reason'])
|
|
125
127
|
&& typeof value.next_action.reason === 'string' && value.next_action.reason.length > 0
|
|
126
128
|
&& (value.state !== 'active_run' || value.active_runs.length > 0)
|
|
127
129
|
&& (value.state !== 'ready' || value.active_runs.length === 0);
|
|
@@ -252,7 +254,10 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
|
|
|
252
254
|
try { manifestState = await lstat(manifestAbsolute); } catch (error) {
|
|
253
255
|
if (error?.code !== 'ENOENT') return invalid('manifest_unreadable');
|
|
254
256
|
}
|
|
255
|
-
|
|
257
|
+
let uninitialized;
|
|
258
|
+
try { uninitialized = await isUninitializedTodoStore({ repoRoot }); }
|
|
259
|
+
catch { return invalid('store_unreadable'); }
|
|
260
|
+
if (uninitialized) {
|
|
256
261
|
return { exitCode: 0, repoRoot, store: null, todo: null, result: statusResult({
|
|
257
262
|
cli: { available: true, version: cliVersion },
|
|
258
263
|
project: { root: repoRoot, git_head: gitHead(repoRoot), project_id: null },
|
|
@@ -318,7 +323,7 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
|
|
|
318
323
|
plan_key: entry.plan_key, plan_version: entry.plan_version,
|
|
319
324
|
})),
|
|
320
325
|
active_runs: activeRuns,
|
|
321
|
-
can_create_plan:
|
|
326
|
+
can_create_plan: true,
|
|
322
327
|
next_action: next,
|
|
323
328
|
});
|
|
324
329
|
return { exitCode: 0, repoRoot, store, todo, result };
|
|
@@ -583,11 +588,11 @@ function describeCreateInputViolation(value) {
|
|
|
583
588
|
...(decoupledPhaseInput ? { phase_accept_dependencies: value.phase_accept_dependencies } : {}),
|
|
584
589
|
});
|
|
585
590
|
} catch (error) {
|
|
586
|
-
//
|
|
591
|
+
// Author-specific fields keep their existing diagnostic priority.
|
|
587
592
|
const shape = describePlanShapeViolation(value, { phaseInput });
|
|
588
593
|
if (shape !== null) return shape;
|
|
589
594
|
return {
|
|
590
|
-
violation_kind: error?.reason ?? error?.code ?? 'topology_invalid',
|
|
595
|
+
violation_kind: error?.detail?.violation_kind ?? error?.reason ?? error?.code ?? 'topology_invalid',
|
|
591
596
|
pointer: error?.detail?.pointer ?? '/',
|
|
592
597
|
expected: error?.detail?.expected ?? { schema: value.schema },
|
|
593
598
|
actual: error?.detail?.actual ?? { message: String(error?.message ?? error) },
|
|
@@ -639,10 +644,9 @@ export async function runPlanCreate({ cwd, inputRef, stdout, inputValue = null,
|
|
|
639
644
|
hardDependencies: input.hard_dependencies,
|
|
640
645
|
joins: input.joins,
|
|
641
646
|
});
|
|
642
|
-
const
|
|
647
|
+
const options = {
|
|
643
648
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
644
|
-
|
|
645
|
-
plan: {
|
|
649
|
+
plan: buildTodoPlan({
|
|
646
650
|
schema: input.schema === MEMO_PHASE_CREATE_INPUT_SCHEMA ? 'lattice.todo_plan.v7'
|
|
647
651
|
: input.schema === DECOUPLED_PHASE_CREATE_INPUT_SCHEMA ? 'lattice.todo_plan.v5'
|
|
648
652
|
: input.schema === PHASE_CREATE_INPUT_SCHEMA
|
|
@@ -654,11 +658,19 @@ export async function runPlanCreate({ cwd, inputRef, stdout, inputValue = null,
|
|
|
654
658
|
MEMO_PHASE_CREATE_INPUT_SCHEMA].includes(input.schema) ? { phases: input.phases } : {}),
|
|
655
659
|
...([DECOUPLED_PHASE_CREATE_INPUT_SCHEMA, MEMO_PHASE_CREATE_INPUT_SCHEMA].includes(input.schema)
|
|
656
660
|
? { phase_accept_dependencies: input.phase_accept_dependencies } : {}),
|
|
657
|
-
},
|
|
661
|
+
}),
|
|
658
662
|
genesis: { actor: input.actor, recorded_at: input.recorded_at, provenance: null },
|
|
659
663
|
...(featureChain === null ? {} : { featureChain }),
|
|
664
|
+
};
|
|
665
|
+
const manifest = await lstat(path.join(repoRoot, MANIFEST_REF)).catch((error) => {
|
|
666
|
+
if (!['ENOENT', 'ENOTDIR'].includes(error?.code)) throw error;
|
|
667
|
+
return null;
|
|
660
668
|
});
|
|
661
|
-
const
|
|
669
|
+
const store = manifest === null
|
|
670
|
+
? await initializeAuthoredTodoStore({ ...options,
|
|
671
|
+
projectId: input.project_id, repositories: [{ repo_id: 'self', path: '.' }] })
|
|
672
|
+
: await appendAuthoredTodoPlan(options);
|
|
673
|
+
const member = store.members.find(({ plan }) => plan.plan_key === input.plan_key);
|
|
662
674
|
const result = {
|
|
663
675
|
schema: CREATE_RESULT_SCHEMA, project_id: store.project_id,
|
|
664
676
|
plan_key: member.plan.plan_key, plan_version: member.plan.plan_version,
|
|
@@ -12,6 +12,8 @@ import path from 'node:path';
|
|
|
12
12
|
|
|
13
13
|
import { canonicalizeArtifact, digestArtifact } from './artifact-contracts.mjs';
|
|
14
14
|
import { buildExecutorPackets } from './runtime-engine.mjs';
|
|
15
|
+
import { verifyRunEventChain } from './runtime-event-store.mjs';
|
|
16
|
+
import { validateRuntimeControlJournal } from './runtime-control-store.mjs';
|
|
15
17
|
import {
|
|
16
18
|
RUNTIME_CONFLICT_KINDS,
|
|
17
19
|
validateExecutorPacket,
|
|
@@ -93,6 +95,42 @@ function selfDigestValid(value, field) {
|
|
|
93
95
|
return digestArtifact(body) === value[field];
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
function activationPrefixEvidence(events, expectedDigest, { stream, runId, plan }) {
|
|
99
|
+
plan ??= {};
|
|
100
|
+
const isArray = Array.isArray(events);
|
|
101
|
+
const index = isArray ? events.findIndex((event) => event?.event_digest === expectedDigest) : -1;
|
|
102
|
+
const actual = isArray ? events.at(-1)?.event_digest : null;
|
|
103
|
+
const chainValid = isArray && (stream === 'run'
|
|
104
|
+
? verifyRunEventChain({ events }).valid && events[0]?.run_id === runId
|
|
105
|
+
: validateRuntimeControlJournal(events, runId));
|
|
106
|
+
const conflicting = chainValid && index >= 0 ? events.slice(index + 1).find((event) => {
|
|
107
|
+
if (stream === 'run') {
|
|
108
|
+
return event.plan_epoch > plan.plan_epoch
|
|
109
|
+
|| ['run_closed', 'intake_frozen'].includes(event.kind)
|
|
110
|
+
|| (event.kind === 'intake_resumed' && event.plan_epoch === plan.plan_epoch)
|
|
111
|
+
|| (event.kind === 'plan_recompiled' && event.plan_epoch >= plan.plan_epoch
|
|
112
|
+
&& (event.plan_epoch !== plan.plan_epoch
|
|
113
|
+
|| event.payload.new_plan_digest !== plan.plan_digest
|
|
114
|
+
|| event.subject.ref !== plan.plan_ref));
|
|
115
|
+
}
|
|
116
|
+
return ['supervisor_stopped', 'supervisor_recovery_barrier', 'write_gate_committed'].includes(event.kind)
|
|
117
|
+
|| (['epoch_activated', 'intake_resumed'].includes(event.kind)
|
|
118
|
+
&& event.payload.plan_epoch >= plan.plan_epoch);
|
|
119
|
+
}) : null;
|
|
120
|
+
return {
|
|
121
|
+
expected_tail: expectedDigest, actual_tail: HEX_DIGEST.test(actual ?? '') ? actual : null,
|
|
122
|
+
expected_in_chain: index >= 0, chain_valid: chainValid,
|
|
123
|
+
conflicting_event_digest: conflicting?.event_digest ?? null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function activationEvidence(runEvents, controlEvents, runDigest, controlDigest, runId, plan) {
|
|
128
|
+
return {
|
|
129
|
+
run: activationPrefixEvidence(runEvents, runDigest, { stream: 'run', runId, plan }),
|
|
130
|
+
control: activationPrefixEvidence(controlEvents, controlDigest, { stream: 'control', runId, plan }),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
96
134
|
export function validateRuntimeFindingRecord(value) {
|
|
97
135
|
if (!exactRecord(value, ['schema', 'finding_id', 'run_id', 'plan_epoch',
|
|
98
136
|
'source_checkpoint_digest', 'observed_event_digest', 'finding', 'recorded_by', 'finding_digest'])
|
|
@@ -431,13 +469,12 @@ export async function activateEpochOneStore({
|
|
|
431
469
|
}
|
|
432
470
|
const runEvents = await readRegularJson(path.join(runDir, 'events.json'), 'run events');
|
|
433
471
|
const controlEvents = await readRegularJson(path.join(runDir, 'control-events.json'), 'runtime control events');
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
||
|
|
439
|
-
|
|
440
|
-
fail('INVALID_RUN_STORE', 'activation pointerがdurable event headへbindしない');
|
|
472
|
+
const evidence = activationEvidence(runEvents, controlEvents, activationRunEventDigest,
|
|
473
|
+
activationControlEventDigest, request?.request_id, compileArtifact?.plan);
|
|
474
|
+
if (!Object.values(evidence).every((entry) => entry.chain_valid && entry.expected_in_chain
|
|
475
|
+
&& entry.conflicting_event_digest === null)
|
|
476
|
+
|| controlEvents.find((event) => event.event_digest === activationControlEventDigest)?.kind !== 'supervisor_activated') {
|
|
477
|
+
fail('INVALID_RUN_STORE', `activation pointerがdurable event prefixへbindしない: ${JSON.stringify(evidence)}`, evidence);
|
|
441
478
|
}
|
|
442
479
|
const normalizedMeta = normalizeActivationMeta(legacyMeta, request, compileArtifact);
|
|
443
480
|
const bundle = buildEpochOneBundle({ request, compileArtifact, legacyMeta: normalizedMeta });
|
|
@@ -507,7 +544,7 @@ export async function activateEpochOneStore({
|
|
|
507
544
|
};
|
|
508
545
|
meta.meta_digest = digestArtifact(meta);
|
|
509
546
|
await replaceDurableJson(runDir, 'run-meta.json', meta);
|
|
510
|
-
return { bundle, meta, pointer };
|
|
547
|
+
return { bundle, meta, pointer, activation_evidence: evidence };
|
|
511
548
|
}
|
|
512
549
|
|
|
513
550
|
/** pointerを正本としてactive bundleだけを読む。directory最大値へfallbackしない。 */
|
|
@@ -697,7 +734,7 @@ export async function stageSuccessorEpoch({ runDir, transactionId, bundle, recom
|
|
|
697
734
|
}
|
|
698
735
|
|
|
699
736
|
/**
|
|
700
|
-
* staged successorをepoch historyへrenameし、durable
|
|
737
|
+
* staged successorをepoch historyへrenameし、durable activation prefixを確認してpointerを最後にcommitする。
|
|
701
738
|
* 同digest retryだけを許し、directory最大値や別transactionへfallbackしない。
|
|
702
739
|
*/
|
|
703
740
|
export async function commitStagedSuccessorEpoch({ runDir, transactionId,
|
|
@@ -746,9 +783,12 @@ export async function commitStagedSuccessorEpoch({ runDir, transactionId,
|
|
|
746
783
|
const controlEvents = typeof readActivationControlEvents === 'function'
|
|
747
784
|
? await readActivationControlEvents()
|
|
748
785
|
: await readRegularJson(path.join(runDir, 'control-events.json'), 'runtime control events');
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
786
|
+
const evidence = activationEvidence(runEvents, controlEvents, activationRunEventDigest,
|
|
787
|
+
activationControlEventDigest, bundle.run_id, bundle.plan);
|
|
788
|
+
if (!Object.values(evidence).every((entry) => entry.chain_valid && entry.expected_in_chain
|
|
789
|
+
&& entry.conflicting_event_digest === null)) {
|
|
790
|
+
fail('EPOCH_ACTIVATION_INCOMPLETE',
|
|
791
|
+
`successor activation event prefixが未耐久化又は矛盾: ${JSON.stringify(evidence)}`, evidence);
|
|
752
792
|
}
|
|
753
793
|
const epochsDir = path.join(runDir, 'epochs');
|
|
754
794
|
const epochDir = path.join(epochsDir, String(bundle.plan_epoch).padStart(8, '0'));
|
|
@@ -776,7 +816,7 @@ export async function commitStagedSuccessorEpoch({ runDir, transactionId,
|
|
|
776
816
|
};
|
|
777
817
|
pointer.pointer_digest = digestArtifact(pointer);
|
|
778
818
|
await replaceDurableJson(runDir, 'committed-epoch.json', pointer);
|
|
779
|
-
return { bundle, pointer };
|
|
819
|
+
return { bundle, pointer, activation_evidence: evidence };
|
|
780
820
|
}
|
|
781
821
|
|
|
782
822
|
export async function commitReleaseEpochBarrier({ runDir, barrier }) {
|
|
@@ -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';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// 席の識別の唯一の置き場。AIは LATTICE_SEAT_ID を言い、機械が seat_id と状態の置き場を導く。
|
|
2
|
+
// 不正な値は拒否せず null に落とす(席が無名になるだけで、何も止めない)。
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
const SEAT_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
7
|
+
|
|
8
|
+
/** @returns {{ seat_id: string|null, state_dir: string }} */
|
|
9
|
+
export function resolveSeatIdentity(env = process.env) {
|
|
10
|
+
const raw = env.LATTICE_SEAT_ID;
|
|
11
|
+
const seat_id = typeof raw === 'string' && SEAT_ID.test(raw) ? raw : null;
|
|
12
|
+
const configured = env.LATTICE_CONFIG_DIR;
|
|
13
|
+
const state_dir = typeof configured === 'string' && path.isAbsolute(configured)
|
|
14
|
+
? configured
|
|
15
|
+
: seat_id === null ? path.join(homedir(), '.lattice') : path.join(homedir(), '.lattice', 'seats', seat_id);
|
|
16
|
+
return Object.freeze({ seat_id, state_dir });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** status / session-context の top-level へ混ぜる欄。未設定なら空(欄を出さない)。 */
|
|
20
|
+
export function seatIdentityFields(env = process.env) {
|
|
21
|
+
const { seat_id } = resolveSeatIdentity(env);
|
|
22
|
+
return seat_id === null ? {} : { seat_id };
|
|
23
|
+
}
|