@oracle-agent/oracle 0.1.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 (169) hide show
  1. package/CONTRIBUTING.md +98 -0
  2. package/LICENSE +202 -0
  3. package/README.md +384 -0
  4. package/SECURITY.md +89 -0
  5. package/SETUP.md +235 -0
  6. package/artifacts/inscription/oracle-was-here-preview.png +0 -0
  7. package/artifacts/inscription/oracle-was-here.svg +1 -0
  8. package/artifacts/specialist-packs/oracle-full-crypto.json +273 -0
  9. package/bin/desk-server.mjs +438 -0
  10. package/bin/oracle-data-mcp.mjs +603 -0
  11. package/bin/oracle-init.mjs +423 -0
  12. package/bin/oracle-public-server.mjs +36 -0
  13. package/bin/oracle-route.mjs +254 -0
  14. package/bin/oracle-scan.mjs +192 -0
  15. package/docs/adding-a-chain.md +229 -0
  16. package/docs/architecture.md +135 -0
  17. package/docs/profiles.md +132 -0
  18. package/examples/add-a-chain.mjs +65 -0
  19. package/examples/research-a-token.mjs +70 -0
  20. package/package.json +90 -0
  21. package/profiles/_template/SOUL.md +47 -0
  22. package/profiles/_template/profile.json +22 -0
  23. package/profiles/bitcoin-agent/SOUL.md +31 -0
  24. package/profiles/bitcoin-agent/profile.json +32 -0
  25. package/profiles/hyperliquid-agent/SOUL.md +34 -0
  26. package/profiles/hyperliquid-agent/profile.json +37 -0
  27. package/profiles/oracle/SOUL.md +65 -0
  28. package/profiles/oracle/profile.json +35 -0
  29. package/profiles/polymarket-agent/SOUL.md +35 -0
  30. package/profiles/polymarket-agent/profile.json +34 -0
  31. package/profiles/profile.schema.json +90 -0
  32. package/profiles/protocol-builder/SOUL.md +50 -0
  33. package/profiles/protocol-builder/profile.json +37 -0
  34. package/profiles/robinhood-agent/SOUL.md +45 -0
  35. package/profiles/robinhood-agent/profile.json +39 -0
  36. package/profiles/solana-agent/SOUL.md +37 -0
  37. package/profiles/solana-agent/profile.json +37 -0
  38. package/profiles/stable-agent/SOUL.md +43 -0
  39. package/profiles/stable-agent/profile.json +37 -0
  40. package/public/oracle-console/app.js +272 -0
  41. package/public/oracle-console/bitcoin-wallets.js +206 -0
  42. package/public/oracle-console/index.html +91 -0
  43. package/public/oracle-console/styles.css +239 -0
  44. package/public/oracle-splash/index.html +931 -0
  45. package/scripts/build-inscription.py +230 -0
  46. package/scripts/check-test-count.mjs +105 -0
  47. package/scripts/e2e-hl-markets.mjs +21 -0
  48. package/scripts/e2e-hl-perps.mjs +48 -0
  49. package/scripts/e2e-hypercore-staking.mjs +128 -0
  50. package/scripts/e2e-solana-bitcoin.mjs +183 -0
  51. package/scripts/public-api-scan.mjs +23 -0
  52. package/scripts/secret-scan.mjs +181 -0
  53. package/scripts/verify-v3-venues.mjs +192 -0
  54. package/skills/oracle-best-execution/SKILL.md +127 -0
  55. package/skills/oracle-bitcoin/SKILL.md +53 -0
  56. package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +59 -0
  57. package/skills/oracle-circuit-breaker/SKILL.md +51 -0
  58. package/skills/oracle-contract-research/SKILL.md +55 -0
  59. package/skills/oracle-desk/SKILL.md +58 -0
  60. package/skills/oracle-dex-launch/SKILL.md +38 -0
  61. package/skills/oracle-grants/SKILL.md +69 -0
  62. package/skills/oracle-hypercore-staking/SKILL.md +57 -0
  63. package/skills/oracle-hyperliquid/SKILL.md +56 -0
  64. package/skills/oracle-meme-token-sniper/SKILL.md +73 -0
  65. package/skills/oracle-nft-gacha-launch/SKILL.md +48 -0
  66. package/skills/oracle-nft-mint-gas-war/SKILL.md +63 -0
  67. package/skills/oracle-polymarket/SKILL.md +60 -0
  68. package/skills/oracle-protocol-builder/SKILL.md +38 -0
  69. package/skills/oracle-protocol-security/SKILL.md +60 -0
  70. package/skills/oracle-public-product/SKILL.md +44 -0
  71. package/skills/oracle-receipts/SKILL.md +52 -0
  72. package/skills/oracle-rfq-tokenized-assets/SKILL.md +69 -0
  73. package/skills/oracle-smart-wallet-scanner/SKILL.md +49 -0
  74. package/skills/oracle-solana/SKILL.md +65 -0
  75. package/skills/oracle-solana-nft/SKILL.md +54 -0
  76. package/skills/oracle-token-research/SKILL.md +67 -0
  77. package/src/agent-auth.mjs +191 -0
  78. package/src/approval-guard.mjs +282 -0
  79. package/src/attestation-secret.mjs +88 -0
  80. package/src/audit-log.mjs +196 -0
  81. package/src/auto-slippage.mjs +378 -0
  82. package/src/capability-posture.mjs +125 -0
  83. package/src/chains.mjs +62 -0
  84. package/src/data/catalog.mjs +495 -0
  85. package/src/data/desk-data.mjs +623 -0
  86. package/src/data/http.mjs +200 -0
  87. package/src/data/provider-endpoint.mjs +94 -0
  88. package/src/data/providers/aerodrome.mjs +244 -0
  89. package/src/data/providers/balancer.mjs +208 -0
  90. package/src/data/providers/bitcoin-esplora.mjs +230 -0
  91. package/src/data/providers/bitcoin-meta.mjs +378 -0
  92. package/src/data/providers/blockscout.mjs +14 -0
  93. package/src/data/providers/bridges.mjs +241 -0
  94. package/src/data/providers/cowswap.mjs +501 -0
  95. package/src/data/providers/curve.mjs +200 -0
  96. package/src/data/providers/defillama.mjs +88 -0
  97. package/src/data/providers/dexscreener.mjs +43 -0
  98. package/src/data/providers/evm-rpc.mjs +203 -0
  99. package/src/data/providers/geckoterminal.mjs +34 -0
  100. package/src/data/providers/gmx.mjs +495 -0
  101. package/src/data/providers/hl-info.mjs +102 -0
  102. package/src/data/providers/hl-markets.mjs +210 -0
  103. package/src/data/providers/hl-perps.mjs +382 -0
  104. package/src/data/providers/hl-staking.mjs +352 -0
  105. package/src/data/providers/hl-ws.mjs +119 -0
  106. package/src/data/providers/hyperevm-dex.mjs +49 -0
  107. package/src/data/providers/jupiter.mjs +182 -0
  108. package/src/data/providers/lifi.mjs +150 -0
  109. package/src/data/providers/magiceden-sol.mjs +355 -0
  110. package/src/data/providers/morpho.mjs +173 -0
  111. package/src/data/providers/odos.mjs +155 -0
  112. package/src/data/providers/oneinch.mjs +173 -0
  113. package/src/data/providers/opensea-multichain.mjs +136 -0
  114. package/src/data/providers/opensea-nft.mjs +99 -0
  115. package/src/data/providers/paraswap.mjs +117 -0
  116. package/src/data/providers/pendle.mjs +187 -0
  117. package/src/data/providers/poly-public.mjs +96 -0
  118. package/src/data/providers/poly-ws.mjs +103 -0
  119. package/src/data/providers/rh-agent.mjs +59 -0
  120. package/src/data/providers/satflow.mjs +336 -0
  121. package/src/data/providers/solana-rpc.mjs +186 -0
  122. package/src/data/providers/uniswap-v3.mjs +303 -0
  123. package/src/data/providers/zerox.mjs +166 -0
  124. package/src/data/public-api-scan.mjs +61 -0
  125. package/src/data/quote-placeholder.mjs +31 -0
  126. package/src/exact-integer.mjs +72 -0
  127. package/src/exec-policy.mjs +444 -0
  128. package/src/flags.mjs +15 -0
  129. package/src/fresh-window.mjs +76 -0
  130. package/src/gmx-attestation.mjs +175 -0
  131. package/src/index.mjs +50 -0
  132. package/src/nft-gas-war-guard.mjs +139 -0
  133. package/src/onboarding/agent-keys.mjs +157 -0
  134. package/src/onboarding/index.mjs +18 -0
  135. package/src/onboarding/tiers.mjs +139 -0
  136. package/src/oracle-env.mjs +38 -0
  137. package/src/protocol-execution.mjs +84 -0
  138. package/src/public-api/buzz-integration.mjs +256 -0
  139. package/src/public-api/connect-agent.mjs +397 -0
  140. package/src/public-api/grants.mjs +142 -0
  141. package/src/public-api/http.mjs +374 -0
  142. package/src/public-control/aa-adapter.mjs +402 -0
  143. package/src/public-control/build-registry.mjs +227 -0
  144. package/src/public-control/bundler-client.mjs +372 -0
  145. package/src/public-control/grant-indexer.mjs +296 -0
  146. package/src/public-control/policy-render.mjs +69 -0
  147. package/src/public-control/policy-schema.mjs +318 -0
  148. package/src/public-control/runtime-config.mjs +265 -0
  149. package/src/public-control/session-key-model.mjs +374 -0
  150. package/src/public-control/session-orchestrator.mjs +412 -0
  151. package/src/route-attestation.mjs +132 -0
  152. package/src/router/best-execution.mjs +221 -0
  153. package/src/router/index.mjs +185 -0
  154. package/src/router/prepare-bridge.mjs +288 -0
  155. package/src/router/prepare-route.mjs +341 -0
  156. package/src/router/proposal.mjs +311 -0
  157. package/src/router/risk-classifier.mjs +119 -0
  158. package/src/router/route-sources.mjs +292 -0
  159. package/src/scanner/chains.config.mjs +381 -0
  160. package/src/scanner/contract.mjs +270 -0
  161. package/src/scanner/evm-scanner.mjs +394 -0
  162. package/src/scanner/index.mjs +9 -0
  163. package/src/scanner/v2-venue.mjs +335 -0
  164. package/src/scanner/v3-venue.mjs +290 -0
  165. package/src/scopes.mjs +44 -0
  166. package/src/sell-simulation.mjs +167 -0
  167. package/src/token-transfer-guard.mjs +188 -0
  168. package/src/vault-attestation.mjs +145 -0
  169. package/src/venues.mjs +206 -0
@@ -0,0 +1,423 @@
1
+ #!/usr/bin/env node
2
+ // oracle-init -- install Oracle's agent lanes into Hermes.
3
+ //
4
+ // Reads profiles/<lane>/profile.json, validates each against the shipped schema,
5
+ // then creates the Hermes profile, installs its SOUL.md, registers the repo's
6
+ // skills, and wires the oracle-data MCP server.
7
+ //
8
+ // Deliberate omissions:
9
+ // * No model or provider is written. Oracle makes no model calls; each lane
10
+ // inherits whatever the operator's Hermes already serves. profile.json carries
11
+ // a capability CLASS ("strong-reasoner"), never a model id, so this installer
12
+ // never pins a vendor.
13
+ // * No grant is armed. Every lane lands DISARMED. Arming is a signed, scoped,
14
+ // expiring act the user performs later.
15
+ //
16
+ // Default is a DRY RUN. Pass --apply to make changes.
17
+
18
+ import fs from "node:fs";
19
+ import path from "node:path";
20
+ import os from "node:os";
21
+ import { randomBytes } from "node:crypto";
22
+ import { execFileSync } from "node:child_process";
23
+ import { fileURLToPath } from "node:url";
24
+
25
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
26
+ const PROFILES_DIR = path.join(ROOT, "profiles");
27
+ const SKILLS_DIR = path.join(ROOT, "skills");
28
+
29
+ const args = process.argv.slice(2);
30
+ const APPLY = args.includes("--apply");
31
+ const FORCE = args.includes("--force");
32
+ const JSON_OUT = args.includes("--json");
33
+ const only = (() => {
34
+ const i = args.indexOf("--only");
35
+ return i >= 0 ? args[i + 1] : null;
36
+ })();
37
+
38
+ const log = (...m) => {
39
+ if (!JSON_OUT) console.log(...m);
40
+ };
41
+
42
+ // ---------------------------------------------------------------- validation
43
+
44
+ function loadSchema() {
45
+ return JSON.parse(
46
+ fs.readFileSync(path.join(PROFILES_DIR, "profile.schema.json"), "utf8"),
47
+ );
48
+ }
49
+
50
+ // Focused validator for the fields we actually depend on. Not a general JSON
51
+ // Schema engine -- pulling one in for eight files would add a dependency to a
52
+ // zero-dependency installer.
53
+ function validateProfile(def, schema, skillNames) {
54
+ const errors = [];
55
+ const req = schema.required || [];
56
+ for (const k of req) {
57
+ if (def[k] === undefined) errors.push(`missing required field: ${k}`);
58
+ }
59
+ if (def.id && !/^[a-z_][a-z0-9-]*$/.test(def.id)) {
60
+ errors.push(`id "${def.id}" must be lowercase, no dots (Hermes rejects dots)`);
61
+ }
62
+ const roles = schema.properties.role.enum;
63
+ if (def.role && !roles.includes(def.role)) {
64
+ errors.push(`role "${def.role}" not one of ${roles.join(", ")}`);
65
+ }
66
+ const p = def.posture || {};
67
+ if (p.default !== "DISARMED") {
68
+ errors.push("posture.default must be DISARMED -- a lane that ships armed is a bug");
69
+ }
70
+ if (p.signing && !["none", "user-wallet"].includes(p.signing)) {
71
+ errors.push(`posture.signing "${p.signing}" invalid -- Oracle holds no keys`);
72
+ }
73
+ const allowedActions =
74
+ schema.properties.posture.properties.grantActions.items.enum;
75
+ for (const a of p.grantActions || []) {
76
+ if (!allowedActions.includes(a)) {
77
+ errors.push(`grantAction "${a}" not allowed (broadcast/sign actions are forbidden)`);
78
+ }
79
+ }
80
+ if (typeof p.rationale === "string" && p.rationale.length < 20) {
81
+ errors.push("posture.rationale too short -- justify the grant");
82
+ }
83
+ // Every named skill must actually exist. This is the check that would have
84
+ // caught the phantom-skill problem in the original pack manifest.
85
+ for (const s of def.skills || []) {
86
+ if (!skillNames.has(s)) errors.push(`skill "${s}" does not exist in skills/`);
87
+ }
88
+ return errors;
89
+ }
90
+
91
+ // ---------------------------------------------------------------- discovery
92
+
93
+ function discoverSkills() {
94
+ if (!fs.existsSync(SKILLS_DIR)) return new Map();
95
+ const out = new Map();
96
+ for (const e of fs.readdirSync(SKILLS_DIR, { withFileTypes: true })) {
97
+ if (!e.isDirectory()) continue;
98
+ const skillFile = path.join(SKILLS_DIR, e.name, "SKILL.md");
99
+ if (fs.existsSync(skillFile)) out.set(e.name, skillFile);
100
+ }
101
+ return out;
102
+ }
103
+
104
+ function discoverProfiles() {
105
+ if (!fs.existsSync(PROFILES_DIR)) return [];
106
+ const out = [];
107
+ for (const e of fs.readdirSync(PROFILES_DIR, { withFileTypes: true })) {
108
+ if (!e.isDirectory()) continue;
109
+ const f = path.join(PROFILES_DIR, e.name, "profile.json");
110
+ if (!fs.existsSync(f)) continue;
111
+ const def = JSON.parse(fs.readFileSync(f, "utf8"));
112
+ def.__dir = path.join(PROFILES_DIR, e.name);
113
+ out.push(def);
114
+ }
115
+ return out;
116
+ }
117
+
118
+ // ---------------------------------------------------------------- hermes glue
119
+
120
+ function hermesAvailable() {
121
+ try {
122
+ execFileSync("hermes", ["--version"], { stdio: "pipe", timeout: 20_000 });
123
+ return true;
124
+ } catch {
125
+ return false;
126
+ }
127
+ }
128
+
129
+ // Resolve the GLOBAL Hermes root, not a profile-scoped one.
130
+ //
131
+ // Trap worth knowing: when this runs inside an agent session that is itself
132
+ // profile-scoped, HERMES_HOME points at ~/.hermes/profiles/<name>, not ~/.hermes.
133
+ // Using it verbatim writes ~/.hermes/profiles/<name>/profiles/<lane>/SOUL.md --
134
+ // a nested path Hermes never reads, so the install silently does nothing.
135
+ // Detect that shape and walk back up to the real root.
136
+ function hermesRoot() {
137
+ const env = (process.env.HERMES_HOME || "").trim();
138
+ if (env) {
139
+ const parts = env.split(path.sep);
140
+ const i = parts.lastIndexOf("profiles");
141
+ // ".../profiles/<name>" -> strip the last two segments
142
+ if (i > 0 && i === parts.length - 2) {
143
+ return parts.slice(0, i).join(path.sep);
144
+ }
145
+ return env;
146
+ }
147
+ return path.join(os.homedir(), ".hermes");
148
+ }
149
+
150
+ function profileExists(id) {
151
+ try {
152
+ const out = execFileSync("hermes", ["profile", "list"], {
153
+ encoding: "utf8",
154
+ timeout: 30_000,
155
+ });
156
+ return new RegExp(`(^|\\s)${id}(\\s|$)`, "m").test(out);
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
161
+
162
+ const actions = [];
163
+ const skipped = [];
164
+ const mcpManual = [];
165
+
166
+ function sameFile(a, b) {
167
+ try {
168
+ return fs.readFileSync(a, "utf8") === fs.readFileSync(b, "utf8");
169
+ } catch {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ function record(kind, detail) {
175
+ actions.push({ kind, detail, applied: APPLY });
176
+ log(`${APPLY ? " ✔" : " ·"} ${kind}: ${detail}`);
177
+ }
178
+
179
+ // ---------------------------------------------------------------- main
180
+
181
+ const schema = loadSchema();
182
+ const skills = discoverSkills();
183
+ const skillNames = new Set(skills.keys());
184
+ let profiles = discoverProfiles();
185
+
186
+ // The template is documentation, not a lane to install.
187
+ profiles = profiles.filter((p) => !p.template);
188
+ if (only) profiles = profiles.filter((p) => p.id === only);
189
+
190
+ log(`oracle-init ${APPLY ? "(APPLY)" : "(dry run -- pass --apply to install)"}`);
191
+ log(` profiles: ${profiles.length} skills: ${skills.size}`);
192
+
193
+ // 1. validate everything BEFORE touching the system. A partial install across a
194
+ // profile mesh is worse than no install.
195
+ const invalid = [];
196
+ for (const def of profiles) {
197
+ const errs = validateProfile(def, schema, skillNames);
198
+ if (errs.length) invalid.push({ id: def.id, errors: errs });
199
+ }
200
+ if (invalid.length) {
201
+ if (JSON_OUT) {
202
+ process.stdout.write(`${JSON.stringify({ ok: false, invalid }, null, 2)}\n`);
203
+ } else {
204
+ console.error("\nvalidation failed:");
205
+ for (const v of invalid) {
206
+ console.error(` ${v.id}:`);
207
+ for (const e of v.errors) console.error(` - ${e}`);
208
+ }
209
+ }
210
+ process.exit(1);
211
+ }
212
+ log(" validation: ok");
213
+
214
+ // Ensure a route/slippage attestation secret exists for fresh installs.
215
+ // Without it, swap sign/broadcast fails closed (unsigned guards are refused).
216
+ // Never overwrite an existing secret.
217
+ {
218
+ const cfgDir = path.join(os.homedir(), ".config", "oracle");
219
+ const envPath = path.join(cfgDir, "exec.env");
220
+ let hasSecret = Boolean(
221
+ process.env.ORACLE_ROUTE_ATTESTATION_SECRET || process.env.MAD_ROUTE_ATTESTATION_SECRET
222
+ );
223
+ if (!hasSecret && fs.existsSync(envPath)) {
224
+ try {
225
+ const txt = fs.readFileSync(envPath, "utf8");
226
+ hasSecret = /^ORACLE_ROUTE_ATTESTATION_SECRET=.+$/m.test(txt) || /^MAD_ROUTE_ATTESTATION_SECRET=.+$/m.test(txt);
227
+ } catch {
228
+ /* treat as missing */
229
+ }
230
+ }
231
+ if (hasSecret) {
232
+ record("attestation secret", "present");
233
+ } else {
234
+ record("attestation secret", `generate -> ${path.relative(os.homedir(), envPath)}`);
235
+ if (APPLY) {
236
+ fs.mkdirSync(cfgDir, { recursive: true, mode: 0o700 });
237
+ try {
238
+ fs.chmodSync(cfgDir, 0o700);
239
+ } catch {
240
+ /* best-effort */
241
+ }
242
+ const secret = randomBytes(32).toString("hex");
243
+ const line = `ORACLE_ROUTE_ATTESTATION_SECRET=${secret}\n`;
244
+ if (fs.existsSync(envPath)) {
245
+ const prev = fs.readFileSync(envPath, "utf8");
246
+ if (!/ORACLE_ROUTE_ATTESTATION_SECRET=/.test(prev) && !/MAD_ROUTE_ATTESTATION_SECRET=/.test(prev)) {
247
+ fs.appendFileSync(envPath, prev.endsWith("\n") || prev.length === 0 ? line : `\n${line}`, { mode: 0o600 });
248
+ }
249
+ } else {
250
+ fs.writeFileSync(envPath, line, { mode: 0o600 });
251
+ }
252
+ try {
253
+ fs.chmodSync(envPath, 0o600);
254
+ } catch {
255
+ /* best-effort */
256
+ }
257
+ }
258
+ }
259
+ }
260
+
261
+ const hermes = hermesAvailable();
262
+ // The hermes CLI is a CONVENIENCE, not a requirement.
263
+ //
264
+ // Verified behaviour: Hermes discovers any profile directory under
265
+ // <root>/profiles/<name>/, so writing SOUL.md and skills/ is sufficient to create a
266
+ // working lane. `hermes profile create` only pre-seeds boilerplate, and
267
+ // `hermes mcp add` only edits that profile's config.
268
+ //
269
+ // Making the CLI mandatory would mean this installer -- and its tests -- could only
270
+ // run on a machine with Hermes already installed, which is both a worse contributor
271
+ // experience and untestable in CI. So: install files always, use the CLI when it is
272
+ // there, and say plainly what was skipped when it is not.
273
+ if (!hermes) {
274
+ log(
275
+ " hermes CLI: not found -- installing profile files directly.\n" +
276
+ " (Hermes discovers any directory under <root>/profiles/, so this works.\n" +
277
+ " MCP wiring is the one step that needs the CLI; instructions printed at the end.)",
278
+ );
279
+ } else {
280
+ log(" hermes CLI: found");
281
+ }
282
+
283
+ // 2. install
284
+ for (const def of profiles) {
285
+ log(`\n${def.label} (${def.id})`);
286
+
287
+ // Snapshot what exists BEFORE we create anything. This is the reliable signal
288
+ // for the no-clobber guard below.
289
+ //
290
+ // Why not just check for the file later: `hermes profile create` writes its own
291
+ // boilerplate SOUL.md, so after creation a SOUL.md always exists. Treating that
292
+ // as "the user's file" would make the guard refuse to install the lane persona,
293
+ // the install would silently no-op, and every lane would run generic Hermes.
294
+ // Only a file that predates our run can hold work worth protecting.
295
+ const laneDir = path.join(hermesRoot(), "profiles", def.id);
296
+ const soulDest = path.join(laneDir, "SOUL.md");
297
+ const soulExistedBefore = fs.existsSync(soulDest);
298
+ const skillExistedBefore = new Map(
299
+ (def.skills || []).map((s) => [
300
+ s,
301
+ fs.existsSync(path.join(laneDir, "skills", s, "SKILL.md")),
302
+ ]),
303
+ );
304
+
305
+ const preExisting = hermes ? profileExists(def.id) : fs.existsSync(laneDir);
306
+ if (preExisting) {
307
+ record("profile exists", def.id);
308
+ } else if (hermes) {
309
+ record("create profile", def.id);
310
+ if (APPLY) {
311
+ try {
312
+ execFileSync("hermes", ["profile", "create", def.id], {
313
+ stdio: "pipe",
314
+ timeout: 120_000,
315
+ });
316
+ } catch (err) {
317
+ // Not fatal: writing the directory below is what actually creates the lane.
318
+ record("create note", `hermes profile create failed for ${def.id}; writing files directly`);
319
+ }
320
+ }
321
+ } else {
322
+ record("create profile dir", def.id);
323
+ if (APPLY) fs.mkdirSync(laneDir, { recursive: true });
324
+ }
325
+
326
+ // SOUL.md -- never clobber a persona the user wrote.
327
+ const soulSrc = path.join(def.__dir, "SOUL.md");
328
+ if (fs.existsSync(soulSrc)) {
329
+ const collision = soulExistedBefore && !sameFile(soulSrc, soulDest);
330
+ if (collision && !FORCE) {
331
+ record(
332
+ "SKIP SOUL.md (exists)",
333
+ `${path.relative(os.homedir(), soulDest)} -- kept yours; --force to overwrite`,
334
+ );
335
+ skipped.push({ lane: def.id, file: "SOUL.md", reason: "already exists" });
336
+ } else {
337
+ record("install SOUL.md", path.relative(os.homedir(), soulDest));
338
+ if (APPLY) {
339
+ fs.mkdirSync(path.dirname(soulDest), { recursive: true });
340
+ if (collision) {
341
+ const bak = `${soulDest}.bak-oracle-init-${Date.now()}`;
342
+ fs.copyFileSync(soulDest, bak);
343
+ record("backed up", path.relative(os.homedir(), bak));
344
+ }
345
+ fs.copyFileSync(soulSrc, soulDest);
346
+ }
347
+ }
348
+ }
349
+
350
+ // skills -- same discipline
351
+ for (const s of def.skills || []) {
352
+ const dest = path.join(laneDir, "skills", s, "SKILL.md");
353
+ const collision = skillExistedBefore.get(s) && !sameFile(skills.get(s), dest);
354
+ if (collision && !FORCE) {
355
+ record("SKIP skill (exists)", `${s} -> ${def.id}`);
356
+ skipped.push({ lane: def.id, file: `skills/${s}`, reason: "already exists" });
357
+ continue;
358
+ }
359
+ record("install skill", `${s} -> ${def.id}`);
360
+ if (APPLY) {
361
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
362
+ fs.copyFileSync(skills.get(s), dest);
363
+ }
364
+ }
365
+
366
+ // MCP: the read plane. This is the one step that genuinely needs the CLI, since
367
+ // it edits the profile's own config. Without it, print the command instead.
368
+ for (const m of def.mcp || []) {
369
+ const cmd = path.join(ROOT, "bin", "oracle-data-mcp.mjs");
370
+ if (!hermes) {
371
+ record("mcp manual", `hermes -p ${def.id} mcp add ${m} --command "node ${cmd}"`);
372
+ mcpManual.push({ lane: def.id, server: m, command: `hermes -p ${def.id} mcp add ${m} --command "node ${cmd}"` });
373
+ continue;
374
+ }
375
+ record("wire mcp", `${m} (${def.id})`);
376
+ if (APPLY && m === "oracle-data") {
377
+ try {
378
+ execFileSync(
379
+ "hermes",
380
+ ["-p", def.id, "mcp", "add", "oracle-data", "--command", `node ${cmd}`],
381
+ { stdio: "pipe", timeout: 60_000 },
382
+ );
383
+ } catch {
384
+ // Already registered, or this Hermes build wants different flags. Not fatal:
385
+ // the profile is usable, it just needs the MCP wired by hand.
386
+ record("mcp note", `could not auto-wire ${m} for ${def.id}; add it manually`);
387
+ mcpManual.push({ lane: def.id, server: m, command: `hermes -p ${def.id} mcp add ${m} --command "node ${cmd}"` });
388
+ }
389
+ }
390
+ }
391
+
392
+ record("posture", `DISARMED (${(def.posture.grantActions || []).join(", ")})`);
393
+ }
394
+
395
+ const summary = {
396
+ ok: true,
397
+ applied: APPLY,
398
+ profiles: profiles.map((p) => p.id),
399
+ skills: [...skillNames],
400
+ actions: actions.length,
401
+ skipped,
402
+ mcpManual,
403
+ hermesDetected: hermes,
404
+ hermesRoot: hermesRoot(),
405
+ };
406
+
407
+ if (JSON_OUT) {
408
+ process.stdout.write(`${JSON.stringify(summary, null, 2)}\n`);
409
+ } else {
410
+ log(`\n${APPLY ? "installed" : "would install"} ${profiles.length} lanes.`);
411
+ if (skipped.length) {
412
+ log(`${skipped.length} file(s) already existed and were kept:`);
413
+ for (const s of skipped) log(` - ${s.lane}/${s.file}`);
414
+ log("pass --force to overwrite (a timestamped .bak is written first).");
415
+ }
416
+ if (mcpManual.length) {
417
+ log("\nMCP wiring needs the hermes CLI. Run these when it is available:");
418
+ for (const m of mcpManual) log(` ${m.command}`);
419
+ }
420
+ if (!APPLY) log("re-run with --apply to make changes.");
421
+ log("\nEvery lane is DISARMED. Set each lane's model in:");
422
+ log(` ${path.join(hermesRoot(), "profiles", "<lane>", "config.yaml")}`);
423
+ }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ // Oracle Public HTTP server (Slice G) — secret-free BFF boot script.
3
+ //
4
+ // ORACLE_PUBLIC_HOST=127.0.0.1 ORACLE_PUBLIC_PORT=8799 node bin/oracle-public-server.mjs
5
+ //
6
+ // Loopback by default. Serves ONLY the public read/assemble contract; no
7
+ // signing, no keys, no executor imports. Every response body is scanned for
8
+ // secret material before send (see src/public-api/http.mjs).
9
+
10
+ import { startPublicServer, resolvePublicBind, VERSION, PUBLIC_PLANE } from "../src/public-api/http.mjs";
11
+
12
+ const bind = resolvePublicBind();
13
+ const server = startPublicServer(bind);
14
+
15
+ server.on("listening", () => {
16
+ const addr = server.address();
17
+ const host = typeof addr === "object" && addr ? addr.address : bind.host;
18
+ const port = typeof addr === "object" && addr ? addr.port : bind.port;
19
+ // NOTE: log line intentionally carries only public bind info + version.
20
+ console.log(
21
+ `oracle-public-server listening on http://${host}:${port} (plane=${PUBLIC_PLANE}, version=${VERSION}, unsigned-only)`
22
+ );
23
+ });
24
+
25
+ server.on("error", (err) => {
26
+ console.error(`oracle-public-server failed to bind: ${err.code || err.message}`);
27
+ process.exit(1);
28
+ });
29
+
30
+ for (const sig of ["SIGINT", "SIGTERM"]) {
31
+ process.on(sig, () => {
32
+ server.close(() => process.exit(0));
33
+ // Fallback hard-exit if sockets linger.
34
+ setTimeout(() => process.exit(0), 1000).unref();
35
+ });
36
+ }