@murmurv2/cli 2.12.0 → 2.13.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.
Files changed (57) hide show
  1. package/README.md +65 -24
  2. package/package.json +7 -6
  3. package/runtime/bin/murmur-svc.exe +0 -0
  4. package/runtime/npm-runtime-manifest.json +151 -75
  5. package/runtime/package.json +1 -1
  6. package/runtime/packages/mcp-server/dist/src/agent-config.js +1 -0
  7. package/runtime/packages/setup/bin/murmur.mjs +3 -2
  8. package/runtime/packages/setup/dist/src/backups.d.ts +36 -0
  9. package/runtime/packages/setup/dist/src/backups.js +128 -0
  10. package/runtime/packages/setup/dist/src/broker-input.d.ts +24 -0
  11. package/runtime/packages/setup/dist/src/broker-input.js +98 -0
  12. package/runtime/packages/setup/dist/src/broker-migration.d.ts +35 -0
  13. package/runtime/packages/setup/dist/src/broker-migration.js +138 -0
  14. package/runtime/packages/setup/dist/src/cli-error.d.ts +2 -0
  15. package/runtime/packages/setup/dist/src/cli-error.js +30 -0
  16. package/runtime/packages/setup/dist/src/cli.js +67 -10
  17. package/runtime/packages/setup/dist/src/clients.d.ts +28 -76
  18. package/runtime/packages/setup/dist/src/clients.js +159 -25
  19. package/runtime/packages/setup/dist/src/commands.js +3 -3
  20. package/runtime/packages/setup/dist/src/config.d.ts +8 -0
  21. package/runtime/packages/setup/dist/src/config.js +58 -10
  22. package/runtime/packages/setup/dist/src/connect.d.ts +143 -0
  23. package/runtime/packages/setup/dist/src/connect.js +126 -0
  24. package/runtime/packages/setup/dist/src/doctor.d.ts +30 -0
  25. package/runtime/packages/setup/dist/src/doctor.js +72 -10
  26. package/runtime/packages/setup/dist/src/installation.d.ts +25 -0
  27. package/runtime/packages/setup/dist/src/installation.js +89 -0
  28. package/runtime/packages/setup/dist/src/message-status.d.ts +1 -0
  29. package/runtime/packages/setup/dist/src/message-status.js +3 -0
  30. package/runtime/packages/setup/dist/src/onboarding.d.ts +11 -6
  31. package/runtime/packages/setup/dist/src/onboarding.js +92 -21
  32. package/runtime/packages/setup/dist/src/paths.d.ts +7 -0
  33. package/runtime/packages/setup/dist/src/paths.js +39 -24
  34. package/runtime/packages/setup/dist/src/platform/darwin.d.ts +3 -0
  35. package/runtime/packages/setup/dist/src/platform/darwin.js +235 -9
  36. package/runtime/packages/setup/dist/src/platform/linux.js +132 -2
  37. package/runtime/packages/setup/dist/src/platform/profile-usage.d.ts +20 -0
  38. package/runtime/packages/setup/dist/src/platform/profile-usage.js +89 -0
  39. package/runtime/packages/setup/dist/src/platform/windows.js +22 -1
  40. package/runtime/packages/setup/dist/src/private-file.d.ts +4 -1
  41. package/runtime/packages/setup/dist/src/private-file.js +39 -3
  42. package/runtime/packages/setup/dist/src/state.d.ts +4 -0
  43. package/runtime/packages/setup/dist/src/state.js +65 -1
  44. package/runtime/packages/setup/dist/src/status.d.ts +9 -0
  45. package/runtime/packages/setup/dist/src/status.js +7 -3
  46. package/runtime/packages/setup/dist/src/types.d.ts +10 -0
  47. package/runtime/packages/setup/dist/src/wake-readers.d.ts +12 -0
  48. package/runtime/packages/setup/dist/src/wake-readers.js +65 -0
  49. package/runtime/packages/setup/package.json +1 -1
  50. package/runtime/scripts/auth-security.mjs +93 -0
  51. package/runtime/scripts/codex-app-server-wake.mjs +13 -0
  52. package/runtime/scripts/daemon-contacts.mjs +1 -1
  53. package/runtime/scripts/murmur-auth-token.mjs +140 -0
  54. package/runtime/scripts/murmur-daemon.mjs +22 -6
  55. package/runtime/scripts/murmur-jetstream-advisory.mjs +27 -0
  56. package/runtime/scripts/murmur-shell-send.mjs +3 -3
  57. package/runtime/scripts/wake-drain-claude.mjs +124 -7
@@ -0,0 +1,143 @@
1
+ import type { PlatformAdapter } from './types.js';
2
+ export declare function connect(adapter: PlatformAdapter, options: {
3
+ agentId?: string;
4
+ dataDir?: string;
5
+ inviteFile?: string;
6
+ invitation?: string;
7
+ inviteArgument?: string;
8
+ replyOut?: string;
9
+ client?: string;
10
+ noService?: boolean;
11
+ copyReply?: boolean;
12
+ }): Promise<{
13
+ schema: string;
14
+ dataDir: string;
15
+ service: {
16
+ ok: null;
17
+ state: string;
18
+ error: null;
19
+ hint: null;
20
+ } | {
21
+ ok: boolean;
22
+ state: "running";
23
+ error: null;
24
+ hint: null;
25
+ } | {
26
+ ok: boolean;
27
+ state: "running" | "running-unmanaged" | "stopped" | "failed" | "unknown";
28
+ error: string;
29
+ hint: string;
30
+ };
31
+ clients: {
32
+ state: string;
33
+ results: never[];
34
+ hint: string;
35
+ } | {
36
+ state: string;
37
+ results: ({
38
+ state: string;
39
+ error: null;
40
+ hint: null;
41
+ serverName: string;
42
+ planId?: string | undefined;
43
+ agentId?: string | undefined;
44
+ dataDir?: string | undefined;
45
+ schema: string;
46
+ client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
47
+ configPath: string;
48
+ changed: boolean;
49
+ backup: null;
50
+ restartRequired: boolean;
51
+ } | {
52
+ state: string;
53
+ error: null;
54
+ hint: null;
55
+ restartRequired: boolean;
56
+ instruction: string;
57
+ serverName: string;
58
+ planId?: string | undefined;
59
+ agentId?: string | undefined;
60
+ dataDir?: string | undefined;
61
+ schema: string;
62
+ client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
63
+ configPath: string;
64
+ changed: boolean;
65
+ backup: string | null;
66
+ } | {
67
+ state: string;
68
+ error: null;
69
+ hint: null;
70
+ changed: boolean;
71
+ wakeHook: {
72
+ settingsPath: string;
73
+ action: "unchanged";
74
+ changed: boolean;
75
+ backup: null;
76
+ repointed: string[];
77
+ } | {
78
+ settingsPath: string;
79
+ action: "replace" | "add";
80
+ changed: boolean;
81
+ backup: string | null;
82
+ repointed: string[];
83
+ };
84
+ serverName: string;
85
+ planId?: string | undefined;
86
+ agentId?: string | undefined;
87
+ dataDir?: string | undefined;
88
+ schema: string;
89
+ client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
90
+ configPath: string;
91
+ backup: null;
92
+ restartRequired: boolean;
93
+ } | {
94
+ state: string;
95
+ error: null;
96
+ hint: null;
97
+ changed: boolean;
98
+ wakeHook: {
99
+ settingsPath: string;
100
+ action: "unchanged";
101
+ changed: boolean;
102
+ backup: null;
103
+ repointed: string[];
104
+ } | {
105
+ settingsPath: string;
106
+ action: "replace" | "add";
107
+ changed: boolean;
108
+ backup: string | null;
109
+ repointed: string[];
110
+ };
111
+ restartRequired: boolean;
112
+ instruction: string;
113
+ serverName: string;
114
+ planId?: string | undefined;
115
+ agentId?: string | undefined;
116
+ dataDir?: string | undefined;
117
+ schema: string;
118
+ client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
119
+ configPath: string;
120
+ backup: string | null;
121
+ } | {
122
+ client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
123
+ state: string;
124
+ error: string;
125
+ hint: string;
126
+ })[];
127
+ hint: null;
128
+ };
129
+ copiedToClipboard: boolean;
130
+ agentId: string;
131
+ peerId: any;
132
+ paired: null;
133
+ replyFile: string | null;
134
+ reply: string;
135
+ backup: null;
136
+ restartRequired: boolean;
137
+ contactsReload: {
138
+ mechanism: string;
139
+ state: string;
140
+ };
141
+ serviceName: string;
142
+ }>;
143
+ export declare function renderConnect(result: Awaited<ReturnType<typeof connect>>): string;
@@ -0,0 +1,126 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { hostname, userInfo } from 'node:os';
3
+ import { configureClient } from './clients.js';
4
+ import { safeError, validAgentId } from './config.js';
5
+ import { join } from './onboarding.js';
6
+ import { defaultProfileDir, resolveContext } from './paths.js';
7
+ import { readStatus } from './status.js';
8
+ const automaticClients = new Set(['claude-code', 'codex-cli', 'codex-desktop']);
9
+ const clientIds = new Map([
10
+ ['claude-code', 'claude-code'], ['claude-desktop', 'claude-desktop'],
11
+ ['codex-cli', 'codex-cli'], ['codex', 'codex-desktop'],
12
+ ]);
13
+ function defaultAgentId() {
14
+ let username = '';
15
+ try {
16
+ username = userInfo().username;
17
+ }
18
+ catch { /* OS account lookup is optional. */ }
19
+ const slug = (value) => value.toLowerCase().replace(/[^a-z0-9]+/g, '-')
20
+ .replace(/^-+/, '').slice(0, 122).replace(/-+$/, '');
21
+ return 'agent-' + (slug(username) || slug(hostname()) || 'peer');
22
+ }
23
+ async function startService(context, adapter, skip) {
24
+ if (skip)
25
+ return { ok: null, state: 'skipped', error: null, hint: null };
26
+ const status = async () => (await readStatus({ context, adapter })).service.state;
27
+ let state = await status();
28
+ let phase = 'install';
29
+ try {
30
+ if (state === 'running-unmanaged')
31
+ throw new Error('service.running-unmanaged');
32
+ if (state !== 'running') {
33
+ await adapter.install(context);
34
+ phase = 'start';
35
+ await adapter.start(context);
36
+ state = await status();
37
+ if (state !== 'running') {
38
+ phase = 'verify';
39
+ throw new Error('service.running-unverified');
40
+ }
41
+ }
42
+ return { ok: true, state, error: null, hint: null };
43
+ }
44
+ catch (error) {
45
+ const hint = state === 'running-unmanaged'
46
+ ? 'This profile is already running outside the service manager. Stop that instance before installing a service.'
47
+ : phase === 'verify'
48
+ ? 'Run murmur doctor for this profile to check whether the service started.'
49
+ : `Run murmur service ${phase} --data-dir with the profile path shown above after checking your service manager.`
50
+ + (adapter.manager === 'windows-service' ? ' On Windows, run that service command as Administrator.' : '');
51
+ return { ok: false, state: await status(), error: safeError(error), hint };
52
+ }
53
+ }
54
+ async function wireClients(context, adapter, selection) {
55
+ if (selection === 'none')
56
+ return { state: 'skipped', results: [], hint: null };
57
+ let ids;
58
+ try {
59
+ ids = selection === 'auto'
60
+ ? [...new Set((await adapter.detectClients(context)).filter(row => row.installed && automaticClients.has(row.id)).map(row => row.id))]
61
+ : [clientIds.get(selection)];
62
+ }
63
+ catch {
64
+ return { state: 'failed', results: [], hint: 'Client detection failed. Run murmur clients detect for this profile to check again.' };
65
+ }
66
+ if (!ids.length)
67
+ return { state: 'not-detected', results: [], hint: 'No supported AI client was detected. Install one, then rerun connect or run murmur clients detect.' };
68
+ const results = [];
69
+ for (const client of ids) {
70
+ try {
71
+ const result = await configureClient(context, adapter, client);
72
+ results.push({ ...result, state: 'configured', error: null, hint: null });
73
+ }
74
+ catch (error) {
75
+ const code = safeError(error);
76
+ const hint = ['client.murmur-entry-conflict', 'client.wake-hook-conflict'].includes(code)
77
+ ? `Existing settings were kept. Review them, then use murmur clients configure --client ${client} --replace with this profile if you want to replace them.`
78
+ : 'Check whether the client is installed and its settings are accessible, then run murmur clients detect for this profile.';
79
+ results.push({ client, state: 'failed', error: code, hint });
80
+ }
81
+ }
82
+ return { state: results.every(row => row.state === 'configured') ? 'configured' : 'needs-attention', results, hint: null };
83
+ }
84
+ async function copyReply(reply) {
85
+ const tools = process.platform === 'darwin' ? [['/usr/bin/pbcopy', []]]
86
+ : process.platform === 'win32' ? [['clip.exe', []]]
87
+ : process.platform === 'linux' ? [['wl-copy', []], ['xclip', ['-selection', 'clipboard']]] : [];
88
+ for (const [command, args] of tools) {
89
+ const copied = await new Promise((resolve) => {
90
+ const child = execFile(command, args, { timeout: 3000, windowsHide: true }, error => resolve(!error));
91
+ child.stdin?.on('error', () => { });
92
+ child.stdin?.end(reply);
93
+ });
94
+ if (copied)
95
+ return true;
96
+ }
97
+ return false;
98
+ }
99
+ export async function connect(adapter, options) {
100
+ const selection = options.client ?? 'auto';
101
+ if (!['auto', 'none'].includes(selection) && !clientIds.has(selection))
102
+ throw new Error('connect.invalid-client');
103
+ const agentId = options.agentId ?? defaultAgentId();
104
+ if (!validAgentId(agentId))
105
+ throw new Error('config.identity-invalid');
106
+ const context = resolveContext({ dataDir: options.dataDir ?? defaultProfileDir(agentId) });
107
+ const joined = await join(context, { ...options, agentId, connect: true });
108
+ const service = await startService(context, adapter, !!options.noService);
109
+ const clients = await wireClients(context, adapter, selection);
110
+ const copiedToClipboard = !!options.copyReply && await copyReply(joined.reply);
111
+ return { ...joined, schema: 'murmur.connect/1', dataDir: context.dataDir, service, clients, copiedToClipboard };
112
+ }
113
+ export function renderConnect(result) {
114
+ return [
115
+ `Murmur identity: ${result.agentId} (${result.dataDir})`,
116
+ `Inviter: ${result.peerId} (connection not yet verified)`,
117
+ `Service: ${result.service.state}${result.service.error ? ` (${result.service.error})` : ''}`,
118
+ result.service.hint,
119
+ `AI clients: ${result.clients.state}`,
120
+ result.clients.hint,
121
+ ...result.clients.results.map(row => ` ${row.client}: ${row.state}${row.hint ? `. ${row.hint}` : ''}`),
122
+ `Reply saved to ${result.replyFile}${result.copiedToClipboard ? ' and copied to the clipboard' : ''}.`,
123
+ '', result.reply, '',
124
+ 'Send this MURMUR-REPLY line back to the person who invited you. Restart your AI client to see murmur tools.',
125
+ ].filter(line => line !== null).join('\n');
126
+ }
@@ -7,6 +7,27 @@ export interface DoctorOptions {
7
7
  peer?: string;
8
8
  timeoutMs?: number;
9
9
  }
10
+ export declare function evaluatePeers(list: Array<{
11
+ agentId: string;
12
+ paired: boolean | null;
13
+ }>, peer?: string): {
14
+ state?: string;
15
+ reason?: string;
16
+ detail: string;
17
+ fixHint?: string;
18
+ };
19
+ /**
20
+ * How a silent probe reads. A daemon older than 2.11.0 never answers one, so silence alone is
21
+ * not the same finding as an unreachable peer (#292). A signed message this store persisted
22
+ * from that peer recently proves the transport in one direction; without that evidence the
23
+ * timeout stays a failure, and null tells the caller to let it through as one.
24
+ */
25
+ export declare function evaluateSilentPeer(peer: string, lastInboundAt: string | null, now?: number): {
26
+ state: string;
27
+ reason: string;
28
+ detail: string;
29
+ fixHint: string;
30
+ } | null;
10
31
  export declare function probeRoundtrip(c: ServiceContext, config: AgentConfig, peerId: string, connection: NatsConnection, timeoutMs: number): Promise<{
11
32
  msgId: string;
12
33
  replyMsgId: string;
@@ -29,6 +50,15 @@ export declare function runDoctor({ context, adapter, peer, timeoutMs }: DoctorO
29
50
  reason: string;
30
51
  fixHint: string;
31
52
  } | null;
53
+ wakeReaders: {
54
+ active: number | null;
55
+ measuredAt: string;
56
+ unknownReason: string;
57
+ } | {
58
+ active: number;
59
+ measuredAt: string;
60
+ unknownReason: null;
61
+ };
32
62
  stages: Record<string, unknown>[];
33
63
  summary: {
34
64
  worst: string;
@@ -6,9 +6,41 @@ import { realpath } from 'node:fs/promises';
6
6
  import { buildNatsConnectionOptions } from '@murmurv2/broker-nats';
7
7
  import { channelSubjectRoutes, resolveMessageSubject, SQLiteDedupeOutboxStore, stableEnvelopePayload, isEnvelopeV1 } from '@murmurv2/core';
8
8
  import { encryptPayload, signEnvelope, verifyEnvelopeSignature, decryptPayload } from '@murmurv2/security';
9
+ import { claudeWakeHookState } from './clients.js';
9
10
  import { loadConfig, readJson, safeError } from './config.js';
11
+ import { validateConfiguredTlsFiles } from './broker-input.js';
10
12
  import { pairFingerprint, readStatus } from './status.js';
11
13
  import { writeState } from './state.js';
14
+ // With --peer the peers stage answers for that peer: a fresh two-way proof for it is the evidence, and
15
+ // unmeasured pairs of other contacts do not hide it (#282). Without --peer every contact has to be measured.
16
+ export function evaluatePeers(list, peer) {
17
+ const hint = 'Run murmur doctor --peer <configured-agent-id> --json';
18
+ if (peer) {
19
+ return list.find(p => p.agentId === peer)?.paired === true
20
+ ? { detail: `Fresh two-way proof exists for ${peer}` }
21
+ : { state: 'warn', reason: 'peers.unmeasured', detail: `No fresh two-way proof for ${peer} yet; a completed roundtrip in this run records one`, fixHint: `${hint} once more` };
22
+ }
23
+ const measured = list.filter(p => p.paired === true).length;
24
+ return measured === list.length ? { detail: 'Fresh two-way proofs exist for configured peers' }
25
+ : { state: 'warn', reason: 'peers.unmeasured', detail: `Fresh two-way proofs exist for ${measured} of ${list.length} configured peers; local keys alone do not prove mutual pairing`, fixHint: hint };
26
+ }
27
+ // How recent an ordinary signed message must be to say the transport was proven "now" rather
28
+ // than once. An hour outlives a restart or a short outage without excusing a dead channel.
29
+ const PEER_TRAFFIC_WINDOW_MS = 3600_000;
30
+ /**
31
+ * How a silent probe reads. A daemon older than 2.11.0 never answers one, so silence alone is
32
+ * not the same finding as an unreachable peer (#292). A signed message this store persisted
33
+ * from that peer recently proves the transport in one direction; without that evidence the
34
+ * timeout stays a failure, and null tells the caller to let it through as one.
35
+ */
36
+ export function evaluateSilentPeer(peer, lastInboundAt, now = Date.now()) {
37
+ const at = lastInboundAt === null ? NaN : Date.parse(lastInboundAt);
38
+ if (!Number.isFinite(at) || now - at >= PEER_TRAFFIC_WINDOW_MS || at > now)
39
+ return null;
40
+ return { state: 'warn', reason: 'roundtrip.peer-silent',
41
+ detail: `No probe reply from ${peer}; a signed message from it was persisted at ${lastInboundAt}`,
42
+ fixHint: `The channel may be fine: a daemon older than 2.11.0 does not answer probes. Ask ${peer} for murmur --version, and check an ordinary message both ways.` };
43
+ }
12
44
  const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
13
45
  export async function probeRoundtrip(c, config, peerId, connection, timeoutMs) {
14
46
  const peer = config.peers[peerId];
@@ -89,6 +121,7 @@ const failureHints = (serviceName) => ({
89
121
  'config.missing': 'No profile here yet: run murmur join --data-dir <this profile> --agent-id <your-agent-id> --invite-file <invite file> --reply-out <new reply file>',
90
122
  'daemon.not-running': `Install or start the service: murmur service install --data-dir <this profile> --service-name ${serviceName} (or service start with the same options if installed; on Windows from an administrator terminal)`,
91
123
  'accepted-turn-unobservable': 'Inspect the Assistant session. After reviewing the unknown outcome, use murmur wake dismiss --data-dir <this profile> --msg-id <message-id> --expected-agent <your-identity> to acknowledge it without running it again.',
124
+ 'roundtrip.timeout': 'The peer sent no probe reply. A daemon older than 2.11.0 never answers one, so the channel may still be fine: ask the peer for murmur --version, and check an ordinary message in both directions before treating this as a broken channel.',
92
125
  });
93
126
  export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
94
127
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 60000)
@@ -120,7 +153,11 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
120
153
  }
121
154
  };
122
155
  try {
123
- await stage('config', 'Configuration', async () => { config = await loadConfig(context); return { detail: 'Identity, keys and peer configuration validated' }; });
156
+ await stage('config', 'Configuration', async () => {
157
+ config = await loadConfig(context);
158
+ await validateConfiguredTlsFiles(config);
159
+ return { detail: 'Identity, keys, peer configuration, and referenced TLS files validated' };
160
+ });
124
161
  await stage('daemon', 'Daemon and store', async () => {
125
162
  snapshot = await readStatus({ context, adapter });
126
163
  if (!['running', 'running-unmanaged'].includes(snapshot.service.state))
@@ -131,7 +168,8 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
131
168
  });
132
169
  await stage('broker', 'Broker authentication and RTT', async () => {
133
170
  try {
134
- connection = await connect({ ...buildNatsConnectionOptions({ url: config.natsUrl, token: config.natsToken }), reconnect: false, waitOnFirstConnect: false, timeout: timeoutMs });
171
+ connection = await connect({ ...buildNatsConnectionOptions({ url: config.natsUrl, token: config.natsToken,
172
+ user: config.natsUser, password: config.natsPassword, tls: config.natsTls }), reconnect: false, waitOnFirstConnect: false, timeout: timeoutMs });
135
173
  await connection.rtt();
136
174
  }
137
175
  catch (e) {
@@ -144,14 +182,23 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
144
182
  throw new Error('peers.unknown');
145
183
  if (!Object.keys(config.peers).length)
146
184
  throw new Error('peers.none');
147
- const list = snapshot.peers.list ?? [];
148
- return list.every(p => p.paired === true) ? { detail: 'Fresh two-way proofs exist for configured peers' }
149
- : { state: 'warn', reason: 'peers.unmeasured', detail: 'Local keys alone do not prove mutual pairing', fixHint: 'Run murmur doctor --peer <configured-agent-id> --json' };
185
+ return evaluatePeers(snapshot.peers.list ?? [], peer);
150
186
  });
151
187
  await stage('roundtrip', 'Encrypted signed roundtrip', async () => {
152
188
  if (!peer)
153
189
  return { state: 'warn', reason: 'roundtrip.peer-required', detail: 'No diagnostic peer selected; no message sent', fixHint: 'Run murmur doctor --peer <configured-agent-id> --json' };
154
- const proof = await probeRoundtrip(context, config, peer, connection, timeoutMs);
190
+ let proof;
191
+ try {
192
+ proof = await probeRoundtrip(context, config, peer, connection, timeoutMs);
193
+ }
194
+ catch (e) {
195
+ if (safeError(e) !== 'roundtrip.timeout')
196
+ throw e;
197
+ const silent = evaluateSilentPeer(peer, snapshot?.peers.list?.find(row => row.agentId === peer)?.lastInboundAt ?? null);
198
+ if (!silent)
199
+ throw e;
200
+ return silent;
201
+ }
155
202
  peerCheck = { peerId: peer, state: 'connected', lastExchangeAt: proof.verifiedAt,
156
203
  requestMsgId: proof.msgId, replyMsgId: proof.replyMsgId, reason: null };
157
204
  return { detail: `Authenticated reply persisted from ${proof.peerId}` };
@@ -166,8 +213,20 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
166
213
  return { state: 'warn', reason: 'wake.mode-mismatch', detail: 'Configured and effective wake differ', fixHint: 'Run murmur wake pause --apply or murmur wake resume --apply for the intended mode' };
167
214
  if (!s.wake.effective.enabled)
168
215
  return { state: 'warn', reason: 'wake.paused', detail: 'Wake is paused; pending messages remain queued' };
169
- if (s.wake.config.mode === 'none' || s.wake.config.responder === 'none')
170
- return { state: 'warn', reason: 'wake.no-responder', detail: 'No wake responder configured' };
216
+ if (s.wake.config.mode === 'none' || s.wake.config.responder === 'none') {
217
+ // Claude Code is woken by the Stop hook clients configure writes, not by a responder in
218
+ // the daemon. Reporting no-responder there told a working setup it was misconfigured (#293).
219
+ const hook = await claudeWakeHookState(context, adapter);
220
+ if (hook === 'outdated')
221
+ return { state: 'warn', reason: 'wake.hook-outdated',
222
+ detail: 'Claude Code Stop hook differs from the one this version installs',
223
+ fixHint: 'Run murmur clients configure --client claude-code --replace' };
224
+ if (hook === 'absent')
225
+ return { state: 'warn', reason: 'wake.no-responder', detail: 'No wake responder configured' };
226
+ // This stage reads configuration: the hook is installed and current. Whether a live
227
+ // session was woken is the separate proof the responder branch below also withholds.
228
+ return { detail: 'Claude Code Stop hook installed for this profile; a live session receipt is separate proof' };
229
+ }
171
230
  if (s.wake.faults.lastFault)
172
231
  throw new Error(s.wake.faults.lastFault);
173
232
  // A reply is not evidence that a particular UI/session was awakened.
@@ -179,7 +238,10 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
179
238
  }
180
239
  if (peerCheck && peerCheck.state !== 'connected') {
181
240
  peerCheck.state = 'failed';
182
- peerCheck.reason = String(stages.find(s => s.state === 'fail')?.reason ?? 'roundtrip.not-checked');
241
+ // A silent peer with recent verified traffic leaves no failed stage, so carry that stage's
242
+ // own reason rather than saying the check never ran (#292).
243
+ const silent = stages.find(s => s.id === 'roundtrip' && s.state === 'warn')?.reason;
244
+ peerCheck.reason = String(stages.find(s => s.state === 'fail')?.reason ?? silent ?? 'roundtrip.not-checked');
183
245
  }
184
246
  // A local accepted-outcome fault is useful even when an earlier network stage
185
247
  // blocked the wake probe. This read sends no message and changes no state.
@@ -187,5 +249,5 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
187
249
  const wakeFault = local.wake.faults.lastFault === 'accepted-turn-unobservable'
188
250
  ? { reason: 'accepted-turn-unobservable', fixHint: failureHints(context.serviceName)['accepted-turn-unobservable'] } : null;
189
251
  return { schema: 'murmur.doctor/1', generatedAt, agentId: config?.agentId ?? null,
190
- peerCheck, wakeFault, stages, summary: { worst, failedStage } };
252
+ peerCheck, wakeFault, wakeReaders: local.wake.readers, stages, summary: { worst, failedStage } };
191
253
  }
@@ -0,0 +1,25 @@
1
+ import type { ServiceContext } from './types.js';
2
+ export declare function showInstallation(file?: string): {
3
+ descriptorFile: string;
4
+ schema?: "murmur.installation/1" | undefined;
5
+ dataDir?: string | undefined;
6
+ agentId?: string | undefined;
7
+ identityFingerprint?: string | undefined;
8
+ };
9
+ export declare function checkInstallationSelection(c: ServiceContext, options?: {
10
+ file?: string;
11
+ replace?: boolean;
12
+ }): void;
13
+ /** Explicitly register an existing profile; never relocate it, rotate keys or rewrite client/service settings. */
14
+ export declare function selectInstallation(c: ServiceContext, options?: {
15
+ file?: string;
16
+ replace?: boolean;
17
+ }): Promise<{
18
+ descriptorFile: string;
19
+ changed: boolean;
20
+ existingConsumersChanged: boolean;
21
+ schema: "murmur.installation/1";
22
+ dataDir: string;
23
+ agentId: string;
24
+ identityFingerprint: string;
25
+ }>;
@@ -0,0 +1,89 @@
1
+ import { constants } from 'node:fs';
2
+ import { lstat, mkdir, open, rename, rmdir, unlink } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { isDeepStrictEqual } from 'node:util';
6
+ import { installationFile, installationIdentity, readInstallationDescriptor, resolveInstallation } from '@murmurv2/core';
7
+ import { protectPrivateFile } from './private-file.js';
8
+ import { loadConfig } from './config.js';
9
+ export function showInstallation(file) {
10
+ const descriptorFile = installationFile({ installationFile: file });
11
+ // Show the registered choice, not an ambient DATA_DIR override.
12
+ const selected = resolveInstallation({ installationFile: descriptorFile, env: {} });
13
+ return { ...selected.descriptor, descriptorFile };
14
+ }
15
+ export function checkInstallationSelection(c, options = {}) {
16
+ const file = installationFile({ installationFile: options.file });
17
+ const relative = path.relative(c.dataDir, file);
18
+ if ((!relative.startsWith('..' + path.sep) && relative !== '..' && !path.isAbsolute(relative))
19
+ && relative !== 'installation.json')
20
+ throw new Error('installation.file-conflict');
21
+ try {
22
+ const previous = readInstallationDescriptor(file);
23
+ if (!options.replace && (previous.dataDir !== c.dataDir || !isDeepStrictEqual({ agentId: previous.agentId, identityFingerprint: previous.identityFingerprint }, installationIdentity(c.dataDir)))) {
24
+ throw new Error('installation.selection-conflict');
25
+ }
26
+ }
27
+ catch (error) {
28
+ if (!(error instanceof Error && error.message === 'installation.descriptor-missing'))
29
+ throw error;
30
+ }
31
+ }
32
+ /** Explicitly register an existing profile; never relocate it, rotate keys or rewrite client/service settings. */
33
+ export async function selectInstallation(c, options = {}) {
34
+ checkInstallationSelection(c, options);
35
+ await loadConfig(c);
36
+ const identity = installationIdentity(c.dataDir), file = installationFile({ installationFile: options.file });
37
+ if (file === c.configPath || file === c.storePath)
38
+ throw new Error('installation.file-conflict');
39
+ const desired = { schema: 'murmur.installation/1', dataDir: c.dataDir, ...identity };
40
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
41
+ const lock = `${file}.murmur-lock`;
42
+ await mkdir(lock, { mode: 0o700 });
43
+ const read = () => {
44
+ try {
45
+ return readInstallationDescriptor(file);
46
+ }
47
+ catch (error) {
48
+ if (error instanceof Error && error.message === 'installation.descriptor-missing')
49
+ return null;
50
+ throw error;
51
+ }
52
+ };
53
+ const temporary = `${file}.${randomUUID()}.tmp`;
54
+ try {
55
+ const previous = read();
56
+ if (isDeepStrictEqual(previous, desired))
57
+ return { ...desired, descriptorFile: file, changed: false, existingConsumersChanged: false };
58
+ if (previous && !options.replace)
59
+ throw new Error('installation.selection-conflict');
60
+ const handle = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
61
+ try {
62
+ await protectPrivateFile(temporary, handle);
63
+ await handle.writeFile(JSON.stringify(desired, null, 2) + '\n');
64
+ await handle.sync();
65
+ }
66
+ finally {
67
+ await handle.close();
68
+ }
69
+ if (!isDeepStrictEqual(previous, read()) || !isDeepStrictEqual(identity, installationIdentity(c.dataDir)))
70
+ throw new Error('installation.selection-changed');
71
+ if (!previous) {
72
+ // A non-cooperating creator appearing while we prepared the descriptor must not be overwritten.
73
+ try {
74
+ await lstat(file);
75
+ throw new Error('installation.selection-changed');
76
+ }
77
+ catch (error) {
78
+ if (error.code !== 'ENOENT')
79
+ throw error;
80
+ }
81
+ }
82
+ await rename(temporary, file);
83
+ return { ...desired, descriptorFile: file, changed: true, existingConsumersChanged: false };
84
+ }
85
+ finally {
86
+ await unlink(temporary).catch(() => { });
87
+ await rmdir(lock);
88
+ }
89
+ }
@@ -1,4 +1,5 @@
1
1
  import type { DatabaseSync } from 'node:sqlite';
2
+ export declare const personalInboxSql = "COALESCE(conversation_id, '') NOT LIKE 'murmur:doctor:%'";
2
3
  /** Older stores remain readable without a migration or an invented wake result. */
3
4
  export declare function wakeColumns(db: DatabaseSync): string;
4
5
  export declare function assistantRead(wakeStatus: unknown): boolean | null;
@@ -1,3 +1,6 @@
1
+ // Reserved machine-only conversations remain in history for diagnosis, but do
2
+ // not fill a person's inbox or unread badge. Never infer this from message text.
3
+ export const personalInboxSql = "COALESCE(conversation_id, '') NOT LIKE 'murmur:doctor:%'";
1
4
  /** Older stores remain readable without a migration or an invented wake result. */
2
5
  export function wakeColumns(db) {
3
6
  const columns = new Set(db.prepare('PRAGMA table_info(local_messages)').all().map(row => row.name));
@@ -1,9 +1,9 @@
1
+ import { type BrokerInputFiles } from './broker-input.js';
1
2
  import type { ServiceContext } from './types.js';
2
3
  export declare function initialize(c: ServiceContext, options: {
3
4
  agentId: string;
4
5
  brokerUrl: string;
5
- tokenFile?: string;
6
- }): Promise<{
6
+ } & BrokerInputFiles): Promise<{
7
7
  schema: string;
8
8
  agentId: string;
9
9
  dataDir: string;
@@ -12,19 +12,24 @@ export declare function initialize(c: ServiceContext, options: {
12
12
  }>;
13
13
  export declare function invite(c: ServiceContext, outFile?: string, options?: {
14
14
  brokerUrl?: string;
15
+ printSecret?: boolean;
15
16
  }): Promise<{
16
- schema: string;
17
- file: string | null;
18
- invitation: string;
19
17
  containsBrokerCredential: boolean;
20
18
  instruction: string;
19
+ invitation?: string | undefined;
20
+ outFile?: string | undefined;
21
+ secretRedacted?: boolean | undefined;
22
+ schema: string;
23
+ file: string | null;
21
24
  }>;
22
25
  export declare function join(c: ServiceContext, options: {
23
26
  agentId: string;
24
27
  inviteFile?: string;
25
28
  invitation?: string;
29
+ inviteArgument?: string;
26
30
  replyOut?: string;
27
- }): Promise<{
31
+ connect?: boolean;
32
+ } & BrokerInputFiles): Promise<{
28
33
  schema: string;
29
34
  agentId: string;
30
35
  peerId: any;