@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,273 +0,0 @@
1
- import { isDeepStrictEqual } from 'node:util';
2
-
3
- import {
4
- digestArtifact,
5
- validateTransformArtifact,
6
- } from './artifact-contracts.mjs';
7
- import { verifyRc1V6BehaviorReceipt } from './rc1-v6-causal-binding.mjs';
8
- import { sourceSnapshotFromRc1BehaviorSurface } from './rc1-v6-measurement.mjs';
9
-
10
- const SHA256 = /^[0-9a-f]{64}$/;
11
- const GIT_SHA1 = /^[0-9a-f]{40}$/;
12
- const ENVELOPE_KEYS = [
13
- 'schema',
14
- 'base_sha',
15
- 'oracle_digest',
16
- 'runtime_identity_digest',
17
- 'case_contract_digest',
18
- 'pre_receipt_digest',
19
- 'post_receipt_digest',
20
- 'pre_surface_digest',
21
- 'post_surface_digest',
22
- 'transform_artifact_digest',
23
- 'patch_digest',
24
- 'output_snapshot_digest',
25
- 'envelope_digest',
26
- ];
27
-
28
- function exactRecord(value, keys) {
29
- if (value === null || typeof value !== 'object' || Array.isArray(value)
30
- || Object.getPrototypeOf(value) !== Object.prototype) {
31
- return false;
32
- }
33
- const actual = Object.keys(value).sort();
34
- const expected = [...keys].sort();
35
- return actual.length === expected.length
36
- && actual.every((key, index) => key === expected[index]);
37
- }
38
-
39
- function repoPath(value) {
40
- return typeof value === 'string'
41
- && value.length > 0
42
- && value.length <= 512
43
- && !value.startsWith('/')
44
- && !value.includes('\\')
45
- && !value.split('/').includes('..');
46
- }
47
-
48
- function verification(checks) {
49
- const failedConditions = checks.filter(({ passed }) => !passed).map(({ id }) => id);
50
- return {
51
- schema: 'lattice.rc1.behavior_evidence_verification.v1',
52
- valid: failedConditions.length === 0,
53
- checks,
54
- failed_conditions: failedConditions,
55
- };
56
- }
57
-
58
- function digestWithout(value, field) {
59
- if (value === null || typeof value !== 'object' || Array.isArray(value)) return null;
60
- try {
61
- const { [field]: ignored, ...preimage } = value;
62
- return digestArtifact(preimage);
63
- } catch {
64
- return null;
65
- }
66
- }
67
-
68
- function validSurface(value) {
69
- if (!exactRecord(value, ['schema', 'files'])
70
- || value.schema !== 'lattice.rc1.behavior_surface_snapshot.v1'
71
- || !Array.isArray(value.files)
72
- || value.files.length === 0
73
- || value.files.length > 128) {
74
- return false;
75
- }
76
- return value.files.every((file, index) => (
77
- exactRecord(file, ['path', 'state', 'content_digest'])
78
- && repoPath(file.path)
79
- && (index === 0 || value.files[index - 1].path < file.path)
80
- && (file.state === 'present' || file.state === 'absent')
81
- && (file.state === 'present'
82
- ? typeof file.content_digest === 'string' && SHA256.test(file.content_digest)
83
- : file.content_digest === null)
84
- ));
85
- }
86
-
87
- function validAcceptedTransform(value) {
88
- return validateTransformArtifact(value)
89
- && value.status === 'accepted'
90
- && GIT_SHA1.test(value.source?.base_sha)
91
- && SHA256.test(value.source?.code_snapshot_digest)
92
- && SHA256.test(value.patch?.digest)
93
- && Array.isArray(value.scope?.allowed_paths)
94
- && value.scope.allowed_paths.length > 0
95
- && Array.isArray(value.output?.files)
96
- && value.output.files.length > 0
97
- && SHA256.test(value.output?.snapshot_digest)
98
- && value.output.snapshot_digest === digestArtifact({ files: value.output.files });
99
- }
100
-
101
- function surfacePaths(surface) {
102
- return validSurface(surface) ? surface.files.map(({ path }) => path) : [];
103
- }
104
-
105
- function outputProjection(surface) {
106
- if (!validSurface(surface) || surface.files.some(({ state }) => state !== 'present')) return null;
107
- return {
108
- files: surface.files.map(({ path, content_digest: contentDigest }) => ({
109
- path,
110
- content_digest: contentDigest,
111
- })),
112
- };
113
- }
114
-
115
- function envelopeValid(value) {
116
- return exactRecord(value, ENVELOPE_KEYS)
117
- && value.schema === 'lattice.rc1.behavior_evidence_envelope.v2'
118
- && GIT_SHA1.test(value.base_sha)
119
- && [
120
- value.oracle_digest,
121
- value.runtime_identity_digest,
122
- value.case_contract_digest,
123
- value.pre_receipt_digest,
124
- value.post_receipt_digest,
125
- value.pre_surface_digest,
126
- value.post_surface_digest,
127
- value.transform_artifact_digest,
128
- value.patch_digest,
129
- value.output_snapshot_digest,
130
- value.envelope_digest,
131
- ].every((entry) => typeof entry === 'string' && SHA256.test(entry))
132
- && value.envelope_digest === digestWithout(value, 'envelope_digest');
133
- }
134
-
135
- function behaviorChecks(options) {
136
- const inputValid = exactRecord(options, [
137
- 'oracle',
138
- 'runtimeIdentity',
139
- 'preReceipt',
140
- 'postReceipt',
141
- 'transformArtifact',
142
- 'patchDigest',
143
- 'envelope',
144
- ]);
145
- const oracle = inputValid ? options.oracle : null;
146
- const runtimeIdentity = inputValid ? options.runtimeIdentity : null;
147
- const pre = inputValid ? options.preReceipt : null;
148
- const post = inputValid ? options.postReceipt : null;
149
- const transform = inputValid ? options.transformArtifact : null;
150
- const patchDigest = inputValid ? options.patchDigest : null;
151
- const envelope = inputValid ? options.envelope : null;
152
- const preVerification = inputValid ? verifyRc1V6BehaviorReceipt({
153
- receipt: pre,
154
- oracle,
155
- expectedRole: 'pre_transform',
156
- expectedRuntimeIdentity: runtimeIdentity,
157
- }) : { valid: false };
158
- const postVerification = inputValid ? verifyRc1V6BehaviorReceipt({
159
- receipt: post,
160
- oracle,
161
- expectedRole: 'post_transform',
162
- expectedRuntimeIdentity: runtimeIdentity,
163
- }) : { valid: false };
164
- const receiptsValid = preVerification.valid && postVerification.valid;
165
- const transformValid = inputValid && validAcceptedTransform(transform);
166
- const validEnvelope = inputValid && envelopeValid(envelope);
167
- const preSurfaceValid = receiptsValid && validSurface(pre.surface);
168
- const postSurfaceValid = receiptsValid && validSurface(post.surface);
169
- const prePaths = preSurfaceValid ? surfacePaths(pre.surface) : [];
170
- const postPaths = postSurfaceValid ? surfacePaths(post.surface) : [];
171
- const projection = postSurfaceValid ? outputProjection(post.surface) : null;
172
- const outputBound = transformValid
173
- && projection !== null
174
- && isDeepStrictEqual(prePaths, postPaths)
175
- && isDeepStrictEqual(postPaths, transform.scope.allowed_paths)
176
- && digestArtifact(projection) === transform.output.snapshot_digest
177
- && digestArtifact(projection.files) === digestArtifact(transform.output.files);
178
-
179
- return [
180
- { id: 'input_contract', passed: inputValid },
181
- { id: 'pre_receipt', passed: preVerification.valid },
182
- { id: 'post_receipt', passed: postVerification.valid },
183
- { id: 'envelope_contract', passed: validEnvelope },
184
- { id: 'transform_contract', passed: transformValid },
185
- {
186
- id: 'base_binding',
187
- passed: receiptsValid && transformValid
188
- && pre.base_sha === post.base_sha
189
- && pre.base_sha === transform.source.base_sha,
190
- },
191
- {
192
- id: 'oracle_runtime_binding',
193
- passed: receiptsValid
194
- && pre.oracle_digest === post.oracle_digest
195
- && pre.runtime_identity_digest === post.runtime_identity_digest
196
- && pre.case_contract_digest === post.case_contract_digest,
197
- },
198
- {
199
- id: 'behavior_outcome',
200
- passed: receiptsValid && pre.outcome === 'passed' && post.outcome === 'passed',
201
- },
202
- {
203
- id: 'pre_source_binding',
204
- passed: preSurfaceValid && transformValid
205
- && digestArtifact(sourceSnapshotFromRc1BehaviorSurface(pre.surface))
206
- === transform.source.code_snapshot_digest,
207
- },
208
- { id: 'post_output_binding', passed: outputBound },
209
- {
210
- id: 'patch_binding',
211
- passed: transformValid
212
- && typeof patchDigest === 'string'
213
- && SHA256.test(patchDigest)
214
- && patchDigest === transform.patch.digest,
215
- },
216
- {
217
- id: 'envelope_binding',
218
- passed: receiptsValid && transformValid && validEnvelope && outputBound
219
- && envelope.base_sha === pre.base_sha
220
- && envelope.oracle_digest === pre.oracle_digest
221
- && envelope.runtime_identity_digest === pre.runtime_identity_digest
222
- && envelope.case_contract_digest === pre.case_contract_digest
223
- && envelope.pre_receipt_digest === pre.receipt_digest
224
- && envelope.post_receipt_digest === post.receipt_digest
225
- && envelope.pre_surface_digest === pre.surface_digest
226
- && envelope.post_surface_digest === post.surface_digest
227
- && envelope.transform_artifact_digest === digestArtifact(transform)
228
- && envelope.patch_digest === patchDigest
229
- && envelope.output_snapshot_digest === transform.output.snapshot_digest,
230
- },
231
- ];
232
- }
233
-
234
- /** v6 full receiptsをsaved oracle、runtime、accepted transformへcross-bindする。 */
235
- export function compileRc1V6BehaviorEvidence(options = {}) {
236
- if (!exactRecord(options, [
237
- 'oracle',
238
- 'runtimeIdentity',
239
- 'preReceipt',
240
- 'postReceipt',
241
- 'transformArtifact',
242
- 'patchDigest',
243
- ])) {
244
- throw new TypeError('RC1 v6 behavior evidence契約違反: input shapeが不正');
245
- }
246
- const preimage = {
247
- schema: 'lattice.rc1.behavior_evidence_envelope.v2',
248
- base_sha: options.preReceipt?.base_sha,
249
- oracle_digest: options.preReceipt?.oracle_digest,
250
- runtime_identity_digest: options.preReceipt?.runtime_identity_digest,
251
- case_contract_digest: options.preReceipt?.case_contract_digest,
252
- pre_receipt_digest: options.preReceipt?.receipt_digest,
253
- post_receipt_digest: options.postReceipt?.receipt_digest,
254
- pre_surface_digest: options.preReceipt?.surface_digest,
255
- post_surface_digest: options.postReceipt?.surface_digest,
256
- transform_artifact_digest: digestArtifact(options.transformArtifact),
257
- patch_digest: options.patchDigest,
258
- output_snapshot_digest: options.transformArtifact?.output?.snapshot_digest,
259
- };
260
- const envelope = { ...preimage, envelope_digest: digestArtifact(preimage) };
261
- const result = verifyRc1V6BehaviorEvidence({ ...options, envelope });
262
- if (!result.valid) {
263
- throw new TypeError(
264
- `RC1 v6 behavior evidence契約違反: cross-binding failed: ${result.failed_conditions.join(', ')}`,
265
- );
266
- }
267
- return envelope;
268
- }
269
-
270
- /** 保存artifactだけからv6 behavior evidenceの全cross-bindingを再計算する。 */
271
- export function verifyRc1V6BehaviorEvidence(options = {}) {
272
- return verification(behaviorChecks(options));
273
- }