@quolu/lattice 0.92.0 → 0.93.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quolu/lattice",
3
- "version": "0.92.0",
3
+ "version": "0.93.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}',
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
- reachable = new Set(gitSync(['rev-list', '--objects', '--all'], {
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,71 @@ 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
+ const store = await readTodoStore({ repoRoot });
4883
+ const anchored = [];
4884
+ const missing = [];
4885
+ const seen = new Set();
4886
+ let already = 0;
4887
+ for (const { evidence, ...owner } of recordedEvidence(store)) {
4888
+ const repo = evidenceRepoRoot(repoRoot, store, evidence);
4889
+ const key = `${repo}\0${evidence.git_blob_oid}`;
4890
+ if (seen.has(key)) continue;
4891
+ seen.add(key);
4892
+ const item = { ...owner, git_blob_oid: evidence.git_blob_oid };
4893
+ if (isTodoEvidenceUncommitted({ repoRoot, store, evidence })) {
4894
+ if (evidenceAnchored(repo, evidence.git_blob_oid)) already += 1;
4895
+ else { anchorEvidenceBlob(repo, evidence.git_blob_oid); anchored.push(item); }
4896
+ continue;
4897
+ }
4898
+ try {
4899
+ gitSync(['cat-file', '-e', evidence.git_blob_oid], { cwd: repo, stdio: 'ignore' });
4900
+ } catch {
4901
+ missing.push(item);
4902
+ }
4903
+ }
4904
+ const result = { schema: 'lattice.todo_evidence_anchor_result.v1', project_id: store.project_id,
4905
+ anchored, already, missing, result_digest: '' };
4906
+ result.result_digest = todoSelfDigest(result, 'result_digest');
4907
+ return result;
4908
+ }
4909
+
4823
4910
  async function verify({ repoRoot, requestedPlanKey }) {
4824
4911
  const store = await readTodoStore({ repoRoot });
4825
4912
  const members = selectMembers(store, requestedPlanKey);
@@ -4835,13 +4922,11 @@ async function verify({ repoRoot, requestedPlanKey }) {
4835
4922
  const pending = member.tasks.filter((task) => task.evidence_unverified
4836
4923
  && isTodoEvidenceUncommitted({ repoRoot, store, evidence: task.evidence }));
4837
4924
  for (const { task_id: taskId, evidence } of pending) {
4838
- uncommittedEvidence.push({ plan_key: planKey, task_id: taskId, repo_id: evidence.repo_id, path: evidence.path,
4839
- next_action: `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.` });
4925
+ uncommittedEvidence.push({ plan_key: planKey, task_id: taskId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
4840
4926
  }
4841
4927
  for (const { phase_id: phaseId, decision_evidence: evidence } of member.phases) {
4842
4928
  if (decisionEvidenceState(repoRoot, store, evidence) !== 'uncommitted') continue;
4843
- uncommittedEvidence.push({ plan_key: planKey, phase_id: phaseId, repo_id: evidence.repo_id, path: evidence.path,
4844
- next_action: `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.` });
4929
+ uncommittedEvidence.push({ plan_key: planKey, phase_id: phaseId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
4845
4930
  }
4846
4931
  const unverified = member.tasks.find((task) => task.evidence_unverified && !pending.includes(task));
4847
4932
  if (unverified !== undefined) {
@@ -5439,6 +5524,9 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5439
5524
  kind: 'unblock', payload: {}, evidenceRef: null,
5440
5525
  }) });
5441
5526
  }
5527
+ } else if (argv[0] === 'evidence' && argv[1] === 'anchor'
5528
+ && matchFlagCommand(argv, ['evidence', 'anchor'], TODO_FLAG_SPECS['evidence anchor']) !== null) {
5529
+ action = (repoRoot) => evidenceAnchor({ repoRoot });
5442
5530
  } else if (argv[0] === 'evidence' && argv[1] === 'promote') {
5443
5531
  const flags = matchFlagCommand(argv, ['evidence', 'promote'], TODO_FLAG_SPECS['evidence promote']);
5444
5532
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
@@ -1115,7 +1115,8 @@ function reachableObjects(absoluteRepo) {
1115
1115
  if (cached !== undefined) return cached;
1116
1116
  let set;
1117
1117
  try {
1118
- const stdout = gitSync(['rev-list', '--objects', '--all'],
1118
+ // evidence-ref: Lattice's evidence anchors (refs/lattice/evidence/*, not seam refs) keep evidence from gc; anchored is not committed.
1119
+ const stdout = gitSync(['rev-list', '--objects', '--exclude=refs/lattice/evidence/*', '--all'],
1119
1120
  { cwd: absoluteRepo, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
1120
1121
  maxBuffer: 256 * 1024 * 1024 });
1121
1122
  set = new Set();