@quolu/lattice 0.92.0 → 0.94.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/package.json +1 -1
- package/src/cli-help.mjs +3 -1
- package/src/todo-cli.mjs +100 -5
- package/src/todo-store.mjs +17 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.94.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/cli-help.mjs
CHANGED
|
@@ -135,6 +135,7 @@ Write commands:
|
|
|
135
135
|
# 監査と構造finalizationは残作業であり、doneの門ではない
|
|
136
136
|
reopen --plan <key> --task <id> --reason <text> [--override-reason <text>]
|
|
137
137
|
evidence promote --plan <key> --task <id> --evidence <file>
|
|
138
|
+
evidence anchor [--json] # 既存の証拠をgcから守る印(refs/lattice/evidence/<oid>)を付ける。commit済みにはならない
|
|
138
139
|
# done状態と完了時刻を維持し、最新doneへ追記eventで証拠を再束縛する
|
|
139
140
|
start --plan <key> --task <id> --rebind --reason <text> # 改訂でcarryされたin-progressへ現版のstart束縛を積み直す(ADR 0191)
|
|
140
141
|
dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
|
|
@@ -345,7 +346,8 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
345
346
|
+ ' [--design-memo <text>] [--after <id>[,<id>...]] [--before <id>[,<id>...]] [--reason <text>]',
|
|
346
347
|
'todo done': 'todo done --plan <key> --task <id> [--evidence <file>] [--message <text>] [--test-result <markdown-file>]',
|
|
347
348
|
'todo reopen': 'todo reopen --plan <key> --task <id> --reason <text> [--override-reason <text>]',
|
|
348
|
-
'todo evidence': 'todo evidence promote --plan <key> --task <id> --evidence <file>',
|
|
349
|
+
'todo evidence': 'todo evidence promote --plan <key> --task <id> --evidence <file> | anchor [--json]',
|
|
350
|
+
'todo evidence anchor': 'todo evidence anchor [--json] # lattice.todo_evidence_anchor_result.v1 {anchored, already, missing}; no Store yet: lattice.todo_evidence_anchor_uninitialized.v1',
|
|
349
351
|
'todo evidence promote': 'todo evidence promote --plan <key> --task <id> --evidence <file>',
|
|
350
352
|
'todo dependency': [
|
|
351
353
|
'todo dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
|
package/src/todo-cli.mjs
CHANGED
|
@@ -360,6 +360,7 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
360
360
|
'phase reject': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message', 'reason', 'input'], required: ['plan', 'phase'] }),
|
|
361
361
|
'phase reopen': Object.freeze({ known: ['plan', 'phase', 'reason', 'override-reason'], required: ['plan', 'phase', 'reason'] }),
|
|
362
362
|
'evidence promote': Object.freeze({ known: ['plan', 'task', 'evidence'], required: ['plan', 'task', 'evidence'] }),
|
|
363
|
+
'evidence anchor': Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
|
|
363
364
|
'independence compile': Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
364
365
|
'independence mode': Object.freeze({ known: ['plan', 'set', 'reason'], required: ['plan', 'set', 'reason'] }),
|
|
365
366
|
'independence witness scaffold': Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
@@ -735,6 +736,23 @@ function looksLikeEvidenceDescriptor(value) {
|
|
|
735
736
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
736
737
|
}
|
|
737
738
|
|
|
739
|
+
// evidence-ref: every evidence blob Lattice writes is anchored here so gc keeps it. The Store's reachability walk
|
|
740
|
+
// excludes refs/lattice/evidence/* (seam refs still count), so an anchored blob still reads `uncommitted` until a commit reaches it.
|
|
741
|
+
const EVIDENCE_REF_PREFIX = 'refs/lattice/evidence/';
|
|
742
|
+
|
|
743
|
+
function anchorEvidenceBlob(repoRoot, oid) {
|
|
744
|
+
gitSync(['update-ref', `${EVIDENCE_REF_PREFIX}${oid}`, oid], { cwd: repoRoot, stdio: ['ignore', 'ignore', 'pipe'] });
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function evidenceAnchored(repoRoot, oid) {
|
|
748
|
+
try {
|
|
749
|
+
gitSync(['show-ref', '--verify', '--quiet', `${EVIDENCE_REF_PREFIX}${oid}`], { cwd: repoRoot, stdio: 'ignore' });
|
|
750
|
+
return true;
|
|
751
|
+
} catch {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
738
756
|
function writeEvidenceBlob(repoRoot, bytes, blobPath, write = true) {
|
|
739
757
|
// worktree pathから作る証拠は`git add`と同じclean filterを通す。生のCRLF bytesを
|
|
740
758
|
// そのままhashすると、commit先はLFへ正規化される一方、descriptorはdangling blobを
|
|
@@ -750,6 +768,9 @@ function writeEvidenceBlob(repoRoot, bytes, blobPath, write = true) {
|
|
|
750
768
|
if (!write) return { git_blob_oid: oid, content_digest: null };
|
|
751
769
|
throw error;
|
|
752
770
|
}
|
|
771
|
+
// Anchored before the event is appended: no recorded evidence without an anchor. A failed append leaves one ref
|
|
772
|
+
// keeping one blob alive (bounded, harmless).
|
|
773
|
+
if (write) anchorEvidenceBlob(repoRoot, oid);
|
|
753
774
|
return {
|
|
754
775
|
git_blob_oid: oid,
|
|
755
776
|
content_digest: createHash('sha256').update(storedBytes).digest('hex'),
|
|
@@ -2247,7 +2268,8 @@ function extractionFreshnessViolations(repoRoot, extraction) {
|
|
|
2247
2268
|
// rev-listの出力はobject数に比例して伸びる(本repo実測で既定maxBuffer 1MiB超過済み)。
|
|
2248
2269
|
// 隣のgit showと同様にmaxBufferを明示しないと、ENOBUFSが握られて
|
|
2249
2270
|
// source_reachability_unreadableへ誤変換される。
|
|
2250
|
-
|
|
2271
|
+
// evidence-ref: an anchored evidence blob is not a reachable source.
|
|
2272
|
+
reachable = new Set(gitSync(['rev-list', '--objects', `--exclude=${EVIDENCE_REF_PREFIX}*`, '--all'], {
|
|
2251
2273
|
cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 134_217_728,
|
|
2252
2274
|
}).split('\n').filter(Boolean).map((line) => line.split(' ')[0]));
|
|
2253
2275
|
} catch {
|
|
@@ -4820,6 +4842,78 @@ async function ensureActiveProjectDashboard({ repoRoot, env, stderr, strict = fa
|
|
|
4820
4842
|
}
|
|
4821
4843
|
}
|
|
4822
4844
|
|
|
4845
|
+
/** evidence-ref: an uncommitted item says whether gc is kept off it, and how to protect it if not. */
|
|
4846
|
+
function uncommittedEvidenceItem(repoRoot, store, evidence) {
|
|
4847
|
+
const anchored = evidenceAnchored(evidenceRepoRoot(repoRoot, store, evidence), evidence.git_blob_oid);
|
|
4848
|
+
return { repo_id: evidence.repo_id, path: evidence.path, anchored,
|
|
4849
|
+
next_action: anchored
|
|
4850
|
+
? `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.`
|
|
4851
|
+
: 'Anchor it so gc keeps it: `lattice todo evidence anchor --json`; commit it to make it committed.' };
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
function evidenceRepoRoot(repoRoot, store, evidence) {
|
|
4855
|
+
const ref = store.manifest.repositories.find(({ repo_id: id }) => id === evidence.repo_id)?.path ?? '.';
|
|
4856
|
+
return path.resolve(repoRoot, ref);
|
|
4857
|
+
}
|
|
4858
|
+
|
|
4859
|
+
/** The evidence descriptors a Store records: task evidence, phase decision evidence and accepted slot evidence. */
|
|
4860
|
+
function recordedEvidence(store) {
|
|
4861
|
+
const entries = [];
|
|
4862
|
+
for (const member of store.members) {
|
|
4863
|
+
const planKey = member.plan.plan_key;
|
|
4864
|
+
for (const task of member.tasks) {
|
|
4865
|
+
if (validateEvidenceDescriptor(task.evidence)) entries.push({ plan_key: planKey, task_id: task.task_id, evidence: task.evidence });
|
|
4866
|
+
}
|
|
4867
|
+
for (const event of member.journal.events) {
|
|
4868
|
+
if (!['phase_accept', 'phase_reject'].includes(event.kind)) continue;
|
|
4869
|
+
for (const evidence of [event.payload.decision_evidence, ...(event.payload.evidence_slots ?? []).map((slot) => slot.evidence)]) {
|
|
4870
|
+
if (validateEvidenceDescriptor(evidence)) entries.push({ plan_key: planKey, phase_id: event.phase_id, evidence });
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
return entries;
|
|
4875
|
+
}
|
|
4876
|
+
|
|
4877
|
+
/**
|
|
4878
|
+
* `todo evidence anchor` (evidence-ref): anchor evidence recorded before writes anchored it. Idempotent; run once per
|
|
4879
|
+
* existing chart. Evidence gc already pruned cannot come back and is listed as `missing`.
|
|
4880
|
+
*/
|
|
4881
|
+
async function evidenceAnchor({ repoRoot }) {
|
|
4882
|
+
// No Store yet: nothing recorded, so nothing to anchor. Answer like `todo status` does, not as a broken store.
|
|
4883
|
+
if (await isUninitializedTodoStore({ repoRoot })) {
|
|
4884
|
+
const result = { schema: 'lattice.todo_evidence_anchor_uninitialized.v1', anchored: [], already: 0, missing: [],
|
|
4885
|
+
next_actions: ['lattice plan create --template --json', 'lattice plan create --input <file>'], result_digest: '' };
|
|
4886
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
4887
|
+
return result;
|
|
4888
|
+
}
|
|
4889
|
+
const store = await readTodoStore({ repoRoot });
|
|
4890
|
+
const anchored = [];
|
|
4891
|
+
const missing = [];
|
|
4892
|
+
const seen = new Set();
|
|
4893
|
+
let already = 0;
|
|
4894
|
+
for (const { evidence, ...owner } of recordedEvidence(store)) {
|
|
4895
|
+
const repo = evidenceRepoRoot(repoRoot, store, evidence);
|
|
4896
|
+
const key = `${repo}\0${evidence.git_blob_oid}`;
|
|
4897
|
+
if (seen.has(key)) continue;
|
|
4898
|
+
seen.add(key);
|
|
4899
|
+
const item = { ...owner, git_blob_oid: evidence.git_blob_oid };
|
|
4900
|
+
if (isTodoEvidenceUncommitted({ repoRoot, store, evidence })) {
|
|
4901
|
+
if (evidenceAnchored(repo, evidence.git_blob_oid)) already += 1;
|
|
4902
|
+
else { anchorEvidenceBlob(repo, evidence.git_blob_oid); anchored.push(item); }
|
|
4903
|
+
continue;
|
|
4904
|
+
}
|
|
4905
|
+
try {
|
|
4906
|
+
gitSync(['cat-file', '-e', evidence.git_blob_oid], { cwd: repo, stdio: 'ignore' });
|
|
4907
|
+
} catch {
|
|
4908
|
+
missing.push(item);
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
const result = { schema: 'lattice.todo_evidence_anchor_result.v1', project_id: store.project_id,
|
|
4912
|
+
anchored, already, missing, result_digest: '' };
|
|
4913
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
4914
|
+
return result;
|
|
4915
|
+
}
|
|
4916
|
+
|
|
4823
4917
|
async function verify({ repoRoot, requestedPlanKey }) {
|
|
4824
4918
|
const store = await readTodoStore({ repoRoot });
|
|
4825
4919
|
const members = selectMembers(store, requestedPlanKey);
|
|
@@ -4835,13 +4929,11 @@ async function verify({ repoRoot, requestedPlanKey }) {
|
|
|
4835
4929
|
const pending = member.tasks.filter((task) => task.evidence_unverified
|
|
4836
4930
|
&& isTodoEvidenceUncommitted({ repoRoot, store, evidence: task.evidence }));
|
|
4837
4931
|
for (const { task_id: taskId, evidence } of pending) {
|
|
4838
|
-
uncommittedEvidence.push({ plan_key: planKey, task_id: taskId,
|
|
4839
|
-
next_action: `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.` });
|
|
4932
|
+
uncommittedEvidence.push({ plan_key: planKey, task_id: taskId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
|
|
4840
4933
|
}
|
|
4841
4934
|
for (const { phase_id: phaseId, decision_evidence: evidence } of member.phases) {
|
|
4842
4935
|
if (decisionEvidenceState(repoRoot, store, evidence) !== 'uncommitted') continue;
|
|
4843
|
-
uncommittedEvidence.push({ plan_key: planKey, phase_id: phaseId,
|
|
4844
|
-
next_action: `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.` });
|
|
4936
|
+
uncommittedEvidence.push({ plan_key: planKey, phase_id: phaseId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
|
|
4845
4937
|
}
|
|
4846
4938
|
const unverified = member.tasks.find((task) => task.evidence_unverified && !pending.includes(task));
|
|
4847
4939
|
if (unverified !== undefined) {
|
|
@@ -5439,6 +5531,9 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5439
5531
|
kind: 'unblock', payload: {}, evidenceRef: null,
|
|
5440
5532
|
}) });
|
|
5441
5533
|
}
|
|
5534
|
+
} else if (argv[0] === 'evidence' && argv[1] === 'anchor'
|
|
5535
|
+
&& matchFlagCommand(argv, ['evidence', 'anchor'], TODO_FLAG_SPECS['evidence anchor']) !== null) {
|
|
5536
|
+
action = (repoRoot) => evidenceAnchor({ repoRoot });
|
|
5442
5537
|
} else if (argv[0] === 'evidence' && argv[1] === 'promote') {
|
|
5443
5538
|
const flags = matchFlagCommand(argv, ['evidence', 'promote'], TODO_FLAG_SPECS['evidence promote']);
|
|
5444
5539
|
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
package/src/todo-store.mjs
CHANGED
|
@@ -113,6 +113,13 @@ function fail(code, reason, detail) {
|
|
|
113
113
|
throw new TodoStoreError(code, reason, reason, detail);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
// No Store yet is an empty project, not a broken one (same classification as `status`): never invite repair or deletion.
|
|
117
|
+
function failUninitialized() {
|
|
118
|
+
fail('STORE_UNINITIALIZED', 'store_uninitialized', {
|
|
119
|
+
ref: STORE_ROOT_REF, next_action: 'lattice plan create --template --json',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
116
123
|
const upgradeAction = (what) => `${what} was written by a newer Lattice than ${packageJson.version}. The record is`
|
|
117
124
|
+ ` not corrupt: do not repair or delete it. Upgrade Lattice on this host to a version newer than`
|
|
118
125
|
+ ` ${packageJson.version}, then run the command again.`;
|
|
@@ -1115,7 +1122,8 @@ function reachableObjects(absoluteRepo) {
|
|
|
1115
1122
|
if (cached !== undefined) return cached;
|
|
1116
1123
|
let set;
|
|
1117
1124
|
try {
|
|
1118
|
-
|
|
1125
|
+
// evidence-ref: Lattice's evidence anchors (refs/lattice/evidence/*, not seam refs) keep evidence from gc; anchored is not committed.
|
|
1126
|
+
const stdout = gitSync(['rev-list', '--objects', '--exclude=refs/lattice/evidence/*', '--all'],
|
|
1119
1127
|
{ cwd: absoluteRepo, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
|
|
1120
1128
|
maxBuffer: 256 * 1024 * 1024 });
|
|
1121
1129
|
set = new Set();
|
|
@@ -1533,8 +1541,12 @@ async function readTodoStoreView(options = {}) {
|
|
|
1533
1541
|
await assertNoCrossPlanImportRecoveryNeeded(repoRoot);
|
|
1534
1542
|
const pinnedSourceCache = { commits: new Set(), blobs: new Map() };
|
|
1535
1543
|
const manifest = await readArtifact(repoRoot, MANIFEST_REF, {
|
|
1536
|
-
code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest,
|
|
1544
|
+
code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest, missing: true,
|
|
1537
1545
|
});
|
|
1546
|
+
if (manifest === null) {
|
|
1547
|
+
if (await isUninitializedTodoStore({ repoRoot })) failUninitialized();
|
|
1548
|
+
fail('STORE_INCONSISTENT', 'artifact_missing', { ref: MANIFEST_REF });
|
|
1549
|
+
}
|
|
1538
1550
|
const loaded = [];
|
|
1539
1551
|
for (const descriptor of manifest.members) {
|
|
1540
1552
|
const plan = await readArtifact(repoRoot, descriptor.plan_ref, {
|
|
@@ -2161,11 +2173,11 @@ async function withLock(repoRoot, callback, {
|
|
|
2161
2173
|
try {
|
|
2162
2174
|
if (!initialize) {
|
|
2163
2175
|
const root = await lstat(path.join(repoRoot, STORE_ROOT_REF)).catch((error) => {
|
|
2164
|
-
if (error?.code === 'ENOENT')
|
|
2176
|
+
if (error?.code === 'ENOENT') failUninitialized();
|
|
2165
2177
|
throw error;
|
|
2166
2178
|
});
|
|
2167
2179
|
const parent = await lstat(path.join(repoRoot, '.lattice')).catch((error) => {
|
|
2168
|
-
if (error?.code === 'ENOENT')
|
|
2180
|
+
if (error?.code === 'ENOENT') failUninitialized();
|
|
2169
2181
|
throw error;
|
|
2170
2182
|
});
|
|
2171
2183
|
if (!root.isDirectory() || root.isSymbolicLink()
|
|
@@ -3545,7 +3557,7 @@ async function prepareAuthoredStoreRoot(repoRoot, options) {
|
|
|
3545
3557
|
}); } catch (error) {
|
|
3546
3558
|
const gone = (await uninitializedStoreLayout(repoRoot)).identity === null;
|
|
3547
3559
|
if (gone && error instanceof TodoStoreError
|
|
3548
|
-
&& ['store_locked', 'artifact_missing'].includes(error.detail.reason)) return;
|
|
3560
|
+
&& ['store_locked', 'artifact_missing', 'store_uninitialized'].includes(error.detail.reason)) return;
|
|
3549
3561
|
throw error;
|
|
3550
3562
|
}
|
|
3551
3563
|
await protocolStage(options, 'authoring_residue_released');
|