amalgm 0.1.238 → 0.1.240

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 (86) hide show
  1. package/lib/shared-realtime-tunnel.js +22 -14
  2. package/package.json +1 -1
  3. package/runtime/scripts/amalgm-mcp/browser/cookie-jar.js +68 -20
  4. package/runtime/scripts/amalgm-mcp/project-context/store.js +87 -19
  5. package/runtime/scripts/amalgm-mcp/state/attachments.js +40 -12
  6. package/runtime/scripts/amalgm-mcp/state/db.js +216 -17
  7. package/runtime/scripts/amalgm-mcp/state/doc-disk.js +550 -0
  8. package/runtime/scripts/amalgm-mcp/state/docs.js +1101 -301
  9. package/runtime/scripts/amalgm-mcp/state/mutation-contracts.js +99 -0
  10. package/runtime/scripts/amalgm-mcp/state/mutations.js +507 -130
  11. package/runtime/scripts/amalgm-mcp/state/promotions.js +21 -1
  12. package/runtime/scripts/amalgm-mcp/state/replicas.js +134 -13
  13. package/runtime/scripts/amalgm-mcp/state/shared-rest.js +14 -8
  14. package/runtime/scripts/amalgm-mcp/tests/browser-cookie-cloud.test.js +193 -0
  15. package/runtime/scripts/amalgm-mcp/tests/code-project-stream.test.js +313 -94
  16. package/runtime/scripts/amalgm-mcp/tests/fixtures/code-project-stream-v2.json +1 -0
  17. package/runtime/scripts/amalgm-mcp/tests/project-context.test.js +32 -17
  18. package/runtime/scripts/amalgm-mcp/tests/shared-tunnel-rehydration.test.js +84 -0
  19. package/runtime/scripts/amalgm-mcp/tests/state-docs.test.js +376 -13
  20. package/runtime/scripts/amalgm-mcp/tests/state-mutations.test.js +309 -0
  21. package/runtime/scripts/amalgm-mcp/tests/state-shared-replica.test.js +758 -30
  22. package/runtime/scripts/amalgm-mcp/tests/workspace-cards-store.test.js +72 -3
  23. package/runtime/scripts/amalgm-mcp/tests/workspace-cards.test.js +33 -6
  24. package/runtime/scripts/amalgm-mcp/tests/workspace-checkpoint-reducer.test.js +27 -0
  25. package/runtime/scripts/amalgm-mcp/tests/workspace-checkpoint.test.js +334 -191
  26. package/runtime/scripts/amalgm-mcp/tests/workspace-durable.test.js +24 -0
  27. package/runtime/scripts/amalgm-mcp/tests/workspace-local-intent.test.js +1999 -0
  28. package/runtime/scripts/amalgm-mcp/tests/workspace-native-file-transaction.test.js +364 -0
  29. package/runtime/scripts/amalgm-mcp/tests/workspace-object-tunnel.test.js +81 -3
  30. package/runtime/scripts/amalgm-mcp/tests/workspace-objects.test.js +114 -8
  31. package/runtime/scripts/amalgm-mcp/tests/workspace-provenance.test.js +185 -0
  32. package/runtime/scripts/amalgm-mcp/tests/workspace-publication-invariants.test.js +174 -269
  33. package/runtime/scripts/amalgm-mcp/tests/workspace-reducer-liveness.test.js +26 -0
  34. package/runtime/scripts/amalgm-mcp/tests/workspace-reducer.test.js +2060 -407
  35. package/runtime/scripts/amalgm-mcp/tests/workspace-sync-stats.test.js +119 -0
  36. package/runtime/scripts/amalgm-mcp/tests/workspace-transition.test.js +1446 -0
  37. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-cloud.test.js +5319 -3
  38. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-core.test.js +191 -1
  39. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-store.test.js +3140 -17
  40. package/runtime/scripts/amalgm-mcp/tests/workspace-wall.test.js +135 -637
  41. package/runtime/scripts/amalgm-mcp/workspace/access-store.js +5 -1
  42. package/runtime/scripts/amalgm-mcp/workspace/card.js +7 -7
  43. package/runtime/scripts/amalgm-mcp/workspace/cards.js +36 -12
  44. package/runtime/scripts/amalgm-mcp/workspace/checkpoint.js +436 -173
  45. package/runtime/scripts/amalgm-mcp/workspace/content.js +32 -0
  46. package/runtime/scripts/amalgm-mcp/workspace/durable.js +45 -0
  47. package/runtime/scripts/amalgm-mcp/workspace/git.js +391 -37
  48. package/runtime/scripts/amalgm-mcp/workspace/intent.js +535 -0
  49. package/runtime/scripts/amalgm-mcp/workspace/merge.js +89 -6
  50. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/BUILD.md +31 -0
  51. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/bin/darwin-arm64/amalgm-file-transaction +0 -0
  52. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/bin/linux-x64/amalgm-file-transaction +0 -0
  53. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/build.mjs +72 -0
  54. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/client.js +165 -0
  55. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/go.mod +5 -0
  56. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/go.sum +2 -0
  57. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/main.go +2201 -0
  58. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/manifest.json +19 -0
  59. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/move_darwin.go +18 -0
  60. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/move_linux.go +18 -0
  61. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/process_darwin.go +33 -0
  62. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/process_linux.go +47 -0
  63. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/verify.mjs +43 -0
  64. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/writers_darwin.go +114 -0
  65. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/writers_linux.go +84 -0
  66. package/runtime/scripts/amalgm-mcp/workspace/objects.js +119 -54
  67. package/runtime/scripts/amalgm-mcp/workspace/project-stream.js +616 -168
  68. package/runtime/scripts/amalgm-mcp/workspace/provenance.js +240 -0
  69. package/runtime/scripts/amalgm-mcp/workspace/reducer.js +1979 -570
  70. package/runtime/scripts/amalgm-mcp/workspace/rest.js +49 -28
  71. package/runtime/scripts/amalgm-mcp/workspace/store.js +77 -4
  72. package/runtime/scripts/amalgm-mcp/workspace/sync-stats.js +240 -0
  73. package/runtime/scripts/amalgm-mcp/workspace/transition.js +1729 -192
  74. package/runtime/scripts/amalgm-mcp/workspace/tree/floor.js +100 -0
  75. package/runtime/scripts/amalgm-mcp/workspace/tree/inclusion.js +7 -1
  76. package/runtime/scripts/amalgm-mcp/workspace/tree/local-state.js +73 -61
  77. package/runtime/scripts/amalgm-mcp/workspace/tree/observation-holds.js +127 -0
  78. package/runtime/scripts/amalgm-mcp/workspace/tree/path-state.js +12 -0
  79. package/runtime/scripts/amalgm-mcp/workspace/tree/reducer.js +51 -6
  80. package/runtime/scripts/amalgm-mcp/workspace/tree/root-binding.js +125 -0
  81. package/runtime/scripts/amalgm-mcp/workspace/tree/snapshot.js +79 -8
  82. package/runtime/scripts/amalgm-mcp/workspace/tree/symlinks.js +76 -0
  83. package/runtime/scripts/amalgm-mcp/workspace/tree-cloud.js +3480 -165
  84. package/runtime/scripts/amalgm-mcp/workspace/tree-materialization.js +3766 -0
  85. package/runtime/scripts/amalgm-mcp/workspace/tree-store.js +899 -71
  86. package/runtime/scripts/amalgm-mcp/workspace/wall.js +352 -497
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const test = require('node:test');
5
+
6
+ const provenance = require('../workspace/provenance');
7
+
8
+ const {
9
+ ACTION,
10
+ CLASS,
11
+ STATE,
12
+ TRANSITIONS,
13
+ allStates,
14
+ provenanceClass,
15
+ publicationState,
16
+ requireTransition,
17
+ } = provenance;
18
+
19
+ const key = (from, action, to) => `${from} --${action}--> ${to}`;
20
+
21
+ test('managed bytes have exactly three provenance classes', () => {
22
+ assert.deepEqual(Object.values(CLASS), [
23
+ 'officially-applied',
24
+ 'journaled-local-intent',
25
+ 'unknown-provenance',
26
+ ]);
27
+ assert.deepEqual(
28
+ [...new Set(allStates.map(provenanceClass))].sort(),
29
+ Object.values(CLASS).sort(),
30
+ );
31
+ assert.equal(allStates.every((state) => provenanceClass(state) !== null), true);
32
+ });
33
+
34
+ test('the complete provenance transition relation has no implicit branch', () => {
35
+ const legal = new Set(TRANSITIONS.map((entry) => key(
36
+ entry.from,
37
+ entry.action,
38
+ entry.to,
39
+ )));
40
+ assert.equal(legal.size, TRANSITIONS.length, 'every transition is named once');
41
+
42
+ for (const from of allStates) {
43
+ for (const action of Object.values(ACTION)) {
44
+ for (const to of allStates) {
45
+ const transitionKey = key(from, action, to);
46
+ if (legal.has(transitionKey)) {
47
+ const entry = TRANSITIONS.find((candidate) => (
48
+ key(candidate.from, candidate.action, candidate.to) === transitionKey
49
+ ));
50
+ assert.ok(entry.facts.length > 0, `${transitionKey} names its durable facts`);
51
+ assert.equal(
52
+ requireTransition(from, action, to, entry.facts),
53
+ entry,
54
+ transitionKey,
55
+ );
56
+ } else {
57
+ assert.throws(
58
+ () => requireTransition(from, action, to),
59
+ /illegal provenance transition/,
60
+ transitionKey,
61
+ );
62
+ }
63
+ }
64
+ }
65
+ }
66
+ });
67
+
68
+ test('publication substates keep numbering, folding, and physical apply distinct', () => {
69
+ const publication = {
70
+ mutationId: 'mutation_provenance_state_01',
71
+ numberedVersion: null,
72
+ numberedAt: null,
73
+ foldedAt: null,
74
+ };
75
+ assert.equal(publicationState(null), STATE.CAPTURED);
76
+ assert.equal(publicationState(publication), STATE.RESERVED);
77
+ assert.equal(publicationState({
78
+ ...publication,
79
+ numberedVersion: 51,
80
+ numberedAt: '2026-07-27T00:00:00.000Z',
81
+ }), STATE.NUMBERED);
82
+ assert.equal(publicationState({
83
+ ...publication,
84
+ numberedVersion: 51,
85
+ numberedAt: '2026-07-27T00:00:00.000Z',
86
+ foldedAt: '2026-07-27T00:00:01.000Z',
87
+ }), STATE.FOLDED);
88
+
89
+ assert.throws(
90
+ () => requireTransition(
91
+ STATE.RESERVED,
92
+ ACTION.NUMBER,
93
+ STATE.NUMBERED,
94
+ ['publication-id', 'official-version'],
95
+ ),
96
+ /server-receipt/,
97
+ );
98
+ assert.throws(
99
+ () => requireTransition(
100
+ STATE.NUMBERED,
101
+ ACTION.APPLY,
102
+ STATE.OFFICIAL,
103
+ [],
104
+ ),
105
+ /illegal provenance transition/,
106
+ 'numbered work must fold before physical apply',
107
+ );
108
+ });
109
+
110
+ test('unknown bytes can only verify, capture, or remain unknown', () => {
111
+ const outgoing = TRANSITIONS
112
+ .filter((entry) => entry.from === STATE.UNKNOWN)
113
+ .map((entry) => [entry.action, entry.to])
114
+ .sort();
115
+ assert.deepEqual(outgoing, [
116
+ [ACTION.CAPTURE, STATE.CAPTURED],
117
+ [ACTION.OBSERVE_UNKNOWN, STATE.UNKNOWN],
118
+ [ACTION.RECOVER, STATE.UNKNOWN],
119
+ [ACTION.SNAPSHOT, STATE.OFFICIAL],
120
+ [ACTION.SNAPSHOT, STATE.UNKNOWN],
121
+ [ACTION.VERIFY, STATE.OFFICIAL],
122
+ ].sort());
123
+ assert.equal(
124
+ outgoing.some(([action]) => (
125
+ action === ACTION.RESERVE
126
+ || action === ACTION.RETRY
127
+ || action === ACTION.APPLY
128
+ )),
129
+ false,
130
+ );
131
+ });
132
+
133
+ test('server compaction, local journal prune, and intent retirement are distinct', () => {
134
+ const prunes = TRANSITIONS.filter((entry) => entry.action === ACTION.PRUNE);
135
+ assert.deepEqual(prunes[0], {
136
+ from: STATE.FOLDED,
137
+ action: ACTION.PRUNE,
138
+ to: STATE.FOLDED,
139
+ facts: [
140
+ 'official-fold',
141
+ 'durable-folded-intent',
142
+ ],
143
+ });
144
+ assert.deepEqual(prunes[1], {
145
+ from: STATE.OFFICIAL,
146
+ action: ACTION.PRUNE,
147
+ to: STATE.OFFICIAL,
148
+ facts: [
149
+ 'official-fold',
150
+ 'physical-verification',
151
+ 'applied-cursor',
152
+ ],
153
+ });
154
+ const compact = TRANSITIONS.find((entry) => entry.action === ACTION.COMPACT);
155
+ assert.deepEqual(compact.facts, [
156
+ 'retained-server-receipt',
157
+ 'verified-server-snapshot',
158
+ ]);
159
+ const physicalApply = TRANSITIONS.find((entry) => (
160
+ entry.from === STATE.FOLDED
161
+ && entry.action === ACTION.APPLY
162
+ && entry.to === STATE.OFFICIAL
163
+ ));
164
+ assert.deepEqual(physicalApply.facts.slice(-3), [
165
+ 'physical-verification',
166
+ 'applied-cursor',
167
+ 'intent-retired',
168
+ ]);
169
+ });
170
+
171
+ test('WAL recovery keeps source and target provenance but exposes any third value', () => {
172
+ for (const state of allStates.filter((candidate) => candidate !== STATE.UNKNOWN)) {
173
+ assert.ok(TRANSITIONS.some((entry) => (
174
+ entry.from === state
175
+ && entry.action === ACTION.RECOVER
176
+ && entry.to === state
177
+ )));
178
+ assert.ok(TRANSITIONS.some((entry) => (
179
+ entry.from === state
180
+ && entry.action === ACTION.RECOVER
181
+ && entry.to === STATE.UNKNOWN
182
+ && entry.facts.includes('exact-third-value-observation')
183
+ )));
184
+ }
185
+ });