@quolu/lattice 0.94.0 → 0.95.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.94.0",
3
+ "version": "0.95.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
@@ -88,6 +88,7 @@ Read commands:
88
88
  show --plan <key> --task <id> --json # 個別ToDoと最新bounded note contextを追加操作なしで返す
89
89
  note list --plan <key> [--task <id>] --json # note全履歴の診断面(通常read/startでは不要)
90
90
  notice list [--lane <lane>] [--include-acked] [--json] # 着手できるようになった工程の知らせ(既定は未ackだけ。lane省略で全lane)
91
+ nudge [--json] # 前の工程が終わっているのに未着手の工程を担当ごとに返し、発火(着手)と、動けない時の止め(todo block)を促す(読むだけ)
91
92
  bindings [--plan <key>] [--json] # compile_binding付きTaskをTODO identityつきで投影する
92
93
  display read [--json] # host表示用の工程表読取(lattice.todo_display_read_result.v1)。不整合でも断らずstateで返す
93
94
  display source [--json] # 安い変更検知(lattice.todo_store_display_source.v1)。変わった時だけreadする
@@ -306,6 +307,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
306
307
  'todo notice': 'todo notice list [--lane <lane>] [--include-acked] [--json] | ack --lane <lane> --notice <id>[,<id>...] [--json]',
307
308
  'todo notice list': 'todo notice list [--lane <lane>] [--include-acked] [--json] # lattice.todo_notice_list_result.v1',
308
309
  'todo notice ack': 'todo notice ack --lane <lane> --notice <id>[,<id>...] [--json] # lattice.todo_notice_ack_result.v1 {acked, already, closed}',
310
+ 'todo nudge': 'todo nudge [--json] # lattice.todo_nudge_result.v1 {lanes: [{lane, tasks: [{fire_actions, stop_action, prompt}]}]}',
309
311
  'todo wait': 'todo wait --plan <key> --task <id> [--reason <text>] | --cancel [--json] # lattice.todo_wait_result.v1 {state: waiting|startable_now|not_pending|cancelled}',
310
312
  'todo bindings': 'todo bindings [--plan <key>] [--json]',
311
313
  'todo display': 'todo display read [--json] | source [--json] # host表示用の読取。不整合でも断らずstateで返す',
package/src/todo-cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { retireStateConflict, validateProspectiveEvent } from './todo-readiness.mjs';
1
+ import { createTodoReadiness, retireStateConflict, validateProspectiveEvent } from './todo-readiness.mjs';
2
2
  import { cliCommandKind } from './cli-command-kind.mjs';
3
3
  import { cliFailureClass } from './cli-failure-class.mjs';
4
4
  import { ENFORCED_DONE_MESSAGE, FLAG_PLACEHOLDER, publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
@@ -170,6 +170,7 @@ import {
170
170
  import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
171
171
  import { collectSensorEvidence } from './sensor-adapter.mjs';
172
172
  import { newTodoNotices, projectTodoNotices, waitInEffect } from './todo-notices.mjs';
173
+ import { projectTodoNudges } from './todo-nudges.mjs';
173
174
  import {
174
175
  ackTodoNotices, cancelTodoNoticeWait, readAllTodoNoticeAcks, readAllTodoNoticeWaits, readTodoNoticeAcks, writeTodoNoticeWait,
175
176
  } from './todo-notice-store.mjs';
@@ -307,7 +308,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
307
308
  'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
308
309
  'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
309
310
  'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
310
- 'retract', 'dependency', 'add', 'notice', 'wait',
311
+ 'retract', 'dependency', 'add', 'notice', 'wait', 'nudge',
311
312
  ]);
312
313
 
313
314
  function typedArgumentFailure(stderr, code, message, detail, context = {}) {
@@ -369,6 +370,7 @@ const TODO_FLAG_SPECS = Object.freeze({
369
370
  show: Object.freeze({ known: ['plan', 'task', 'json'], required: ['plan', 'task'], booleans: ['json'] }),
370
371
  'notice list': Object.freeze({ known: ['lane', 'include-acked', 'json'], required: [], booleans: ['include-acked', 'json'] }),
371
372
  'notice ack': Object.freeze({ known: ['lane', 'notice', 'json'], required: ['lane', 'notice'], booleans: ['json'] }),
373
+ nudge: Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
372
374
  wait: Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
373
375
  'note list': Object.freeze({ known: ['plan', 'task', 'json'], required: ['plan'], booleans: ['json'] }),
374
376
  'phase status': Object.freeze({ known: ['plan', 'json'], required: ['plan'], booleans: ['json'] }),
@@ -3863,6 +3865,27 @@ async function scaffoldWitnessDraft({ repoRoot, planKey, draft }) {
3863
3865
  };
3864
3866
  }
3865
3867
 
3868
+ /**
3869
+ * declare-hint-knows-order: offer `todo start` only for a task the start path accepts now; otherwise name what it
3870
+ * waits on (the blocking set a start refusal computes), so the hint never leads into predecessor_unfinished.
3871
+ */
3872
+ function declaredStartHint(store, member, state) {
3873
+ const { plan_key: planKey } = member.plan;
3874
+ const taskId = state.task_id;
3875
+ if (state.status !== 'pending') return `${taskId} is already ${state.status}; no start is needed.`;
3876
+ const readiness = createTodoReadiness(store);
3877
+ const key = readiness.key({ ...member.plan, task_id: taskId });
3878
+ if (readiness.isReady(key)) return `The declared task can start: \`lattice todo start --plan ${planKey} --task ${taskId}\`.`;
3879
+ const { blocking } = readiness.prerequisites(key);
3880
+ const waits = [
3881
+ ...(blocking.blocking_tasks ?? []).map((ref) => `${ref.plan_key}/${ref.task_id} (${ref.status})`),
3882
+ ...(blocking.blocking_phases ?? []).map((ref) => `phase ${ref.plan_key}/${ref.phase_id} (${ref.status})`),
3883
+ ];
3884
+ const on = waits.length > 0 ? `it waits on ${waits.join(', ')}`
3885
+ : `its phase is ${readiness.ownPhaseStatus(key) ?? 'not active'}`;
3886
+ return `${taskId} cannot start yet: ${on}. Start it once \`lattice todo status --json\` lists it in next_ready.`;
3887
+ }
3888
+
3866
3889
  /**
3867
3890
  * a40: one task's witness row, declared by its member. Rows nobody declared stay out (an empty row
3868
3891
  * would claim "touches nothing"); compile runs once every ready task is declared.
@@ -3910,8 +3933,7 @@ async function witnessDeclare({ repoRoot, planKey, flags }) {
3910
3933
  ...(observable ? {} : {
3911
3934
  observation: 'unavailable',
3912
3935
  next_action: `The Store root has no commit (git HEAD unresolved), so ${taskId}'s row is recorded but not observed or compiled:`
3913
- + ' coverage reads declared_unobserved (not judged safe). The declared task can start:'
3914
- + ` \`lattice todo start --plan ${planKey} --task ${taskId}\`.`,
3936
+ + ` coverage reads declared_unobserved (not judged safe). ${declaredStartHint(store, member, state)}`,
3915
3937
  }),
3916
3938
  result_digest: '',
3917
3939
  };
@@ -4639,21 +4661,47 @@ function releasesTasks(argv) {
4639
4661
  || (command === 'dependency' && second === 'disconnect');
4640
4662
  }
4641
4663
 
4642
- /** Open notices with their waiters (wait-design); an unreadable wait file is named, its waits read as none. */
4643
- async function openNoticeView(repoRoot) {
4644
- const store = await readTodoStore({ repoRoot });
4664
+ /** `declared(planKey, taskId)`: whether an enforced plan's witness set records the task's row (unreadable = none). */
4665
+ async function declaredWitnessRows(repoRoot, store) {
4645
4666
  const rows = new Map();
4646
4667
  for (const member of store.members) {
4647
4668
  if (member.coordination?.mode !== 'enforced') continue;
4648
4669
  const recorded = await readTodoWitnessSet({ repoRoot, planKey: member.plan.plan_key }).catch(() => null);
4649
4670
  rows.set(member.plan.plan_key, new Set(Object.keys(recorded?.manual_witness ?? {})));
4650
4671
  }
4672
+ return (planKey, taskId) => rows.get(planKey)?.has(taskId) === true;
4673
+ }
4674
+
4675
+ /**
4676
+ * `todo nudge` (sweep-list, dfd-nudge.md): the ready set by lane with fire/stop prompts. Read-only. A directory with
4677
+ * no Store yet answers an empty list, since the BellTeam run walks every chart directory.
4678
+ */
4679
+ async function nudgeList({ repoRoot }) {
4680
+ let store;
4681
+ try { store = await readTodoStore({ repoRoot }); }
4682
+ catch (error) {
4683
+ if (error?.code !== 'STORE_UNINITIALIZED') throw error;
4684
+ store = null;
4685
+ }
4686
+ const result = {
4687
+ schema: 'lattice.todo_nudge_result.v1', project_id: store?.project_id ?? null,
4688
+ lanes: store === null ? [] : projectTodoNudges(store, { declared: await declaredWitnessRows(repoRoot, store) }),
4689
+ result_digest: '',
4690
+ };
4691
+ result.result_digest = todoSelfDigest(result, 'result_digest');
4692
+ return result;
4693
+ }
4694
+
4695
+ /** Open notices with their waiters (wait-design); an unreadable wait file is named, its waits read as none. */
4696
+ async function openNoticeView(repoRoot) {
4697
+ const store = await readTodoStore({ repoRoot });
4698
+ const declared = await declaredWitnessRows(repoRoot, store);
4651
4699
  const stored = await readAllTodoNoticeWaits({ repoRoot });
4652
4700
  // Readers return raw records: waits that ended since the file's last write are dropped here.
4653
4701
  const waits = stored.waits.flatMap((record) => record.waits.map((wait) => ({ plan_key: record.plan_key, ...wait })))
4654
4702
  .filter((wait) => waitInEffect(store, wait));
4655
4703
  const notices = projectTodoNotices(store, {
4656
- declared: (planKey, taskId) => rows.get(planKey)?.has(taskId) === true, waits,
4704
+ declared, waits,
4657
4705
  });
4658
4706
  return { store, notices, waitUnreadable: stored.unreadable };
4659
4707
  }
@@ -5205,6 +5253,8 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5205
5253
  if (isNoticeLane(flags.lane) && ids.length > 0 && ids.every((id) => /^[0-9a-f]{64}$/u.test(id))) {
5206
5254
  action = (repoRoot) => noticeAck({ repoRoot, env, lane: flags.lane, ids });
5207
5255
  }
5256
+ } else if (argv[0] === 'nudge' && matchFlagCommand(argv, ['nudge'], TODO_FLAG_SPECS.nudge) !== null) {
5257
+ action = (repoRoot) => nudgeList({ repoRoot });
5208
5258
  } else if (argv[0] === 'wait' && matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait) !== null) {
5209
5259
  const flags = matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait);
5210
5260
  const reasonOk = flags.reason === undefined
@@ -21,6 +21,15 @@ function triggerOf(member, event, ref) {
21
21
  };
22
22
  }
23
23
 
24
+ /** The start path a lane can run for a ready task, in order: witness declare first on an enforced plan without its row. */
25
+ export function startPath(planKey, taskId, mode, declared) {
26
+ return [
27
+ ...(mode === 'enforced' && !declared
28
+ ? [`lattice todo independence witness declare --plan ${planKey} --task ${taskId} --owns <path>[,<path>...]`] : []),
29
+ `lattice todo start --plan ${planKey} --task ${taskId}`,
30
+ ];
31
+ }
32
+
24
33
  /**
25
34
  * wait-design: a wait is in effect while its task is pending or blocked and has no own start or retire after `since`.
26
35
  * shortcut: a start-then-retract in an earlier plan version followed by a revise can bring a wait back (that version's
@@ -95,9 +104,7 @@ export function projectTodoNotices(store, { lane = null, declared = () => true,
95
104
  waiting_digest: todoNoticeWaitingDigest(waiting.map(({ agent, since }) => ({ agent, since }))),
96
105
  summary: noticeSummary(planKey, task, waiting),
97
106
  // The command if the lane starts; information, never an assignment. Same rule as the enforced done hints (#141): offer what the start path accepts.
98
- next_action: mode === 'enforced' && !declared(planKey, task.task_id)
99
- ? `lattice todo independence witness declare --plan ${planKey} --task ${task.task_id} --owns <path>[,<path>...]`
100
- : `lattice todo start --plan ${planKey} --task ${task.task_id}`,
107
+ next_action: startPath(planKey, task.task_id, mode, declared(planKey, task.task_id))[0],
101
108
  });
102
109
  }
103
110
  return notices.sort((left, right) => byText(`${left.plan_key}\0${left.task_id}`, `${right.plan_key}\0${right.task_id}`));
@@ -0,0 +1,37 @@
1
+ // Nudges (sweep-list, docs/architecture/dfd-nudge.md): the ready set grouped by lane, each task with the prompt to
2
+ // fire it and, if it cannot move once fired, to set a stop. Read-only; no other condition (the Owner's spec).
3
+
4
+ import { startPath } from './todo-notices.mjs';
5
+ import { projectTodoStatus, TODO_STATUS_DISPATCH_ONLY } from './todo-status.mjs';
6
+
7
+ const laneOrder = (lane) => (lane === null ? '\u{10FFFF}' : lane);
8
+
9
+ /** `declared(planKey, taskId)` says whether an enforced plan's witness set records the task's row. */
10
+ export function projectTodoNudges(store, { declared = () => true } = {}) {
11
+ const members = new Map(store.members.map((member) => [member.plan.plan_key, member]));
12
+ const lanes = new Map();
13
+ for (const ready of projectTodoStatus(store, TODO_STATUS_DISPATCH_ONLY).next_ready) {
14
+ const member = members.get(ready.plan_key);
15
+ const task = member?.plan.tasks.find(({ task_id: id }) => id === ready.task_id);
16
+ if (task === undefined) continue;
17
+ const planKey = member.plan.plan_key;
18
+ const fire = startPath(planKey, task.task_id, member.coordination?.mode ?? null, declared(planKey, task.task_id));
19
+ const stop = `lattice todo block --plan ${planKey} --task ${task.task_id} --reason <why it cannot move>`;
20
+ const lane = task.lane ?? null;
21
+ if (!lanes.has(lane)) lanes.set(lane, []);
22
+ lanes.get(lane).push({
23
+ plan_key: planKey,
24
+ plan_version: member.plan.plan_version,
25
+ task_id: task.task_id,
26
+ title: task.title,
27
+ done_condition: task.done_condition ?? null,
28
+ fire_actions: fire,
29
+ stop_action: stop,
30
+ prompt: `${planKey}/${task.task_id} 「${task.title}」: its predecessors are finished and it is not started.`
31
+ + ` Fire it: ${fire.map((command) => `\`${command}\``).join(' then ')}.`
32
+ + ` If it cannot move once fired, set a stop: \`${stop}\`.`,
33
+ });
34
+ }
35
+ return [...lanes].sort(([left], [right]) => (laneOrder(left) < laneOrder(right) ? -1 : 1))
36
+ .map(([lane, tasks]) => ({ lane, tasks }));
37
+ }
@@ -120,6 +120,19 @@ function failUninitialized() {
120
120
  });
121
121
  }
122
122
 
123
+ /** Absent manifest: uninitialized when no Store exists yet; a Store without its manifest stays STORE_INCONSISTENT. */
124
+ async function failManifestMissing(repoRoot) {
125
+ if (await isUninitializedTodoStore({ repoRoot })) failUninitialized();
126
+ fail('STORE_INCONSISTENT', 'artifact_missing', { ref: MANIFEST_REF });
127
+ }
128
+
129
+ async function readManifest(repoRoot) {
130
+ const manifest = await readArtifact(repoRoot, MANIFEST_REF, {
131
+ code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest, missing: true,
132
+ });
133
+ return manifest ?? failManifestMissing(repoRoot);
134
+ }
135
+
123
136
  const upgradeAction = (what) => `${what} was written by a newer Lattice than ${packageJson.version}. The record is`
124
137
  + ` not corrupt: do not repair or delete it. Upgrade Lattice on this host to a version newer than`
125
138
  + ` ${packageJson.version}, then run the command again.`;
@@ -1540,13 +1553,7 @@ async function readTodoStoreView(options = {}) {
1540
1553
  }
1541
1554
  await assertNoCrossPlanImportRecoveryNeeded(repoRoot);
1542
1555
  const pinnedSourceCache = { commits: new Set(), blobs: new Map() };
1543
- const manifest = await readArtifact(repoRoot, MANIFEST_REF, {
1544
- code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest, missing: true,
1545
- });
1546
- if (manifest === null) {
1547
- if (await isUninitializedTodoStore({ repoRoot })) failUninitialized();
1548
- fail('STORE_INCONSISTENT', 'artifact_missing', { ref: MANIFEST_REF });
1549
- }
1556
+ const manifest = await readManifest(repoRoot);
1550
1557
  const loaded = [];
1551
1558
  for (const descriptor of manifest.members) {
1552
1559
  const plan = await readArtifact(repoRoot, descriptor.plan_ref, {
@@ -1828,21 +1835,15 @@ async function readStoreStableWith(options, readStore) {
1828
1835
  // これにより一時窓を早計に破損扱いせず、恒久破損もSTORE_BUSYへ丸めない。
1829
1836
  let lastError = null;
1830
1837
  for (let attempt = 1; attempt <= maximumAttempts; attempt += 1) {
1831
- const before = await readArtifact(repoRoot, MANIFEST_REF, {
1832
- code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest,
1833
- });
1838
+ const before = await readManifest(repoRoot);
1834
1839
  try {
1835
1840
  const store = await readStore(options);
1836
- const after = await readArtifact(repoRoot, MANIFEST_REF, {
1837
- code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest,
1838
- });
1841
+ const after = await readManifest(repoRoot);
1839
1842
  if (before.manifest_digest === after.manifest_digest
1840
1843
  && store.manifest.manifest_digest === after.manifest_digest) return store;
1841
1844
  } catch (error) {
1842
1845
  if (!(error instanceof TodoStoreError)) throw error;
1843
- const after = await readArtifact(repoRoot, MANIFEST_REF, {
1844
- code: 'STORE_INCONSISTENT', maxBytes: TODO_LIMITS.snapshotBytes, validate: validateTodoManifest,
1845
- });
1846
+ const after = await readManifest(repoRoot);
1846
1847
  const transientWriteWindow = error.code === 'STORE_INCONSISTENT'
1847
1848
  && ['manifest_journal_head_mismatch', 'manifest_plan_binding_mismatch']
1848
1849
  .includes(error.detail.reason);
@@ -1913,6 +1914,9 @@ async function rawLastEventDigest(repoRoot, ref, { missing = false } = {}) {
1913
1914
  }
1914
1915
 
1915
1916
  async function readRawManifest(repoRoot) {
1917
+ if (await readRawStoreFile(repoRoot, MANIFEST_REF, TODO_LIMITS.snapshotBytes, { missing: true }) === null) {
1918
+ await failManifestMissing(repoRoot);
1919
+ }
1916
1920
  const manifest = await readRawStoreJson(repoRoot, MANIFEST_REF, TODO_LIMITS.snapshotBytes);
1917
1921
  if (manifest === null || typeof manifest !== 'object' || !Array.isArray(manifest.members)) {
1918
1922
  fail('STORE_INCONSISTENT', 'manifest_members_unenumerable', { ref: MANIFEST_REF });
@@ -2063,7 +2067,15 @@ async function readRawDisplayMembers(repoRoot, manifest) {
2063
2067
  /** Cheap unverified change hint for display polling; never validation or recovery. */
2064
2068
  export async function readTodoStoreDisplaySource({ repoRoot = process.cwd() } = {}) {
2065
2069
  const root = path.resolve(repoRoot);
2066
- return observeDisplaySource(root, await readRawManifest(root));
2070
+ let manifest;
2071
+ try { manifest = await readRawManifest(root); } catch (error) {
2072
+ // No Store yet is an observation like display read's, not a probe failure.
2073
+ if (error?.code !== 'STORE_UNINITIALIZED') throw error;
2074
+ const source = await observeDisplaySource(root, { members: [] });
2075
+ source.diagnostics.push({ plan_key: null, field: 'manifest', code: error.code, reason: error.detail.reason });
2076
+ return source;
2077
+ }
2078
+ return observeDisplaySource(root, manifest);
2067
2079
  }
2068
2080
 
2069
2081
  /** Display-only envelope: verified > unverified current raw > last_verified > unavailable. */