@cello-protocol/cli 0.0.306 → 0.0.307
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +15 -0
- package/README.md +107 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +564 -0
- package/dist/daemon/account-page-assets.d.ts +4 -0
- package/dist/daemon/account-page-assets.js +160 -0
- package/dist/daemon/account-page.d.ts +14 -0
- package/dist/daemon/account-page.js +104 -0
- package/dist/daemon/address.d.ts +10 -0
- package/dist/daemon/address.js +34 -0
- package/dist/daemon/away.d.ts +31 -0
- package/dist/daemon/away.js +65 -0
- package/dist/daemon/channel-store.d.ts +112 -0
- package/dist/daemon/channel-store.js +284 -0
- package/dist/daemon/channels.d.ts +46 -0
- package/dist/daemon/channels.js +1049 -0
- package/dist/daemon/contacts.d.ts +26 -0
- package/dist/daemon/contacts.js +74 -0
- package/dist/daemon/engine.d.ts +80 -0
- package/dist/daemon/engine.js +2882 -0
- package/dist/daemon/errors.d.ts +5 -0
- package/dist/daemon/errors.js +16 -0
- package/dist/daemon/governance.d.ts +66 -0
- package/dist/daemon/governance.js +514 -0
- package/dist/daemon/guards.d.ts +36 -0
- package/dist/daemon/guards.js +140 -0
- package/dist/daemon/issuer-client.d.ts +56 -0
- package/dist/daemon/issuer-client.js +143 -0
- package/dist/daemon/link.d.ts +30 -0
- package/dist/daemon/link.js +191 -0
- package/dist/daemon/log.d.ts +1 -0
- package/dist/daemon/log.js +4 -0
- package/dist/daemon/main.d.ts +1 -0
- package/dist/daemon/main.js +511 -0
- package/dist/daemon/paths.d.ts +6 -0
- package/dist/daemon/paths.js +21 -0
- package/dist/daemon/pii.d.ts +24 -0
- package/dist/daemon/pii.js +146 -0
- package/dist/daemon/policy-cadence.d.ts +33 -0
- package/dist/daemon/policy-cadence.js +59 -0
- package/dist/daemon/policy-proposals.d.ts +41 -0
- package/dist/daemon/policy-proposals.js +83 -0
- package/dist/daemon/policy-store.d.ts +47 -0
- package/dist/daemon/policy-store.js +144 -0
- package/dist/daemon/presented.d.ts +36 -0
- package/dist/daemon/presented.js +94 -0
- package/dist/daemon/rate-limit.d.ts +17 -0
- package/dist/daemon/rate-limit.js +44 -0
- package/dist/daemon/reach.d.ts +63 -0
- package/dist/daemon/reach.js +207 -0
- package/dist/daemon/screening.d.ts +97 -0
- package/dist/daemon/screening.js +362 -0
- package/dist/daemon/settings.d.ts +125 -0
- package/dist/daemon/settings.js +73 -0
- package/dist/daemon/signal-rules.d.ts +55 -0
- package/dist/daemon/signal-rules.js +127 -0
- package/dist/daemon/signal-store.d.ts +53 -0
- package/dist/daemon/signal-store.js +114 -0
- package/dist/daemon/store.d.ts +188 -0
- package/dist/daemon/store.js +474 -0
- package/dist/daemon/tiers.d.ts +14 -0
- package/dist/daemon/tiers.js +9 -0
- package/dist/daemon/wallet.d.ts +73 -0
- package/dist/daemon/wallet.js +428 -0
- package/dist/daemon/who-label.d.ts +3 -0
- package/dist/daemon/who-label.js +11 -0
- package/dist/guidance.d.ts +39 -0
- package/dist/guidance.js +98 -0
- package/dist/hermes-bridge.d.ts +26 -0
- package/dist/hermes-bridge.js +180 -0
- package/dist/install-mcp.d.ts +6 -0
- package/dist/install-mcp.js +77 -0
- package/dist/ipc/client.d.ts +18 -0
- package/dist/ipc/client.js +107 -0
- package/dist/ipc/operations.d.ts +30 -0
- package/dist/ipc/operations.js +835 -0
- package/dist/ipc/protocol.d.ts +21 -0
- package/dist/ipc/protocol.js +1 -0
- package/dist/issuer-list-sign.d.ts +12 -0
- package/dist/issuer-list-sign.js +43 -0
- package/dist/local-operations.d.ts +2 -0
- package/dist/local-operations.js +73 -0
- package/dist/mcp-tools.d.ts +14 -0
- package/dist/mcp-tools.js +45 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +155 -0
- package/dist/protocol/aead.d.ts +4 -0
- package/dist/protocol/aead.js +35 -0
- package/dist/protocol/cbor.d.ts +40 -0
- package/dist/protocol/cbor.js +106 -0
- package/dist/protocol/chain.d.ts +44 -0
- package/dist/protocol/chain.js +126 -0
- package/dist/protocol/channel.d.ts +153 -0
- package/dist/protocol/channel.js +298 -0
- package/dist/protocol/encode.d.ts +6 -0
- package/dist/protocol/encode.js +21 -0
- package/dist/protocol/identity.d.ts +27 -0
- package/dist/protocol/identity.js +94 -0
- package/dist/protocol/issuer-list.d.ts +56 -0
- package/dist/protocol/issuer-list.js +193 -0
- package/dist/protocol/issuer-roots.d.ts +6 -0
- package/dist/protocol/issuer-roots.js +10 -0
- package/dist/protocol/key-agreement.d.ts +20 -0
- package/dist/protocol/key-agreement.js +88 -0
- package/dist/protocol/merkle.d.ts +16 -0
- package/dist/protocol/merkle.js +166 -0
- package/dist/protocol/ml-dsa.d.ts +28 -0
- package/dist/protocol/ml-dsa.js +58 -0
- package/dist/protocol/ml-kem.d.ts +14 -0
- package/dist/protocol/ml-kem.js +57 -0
- package/dist/protocol/pq-errors.d.ts +9 -0
- package/dist/protocol/pq-errors.js +23 -0
- package/dist/protocol/pq-warnings.d.ts +1 -0
- package/dist/protocol/pq-warnings.js +18 -0
- package/dist/protocol/presented-signals.d.ts +17 -0
- package/dist/protocol/presented-signals.js +92 -0
- package/dist/protocol/salt.d.ts +5 -0
- package/dist/protocol/salt.js +47 -0
- package/dist/protocol/seal.d.ts +58 -0
- package/dist/protocol/seal.js +220 -0
- package/dist/protocol/signal.d.ts +54 -0
- package/dist/protocol/signal.js +266 -0
- package/dist/protocol/status.d.ts +41 -0
- package/dist/protocol/status.js +64 -0
- package/dist/protocol/structures.d.ts +359 -0
- package/dist/protocol/structures.js +296 -0
- package/dist/protocol/transcript.d.ts +61 -0
- package/dist/protocol/transcript.js +319 -0
- package/dist/protocol/wire.d.ts +212 -0
- package/dist/protocol/wire.js +161 -0
- package/dist/require-node.d.ts +1 -0
- package/dist/require-node.js +10 -0
- package/dist/screener/affordance.d.ts +1 -0
- package/dist/screener/affordance.js +2 -0
- package/dist/screener/classifier-selfcheck.d.ts +29 -0
- package/dist/screener/classifier-selfcheck.js +56 -0
- package/dist/screener/exfil.d.ts +11 -0
- package/dist/screener/exfil.js +45 -0
- package/dist/screener/gitleaks-rules.d.ts +9 -0
- package/dist/screener/gitleaks-rules.js +226 -0
- package/dist/screener/inbound.d.ts +25 -0
- package/dist/screener/inbound.js +102 -0
- package/dist/screener/injection-classifier-onnx.d.ts +20 -0
- package/dist/screener/injection-classifier-onnx.js +89 -0
- package/dist/screener/injection-classifier-wasm.d.ts +2 -0
- package/dist/screener/injection-classifier-wasm.js +97 -0
- package/dist/screener/injection-patterns.d.ts +8 -0
- package/dist/screener/injection-patterns.js +48 -0
- package/dist/screener/injection-windows.d.ts +9 -0
- package/dist/screener/injection-windows.js +37 -0
- package/dist/screener/language.d.ts +15 -0
- package/dist/screener/language.js +71 -0
- package/dist/screener/linear-regex.d.ts +8 -0
- package/dist/screener/linear-regex.js +27 -0
- package/dist/screener/model-installer.d.ts +14 -0
- package/dist/screener/model-installer.js +61 -0
- package/dist/screener/outbound.d.ts +19 -0
- package/dist/screener/outbound.js +62 -0
- package/dist/screener/sanitize.d.ts +44 -0
- package/dist/screener/sanitize.js +361 -0
- package/dist/screener/scan-variants.d.ts +5 -0
- package/dist/screener/scan-variants.js +146 -0
- package/dist/screener/screener-model-manifest.d.ts +16 -0
- package/dist/screener/screener-model-manifest.js +20 -0
- package/dist/screener/screener-state.d.ts +29 -0
- package/dist/screener/screener-state.js +119 -0
- package/dist/screener/secrets.d.ts +18 -0
- package/dist/screener/secrets.js +84 -0
- package/dist/screener/worker.d.ts +6 -0
- package/dist/screener/worker.js +83 -0
- package/dist/setup.d.ts +9 -0
- package/dist/setup.js +252 -0
- package/dist/shipped-issuer-list.d.ts +1 -0
- package/dist/shipped-issuer-list.js +3 -0
- package/dist/signals-text.d.ts +46 -0
- package/dist/signals-text.js +81 -0
- package/dist/verify-seal.d.ts +9 -0
- package/dist/verify-seal.js +30 -0
- package/hermes/plugin/__init__.py +1040 -0
- package/hermes/plugin/plugin.yaml +30 -0
- package/hermes/skills/cello-bridge-setup/SKILL.md +38 -0
- package/hermes/skills/cello-policy/SKILL.md +44 -0
- package/package.json +48 -16
- package/plugins/cello/.claude-plugin/plugin.json +19 -0
- package/plugins/cello/.mcp.json +7 -0
- package/plugins/cello/skills/cello/SKILL.md +117 -0
- package/dist/arg-parse.d.ts +0 -19
- package/dist/arg-parse.d.ts.map +0 -1
- package/dist/arg-parse.js +0 -29
- package/dist/arg-parse.js.map +0 -1
- package/dist/bin/cello.d.ts +0 -15
- package/dist/bin/cello.d.ts.map +0 -1
- package/dist/bin/cello.js +0 -110
- package/dist/bin/cello.js.map +0 -1
- package/dist/cli-args.d.ts +0 -62
- package/dist/cli-args.d.ts.map +0 -1
- package/dist/cli-args.js +0 -129
- package/dist/cli-args.js.map +0 -1
- package/dist/commands.d.ts +0 -196
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -1544
- package/dist/commands.js.map +0 -1
- package/dist/hermes/assets.d.ts +0 -41
- package/dist/hermes/assets.d.ts.map +0 -1
- package/dist/hermes/assets.js +0 -2281
- package/dist/hermes/assets.js.map +0 -1
- package/dist/hermes/install-hermes.d.ts +0 -50
- package/dist/hermes/install-hermes.d.ts.map +0 -1
- package/dist/hermes/install-hermes.js +0 -232
- package/dist/hermes/install-hermes.js.map +0 -1
- package/dist/json-out.d.ts +0 -41
- package/dist/json-out.d.ts.map +0 -1
- package/dist/json-out.js +0 -59
- package/dist/json-out.js.map +0 -1
- package/dist/node-runtime-guard-init.d.ts +0 -6
- package/dist/node-runtime-guard-init.d.ts.map +0 -1
- package/dist/node-runtime-guard-init.js +0 -7
- package/dist/node-runtime-guard-init.js.map +0 -1
- package/dist/node-runtime-guard.d.ts +0 -48
- package/dist/node-runtime-guard.d.ts.map +0 -1
- package/dist/node-runtime-guard.js +0 -79
- package/dist/node-runtime-guard.js.map +0 -1
- package/dist/parity-commands.d.ts +0 -427
- package/dist/parity-commands.d.ts.map +0 -1
- package/dist/parity-commands.js +0 -953
- package/dist/parity-commands.js.map +0 -1
- package/dist/registry.d.ts +0 -120
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -2169
- package/dist/registry.js.map +0 -1
- package/dist/screener-commands.d.ts +0 -85
- package/dist/screener-commands.d.ts.map +0 -1
- package/dist/screener-commands.js +0 -313
- package/dist/screener-commands.js.map +0 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const SCHEMA = `
|
|
2
|
+
-- What an admin alone holds. The seeds are the channel key: lose them and the channel can't change again.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS channel_owned (
|
|
4
|
+
channel_id BLOB PRIMARY KEY,
|
|
5
|
+
agent_id BLOB NOT NULL REFERENCES agents(agent_id),
|
|
6
|
+
ed_seed BLOB NOT NULL,
|
|
7
|
+
pq_seed BLOB NOT NULL,
|
|
8
|
+
x25519_secret BLOB NOT NULL,
|
|
9
|
+
mlkem_seed BLOB NOT NULL
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- position is the highest number with nothing unresolved at or below it. Only a post held, a signed first-held position,
|
|
13
|
+
-- or a post declared lost can move it. high is the highest number fetched, which can be above a gap.
|
|
14
|
+
CREATE TABLE IF NOT EXISTS channel_follows (
|
|
15
|
+
agent_id BLOB NOT NULL REFERENCES agents(agent_id),
|
|
16
|
+
channel_id BLOB NOT NULL,
|
|
17
|
+
record TEXT NOT NULL,
|
|
18
|
+
state TEXT NOT NULL CHECK (state IN ('active', 'pending', 'refused', 'ejected', 'left')),
|
|
19
|
+
x25519_secret BLOB,
|
|
20
|
+
mlkem_seed BLOB,
|
|
21
|
+
x25519_public BLOB,
|
|
22
|
+
mlkem_public BLOB,
|
|
23
|
+
info TEXT NOT NULL,
|
|
24
|
+
info_revision INTEGER NOT NULL,
|
|
25
|
+
delivery TEXT NOT NULL DEFAULT 'follow' CHECK (delivery IN ('follow', 'pull')),
|
|
26
|
+
screen_bodies TEXT NOT NULL DEFAULT 'read' CHECK (screen_bodies IN ('read', 'arrival')),
|
|
27
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
28
|
+
high INTEGER NOT NULL DEFAULT 0,
|
|
29
|
+
first_held INTEGER NOT NULL DEFAULT 1,
|
|
30
|
+
tip INTEGER NOT NULL DEFAULT 0,
|
|
31
|
+
aged_out INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
readers INTEGER,
|
|
33
|
+
roster TEXT,
|
|
34
|
+
roster_revision INTEGER NOT NULL DEFAULT 0,
|
|
35
|
+
roster_hash BLOB,
|
|
36
|
+
PRIMARY KEY (agent_id, channel_id)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE TABLE IF NOT EXISTS channel_keys (
|
|
40
|
+
agent_id BLOB NOT NULL,
|
|
41
|
+
channel_id BLOB NOT NULL,
|
|
42
|
+
generation INTEGER NOT NULL,
|
|
43
|
+
group_key BLOB NOT NULL,
|
|
44
|
+
PRIMARY KEY (agent_id, channel_id, generation)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- Who the signed rosters listed under each generation, so a post is checked against the generation it was written in.
|
|
48
|
+
CREATE TABLE IF NOT EXISTS channel_roster_members (
|
|
49
|
+
agent_id BLOB NOT NULL,
|
|
50
|
+
channel_id BLOB NOT NULL,
|
|
51
|
+
generation INTEGER NOT NULL,
|
|
52
|
+
member_id BLOB NOT NULL,
|
|
53
|
+
PRIMARY KEY (agent_id, channel_id, generation, member_id)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
CREATE TABLE IF NOT EXISTS channel_posts (
|
|
57
|
+
agent_id BLOB NOT NULL,
|
|
58
|
+
channel_id BLOB NOT NULL,
|
|
59
|
+
position INTEGER NOT NULL,
|
|
60
|
+
author_id BLOB,
|
|
61
|
+
author_name TEXT,
|
|
62
|
+
author_seq INTEGER,
|
|
63
|
+
generation INTEGER,
|
|
64
|
+
published_at INTEGER,
|
|
65
|
+
title BLOB,
|
|
66
|
+
body BLOB,
|
|
67
|
+
state TEXT NOT NULL CHECK (state IN ('unread', 'read', 'blocked', 'unopenable', 'refused')),
|
|
68
|
+
title_verdict TEXT NOT NULL DEFAULT 'pending' CHECK (title_verdict IN ('pending', 'allow', 'flagged', 'blocked')),
|
|
69
|
+
body_verdict TEXT NOT NULL DEFAULT 'pending' CHECK (body_verdict IN ('pending', 'allow', 'flagged', 'blocked')),
|
|
70
|
+
-- What the screen found and what the agent reads, which isn't always the text as posted.
|
|
71
|
+
title_detail TEXT,
|
|
72
|
+
body_detail TEXT,
|
|
73
|
+
PRIMARY KEY (agent_id, channel_id, position)
|
|
74
|
+
);
|
|
75
|
+
CREATE INDEX IF NOT EXISTS channel_posts_state ON channel_posts(agent_id, channel_id, state, position);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS channel_posts_author ON channel_posts(agent_id, channel_id, author_id, author_seq);
|
|
77
|
+
|
|
78
|
+
CREATE TABLE IF NOT EXISTS channel_gaps (
|
|
79
|
+
agent_id BLOB NOT NULL,
|
|
80
|
+
channel_id BLOB NOT NULL,
|
|
81
|
+
position INTEGER NOT NULL,
|
|
82
|
+
first_seen INTEGER NOT NULL,
|
|
83
|
+
state TEXT NOT NULL CHECK (state IN ('missing', 'lost')),
|
|
84
|
+
PRIMARY KEY (agent_id, channel_id, position)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
CREATE TABLE IF NOT EXISTS channel_notices (
|
|
88
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
89
|
+
agent_id BLOB NOT NULL,
|
|
90
|
+
channel_id BLOB NOT NULL,
|
|
91
|
+
text TEXT NOT NULL
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
-- The publisher's own copy. It holds the plaintext, because a new key generation has to seal a waiting post again.
|
|
95
|
+
CREATE TABLE IF NOT EXISTS channel_log (
|
|
96
|
+
agent_id BLOB NOT NULL,
|
|
97
|
+
channel_id BLOB NOT NULL,
|
|
98
|
+
author_seq INTEGER NOT NULL,
|
|
99
|
+
-- Nullable because the driver stores an empty byte string as NULL, and a post needn't have a title.
|
|
100
|
+
title BLOB,
|
|
101
|
+
body BLOB,
|
|
102
|
+
wire TEXT NOT NULL,
|
|
103
|
+
position INTEGER,
|
|
104
|
+
ack TEXT,
|
|
105
|
+
logged_at INTEGER NOT NULL,
|
|
106
|
+
PRIMARY KEY (agent_id, channel_id, author_seq)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
-- A report of a lost post that's already been passed on, so a restart doesn't tell it twice.
|
|
110
|
+
CREATE TABLE IF NOT EXISTS channel_lost_told (
|
|
111
|
+
agent_id BLOB NOT NULL,
|
|
112
|
+
channel_id BLOB NOT NULL,
|
|
113
|
+
position INTEGER NOT NULL,
|
|
114
|
+
PRIMARY KEY (agent_id, channel_id, position)
|
|
115
|
+
);
|
|
116
|
+
`;
|
|
117
|
+
export class ChannelStore {
|
|
118
|
+
#db;
|
|
119
|
+
constructor(store) {
|
|
120
|
+
this.#db = store.raw();
|
|
121
|
+
this.#db.exec(SCHEMA);
|
|
122
|
+
}
|
|
123
|
+
transaction(work) {
|
|
124
|
+
return this.#db.transaction(work);
|
|
125
|
+
}
|
|
126
|
+
insertOwned(row) {
|
|
127
|
+
this.#db.run("INSERT INTO channel_owned (channel_id, agent_id, ed_seed, pq_seed, x25519_secret, mlkem_seed) VALUES (?, ?, ?, ?, ?, ?)", [row.channel_id, row.agent_id, row.ed_seed, row.pq_seed, row.x25519_secret, row.mlkem_seed]);
|
|
128
|
+
}
|
|
129
|
+
owned(channel) {
|
|
130
|
+
return this.#db.get("SELECT * FROM channel_owned WHERE channel_id = ?", [channel]);
|
|
131
|
+
}
|
|
132
|
+
// A create the server refused, so that nothing stays half-made here either.
|
|
133
|
+
forgetCreated(agent, channel) {
|
|
134
|
+
this.#db.transaction(() => {
|
|
135
|
+
this.#db.run("DELETE FROM channel_roster_members WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
136
|
+
this.#db.run("DELETE FROM channel_keys WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
137
|
+
this.#db.run("DELETE FROM channel_follows WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
138
|
+
this.#db.run("DELETE FROM channel_owned WHERE channel_id = ?", [channel]);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
follow(agent, channel) {
|
|
142
|
+
return this.#db.get("SELECT * FROM channel_follows WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
143
|
+
}
|
|
144
|
+
follows(agent) {
|
|
145
|
+
return this.#db.all("SELECT * FROM channel_follows WHERE agent_id = ?", [agent]);
|
|
146
|
+
}
|
|
147
|
+
putFollow(row) {
|
|
148
|
+
this.#db.run(`INSERT INTO channel_follows (agent_id, channel_id, record, state, x25519_secret, mlkem_seed, x25519_public, mlkem_public, info, info_revision) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
149
|
+
ON CONFLICT (agent_id, channel_id) DO UPDATE SET state = excluded.state, x25519_secret = excluded.x25519_secret, mlkem_seed = excluded.mlkem_seed, x25519_public = excluded.x25519_public, mlkem_public = excluded.mlkem_public`, [row.agent_id, row.channel_id, row.record, row.state, row.x25519_secret, row.mlkem_seed, row.x25519_public, row.mlkem_public, row.info, row.info_revision]);
|
|
150
|
+
}
|
|
151
|
+
updateFollow(agent, channel, changes) {
|
|
152
|
+
const columns = Object.keys(changes);
|
|
153
|
+
if (columns.length === 0)
|
|
154
|
+
return;
|
|
155
|
+
this.#db.run(`UPDATE channel_follows SET ${columns.map((column) => `${column} = ?`).join(", ")} WHERE agent_id = ? AND channel_id = ?`, [...columns.map((column) => changes[column]), agent, channel]);
|
|
156
|
+
}
|
|
157
|
+
addAgedOut(agent, channel, count) {
|
|
158
|
+
this.#db.run("UPDATE channel_follows SET aged_out = aged_out + ? WHERE agent_id = ? AND channel_id = ?", [count, agent, channel]);
|
|
159
|
+
}
|
|
160
|
+
putKey(agent, channel, generation, key) {
|
|
161
|
+
this.#db.run("INSERT INTO channel_keys (agent_id, channel_id, generation, group_key) VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING", [agent, channel, generation, key]);
|
|
162
|
+
}
|
|
163
|
+
key(agent, channel, generation) {
|
|
164
|
+
const row = this.#db.get("SELECT group_key FROM channel_keys WHERE agent_id = ? AND channel_id = ? AND generation = ?", [agent, channel, generation]);
|
|
165
|
+
return row?.group_key;
|
|
166
|
+
}
|
|
167
|
+
highestKey(agent, channel) {
|
|
168
|
+
const row = this.#db.get("SELECT max(generation) AS g FROM channel_keys WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
169
|
+
return row.g ?? 0;
|
|
170
|
+
}
|
|
171
|
+
addRosterMember(agent, channel, generation, member) {
|
|
172
|
+
this.#db.run("INSERT INTO channel_roster_members (agent_id, channel_id, generation, member_id) VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING", [agent, channel, generation, member]);
|
|
173
|
+
}
|
|
174
|
+
wasOnRoster(agent, channel, generation, member) {
|
|
175
|
+
return this.#db.get("SELECT 1 AS found FROM channel_roster_members WHERE agent_id = ? AND channel_id = ? AND generation = ? AND member_id = ?", [agent, channel, generation, member]) !== undefined;
|
|
176
|
+
}
|
|
177
|
+
hasPost(agent, channel, position) {
|
|
178
|
+
return this.#db.get("SELECT 1 AS found FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]) !== undefined;
|
|
179
|
+
}
|
|
180
|
+
// What a replay would have to get past: this author's number, compared with the ones already held before this position.
|
|
181
|
+
authorSeqTaken(agent, channel, author, seq, position) {
|
|
182
|
+
const row = this.#db.get("SELECT 1 AS found FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND author_id = ? AND ((author_seq >= ? AND position < ?) OR author_seq = ?) LIMIT 1", [agent, channel, author, seq, position, seq]);
|
|
183
|
+
return row !== undefined;
|
|
184
|
+
}
|
|
185
|
+
highestGenerationBefore(agent, channel, position) {
|
|
186
|
+
const row = this.#db.get("SELECT max(generation) AS g FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND position < ?", [agent, channel, position]);
|
|
187
|
+
return row.g ?? 0;
|
|
188
|
+
}
|
|
189
|
+
insertPost(agent, channel, post) {
|
|
190
|
+
this.#db.run(`INSERT INTO channel_posts (agent_id, channel_id, position, author_id, author_name, author_seq, generation, published_at, title, body, state, title_verdict, body_verdict)
|
|
191
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT DO NOTHING`, [agent, channel, post.position, post.author_id, post.author_name, post.author_seq, post.generation, post.published_at, post.title, post.body, post.state, post.title_verdict, post.body_verdict]);
|
|
192
|
+
}
|
|
193
|
+
post(agent, channel, position) {
|
|
194
|
+
return this.#db.get("SELECT * FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]);
|
|
195
|
+
}
|
|
196
|
+
unread(agent, channel, limit) {
|
|
197
|
+
return this.#db.all("SELECT * FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND state IN ('unread', 'unopenable') ORDER BY position LIMIT ?", [agent, channel, limit]);
|
|
198
|
+
}
|
|
199
|
+
history(agent, channel, after, limit) {
|
|
200
|
+
return this.#db.all("SELECT * FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND position > ? AND state IN ('unread', 'read', 'blocked') ORDER BY position LIMIT ?", [agent, channel, after, limit]);
|
|
201
|
+
}
|
|
202
|
+
// What's waiting for the arrival screen, read from here so a restart picks it up again.
|
|
203
|
+
needingArrivalScreen(agent, channel, bodiesToo, limit) {
|
|
204
|
+
return this.#db.all("SELECT * FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND state = 'unread' AND (title_verdict = 'pending' OR (? = 1 AND body_verdict = 'pending')) ORDER BY position LIMIT ?", [agent, channel, bodiesToo ? 1 : 0, limit]);
|
|
205
|
+
}
|
|
206
|
+
unreadCount(agent, channel) {
|
|
207
|
+
return this.#db.get("SELECT count(*) AS c FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND state = 'unread'", [agent, channel]).c;
|
|
208
|
+
}
|
|
209
|
+
setVerdict(agent, channel, position, part, verdict, detail) {
|
|
210
|
+
const columns = part === "title" ? "title_verdict = ?, title_detail = ?" : "body_verdict = ?, body_detail = ?";
|
|
211
|
+
this.#db.run(`UPDATE channel_posts SET ${columns} WHERE agent_id = ? AND channel_id = ? AND position = ?`, [verdict, detail, agent, channel, position]);
|
|
212
|
+
}
|
|
213
|
+
// A blocked post's text has no further use on this machine, and it counts as delivered.
|
|
214
|
+
blockPost(agent, channel, position) {
|
|
215
|
+
this.#db.run("UPDATE channel_posts SET state = 'blocked', title = NULL, body = NULL, title_detail = NULL, body_detail = NULL WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]);
|
|
216
|
+
}
|
|
217
|
+
markRead(agent, channel, positions) {
|
|
218
|
+
this.#db.transaction(() => {
|
|
219
|
+
for (const position of positions)
|
|
220
|
+
this.#db.run("UPDATE channel_posts SET state = 'read' WHERE agent_id = ? AND channel_id = ? AND position = ? AND state IN ('unread', 'unopenable')", [agent, channel, position]);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Positions live on the follow row, so they're untouched. Each author's newest row stays, because refusing a replayed
|
|
224
|
+
// number and an older key generation both compare against it. Unread posts and anything above the position always stay.
|
|
225
|
+
prune(agent, channel, olderThan) {
|
|
226
|
+
this.#db.run(`DELETE FROM channel_posts WHERE agent_id = ? AND channel_id = ?
|
|
227
|
+
AND position <= (SELECT position FROM channel_follows WHERE agent_id = ? AND channel_id = ?)
|
|
228
|
+
AND state IN ('read', 'blocked', 'refused') AND (published_at IS NULL OR published_at < ?)
|
|
229
|
+
AND position NOT IN (SELECT max(position) FROM channel_posts WHERE agent_id = ? AND channel_id = ? AND author_id IS NOT NULL GROUP BY author_id)`, [agent, channel, agent, channel, olderThan, agent, channel]);
|
|
230
|
+
// The newest stays here too: the next number comes from it.
|
|
231
|
+
this.#db.run(`DELETE FROM channel_log WHERE agent_id = ? AND channel_id = ? AND position IS NOT NULL AND logged_at < ?
|
|
232
|
+
AND author_seq < (SELECT max(author_seq) FROM channel_log WHERE agent_id = ? AND channel_id = ?)`, [agent, channel, olderThan, agent, channel]);
|
|
233
|
+
}
|
|
234
|
+
gaps(agent, channel) {
|
|
235
|
+
return this.#db.all("SELECT position, first_seen, state FROM channel_gaps WHERE agent_id = ? AND channel_id = ? ORDER BY position", [agent, channel]);
|
|
236
|
+
}
|
|
237
|
+
putGap(agent, channel, position, firstSeen) {
|
|
238
|
+
this.#db.run("INSERT INTO channel_gaps (agent_id, channel_id, position, first_seen, state) VALUES (?, ?, ?, ?, 'missing') ON CONFLICT DO NOTHING", [agent, channel, position, firstSeen]);
|
|
239
|
+
}
|
|
240
|
+
markGapLost(agent, channel, position) {
|
|
241
|
+
this.#db.run("UPDATE channel_gaps SET state = 'lost' WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]);
|
|
242
|
+
}
|
|
243
|
+
deleteGap(agent, channel, position) {
|
|
244
|
+
this.#db.run("DELETE FROM channel_gaps WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]);
|
|
245
|
+
}
|
|
246
|
+
// A fault that persists is checked again on every pass, and it needs telling once while it's unread.
|
|
247
|
+
addNotice(agent, channel, text) {
|
|
248
|
+
this.#db.run("INSERT INTO channel_notices (agent_id, channel_id, text) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM channel_notices WHERE agent_id = ? AND channel_id = ? AND text = ?)", [agent, channel, text, agent, channel, text]);
|
|
249
|
+
}
|
|
250
|
+
notices(agent, channel) {
|
|
251
|
+
return this.#db.all("SELECT id, text FROM channel_notices WHERE agent_id = ? AND channel_id = ? ORDER BY id", [agent, channel]);
|
|
252
|
+
}
|
|
253
|
+
deleteNotices(ids) {
|
|
254
|
+
for (const id of ids)
|
|
255
|
+
this.#db.run("DELETE FROM channel_notices WHERE id = ?", [id]);
|
|
256
|
+
}
|
|
257
|
+
nextAuthorSeq(agent, channel) {
|
|
258
|
+
const row = this.#db.get("SELECT max(author_seq) AS m FROM channel_log WHERE agent_id = ? AND channel_id = ?", [agent, channel]);
|
|
259
|
+
return (row.m ?? 0) + 1;
|
|
260
|
+
}
|
|
261
|
+
addLog(agent, channel, seq, title, body, wire) {
|
|
262
|
+
this.#db.run("INSERT INTO channel_log (agent_id, channel_id, author_seq, title, body, wire, logged_at) VALUES (?, ?, ?, ?, ?, ?, ?)", [agent, channel, seq, title, body, wire, Date.now()]);
|
|
263
|
+
}
|
|
264
|
+
setLogWire(agent, channel, seq, wire) {
|
|
265
|
+
this.#db.run("UPDATE channel_log SET wire = ? WHERE agent_id = ? AND channel_id = ? AND author_seq = ?", [wire, agent, channel, seq]);
|
|
266
|
+
}
|
|
267
|
+
landLog(agent, channel, seq, position, ack) {
|
|
268
|
+
this.#db.run("UPDATE channel_log SET position = ?, ack = ? WHERE agent_id = ? AND channel_id = ? AND author_seq = ?", [position, ack, agent, channel, seq]);
|
|
269
|
+
}
|
|
270
|
+
// Refused for good, so its number can be used again and no reader sees a jump.
|
|
271
|
+
deleteLog(agent, channel, seq) {
|
|
272
|
+
this.#db.run("DELETE FROM channel_log WHERE agent_id = ? AND channel_id = ? AND author_seq = ?", [agent, channel, seq]);
|
|
273
|
+
}
|
|
274
|
+
waitingLog(agent, channel) {
|
|
275
|
+
return this.#db.all("SELECT author_seq, title, body, wire, position FROM channel_log WHERE agent_id = ? AND channel_id = ? AND position IS NULL ORDER BY author_seq", [agent, channel]);
|
|
276
|
+
}
|
|
277
|
+
logOwnsPosition(agent, channel, position) {
|
|
278
|
+
return this.#db.get("SELECT 1 AS found FROM channel_log WHERE agent_id = ? AND channel_id = ? AND position = ?", [agent, channel, position]) !== undefined;
|
|
279
|
+
}
|
|
280
|
+
markLostTold(agent, channel, position) {
|
|
281
|
+
const row = this.#db.get("INSERT INTO channel_lost_told (agent_id, channel_id, position) VALUES (?, ?, ?) ON CONFLICT DO NOTHING RETURNING position", [agent, channel, position]);
|
|
282
|
+
return row !== undefined;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PublicIdentity, type Signer } from "../protocol/identity.ts";
|
|
2
|
+
import { type PushFrame } from "../protocol/wire.ts";
|
|
3
|
+
import type { InboundVerdict } from "../screener/inbound.ts";
|
|
4
|
+
import { type Doorbell } from "./engine.ts";
|
|
5
|
+
import type { Store } from "./store.ts";
|
|
6
|
+
export interface ChannelHost {
|
|
7
|
+
signer(agentHex: string): Signer;
|
|
8
|
+
agents(): string[];
|
|
9
|
+
online(agentHex: string): boolean;
|
|
10
|
+
call(method: string, params: unknown): Promise<unknown>;
|
|
11
|
+
callLong(agentHex: string, method: string, params: unknown): Promise<unknown>;
|
|
12
|
+
serverIdentity(): PublicIdentity;
|
|
13
|
+
ring(agentHex: string, bell: Doorbell): void;
|
|
14
|
+
screen(agentHex: string, scope: string, position: number, senderHex: string, text: string): Promise<InboundVerdict>;
|
|
15
|
+
screenOutbound(agentHex: string, text: string, params: Record<string, unknown>, retry: string): Promise<{
|
|
16
|
+
text: string;
|
|
17
|
+
report: Record<string, unknown>;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare class Channels {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(store: Store, host: ChannelHost);
|
|
23
|
+
settingsChanged(): void;
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
create(agentHex: string, name: string, type: string, posting: string | undefined, retentionDays: number | undefined): Promise<unknown>;
|
|
27
|
+
join(agentHex: string, channelHex: string, note: string | undefined): Promise<unknown>;
|
|
28
|
+
leave(agentHex: string, channelHex: string): Promise<unknown>;
|
|
29
|
+
requests(agentHex: string, channelHex: string): Promise<unknown>;
|
|
30
|
+
approve(agentHex: string, channelHex: string, memberHex: string): Promise<unknown>;
|
|
31
|
+
refuse(agentHex: string, channelHex: string, memberHex: string): Promise<unknown>;
|
|
32
|
+
eject(agentHex: string, channelHex: string, memberHex: string): Promise<unknown>;
|
|
33
|
+
addPoster(agentHex: string, channelHex: string, posterHex: string): Promise<unknown>;
|
|
34
|
+
removePoster(agentHex: string, channelHex: string, posterHex: string): Promise<unknown>;
|
|
35
|
+
post(agentHex: string, channelHex: string, text: string, title: string | undefined, params?: Record<string, unknown>): Promise<unknown>;
|
|
36
|
+
checkAgent(agentHex: string): Promise<void>;
|
|
37
|
+
onPush(frame: PushFrame): void;
|
|
38
|
+
collect(agentHex: string, channelHex: string | undefined): Promise<unknown>;
|
|
39
|
+
list(agentHex: string): Promise<unknown>;
|
|
40
|
+
settings(agentHex: string, channelHex: string, delivery: string | undefined, screenBodies: string | undefined): unknown;
|
|
41
|
+
read(agentHex: string, channelHex: string, titlesOnly: boolean): Promise<{
|
|
42
|
+
result: unknown;
|
|
43
|
+
commit(): void;
|
|
44
|
+
}>;
|
|
45
|
+
history(agentHex: string, channelHex: string, after: number): Promise<unknown>;
|
|
46
|
+
}
|