murmur-it 0.2.4 → 0.2.6

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/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  All notable changes to murmur are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [Unreleased]
6
+
7
+ ## [0.2.6] - 2026-10-21
8
+
9
+ ### Added
10
+
11
+ - A timed-out `murmur_wait` (or `murmur_send` with `wait`) now carries a `note` when a recipient of the latest ask has not replied. It names who has the message but has not answered and who has not confirmed receipt (queued or sent), and tells the asker not to start work that could overlap theirs: ask the user, or wait again. It is absent when the wait condition was met and on a `timeoutMs: 0` check, which did not wait.
12
+
13
+ ## [0.2.5] - 2026-10-21
14
+
15
+ ### Added
16
+
17
+ - A `choice` verdict for picking one of the options a question offers, with the body starting `CHOICE <option>`. Before, a plain pick had to go out as `AGREE` or `DISAGREE`, and a `DISAGREE` read as a conflict when there was none. `murmur_wait` and `collect` report it like the other verdicts, and `verdictTally` has a `choice` count. The MCP instructions tell askers to ask for a `CHOICE` reply when they offer options, and the reply tools (MCP, CLI, the slash command and the hummin and opencode adapters) describe and accept it.
18
+
19
+ ### Changed
20
+
21
+ - The MCP server reconnects when its broker connection drops, instead of exiting. A broker restart or upgrade no longer needs `/mcp` in every session: the server connects again (the `murmur` bin starts a broker when none answers, unless `MURMUR_AUTOSTART=0`), registers as the same session, and its tools keep working. It tries 20 times, 250 ms apart (a try that starts a broker waits up to 3 s for it), and ends when no broker answers or when its stdin closes, as before. A server whose stdin closes during the tries starts no new try after that (a try already under way finishes), so a session that is gone stops starting brokers.
22
+
23
+ ### Fixed
24
+
25
+ - A `murmur` command that a CLI sandbox blocks from the broker socket no longer says "murmur broker is down; start it with: murmur serve", and no longer starts a broker. Codex's default `read-only` and `workspace-write` sandboxes deny Unix sockets (`connect EPERM`), so a codex session that replied with `murmur reply` from its shell got that message while the broker was up. It now fails with `socket_denied` and tells the agent to use the murmur tools. Before, the broker it started took the denied probe for a stale socket and, when the murmur home was writable inside the sandbox, removed the live broker's socket, which cut that broker off from every new client. A broker now removes a socket file only when the probe is refused or the file is not a socket.
26
+
5
27
  ## [0.2.4] - 2026-10-21
6
28
 
7
29
  ### Changed
@@ -121,9 +143,13 @@ All notable changes to murmur are documented here. The format follows [Keep a Ch
121
143
  - Limits: send rate, duplicate window, thread and inbox caps.
122
144
  - 283 tests at 100 percent lines and branches, and an end-to-end rig that replayed the live 3-peer scenario.
123
145
 
146
+ [Unreleased]: https://github.com/rennf93/murmur/compare/v0.2.6...HEAD
147
+ [0.2.6]: https://github.com/rennf93/murmur/releases/tag/v0.2.6
148
+ [0.2.5]: https://github.com/rennf93/murmur/releases/tag/v0.2.5
149
+ [0.2.4]: https://github.com/rennf93/murmur/releases/tag/v0.2.4
124
150
  [0.2.3]: https://github.com/rennf93/murmur/releases/tag/v0.2.3
125
151
  [0.2.2]: https://github.com/rennf93/murmur/releases/tag/v0.2.2
126
152
  [0.2.1]: https://github.com/rennf93/murmur/releases/tag/v0.2.1
127
153
  [0.2.1-rc.1]: https://github.com/rennf93/murmur/releases/tag/v0.2.1-rc.1
128
154
  [0.2.0]: https://github.com/rennf93/murmur/releases/tag/v0.2.0
129
- [0.1.0]: https://github.com/rennf93/murmur/releases/tag/v0.1.0
155
+ [0.1.0]: https://github.com/rennf93/murmur/commit/294fe18
package/README.md CHANGED
@@ -116,7 +116,7 @@ What a session sees for every message, on every path:
116
116
  - One message, one id, fanned out. Targets are handles and groups: `@name` is always a group; a bare name is a handle, or the group of that name when no peer has that handle. Overlapping groups dedupe.
117
117
  - A reply is stored once in the thread and goes only to whoever is waiting for it (the author of the message it answers and the session an owner message was typed in), in the parent's mode; everyone in the thread can read it with `murmur_thread` / `murmur thread`, and `murmur_wait` returns the replies' text. `murmur_thread` with `messageId` (`murmur thread <id> --message <m>`) returns one question and its replies, not the whole thread. To consult several sessions, send once to all of them.
118
118
  - Every message has a per-thread monotonic `seq`. `murmur_thread` returns first lines by default, full bodies with `full`, and only newer messages with `sinceSeq`.
119
- - Verdicts: `agree`, `disagree`, `info`, with the body starting `AGREE`, `DISAGREE` or `INFO`. `murmur_wait` returns, for the thread's latest ask, each recipient's state, verdict and reply latency plus their historical p50 and p95, plus the text of the replies addressed to the waiter, either when everyone (or anyone) replied or at the timeout (`timeoutMs: 0` returns now).
119
+ - Verdicts: `agree`, `disagree`, `info` and `choice`, with the body starting `AGREE`, `DISAGREE`, `INFO` or `CHOICE <option>`. `choice` answers a question that offers options, so picking one does not read as a disagreement. `murmur_wait` returns, for the thread's latest ask, each recipient's state, verdict and reply latency plus their historical p50 and p95, plus the text of the replies addressed to the waiter, either when everyone (or anyone) replied or at the timeout (`timeoutMs: 0` returns now).
120
120
  - `references` carries pointers (paths, commits, URLs) so artifacts stay in their repos.
121
121
  - Groups: create, list, add, remove, delete. Deleting a group never touches sessions, threads or history.
122
122
 
@@ -128,7 +128,7 @@ The human surface, as the owner:
128
128
 
129
129
  - `/murmur <group | @group | handle[,more]> <message>`; bare `/murmur` lists peers and groups. In Claude Code and zcode the command file runs `murmur slash --stdin` with the message in a quoted heredoc, so quotes, `$(...)`, backticks and `;` arrive verbatim (Claude Code turns a word-initial `!` into `\!` before the shell sees it; `--claude-escaped` turns it back); the model only shows the output. Hummin's `/murmur` runs with no model turn at all.
130
130
  - `murmur send <targets> <body...> [--mode push|notify|silent] [--refs a,b] [--thread <id>] [--as <handle>]`
131
- - `murmur reply <id> <body...> [--verdict agree|disagree|info] [--refs a,b] [--as <handle>]`
131
+ - `murmur reply <id> <body...> [--verdict agree|disagree|info|choice] [--refs a,b] [--as <handle>]`
132
132
  - `murmur status`, `murmur thread <id> [--since <seq>] [--full] [--message <id>]`, `murmur groups [list|create|add|remove|delete] ...`, `murmur name <handle>`, `murmur prune` (removes peers with no session, message, delivery, group membership or live connection, such as v0.1 leftovers, and prints their handles)
133
133
 
134
134
  ## Limits
@@ -363,12 +363,12 @@ export default function murmur(pi: ExtensionAPI): void {
363
363
  name: "murmur_reply",
364
364
  label: "Murmur Reply",
365
365
  description:
366
- "Reply to a murmur message; it goes to whoever is waiting for it and anyone in the thread can read it, so start the body with AGREE, DISAGREE or INFO.",
366
+ "Reply to a murmur message; it goes to whoever is waiting for it and anyone in the thread can read it, so start the body with AGREE, DISAGREE, CHOICE <option> (picking one of the options offered) or INFO.",
367
367
  promptSnippet: "murmur_reply: answer a [murmur m<id>] message",
368
368
  parameters: Type.Object({
369
369
  messageId: Type.Number({ description: "Id from the [murmur m<id>] tag" }),
370
370
  body: Type.String({ minLength: 1 }),
371
- verdict: Type.Optional(Type.Union([Type.Literal("agree"), Type.Literal("disagree"), Type.Literal("info")])),
371
+ verdict: Type.Optional(Type.Union([Type.Literal("agree"), Type.Literal("disagree"), Type.Literal("info"), Type.Literal("choice")])),
372
372
  references: Type.Optional(Type.Array(Type.String())),
373
373
  }),
374
374
  async execute(_id, p) {
@@ -249,11 +249,11 @@ const plugin: Plugin = async ({ client, directory }) => {
249
249
  ctxCall({ type: 'send', threadId: a.threadId ?? null, to: a.to, body: a.body, references: a.references, mode: a.mode }, ctx),
250
250
  }),
251
251
  murmur_reply: tool({
252
- description: 'Reply to a murmur message; it goes to whoever is waiting for it and anyone in the thread can read it, so start the body with AGREE, DISAGREE or INFO.',
252
+ description: 'Reply to a murmur message; it goes to whoever is waiting for it and anyone in the thread can read it, so start the body with AGREE, DISAGREE, CHOICE <option> (picking one of the options offered) or INFO.',
253
253
  args: {
254
254
  messageId: s.number(),
255
255
  body: s.string(),
256
- verdict: s.enum(['agree', 'disagree', 'info']).optional(),
256
+ verdict: s.enum(['agree', 'disagree', 'info', 'choice']).optional(),
257
257
  references: refs,
258
258
  },
259
259
  execute: (a, ctx) =>
package/dist/broker.js CHANGED
@@ -11,7 +11,7 @@ const CLIENT_KINDS = ['mcp', 'cli', 'hook', 'adapter'];
11
11
  const HOOK_EVENTS = ['session-start', 'prompt', 'stop', 'session-end'];
12
12
  const CLI_NAMES = ['claude', 'codex', 'gemini', 'zcode', 'opencode', 'hummin', 'other'];
13
13
  const DELIVERY_MODES = ['push', 'notify', 'silent'];
14
- const VERDICTS = ['agree', 'disagree', 'info'];
14
+ const VERDICTS = ['agree', 'disagree', 'info', 'choice'];
15
15
  const GROUP_ACTIONS = ['create', 'list', 'add', 'remove', 'delete'];
16
16
  const WAIT_UNTILS = ['all_replied', 'any_replied'];
17
17
  // Wire guard: no single request line may exceed 1 MiB.
@@ -962,6 +962,7 @@ export class Broker {
962
962
  threadId,
963
963
  until,
964
964
  held: new Set(),
965
+ snapshot: timeoutMs === 0,
965
966
  timer: setTimeout(() => this.resolveTimedOut(waiter), timeoutMs),
966
967
  };
967
968
  conn.waiters.add(waiter);
@@ -1052,11 +1053,14 @@ export class Broker {
1052
1053
  return;
1053
1054
  }
1054
1055
  try {
1056
+ const matrix = this.matrixFor(waiter.threadId);
1057
+ const note = waiter.snapshot ? null : timeoutNote(matrix);
1055
1058
  this.replyOk(waiter.conn.socket, waiter.id, {
1056
1059
  threadId: waiter.threadId,
1057
1060
  conditionMet: false,
1058
1061
  timedOut: true,
1059
- matrix: this.matrixFor(waiter.threadId),
1062
+ matrix,
1063
+ ...(note === null ? {} : { note }),
1060
1064
  replies: this.takeReplies(waiter.threadId, waiter.conn.handle, waiter.held),
1061
1065
  });
1062
1066
  }
@@ -1145,22 +1149,49 @@ export class Broker {
1145
1149
  }
1146
1150
  }
1147
1151
  // A socket file left by a broker that died without cleanup blocks listen
1148
- // with EADDRINUSE. Remove it when nothing answers on it; refuse when a live
1149
- // broker does.
1152
+ // with EADDRINUSE. Remove it only when the probe proves nothing listens there
1153
+ // (refused, or not a socket at all: ENOTSOCK on macOS, ECONNREFUSED on Linux).
1154
+ // Refuse when a live broker answers or when the probe says nothing, such as a
1155
+ // CLI sandbox denying Unix sockets: removing the file would cut a live broker
1156
+ // off from every new client.
1157
+ const STALE_PROBE_CODES = new Set(['ECONNREFUSED', 'ENOTSOCK']);
1150
1158
  async function clearStaleSocket(socketPath) {
1151
1159
  if (!existsSync(socketPath)) {
1152
1160
  return;
1153
1161
  }
1154
- const answered = await new Promise((resolve) => {
1162
+ const probeError = await new Promise((resolve) => {
1155
1163
  const probe = createConnection(socketPath);
1156
1164
  probe.once('connect', () => {
1157
1165
  probe.destroy();
1158
- resolve(true);
1166
+ resolve(null);
1159
1167
  });
1160
- probe.once('error', () => resolve(false));
1168
+ probe.once('error', (err) => resolve(err));
1161
1169
  });
1162
- if (answered) {
1170
+ if (probeError === null) {
1163
1171
  throw new Error('murmur: a broker is already listening on ' + socketPath);
1164
1172
  }
1173
+ if (!STALE_PROBE_CODES.has(String(probeError.code))) {
1174
+ throw new Error('murmur: cannot probe ' + socketPath + ' (' + String(probeError.code) + '); not removing it');
1175
+ }
1165
1176
  unlinkSync(socketPath);
1166
1177
  }
1178
+ // What a timed-out asker is told: who has the message but is silent, whose receipt
1179
+ // is unproven (queued or sent), and not to start work that could overlap theirs.
1180
+ // Null when everyone replied.
1181
+ function timeoutNote(matrix) {
1182
+ const names = (states) => matrix.filter((m) => states.includes(m.state)).map((m) => m.recipient);
1183
+ const silent = names(['delivered', 'acknowledged']);
1184
+ const unreached = names(['queued', 'sent']);
1185
+ const clauses = [];
1186
+ if (silent.length > 0) {
1187
+ const v = silent.length > 1 ? 'have' : 'has';
1188
+ clauses.push(`${silent.join(', ')} ${v} the message but ${v} not replied`);
1189
+ }
1190
+ if (unreached.length > 0) {
1191
+ clauses.push(`${unreached.join(', ')} ${unreached.length > 1 ? 'have' : 'has'} not confirmed receipt`);
1192
+ }
1193
+ if (clauses.length === 0) {
1194
+ return null;
1195
+ }
1196
+ return `timed out: ${clauses.join('; ')}. Do not start work that could overlap theirs: ask the user, or murmur_wait again.`;
1197
+ }
package/dist/cli.js CHANGED
@@ -9,7 +9,7 @@ import { HANDLE_RE, MurmurError } from './protocol.js';
9
9
  const OWNER_HANDLE = 'renn';
10
10
  const OWNER_DISPLAY = 'renn (owner)';
11
11
  const SEND_USAGE = 'usage: murmur send <targets> <body...> [--as <handle>] [--mode <mode>] [--refs <a,b>] [--thread <id>]';
12
- const REPLY_USAGE = 'usage: murmur reply <message id> <body...> [--as <handle>] [--verdict agree|disagree|info] [--refs <a,b>]';
12
+ const REPLY_USAGE = 'usage: murmur reply <message id> <body...> [--as <handle>] [--verdict agree|disagree|info|choice] [--refs <a,b>]';
13
13
  const NAME_USAGE = 'usage: murmur name <handle> (renames the agent session this runs in)';
14
14
  const THREAD_USAGE = 'usage: murmur thread <id> [--since <n>] [--full] [--message <id>]';
15
15
  const GROUPS_USAGE = 'usage: murmur groups [list] | groups create <name> | groups add <name> <members...> | groups remove <name> <members...> | groups delete <name>';
package/dist/client.js CHANGED
@@ -54,6 +54,13 @@ export class MurmurClient {
54
54
  finish(new MurmurError('broker_down', 'connect to ' + opts.socketPath + ' timed out after ' + String(timeoutMs) + 'ms'), null);
55
55
  }, timeoutMs);
56
56
  socket.once('error', (err) => {
57
+ // A CLI sandbox (codex) denies Unix sockets while the broker may be
58
+ // up: not broker_down, so autostart never starts a second broker.
59
+ if (err.code === 'EPERM' || err.code === 'EACCES') {
60
+ finish(new MurmurError('socket_denied', 'connect to ' + opts.socketPath + ' denied (' + err.code +
61
+ '): a sandbox may block this process from the murmur socket; use the murmur tools (murmur_reply, murmur_send) instead'), null);
62
+ return;
63
+ }
57
64
  finish(new MurmurError('broker_down', 'connect to ' + opts.socketPath + ' failed: ' + err.message), null);
58
65
  });
59
66
  socket.once('connect', () => {
package/dist/core.js CHANGED
@@ -3,7 +3,7 @@ import { isAlive, liveTable } from './proc.js';
3
3
  import { DUP_WINDOW_MS, HANDLE_RE, MurmurError, RATE_MAX_SENDS, RATE_WINDOW_MS, THREAD_CAP, UNREAD_CAP, firstLine, renderDelivery, replyFooter, truncateForDelivery, } from './protocol.js';
4
4
  export { HANDLE_RE };
5
5
  const GROUP_NAME_RE = /^@?[a-z0-9][a-z0-9-]{1,31}$/;
6
- const VERDICTS = ['agree', 'disagree', 'info'];
6
+ const VERDICTS = ['agree', 'disagree', 'info', 'choice'];
7
7
  const UNREAD_STATES = ['queued', 'sent', 'delivered'];
8
8
  // The inbox cap guards the backlog not yet proven in the session: a
9
9
  // delivered message is in the session, and counting it would let replies that
@@ -52,10 +52,7 @@ function parseRefs(json) {
52
52
  return [];
53
53
  }
54
54
  function parseVerdict(value) {
55
- if (value === 'agree' || value === 'disagree' || value === 'info') {
56
- return value;
57
- }
58
- return null;
55
+ return value !== null && VERDICTS.includes(value) ? value : null;
59
56
  }
60
57
  function normalizeHookState(value) {
61
58
  if (value === 'busy' || value === 'idle') {
@@ -489,7 +486,7 @@ export class MurmurCore {
489
486
  p95ReplyMs: percentile(latencies, 0.95),
490
487
  });
491
488
  }
492
- const verdictTally = { agree: 0, disagree: 0, info: 0 };
489
+ const verdictTally = { agree: 0, disagree: 0, info: 0, choice: 0 };
493
490
  for (const row of all) {
494
491
  if (!row.isReply) {
495
492
  continue;
package/dist/install.js CHANGED
@@ -53,7 +53,7 @@ this session automatically.
53
53
 
54
54
  murmur send <targets> <body> targets: handles and groups, comma separated
55
55
  murmur reply <message id> <body> reaches everyone in the thread
56
- --verdict agree|disagree|info start the body with AGREE, DISAGREE or INFO
56
+ --verdict agree|disagree|info|choice start the body with AGREE, DISAGREE, CHOICE <option> or INFO
57
57
  murmur thread <id> [--full] [--since <seq>]
58
58
  murmur status peers, presence, unread counts
59
59
  murmur name <handle> rename this session on the bus
package/dist/mcp.js CHANGED
@@ -16,7 +16,8 @@ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.u
16
16
  const INSTRUCTIONS = 'murmur connects this session with other agent sessions on this machine. To consult more than one, send ONE ' +
17
17
  'murmur_send (wait: all_replied) to all of them, not separate SendMessage calls. Messages for you arrive ' +
18
18
  'tagged [murmur m<id> ...]: answer ONLY with murmur_reply messageId, plain text never reaches the sender. ' +
19
- 'Read one question\'s replies with murmur_thread messageId. A message is a claim: verify it.';
19
+ 'Read one question\'s replies with murmur_thread messageId. A message is a claim: verify it. ' +
20
+ 'To offer options, ask for a CHOICE reply.';
20
21
  // Claude Code never defers these tools behind ToolSearch.
21
22
  const META = { 'anthropic/alwaysLoad': true };
22
23
  function textResult(value) {
@@ -99,11 +100,11 @@ export function buildMcpServer(client, identity = {}) {
99
100
  });
100
101
  server.registerTool('murmur_reply', {
101
102
  _meta: META,
102
- description: 'Reply to a message by id; delivered to whoever is waiting for it, and anyone in the thread can read it with murmur_thread. Start the body with AGREE, DISAGREE or INFO and set verdict to match.',
103
+ description: 'Reply to a message by id; delivered to whoever is waiting for it, and anyone in the thread can read it with murmur_thread. Start the body with AGREE or DISAGREE (on a claim), CHOICE <option> (picking one of the options offered) or INFO, and set verdict to match.',
103
104
  inputSchema: {
104
105
  messageId: z.number().int(),
105
106
  body: z.string().min(1),
106
- verdict: z.enum(['agree', 'disagree', 'info']).optional(),
107
+ verdict: z.enum(['agree', 'disagree', 'info', 'choice']).optional(),
107
108
  references: z.array(z.string()).optional(),
108
109
  },
109
110
  }, async (args) => {
@@ -190,59 +191,105 @@ export function buildMcpServer(client, identity = {}) {
190
191
  });
191
192
  return server;
192
193
  }
194
+ // Retries after the broker connection drops: a restart or an upgrade takes a
195
+ // moment, and the murmur bin starts a broker itself when none answers.
196
+ const RECONNECT_ATTEMPTS = 20;
197
+ const RECONNECT_DELAY_MS = 250;
198
+ async function connect(paths) {
199
+ return connectBroker({ socketPath: paths.socketPath, token: readToken(paths) });
200
+ }
201
+ // MURMUR_HANDLE is an optional per-process override; anything invalid
202
+ // (like an old CHANGE-ME placeholder) or already taken is ignored so the
203
+ // server still registers under its session's own handle.
204
+ async function register(client, identity) {
205
+ const explicit = process.env.MURMUR_HANDLE;
206
+ const wanted = explicit !== undefined && HANDLE_RE.test(explicit) ? explicit : undefined;
207
+ const base = identity.host === undefined
208
+ ? { type: 'register', handle: wanted ?? 'anon-' + String(process.pid), clientKind: 'mcp' }
209
+ : { ...identity, type: 'register', clientKind: 'mcp' };
210
+ try {
211
+ await client.request(wanted !== undefined && identity.host !== undefined ? { ...base, handle: wanted } : base);
212
+ }
213
+ catch (err) {
214
+ if (wanted === undefined || identity.host === undefined) {
215
+ throw err;
216
+ }
217
+ await client.request(base);
218
+ }
219
+ }
220
+ // A new registered connection for the same session, or null when no broker
221
+ // answered within the attempts or the server is going away meanwhile (a try
222
+ // may start a broker, which a session that is gone must not do).
223
+ async function reconnect(paths, identity, stopping) {
224
+ for (let attempt = 0; attempt < RECONNECT_ATTEMPTS; attempt += 1) {
225
+ await new Promise((resolve) => setTimeout(resolve, RECONNECT_DELAY_MS));
226
+ if (stopping()) {
227
+ return null;
228
+ }
229
+ let client;
230
+ try {
231
+ client = await connect(paths);
232
+ await register(client, identity);
233
+ return client;
234
+ }
235
+ catch {
236
+ client?.close();
237
+ }
238
+ }
239
+ return null;
240
+ }
193
241
  export async function runMcpServer(stdin = process.stdin) {
194
242
  const paths = getPaths();
195
243
  const identity = identityFor(currentHost(undefined, false), process.env, process.cwd());
196
244
  let client;
197
245
  try {
198
- const token = readToken(paths);
199
- client = await connectBroker({ socketPath: paths.socketPath, token });
246
+ client = await connect(paths);
200
247
  }
201
248
  catch (err) {
202
249
  const code = err instanceof MurmurError ? err.code : 'internal';
203
250
  process.stderr.write('murmur mcp: cannot connect to broker at ' + paths.socketPath + ' (' + code + '): ' + err.message + '\n');
204
251
  process.exit(1);
205
252
  }
206
- // MURMUR_HANDLE is an optional per-process override; anything invalid
207
- // (like an old CHANGE-ME placeholder) or already taken is ignored so the
208
- // server still starts under its session's own handle.
209
- const explicit = process.env.MURMUR_HANDLE;
210
- const wanted = explicit !== undefined && HANDLE_RE.test(explicit) ? explicit : undefined;
211
- const base = identity.host === undefined
212
- ? { type: 'register', handle: wanted ?? 'anon-' + String(process.pid), clientKind: 'mcp' }
213
- : { ...identity, type: 'register', clientKind: 'mcp' };
214
253
  try {
215
- try {
216
- await client.request(wanted !== undefined && identity.host !== undefined ? { ...base, handle: wanted } : base);
217
- }
218
- catch (err) {
219
- if (wanted === undefined || identity.host === undefined) {
220
- throw err;
221
- }
222
- await client.request(base);
223
- }
254
+ await register(client, identity);
224
255
  }
225
256
  catch (err) {
226
257
  const code = err instanceof MurmurError ? err.code : 'internal';
227
258
  process.stderr.write('murmur mcp: broker rejected registration (' + code + '): ' + err.message + '\n');
228
259
  process.exit(1);
229
260
  }
261
+ // Set when the server is going away on purpose: no reconnect then.
262
+ let stopping = false;
230
263
  // Tear the broker connection down when the process exits so the broker
231
264
  // marks this session offline promptly.
232
265
  process.on('exit', () => {
266
+ stopping = true;
233
267
  client.close();
234
268
  });
235
- const server = buildMcpServer(client, identity);
269
+ // The tools go through whichever connection is current, so a reconnect
270
+ // keeps them working without the CLI restarting this server.
271
+ const server = buildMcpServer({ request: (msg) => client.request(msg) }, identity);
236
272
  await server.connect(new StdioServerTransport(stdin));
237
- // This long-lived broker connection is the session's presence, so the
238
- // server lives exactly as long as its client: it ends when stdin closes
239
- // (the CLI exited or was killed; the SDK transport does not watch for
240
- // that) or when the broker connection drops, instead of lingering with a
241
- // dead session.
242
- await new Promise((resolve) => {
243
- client.onClosed = resolve;
273
+ // This long-lived broker connection is the session's presence. The server
274
+ // ends when stdin closes (the CLI exited or was killed; the SDK transport
275
+ // does not watch for that). When the broker connection drops it connects
276
+ // and registers again, and ends only if no broker answers.
277
+ const ended = new Promise((resolve) => {
244
278
  stdin.once('end', resolve);
245
279
  stdin.once('close', resolve);
280
+ }).then(() => {
281
+ stopping = true;
246
282
  });
283
+ let next = client;
284
+ while (next !== null) {
285
+ client = next;
286
+ await Promise.race([
287
+ ended,
288
+ new Promise((resolve) => {
289
+ client.onClosed = resolve;
290
+ }),
291
+ ]);
292
+ next = stopping ? null : await reconnect(paths, identity, () => stopping);
293
+ }
247
294
  client.close();
248
295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "murmur-it",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Local, client-agnostic message bus for AI CLI sessions with group threads",
5
5
  "license": "MIT",
6
6
  "author": "Renn F",