@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.
- package/.claude-plugin/marketplace.json +15 -0
- package/README.md +107 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +602 -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 +82 -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 +513 -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 +147 -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 +62 -0
- package/dist/daemon/reach.js +204 -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 +189 -0
- package/dist/daemon/store.js +477 -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 +429 -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 +34 -0
- package/dist/hermes-bridge.js +223 -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 +846 -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 +160 -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 +259 -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 +1066 -0
- package/hermes/plugin/plugin.yaml +30 -0
- package/hermes/skills/cello-bridge-setup/SKILL.md +48 -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
package/dist/commands.js
DELETED
|
@@ -1,1544 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI command implementations for the `cello` binary.
|
|
3
|
-
*/
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import { CO_OWNERSHIP_NOTE } from "@cello-protocol/protocol-types";
|
|
7
|
-
import { screenerState, screenerModelDir, runtimeAvailable } from "@cello-protocol/gateway";
|
|
8
|
-
import { DOWNLOAD_MB } from "./screener-commands.js";
|
|
9
|
-
import { replaySelectedAgent } from "./parity-commands.js";
|
|
10
|
-
import { connectOrStart, connectToDaemon, getDaemonIpcEndpoint, readLock, removeLock,
|
|
11
|
-
// isProcessAlive may NEVER answer "does a daemon exist?" — a pid can be dead, or reused by an
|
|
12
|
-
// unrelated process. The kernel's lock is the only thing that knows that, and every EXISTENCE
|
|
13
|
-
// decision in this file still goes through probeSingletonLock.
|
|
14
|
-
//
|
|
15
|
-
// DOD-LOGOUT-EXIT-1 imports it for the one question it CAN answer: "is this specific pid, which
|
|
16
|
-
// was alive when I told it to stop, gone yet?" That is a non-existence check layered ON TOP of
|
|
17
|
-
// the lock, never instead of it, and being wrong fails safe (logout reports "did not complete"
|
|
18
|
-
// instead of claiming a stop that did not happen). See `daemonGone`.
|
|
19
|
-
isProcessAlive, probeSingletonLock, SINGLETON_LOCK_FILENAME, noAgentsGuidance, } from "@cello-protocol/daemon";
|
|
20
|
-
/**
|
|
21
|
-
* Open an IPC connection, run `fn`, and ALWAYS close it.
|
|
22
|
-
*
|
|
23
|
-
* The close belongs in a `finally`, never after the send. The daemon enforces IPC_CONNECTION_LIMIT,
|
|
24
|
-
* so a connection is a BOUNDED resource: a `client.close()` written after `client.send()` inside a
|
|
25
|
-
* try is SKIPPED on any throw, and each failed command leaks a socket the daemon never reclaims.
|
|
26
|
-
* Leak enough and it refuses new connections — a failure whose symptom looks nothing like its cause.
|
|
27
|
-
*
|
|
28
|
-
* Every single-call command goes through this. The three that cannot are `login` (the connection is
|
|
29
|
-
* created by connectOrStart and handed to us), `logout` (it must outlive the send to poll for death),
|
|
30
|
-
* and `daemonGone` (it races the connect against a timeout). Each closes in a `finally` or reaps the
|
|
31
|
-
* abandoned promise explicitly — see them. Any NEW command that reaches for connectToDaemon directly
|
|
32
|
-
* is reintroducing the leak.
|
|
33
|
-
*/
|
|
34
|
-
async function withIpc(socketPath, fn) {
|
|
35
|
-
const client = await connectToDaemon(socketPath);
|
|
36
|
-
try {
|
|
37
|
-
return await fn(client);
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
client.close();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* withIpc for an AGENT-SCOPED verb: the daemon's current agent is per-connection, so a fresh CLI
|
|
45
|
-
* connection must replay the `cello use-agent` selection first, by the same rule as every parity
|
|
46
|
-
* command. A refusal comes back as the `{ ok: false, reason, guidance }` these verbs already print.
|
|
47
|
-
*/
|
|
48
|
-
async function withAgentIpc(celloDir, socketPath, fn) {
|
|
49
|
-
return withIpc(socketPath, async (client) => {
|
|
50
|
-
await client.send("ipc.connect", { clientType: "cli" });
|
|
51
|
-
const refused = await replaySelectedAgent(client, celloDir);
|
|
52
|
-
if (refused)
|
|
53
|
-
return (refused.daemonReply ?? { ok: false, reason: refused.reason, guidance: refused.guidance });
|
|
54
|
-
return fn(client);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* M8C-LOGINSTART-1 CORE: bring every loaded agent online. Called by `cello login` after the daemon
|
|
59
|
-
* is up. login ALWAYS completes — a per-agent start failure is COLLECTED, never thrown, so one bad
|
|
60
|
-
* agent can't abort login. `cello_start_agent` is idempotent, so re-login is safe. The per-agent
|
|
61
|
-
* `autoStart: false` opt-out is PARKED until the M9 config store lands (D14).
|
|
62
|
-
* Lives here rather than inline in login() so it is unit-testable against an in-process daemon.
|
|
63
|
-
*/
|
|
64
|
-
export async function autoStartAllAgents(client) {
|
|
65
|
-
const started = [];
|
|
66
|
-
const failed = [];
|
|
67
|
-
const listRes = (await client.send("cello_list_agents"));
|
|
68
|
-
for (const a of listRes.agents ?? []) {
|
|
69
|
-
try {
|
|
70
|
-
const r = (await client.send("cello_start_agent", { name: a.name }));
|
|
71
|
-
if (r.ok)
|
|
72
|
-
started.push(a.name);
|
|
73
|
-
else
|
|
74
|
-
failed.push({ name: a.name, reason: r.reason ?? "unknown" });
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
failed.push({ name: a.name, reason: err instanceof Error ? err.message : String(err) });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// M16 033-CHANNELVIEW: channels are NOT agents, so cello_list_agents no longer returns them — they
|
|
81
|
-
// are listed on cello_status under `channels`. They must still be brought online (a channel
|
|
82
|
-
// publishes and holds keys), so start each here and report them under their OWN heading. A channel
|
|
83
|
-
// is started exactly like an agent; only what is SHOWN differs, and no online doorbell rings for it.
|
|
84
|
-
const started_channels = [];
|
|
85
|
-
// A channel that fails to start is collected, never swallowed (reviewer MEDIUM) — and never
|
|
86
|
-
// miscounted as a failed AGENT, because a channel is not an agent. Its own list, its own clause.
|
|
87
|
-
const failed_channels = [];
|
|
88
|
-
const statusRes = (await client.send("cello_status"));
|
|
89
|
-
for (const c of statusRes.channels ?? []) {
|
|
90
|
-
try {
|
|
91
|
-
const r = (await client.send("cello_start_agent", { name: c.name }));
|
|
92
|
-
if (r.ok)
|
|
93
|
-
started_channels.push(c.name);
|
|
94
|
-
else
|
|
95
|
-
failed_channels.push({ name: c.name, reason: r.reason ?? "unknown" });
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
failed_channels.push({ name: c.name, reason: err instanceof Error ? err.message : String(err) });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return { started, failed, started_channels, failed_channels };
|
|
102
|
-
}
|
|
103
|
-
export async function login(celloDir, daemonBin, logger) {
|
|
104
|
-
try {
|
|
105
|
-
const result = await connectOrStart(celloDir, logger, daemonBin);
|
|
106
|
-
// M8C-LOGINSTART-1: bring every registered agent online, then report. Never let this abort login.
|
|
107
|
-
const head = result.alreadyRunning ? "Daemon already running." : "Daemon started.";
|
|
108
|
-
let summary;
|
|
109
|
-
try {
|
|
110
|
-
await result.client.send("ipc.connect", { clientType: "cli" });
|
|
111
|
-
summary = formatLoginSummary(await autoStartAllAgents(result.client));
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
// Auto-start is best-effort — the daemon IS up. Surface the reason but complete login (exit 0).
|
|
115
|
-
summary = `Agents were not auto-started (${err instanceof Error ? err.message : String(err)}); run 'cello status' and start them with cello_use_agent.`;
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
result.client.close();
|
|
119
|
-
}
|
|
120
|
-
// DOD-M9C-SCREENINSTALL-1: the screener line, EVERY login until it is installed.
|
|
121
|
-
//
|
|
122
|
-
// It repeats deliberately. An operator who skipped it once has postponed, not decided, and a
|
|
123
|
-
// one-time notice at the end of a busy install is indistinguishable from no notice at all. It
|
|
124
|
-
// rides on `guidance` (stderr), so a script parsing login's stdout is unaffected.
|
|
125
|
-
const screener = await screenerLoginLine();
|
|
126
|
-
return { exitCode: 0, output: `${head}\n${summary}`, ...(screener ? { guidance: screener } : {}) };
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
130
|
-
return { exitCode: 1, output: `Failed to start daemon: ${message}` };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* One line when the classifier is not installed-and-verified, empty when it is.
|
|
135
|
-
*
|
|
136
|
-
* Never throws and never blocks login: a screener check that could break sign-in would be a worse
|
|
137
|
-
* defect than the one it reports.
|
|
138
|
-
*/
|
|
139
|
-
export async function screenerLoginLine(stateImpl) {
|
|
140
|
-
try {
|
|
141
|
-
const status = stateImpl
|
|
142
|
-
? await stateImpl()
|
|
143
|
-
: await screenerState({ dir: screenerModelDir(), runtimePresent: await runtimeAvailable() });
|
|
144
|
-
if (status.state === "ready")
|
|
145
|
-
return "";
|
|
146
|
-
if (status.state === "broken") {
|
|
147
|
-
return `Screening: the classifier is BROKEN: ${status.problem ?? "unknown fault"}. Fix it with: cello screener install --repair`;
|
|
148
|
-
}
|
|
149
|
-
// The size comes from the command that quotes it, so the two cannot drift apart.
|
|
150
|
-
return `Screening: 1 of 2 layers active. Install the classifier (~${DOWNLOAD_MB} MB): cello screener install`;
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
// Silence here means login stops nagging because the CHECK broke, which is indistinguishable
|
|
154
|
-
// from the classifier being installed. Say what happened instead; never throw, because a
|
|
155
|
-
// screener check that breaks sign-in is worse than the gap it reports.
|
|
156
|
-
return `Screening: state UNKNOWN — the screener check failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* M8C-LOGINSTART-1: compose the operator-facing auto-start summary — every failed agent enumerated
|
|
161
|
-
* by name + reason. Pure + exported so the enumeration string is directly testable.
|
|
162
|
-
*/
|
|
163
|
-
export function formatLoginSummary(result) {
|
|
164
|
-
const parts = [];
|
|
165
|
-
if (result.started.length > 0)
|
|
166
|
-
parts.push(`Started ${result.started.length} agent(s): ${result.started.join(", ")}.`);
|
|
167
|
-
// M16 033-CHANNELVIEW: channels get their own clause — an operator used to read "Started 6
|
|
168
|
-
// agent(s)" when four of the six were channels. Omitted when zero, so it never appears empty.
|
|
169
|
-
const startedChannels = result.started_channels ?? [];
|
|
170
|
-
if (startedChannels.length > 0)
|
|
171
|
-
parts.push(`Started ${startedChannels.length} channel(s): ${startedChannels.join(", ")}.`);
|
|
172
|
-
// Reviewer MEDIUM: a channel that failed to start is named here, mirroring the agent failure
|
|
173
|
-
// clause below — never swallowed, never silently absent from the summary.
|
|
174
|
-
const failedChannels = result.failed_channels ?? [];
|
|
175
|
-
if (failedChannels.length > 0) {
|
|
176
|
-
parts.push(`${failedChannels.length} channel(s) failed to start: ${failedChannels.map((f) => `${f.name} (${f.reason})`).join(", ")}. ` +
|
|
177
|
-
"Run 'cello status' to check.");
|
|
178
|
-
}
|
|
179
|
-
if (result.failed.length > 0) {
|
|
180
|
-
parts.push(`${result.failed.length} agent(s) failed to start: ${result.failed.map((f) => `${f.name} (${f.reason})`).join(", ")}. ` +
|
|
181
|
-
"Run 'cello status' to check; a failed agent stays offline and can be retried with cello_use_agent.");
|
|
182
|
-
}
|
|
183
|
-
// The empty case is usually a new operator's first screen, so it names the next two commands
|
|
184
|
-
// and what the first registration asks of them. See onboarding-guidance.ts.
|
|
185
|
-
if (result.started.length === 0 && result.failed.length === 0 && startedChannels.length === 0 && failedChannels.length === 0)
|
|
186
|
-
parts.push(noAgentsGuidance());
|
|
187
|
-
return parts.join("\n");
|
|
188
|
-
}
|
|
189
|
-
// DOD-LOGOUT-WAIT-1: how long logout waits for the daemon to actually die after acknowledging
|
|
190
|
-
// the shutdown request, and how often it re-checks. A daemon closing SQLCipher + libp2p takes
|
|
191
|
-
// real time; 5 s is generous headroom, and a daemon still alive past it is genuinely stuck.
|
|
192
|
-
const LOGOUT_WAIT_TIMEOUT_MS = 5_000;
|
|
193
|
-
const LOGOUT_WAIT_POLL_MS = 50;
|
|
194
|
-
/**
|
|
195
|
-
* DOD-LOGOUT-WAIT-1: is the daemon actually GONE — judged by the same evidence `connectOrStart`
|
|
196
|
-
* consults, so a completed logout GUARANTEES the next login starts fresh.
|
|
197
|
-
*
|
|
198
|
-
* Two facts, both required, neither of them a file:
|
|
199
|
-
* 1. nothing answers on the socket, and
|
|
200
|
-
* 2. no process holds the singleton lock.
|
|
201
|
-
*
|
|
202
|
-
* (1) alone is not enough: a daemon wedged mid-shutdown may have closed its IPC server while still
|
|
203
|
-
* holding the DB. (2) alone is not enough either, because a pre-singleton-lock daemon holds no
|
|
204
|
-
* singleton lock at all — for those, "free" says nothing about whether it is alive, and only the
|
|
205
|
-
* socket can tell us. Together they are exactly the conditions under which the next daemon can
|
|
206
|
-
* safely start.
|
|
207
|
-
*
|
|
208
|
-
* Neither `isProcessAlive(lock.pid)` nor the lock FILE may be SUBSTITUTED for these two facts: a pid
|
|
209
|
-
* can be reused, and a lock file can be deleted by anyone.
|
|
210
|
-
*
|
|
211
|
-
* DOD-LOGOUT-EXIT-1 adds a THIRD, and the distinction from the paragraph above is the whole point:
|
|
212
|
-
* `livePid` is an ADDITIONAL requirement, never a substitute. Both facts above are released inside
|
|
213
|
-
* `stop()`'s `finally`, BEFORE the daemon actually ends — that gap is precisely how logout came to
|
|
214
|
-
* report "Daemon stopped." over a process still holding a directory connection. So when we know a
|
|
215
|
-
* pid that was alive at the moment we asked it to stop, it must also be gone.
|
|
216
|
-
*
|
|
217
|
-
* The pid-reuse objection does not apply to this use: the window is the 5 s logout wait, and being
|
|
218
|
-
* wrong here fails SAFE — an unrelated process inheriting the pid makes logout report "did not
|
|
219
|
-
* complete" (exit 1, loud, actionable) rather than claim a stop that did not happen.
|
|
220
|
-
*/
|
|
221
|
-
async function daemonGone(celloDir, socketPath, logger, livePid) {
|
|
222
|
-
// Checked FIRST — it is the cheapest, and it is the only one of the three that is about the
|
|
223
|
-
// process rather than about a handle the process has already let go of.
|
|
224
|
-
if (livePid !== undefined && isProcessAlive(livePid))
|
|
225
|
-
return false;
|
|
226
|
-
// connectToDaemon has no connect timeout of its own — bound the probe so a pathological hang
|
|
227
|
-
// cannot stall the poll loop past its deadline. On the expected path the socket is already gone,
|
|
228
|
-
// so this fails fast (ENOENT/ECONNREFUSED).
|
|
229
|
-
//
|
|
230
|
-
// The race LOSER must still be closed. If the timeout wins, the connect promise is abandoned — but
|
|
231
|
-
// it can still resolve afterwards into a live IpcClient that nobody holds and nobody closes. This
|
|
232
|
-
// runs in a POLL LOOP inside one process, against the daemon's bounded IPC_CONNECTION_LIMIT, so
|
|
233
|
-
// those accumulate. Of every connect in this file it is the only one that can genuinely exhaust the
|
|
234
|
-
// pool — everywhere else the process exits and the OS reclaims the fd. So: keep the promise, and
|
|
235
|
-
// close whatever it eventually yields.
|
|
236
|
-
const connecting = connectToDaemon(socketPath);
|
|
237
|
-
connecting.then((late) => { try {
|
|
238
|
-
late.close();
|
|
239
|
-
}
|
|
240
|
-
catch { /* already closed by the winner below */ } }, () => { });
|
|
241
|
-
try {
|
|
242
|
-
const probe = await Promise.race([
|
|
243
|
-
connecting,
|
|
244
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("probe_timeout")), 500)),
|
|
245
|
-
]);
|
|
246
|
-
probe.close();
|
|
247
|
-
return false; // something still answers — the daemon is up
|
|
248
|
-
}
|
|
249
|
-
catch {
|
|
250
|
-
// Nothing answers. Now make sure the process is really gone and not merely deaf: a daemon that
|
|
251
|
-
// still holds the kernel lock is still alive, and the next login would refuse to start beside it.
|
|
252
|
-
return probeSingletonLock(celloDir, logger) === "free";
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
export async function logout(celloDir, onProgress,
|
|
256
|
-
// Injectable bounds so the timeout path is testable without a 5 s wait. Production (the bin)
|
|
257
|
-
// passes nothing and gets the named defaults.
|
|
258
|
-
waitOpts) {
|
|
259
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
260
|
-
const noopLogger = { debug() { }, info() { }, warn() { }, error() { } };
|
|
261
|
-
const timeoutMs = waitOpts?.timeoutMs ?? LOGOUT_WAIT_TIMEOUT_MS;
|
|
262
|
-
const pollMs = waitOpts?.pollMs ?? LOGOUT_WAIT_POLL_MS;
|
|
263
|
-
// The socket path is DETERMINISTIC. `daemon.lock`'s copy of it is metadata, and metadata is not
|
|
264
|
-
// to be trusted here.
|
|
265
|
-
const socketPath = getDaemonIpcEndpoint(celloDir);
|
|
266
|
-
const lock = await readLock(lockFilePath);
|
|
267
|
-
// DOD-SINGLE-DAEMON-1 (AC4) — the lock file does not get to decide whether a daemon exists.
|
|
268
|
-
//
|
|
269
|
-
// Never short-circuit on `if (!lock) return "No daemon running."`. That is a KILL SWITCH REPORTING
|
|
270
|
-
// SUCCESS WITHOUT DOING ANYTHING, and the state that triggers it is real: an exiting orphan unlinks
|
|
271
|
-
// a HEALTHY daemon's lock (so does `rm ~/.cello/daemon.lock`). The operator then runs `cello logout`
|
|
272
|
-
// to stop their agent, is told it was never running, and walks away — while the daemon is still
|
|
273
|
-
// online, still on the directory, still extending the hash chain. A kill switch may not lie.
|
|
274
|
-
//
|
|
275
|
-
// So we ask the daemon itself. If something ANSWERS on the socket, a daemon is running — that is
|
|
276
|
-
// the strongest evidence available, it needs no file, and it holds even for a pre-singleton-lock
|
|
277
|
-
// daemon, which holds no singleton lock at all.
|
|
278
|
-
let client;
|
|
279
|
-
try {
|
|
280
|
-
client = await connectToDaemon(socketPath);
|
|
281
|
-
}
|
|
282
|
-
catch (err) {
|
|
283
|
-
// Nothing answered. Now the kernel decides — not the pid in the JSON, which may be dead, or
|
|
284
|
-
// REUSED by an unrelated process (in which case `isProcessAlive` says "alive" forever).
|
|
285
|
-
const probe = probeSingletonLock(celloDir, noopLogger);
|
|
286
|
-
if (probe === "held") {
|
|
287
|
-
// A daemon holds the lock but will not talk to us. We have NOT stopped it, and must not imply
|
|
288
|
-
// otherwise. Point at the authoritative holder rather than a pid we did not verify.
|
|
289
|
-
const named = lock ? ` (daemon.lock names pid ${lock.pid}, which may be stale)` : "";
|
|
290
|
-
return {
|
|
291
|
-
exitCode: 1,
|
|
292
|
-
output: `A daemon is running${named} and holds the singleton lock, but is not answering on ` +
|
|
293
|
-
`${socketPath} (${err instanceof Error ? err.message : String(err)}). It has NOT been ` +
|
|
294
|
-
`stopped. Find the process that holds the lock with \`lsof ${join(celloDir, SINGLETON_LOCK_FILENAME)}\`, ` +
|
|
295
|
-
"stop it, then re-run 'cello logout' to clean up.",
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
if (probe === "unknown") {
|
|
299
|
-
// We could not ask. Reporting "no daemon running" on a guess is the whole failure mode.
|
|
300
|
-
return {
|
|
301
|
-
exitCode: 1,
|
|
302
|
-
output: `Could not determine whether a daemon is running: the singleton lock at ` +
|
|
303
|
-
`${join(celloDir, SINGLETON_LOCK_FILENAME)} could not be checked. Refusing to report a ` +
|
|
304
|
-
"daemon stopped without proof.",
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
// probe === "free": nothing holds the lock and nothing answers. There is no daemon.
|
|
308
|
-
if (!lock) {
|
|
309
|
-
return { exitCode: 0, output: "No daemon running." };
|
|
310
|
-
}
|
|
311
|
-
// DOD-LOGOUT-WAIT-1: only CLAIM the removal when it actually happened — removeLock swallows
|
|
312
|
-
// non-ENOENT errors into a (here discarded) warn, and printing "Removed" for a lock still on
|
|
313
|
-
// disk would be this unit's own lie in miniature.
|
|
314
|
-
const removed = await removeLock(lockFilePath, noopLogger)
|
|
315
|
-
.then(async () => (await readLock(lockFilePath)) === null)
|
|
316
|
-
.catch(() => false);
|
|
317
|
-
return {
|
|
318
|
-
exitCode: 0,
|
|
319
|
-
output: removed
|
|
320
|
-
? "No daemon running. (Removed a stale daemon.lock — no daemon holds the singleton lock.)"
|
|
321
|
-
: `No daemon running. (A stale daemon.lock remains at ${lockFilePath} and could not be removed — check its permissions.)`,
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
try {
|
|
325
|
-
await client.send("shutdown");
|
|
326
|
-
}
|
|
327
|
-
catch (err) {
|
|
328
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
329
|
-
return { exitCode: 1, output: `Failed to stop daemon: ${message}` };
|
|
330
|
-
}
|
|
331
|
-
finally {
|
|
332
|
-
// In the `finally`, not after the send: a throw from `shutdown` must not leak the connection.
|
|
333
|
-
client.close();
|
|
334
|
-
}
|
|
335
|
-
// The request is in — tell the operator NOW, then report "stopped" only when it is true.
|
|
336
|
-
onProgress?.("Shutting down the daemon…");
|
|
337
|
-
// DOD-LOGOUT-WAIT-1: do NOT return the instant the shutdown request is WRITTEN. That leaves a
|
|
338
|
-
// window where `cello logout && cello login` finds the daemon mid-death — connectOrStart sees a
|
|
339
|
-
// live pid + connectable socket and prints "Daemon already running.", leaving the operator logged
|
|
340
|
-
// out while being told otherwise. Wait until the daemon is genuinely gone; "Daemon stopped." for a
|
|
341
|
-
// daemon that is still running is the same class of lie as a success log on a failed send
|
|
342
|
-
// (DOD-SENDRAW-1).
|
|
343
|
-
// DOD-LOGOUT-EXIT-1: the pid to hold the shutdown to. Taken from the lock read BEFORE the
|
|
344
|
-
// shutdown was sent, and only trusted if it was actually alive then — a stale lock naming a dead
|
|
345
|
-
// (or never-ours) pid must not make every logout wait out the full timeout. `undefined` here
|
|
346
|
-
// means we have no process-level evidence to demand, and the two handle facts stand alone, which
|
|
347
|
-
// is the pre-singleton-lock daemon's case.
|
|
348
|
-
//
|
|
349
|
-
// `lock.pid !== process.pid` is NOT a test accommodation: an IN-PROCESS daemon (an embedder, or
|
|
350
|
-
// vitest) writes OUR pid into the lock, and requiring it to exit would mean requiring the caller
|
|
351
|
-
// to exit before its own logout returns — never satisfiable, so every such logout would burn the
|
|
352
|
-
// full timeout and then report a failure that did not happen. For that daemon "the process
|
|
353
|
-
// ended" is not the right question; the handles are all there is, which is the pre-existing
|
|
354
|
-
// contract. The defect this unit fixes is only reachable when the daemon is a SEPARATE process.
|
|
355
|
-
const pidToOutlive = lock && lock.pid !== process.pid && isProcessAlive(lock.pid) ? lock.pid : undefined;
|
|
356
|
-
const deadline = Date.now() + timeoutMs;
|
|
357
|
-
while (Date.now() < deadline) {
|
|
358
|
-
if (await daemonGone(celloDir, socketPath, noopLogger, pidToOutlive)) {
|
|
359
|
-
return { exitCode: 0, output: "Daemon stopped." };
|
|
360
|
-
}
|
|
361
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
362
|
-
}
|
|
363
|
-
const who = lock ? `pid ${lock.pid}, ` : "";
|
|
364
|
-
return {
|
|
365
|
-
exitCode: 1,
|
|
366
|
-
output: `Daemon shutdown did not complete within ${timeoutMs / 1000}s ` +
|
|
367
|
-
`(${who}socket ${socketPath}). The daemon acknowledged the request but is ` +
|
|
368
|
-
`still running — it may be stuck closing sessions or its database. Check 'cello status'; ` +
|
|
369
|
-
`if it never exits, find it with \`lsof ${join(celloDir, SINGLETON_LOCK_FILENAME)}\`, stop it, ` +
|
|
370
|
-
"and re-run 'cello logout' to clean up.",
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* register(celloDir, agent, token):
|
|
375
|
-
* - Refuse any token, before the daemon is asked: registration tokens are retired.
|
|
376
|
-
* - Read the lock file to find the daemon's socket (the daemon must be running).
|
|
377
|
-
* - With no token, pair this device first if it is not yet paired: print the approve link and
|
|
378
|
-
* code, then wait for the approval.
|
|
379
|
-
* - Send 'cello_register'. The daemon runs keygen and the FROST DKG with the directory, then
|
|
380
|
-
* persists the agent's key material and registration state.
|
|
381
|
-
* - Print structured JSON; exit 0 on success, 1 on failure.
|
|
382
|
-
*/
|
|
383
|
-
/**
|
|
384
|
-
* The OS opener for the approve link, or null where there is no browser to open: a Linux machine
|
|
385
|
-
* with no display, any session over SSH, or anywhere CELLO_NO_BROWSER is set non-empty (test
|
|
386
|
-
* harnesses). Opening is best effort and never blocks the wait.
|
|
387
|
-
*/
|
|
388
|
-
export function browserOpener(platform = process.platform, env = process.env) {
|
|
389
|
-
// Test harnesses register many agents and must not fill the operator's screen with pairing pages.
|
|
390
|
-
if (env["CELLO_NO_BROWSER"])
|
|
391
|
-
return null;
|
|
392
|
-
if (platform === "darwin")
|
|
393
|
-
return "open";
|
|
394
|
-
if (platform === "linux" && (env["DISPLAY"] || env["WAYLAND_DISPLAY"]) && !env["SSH_CONNECTION"])
|
|
395
|
-
return "xdg-open";
|
|
396
|
-
return null;
|
|
397
|
-
}
|
|
398
|
-
function openBrowser(url) {
|
|
399
|
-
const cmd = browserOpener();
|
|
400
|
-
if (!cmd)
|
|
401
|
-
return;
|
|
402
|
-
try {
|
|
403
|
-
const child = spawn(cmd, [url], { detached: true, stdio: "ignore" });
|
|
404
|
-
child.on("error", () => { });
|
|
405
|
-
child.unref();
|
|
406
|
-
}
|
|
407
|
-
catch {
|
|
408
|
-
// Best effort: the link is already printed.
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
/** `KQ7M4TXP` → `KQ7M-4TXP`, the way the approval page shows it. */
|
|
412
|
-
function displayCode(code) {
|
|
413
|
-
return code.length === 8 ? `${code.slice(0, 4)}-${code.slice(4)}` : code;
|
|
414
|
-
}
|
|
415
|
-
export async function register(celloDir, agent, token, onProgress) {
|
|
416
|
-
// Failures print JSON on stdout, with the prose in `guidance` on stderr, so a script that parses
|
|
417
|
-
// the output reads the reason instead of a parse error.
|
|
418
|
-
const fail = (reason, guidance) => ({
|
|
419
|
-
exitCode: 1,
|
|
420
|
-
output: JSON.stringify({ ok: false, reason, guidance }, null, 2),
|
|
421
|
-
guidance,
|
|
422
|
-
});
|
|
423
|
-
if (!agent) {
|
|
424
|
-
return fail("missing_agent_name", "You didn't name an agent to register. Usage: cello register-agent <agent>. See your agents with 'cello status'.");
|
|
425
|
-
}
|
|
426
|
-
// Every registration pairs this device; no directory accepts a token.
|
|
427
|
-
if (token !== "") {
|
|
428
|
-
return fail("token_retired", "CELLO no longer uses registration tokens. Run 'cello register-agent <name>' with no token; the first time on this machine it shows a link to approve this device.");
|
|
429
|
-
}
|
|
430
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
431
|
-
const lock = await readLock(lockFilePath);
|
|
432
|
-
if (!lock) {
|
|
433
|
-
return fail("daemon_not_running", "No daemon running. Run 'cello login' first, then retry registration.");
|
|
434
|
-
}
|
|
435
|
-
try {
|
|
436
|
-
const { result, sharePubkey } = await withIpc(lock.socketPath, async (client) => {
|
|
437
|
-
{
|
|
438
|
-
// This device presents its own credential, pairing first if it has none.
|
|
439
|
-
const start = (await client.send("cello_pair_start"));
|
|
440
|
-
if (!start.ok)
|
|
441
|
-
return { result: start, sharePubkey: undefined };
|
|
442
|
-
if (start.paired === false) {
|
|
443
|
-
onProgress?.(`Open ${start.approve_url} and enter ${displayCode(start.pairing_code ?? "")}`);
|
|
444
|
-
onProgress?.("Approve it there, on this machine or any other. The code expires in 10 minutes. Waiting...");
|
|
445
|
-
openBrowser(start.approve_url ?? "");
|
|
446
|
-
const done = (await client.send("cello_pair_await"));
|
|
447
|
-
if (!done.ok)
|
|
448
|
-
return { result: done, sharePubkey: undefined };
|
|
449
|
-
onProgress?.("This device is paired.");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const reg = (await client.send("cello_register", { agent }));
|
|
453
|
-
if (!reg.ok)
|
|
454
|
-
return { result: reg, sharePubkey: undefined };
|
|
455
|
-
const list = (await client.send("cello_list_agents"));
|
|
456
|
-
return { result: reg, sharePubkey: list.agents?.find((a) => a.name === agent)?.pubkey };
|
|
457
|
-
});
|
|
458
|
-
if (!result.ok) {
|
|
459
|
-
return {
|
|
460
|
-
exitCode: 1,
|
|
461
|
-
output: JSON.stringify({ ok: false, reason: result.reason, guidance: result.guidance }, null, 2),
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
return {
|
|
465
|
-
exitCode: 0,
|
|
466
|
-
output: JSON.stringify({
|
|
467
|
-
ok: true,
|
|
468
|
-
share_this_pubkey: sharePubkey,
|
|
469
|
-
directory_agent_id: result.agent_id,
|
|
470
|
-
directory_primary_pubkey: result.primary_pubkey,
|
|
471
|
-
// Kept, unchanged, for anything that already reads them. They are the directory's record.
|
|
472
|
-
agent_id: result.agent_id,
|
|
473
|
-
primary_pubkey: result.primary_pubkey,
|
|
474
|
-
}, null, 2),
|
|
475
|
-
// M8C-ONBOARD-NEXTSTEP-1: every command output carries the next step + state legibility.
|
|
476
|
-
// Broken onto multiple lines — a dense one-liner buries the three status cues.
|
|
477
|
-
//
|
|
478
|
-
// DOD-M15-CLIJSON-1: on STDERR, not appended to the JSON above. A human in a terminal sees
|
|
479
|
-
// both streams and loses nothing; a script gets parseable output. This text used to make
|
|
480
|
-
// `register-agent` unparseable on its SUCCESS path.
|
|
481
|
-
guidance: `Give this key to others: ${sharePubkey ?? "(run cello agents to see it)"}\n` +
|
|
482
|
-
` • it is the key cello agents lists. directory_primary_pubkey is the directory's own record, not the key to share.\n` +
|
|
483
|
-
`Next: run cello status to confirm '${agent}' is registered.\n` +
|
|
484
|
-
` • it's normal for this to take a minute or two while registration settles.\n` +
|
|
485
|
-
` • ready = the agent shows state 'online' and directory_signaling 'connected'.\n` +
|
|
486
|
-
` • if it stays offline, run cello logout then cello login.`,
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
catch (err) {
|
|
490
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
491
|
-
return fail("register_failed", `Failed to register: ${message}`);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* pairStatus(celloDir): report whether THIS DEVICE is paired — i.e. whether a directory-signed
|
|
496
|
-
* daemon credential has been stored because the owner approved the device. Read-only and
|
|
497
|
-
* non-blocking: it reads the pairing store, never opening, polling or waiting on a pairing, so it is
|
|
498
|
-
* safe to call on every status poll. A hosted host agent uses it as the reliable, non-log signal
|
|
499
|
-
* for "approved but not registered": paired:true plus an agent the directory does not yet know means
|
|
500
|
-
* step 2 ('cello register-agent') can be finished with the stored credential WITHOUT opening a new
|
|
501
|
-
* pairing (which would kill a live code). pending distinguishes "a code is live, still waiting" from
|
|
502
|
-
* "no pairing at all".
|
|
503
|
-
*/
|
|
504
|
-
export async function pairStatus(celloDir) {
|
|
505
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
506
|
-
const lock = await readLock(lockFilePath);
|
|
507
|
-
if (!lock) {
|
|
508
|
-
return {
|
|
509
|
-
exitCode: 1,
|
|
510
|
-
output: JSON.stringify({ ok: false, reason: "daemon_not_running", guidance: "No daemon running. Run 'cello login' first, then retry." }, null, 2),
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
try {
|
|
514
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("cello_pair_status")));
|
|
515
|
-
return { exitCode: 0, output: JSON.stringify(result, null, 2) };
|
|
516
|
-
}
|
|
517
|
-
catch (err) {
|
|
518
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
519
|
-
return {
|
|
520
|
-
exitCode: 1,
|
|
521
|
-
output: JSON.stringify({ ok: false, reason: "pair_status_failed", guidance: `Could not read pairing status: ${message}` }, null, 2),
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* createAgent(celloDir, name):
|
|
527
|
-
* - Connect to the daemon, send 'cello_create_agent' with { name }.
|
|
528
|
-
* - The daemon generates a fresh K_local seed, writes it as an `agents` row in the encrypted DB
|
|
529
|
-
* (PERSIST-002 — no key file), and wires the agent in so it can be registered immediately.
|
|
530
|
-
*/
|
|
531
|
-
export async function createAgent(celloDir, name) {
|
|
532
|
-
if (!name) {
|
|
533
|
-
return { exitCode: 1, output: "Usage: cello create-agent <name> — creates a new local agent identity." };
|
|
534
|
-
}
|
|
535
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
536
|
-
const lock = await readLock(lockFilePath);
|
|
537
|
-
if (!lock) {
|
|
538
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first, then retry create-agent." };
|
|
539
|
-
}
|
|
540
|
-
try {
|
|
541
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("cello_create_agent", { name })));
|
|
542
|
-
if (!result.ok) {
|
|
543
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: result.reason, guidance: result.guidance }, null, 2) };
|
|
544
|
-
}
|
|
545
|
-
return {
|
|
546
|
-
exitCode: 0,
|
|
547
|
-
output: JSON.stringify({ ok: true, name: result.name, pubkey: result.pubkey, agentId: result.agentId }, null, 2),
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
catch (err) {
|
|
551
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
552
|
-
return { exitCode: 1, output: `Failed to create agent: ${message}` };
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* refreshShares(celloDir, name): M8B DOD-REFRESH-1.
|
|
557
|
-
* - Connect to the daemon, send 'cello_refresh_shares' with { agent }.
|
|
558
|
-
* - The daemon runs a proactive share refresh across the consortium: every shareholder rotates its
|
|
559
|
-
* share to a new epoch, the group public key is unchanged, and old-epoch shares no longer sign.
|
|
560
|
-
*/
|
|
561
|
-
export async function refreshShares(celloDir, name) {
|
|
562
|
-
if (!name) {
|
|
563
|
-
return { exitCode: 1, output: "Usage: cello refresh <name> — proactively refresh the agent's threshold shares (new epoch)." };
|
|
564
|
-
}
|
|
565
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
566
|
-
const lock = await readLock(lockFilePath);
|
|
567
|
-
if (!lock) {
|
|
568
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first, then retry refresh." };
|
|
569
|
-
}
|
|
570
|
-
try {
|
|
571
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("cello_refresh_shares", { agent: name })));
|
|
572
|
-
if (!result.ok) {
|
|
573
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: result.reason, guidance: result.guidance }, null, 2) };
|
|
574
|
-
}
|
|
575
|
-
return {
|
|
576
|
-
exitCode: 0,
|
|
577
|
-
output: JSON.stringify({ ok: true, epoch: result.epoch, primary_pubkey: result.primary_pubkey, verifying_shares_digest: result.verifying_shares_digest }, null, 2),
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
catch (err) {
|
|
581
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
582
|
-
return { exitCode: 1, output: `Failed to refresh shares: ${message}` };
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* relayReceipts(celloDir, name): M8B DOD-RELAYSIG-1.
|
|
587
|
-
* - Connect to the daemon, send 'cello_get_relay_receipts' with { agent }.
|
|
588
|
-
* - Returns the agent's durably-stored, signature-verified relay ordering-record receipts.
|
|
589
|
-
*/
|
|
590
|
-
export async function relayReceipts(celloDir, name) {
|
|
591
|
-
if (!name) {
|
|
592
|
-
return { exitCode: 1, output: "Usage: cello relay-receipts <name> — ADVANCED/DEBUG: the per-message proofs a relay signed when it "
|
|
593
|
-
+ "delivered for this agent. For a session's notarized seal, use 'cello sealed-receipt <session-id>'." };
|
|
594
|
-
}
|
|
595
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
596
|
-
const lock = await readLock(lockFilePath);
|
|
597
|
-
if (!lock) {
|
|
598
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first, then retry receipts." };
|
|
599
|
-
}
|
|
600
|
-
try {
|
|
601
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("cello_get_relay_receipts", { agent: name })));
|
|
602
|
-
if (!result.ok) {
|
|
603
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: result.reason, guidance: result.guidance }, null, 2) };
|
|
604
|
-
}
|
|
605
|
-
return { exitCode: 0, output: JSON.stringify({ ok: true, receipts: result.receipts ?? [] }, null, 2) };
|
|
606
|
-
}
|
|
607
|
-
catch (err) {
|
|
608
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
609
|
-
return { exitCode: 1, output: `Failed to get relay receipts: ${message}` };
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* removeAgent(celloDir, name) — CELLO-M7-REMOVE-001 (DOD-REMOVE-1):
|
|
614
|
-
* - Connect to the daemon, send 'cello_remove_agent' with { name }.
|
|
615
|
-
* - The daemon RETIRES the agent (state=retired; row, keys, and history KEPT for accountability) and
|
|
616
|
-
* FREES the human name for reuse. One-way.
|
|
617
|
-
*/
|
|
618
|
-
export async function removeAgent(celloDir, name) {
|
|
619
|
-
if (!name) {
|
|
620
|
-
return { exitCode: 1, output: "Usage: cello remove-agent <name> — retires a local agent (one-way) and frees its name." };
|
|
621
|
-
}
|
|
622
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
623
|
-
const lock = await readLock(lockFilePath);
|
|
624
|
-
if (!lock) {
|
|
625
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first, then retry remove-agent." };
|
|
626
|
-
}
|
|
627
|
-
try {
|
|
628
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("cello_remove_agent", { name })));
|
|
629
|
-
if (!result.ok) {
|
|
630
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: result.reason, guidance: result.guidance }, null, 2) };
|
|
631
|
-
}
|
|
632
|
-
return {
|
|
633
|
-
exitCode: 0,
|
|
634
|
-
output: JSON.stringify({
|
|
635
|
-
ok: true,
|
|
636
|
-
name: result.name,
|
|
637
|
-
agentId: result.agentId,
|
|
638
|
-
oneWay: result.oneWay,
|
|
639
|
-
// DOD-REMOVE-2: whether the signed revocation was recorded at the directory (recorded /
|
|
640
|
-
// deferred — directory unreachable / skipped — never registered). The daemon's guidance
|
|
641
|
-
// carries the actionable detail.
|
|
642
|
-
directoryRevocation: result.directoryRevocation,
|
|
643
|
-
message: result.guidance ?? "Agent retired (one-way). Its identity and history are kept; the name is free to reuse.",
|
|
644
|
-
}, null, 2),
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
catch (err) {
|
|
648
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
649
|
-
return { exitCode: 1, output: `Failed to remove agent: ${message}` };
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
export async function status(celloDir) {
|
|
653
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
654
|
-
const lock = await readLock(lockFilePath);
|
|
655
|
-
// DOD-LOGOUT-EXIT-1 (AC3): `stopped` used to come from a single FILE STAT — no lock file, no
|
|
656
|
-
// daemon. That is exactly the reasoning `logout` refuses by name above ("the lock file does not
|
|
657
|
-
// get to decide whether a daemon exists"), and it fails the same way: an exiting orphan unlinks a
|
|
658
|
-
// HEALTHY daemon's lock, and so does `rm ~/.cello/daemon.lock`. The operator then reads `stopped`
|
|
659
|
-
// while the daemon is online, on the directory, and extending the hash chain.
|
|
660
|
-
//
|
|
661
|
-
// So ask the daemon itself first, at the DETERMINISTIC socket path — daemon.lock's copy is
|
|
662
|
-
// metadata, and here there may be no lock file to read it from anyway.
|
|
663
|
-
const socketPath = lock?.socketPath ?? getDaemonIpcEndpoint(celloDir);
|
|
664
|
-
try {
|
|
665
|
-
// Bounded, for the same reason `daemonGone` bounds its probe: connectToDaemon has no connect
|
|
666
|
-
// timeout of its own, so a half-dead daemon holding a listening socket it will never answer on
|
|
667
|
-
// would hang `cello status` forever. That is not a hypothetical here — it is a shape of the
|
|
668
|
-
// very broken-shutdown state this function now has to report on.
|
|
669
|
-
const result = (await Promise.race([
|
|
670
|
-
withIpc(socketPath, (client) => client.send("status")),
|
|
671
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("status probe timed out after 3000ms")), 3_000)),
|
|
672
|
-
]));
|
|
673
|
-
return { exitCode: 0, output: JSON.stringify(result, null, 2) };
|
|
674
|
-
}
|
|
675
|
-
catch (err) {
|
|
676
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
677
|
-
// Nothing answered. Now the kernel decides whether a daemon process exists — not a file.
|
|
678
|
-
const probe = probeSingletonLock(celloDir, { debug() { }, info() { }, warn() { }, error() { } });
|
|
679
|
-
if (probe === "held") {
|
|
680
|
-
// A daemon process exists but has released (or never opened) its socket. That is a BROKEN
|
|
681
|
-
// SHUTDOWN, not a clean stop, and it is the state DOD-LOGOUT-EXIT-1 was filed for: the
|
|
682
|
-
// process is still alive and may still be on the network. Reporting `stopped` here is the
|
|
683
|
-
// lie. Name the state and point at the holder.
|
|
684
|
-
return {
|
|
685
|
-
exitCode: 1,
|
|
686
|
-
output: JSON.stringify({
|
|
687
|
-
daemon: "broken_shutdown",
|
|
688
|
-
detail: "A daemon process holds the singleton lock but is not answering on its socket. It has " +
|
|
689
|
-
"NOT cleanly stopped and may still be connected to a directory. Find it with " +
|
|
690
|
-
`\`lsof ${join(celloDir, SINGLETON_LOCK_FILENAME)}\` and stop it, then run 'cello logout' to clean up.`,
|
|
691
|
-
socketPath,
|
|
692
|
-
error: message,
|
|
693
|
-
}, null, 2),
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
if (probe === "unknown") {
|
|
697
|
-
// We could not ask. Reporting either "running" or "stopped" on a guess is the failure mode.
|
|
698
|
-
return {
|
|
699
|
-
exitCode: 1,
|
|
700
|
-
output: JSON.stringify({
|
|
701
|
-
daemon: "unknown",
|
|
702
|
-
detail: `The singleton lock at ${join(celloDir, SINGLETON_LOCK_FILENAME)} could not be checked, ` +
|
|
703
|
-
"so whether a daemon is running cannot be determined.",
|
|
704
|
-
error: message,
|
|
705
|
-
}, null, 2),
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
// probe === "free": nothing holds the lock and nothing answers, so there is no daemon OF THIS
|
|
709
|
-
// VERSION. The claim is deliberately narrower than "no daemon": a pre-singleton-lock daemon
|
|
710
|
-
// holds no singleton lock at all, so `free` says nothing about it and only the socket could
|
|
711
|
-
// have told us — which is why the socket is tried first, above. That residue is bounded by the
|
|
712
|
-
// upgrade and cannot be closed from this side.
|
|
713
|
-
// A lock file that is still present is stale metadata, not evidence of a process.
|
|
714
|
-
if (!lock) {
|
|
715
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "stopped" }, null, 2) };
|
|
716
|
-
}
|
|
717
|
-
return {
|
|
718
|
-
exitCode: 1,
|
|
719
|
-
output: JSON.stringify({ daemon: "unreachable", error: message }, null, 2),
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* `cello sessions [--open|--closed|--failed|--all] [--limit N]` — the full, queryable session
|
|
725
|
-
* history (the discovery surface `cello status` deliberately does NOT dump). Defaults to OPEN
|
|
726
|
-
* (live + resumable) so a long-lived agent's failed/closed history doesn't flood it, and caps the
|
|
727
|
-
* count at the daemon's default limit. Output reports `totalMatched` so the operator can tell when
|
|
728
|
-
* results were truncated.
|
|
729
|
-
*/
|
|
730
|
-
export async function sessions(celloDir, opts = {}) {
|
|
731
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
732
|
-
const lock = await readLock(lockFilePath);
|
|
733
|
-
if (!lock) {
|
|
734
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "stopped" }, null, 2) };
|
|
735
|
-
}
|
|
736
|
-
try {
|
|
737
|
-
const params = {};
|
|
738
|
-
if (opts.filter)
|
|
739
|
-
params.filter = opts.filter;
|
|
740
|
-
if (opts.limit !== undefined)
|
|
741
|
-
params.limit = opts.limit;
|
|
742
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("list_sessions", params)));
|
|
743
|
-
return { exitCode: 0, output: JSON.stringify(result, null, 2) };
|
|
744
|
-
}
|
|
745
|
-
catch (err) {
|
|
746
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
747
|
-
return {
|
|
748
|
-
exitCode: 1,
|
|
749
|
-
output: JSON.stringify({ daemon: "unreachable", error: message }, null, 2),
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
/** M8C-TGDOOR-1: `cello telegram set-token <bot_token> <allowlisted_chat_id>` — persists the
|
|
754
|
-
* daemon-wide bot credentials (narrow, dedicated surface; NOT folded into the parked `cello
|
|
755
|
-
* config`, since a bot token has no sensible default and can't wait for M9-CFG-001). */
|
|
756
|
-
/**
|
|
757
|
-
* `cello attestations` — the M10E REVIEW system (008-ENDRENAME).
|
|
758
|
-
*
|
|
759
|
-
* Namespaces, service-event marks, rights, the owner index, claim-service and activity counts — a
|
|
760
|
-
* review earned at a service event, which nothing can refuse or withdraw. The person-to-person
|
|
761
|
-
* ENDORSEMENT (vouch + accept/refuse) that used to live under `issue`/`issued` here is now
|
|
762
|
-
* `cello endorsements`; those two sub-verbs refuse with a rename line.
|
|
763
|
-
*/
|
|
764
|
-
export async function attestations(celloDir, sub, args) {
|
|
765
|
-
// 008-ENDRENAME — `issue`/`issued` are the person-to-person ENDORSEMENT, now `cello endorsements`.
|
|
766
|
-
// A CLI is typed by a person, so point them at the new name and act on nothing, rather than
|
|
767
|
-
// silently aliasing. The MCP tools keep deprecated aliases; a typed command does not need one.
|
|
768
|
-
if (sub === "issue" || sub === "issued") {
|
|
769
|
-
return { exitCode: 1, output: `renamed: use \`cello endorsements ${sub}\`` };
|
|
770
|
-
}
|
|
771
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
772
|
-
const lock = await readLock(lockFilePath);
|
|
773
|
-
if (!lock) {
|
|
774
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first." };
|
|
775
|
-
}
|
|
776
|
-
// M10E 003-NSCLIENT — attestation namespaces.
|
|
777
|
-
if (sub === "namespace") {
|
|
778
|
-
const [action, ns, ...flags] = args;
|
|
779
|
-
if (action === "create") {
|
|
780
|
-
let mode;
|
|
781
|
-
let condition;
|
|
782
|
-
let scored = false;
|
|
783
|
-
let ttl;
|
|
784
|
-
for (let i = 0; i < flags.length; i++) {
|
|
785
|
-
if (flags[i] === "--mode")
|
|
786
|
-
mode = flags[++i];
|
|
787
|
-
else if (flags[i] === "--scored")
|
|
788
|
-
scored = true;
|
|
789
|
-
else if (flags[i] === "--ttl")
|
|
790
|
-
ttl = Number(flags[++i]);
|
|
791
|
-
else if (flags[i] === "--condition")
|
|
792
|
-
condition = flags[++i];
|
|
793
|
-
}
|
|
794
|
-
if (!ns || !mode || !condition) {
|
|
795
|
-
return {
|
|
796
|
-
exitCode: 1,
|
|
797
|
-
output: 'Usage: cello attestations namespace create <ns> --mode <public|private> [--scored] [--ttl <days>] --condition "<words>"\n' +
|
|
798
|
-
"\n" +
|
|
799
|
-
" <ns> 1–3 dotted segments, e.g. reviews.prop_8821\n" +
|
|
800
|
-
" --mode public (anyone reads the reviews) or private (chosen readers)\n" +
|
|
801
|
-
" --scored a 1–5 rating plus text; omit for text-only\n" +
|
|
802
|
-
" --ttl how many days a reviewer has, 7–180 (default 30)\n" +
|
|
803
|
-
" --condition the plain-words rule under which the right to review is granted",
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
try {
|
|
807
|
-
const params = { namespace: ns, mode, scored, condition };
|
|
808
|
-
if (ttl !== undefined)
|
|
809
|
-
params.ttl_days = ttl;
|
|
810
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_namespace_create", params)));
|
|
811
|
-
if (!result.ok)
|
|
812
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
813
|
-
return { exitCode: 0, output: result.guidance ?? "Created." };
|
|
814
|
-
}
|
|
815
|
-
catch (err) {
|
|
816
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
if (action === "close") {
|
|
820
|
-
if (!ns)
|
|
821
|
-
return { exitCode: 1, output: "Usage: cello attestations namespace close <ns>" };
|
|
822
|
-
try {
|
|
823
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_namespace_close", { namespace: ns })));
|
|
824
|
-
if (!result.ok)
|
|
825
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
826
|
-
return { exitCode: 0, output: result.guidance ?? "Closed." };
|
|
827
|
-
}
|
|
828
|
-
catch (err) {
|
|
829
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
return { exitCode: 1, output: "Usage:\n cello attestations namespace create <ns> --mode <public|private> [--scored] [--ttl <days>] --condition \"<words>\"\n cello attestations namespace close <ns>" };
|
|
833
|
-
}
|
|
834
|
-
if (sub === "index") {
|
|
835
|
-
let owner;
|
|
836
|
-
let after;
|
|
837
|
-
for (let i = 0; i < args.length; i++) {
|
|
838
|
-
if (args[i] === "--after")
|
|
839
|
-
after = args[++i];
|
|
840
|
-
else if (!args[i].startsWith("--"))
|
|
841
|
-
owner = args[i];
|
|
842
|
-
}
|
|
843
|
-
try {
|
|
844
|
-
const params = {};
|
|
845
|
-
if (owner)
|
|
846
|
-
params.owner_pubkey = owner;
|
|
847
|
-
if (after)
|
|
848
|
-
params.after = after;
|
|
849
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_index", params)));
|
|
850
|
-
if (!result.ok)
|
|
851
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
852
|
-
const entries = result.entries ?? [];
|
|
853
|
-
if (entries.length === 0)
|
|
854
|
-
return { exitCode: 0, output: "No namespaces." };
|
|
855
|
-
const lines = entries.map((e) => {
|
|
856
|
-
const ttl = e.right_ttl_days === null ? "—" : `${e.right_ttl_days}d`;
|
|
857
|
-
const state = e.closed_at === null ? "open" : "closed";
|
|
858
|
-
const flag = e.verified ? "" : " UNVERIFIED";
|
|
859
|
-
return ` ${e.namespace.padEnd(28)} ${(e.mode ?? "—").padEnd(8)} ${(e.template ?? "—").padEnd(7)} ${ttl.padEnd(5)} ${state}${flag}`;
|
|
860
|
-
});
|
|
861
|
-
const more = result.next ? `\n\n More — cello attestations index ${owner ?? ""} --after ${result.next}` : "";
|
|
862
|
-
return { exitCode: 0, output: lines.join("\n") + more };
|
|
863
|
-
}
|
|
864
|
-
catch (err) {
|
|
865
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
// M10E 005-SVCCLIENT — mark a service event while a session is open.
|
|
869
|
-
if (sub === "mark") {
|
|
870
|
-
const [sessionId, ns, ...flags] = args;
|
|
871
|
-
let originChannel;
|
|
872
|
-
for (let i = 0; i < flags.length; i++) {
|
|
873
|
-
if (flags[i] === "--origin-channel")
|
|
874
|
-
originChannel = flags[++i];
|
|
875
|
-
}
|
|
876
|
-
if (!sessionId || !ns) {
|
|
877
|
-
return { exitCode: 1, output: "Usage: cello attestations mark <session-id> <namespace> [--origin-channel <pubkey>]" };
|
|
878
|
-
}
|
|
879
|
-
try {
|
|
880
|
-
const params = { session_id: sessionId, namespace: ns };
|
|
881
|
-
if (originChannel)
|
|
882
|
-
params.origin_channel = originChannel;
|
|
883
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_mark", params)));
|
|
884
|
-
if (!result.ok)
|
|
885
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
886
|
-
return { exitCode: 0, output: result.guidance ?? "Marked." };
|
|
887
|
-
}
|
|
888
|
-
catch (err) {
|
|
889
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
// M10E 005-SVCCLIENT — the rights this agent holds (expired ones shown, flagged).
|
|
893
|
-
if (sub === "rights") {
|
|
894
|
-
let after;
|
|
895
|
-
for (let i = 0; i < args.length; i++) {
|
|
896
|
-
if (args[i] === "--after")
|
|
897
|
-
after = args[++i];
|
|
898
|
-
}
|
|
899
|
-
try {
|
|
900
|
-
const params = {};
|
|
901
|
-
if (after)
|
|
902
|
-
params.after = after;
|
|
903
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_rights", params)));
|
|
904
|
-
if (!result.ok)
|
|
905
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
906
|
-
const rights = result.rights ?? [];
|
|
907
|
-
if (rights.length === 0)
|
|
908
|
-
return { exitCode: 0, output: "No rights." };
|
|
909
|
-
const lines = rights.map((r) => {
|
|
910
|
-
const flag = r.expired ? " EXPIRED" : "";
|
|
911
|
-
return ` ${r.namespace.padEnd(28)} ${(r.template ?? "—").padEnd(7)} ${r.subject_pubkey.slice(0, 16)}… ${r.right_id.slice(0, 16)}…${flag}`;
|
|
912
|
-
});
|
|
913
|
-
const more = result.next ? `\n\n More — cello attestations rights --after ${result.next}` : "";
|
|
914
|
-
return { exitCode: 0, output: lines.join("\n") + more };
|
|
915
|
-
}
|
|
916
|
-
catch (err) {
|
|
917
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
// M10E 013-PRIVATE — the readers of a PRIVATE namespace (owner only).
|
|
921
|
-
// cello attestations readers list <ns>
|
|
922
|
-
// cello attestations readers add|remove <ns> <pubkey>
|
|
923
|
-
if (sub === "readers") {
|
|
924
|
-
const [action, ns, pubkey] = args;
|
|
925
|
-
if (action === "list") {
|
|
926
|
-
if (!ns)
|
|
927
|
-
return { exitCode: 1, output: "Usage: cello attestations readers list <ns>" };
|
|
928
|
-
try {
|
|
929
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_readers_list", { namespace: ns })));
|
|
930
|
-
if (!result.ok)
|
|
931
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
932
|
-
const readers = result.readers ?? [];
|
|
933
|
-
const body = readers.length === 0 ? "No readers." : readers.map((r) => ` ${r}`).join("\n");
|
|
934
|
-
return { exitCode: 0, output: `${body}\n\n ${result.guidance ?? ""}`.trimEnd() };
|
|
935
|
-
}
|
|
936
|
-
catch (err) {
|
|
937
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (action === "add" || action === "remove") {
|
|
941
|
-
if (!ns || !pubkey || !/^[0-9a-f]{64}$/i.test(pubkey)) {
|
|
942
|
-
return { exitCode: 1, output: `Usage: cello attestations readers ${action} <ns> <pubkey-64hex>` };
|
|
943
|
-
}
|
|
944
|
-
try {
|
|
945
|
-
const verb = action === "add" ? "cello_attestations_readers_add" : "cello_attestations_readers_remove";
|
|
946
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send(verb, { namespace: ns, pubkey: pubkey.toLowerCase() })));
|
|
947
|
-
if (!result.ok)
|
|
948
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
949
|
-
return { exitCode: 0, output: result.guidance ?? "Reader list updated." };
|
|
950
|
-
}
|
|
951
|
-
catch (err) {
|
|
952
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
return { exitCode: 1, output: "Usage:\n cello attestations readers list <ns>\n cello attestations readers add <ns> <pubkey>\n cello attestations readers remove <ns> <pubkey>" };
|
|
956
|
-
}
|
|
957
|
-
// M10E 011-CLAIM — write a review for a right you hold. Text after `--`, so it can contain flags
|
|
958
|
-
// or dashes without being parsed. `cello attestations write <right-id> [--rating N] [--origin-channel pk] -- <text…>`
|
|
959
|
-
if (sub === "write") {
|
|
960
|
-
const [rightId, ...rest] = args;
|
|
961
|
-
let rating;
|
|
962
|
-
let originChannel;
|
|
963
|
-
const textParts = [];
|
|
964
|
-
for (let i = 0; i < rest.length; i++) {
|
|
965
|
-
if (rest[i] === "--rating")
|
|
966
|
-
rating = Number(rest[++i]);
|
|
967
|
-
else if (rest[i] === "--origin-channel")
|
|
968
|
-
originChannel = rest[++i];
|
|
969
|
-
else if (rest[i] === "--") {
|
|
970
|
-
textParts.push(...rest.slice(i + 1));
|
|
971
|
-
break;
|
|
972
|
-
}
|
|
973
|
-
else
|
|
974
|
-
textParts.push(rest[i]);
|
|
975
|
-
}
|
|
976
|
-
const text = textParts.join(" ").trim();
|
|
977
|
-
if (!rightId || text.length === 0) {
|
|
978
|
-
return { exitCode: 1, output: 'Usage: cello attestations write <right-id> [--rating <1-5>] [--origin-channel <pubkey>] -- <review text>' };
|
|
979
|
-
}
|
|
980
|
-
try {
|
|
981
|
-
const params = { right_id: rightId, text };
|
|
982
|
-
if (rating !== undefined)
|
|
983
|
-
params.rating = rating;
|
|
984
|
-
if (originChannel)
|
|
985
|
-
params.origin_channel = originChannel;
|
|
986
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_write", params)));
|
|
987
|
-
if (!result.ok)
|
|
988
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
989
|
-
return { exitCode: 0, output: result.guidance ?? "Review submitted." };
|
|
990
|
-
}
|
|
991
|
-
catch (err) {
|
|
992
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
// M10E 011-CLAIM — the reviews you have written, each with its submission outcome.
|
|
996
|
-
if (sub === "written") {
|
|
997
|
-
try {
|
|
998
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_written", {})));
|
|
999
|
-
if (!result.ok)
|
|
1000
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1001
|
-
const claimed = result.claimed ?? [];
|
|
1002
|
-
if (claimed.length === 0)
|
|
1003
|
-
return { exitCode: 0, output: "No reviews written." };
|
|
1004
|
-
const lines = claimed.map((c) => {
|
|
1005
|
-
const score = c.rating === null ? "—" : `${c.rating}/5`;
|
|
1006
|
-
return ` ${c.namespace.padEnd(28)} ${c.subject_pubkey.slice(0, 16)}… ${score.padEnd(4)} ${c.outcome.padEnd(8)} ${c.submission_id.slice(0, 16)}…`;
|
|
1007
|
-
});
|
|
1008
|
-
const note = result.results_unavailable ? `\n\n Outcomes could not be read now (${result.results_unavailable}); they show 'pending'. Nothing is lost.` : "";
|
|
1009
|
-
return { exitCode: 0, output: lines.join("\n") + note };
|
|
1010
|
-
}
|
|
1011
|
-
catch (err) {
|
|
1012
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
// M10E 007-NOTICES — file a service-received claim for a session that earned no right.
|
|
1016
|
-
if (sub === "claim-service") {
|
|
1017
|
-
const [sessionId, ns] = args;
|
|
1018
|
-
if (!sessionId || !ns) {
|
|
1019
|
-
return { exitCode: 1, output: "Usage: cello attestations claim-service <session-id> <namespace>" };
|
|
1020
|
-
}
|
|
1021
|
-
try {
|
|
1022
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_claim_service", { session_id: sessionId, namespace: ns })));
|
|
1023
|
-
if (!result.ok)
|
|
1024
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1025
|
-
return { exitCode: 0, output: result.guidance ?? "Claim filed." };
|
|
1026
|
-
}
|
|
1027
|
-
catch (err) {
|
|
1028
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
// M10E 015-READ — a buyer reads a namespace's summary from a MAJORITY of directories.
|
|
1032
|
-
// cello attestations summary <owner> <namespace>
|
|
1033
|
-
if (sub === "summary") {
|
|
1034
|
-
const [owner, ns] = args;
|
|
1035
|
-
if (!owner || !ns)
|
|
1036
|
-
return { exitCode: 1, output: "Usage: cello attestations summary <owner-pubkey> <namespace>" };
|
|
1037
|
-
try {
|
|
1038
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_summary", { owner_pubkey: owner, namespace: ns })));
|
|
1039
|
-
if (!result.ok)
|
|
1040
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1041
|
-
const avg = result.average_rating === null || result.average_rating === undefined ? "—" : result.average_rating.toFixed(2);
|
|
1042
|
-
return { exitCode: 0, output: ` ${ns}\n reviews: ${result.count ?? 0}\n average rating: ${avg}\n removed by ruling: ${result.removed_count ?? 0}\n unmarked claims: ${result.unmarked_claims ?? 0}\n directories agreed: ${result.agreed ?? 0} of ${result.validators ?? 0}` };
|
|
1043
|
-
}
|
|
1044
|
-
catch (err) {
|
|
1045
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
// M10E 015-READ — the reviews themselves, each verified against the majority root.
|
|
1049
|
-
// cello attestations reviews <owner> <namespace>
|
|
1050
|
-
if (sub === "reviews") {
|
|
1051
|
-
const [owner, ns] = args;
|
|
1052
|
-
if (!owner || !ns)
|
|
1053
|
-
return { exitCode: 1, output: "Usage: cello attestations reviews <owner-pubkey> <namespace>" };
|
|
1054
|
-
try {
|
|
1055
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_reviews", { owner_pubkey: owner, namespace: ns })));
|
|
1056
|
-
if (!result.ok)
|
|
1057
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1058
|
-
const reviews = result.reviews ?? [];
|
|
1059
|
-
const removed = result.removed ?? [];
|
|
1060
|
-
// Review text is quoted, untrusted data — shown indented under a label, never as a bare line
|
|
1061
|
-
// that could read as an instruction.
|
|
1062
|
-
const body = reviews.length === 0 ? "No reviews." : reviews.map((r) => {
|
|
1063
|
-
const score = r.rating === null ? "—" : `${r.rating}/5`;
|
|
1064
|
-
return ` [${r.index}] ${score} review (quoted, untrusted):\n ${r.quoted_text.replace(/\n/g, "\n ")}`;
|
|
1065
|
-
}).join("\n");
|
|
1066
|
-
const removedBlock = removed.length === 0 ? "" : "\n\n Removed by ruling:\n" + removed.map((rm) => ` ${rm.attestation_hash.slice(0, 16)}… reason: ${rm.reason}`).join("\n");
|
|
1067
|
-
return { exitCode: 0, output: ` ${ns} — ${result.count ?? 0} verified, ${result.agreed ?? 0} directories agreed\n${body}${removedBlock}` };
|
|
1068
|
-
}
|
|
1069
|
-
catch (err) {
|
|
1070
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
// M10E 015-READ — a channel's deals and average rating, read from the home directory.
|
|
1074
|
-
// cello attestations deals <channel-pubkey>
|
|
1075
|
-
if (sub === "deals") {
|
|
1076
|
-
const [channel] = args;
|
|
1077
|
-
if (!channel)
|
|
1078
|
-
return { exitCode: 1, output: "Usage: cello attestations deals <channel-pubkey>" };
|
|
1079
|
-
try {
|
|
1080
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_deals", { channel_pubkey: channel })));
|
|
1081
|
-
if (!result.ok)
|
|
1082
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1083
|
-
const avg = result.average_rating === null || result.average_rating === undefined ? "—" : result.average_rating.toFixed(2);
|
|
1084
|
-
return { exitCode: 0, output: ` channel ${channel.slice(0, 16)}…\n deals: ${result.deals ?? 0}\n average rating: ${avg}` };
|
|
1085
|
-
}
|
|
1086
|
-
catch (err) {
|
|
1087
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
// M10E 015-READ — the judge's client: build, sign and submit a removal ruling to every node.
|
|
1091
|
-
// cello attestations rule <attestation-hash> --owner <pubkey> --namespace <ns> --reason <text> [--evidence <hash>…]
|
|
1092
|
-
if (sub === "rule") {
|
|
1093
|
-
const [attHash, ...rest] = args;
|
|
1094
|
-
let owner;
|
|
1095
|
-
let ns;
|
|
1096
|
-
let reason;
|
|
1097
|
-
const evidence = [];
|
|
1098
|
-
for (let i = 0; i < rest.length; i++) {
|
|
1099
|
-
if (rest[i] === "--owner")
|
|
1100
|
-
owner = rest[++i];
|
|
1101
|
-
else if (rest[i] === "--namespace")
|
|
1102
|
-
ns = rest[++i];
|
|
1103
|
-
else if (rest[i] === "--reason")
|
|
1104
|
-
reason = rest[++i];
|
|
1105
|
-
else if (rest[i] === "--evidence") {
|
|
1106
|
-
const h = rest[++i];
|
|
1107
|
-
if (h)
|
|
1108
|
-
evidence.push(h);
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
if (!attHash || !owner || !ns || !reason) {
|
|
1112
|
-
return { exitCode: 1, output: "Usage: cello attestations rule <attestation-hash> --owner <pubkey> --namespace <ns> --reason <text> [--evidence <hash>…]" };
|
|
1113
|
-
}
|
|
1114
|
-
try {
|
|
1115
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_rule", { attestation_hash: attHash, owner_pubkey: owner, namespace: ns, reason, evidence_hashes: evidence })));
|
|
1116
|
-
if (!result.ok)
|
|
1117
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1118
|
-
const rows = (result.results ?? []).map((n) => ` ${n.node_id.padEnd(16)} ${n.error ? `error: ${n.error}` : `countersigns: ${n.countersigns ?? 0}${n.in_force ? " (in force)" : ""}`}`).join("\n");
|
|
1119
|
-
return { exitCode: 0, output: ` ${rows}\n\n ${result.guidance ?? ""}`.trimEnd() };
|
|
1120
|
-
}
|
|
1121
|
-
catch (err) {
|
|
1122
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
// M10E 007-NOTICES — the public activity counts for an owner's namespace.
|
|
1126
|
-
if (sub === "activity") {
|
|
1127
|
-
const [owner, ns] = args;
|
|
1128
|
-
if (!owner || !ns) {
|
|
1129
|
-
return { exitCode: 1, output: "Usage: cello attestations activity <pubkey> <namespace>" };
|
|
1130
|
-
}
|
|
1131
|
-
try {
|
|
1132
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_attestations_activity", { owner_pubkey: owner, namespace: ns })));
|
|
1133
|
-
if (!result.ok)
|
|
1134
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1135
|
-
return { exitCode: 0, output: ` ${ns}\n service events: ${result.service_events ?? 0}\n unmarked claims: ${result.unmarked_claims ?? 0}` };
|
|
1136
|
-
}
|
|
1137
|
-
catch (err) {
|
|
1138
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
return {
|
|
1142
|
-
exitCode: 1,
|
|
1143
|
-
output: "Usage:\n" +
|
|
1144
|
-
" cello attestations namespace create <ns> … — open a review namespace\n" +
|
|
1145
|
-
" cello attestations namespace close <ns> — stop a namespace granting new rights\n" +
|
|
1146
|
-
" cello attestations index [<pubkey>] — list an owner's namespaces\n" +
|
|
1147
|
-
" cello attestations mark <session-id> <ns> — mark a service event during a session\n" +
|
|
1148
|
-
" cello attestations rights — the rights to review that you hold\n" +
|
|
1149
|
-
" cello attestations write <right-id> -- <text> — write a review for a right you hold\n" +
|
|
1150
|
-
" cello attestations written — the reviews you have written, with outcomes\n" +
|
|
1151
|
-
" cello attestations claim-service <sid> <ns> — claim a dodged service event (no right)\n" +
|
|
1152
|
-
" cello attestations activity <pubkey> <ns> — service-event and unmarked-claim counts\n" +
|
|
1153
|
-
" cello attestations summary <owner> <ns> — a namespace's review summary, from a majority of directories\n" +
|
|
1154
|
-
" cello attestations reviews <owner> <ns> — the reviews, each verified against the majority root\n" +
|
|
1155
|
-
" cello attestations deals <channel> — the deals a channel is credited with\n" +
|
|
1156
|
-
" cello attestations rule <att-hash> --owner <pk> --namespace <ns> --reason <text> — a judge removes a false review\n" +
|
|
1157
|
-
"\n" +
|
|
1158
|
-
"To vouch for another agent in your own words, that is 'cello endorsements' (008-ENDRENAME).",
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* `cello endorsements` — YOUR words about ANOTHER agent, and what became of them (008-ENDRENAME).
|
|
1163
|
-
*
|
|
1164
|
-
* Split from `cello attestations` so the two systems stop sharing a word. `cello attestations` is
|
|
1165
|
-
* the M10E review system, where nothing can be refused; an ENDORSEMENT is a PERSON vouching for a
|
|
1166
|
-
* PERSON, which the subject accepts or refuses. The receiving direction is `cello endorsement-consent`.
|
|
1167
|
-
*
|
|
1168
|
-
* Subcommands:
|
|
1169
|
-
* issue <pubkey> <text…> — vouch for something you have seen them do
|
|
1170
|
-
* issued — what happened to the ones you wrote
|
|
1171
|
-
*/
|
|
1172
|
-
export async function endorsements(celloDir, sub, args) {
|
|
1173
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
1174
|
-
const lock = await readLock(lockFilePath);
|
|
1175
|
-
if (!lock) {
|
|
1176
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first." };
|
|
1177
|
-
}
|
|
1178
|
-
// M10B / `M10B-D25r2` — "what happened to what I submitted?". A NETWORK call, so it is its own verb
|
|
1179
|
-
// rather than folded into `list`: listing what you hold must keep working when the directory is
|
|
1180
|
-
// unreachable, and a remote failure must not break a local read.
|
|
1181
|
-
if (sub === "issued") {
|
|
1182
|
-
try {
|
|
1183
|
-
// TWO CALLS. `wallet_list_issued` is the local record of what was submitted; `wallet_fetch_results`
|
|
1184
|
-
// is the network sweep for outcomes. Showing only the second made a submission still awaiting the
|
|
1185
|
-
// subject INVISIBLE — three in flight printed as "no outcomes waiting", which reads as "nothing
|
|
1186
|
-
// was ever sent" rather than "nobody has answered yet".
|
|
1187
|
-
const [issued, res] = (await withAgentIpc(celloDir, lock.socketPath, async (client) => Promise.all([client.send("wallet_list_issued"), client.send("wallet_fetch_results")])).then((r) => (Array.isArray(r) ? r : [r, r])));
|
|
1188
|
-
if (!issued.ok) {
|
|
1189
|
-
return { exitCode: 1, output: `${issued.reason ?? "failed"}\n${issued.guidance ?? ""}`.trim() };
|
|
1190
|
-
}
|
|
1191
|
-
if (!res.ok) {
|
|
1192
|
-
return { exitCode: 1, output: `${res.reason ?? "failed"}\n${res.guidance ?? ""}`.trim() };
|
|
1193
|
-
}
|
|
1194
|
-
const byId = new Map((res.results ?? []).map((r) => [r.submission_id, r]));
|
|
1195
|
-
const rows = (issued.issued ?? []).map((s) => ({
|
|
1196
|
-
...(byId.get(s.submission_id) ?? { outcome: "pending", reason: null, message: null }),
|
|
1197
|
-
submission_id: s.submission_id,
|
|
1198
|
-
}));
|
|
1199
|
-
// Anything that came back for a submission this wallet has no local record of still gets shown —
|
|
1200
|
-
// dropping it would hide a real outcome behind a local bookkeeping gap.
|
|
1201
|
-
for (const r of res.results ?? [])
|
|
1202
|
-
if (!rows.some((x) => x.submission_id === r.submission_id))
|
|
1203
|
-
rows.push(r);
|
|
1204
|
-
// A node that did not answer is stated, never folded into the list — an incomplete sweep must not
|
|
1205
|
-
// be readable as "nothing came back".
|
|
1206
|
-
const partial = (res.unreachable_nodes ?? []).length > 0
|
|
1207
|
-
? `\n\n ⚠ ${res.unreachable_nodes.length} node(s) did not answer (${res.unreachable_nodes.join(", ")}).\n This list may be incomplete — an outcome recorded there is not shown yet.`
|
|
1208
|
-
: "";
|
|
1209
|
-
/**
|
|
1210
|
-
* DOD-M15-ENDORSE-RETRY-1 — THE ONES THAT NEVER REACHED A NODE, printed in their own block.
|
|
1211
|
-
*
|
|
1212
|
-
* Not merged into the table above: those rows carry an OUTCOME from a directory, and these
|
|
1213
|
-
* have none because no directory has ever seen them. Printing them as `pending` would say the
|
|
1214
|
-
* subject has not answered yet, about a submission nobody was ever asked about.
|
|
1215
|
-
*
|
|
1216
|
-
* Printed BEFORE the empty check too, or an operator whose node was down for the whole
|
|
1217
|
-
* session reads "You have submitted no endorsements" while the daemon is holding three.
|
|
1218
|
-
*/
|
|
1219
|
-
const flight = issued.in_flight ?? [];
|
|
1220
|
-
const flightBlock = flight.length === 0 ? "" :
|
|
1221
|
-
"\n\n Not yet at any directory node (held in memory — a daemon restart loses these):\n" +
|
|
1222
|
-
flight.map((f) => {
|
|
1223
|
-
const state = f.delivery === "gave_up" ? `gave up (${f.gave_up_because ?? "unknown"})` : "retrying";
|
|
1224
|
-
return ` ${state.padEnd(30)} ${f.submission_id.slice(0, 12)}… ${f.op} last: ${f.last_reason}\n ${f.guidance}`;
|
|
1225
|
-
}).join("\n");
|
|
1226
|
-
if (rows.length === 0) {
|
|
1227
|
-
return {
|
|
1228
|
-
exitCode: 0,
|
|
1229
|
-
output: (flight.length === 0
|
|
1230
|
-
? "You have submitted no endorsements. Results are held until you collect them, so nothing has been missed."
|
|
1231
|
-
: "No submission has reached a directory node yet.") + flightBlock + partial,
|
|
1232
|
-
};
|
|
1233
|
-
}
|
|
1234
|
-
const lines = rows.map((r) => {
|
|
1235
|
-
const head = ` ${r.outcome.padEnd(10)} ${r.submission_id.slice(0, 12)}… ${r.reason ?? "—"}`;
|
|
1236
|
-
// THE MESSAGE ON ITS OWN LINE, quoted and attributed. It is the SUBJECT'S words about the
|
|
1237
|
-
// operator's claim, and running it into the status columns would read as CELLO's verdict.
|
|
1238
|
-
return r.message ? `${head}\n they said: "${r.message}"` : head;
|
|
1239
|
-
});
|
|
1240
|
-
const header = ` ${"outcome".padEnd(10)} submission reason`;
|
|
1241
|
-
return {
|
|
1242
|
-
exitCode: 0,
|
|
1243
|
-
output: [header, " " + "─".repeat(60), ...lines].join("\n") +
|
|
1244
|
-
flightBlock +
|
|
1245
|
-
"\n\n A refusal is the subject declining to stand behind your claim — not a fault in it.\n" +
|
|
1246
|
-
" Re-submitting a corrected version is the intended next step.\n" +
|
|
1247
|
-
" 'pending' means the subject has not answered yet — the submission is not lost." + partial,
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
catch (err) {
|
|
1251
|
-
return { exitCode: 1, output: `Could not reach the daemon: ${err instanceof Error ? err.message : String(err)}` };
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
if (sub === "issue") {
|
|
1255
|
-
const [subject, ...rest] = args;
|
|
1256
|
-
// `--` ENDS FLAG PARSING. Free prose is the whole point of this verb, and prose contains things
|
|
1257
|
-
// that look like flags: "cut p99 -30ms" is rejected as an unknown flag, and "-h" anywhere prints
|
|
1258
|
-
// help instead of issuing. The operator needs a way to say "the rest is text", and `--` is the
|
|
1259
|
-
// convention every shell user already knows.
|
|
1260
|
-
const body = (rest[0] === "--" ? rest.slice(1) : rest).join(" ");
|
|
1261
|
-
if (!subject || body.length === 0) {
|
|
1262
|
-
return {
|
|
1263
|
-
exitCode: 1,
|
|
1264
|
-
output: "Usage: cello endorsements issue <subject-pubkey> <what you are endorsing them for…>\n" +
|
|
1265
|
-
"\n" +
|
|
1266
|
-
"The text: MAXIMUM 500 CHARACTERS — a testimonial, not a document. Line breaks are fine;\n" +
|
|
1267
|
-
"no other control characters, and no < or >.\n" +
|
|
1268
|
-
"\n" +
|
|
1269
|
-
"If your text contains something that looks like a flag (a leading '-', or '-h'), put `--`\n" +
|
|
1270
|
-
"before it so it is read as text:\n" +
|
|
1271
|
-
" cello endorsements issue <pubkey> -- cut p99 by -30ms on the auth path",
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
try {
|
|
1275
|
-
const result = (await withAgentIpc(celloDir, lock.socketPath, (client) => client.send("cello_endorsements_issue", { subject_pubkey: subject, body })));
|
|
1276
|
-
if (!result.ok) {
|
|
1277
|
-
return { exitCode: 1, output: `${result.reason}\n${result.guidance ?? ""}`.trim() };
|
|
1278
|
-
}
|
|
1279
|
-
return { exitCode: 0, output: result.guidance ?? "Submitted." };
|
|
1280
|
-
}
|
|
1281
|
-
catch (err) {
|
|
1282
|
-
return { exitCode: 1, output: `Failed to issue signal: ${err instanceof Error ? err.message : String(err)}` };
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
return {
|
|
1286
|
-
exitCode: 1,
|
|
1287
|
-
output: "Usage:\n" +
|
|
1288
|
-
" cello endorsements issue <pubkey> <text…> — vouch for something you have seen them do\n" +
|
|
1289
|
-
" cello endorsements issued — what happened to the ones you wrote\n" +
|
|
1290
|
-
"\n" +
|
|
1291
|
-
"What others wrote about YOU is 'cello endorsement-consent'.",
|
|
1292
|
-
};
|
|
1293
|
-
}
|
|
1294
|
-
/**
|
|
1295
|
-
* `cello trust-signals` — inspect and manage the operator's trust-signal wallet.
|
|
1296
|
-
*
|
|
1297
|
-
* Subcommands:
|
|
1298
|
-
* list — tabular view of all signals (includes default column)
|
|
1299
|
-
* view <hash-prefix> — full decoded payload for one signal
|
|
1300
|
-
* enable <hash-prefix> — include signal in the default presentation bundle
|
|
1301
|
-
* disable <hash-prefix> — exclude signal from the default bundle
|
|
1302
|
-
* revoke <hash-prefix> — tombstone at the directory AND hard-delete locally
|
|
1303
|
-
*/
|
|
1304
|
-
export async function trustSignals(celloDir, sub, args) {
|
|
1305
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
1306
|
-
const lock = await readLock(lockFilePath);
|
|
1307
|
-
if (!lock) {
|
|
1308
|
-
return { exitCode: 1, output: "No daemon running. Run 'cello login' first." };
|
|
1309
|
-
}
|
|
1310
|
-
if (sub === "list") {
|
|
1311
|
-
const showAll = args.includes("--all");
|
|
1312
|
-
try {
|
|
1313
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("wallet_list_signals")));
|
|
1314
|
-
if (!result.ok) {
|
|
1315
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: result.reason }, null, 2) };
|
|
1316
|
-
}
|
|
1317
|
-
const all = result.signals ?? [];
|
|
1318
|
-
const signals = showAll ? all : all.filter((s) => s.status === "active");
|
|
1319
|
-
const supersededCount = all.filter((s) => s.status !== "active").length;
|
|
1320
|
-
if (signals.length === 0 && all.length === 0) {
|
|
1321
|
-
return { exitCode: 0, output: "No trust signals in wallet." };
|
|
1322
|
-
}
|
|
1323
|
-
if (signals.length === 0) {
|
|
1324
|
-
return { exitCode: 0, output: `No active trust signals. ${supersededCount} superseded (run with --all to show).` };
|
|
1325
|
-
}
|
|
1326
|
-
// M10B / DOD-END-SURFACE-1. `status` is the DIRECTORY's answer (is the notarization live);
|
|
1327
|
-
// consent is the SUBJECT's answer (may it be shown at all). A signal needs both, and only
|
|
1328
|
-
// `accepted` is presentable — so anything else must never render as included, or the
|
|
1329
|
-
// operator's own list contradicts what presentation actually does.
|
|
1330
|
-
const presentable = (s) => s.consent_state === "accepted";
|
|
1331
|
-
const anyAwaiting = signals.some((s) => !presentable(s));
|
|
1332
|
-
const lines = signals.map((s) => {
|
|
1333
|
-
const date = new Date(s.issued_at * 1000).toISOString().slice(0, 10);
|
|
1334
|
-
const hash = s.signal_hash.slice(0, 12) + "…";
|
|
1335
|
-
const status = s.status === "active" ? "active" : s.status === "superseded" ? "superseded" : s.status;
|
|
1336
|
-
// ABSENT IS NOT FINE (§5a): an unset or unrecognised consent state reads as "awaiting", never
|
|
1337
|
-
// as presentable. The attacker never has to defeat this check — they omit what triggers it.
|
|
1338
|
-
const consent = s.consent_state === "accepted" ? "—"
|
|
1339
|
-
: s.consent_state === "pending" ? "PENDING"
|
|
1340
|
-
: s.consent_state === "refused" ? "refused"
|
|
1341
|
-
: "awaiting";
|
|
1342
|
-
const inc = presentable(s) ? (s.default_present ? "✓" : "–") : "✗";
|
|
1343
|
-
// M10B / DOD-END-COUNT-1 — MCP/CLI parity (DOD-END-SURFACE-1). The daemon returns
|
|
1344
|
-
// `same_operator` and the MCP surface shows it; without this column the CLI operator sees two
|
|
1345
|
-
// endorsements as identical when one is capped — a recipient's floor excludes a co-owned
|
|
1346
|
-
// endorsement from `min_count` — and that reads as the protocol behaving arbitrarily.
|
|
1347
|
-
const own = s.same_operator === true ? "own" : "—";
|
|
1348
|
-
return ` ${s.type.padEnd(22)} ${hash} ${status.padEnd(12)} ${consent.padEnd(9)} ${own.padEnd(5)} ${inc.padEnd(4)} ${date}`;
|
|
1349
|
-
});
|
|
1350
|
-
const header = ` ${"type".padEnd(22)} hash status consent co-own include issued`;
|
|
1351
|
-
const divider = " " + "─".repeat(92);
|
|
1352
|
-
const consentLegend = anyAwaiting
|
|
1353
|
-
? `\n consent: PENDING = someone issued this ABOUT you and it awaits your decision — it is NOT\n shown to anyone until you accept. Run 'cello attestation-consent list' to read and decide.\n refused = you refused it; it stays inert. ✗ = not presentable, whatever 'include' says.`
|
|
1354
|
-
: "";
|
|
1355
|
-
// The co-own legend appears only when a co-owned signal is present: a line explaining a column
|
|
1356
|
-
// that reads "—" on every row is noise, and its APPEARANCE is what makes the operator look.
|
|
1357
|
-
const anyCoOwned = signals.some((s) => s.same_operator === true);
|
|
1358
|
-
const coOwnLegend = anyCoOwned
|
|
1359
|
-
? `\n co-own: 'own' = the endorser and the subject are your own agents. Still shown to contacts,\n but it does NOT count toward a counterparty's minimum-endorsements requirement.`
|
|
1360
|
-
: "";
|
|
1361
|
-
const legend = `\n include: ✓ = presented to contacts by default – = excluded from presentation\n To change: 'cello trust-signals enable <hash>' or 'cello trust-signals disable <hash>'${coOwnLegend}${consentLegend}`;
|
|
1362
|
-
const footer = !showAll && supersededCount > 0
|
|
1363
|
-
? `\n (${supersededCount} superseded not shown — run with --all to include)`
|
|
1364
|
-
: "";
|
|
1365
|
-
return { exitCode: 0, output: [header, divider, ...lines].join("\n") + legend + footer };
|
|
1366
|
-
}
|
|
1367
|
-
catch (err) {
|
|
1368
|
-
return { exitCode: 1, output: `Failed to list signals: ${err instanceof Error ? err.message : String(err)}` };
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
if (sub === "view") {
|
|
1372
|
-
const prefix = args[0];
|
|
1373
|
-
if (!prefix) {
|
|
1374
|
-
return { exitCode: 1, output: "Usage: cello trust-signals view <hash-prefix>" };
|
|
1375
|
-
}
|
|
1376
|
-
try {
|
|
1377
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("wallet_view_signal", { hash_prefix: prefix })));
|
|
1378
|
-
if (!result.ok) {
|
|
1379
|
-
return { exitCode: 1, output: result.guidance ?? result.reason ?? "signal not found" };
|
|
1380
|
-
}
|
|
1381
|
-
const lines = [
|
|
1382
|
-
`type: ${result.type}`,
|
|
1383
|
-
`signal_hash: ${result.signal_hash}`,
|
|
1384
|
-
`status: ${result.status}`,
|
|
1385
|
-
`default_present: ${result.default_present ? "yes" : "no"}`,
|
|
1386
|
-
`subject_kind: ${result.subject_kind}`,
|
|
1387
|
-
`subject: ${result.subject}`,
|
|
1388
|
-
`issuer_kind: ${result.issuer_kind}`,
|
|
1389
|
-
`issuer_pubkey: ${result.issuer_pubkey}`,
|
|
1390
|
-
`schema_version: ${result.schema_version}`,
|
|
1391
|
-
`issued_at: ${result.issued_at ? new Date(result.issued_at * 1000).toISOString() : "—"}`,
|
|
1392
|
-
`expires_at: ${result.expires_at ? new Date(result.expires_at * 1000).toISOString() : "—"}`,
|
|
1393
|
-
`supersedes: ${result.supersedes_hash ?? "—"}`,
|
|
1394
|
-
`payload: ${JSON.stringify(result.payload, null, 2)}`,
|
|
1395
|
-
];
|
|
1396
|
-
// CO-OWNERSHIP, ON ITS OWN LINE. The portal also writes `co_ownership_note` into the payload,
|
|
1397
|
-
// which prints above — but inside a JSON blob, where the one fact that decides what this
|
|
1398
|
-
// endorsement is worth reads as another key. This line is driven by the ENVELOPE BOOLEAN, not
|
|
1399
|
-
// by the payload note, so it also fires for signals minted before the note existed.
|
|
1400
|
-
if (result.same_operator === true)
|
|
1401
|
-
lines.push(`co-ownership: ${CO_OWNERSHIP_NOTE}`);
|
|
1402
|
-
return { exitCode: 0, output: lines.join("\n") };
|
|
1403
|
-
}
|
|
1404
|
-
catch (err) {
|
|
1405
|
-
return { exitCode: 1, output: `Failed to view signal: ${err instanceof Error ? err.message : String(err)}` };
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
if (sub === "enable") {
|
|
1409
|
-
const prefix = args[0];
|
|
1410
|
-
if (!prefix) {
|
|
1411
|
-
return { exitCode: 1, output: "Usage: cello trust-signals enable <hash-prefix>" };
|
|
1412
|
-
}
|
|
1413
|
-
try {
|
|
1414
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("wallet_enable_signal", { hash_prefix: prefix })));
|
|
1415
|
-
if (!result.ok) {
|
|
1416
|
-
return { exitCode: 1, output: result.guidance ?? result.reason ?? "failed to enable signal" };
|
|
1417
|
-
}
|
|
1418
|
-
return { exitCode: 0, output: `Signal ${result.signal_hash} enabled (included in default presentation).` };
|
|
1419
|
-
}
|
|
1420
|
-
catch (err) {
|
|
1421
|
-
return { exitCode: 1, output: `Failed to enable signal: ${err instanceof Error ? err.message : String(err)}` };
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
if (sub === "disable") {
|
|
1425
|
-
const prefix = args[0];
|
|
1426
|
-
if (!prefix) {
|
|
1427
|
-
return { exitCode: 1, output: "Usage: cello trust-signals disable <hash-prefix>" };
|
|
1428
|
-
}
|
|
1429
|
-
try {
|
|
1430
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("wallet_disable_signal", { hash_prefix: prefix })));
|
|
1431
|
-
if (!result.ok) {
|
|
1432
|
-
return { exitCode: 1, output: result.guidance ?? result.reason ?? "failed to disable signal" };
|
|
1433
|
-
}
|
|
1434
|
-
return { exitCode: 0, output: `Signal ${result.signal_hash} disabled (excluded from default presentation).` };
|
|
1435
|
-
}
|
|
1436
|
-
catch (err) {
|
|
1437
|
-
return { exitCode: 1, output: `Failed to disable signal: ${err instanceof Error ? err.message : String(err)}` };
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
if (sub === "revoke") {
|
|
1441
|
-
const prefix = args[0];
|
|
1442
|
-
if (!prefix) {
|
|
1443
|
-
return { exitCode: 1, output: "Usage: cello trust-signals revoke <hash-prefix>" };
|
|
1444
|
-
}
|
|
1445
|
-
try {
|
|
1446
|
-
const result = (await withIpc(lock.socketPath, (client) => client.send("wallet_revoke_signal", { hash_prefix: prefix })));
|
|
1447
|
-
if (!result.ok) {
|
|
1448
|
-
return { exitCode: 1, output: result.guidance ?? result.reason ?? "failed to revoke signal" };
|
|
1449
|
-
}
|
|
1450
|
-
// QUEUED, NOT REVOKED — and the daemon's own guidance says what happens next.
|
|
1451
|
-
//
|
|
1452
|
-
// This printed `Revoked signal <hash>. directory unreachable — tombstone may be pending.` on
|
|
1453
|
-
// every success, at exit 0. Three untruths in one line: it was not revoked, no directory was
|
|
1454
|
-
// contacted from here, and `directory_results` had stopped existing so `every()` on undefined
|
|
1455
|
-
// fell to `false` and the failure branch ran unconditionally. It also DROPPED the daemon's
|
|
1456
|
-
// guidance, which is the only place the operator learns that their local copy is kept and how
|
|
1457
|
-
// to check the outcome.
|
|
1458
|
-
return {
|
|
1459
|
-
exitCode: 0,
|
|
1460
|
-
output: `Revocation queued for ${result.signal_hash}` +
|
|
1461
|
-
(result.submission_id ? ` (submission ${result.submission_id.slice(0, 12)}…)` : "") +
|
|
1462
|
-
(result.guidance ? `\n${result.guidance}` : ""),
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
catch (err) {
|
|
1466
|
-
return { exitCode: 1, output: `Failed to revoke signal: ${err instanceof Error ? err.message : String(err)}` };
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
return {
|
|
1470
|
-
exitCode: 1,
|
|
1471
|
-
output: "Usage:\n" +
|
|
1472
|
-
" cello trust-signals list [--all] — show active signals (--all includes superseded)\n" +
|
|
1473
|
-
" cello trust-signals view <hash> — decode and display a signal's full payload\n" +
|
|
1474
|
-
" cello trust-signals enable <hash> — include signal in the default presentation bundle\n" +
|
|
1475
|
-
" cello trust-signals disable <hash> — exclude signal from the default bundle\n" +
|
|
1476
|
-
" cello trust-signals revoke <hash> — ask the portal to retract a signal (queued; your copy is kept)\n" +
|
|
1477
|
-
"\n" +
|
|
1478
|
-
"<hash> can be a prefix (min 8 chars). See 'cello trust-signals list' for hashes.",
|
|
1479
|
-
};
|
|
1480
|
-
}
|
|
1481
|
-
/**
|
|
1482
|
-
* M16 018-PUBCOLLECT — the terminal side of the four channel publishing verbs.
|
|
1483
|
-
*
|
|
1484
|
-
* These are IPC-only by order 018: an MCP tool would put "publish to every subscriber" in reach of
|
|
1485
|
-
* anything that can drive an agent's tools, and a channel's posts are the publisher's own name on
|
|
1486
|
-
* the record. The caller here is a person at a terminal, deliberately.
|
|
1487
|
-
*
|
|
1488
|
-
* ⚠️ **A REFUSAL THAT ARRIVED IS NOT AN UNREACHABLE DAEMON, and the two must not print the same.**
|
|
1489
|
-
* Most refusals come back as `{ ok: false, reason }`, but a handler that THROWS becomes an IPC
|
|
1490
|
-
* error response — which still travelled over a working socket. Printing that as
|
|
1491
|
-
* `{"daemon":"unreachable"}` sends the operator to check the socket, the lock file and the process,
|
|
1492
|
-
* none of which is the problem: the daemon answered, and what it said was `channel_group_key_unavailable`.
|
|
1493
|
-
* Only a failure to connect is reported as unreachable.
|
|
1494
|
-
*/
|
|
1495
|
-
export async function channelVerb(celloDir, verb, params) {
|
|
1496
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
1497
|
-
const lock = await readLock(lockFilePath);
|
|
1498
|
-
if (!lock) {
|
|
1499
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "stopped" }, null, 2) };
|
|
1500
|
-
}
|
|
1501
|
-
// Connecting is the ONLY step whose failure means "unreachable". Split from the call itself so a
|
|
1502
|
-
// refusal that arrived over a working socket can never be labelled as a dead daemon.
|
|
1503
|
-
let client;
|
|
1504
|
-
try {
|
|
1505
|
-
client = await connectToDaemon(lock.socketPath);
|
|
1506
|
-
}
|
|
1507
|
-
catch (err) {
|
|
1508
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
1509
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "unreachable", error: message }, null, 2) };
|
|
1510
|
-
}
|
|
1511
|
-
try {
|
|
1512
|
-
await client.send("ipc.connect", { clientType: "cli" });
|
|
1513
|
-
const result = (await client.send(verb, params));
|
|
1514
|
-
return { exitCode: result?.ok === true ? 0 : 1, output: JSON.stringify(result, null, 2) };
|
|
1515
|
-
}
|
|
1516
|
-
catch (err) {
|
|
1517
|
-
// The daemon ANSWERED and what it said was an error. Report its words, not a guess about the
|
|
1518
|
-
// socket: `channel_group_key_unavailable` is a decision the daemon made, not a connection fault.
|
|
1519
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
1520
|
-
return { exitCode: 1, output: JSON.stringify({ ok: false, reason: message }, null, 2) };
|
|
1521
|
-
}
|
|
1522
|
-
finally {
|
|
1523
|
-
client.close();
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
export async function telegramSetToken(celloDir, botToken, chatId) {
|
|
1527
|
-
const lockFilePath = join(celloDir, "daemon.lock");
|
|
1528
|
-
const lock = await readLock(lockFilePath);
|
|
1529
|
-
if (!lock) {
|
|
1530
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "stopped" }, null, 2) };
|
|
1531
|
-
}
|
|
1532
|
-
try {
|
|
1533
|
-
const result = (await withIpc(lock.socketPath, async (client) => {
|
|
1534
|
-
await client.send("ipc.connect", { clientType: "cli" });
|
|
1535
|
-
return client.send("cello_telegram_set_token", { bot_token: botToken, allowlisted_chat_id: chatId });
|
|
1536
|
-
}));
|
|
1537
|
-
return { exitCode: result.ok ? 0 : 1, output: JSON.stringify(result, null, 2) };
|
|
1538
|
-
}
|
|
1539
|
-
catch (err) {
|
|
1540
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
1541
|
-
return { exitCode: 1, output: JSON.stringify({ daemon: "unreachable", error: message }, null, 2) };
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
//# sourceMappingURL=commands.js.map
|