@oracle-agent/oracle 0.4.1 → 0.5.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 (80) hide show
  1. package/README.md +74 -20
  2. package/SETUP.md +15 -2
  3. package/bin/oracle-data-mcp.mjs +1 -1
  4. package/bin/oracle.mjs +33 -0
  5. package/docs/cli.md +19 -0
  6. package/docs/connectors.md +13 -0
  7. package/docs/oracle-pack-standard.md +29 -0
  8. package/docs/profiles.md +1 -1
  9. package/examples/oracle-pack-template.mjs +38 -0
  10. package/package.json +13 -4
  11. package/profiles/oracle/SOUL.md +3 -1
  12. package/profiles/robinhood-agent/SOUL.md +5 -3
  13. package/public/agent-connect/app.js +84 -0
  14. package/public/agent-connect/index.html +83 -0
  15. package/public/agent-connect/styles.css +70 -0
  16. package/public/oracle-splash/assets/wordmarks/across.svg +4 -0
  17. package/public/oracle-splash/assets/wordmarks/aerodrome.svg +23 -0
  18. package/public/oracle-splash/assets/wordmarks/balancer.svg +3 -0
  19. package/public/oracle-splash/assets/wordmarks/cowswap.svg +1 -0
  20. package/public/oracle-splash/assets/wordmarks/gmx.svg +13 -0
  21. package/public/oracle-splash/assets/wordmarks/hyperliquid.svg +21 -0
  22. package/public/oracle-splash/assets/wordmarks/hyperswap.svg +13 -0
  23. package/public/oracle-splash/assets/wordmarks/jupiter.svg +35 -0
  24. package/public/oracle-splash/assets/wordmarks/lifi.png +0 -0
  25. package/public/oracle-splash/assets/wordmarks/magic-eden.svg +1 -0
  26. package/public/oracle-splash/assets/wordmarks/morpho.svg +1 -0
  27. package/public/oracle-splash/assets/wordmarks/odos.svg +3 -0
  28. package/public/oracle-splash/assets/wordmarks/oneinch.svg +6 -0
  29. package/public/oracle-splash/assets/wordmarks/opensea.svg +1 -0
  30. package/public/oracle-splash/assets/wordmarks/pancakeswap.svg +18 -0
  31. package/public/oracle-splash/assets/wordmarks/paraswap.svg +16 -0
  32. package/public/oracle-splash/assets/wordmarks/pendle.png +0 -0
  33. package/public/oracle-splash/assets/wordmarks/polymarket.png +0 -0
  34. package/public/oracle-splash/assets/wordmarks/quickswap.png +0 -0
  35. package/public/oracle-splash/assets/wordmarks/relay.svg +8 -0
  36. package/public/oracle-splash/assets/wordmarks/stargate.svg +15 -0
  37. package/public/oracle-splash/assets/wordmarks/uniswap.svg +18 -0
  38. package/public/oracle-splash/assets/wordmarks/velodrome.svg +84 -0
  39. package/public/oracle-splash/index.html +789 -485
  40. package/scripts/adversarial-bench.mjs +114 -0
  41. package/scripts/check-doc-drift.mjs +111 -0
  42. package/skills/oracle-action-semantics/SKILL.md +1 -1
  43. package/src/action-receipts.mjs +168 -0
  44. package/src/address-book.mjs +53 -5
  45. package/src/cli/commands/credential.mjs +9 -0
  46. package/src/cli/commands/data-mcp.mjs +18 -0
  47. package/src/cli/commands/data.mjs +73 -0
  48. package/src/cli/commands/doctor.mjs +131 -0
  49. package/src/cli/commands/help.mjs +7 -0
  50. package/src/cli/commands/init.mjs +27 -0
  51. package/src/cli/commands/mcp.mjs +142 -0
  52. package/src/cli/commands/prepare.mjs +12 -0
  53. package/src/cli/commands/public.mjs +20 -0
  54. package/src/cli/commands/route.mjs +12 -0
  55. package/src/cli/commands/runner.mjs +9 -0
  56. package/src/cli/commands/scan.mjs +12 -0
  57. package/src/cli/commands/sign.mjs +21 -0
  58. package/src/cli/commands/signer.mjs +9 -0
  59. package/src/cli/commands/upgrade.mjs +12 -0
  60. package/src/cli/commands/vault.mjs +9 -0
  61. package/src/cli/commands/version.mjs +22 -0
  62. package/src/cli/first-run.mjs +20 -0
  63. package/src/cli/kernel.mjs +198 -0
  64. package/src/cli/mcp-targets/chatgpt.mjs +51 -0
  65. package/src/cli/mcp-targets/claude-code.mjs +39 -0
  66. package/src/cli/mcp-targets/claude-desktop.mjs +24 -0
  67. package/src/cli/mcp-targets/codex.mjs +41 -0
  68. package/src/cli/mcp-targets/shared.mjs +61 -0
  69. package/src/cli/operator-dispatch.mjs +258 -0
  70. package/src/cli/paths.mjs +78 -0
  71. package/src/cli/spawn-child.mjs +43 -0
  72. package/src/exec-policy.mjs +6 -0
  73. package/src/index.mjs +24 -0
  74. package/src/onboarding/harness-configs.mjs +102 -0
  75. package/src/oracle-env.mjs +11 -2
  76. package/src/portfolio-risk.mjs +170 -0
  77. package/src/public-api/connect-agent.mjs +29 -10
  78. package/src/signals/engine.mjs +146 -0
  79. package/src/signals/index.mjs +1 -0
  80. package/src/watch-preferences.mjs +85 -0
@@ -0,0 +1,51 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fakeHome, report } from "./shared.mjs";
4
+
5
+ export const CHATGPT_CANNOT_SIGN =
6
+ "ChatGPT is hosted and can NEVER sign or reach your keys. This connector is read/prepare only; anything it prepares is unsigned until you sign it locally.";
7
+
8
+ function openApiDoc() {
9
+ return {
10
+ openapi: "3.1.0",
11
+ info: {
12
+ title: "Oracle Public (read/prepare)",
13
+ version: "1.0.0",
14
+ description: "Secret-free public surface for hosted clients. " + CHATGPT_CANNOT_SIGN,
15
+ },
16
+ servers: [{ url: "https://REPLACE-WITH-YOUR-TUNNEL" }],
17
+ paths: {
18
+ "/public/health": { get: { operationId: "publicHealth", summary: "Health check", responses: { "200": { description: "ok" } } } },
19
+ "/public/config": { get: { operationId: "publicConfig", summary: "Public config", responses: { "200": { description: "ok" } } } },
20
+ "/public/connect/request": { post: { operationId: "connectRequest", summary: "Build a connect request (unsigned)", responses: { "200": { description: "unsigned request artifact" } } } },
21
+ "/public/connect/assemble": { post: { operationId: "connectAssemble", summary: "Assemble an unsigned grant artifact", responses: { "200": { description: "unsigned grant artifact" } } } },
22
+ "/public/grants/active": { post: { operationId: "grantsActive", summary: "List active grants (read)", responses: { "200": { description: "ok" } } } },
23
+ "/public/grants/get": { post: { operationId: "grantsGet", summary: "Get a grant by id (read)", responses: { "200": { description: "ok" } } } },
24
+ },
25
+ };
26
+ }
27
+
28
+ export async function installChatgpt({ printOnly = false } = {}) {
29
+ const doc = openApiDoc();
30
+ const target = path.join(fakeHome(), ".config", "oracle", "connectors", "chatgpt-openapi.json");
31
+ const text = JSON.stringify(doc, null, 2) + "\n";
32
+ if (!printOnly) {
33
+ fs.mkdirSync(path.dirname(target), { recursive: true });
34
+ fs.writeFileSync(target, text);
35
+ }
36
+ const instructions = [
37
+ CHATGPT_CANNOT_SIGN, "",
38
+ "Next steps:",
39
+ " 1. oracle public serve",
40
+ " 2. Expose 127.0.0.1:8799 through YOUR HTTPS tunnel (cloudflared, tailscale funnel, etc.).",
41
+ " Oracle will not create tunnels for you.",
42
+ " 3. Paste the OpenAPI spec into a GPT Action, or add the tunnel URL as a developer-mode MCP connector.",
43
+ printOnly ? "" : ` Spec written to: ${target}`,
44
+ ].filter(Boolean).join("\n");
45
+ return {
46
+ ok: true,
47
+ ...report(printOnly ? "printed" : "written", {
48
+ path: target, print: doc, instructions, cannotSign: CHATGPT_CANNOT_SIGN,
49
+ }),
50
+ };
51
+ }
@@ -0,0 +1,39 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import path from "node:path";
3
+ import { fakeHome, buildServerSpecs, mergeMcpServers, report } from "./shared.mjs";
4
+
5
+ function claudeJsonPath() { return path.join(fakeHome(), ".claude.json"); }
6
+ function projectMcpPath(cwd) { return path.join(cwd || process.cwd(), ".mcp.json"); }
7
+
8
+ function tryClaudeCli(name, spec) {
9
+ const probe = spawnSync("claude", ["--version"], { encoding: "utf8", timeout: 10000 });
10
+ if (probe.error || probe.status !== 0) return null;
11
+ const r = spawnSync("claude", ["mcp", "add-json", name, JSON.stringify(spec), "--scope", "user"], {
12
+ encoding: "utf8", timeout: 30000,
13
+ });
14
+ if (r.status !== 0) return { ok: false, stderr: r.stderr || r.stdout || "failed" };
15
+ return { ok: true };
16
+ }
17
+
18
+ export async function installClaudeCode({
19
+ oracleRoot, operator, withControl = false, project = false, printOnly = false, cwd = process.cwd(),
20
+ }) {
21
+ const built = buildServerSpecs({ oracleRoot, operator, withControl });
22
+ if (!built.ok) return { ok: false, code: 3, reason: built.reason };
23
+ if (printOnly) return { ok: true, print: { mcpServers: built.specs } };
24
+ if (project) {
25
+ const target = projectMcpPath(cwd);
26
+ const result = mergeMcpServers(target, built.specs);
27
+ return { ok: true, ...report(result.status, { path: target, backup: result.backup }) };
28
+ }
29
+ let usedCli = false;
30
+ for (const [name, spec] of Object.entries(built.specs)) {
31
+ const cli = tryClaudeCli(name, spec);
32
+ if (cli && cli.ok) { usedCli = true; continue; }
33
+ break;
34
+ }
35
+ if (usedCli) return { ok: true, ...report("written", { method: "claude-cli" }) };
36
+ const target = claudeJsonPath();
37
+ const result = mergeMcpServers(target, built.specs);
38
+ return { ok: true, ...report(result.status, { path: target, backup: result.backup }) };
39
+ }
@@ -0,0 +1,24 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fakeHome, buildServerSpecs, mergeMcpServers, report } from "./shared.mjs";
4
+
5
+ function desktopConfigPath() {
6
+ if (process.platform === "darwin") {
7
+ return path.join(fakeHome(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
8
+ }
9
+ return path.join(fakeHome(), ".config", "Claude", "claude_desktop_config.json");
10
+ }
11
+
12
+ export async function installClaudeDesktop({ oracleRoot, operator, withControl = false, printOnly = false }) {
13
+ const built = buildServerSpecs({ oracleRoot, operator, withControl });
14
+ if (!built.ok) return { ok: false, code: 3, reason: built.reason };
15
+ const target = desktopConfigPath();
16
+ const payload = { mcpServers: built.specs };
17
+ if (printOnly) return { ok: true, print: payload };
18
+ const parent = path.dirname(target);
19
+ if (!fs.existsSync(parent)) {
20
+ return { ok: true, status: "printed (Claude Desktop not detected)", path: target, print: payload };
21
+ }
22
+ const result = mergeMcpServers(target, built.specs);
23
+ return { ok: true, ...report(result.status, { path: target, backup: result.backup }) };
24
+ }
@@ -0,0 +1,41 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fakeHome, buildServerSpecs, backupFile, report } from "./shared.mjs";
4
+
5
+ const BEGIN = "# oracle-mcp-install begin";
6
+ const END = "# oracle-mcp-install end";
7
+
8
+ function codexPath() { return path.join(fakeHome(), ".codex", "config.toml"); }
9
+
10
+ function renderBlock(specs) {
11
+ const lines = [BEGIN];
12
+ for (const [name, spec] of Object.entries(specs)) {
13
+ lines.push(`[mcp_servers.${name}]`);
14
+ lines.push(`command = ${JSON.stringify(spec.command)}`);
15
+ lines.push(`args = [${spec.args.map((a) => JSON.stringify(a)).join(", ")}]`);
16
+ lines.push("");
17
+ }
18
+ lines.push(END);
19
+ return lines.join("\n") + "\n";
20
+ }
21
+
22
+ function stripExistingBlock(text) {
23
+ return text.replace(new RegExp(`${BEGIN}[\\s\\S]*?${END}\\n?`, "g"), "");
24
+ }
25
+
26
+ export async function installCodex({ oracleRoot, operator, withControl = false, printOnly = false }) {
27
+ const built = buildServerSpecs({ oracleRoot, operator, withControl });
28
+ if (!built.ok) return { ok: false, code: 3, reason: built.reason };
29
+ const block = renderBlock(built.specs);
30
+ const target = codexPath();
31
+ if (printOnly) return { ok: true, printText: block, path: target };
32
+ fs.mkdirSync(path.dirname(target), { recursive: true });
33
+ const prev = fs.existsSync(target) ? fs.readFileSync(target, "utf8") : "";
34
+ if (prev.includes(block.trim())) return { ok: true, ...report("present", { path: target, backup: null }) };
35
+ const stripped = stripExistingBlock(prev);
36
+ const next = (stripped.trimEnd() + "\n\n" + block).replace(/^\n+/, "");
37
+ if (prev.trim() === next.trim()) return { ok: true, ...report("present", { path: target, backup: null }) };
38
+ const backup = prev ? backupFile(target) : null;
39
+ fs.writeFileSync(target, next.endsWith("\n") ? next : next + "\n");
40
+ return { ok: true, ...report("written", { path: target, backup }) };
41
+ }
@@ -0,0 +1,61 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+ import { PACKAGE_ROOT } from "../paths.mjs";
5
+
6
+ export function fakeHome() {
7
+ return process.env.ORACLE_FAKE_HOME || os.homedir();
8
+ }
9
+
10
+ export function buildServerSpecs({ oracleRoot = PACKAGE_ROOT, operator = null, withControl = false } = {}) {
11
+ const specs = {
12
+ "oracle-data": {
13
+ command: "node",
14
+ args: [path.join(oracleRoot, "bin", "oracle-data-mcp.mjs")],
15
+ },
16
+ };
17
+ if (withControl) {
18
+ if (!operator || !operator.ok) return { ok: false, reason: "operator-missing" };
19
+ const control = operator.bins?.["oracle-control-mcp"] || operator.controlMcp || null;
20
+ if (!control) return { ok: false, reason: "control-bin-missing" };
21
+ specs["oracle-control"] = { command: "node", args: [control] };
22
+ }
23
+ return { ok: true, specs };
24
+ }
25
+
26
+ export function backupFile(filePath) {
27
+ if (!fs.existsSync(filePath)) return null;
28
+ const bak = `${filePath}.bak-oracle-${Math.floor(Date.now() / 1000)}`;
29
+ fs.copyFileSync(filePath, bak);
30
+ return bak;
31
+ }
32
+
33
+ export function readJson(filePath, fallback = {}) {
34
+ if (!fs.existsSync(filePath)) return structuredClone(fallback);
35
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
36
+ }
37
+
38
+ export function writeJson(filePath, obj) {
39
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
40
+ fs.writeFileSync(filePath, JSON.stringify(obj, null, 2) + "\n");
41
+ }
42
+
43
+ export function mergeMcpServers(filePath, specs) {
44
+ const existing = readJson(filePath, {});
45
+ if (!existing.mcpServers || typeof existing.mcpServers !== "object") existing.mcpServers = {};
46
+ let changed = false;
47
+ for (const [name, spec] of Object.entries(specs)) {
48
+ const prev = existing.mcpServers[name];
49
+ if (prev && JSON.stringify(prev) === JSON.stringify(spec)) continue;
50
+ existing.mcpServers[name] = spec;
51
+ changed = true;
52
+ }
53
+ if (!changed) return { status: "present", backup: null };
54
+ const backup = backupFile(filePath);
55
+ writeJson(filePath, existing);
56
+ return { status: "written", backup };
57
+ }
58
+
59
+ export function report(status, detail = {}) {
60
+ return { status, ...detail };
61
+ }
@@ -0,0 +1,258 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { spawnSync } from "node:child_process";
4
+ import { createRequire } from "node:module";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
8
+ const PACKAGE_ROOT = path.resolve(HERE, "../..");
9
+
10
+ export const OPERATOR_BIN_NAMES = Object.freeze([
11
+ "oracle-vault",
12
+ "oracle-credential",
13
+ "oracle-signer",
14
+ "oracle-runner",
15
+ "oracle-agentic-init",
16
+ "oracle-agentic-doctor",
17
+ "oracle-control-mcp",
18
+ "oracle-operator-caps",
19
+ ]);
20
+
21
+ export const SIGN_NOUNS = Object.freeze([
22
+ "vault",
23
+ "credential",
24
+ "signer",
25
+ "runner",
26
+ "sign",
27
+ ]);
28
+
29
+ export const OPERATOR_NOT_INSTALLED_MESSAGE = `oracle: signing lives in @oracle-agent/operator, which is not installed.
30
+
31
+ The public 'oracle' package is prepare-only and never handles keys.
32
+ To enable local signing on THIS machine:
33
+
34
+ npm i -g @oracle-agent/operator # or add it to this project
35
+ oracle sign init # provision keys + policy (interactive)
36
+
37
+ Nothing about your read/research setup is affected.
38
+ `;
39
+
40
+ export const SIGN_HINT =
41
+ "hint: run 'oracle sign init' to provision keys, or 'oracle sign doctor --json' for detail.";
42
+
43
+ function whichOnPath(binName) {
44
+ const pathEnv = process.env.PATH || "";
45
+ const parts = pathEnv.split(path.delimiter).filter(Boolean);
46
+ const exts = process.platform === "win32" ? ["", ".cmd", ".exe", ".bat"] : [""];
47
+ for (const dir of parts) {
48
+ for (const ext of exts) {
49
+ const candidate = path.join(dir, binName + ext);
50
+ try {
51
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
52
+ return candidate;
53
+ }
54
+ } catch {
55
+ // ignore
56
+ }
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+
62
+ function binsFromDir(binDir) {
63
+ const bins = {};
64
+ for (const name of OPERATOR_BIN_NAMES) {
65
+ const candidates = [
66
+ path.join(binDir, name),
67
+ path.join(binDir, `${name}.mjs`),
68
+ path.join(binDir, `${name}.js`),
69
+ ];
70
+ for (const c of candidates) {
71
+ if (fs.existsSync(c) && fs.statSync(c).isFile()) {
72
+ bins[name] = c;
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ return bins;
78
+ }
79
+
80
+ function findPackageRoot(entryPath) {
81
+ let dir = path.dirname(entryPath);
82
+ while (dir !== path.dirname(dir)) {
83
+ const pkgJson = path.join(dir, "package.json");
84
+ if (fs.existsSync(pkgJson)) {
85
+ try {
86
+ const pkg = JSON.parse(fs.readFileSync(pkgJson, "utf8"));
87
+ if (pkg.name === "@oracle-agent/operator") return { root: dir, pkg };
88
+ } catch {
89
+ // continue upward
90
+ }
91
+ }
92
+ dir = path.dirname(dir);
93
+ }
94
+ return null;
95
+ }
96
+
97
+ function tryResolvePackage(fromPaths) {
98
+ for (const from of fromPaths) {
99
+ try {
100
+ const req = createRequire(path.join(from, "package.json"));
101
+ let found;
102
+ try {
103
+ const pkgJson = req.resolve("@oracle-agent/operator/package.json");
104
+ found = {
105
+ root: path.dirname(pkgJson),
106
+ pkg: JSON.parse(fs.readFileSync(pkgJson, "utf8")),
107
+ };
108
+ } catch {
109
+ const entry = req.resolve("@oracle-agent/operator");
110
+ found = findPackageRoot(entry);
111
+ }
112
+ if (!found) continue;
113
+ const { root, pkg } = found;
114
+ const binField = pkg.bin || {};
115
+ const bins = {};
116
+ for (const [name, rel] of Object.entries(binField)) {
117
+ bins[name] = path.resolve(root, rel);
118
+ }
119
+ const extra = binsFromDir(path.join(root, "bin"));
120
+ for (const [k, v] of Object.entries(extra)) {
121
+ if (!bins[k]) bins[k] = v;
122
+ }
123
+ return {
124
+ ok: true,
125
+ binDir: path.join(root, "bin"),
126
+ version: pkg.version || "unknown",
127
+ bins,
128
+ source: `require:${from}`,
129
+ };
130
+ } catch {
131
+ // continue
132
+ }
133
+ }
134
+ return null;
135
+ }
136
+
137
+ function tryCapsOnPath() {
138
+ const capsBin = whichOnPath("oracle-operator-caps");
139
+ if (!capsBin) return null;
140
+ const r = spawnSync(capsBin, [], {
141
+ encoding: "utf8",
142
+ timeout: 5000,
143
+ env: process.env,
144
+ });
145
+ if (r.status !== 0 || !r.stdout) return null;
146
+ try {
147
+ const report = JSON.parse(r.stdout);
148
+ if (!report || typeof report !== "object" || !report.bins) return null;
149
+ return {
150
+ ok: true,
151
+ binDir: path.dirname(Object.values(report.bins)[0] || capsBin),
152
+ version: report.version || "unknown",
153
+ bins: report.bins,
154
+ source: "caps-path",
155
+ controlMcp: report.controlMcp,
156
+ };
157
+ } catch {
158
+ return null;
159
+ }
160
+ }
161
+
162
+ function tryPathProbe() {
163
+ const bins = {};
164
+ for (const name of OPERATOR_BIN_NAMES) {
165
+ const hit = whichOnPath(name);
166
+ if (hit) bins[name] = hit;
167
+ }
168
+ if (!Object.keys(bins).length) return null;
169
+ return {
170
+ ok: true,
171
+ binDir: path.dirname(Object.values(bins)[0]),
172
+ version: "unknown",
173
+ bins,
174
+ source: "path-probe",
175
+ };
176
+ }
177
+
178
+ export function resolveOperator() {
179
+ const envDir = process.env.ORACLE_OPERATOR_BIN_DIR;
180
+ if (envDir) {
181
+ const abs = path.resolve(envDir);
182
+ if (!fs.existsSync(abs)) return { ok: false };
183
+ const bins = binsFromDir(abs);
184
+ if (!Object.keys(bins).length) return { ok: false };
185
+ let version = "unknown";
186
+ const pkgCandidate = path.resolve(abs, "../package.json");
187
+ if (fs.existsSync(pkgCandidate)) {
188
+ try {
189
+ version = JSON.parse(fs.readFileSync(pkgCandidate, "utf8")).version || version;
190
+ } catch {
191
+ // ignore
192
+ }
193
+ }
194
+ return { ok: true, binDir: abs, version, bins, source: "env:ORACLE_OPERATOR_BIN_DIR" };
195
+ }
196
+
197
+ const fromPkg =
198
+ tryResolvePackage([process.cwd(), PACKAGE_ROOT]) ||
199
+ tryCapsOnPath() ||
200
+ tryPathProbe();
201
+ return fromPkg || { ok: false };
202
+ }
203
+
204
+ export function printOperatorNotInstalled(stream = process.stderr) {
205
+ stream.write(OPERATOR_NOT_INSTALLED_MESSAGE);
206
+ if (!OPERATOR_NOT_INSTALLED_MESSAGE.endsWith("\n")) stream.write("\n");
207
+ }
208
+
209
+ export function dispatchOperator(binName, argv = [], opts = {}) {
210
+ const resolved = resolveOperator();
211
+ if (!resolved.ok) {
212
+ printOperatorNotInstalled(opts.stderr || process.stderr);
213
+ return 3;
214
+ }
215
+ const binPath = resolved.bins[binName];
216
+ if (!binPath) {
217
+ const err = opts.stderr || process.stderr;
218
+ err.write(`oracle: operator bin '${binName}' not found in resolved operator (${resolved.source})\n`);
219
+ return 3;
220
+ }
221
+
222
+ const stdio = opts.stdio || "inherit";
223
+ const isJs = /\.(mjs|cjs|js)$/.test(binPath);
224
+ const command = isJs ? process.execPath : binPath;
225
+ const args = isJs ? [binPath, ...argv] : [...argv];
226
+ const r = spawnSync(command, args, {
227
+ stdio,
228
+ env: opts.env || process.env,
229
+ cwd: opts.cwd || process.cwd(),
230
+ encoding: stdio === "pipe" ? "utf8" : undefined,
231
+ });
232
+
233
+ if (r.error) {
234
+ const err = opts.stderr || process.stderr;
235
+ err.write(`oracle: failed to spawn ${binName}: ${r.error.message}\n`);
236
+ return 1;
237
+ }
238
+
239
+ const code = typeof r.status === "number" ? r.status : 1;
240
+ if (code !== 0 && opts.appendHintOnError) {
241
+ const err = opts.stderr || process.stderr;
242
+ err.write(SIGN_HINT + "\n");
243
+ }
244
+ if (stdio === "pipe") {
245
+ return { code, stdout: r.stdout || "", stderr: r.stderr || "" };
246
+ }
247
+ return code;
248
+ }
249
+
250
+ export default {
251
+ resolveOperator,
252
+ dispatchOperator,
253
+ printOperatorNotInstalled,
254
+ OPERATOR_NOT_INSTALLED_MESSAGE,
255
+ SIGN_HINT,
256
+ SIGN_NOUNS,
257
+ OPERATOR_BIN_NAMES,
258
+ };
@@ -0,0 +1,78 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
7
+ export const PACKAGE_ROOT = path.resolve(HERE, "../..");
8
+
9
+ export function homeDir() {
10
+ return process.env.ORACLE_FAKE_HOME || os.homedir();
11
+ }
12
+
13
+ export function oracleConfigDir() {
14
+ return path.join(homeDir(), ".config", "oracle");
15
+ }
16
+
17
+ export function oracleExecEnvPath() {
18
+ return path.join(oracleConfigDir(), "exec.env");
19
+ }
20
+
21
+ export function hermesRoot() {
22
+ if (process.env.HERMES_HOME) return path.resolve(process.env.HERMES_HOME);
23
+ return path.join(homeDir(), ".hermes");
24
+ }
25
+
26
+ export function claudeCodeUserConfigPath() {
27
+ return path.join(homeDir(), ".claude.json");
28
+ }
29
+
30
+ export function claudeCodeProjectMcpPath(cwd = process.cwd()) {
31
+ return path.join(cwd, ".mcp.json");
32
+ }
33
+
34
+ export function claudeDesktopConfigPath() {
35
+ if (process.platform === "darwin") {
36
+ return path.join(homeDir(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
37
+ }
38
+ return path.join(homeDir(), ".config", "Claude", "claude_desktop_config.json");
39
+ }
40
+
41
+ export function codexConfigPath() {
42
+ return path.join(homeDir(), ".codex", "config.toml");
43
+ }
44
+
45
+ export function chatgptConnectorDir() {
46
+ return path.join(oracleConfigDir(), "connectors");
47
+ }
48
+
49
+ export function chatgptOpenApiPath() {
50
+ return path.join(chatgptConnectorDir(), "chatgpt-openapi.json");
51
+ }
52
+
53
+ export function packageBin(name) {
54
+ return path.join(PACKAGE_ROOT, "bin", name);
55
+ }
56
+
57
+ export function ensureDir(dir) {
58
+ fs.mkdirSync(dir, { recursive: true });
59
+ return dir;
60
+ }
61
+
62
+ export const paths = {
63
+ homeDir,
64
+ oracleConfigDir,
65
+ oracleExecEnvPath,
66
+ hermesRoot,
67
+ claudeCodeUserConfigPath,
68
+ claudeCodeProjectMcpPath,
69
+ claudeDesktopConfigPath,
70
+ codexConfigPath,
71
+ chatgptConnectorDir,
72
+ chatgptOpenApiPath,
73
+ packageBin,
74
+ ensureDir,
75
+ PACKAGE_ROOT,
76
+ };
77
+
78
+ export default paths;
@@ -0,0 +1,43 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
4
+
5
+ export function spawnChild(command, args = [], options = {}, label = command) {
6
+ return new Promise((resolve) => {
7
+ const child = spawn(command, args, options);
8
+ let settled = false;
9
+ let forwardedSignal = null;
10
+
11
+ const handlers = new Map(
12
+ FORWARDED_SIGNALS.map((signal) => [signal, () => {
13
+ forwardedSignal ||= signal;
14
+ if (child.exitCode === null && child.signalCode === null) child.kill(signal);
15
+ }]),
16
+ );
17
+ for (const [signal, handler] of handlers) process.on(signal, handler);
18
+
19
+ const cleanup = () => {
20
+ for (const [signal, handler] of handlers) process.off(signal, handler);
21
+ };
22
+
23
+ child.once("error", (error) => {
24
+ if (settled) return;
25
+ settled = true;
26
+ cleanup();
27
+ process.stderr.write(`oracle: could not start ${label}: ${error.message}\n`);
28
+ resolve(1);
29
+ });
30
+
31
+ child.once("exit", (code, signal) => {
32
+ if (settled) return;
33
+ settled = true;
34
+ cleanup();
35
+ const propagated = forwardedSignal || signal;
36
+ if (propagated) {
37
+ process.kill(process.pid, propagated);
38
+ return;
39
+ }
40
+ resolve(code ?? 1);
41
+ });
42
+ });
43
+ }
@@ -419,6 +419,12 @@ export function enforceTxPolicy(tx = {}, phase = "broadcast") {
419
419
  // Spending caps toggle. Set MAD_VALUE_CAPS_ENABLED=0 in exec.env to lift the
420
420
  // per-tx + daily native caps (chain/dest allowlists still enforced). Flip back
421
421
  // to 1 to re-arm the cap wall. Default = ON when unset.
422
+ //
423
+ // Deliberately strict: ONLY the literal "0" lifts the caps. This is the
424
+ // opposite polarity from a kill switch. Disabling a kill switch makes a
425
+ // deployment safer, so it accepts 0/false/off/no. Disabling THIS makes a
426
+ // deployment riskier, so a stray "false" must keep the cap wall standing
427
+ // rather than silently removing it. Do not route this through envEnabled.
422
428
  const capsOn = String(env("ORACLE_VALUE_CAPS_ENABLED", "MAD_VALUE_CAPS_ENABLED", "1")).trim() !== "0";
423
429
  if (!capsOn) return true;
424
430
 
package/src/index.mjs CHANGED
@@ -67,3 +67,27 @@ export {
67
67
  DEFAULT_SCOPES,
68
68
  normalizeScopes,
69
69
  } from "./scopes.mjs";
70
+
71
+ export { emitHarnessConfigs, createHarnessConfigs } from "./onboarding/harness-configs.mjs";
72
+ export {
73
+ ACTION_RECEIPT_VERSION,
74
+ ActionReceiptSecretError,
75
+ assertNoReceiptSecrets,
76
+ canonicalReceiptJson,
77
+ computeReceiptId,
78
+ normalizeActionReceipt,
79
+ createActionReceipt,
80
+ summarizeActionReceipt,
81
+ formatActionReceipt,
82
+ } from "./action-receipts.mjs";
83
+ export { DEFAULT_RISK_THRESHOLDS, summarizePortfolioRisk, portfolioRiskSummary } from "./portfolio-risk.mjs";
84
+ export {
85
+ WATCH_CATEGORIES,
86
+ defaultPreferences,
87
+ subscribe,
88
+ unsubscribe,
89
+ createWatch,
90
+ evaluateAlert,
91
+ shouldDeliverAlert,
92
+ } from "./watch-preferences.mjs";
93
+ export { SIGNAL_TYPES, scoreSignals, createSignalsEngine } from "./signals/index.mjs";