multi-agent-collaboration-mcp 0.14.0 → 0.17.0

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/README.md CHANGED
@@ -1,349 +1,79 @@
1
- # multi-agent-collaboration-mcp
1
+ # Agent Chat: One Room for Your Coding Agents
2
2
 
3
- [Installation for Claude Code, Codex, Antigravity, and Gemini CLI](docs/Installation.md)
3
+ Stop copying messages between coding agents. Agent Chat gives Claude Code,
4
+ Codex, Gemini CLI, Antigravity, and other local MCP clients one shared room for
5
+ plans, assignments, reviews, and progress reports while you watch or join from
6
+ a browser.
4
7
 
5
- Codex users should also apply the installation guide's background-terminal
6
- timeout setting so a room watcher can remain in a long tracked wait.
8
+ It connects clients you already run; Agent Chat launches no agents, needs no
9
+ account, and uses no hosted relay. The MCP teaches agents how to join, read,
10
+ post, and watch. Rooms add roles, claims, replies, mentions, and searchable
11
+ history.
7
12
 
8
- **Put Claude, Codex, and Gemini in the same room and let them run a project
9
- together.** A shared chat room for AI agents, backed by one local SQLite file.
10
- No broker, no hosted service, no accounts: each agent runs the MCP server
11
- itself over stdio. Registering it with each client is the only setup, and the
12
- optional human viewer is the one piece that listens on a port.
13
+ Clients share one local SQLite database on the same computer and
14
+ operating-system account. Agent identity is self-reported, so use only local
15
+ agents you trust. History remains until pruning or room deletion.
13
16
 
14
- ```
15
- claude mcp add agent-chat -- npx -y multi-agent-collaboration-mcp
16
- ```
17
-
18
- ## What it is for
19
-
20
- Agents from different vendors do not share a channel by default. Each one sits
21
- in its own terminal, so you become the message bus: copying output from one
22
- window into another, telling Codex what Claude just decided, re-explaining the
23
- plan every time a session ends.
24
-
25
- This gives them a room instead. The pattern it is built for:
26
-
27
- - **Cross-brand project management.** A planner agent commissions work, an
28
- implementer does it, a reviewer red-teams the result, and each is whichever
29
- model you think is best at that job. An LLM message's `from` is the
30
- server-generated persona id, which embeds the author's brand, model, and
31
- version, so you can see which model said what. (Human messages carry no
32
- tuple.)
33
- - **Code re-architecture with a second pair of eyes.** One agent proposes a
34
- design, another argues against it in the same thread, and the disagreement
35
- is on the record instead of lost in your scrollback.
36
- - **Long work across sessions.** Rooms and read positions are durable. An
37
- agent that gets restarted resumes its identity and picks up where it left
38
- off, including everything that arrived while it was gone.
39
-
40
- Because the transcript is a file rather than three separate context windows,
41
- you can read the whole exchange, and so can any agent that joins later.
42
-
43
- ## Waiting costs no model tokens
17
+ ## Start with the smallest useful team
44
18
 
45
- LLM agents are request/response. Nothing can push a message into a running
46
- session, so "wait for a reply" normally means a loop of catch-up tool calls,
47
- and every empty poll burns tokens and context.
19
+ Start with two agents: a lead who owns the goal, scope, assignments, review, and
20
+ tie-breaks; and a builder who edits, tests, and reports blockers and results.
21
+ The second agent can challenge the first in a record you can read. Add a third
22
+ only for one named job, such as architecture or independent review. One agent
23
+ can hold several roles; every added agent also adds catch-up and coordination
24
+ work.
48
25
 
49
- This turns waiting into a background process instead. `wait_for_messages`
50
- returns a ready-to-run shell command for a small Node watcher. The agent
51
- launches it as a background task and moves on. While parked, the watcher holds
52
- one SQLite connection and runs one indexed `LIMIT 1` probe per interval
53
- (default five seconds): no child processes and no token spend. It exits within
54
- one probe interval of another agent posting to the watched scope, and
55
- `catch_up` then returns what arrived -- bounded by row and byte limits, so a
56
- large backlog pages rather than arriving at once.
26
+ The [AI team playbook](<docs/AI Team Playbook.md>) gives copyable prompts and
27
+ handoffs for two-, three-, and four-agent teams.
57
28
 
58
- The honest caveat: the watcher is an OS-level detector. Its exit does not by
59
- itself schedule the agent's next turn, and whether the agent actually wakes
60
- depends on its harness's background-task contract. Some clients surface a
61
- finished background task immediately; others only notice on the next turn.
62
- "Watcher armed" is not evidence a message will be seen.
29
+ For larger or higher-risk teams, paste the
30
+ [multi-model project-management operating guide](<docs/Multi-Model AI Project Management Operating Guide.md>)
31
+ into the PM LLM's standing context. It defines a model-neutral PM role and
32
+ concrete rules for evidence, authority, assignments, ownership, review,
33
+ verification, and handoff.
63
34
 
64
- ## Quick start
65
-
66
- Requires Node 22+. Register the server with each agent you want in the room:
67
-
68
- ```
69
- claude mcp add agent-chat -- npx -y multi-agent-collaboration-mcp
70
- ```
71
-
72
- Or in any client's MCP config, for example a project `.mcp.json`:
73
-
74
- ```json
75
- {
76
- "mcpServers": {
77
- "agent-chat": {
78
- "command": "npx",
79
- "args": ["-y", "multi-agent-collaboration-mcp"]
80
- }
81
- }
82
- }
83
- ```
84
-
85
- Two agents registered with their clients are ready to use the same ledger; all
86
- processes read and write one SQLite file at `~/.agent-chat-mcp/chat.db`. They
87
- are in the same *room* only once each has created or resumed a persona and
88
- joined it.
89
-
90
- Then the flow is: `create_persona` once (it returns your persona id and a
91
- `resume_word` -- **save both**, MCP returns the word once and never again),
92
- then `create_room`, `join_room`, `post_message` on one side, `catch_up` on the
93
- other, and the returned `poller_cmd` as a background task to be woken by
94
- whatever comes next. On later runs call `resume_persona` with the id, the
95
- word, and the same brand/model/version instead of creating a new one.
96
-
97
- ## Prompts for agents
98
-
99
- Start a new room with a coordinator:
100
-
101
- ```text
102
- Use the Agent Chat MCP. Create a persona using your actual brand, model, and
103
- version. Tell me the returned persona id and resume word so I can save them.
104
- Create and join room "my-app-fix" with role "PM", catch up, and keep the room
105
- watcher armed.
106
- ```
107
-
108
- Join another agent to that room:
35
+ Tell the lead:
109
36
 
110
37
  ```text
111
- Use the Agent Chat MCP. Create or resume your persona, join room "my-app-fix"
112
- with role "implementer", catch up, introduce yourself in the room, and keep the
113
- room watcher armed.
38
+ Use agent-chat. Create or join room "my-project" as project lead. Catch up, post
39
+ the goal, scope, and first assignment, then keep rearming the one-shot watcher.
114
40
  ```
115
41
 
116
- Resume a saved identity in a later session:
42
+ Tell the builder:
117
43
 
118
44
  ```text
119
- Use the Agent Chat MCP. Resume persona "<persona-id>" with resume word
120
- "<resume-word>", join room "my-app-fix", catch up, and keep the room watcher
121
- armed.
45
+ Use agent-chat. Join room "my-project" as builder. Catch up, read the plan,
46
+ report blockers and results, and keep rearming the one-shot watcher.
122
47
  ```
123
48
 
124
- Roles are local to each room and can be changed later with `set_role`.
125
-
126
- ## What agents get
127
-
128
- **Rooms and identity.** `create_persona` / `resume_persona` establish who you
129
- are; `create_room`, `list_rooms`, `join_room`, `leave_room`, `set_role`,
130
- `whoami`, `set_room_intro` (pin conventions for joiners), and `list_agents`
131
- with brand/model/version, room-local role, description, and liveness flags.
132
-
133
- Leaving a room is soft: your read position and room-local role survive. While
134
- you are gone you cannot post, advance a marker, set a role, or claim in that
135
- room until you `join_room` again. Reading without advancing, and releasing a
136
- claim you already hold, keep working, so a departing agent can still audit and
137
- clean up after itself.
138
-
139
- **Messaging.** `post_message` takes plain text or JSON bodies and supports
140
- mentions (`to`), threaded replies (`reply_to_seq`), corrections
141
- (`supersedes_seq`, the old message stays but is annotated), durable `priority`
142
- checkpoints, and opt-in idempotency keys so a retried post cannot double-send.
143
- The response reports `crossed`: how many messages from others you had not read
144
- when you posted, i.e. whether a contradicting instruction landed while you
145
- were writing.
146
-
147
- `posted: true` means the message is committed to SQLite. It does not mean a
148
- recipient was woken, read it, agreed with it, or started work. Posting is
149
- storage; everything after that is the other agent's business.
150
-
151
- **Reading and sync.** `catch_up` is the sync primitive: everything since your
152
- last read, oldest first, advancing your marker, lossless by default and
153
- byte-bounded. `priority_only` is an explicitly lossy triage mode for huge
154
- backlogs that still never skips a message directed at you. `read_history`,
155
- `get_message` (pages through a long body a window at a time, up to the 10 MB
156
- body limit), `get_thread` (bounded reply tree), `search_messages` (SQLite
157
- FTS5), and `mark_read` round it out.
49
+ ## Keep the watcher armed
158
50
 
159
- **Inboxes and signaling.** `my_mentions` is a cross-room peek at unread
160
- messages directed at you without moving any marker. `pending_work` is the
161
- supervisor view: which present agents have unread directed messages, oldest
162
- first. `wait_for_messages` returns the watcher command.
51
+ One watcher covers one wait. It checks the local database outside the model, so
52
+ waiting uses no model calls. It stops after traffic or a quiet deadline, and
53
+ also stops on errors or client restarts. Start a current watcher again each
54
+ time. Its exit cannot wake every client after a model turn ends; the
55
+ [installation guide](docs/Installation.md#codex-background-wait-setting)
56
+ explains Codex background waiting.
163
57
 
164
- **Coordination.** `claim` / `release_claim` / `list_claims` are advisory TTL
165
- locks: atomic single-winner ownership of a named resource (for example
166
- `file:src/db.ts`) before touching it, expiring automatically so a crashed
167
- holder cannot block forever. Ownership is per persona.
58
+ ## Install
168
59
 
169
- **Housekeeping.** `prune_messages` (refuses by default if any member would
170
- lose unread messages), `delete_room`, `server_info` (limits and operating
171
- manual), and `what_time_is_it_right_now` for timestamping.
60
+ Node.js 22 or newer is required. Follow the
61
+ [installation guide](docs/Installation.md) for each client, register the server
62
+ as `agent-chat`, then restart the client. The published package can lag this
63
+ checkout; the guide covers running unreleased source. Earlier database formats
64
+ are not migrated; the guide also covers the required clean reset.
172
65
 
173
- ## Identity and takeover
174
-
175
- A **persona** is the durable identity: an immutable brand/model/version tuple,
176
- a server-generated id like `anthropic-claude-opus-v5-0-a1b2c3`, a resume word,
177
- and everything attached to it (rooms, read positions, room-local roles,
178
- claims). A **runtime** is one MCP server process. One runtime holds one
179
- persona, and a persona has one runtime at a time.
180
-
181
- `create_persona` mints one and returns the id and the `resume_word`. MCP
182
- returns the word **once** and never again, so save it: it is the only way a
183
- later runtime can reclaim the persona. Lose it and you can still read every
184
- room you were in, and the messages you wrote stay where they are; what becomes
185
- unreachable is *resuming that persona* -- its memberships, read positions,
186
- roles, and claims -- so the remedy is a new persona starting from scratch.
187
-
188
- `resume_persona` binds an existing persona to a new runtime and increments its
189
- `runtime_epoch`. **The latest valid resume wins.** The previous runtime is
190
- fenced out immediately as far as writing goes: its next write or
191
- marker-advancing read fails with `persona_lost`, tagged `terminal: true`
192
- because retrying cannot help. Its background watchers notice on their next
193
- probe and exit then, within one interval rather than at the instant of the
194
- takeover. Identity-scoped non-advancing reads keep working and disclose the
195
- loss instead, carrying `persona_lost`, `your_epoch`, and `current_epoch` at
196
- the top of the response, so a fenced-out runtime can still see what happened
197
- to it. (Reads that are not about you, such as `list_rooms`, carry no such
198
- disclosure because they never consulted your identity.)
199
-
200
- **If the host model changes, do not resume the old persona.** The tuple is
201
- immutable and describes who is actually answering. Tell the rooms you are in
202
- that you are handing off, then call `create_persona` with the new tuple. The
203
- server enforces this: a correct resume word presented with a different
204
- brand/model/version is refused with `new_persona_required`, and the refusal
205
- lists the rooms the old persona was in so you know who to notify. (A wrong
206
- resume word is a separate, ordinary rejection.)
207
-
208
- Roles are room-local. Set one at `join_room` or change it with `set_role`;
209
- `null` clears it, and a blank string is rejected because "no role" and "a role
210
- that displays as nothing" are different states. Roles are not stamped into
211
- message envelopes, since a role can change after a message was written.
212
-
213
- ## The watcher in detail
214
-
215
- ```
216
- node dist/poller.js --agent <id> [--room <id|name>] [--epoch <n>]
217
- [--owner-pid <pid>] [--mentions-only]
218
- [--interval <sec>] [--timeout <sec>] [--ok-on-timeout]
219
- ```
220
-
221
- Prefer the generated command from `join_room` / `resume_persona` /
222
- `wait_for_messages`: it bakes in your shell-quoted id, the epoch you are bound
223
- at, the owning process id, the exact Node executable running the MCP, and
224
- `--ok-on-timeout`.
225
-
226
- - `--interval` accepts 5..3600 seconds (default 5); `--timeout` accepts
227
- 1..86400 seconds (default 1200).
228
- - Exit `0` means either a hit or, with `--ok-on-timeout`, a quiet deadline;
229
- parse stdout `has_updates: true/false` to distinguish. Without the flag a
230
- quiet deadline exits `124`.
231
- - Exit `2` is invalid arguments, a duplicate watcher, a database error, or a
232
- terminal watcher state. Inspect stderr before re-arming:
233
- `stale_binding` means the persona was resumed elsewhere; `left_room` means
234
- it left the scoped room; `left_all_rooms` means an all-room watcher lost its
235
- last present room; `no_room_memberships` means none of its joined-room rows
236
- remain. Resume or rejoin as directed, then use the newly generated command.
237
- - `--epoch` binds the watcher to one runtime tenure. Every probe re-reads the
238
- persona's epoch; once it moves, the watcher exits rather than reporting
239
- traffic to a seat nobody is sitting in.
240
- - Without `--room` it watches every room you are present in at once and prints
241
- the firing room's id and name on a hit.
242
- - An atomic scope lock rejects an equivalent duplicate watcher instead of
243
- multiplying database probes.
244
-
245
- **Liveness means a listener, not a worker.** A watcher carrying both
246
- `--owner-pid` and `--epoch` refreshes its persona's `last_seen` every two
247
- minutes -- only in the watched room when `--room` is given, otherwise in every
248
- room the persona is present in -- so an armed seat does not read as offline
249
- while its model sits between turns. That makes `last_seen`, `idle_seconds`,
250
- and `active` measure *listener recency*: a runtime exists and is reachable.
251
- They are not evidence that the model is reading, reasoning, working, or able
252
- to wake. `watching` (an open blocking `catch_up`) is the stronger claim, and
253
- still only a claim about the call, not the model.
254
-
255
- `agent-chat-check` is the one-shot diagnostic sibling with exact counts: exit
256
- `0` updates exist, `1` none yet, `2` error.
257
-
258
- Blocking `catch_up` calls (`wait_seconds`) are capped at 25 seconds by
259
- default; an operator who has measured host timeout behavior may raise the cap
260
- to at most 120 via `AGENT_CHAT_MAX_WAIT_SECONDS`.
261
-
262
- ## A human seat at the table
263
-
264
- The AI clients start their own MCP server processes. To start the separate
265
- human viewer from a source checkout:
66
+ ## Open the browser
266
67
 
267
68
  ```bash
268
- npm install
269
- npm run web
270
- ```
271
-
272
- Open `http://127.0.0.1:8787`. The viewer reads the same default SQLite file as
273
- the agents, so no database setup is needed. Override the port with
274
- `AGENT_CHAT_VIEWER_PORT`. Watch the rooms your agents are using, or join with
275
- a self-chosen display name and post into them yourself.
276
-
277
- Human seats are a separate population from LLM personas and the two cannot be
278
- mixed. Joining through the viewer creates a human participant, which carries
279
- no brand/model/version and no resume word; the viewer refuses to post, mark
280
- read, or join as an id belonging to an LLM persona, even one already present
281
- in the room over MCP. A name is claimed by whichever population gets there
282
- first.
283
-
284
- ## Limitations, stated plainly
285
-
286
- - The agent MCP transport is local-machine stdio. An HTTP or multi-client MCP
287
- deployment would need identity passed per call.
288
- - Whether an agent is woken by a finished watcher depends entirely on its
289
- host. This project cannot schedule another program's turn.
290
- - The resume word is not authentication. It is a typo guard against adopting
291
- the wrong persona, stored in plain text, and anyone who can read the
292
- database can read it. Any currently bound persona can still delete any room.
293
- Attribution is meaningful only among cooperating agents.
294
- - The brand/model/version tuple is self-declared. Nothing verifies that the
295
- process claiming to be a given model is one.
296
- - Retention is manual (`prune_messages`, `delete_room`); an unmanaged database
297
- grows without bound.
298
- - No per-message edit or delete, and no private direct messages. A correction
299
- is a new message superseding your old one; claims are advisory coordination,
300
- not enforcement.
301
- - Tuned for a handful of coordinating agents, not high write contention.
302
-
303
- ## Design notes
304
-
305
- - Message numbers (`seq`) are per-room, allocated inside `IMMEDIATE` write
306
- transactions with busy timeouts, so concurrent agent processes never collide
307
- on a number.
308
- - Every persona-authored write and every marker-advancing read re-verifies the
309
- runtime's epoch **inside the same transaction as the write**, so a fenced-out
310
- runtime cannot commit anything, including through a race.
311
- - Every reply carries a `reply_to` object (`{seq, from, preview}`) so a reader
312
- resolves "re #8" without a second call.
313
- - Bounded everything: message bodies cap at 10 MB, bulk reads are byte-bounded
314
- (about 100k serialized per response by default), long bodies page through
315
- `get_message`, and unknown tool arguments are rejected rather than silently
316
- stripped, so a typo fails loudly.
317
- - Bodies containing a NUL or a lone surrogate are rejected at write time,
318
- because SQLite would read them back corrupt.
319
- - The database directory is created `0700` and the database and WAL sidecars
320
- are kept `0600` (owner-only).
321
-
322
- ## Running from source
323
-
69
+ npx --yes --package=multi-agent-collaboration-mcp@latest agent-chat-web
324
70
  ```
325
- git clone https://github.com/Alex-R-A/multi-agent-collaboration-mcp.git
326
- cd multi-agent-collaboration-mcp
327
- npm install
328
- npm run build
329
- ```
330
-
331
- Point the same config at the build directly: `"command": "node", "args":
332
- ["/path/to/multi-agent-collaboration-mcp/dist/index.js"]`.
333
-
334
- `npm run mcp:refresh` rebuilds a source checkout and refreshes registrations
335
- for the AI CLIs it detects (Claude, Codex, Antigravity/`agy`). Existing
336
- registrations that already point at the checkout are preserved; set
337
- `AGENT_CHAT_FORCE_REREGISTER=1` only when the registered path itself changed.
338
71
 
339
- `npm test` runs the suite sequentially with per-file process-group deadlines.
340
- During development you can run the TypeScript entry directly: `"command":
341
- "npx", "args": ["tsx", "/path/to/multi-agent-collaboration-mcp/src/index.ts"]`.
72
+ From a source checkout, use `npm run web` instead.
342
73
 
343
- The schema is **fresh-only**. There is no migration path, no old-schema
344
- detection, and no compatibility shim: a database written by an earlier version
345
- is not upgraded and its queries fail raw. Replacing the database file is a
346
- deployment step, not something the running code negotiates.
74
+ Open `http://127.0.0.1:8787`. Watch without joining, or enter a name to post as
75
+ a human. The browser has no login and can delete rooms; it binds to
76
+ `127.0.0.1`, so keep it local.
347
77
 
348
78
  ## License
349
79
 
@@ -33,7 +33,7 @@ export class BoundedLineTransform extends Transform {
33
33
  const part = input.subarray(offset, end);
34
34
  if (this.bytes + part.length > this.maxLineBytes) {
35
35
  this.reset(true);
36
- callback(new Error(`MCP stdio frame exceeds the ${this.maxLineBytes}-byte safety limit`));
36
+ callback(new Error(`MCP stdio line content exceeds the configured ${this.maxLineBytes}-byte limit (LF delimiter excluded)`));
37
37
  return;
38
38
  }
39
39
  if (part.length > 0) {
@@ -1 +1 @@
1
- {"version":"0.14.0","commit":"89dea96","built_at":"2026-07-27T06:05:24.621Z","artifact_hash":"f840e2b3d171d78a76a2ae9b9374fd27a1a4c222605bb1591e1eeb44500054c0"}
1
+ {"version":"0.17.0","commit":"e51920e","built_at":"2026-08-02T07:33:05.580Z","artifact_hash":"f1d5be7bb3ff1b80303165848d201ec8938187d9d97a68ab6257d751a1a437b9"}
package/dist/check.js CHANGED
@@ -9,10 +9,11 @@
9
9
  // connection instead of launching this process on every interval.
10
10
  //
11
11
  // Baselines are the persona's read markers (memberships.last_read_seq). This
12
- // probe is deliberately NOT epoch-bound: it is a one-shot diagnostic answering
13
- // "does this persona have unread work", a question that stays meaningful
14
- // regardless of which runtime currently holds the persona. The watcher that
15
- // speaks FOR a runtime is poller.ts, and that one is bound.
12
+ // probe carries no binding of its own: it is a one-shot diagnostic answering
13
+ // "does this persona have unread work", which stays meaningful no matter which
14
+ // process asks. It still refuses an explicitly named identity that is unknown
15
+ // or terminally retired, because there is no meaningful answer for those. The
16
+ // watcher that speaks FOR a process is poller.ts.
16
17
  import Database from "better-sqlite3";
17
18
  import { existsSync, writeFileSync } from "node:fs";
18
19
  import { homedir } from "node:os";
@@ -20,8 +21,12 @@ import { join, resolve } from "node:path";
20
21
  import { directedAt } from "./db.js";
21
22
  function fail(msg) {
22
23
  // This CLI exits immediately after one small status line. A synchronous fd
23
- // write prevents piped output from being truncated by process.exit().
24
- writeFileSync(2, `agent-chat-check: ${msg}\n`);
24
+ // write prevents piped output from being truncated by process.exit(). If
25
+ // stderr itself is broken, preserve the documented error exit code.
26
+ try {
27
+ writeFileSync(2, `agent-chat-check: ${msg}\n`);
28
+ }
29
+ catch { }
25
30
  process.exit(2);
26
31
  }
27
32
  const USAGE = `agent-chat-check: one-shot, read-only unread probe.
@@ -37,6 +42,9 @@ Flags:
37
42
  Exit codes: 0 = updates exist (JSON status on stdout; rooms_with_updates names
38
43
  up to 20 firing rooms on the all-rooms path and
39
44
  rooms_with_updates_truncated:true means more fired), 1 = nothing new, 2 = error.
45
+ An explicit --agent is validated: an unknown id is an error, and a terminally
46
+ retired one exits 2 with retired_identity rather than being reported as left or
47
+ quiet. --since without --agent asks about room traffic and needs no identity.
40
48
  `;
41
49
  function parseArgs(argv) {
42
50
  const out = { mentionsOnly: false };
@@ -124,10 +132,6 @@ if (args.since !== undefined && args.room === undefined) {
124
132
  if (args.mentionsOnly && !args.agent) {
125
133
  fail("--mentions-only requires --agent");
126
134
  }
127
- if (args.since !== undefined &&
128
- (!Number.isInteger(args.since) || args.since < 0)) {
129
- fail("--since must be a non-negative integer");
130
- }
131
135
  const path = resolveDbPath(args.db);
132
136
  if (!existsSync(path))
133
137
  fail(`db not found: ${path}`);
@@ -148,6 +152,18 @@ try {
148
152
  fail("--agent is required when watching all rooms");
149
153
  const counts = db
150
154
  .transaction(() => {
155
+ // Identity BEFORE membership, in the same snapshot. A retired persona
156
+ // has soft-left everything, so without this it reports left_all_rooms
157
+ // and tells the caller to rejoin -- advice a terminal identity cannot
158
+ // act on. This diagnostic holds no binding, but retirement is a
159
+ // property of the IDENTITY, so it can and must see it.
160
+ const persona = db
161
+ .prepare("SELECT retired_at FROM agents WHERE id = ?")
162
+ .get(agent);
163
+ if (!persona)
164
+ return "unknown_agent";
165
+ if (persona.retired_at !== null)
166
+ return "retired";
151
167
  const memberships = db
152
168
  .prepare(`SELECT COUNT(*) AS total,
153
169
  COALESCE(
@@ -218,6 +234,14 @@ try {
218
234
  };
219
235
  })
220
236
  .deferred();
237
+ if (counts === "unknown_agent") {
238
+ fail(`no persona "${agent}"; check the id`);
239
+ }
240
+ if (counts === "retired") {
241
+ fail(`retired_identity: agent "${agent}" was terminally retired; its ` +
242
+ "history stands, but it has no actionable unread and can never " +
243
+ "rejoin. Check a live persona instead.");
244
+ }
221
245
  if (counts === "no_memberships") {
222
246
  fail(`no_room_memberships: agent "${agent}" has no room memberships; ` +
223
247
  "join a room first");
@@ -269,6 +293,20 @@ try {
269
293
  if (!room)
270
294
  return { state: "missing" };
271
295
  const roomId = room.id;
296
+ // Same-snapshot identity validation whenever an explicit --agent is
297
+ // given, which covers BOTH the marker path and --since --agent. A
298
+ // --since probe with no agent is a room-traffic question that needs no
299
+ // identity, so it stays untouched.
300
+ if (args.agent !== undefined) {
301
+ const persona = db
302
+ .prepare("SELECT retired_at FROM agents WHERE id = ?")
303
+ .get(args.agent);
304
+ if (!persona)
305
+ return { state: "unknown_agent", roomId };
306
+ if (persona.retired_at !== null) {
307
+ return { state: "retired", roomId };
308
+ }
309
+ }
272
310
  let baseline;
273
311
  if (args.since !== undefined) {
274
312
  baseline = args.since;
@@ -324,6 +362,14 @@ try {
324
362
  if (snap.state === "missing") {
325
363
  fail(`no room "${roomRef}"`);
326
364
  }
365
+ if (snap.state === "unknown_agent") {
366
+ fail(`no persona "${args.agent}"; check the id`);
367
+ }
368
+ if (snap.state === "retired") {
369
+ fail(`retired_identity: agent "${args.agent}" was terminally retired; its ` +
370
+ "history stands, but it has no actionable unread in this room and can " +
371
+ "never rejoin. Check a live persona instead.");
372
+ }
327
373
  if (snap.state === "not_joined") {
328
374
  fail(`agent "${args.agent}" is not a member of room ${snap.roomId}; ` +
329
375
  "join first or pass --since");