@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.
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 +564 -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 +80 -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 +511 -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 +146 -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 +63 -0
  50. package/dist/daemon/reach.js +207 -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 +188 -0
  60. package/dist/daemon/store.js +474 -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 +428 -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 +26 -0
  70. package/dist/hermes-bridge.js +180 -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 +835 -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 +155 -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 +252 -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 +1040 -0
  180. package/hermes/plugin/plugin.yaml +30 -0
  181. package/hermes/skills/cello-bridge-setup/SKILL.md +38 -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
@@ -0,0 +1,160 @@
1
+ // The page itself, as strings, so it ships inside the build with nothing to copy and nothing fetched from anywhere.
2
+ // It shows what the daemon returns, as text, and never as markup: a signal's words come from an issuer, and a contact's
3
+ // moniker from a stranger.
4
+ const HTML = `<!doctype html>
5
+ <html lang="en">
6
+ <head>
7
+ <meta charset="utf-8">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+ <title>CELLO</title>
10
+ <link rel="stylesheet" href="/page.css">
11
+ </head>
12
+ <body>
13
+ <header>
14
+ <h1>CELLO</h1>
15
+ <label>Agent <select id="agent"></select></label>
16
+ </header>
17
+ <p id="problem" role="alert" hidden></p>
18
+ <main id="sections"></main>
19
+ <script src="/page.js"></script>
20
+ </body>
21
+ </html>
22
+ `;
23
+ const CSS = `:root { color-scheme: light dark; --edge: #8886; --soft: #8882; }
24
+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0 auto; max-width: 56rem; padding: 0 16px 48px; }
25
+ header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0; }
26
+ h1 { font-size: 1.25rem; margin: 0; }
27
+ h2 { font-size: 1.05rem; margin: 32px 0 8px; }
28
+ select { font: inherit; max-width: 100%; }
29
+ section.off { opacity: 0.5; }
30
+ .scroll { overflow-x: auto; }
31
+ table { border-collapse: collapse; width: 100%; }
32
+ th, td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--edge); vertical-align: top; }
33
+ th { font-weight: 600; white-space: nowrap; }
34
+ td.key { font-family: ui-monospace, monospace; font-size: 0.85rem; overflow-wrap: anywhere; }
35
+ #problem { background: var(--soft); border-left: 4px solid #c33; padding: 8px 12px; }
36
+ `;
37
+ const JS = `"use strict";
38
+ const SECTIONS = [
39
+ { id: "agents", title: "Agents", method: "agents", pick: (r) => r.agents },
40
+ { id: "signals", title: "Signals", method: "signals_list", perAgent: true, pick: (r) => r.signals },
41
+ { id: "contacts", title: "Contacts", method: "contacts", perAgent: true, pick: (r) => r.contacts },
42
+ { id: "settings", title: "Settings", method: "settings", pick: (r) => r.settings },
43
+ { id: "guards", title: "Guards", method: "config", perAgent: true, pick: (r) => r.guards },
44
+ { id: "track", title: "Track record", off: true, note: "Coming soon: how much you use CELLO and who you reach." },
45
+ ];
46
+
47
+ let token = "";
48
+ try { token = sessionStorage.getItem("token") || ""; } catch { /* a private window: the link has to be used again after a reload */ }
49
+ if (location.hash.length > 1) {
50
+ token = location.hash.slice(1);
51
+ try { sessionStorage.setItem("token", token); } catch { /* as above */ }
52
+ history.replaceState(null, "", location.pathname);
53
+ }
54
+
55
+ const problem = document.getElementById("problem");
56
+ const sections = document.getElementById("sections");
57
+ const picker = document.getElementById("agent");
58
+
59
+ function say(text) {
60
+ problem.textContent = text;
61
+ problem.hidden = text === "";
62
+ }
63
+
64
+ async function read(method, params) {
65
+ const query = new URLSearchParams(params).toString();
66
+ const reply = await fetch("/api/" + method + (query ? "?" + query : ""), { headers: { authorization: "Bearer " + token } });
67
+ const body = await reply.json();
68
+ if (!body.ok) throw new Error(body.error.message);
69
+ return body.result;
70
+ }
71
+
72
+ function show(value) {
73
+ if (value === null || value === undefined) return "";
74
+ if (typeof value === "object") return JSON.stringify(value);
75
+ return String(value);
76
+ }
77
+
78
+ const KEYS = /(^|_)(id|hash|address|pubkey)$/;
79
+
80
+ function table(rows) {
81
+ const columns = [...new Set(rows.flatMap((row) => Object.keys(row)))];
82
+ const wrap = document.createElement("div");
83
+ wrap.className = "scroll";
84
+ const t = document.createElement("table");
85
+ const head = t.createTHead().insertRow();
86
+ for (const name of columns) {
87
+ const th = document.createElement("th");
88
+ th.textContent = name.replaceAll("_", " ");
89
+ head.append(th);
90
+ }
91
+ const body = t.createTBody();
92
+ for (const row of rows) {
93
+ const tr = body.insertRow();
94
+ for (const name of columns) {
95
+ const td = tr.insertCell();
96
+ td.textContent = show(row[name]);
97
+ if (KEYS.test(name)) td.className = "key";
98
+ }
99
+ }
100
+ wrap.append(t);
101
+ return wrap;
102
+ }
103
+
104
+ function frame(section) {
105
+ const el = document.createElement("section");
106
+ el.id = section.id;
107
+ if (section.off) el.className = "off";
108
+ const h = document.createElement("h2");
109
+ h.textContent = section.title;
110
+ el.append(h);
111
+ if (section.note) {
112
+ const p = document.createElement("p");
113
+ p.textContent = section.note;
114
+ el.append(p);
115
+ }
116
+ return el;
117
+ }
118
+
119
+ async function load() {
120
+ say("");
121
+ sections.replaceChildren();
122
+ const agent = picker.value;
123
+ for (const section of SECTIONS) {
124
+ const el = frame(section);
125
+ sections.append(el);
126
+ if (section.off) continue;
127
+ if (section.perAgent && !agent) continue;
128
+ try {
129
+ const params = section.perAgent || section.id === "settings" ? (agent ? { agent } : {}) : {};
130
+ const rows = section.pick(await read(section.method, params)) || [];
131
+ if (rows.length) el.append(table(rows));
132
+ } catch (err) {
133
+ say(section.title + ": " + err.message);
134
+ }
135
+ }
136
+ }
137
+
138
+ async function start() {
139
+ if (!token) {
140
+ say("This page needs its link. Run cello account in a terminal to get it.");
141
+ return;
142
+ }
143
+ try {
144
+ const { agents } = await read("agents", {});
145
+ picker.replaceChildren(...agents.map((a) => Object.assign(document.createElement("option"), { value: a.agent_id, textContent: a.name })));
146
+ } catch (err) {
147
+ say(err.message);
148
+ return;
149
+ }
150
+ picker.addEventListener("change", load);
151
+ await load();
152
+ }
153
+
154
+ start();
155
+ `;
156
+ export const ACCOUNT_PAGE_ASSETS = {
157
+ "/": { type: "text/html; charset=utf-8", body: HTML },
158
+ "/page.css": { type: "text/css; charset=utf-8", body: CSS },
159
+ "/page.js": { type: "text/javascript; charset=utf-8", body: JS },
160
+ };
@@ -0,0 +1,14 @@
1
+ export declare const ACCOUNT_PAGE_READS: readonly ["agents", "signals_list", "contacts", "settings", "config"];
2
+ export type AccountPageCall = (method: string, params: Record<string, unknown>) => Promise<unknown>;
3
+ export interface AccountPageOptions {
4
+ host: string;
5
+ port: number;
6
+ token: string;
7
+ call: AccountPageCall;
8
+ allowedHosts: (port: number) => string[];
9
+ }
10
+ export interface RunningAccountPage {
11
+ port: number;
12
+ close: () => Promise<void>;
13
+ }
14
+ export declare function serveAccountPage(options: AccountPageOptions): Promise<RunningAccountPage>;
@@ -0,0 +1,104 @@
1
+ // The account page: a web page the daemon serves about its own agents. It only reads, so nothing a person can weaken
2
+ // is reachable from it. That stays at the terminal. It knows nothing about where the daemon runs: the caller says
3
+ // where to listen and how a request is answered, so a hosted container can serve the same page beside its endpoint.
4
+ import { timingSafeEqual } from "node:crypto";
5
+ import { createServer } from "node:http";
6
+ import { ACCOUNT_PAGE_ASSETS } from "./account-page-assets.js";
7
+ import { LocalError } from "./engine.js";
8
+ // What the page may ask for. Each is a read that acts as nobody. A test checks that every name is a real operation.
9
+ export const ACCOUNT_PAGE_READS = ["agents", "signals_list", "contacts", "settings", "config"];
10
+ function sameSecret(given, expected) {
11
+ const a = Buffer.from(given);
12
+ const b = Buffer.from(expected);
13
+ return a.length === b.length && timingSafeEqual(a, b);
14
+ }
15
+ const SECURITY_HEADERS = {
16
+ "content-security-policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
17
+ "x-content-type-options": "nosniff",
18
+ "referrer-policy": "no-referrer",
19
+ "cache-control": "no-store",
20
+ };
21
+ function send(res, status, type, body) {
22
+ res.writeHead(status, { ...SECURITY_HEADERS, "content-type": type });
23
+ res.end(body);
24
+ }
25
+ function sendJson(res, status, body) {
26
+ send(res, status, "application/json; charset=utf-8", JSON.stringify(body));
27
+ }
28
+ function failure(code, message) {
29
+ return { ok: false, error: { code, message } };
30
+ }
31
+ // A flag is "true" or "false", and a number is a number, because a query string only carries text.
32
+ function paramsFrom(url) {
33
+ const params = {};
34
+ for (const [key, value] of url.searchParams) {
35
+ params[key] = value === "true" ? true : value === "false" ? false : value;
36
+ }
37
+ return params;
38
+ }
39
+ async function answer(req, res, options, port) {
40
+ if (!options.allowedHosts(port).includes(req.headers.host ?? "")) {
41
+ sendJson(res, 421, failure("wrong_host", "This page answers only under its own address."));
42
+ return;
43
+ }
44
+ const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
45
+ if (req.method !== "GET") {
46
+ sendJson(res, 405, failure("read_only", "This page only reads. Anything that changes a guard is done at the terminal."));
47
+ return;
48
+ }
49
+ const asset = ACCOUNT_PAGE_ASSETS[url.pathname];
50
+ if (asset) {
51
+ send(res, 200, asset.type, asset.body);
52
+ return;
53
+ }
54
+ const route = /^\/api\/([a-z_]+)$/.exec(url.pathname);
55
+ if (!route) {
56
+ sendJson(res, 404, failure("not_found", `Nothing is served at ${url.pathname}.`));
57
+ return;
58
+ }
59
+ const bearer = /^Bearer (.+)$/.exec(req.headers.authorization ?? "")?.[1] ?? "";
60
+ if (!sameSecret(bearer, options.token)) {
61
+ sendJson(res, 401, failure("not_signed_in", "This page needs its link. Run cello account in a terminal to get it."));
62
+ return;
63
+ }
64
+ const method = route[1];
65
+ if (!ACCOUNT_PAGE_READS.includes(method)) {
66
+ sendJson(res, 404, failure("not_on_this_page", `${method} isn't something this page can ask for.`));
67
+ return;
68
+ }
69
+ try {
70
+ sendJson(res, 200, { ok: true, result: await options.call(method, paramsFrom(url)) });
71
+ }
72
+ catch (err) {
73
+ if (err instanceof LocalError)
74
+ sendJson(res, 400, failure(err.code, err.message));
75
+ else
76
+ sendJson(res, 500, failure("internal_error", err instanceof Error ? err.message : String(err)));
77
+ }
78
+ }
79
+ export async function serveAccountPage(options) {
80
+ let port = options.port;
81
+ const server = createServer((req, res) => {
82
+ answer(req, res, options, port).catch((err) => {
83
+ if (!res.headersSent)
84
+ sendJson(res, 500, failure("internal_error", err instanceof Error ? err.message : String(err)));
85
+ else
86
+ res.destroy();
87
+ });
88
+ });
89
+ await new Promise((resolve, reject) => {
90
+ server.once("error", reject);
91
+ server.listen({ host: options.host, port: options.port }, () => {
92
+ server.off("error", reject);
93
+ resolve();
94
+ });
95
+ });
96
+ port = server.address().port;
97
+ return {
98
+ port,
99
+ close: () => new Promise((resolve) => {
100
+ server.close(() => resolve());
101
+ server.closeAllConnections();
102
+ }),
103
+ };
104
+ }
@@ -0,0 +1,10 @@
1
+ export interface Address {
2
+ id: string;
3
+ server?: string;
4
+ }
5
+ export declare class PlainTextServer extends RangeError {
6
+ readonly code = "plain_text_server";
7
+ }
8
+ export declare function serverUrlFrom(host: string): string;
9
+ export declare function parseAddress(target: string): Address;
10
+ export declare function formatAddress(id: string, serverUrl: string): string;
@@ -0,0 +1,34 @@
1
+ // An agent's address is its key plus its server, like an email address: <64 hex>@cello.example.com.
2
+ // Plain ws is for this machine only. An address comes from someone else, so one that names a plain-text host off this machine
3
+ // could get a daemon connecting unencrypted and pinning whatever key that host shows. It's refused, whoever hands it over.
4
+ const LOOPBACK = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/;
5
+ const SHORT_HOST = /^[A-Za-z0-9.-]+(:\d+)?$|^\[[0-9A-Fa-f:]+\](:\d+)?$/;
6
+ export class PlainTextServer extends RangeError {
7
+ code = "plain_text_server";
8
+ }
9
+ export function serverUrlFrom(host) {
10
+ if (host.includes("://")) {
11
+ const url = new URL(host);
12
+ if (url.protocol !== "ws:" && url.protocol !== "wss:")
13
+ throw new RangeError(`a server address must be ws or wss, not ${url.protocol}`);
14
+ if (url.protocol === "ws:" && !LOOPBACK.test(url.host))
15
+ throw new PlainTextServer(`${url.host} is on another machine and this address has no encryption, so it wasn't contacted. Whoever gave you this address should give you one on wss.`);
16
+ return url.toString().replace(/\/$/, "");
17
+ }
18
+ if (!SHORT_HOST.test(host))
19
+ throw new RangeError(`this isn't a server address: ${host}`);
20
+ return `${LOOPBACK.test(host) ? "ws" : "wss"}://${host}/v1`;
21
+ }
22
+ export function parseAddress(target) {
23
+ const at = target.indexOf("@");
24
+ if (at < 0)
25
+ return { id: target };
26
+ return { id: target.slice(0, at), server: serverUrlFrom(target.slice(at + 1)) };
27
+ }
28
+ // The shortest spelling that parses back to the same URL.
29
+ export function formatAddress(id, serverUrl) {
30
+ const match = /^wss?:\/\/([^/]+)\/v1$/.exec(serverUrl);
31
+ const host = match?.[1];
32
+ const short = host !== undefined && SHORT_HOST.test(host) && serverUrlFrom(host) === serverUrl;
33
+ return `${id}@${short ? host : serverUrl}`;
34
+ }
@@ -0,0 +1,31 @@
1
+ import type { Store } from "./store.ts";
2
+ export type VisitState = "due" | "sent" | "not_sent" | "closed" | "answered";
3
+ export interface GreetingRow {
4
+ agent_id: Uint8Array;
5
+ session_id: Uint8Array;
6
+ sender_id: Uint8Array;
7
+ body: Uint8Array | null;
8
+ verdict: string | null;
9
+ verdict_detail: string | null;
10
+ received_at: number;
11
+ read_at: number | null;
12
+ }
13
+ export declare const ONE_MESSAGE_LINE = "This inbox only accepts one message per visit. Closing.";
14
+ export declare class Away {
15
+ #private;
16
+ constructor(store: Store);
17
+ startVisit(agentId: Uint8Array, sessionId: Uint8Array): void;
18
+ visit(agentId: Uint8Array, sessionId: Uint8Array): {
19
+ state: VisitState;
20
+ greeting: string | null;
21
+ } | undefined;
22
+ setVisit(agentId: Uint8Array, sessionId: Uint8Array, state: VisitState, greeting?: string): void;
23
+ greeting(agentId: Uint8Array, sessionId: Uint8Array): GreetingRow | undefined;
24
+ addGreeting(agentId: Uint8Array, sessionId: Uint8Array, senderId: Uint8Array, body: Uint8Array): void;
25
+ rejectGreeting(agentId: Uint8Array, sessionId: Uint8Array, senderId: Uint8Array, why: string): void;
26
+ setVerdict(agentId: Uint8Array, sessionId: Uint8Array, verdict: string, detail: string): void;
27
+ unscreened(): GreetingRow[];
28
+ unread(agentId: Uint8Array): GreetingRow[];
29
+ all(agentId: Uint8Array): GreetingRow[];
30
+ markRead(agentId: Uint8Array, sessionId: Uint8Array): void;
31
+ }
@@ -0,0 +1,65 @@
1
+ const SCHEMA = `
2
+ -- The callee's side: one row per call answered while nobody was reachable.
3
+ CREATE TABLE IF NOT EXISTS away_visits (
4
+ agent_id BLOB NOT NULL REFERENCES agents(agent_id),
5
+ session_id BLOB NOT NULL,
6
+ state TEXT NOT NULL CHECK (state IN ('due', 'sent', 'not_sent', 'closed', 'answered')),
7
+ -- Signed once, so a retry after a crash sends the same bytes.
8
+ greeting TEXT,
9
+ PRIMARY KEY (agent_id, session_id)
10
+ );
11
+ -- The caller's side: what the other agent's greeting said, and what screening made of it. Nothing shows it until it has a verdict.
12
+ CREATE TABLE IF NOT EXISTS greetings (
13
+ agent_id BLOB NOT NULL REFERENCES agents(agent_id),
14
+ session_id BLOB NOT NULL,
15
+ sender_id BLOB NOT NULL,
16
+ body BLOB,
17
+ verdict TEXT CHECK (verdict IS NULL OR verdict IN ('allow', 'flagged', 'blocked', 'rejected')),
18
+ verdict_detail TEXT,
19
+ received_at INTEGER NOT NULL,
20
+ read_at INTEGER,
21
+ PRIMARY KEY (agent_id, session_id)
22
+ );
23
+ `;
24
+ export const ONE_MESSAGE_LINE = "This inbox only accepts one message per visit. Closing.";
25
+ export class Away {
26
+ #store;
27
+ constructor(store) {
28
+ this.#store = store;
29
+ store.exec(SCHEMA);
30
+ }
31
+ startVisit(agentId, sessionId) {
32
+ this.#store.prepare("INSERT OR IGNORE INTO away_visits (agent_id, session_id, state) VALUES (?, ?, 'due')").run(agentId, sessionId);
33
+ }
34
+ visit(agentId, sessionId) {
35
+ return this.#store.prepare("SELECT state, greeting FROM away_visits WHERE agent_id = ? AND session_id = ?").get(agentId, sessionId);
36
+ }
37
+ setVisit(agentId, sessionId, state, greeting) {
38
+ this.#store.prepare("UPDATE away_visits SET state = ?, greeting = COALESCE(?, greeting) WHERE agent_id = ? AND session_id = ?").run(state, greeting ?? null, agentId, sessionId);
39
+ }
40
+ greeting(agentId, sessionId) {
41
+ return this.#store.prepare("SELECT * FROM greetings WHERE agent_id = ? AND session_id = ?").get(agentId, sessionId);
42
+ }
43
+ addGreeting(agentId, sessionId, senderId, body) {
44
+ this.#store.prepare("INSERT OR IGNORE INTO greetings (agent_id, session_id, sender_id, body, received_at) VALUES (?, ?, ?, ?, ?)").run(agentId, sessionId, senderId, body, Date.now());
45
+ }
46
+ // One that fails its checks is kept as a fact with no text, so a bad frame isn't checked again at every catch-up.
47
+ rejectGreeting(agentId, sessionId, senderId, why) {
48
+ this.#store.prepare("INSERT OR IGNORE INTO greetings (agent_id, session_id, sender_id, verdict, verdict_detail, received_at) VALUES (?, ?, ?, 'rejected', ?, ?)").run(agentId, sessionId, senderId, why, Date.now());
49
+ }
50
+ setVerdict(agentId, sessionId, verdict, detail) {
51
+ this.#store.prepare("UPDATE greetings SET verdict = ?, verdict_detail = ? WHERE agent_id = ? AND session_id = ?").run(verdict, detail, agentId, sessionId);
52
+ }
53
+ unscreened() {
54
+ return this.#store.prepare("SELECT * FROM greetings WHERE verdict IS NULL").all();
55
+ }
56
+ unread(agentId) {
57
+ return this.#store.prepare("SELECT * FROM greetings WHERE agent_id = ? AND read_at IS NULL AND verdict IN ('allow', 'flagged', 'blocked') ORDER BY received_at").all(agentId);
58
+ }
59
+ all(agentId) {
60
+ return this.#store.prepare("SELECT * FROM greetings WHERE agent_id = ? AND verdict IN ('allow', 'flagged', 'blocked') ORDER BY received_at").all(agentId);
61
+ }
62
+ markRead(agentId, sessionId) {
63
+ this.#store.prepare("UPDATE greetings SET read_at = ? WHERE agent_id = ? AND session_id = ? AND read_at IS NULL").run(Date.now(), agentId, sessionId);
64
+ }
65
+ }
@@ -0,0 +1,112 @@
1
+ import type { Store } from "./store.ts";
2
+ export interface OwnedRow {
3
+ channel_id: Uint8Array;
4
+ agent_id: Uint8Array;
5
+ ed_seed: Uint8Array;
6
+ pq_seed: Uint8Array;
7
+ x25519_secret: Uint8Array;
8
+ mlkem_seed: Uint8Array;
9
+ }
10
+ export type FollowState = "active" | "pending" | "refused" | "ejected" | "left";
11
+ export interface FollowRow {
12
+ agent_id: Uint8Array;
13
+ channel_id: Uint8Array;
14
+ record: string;
15
+ state: FollowState;
16
+ x25519_secret: Uint8Array | null;
17
+ mlkem_seed: Uint8Array | null;
18
+ x25519_public: Uint8Array | null;
19
+ mlkem_public: Uint8Array | null;
20
+ info: string;
21
+ info_revision: number;
22
+ delivery: "follow" | "pull";
23
+ screen_bodies: "read" | "arrival";
24
+ position: number;
25
+ high: number;
26
+ first_held: number;
27
+ tip: number;
28
+ aged_out: number;
29
+ readers: number | null;
30
+ roster: string | null;
31
+ roster_revision: number;
32
+ roster_hash: Uint8Array | null;
33
+ }
34
+ export type Verdict = "pending" | "allow" | "flagged" | "blocked";
35
+ export interface PostRow {
36
+ position: number;
37
+ author_id: Uint8Array | null;
38
+ author_name: string | null;
39
+ author_seq: number | null;
40
+ generation: number | null;
41
+ published_at: number | null;
42
+ title: Uint8Array | null;
43
+ body: Uint8Array | null;
44
+ state: "unread" | "read" | "blocked" | "unopenable" | "refused";
45
+ title_verdict: Verdict;
46
+ body_verdict: Verdict;
47
+ title_detail?: string | null;
48
+ body_detail?: string | null;
49
+ }
50
+ export interface GapRow {
51
+ position: number;
52
+ first_seen: number;
53
+ state: "missing" | "lost";
54
+ }
55
+ export interface LogRow {
56
+ author_seq: number;
57
+ title: Uint8Array | null;
58
+ body: Uint8Array | null;
59
+ wire: string;
60
+ position: number | null;
61
+ }
62
+ type FollowProgress = Partial<Pick<FollowRow, "position" | "high" | "first_held" | "tip" | "readers" | "state" | "info" | "info_revision" | "delivery" | "screen_bodies" | "roster" | "roster_revision" | "roster_hash">>;
63
+ export declare class ChannelStore {
64
+ #private;
65
+ constructor(store: Store);
66
+ transaction<T>(work: () => T): T;
67
+ insertOwned(row: OwnedRow): void;
68
+ owned(channel: Uint8Array): OwnedRow | undefined;
69
+ forgetCreated(agent: Uint8Array, channel: Uint8Array): void;
70
+ follow(agent: Uint8Array, channel: Uint8Array): FollowRow | undefined;
71
+ follows(agent: Uint8Array): FollowRow[];
72
+ putFollow(row: Pick<FollowRow, "agent_id" | "channel_id" | "record" | "state" | "x25519_secret" | "mlkem_seed" | "x25519_public" | "mlkem_public" | "info" | "info_revision">): void;
73
+ updateFollow(agent: Uint8Array, channel: Uint8Array, changes: FollowProgress): void;
74
+ addAgedOut(agent: Uint8Array, channel: Uint8Array, count: number): void;
75
+ putKey(agent: Uint8Array, channel: Uint8Array, generation: number, key: Uint8Array): void;
76
+ key(agent: Uint8Array, channel: Uint8Array, generation: number): Uint8Array | undefined;
77
+ highestKey(agent: Uint8Array, channel: Uint8Array): number;
78
+ addRosterMember(agent: Uint8Array, channel: Uint8Array, generation: number, member: Uint8Array): void;
79
+ wasOnRoster(agent: Uint8Array, channel: Uint8Array, generation: number, member: Uint8Array): boolean;
80
+ hasPost(agent: Uint8Array, channel: Uint8Array, position: number): boolean;
81
+ authorSeqTaken(agent: Uint8Array, channel: Uint8Array, author: Uint8Array, seq: number, position: number): boolean;
82
+ highestGenerationBefore(agent: Uint8Array, channel: Uint8Array, position: number): number;
83
+ insertPost(agent: Uint8Array, channel: Uint8Array, post: Omit<PostRow, never>): void;
84
+ post(agent: Uint8Array, channel: Uint8Array, position: number): PostRow | undefined;
85
+ unread(agent: Uint8Array, channel: Uint8Array, limit: number): PostRow[];
86
+ history(agent: Uint8Array, channel: Uint8Array, after: number, limit: number): PostRow[];
87
+ needingArrivalScreen(agent: Uint8Array, channel: Uint8Array, bodiesToo: boolean, limit: number): PostRow[];
88
+ unreadCount(agent: Uint8Array, channel: Uint8Array): number;
89
+ setVerdict(agent: Uint8Array, channel: Uint8Array, position: number, part: "title" | "body", verdict: Verdict, detail: string): void;
90
+ blockPost(agent: Uint8Array, channel: Uint8Array, position: number): void;
91
+ markRead(agent: Uint8Array, channel: Uint8Array, positions: readonly number[]): void;
92
+ prune(agent: Uint8Array, channel: Uint8Array, olderThan: number): void;
93
+ gaps(agent: Uint8Array, channel: Uint8Array): GapRow[];
94
+ putGap(agent: Uint8Array, channel: Uint8Array, position: number, firstSeen: number): void;
95
+ markGapLost(agent: Uint8Array, channel: Uint8Array, position: number): void;
96
+ deleteGap(agent: Uint8Array, channel: Uint8Array, position: number): void;
97
+ addNotice(agent: Uint8Array, channel: Uint8Array, text: string): void;
98
+ notices(agent: Uint8Array, channel: Uint8Array): {
99
+ id: number;
100
+ text: string;
101
+ }[];
102
+ deleteNotices(ids: readonly number[]): void;
103
+ nextAuthorSeq(agent: Uint8Array, channel: Uint8Array): number;
104
+ addLog(agent: Uint8Array, channel: Uint8Array, seq: number, title: Uint8Array, body: Uint8Array, wire: string): void;
105
+ setLogWire(agent: Uint8Array, channel: Uint8Array, seq: number, wire: string): void;
106
+ landLog(agent: Uint8Array, channel: Uint8Array, seq: number, position: number, ack: string): void;
107
+ deleteLog(agent: Uint8Array, channel: Uint8Array, seq: number): void;
108
+ waitingLog(agent: Uint8Array, channel: Uint8Array): LogRow[];
109
+ logOwnsPosition(agent: Uint8Array, channel: Uint8Array, position: number): boolean;
110
+ markLostTold(agent: Uint8Array, channel: Uint8Array, position: number): boolean;
111
+ }
112
+ export {};