enigma-memory 0.1.18 → 0.1.22

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 (276) hide show
  1. package/README.md +76 -24
  2. package/apps/cli/bin/enigma-desktop.mjs +140 -0
  3. package/apps/cli/bin/enigma-terminal.mjs +78 -0
  4. package/apps/cli/bin/enigma.mjs +1923 -285
  5. package/apps/desktop/electron-main.cjs +217 -0
  6. package/apps/desktop/package.json +12 -0
  7. package/apps/desktop/src/app.js +264 -7
  8. package/apps/desktop/src/index.html +3514 -1373
  9. package/apps/desktop/src/launch-electron.mjs +51 -0
  10. package/apps/desktop/src/server.mjs +2914 -0
  11. package/apps/desktop/src/styles.css +2972 -260
  12. package/apps/desktop/src/zk-browser-prove.mjs +53 -0
  13. package/apps/desktop/src/zk-state.mjs +1789 -0
  14. package/apps/gateway/bin/enigma-gateway.mjs +102 -5
  15. package/apps/gateway/src/server.mjs +271 -8
  16. package/apps/ios/EnigmaCore/Package.swift +12 -0
  17. package/apps/ios/EnigmaCore/Sources/EnigmaCore/EnigmaAPIClient.swift +227 -0
  18. package/apps/ios/EnigmaCore/Sources/EnigmaCore/Models.swift +278 -0
  19. package/apps/ios/EnigmaCore/Sources/EnigmaCore/PKCE.swift +96 -0
  20. package/apps/ios/EnigmaCore/Sources/EnigmaCore/PrivacyMinimizer.swift +187 -0
  21. package/apps/ios/EnigmaCore/Sources/EnigmaCore/ToolModels.swift +129 -0
  22. package/apps/ios/EnigmaCore/Tests/EnigmaCoreTests/EnigmaCoreTests.swift +42 -0
  23. package/apps/ios/EnigmaIOS/Enigma/AppModel.swift +346 -0
  24. package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AccentColor.colorset/Contents.json +12 -0
  25. package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/Contents.json +11 -0
  26. package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/EnigmaAppIcon.png +0 -0
  27. package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/Contents.json +3 -0
  28. package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/LaunchBackground.colorset/Contents.json +12 -0
  29. package/apps/ios/EnigmaIOS/Enigma/ChatView.swift +181 -0
  30. package/apps/ios/EnigmaIOS/Enigma/CouncilView.swift +78 -0
  31. package/apps/ios/EnigmaIOS/Enigma/CreateView.swift +152 -0
  32. package/apps/ios/EnigmaIOS/Enigma/EnigmaApp.swift +52 -0
  33. package/apps/ios/EnigmaIOS/Enigma/Info.plist +52 -0
  34. package/apps/ios/EnigmaIOS/Enigma/NaturalLanguagePrivacyTagger.swift +26 -0
  35. package/apps/ios/EnigmaIOS/Enigma/OAuthClient.swift +321 -0
  36. package/apps/ios/EnigmaIOS/Enigma/OnboardingView.swift +105 -0
  37. package/apps/ios/EnigmaIOS/Enigma/PrivateVaultView.swift +275 -0
  38. package/apps/ios/EnigmaIOS/Enigma/SecureStore.swift +76 -0
  39. package/apps/ios/EnigmaIOS/Enigma/SettingsView.swift +60 -0
  40. package/apps/ios/EnigmaIOS/Enigma/Theme.swift +80 -0
  41. package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/project.pbxproj +211 -0
  42. package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/xcshareddata/xcschemes/Enigma.xcscheme +23 -0
  43. package/apps/native-host/README.md +19 -8
  44. package/apps/native-host/bin/enigma-native-host.mjs +229 -13
  45. package/apps/relay/bin/enigma-relay.mjs +103 -5
  46. package/apps/relay/src/federation-runtime.mjs +618 -0
  47. package/apps/relay/src/server.mjs +310 -9
  48. package/apps/verifier/bin/enigma-verify.mjs +327 -11
  49. package/cortex-v3/circuits/build/intent_vk_bytes.json +35 -0
  50. package/cortex-v3/circuits/build/sale_vk_bytes.json +35 -0
  51. package/cortex-v3/circuits/build/vk_bytes.json +32 -0
  52. package/cortex-v3/proving-assets.json +64 -0
  53. package/cortex-v3/zk/BUILD-CONTRACT.md +87 -0
  54. package/cortex-v3/zk/action-transition-vk.json +119 -0
  55. package/cortex-v3/zk/alias-adversarial.test.mjs +220 -0
  56. package/cortex-v3/zk/groth16-verify-child.mjs +17 -0
  57. package/cortex-v3/zk/intent-witness.mjs +365 -0
  58. package/cortex-v3/zk/intent-witness.test.mjs +485 -0
  59. package/cortex-v3/zk/proving-assets.mjs +203 -0
  60. package/cortex-v3/zk/sale-witness.mjs +783 -0
  61. package/cortex-v3/zk/sale-witness.test.mjs +784 -0
  62. package/cortex-v3/zk/sealed-sale-release-vk.json +119 -0
  63. package/cortex-v3/zk/settlement-evidence.mjs +722 -0
  64. package/cortex-v3/zk/setup-intent.mjs +688 -0
  65. package/cortex-v3/zk/setup-sale.mjs +666 -0
  66. package/cortex-v3/zk/setup.mjs +594 -0
  67. package/cortex-v3/zk/witness.mjs +184 -0
  68. package/cortex-v3/zk/zk-codec.mjs +232 -0
  69. package/cortex-v3/zk/zk-codec.test.mjs +293 -0
  70. package/cortex-v3/zk/zk-settle.mjs +370 -0
  71. package/cortex-v3/zk/zk-tree.mjs +256 -0
  72. package/cortex-v3/zk/zk-tree.test.mjs +419 -0
  73. package/deploy/docker-compose.local-production-simulation.yml +36 -0
  74. package/docs/browser-extension-install.md +8 -6
  75. package/docs/client-connectors.md +15 -11
  76. package/docs/developer-ecosystem.md +15 -13
  77. package/docs/enigma-memory-ready-conformance.md +11 -9
  78. package/docs/install-anywhere.md +61 -28
  79. package/docs/installers-and-desktop.md +8 -7
  80. package/docs/novelty-invention-candidates.md +161 -161
  81. package/docs/proof-network-claim-boundaries.md +320 -318
  82. package/examples/01-quickstart-agent/index.mjs +49 -0
  83. package/examples/01_agent_memory_quickstart.mjs +57 -0
  84. package/examples/02-multi-agent-swarm/index.mjs +57 -0
  85. package/examples/02_cross_model_passport.mjs +64 -0
  86. package/examples/03-langchain-memory/index.mjs +41 -0
  87. package/examples/03_poseidon_commitment_verification.mjs +71 -0
  88. package/examples/04-python-trading-agent/trader.py +49 -0
  89. package/examples/README.md +27 -0
  90. package/examples/ci/github-actions.yml +7 -2
  91. package/package.json +142 -11
  92. package/packages/adapters/PACKAGE_CONTRACT.md +1 -1
  93. package/packages/connectors/src/index.js +196 -4
  94. package/packages/connectors/swarm-router.mjs +168 -0
  95. package/packages/core/src/index.js +248 -1
  96. package/packages/core/src/version.mjs +7 -0
  97. package/packages/dev-tools/package.json +19 -0
  98. package/packages/dev-tools/src/index.js +4 -0
  99. package/packages/dev-tools/src/memory-benchmark-suite.js +112 -0
  100. package/packages/dev-tools/src/swarm-simulator.js +101 -0
  101. package/packages/dev-tools/src/vault-inspector.js +114 -0
  102. package/packages/dev-tools/src/vector-benchmark.js +100 -0
  103. package/packages/developer-platform/src/access-credentials.js +341 -0
  104. package/packages/developer-platform/src/http.js +132 -0
  105. package/packages/developer-platform/src/index.js +4 -0
  106. package/packages/developer-platform/src/usage-http.js +60 -0
  107. package/packages/developer-platform/src/usage.js +295 -0
  108. package/packages/enclave-runtime/attestation.mjs +159 -0
  109. package/packages/enclave-runtime/index.mjs +47 -0
  110. package/packages/enclave-runtime/session-manager.mjs +253 -0
  111. package/packages/enclave-runtime/zeroization-proof.mjs +227 -0
  112. package/packages/enigma-reflex/package.json +14 -0
  113. package/packages/enigma-reflex/src/index.js +204 -0
  114. package/packages/enigma-reflex/training/generate-dataset.mjs +40 -0
  115. package/packages/enigma-reflex/training/requirements.txt +8 -0
  116. package/packages/enigma-reflex/training/train.py +314 -0
  117. package/packages/enigma-weave/LICENSE +22 -0
  118. package/packages/enigma-weave/UPSTREAM.json +21 -0
  119. package/packages/enigma-weave/package.json +14 -0
  120. package/packages/enigma-weave/src/index.js +286 -0
  121. package/packages/hosted-cloud/src/index.js +80 -5
  122. package/packages/importers/src/index.js +432 -0
  123. package/packages/inference-runtime/src/browser.js +401 -0
  124. package/packages/inference-runtime/src/chat.js +265 -0
  125. package/packages/inference-runtime/src/code.js +407 -0
  126. package/packages/inference-runtime/src/contracts.js +162 -0
  127. package/packages/inference-runtime/src/http.js +232 -0
  128. package/packages/inference-runtime/src/image.js +186 -0
  129. package/packages/inference-runtime/src/index.js +10 -0
  130. package/packages/inference-runtime/src/model-router.js +320 -0
  131. package/packages/inference-runtime/src/platform.js +125 -0
  132. package/packages/inference-runtime/src/privacy.js +400 -0
  133. package/packages/inference-runtime/src/video.js +253 -0
  134. package/packages/mcp-server/README.md +22 -6
  135. package/packages/mcp-server/bin/enigma-mcp.mjs +2 -1
  136. package/packages/mcp-server/src/index.js +1418 -105
  137. package/packages/mcp-server/src/oauth.js +561 -0
  138. package/packages/mcp-server/src/private-handoff.js +84 -0
  139. package/packages/mcp-server/src/remote-http.js +273 -0
  140. package/packages/mcp-server/src/remote-policy.js +72 -0
  141. package/packages/mcp-server/swarm-bridge.mjs +361 -0
  142. package/packages/mesh/index.d.ts +283 -0
  143. package/packages/mesh/package.json +23 -0
  144. package/packages/mesh/src/crypto.js +189 -0
  145. package/packages/mesh/src/federation-packets.js +353 -0
  146. package/packages/mesh/src/gossip.js +311 -0
  147. package/packages/mesh/src/index.js +6 -0
  148. package/packages/mesh/src/protocol.js +255 -0
  149. package/packages/mesh/src/router.js +279 -0
  150. package/packages/mesh/src/transport.js +306 -0
  151. package/packages/passport/src/index.js +426 -1
  152. package/packages/private-economy/src/credits-http.js +100 -0
  153. package/packages/private-economy/src/credits.js +447 -0
  154. package/packages/private-economy/src/index.js +5 -0
  155. package/packages/private-economy/src/payments-http.js +120 -0
  156. package/packages/private-economy/src/payments.js +509 -0
  157. package/packages/private-economy/src/x402.js +346 -0
  158. package/packages/proof-network/PACKAGE_CONTRACT.md +21 -0
  159. package/packages/rag/index.d.ts +182 -0
  160. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/THIRD_PARTY_LICENSES.txt +207 -0
  161. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/config.json +25 -0
  162. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/onnx/model_quantized.onnx +0 -0
  163. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/sha256-manifest.json +28 -0
  164. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer.json +30686 -0
  165. package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer_config.json +15 -0
  166. package/packages/rag/package.json +27 -0
  167. package/packages/rag/src/blinded-search.js +109 -0
  168. package/packages/rag/src/bm25.js +169 -0
  169. package/packages/rag/src/embeddings.js +459 -0
  170. package/packages/rag/src/hybrid.js +76 -0
  171. package/packages/rag/src/index.js +38 -0
  172. package/packages/rag/src/reranker.js +61 -0
  173. package/packages/rag/src/research.js +107 -0
  174. package/packages/rag/src/vector-store.js +430 -0
  175. package/packages/rag/src/verify-model-artifacts.mjs +4 -0
  176. package/packages/sdk/index.d.ts +760 -0
  177. package/packages/sdk/package.json +33 -0
  178. package/packages/sdk/python/README.md +24 -0
  179. package/packages/sdk/python/enigma_sdk.py +250 -0
  180. package/packages/sdk/python/pyproject.toml +34 -0
  181. package/packages/sdk/python/requirements.txt +1 -0
  182. package/packages/sdk/python/setup.py +20 -0
  183. package/packages/sdk/src/federation/capability-grant.js +389 -0
  184. package/packages/sdk/src/federation/federation-router.js +360 -0
  185. package/packages/sdk/src/federation/ghostmesh-bridge.js +497 -0
  186. package/packages/sdk/src/federation/index.js +3 -0
  187. package/packages/sdk/src/index.js +1796 -0
  188. package/packages/sdk/src/intelligence/contradiction.js +337 -0
  189. package/packages/sdk/src/intelligence/decision-engine.js +155 -0
  190. package/packages/sdk/src/intelligence/index.js +4 -0
  191. package/packages/sdk/src/intelligence/ontology.js +122 -0
  192. package/packages/sdk/src/intelligence/temporal.js +123 -0
  193. package/packages/sdk/src/market-client.js +142 -0
  194. package/packages/sdk/src/mesh-client.js +110 -0
  195. package/packages/sdk/src/middleware/index.js +3 -0
  196. package/packages/sdk/src/middleware/langchain.js +159 -0
  197. package/packages/sdk/src/middleware/llamaindex.js +101 -0
  198. package/packages/sdk/src/middleware/vercel-ai.js +112 -0
  199. package/packages/sdk/src/rag-client.js +85 -0
  200. package/packages/sdk/src/swarm-orchestrator.js +260 -0
  201. package/packages/settlement/PACKAGE_CONTRACT.md +1 -1
  202. package/packages/snapcompact/THIRD_PARTY_LICENSES.txt +40 -0
  203. package/packages/snapcompact/assets/8x13-latin1.bdf +3837 -0
  204. package/packages/snapcompact/index.d.ts +284 -0
  205. package/packages/snapcompact/package.json +25 -0
  206. package/packages/snapcompact/src/index.js +716 -0
  207. package/packages/storage/PACKAGE_CONTRACT.md +1 -1
  208. package/packages/terminal-console/animations.mjs +240 -0
  209. package/packages/terminal-console/auto-anchor.mjs +220 -0
  210. package/packages/terminal-console/banner.mjs +91 -0
  211. package/packages/terminal-console/commands.mjs +459 -0
  212. package/packages/terminal-console/delegation.mjs +152 -0
  213. package/packages/terminal-console/index.mjs +5 -0
  214. package/packages/terminal-console/outbox.mjs +143 -0
  215. package/packages/terminal-console/phantom-bridge.mjs +637 -0
  216. package/packages/terminal-console/repl.mjs +136 -0
  217. package/packages/terminal-console/signer-store.mjs +130 -0
  218. package/packages/terminal-console/solana-rpc.mjs +214 -0
  219. package/packages/terminal-console/solana-transport.mjs +189 -0
  220. package/packages/terminal-tui/dashboard.mjs +214 -0
  221. package/packages/terminal-tui/index.mjs +28 -0
  222. package/packages/terminal-tui/merkle-tree-renderer.mjs +268 -0
  223. package/packages/terminal-tui/telemetry-hud.mjs +137 -0
  224. package/packages/vault/index.d.ts +449 -0
  225. package/packages/vault/package.json +27 -0
  226. package/packages/vault/src/e2ee.mjs +393 -0
  227. package/packages/vault/src/enclave.js +481 -0
  228. package/packages/vault/src/erasure.js +207 -0
  229. package/packages/vault/src/index.js +1018 -155
  230. package/packages/vault/src/persistence.js +307 -0
  231. package/packages/vault/src/poseidon.js +354 -0
  232. package/packages/vault/src/receipt.js +459 -0
  233. package/scripts/benchmark-optical-context.mjs +166 -0
  234. package/scripts/bootstrap-enigma.mjs +502 -0
  235. package/scripts/build-edge-backend-workers.mjs +20 -5
  236. package/scripts/build-goal-completion-audit.mjs +72 -25
  237. package/scripts/build-hosted-api-key-lifecycle.mjs +26 -8
  238. package/scripts/build-hosted-customer-lifecycle.mjs +20 -3
  239. package/scripts/build-hosted-probe-worker.mjs +19 -4
  240. package/scripts/build-installer-assets.mjs +41 -21
  241. package/scripts/build-operator-evidence-starter.mjs +59 -1
  242. package/scripts/build-production-backend-env-kit.mjs +2 -0
  243. package/scripts/build-production-unblocker.mjs +3 -0
  244. package/scripts/check.mjs +17 -3
  245. package/scripts/collect-hosted-backend-live-evidence.mjs +49 -12
  246. package/scripts/install-enigma-local.mjs +18 -5
  247. package/scripts/release-audit.mjs +65 -109
  248. package/scripts/release-provenance.mjs +6 -0
  249. package/scripts/run-backend-readiness-smoke.mjs +112 -10
  250. package/scripts/scan-secrets.mjs +1 -0
  251. package/scripts/simulate-production-env.mjs +7 -2
  252. package/scripts/validate-hosted-backend-live.mjs +112 -1
  253. package/specs/antibody-pack-v1.schema.json +95 -0
  254. package/specs/antigen-envelope-v1.schema.json +81 -0
  255. package/specs/boundary-manifest-v1.schema.json +35 -35
  256. package/specs/capsule-v1.schema.json +55 -55
  257. package/specs/claim-boundary-manifest-v1.schema.json +22 -22
  258. package/specs/claim-ledger-v1.schema.json +291 -0
  259. package/specs/context-passport-v1.schema.json +59 -0
  260. package/specs/deletion-tombstone-v1.schema.json +26 -26
  261. package/specs/evidence-packet-v1.schema.json +177 -0
  262. package/specs/hosted-backend-live-evidence-v1.schema.json +72 -3
  263. package/specs/immune-scan-report-v1.schema.json +112 -0
  264. package/specs/lifecycle-receipt-log-v1.schema.json +67 -0
  265. package/specs/memory-atom-v1.schema.json +59 -0
  266. package/specs/memory-event-v1.schema.json +42 -42
  267. package/specs/passport-v1.schema.json +50 -50
  268. package/specs/proof-of-non-use-v1.schema.json +65 -0
  269. package/specs/quarantine-record-v1.schema.json +126 -0
  270. package/specs/receipt-v1.schema.json +61 -61
  271. package/specs/state-checkpoint-v1.schema.json +37 -37
  272. package/specs/trust-bundle-v1.schema.json +56 -56
  273. package/specs/trust-card-v1.schema.json +119 -0
  274. package/docs/proof-network-launch-plan.md +0 -421
  275. package/packages/metering/PACKAGE_CONTRACT.md +0 -20
  276. package/scripts/build-ai-orchestration-plan.mjs +0 -248
@@ -0,0 +1,112 @@
1
+ // Enigma Vercel AI SDK Middleware & Multi-Hook Lifecycle.
2
+ // Injects sovereign memory context into streamText / generateText functions,
3
+ // tracks tool executions, and applies selective noise filtering.
4
+ import { Enigma } from '../index.js';
5
+
6
+ /**
7
+ * Creates a middleware wrapper for Vercel AI SDK streamText / generateText functions.
8
+ * @param {Enigma} enigma - Connected Enigma instance
9
+ * @param {Object} [options]
10
+ * @param {number} [options.maxTokens=1500]
11
+ * @param {string} [options.scope]
12
+ * @param {boolean} [options.autoRemember=true]
13
+ * @param {boolean} [options.selectiveMemory=true]
14
+ */
15
+ export function createEnigmaContextMiddleware(enigma, options = {}) {
16
+ if (!enigma || typeof enigma.remember !== 'function') {
17
+ throw new Error('enigma must be an initialized Enigma instance');
18
+ }
19
+
20
+ const maxTokens = options.maxTokens ?? 1500;
21
+ const scope = options.scope || enigma.scope;
22
+ const autoRemember = options.autoRemember !== false;
23
+ const selectiveMemory = options.selectiveMemory !== false;
24
+
25
+ return {
26
+ /**
27
+ * Augments user prompt / messages with sovereign memory context.
28
+ * @param {Object} params
29
+ * @param {string} [params.prompt]
30
+ * @param {Array<{ role: string, content: string }>} [params.messages]
31
+ * @param {string} [params.system]
32
+ * @returns {Promise<Object>}
33
+ */
34
+ async enrichPrompt(params = {}) {
35
+ const queryText = params.prompt
36
+ || (params.messages && params.messages.length > 0 ? params.messages[params.messages.length - 1].content : '');
37
+
38
+ if (!queryText) return params;
39
+
40
+ const pack = await enigma.getContextPack(queryText, { maxTokens, scope });
41
+ if (!pack.contextText) return params;
42
+
43
+ const sovereignSystemHeader = `\n\n[SOVEREIGN MEMORY CONTEXT]\n${pack.contextText}\n[END CONTEXT]\n`;
44
+
45
+ return {
46
+ ...params,
47
+ system: params.system ? `${params.system}${sovereignSystemHeader}` : sovereignSystemHeader.trim(),
48
+ sovereignContext: pack.contextText,
49
+ contextItems: pack.items,
50
+ };
51
+ },
52
+
53
+ /**
54
+ * Records completed model response into sovereign encrypted memory.
55
+ * Filters transient chatter if selectiveMemory is true.
56
+ * @param {string} prompt
57
+ * @param {string} completion
58
+ * @param {Object} [metadata]
59
+ * @returns {Promise<Object|null>}
60
+ */
61
+ async recordTurn(prompt, completion, metadata = {}) {
62
+ if (!autoRemember || !prompt || !completion) return null;
63
+ const turnRecord = `User: ${prompt}\nAI: ${completion}`;
64
+
65
+ if (selectiveMemory) {
66
+ const evaluation = enigma.evaluateObservation(turnRecord, { framework: 'vercel_ai_sdk', ...metadata });
67
+ if (!evaluation.shouldRemember) {
68
+ return null; // Filtered noise
69
+ }
70
+ }
71
+
72
+ return await enigma.remember(turnRecord, {
73
+ scope,
74
+ metadata: { framework: 'vercel_ai_sdk', recordedAt: Date.now(), ...metadata },
75
+ });
76
+ },
77
+
78
+ /**
79
+ * Lifecycle Hook: Records tool invocation and result.
80
+ * @param {string} toolName
81
+ * @param {Object} args
82
+ * @param {Object} result
83
+ */
84
+ async onToolExecution(toolName, args, result) {
85
+ const toolText = `Vercel AI Tool Execution [${toolName}]: Args: ${JSON.stringify(args)} => Result: ${JSON.stringify(result)}`;
86
+ return await enigma.remember(toolText, {
87
+ scope,
88
+ type: 'procedural',
89
+ importance: 1.2,
90
+ metadata: { toolName, framework: 'vercel_ai_sdk' },
91
+ });
92
+ },
93
+
94
+ /**
95
+ * Registers a user correction and updates supersession graph.
96
+ * @param {string} priorFact
97
+ * @param {string} updatedFact
98
+ */
99
+ async onCorrection(priorFact, updatedFact) {
100
+ const matches = await enigma.recall(priorFact, { scope, topK: 3 });
101
+ const priorId = matches.length > 0 ? matches[0].id : null;
102
+
103
+ return await enigma.remember(updatedFact, {
104
+ scope,
105
+ type: 'semantic',
106
+ importance: 2.0,
107
+ supersedes: priorId ? [priorId] : [],
108
+ metadata: { framework: 'vercel_ai_sdk', correction: true },
109
+ });
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,85 @@
1
+ // Enigma SDK: Semantic Vector & RAG Client.
2
+ import { EncryptedVectorStore, createEmbeddingProvider } from '../../rag/src/index.js';
3
+
4
+ export class EnigmaRagClient {
5
+ /**
6
+ * @param {Object} [options]
7
+ * @param {EncryptedVectorStore} [options.vectorStore]
8
+ * @param {Object} [options.embeddingProvider]
9
+ * @param {'neural'|'lexical'} [options.embeddingModel='neural']
10
+ */
11
+ constructor(options = {}) {
12
+ if (options.vectorStore) {
13
+ this.store = options.vectorStore;
14
+ return;
15
+ }
16
+ const embeddingProvider = options.embeddingProvider || createEmbeddingProvider({
17
+ modelType: options.embeddingModel || 'neural',
18
+ });
19
+ this.store = new EncryptedVectorStore({ quantize: true, embeddingProvider });
20
+ }
21
+
22
+ /**
23
+ * Indexes a memory text string into the local semantic vector store.
24
+ * @param {string} id
25
+ * @param {string} text
26
+ * @param {Object} [metadata={}]
27
+ */
28
+ async index(id, text, metadata = {}, options = {}) {
29
+ return await this.store.add(id, text, metadata, options);
30
+ }
31
+
32
+ /**
33
+ * Replaces retrieval metadata without treating receipt payloads as embeddable prose.
34
+ * @param {string} id
35
+ * @param {Object} metadata
36
+ */
37
+ updateMetadata(id, metadata) {
38
+ return this.store.updateMetadata(id, metadata);
39
+ }
40
+
41
+ /**
42
+ * Searches for top-k semantically similar memory atoms.
43
+ * @param {string} query
44
+ * @param {Object} [options]
45
+ * @returns {Promise<Array<Object>>}
46
+ */
47
+ async search(query, options = {}) {
48
+ return await this.store.search(query, options);
49
+ }
50
+
51
+ /**
52
+ * Compiles token-budgeted prompt context for an autonomous agent.
53
+ * @param {string} query
54
+ * @param {Object} [options]
55
+ * @returns {Promise<{ contextText: string, items: Array, totalChars: number, estimatedTokens: number }>}
56
+ */
57
+ async compileContext(query, options = {}) {
58
+ return await this.store.compileContextPack(query, options);
59
+ }
60
+
61
+ /**
62
+ * Encrypts the vector collection at rest for vault persistence.
63
+ * @param {Buffer|string} vaultKey
64
+ */
65
+ encryptAtRest(vaultKey) {
66
+ return this.store.encryptForVault(vaultKey);
67
+ }
68
+
69
+ /**
70
+ * Restores vector store from an encrypted bundle, retaining its recorded
71
+ * provider semantics. Legacy or adapter-backed bundles require an explicit
72
+ * embeddingProvider.
73
+ * @param {Object} bundle
74
+ * @param {Buffer|string} vaultKey
75
+ * @param {{ embeddingProvider?: Object }} [options]
76
+ */
77
+ static fromEncryptedBundle(bundle, vaultKey, options = {}) {
78
+ const store = EncryptedVectorStore.decryptFromVault(bundle, vaultKey, options);
79
+ return new EnigmaRagClient({ vectorStore: store });
80
+ }
81
+
82
+ async dispose() {
83
+ await this.store.embedder.dispose?.();
84
+ }
85
+ }
@@ -0,0 +1,260 @@
1
+ // Enigma Swarm Orchestrator.
2
+ // Coordinates multi-agent sovereign memory swarms with Role-Based Access Control (RBAC),
3
+ // broadcast coordination, real-time memory events, and synchronized rule consensus.
4
+ import crypto from 'node:crypto';
5
+ import { EventEmitter } from 'node:events';
6
+ import { Enigma } from './index.js';
7
+ import { InMemoryBus, InMemoryTransport } from '../../mesh/src/index.js';
8
+
9
+ export class EnigmaSwarmOrchestrator extends EventEmitter {
10
+ /**
11
+ * @param {Object} [options]
12
+ * @param {string} [options.swarmId]
13
+ * @param {string} [options.passphrase]
14
+ * @param {string} [options.storageDir]
15
+ * @param {Object} [options.bus] - Custom shared mesh bus
16
+ * @param {(options: Object) => Promise<Enigma>} [options.enigmaFactory] - Optional agent factory
17
+ */
18
+ constructor(options = {}) {
19
+ super();
20
+ this.swarmId = options.swarmId || `swarm_${crypto.randomBytes(4).toString('hex')}`;
21
+ this.passphrase = options.passphrase || null;
22
+ this.storageDir = options.storageDir || null;
23
+ this.bus = options.bus || new InMemoryBus();
24
+ this.enigmaFactory = options.enigmaFactory || ((connectOptions) => Enigma.connect(connectOptions));
25
+ /** @type {Map<string, { enigma: Enigma, role: string, permissions: Set<string>, scope: string, inbox: Array<Object> }>} */
26
+ this.agents = new Map();
27
+ }
28
+
29
+ /**
30
+ * Spawns and registers an autonomous agent into the swarm.
31
+ * @param {string} agentId
32
+ * @param {Object} [options]
33
+ * @param {string} [options.role='worker'] - Agent role (e.g. 'coordinator', 'trader', 'auditor', 'worker')
34
+ * @param {string[]} [options.permissions] - Granular permissions (e.g. ['read', 'write', 'broadcast', 'zk_prove'])
35
+ * @param {string} [options.scope] - Agent scope (defaults to agentId)
36
+ * @returns {Promise<Enigma>}
37
+ */
38
+ async registerAgent(agentId, options = {}) {
39
+ if (!agentId || typeof agentId !== 'string') {
40
+ throw new Error('agentId must be a non-empty string');
41
+ }
42
+ if (this.agents.has(agentId)) {
43
+ return this.agents.get(agentId).enigma;
44
+ }
45
+
46
+ const role = options.role || 'worker';
47
+ const permissions = new Set(options.permissions || ['read', 'write']);
48
+ const scope = options.scope || `agent.${agentId}`;
49
+
50
+ const storagePath = this.storageDir
51
+ ? `${this.storageDir}/${agentId}.vault.enc.json`
52
+ : undefined;
53
+
54
+ const enigma = await this.enigmaFactory({
55
+ agentId,
56
+ scope,
57
+ passphrase: this.passphrase,
58
+ storagePath,
59
+ });
60
+
61
+ // Attach shared in-memory transport to agent's mesh client
62
+ const transport = new InMemoryTransport(agentId, this.bus);
63
+ enigma.mesh.addTransport(transport);
64
+ await enigma.mesh.start();
65
+ await enigma.mesh.announce({ role, agentId });
66
+
67
+ const inbox = [];
68
+ const agentEntry = {
69
+ enigma,
70
+ role,
71
+ permissions,
72
+ scope,
73
+ inbox,
74
+ };
75
+
76
+ // Wire real-time mesh listeners
77
+ enigma.mesh.onCapsule((capsule) => {
78
+ inbox.push(capsule);
79
+ this.emit('capsule:received', {
80
+ swarmId: this.swarmId,
81
+ recipientAgentId: agentId,
82
+ sender: capsule.sender,
83
+ plaintext: capsule.plaintext,
84
+ receivedAt: capsule.receivedAt,
85
+ });
86
+ });
87
+
88
+ this.agents.set(agentId, agentEntry);
89
+
90
+ this.emit('agent:registered', {
91
+ swarmId: this.swarmId,
92
+ agentId,
93
+ role,
94
+ scope,
95
+ });
96
+
97
+ return enigma;
98
+ }
99
+
100
+ /**
101
+ * Retrieves a registered agent by ID.
102
+ * @param {string} agentId
103
+ * @returns {Enigma|undefined}
104
+ */
105
+ getAgent(agentId) {
106
+ const entry = this.agents.get(agentId);
107
+ return entry ? entry.enigma : undefined;
108
+ }
109
+
110
+ /**
111
+ * Unregisters an agent from the swarm.
112
+ * @param {string} agentId
113
+ * @returns {Promise<boolean>}
114
+ */
115
+ async unregisterAgent(agentId) {
116
+ const entry = this.agents.get(agentId);
117
+ if (!entry) return false;
118
+
119
+ await entry.enigma.mesh.stop();
120
+ this.agents.delete(agentId);
121
+ this.emit('agent:unregistered', { swarmId: this.swarmId, agentId });
122
+ return true;
123
+ }
124
+
125
+ /**
126
+ * Propagates a global protocol rule across all registered agents in the swarm.
127
+ * @param {string} ruleText
128
+ * @param {Object} [metadata]
129
+ * @returns {Promise<{ ruleId: string, syncedCount: number }>}
130
+ */
131
+ async syncGlobalRule(ruleText, metadata = {}) {
132
+ if (!ruleText || typeof ruleText !== 'string') {
133
+ throw new Error('Rule text must be a non-empty string');
134
+ }
135
+
136
+ const ruleId = `rule_${Date.now()}_${crypto.randomBytes(3).toString('hex')}`;
137
+ let syncedCount = 0;
138
+
139
+ for (const [agentId, entry] of this.agents.entries()) {
140
+ if (entry.permissions.has('write')) {
141
+ await entry.enigma.remember(ruleText, {
142
+ id: `${ruleId}_${agentId}`,
143
+ scope: entry.scope,
144
+ importance: 2.0,
145
+ metadata: {
146
+ swarmId: this.swarmId,
147
+ ruleId,
148
+ syncedAt: Date.now(),
149
+ ...metadata,
150
+ },
151
+ });
152
+ syncedCount++;
153
+ }
154
+ }
155
+
156
+ this.emit('rule:synced', {
157
+ swarmId: this.swarmId,
158
+ ruleId,
159
+ ruleText,
160
+ syncedCount,
161
+ });
162
+
163
+ return { ruleId, syncedCount };
164
+ }
165
+
166
+ /**
167
+ * Dispatches an encrypted coordination signal from a sender agent to a target recipient in the swarm.
168
+ * @param {string} senderAgentId
169
+ * @param {string} targetAgentId
170
+ * @param {string} message
171
+ * @returns {Promise<{ delivered: boolean, packetId: string, receivedPlaintext?: string }>}
172
+ */
173
+ async dispatchSignal(senderAgentId, targetAgentId, message) {
174
+ const sender = this.agents.get(senderAgentId);
175
+ const target = this.agents.get(targetAgentId);
176
+
177
+ if (!sender) throw new Error(`Sender agent "${senderAgentId}" is not registered in swarm`);
178
+ if (!target) throw new Error(`Target agent "${targetAgentId}" is not registered in swarm`);
179
+
180
+ if (!sender.permissions.has('write') && !sender.permissions.has('broadcast')) {
181
+ throw new Error(`Sender agent "${senderAgentId}" lacks permission to dispatch swarm signals`);
182
+ }
183
+
184
+ // Set up reception listener for exact delivery proof
185
+ const deliveryPromise = new Promise((resolve) => {
186
+ const onCapsule = (event) => {
187
+ if (event.plaintext === message) {
188
+ target.enigma.mesh.node.off('capsule', onCapsule);
189
+ resolve(true);
190
+ }
191
+ };
192
+ target.enigma.mesh.node.on('capsule', onCapsule);
193
+ // Timeout guard
194
+ setTimeout(() => {
195
+ target.enigma.mesh.node.off('capsule', onCapsule);
196
+ resolve(false);
197
+ }, 500);
198
+ });
199
+
200
+ const targetIdentity = target.enigma.mesh.identity;
201
+ const sendResult = await sender.enigma.mesh.send(
202
+ targetIdentity.destinationHex,
203
+ targetIdentity.encryptionPublicKey,
204
+ message
205
+ );
206
+
207
+ const received = await deliveryPromise;
208
+
209
+ this.emit('signal:dispatched', {
210
+ swarmId: this.swarmId,
211
+ senderAgentId,
212
+ targetAgentId,
213
+ message,
214
+ routed: sendResult.routed,
215
+ delivered: received,
216
+ packetId: sendResult.packetId,
217
+ });
218
+
219
+ return {
220
+ delivered: received && sendResult.routed,
221
+ packetId: sendResult.packetId,
222
+ receivedPlaintext: received ? message : undefined,
223
+ };
224
+ }
225
+
226
+ /**
227
+ * Returns complete swarm topology and agent roster.
228
+ */
229
+ getTopology() {
230
+ const roster = [];
231
+ for (const [agentId, entry] of this.agents.entries()) {
232
+ roster.push({
233
+ agentId,
234
+ role: entry.role,
235
+ scope: entry.scope,
236
+ permissions: Array.from(entry.permissions),
237
+ memoryCount: entry.enigma.status().memoryCount,
238
+ vectorCount: entry.enigma.status().vectorCount,
239
+ destinationHex: entry.enigma.mesh.identity.destinationHex,
240
+ inboxCount: entry.inbox.length,
241
+ });
242
+ }
243
+ return {
244
+ swarmId: this.swarmId,
245
+ agentCount: this.agents.size,
246
+ roster,
247
+ };
248
+ }
249
+
250
+ /**
251
+ * Gracefully shuts down all agents and active mesh nodes in the swarm.
252
+ */
253
+ async shutdown() {
254
+ for (const entry of this.agents.values()) {
255
+ await entry.enigma.mesh.stop();
256
+ }
257
+ this.agents.clear();
258
+ this.emit('swarm:shutdown', { swarmId: this.swarmId });
259
+ }
260
+ }
@@ -1,4 +1,4 @@
1
- # `@enigma-ai/enigma/settlement`
1
+ # `enigma-memory/settlement`
2
2
 
3
3
  Permissionless access and service-settlement protocol for Enigma memory jobs.
4
4
 
@@ -0,0 +1,40 @@
1
+ X.ORG MISC-FIXED 8x13 FONT
2
+ ===========================
3
+ Asset: assets/8x13-latin1.bdf
4
+ Upstream: https://gitlab.freedesktop.org/xorg/font/misc-misc/-/blob/master/8x13.bdf
5
+ The bundled asset is a Latin-1 subset of the upstream X.Org 8x13 ISO10646-1
6
+ BDF. The upstream BDF declares:
7
+
8
+ "Public domain font. Share and enjoy."
9
+
10
+
11
+ @OH-MY-PI/SNAPCOMPACT STRATEGY
12
+ ==============================
13
+ This package is an independent Node implementation inspired by the dense
14
+ bitmap context strategy in @oh-my-pi/snapcompact. It does not copy or import
15
+ that package, its Bun/native runtime, or its implementation.
16
+ Upstream: https://github.com/can1357/oh-my-pi/tree/main/packages/snapcompact
17
+
18
+ MIT License
19
+
20
+ Copyright (c) 2025 Mario Zechner
21
+ Copyright (c) 2025-2026 Can Bölük
22
+ Copyright (c) 2026 Stencil Labs, Inc.
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy
25
+ of this software and associated documentation files (the "Software"), to deal
26
+ in the Software without restriction, including without limitation the rights
27
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
+ copies of the Software, and to permit persons to whom the Software is
29
+ furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in all
32
+ copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
+ SOFTWARE.