@oracle-agent/oracle 0.4.2 → 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.
- package/README.md +66 -17
- package/SETUP.md +13 -0
- package/bin/oracle-data-mcp.mjs +1 -1
- package/bin/oracle.mjs +33 -0
- package/docs/cli.md +19 -0
- package/docs/connectors.md +13 -0
- package/package.json +7 -3
- package/profiles/robinhood-agent/SOUL.md +5 -3
- package/public/agent-connect/app.js +16 -13
- package/public/oracle-splash/assets/wordmarks/across.svg +4 -0
- package/public/oracle-splash/assets/wordmarks/aerodrome.svg +23 -0
- package/public/oracle-splash/assets/wordmarks/balancer.svg +3 -0
- package/public/oracle-splash/assets/wordmarks/cowswap.svg +1 -0
- package/public/oracle-splash/assets/wordmarks/gmx.svg +13 -0
- package/public/oracle-splash/assets/wordmarks/hyperliquid.svg +21 -0
- package/public/oracle-splash/assets/wordmarks/hyperswap.svg +13 -0
- package/public/oracle-splash/assets/wordmarks/jupiter.svg +35 -0
- package/public/oracle-splash/assets/wordmarks/lifi.png +0 -0
- package/public/oracle-splash/assets/wordmarks/magic-eden.svg +1 -0
- package/public/oracle-splash/assets/wordmarks/morpho.svg +1 -0
- package/public/oracle-splash/assets/wordmarks/odos.svg +3 -0
- package/public/oracle-splash/assets/wordmarks/oneinch.svg +6 -0
- package/public/oracle-splash/assets/wordmarks/opensea.svg +1 -0
- package/public/oracle-splash/assets/wordmarks/pancakeswap.svg +18 -0
- package/public/oracle-splash/assets/wordmarks/paraswap.svg +16 -0
- package/public/oracle-splash/assets/wordmarks/pendle.png +0 -0
- package/public/oracle-splash/assets/wordmarks/polymarket.png +0 -0
- package/public/oracle-splash/assets/wordmarks/quickswap.png +0 -0
- package/public/oracle-splash/assets/wordmarks/relay.svg +8 -0
- package/public/oracle-splash/assets/wordmarks/stargate.svg +15 -0
- package/public/oracle-splash/assets/wordmarks/uniswap.svg +18 -0
- package/public/oracle-splash/assets/wordmarks/velodrome.svg +84 -0
- package/public/oracle-splash/index.html +789 -485
- package/scripts/check-doc-drift.mjs +111 -0
- package/src/cli/commands/credential.mjs +9 -0
- package/src/cli/commands/data-mcp.mjs +18 -0
- package/src/cli/commands/data.mjs +73 -0
- package/src/cli/commands/doctor.mjs +131 -0
- package/src/cli/commands/help.mjs +7 -0
- package/src/cli/commands/init.mjs +27 -0
- package/src/cli/commands/mcp.mjs +142 -0
- package/src/cli/commands/prepare.mjs +12 -0
- package/src/cli/commands/public.mjs +20 -0
- package/src/cli/commands/route.mjs +12 -0
- package/src/cli/commands/runner.mjs +9 -0
- package/src/cli/commands/scan.mjs +12 -0
- package/src/cli/commands/sign.mjs +21 -0
- package/src/cli/commands/signer.mjs +9 -0
- package/src/cli/commands/upgrade.mjs +12 -0
- package/src/cli/commands/vault.mjs +9 -0
- package/src/cli/commands/version.mjs +22 -0
- package/src/cli/first-run.mjs +20 -0
- package/src/cli/kernel.mjs +198 -0
- package/src/cli/mcp-targets/chatgpt.mjs +51 -0
- package/src/cli/mcp-targets/claude-code.mjs +39 -0
- package/src/cli/mcp-targets/claude-desktop.mjs +24 -0
- package/src/cli/mcp-targets/codex.mjs +41 -0
- package/src/cli/mcp-targets/shared.mjs +61 -0
- package/src/cli/operator-dispatch.mjs +258 -0
- package/src/cli/paths.mjs +78 -0
- package/src/cli/spawn-child.mjs +43 -0
- package/src/public-api/connect-agent.mjs +29 -10
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveOperator } from "../operator-dispatch.mjs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: "version",
|
|
7
|
+
summary: "print oracle (and operator, if present) version",
|
|
8
|
+
group: "meta",
|
|
9
|
+
usage: "oracle version",
|
|
10
|
+
async run(ctx) {
|
|
11
|
+
let version = "0.0.0";
|
|
12
|
+
try {
|
|
13
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(ctx.root, "package.json"), "utf8"));
|
|
14
|
+
version = pkg.version || version;
|
|
15
|
+
} catch {}
|
|
16
|
+
let line = `oracle ${version}`;
|
|
17
|
+
const op = (ctx.resolveOperator || resolveOperator)();
|
|
18
|
+
if (op.ok) line += ` operator ${op.version}`;
|
|
19
|
+
process.stdout.write(line + "\n");
|
|
20
|
+
return 0;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const NEXT_STEPS_AFTER_INIT = [
|
|
2
|
+
"oracle data serve # loopback read/prepare plane on 127.0.0.1:8787",
|
|
3
|
+
"oracle doctor # verify",
|
|
4
|
+
"oracle mcp install claude-code",
|
|
5
|
+
"# optional, explicit second step — signing stays a separate local package:",
|
|
6
|
+
"npm i -g @oracle-agent/operator",
|
|
7
|
+
"oracle sign init",
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export function renderNextSteps() {
|
|
11
|
+
return [
|
|
12
|
+
"",
|
|
13
|
+
"Next:",
|
|
14
|
+
...NEXT_STEPS_AFTER_INIT.map((l) => " " + l),
|
|
15
|
+
"",
|
|
16
|
+
].join("\n");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DOCTOR_SIGNING_OPTIONAL =
|
|
20
|
+
"signing: not installed (optional) — npm i -g @oracle-agent/operator";
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { PACKAGE_ROOT, paths } from "./paths.mjs";
|
|
5
|
+
import {
|
|
6
|
+
dispatchOperator,
|
|
7
|
+
resolveOperator,
|
|
8
|
+
printOperatorNotInstalled,
|
|
9
|
+
SIGN_NOUNS,
|
|
10
|
+
} from "./operator-dispatch.mjs";
|
|
11
|
+
|
|
12
|
+
const HELP_HEADER = `oracle — prepare-only multichain agent control plane`;
|
|
13
|
+
|
|
14
|
+
const STATIC_HELP = `READ / RESEARCH (no keys, this package)
|
|
15
|
+
oracle init install agent lanes + read plane (dry-run by default)
|
|
16
|
+
oracle doctor check read plane; checks signer too when installed
|
|
17
|
+
oracle data serve|call|catalog|health
|
|
18
|
+
oracle data-mcp start the read-only MCP server
|
|
19
|
+
oracle scan chains|head|token|pools|risk|quote|sell
|
|
20
|
+
oracle route swap|bridge|prepare|prepare-bridge
|
|
21
|
+
oracle prepare build an unsigned swap (alias of route prepare)
|
|
22
|
+
oracle public serve secret-free public HTTP surface
|
|
23
|
+
oracle mcp install <t> wire Oracle into claude-code|claude-desktop|codex|chatgpt
|
|
24
|
+
oracle upgrade upgrade installed Hermes lanes
|
|
25
|
+
|
|
26
|
+
SIGNING (dispatches to @oracle-agent/operator on THIS machine; never in this package)
|
|
27
|
+
oracle sign init|doctor provision / check the local signer (opt-in)
|
|
28
|
+
oracle vault ... encrypt local key files at rest
|
|
29
|
+
oracle signer / runner loopback signer daemon / action runner
|
|
30
|
+
oracle credential ... OS credential store glue
|
|
31
|
+
|
|
32
|
+
oracle <noun> --help for details. Keys never leave your machine; this package
|
|
33
|
+
cannot sign — signing commands run the locally installed operator package.
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
function readPackageVersion() {
|
|
37
|
+
try {
|
|
38
|
+
const pkg = JSON.parse(
|
|
39
|
+
fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8"),
|
|
40
|
+
);
|
|
41
|
+
return pkg.version || "0.0.0";
|
|
42
|
+
} catch {
|
|
43
|
+
return "0.0.0";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function commandsDir() {
|
|
48
|
+
return path.join(PACKAGE_ROOT, "src", "cli", "commands");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function discoverCommands() {
|
|
52
|
+
const dir = commandsDir();
|
|
53
|
+
const out = new Map();
|
|
54
|
+
if (!fs.existsSync(dir)) return out;
|
|
55
|
+
const entries = fs
|
|
56
|
+
.readdirSync(dir)
|
|
57
|
+
.filter((f) => f.endsWith(".mjs"))
|
|
58
|
+
.sort();
|
|
59
|
+
for (const file of entries) {
|
|
60
|
+
const full = path.join(dir, file);
|
|
61
|
+
try {
|
|
62
|
+
const mod = await import(pathToFileURL(full).href + `?t=${Date.now()}`);
|
|
63
|
+
const cmd = mod.default;
|
|
64
|
+
if (!cmd || typeof cmd !== "object" || typeof cmd.run !== "function") {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const name = cmd.name || file.replace(/\.mjs$/, "");
|
|
68
|
+
out.set(name, { ...cmd, name, __file: full });
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (process.env.ORACLE_CLI_DEBUG) {
|
|
71
|
+
console.error(`oracle: failed loading command ${file}: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function renderHelp(version, commands) {
|
|
79
|
+
const lines = [];
|
|
80
|
+
lines.push(`${HELP_HEADER} (v${version})`);
|
|
81
|
+
lines.push("");
|
|
82
|
+
lines.push(STATIC_HELP.trimEnd());
|
|
83
|
+
|
|
84
|
+
const extras = [];
|
|
85
|
+
for (const cmd of commands.values()) {
|
|
86
|
+
if (["help", "version"].includes(cmd.name)) continue;
|
|
87
|
+
const known = new Set([
|
|
88
|
+
"init","doctor","data","data-mcp","scan","route","prepare","public","mcp","upgrade",
|
|
89
|
+
"sign","vault","signer","runner","credential",
|
|
90
|
+
]);
|
|
91
|
+
if (!known.has(cmd.name) && cmd.summary) {
|
|
92
|
+
extras.push(` oracle ${cmd.name.padEnd(20)} ${cmd.summary}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (extras.length) {
|
|
96
|
+
lines.push("");
|
|
97
|
+
lines.push("ADDITIONAL");
|
|
98
|
+
lines.push(...extras);
|
|
99
|
+
}
|
|
100
|
+
return lines.join("\n") + "\n";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function unknownNounMessage(noun, commands) {
|
|
104
|
+
const known = [...commands.keys()].sort();
|
|
105
|
+
const list = known.length ? known.join(", ") : "(none loaded yet)";
|
|
106
|
+
return `oracle: unknown command '${noun}'. Known: ${list}\nTry: oracle --help\n`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function buildCtx(argv) {
|
|
110
|
+
return {
|
|
111
|
+
argv,
|
|
112
|
+
root: PACKAGE_ROOT,
|
|
113
|
+
paths,
|
|
114
|
+
dispatchOperator,
|
|
115
|
+
resolveOperator,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function run(argv = []) {
|
|
120
|
+
const version = readPackageVersion();
|
|
121
|
+
|
|
122
|
+
if (argv.includes("--version") || argv.includes("-V")) {
|
|
123
|
+
return runVersion();
|
|
124
|
+
}
|
|
125
|
+
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
|
|
126
|
+
const commands = await discoverCommands();
|
|
127
|
+
process.stdout.write(renderHelp(version, commands));
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const noun = argv[0];
|
|
132
|
+
const rest = argv.slice(1);
|
|
133
|
+
|
|
134
|
+
if (noun === "version") {
|
|
135
|
+
return runVersion();
|
|
136
|
+
}
|
|
137
|
+
if (noun === "help") {
|
|
138
|
+
const commands = await discoverCommands();
|
|
139
|
+
if (rest[0]) {
|
|
140
|
+
const cmd = commands.get(rest[0]);
|
|
141
|
+
if (cmd) {
|
|
142
|
+
process.stdout.write((cmd.usage || `oracle ${cmd.name}`) + "\n");
|
|
143
|
+
if (cmd.summary) process.stdout.write(cmd.summary + "\n");
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
process.stderr.write(unknownNounMessage(rest[0], commands));
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
process.stdout.write(renderHelp(version, commands));
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const commands = await discoverCommands();
|
|
154
|
+
const cmd = commands.get(noun);
|
|
155
|
+
|
|
156
|
+
if (cmd) {
|
|
157
|
+
if (rest[0] === "--help" || rest[0] === "-h") {
|
|
158
|
+
process.stdout.write((cmd.usage || `oracle ${cmd.name}`) + "\n");
|
|
159
|
+
if (cmd.summary) process.stdout.write(cmd.summary + "\n");
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const code = await cmd.run(buildCtx(rest));
|
|
164
|
+
return typeof code === "number" ? code : 0;
|
|
165
|
+
} catch (err) {
|
|
166
|
+
process.stderr.write(`oracle ${noun}: ${err?.message || err}\n`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (SIGN_NOUNS.includes(noun)) {
|
|
172
|
+
const resolved = resolveOperator();
|
|
173
|
+
if (!resolved.ok) {
|
|
174
|
+
printOperatorNotInstalled(process.stderr);
|
|
175
|
+
return 3;
|
|
176
|
+
}
|
|
177
|
+
process.stderr.write(
|
|
178
|
+
`oracle: sign-plane command '${noun}' is not available in this build (operator is installed).\n`,
|
|
179
|
+
);
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
process.stderr.write(unknownNounMessage(noun, commands));
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function runVersion() {
|
|
188
|
+
const version = readPackageVersion();
|
|
189
|
+
let line = `oracle ${version}`;
|
|
190
|
+
const op = resolveOperator();
|
|
191
|
+
if (op.ok) {
|
|
192
|
+
line += ` operator ${op.version}`;
|
|
193
|
+
}
|
|
194
|
+
process.stdout.write(line + "\n");
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default { run, discoverCommands, renderHelp };
|
|
@@ -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
|
+
}
|