amalgm 0.1.239 → 0.1.241

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 (87) hide show
  1. package/lib/shared-realtime-tunnel.js +18 -4
  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/server/routes/state.js +13 -0
  6. package/runtime/scripts/amalgm-mcp/state/attachments.js +40 -12
  7. package/runtime/scripts/amalgm-mcp/state/db.js +216 -17
  8. package/runtime/scripts/amalgm-mcp/state/doc-disk.js +550 -0
  9. package/runtime/scripts/amalgm-mcp/state/docs.js +1101 -301
  10. package/runtime/scripts/amalgm-mcp/state/mutation-contracts.js +99 -0
  11. package/runtime/scripts/amalgm-mcp/state/mutations.js +507 -130
  12. package/runtime/scripts/amalgm-mcp/state/promotions.js +21 -1
  13. package/runtime/scripts/amalgm-mcp/state/replicas.js +134 -13
  14. package/runtime/scripts/amalgm-mcp/state/shared-rest.js +14 -8
  15. package/runtime/scripts/amalgm-mcp/tests/browser-cookie-cloud.test.js +193 -0
  16. package/runtime/scripts/amalgm-mcp/tests/code-project-stream.test.js +313 -94
  17. package/runtime/scripts/amalgm-mcp/tests/fixtures/code-project-stream-v2.json +1 -0
  18. package/runtime/scripts/amalgm-mcp/tests/project-context.test.js +32 -17
  19. package/runtime/scripts/amalgm-mcp/tests/shared-tunnel-rehydration.test.js +84 -0
  20. package/runtime/scripts/amalgm-mcp/tests/state-docs.test.js +376 -13
  21. package/runtime/scripts/amalgm-mcp/tests/state-mutations.test.js +309 -0
  22. package/runtime/scripts/amalgm-mcp/tests/state-shared-replica.test.js +758 -30
  23. package/runtime/scripts/amalgm-mcp/tests/workspace-cards-store.test.js +72 -3
  24. package/runtime/scripts/amalgm-mcp/tests/workspace-cards.test.js +33 -6
  25. package/runtime/scripts/amalgm-mcp/tests/workspace-checkpoint-reducer.test.js +27 -0
  26. package/runtime/scripts/amalgm-mcp/tests/workspace-checkpoint.test.js +334 -191
  27. package/runtime/scripts/amalgm-mcp/tests/workspace-durable.test.js +24 -0
  28. package/runtime/scripts/amalgm-mcp/tests/workspace-local-intent.test.js +1999 -0
  29. package/runtime/scripts/amalgm-mcp/tests/workspace-native-file-transaction.test.js +364 -0
  30. package/runtime/scripts/amalgm-mcp/tests/workspace-object-tunnel.test.js +98 -4
  31. package/runtime/scripts/amalgm-mcp/tests/workspace-objects.test.js +156 -8
  32. package/runtime/scripts/amalgm-mcp/tests/workspace-provenance.test.js +185 -0
  33. package/runtime/scripts/amalgm-mcp/tests/workspace-publication-invariants.test.js +174 -269
  34. package/runtime/scripts/amalgm-mcp/tests/workspace-reducer-liveness.test.js +26 -0
  35. package/runtime/scripts/amalgm-mcp/tests/workspace-reducer.test.js +2060 -407
  36. package/runtime/scripts/amalgm-mcp/tests/workspace-sync-stats.test.js +119 -0
  37. package/runtime/scripts/amalgm-mcp/tests/workspace-transition.test.js +1446 -0
  38. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-cloud.test.js +5319 -3
  39. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-core.test.js +191 -1
  40. package/runtime/scripts/amalgm-mcp/tests/workspace-tree-store.test.js +3140 -17
  41. package/runtime/scripts/amalgm-mcp/tests/workspace-wall.test.js +135 -637
  42. package/runtime/scripts/amalgm-mcp/workspace/access-store.js +5 -1
  43. package/runtime/scripts/amalgm-mcp/workspace/card.js +7 -7
  44. package/runtime/scripts/amalgm-mcp/workspace/cards.js +36 -12
  45. package/runtime/scripts/amalgm-mcp/workspace/checkpoint.js +436 -173
  46. package/runtime/scripts/amalgm-mcp/workspace/content.js +32 -0
  47. package/runtime/scripts/amalgm-mcp/workspace/durable.js +45 -0
  48. package/runtime/scripts/amalgm-mcp/workspace/git.js +391 -37
  49. package/runtime/scripts/amalgm-mcp/workspace/intent.js +535 -0
  50. package/runtime/scripts/amalgm-mcp/workspace/merge.js +89 -6
  51. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/BUILD.md +31 -0
  52. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/bin/darwin-arm64/amalgm-file-transaction +0 -0
  53. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/bin/linux-x64/amalgm-file-transaction +0 -0
  54. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/build.mjs +72 -0
  55. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/client.js +165 -0
  56. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/go.mod +5 -0
  57. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/go.sum +2 -0
  58. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/main.go +2201 -0
  59. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/manifest.json +19 -0
  60. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/move_darwin.go +18 -0
  61. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/move_linux.go +18 -0
  62. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/process_darwin.go +33 -0
  63. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/process_linux.go +47 -0
  64. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/verify.mjs +43 -0
  65. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/writers_darwin.go +114 -0
  66. package/runtime/scripts/amalgm-mcp/workspace/native-file-transaction/writers_linux.go +84 -0
  67. package/runtime/scripts/amalgm-mcp/workspace/objects.js +185 -55
  68. package/runtime/scripts/amalgm-mcp/workspace/project-stream.js +616 -168
  69. package/runtime/scripts/amalgm-mcp/workspace/provenance.js +240 -0
  70. package/runtime/scripts/amalgm-mcp/workspace/reducer.js +1979 -570
  71. package/runtime/scripts/amalgm-mcp/workspace/rest.js +49 -28
  72. package/runtime/scripts/amalgm-mcp/workspace/store.js +77 -4
  73. package/runtime/scripts/amalgm-mcp/workspace/sync-stats.js +240 -0
  74. package/runtime/scripts/amalgm-mcp/workspace/transition.js +1729 -192
  75. package/runtime/scripts/amalgm-mcp/workspace/tree/floor.js +100 -0
  76. package/runtime/scripts/amalgm-mcp/workspace/tree/inclusion.js +7 -1
  77. package/runtime/scripts/amalgm-mcp/workspace/tree/local-state.js +73 -61
  78. package/runtime/scripts/amalgm-mcp/workspace/tree/observation-holds.js +127 -0
  79. package/runtime/scripts/amalgm-mcp/workspace/tree/path-state.js +12 -0
  80. package/runtime/scripts/amalgm-mcp/workspace/tree/reducer.js +51 -6
  81. package/runtime/scripts/amalgm-mcp/workspace/tree/root-binding.js +125 -0
  82. package/runtime/scripts/amalgm-mcp/workspace/tree/snapshot.js +79 -8
  83. package/runtime/scripts/amalgm-mcp/workspace/tree/symlinks.js +76 -0
  84. package/runtime/scripts/amalgm-mcp/workspace/tree-cloud.js +3480 -165
  85. package/runtime/scripts/amalgm-mcp/workspace/tree-materialization.js +3766 -0
  86. package/runtime/scripts/amalgm-mcp/workspace/tree-store.js +899 -71
  87. package/runtime/scripts/amalgm-mcp/workspace/wall.js +352 -497
@@ -10,7 +10,9 @@
10
10
 
11
11
  const { decryptJson, encryptJson } = require('../browser/auth-vault');
12
12
 
13
+ const CODE_PROJECT_CONTRACT = 'code-project-stream@2';
13
14
  const COOKIE_CONTRACT = 'browser-cookie-jar@1';
15
+ const WORKSPACE_TREE_CONTRACT = 'workspace-tree@1';
14
16
  const PROTECTED_KIND = 'amalgm.encrypted-json@1';
15
17
 
16
18
  function isSensitiveContract(contract) {
@@ -47,10 +49,107 @@ function diagnosticOperation(contract, operation) {
47
49
  };
48
50
  }
49
51
 
52
+ /**
53
+ * A numbered code publication may leave the generic journal only after the
54
+ * canonical code-project snapshot carries at least that contiguous number.
55
+ */
56
+ function codeProjectOrderIsDurable(row, options = {}) {
57
+ const database = options.database;
58
+ const version = Number(row.official_cloud_version);
59
+ if (
60
+ !database
61
+ || !row.shared_resource_id
62
+ || !Number.isSafeInteger(version)
63
+ || version < 1
64
+ ) return false;
65
+
66
+ const cache = options.snapshotCache;
67
+ let snapshot = cache?.get(row.shared_resource_id);
68
+ if (snapshot === undefined) {
69
+ const replica = database.prepare(`
70
+ SELECT local_path, applied_version
71
+ FROM shared_resource_replicas
72
+ WHERE resource_id = ?
73
+ `).get(row.shared_resource_id);
74
+ try {
75
+ snapshot = (
76
+ replica?.local_path
77
+ && Number.isSafeInteger(Number(replica.applied_version))
78
+ ) ? require('../workspace/project-stream').readSnapshot(
79
+ replica.local_path,
80
+ row.shared_resource_id,
81
+ ) : null;
82
+ if (snapshot && snapshot.version !== Number(replica.applied_version)) {
83
+ snapshot = null;
84
+ }
85
+ } catch {
86
+ snapshot = null;
87
+ }
88
+ cache?.set(row.shared_resource_id, snapshot);
89
+ }
90
+
91
+ if (
92
+ !snapshot
93
+ || snapshot.version < version
94
+ ) return false;
95
+ return true;
96
+ }
97
+
98
+ /**
99
+ * A local code outbox row may leave only after another durable local fact can
100
+ * finish recovery: either the folded intent still names it, or the verified
101
+ * physical repo has already advanced through it.
102
+ */
103
+ function codeProjectLocalRecoveryIsDurable(row) {
104
+ if (row.mutation_origin !== 'local') return true;
105
+ const project = require('../workspace/wall').projectForResource(row.shared_resource_id);
106
+ if (!project) return false;
107
+ const intent = require('../workspace/intent').readIntent(project);
108
+ if (
109
+ intent?.publication?.mutationId === row.mutation_id
110
+ && intent.publication.numberedVersion === Number(row.official_cloud_version)
111
+ && typeof intent.publication.foldedAt === 'string'
112
+ ) return true;
113
+ const state = require('../workspace/reducer').readRepoState(
114
+ project.repoKey,
115
+ project.resourceId,
116
+ );
117
+ return state?.materialized === true
118
+ && Number.isSafeInteger(state.appliedThrough)
119
+ && state.appliedThrough >= Number(row.official_cloud_version);
120
+ }
121
+
122
+ function mutationMayPrune(row, options = {}) {
123
+ if (row.contract !== CODE_PROJECT_CONTRACT) return true;
124
+ return codeProjectOrderIsDurable(row, options)
125
+ && codeProjectLocalRecoveryIsDurable(row);
126
+ }
127
+
128
+ function mutationNeedsOfficialMaterialization(contract) {
129
+ return contract === CODE_PROJECT_CONTRACT;
130
+ }
131
+
132
+ /**
133
+ * Some locally materialized contracts still need their own numbered echo to
134
+ * move the official floor. They may not let generic acknowledgement logic
135
+ * mark the row projected or advance the cursor merely because local bytes
136
+ * already resemble the event.
137
+ */
138
+ function mutationNeedsOrderedEcho(contract) {
139
+ return contract === CODE_PROJECT_CONTRACT || contract === WORKSPACE_TREE_CONTRACT;
140
+ }
141
+
50
142
  module.exports = {
143
+ CODE_PROJECT_CONTRACT,
51
144
  COOKIE_CONTRACT,
145
+ WORKSPACE_TREE_CONTRACT,
146
+ codeProjectLocalRecoveryIsDurable,
147
+ codeProjectOrderIsDurable,
52
148
  diagnosticOperation,
53
149
  isSensitiveContract,
150
+ mutationMayPrune,
151
+ mutationNeedsOfficialMaterialization,
152
+ mutationNeedsOrderedEcho,
54
153
  protectOperation,
55
154
  revealOperation,
56
155
  };