@cello-protocol/cli 0.0.305 → 0.0.307
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/.claude-plugin/marketplace.json +15 -0
- package/README.md +107 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +564 -0
- package/dist/daemon/account-page-assets.d.ts +4 -0
- package/dist/daemon/account-page-assets.js +160 -0
- package/dist/daemon/account-page.d.ts +14 -0
- package/dist/daemon/account-page.js +104 -0
- package/dist/daemon/address.d.ts +10 -0
- package/dist/daemon/address.js +34 -0
- package/dist/daemon/away.d.ts +31 -0
- package/dist/daemon/away.js +65 -0
- package/dist/daemon/channel-store.d.ts +112 -0
- package/dist/daemon/channel-store.js +284 -0
- package/dist/daemon/channels.d.ts +46 -0
- package/dist/daemon/channels.js +1049 -0
- package/dist/daemon/contacts.d.ts +26 -0
- package/dist/daemon/contacts.js +74 -0
- package/dist/daemon/engine.d.ts +80 -0
- package/dist/daemon/engine.js +2882 -0
- package/dist/daemon/errors.d.ts +5 -0
- package/dist/daemon/errors.js +16 -0
- package/dist/daemon/governance.d.ts +66 -0
- package/dist/daemon/governance.js +514 -0
- package/dist/daemon/guards.d.ts +36 -0
- package/dist/daemon/guards.js +140 -0
- package/dist/daemon/issuer-client.d.ts +56 -0
- package/dist/daemon/issuer-client.js +143 -0
- package/dist/daemon/link.d.ts +30 -0
- package/dist/daemon/link.js +191 -0
- package/dist/daemon/log.d.ts +1 -0
- package/dist/daemon/log.js +4 -0
- package/dist/daemon/main.d.ts +1 -0
- package/dist/daemon/main.js +511 -0
- package/dist/daemon/paths.d.ts +6 -0
- package/dist/daemon/paths.js +21 -0
- package/dist/daemon/pii.d.ts +24 -0
- package/dist/daemon/pii.js +146 -0
- package/dist/daemon/policy-cadence.d.ts +33 -0
- package/dist/daemon/policy-cadence.js +59 -0
- package/dist/daemon/policy-proposals.d.ts +41 -0
- package/dist/daemon/policy-proposals.js +83 -0
- package/dist/daemon/policy-store.d.ts +47 -0
- package/dist/daemon/policy-store.js +144 -0
- package/dist/daemon/presented.d.ts +36 -0
- package/dist/daemon/presented.js +94 -0
- package/dist/daemon/rate-limit.d.ts +17 -0
- package/dist/daemon/rate-limit.js +44 -0
- package/dist/daemon/reach.d.ts +63 -0
- package/dist/daemon/reach.js +207 -0
- package/dist/daemon/screening.d.ts +97 -0
- package/dist/daemon/screening.js +362 -0
- package/dist/daemon/settings.d.ts +125 -0
- package/dist/daemon/settings.js +73 -0
- package/dist/daemon/signal-rules.d.ts +55 -0
- package/dist/daemon/signal-rules.js +127 -0
- package/dist/daemon/signal-store.d.ts +53 -0
- package/dist/daemon/signal-store.js +114 -0
- package/dist/daemon/store.d.ts +188 -0
- package/dist/daemon/store.js +474 -0
- package/dist/daemon/tiers.d.ts +14 -0
- package/dist/daemon/tiers.js +9 -0
- package/dist/daemon/wallet.d.ts +73 -0
- package/dist/daemon/wallet.js +428 -0
- package/dist/daemon/who-label.d.ts +3 -0
- package/dist/daemon/who-label.js +11 -0
- package/dist/guidance.d.ts +39 -0
- package/dist/guidance.js +98 -0
- package/dist/hermes-bridge.d.ts +26 -0
- package/dist/hermes-bridge.js +180 -0
- package/dist/install-mcp.d.ts +6 -0
- package/dist/install-mcp.js +77 -0
- package/dist/ipc/client.d.ts +18 -0
- package/dist/ipc/client.js +107 -0
- package/dist/ipc/operations.d.ts +30 -0
- package/dist/ipc/operations.js +835 -0
- package/dist/ipc/protocol.d.ts +21 -0
- package/dist/ipc/protocol.js +1 -0
- package/dist/issuer-list-sign.d.ts +12 -0
- package/dist/issuer-list-sign.js +43 -0
- package/dist/local-operations.d.ts +2 -0
- package/dist/local-operations.js +73 -0
- package/dist/mcp-tools.d.ts +14 -0
- package/dist/mcp-tools.js +45 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +155 -0
- package/dist/protocol/aead.d.ts +4 -0
- package/dist/protocol/aead.js +35 -0
- package/dist/protocol/cbor.d.ts +40 -0
- package/dist/protocol/cbor.js +106 -0
- package/dist/protocol/chain.d.ts +44 -0
- package/dist/protocol/chain.js +126 -0
- package/dist/protocol/channel.d.ts +153 -0
- package/dist/protocol/channel.js +298 -0
- package/dist/protocol/encode.d.ts +6 -0
- package/dist/protocol/encode.js +21 -0
- package/dist/protocol/identity.d.ts +27 -0
- package/dist/protocol/identity.js +94 -0
- package/dist/protocol/issuer-list.d.ts +56 -0
- package/dist/protocol/issuer-list.js +193 -0
- package/dist/protocol/issuer-roots.d.ts +6 -0
- package/dist/protocol/issuer-roots.js +10 -0
- package/dist/protocol/key-agreement.d.ts +20 -0
- package/dist/protocol/key-agreement.js +88 -0
- package/dist/protocol/merkle.d.ts +16 -0
- package/dist/protocol/merkle.js +166 -0
- package/dist/protocol/ml-dsa.d.ts +28 -0
- package/dist/protocol/ml-dsa.js +58 -0
- package/dist/protocol/ml-kem.d.ts +14 -0
- package/dist/protocol/ml-kem.js +57 -0
- package/dist/protocol/pq-errors.d.ts +9 -0
- package/dist/protocol/pq-errors.js +23 -0
- package/dist/protocol/pq-warnings.d.ts +1 -0
- package/dist/protocol/pq-warnings.js +18 -0
- package/dist/protocol/presented-signals.d.ts +17 -0
- package/dist/protocol/presented-signals.js +92 -0
- package/dist/protocol/salt.d.ts +5 -0
- package/dist/protocol/salt.js +47 -0
- package/dist/protocol/seal.d.ts +58 -0
- package/dist/protocol/seal.js +220 -0
- package/dist/protocol/signal.d.ts +54 -0
- package/dist/protocol/signal.js +266 -0
- package/dist/protocol/status.d.ts +41 -0
- package/dist/protocol/status.js +64 -0
- package/dist/protocol/structures.d.ts +359 -0
- package/dist/protocol/structures.js +296 -0
- package/dist/protocol/transcript.d.ts +61 -0
- package/dist/protocol/transcript.js +319 -0
- package/dist/protocol/wire.d.ts +212 -0
- package/dist/protocol/wire.js +161 -0
- package/dist/require-node.d.ts +1 -0
- package/dist/require-node.js +10 -0
- package/dist/screener/affordance.d.ts +1 -0
- package/dist/screener/affordance.js +2 -0
- package/dist/screener/classifier-selfcheck.d.ts +29 -0
- package/dist/screener/classifier-selfcheck.js +56 -0
- package/dist/screener/exfil.d.ts +11 -0
- package/dist/screener/exfil.js +45 -0
- package/dist/screener/gitleaks-rules.d.ts +9 -0
- package/dist/screener/gitleaks-rules.js +226 -0
- package/dist/screener/inbound.d.ts +25 -0
- package/dist/screener/inbound.js +102 -0
- package/dist/screener/injection-classifier-onnx.d.ts +20 -0
- package/dist/screener/injection-classifier-onnx.js +89 -0
- package/dist/screener/injection-classifier-wasm.d.ts +2 -0
- package/dist/screener/injection-classifier-wasm.js +97 -0
- package/dist/screener/injection-patterns.d.ts +8 -0
- package/dist/screener/injection-patterns.js +48 -0
- package/dist/screener/injection-windows.d.ts +9 -0
- package/dist/screener/injection-windows.js +37 -0
- package/dist/screener/language.d.ts +15 -0
- package/dist/screener/language.js +71 -0
- package/dist/screener/linear-regex.d.ts +8 -0
- package/dist/screener/linear-regex.js +27 -0
- package/dist/screener/model-installer.d.ts +14 -0
- package/dist/screener/model-installer.js +61 -0
- package/dist/screener/outbound.d.ts +19 -0
- package/dist/screener/outbound.js +62 -0
- package/dist/screener/sanitize.d.ts +44 -0
- package/dist/screener/sanitize.js +361 -0
- package/dist/screener/scan-variants.d.ts +5 -0
- package/dist/screener/scan-variants.js +146 -0
- package/dist/screener/screener-model-manifest.d.ts +16 -0
- package/dist/screener/screener-model-manifest.js +20 -0
- package/dist/screener/screener-state.d.ts +29 -0
- package/dist/screener/screener-state.js +119 -0
- package/dist/screener/secrets.d.ts +18 -0
- package/dist/screener/secrets.js +84 -0
- package/dist/screener/worker.d.ts +6 -0
- package/dist/screener/worker.js +83 -0
- package/dist/setup.d.ts +9 -0
- package/dist/setup.js +252 -0
- package/dist/shipped-issuer-list.d.ts +1 -0
- package/dist/shipped-issuer-list.js +3 -0
- package/dist/signals-text.d.ts +46 -0
- package/dist/signals-text.js +81 -0
- package/dist/verify-seal.d.ts +9 -0
- package/dist/verify-seal.js +30 -0
- package/hermes/plugin/__init__.py +1040 -0
- package/hermes/plugin/plugin.yaml +30 -0
- package/hermes/skills/cello-bridge-setup/SKILL.md +38 -0
- package/hermes/skills/cello-policy/SKILL.md +44 -0
- package/package.json +48 -16
- package/plugins/cello/.claude-plugin/plugin.json +19 -0
- package/plugins/cello/.mcp.json +7 -0
- package/plugins/cello/skills/cello/SKILL.md +117 -0
- package/dist/arg-parse.d.ts +0 -19
- package/dist/arg-parse.d.ts.map +0 -1
- package/dist/arg-parse.js +0 -29
- package/dist/arg-parse.js.map +0 -1
- package/dist/bin/cello.d.ts +0 -15
- package/dist/bin/cello.d.ts.map +0 -1
- package/dist/bin/cello.js +0 -110
- package/dist/bin/cello.js.map +0 -1
- package/dist/cli-args.d.ts +0 -62
- package/dist/cli-args.d.ts.map +0 -1
- package/dist/cli-args.js +0 -129
- package/dist/cli-args.js.map +0 -1
- package/dist/commands.d.ts +0 -196
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -1544
- package/dist/commands.js.map +0 -1
- package/dist/hermes/assets.d.ts +0 -41
- package/dist/hermes/assets.d.ts.map +0 -1
- package/dist/hermes/assets.js +0 -2281
- package/dist/hermes/assets.js.map +0 -1
- package/dist/hermes/install-hermes.d.ts +0 -50
- package/dist/hermes/install-hermes.d.ts.map +0 -1
- package/dist/hermes/install-hermes.js +0 -232
- package/dist/hermes/install-hermes.js.map +0 -1
- package/dist/json-out.d.ts +0 -41
- package/dist/json-out.d.ts.map +0 -1
- package/dist/json-out.js +0 -59
- package/dist/json-out.js.map +0 -1
- package/dist/node-runtime-guard-init.d.ts +0 -6
- package/dist/node-runtime-guard-init.d.ts.map +0 -1
- package/dist/node-runtime-guard-init.js +0 -7
- package/dist/node-runtime-guard-init.js.map +0 -1
- package/dist/node-runtime-guard.d.ts +0 -48
- package/dist/node-runtime-guard.d.ts.map +0 -1
- package/dist/node-runtime-guard.js +0 -79
- package/dist/node-runtime-guard.js.map +0 -1
- package/dist/parity-commands.d.ts +0 -427
- package/dist/parity-commands.d.ts.map +0 -1
- package/dist/parity-commands.js +0 -953
- package/dist/parity-commands.js.map +0 -1
- package/dist/registry.d.ts +0 -120
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -2169
- package/dist/registry.js.map +0 -1
- package/dist/screener-commands.d.ts +0 -85
- package/dist/screener-commands.d.ts.map +0 -1
- package/dist/screener-commands.js +0 -313
- package/dist/screener-commands.js.map +0 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// cello bridge: wires this machine's daemon into a Hermes home, through Hermes' own commands. A person runs it at a terminal.
|
|
2
|
+
// It's safe to run again, and it has to be after an upgrade, because Hermes keeps a copy of the plugin.
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { accessSync, constants, copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { extname, join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { celloHome, logPath } from "./daemon/paths.js";
|
|
9
|
+
// Both doors to an agent use this name. A hold is per agent, so a whole machine can share it.
|
|
10
|
+
export const BRIDGE_CALLER = "hermes";
|
|
11
|
+
export const SESSION_SCOPES = ["agent", "peer"];
|
|
12
|
+
const CHANNEL_NOTIFICATIONS = ["on", "off"];
|
|
13
|
+
const SAFE_SESSION_ID = /^[A-Za-z0-9+/=_.:@-]{1,120}$/;
|
|
14
|
+
// All a public agent's model can reach. It talks to strangers, so it can't change settings or make agents.
|
|
15
|
+
export const PUBLIC_TOOLS = ["cello_receive", "cello_send", "cello_sessions", "cello_inbox", "cello_close_session", "cello_contacts", "cello_channel_read", "cello_channels", "cello_status"];
|
|
16
|
+
const SKILLS = ["cello-bridge-setup", "cello-policy"];
|
|
17
|
+
// What v1's install wrote, which this one no longer reads.
|
|
18
|
+
const RETIRED_ENV = ["CELLO_DELIVERY_MODE", "CELLO_DIR"];
|
|
19
|
+
const runHermes = (command, args, hermesHome) => new Promise((resolve, reject) => {
|
|
20
|
+
const child = spawn(command, args, { stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, HERMES_HOME: hermesHome } });
|
|
21
|
+
// hermes mcp add asks to overwrite on a re-run, then asks about its tools. A closed stdin reads as "Cancelled." with exit 0.
|
|
22
|
+
child.stdin.end("Y\nY\nY\n");
|
|
23
|
+
let stdout = "";
|
|
24
|
+
let stderr = "";
|
|
25
|
+
child.stdout.on("data", (d) => { stdout += d.toString(); });
|
|
26
|
+
child.stderr.on("data", (d) => { stderr += d.toString(); });
|
|
27
|
+
child.on("error", reject);
|
|
28
|
+
child.on("close", (code) => { resolve({ code: code ?? 1, stdout, stderr }); });
|
|
29
|
+
});
|
|
30
|
+
// This file is one folder below hermes/ whether it's running from src or dist.
|
|
31
|
+
const assetDir = () => fileURLToPath(new URL("../hermes/", import.meta.url));
|
|
32
|
+
const mcpEntry = () => fileURLToPath(new URL(`./mcp${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
33
|
+
const daemonEntry = () => fileURLToPath(new URL(`./daemon/main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
34
|
+
function withEnv(existing, set, drop) {
|
|
35
|
+
const keyOf = (line) => line.split("=", 1)[0];
|
|
36
|
+
const lines = existing.split("\n").filter((line) => !drop.includes(keyOf(line)));
|
|
37
|
+
while (lines.at(-1) === "")
|
|
38
|
+
lines.pop();
|
|
39
|
+
for (const [key, value] of Object.entries(set)) {
|
|
40
|
+
const at = lines.findIndex((line) => keyOf(line) === key);
|
|
41
|
+
if (at >= 0)
|
|
42
|
+
lines[at] = `${key}=${value}`;
|
|
43
|
+
else
|
|
44
|
+
lines.push(`${key}=${value}`);
|
|
45
|
+
}
|
|
46
|
+
return `${lines.join("\n")}\n`;
|
|
47
|
+
}
|
|
48
|
+
export async function installBridge(options) {
|
|
49
|
+
const refuse = (output) => ({ ok: false, output });
|
|
50
|
+
const agent = options.agent.trim();
|
|
51
|
+
if (!/^[^\s=]+$/.test(agent))
|
|
52
|
+
return refuse(`'${agent}' can't be an agent's name here.`);
|
|
53
|
+
const hermesHome = options.hermesHome || process.env["HERMES_HOME"] || join(homedir(), ".hermes");
|
|
54
|
+
if (!existsSync(hermesHome))
|
|
55
|
+
return refuse(`There's no Hermes home at ${hermesHome}. Install Hermes first, or pass --hermes-home.`);
|
|
56
|
+
const envPath = join(hermesHome, ".env");
|
|
57
|
+
const hermesEnv = existsSync(envPath) ? readFileSync(envPath, "utf8") : "";
|
|
58
|
+
// This has to be re-run after every upgrade, and forgetting a flag then mustn't open a public agent to strangers. Only --not-public ends it.
|
|
59
|
+
const wasPublic = hermesEnv.split("\n").includes("CELLO_PUBLIC=1");
|
|
60
|
+
if (options.public && options.notPublic)
|
|
61
|
+
return refuse("--public and --not-public can't go together.");
|
|
62
|
+
const isPublic = options.public || (wasPublic && !options.notPublic);
|
|
63
|
+
const allowInitiate = options.allowInitiate || (isPublic && !options.notPublic && hermesEnv.split("\n").includes("CELLO_ALLOW_INITIATE=1"));
|
|
64
|
+
const scope = options.sessionScope ?? (isPublic ? "peer" : "agent");
|
|
65
|
+
if (!SESSION_SCOPES.includes(scope))
|
|
66
|
+
return refuse(`--session-scope must be one of ${SESSION_SCOPES.join(", ")}, not '${scope}'.`);
|
|
67
|
+
if (isPublic && scope !== "peer")
|
|
68
|
+
return refuse("A public agent needs --session-scope peer, or callers would share one conversation.");
|
|
69
|
+
const channels = options.channelNotifications ?? "on";
|
|
70
|
+
if (!CHANNEL_NOTIFICATIONS.includes(channels))
|
|
71
|
+
return refuse(`--channel-notifications must be one of ${CHANNEL_NOTIFICATIONS.join(", ")}, not '${channels}'.`);
|
|
72
|
+
if (options.allowInitiate && !isPublic)
|
|
73
|
+
return refuse("--allow-initiate only means something with --public.");
|
|
74
|
+
const landing = options.landingSession?.trim();
|
|
75
|
+
if (landing && !SAFE_SESSION_ID.test(landing))
|
|
76
|
+
return refuse(`--landing-session '${landing}' isn't a session id.`);
|
|
77
|
+
// Strangers' text goes straight to this agent's model, so a public agent doesn't start on the rules alone.
|
|
78
|
+
if (isPublic && !await options.modelReady())
|
|
79
|
+
return refuse("Nothing was changed. A public agent needs the screening model, and it isn't installed here. Run: cello screener install");
|
|
80
|
+
const tools = isPublic ? [...PUBLIC_TOOLS, ...(allowInitiate ? ["cello_initiate_session"] : [])] : undefined;
|
|
81
|
+
const settings = {
|
|
82
|
+
...(isPublic ? { CELLO_PUBLIC: "1" } : {}),
|
|
83
|
+
...(allowInitiate ? { CELLO_ALLOW_INITIATE: "1" } : {}),
|
|
84
|
+
...(tools ? { CELLO_TOOLS: tools.join(",") } : {}),
|
|
85
|
+
CELLO_AGENT_NAME: agent,
|
|
86
|
+
CELLO_CALLER: BRIDGE_CALLER,
|
|
87
|
+
CELLO_SESSION_SCOPE: scope,
|
|
88
|
+
CELLO_CHANNEL_NOTIFICATIONS: channels,
|
|
89
|
+
...(process.env["CELLO_HOME"] ? { CELLO_HOME: celloHome() } : {}),
|
|
90
|
+
...(landing ? { CELLO_LANDING_SESSION: landing } : {}),
|
|
91
|
+
};
|
|
92
|
+
const wanted = withEnv(hermesEnv, settings, [...RETIRED_ENV, ...(landing ? [] : ["CELLO_LANDING_SESSION"]), ...(isPublic ? [] : ["CELLO_PUBLIC", "CELLO_TOOLS"]), ...(allowInitiate ? [] : ["CELLO_ALLOW_INITIATE"])]);
|
|
93
|
+
const envNeedsWriting = wanted !== hermesEnv;
|
|
94
|
+
if (envNeedsWriting) {
|
|
95
|
+
// Checked before anything is written. A hardened host keeps this file read-only, and half an install looks like a failed one.
|
|
96
|
+
try {
|
|
97
|
+
accessSync(existsSync(envPath) ? envPath : hermesHome, constants.W_OK);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return refuse(`Nothing was changed. ${envPath} is read-only, and it needs these lines:\n${Object.entries(settings).map(([k, v]) => ` ${k}=${v}`).join("\n")}\nUnlock it, run this again, then lock it.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const out = [];
|
|
104
|
+
const pluginDir = join(hermesHome, "plugins", "cello");
|
|
105
|
+
mkdirSync(pluginDir, { recursive: true });
|
|
106
|
+
for (const file of ["plugin.yaml", "__init__.py"])
|
|
107
|
+
copyFileSync(join(assetDir(), "plugin", file), join(pluginDir, file));
|
|
108
|
+
out.push(`Plugin: ${pluginDir}`);
|
|
109
|
+
for (const skill of SKILLS) {
|
|
110
|
+
const dir = join(hermesHome, "skills", skill);
|
|
111
|
+
mkdirSync(dir, { recursive: true });
|
|
112
|
+
copyFileSync(join(assetDir(), "skills", skill, "SKILL.md"), join(dir, "SKILL.md"));
|
|
113
|
+
out.push(`Skill: ${dir}`);
|
|
114
|
+
}
|
|
115
|
+
if (envNeedsWriting)
|
|
116
|
+
writeFileSync(envPath, wanted, { mode: 0o600 });
|
|
117
|
+
out.push(`Agent: ${agent}, scope ${scope}, caller ${BRIDGE_CALLER}${landing ? `, landing session ${landing}` : ""}`);
|
|
118
|
+
const landingFile = join(hermesHome, "cello", "landing-session.json");
|
|
119
|
+
if (landing) {
|
|
120
|
+
mkdirSync(join(hermesHome, "cello"), { recursive: true });
|
|
121
|
+
writeFileSync(landingFile, `${JSON.stringify({ session_id: landing })}\n`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
rmSync(landingFile, { force: true });
|
|
125
|
+
}
|
|
126
|
+
// By full path, so a gateway started by a service manager with a short PATH still finds it.
|
|
127
|
+
// The limit is enforced by the tool process itself. 'hermes config set' can only write a string, which Hermes would read as one tool's name.
|
|
128
|
+
const mcpEnv = [`CELLO_CALLER=${BRIDGE_CALLER}`, ...(process.env["CELLO_HOME"] ? [`CELLO_HOME=${celloHome()}`] : []), ...(tools ? [`CELLO_TOOLS=${tools.join(",")}`] : [])];
|
|
129
|
+
const mcpAdd = ["mcp", "add", "cello", "--env", ...mcpEnv, "--command", process.execPath, "--args", mcpEntry()];
|
|
130
|
+
// The tools first: an enabled plugin with no tools reads messages and can never answer them.
|
|
131
|
+
const steps = [mcpAdd, ["plugins", "enable", "cello"]];
|
|
132
|
+
const byHand = steps.map((step) => ` hermes ${step.join(" ")}`).join("\n");
|
|
133
|
+
const hermes = (args) => (options.exec ?? runHermes)("hermes", args, hermesHome);
|
|
134
|
+
for (const step of steps) {
|
|
135
|
+
let result;
|
|
136
|
+
try {
|
|
137
|
+
result = await hermes(step);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return refuse(`${out.join("\n")}\n\nThe files are in place, but the 'hermes' command couldn't run (${err instanceof Error ? err.message : String(err)}). Run these by hand, then restart the gateway:\n${byHand}`);
|
|
141
|
+
}
|
|
142
|
+
if (result.code !== 0)
|
|
143
|
+
return refuse(`${out.join("\n")}\n\n'hermes ${step.join(" ")}' failed (exit ${result.code}):\n${(result.stderr || result.stdout).trim()}\nFix that and run this again.`);
|
|
144
|
+
out.push(`Ran: hermes ${step.slice(0, 3).join(" ")}`);
|
|
145
|
+
if (step === mcpAdd) {
|
|
146
|
+
// hermes mcp add can say "Cancelled." and still exit 0.
|
|
147
|
+
const listed = await hermes(["mcp", "list"]);
|
|
148
|
+
if (!listed.stdout.includes("cello"))
|
|
149
|
+
return refuse(`${out.join("\n")}\n\n'hermes mcp add' reported success, but 'hermes mcp list' has no cello server. Run this by hand and answer Y, then run this command again:\n hermes ${mcpAdd.join(" ")}`);
|
|
150
|
+
out.push("Checked: cello is in hermes mcp list");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (tools)
|
|
154
|
+
out.push(`Tools the model can reach: ${tools.join(", ")}`);
|
|
155
|
+
out.push("", "Now restart the gateway, so Hermes loads the plugin: hermes gateway restart", "The daemon must stay up by itself on a server: cello bridge daemon-unit");
|
|
156
|
+
return { ok: true, output: out.join("\n") };
|
|
157
|
+
}
|
|
158
|
+
// A systemd user unit that runs the daemon in the foreground. Not 'cello login', which starts it and exits, so a plain unit would call that a failure.
|
|
159
|
+
export function daemonUnit() {
|
|
160
|
+
return `# ~/.config/systemd/user/cello-daemon.service
|
|
161
|
+
# Then: systemctl --user daemon-reload && systemctl --user enable --now cello-daemon
|
|
162
|
+
# And once, so it starts at boot with nobody logged in: loginctl enable-linger $USER
|
|
163
|
+
# Run 'cello login --server <url>' once first, then 'cello logout', because the server's address lives in the database.
|
|
164
|
+
[Unit]
|
|
165
|
+
Description=CELLO daemon
|
|
166
|
+
After=network-online.target
|
|
167
|
+
Wants=network-online.target
|
|
168
|
+
|
|
169
|
+
[Service]
|
|
170
|
+
ExecStart=${process.execPath} ${daemonEntry()}
|
|
171
|
+
Environment=CELLO_HOME=${celloHome()}
|
|
172
|
+
Restart=always
|
|
173
|
+
RestartSec=2
|
|
174
|
+
StandardOutput=append:${logPath()}
|
|
175
|
+
StandardError=append:${logPath()}
|
|
176
|
+
|
|
177
|
+
[Install]
|
|
178
|
+
WantedBy=default.target
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// cello setup --install-mcp: connects the apps on this machine, and says exactly what it changed. Nothing here leaves the machine.
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, extname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
const CLAUDE_WAIT_MS = 120_000;
|
|
8
|
+
function writeAtomically(path, text) {
|
|
9
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
10
|
+
writeFileSync(`${path}.cello-tmp`, text, { mode: 0o600 });
|
|
11
|
+
renameSync(`${path}.cello-tmp`, path);
|
|
12
|
+
}
|
|
13
|
+
function claudeCode(packageRoot) {
|
|
14
|
+
const app = "Claude Code";
|
|
15
|
+
const onPath = spawnSync("sh", ["-c", "command -v claude"], { encoding: "utf8" }).stdout.trim();
|
|
16
|
+
if (!onPath)
|
|
17
|
+
return { app, outcome: "not_found", detail: "no claude command on this PATH" };
|
|
18
|
+
const claude = (args) => {
|
|
19
|
+
const run = spawnSync(onPath, args, { encoding: "utf8", timeout: CLAUDE_WAIT_MS });
|
|
20
|
+
return { ok: run.status === 0, said: `${run.stdout ?? ""}${run.stderr ?? ""}`.trim() };
|
|
21
|
+
};
|
|
22
|
+
const listed = claude(["plugin", "list"]);
|
|
23
|
+
if (listed.ok && /cello@cello-protocol/.test(listed.said))
|
|
24
|
+
return { app, outcome: "unchanged", detail: "the plugin cello@cello-protocol is already installed. If it came from the old version, remove it with: claude plugin uninstall cello@cello-protocol" };
|
|
25
|
+
const market = claude(["plugin", "marketplace", "add", packageRoot]);
|
|
26
|
+
if (!market.ok)
|
|
27
|
+
return { app, outcome: "failed", detail: `adding the marketplace failed: ${market.said}` };
|
|
28
|
+
const plugin = claude(["plugin", "install", "cello@cello-protocol"]);
|
|
29
|
+
if (!plugin.ok)
|
|
30
|
+
return { app, outcome: "failed", detail: `installing the plugin failed: ${plugin.said}` };
|
|
31
|
+
return { app, outcome: "installed", detail: `added the plugin cello@cello-protocol, from ${packageRoot}. To be woken by messages, start it with: claude --dangerously-load-development-channels plugin:cello@cello-protocol` };
|
|
32
|
+
}
|
|
33
|
+
function claudeDesktop(home, command, args) {
|
|
34
|
+
const app = "Claude Desktop";
|
|
35
|
+
const folder = process.platform === "darwin" ? join(home, "Library", "Application Support", "Claude") : join(home, ".config", "Claude");
|
|
36
|
+
if (!existsSync(folder))
|
|
37
|
+
return { app, outcome: "not_found", detail: `no ${folder}` };
|
|
38
|
+
const path = join(folder, "claude_desktop_config.json");
|
|
39
|
+
let config = {};
|
|
40
|
+
if (existsSync(path)) {
|
|
41
|
+
try {
|
|
42
|
+
config = JSON.parse(readFileSync(path, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return { app, outcome: "failed", detail: `${path} isn't valid JSON, so it was left alone` };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const entry = { command, args };
|
|
49
|
+
const before = config.mcpServers?.["cello"];
|
|
50
|
+
if (JSON.stringify(before) === JSON.stringify(entry))
|
|
51
|
+
return { app, outcome: "unchanged", detail: `${path} already has it` };
|
|
52
|
+
writeAtomically(path, `${JSON.stringify({ ...config, mcpServers: { ...config.mcpServers, cello: entry } }, null, 2)}\n`);
|
|
53
|
+
return { app, outcome: "installed", detail: `${before ? "replaced" : "added"} the cello server in ${path}${before ? `, which was ${JSON.stringify(before)}` : ""}. Restart the app. Messages wait for your next turn there, because nothing wakes it.` };
|
|
54
|
+
}
|
|
55
|
+
const toml = (value) => JSON.stringify(value);
|
|
56
|
+
function chatGptDesktop(home, command, args) {
|
|
57
|
+
const app = "ChatGPT Desktop";
|
|
58
|
+
const folder = join(home, ".codex");
|
|
59
|
+
if (!existsSync(folder) && !existsSync(join(home, "Library", "Application Support", "com.openai.chat")))
|
|
60
|
+
return { app, outcome: "not_found", detail: "neither ~/.codex nor its app folder is here" };
|
|
61
|
+
const path = join(folder, "config.toml");
|
|
62
|
+
const held = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
63
|
+
const block = `[mcp_servers.cello]\ncommand = ${toml(command)}\nargs = [${args.map(toml).join(", ")}]\n`;
|
|
64
|
+
if (held.includes(block))
|
|
65
|
+
return { app, outcome: "unchanged", detail: `${path} already has it` };
|
|
66
|
+
if (/^\[mcp_servers\.cello\]/m.test(held))
|
|
67
|
+
return { app, outcome: "failed", detail: `${path} already has a different [mcp_servers.cello], so it was left alone. Remove that section, then run this again.` };
|
|
68
|
+
writeAtomically(path, `${held}${held === "" || held.endsWith("\n") ? "" : "\n"}\n${block}`);
|
|
69
|
+
return { app, outcome: "installed", detail: `added [mcp_servers.cello] to ${path}. Restart the app. Messages wait for your next turn there, because nothing wakes it.` };
|
|
70
|
+
}
|
|
71
|
+
export function installMcp(home = homedir()) {
|
|
72
|
+
const here = fileURLToPath(import.meta.url);
|
|
73
|
+
const packageRoot = join(dirname(here), "..");
|
|
74
|
+
// By full path: a desktop app doesn't start with the shell's PATH, so it wouldn't find node or cello-mcp.
|
|
75
|
+
const args = [join(dirname(here), `mcp${extname(here)}`)];
|
|
76
|
+
return [claudeCode(packageRoot), claudeDesktop(home, process.execPath, args), chatGptDesktop(home, process.execPath, args)];
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IpcNotification } from "./protocol.ts";
|
|
2
|
+
export declare class DaemonRefused extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class DaemonGone extends Error {
|
|
7
|
+
readonly code = "daemon_not_running";
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
export declare class IpcClient {
|
|
11
|
+
#private;
|
|
12
|
+
onNotification: (frame: IpcNotification) => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
private constructor();
|
|
15
|
+
static connect(path: string): Promise<IpcClient>;
|
|
16
|
+
call(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<unknown>;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createConnection } from "node:net";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
3
|
+
export class DaemonRefused extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "DaemonRefused";
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class DaemonGone extends Error {
|
|
12
|
+
code = "daemon_not_running";
|
|
13
|
+
constructor() {
|
|
14
|
+
super("the daemon isn't running. Run: cello login");
|
|
15
|
+
this.name = "DaemonGone";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// A wedged daemon mustn't hang a tool forever. It outlasts every wait the daemon has of its own.
|
|
19
|
+
const CALL_TIMEOUT_MS = 90_000;
|
|
20
|
+
// The daemon may have saved a call before it stopped, so what a caller should do next depends on the call.
|
|
21
|
+
function afterCutOff(method) {
|
|
22
|
+
switch (method) {
|
|
23
|
+
case "send":
|
|
24
|
+
return "The message may still go out by itself after the next login: check the transcript before sending it again.";
|
|
25
|
+
case "close_session":
|
|
26
|
+
return "The close may still go out by itself after the next login: check sessions before closing again.";
|
|
27
|
+
case "initiate_session":
|
|
28
|
+
return "A session may have started: check sessions after the next login before starting another.";
|
|
29
|
+
case "create_agent":
|
|
30
|
+
return "The agent may have been created: check agents after the next login before creating it again.";
|
|
31
|
+
case "receive":
|
|
32
|
+
return "Whatever you didn't get still counts as unread, so call receive again after the next login.";
|
|
33
|
+
default:
|
|
34
|
+
return "Its outcome is unknown: check after the next login before repeating it.";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class IpcClient {
|
|
38
|
+
#socket;
|
|
39
|
+
#waiting = new Map();
|
|
40
|
+
#nextId = 1;
|
|
41
|
+
onNotification = () => undefined;
|
|
42
|
+
onClose = () => undefined;
|
|
43
|
+
constructor(socket) {
|
|
44
|
+
this.#socket = socket;
|
|
45
|
+
createInterface({ input: socket }).on("line", (line) => {
|
|
46
|
+
let frame;
|
|
47
|
+
try {
|
|
48
|
+
frame = JSON.parse(line);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// A daemon killed part way through a line. This is the call being cut off, so the close below reports it.
|
|
52
|
+
socket.destroy();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if ("notification" in frame) {
|
|
56
|
+
this.onNotification(frame);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const waiter = this.#waiting.get(frame.id);
|
|
60
|
+
this.#waiting.delete(frame.id);
|
|
61
|
+
if (frame.ok)
|
|
62
|
+
waiter?.resolve(frame.result);
|
|
63
|
+
else
|
|
64
|
+
waiter?.reject(new DaemonRefused(frame.error.code, frame.error.message));
|
|
65
|
+
});
|
|
66
|
+
socket.on("close", () => {
|
|
67
|
+
for (const waiter of this.#waiting.values())
|
|
68
|
+
waiter.reject(new DaemonRefused("daemon_stopped_during_call", `the daemon stopped during this call. ${afterCutOff(waiter.method)}`));
|
|
69
|
+
this.#waiting.clear();
|
|
70
|
+
this.onClose();
|
|
71
|
+
});
|
|
72
|
+
socket.on("error", () => undefined);
|
|
73
|
+
}
|
|
74
|
+
static connect(path) {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const socket = createConnection(path);
|
|
77
|
+
socket.once("connect", () => {
|
|
78
|
+
socket.removeAllListeners("error");
|
|
79
|
+
resolve(new IpcClient(socket));
|
|
80
|
+
});
|
|
81
|
+
socket.once("error", () => reject(new DaemonGone()));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
call(method, params = {}, timeoutMs = CALL_TIMEOUT_MS) {
|
|
85
|
+
const id = this.#nextId++;
|
|
86
|
+
const request = { id, method, params };
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
if (this.#socket.destroyed) {
|
|
89
|
+
reject(new DaemonGone());
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
this.#waiting.delete(id);
|
|
94
|
+
reject(new DaemonRefused("daemon_no_answer", `the daemon didn't answer ${method} within ${timeoutMs / 1000} seconds, so its outcome is unknown`));
|
|
95
|
+
}, timeoutMs);
|
|
96
|
+
this.#waiting.set(id, {
|
|
97
|
+
method,
|
|
98
|
+
resolve(value) { clearTimeout(timer); resolve(value); },
|
|
99
|
+
reject(err) { clearTimeout(timer); reject(err); },
|
|
100
|
+
});
|
|
101
|
+
this.#socket.write(`${JSON.stringify(request)}\n`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
this.#socket.destroy();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface Param {
|
|
2
|
+
name: string;
|
|
3
|
+
kind: "string" | "number" | "boolean";
|
|
4
|
+
description: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
positional?: boolean;
|
|
7
|
+
allowed?: readonly string[];
|
|
8
|
+
programOnly?: boolean;
|
|
9
|
+
daemonEnforced?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface Definition {
|
|
12
|
+
command: string;
|
|
13
|
+
group: string;
|
|
14
|
+
summary: string;
|
|
15
|
+
description: string;
|
|
16
|
+
scoped: boolean;
|
|
17
|
+
acts: boolean;
|
|
18
|
+
local?: boolean;
|
|
19
|
+
personOnly?: boolean;
|
|
20
|
+
programOnly?: boolean;
|
|
21
|
+
plain?: (result: never) => string;
|
|
22
|
+
params: readonly Param[];
|
|
23
|
+
}
|
|
24
|
+
export interface Operation extends Definition {
|
|
25
|
+
tool: string;
|
|
26
|
+
method: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const OPERATIONS: readonly Operation[];
|
|
29
|
+
export declare const DEFAULT_WAIT_SECONDS = 300;
|
|
30
|
+
export {};
|