@quolu/lattice 0.98.0 → 0.99.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.98.0",
3
+ "version": "0.99.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
@@ -139,9 +139,10 @@ Write commands:
139
139
  evidence anchor [--json] # 既存の証拠をgcから守る印(refs/lattice/evidence/<oid>)を付ける。commit済みにはならない
140
140
  # done状態と完了時刻を維持し、最新doneへ追記eventで証拠を再束縛する
141
141
  start --plan <key> --task <id> --rebind --reason <text> # 改訂でcarryされたin-progressへ現版のstart束縛を積み直す(ADR 0191)
142
- dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
143
- dependency disconnect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
142
+ dependency connect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
143
+ dependency disconnect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
144
144
  # 開発中に発見した依存を明示接続する。同一plan内の辺はplan本体を軽い改訂で書き換え(plan_versionが変わる)、plan跨ぎは台帳に積む。依存の自動推定は行わない
145
+ # --from-project = 別の工程表(別プロジェクト)の工程を前工程にする。LATTICE_CHARTS_ROOT/<project_id>/.lattice を読むだけで書かない。読めない間は待ちのまま
145
146
  independence mode --plan <key> --set <witness|conversation|enforced> --reason <text>
146
147
  # enforced = witness+未宣言・古い宣言・衝突・参照なしdone・heavy段階の監査なし閉じを止める(ADR 0200)
147
148
  # このplanの調整方式(witness検証で並列するか、会話で調整するか)を記録する
@@ -352,11 +353,11 @@ const SUBCOMMAND_USAGE = Object.freeze({
352
353
  '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',
353
354
  'todo evidence promote': 'todo evidence promote --plan <key> --task <id> --evidence <file>',
354
355
  'todo dependency': [
355
- 'todo dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
356
- 'todo dependency disconnect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
356
+ 'todo dependency connect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
357
+ 'todo dependency disconnect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
357
358
  ].join('\n lattice '),
358
- 'todo dependency connect': 'todo dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
359
- 'todo dependency disconnect': 'todo dependency disconnect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
359
+ 'todo dependency connect': 'todo dependency connect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
360
+ 'todo dependency disconnect': 'todo dependency disconnect [--from-project <id>] --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>',
360
361
  'todo split': 'todo split --plan <key> --input <file>',
361
362
  'todo revise': 'todo revise --plan <key> --input <file> | --schema --json',
362
363
  'todo revise-phase': 'todo revise-phase --plan <key> --input <file> | --schema --json',
@@ -1,3 +1,4 @@
1
+ import { withTodoExternalTasks } from './todo-external.mjs';
1
2
  import { gitSync } from './git-process.mjs';
2
3
  import { constants as fsConstants } from 'node:fs';
3
4
  import { lstat, open } from 'node:fs/promises';
@@ -240,7 +241,7 @@ function invalidStatus({ cliVersion, repoRoot, reason, nextAction = null }) {
240
241
  * store読みはここでしか行わない——session開始経路が同じstoreを二度払っていたのが
241
242
  * ADR 0131で直した欠陥である。
242
243
  */
243
- async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts = false }) {
244
+ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts = false, env = process.env }) {
244
245
  const repoRoot = resolveRepoRoot(cwd);
245
246
  if (repoRoot === null) {
246
247
  return { exitCode: 1, repoRoot: null, store: null, todo: null,
@@ -290,7 +291,8 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
290
291
  return invalid('store_layout_invalid');
291
292
  }
292
293
  try {
293
- const store = await readTodoStore({ repoRoot });
294
+ // xchart: predecessors on other charts count for next_ready here too.
295
+ const store = await withTodoExternalTasks(await readTodoStore({ repoRoot }), env);
294
296
  if (diagnoseStructureArtifacts) {
295
297
  const diagnostics = await readTodoStructureArtifactDiagnostics({ repoRoot, store });
296
298
  if (diagnostics.length > 0) {
@@ -362,7 +364,7 @@ export async function runProjectStatus({ cwd, stdout, stderr = process.stderr, c
362
364
  ensureDashboardActivity = ensureTodoDashboardActivity,
363
365
  reportDelivery = reportProjectDashboardDelivery }) {
364
366
  const state = await resolveProjectState({
365
- cwd, cliVersion, diagnoseStructureArtifacts: true,
367
+ cwd, cliVersion, diagnoseStructureArtifacts: true, env,
366
368
  });
367
369
  // dashboard活動の登録はdiscovery面の副作用として維持する(ADR 0131 Decision 4で
368
370
  // session-context側だけが持たない、と決めた面である)。
@@ -431,7 +433,7 @@ export function projectTurn({ store, todo, actor, reason = 'store_unavailable' }
431
433
  * dashboard活動の登録は行わない。現在地を知るために呼ぶ面であり、常駐面を起こす面ではない。
432
434
  */
433
435
  export async function runSessionContext({ cwd, stdout, cliVersion, env = process.env }) {
434
- const state = await resolveProjectState({ cwd, cliVersion });
436
+ const state = await resolveProjectState({ cwd, cliVersion, env });
435
437
  const independence = state.store === null || state.todo === null
436
438
  ? [] : await summarizeIndependence({ repoRoot: state.repoRoot, store: state.store, todo: state.todo });
437
439
  const result = {
package/src/todo-cli.mjs CHANGED
@@ -171,6 +171,9 @@ import {
171
171
  import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
172
172
  import { collectSensorEvidence } from './sensor-adapter.mjs';
173
173
  import { newTodoNotices, projectTodoNotices, waitInEffect } from './todo-notices.mjs';
174
+ import {
175
+ externalCycle, readTodoExternalChart, readTodoExternalTasks, withTodoExternalTasks,
176
+ } from './todo-external.mjs';
174
177
  import { projectTodoBlockers, todoBlockerKey } from './todo-blockers.mjs';
175
178
  import {
176
179
  ackTodoNotices, cancelTodoNoticeWait, readAllTodoNoticeAcks, readAllTodoNoticeWaits, readTodoNoticeAcks, writeTodoNoticeWait,
@@ -330,7 +333,7 @@ const REASON_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'reason'], requ
330
333
  const PHASE_REASON_FLAG_SPEC = Object.freeze({ known: ['plan', 'phase', 'reason'], required: ['plan', 'phase', 'reason'] });
331
334
  const NOTE_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'message', 'input', 'supersedes'], required: ['plan'] });
332
335
  const DEPENDENCY_FLAG_SPEC = Object.freeze({
333
- known: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
336
+ known: ['from-project', 'from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
334
337
  required: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
335
338
  });
336
339
  // a18: one spec per write command is both its parser and the explanation of its refusal.
@@ -406,7 +409,8 @@ function repairedCommand(head, spec, flags) {
406
409
  /** `dependency connect|disconnect` flags by name (order-free), or null. */
407
410
  function dependencyFlags(argv) {
408
411
  const flags = matchFlagCommand(argv, argv.slice(0, 2), DEPENDENCY_FLAG_SPEC);
409
- return flags !== null && IDENTIFIER_FLAGS.slice(3).every((name) => isTodoIdentifier(flags[name])) ? flags : null;
412
+ return flags !== null && IDENTIFIER_FLAGS.slice(3).every((name) => isTodoIdentifier(flags[name]))
413
+ && (flags['from-project'] === undefined || isTodoIdentifier(flags['from-project'])) ? flags : null;
410
414
  }
411
415
 
412
416
  /** a28: a read command's flags by name (order-free, --json optional) with valid identifiers, or null. */
@@ -975,9 +979,14 @@ function reopenAdvisory(plan, phases, taskId) {
975
979
  async function mutate({
976
980
  repoRoot, env, planKey, taskId, kind, payload, evidenceRef, evidenceMessage = null,
977
981
  advisory = null, noteContext = null, structureContext = null, featureContext = null,
978
- testResultRef = null, actor: carriedActor = null,
982
+ testResultRef = null, actor: carriedActor = null, externalTasks = null,
979
983
  }) {
980
984
  const actor = carriedActor ?? resolveTodoActor(env);
985
+ // xchart: start and authored done check predecessors on other charts too, read before the lock.
986
+ const external = externalTasks ?? (kind === 'start' || (kind === 'done' && payload === 'authored')
987
+ ? (await readTodoExternalTasks(await readTodoStore({ repoRoot }), env)).external_tasks : []);
988
+ const validator = external.length === 0 ? validateProspectiveEvent
989
+ : (input) => validateProspectiveEvent({ ...input, store: { ...input.store, external_tasks: external } });
981
990
  const evidence = evidenceRef === null && evidenceMessage === null
982
991
  ? null
983
992
  : await resolveDoneEvidence({
@@ -1005,7 +1014,7 @@ async function mutate({
1005
1014
  eventPayload = { done_mode: 'evidence_promotion', evidence };
1006
1015
  }
1007
1016
  const { event, snapshot, plan, phases } = await appendTodoEvent({
1008
- validateProspectiveEvent,
1017
+ validateProspectiveEvent: validator,
1009
1018
  repoRoot,
1010
1019
  writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
1011
1020
  planKey,
@@ -1389,10 +1398,22 @@ async function startAdvisory({ repoRoot, store, projection, planKey, taskId }) {
1389
1398
  };
1390
1399
  }
1391
1400
 
1401
+ /** xchart: the display envelope plus `external_tasks`, so a host computing readiness from it sees other charts too. */
1402
+ async function displayRead(repoRoot, env) {
1403
+ const display = await readTodoStoreForDisplay({ repoRoot });
1404
+ const externalTasks = display.store ? (await readTodoExternalTasks(display.store, env)).external_tasks : [];
1405
+ return { schema: 'lattice.todo_display_read_result.v1', ...display, external_tasks: externalTasks };
1406
+ }
1407
+
1408
+ /** xchart: the Store plus its external predecessors' states; every readiness reader reads through this. */
1409
+ async function readTodoStoreForReadiness({ repoRoot, env = process.env }) {
1410
+ return withTodoExternalTasks(await readTodoStore({ repoRoot }), env);
1411
+ }
1412
+
1392
1413
  async function startTask({
1393
1414
  repoRoot, env, planKey, taskId, overrideReason,
1394
1415
  }) {
1395
- const store = await readTodoStore({ repoRoot });
1416
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
1396
1417
  // startはready判定にしかprojectionを使わず、resultを出力しない。
1397
1418
  const projection = projectTodoStatus(store, TODO_STATUS_DISPATCH_ONLY);
1398
1419
  const readyTask = projection.next_ready.find((task) => (
@@ -1461,7 +1482,7 @@ async function startTask({
1461
1482
  }
1462
1483
  return mutate({ repoRoot, env, planKey, taskId: resolvedTaskId, kind: 'start',
1463
1484
  payload: { override_reason: overrideReason }, evidenceRef: null, advisory, noteContext,
1464
- structureContext, featureContext });
1485
+ structureContext, featureContext, externalTasks: store.external_tasks ?? [] });
1465
1486
  }
1466
1487
 
1467
1488
  /** declare-without-git: HEAD does not resolve (no commit) and the plan's witness set records this task's row. */
@@ -1872,9 +1893,11 @@ const samePlanEdge = (member, fromTaskId, toTaskId) => member.plan.hard_dependen
1872
1893
  * consumer planのplan-scoped chainへ。
1873
1894
  */
1874
1895
  async function dependencyConnect(options) {
1875
- const { repoRoot, env, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason } = options;
1876
- if (fromPlanKey !== toPlanKey) return dependencyConnectLedger(options);
1896
+ const { repoRoot, env, fromProjectId = null, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason } = options;
1877
1897
  const store = await readTodoStore({ repoRoot });
1898
+ // xchart: --from-project omitted or this project = the in-chart routes below, unchanged.
1899
+ if (fromProjectId !== null && fromProjectId !== store.project_id) return dependencyConnectExternal({ ...options, store });
1900
+ if (fromPlanKey !== toPlanKey) return dependencyConnectLedger(options);
1878
1901
  const member = store.members.find(({ plan }) => plan.plan_key === fromPlanKey);
1879
1902
  const tasks = member?.plan.tasks ?? [];
1880
1903
  // 台帳経路と同じ事前検査(plan不在・task不在・自己辺・既存辺・完了済み終点)の拒否を保つ。
@@ -1897,15 +1920,15 @@ async function dependencyConnect(options) {
1897
1920
  }
1898
1921
 
1899
1922
  /** A live ledger edge with these endpoints (cross-plan, or an earlier same-plan connect). */
1900
- function liveLedgerEdge(store, { fromPlanKey, fromTaskId, toPlanKey, toTaskId }) {
1923
+ function liveLedgerEdge(store, { fromProjectId = null, fromPlanKey, fromTaskId, toPlanKey, toTaskId }) {
1901
1924
  return projectTodoCrossPlanDependencies(store.members).some((dependency) => (
1902
- dependency.from.plan_key === fromPlanKey && dependency.from.task_id === fromTaskId
1925
+ dependency.from.project_id === (fromProjectId ?? store.project_id) && dependency.from.plan_key === fromPlanKey && dependency.from.task_id === fromTaskId
1903
1926
  && dependency.to.plan_key === toPlanKey && dependency.to.task_id === toTaskId));
1904
1927
  }
1905
1928
 
1906
1929
  /** a28: connect of an existing edge succeeds unchanged, like a repeated done/block/retire (a12). */
1907
- function dependencyUnchanged(store, { fromPlanKey, fromTaskId, toPlanKey, toTaskId }) {
1908
- const from = { project_id: store.project_id, plan_key: fromPlanKey, task_id: fromTaskId };
1930
+ function dependencyUnchanged(store, { fromProjectId = null, fromPlanKey, fromTaskId, toPlanKey, toTaskId }) {
1931
+ const from = { project_id: fromProjectId ?? store.project_id, plan_key: fromPlanKey, task_id: fromTaskId };
1909
1932
  const to = { project_id: store.project_id, plan_key: toPlanKey, task_id: toTaskId };
1910
1933
  const result = {
1911
1934
  schema: 'lattice.todo_dependency_unchanged_result.v1', project_id: store.project_id,
@@ -1954,9 +1977,13 @@ async function dependencyConnectLedger({
1954
1977
  project_id: store.project_id, plan_key: toPlanKey, task_id: toTaskId,
1955
1978
  expected_topology_digest: target.plan.topology_digest,
1956
1979
  };
1980
+ return appendLedgerEdge({ repoRoot, env, store, from, to, reason });
1981
+ }
1982
+
1983
+ async function appendLedgerEdge({ repoRoot, env, store, from, to, reason }) {
1957
1984
  const { event } = await appendTodoEvent({
1958
1985
  validateProspectiveEvent,
1959
- repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey: toPlanKey,
1986
+ repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey: to.plan_key,
1960
1987
  event: {
1961
1988
  kind: 'cross_plan_dependency', actor: resolveTodoActor(env), payload: { from, to, reason },
1962
1989
  },
@@ -1972,9 +1999,54 @@ async function dependencyConnectLedger({
1972
1999
  return result;
1973
2000
  }
1974
2001
 
2002
+ /**
2003
+ * xchart: wait on a task of another chart. The other chart is read read-only (plan, task, topology, cycle);
2004
+ * the edge is the existing ledger event on this chart's to-plan, nothing is written there.
2005
+ */
2006
+ async function dependencyConnectExternal({
2007
+ repoRoot, env, store, fromProjectId, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason,
2008
+ }) {
2009
+ const target = store.members.find(({ plan }) => plan.plan_key === toPlanKey);
2010
+ if (target === undefined) {
2011
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'dependency_plan_not_found', undefined, { plan_key: toPlanKey });
2012
+ }
2013
+ if (!target.plan.tasks.some(({ task_id: taskId }) => taskId === toTaskId)) {
2014
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'dependency_task_not_found', undefined, {
2015
+ plan_key: toPlanKey, task_id: toTaskId,
2016
+ });
2017
+ }
2018
+ const endpoints = { fromProjectId, fromPlanKey, fromTaskId, toPlanKey, toTaskId };
2019
+ if (liveLedgerEdge(store, endpoints)) return dependencyUnchanged(store, endpoints);
2020
+ const other = await readTodoExternalChart(env, fromProjectId);
2021
+ const source = other.members.find(({ plan }) => plan.plan_key === fromPlanKey);
2022
+ if (source === undefined) {
2023
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'dependency_plan_not_found', undefined, {
2024
+ project_id: fromProjectId, plan_key: fromPlanKey,
2025
+ });
2026
+ }
2027
+ if (!source.plan.tasks.some(({ task_id: taskId }) => taskId === fromTaskId)) {
2028
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'dependency_task_not_found', undefined, {
2029
+ project_id: fromProjectId, plan_key: fromPlanKey, task_id: fromTaskId,
2030
+ });
2031
+ }
2032
+ const from = { project_id: fromProjectId, plan_key: fromPlanKey, task_id: fromTaskId,
2033
+ expected_topology_digest: source.plan.topology_digest };
2034
+ const to = { project_id: store.project_id, plan_key: toPlanKey, task_id: toTaskId,
2035
+ expected_topology_digest: target.plan.topology_digest };
2036
+ const cycle = await externalCycle({ env, fromStore: other, from, to, localStore: store });
2037
+ if (cycle !== null) {
2038
+ throw new TodoStoreError('DEPENDENCY_CYCLE', 'cross_plan_dependency_cycle', undefined, { from, to, cycle });
2039
+ }
2040
+ return appendLedgerEdge({ repoRoot, env, store, from, to, reason });
2041
+ }
2042
+
1975
2043
  // connectの対。同一planでplan本体が持つ辺は軽量改訂で外し(a14)、それ以外は台帳の除去へ。
1976
2044
  async function dependencyDisconnect(options) {
1977
2045
  const { repoRoot, env, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason } = options;
2046
+ // xchart: --from-project equal to this project is the in-chart route.
2047
+ const fromProjectId = options.fromProjectId === null || options.fromProjectId === undefined
2048
+ || options.fromProjectId === (await readTodoStore({ repoRoot })).project_id ? null : options.fromProjectId;
2049
+ if (fromProjectId !== null) return dependencyDisconnectLedger({ ...options, fromProjectId });
1978
2050
  if (fromPlanKey === toPlanKey) {
1979
2051
  const store = await readTodoStore({ repoRoot });
1980
2052
  const member = store.members.find(({ plan }) => plan.plan_key === fromPlanKey);
@@ -1989,17 +2061,17 @@ async function dependencyDisconnect(options) {
1989
2061
  // 誤って張った線の除去(tombstone)。端点で一意に生きた接続を特定し、
1990
2062
  // その接続eventが積まれているplanのplan-scoped chainへ除去eventを積む。
1991
2063
  async function dependencyDisconnectLedger({
1992
- repoRoot, env, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason,
2064
+ repoRoot, env, fromProjectId = null, fromPlanKey, fromTaskId, toPlanKey, toTaskId, reason,
1993
2065
  }) {
1994
2066
  const store = await readTodoStore({ repoRoot });
1995
2067
  const live = projectTodoCrossPlanDependencies(store.members).filter((dependency) => (
1996
- dependency.from.plan_key === fromPlanKey && dependency.from.task_id === fromTaskId
2068
+ dependency.from.project_id === (fromProjectId ?? store.project_id) && dependency.from.plan_key === fromPlanKey && dependency.from.task_id === fromTaskId
1997
2069
  && dependency.to.plan_key === toPlanKey && dependency.to.task_id === toTaskId
1998
2070
  ));
1999
2071
  if (live.length === 0) {
2000
- const from = { plan_key: fromPlanKey, task_id: fromTaskId };
2072
+ const from = { ...(fromProjectId === null ? {} : { project_id: fromProjectId }), plan_key: fromPlanKey, task_id: fromTaskId };
2001
2073
  const to = { plan_key: toPlanKey, task_id: toTaskId };
2002
- if (fromPlanKey === toPlanKey) {
2074
+ if (fromPlanKey === toPlanKey && fromProjectId === null) {
2003
2075
  const member = store.members.find(({ plan }) => plan.plan_key === toPlanKey);
2004
2076
  const predecessors = (member?.plan.hard_dependencies ?? [])
2005
2077
  .filter((edge) => edge.to.task_id === toTaskId).map((edge) => edge.from.task_id).sort();
@@ -2607,7 +2679,7 @@ async function splitTodo({ repoRoot, env, planKey, inputRef }) {
2607
2679
  return result;
2608
2680
  }
2609
2681
 
2610
- async function status({ repoRoot }) {
2682
+ async function status({ repoRoot, env }) {
2611
2683
  // No plan yet is an empty project, not a broken store: answer zero plans and how to make one.
2612
2684
  if (await isUninitializedTodoStore({ repoRoot })) {
2613
2685
  const result = {
@@ -2619,7 +2691,7 @@ async function status({ repoRoot }) {
2619
2691
  result.result_digest = todoSelfDigest(result, 'result_digest');
2620
2692
  return result;
2621
2693
  }
2622
- const store = await readTodoStore({ repoRoot });
2694
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
2623
2695
  const result = projectTodoStatus(store, {
2624
2696
  planNotes: await readTodoPlanNotesForStatus({ repoRoot, store }),
2625
2697
  parallelCandidates: await readTodoParallelCandidatesForStatus({
@@ -2650,8 +2722,8 @@ async function adoptDashboardRoot({ repoRoot, env }) {
2650
2722
  return result;
2651
2723
  }
2652
2724
 
2653
- async function todoDetail({ repoRoot, planKey, taskId }) {
2654
- const store = await readTodoStore({ repoRoot });
2725
+ async function todoDetail({ repoRoot, env, planKey, taskId }) {
2726
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
2655
2727
  const [member] = selectMembers(store, planKey);
2656
2728
  const task = selectNoteTask(member, taskId);
2657
2729
  const state = member.tasks.find(({ task_id: current }) => current === task.task_id);
@@ -2671,6 +2743,7 @@ async function todoDetail({ repoRoot, planKey, taskId }) {
2671
2743
  task: { ...task, done_condition: task.done_condition ?? null },
2672
2744
  design_memo: designMemoProjection(task),
2673
2745
  state,
2746
+ prerequisites: taskPrerequisites(store, member, task.task_id),
2674
2747
  note_context: context,
2675
2748
  ...(featureContext === null ? {} : { feature_context: featureContext }),
2676
2749
  result_digest: '',
@@ -2679,6 +2752,15 @@ async function todoDetail({ repoRoot, planKey, taskId }) {
2679
2752
  return result;
2680
2753
  }
2681
2754
 
2755
+ /** xchart: what a task waits on, by the readiness predicate (`ready` is the start path's own answer). */
2756
+ function taskPrerequisites(store, member, taskId) {
2757
+ const readiness = createTodoReadiness(store);
2758
+ const key = readiness.key({ ...member.plan, task_id: taskId });
2759
+ const { blocking } = readiness.prerequisites(key);
2760
+ return { ready: readiness.isReady(key), tasks: readiness.prerequisiteRefs(key).tasks,
2761
+ blocking_tasks: blocking.blocking_tasks ?? [], blocking_phases: blocking.blocking_phases ?? [] };
2762
+ }
2763
+
2682
2764
  /**
2683
2765
  * `taskId === null`はplan単位note。task noteと違い宛先taskが無いので、
2684
2766
  * 訂正できる相手はplan noteだけ、返すcontextも特定taskのものにできない。
@@ -3882,8 +3964,8 @@ function declaredStartHint(store, member, state) {
3882
3964
  * a40: one task's witness row, declared by its member. Rows nobody declared stay out (an empty row
3883
3965
  * would claim "touches nothing"); compile runs once every ready task is declared.
3884
3966
  */
3885
- async function witnessDeclare({ repoRoot, planKey, flags }) {
3886
- const store = await readTodoStore({ repoRoot });
3967
+ async function witnessDeclare({ repoRoot, env, planKey, flags }) {
3968
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
3887
3969
  const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
3888
3970
  if (member === undefined) throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
3889
3971
  const taskId = flags.task;
@@ -3910,7 +3992,7 @@ async function witnessDeclare({ repoRoot, planKey, flags }) {
3910
3992
  pointer: at, ...keys, next_action: witnessRoute(planKey) });
3911
3993
  }
3912
3994
  const scaffolded = await scaffoldWitnessDraft({ repoRoot, planKey, draft });
3913
- const waitingFor = projectTodoStatus(await readTodoStore({ repoRoot }), TODO_STATUS_DISPATCH_ONLY).next_ready
3995
+ const waitingFor = projectTodoStatus(await readTodoStoreForReadiness({ repoRoot, env }), TODO_STATUS_DISPATCH_ONLY).next_ready
3914
3996
  .filter((task) => task.plan_key === planKey && !keep.has(task.task_id))
3915
3997
  .map(({ task_id: id }) => id).sort();
3916
3998
  // declare-without-git: a Store root with no commit cannot be observed, so the row is recorded and not compiled.
@@ -4408,8 +4490,8 @@ export async function renderTodoGanttForProject({
4408
4490
  repoRoot, stable = false, displayName = null, env = process.env, readModel = null,
4409
4491
  scope = DEFAULT_GANTT_SCOPE, degraded = false,
4410
4492
  }) {
4411
- const store = readModel
4412
- ?? (stable ? await readTodoStoreStable({ repoRoot }) : await readTodoStore({ repoRoot }));
4493
+ const store = await withTodoExternalTasks(readModel
4494
+ ?? (stable ? await readTodoStoreStable({ repoRoot }) : await readTodoStore({ repoRoot })), env);
4413
4495
  const identity = displayName === null
4414
4496
  ? await resolveProjectIdentity({ repoRoot, projectId: store.project_id, env })
4415
4497
  : { displayName };
@@ -4696,8 +4778,8 @@ async function blockerList({ repoRoot }) {
4696
4778
  }
4697
4779
 
4698
4780
  /** Open notices with their waiters (wait-design); an unreadable wait file is named, its waits read as none. */
4699
- async function openNoticeView(repoRoot) {
4700
- const store = await readTodoStore({ repoRoot });
4781
+ async function openNoticeView(repoRoot, env) {
4782
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
4701
4783
  const declared = await declaredWitnessRows(repoRoot, store);
4702
4784
  const stored = await readAllTodoNoticeWaits({ repoRoot });
4703
4785
  // Readers return raw records: waits that ended since the file's last write are dropped here.
@@ -4709,8 +4791,8 @@ async function openNoticeView(repoRoot) {
4709
4791
  return { store, notices, waitUnreadable: stored.unreadable };
4710
4792
  }
4711
4793
 
4712
- async function openNotices(repoRoot) {
4713
- return (await openNoticeView(repoRoot)).notices;
4794
+ async function openNotices(repoRoot, env) {
4795
+ return (await openNoticeView(repoRoot, env)).notices;
4714
4796
  }
4715
4797
 
4716
4798
  /** lane -> notice_id -> [{waiting_digest, recipients}] from ack set records. */
@@ -4737,12 +4819,12 @@ function withAckState(notice, index) {
4737
4819
  const noticeRecipients = (notice) => [...new Set([notice.lane, ...notice.waiting.map(({ agent }) => agent)])].sort();
4738
4820
 
4739
4821
  /** A committed write is never undone for its notices: an unreadable projection says so and `notice list` recovers. */
4740
- async function withNotices(repoRoot, result, before) {
4822
+ async function withNotices(repoRoot, result, before, env) {
4741
4823
  if (result === null || typeof result !== 'object' || typeof result.result_digest !== 'string') return result;
4742
4824
  let extra;
4743
4825
  try {
4744
4826
  if (before === null) throw new Error('notices_before_unreadable');
4745
- const released = newTodoNotices(before, await openNotices(repoRoot));
4827
+ const released = newTodoNotices(before, await openNotices(repoRoot, env));
4746
4828
  // An unreadable ack set only means nobody counts as covered yet: delivery repeats, nothing is lost.
4747
4829
  const index = ackIndex(released.length === 0 ? []
4748
4830
  : await readAllTodoNoticeAcks({ repoRoot }).then(({ acks }) => acks, () => []));
@@ -4768,8 +4850,8 @@ function noticeAckRefusal(error, lane) {
4768
4850
  }
4769
4851
 
4770
4852
  /** `todo notice list`: open notices, unacked unless asked; one unreadable ack file never hides the rest. */
4771
- async function noticeList({ repoRoot, lane, includeAcked }) {
4772
- const view = await openNoticeView(repoRoot);
4853
+ async function noticeList({ repoRoot, env, lane, includeAcked }) {
4854
+ const view = await openNoticeView(repoRoot, env);
4773
4855
  const open = view.notices.filter((notice) => lane === null || notice.lane === lane);
4774
4856
  const records = [];
4775
4857
  const ackUnreadable = [];
@@ -4798,7 +4880,7 @@ async function noticeList({ repoRoot, lane, includeAcked }) {
4798
4880
 
4799
4881
  /** `todo notice ack`: an id that is no longer open is reported as closed, never refused (nothing is left to ack). */
4800
4882
  async function noticeAck({ repoRoot, env, lane, ids }) {
4801
- const view = await openNoticeView(repoRoot);
4883
+ const view = await openNoticeView(repoRoot, env);
4802
4884
  const laneNotices = view.notices.filter((notice) => notice.lane === lane);
4803
4885
  const openIds = laneNotices.map(({ notice_id: id }) => id);
4804
4886
  const open = new Set(openIds);
@@ -4824,7 +4906,7 @@ async function noticeAck({ repoRoot, env, lane, ids }) {
4824
4906
  * gate: an already startable or finished T is answered with a state and nothing is written.
4825
4907
  */
4826
4908
  async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
4827
- const view = await openNoticeView(repoRoot);
4909
+ const view = await openNoticeView(repoRoot, env);
4828
4910
  const { store } = view;
4829
4911
  const member = store.members.find(({ plan }) => plan.plan_key === planKey);
4830
4912
  if (member === undefined) throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
@@ -5196,7 +5278,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5196
5278
  action = (repoRoot) => repairStoreEol({ repoRoot });
5197
5279
  } else if ((argv.length === 1 && argv[0] === 'status')
5198
5280
  || (argv.length === 2 && argv[0] === 'status' && argv[1] === '--json')) {
5199
- action = (repoRoot) => status({ repoRoot });
5281
+ action = (repoRoot) => status({ repoRoot, env });
5200
5282
  } else if (argv.length === 3 && argv[0] === 'dashboard'
5201
5283
  && argv[1] === 'adopt' && argv[2] === '--json') {
5202
5284
  action = (repoRoot) => adoptDashboardRoot({ repoRoot, env });
@@ -5213,7 +5295,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5213
5295
  };
5214
5296
  } else if (argv[0] === 'show' && readFlags(argv, ['show']) !== null) {
5215
5297
  const flags = readFlags(argv, ['show']);
5216
- action = (repoRoot) => todoDetail({ repoRoot, planKey: flags.plan, taskId: flags.task });
5298
+ action = (repoRoot) => todoDetail({ repoRoot, env, planKey: flags.plan, taskId: flags.task });
5217
5299
  } else if ((argv.length === 1 && argv[0] === 'bindings')
5218
5300
  || (argv.length === 2 && argv[0] === 'bindings' && argv[1] === '--json')) {
5219
5301
  action = (repoRoot) => bindings({ repoRoot, requestedPlanKey: null });
@@ -5225,7 +5307,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5225
5307
  && (argv.length === 2 || (argv.length === 3 && argv[2] === '--json'))) {
5226
5308
  // Host display read (BellTeam module): a typed inconsistency is a state, never a refusal.
5227
5309
  action = argv[1] === 'read'
5228
- ? async (repoRoot) => ({ schema: 'lattice.todo_display_read_result.v1', ...await readTodoStoreForDisplay({ repoRoot }) })
5310
+ ? async (repoRoot) => displayRead(repoRoot, env)
5229
5311
  : (repoRoot) => readTodoStoreDisplaySource({ repoRoot });
5230
5312
  } else if (argv[0] === 'note' && argv[1] !== 'list') {
5231
5313
  const flags = matchFlagCommand(argv, ['note'], NOTE_FLAG_SPEC);
@@ -5247,7 +5329,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5247
5329
  && matchFlagCommand(argv, ['notice', 'list'], TODO_FLAG_SPECS['notice list']) !== null) {
5248
5330
  const flags = matchFlagCommand(argv, ['notice', 'list'], TODO_FLAG_SPECS['notice list']);
5249
5331
  if (flags.lane === undefined || isNoticeLane(flags.lane)) {
5250
- action = (repoRoot) => noticeList({ repoRoot, lane: flags.lane ?? null, includeAcked: flags['include-acked'] === true });
5332
+ action = (repoRoot) => noticeList({ repoRoot, env, lane: flags.lane ?? null, includeAcked: flags['include-acked'] === true });
5251
5333
  }
5252
5334
  } else if (argv[0] === 'notice' && argv[1] === 'ack'
5253
5335
  && matchFlagCommand(argv, ['notice', 'ack'], TODO_FLAG_SPECS['notice ack']) !== null) {
@@ -5284,14 +5366,14 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5284
5366
  && dependencyFlags(argv) !== null) {
5285
5367
  const flags = dependencyFlags(argv);
5286
5368
  action = (repoRoot) => dependencyConnect({
5287
- repoRoot, env, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5369
+ repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5288
5370
  toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
5289
5371
  });
5290
5372
  } else if (argv[0] === 'dependency' && argv[1] === 'disconnect'
5291
5373
  && dependencyFlags(argv) !== null) {
5292
5374
  const flags = dependencyFlags(argv);
5293
5375
  action = (repoRoot) => dependencyDisconnect({
5294
- repoRoot, env, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5376
+ repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5295
5377
  toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
5296
5378
  });
5297
5379
  } else if (argv[0] === 'independence' && argv[1] === 'compile') {
@@ -5362,7 +5444,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5362
5444
  const flags = matchFlagCommand(argv, ['independence', 'witness', 'declare'],
5363
5445
  TODO_FLAG_SPECS['independence witness declare']);
5364
5446
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
5365
- action = (repoRoot) => witnessDeclare({ repoRoot, planKey: flags.plan, flags });
5447
+ action = (repoRoot) => witnessDeclare({ repoRoot, env, planKey: flags.plan, flags });
5366
5448
  }
5367
5449
  } else if (argv[0] === 'independence' && argv[1] === 'witness' && argv[2] === 'scaffold') {
5368
5450
  const flags = matchFlagCommand(argv, ['independence', 'witness', 'scaffold'],
@@ -5647,11 +5729,11 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5647
5729
  if (writesTodoStore(argv)) {
5648
5730
  await ensureActiveProjectDashboard({ repoRoot, env, stderr });
5649
5731
  }
5650
- const before = releasesTasks(argv) ? await openNotices(repoRoot).catch(() => null) : null;
5732
+ const before = releasesTasks(argv) ? await openNotices(repoRoot, env).catch(() => null) : null;
5651
5733
  const written = atomicCommit
5652
5734
  ? await commitTodoStoreMutation({ repoRoot, argv, action, env })
5653
5735
  : await action(repoRoot);
5654
- const result = releasesTasks(argv) ? await withNotices(repoRoot, written, before) : written;
5736
+ const result = releasesTasks(argv) ? await withNotices(repoRoot, written, before, env) : written;
5655
5737
  if (result !== null) stdout.write(`${plainVerify ? verifyVerdictLine(result) : JSON.stringify(result)}\n`);
5656
5738
  return 0;
5657
5739
  } catch (error) {
@@ -0,0 +1,125 @@
1
+ // Cross-chart predecessors (xchart, docs/architecture/dfd-plan-revise.md#cross-chart-dependency-xchart-2026-11-13):
2
+ // a ledger edge whose `from` is a task of another chart (another project's Store under LATTICE_CHARTS_ROOT).
3
+ // Plan reads the other chart read-only; an unreadable one only keeps its waiters waiting.
4
+
5
+ import path from 'node:path';
6
+
7
+ import { createTodoReadiness } from './todo-readiness.mjs';
8
+ import { isFinishedTodoTaskState, projectTodoCrossPlanDependencies } from './todo-store-view.mjs';
9
+ import { readTodoStoreReadOnly, TodoStoreError } from './todo-store.mjs';
10
+
11
+ export const TODO_CHARTS_ROOT_ENV = 'LATTICE_CHARTS_ROOT';
12
+
13
+ /** Live ledger edges of `store` whose predecessor is on another chart. */
14
+ export function externalTodoDependencies(store) {
15
+ return projectTodoCrossPlanDependencies(store.members)
16
+ .filter(({ from }) => from.project_id !== store.project_id);
17
+ }
18
+
19
+ /** The other chart's Store, or a reason it cannot be read: `{store}` | `{reason, path}`. Never throws. */
20
+ async function readChart(env, projectId) {
21
+ const root = env?.[TODO_CHARTS_ROOT_ENV];
22
+ if (typeof root !== 'string' || root === '') return { reason: 'charts_root_unset', path: null };
23
+ // project ids are identifiers (no separators), so the join stays inside the root.
24
+ const chartPath = path.join(path.resolve(root), projectId);
25
+ try {
26
+ const store = await readTodoStoreReadOnly({ repoRoot: chartPath });
27
+ // A chart that says it is another project is the wrong target, not this one.
28
+ return store.project_id === projectId ? { store } : { reason: 'chart_unreadable', path: chartPath };
29
+ } catch {
30
+ return { reason: 'chart_unreadable', path: chartPath };
31
+ }
32
+ }
33
+
34
+ /** Connect-time read: the other chart's Store, or a refusal that names the env var or the chart. */
35
+ export async function readTodoExternalChart(env, projectId) {
36
+ const chart = await readChart(env, projectId);
37
+ if (chart.store !== undefined) return chart.store;
38
+ if (chart.reason === 'charts_root_unset') {
39
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'charts_root_unset', undefined, {
40
+ project_id: projectId,
41
+ next_action: `Set ${TODO_CHARTS_ROOT_ENV} to the directory whose children are chart directories named by`
42
+ + ` project id (${projectId} is read from <${TODO_CHARTS_ROOT_ENV}>/${projectId}/.lattice), then connect again.`,
43
+ });
44
+ }
45
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'chart_unreadable', undefined, {
46
+ project_id: projectId, path: chart.path,
47
+ next_action: `No readable Lattice chart for project ${projectId} at ${chart.path}; check the project id`
48
+ + ` (\`lattice status --json\` in that chart) and ${TODO_CHARTS_ROOT_ENV}.`,
49
+ });
50
+ }
51
+
52
+ function taskTrigger(member, taskId) {
53
+ const event = member.journal.events.findLast((entry) => entry.task_id === taskId);
54
+ return event === undefined ? null
55
+ : { kind: event.kind, event_digest: event.event_digest, recorded_at: event.recorded_at, actor: event.actor ?? null };
56
+ }
57
+
58
+ /**
59
+ * The states of every external predecessor of `store`, one read per other project:
60
+ * `{external_tasks, findings}`; nothing is read when there is no external edge.
61
+ */
62
+ export async function readTodoExternalTasks(store, env) {
63
+ const dependencies = externalTodoDependencies(store);
64
+ const charts = new Map();
65
+ for (const { from } of dependencies) {
66
+ if (!charts.has(from.project_id)) charts.set(from.project_id, await readChart(env, from.project_id));
67
+ }
68
+ const tasks = new Map();
69
+ const findings = [];
70
+ for (const dependency of dependencies) {
71
+ const { from } = dependency;
72
+ const chart = charts.get(from.project_id);
73
+ const member = chart.store?.members.find(({ plan }) => plan.plan_key === from.plan_key);
74
+ const state = member?.tasks.find(({ task_id: id }) => id === from.task_id);
75
+ const reason = chart.store === undefined ? chart.reason : state === undefined ? 'endpoint_missing' : null;
76
+ if (reason !== null) {
77
+ findings.push({ owner_plan_key: dependency.to.plan_key, event_digest: dependency.event_digest,
78
+ side: 'from', ref: structuredClone(from), reason });
79
+ }
80
+ tasks.set(`${from.project_id}\0${from.plan_key}\0${from.task_id}`, {
81
+ project_id: from.project_id, plan_key: from.plan_key, task_id: from.task_id,
82
+ status: state?.status ?? null, finished: isFinishedTodoTaskState(state), reason,
83
+ trigger: state === undefined ? null : taskTrigger(member, from.task_id),
84
+ });
85
+ }
86
+ return { external_tasks: [...tasks.values()], findings };
87
+ }
88
+
89
+ /** `store` plus `external_tasks` and their findings, so every readiness reader sees one predicate. */
90
+ export async function withTodoExternalTasks(store, env) {
91
+ if (store.external_tasks !== undefined || externalTodoDependencies(store).length === 0) return store;
92
+ const { external_tasks: externalTasks, findings } = await readTodoExternalTasks(store, env);
93
+ return { ...store, external_tasks: externalTasks,
94
+ cross_plan_findings: [...(store.cross_plan_findings ?? []), ...findings] };
95
+ }
96
+
97
+ /**
98
+ * Connect-time cycle check through readable charts: walk `from`'s predecessors (in-chart and cross-chart) from
99
+ * `fromStore`; reaching `to` closes a cycle. Returns the closed path (from … to) or null. Unreadable charts end
100
+ * their branch (a cycle nobody can see is not refused).
101
+ */
102
+ export async function externalCycle({ env, fromStore, from, to, localStore }) {
103
+ const key = (ref) => `${ref.project_id}\0${ref.plan_key}\0${ref.task_id}`;
104
+ const stores = new Map([[localStore.project_id, localStore], [fromStore.project_id, fromStore]]);
105
+ const target = key(to);
106
+ const seen = new Set();
107
+ const walk = async (ref, trail) => {
108
+ if (key(ref) === target) return [...trail, ref];
109
+ if (seen.has(key(ref))) return null;
110
+ seen.add(key(ref));
111
+ if (!stores.has(ref.project_id)) stores.set(ref.project_id, (await readChart(env, ref.project_id)).store ?? null);
112
+ const store = stores.get(ref.project_id);
113
+ if (store === null) return null;
114
+ const readiness = createTodoReadiness(store);
115
+ for (const pred of readiness.prerequisiteRefs(readiness.key(ref)).tasks) {
116
+ const found = await walk({ project_id: pred.project_id ?? store.project_id, plan_key: pred.plan_key,
117
+ task_id: pred.task_id }, [...trail, ref]);
118
+ if (found !== null) return found;
119
+ }
120
+ return null;
121
+ };
122
+ const closed = await walk({ project_id: from.project_id, plan_key: from.plan_key, task_id: from.task_id }, []);
123
+ return closed === null ? null : [to, ...closed.slice(0, -1).reverse(), to]
124
+ .map(({ project_id: projectId, plan_key: planKey, task_id: taskId }) => ({ project_id: projectId, plan_key: planKey, task_id: taskId }));
125
+ }
@@ -59,6 +59,8 @@ function noticeSummary(planKey, task, waiting) {
59
59
  export function projectTodoNotices(store, { lane = null, declared = () => true, waits = [] } = {}) {
60
60
  const readiness = createTodoReadiness(store);
61
61
  const members = new Map(store.members.map((member) => [member.plan.plan_key, member]));
62
+ const external = new Map((store.external_tasks ?? []).map((entry) => [
63
+ `${entry.project_id}\0${entry.plan_key}\0${entry.task_id}`, entry]));
62
64
  const notices = [];
63
65
  for (const ready of projectTodoStatus(store, TODO_STATUS_DISPATCH_ONLY).next_ready) {
64
66
  const member = members.get(ready.plan_key);
@@ -67,6 +69,12 @@ export function projectTodoNotices(store, { lane = null, declared = () => true,
67
69
  const refs = readiness.prerequisiteRefs(readiness.key({ ...member.plan, ...task }));
68
70
  const triggers = [];
69
71
  for (const ref of refs.tasks) {
72
+ if (ref.project_id !== undefined) {
73
+ // xchart: the done was written in the other chart; its latest event is read there (withTodoExternalTasks).
74
+ const trigger = external.get(`${ref.project_id}\0${ref.plan_key}\0${ref.task_id}`)?.trigger ?? null;
75
+ if (trigger !== null) triggers.push({ project_id: ref.project_id, plan_key: ref.plan_key, task_id: ref.task_id, ...trigger });
76
+ continue;
77
+ }
70
78
  const event = latestEvent(members.get(ref.plan_key), (entry) => entry.task_id === ref.task_id);
71
79
  if (event !== null) triggers.push(triggerOf(members.get(ref.plan_key), event, { task_id: ref.task_id }));
72
80
  }
@@ -50,9 +50,21 @@ export function createTodoReadiness(store) {
50
50
  acceptanceIncoming.set(key, new Set());
51
51
  }
52
52
  }
53
+ // xchart: predecessors on other charts, as their chart reports them (`withTodoExternalTasks`); never phase-gated.
54
+ for (const entry of store.external_tasks ?? []) {
55
+ nodes.set(taskKey(entry), { status: entry.status, task_id: entry.task_id, finished: entry.finished === true,
56
+ schema: null, plan_key: entry.plan_key, project_id: entry.project_id, phase_id: null, reason: entry.reason });
57
+ }
58
+ // An external edge whose state was not loaded waits (fail closed), named `chart_not_read`.
59
+ const external = new Map();
60
+ const predecessorNode = (source) => nodes.get(source) ?? (external.has(source)
61
+ ? { ...external.get(source), status: null, finished: false, schema: null, reason: 'chart_not_read' } : undefined);
53
62
  const connect = (from, to) => {
54
63
  const source = taskKey(from);
55
64
  const target = taskKey(to);
65
+ if (from.project_id !== to.project_id) {
66
+ external.set(source, { project_id: from.project_id, plan_key: from.plan_key, task_id: from.task_id });
67
+ }
56
68
  incoming.get(target)?.add(source);
57
69
  outgoing.get(source)?.add(target);
58
70
  };
@@ -85,7 +97,7 @@ export function createTodoReadiness(store) {
85
97
 
86
98
  function prerequisites(key) {
87
99
  // u03 A24: 消えた端点(Storeのendpoint_missing finding)は後続を止めない。Store replayも同じ規則。
88
- const predecessors = [...(incoming.get(key) ?? [])].map((source) => nodes.get(source))
100
+ const predecessors = [...(incoming.get(key) ?? [])].map(predecessorNode)
89
101
  .filter((node) => node !== undefined);
90
102
  const unfinished = predecessors.filter((node) => node.finished !== true);
91
103
  const unreadyPhases = predecessors.filter((node) => !dependencyPhaseReady(node, nodes.get(key)));
@@ -107,7 +119,7 @@ export function createTodoReadiness(store) {
107
119
  cause,
108
120
  // a12: a refusal names what blocks, not only why.
109
121
  blocking: cause === 'predecessor_unfinished'
110
- ? { blocking_tasks: unfinished.map(({ plan_key, task_id, status }) => ({ plan_key, task_id, status })).sort(byRef) }
122
+ ? { blocking_tasks: unfinished.map(blockingTask).sort(byRef) }
111
123
  : cause === 'acceptance_edge'
112
124
  ? { blocking_phases: uniqueRefs(blockingPhases).map((phase) => ({ ...phase })).sort(byRef) } : {},
113
125
  };
@@ -133,8 +145,10 @@ export function createTodoReadiness(store) {
133
145
  /** notice-impl: what a task waits on — predecessor tasks, phases whose accept it needs, and its own phase. */
134
146
  function prerequisiteRefs(key) {
135
147
  const node = nodes.get(key);
136
- const tasks = [...(incoming.get(key) ?? [])].map((source) => nodes.get(source))
137
- .filter((pred) => pred !== undefined).map(({ plan_key, task_id }) => ({ plan_key, task_id }));
148
+ const tasks = [...(incoming.get(key) ?? [])].map(predecessorNode)
149
+ .filter((pred) => pred !== undefined).map(({ project_id: projectId, plan_key, task_id }) => (
150
+ external.has(taskKey({ project_id: projectId, plan_key, task_id }))
151
+ ? { project_id: projectId, plan_key, task_id } : { plan_key, task_id }));
138
152
  const phaseRefs = [...(acceptanceIncoming.get(key) ?? [])].map((source) => phases.get(source))
139
153
  .filter((phase) => phase !== undefined).map(({ plan_key, phase_id }) => ({ plan_key, phase_id }));
140
154
  for (const source of incoming.get(key) ?? []) {
@@ -172,7 +186,13 @@ export function createTodoReadiness(store) {
172
186
  };
173
187
  }
174
188
 
175
- const refId = (ref) => `${ref.plan_key}\0${ref.task_id ?? ref.phase_id}`;
189
+ const refId = (ref) => `${ref.project_id ?? ''}\0${ref.plan_key}\0${ref.task_id ?? ref.phase_id}`;
190
+
191
+ /** a12 blocking entry; an external predecessor also names its project and why it waits (null when readable). */
192
+ function blockingTask({ project_id: projectId, plan_key, task_id, status, reason }) {
193
+ return projectId === undefined ? { plan_key, task_id, status }
194
+ : { project_id: projectId, plan_key, task_id, status, reason: reason ?? null };
195
+ }
176
196
  function byRef(left, right) {
177
197
  return refId(left) < refId(right) ? -1 : refId(left) > refId(right) ? 1 : 0;
178
198
  }
@@ -330,7 +330,7 @@ function crossPlanFindingEntry(value) {
330
330
  || !isTodoIdentifier(value.owner_plan_key)
331
331
  || !(value.event_digest === null || isTodoDigest(value.event_digest))
332
332
  || !['from', 'to'].includes(value.side)
333
- || !['binding_stale', 'endpoint_missing'].includes(value.reason)) return false;
333
+ || !['binding_stale', 'endpoint_missing', 'charts_root_unset', 'chart_unreadable'].includes(value.reason)) return false;
334
334
  const { ref } = value;
335
335
  const common = (keys) => exactRecord(ref, keys) && isTodoIdentifier(ref.project_id)
336
336
  && isTodoIdentifier(ref.plan_key)
@@ -534,6 +534,8 @@ function buildTodoGraph(readModel) {
534
534
  // active plan topologyは追記改変しない。開発中に接続したplan-scoped edgeを同じincomingへ
535
535
  // 合成することで、projectTodoStatusとcomputeReadyFrontierが同じ待機判定を即座に読む。
536
536
  for (const dependency of projectTodoCrossPlanDependencies(members)) {
537
+ // xchart: a predecessor on another chart is not a node here; readiness (external_tasks) decides next_ready.
538
+ if (dependency.from.project_id !== dependency.to.project_id) continue;
537
539
  addPredecessor(dependency.from, dependency.to);
538
540
  }
539
541
 
@@ -1032,6 +1032,8 @@ function validateMergedGraph(members, crossPlanDependencies = projectTodoCrossPl
1032
1032
  const owner = members.find(({ plan }) => plan.project_id === dependency.to.project_id
1033
1033
  && plan.plan_key === dependency.to.plan_key);
1034
1034
  if (owner === undefined) fail('STORE_INCONSISTENT', 'cross_plan_dependency_owner_missing');
1035
+ // xchart S2: a predecessor on another chart is Plan's node (read there); no finding, no adjacency here.
1036
+ if (dependency.from.project_id !== owner.plan.project_id) continue;
1035
1037
  const digest = dependency.event_digest ?? null;
1036
1038
  const from = bind(dependency.from, owner.plan, digest, 'from');
1037
1039
  const to = bind(dependency.to, owner.plan, digest, 'to');
@@ -1077,9 +1079,14 @@ function crossPlanDependencyTask(store, ref) {
1077
1079
  return { member, task };
1078
1080
  }
1079
1081
 
1080
- function validateCrossPlanDependencyTransition(store, owner, input) {
1082
+ /**
1083
+ * xchart S3: only `todo dependency connect` (appendTodoEvent, `foreignFrom`) may record a predecessor on another
1084
+ * chart; Plan checked it there just before. Genesis, import and connectionOnly keep refusing a foreign from.
1085
+ */
1086
+ function validateCrossPlanDependencyTransition(store, owner, input, { foreignFrom = false } = {}) {
1081
1087
  const { from, to } = input.payload;
1082
- if (from.project_id !== store.project_id || to.project_id !== store.project_id) {
1088
+ const foreign = from.project_id !== store.project_id;
1089
+ if ((foreign && !foreignFrom) || to.project_id !== store.project_id) {
1083
1090
  fail('DEPENDENCY_INVALID', 'dependency_project_mismatch');
1084
1091
  }
1085
1092
  // 同一plan内の後追い接続も受ける(2026-08-25 オーナー裁定)。「工程の線を誤ったので足す」という
@@ -1097,7 +1104,7 @@ function validateCrossPlanDependencyTransition(store, owner, input) {
1097
1104
  edge.from.task_id === from.task_id && edge.to.task_id === to.task_id))) {
1098
1105
  fail('DEPENDENCY_EXISTS', 'dependency_already_in_plan', { from, to });
1099
1106
  }
1100
- const source = crossPlanDependencyTask(store, from);
1107
+ if (!foreign) crossPlanDependencyTask(store, from);
1101
1108
  const target = crossPlanDependencyTask(store, to);
1102
1109
  // A completed source already satisfies the prerequisite. Keep the existing
1103
1110
  // completion record as the proof instead of creating a second ledger entry.
@@ -1850,6 +1857,16 @@ async function repairCrossPlanBindings(repoRoot, store, { assertHeld, actor, rec
1850
1857
  return repairs;
1851
1858
  }
1852
1859
 
1860
+ /**
1861
+ * xchart S1: read another chart without touching it: the non-recovering view (no lock, no recovery, no write).
1862
+ * Throws where that chart's own writer must recover (manifest_journal_head_mismatch after the stable-read attempts,
1863
+ * cross_plan_import_recovery_required, source_cutover_recovery_required) and STORE_UNINITIALIZED; Plan reads any
1864
+ * throw as "that chart is unreadable" for its edges only.
1865
+ */
1866
+ export async function readTodoStoreReadOnly({ repoRoot }) {
1867
+ return readStoreStableWith({ repoRoot }, readTodoStoreView);
1868
+ }
1869
+
1853
1870
  export async function readTodoStoreStable(options = {}) {
1854
1871
  return readStoreStableWith(options, readTodoStore);
1855
1872
  }
@@ -2409,7 +2426,7 @@ export async function appendTodoEvent(options = {}) {
2409
2426
  // 「作業が進んだ」の意味であり、方式選択や依存接続でそこを動かすと意味がずれる。
2410
2427
  if (TODO_PLAN_SCOPED_EVENT_KINDS.includes(options.event.kind)) {
2411
2428
  if (options.event.kind === 'cross_plan_dependency') {
2412
- validateCrossPlanDependencyTransition(store, member, options.event);
2429
+ validateCrossPlanDependencyTransition(store, member, options.event, { foreignFrom: true });
2413
2430
  }
2414
2431
  if (options.event.kind === 'cross_plan_dependency_removed') {
2415
2432
  const digest = options.event.payload.target_event_digest;