@murmurv2/cli 2.11.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 (69) hide show
  1. package/README.md +85 -19
  2. package/package.json +8 -6
  3. package/runtime/bin/murmur-svc.exe +0 -0
  4. package/runtime/npm-runtime-manifest.json +193 -81
  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 +6 -3
  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.d.ts +1 -1
  17. package/runtime/packages/setup/dist/src/cli.js +111 -14
  18. package/runtime/packages/setup/dist/src/clients.d.ts +28 -76
  19. package/runtime/packages/setup/dist/src/clients.js +166 -26
  20. package/runtime/packages/setup/dist/src/commands.d.ts +3 -1
  21. package/runtime/packages/setup/dist/src/commands.js +18 -7
  22. package/runtime/packages/setup/dist/src/config.d.ts +10 -0
  23. package/runtime/packages/setup/dist/src/config.js +119 -10
  24. package/runtime/packages/setup/dist/src/connect.d.ts +143 -0
  25. package/runtime/packages/setup/dist/src/connect.js +126 -0
  26. package/runtime/packages/setup/dist/src/doctor.d.ts +42 -0
  27. package/runtime/packages/setup/dist/src/doctor.js +89 -10
  28. package/runtime/packages/setup/dist/src/installation.d.ts +25 -0
  29. package/runtime/packages/setup/dist/src/installation.js +89 -0
  30. package/runtime/packages/setup/dist/src/invitation-server.d.ts +2 -0
  31. package/runtime/packages/setup/dist/src/invitation-server.js +45 -0
  32. package/runtime/packages/setup/dist/src/message-status.d.ts +5 -0
  33. package/runtime/packages/setup/dist/src/message-status.js +13 -0
  34. package/runtime/packages/setup/dist/src/onboarding.d.ts +28 -10
  35. package/runtime/packages/setup/dist/src/onboarding.js +129 -34
  36. package/runtime/packages/setup/dist/src/outbox-attention.js +3 -21
  37. package/runtime/packages/setup/dist/src/paths.d.ts +7 -0
  38. package/runtime/packages/setup/dist/src/paths.js +39 -24
  39. package/runtime/packages/setup/dist/src/platform/darwin.d.ts +3 -0
  40. package/runtime/packages/setup/dist/src/platform/darwin.js +241 -9
  41. package/runtime/packages/setup/dist/src/platform/linux.js +152 -17
  42. package/runtime/packages/setup/dist/src/platform/profile-usage.d.ts +20 -0
  43. package/runtime/packages/setup/dist/src/platform/profile-usage.js +89 -0
  44. package/runtime/packages/setup/dist/src/platform/windows.js +89 -4
  45. package/runtime/packages/setup/dist/src/private-file.d.ts +4 -1
  46. package/runtime/packages/setup/dist/src/private-file.js +39 -3
  47. package/runtime/packages/setup/dist/src/state.d.ts +4 -0
  48. package/runtime/packages/setup/dist/src/state.js +65 -1
  49. package/runtime/packages/setup/dist/src/status.d.ts +26 -2
  50. package/runtime/packages/setup/dist/src/status.js +84 -20
  51. package/runtime/packages/setup/dist/src/types.d.ts +21 -1
  52. package/runtime/packages/setup/dist/src/verdict.js +4 -2
  53. package/runtime/packages/setup/dist/src/wake-attention.d.ts +11 -0
  54. package/runtime/packages/setup/dist/src/wake-attention.js +44 -0
  55. package/runtime/packages/setup/dist/src/wake-readers.d.ts +12 -0
  56. package/runtime/packages/setup/dist/src/wake-readers.js +65 -0
  57. package/runtime/packages/setup/package.json +1 -1
  58. package/runtime/scripts/auth-security.mjs +93 -0
  59. package/runtime/scripts/codex-app-server-wake.mjs +182 -32
  60. package/runtime/scripts/daemon-contacts.mjs +56 -0
  61. package/runtime/scripts/daemon-flush-tick.mjs +25 -0
  62. package/runtime/scripts/daemon-link-watch.mjs +60 -0
  63. package/runtime/scripts/daemon-observation.mjs +74 -18
  64. package/runtime/scripts/murmur-auth-token.mjs +140 -0
  65. package/runtime/scripts/murmur-daemon.mjs +66 -36
  66. package/runtime/scripts/murmur-jetstream-advisory.mjs +27 -0
  67. package/runtime/scripts/murmur-shell-send.mjs +3 -3
  68. package/runtime/scripts/wake-drain-claude.mjs +193 -39
  69. package/runtime/scripts/wake-monitor.mjs +46 -18
@@ -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];
@@ -88,6 +120,8 @@ export async function probeRoundtrip(c, config, peerId, connection, timeoutMs) {
88
120
  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)`,
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.',
91
125
  });
92
126
  export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
93
127
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 60000)
@@ -95,6 +129,8 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
95
129
  const generatedAt = new Date().toISOString(), stages = [];
96
130
  let config = null, connection;
97
131
  let snapshot;
132
+ let peerCheck = peer
133
+ ? { peerId: peer, state: 'not-checked', lastExchangeAt: null, requestMsgId: null, replyMsgId: null, reason: null } : null;
98
134
  let failedStage = null, worst = 'ok';
99
135
  const stage = async (id, title, fn) => {
100
136
  const start = Date.now();
@@ -117,10 +153,14 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
117
153
  }
118
154
  };
119
155
  try {
120
- 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
+ });
121
161
  await stage('daemon', 'Daemon and store', async () => {
122
162
  snapshot = await readStatus({ context, adapter });
123
- if (snapshot.service.state !== 'running')
163
+ if (!['running', 'running-unmanaged'].includes(snapshot.service.state))
124
164
  throw new Error('daemon.not-running');
125
165
  if (!snapshot.service.observedStorePath || await realpath(snapshot.service.observedStorePath) !== await realpath(context.storePath))
126
166
  throw new Error('daemon.store-unverified');
@@ -128,7 +168,8 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
128
168
  });
129
169
  await stage('broker', 'Broker authentication and RTT', async () => {
130
170
  try {
131
- 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 });
132
173
  await connection.rtt();
133
174
  }
134
175
  catch (e) {
@@ -141,26 +182,51 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
141
182
  throw new Error('peers.unknown');
142
183
  if (!Object.keys(config.peers).length)
143
184
  throw new Error('peers.none');
144
- const list = snapshot.peers.list ?? [];
145
- return list.every(p => p.paired === true) ? { detail: 'Fresh two-way proofs exist for configured peers' }
146
- : { 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);
147
186
  });
148
187
  await stage('roundtrip', 'Encrypted signed roundtrip', async () => {
149
188
  if (!peer)
150
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' };
151
- 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
+ }
202
+ peerCheck = { peerId: peer, state: 'connected', lastExchangeAt: proof.verifiedAt,
203
+ requestMsgId: proof.msgId, replyMsgId: proof.replyMsgId, reason: null };
152
204
  return { detail: `Authenticated reply persisted from ${proof.peerId}` };
153
205
  });
154
206
  await stage('wake', 'Wake mode and responder', async () => {
155
207
  const s = await readStatus({ context, adapter });
208
+ if (s.wake.faults.lastFault === 'accepted-turn-unobservable')
209
+ throw new Error('accepted-turn-unobservable');
156
210
  if (s.wake.effective.enabled === null)
157
211
  return { state: 'warn', reason: 'wake.unmeasured', detail: 'No fresh runtime evidence' };
158
212
  if (s.wake.effective.needsRestart)
159
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' };
160
214
  if (!s.wake.effective.enabled)
161
215
  return { state: 'warn', reason: 'wake.paused', detail: 'Wake is paused; pending messages remain queued' };
162
- if (s.wake.config.mode === 'none' || s.wake.config.responder === 'none')
163
- 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
+ }
164
230
  if (s.wake.faults.lastFault)
165
231
  throw new Error(s.wake.faults.lastFault);
166
232
  // A reply is not evidence that a particular UI/session was awakened.
@@ -170,5 +236,18 @@ export async function runDoctor({ context, adapter, peer, timeoutMs = 10000 }) {
170
236
  finally {
171
237
  await connection?.close();
172
238
  }
173
- return { schema: 'murmur.doctor/1', generatedAt, agentId: config?.agentId ?? null, stages, summary: { worst, failedStage } };
239
+ if (peerCheck && peerCheck.state !== 'connected') {
240
+ peerCheck.state = 'failed';
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');
245
+ }
246
+ // A local accepted-outcome fault is useful even when an earlier network stage
247
+ // blocked the wake probe. This read sends no message and changes no state.
248
+ const local = await readStatus({ context, adapter });
249
+ const wakeFault = local.wake.faults.lastFault === 'accepted-turn-unobservable'
250
+ ? { reason: 'accepted-turn-unobservable', fixHint: failureHints(context.serviceName)['accepted-turn-unobservable'] } : null;
251
+ return { schema: 'murmur.doctor/1', generatedAt, agentId: config?.agentId ?? null,
252
+ peerCheck, wakeFault, wakeReaders: local.wake.readers, stages, summary: { worst, failedStage } };
174
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
+ }
@@ -0,0 +1,2 @@
1
+ /** Address policy only: Invitation creation never connects or claims reachability. */
2
+ export declare function invitationServerAddress(value: string): string;
@@ -0,0 +1,45 @@
1
+ import { BlockList, isIP } from 'node:net';
2
+ const nonPublic = new BlockList();
3
+ for (const [network, prefix] of [
4
+ ['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
5
+ ['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24],
6
+ ['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24],
7
+ ['224.0.0.0', 4], ['240.0.0.0', 4],
8
+ ])
9
+ nonPublic.addSubnet(network, prefix, 'ipv4');
10
+ for (const [network, prefix] of [
11
+ ['::', 96], ['64:ff9b::', 96], ['2001:db8::', 32], ['fc00::', 7], ['fe80::', 10], ['ff00::', 8],
12
+ ])
13
+ nonPublic.addSubnet(network, prefix, 'ipv6');
14
+ const privateSuffixes = ['local', 'localhost', 'localdomain', 'ts.net', 'internal', 'home.arpa', 'lan'];
15
+ /** Address policy only: Invitation creation never connects or claims reachability. */
16
+ export function invitationServerAddress(value) {
17
+ let host;
18
+ try {
19
+ // URL parsing otherwise silently removes whitespace and controls. Never let the
20
+ // checked address and the value carried in the Invitation disagree that way.
21
+ if (/[\s\x00-\x1f\x7f\\]/u.test(value))
22
+ throw new Error();
23
+ const url = new URL(value);
24
+ if (!['nats:', 'tls:'].includes(url.protocol) || !url.host || url.username || url.password
25
+ || url.search || url.hash || !['', '/'].includes(url.pathname) || url.port === '0')
26
+ throw new Error();
27
+ // nats/tls are opaque-host URL schemes. The standard HTTP host parser also
28
+ // recognizes numeric, short, hex and octal IPv4 spellings (127.1, 0x7f000001),
29
+ // percent-encoded hostnames, case and IPv4-mapped IPv6, without a DNS lookup.
30
+ host = new URL(`http://${url.host}`).hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '').toLowerCase();
31
+ if (!isIP(host) && (host.length > 253 || !host.split('.').every(label => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label))))
32
+ throw new Error();
33
+ }
34
+ catch {
35
+ throw new Error('onboarding.invite-server-address-invalid');
36
+ }
37
+ const family = isIP(host);
38
+ // BlockList checks IPv4 rules for mapped IPv6 too; ::ffff:192.168.1.1 cannot
39
+ // turn a private IPv4 destination into a public Invitation address.
40
+ const privateAddress = family ? nonPublic.check(host, family === 4 ? 'ipv4' : 'ipv6')
41
+ : !host.includes('.') || privateSuffixes.some(suffix => host === suffix || host.endsWith(`.${suffix}`));
42
+ if (privateAddress)
43
+ throw new Error('onboarding.invite-public-server-required');
44
+ return value;
45
+ }
@@ -0,0 +1,5 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ export declare const personalInboxSql = "COALESCE(conversation_id, '') NOT LIKE 'murmur:doctor:%'";
3
+ /** Older stores remain readable without a migration or an invented wake result. */
4
+ export declare function wakeColumns(db: DatabaseSync): string;
5
+ export declare function assistantRead(wakeStatus: unknown): boolean | null;
@@ -0,0 +1,13 @@
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:%'";
4
+ /** Older stores remain readable without a migration or an invented wake result. */
5
+ export function wakeColumns(db) {
6
+ const columns = new Set(db.prepare('PRAGMA table_info(local_messages)').all().map(row => row.name));
7
+ return ['wake_status', 'wake_updated_at', 'wake_error'].map(name => columns.has(name) ? name : `NULL AS ${name}`).join(',');
8
+ }
9
+ export function assistantRead(wakeStatus) {
10
+ if (wakeStatus === 'handled')
11
+ return true;
12
+ return ['pending', 'inflight', 'failed', 'dlq', 'stored-only', 'muted'].includes(String(wakeStatus)) ? false : null;
13
+ }
@@ -1,36 +1,50 @@
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;
10
10
  serviceName: string;
11
11
  existing: boolean;
12
12
  }>;
13
- export declare function invite(c: ServiceContext, outFile: string): Promise<{
14
- schema: string;
15
- file: string;
13
+ export declare function invite(c: ServiceContext, outFile?: string, options?: {
14
+ brokerUrl?: string;
15
+ printSecret?: boolean;
16
+ }): Promise<{
16
17
  containsBrokerCredential: boolean;
17
18
  instruction: string;
19
+ invitation?: string | undefined;
20
+ outFile?: string | undefined;
21
+ secretRedacted?: boolean | undefined;
22
+ schema: string;
23
+ file: string | null;
18
24
  }>;
19
25
  export declare function join(c: ServiceContext, options: {
20
26
  agentId: string;
21
- inviteFile: string;
22
- replyOut: string;
23
- }): Promise<{
27
+ inviteFile?: string;
28
+ invitation?: string;
29
+ inviteArgument?: string;
30
+ replyOut?: string;
31
+ connect?: boolean;
32
+ } & BrokerInputFiles): Promise<{
24
33
  schema: string;
25
34
  agentId: string;
26
35
  peerId: any;
27
36
  paired: null;
28
- replyFile: string;
37
+ replyFile: string | null;
38
+ reply: string;
29
39
  backup: null;
30
40
  restartRequired: boolean;
41
+ contactsReload: {
42
+ mechanism: string;
43
+ state: string;
44
+ };
31
45
  serviceName: string;
32
46
  }>;
33
- export declare function importPeer(c: ServiceContext, replyFile: string): Promise<{
47
+ export declare function importPeer(c: ServiceContext, replyFile?: string, reply?: string): Promise<{
34
48
  schema: string;
35
49
  peerId: any;
36
50
  paired: null;
@@ -43,4 +57,8 @@ export declare function importPeer(c: ServiceContext, replyFile: string): Promis
43
57
  reason: string;
44
58
  };
45
59
  restartRequired: boolean;
60
+ contactsReload: {
61
+ mechanism: string;
62
+ state: string;
63
+ };
46
64
  }>;