@quolu/lattice 0.85.4 → 0.85.5
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/package.json +1 -1
- package/src/cli-help.mjs +5 -0
- package/src/store-lock.mjs +30 -5
- package/src/todo-cli.mjs +9 -1
- package/src/todo-note-store.mjs +2 -2
- package/src/todo-store.mjs +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.85.
|
|
3
|
+
"version": "0.85.5",
|
|
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/cli-help.mjs
CHANGED
|
@@ -87,6 +87,8 @@ Read commands:
|
|
|
87
87
|
show --plan <key> --task <id> --json # 個別ToDoと最新bounded note contextを追加操作なしで返す
|
|
88
88
|
note list --plan <key> [--task <id>] --json # note全履歴の診断面(通常read/startでは不要)
|
|
89
89
|
bindings [--plan <key>] [--json] # compile_binding付きTaskをTODO identityつきで投影する
|
|
90
|
+
display read [--json] # host表示用の工程表読取(lattice.todo_display_read_result.v1)。不整合でも断らずstateで返す
|
|
91
|
+
display source [--json] # 安い変更検知(lattice.todo_store_display_source.v1)。変わった時だけreadする
|
|
90
92
|
independence [--plan <key>] [--json] # readyを検証済み並列・要直列・未検査へ分けて投影する
|
|
91
93
|
structure --schema --json # plan定義後に入力する論理dataflow契約をstore非依存で返す
|
|
92
94
|
structure [--plan <key>] --json # 保存済み構造をsensor再実行なしでfreshness・finding付き投影する
|
|
@@ -290,6 +292,9 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
290
292
|
'todo note': 'todo note --plan <key> [--task <id>] (--message <text>|--input <file>) | list --plan <key> [--task <id>] --json',
|
|
291
293
|
'todo note list': 'todo note list --plan <key> [--task <id>] [--json]',
|
|
292
294
|
'todo bindings': 'todo bindings [--plan <key>] [--json]',
|
|
295
|
+
'todo display': 'todo display read [--json] | source [--json] # host表示用の読取。不整合でも断らずstateで返す',
|
|
296
|
+
'todo display read': 'todo display read [--json] # lattice.todo_display_read_result.v1(state: verified|unverified|last_verified|unavailable)',
|
|
297
|
+
'todo display source': 'todo display source [--json] # lattice.todo_store_display_source.v1(安い変更検知。変わった時だけreadする)',
|
|
293
298
|
'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation> --reason <text>'
|
|
294
299
|
+ ' | compile --plan <key> --input <file> | compile --schema --json | witness migrate --plan <key>'
|
|
295
300
|
+ ' | witness scaffold --template --plan <key> [--json] | witness scaffold --schema --json | witness scaffold --plan <key> --input <draft>',
|
package/src/store-lock.mjs
CHANGED
|
@@ -11,6 +11,8 @@ const CLAIM = /^([0-9a-f]{64})-([1-9][0-9]*)-([0-9a-f]{64})-([0-9a-f]{16})$/u;
|
|
|
11
11
|
// its heartbeat mtime is older than LOCK_STALE_MS; every holder touches its lock and claim.
|
|
12
12
|
export const LOCK_STALE_MS = 10 * 60_000;
|
|
13
13
|
export const LOCK_HEARTBEAT_MS = 30_000;
|
|
14
|
+
// Several seats share one store: a writer waits out another live process this long, then refuses.
|
|
15
|
+
export const LOCK_WAIT_MS = 30_000;
|
|
14
16
|
// Weak identity when own observation is unavailable: never PID-recovered, only heartbeat-stale.
|
|
15
17
|
const WEAK = 'unobserved';
|
|
16
18
|
const NO_HARD_LINK = ['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'EXDEV', 'ENOSYS'];
|
|
@@ -167,10 +169,12 @@ async function recoveryClaim(claimsPath, owner, lockPath) {
|
|
|
167
169
|
// Timestamp ordering could let a delayed earlier publisher enter twice.
|
|
168
170
|
const candidates = await readdir(claimsPath);
|
|
169
171
|
if (candidates.length === 1 && candidates[0] === name) return claimPath;
|
|
170
|
-
|
|
172
|
+
const contended = new StoreLockError('store_locked', lockPath, {
|
|
171
173
|
recovery_claims_path: claimsPath,
|
|
172
174
|
next_action: `Retry after recovery claimants exit; for foreign or unidentified claims, confirm no writer on their recorded host before clearing only abandoned entries in ${claimsPath}`,
|
|
173
175
|
});
|
|
176
|
+
contended.contended = true;
|
|
177
|
+
throw contended;
|
|
174
178
|
} catch (error) {
|
|
175
179
|
await rmdir(claimPath);
|
|
176
180
|
throw error;
|
|
@@ -206,7 +210,7 @@ async function removeClaim(claimPath, claimsPath) {
|
|
|
206
210
|
|
|
207
211
|
/** Complete ownership is linked atomically; recovery never removes a live owner. */
|
|
208
212
|
export async function withStoreLock({ lockPath, recoveryClaimsPath = `${lockPath}.recovery`,
|
|
209
|
-
onRecoveryClaim = null, createParent = true, releasePath = () => lockPath }, callback) {
|
|
213
|
+
onRecoveryClaim = null, createParent = true, releasePath = () => lockPath, waitMs = 0 }, callback) {
|
|
210
214
|
if (createParent) await mkdir(path.dirname(lockPath), { recursive: true });
|
|
211
215
|
ownStart ??= observeStartIdentityRaw(process.pid).catch((error) => { ownStart = undefined; throw error; });
|
|
212
216
|
ownHost ??= observeProcessHostIdentityRaw().then((value) => {
|
|
@@ -259,6 +263,8 @@ export async function withStoreLock({ lockPath, recoveryClaimsPath = `${lockPath
|
|
|
259
263
|
fileIdentity = await handle.stat();
|
|
260
264
|
}
|
|
261
265
|
finally { await handle.close(); }
|
|
266
|
+
const deadline = Date.now() + waitMs;
|
|
267
|
+
let pause = 10;
|
|
262
268
|
for (;;) {
|
|
263
269
|
try { await link(temporary, lockPath); acquired = true; break; }
|
|
264
270
|
catch (error) {
|
|
@@ -279,14 +285,33 @@ export async function withStoreLock({ lockPath, recoveryClaimsPath = `${lockPath
|
|
|
279
285
|
}
|
|
280
286
|
const existing = await readOwner(lockPath);
|
|
281
287
|
if (existing === null) continue;
|
|
282
|
-
|
|
288
|
+
const backOff = async (refusal) => {
|
|
289
|
+
if (Date.now() >= deadline) throw refusal;
|
|
290
|
+
await new Promise((resolve) => { setTimeout(resolve, pause + Math.random() * pause); });
|
|
291
|
+
pause = Math.min(pause * 2, 250);
|
|
292
|
+
};
|
|
293
|
+
// A live owner is waited out until the deadline. Our own PID (re-entry) would wait on
|
|
294
|
+
// ourselves, and an unidentified owner keeps its refusal, so both refuse at once.
|
|
295
|
+
const waitFor = async (live) => {
|
|
296
|
+
const self = live.owner?.pid === process.pid && live.owner?.host === host;
|
|
297
|
+
if (live.owner === null || self) throw busy(live, lockPath);
|
|
298
|
+
await backOff(busy(live, lockPath));
|
|
299
|
+
};
|
|
300
|
+
if (!await abandoned(existing, host)) { await waitFor(existing); continue; }
|
|
283
301
|
if (claimPath === null) {
|
|
284
|
-
claimPath = await recoveryClaim(recoveryClaimsPath, owner, lockPath);
|
|
302
|
+
try { claimPath = await recoveryClaim(recoveryClaimsPath, owner, lockPath); }
|
|
303
|
+
catch (error) {
|
|
304
|
+
// Several writers judged the same just-exited owner at once; none is sole, so all back off.
|
|
305
|
+
if (error?.contended !== true) throw error;
|
|
306
|
+
await backOff(error);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
285
309
|
if (onRecoveryClaim) await onRecoveryClaim();
|
|
286
310
|
}
|
|
287
311
|
const fresh = await readOwner(lockPath);
|
|
288
312
|
if (fresh !== null) {
|
|
289
|
-
|
|
313
|
+
// The judged owner released and a new live writer linked in meanwhile.
|
|
314
|
+
if (!await abandoned(fresh, host)) { await waitFor(fresh); continue; }
|
|
290
315
|
await removeJudged(lockPath, fresh.info);
|
|
291
316
|
}
|
|
292
317
|
}
|
package/src/todo-cli.mjs
CHANGED
|
@@ -87,6 +87,8 @@ import {
|
|
|
87
87
|
readTodoWitnessSet,
|
|
88
88
|
todoWitnessRef,
|
|
89
89
|
writeTodoWitnessSet,
|
|
90
|
+
readTodoStoreDisplaySource,
|
|
91
|
+
readTodoStoreForDisplay,
|
|
90
92
|
readTodoStoreStable,
|
|
91
93
|
rebuildTodoSnapshot,
|
|
92
94
|
writeTodoIndependenceArtifact,
|
|
@@ -287,7 +289,7 @@ function internalFailure(stderr, error) {
|
|
|
287
289
|
}
|
|
288
290
|
|
|
289
291
|
const TODO_COMMAND_NAMES = Object.freeze([
|
|
290
|
-
'status', 'show', 'note', 'bindings', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
292
|
+
'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
291
293
|
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
292
294
|
'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
293
295
|
'retract', 'dependency',
|
|
@@ -4633,6 +4635,12 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
4633
4635
|
&& argv[1] === '--plan' && isTodoIdentifier(argv[2])
|
|
4634
4636
|
&& (argv.length === 3 || argv[3] === '--json')) {
|
|
4635
4637
|
action = (repoRoot) => bindings({ repoRoot, requestedPlanKey: argv[2] });
|
|
4638
|
+
} else if (argv[0] === 'display' && (argv[1] === 'read' || argv[1] === 'source')
|
|
4639
|
+
&& (argv.length === 2 || (argv.length === 3 && argv[2] === '--json'))) {
|
|
4640
|
+
// Host display read (BellTeam module): a typed inconsistency is a state, never a refusal.
|
|
4641
|
+
action = argv[1] === 'read'
|
|
4642
|
+
? async (repoRoot) => ({ schema: 'lattice.todo_display_read_result.v1', ...await readTodoStoreForDisplay({ repoRoot }) })
|
|
4643
|
+
: (repoRoot) => readTodoStoreDisplaySource({ repoRoot });
|
|
4636
4644
|
} else if (argv[0] === 'note' && argv[1] !== 'list') {
|
|
4637
4645
|
const flags = matchFlagCommand(argv, ['note'], NOTE_FLAG_SPEC);
|
|
4638
4646
|
const hasMessage = typeof flags?.message === 'string' && flags.message.length > 0;
|
package/src/todo-note-store.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
lstat, mkdir, open, readFile, readdir, rename, rm, stat,
|
|
5
5
|
} from 'node:fs/promises';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import { StoreLockError, withStoreLock } from './store-lock.mjs';
|
|
7
|
+
import { LOCK_WAIT_MS, StoreLockError, withStoreLock } from './store-lock.mjs';
|
|
8
8
|
import { syncPublishedFile } from './fs-publish.mjs';
|
|
9
9
|
import { normalizeCheckoutEol } from './todo-store-view.mjs';
|
|
10
10
|
|
|
@@ -236,7 +236,7 @@ async function withNoteLock(repoRoot, callback) {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
await ensureNoteDirectory(root);
|
|
239
|
-
return await withStoreLock({ lockPath: path.join(root, '.write.lock'), createParent: false }, callback);
|
|
239
|
+
return await withStoreLock({ lockPath: path.join(root, '.write.lock'), createParent: false, waitMs: LOCK_WAIT_MS }, callback);
|
|
240
240
|
}
|
|
241
241
|
catch (error) {
|
|
242
242
|
if (error instanceof StoreLockError) {
|
package/src/todo-store.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export {
|
|
|
17
17
|
import { randomBytes } from 'node:crypto';
|
|
18
18
|
import { fsyncDirectory } from './fs-dir-sync.mjs';
|
|
19
19
|
import { renamePublishedFile, syncPublishedFile } from './fs-publish.mjs';
|
|
20
|
-
import { StoreLockError, withStoreLock } from './store-lock.mjs';
|
|
20
|
+
import { LOCK_WAIT_MS, StoreLockError, withStoreLock } from './store-lock.mjs';
|
|
21
21
|
import {
|
|
22
22
|
lstat, mkdir, open, readFile, readdir, realpath, rename, rm, rmdir,
|
|
23
23
|
} from 'node:fs/promises';
|
|
@@ -2122,6 +2122,7 @@ async function withLock(repoRoot, callback, {
|
|
|
2122
2122
|
return await withStoreLock({
|
|
2123
2123
|
lockPath: path.join(repoRoot, STORE_ROOT_REF, '.write.lock'),
|
|
2124
2124
|
createParent: initialize,
|
|
2125
|
+
waitMs: LOCK_WAIT_MS,
|
|
2125
2126
|
recoveryClaimsPath: path.join(repoRoot, CROSS_PLAN_RECOVERY_CLAIMS_REF),
|
|
2126
2127
|
onRecoveryClaim: typeof onProtocolStage === 'function'
|
|
2127
2128
|
? () => onProtocolStage('cross_plan_lock_recovery_mutex_acquired') : null,
|