@quolu/lattice 0.107.0 → 0.109.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.
Files changed (37) hide show
  1. package/README.ja.md +1 -1
  2. package/README.md +2 -2
  3. package/bin/lattice.mjs +5 -2
  4. package/docs/schemas/lattice.plan_create_input.v6.schema.json +384 -0
  5. package/docs/schemas/lattice.plan_revise_input.v1.schema.json +3 -0
  6. package/docs/schemas/lattice.todo_witness_draft.v2.schema.json +14 -2
  7. package/docs/schemas/lattice.todo_witness_set.v6.schema.json +482 -0
  8. package/package.json +3 -1
  9. package/sensor/dist/bin/lattice-sensor.js +76 -0
  10. package/sensor/dist/graph/anchor-resolve.d.ts +90 -0
  11. package/sensor/dist/graph/anchor-resolve.d.ts.map +1 -0
  12. package/sensor/dist/graph/anchor-resolve.js +132 -0
  13. package/sensor/dist/graph/anchor-resolve.js.map +1 -0
  14. package/sensor/dist/graph/touched-symbols.d.ts +42 -0
  15. package/sensor/dist/graph/touched-symbols.d.ts.map +1 -0
  16. package/sensor/dist/graph/touched-symbols.js +80 -0
  17. package/sensor/dist/graph/touched-symbols.js.map +1 -0
  18. package/src/cli-help.mjs +21 -7
  19. package/src/plan-revise.mjs +12 -1
  20. package/src/plan-scope-review.mjs +1 -1
  21. package/src/project-cli.mjs +20 -3
  22. package/src/runtime-front-end.mjs +26 -9
  23. package/src/schedulability-compiler-v2.mjs +10 -4
  24. package/src/sensor-cli.mjs +82 -1
  25. package/src/sensor-resolve.mjs +116 -0
  26. package/src/sensor-touched.mjs +76 -0
  27. package/src/todo-authoring-input.mjs +1 -0
  28. package/src/todo-cli.mjs +233 -43
  29. package/src/todo-contracts.mjs +62 -0
  30. package/src/todo-declaration.mjs +165 -0
  31. package/src/todo-independence-authoritative-observation.mjs +45 -15
  32. package/src/todo-independence-contracts.mjs +18 -4
  33. package/src/todo-independence.mjs +8 -2
  34. package/src/todo-judgment.mjs +141 -0
  35. package/src/todo-relation-store.mjs +294 -0
  36. package/src/todo-store.mjs +8 -4
  37. package/src/witness-scaffold.mjs +23 -15
@@ -93,7 +93,7 @@ const CROSS_PLAN_IMPORT_TRANSACTION_SCHEMA = 'lattice.todo_cross_plan_import_tra
93
93
  const SOURCE_CUTOVER_BARRIER_REF = `${STORE_ROOT_REF}/source-cutover-recovery.json`;
94
94
  const SOURCE_CUTOVER_RECOVERY_CAPABILITY = Symbol('lattice.todo.source-cutover-recovery');
95
95
  const STORE_LOCK_HELD = Symbol('lattice.todo.lock-held');
96
- const WRITER_CALLERS = new Set(['g4-migration', 'g5-authoring']);
96
+ const WRITER_CALLERS = new Set(['g4-migration', 'g5-authoring', 'todo-relations']);
97
97
  const TODO_REVISION_SCHEMAS = Object.freeze([
98
98
  'lattice.todo_revision.v1', 'lattice.todo_revision.v2',
99
99
  ]);
@@ -114,7 +114,7 @@ export class TodoStoreError extends Error {
114
114
 
115
115
  export function createTodoStoreWriter(options = {}) {
116
116
  if (!exactRecord(options, ['caller']) || !WRITER_CALLERS.has(options.caller)) {
117
- throw new TypeError('todo store writer caller must be g4-migration or g5-authoring');
117
+ throw new TypeError('todo store writer caller must be g4-migration, g5-authoring or todo-relations');
118
118
  }
119
119
  return Object.freeze({ schema: 'lattice.todo_store_writer.v1', caller: options.caller });
120
120
  }
@@ -160,8 +160,10 @@ function rejectUnsupportedRevisionSchema(value, { family, supportedSchemas }) {
160
160
 
161
161
  // Reader registration (newer-value-says-upgrade): the newest schema of each Store record family this
162
162
  // reader knows. Bump it in the same diff that teaches the validator a new version.
163
- export const NEWEST_KNOWN_TODO_SCHEMA = Object.freeze({ todo_event: 4, todo_plan: 8, todo_manifest: 2, todo_notice_acks: 2, todo_notice_waits: 1, chart_meta: 1 });
164
- const NEWER_SCHEMA_FAMILY = new Map([[validateTodoPlan, 'todo_plan'], [validateTodoManifest, 'todo_manifest']]);
163
+ export const NEWEST_KNOWN_TODO_SCHEMA = Object.freeze({ todo_event: 4, todo_plan: 8, todo_manifest: 2, todo_notice_acks: 2, todo_notice_waits: 1, chart_meta: 1,
164
+ todo_relation_event: 1, todo_relation_summary: 1, todo_witness_set: 6 });
165
+ const NEWER_SCHEMA_FAMILY = new Map([[validateTodoPlan, 'todo_plan'], [validateTodoManifest, 'todo_manifest'],
166
+ [validateTodoWitnessSet, 'todo_witness_set']]);
165
167
  const vocabularyWord = (value) => typeof value === 'string' && /^[a-z][a-z0-9_-]{0,63}$/u.test(value);
166
168
 
167
169
  function newerSchema(value, family) {
@@ -198,6 +200,8 @@ export function rejectNewerTodoSchema(value, family, ref) {
198
200
  if (newer !== null) failNewer(newer, ref);
199
201
  }
200
202
 
203
+ export function requireTodoStoreWriter(writer, caller) { requireWriter(writer, caller); }
204
+
201
205
  function requireWriter(writer, caller) {
202
206
  if (!exactRecord(writer, ['schema', 'caller']) || writer.schema !== 'lattice.todo_store_writer.v1'
203
207
  || writer.caller !== caller) throw new TypeError(`writer capability for ${caller} required`);
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  import { canonicalizeTodoArtifact, isTodoIdentifier, isTodoRef, todoSelfDigest } from './todo-contracts.mjs';
15
- import { TODO_WITNESS_SET_SCHEMA } from './todo-independence-contracts.mjs';
15
+ import { TODO_WITNESS_SET_READ_ANCHORS_SCHEMA, TODO_WITNESS_SET_SCHEMA } from './todo-independence-contracts.mjs';
16
16
 
17
17
  const compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
18
18
  const sortedUnique = (values) => [...new Set(values)].sort(compareText);
@@ -66,10 +66,12 @@ function explainDraftTask(task, schema) {
66
66
  && isTodoIdentifier(entry.kind) && typeof entry.ref === 'string' && entry.ref.length > 0))) {
67
67
  return { reason: 'invalid_unknowns', path: '/unknowns' };
68
68
  }
69
- if (task.concern_anchors !== undefined && !(Array.isArray(task.concern_anchors)
70
- && task.concern_anchors.every((anchor) => plainObject(anchor) && isTodoRef(anchor.within)
71
- && Array.isArray(anchor.symbols) && anchor.symbols.length > 0 && anchor.symbols.every(isTodoIdentifier)))) {
72
- return { reason: 'invalid_concern_anchors', path: '/concern_anchors' };
69
+ for (const key of ['concern_anchors', 'read_anchors']) {
70
+ if (task[key] !== undefined && !(Array.isArray(task[key])
71
+ && task[key].every((anchor) => plainObject(anchor) && isTodoRef(anchor.within)
72
+ && Array.isArray(anchor.symbols) && anchor.symbols.length > 0 && anchor.symbols.every(isTodoIdentifier)))) {
73
+ return { reason: `invalid_${key}`, path: `/${key}` };
74
+ }
73
75
  }
74
76
  return null;
75
77
  }
@@ -123,6 +125,9 @@ export function witnessDraftTemplate({ projectId, planKey, taskIds, witnessSet =
123
125
  ...(witness.concern_anchors?.length > 0 ? {
124
126
  concern_anchors: witness.concern_anchors.map(({ within, symbols }) => ({ within: within.target, symbols: [...symbols] })),
125
127
  } : {}),
128
+ ...(witness.read_anchors?.length > 0 ? {
129
+ read_anchors: witness.read_anchors.map(({ within, symbols }) => ({ within: within.target, symbols: [...symbols] })),
130
+ } : {}),
126
131
  };
127
132
  };
128
133
  return {
@@ -185,6 +190,13 @@ export function buildWitnessSet({ draft, observationByPath } = {}) {
185
190
  reasons.push(`anchor_outside_owned:${taskId}:${anchor.within}`);
186
191
  }
187
192
  }
193
+ const readTargets = new Set(Array.isArray(task.reads) ? task.reads : []);
194
+ for (const anchor of task.read_anchors ?? []) {
195
+ if (!readTargets.has(anchor.within)) reasons.push(`read_anchor_outside_reads:${taskId}:${anchor.within}`);
196
+ }
197
+ const anchorEntries = (anchors) => [...anchors]
198
+ .map((anchor) => ({ within: { kind: 'path', target: anchor.within }, symbols: sortedUnique(anchor.symbols) }))
199
+ .sort((left, right) => compareText(left.within.target, right.within.target));
188
200
  manualWitness[taskId] = {
189
201
  owns: owns.map(({ target, creates }) => (
190
202
  creates ? { kind: 'path', target, creates: true } : { kind: 'path', target }
@@ -205,21 +217,17 @@ export function buildWitnessSet({ draft, observationByPath } = {}) {
205
217
  .map(({ kind, ref }) => ({ kind, ref }))
206
218
  .sort((left, right) => compareText(`${left.kind}\u0000${left.ref}`, `${right.kind}\u0000${right.ref}`)),
207
219
  ...(Array.isArray(task.concern_anchors) && task.concern_anchors.length > 0
208
- ? {
209
- concern_anchors: [...task.concern_anchors]
210
- .map((anchor) => ({
211
- within: { kind: 'path', target: anchor.within },
212
- symbols: sortedUnique(anchor.symbols),
213
- }))
214
- .sort((left, right) => compareText(left.within.target, right.within.target)),
215
- }
216
- : {}),
220
+ ? { concern_anchors: anchorEntries(task.concern_anchors) } : {}),
221
+ ...(Array.isArray(task.read_anchors) && task.read_anchors.length > 0
222
+ ? { read_anchors: anchorEntries(task.read_anchors) } : {}),
217
223
  };
218
224
  }
219
225
  if (reasons.length > 0) return reject(reasons);
220
226
 
221
227
  const witnessSet = {
222
- schema: TODO_WITNESS_SET_SCHEMA,
228
+ // v6 only when some task reads functions: charts that do not use reads keep v5 and older readers (ADR 0204 §6).
229
+ schema: Object.values(manualWitness).some((witness) => witness.read_anchors !== undefined)
230
+ ? TODO_WITNESS_SET_READ_ANCHORS_SCHEMA : TODO_WITNESS_SET_SCHEMA,
223
231
  project_id: draft.project_id,
224
232
  plan_key: draft.plan_key,
225
233
  capacity: { executors: draft.capacity.executors },