stanford-openarch 0.0.0 → 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.
- package/cli/check.js +467 -0
- package/cli/draft.js +75 -0
- package/cli/init.js +511 -0
- package/cli/mcp.js +302 -0
- package/cli/openarch.js +856 -0
- package/cli/pathCheck.js +114 -0
- package/cli/research.js +248 -0
- package/cli/safeFile.js +69 -0
- package/cli/ui.js +209 -0
- package/members/kit/README.md +215 -0
- package/members/kit/catalog.js +217 -0
- package/members/kit/csv.js +51 -0
- package/members/kit/index.js +286 -0
- package/members/kit/searchIndex.js +61 -0
- package/members/lib/fileSafety.js +35 -0
- package/members/lib/verifyQuote.js +210 -0
- package/package.json +22 -3
- package/protocol/MEMBERSHIP-AGREEMENT.md +105 -0
- package/protocol/OPENARCH-PROTOCOL.md +475 -0
- package/protocol/PARTNER-TERMS.md +43 -0
- package/server/lib/mcpTools.js +194 -0
- package/server/lib/readCapped.js +34 -0
- package/server/lib/vocabulary.js +177 -0
- package/README.md +0 -3
package/cli/mcp.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// mcp.js — openarch for agents: serve the network's tools over stdio, wire them into
|
|
2
|
+
// an agent's config in one command, and prove the wiring works.
|
|
3
|
+
//
|
|
4
|
+
// openarch mcp serve stdio MCP server, same tools as the hub's /mcp,
|
|
5
|
+
// authenticated by the key stored on this machine
|
|
6
|
+
// openarch mcp install claude|desktop|cursor|vscode [--http] [--print] [--config <file>] [-y]
|
|
7
|
+
// openarch mcp uninstall <client> [--config <file>] [-y]
|
|
8
|
+
// openarch mcp doctor hub · key · MCP handshake · tools · bridge · clients
|
|
9
|
+
//
|
|
10
|
+
// By default every client runs the stdio bridge, so the key lives in exactly one
|
|
11
|
+
// file (~/.config/openarch/config.json, mode 600) and no agent config holds it.
|
|
12
|
+
// --http writes the hub's URL and the key into the client's config instead.
|
|
13
|
+
import { openarchOnPath, judgeOpenarchOnPath } from "./pathCheck.js";
|
|
14
|
+
import { readFileSync, existsSync, mkdirSync, chmodSync, lstatSync, realpathSync } from "node:fs";
|
|
15
|
+
import { writeReplacing } from "./safeFile.js"; // run-2 #7's writer, shared with pull, init and apply (ind-sec run-3 P2)
|
|
16
|
+
import { execFile } from "node:child_process";
|
|
17
|
+
import { promisify } from "node:util";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
import { homedir, platform } from "node:os";
|
|
20
|
+
import * as ui from "./ui.js";
|
|
21
|
+
|
|
22
|
+
const run = promisify(execFile);
|
|
23
|
+
const mask = (k) => (k ? `${k.slice(0, 10)}…` : "");
|
|
24
|
+
/** Any key in a string, masked: node's execFile error message embeds the child's argv (ind-sec run-1, claude-header-key-in-argv). */
|
|
25
|
+
const redact = (s) => String(s ?? "").replace(/oa_[a-z]+_[0-9a-f]{40}/g, (k) => mask(k));
|
|
26
|
+
|
|
27
|
+
const CLIENTS = {
|
|
28
|
+
// Claude Code takes an http server's headers only on its command line, where every
|
|
29
|
+
// process on the machine can read them (ps, /proc): so no --http for it, only the
|
|
30
|
+
// stdio bridge, which reads the key from this machine's config (ind-sec run-2 #23,
|
|
31
|
+
// mcp install:claude-header-key-in-argv)
|
|
32
|
+
claude: { name: "Claude Code", kind: "cli", http: false, httpWhy: "Claude Code takes an http server's key only on its command line, where other processes on this machine can read it." },
|
|
33
|
+
desktop: { name: "Claude Desktop", kind: "json", root: "mcpServers", path: () => (platform() === "darwin" ? join(homedir(), "Library", "Application Support", "Claude", "claude_desktop_config.json") : platform() === "win32" ? join(process.env.APPDATA || homedir(), "Claude", "claude_desktop_config.json") : join(homedir(), ".config", "Claude", "claude_desktop_config.json")), http: false },
|
|
34
|
+
cursor: { name: "Cursor", kind: "json", root: "mcpServers", path: () => join(homedir(), ".cursor", "mcp.json"), http: true },
|
|
35
|
+
vscode: { name: "VS Code (this workspace)", kind: "json", root: "servers", path: () => join(process.cwd(), ".vscode", "mcp.json"), http: true },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Why an agent's stdio bridge entry does not run this program, or null when it does. The
|
|
39
|
+
* entry holds an absolute path into the package that wrote it, so it outlives that install:
|
|
40
|
+
* the package was renamed stanford-openarch on 2026-11-29, and an install from before then
|
|
41
|
+
* lived under node_modules/openarch, which `npm rm -g openarch` removes (or keeps running the
|
|
42
|
+
* old name's code, if it stays). */
|
|
43
|
+
export function strayBridge(entry, root) {
|
|
44
|
+
const script = Array.isArray(entry?.args) ? entry.args[0] : null;
|
|
45
|
+
if (!entry?.command || typeof script !== "string") return null;
|
|
46
|
+
const mine = join(root, "cli", "openarch.js");
|
|
47
|
+
const real = (p) => { try { return realpathSync(p); } catch { return null; } };
|
|
48
|
+
if (script === mine || (real(script) !== null && real(script) === real(mine))) return null;
|
|
49
|
+
return existsSync(script) ? `the stdio bridge runs ${script}, not this program (${mine})` : `the stdio bridge runs ${script}, which is not there`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function bridgeEntry(ctx) {
|
|
53
|
+
const entry = { command: process.execPath, args: [join(ctx.ROOT, "cli", "openarch.js"), "mcp", "serve"] };
|
|
54
|
+
if (ctx.HUB !== ctx.DEFAULT_HUB) entry.env = { OPENARCH_HUB: ctx.HUB };
|
|
55
|
+
return entry;
|
|
56
|
+
}
|
|
57
|
+
function httpEntry(ctx, client) {
|
|
58
|
+
const e = { url: `${ctx.HUB}/mcp`, headers: { Authorization: `Bearer ${ctx.KEY}` } };
|
|
59
|
+
return client === "vscode" ? { type: "http", ...e } : e;
|
|
60
|
+
}
|
|
61
|
+
const showEntry = (e) => JSON.stringify(e, null, 2).replace(/Bearer oa_[a-z]+_[0-9a-f]{40}/g, (m) => `Bearer ${mask(m.slice(7))}`);
|
|
62
|
+
|
|
63
|
+
// A config path a cloned repository could plant (ind-sec run-2, workspace-config-paths-
|
|
64
|
+
// follow-symlinks): .vscode/mcp.json, or its backup, as a symbolic link would turn
|
|
65
|
+
// `mcp install vscode` into a write outside the workspace, through the user's own hand.
|
|
66
|
+
// The directory, the config and its backup must not be links; an existing file must be a
|
|
67
|
+
// regular file the user owns. Writes go through a new file in the same directory, then a
|
|
68
|
+
// rename over the destination, which replaces a link instead of following it.
|
|
69
|
+
function unsafePath(path) {
|
|
70
|
+
const own = typeof process.getuid === "function" ? process.getuid() : null;
|
|
71
|
+
const check = (p, kind) => {
|
|
72
|
+
let st;
|
|
73
|
+
try { st = lstatSync(p); } catch (e) { return e.code === "ENOENT" ? null : `${p}: ${e.message}`; }
|
|
74
|
+
if (st.isSymbolicLink()) return `${p} is a symbolic link`;
|
|
75
|
+
if (kind === "dir" ? !st.isDirectory() : !st.isFile()) return `${p} is not a ${kind === "dir" ? "directory" : "regular file"}`;
|
|
76
|
+
if (kind === "file" && own !== null && st.uid !== own) return `${p} is not yours`;
|
|
77
|
+
return null;
|
|
78
|
+
};
|
|
79
|
+
return check(dirname(path), "dir") ?? check(path, "file") ?? check(`${path}.openarch-backup`, "file");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function readJson(path) {
|
|
83
|
+
if (!existsSync(path)) return {};
|
|
84
|
+
const raw = readFileSync(path, "utf8");
|
|
85
|
+
if (!raw.trim()) return {};
|
|
86
|
+
return JSON.parse(raw); // a config that is not JSON is the user's; the caller refuses to touch it
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function cmdMcp(ctx, sub, client) {
|
|
90
|
+
switch (sub) {
|
|
91
|
+
case "serve": return serve(ctx);
|
|
92
|
+
case "install": return install(ctx, client, false);
|
|
93
|
+
case "uninstall": case "remove": return install(ctx, client, true);
|
|
94
|
+
case "doctor": return doctor(ctx);
|
|
95
|
+
default: return ui.fail(`Unknown mcp command ${JSON.stringify(sub ?? "")}.`, "openarch mcp install <claude|desktop|cursor|vscode> · mcp doctor · mcp serve");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── install / uninstall ─────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
async function install(ctx, client, remove) {
|
|
102
|
+
const { flags, JSON_OUT } = ctx;
|
|
103
|
+
const c = CLIENTS[client];
|
|
104
|
+
if (!c) return ui.fail(`Install into which client?`, `openarch mcp ${remove ? "uninstall" : "install"} ${Object.keys(CLIENTS).join("|")} [--http] [--print] [-y]`);
|
|
105
|
+
const http = Boolean(flags.http);
|
|
106
|
+
if (!remove) {
|
|
107
|
+
if (http && c.http === false) return ui.fail(c.httpWhy ?? `${c.name} runs local servers; it cannot send a key to a remote one.`, `openarch mcp install ${client} (without --http) wires the stdio bridge, which reads your stored key.`);
|
|
108
|
+
if (http && !ctx.KEY) return ui.fail("--http writes your key into the client's config, and there is no key.", "openarch login, or pass --key.");
|
|
109
|
+
if (http && ui.plainHttpRemote(ctx.HUB)) return ui.fail(`${ctx.HUB} is plain http on another machine; an agent's key goes only over https.`, "Use the hub's https address, or the stdio bridge (without --http).");
|
|
110
|
+
if (!http && !ctx.storedKey) return ui.fail(ctx.storedKeyHub ? `The bridge reads the key stored on this machine, and that key is for ${ui.cleanLine(ctx.storedKeyHub)}, not ${ctx.HUB}.` : "The bridge reads the key stored on this machine, and none is stored.", ctx.storedKeyHub ? "A stored key is only ever sent to its own hub. openarch login --hub <this hub> stores one for it." : "openarch login stores one (~/.config/openarch, mode 600).");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (c.kind === "cli") {
|
|
114
|
+
// never a key in this argv (#23): the bridge reads it from the stored config
|
|
115
|
+
const argv = remove ? ["mcp", "remove", "--scope", "user", "openarch"]
|
|
116
|
+
// The name goes before -e: `claude mcp add` reads -e as variadic and would
|
|
117
|
+
// take the name for a second variable (claude 2.x, 2026-11-21).
|
|
118
|
+
: ["mcp", "add", "--scope", "user", "openarch", ...(ctx.HUB !== ctx.DEFAULT_HUB ? ["-e", `OPENARCH_HUB=${ctx.HUB}`] : []), "--", process.execPath, join(ctx.ROOT, "cli", "openarch.js"), "mcp", "serve"];
|
|
119
|
+
const shown = `claude ${argv.map((a) => (/[\s"]/.test(a) ? JSON.stringify(a) : a)).join(" ")}`.replace(/Bearer oa_[a-z]+_[0-9a-f]{40}/g, (m) => `Bearer ${mask(m.slice(7))}`);
|
|
120
|
+
if (flags.print) { if (JSON_OUT) return ui.json({ client, command: shown }); ui.blank(); ui.out(` ${shown}`); ui.blank(); return; }
|
|
121
|
+
try { await run("claude", argv, { timeout: 30_000 }); }
|
|
122
|
+
catch (e) {
|
|
123
|
+
if (e.code === "ENOENT") return ui.fail("The claude command is not on this PATH.", `Run it yourself: ${shown}`);
|
|
124
|
+
return ui.fail(`claude ${remove ? "mcp remove" : "mcp add"} failed: ${redact((e.stderr || e.message).trim().split("\n")[0])}`, remove ? "" : "If openarch is already there: openarch mcp uninstall claude, then install again.");
|
|
125
|
+
}
|
|
126
|
+
if (JSON_OUT) return ui.json({ client, ok: true, removed: remove });
|
|
127
|
+
ui.out(` ${ui.glyph.pass} ${remove ? "removed openarch from" : "openarch added to"} ${ui.bold(c.name)} ${ui.dim("(user scope)")}${remove ? "" : ui.dim(" · try: openarch mcp doctor")}`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const path = flags.config || c.path();
|
|
132
|
+
let conf;
|
|
133
|
+
const unsafe = unsafePath(path);
|
|
134
|
+
if (unsafe) return ui.fail(`Refusing to touch ${path}: ${unsafe}.`, "openarch writes an agent config only as a regular file of yours, never through a link; remove the link, or pass --config <file>.");
|
|
135
|
+
try { conf = readJson(path); } catch (e) { return ui.fail(`${path} is not valid JSON (${e.message}).`, "openarch leaves a config it cannot read untouched; fix it or pass --config <file>."); }
|
|
136
|
+
const servers = { ...(conf[c.root] ?? {}) };
|
|
137
|
+
const before = servers.openarch ?? null;
|
|
138
|
+
if (remove) { if (!before) return ui.out(` ${ui.dim(`openarch is not in ${path}`)}`); delete servers.openarch; }
|
|
139
|
+
else servers.openarch = http ? httpEntry(ctx, client) : bridgeEntry(ctx);
|
|
140
|
+
const next = { ...conf, [c.root]: servers };
|
|
141
|
+
if (!remove && JSON.stringify(before) === JSON.stringify(servers.openarch)) {
|
|
142
|
+
if (JSON_OUT) return ui.json({ client, path, changed: false });
|
|
143
|
+
return ui.out(` ${ui.glyph.pass} ${ui.bold(c.name)} already has this openarch entry ${ui.dim(`(${path})`)}`);
|
|
144
|
+
}
|
|
145
|
+
if (flags.print) {
|
|
146
|
+
if (JSON_OUT) return ui.json({ client, path, [c.root]: { openarch: remove ? null : JSON.parse(showEntry(servers.openarch)) } });
|
|
147
|
+
ui.blank(); ui.out(` ${ui.dim(path)}`); ui.out(` ${ui.dim(`"${c.root}": { "openarch":`)}`); ui.out(showEntry(servers.openarch ?? null).split("\n").map((l) => ` ${l}`).join("\n")); ui.out(` ${ui.dim("}")}`); ui.blank(); return;
|
|
148
|
+
}
|
|
149
|
+
if (!JSON_OUT) {
|
|
150
|
+
ui.blank();
|
|
151
|
+
ui.out(` ${ui.bold(c.name)} ${ui.dim(path)}`);
|
|
152
|
+
ui.out(remove ? ` ${ui.dim("remove the openarch entry; every other server stays")}` : showEntry(servers.openarch).split("\n").map((l) => ` ${ui.dim(l)}`).join("\n"));
|
|
153
|
+
if (!remove && http) ui.out(` ${ui.glyph.warn} ${ui.amber("This file will hold your key.")} ${ui.dim("Without --http it would not.")}`);
|
|
154
|
+
}
|
|
155
|
+
if (!flags.yes && !(await ui.confirm(remove ? "Remove it?" : before ? "Replace the existing openarch entry?" : "Write it?", true))) return ui.out(` ${ui.dim("Nothing written.")}`);
|
|
156
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
157
|
+
{ const late = unsafePath(path); if (late) return ui.fail(`Refusing to touch ${path}: ${late}.`, "remove the link, or pass --config <file>."); }
|
|
158
|
+
// The backup is the user's config as it was, owner-only, and WITHOUT openarch's
|
|
159
|
+
// own key: a previous --http entry's Authorization header is taken out, so
|
|
160
|
+
// uninstalling or moving to the bridge leaves no key behind (ind-sec run-1,
|
|
161
|
+
// key-bearing-config-copies).
|
|
162
|
+
if (existsSync(path)) {
|
|
163
|
+
let text = readFileSync(path, "utf8");
|
|
164
|
+
try {
|
|
165
|
+
const old = JSON.parse(text);
|
|
166
|
+
const h = old?.[c.root]?.openarch?.headers;
|
|
167
|
+
if (h && typeof h === "object") for (const k of Object.keys(h)) if (/^authorization$/i.test(k)) h[k] = "Bearer <removed by openarch>";
|
|
168
|
+
text = JSON.stringify(old, null, 2) + "\n";
|
|
169
|
+
} catch { text = redact(text); }
|
|
170
|
+
writeReplacing(`${path}.openarch-backup`, text);
|
|
171
|
+
}
|
|
172
|
+
writeReplacing(path, JSON.stringify(next, null, 2) + "\n");
|
|
173
|
+
// a file that now holds the key is owner-only whatever mode it had
|
|
174
|
+
if (!remove && http) chmodSync(path, 0o600);
|
|
175
|
+
if (JSON_OUT) return ui.json({ client, path, changed: true, removed: remove, backup: existsSync(`${path}.openarch-backup`) ? `${path}.openarch-backup` : null });
|
|
176
|
+
ui.out(` ${ui.glyph.pass} ${remove ? "removed from" : "wrote"} ${path}${existsSync(`${path}.openarch-backup`) ? ui.dim(` (previous copy: ${path}.openarch-backup)`) : ""}`);
|
|
177
|
+
if (!remove) ui.out(` ${ui.dim(`Restart ${c.name} to load it · openarch mcp doctor checks the wiring`)}`);
|
|
178
|
+
ui.blank();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── serve (stdio) ───────────────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
async function serve(ctx) {
|
|
184
|
+
// stdout belongs to the protocol from here on: every word for a person goes to stderr
|
|
185
|
+
if (!ctx.KEY) { process.stderr.write("openarch mcp serve: no key. Run `openarch login` (or set OPENARCH_API_KEY).\n"); process.exitCode = 1; return; }
|
|
186
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
187
|
+
const { buildHubMcpServer } = await import("../server/lib/mcpTools.js");
|
|
188
|
+
const api = (method, path, query, body) => ctx.hub(path, { method, query, body }).catch((e) => { throw new Error(e.body?.error ? `${e.body.error}${e.body.message ? `: ${e.body.message}` : ""}` : e.message); });
|
|
189
|
+
if (ui.plainHttpRemote(ctx.HUB)) { process.stderr.write(`openarch mcp serve: not sending the key to ${ctx.HUB} (plain http on another machine).\n`); process.exitCode = 1; return; }
|
|
190
|
+
const raw = (path) => fetch(`${ctx.HUB}/api/v1${path}`, { headers: { Authorization: `Bearer ${ctx.KEY}`, "User-Agent": `openarch-cli/${ctx.version} (mcp)` }, redirect: "manual" });
|
|
191
|
+
const server = buildHubMcpServer({ api, raw, who: `the key stored on this machine (${mask(ctx.KEY)}), through ${ctx.HUB}`, publicBase: ctx.HUB });
|
|
192
|
+
await server.connect(new StdioServerTransport());
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── doctor ──────────────────────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
const EXPECTED_TOOLS = ["list_members", "get_member", "search", "get_document", "cite_document", "list_files", "get_file", "verify_quote", "verify_quotes", "find_quote", "may_i"];
|
|
198
|
+
|
|
199
|
+
async function doctor(ctx) {
|
|
200
|
+
const { hub, HUB, KEY, JSON_OUT } = ctx;
|
|
201
|
+
const checks = [];
|
|
202
|
+
const add = (status, id, title, detail = "", fix = "") => { checks.push({ id, status, title, detail, fix }); sp.update(`${id} ${title}`); };
|
|
203
|
+
const time = async (fn) => { const t0 = Date.now(); const v = await fn(); return [v, Date.now() - t0]; };
|
|
204
|
+
const sp = ui.spinner(`checking openarch for agents against ${HUB}`);
|
|
205
|
+
try {
|
|
206
|
+
// K1 key
|
|
207
|
+
// which `openarch` a typed command runs: never someone else's program with your key
|
|
208
|
+
const onPath = judgeOpenarchOnPath(openarchOnPath(ctx.ROOT));
|
|
209
|
+
add(onPath.status, "O1", "openarch on PATH", onPath.detail, onPath.fix ?? "");
|
|
210
|
+
if (!KEY) add("fail", "K1", "key", "none found (flag, OPENARCH_API_KEY, or ~/.config/openarch)", "openarch login");
|
|
211
|
+
else add("pass", "K1", "key", `${mask(KEY)} · from ${ctx.keySource}`);
|
|
212
|
+
// H1 hub
|
|
213
|
+
let meta = null;
|
|
214
|
+
try { const [m, ms] = await time(() => hub("/meta", { auth: false })); meta = m; add("pass", "H1", "hub answers", `protocol ${m.protocol} · ${m.members.length} member${m.members.length === 1 ? "" : "s"} · ${ui.fmtMs(ms)}`); }
|
|
215
|
+
catch (e) { add("fail", "H1", "hub answers", e.message, `Is ${HUB} right? --hub <url> or OPENARCH_HUB.`); }
|
|
216
|
+
// H2 key accepted
|
|
217
|
+
let who = null;
|
|
218
|
+
if (KEY && meta) {
|
|
219
|
+
try { who = await hub("/whoami"); add("pass", "H2", "key accepted", `${who.holder ?? "?"} · ${who.role} · ${ui.fmtInt(who.remaining?.documents_today)} documents left today`); }
|
|
220
|
+
catch (e) { add("fail", "H2", "key accepted", `${e.status ?? ""} ${e.message}`.trim(), "openarch login with a key this hub issued."); }
|
|
221
|
+
} else add("skip", "H2", "key accepted", "needs a key and a hub");
|
|
222
|
+
// P1–P3 MCP over HTTP
|
|
223
|
+
let tools = [];
|
|
224
|
+
if (who) {
|
|
225
|
+
const { Client } = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
226
|
+
const { StreamableHTTPClientTransport } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
227
|
+
const client = new Client({ name: "openarch-doctor", version: ctx.version });
|
|
228
|
+
try {
|
|
229
|
+
const [, ms] = await time(() => client.connect(new StreamableHTTPClientTransport(new URL(`${HUB}/mcp`), { requestInit: { headers: { Authorization: `Bearer ${KEY}` } } })));
|
|
230
|
+
const sv = client.getServerVersion();
|
|
231
|
+
add("pass", "P1", "MCP handshake", `${sv?.name ?? "?"} ${sv?.version ?? ""} at ${HUB}/mcp · ${ui.fmtMs(ms)}`);
|
|
232
|
+
tools = (await client.listTools()).tools.map((t) => t.name);
|
|
233
|
+
const missing = EXPECTED_TOOLS.filter((t) => !tools.includes(t));
|
|
234
|
+
add(missing.length ? "warn" : "pass", "P2", "tools listed", missing.length ? `${tools.length} tools; missing ${missing.join(", ")}` : `${tools.length} tools`, missing.length ? "The hub runs an older openarch; the missing tools arrive with its next deploy." : "");
|
|
235
|
+
const [r, ms2] = await time(() => client.callTool({ name: "list_members", arguments: {} }));
|
|
236
|
+
if (r.isError) add("fail", "P3", "a tool answers", r.content?.[0]?.text ?? "error");
|
|
237
|
+
else { const n = JSON.parse(r.content[0].text).members?.length ?? 0; add("pass", "P3", "a tool answers", `list_members → ${n} member${n === 1 ? "" : "s"} · ${ui.fmtMs(ms2)}`); }
|
|
238
|
+
} catch (e) { add("fail", "P1", "MCP handshake", e.message, `The hub's /mcp did not complete a handshake with this key.`); }
|
|
239
|
+
finally { await client.close().catch(() => {}); }
|
|
240
|
+
} else add("skip", "P1", "MCP handshake", "needs an accepted key");
|
|
241
|
+
// M1 members answer through the hub
|
|
242
|
+
if (who && meta?.members?.length) {
|
|
243
|
+
try {
|
|
244
|
+
const r = await hub("/search", { query: { q: "openarchdoctorprobe", limit: 1 } });
|
|
245
|
+
for (const g of r.members) {
|
|
246
|
+
if (!g.error) { add("pass", "M1", `member ${g.member}`, "answers through the hub"); continue; }
|
|
247
|
+
const why = g.error === "member_unavailable" ? "not reachable from the hub" : g.error === "member_bad_response" ? "answers, but not with openarch JSON" : `answers ${g.error}`;
|
|
248
|
+
add("warn", "M1", `member ${g.member}`, `${why}${g.message ? ` · ${g.message.slice(0, 60)}` : ""}`, "Its adapter is down, not public, or behind a page the hub cannot pass; its documents are unreachable until the operator fixes the member's URL.");
|
|
249
|
+
}
|
|
250
|
+
} catch (e) { add("warn", "M1", "members", e.message); }
|
|
251
|
+
}
|
|
252
|
+
// B1 the stdio bridge on this machine
|
|
253
|
+
if (KEY && meta) {
|
|
254
|
+
const { Client } = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
255
|
+
const { StdioClientTransport } = await import("@modelcontextprotocol/sdk/client/stdio.js");
|
|
256
|
+
const client = new Client({ name: "openarch-doctor", version: ctx.version });
|
|
257
|
+
try {
|
|
258
|
+
const env = { ...process.env, OPENARCH_HUB: HUB, OPENARCH_API_KEY: KEY };
|
|
259
|
+
const [, ms] = await time(() => client.connect(new StdioClientTransport({ command: process.execPath, args: [join(ctx.ROOT, "cli", "openarch.js"), "mcp", "serve"], env, stderr: "pipe" })));
|
|
260
|
+
const n = (await client.listTools()).tools.length;
|
|
261
|
+
add("pass", "B1", "stdio bridge", `openarch mcp serve · ${n} tools · ${ui.fmtMs(ms)}`);
|
|
262
|
+
} catch (e) { add("fail", "B1", "stdio bridge", e.message, "openarch mcp serve should start and list its tools; run it by hand to see why it does not."); }
|
|
263
|
+
finally { await client.close().catch(() => {}); }
|
|
264
|
+
}
|
|
265
|
+
// C1 which agents on this machine have openarch
|
|
266
|
+
for (const [id, c] of Object.entries(CLIENTS)) {
|
|
267
|
+
if (c.kind === "cli") {
|
|
268
|
+
let has = null, stray = null;
|
|
269
|
+
try { const j = JSON.parse(readFileSync(join(homedir(), ".claude.json"), "utf8")); has = Boolean(j.mcpServers?.openarch); stray = has ? strayBridge(j.mcpServers.openarch, ctx.ROOT) : null; } catch { has = null; }
|
|
270
|
+
if (stray) add("warn", "C1", c.name, stray, `openarch mcp uninstall ${id}, then openarch mcp install ${id}`);
|
|
271
|
+
else add(has ? "pass" : "skip", "C1", c.name, has ? "openarch configured (user scope)" : has === false ? `not configured · openarch mcp install ${id}` : "not found on this machine");
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const path = c.path();
|
|
275
|
+
if (!existsSync(path)) { add("skip", "C1", c.name, `no config · openarch mcp install ${id}`); continue; }
|
|
276
|
+
try {
|
|
277
|
+
const e = readJson(path)[c.root]?.openarch;
|
|
278
|
+
if (!e) add("skip", "C1", c.name, `not configured · openarch mcp install ${id}`);
|
|
279
|
+
else if (strayBridge(e, ctx.ROOT)) add("warn", "C1", c.name, strayBridge(e, ctx.ROOT), `openarch mcp install ${id} -y`);
|
|
280
|
+
else add("pass", "C1", c.name, e.command ? "stdio bridge" : `http · ${e.url}`);
|
|
281
|
+
} catch { add("warn", "C1", c.name, `${path} is not valid JSON`); }
|
|
282
|
+
}
|
|
283
|
+
} finally { sp.stop(); }
|
|
284
|
+
|
|
285
|
+
const failed = checks.filter((c) => c.status === "fail").length, warned = checks.filter((c) => c.status === "warn").length;
|
|
286
|
+
process.exitCode = failed ? 1 : 0;
|
|
287
|
+
if (JSON_OUT) return ui.json({ hub: HUB, failed, warned, checks });
|
|
288
|
+
ui.blank();
|
|
289
|
+
ui.out(` ${ui.bold("openarch mcp doctor")} ${ui.dim(HUB)}`);
|
|
290
|
+
ui.blank();
|
|
291
|
+
// a member's or hub's words, one line each, control characters as U+FFFD (P3 #25)
|
|
292
|
+
for (const c of checks) {
|
|
293
|
+
const L = ui.cleanLine;
|
|
294
|
+
ui.out(` ${ui.glyph[c.status]} ${ui.pad(L(c.title), 26)} ${c.status === "skip" ? ui.dim(L(c.detail)) : L(c.detail)}`);
|
|
295
|
+
if (c.fix && c.status !== "pass") ui.out(` ${ui.dim("→ " + L(c.fix))}`);
|
|
296
|
+
}
|
|
297
|
+
ui.blank();
|
|
298
|
+
ui.out(ui.rule(46));
|
|
299
|
+
ui.out(` ${[ui.green(`${checks.filter((c) => c.status === "pass").length} passed`), failed ? ui.red(`${failed} failed`) : null, warned ? ui.amber(`${warned} warning${warned === 1 ? "" : "s"}`) : null].filter(Boolean).join(ui.dim(" · "))}`);
|
|
300
|
+
if (!failed && !checks.some((c) => c.id === "C1" && c.status === "pass")) ui.out(` ${ui.dim("Working. Wire it into an agent: openarch mcp install claude | desktop | cursor | vscode")}`);
|
|
301
|
+
ui.blank();
|
|
302
|
+
}
|