@quolu/lattice 0.113.1 → 0.114.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-mcp.mjs +3 -2
- package/package.json +1 -1
- package/sensor/dist/db/index.d.ts +3 -2
- package/sensor/dist/db/index.d.ts.map +1 -1
- package/sensor/dist/db/index.js +2 -5
- package/sensor/dist/db/index.js.map +1 -1
- package/sensor/dist/directory.d.ts +2 -0
- package/sensor/dist/directory.d.ts.map +1 -1
- package/sensor/dist/directory.js +3 -1
- package/sensor/dist/directory.js.map +1 -1
- package/sensor/dist/mcp/daemon-paths.d.ts +2 -0
- package/sensor/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/sensor/dist/mcp/daemon-paths.js +3 -1
- package/sensor/dist/mcp/daemon-paths.js.map +1 -1
- package/sensor/dist/mcp/daemon.d.ts +1 -3
- package/sensor/dist/mcp/daemon.d.ts.map +1 -1
- package/sensor/dist/mcp/daemon.js +2 -4
- package/sensor/dist/mcp/daemon.js.map +1 -1
- package/sensor/dist/mcp/handshake-info.d.ts +24 -0
- package/sensor/dist/mcp/handshake-info.d.ts.map +1 -0
- package/sensor/dist/mcp/handshake-info.js +42 -0
- package/sensor/dist/mcp/handshake-info.js.map +1 -0
- package/sensor/dist/mcp/index.d.ts +8 -5
- package/sensor/dist/mcp/index.d.ts.map +1 -1
- package/sensor/dist/mcp/index.js +38 -37
- package/sensor/dist/mcp/index.js.map +1 -1
- package/sensor/dist/mcp/proxy.d.ts +6 -4
- package/sensor/dist/mcp/proxy.d.ts.map +1 -1
- package/sensor/dist/mcp/proxy.js +46 -25
- package/sensor/dist/mcp/proxy.js.map +1 -1
- package/sensor/dist/mcp/session.d.ts +2 -23
- package/sensor/dist/mcp/session.d.ts.map +1 -1
- package/sensor/dist/mcp/session.js +8 -36
- package/sensor/dist/mcp/session.js.map +1 -1
- package/sensor/dist/mcp/tool-definitions.d.ts +82 -0
- package/sensor/dist/mcp/tool-definitions.d.ts.map +1 -0
- package/sensor/dist/mcp/tool-definitions.js +281 -0
- package/sensor/dist/mcp/tool-definitions.js.map +1 -0
- package/sensor/dist/mcp/tools.d.ts +2 -68
- package/sensor/dist/mcp/tools.d.ts.map +1 -1
- package/sensor/dist/mcp/tools.js +8 -274
- package/sensor/dist/mcp/tools.js.map +1 -1
- package/src/cli-help.mjs +2 -2
- package/src/mcp-startup-receipt.mjs +43 -14
- package/src/todo-cli.mjs +6 -1
- package/src/todo-store-view.mjs +10 -6
- package/src/todo-store.mjs +14 -5
- package/src/todo-version-compact.mjs +11 -13
package/src/cli-help.mjs
CHANGED
|
@@ -96,7 +96,7 @@ Read commands:
|
|
|
96
96
|
notice list [--lane <lane>] [--include-acked] [--json] # 着手できるようになった工程の知らせ(既定は未ackだけ。lane省略で全lane)
|
|
97
97
|
blockers [--json] # ブロック中の工程を全部返す(題・担当・理由の全文・ブロックした時刻と者・外すコマンド。読むだけ。外すのは誰でも todo unblock)
|
|
98
98
|
bindings [--plan <key>] [--json] # compile_binding付きTaskをTODO identityつきで投影する
|
|
99
|
-
display read [--json] [--compact] [--open] # host表示用の工程表読取(lattice.todo_display_read_result.v1)。不整合でも断らずstateで返す。--compact は journal を activity、plan_scoped を cross_plan_dependencies に絞った lattice.todo_display_compact_result.v1(大きさは task と生きた線に比例)。--open は --compact を含み、task ごとの一覧を開いた木の task だけに絞って closed {trees, tasks} を足す lattice.todo_display_open_result.
|
|
99
|
+
display read [--json] [--compact] [--open] # host表示用の工程表読取(lattice.todo_display_read_result.v1)。不整合でも断らずstateで返す。--compact は journal を activity、plan_scoped を cross_plan_dependencies に絞った lattice.todo_display_compact_result.v1(大きさは task と生きた線に比例)。--open は --compact を含み、task ごとの一覧を開いた木の task だけに絞って closed {trees, tasks} を足す lattice.todo_display_open_result.v2(member の revision と、検証済み member の snapshot を持たない。next_ready は state が verified の時だけ todo status と同じ一覧、他は null)
|
|
100
100
|
display history [--json] [--limit <n>] [--before <cursor>] # 閉じた木の task を終了の新しい順に1ページ返す(lattice.todo_display_history_result.v1。limit 既定50・最大500、next_cursor を --before へ渡して次頁)
|
|
101
101
|
display source [--json] # 安い変更検知(lattice.todo_store_display_source.v1)。変わった時だけreadする
|
|
102
102
|
independence [--plan <key>] [--json] # readyを検証済み並列・要直列・未検査へ分けて投影する
|
|
@@ -357,7 +357,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
357
357
|
'chart repo': 'chart repo bind --url <url> --branch <branch> [--json] | sync [--json] # lattice.chart_repo_result.v1',
|
|
358
358
|
'chart repo bind': 'chart repo bind --url <url> --branch <branch> [--json] # コード工程表のrepoを記録する',
|
|
359
359
|
'chart repo sync': 'chart repo sync [--json] # depth-1 fetch、accepted_tipからだけ前進(reset/forceしない)、その後sensor。status current|synced|dirty|diverged|failed',
|
|
360
|
-
'todo display read': 'todo display read [--json] [--compact] [--open] # lattice.todo_display_read_result.v1(state: verified|unverified|last_verified|unavailable)。--compact: lattice.todo_display_compact_result.v1(journal→activity、plan_scoped→cross_plan_dependencies)。--open: lattice.todo_display_open_result.
|
|
360
|
+
'todo display read': 'todo display read [--json] [--compact] [--open] # lattice.todo_display_read_result.v1(state: verified|unverified|last_verified|unavailable)。--compact: lattice.todo_display_compact_result.v1(journal→activity、plan_scoped→cross_plan_dependencies)。--open: lattice.todo_display_open_result.v2(--compact を含み、開いた木の task だけ + closed {trees, tasks} + next_ready。revision と検証済み member の snapshot は出さない)',
|
|
361
361
|
'todo display history': 'todo display history [--json] [--limit <n>] [--before <cursor>] # lattice.todo_display_history_result.v1 {state, verified_at, source, inconsistency, dropped_members, closed:{trees,tasks}, tasks:[{tree_id, plan_key, task_id, title, lane, phase_id, parent_task_id, design_memo, done_condition, status, done_at, finished_at, activity:{changed_at, started}}], next_cursor}(閉じた木だけ。finished_at の新しい順。limit 既定50・最大500。不正な cursor は INVALID_ARGUMENTS)',
|
|
362
362
|
'todo display source': 'todo display source [--json] # lattice.todo_store_display_source.v1(安い変更検知。変わった時だけreadする)',
|
|
363
363
|
'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation|enforced> --reason <text>'
|
|
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { lstatSync, mkdirSync, openSync, writeFileSync, closeSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { readdir } from 'node:fs/promises';
|
|
6
7
|
import { ensureSafeDir, ensureSafeFile, replaceStoreFile } from './runtime-errors.mjs';
|
|
7
8
|
import { observeDashboardProcess } from './dashboard-process-control.mjs';
|
|
8
9
|
import { isAclScratchName } from './windows-owner-only.mjs';
|
|
@@ -12,29 +13,57 @@ const PHASES = new Set(['initialize_received', 'initialize_response_written']);
|
|
|
12
13
|
export const MCP_RECEIPT_SLOTS = 64;
|
|
13
14
|
export const MCP_RECEIPT_BYTES = 4096;
|
|
14
15
|
|
|
16
|
+
const receiptRoot = home => path.join(home, '.lattice', 'mcp-startup');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether a slot may still be claimable: fewer than 64 slot names in the root. Slots are never
|
|
20
|
+
* reclaimed, so a full root stays full and a worker would record nothing for ~12 MB of RSS per
|
|
21
|
+
* session. Only a hint: the worker's exclusive mkdir stays the claim (a race still ends as
|
|
22
|
+
* 'capacity'), and any unreadable root counts as free so the worker keeps deciding as before.
|
|
23
|
+
* Async: the MCP response event loop is never blocked on the directory.
|
|
24
|
+
*/
|
|
25
|
+
async function receiptSlotsFree(home) {
|
|
26
|
+
try { return (await readdir(receiptRoot(home))).filter(name => /^slot-\d+$/u.test(name)).length < MCP_RECEIPT_SLOTS; }
|
|
27
|
+
catch { return true; }
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
/** No filesystem or process-identity work on the MCP response event loop. */
|
|
16
31
|
export function createMcpStartupReceipt(wrapperVersion) {
|
|
17
32
|
let worker;
|
|
33
|
+
// idle -> checking (slot hint pending; observations wait in `queued`) -> running | skipped
|
|
34
|
+
let state = 'idle';
|
|
35
|
+
const queued = [];
|
|
18
36
|
const posted = new Set();
|
|
19
|
-
const post = message => {
|
|
37
|
+
const post = message => {
|
|
38
|
+
if (state === 'checking') queued.push(message);
|
|
39
|
+
else if (state === 'running') { try { worker.postMessage(message); } catch { /* observation only */ } }
|
|
40
|
+
};
|
|
20
41
|
const phase = name => {
|
|
21
|
-
if (
|
|
42
|
+
if (state === 'idle' || state === 'skipped' || posted.has(name)) return;
|
|
22
43
|
posted.add(name); post({ phase: name, at: new Date().toISOString() });
|
|
23
44
|
};
|
|
45
|
+
const start = () => {
|
|
46
|
+
state = 'checking';
|
|
47
|
+
const home = homedir();
|
|
48
|
+
receiptSlotsFree(home).then(free => {
|
|
49
|
+
if (!free) { state = 'skipped'; queued.length = 0; return; }
|
|
50
|
+
try {
|
|
51
|
+
worker = new Worker(new URL(import.meta.url), { workerData: {
|
|
52
|
+
receipt: true, home, wrapperVersion, pid: process.pid,
|
|
53
|
+
runId: randomUUID(), startedAt: new Date().toISOString(),
|
|
54
|
+
}, stdout: true, stderr: true });
|
|
55
|
+
worker.stdout.resume(); worker.stderr.resume();
|
|
56
|
+
worker.on('error', () => {});
|
|
57
|
+
worker.unref();
|
|
58
|
+
} catch { state = 'skipped'; queued.length = 0; return; }
|
|
59
|
+
state = 'running';
|
|
60
|
+
for (const message of queued.splice(0)) post(message);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
24
63
|
return {
|
|
25
64
|
setMode(mode, sensorVersion) {
|
|
26
65
|
if (!['direct', 'proxy'].includes(mode) || !VERSION.test(wrapperVersion) || !VERSION.test(sensorVersion)) return;
|
|
27
|
-
if (
|
|
28
|
-
try {
|
|
29
|
-
worker = new Worker(new URL(import.meta.url), { workerData: {
|
|
30
|
-
receipt: true, home: homedir(), wrapperVersion, pid: process.pid,
|
|
31
|
-
runId: randomUUID(), startedAt: new Date().toISOString(),
|
|
32
|
-
}, stdout: true, stderr: true });
|
|
33
|
-
worker.stdout.resume(); worker.stderr.resume();
|
|
34
|
-
worker.on('error', () => {});
|
|
35
|
-
worker.unref();
|
|
36
|
-
} catch { return; }
|
|
37
|
-
}
|
|
66
|
+
if (state === 'idle') start();
|
|
38
67
|
if (!posted.has(mode)) { posted.add(mode); post({ mode, sensorVersion }); }
|
|
39
68
|
},
|
|
40
69
|
initializeReceived() { phase('initialize_received'); },
|
|
@@ -48,7 +77,7 @@ if (!isMainThread && workerData?.receipt === true) {
|
|
|
48
77
|
let slot = null;
|
|
49
78
|
let disabled = false;
|
|
50
79
|
let record = null;
|
|
51
|
-
const root =
|
|
80
|
+
const root = receiptRoot(workerData.home);
|
|
52
81
|
async function prepare() {
|
|
53
82
|
const parent = path.dirname(root);
|
|
54
83
|
try { mkdirSync(parent, { mode: 0o700 }); } catch (error) { if (error.code !== 'EEXIST') throw error; }
|
package/src/todo-cli.mjs
CHANGED
|
@@ -1291,7 +1291,12 @@ async function displayRead(repoRoot, env, { compact = false, open = false } = {}
|
|
|
1291
1291
|
connections: display.store ? await displayConnections(repoRoot, { ...display.store, external_tasks: externalTasks }) : [] };
|
|
1292
1292
|
// trees, labels and connections are read from the full view above; only the shipped store is compacted
|
|
1293
1293
|
const light = compact || open ? { ...result, schema: 'lattice.todo_display_compact_result.v1', store: result.store && compactDisplayStore(result.store) } : result;
|
|
1294
|
-
|
|
1294
|
+
if (!open) return light;
|
|
1295
|
+
// next_ready (open v2): `todo status`'s list from this same verified read, so a host needs no second process or Store verification.
|
|
1296
|
+
const nextReady = display.state === 'verified'
|
|
1297
|
+
? projectTodoStatus(externalTasks.length > 0 ? { ...display.store, external_tasks: externalTasks } : display.store,
|
|
1298
|
+
{ planNotes: [], parallelCandidates: [], structureFinalizations: [] }).next_ready : null;
|
|
1299
|
+
return openDisplayResult({ ...light, next_ready: nextReady });
|
|
1295
1300
|
}
|
|
1296
1301
|
|
|
1297
1302
|
const HISTORY_DEFAULT_LIMIT = 50;
|
package/src/todo-store-view.mjs
CHANGED
|
@@ -122,9 +122,11 @@ const taskKeyOf = (planKey, taskId) => `${planKey}\0${taskId}`;
|
|
|
122
122
|
const isOpenTree = ({ finished, total }) => finished < total;
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
* Open display read (`todo display read --open
|
|
125
|
+
* Open display read (`todo display read --open`, v2): the compact result with every per-task list limited to the tasks of open
|
|
126
126
|
* trees (`finished < total` in the result's own `trees`, the one source) and `closed: {trees, tasks}` over the chart.
|
|
127
|
-
*
|
|
127
|
+
* v2 drops what no host reads: each member's `revision` (the whole desired plan, closed trees included) and, for a
|
|
128
|
+
* verified member (it has `tasks`), its `snapshot` (the same task states); an unverified raw member keeps its filtered
|
|
129
|
+
* `snapshot`. `next_ready` is the caller's (`result.next_ready`, null unless the read is verified). Pure. `plan.phases`, descriptors and `activity.first/last_at` stay whole. A ref of another chart is never a task of
|
|
128
130
|
* this chart here, so a join or dependency naming one keeps it.
|
|
129
131
|
*/
|
|
130
132
|
export function openDisplayResult(result) {
|
|
@@ -134,7 +136,7 @@ export function openDisplayResult(result) {
|
|
|
134
136
|
const closed = { trees: closedTrees.length, tasks: closedTrees.reduce((sum, { total }) => sum + total, 0) };
|
|
135
137
|
const connections = (result.connections ?? []).filter(({ plan_key: planKey, task_id: taskId }) => kept.has(taskKeyOf(planKey, taskId)));
|
|
136
138
|
const referred = new Set(connections.flatMap((entry) => entry.connections.map(({ ref }) => ref)));
|
|
137
|
-
const base = { ...result, schema: 'lattice.todo_display_open_result.
|
|
139
|
+
const base = { ...result, schema: 'lattice.todo_display_open_result.v2', next_ready: result.next_ready ?? null,
|
|
138
140
|
trees: trees.filter(isOpenTree), connections, closed,
|
|
139
141
|
external_tasks: (result.external_tasks ?? []).filter(({ project_id: projectId, plan_key: planKey, task_id: taskId }) => referred.has(`${projectId}/${planKey}/${taskId}`)) };
|
|
140
142
|
if (!isObject(result.store)) return base;
|
|
@@ -145,9 +147,11 @@ export function openDisplayResult(result) {
|
|
|
145
147
|
const keptTask = ({ task_id: taskId }) => kept.has(taskKeyOf(planKey, taskId));
|
|
146
148
|
const local = (ref) => (ref.project_id ?? projectId) === projectId;
|
|
147
149
|
const keepRef = (ref) => isObject(ref) && (!local(ref) || kept.has(taskKeyOf(ref.plan_key, ref.task_id)));
|
|
148
|
-
const
|
|
149
|
-
if (Array.isArray(member.tasks))
|
|
150
|
-
|
|
150
|
+
const { revision: _revision, ...next } = member;
|
|
151
|
+
if (Array.isArray(member.tasks)) {
|
|
152
|
+
next.tasks = member.tasks.filter(keptTask);
|
|
153
|
+
delete next.snapshot;
|
|
154
|
+
} else if (Array.isArray(member.snapshot?.tasks)) next.snapshot = { ...member.snapshot, tasks: member.snapshot.tasks.filter(keptTask) };
|
|
151
155
|
if (isObject(member.plan)) {
|
|
152
156
|
next.plan = { ...member.plan };
|
|
153
157
|
if (Array.isArray(member.plan.tasks)) next.plan.tasks = member.plan.tasks.filter(keptTask);
|
package/src/todo-store.mjs
CHANGED
|
@@ -1787,11 +1787,13 @@ async function readTodoStoreView(options = {}) {
|
|
|
1787
1787
|
* unreadable. perf-store: validated once per process per unchanged plan.json (todo-version-memo).
|
|
1788
1788
|
*/
|
|
1789
1789
|
async function retainedPlanVersion(repoRoot, base, version) {
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1790
|
+
// m1: only the three digests stay in the memo; the record itself (a whole revision's migration) is dropped after the read.
|
|
1791
|
+
const identity = await memoByFileIdentity([path.resolve(repoRoot, base, version, TODO_VERSION_COMPACT_FILE)], async () => {
|
|
1792
|
+
const compact = await readCompactRecord(repoRoot, base, version, { verify: false }).catch(() => null);
|
|
1793
|
+
return compact === null ? null : { plan_digest: compact.plan_digest, predecessor_plan_digest: compact.predecessor_plan_digest,
|
|
1794
|
+
topology_digest: compact.topology_digest };
|
|
1795
|
+
});
|
|
1796
|
+
if (identity !== null) return { plan: identity, journalRef: `${base}/${version}/journal/active.jsonl` };
|
|
1795
1797
|
const ref = `${base}/${version}/plan.json`;
|
|
1796
1798
|
const plan = await memoByFileIdentity([path.resolve(repoRoot, ref)], async () => {
|
|
1797
1799
|
const value = await readArtifact(repoRoot, ref, {
|
|
@@ -2905,6 +2907,13 @@ function carriedPlanScopedChain(store, previous, plan, journalRef, taskMigration
|
|
|
2905
2907
|
payload: { from, to, reason: event.payload.reason } });
|
|
2906
2908
|
pushPlanScopedEvent(successor.plan_scoped, carried);
|
|
2907
2909
|
}
|
|
2910
|
+
// m1: the declaration travels with the plan, so a read of this version finds it in its own chain instead of walking every
|
|
2911
|
+
// retained predecessor (a plan declared 975 revisions ago opened all 1,649 compact records per read).
|
|
2912
|
+
if (previous.coordination) {
|
|
2913
|
+
const { mode, reason, declared_by: actor, declared_at: recordedAt } = previous.coordination;
|
|
2914
|
+
pushPlanScopedEvent(successor.plan_scoped, buildPlanScopedEvent(successor, { kind: 'coordination_mode', actor,
|
|
2915
|
+
recorded_at: recordedAt, provenance: null, payload: { mode, reason } }));
|
|
2916
|
+
}
|
|
2908
2917
|
// 接続: only the schedule connections still open travel; a settled or removed one equals no connection.
|
|
2909
2918
|
for (const entry of projectTodoScheduleConnections(previous.plan_scoped?.events ?? [])) {
|
|
2910
2919
|
const taskId = ids.get(entry.task_id);
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { readFile } from 'node:fs/promises';
|
|
11
11
|
import { gunzipSync, gzipSync } from 'node:zlib';
|
|
12
12
|
import { canonicalizeTodoArtifact, isTodoDigest, isTodoIdentifier, todoSelfDigest } from './todo-contracts.mjs';
|
|
13
|
-
import { memoByFileIdentity } from './todo-version-memo.mjs';
|
|
14
13
|
|
|
15
14
|
export const TODO_VERSION_COMPACT_SCHEMA = 'lattice.todo_version_compact.v1';
|
|
16
15
|
export const TODO_VERSION_COMPACT_FILE = 'compact.json.gz';
|
|
@@ -104,16 +103,15 @@ export const packVersionCompact = (record) => gzipSync(Buffer.from(`${canonicali
|
|
|
104
103
|
* and keeps the shape check: one gunzip and one parse per version, which a read pays for every retained version of a plan.
|
|
105
104
|
*/
|
|
106
105
|
export async function readVersionCompact(directory, maxBytes = 8 * 1024 * 1024, { verify = true } = {}) {
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, verify ? 'verify' : 'read');
|
|
106
|
+
// Not memoized: a record holds a revision's whole per-task migration, so keeping one per retained version grew RSS with the
|
|
107
|
+
// revision count (m1). Callers memoize the small value they derive (identity, note migration).
|
|
108
|
+
let packed;
|
|
109
|
+
try { packed = await readFile(`${directory}/${TODO_VERSION_COMPACT_FILE}`); } catch (error) {
|
|
110
|
+
if (error?.code === 'ENOENT') return null;
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const text = gunzipSync(packed, { maxOutputLength: maxBytes }).toString('utf8');
|
|
114
|
+
const value = JSON.parse(text);
|
|
115
|
+
if ((verify && text !== `${canonicalizeTodoArtifact(value)}\n`) || !validateVersionCompact(value, { verify })) throw new Error('compact_record_invalid');
|
|
116
|
+
return value;
|
|
119
117
|
}
|