@quolu/lattice 0.79.4 → 0.80.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 (73) hide show
  1. package/bin/lattice-dashboard.mjs +6 -5
  2. package/bin/lattice-mcp.mjs +2 -1
  3. package/docs/bridge-setup.md +8 -0
  4. package/docs/schemas/lattice.plan_create_input.v4.schema.json +8 -4
  5. package/docs/schemas/lattice.todo_extraction.v3.schema.json +5 -3
  6. package/docs/schemas/lattice.todo_extraction.v4.schema.json +5 -3
  7. package/package.json +1 -1
  8. package/sensor/dist/mcp/index.d.ts +3 -1
  9. package/sensor/dist/mcp/index.d.ts.map +1 -1
  10. package/sensor/dist/mcp/index.js +7 -2
  11. package/sensor/dist/mcp/index.js.map +1 -1
  12. package/sensor/dist/mcp/proxy.d.ts +2 -0
  13. package/sensor/dist/mcp/proxy.d.ts.map +1 -1
  14. package/sensor/dist/mcp/proxy.js +9 -3
  15. package/sensor/dist/mcp/proxy.js.map +1 -1
  16. package/sensor/dist/mcp/session.d.ts +7 -0
  17. package/sensor/dist/mcp/session.d.ts.map +1 -1
  18. package/sensor/dist/mcp/session.js +4 -1
  19. package/sensor/dist/mcp/session.js.map +1 -1
  20. package/sensor/dist/mcp/transport.d.ts +5 -5
  21. package/sensor/dist/mcp/transport.d.ts.map +1 -1
  22. package/sensor/dist/mcp/transport.js +14 -6
  23. package/sensor/dist/mcp/transport.js.map +1 -1
  24. package/src/dashboard-lifecycle-journal.mjs +3 -1
  25. package/src/fs-publish.mjs +9 -0
  26. package/src/mcp-startup-receipt.mjs +99 -0
  27. package/src/project-cli.mjs +2 -2
  28. package/src/runtime-os-observation.mjs +18 -1
  29. package/src/setup-config.mjs +7 -3
  30. package/src/store-lock.mjs +250 -0
  31. package/src/todo-cli.mjs +6 -0
  32. package/src/todo-contracts.mjs +95 -50
  33. package/src/todo-migration.mjs +35 -10
  34. package/src/todo-note-store.mjs +45 -12
  35. package/src/todo-readiness.mjs +154 -0
  36. package/src/todo-status.mjs +4 -33
  37. package/src/todo-store-cache.mjs +50 -6
  38. package/src/todo-store-git-transaction.mjs +11 -6
  39. package/src/todo-store-view.mjs +47 -0
  40. package/src/todo-store.mjs +597 -398
  41. package/src/artifact-contracts-v2.mjs +0 -325
  42. package/src/boundary-compiler.mjs +0 -712
  43. package/src/bounded-seam.mjs +0 -230
  44. package/src/control-compiler.mjs +0 -532
  45. package/src/rc1-black-box-oracle.mjs +0 -906
  46. package/src/rc1-comparison.mjs +0 -154
  47. package/src/rc1-evidence-bundle.mjs +0 -456
  48. package/src/rc1-v4-campaign.mjs +0 -708
  49. package/src/rc1-v4-transform.mjs +0 -467
  50. package/src/rc1-v5-artifact-set.mjs +0 -855
  51. package/src/rc1-v5-behavior-evidence.mjs +0 -594
  52. package/src/rc1-v5-campaign.mjs +0 -797
  53. package/src/rc1-v5-transform.mjs +0 -421
  54. package/src/rc1-v6-artifact-set.mjs +0 -807
  55. package/src/rc1-v6-behavior-evidence.mjs +0 -273
  56. package/src/rc1-v6-campaign.mjs +0 -623
  57. package/src/rc1-v6-causal-binding.mjs +0 -473
  58. package/src/rc1-v6-measurement.mjs +0 -313
  59. package/src/rc2-artifact-set.mjs +0 -1584
  60. package/src/rc2-campaign.mjs +0 -1495
  61. package/src/rc2-delivery-policy-front-end.mjs +0 -1079
  62. package/src/rc2-delivery-policy-oracle.mjs +0 -134
  63. package/src/rc2-delivery-policy-transform.mjs +0 -1127
  64. package/src/rc2-rc1-transfer-front-end.mjs +0 -511
  65. package/src/rc3-actual-dogfood.mjs +0 -652
  66. package/src/rc3-dogfood-scaffold.mjs +0 -315
  67. package/src/rc3-scripted-campaign.mjs +0 -1383
  68. package/src/rc4-stage1-dogfood.mjs +0 -673
  69. package/src/runtime-scripted-executor.mjs +0 -163
  70. package/src/runtime-worktree-executor.mjs +0 -199
  71. package/src/seam-transform.mjs +0 -554
  72. package/src/treatment-compiler.mjs +0 -728
  73. package/src/treatment-runner.mjs +0 -656
@@ -1,325 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { isDeepStrictEqual } from 'node:util';
3
-
4
- import { compileBoundaryObservationV2 } from './boundary-observation-compiler-v2.mjs';
5
- import { verifySchedulabilityPlanV2 } from './schedulability-verifier-v2.mjs';
6
-
7
- const OBSERVATION_SCHEMA = 'lattice.boundary_observation_set.v2';
8
- const BUNDLE_SCHEMA = 'lattice.normalized_boundary_bundle.v2';
9
- const GRAPH_SCHEMA = 'lattice.normalized_boundary_graph.v2';
10
- const VERDICT_SCHEMA = 'lattice.boundary_verdict.v2';
11
- const MAX_TODOS = 256;
12
- const IDENTIFIER = /^[0-9A-Za-z](?:[0-9A-Za-z._-]{0,127})$/;
13
- const DIGEST = /^[0-9a-f]{64}$/;
14
-
15
- function contractError(reason) {
16
- throw new TypeError(`artifact contracts v2契約違反: ${reason}`);
17
- }
18
-
19
- function plainRecord(value) {
20
- return value !== null
21
- && typeof value === 'object'
22
- && !Array.isArray(value)
23
- && Object.getPrototypeOf(value) === Object.prototype;
24
- }
25
-
26
- function exactRecord(value, keys) {
27
- if (!plainRecord(value)) return false;
28
- const actual = Object.keys(value).sort();
29
- const expected = [...keys].sort();
30
- return actual.length === expected.length
31
- && actual.every((key, index) => key === expected[index]);
32
- }
33
-
34
- function requireArray(value, label) {
35
- if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype) {
36
- contractError(`${label}がarrayではない`);
37
- }
38
- }
39
-
40
- function identifier(value) {
41
- return typeof value === 'string' && IDENTIFIER.test(value);
42
- }
43
-
44
- function boundedText(value) {
45
- return typeof value === 'string'
46
- && value.length > 0
47
- && value === value.trim()
48
- && Buffer.byteLength(value, 'utf8') <= 4_096;
49
- }
50
-
51
- function compareText(left, right) {
52
- if (left < right) return -1;
53
- if (left > right) return 1;
54
- return 0;
55
- }
56
-
57
- function sha256(value) {
58
- return createHash('sha256').update(value).digest('hex');
59
- }
60
-
61
- function conflictOrder(left, right) {
62
- return compareText(left.todo_ids[0], right.todo_ids[0])
63
- || compareText(left.todo_ids[1], right.todo_ids[1])
64
- || compareText(left.resource_id, right.resource_id);
65
- }
66
-
67
- function precedenceOrder(left, right) {
68
- return compareText(left.from_todo_id, right.from_todo_id)
69
- || compareText(left.to_todo_id, right.to_todo_id)
70
- || compareText(left.reason, right.reason);
71
- }
72
-
73
- function unknownOrder(left, right) {
74
- return compareText(left.todo_id, right.todo_id)
75
- || compareText(left.kind, right.kind)
76
- || compareText(left.reason, right.reason);
77
- }
78
-
79
- function assertAcyclic(todos, precedences) {
80
- const indegree = new Map(todos.map((todoId) => [todoId, 0]));
81
- const outgoing = new Map(todos.map((todoId) => [todoId, new Set()]));
82
- for (const precedence of precedences) {
83
- const next = outgoing.get(precedence.from_todo_id);
84
- if (!next.has(precedence.to_todo_id)) {
85
- next.add(precedence.to_todo_id);
86
- indegree.set(precedence.to_todo_id, indegree.get(precedence.to_todo_id) + 1);
87
- }
88
- }
89
- const ready = todos.filter((todoId) => indegree.get(todoId) === 0);
90
- let visited = 0;
91
- for (let cursor = 0; cursor < ready.length; cursor += 1) {
92
- const todoId = ready[cursor];
93
- visited += 1;
94
- for (const next of outgoing.get(todoId)) {
95
- indegree.set(next, indegree.get(next) - 1);
96
- if (indegree.get(next) === 0) ready.push(next);
97
- }
98
- }
99
- if (visited !== todos.length) contractError('precedencesにcycleがある');
100
- }
101
-
102
- function normalizeGraph(value) {
103
- if (!exactRecord(value, [
104
- 'schema_version',
105
- 'todos',
106
- 'conflicts',
107
- 'precedences',
108
- 'unknowns',
109
- 'capacity',
110
- ]) || value.schema_version !== GRAPH_SCHEMA) {
111
- contractError('normalized graph shapeまたはschema_versionが不正');
112
- }
113
-
114
- requireArray(value.todos, 'todos');
115
- if (value.todos.length < 1
116
- || value.todos.length > MAX_TODOS
117
- || !value.todos.every(identifier)
118
- || new Set(value.todos).size !== value.todos.length) {
119
- contractError('todosがbounded unique identifier arrayではない');
120
- }
121
- const todos = [...value.todos].sort(compareText);
122
- const todoSet = new Set(todos);
123
- if (!Number.isSafeInteger(value.capacity)
124
- || value.capacity < 1
125
- || value.capacity > MAX_TODOS) {
126
- contractError('capacityがbounded positive integerではない');
127
- }
128
-
129
- requireArray(value.conflicts, 'conflicts');
130
- const conflictKeys = new Set();
131
- const conflicts = value.conflicts.map((entry) => {
132
- if (!exactRecord(entry, ['todo_ids', 'resource_id'])) {
133
- contractError('conflict shapeが不正');
134
- }
135
- requireArray(entry.todo_ids, 'conflict.todo_ids');
136
- if (entry.todo_ids.length !== 2
137
- || entry.todo_ids.some((todoId) => !todoSet.has(todoId))
138
- || entry.todo_ids[0] === entry.todo_ids[1]
139
- || !identifier(entry.resource_id)) {
140
- contractError('conflict relationが不正');
141
- }
142
- const todoIds = [...entry.todo_ids].sort(compareText);
143
- const key = `${todoIds[0]}\u0000${todoIds[1]}\u0000${entry.resource_id}`;
144
- if (conflictKeys.has(key)) contractError('conflictが重複している');
145
- conflictKeys.add(key);
146
- return { todo_ids: todoIds, resource_id: entry.resource_id };
147
- }).sort(conflictOrder);
148
-
149
- requireArray(value.precedences, 'precedences');
150
- const precedenceKeys = new Set();
151
- const precedences = value.precedences.map((entry) => {
152
- if (!exactRecord(entry, ['from_todo_id', 'to_todo_id', 'reason'])
153
- || !todoSet.has(entry.from_todo_id)
154
- || !todoSet.has(entry.to_todo_id)
155
- || entry.from_todo_id === entry.to_todo_id
156
- || !boundedText(entry.reason)) {
157
- contractError('precedence relationが不正');
158
- }
159
- const key = `${entry.from_todo_id}\u0000${entry.to_todo_id}\u0000${entry.reason}`;
160
- if (precedenceKeys.has(key)) contractError('precedenceが重複している');
161
- precedenceKeys.add(key);
162
- return {
163
- from_todo_id: entry.from_todo_id,
164
- to_todo_id: entry.to_todo_id,
165
- reason: entry.reason,
166
- };
167
- }).sort(precedenceOrder);
168
- assertAcyclic(todos, precedences);
169
-
170
- requireArray(value.unknowns, 'unknowns');
171
- const unknownKeys = new Set();
172
- const unknowns = value.unknowns.map((entry) => {
173
- if (!exactRecord(entry, ['todo_id', 'kind', 'reason'])
174
- || !todoSet.has(entry.todo_id)
175
- || !identifier(entry.kind)
176
- || !boundedText(entry.reason)) {
177
- contractError('unknown relationが不正');
178
- }
179
- const key = `${entry.todo_id}\u0000${entry.kind}\u0000${entry.reason}`;
180
- if (unknownKeys.has(key)) contractError('unknownが重複している');
181
- unknownKeys.add(key);
182
- return { todo_id: entry.todo_id, kind: entry.kind, reason: entry.reason };
183
- }).sort(unknownOrder);
184
-
185
- return {
186
- schema_version: GRAPH_SCHEMA,
187
- todos,
188
- conflicts,
189
- precedences,
190
- unknowns,
191
- capacity: value.capacity,
192
- };
193
- }
194
-
195
- function canonicalGraph(value) {
196
- const normalized = normalizeGraph(value);
197
- if (!isDeepStrictEqual(value, normalized)) contractError('normalized graphがcanonicalではない');
198
- return normalized;
199
- }
200
-
201
- function graphDigest(graph) {
202
- return sha256(JSON.stringify(graph));
203
- }
204
-
205
- function pairwiseVerdicts(graph) {
206
- return [
207
- ...graph.conflicts.map((conflict) => ({
208
- type: 'conflict',
209
- todo_ids: [...conflict.todo_ids],
210
- resource_id: conflict.resource_id,
211
- })),
212
- ...graph.precedences.map((precedence) => ({
213
- type: 'precedence',
214
- from_todo_id: precedence.from_todo_id,
215
- to_todo_id: precedence.to_todo_id,
216
- reason: precedence.reason,
217
- })),
218
- ];
219
- }
220
-
221
- function observationResource(resource) {
222
- if (!exactRecord(resource, [
223
- 'resource_id',
224
- 'kind',
225
- 'target',
226
- 'todo_ids',
227
- 'provenance',
228
- 'status',
229
- ]) || (resource.status !== 'observed' && resource.status !== 'unknown')) {
230
- contractError('normalized resource shapeが不正');
231
- }
232
- return {
233
- resource_id: resource.resource_id,
234
- kind: resource.kind,
235
- target: resource.target,
236
- todo_ids: resource.todo_ids,
237
- provenance: resource.provenance,
238
- };
239
- }
240
-
241
- function validateSafely(callback) {
242
- try {
243
- return callback() === true;
244
- } catch {
245
- return false;
246
- }
247
- }
248
-
249
- /** @param {unknown} graph @returns {boolean} */
250
- export function validateNormalizedBoundaryGraphV2(graph) {
251
- return validateSafely(() => {
252
- canonicalGraph(graph);
253
- return true;
254
- });
255
- }
256
-
257
- /** @param {unknown} bundle @returns {boolean} */
258
- export function validateNormalizedBoundaryBundleV2(bundle) {
259
- return validateSafely(() => {
260
- if (!exactRecord(bundle, [
261
- 'schema_version',
262
- 'source',
263
- 'resources',
264
- 'precedences',
265
- 'graph',
266
- 'graph_digest',
267
- ]) || bundle.schema_version !== BUNDLE_SCHEMA
268
- || typeof bundle.graph_digest !== 'string'
269
- || !DIGEST.test(bundle.graph_digest)) {
270
- return false;
271
- }
272
- const graph = canonicalGraph(bundle.graph);
273
- requireArray(bundle.resources, 'resources');
274
- requireArray(bundle.precedences, 'precedences');
275
- const observationSet = {
276
- schema_version: OBSERVATION_SCHEMA,
277
- source: bundle.source,
278
- capacity: graph.capacity,
279
- todos: graph.todos,
280
- resources: bundle.resources.map(observationResource),
281
- precedences: bundle.precedences,
282
- };
283
- const recompiled = compileBoundaryObservationV2(observationSet);
284
- return isDeepStrictEqual(bundle, recompiled);
285
- });
286
- }
287
-
288
- /**
289
- * @param {unknown} verdict
290
- * @param {unknown} graph
291
- * @returns {boolean}
292
- */
293
- export function validateBoundaryVerdictV2(verdict, graph) {
294
- return validateSafely(() => {
295
- const normalizedGraph = canonicalGraph(graph);
296
- if (!exactRecord(verdict, [
297
- 'schema_version',
298
- 'normalized_graph_digest',
299
- 'verdicts',
300
- ]) || verdict.schema_version !== VERDICT_SCHEMA
301
- || typeof verdict.normalized_graph_digest !== 'string'
302
- || !DIGEST.test(verdict.normalized_graph_digest)
303
- || verdict.normalized_graph_digest !== graphDigest(normalizedGraph)) {
304
- return false;
305
- }
306
- requireArray(verdict.verdicts, 'verdicts');
307
- return isDeepStrictEqual(verdict.verdicts, pairwiseVerdicts(normalizedGraph));
308
- });
309
- }
310
-
311
- /**
312
- * @param {unknown} plan
313
- * @param {unknown} graph
314
- * @param {unknown} options
315
- * @returns {boolean}
316
- */
317
- export function validatePlanGraphV2(plan, graph, options = {}) {
318
- return validateSafely(() => {
319
- const normalizedGraph = canonicalGraph(graph);
320
- const result = verifySchedulabilityPlanV2(normalizedGraph, plan, options);
321
- return result.outcome === 'verified'
322
- && plainRecord(plan)
323
- && result.minimum_feasible_waves === plan.minimum_feasible_waves;
324
- });
325
- }