@cello-protocol/cli 0.0.306 → 0.0.308

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 (234) hide show
  1. package/.claude-plugin/marketplace.json +15 -0
  2. package/README.md +107 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +602 -0
  5. package/dist/daemon/account-page-assets.d.ts +4 -0
  6. package/dist/daemon/account-page-assets.js +160 -0
  7. package/dist/daemon/account-page.d.ts +14 -0
  8. package/dist/daemon/account-page.js +104 -0
  9. package/dist/daemon/address.d.ts +10 -0
  10. package/dist/daemon/address.js +34 -0
  11. package/dist/daemon/away.d.ts +31 -0
  12. package/dist/daemon/away.js +65 -0
  13. package/dist/daemon/channel-store.d.ts +112 -0
  14. package/dist/daemon/channel-store.js +284 -0
  15. package/dist/daemon/channels.d.ts +46 -0
  16. package/dist/daemon/channels.js +1049 -0
  17. package/dist/daemon/contacts.d.ts +26 -0
  18. package/dist/daemon/contacts.js +74 -0
  19. package/dist/daemon/engine.d.ts +82 -0
  20. package/dist/daemon/engine.js +2882 -0
  21. package/dist/daemon/errors.d.ts +5 -0
  22. package/dist/daemon/errors.js +16 -0
  23. package/dist/daemon/governance.d.ts +66 -0
  24. package/dist/daemon/governance.js +514 -0
  25. package/dist/daemon/guards.d.ts +36 -0
  26. package/dist/daemon/guards.js +140 -0
  27. package/dist/daemon/issuer-client.d.ts +56 -0
  28. package/dist/daemon/issuer-client.js +143 -0
  29. package/dist/daemon/link.d.ts +30 -0
  30. package/dist/daemon/link.js +191 -0
  31. package/dist/daemon/log.d.ts +1 -0
  32. package/dist/daemon/log.js +4 -0
  33. package/dist/daemon/main.d.ts +1 -0
  34. package/dist/daemon/main.js +513 -0
  35. package/dist/daemon/paths.d.ts +6 -0
  36. package/dist/daemon/paths.js +21 -0
  37. package/dist/daemon/pii.d.ts +24 -0
  38. package/dist/daemon/pii.js +147 -0
  39. package/dist/daemon/policy-cadence.d.ts +33 -0
  40. package/dist/daemon/policy-cadence.js +59 -0
  41. package/dist/daemon/policy-proposals.d.ts +41 -0
  42. package/dist/daemon/policy-proposals.js +83 -0
  43. package/dist/daemon/policy-store.d.ts +47 -0
  44. package/dist/daemon/policy-store.js +144 -0
  45. package/dist/daemon/presented.d.ts +36 -0
  46. package/dist/daemon/presented.js +94 -0
  47. package/dist/daemon/rate-limit.d.ts +17 -0
  48. package/dist/daemon/rate-limit.js +44 -0
  49. package/dist/daemon/reach.d.ts +62 -0
  50. package/dist/daemon/reach.js +204 -0
  51. package/dist/daemon/screening.d.ts +97 -0
  52. package/dist/daemon/screening.js +362 -0
  53. package/dist/daemon/settings.d.ts +125 -0
  54. package/dist/daemon/settings.js +73 -0
  55. package/dist/daemon/signal-rules.d.ts +55 -0
  56. package/dist/daemon/signal-rules.js +127 -0
  57. package/dist/daemon/signal-store.d.ts +53 -0
  58. package/dist/daemon/signal-store.js +114 -0
  59. package/dist/daemon/store.d.ts +189 -0
  60. package/dist/daemon/store.js +477 -0
  61. package/dist/daemon/tiers.d.ts +14 -0
  62. package/dist/daemon/tiers.js +9 -0
  63. package/dist/daemon/wallet.d.ts +73 -0
  64. package/dist/daemon/wallet.js +429 -0
  65. package/dist/daemon/who-label.d.ts +3 -0
  66. package/dist/daemon/who-label.js +11 -0
  67. package/dist/guidance.d.ts +39 -0
  68. package/dist/guidance.js +98 -0
  69. package/dist/hermes-bridge.d.ts +34 -0
  70. package/dist/hermes-bridge.js +223 -0
  71. package/dist/install-mcp.d.ts +6 -0
  72. package/dist/install-mcp.js +77 -0
  73. package/dist/ipc/client.d.ts +18 -0
  74. package/dist/ipc/client.js +107 -0
  75. package/dist/ipc/operations.d.ts +30 -0
  76. package/dist/ipc/operations.js +846 -0
  77. package/dist/ipc/protocol.d.ts +21 -0
  78. package/dist/ipc/protocol.js +1 -0
  79. package/dist/issuer-list-sign.d.ts +12 -0
  80. package/dist/issuer-list-sign.js +43 -0
  81. package/dist/local-operations.d.ts +2 -0
  82. package/dist/local-operations.js +73 -0
  83. package/dist/mcp-tools.d.ts +14 -0
  84. package/dist/mcp-tools.js +45 -0
  85. package/dist/mcp.d.ts +2 -0
  86. package/dist/mcp.js +160 -0
  87. package/dist/protocol/aead.d.ts +4 -0
  88. package/dist/protocol/aead.js +35 -0
  89. package/dist/protocol/cbor.d.ts +40 -0
  90. package/dist/protocol/cbor.js +106 -0
  91. package/dist/protocol/chain.d.ts +44 -0
  92. package/dist/protocol/chain.js +126 -0
  93. package/dist/protocol/channel.d.ts +153 -0
  94. package/dist/protocol/channel.js +298 -0
  95. package/dist/protocol/encode.d.ts +6 -0
  96. package/dist/protocol/encode.js +21 -0
  97. package/dist/protocol/identity.d.ts +27 -0
  98. package/dist/protocol/identity.js +94 -0
  99. package/dist/protocol/issuer-list.d.ts +56 -0
  100. package/dist/protocol/issuer-list.js +193 -0
  101. package/dist/protocol/issuer-roots.d.ts +6 -0
  102. package/dist/protocol/issuer-roots.js +10 -0
  103. package/dist/protocol/key-agreement.d.ts +20 -0
  104. package/dist/protocol/key-agreement.js +88 -0
  105. package/dist/protocol/merkle.d.ts +16 -0
  106. package/dist/protocol/merkle.js +166 -0
  107. package/dist/protocol/ml-dsa.d.ts +28 -0
  108. package/dist/protocol/ml-dsa.js +58 -0
  109. package/dist/protocol/ml-kem.d.ts +14 -0
  110. package/dist/protocol/ml-kem.js +57 -0
  111. package/dist/protocol/pq-errors.d.ts +9 -0
  112. package/dist/protocol/pq-errors.js +23 -0
  113. package/dist/protocol/pq-warnings.d.ts +1 -0
  114. package/dist/protocol/pq-warnings.js +18 -0
  115. package/dist/protocol/presented-signals.d.ts +17 -0
  116. package/dist/protocol/presented-signals.js +92 -0
  117. package/dist/protocol/salt.d.ts +5 -0
  118. package/dist/protocol/salt.js +47 -0
  119. package/dist/protocol/seal.d.ts +58 -0
  120. package/dist/protocol/seal.js +220 -0
  121. package/dist/protocol/signal.d.ts +54 -0
  122. package/dist/protocol/signal.js +266 -0
  123. package/dist/protocol/status.d.ts +41 -0
  124. package/dist/protocol/status.js +64 -0
  125. package/dist/protocol/structures.d.ts +359 -0
  126. package/dist/protocol/structures.js +296 -0
  127. package/dist/protocol/transcript.d.ts +61 -0
  128. package/dist/protocol/transcript.js +319 -0
  129. package/dist/protocol/wire.d.ts +212 -0
  130. package/dist/protocol/wire.js +161 -0
  131. package/dist/require-node.d.ts +1 -0
  132. package/dist/require-node.js +10 -0
  133. package/dist/screener/affordance.d.ts +1 -0
  134. package/dist/screener/affordance.js +2 -0
  135. package/dist/screener/classifier-selfcheck.d.ts +29 -0
  136. package/dist/screener/classifier-selfcheck.js +56 -0
  137. package/dist/screener/exfil.d.ts +11 -0
  138. package/dist/screener/exfil.js +45 -0
  139. package/dist/screener/gitleaks-rules.d.ts +9 -0
  140. package/dist/screener/gitleaks-rules.js +226 -0
  141. package/dist/screener/inbound.d.ts +25 -0
  142. package/dist/screener/inbound.js +102 -0
  143. package/dist/screener/injection-classifier-onnx.d.ts +20 -0
  144. package/dist/screener/injection-classifier-onnx.js +89 -0
  145. package/dist/screener/injection-classifier-wasm.d.ts +2 -0
  146. package/dist/screener/injection-classifier-wasm.js +97 -0
  147. package/dist/screener/injection-patterns.d.ts +8 -0
  148. package/dist/screener/injection-patterns.js +48 -0
  149. package/dist/screener/injection-windows.d.ts +9 -0
  150. package/dist/screener/injection-windows.js +37 -0
  151. package/dist/screener/language.d.ts +15 -0
  152. package/dist/screener/language.js +71 -0
  153. package/dist/screener/linear-regex.d.ts +8 -0
  154. package/dist/screener/linear-regex.js +27 -0
  155. package/dist/screener/model-installer.d.ts +14 -0
  156. package/dist/screener/model-installer.js +61 -0
  157. package/dist/screener/outbound.d.ts +19 -0
  158. package/dist/screener/outbound.js +62 -0
  159. package/dist/screener/sanitize.d.ts +44 -0
  160. package/dist/screener/sanitize.js +361 -0
  161. package/dist/screener/scan-variants.d.ts +5 -0
  162. package/dist/screener/scan-variants.js +146 -0
  163. package/dist/screener/screener-model-manifest.d.ts +16 -0
  164. package/dist/screener/screener-model-manifest.js +20 -0
  165. package/dist/screener/screener-state.d.ts +29 -0
  166. package/dist/screener/screener-state.js +119 -0
  167. package/dist/screener/secrets.d.ts +18 -0
  168. package/dist/screener/secrets.js +84 -0
  169. package/dist/screener/worker.d.ts +6 -0
  170. package/dist/screener/worker.js +83 -0
  171. package/dist/setup.d.ts +9 -0
  172. package/dist/setup.js +259 -0
  173. package/dist/shipped-issuer-list.d.ts +1 -0
  174. package/dist/shipped-issuer-list.js +3 -0
  175. package/dist/signals-text.d.ts +46 -0
  176. package/dist/signals-text.js +81 -0
  177. package/dist/verify-seal.d.ts +9 -0
  178. package/dist/verify-seal.js +30 -0
  179. package/hermes/plugin/__init__.py +1066 -0
  180. package/hermes/plugin/plugin.yaml +30 -0
  181. package/hermes/skills/cello-bridge-setup/SKILL.md +48 -0
  182. package/hermes/skills/cello-policy/SKILL.md +44 -0
  183. package/package.json +48 -16
  184. package/plugins/cello/.claude-plugin/plugin.json +19 -0
  185. package/plugins/cello/.mcp.json +7 -0
  186. package/plugins/cello/skills/cello/SKILL.md +117 -0
  187. package/dist/arg-parse.d.ts +0 -19
  188. package/dist/arg-parse.d.ts.map +0 -1
  189. package/dist/arg-parse.js +0 -29
  190. package/dist/arg-parse.js.map +0 -1
  191. package/dist/bin/cello.d.ts +0 -15
  192. package/dist/bin/cello.d.ts.map +0 -1
  193. package/dist/bin/cello.js +0 -110
  194. package/dist/bin/cello.js.map +0 -1
  195. package/dist/cli-args.d.ts +0 -62
  196. package/dist/cli-args.d.ts.map +0 -1
  197. package/dist/cli-args.js +0 -129
  198. package/dist/cli-args.js.map +0 -1
  199. package/dist/commands.d.ts +0 -196
  200. package/dist/commands.d.ts.map +0 -1
  201. package/dist/commands.js +0 -1544
  202. package/dist/commands.js.map +0 -1
  203. package/dist/hermes/assets.d.ts +0 -41
  204. package/dist/hermes/assets.d.ts.map +0 -1
  205. package/dist/hermes/assets.js +0 -2281
  206. package/dist/hermes/assets.js.map +0 -1
  207. package/dist/hermes/install-hermes.d.ts +0 -50
  208. package/dist/hermes/install-hermes.d.ts.map +0 -1
  209. package/dist/hermes/install-hermes.js +0 -232
  210. package/dist/hermes/install-hermes.js.map +0 -1
  211. package/dist/json-out.d.ts +0 -41
  212. package/dist/json-out.d.ts.map +0 -1
  213. package/dist/json-out.js +0 -59
  214. package/dist/json-out.js.map +0 -1
  215. package/dist/node-runtime-guard-init.d.ts +0 -6
  216. package/dist/node-runtime-guard-init.d.ts.map +0 -1
  217. package/dist/node-runtime-guard-init.js +0 -7
  218. package/dist/node-runtime-guard-init.js.map +0 -1
  219. package/dist/node-runtime-guard.d.ts +0 -48
  220. package/dist/node-runtime-guard.d.ts.map +0 -1
  221. package/dist/node-runtime-guard.js +0 -79
  222. package/dist/node-runtime-guard.js.map +0 -1
  223. package/dist/parity-commands.d.ts +0 -427
  224. package/dist/parity-commands.d.ts.map +0 -1
  225. package/dist/parity-commands.js +0 -953
  226. package/dist/parity-commands.js.map +0 -1
  227. package/dist/registry.d.ts +0 -120
  228. package/dist/registry.d.ts.map +0 -1
  229. package/dist/registry.js +0 -2169
  230. package/dist/registry.js.map +0 -1
  231. package/dist/screener-commands.d.ts +0 -85
  232. package/dist/screener-commands.d.ts.map +0 -1
  233. package/dist/screener-commands.js +0 -313
  234. package/dist/screener-commands.js.map +0 -1
package/dist/cli.js ADDED
@@ -0,0 +1,602 @@
1
+ #!/usr/bin/env node
2
+ // Everything an agent or a person can do. Each command is one process and one call, with its identity in the call.
3
+ import "./require-node.js";
4
+ import { spawn, spawnSync } from "node:child_process";
5
+ import { createHash, randomBytes } from "node:crypto";
6
+ import { createInterface as createReadline } from "node:readline";
7
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync, writeSync } from "node:fs";
8
+ import { dirname, extname, join, resolve } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { celloHome, holdsOldVersion, logPath, oldVersionMessage, socketPath } from "./daemon/paths.js";
11
+ import { DaemonGone, DaemonRefused, IpcClient } from "./ipc/client.js";
12
+ import { DEFAULT_WAIT_SECONDS, OPERATIONS } from "./ipc/operations.js";
13
+ import { exportTranscript, runLocal } from "./local-operations.js";
14
+ import { daemonUnit, installBridge, setLanding } from "./hermes-bridge.js";
15
+ import { SETUP_HELP, setup } from "./setup.js";
16
+ import { commandSigner, parseRootName, signIssuerListFile } from "./issuer-list-sign.js";
17
+ import { RootKeysNotConfigured } from "./protocol/issuer-list.js";
18
+ import { productionRootKeys } from "./protocol/issuer-roots.js";
19
+ import { installModel } from "./screener/model-installer.js";
20
+ import { SCREENER_RUNTIME_MODULE, describeScreenerState, runtimeAvailable, screenerModelDir, screenerRuntimeDir, screenerState } from "./screener/screener-state.js";
21
+ const DOWNLOAD_MB = 241;
22
+ const DISK_MB = 618;
23
+ // Each shell session that sets CELLO_CALLER is its own caller, so one can't read another's messages by accident.
24
+ // Any stable string works: it's a label, not a proof. Without it, all of this machine's command lines are one caller.
25
+ const CALLER = process.env["CELLO_CALLER"] || "cli";
26
+ const STATUS_COMMANDS = ["suspend", "retire", "remove-agent", "publish-status"];
27
+ const EXIT_REFUSED = 1;
28
+ const EXIT_USAGE = 2;
29
+ const EXIT_TIMEOUT = 3;
30
+ function flag(name) {
31
+ return `--${name.replaceAll("_", "-")}`;
32
+ }
33
+ // send takes its signal as one flag, which can't be mistyped into a wrong value.
34
+ const SIGNAL_FLAGS = "(--over | --standby <minutes> | --wrap)";
35
+ const isSignalParam = (op, param) => op.command === "send" && (param.name === "signal" || param.name === "est_minutes");
36
+ function usageLine(op) {
37
+ const positional = op.params.filter((p) => p.positional).map((p) => (p.required ? `<${p.name}>` : `[<${p.name}>]`));
38
+ const flags = op.params.filter((p) => !p.positional && !isSignalParam(op, p)).map((p) => {
39
+ const text = p.kind === "boolean" ? flag(p.name) : `${flag(p.name)} <${p.kind}>`;
40
+ return p.required ? text : `[${text}]`;
41
+ });
42
+ const signal = op.command === "send" ? [SIGNAL_FLAGS] : [];
43
+ const scoped = [...(op.scoped ? ["[--agent <name-or-id>]"] : []), ...(op.acts ? ["[--force]"] : []), ...(op.plain ? ["[--json]"] : [])];
44
+ return `cello ${[op.command, ...positional, ...signal, ...flags, ...scoped].join(" ")}`;
45
+ }
46
+ function commandHelp(op) {
47
+ const details = op.params.filter((p) => !isSignalParam(op, p)).map((p) => ` ${(p.positional ? `<${p.name}>` : flag(p.name)).padEnd(20)} ${p.description}`);
48
+ if (op.command === "send") {
49
+ details.push(` ${"--over".padEnd(20)} Your turn is done.`, ` ${"--standby <minutes>".padEnd(20)} You'll follow up in about that many minutes.`, ` ${"--wrap".padEnd(20)} Your final message.`);
50
+ }
51
+ if (op.scoped)
52
+ details.push(` ${"--agent".padEnd(20)} The agent's name or id. Can be left out once chosen with use-agent.`);
53
+ if (op.acts)
54
+ details.push(` ${"--force".padEnd(20)} Take the agent from another caller that holds it.`);
55
+ return `Usage: ${usageLine(op)}\n\n${op.description}\n${details.length > 0 ? `\n${details.join("\n")}\n` : ""}`;
56
+ }
57
+ function overview() {
58
+ const groups = new Map([["Setup", [` ${"setup".padEnd(20)} Set up CELLO on this machine, with the code from your admission email.`, ` ${"login".padEnd(20)} Start the daemon, and connect it to a server.`, ` ${"logout".padEnd(20)} Stop the daemon. Conversations carry on after the next login.`, ` ${"screener".padEnd(20)} Install the optional screening model, or see if it's installed.`, ` ${"bridge".padEnd(20)} Connect a Hermes install to an agent on this machine.`, ` ${"issuer-list-sign".padEnd(20)} Add a root key's signature to the signed issuer list.`]]]);
59
+ for (const op of OPERATIONS) {
60
+ const lines = groups.get(op.group) ?? [];
61
+ lines.push(` ${op.command.padEnd(20)} ${op.summary}`);
62
+ groups.set(op.group, lines);
63
+ }
64
+ const sections = [...groups].map(([group, lines]) => `${group}:\n${lines.join("\n")}`);
65
+ return `CELLO: signed, encrypted conversations between agents.
66
+
67
+ Start here:
68
+ cello setup --code <code> Set up this machine. The code is in your admission email.
69
+ cello setup --install-mcp Connect Claude Code, Claude Desktop and ChatGPT Desktop.
70
+ cello initiate-session <address> Start a conversation. It prints a session_id.
71
+ cello send <session_id> "Hi" --over
72
+ cello wait Block until the reply arrives.
73
+ cello receive Read it.
74
+
75
+ Your data is in ~/.cello. Set CELLO_HOME to use another folder.
76
+
77
+ Usage: cello <command> [args]
78
+
79
+ ${sections.join("\n\n")}
80
+
81
+ Run 'cello <command> --help' for details on any command.
82
+ Commands print JSON on one line, and --pretty indents it.
83
+ A failure prints {"error","message"} on standard error and exits ${EXIT_REFUSED}.
84
+ A usage mistake exits ${EXIT_USAGE}, and wait exits ${EXIT_TIMEOUT} when its time runs out.
85
+ Any agent that can run a shell command can use all of this with no MCP.
86
+ Each agent's shell should set CELLO_CALLER to a stable name of its own, so that two can't share an agent by accident.
87
+ Where there's a tool, it has the same name: cello send ↔ cello_send.
88
+ `;
89
+ }
90
+ // Written synchronously, because process.exit can drop what process.stderr still holds, and the caller would get no reason.
91
+ function fail(text, code) {
92
+ const bytes = Buffer.from(text);
93
+ let written = 0;
94
+ while (written < bytes.length) {
95
+ try {
96
+ written += writeSync(2, bytes, written);
97
+ }
98
+ catch (err) {
99
+ // A full pipe that doesn't block asks to be tried again. Anything else means nobody is reading.
100
+ if (err.code !== "EAGAIN")
101
+ break;
102
+ }
103
+ }
104
+ process.exit(code);
105
+ }
106
+ function usageError(message, op) {
107
+ const hint = op ? `\n\n${usageLine(op)}\nRun 'cello ${op.command} --help' for details.` : "\n\nRun 'cello --help' for the list of commands.";
108
+ fail(`${message}${hint}\n`, EXIT_USAGE);
109
+ }
110
+ // Per caller, so one caller's choice can't make another act as the wrong agent.
111
+ const currentAgentFile = () => join(celloHome(), CALLER === "cli" ? "current-agent" : `current-agent-${createHash("sha256").update(CALLER).digest("hex").slice(0, 16)}`);
112
+ function currentAgent() {
113
+ return existsSync(currentAgentFile()) ? readFileSync(currentAgentFile(), "utf8").trim() || undefined : undefined;
114
+ }
115
+ function readValue(param, raw) {
116
+ if (param.kind === "number") {
117
+ const value = Number(raw);
118
+ if (!Number.isFinite(value))
119
+ usageError(`${flag(param.name)} must be a number, got ${raw}`);
120
+ return value;
121
+ }
122
+ if (param.allowed && !param.allowed.includes(raw))
123
+ usageError(`${flag(param.name)} must be one of ${param.allowed.join(", ")}, got ${raw}`);
124
+ return raw;
125
+ }
126
+ // One line by default, because the usual reader is a program or an agent paying for every character.
127
+ let pretty = false;
128
+ let asJson = false;
129
+ const render = (value) => `${pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value)}\n`;
130
+ // Fails on anything it doesn't recognise, so a mistyped flag can't quietly change what a command does.
131
+ function parse(op, args) {
132
+ const params = {};
133
+ const positional = op.params.filter((p) => p.positional);
134
+ const given = [];
135
+ let flagsEnded = false;
136
+ for (let i = 0; i < args.length; i++) {
137
+ const arg = args[i];
138
+ if (flagsEnded || !arg.startsWith("--")) {
139
+ given.push(arg);
140
+ continue;
141
+ }
142
+ if (arg === "--") {
143
+ flagsEnded = true;
144
+ continue;
145
+ }
146
+ if (arg === "--pretty") {
147
+ pretty = true;
148
+ continue;
149
+ }
150
+ if (op.plain && arg === "--json") {
151
+ asJson = true;
152
+ continue;
153
+ }
154
+ if (op.acts && arg === "--force") {
155
+ params["force"] = true;
156
+ continue;
157
+ }
158
+ if (op.scoped && arg === "--agent") {
159
+ const value = args[++i];
160
+ if (!value)
161
+ usageError("--agent needs a value", op);
162
+ params["agent"] = value;
163
+ continue;
164
+ }
165
+ if (op.command === "send" && (arg === "--over" || arg === "--wrap" || arg === "--standby")) {
166
+ if (params["signal"] !== undefined)
167
+ usageError(`send takes one signal: ${SIGNAL_FLAGS}`, op);
168
+ params["signal"] = arg.slice(2);
169
+ if (arg === "--standby") {
170
+ const minutes = Number(args[++i]);
171
+ if (!(minutes > 0))
172
+ usageError("--standby needs a positive number of minutes", op);
173
+ params["est_minutes"] = minutes;
174
+ }
175
+ continue;
176
+ }
177
+ const param = op.params.find((p) => !p.positional && !isSignalParam(op, p) && flag(p.name) === arg);
178
+ if (!param)
179
+ usageError(`${op.command} has no option ${arg}`, op);
180
+ if (param.kind === "boolean") {
181
+ params[param.name] = true;
182
+ continue;
183
+ }
184
+ const value = args[++i];
185
+ if (value === undefined)
186
+ usageError(`${arg} needs a value`, op);
187
+ params[param.name] = readValue(param, value);
188
+ }
189
+ if (given.length > positional.length)
190
+ usageError(`${op.command} takes ${positional.length} argument(s), got ${given.length}`, op);
191
+ positional.forEach((param, i) => {
192
+ const value = given[i];
193
+ if (value !== undefined)
194
+ params[param.name] = param.name === "text" && value === "-" ? readFileSync(0, "utf8") : value;
195
+ });
196
+ for (const param of op.params) {
197
+ if (param.required && params[param.name] === undefined)
198
+ usageError(`${op.command} needs ${isSignalParam(op, param) ? SIGNAL_FLAGS : param.positional ? `<${param.name}>` : flag(param.name)}`, op);
199
+ }
200
+ if (op.scoped) {
201
+ params["agent"] ??= currentAgent();
202
+ if (!params["agent"]) {
203
+ fail(`${JSON.stringify({ error: "no_current_agent", message: "Name the agent with --agent, or choose one with: cello use-agent --agent <name>" })}\n`, EXIT_REFUSED);
204
+ }
205
+ params["caller"] = CALLER;
206
+ }
207
+ return params;
208
+ }
209
+ // The build doesn't rewrite a path held in a string, so the daemon is looked for in the form this file is running in:
210
+ // main.ts from source, main.js when installed.
211
+ function daemonEntry() {
212
+ const here = fileURLToPath(import.meta.url);
213
+ const entry = join(dirname(here), "daemon", `main${extname(here)}`);
214
+ if (!existsSync(entry)) {
215
+ fail(`${JSON.stringify({ error: "daemon_entry_missing", message: `The daemon's code isn't at ${entry}, so this install is incomplete. Install CELLO again.` })}\n`, EXIT_REFUSED);
216
+ }
217
+ return entry;
218
+ }
219
+ async function waitForDaemon(child) {
220
+ let exited;
221
+ child.once("exit", (code) => { exited = code; });
222
+ for (let i = 0; i < 100; i++) {
223
+ if (exited !== undefined)
224
+ break;
225
+ try {
226
+ return await IpcClient.connect(socketPath());
227
+ }
228
+ catch {
229
+ await new Promise((resolve) => setTimeout(resolve, 100));
230
+ }
231
+ }
232
+ const tail = readFileSync(logPath(), "utf8").trim().split("\n").slice(-5).join("\n");
233
+ return fail(`The daemon didn't start. The last lines of ${logPath()}:\n${tail}\n`, EXIT_REFUSED);
234
+ }
235
+ async function startDaemon(server) {
236
+ const entry = daemonEntry();
237
+ mkdirSync(celloHome(), { recursive: true, mode: 0o700 });
238
+ const logFile = openSync(logPath(), "a", 0o600);
239
+ const child = spawn(process.execPath, server ? [entry, server] : [entry], { detached: true, stdio: ["ignore", logFile, logFile] });
240
+ closeSync(logFile);
241
+ const client = await waitForDaemon(child);
242
+ child.unref();
243
+ return client;
244
+ }
245
+ async function login(args) {
246
+ if (holdsOldVersion())
247
+ fail(`${oldVersionMessage()}\n`, EXIT_REFUSED);
248
+ const at = args.indexOf("--server");
249
+ const server = at >= 0 ? args[at + 1] : undefined;
250
+ if (at >= 0 && !server)
251
+ usageError("--server needs a value");
252
+ try {
253
+ const running = await IpcClient.connect(socketPath());
254
+ const status = await running.call("status");
255
+ running.close();
256
+ if (server && status.server !== server) {
257
+ fail(`A daemon is already running for ${status.server}. Run: cello logout\n`, EXIT_REFUSED);
258
+ }
259
+ process.stdout.write(`Already running, process ${status.pid}.\n`);
260
+ return;
261
+ }
262
+ catch (err) {
263
+ if (!(err instanceof DaemonGone))
264
+ throw err;
265
+ }
266
+ const client = await startDaemon(server);
267
+ // A far-away server takes a moment. Say what's true rather than implying it's ready.
268
+ let status = await client.call("status");
269
+ for (let i = 0; i < 50 && !status.connected; i++) {
270
+ await new Promise((resolve) => setTimeout(resolve, 200));
271
+ status = await client.call("status");
272
+ }
273
+ client.close();
274
+ const state = status.connected ? "connected" : `not connected yet (${status.problem ?? "still trying"}). It keeps trying by itself`;
275
+ process.stdout.write(`Daemon started, process ${status.pid}, for ${status.server}: ${state}.\n`);
276
+ // From what's on disk: this runs only at login, and 'status' reports what the running screen really loaded.
277
+ const model = await screenerState({ dir: screenerModelDir(), runtimePresent: await runtimeAvailable(), verifyDigests: false });
278
+ process.stdout.write(model.state === "ready"
279
+ ? "Screening: the deterministic rules and the model. 'cello status' says when the model has really loaded.\n"
280
+ : "Screening: the deterministic rules only. The model is optional: cello screener install\n");
281
+ }
282
+ function askTerminal(question) {
283
+ const rl = createReadline({ input: process.stdin, output: process.stdout });
284
+ return new Promise((done) => {
285
+ rl.once("close", () => done(""));
286
+ rl.question(question, (answer) => {
287
+ rl.removeAllListeners("close");
288
+ rl.close();
289
+ done(answer.trim());
290
+ });
291
+ });
292
+ }
293
+ // v1's guard was stdin being a terminal, and a yes. This also needs stdout to be one, and a code that's only ever shown on it,
294
+ // so an answer can't be prepared in advance. Nothing a message says can reach this: it runs only when someone runs this command.
295
+ // The daemon decides whether a change needs a person, and its refusal says what the change is and who can make it.
296
+ async function confirmPerson(refusal) {
297
+ const refuse = (error, message) => fail(`${JSON.stringify({ error, message })}\n`, EXIT_REFUSED);
298
+ if (!process.stdin.isTTY || !process.stdout.isTTY)
299
+ refuse("person_required", refusal);
300
+ // A shell that names itself as a caller is an agent's, by the rule in the help.
301
+ if (process.env["CELLO_CALLER"])
302
+ refuse("person_required", `${refusal} This shell has CELLO_CALLER set, so it's an agent's shell. Run this in a terminal of your own.`);
303
+ const code = randomBytes(3).toString("hex");
304
+ process.stdout.write(`\n${refusal.split(" Nothing changed.")[0]}\n\n`);
305
+ const answer = await askTerminal(`To go ahead, type ${code}: `);
306
+ if (answer !== code)
307
+ refuse("not_confirmed", "That wasn't the code. Nothing changed.");
308
+ }
309
+ const BRIDGE_USAGE = `Usage: cello bridge hermes --agent <name> [--hermes-home <path>] [--session-scope agent|peer] [--channel-notifications on|off] [--landing-session <id>|current|default] [--public | --not-public] [--allow-initiate]
310
+ cello bridge daemon-unit
311
+
312
+ hermes connects one Hermes profile to one CELLO agent on this machine. Run it again after an upgrade, because Hermes keeps a copy of the plugin.
313
+ A flag you leave out goes back to its default.
314
+
315
+ The bridge decides where the agent's notifications go: a new session request, a message, a channel post.
316
+ --session-scope agent (default) everything goes to one session. That's the agent's own CELLO session, made the first time,
317
+ unless a landing session is set.
318
+ --session-scope peer each caller gets a session of their own, kept for the next time they call, so two callers never share one.
319
+ For an agent strangers reach, like a support desk. Channel notices get a session of their own.
320
+ --landing-session <id> under agent scope, send everything to this Hermes session instead: a dated id, or a Desktop chat's local-... id.
321
+ --landing-session current the Hermes session this command runs in. HERMES_SESSION_ID says which.
322
+ --landing-session default back to the agent's own CELLO session.
323
+ --channel-notifications on|off whether a new post on a channel the agent follows wakes it (default on).
324
+
325
+ An agent can move its own notifications, with no person and no restart: inside Hermes, run
326
+ cello bridge hermes --agent <name> --landing-session current
327
+ before reaching out, so the reply lands in the session it's working in. Only --agent, --hermes-home and --landing-session go with it.
328
+ Everything else takes a person at a terminal.
329
+
330
+ A Hermes with several profiles: run this once per profile, with --hermes-home pointing at that profile (for example ~/.hermes/profiles/<name>).
331
+ --public is for an agent strangers can reach: one conversation per caller, a short list of tools, and the screening model required. --allow-initiate adds the tool that opens sessions to that list. A public agent stays public when you run this again, until you pass --not-public.
332
+ daemon-unit prints a systemd unit that keeps the daemon up on a server.
333
+ `;
334
+ // For a person at a terminal, like the other commands that change what an agent can do. A shell naming itself as a caller is an agent's, by the rule in the help.
335
+ async function bridgeCommand(args) {
336
+ const [target, ...rest] = args;
337
+ if (target === undefined || target === "--help" || target === "-h") {
338
+ process.stdout.write(BRIDGE_USAGE);
339
+ return;
340
+ }
341
+ if (target === "daemon-unit") {
342
+ process.stdout.write(daemonUnit());
343
+ return;
344
+ }
345
+ if (target !== "hermes")
346
+ usageError(`no such bridge: ${target}. Only hermes exists.`);
347
+ if (rest.includes("--help") || rest.includes("-h")) {
348
+ process.stdout.write(BRIDGE_USAGE);
349
+ return;
350
+ }
351
+ const values = {};
352
+ const flags = new Set();
353
+ for (let i = 0; i < rest.length; i++) {
354
+ const arg = rest[i];
355
+ if (arg === "--public" || arg === "--not-public" || arg === "--allow-initiate")
356
+ flags.add(arg);
357
+ else if (["--agent", "--hermes-home", "--session-scope", "--channel-notifications", "--landing-session"].includes(arg)) {
358
+ const value = rest[++i];
359
+ if (value === undefined)
360
+ usageError(`${arg} needs a value`);
361
+ values[arg] = value;
362
+ }
363
+ else
364
+ usageError(`unknown option ${arg}. ${BRIDGE_USAGE}`);
365
+ }
366
+ const agent = values["--agent"];
367
+ if (!agent)
368
+ usageError(`bridge hermes needs --agent. ${BRIDGE_USAGE}`);
369
+ if (process.env["CELLO_CALLER"]) {
370
+ // An agent's shell may move where its own notifications land, as v1 let it, and nothing else.
371
+ const landingOnly = values["--landing-session"] !== undefined && flags.size === 0
372
+ && Object.keys(values).every((k) => ["--agent", "--hermes-home", "--landing-session"].includes(k));
373
+ if (!landingOnly)
374
+ fail(`${JSON.stringify({ error: "person_required", message: "Installing or changing a bridge takes a person. This shell has CELLO_CALLER set, so it's an agent's shell. Run this in a terminal of your own. An agent may only move its own notifications: cello bridge hermes --agent <name> --landing-session current" })}\n`, EXIT_REFUSED);
375
+ const moved = setLanding({ agent, hermesHome: values["--hermes-home"], landingSession: values["--landing-session"] });
376
+ if (!moved.ok)
377
+ fail(`${moved.output}\n`, EXIT_REFUSED);
378
+ process.stdout.write(`${moved.output}\n`);
379
+ return;
380
+ }
381
+ const result = await installBridge({
382
+ agent,
383
+ hermesHome: values["--hermes-home"],
384
+ sessionScope: values["--session-scope"],
385
+ channelNotifications: values["--channel-notifications"],
386
+ landingSession: values["--landing-session"],
387
+ public: flags.has("--public"),
388
+ allowInitiate: flags.has("--allow-initiate"),
389
+ notPublic: flags.has("--not-public"),
390
+ modelReady: async () => (await screenerState({ dir: screenerModelDir(), runtimePresent: await runtimeAvailable() })).state === "ready",
391
+ });
392
+ if (!result.ok)
393
+ fail(`${result.output}\n`, EXIT_REFUSED);
394
+ process.stdout.write(`${result.output}\n`);
395
+ }
396
+ async function screenerCommand(args) {
397
+ const [sub, ...rest] = args;
398
+ const yes = rest.includes("--yes");
399
+ const repair = rest.includes("--repair");
400
+ if (sub === "status") {
401
+ const dir = screenerModelDir();
402
+ const state = await screenerState({ dir, runtimePresent: await runtimeAvailable() });
403
+ process.stdout.write(`${describeScreenerState(state)}\nModel directory: ${dir}\n`);
404
+ return;
405
+ }
406
+ if (sub !== "install" || args[1] === "--help") {
407
+ process.stdout.write(`Usage: cello screener status\n cello screener install [--yes] [--repair]\n\nThe deterministic rules always run. The model is a second, optional layer: about ${DOWNLOAD_MB} MB to download and ${DISK_MB} MB on disk. Nothing fetches it unless you run install and agree. Every file is checked against its published SHA-256.\n`);
408
+ if (sub !== "install" && sub !== undefined && sub !== "--help")
409
+ process.exitCode = EXIT_USAGE;
410
+ return;
411
+ }
412
+ const dir = screenerModelDir();
413
+ const before = await screenerState({ dir, runtimePresent: await runtimeAvailable() });
414
+ if (before.state === "ready") {
415
+ process.stdout.write(`${describeScreenerState(before)}\n`);
416
+ return;
417
+ }
418
+ if (before.state === "broken" && !repair)
419
+ fail(`${describeScreenerState(before)} Run again with --repair to fetch the files that failed.\n`, EXIT_REFUSED);
420
+ if (!yes) {
421
+ if (!process.stdin.isTTY)
422
+ fail(`${JSON.stringify({ error: "consent_required", message: `Nothing was downloaded. The model is about ${DOWNLOAD_MB} MB, and it's only fetched if someone says so. Run this at a terminal, or with --yes.` })}\n`, EXIT_REFUSED);
423
+ process.stdout.write(`CELLO's deterministic screening rules are already running. A prompt-injection model is designed to catch a different set of attacks.\n\nThis downloads:\n Patronus Wolf Defender model, from Hugging Face: 131 MB\n Transformers.js by Hugging Face, with Microsoft's ONNX Runtime, from npm: about 110 MB\n\nTotal: about ${DOWNLOAD_MB} MB to download, about ${DISK_MB} MB on disk. Every model file is checked against its published SHA-256.\n\n`);
424
+ const answer = (await askTerminal("Install now? [y/N] ")).toLowerCase();
425
+ if (answer !== "y" && answer !== "yes") {
426
+ process.stdout.write("Nothing was downloaded.\n");
427
+ return;
428
+ }
429
+ }
430
+ if (repair)
431
+ rmSync(dir, { recursive: true, force: true });
432
+ const model = await installModel({ dir, consent: true, onProgress: (file, i, total) => process.stdout.write(`Model file ${i + 1} of ${total}: ${file}\n`) });
433
+ if (!model.installed)
434
+ fail(`${JSON.stringify({ error: "model_install_failed", message: model.error ?? "the model didn't install" })}\n`, EXIT_REFUSED);
435
+ if (!(await runtimeAvailable())) {
436
+ process.stdout.write(`Installing the runtime into ${screenerRuntimeDir()}\n`);
437
+ mkdirSync(screenerRuntimeDir(), { recursive: true });
438
+ // Its own folder, because Node's ESM resolver doesn't look in npm's global root. The native model runtime needs its install script.
439
+ writeFileSync(join(screenerRuntimeDir(), ".npmrc"), "allow-scripts=onnxruntime-node,protobufjs\n");
440
+ const npm = spawnSync("npm", ["install", "--no-audit", "--no-fund", SCREENER_RUNTIME_MODULE], { stdio: "inherit", cwd: screenerRuntimeDir() });
441
+ if (npm.status !== 0)
442
+ fail(`${JSON.stringify({ error: "runtime_install_failed", message: `npm install failed with status ${npm.status ?? "none"}, so the model can't run. Try again.` })}\n`, EXIT_REFUSED);
443
+ }
444
+ const after = await screenerState({ dir, runtimePresent: await runtimeAvailable() });
445
+ if (after.state !== "ready")
446
+ fail(`${describeScreenerState(after)}\n`, EXIT_REFUSED);
447
+ // A running daemon picks it up now. If none is running, the next login does.
448
+ try {
449
+ const client = await IpcClient.connect(socketPath());
450
+ await client.call("screener_reload");
451
+ client.close();
452
+ process.stdout.write("Installed. The daemon is loading it, and 'cello status' says when it's really running.\n");
453
+ }
454
+ catch (err) {
455
+ if (!(err instanceof DaemonGone))
456
+ throw err;
457
+ process.stdout.write("Installed. It loads at the next login.\n");
458
+ }
459
+ }
460
+ // A code shown only on the terminal, so an answer can't be prepared in advance. A shell naming itself as a caller is an agent's, by the rule in the help.
461
+ async function confirmAtTerminal(what) {
462
+ const refuse = (error, message) => fail(`${JSON.stringify({ error, message })}\n`, EXIT_REFUSED);
463
+ const refusal = "This takes a person at a terminal, on this machine. Nothing changed.";
464
+ if (!process.stdin.isTTY || !process.stdout.isTTY)
465
+ refuse("person_required", refusal);
466
+ if (process.env["CELLO_CALLER"])
467
+ refuse("person_required", `${refusal} This shell has CELLO_CALLER set, so it's an agent's shell. Run this in a terminal of your own.`);
468
+ const code = randomBytes(3).toString("hex");
469
+ process.stdout.write(`\n${what}\n\n`);
470
+ const answer = await askTerminal(`To go ahead, type ${code}: `);
471
+ if (answer !== code)
472
+ refuse("not_confirmed", "That wasn't the code. Nothing changed.");
473
+ }
474
+ async function issuerListSignCommand(args) {
475
+ const value = (name) => {
476
+ const at = args.indexOf(`--${name}`);
477
+ const found = at >= 0 ? args[at + 1] : undefined;
478
+ return found ?? usageError(`issuer-list-sign needs --${name}`);
479
+ };
480
+ const [inPath, outPath, root, command] = [value("in"), value("out"), value("root"), value("signer-command")];
481
+ try {
482
+ const result = await signIssuerListFile({ inPath, outPath, signer: commandSigner(parseRootName(root), command), roots: productionRootKeys() });
483
+ process.stdout.write(`${JSON.stringify({ ok: true, out: outPath, signed_by: result.signed })}\n`);
484
+ }
485
+ catch (err) {
486
+ const code = err instanceof RootKeysNotConfigured ? err.code : "issuer_list_not_signed";
487
+ fail(`${JSON.stringify({ error: code, message: err instanceof Error ? err.message : String(err) })}\n`, EXIT_REFUSED);
488
+ }
489
+ }
490
+ async function main() {
491
+ const [first, ...rest] = process.argv.slice(2);
492
+ // cello signals list is the same operation as cello signals-list, which is what its tool is named after.
493
+ const [command, args] = first === "signals" && rest[0] && !rest[0].startsWith("-") ? [`signals-${rest[0]}`, rest.slice(1)] : [first, rest];
494
+ if (!command || command === "--help" || command === "-h" || command === "help") {
495
+ const named = command === "help" ? OPERATIONS.find((candidate) => candidate.command === args[0]) : undefined;
496
+ process.stdout.write(named ? commandHelp(named) : overview());
497
+ return;
498
+ }
499
+ if (command === "--version" || command === "-v" || command === "version") {
500
+ // The package file sits one folder up from both src/ and dist/.
501
+ const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8"));
502
+ process.stdout.write(`${pkg.version}\n`);
503
+ return;
504
+ }
505
+ // Only as the first argument, so a message that says --help is still a message.
506
+ const wantsHelp = args[0] === "--help" || args[0] === "-h";
507
+ if (command === "login") {
508
+ if (wantsHelp) {
509
+ process.stdout.write("Usage: cello login [--server <wss-url>]\n\nStart the daemon, and connect it to a server. The first login names the server, and it's kept in the database with everything else, so later ones, and a database moved to a new folder with its key, need no --server.\n");
510
+ return;
511
+ }
512
+ return login(args);
513
+ }
514
+ if (command === "setup") {
515
+ if (wantsHelp) {
516
+ process.stdout.write(SETUP_HELP);
517
+ return;
518
+ }
519
+ process.exitCode = await setup(args, {
520
+ startDaemon,
521
+ ask: askTerminal,
522
+ caller: CALLER,
523
+ rememberAgent: (agentId) => writeFileSync(currentAgentFile(), `${agentId}\n`, { mode: 0o600 }),
524
+ });
525
+ return;
526
+ }
527
+ if (command === "screener")
528
+ return screenerCommand(args);
529
+ if (command === "bridge")
530
+ return bridgeCommand(args);
531
+ if (command === "issuer-list-sign") {
532
+ if (wantsHelp) {
533
+ process.stdout.write("Usage: cello issuer-list-sign --in <file> --out <file> --root <enclave|kms|paper> --signer-command <command>\n\nAdd one root key's signature to the signed issuer list. --in is the list as JSON, or a file another root has already signed. The command gets the message on stdin and prints the raw 64-byte signature in hex. A list needs two roots.\n");
534
+ return;
535
+ }
536
+ return issuerListSignCommand(args);
537
+ }
538
+ if (command === "logout") {
539
+ if (wantsHelp) {
540
+ process.stdout.write("Usage: cello logout\n\nStop the daemon. Conversations carry on after the next login.\n");
541
+ return;
542
+ }
543
+ const client = await IpcClient.connect(socketPath());
544
+ await client.call("shutdown");
545
+ client.close();
546
+ process.stdout.write("Daemon stopped.\n");
547
+ return;
548
+ }
549
+ const op = OPERATIONS.find((candidate) => candidate.command === command);
550
+ if (!op)
551
+ usageError(`No such command: ${command}`);
552
+ if (wantsHelp) {
553
+ process.stdout.write(commandHelp(op));
554
+ return;
555
+ }
556
+ const params = parse(op, args);
557
+ if (STATUS_COMMANDS.includes(op.command)) {
558
+ await confirmAtTerminal(`${op.command}${params["agent"] ? ` for ${params["agent"]}` : ""}: ${op.description}`);
559
+ params["person_confirmed"] = true;
560
+ }
561
+ if (op.local) {
562
+ const checked = await runLocal(op.method, params);
563
+ process.stdout.write(render(checked));
564
+ if (!checked["ok"])
565
+ process.exitCode = EXIT_REFUSED;
566
+ return;
567
+ }
568
+ params["caller"] ??= CALLER;
569
+ const client = await IpcClient.connect(socketPath());
570
+ const waited = op.method === "wait" ? (params["timeout_seconds"] ?? DEFAULT_WAIT_SECONDS) * 1000 + 10_000 : undefined;
571
+ const ask = (fields) => (op.method === "export_transcript"
572
+ ? exportTranscript({ ...fields, out: resolve(fields["out"]) }, (sent) => client.call(op.method, sent))
573
+ : client.call(op.method, fields, waited));
574
+ let answer;
575
+ try {
576
+ answer = await ask(params);
577
+ }
578
+ catch (err) {
579
+ if (!(err instanceof DaemonRefused) || err.code !== "person_required")
580
+ throw err;
581
+ await confirmPerson(err.message);
582
+ answer = await ask({ ...params, person_confirmed: true });
583
+ }
584
+ const result = answer;
585
+ client.close();
586
+ process.stdout.write(op.plain && !asJson ? op.plain(result) : render(result));
587
+ // The id, never the name: a name is a label, and it could later mean a different agent.
588
+ if (op.method === "use_agent")
589
+ writeFileSync(currentAgentFile(), `${result.agent_id}\n`, { mode: 0o600 });
590
+ if (op.method === "stop_using_agent" && currentAgent() === result.agent_id)
591
+ rmSync(currentAgentFile());
592
+ if (op.method === "wait" && result.event === "timeout")
593
+ process.exitCode = EXIT_TIMEOUT;
594
+ if (op.method === "verify_session" && !result.ok)
595
+ process.exitCode = EXIT_REFUSED;
596
+ }
597
+ main().catch((err) => {
598
+ if (err instanceof DaemonGone || err instanceof DaemonRefused) {
599
+ fail(`${JSON.stringify({ error: err.code, message: err.message })}\n`, EXIT_REFUSED);
600
+ }
601
+ fail(`${err instanceof Error ? err.stack ?? err.message : String(err)}\n`, EXIT_REFUSED);
602
+ });
@@ -0,0 +1,4 @@
1
+ export declare const ACCOUNT_PAGE_ASSETS: Record<string, {
2
+ type: string;
3
+ body: string;
4
+ }>;