@quolu/lattice 0.106.0 → 0.108.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.
@@ -896,8 +896,12 @@ export function validateTodoChartMeta(value) {
896
896
  const text = (field) => field === null || (typeof field === 'string' && field.length > 0 && field.length <= 1024);
897
897
  const word = (field) => typeof field === 'string' && field.length > 0 && field.length <= 1024;
898
898
  const { repo } = value ?? {};
899
- return exactRecord(value, ['schema', 'name', 'created_by', 'created_at', 'repo'])
900
- && value.schema === TODO_CHART_META_SCHEMA && text(value.name) && text(value.created_by)
899
+ // no_code_lanes is optional: a file without it stays valid, and an empty list is never written (old readers keep working).
900
+ const lanes = value?.no_code_lanes;
901
+ const lanesOk = lanes === undefined || (Array.isArray(lanes) && lanes.every((lane, index) => isTodoIdentifier(lane)
902
+ && (index === 0 || lanes[index - 1] < lane)));
903
+ return exactRecord(value, ['schema', 'name', 'created_by', 'created_at', 'repo', ...(lanes === undefined ? [] : ['no_code_lanes'])])
904
+ && lanesOk && value.schema === TODO_CHART_META_SCHEMA && text(value.name) && text(value.created_by)
901
905
  && (value.created_at === null || isStrictTodoTimestamp(value.created_at))
902
906
  && (repo === null || (exactRecord(repo, ['url', 'branch', 'accepted_tip'])
903
907
  && word(repo.url) && word(repo.branch) && text(repo.accepted_tip)));
@@ -1,3 +1,4 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { mkdtemp, rm } from 'node:fs/promises';
2
3
  import { tmpdir } from 'node:os';
3
4
  import path from 'node:path';
@@ -40,22 +41,46 @@ function memoryStream() {
40
41
  };
41
42
  }
42
43
 
43
- async function initializeSensor(observationRoot) {
44
+ async function runSensor(command, observationRoot) {
44
45
  const stdout = memoryStream();
45
46
  const stderr = memoryStream();
46
47
  const status = await runSensorCli({
47
- argv: ['init', observationRoot, '--json'],
48
+ argv: [command, observationRoot, '--json'],
48
49
  stdout: stdout.stream,
49
50
  stderr: stderr.stream,
50
51
  });
51
52
  if (status !== 0) {
52
53
  fail('INDEPENDENCE_OBSERVATION_SENSOR_INIT_FAILED', 'observation_sensor_init_failed', {
53
- sensor_error: stderr.read(),
54
+ sensor_command: command, sensor_error: stderr.read(),
54
55
  });
55
56
  }
56
57
  }
57
58
 
58
- /** 共有repoのdirtyな状態を観測せず、current HEADのclean worktreeでsensorを実行する。 */
59
+ /**
60
+ * a2 (ADR 0204 Observe): 作業木がHEADと同じ内容か。`.lattice/`はsensor索引とstoreが書く場所で、
61
+ * 索引の対象外なので数えない(storeがtrackedな製品repoでは書込みのたびにdirtyになるため)。
62
+ */
63
+ function isCleanAtHead(repoRoot, headSha) {
64
+ return git({ cwd: repoRoot, args: ['rev-parse', '--verify', 'HEAD^{commit}'], operation: 'resolve_head' }) === headSha
65
+ && git({
66
+ cwd: repoRoot, operation: 'status_clean_check',
67
+ args: ['status', '--porcelain', '--untracked-files=all', '--', '.', ':(exclude).lattice'],
68
+ }) === '';
69
+ }
70
+
71
+ /**
72
+ * HEADと同じ内容の作業木では、維持されている索引を増分syncして使う(無ければ最初の1回だけinit)。
73
+ * 同期の前後でcleanとHEADを確かめ、崩れていたらnull=隔離worktreeの経路へ落とす。
74
+ * 保護するもの: 未commitの状態を判定が観測しないこと。落とす先が出口で、拒否はしない。
75
+ */
76
+ async function observeMaintainedIndex({ repoRoot, headSha, witnessSet }) {
77
+ if (!isCleanAtHead(repoRoot, headSha)) return null;
78
+ await runSensor(existsSync(path.join(repoRoot, '.lattice/sensor/sensor.db')) ? 'sync' : 'init', repoRoot);
79
+ if (!isCleanAtHead(repoRoot, headSha)) return null;
80
+ return { head_sha: headSha, sensor_evidence: await collectWitnessSensorEvidence({ cwd: repoRoot, witnessSet }) };
81
+ }
82
+
83
+ /** 共有repoのdirtyな状態を観測せず、current HEADの索引(維持されたもの、無ければclean worktree)でsensorを実行する。 */
59
84
  export async function collectTodoIndependenceAuthoritativeObservation({ repoRoot, witnessSet } = {}) {
60
85
  if (typeof repoRoot !== 'string' || repoRoot.length === 0
61
86
  || witnessSet === null || typeof witnessSet !== 'object') {
@@ -65,6 +90,8 @@ export async function collectTodoIndependenceAuthoritativeObservation({ repoRoot
65
90
  const headSha = git({
66
91
  cwd: repoRoot, args: ['rev-parse', '--verify', 'HEAD^{commit}'], operation: 'resolve_head',
67
92
  });
93
+ const maintained = await observeMaintainedIndex({ repoRoot, headSha, witnessSet });
94
+ if (maintained !== null) return maintained;
68
95
  const temporaryRoot = await mkdtemp(path.join(tmpdir(), 'lattice-independence-observation-'));
69
96
  const observationRoot = path.join(temporaryRoot, 'worktree');
70
97
  let registered = false;
@@ -86,7 +113,7 @@ export async function collectTodoIndependenceAuthoritativeObservation({ repoRoot
86
113
  expected_head_sha: headSha, actual_head_sha: observedHead,
87
114
  });
88
115
  }
89
- await initializeSensor(observationRoot);
116
+ await runSensor('init', observationRoot);
90
117
  result = await collectWitnessSensorEvidence({ cwd: observationRoot, witnessSet });
91
118
  } catch (error) {
92
119
  operationError = error;
@@ -400,6 +400,7 @@ function wavePlan(value, taskIds) {
400
400
  * conflictは`conflict_resources`のresource idを参照し、kindとnormalized targetを一度だけ保持する。
401
401
  * `task_boundaries`はtask別の宣言境界で、鮮度のdiff交差判定をartifactだけで閉じるために持つ。
402
402
  * `wave_plan`はschedulability compileが`compiled`を返した時だけ持ち、unknownが残る間はnullになる。
403
+ * `outcome: compiled`で`wave_plan: null`は、exact探索の上限(MAX_TODOS)を超えたため波の計画だけを省いた記録で、verdictは全て揃う(g5)。
403
404
  * verdictに現れないペアをverified独立と読めるのは、両taskにunknownが無いときだけである。
404
405
  */
405
406
  export function validateTodoIndependence(value) {
@@ -284,6 +284,7 @@ export function compileTodoIndependence(options = {}) {
284
284
  planRef: witnessRequestId(witnessSet, plan.plan_version),
285
285
  planEpoch: 0,
286
286
  predecessorRefs: [],
287
+ omitWavesOverLimit: true,
287
288
  });
288
289
 
289
290
  if (compiled.outcome !== 'dispatchable'
@@ -316,7 +317,9 @@ export function compileTodoIndependence(options = {}) {
316
317
  conflicts: conflictProjection.conflicts,
317
318
  precedences: dispatchable ? precedencesFrom(compiled.pairwise_verdicts) : [],
318
319
  unknowns: dispatchable ? [] : unknownsFrom(compiled.detail),
319
- wave_plan: dispatchable
320
+ // g5: `outcome: compiled` with `wave_plan: null` = the exact wave search was omitted (more tasks than MAX_TODOS in the
321
+ // schedulability compiler); every verdict above is still complete. `unknown` is the other reason for null.
322
+ wave_plan: dispatchable && compiled.schedule !== null
320
323
  ? {
321
324
  waves: compiled.schedule.waves.map((wave) => ({
322
325
  task_ids: [...wave.todo_ids].sort(compareText),
@@ -1,11 +1,11 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { fsyncDirectory } from './fs-dir-sync.mjs';
3
3
  import {
4
- lstat, mkdir, open, readFile, readdir, rename, rm, stat,
4
+ lstat, mkdir, open, readFile, readdir, rm, stat,
5
5
  } from 'node:fs/promises';
6
6
  import path from 'node:path';
7
7
  import { LOCK_WAIT_MS, StoreLockError, withStoreLock } from './store-lock.mjs';
8
- import { syncPublishedFile } from './fs-publish.mjs';
8
+ import { renamePublishedFile, syncPublishedFile } from './fs-publish.mjs';
9
9
  import { normalizeCheckoutEol } from './todo-store-view.mjs';
10
10
  import { memoByFileIdentity } from './todo-version-memo.mjs';
11
11
  import { TODO_VERSION_COMPACT_FILE, readVersionCompact } from './todo-version-compact.mjs';
@@ -201,7 +201,7 @@ async function atomicWrite(ref, bytes) {
201
201
  await syncPublishedFile(handle, ref);
202
202
  await handle.close();
203
203
  handle = null;
204
- await rename(temporary, ref);
204
+ await renamePublishedFile(temporary, ref);
205
205
  await fsyncDirectory(path.dirname(ref));
206
206
  } finally {
207
207
  if (handle) await handle.close();
@@ -282,7 +282,6 @@ export function validateProspectiveEvent({ store, member, event }) {
282
282
  const definition = todoPhaseDefinitions(member.plan).find(({ phase_id: id }) => id === event.phase_id);
283
283
  return refused('phase_gate_not_ready', 'phase_state', {
284
284
  plan_key: member.plan.plan_key, phase_id: event.phase_id, phase_status: phase.status,
285
- required_evidence_slots: [...(definition?.required_evidence_slots ?? [])],
286
285
  });
287
286
  }
288
287
  }
@@ -436,7 +436,6 @@ function collectAuditPending(member, sink) {
436
436
  implicit,
437
437
  required_evidence_slots: [...definition.required_evidence_slots],
438
438
  next_commands: auditPendingNextCommands(member.plan.plan_key, phase.phase_id, phase.status,
439
- definition.required_evidence_slots.length,
440
439
  { auditRequired: phaseAuditRequired(member, definition.gate_policy) }),
441
440
  });
442
441
  }
@@ -3973,7 +3973,7 @@ async function withInitialStoreLocks(stage, currentRoot, callback) {
3973
3973
  /** G5-only initial authoring transaction. Store membership appears by one final directory rename. */
3974
3974
  const CHART_META_REF = '.lattice/chart.json';
3975
3975
  const CHART_META_MAX_BYTES = 65_536;
3976
- const CHART_META_PATCH_KEYS = ['name', 'created_by', 'repo'];
3976
+ const CHART_META_PATCH_KEYS = ['name', 'created_by', 'repo', 'no_code_lanes'];
3977
3977
 
3978
3978
  /** The recorded chart identity, or null when `.lattice/chart.json` does not exist. */
3979
3979
  async function readChartMetaRecord(repoRoot) {
@@ -3999,7 +3999,7 @@ async function readChartMetaRecord(repoRoot) {
3999
3999
  }
4000
4000
 
4001
4001
  const chartMetaView = (record) => ({ name: record?.name ?? null, created_by: record?.created_by ?? null,
4002
- created_at: record?.created_at ?? null, repo: record?.repo ?? null });
4002
+ created_at: record?.created_at ?? null, repo: record?.repo ?? null, no_code_lanes: record?.no_code_lanes ?? [] });
4003
4003
 
4004
4004
  /**
4005
4005
  * a101 K4: chart identity `.lattice/chart.json` (dfd-charts-read). Read only, no lock, no Store needed: a missing file
@@ -4010,7 +4010,7 @@ export async function readTodoChartMeta({ repoRoot = process.cwd() } = {}) {
4010
4010
  }
4011
4011
 
4012
4012
  /**
4013
- * a101 K4: patch {name?, created_by?, repo?} (absent key = keep). `created_by` applies only while unrecorded and
4013
+ * a101 K4: patch {name?, created_by?, repo?, no_code_lanes?} (absent key = keep; `no_code_lanes` replaces the list). `created_by` applies only while unrecorded and
4014
4014
  * `created_at` is stamped when the file is first created: the creator is never overwritten. Works before the first plan
4015
4015
  * (creates `.lattice/`). The read-modify-write holds `.lattice/.chart.write.lock` so two writers cannot both see an
4016
4016
  * unrecorded creator (identified lock, proven-dead recovery). Name rules are the CLI's.
@@ -4042,6 +4042,10 @@ export async function writeTodoChartMeta({ repoRoot = process.cwd(), patch = {}
4042
4042
  created_at: current === null ? new Date().toISOString() : current.created_at,
4043
4043
  repo: 'repo' in patch ? patch.repo : current?.repo ?? null,
4044
4044
  };
4045
+ // The list is stored only when non-empty; the patch value replaces it (sorted, unique).
4046
+ const lanes = 'no_code_lanes' in patch ? patch.no_code_lanes : current?.no_code_lanes ?? [];
4047
+ if (!Array.isArray(lanes)) throw new TypeError('chart meta patch invalid');
4048
+ if (lanes.length > 0) next.no_code_lanes = 'no_code_lanes' in patch ? [...new Set(lanes)].sort() : lanes;
4045
4049
  if (!validateTodoChartMeta(next)) throw new TypeError('chart meta patch invalid');
4046
4050
  if (current !== null && canonicalizeTodoArtifact(next) === canonicalizeTodoArtifact(current)) {
4047
4051
  return { meta: chartMetaView(current), unchanged: true };