@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.
- package/README.md +85 -19
- package/package.json +8 -6
- package/runtime/bin/murmur-svc.exe +0 -0
- package/runtime/npm-runtime-manifest.json +193 -81
- package/runtime/package.json +1 -1
- package/runtime/packages/mcp-server/dist/src/agent-config.js +1 -0
- package/runtime/packages/setup/bin/murmur.mjs +6 -3
- package/runtime/packages/setup/dist/src/backups.d.ts +36 -0
- package/runtime/packages/setup/dist/src/backups.js +128 -0
- package/runtime/packages/setup/dist/src/broker-input.d.ts +24 -0
- package/runtime/packages/setup/dist/src/broker-input.js +98 -0
- package/runtime/packages/setup/dist/src/broker-migration.d.ts +35 -0
- package/runtime/packages/setup/dist/src/broker-migration.js +138 -0
- package/runtime/packages/setup/dist/src/cli-error.d.ts +2 -0
- package/runtime/packages/setup/dist/src/cli-error.js +30 -0
- package/runtime/packages/setup/dist/src/cli.d.ts +1 -1
- package/runtime/packages/setup/dist/src/cli.js +111 -14
- package/runtime/packages/setup/dist/src/clients.d.ts +28 -76
- package/runtime/packages/setup/dist/src/clients.js +166 -26
- package/runtime/packages/setup/dist/src/commands.d.ts +3 -1
- package/runtime/packages/setup/dist/src/commands.js +18 -7
- package/runtime/packages/setup/dist/src/config.d.ts +10 -0
- package/runtime/packages/setup/dist/src/config.js +119 -10
- package/runtime/packages/setup/dist/src/connect.d.ts +143 -0
- package/runtime/packages/setup/dist/src/connect.js +126 -0
- package/runtime/packages/setup/dist/src/doctor.d.ts +42 -0
- package/runtime/packages/setup/dist/src/doctor.js +89 -10
- package/runtime/packages/setup/dist/src/installation.d.ts +25 -0
- package/runtime/packages/setup/dist/src/installation.js +89 -0
- package/runtime/packages/setup/dist/src/invitation-server.d.ts +2 -0
- package/runtime/packages/setup/dist/src/invitation-server.js +45 -0
- package/runtime/packages/setup/dist/src/message-status.d.ts +5 -0
- package/runtime/packages/setup/dist/src/message-status.js +13 -0
- package/runtime/packages/setup/dist/src/onboarding.d.ts +28 -10
- package/runtime/packages/setup/dist/src/onboarding.js +129 -34
- package/runtime/packages/setup/dist/src/outbox-attention.js +3 -21
- package/runtime/packages/setup/dist/src/paths.d.ts +7 -0
- package/runtime/packages/setup/dist/src/paths.js +39 -24
- package/runtime/packages/setup/dist/src/platform/darwin.d.ts +3 -0
- package/runtime/packages/setup/dist/src/platform/darwin.js +241 -9
- package/runtime/packages/setup/dist/src/platform/linux.js +152 -17
- package/runtime/packages/setup/dist/src/platform/profile-usage.d.ts +20 -0
- package/runtime/packages/setup/dist/src/platform/profile-usage.js +89 -0
- package/runtime/packages/setup/dist/src/platform/windows.js +89 -4
- package/runtime/packages/setup/dist/src/private-file.d.ts +4 -1
- package/runtime/packages/setup/dist/src/private-file.js +39 -3
- package/runtime/packages/setup/dist/src/state.d.ts +4 -0
- package/runtime/packages/setup/dist/src/state.js +65 -1
- package/runtime/packages/setup/dist/src/status.d.ts +26 -2
- package/runtime/packages/setup/dist/src/status.js +84 -20
- package/runtime/packages/setup/dist/src/types.d.ts +21 -1
- package/runtime/packages/setup/dist/src/verdict.js +4 -2
- package/runtime/packages/setup/dist/src/wake-attention.d.ts +11 -0
- package/runtime/packages/setup/dist/src/wake-attention.js +44 -0
- package/runtime/packages/setup/dist/src/wake-readers.d.ts +12 -0
- package/runtime/packages/setup/dist/src/wake-readers.js +65 -0
- package/runtime/packages/setup/package.json +1 -1
- package/runtime/scripts/auth-security.mjs +93 -0
- package/runtime/scripts/codex-app-server-wake.mjs +182 -32
- package/runtime/scripts/daemon-contacts.mjs +56 -0
- package/runtime/scripts/daemon-flush-tick.mjs +25 -0
- package/runtime/scripts/daemon-link-watch.mjs +60 -0
- package/runtime/scripts/daemon-observation.mjs +74 -18
- package/runtime/scripts/murmur-auth-token.mjs +140 -0
- package/runtime/scripts/murmur-daemon.mjs +66 -36
- package/runtime/scripts/murmur-jetstream-advisory.mjs +27 -0
- package/runtime/scripts/murmur-shell-send.mjs +3 -3
- package/runtime/scripts/wake-drain-claude.mjs +193 -39
- package/runtime/scripts/wake-monitor.mjs +46 -18
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { migrateBroker } from './broker-migration.js';
|
|
1
2
|
import { configureClient, previewClientConfiguration } from './clients.js';
|
|
3
|
+
import { previewBackups, cleanupBackups } from './backups.js';
|
|
4
|
+
import { checkInstallationSelection, selectInstallation, showInstallation } from './installation.js';
|
|
2
5
|
import { prepareReplyTest, checkReplyTest } from './reply-test.js';
|
|
3
6
|
import { listOutboxAttention, setOutboxDismissed } from './outbox-attention.js';
|
|
7
|
+
import { dismissWake } from './wake-attention.js';
|
|
4
8
|
import { initialize, invite, join, importPeer } from './onboarding.js';
|
|
9
|
+
import { connect, renderConnect } from './connect.js';
|
|
5
10
|
import { runDoctor } from './doctor.js';
|
|
6
11
|
import { parseArgs } from 'node:util';
|
|
7
12
|
import path from 'node:path';
|
|
@@ -34,16 +39,22 @@ export function platformAdapter() {
|
|
|
34
39
|
export const rawCliOutput = (text) => ({ kind: 'raw', text });
|
|
35
40
|
export const isRawCliOutput = (value) => !!value && typeof value === 'object'
|
|
36
41
|
&& value.kind === 'raw' && typeof value.text === 'string';
|
|
37
|
-
export async function main(args, adapter = platformAdapter()) {
|
|
42
|
+
export async function main(args, adapter = platformAdapter(), input = process.stdin) {
|
|
38
43
|
// `murmur --version` is the first thing people type after npm install; answer it like `murmur version`.
|
|
39
44
|
if (args.some(a => a === '--version' || a === '-v') && args.every(a => ['--version', '-v', '--json'].includes(a)))
|
|
40
45
|
return readVersion();
|
|
41
46
|
let parsed;
|
|
42
47
|
try {
|
|
43
48
|
parsed = parseArgs({ args, allowPositionals: true, options: {
|
|
49
|
+
kind: { type: 'string' }, 'config-file': { type: 'string' }, 'keep-file': { type: 'string', multiple: true },
|
|
50
|
+
'installation-file': { type: 'string' }, select: { type: 'boolean' },
|
|
44
51
|
'msg-id': { type: 'string' }, 'expected-state': { type: 'string' }, 'expected-agent': { type: 'string' },
|
|
45
|
-
'
|
|
46
|
-
|
|
52
|
+
'project-dir': { type: 'string' },
|
|
53
|
+
'user-file': { type: 'string' }, 'password-file': { type: 'string' }, 'ca-file': { type: 'string' }, 'server-name': { type: 'string' },
|
|
54
|
+
'agent-id': { type: 'string' }, 'broker-url': { type: 'string' }, broker: { type: 'string' }, 'token-file': { type: 'string' }, 'invite-file': { type: 'string' }, 'reply-file': { type: 'string' }, 'reply-out': { type: 'string' }, out: { type: 'string' },
|
|
55
|
+
invite: { type: 'string' }, 'no-service': { type: 'boolean' }, 'copy-reply': { type: 'boolean' }, 'print-secret': { type: 'boolean' },
|
|
56
|
+
'invite-stdin': { type: 'boolean' }, 'reply-stdin': { type: 'boolean' },
|
|
57
|
+
client: { type: 'string' }, replace: { type: 'boolean' }, 'replace-previous': { type: 'boolean' }, 'plan-id': { type: 'string' }, 'test-token': { type: 'string' }, json: { type: 'boolean' }, line: { type: 'boolean' }, limit: { type: 'string' }, peer: { type: 'string' }, timeout: { type: 'string' }, 'data-dir': { type: 'string' }, 'service-name': { type: 'string' }, apply: { type: 'boolean' }, help: { type: 'boolean' },
|
|
47
58
|
} });
|
|
48
59
|
}
|
|
49
60
|
catch (error) {
|
|
@@ -52,11 +63,15 @@ export async function main(args, adapter = platformAdapter()) {
|
|
|
52
63
|
}
|
|
53
64
|
const { values, positionals } = parsed;
|
|
54
65
|
if (values.help || !positionals.length)
|
|
55
|
-
return { commands: ['version --json', 'updates check|enable|disable --json', 'init --agent-id ID --broker-url URL [--token-file FILE]', 'invite --out FILE', 'join --agent-id ID --invite-file FILE --reply-out FILE', 'add-peer --reply-file FILE', 'status --json|--line', 'doctor --json [--peer AGENT] [--timeout MILLISECONDS]', 'logs path --json', 'service install|start|stop|uninstall', 'clients detect', 'clients preview --client ID', 'clients configure --client ID [--replace] [--plan-id SHA256]', 'reply-test prepare --peer AGENT', 'reply-test check --test-token TOKEN', 'wake pause|resume [--apply]', 'inbox read [--limit 1..100]', 'inbox mark-read', 'outbox list --json', 'outbox dismiss|restore --msg-id ID --expected-state TOKEN --expected-agent ID', 'mcp serve --data-dir ABSOLUTE'],
|
|
66
|
+
return { commands: ['broker migrate --broker-url URL [--token-file FILE|--user-file FILE --password-file FILE] [--ca-file FILE] [--server-name NAME] [--apply]', 'installation show [--installation-file ABSOLUTE]', 'installation select --data-dir ABSOLUTE [--replace] [--installation-file ABSOLUTE]', 'backups preview|cleanup --kind agent|client [--config-file ABSOLUTE] [--keep-file ABSOLUTE] [--plan-id SHA256]', 'version --json', 'updates check|enable|disable --json', 'init --agent-id ID --broker-url URL [--token-file FILE] [--select]', 'invite [--out FILE] [--broker-url PUBLIC_URL|--broker PUBLIC_URL] [--print-secret] [--json]', 'connect (--invite TEXT_OR_FILE|--invite-file FILE|--invite-stdin) [--agent-id ID] [--data-dir ABSOLUTE] [--reply-out FILE] [--client auto|claude-code|claude-desktop|codex|codex-cli|none] [--no-service] [--copy-reply] [--json]', 'join --agent-id ID (--invite-stdin|--invite-file FILE) [--reply-out FILE] [--select] [--json]', 'add-peer (--reply-stdin|--reply-file FILE)', 'status --json|--line', 'doctor --json [--peer AGENT] [--timeout MILLISECONDS]', 'logs path --json', 'service install [--replace-previous]|start|stop|uninstall', 'clients detect', 'clients preview --client ID [--project-dir ABSOLUTE]', 'clients configure --client ID [--project-dir ABSOLUTE] [--replace] [--plan-id SHA256]', 'reply-test prepare --peer AGENT', 'reply-test check --test-token TOKEN', 'wake pause|resume [--apply]', 'wake dismiss --msg-id ID --expected-agent ID', 'inbox read [--limit 1..100]', 'inbox mark-read', 'outbox list --json', 'outbox dismiss|restore --msg-id ID --expected-state TOKEN --expected-agent ID', 'mcp serve [--data-dir ABSOLUTE]'],
|
|
56
67
|
options: ['--data-dir ABSOLUTE', '--service-name NAME'], note: 'Windows service mutations require an elevated terminal and the matching native helper.' };
|
|
57
68
|
const [command, action, extra] = positionals;
|
|
58
69
|
if (extra)
|
|
59
70
|
throw new Error('cli.unexpected-argument');
|
|
71
|
+
if (['token-file', 'user-file', 'password-file', 'ca-file', 'server-name'].some(key => values[key] !== undefined)
|
|
72
|
+
&& !['init', 'join'].includes(command) && !(command === 'broker' && action === 'migrate')
|
|
73
|
+
|| values['broker-url'] !== undefined && !['init', 'invite'].includes(command) && !(command === 'broker' && action === 'migrate'))
|
|
74
|
+
throw new Error('cli.option-not-supported');
|
|
60
75
|
if (values.line && command !== 'status')
|
|
61
76
|
throw new Error('cli.line-only-for-status');
|
|
62
77
|
if (values.line && values.json)
|
|
@@ -67,17 +82,85 @@ export async function main(args, adapter = platformAdapter()) {
|
|
|
67
82
|
return checkUpdates();
|
|
68
83
|
if (command === 'updates' && ['enable', 'disable'].includes(action))
|
|
69
84
|
return setUpdateChecks(action === 'enable');
|
|
70
|
-
|
|
85
|
+
if (values['project-dir'] !== undefined && !['clients', 'doctor'].includes(command))
|
|
86
|
+
throw new Error('cli.project-dir-only-for-clients-or-doctor');
|
|
71
87
|
const required = (name) => { const value = values[name]; if (typeof value !== 'string' || !value)
|
|
72
88
|
throw new Error('cli.required-option:' + name); return value; };
|
|
89
|
+
if (command === 'backups' && ['preview', 'cleanup'].includes(action) && values.kind === 'client') {
|
|
90
|
+
const selection = { kind: 'client', configFile: required('config-file'), keepFiles: values['keep-file'] };
|
|
91
|
+
return action === 'preview' ? previewBackups(null, selection) : cleanupBackups(null, selection, required('plan-id'));
|
|
92
|
+
}
|
|
93
|
+
if (command === 'installation' && action === 'show')
|
|
94
|
+
return showInstallation(values['installation-file']);
|
|
95
|
+
if (command === 'installation' && action === 'select' && values['data-dir'] === undefined)
|
|
96
|
+
throw new Error('cli.required-option:data-dir');
|
|
97
|
+
if (values.select && !['init', 'join'].includes(command))
|
|
98
|
+
throw new Error('cli.select-only-for-init-or-join');
|
|
99
|
+
if ((values.invite !== undefined || values['no-service'] || values['copy-reply']) && command !== 'connect'
|
|
100
|
+
|| (values.broker !== undefined || values['print-secret']) && command !== 'invite')
|
|
101
|
+
throw new Error('cli.option-not-supported');
|
|
102
|
+
const onboardingInput = async (kind) => {
|
|
103
|
+
if (values[`${kind}-file`] !== undefined && values[`${kind}-stdin`])
|
|
104
|
+
throw new Error('onboarding.input-conflict');
|
|
105
|
+
if (!values[`${kind}-stdin`]) {
|
|
106
|
+
if (!values[`${kind}-file`])
|
|
107
|
+
throw new Error('onboarding.input-required');
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
if (input === process.stdin && process.stdin.isTTY)
|
|
111
|
+
throw new Error('onboarding.stdin-required');
|
|
112
|
+
const chunks = [];
|
|
113
|
+
let size = 0;
|
|
114
|
+
for await (const chunk of input) {
|
|
115
|
+
const bytes = Buffer.from(chunk);
|
|
116
|
+
size += bytes.length;
|
|
117
|
+
if (size > 16384)
|
|
118
|
+
throw new Error('onboarding.input-too-large');
|
|
119
|
+
chunks.push(bytes);
|
|
120
|
+
}
|
|
121
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
122
|
+
};
|
|
123
|
+
if (command === 'connect' && !action) {
|
|
124
|
+
if ([values.invite !== undefined, values['invite-file'] !== undefined, !!values['invite-stdin']].filter(Boolean).length !== 1) {
|
|
125
|
+
throw new Error('connect.one-invite-input-required');
|
|
126
|
+
}
|
|
127
|
+
const result = await connect(adapter, {
|
|
128
|
+
agentId: values['agent-id'], dataDir: values['data-dir'], inviteFile: values['invite-file'],
|
|
129
|
+
inviteArgument: values.invite, invitation: values['invite-stdin'] ? await onboardingInput('invite') : undefined,
|
|
130
|
+
replyOut: values['reply-out'], client: values.client, noService: values['no-service'], copyReply: values['copy-reply'],
|
|
131
|
+
});
|
|
132
|
+
return values.json ? result : rawCliOutput(renderConnect(result));
|
|
133
|
+
}
|
|
134
|
+
const context = resolveContext({ dataDir: values['data-dir'], serviceName: values['service-name'], installationFile: values['installation-file'], clientProjectDir: values['project-dir'] });
|
|
135
|
+
if (command === 'backups' && ['preview', 'cleanup'].includes(action)) {
|
|
136
|
+
const kind = required('kind');
|
|
137
|
+
if (kind !== 'agent' && kind !== 'client')
|
|
138
|
+
throw new Error('backups.kind-required');
|
|
139
|
+
const selection = { kind, configFile: values['config-file'], keepFiles: values['keep-file'] };
|
|
140
|
+
return action === 'preview' ? previewBackups(context, selection) : cleanupBackups(context, selection, required('plan-id'));
|
|
141
|
+
}
|
|
142
|
+
if (command === 'installation' && action === 'select')
|
|
143
|
+
return selectInstallation(context, { file: values['installation-file'], replace: values.replace });
|
|
144
|
+
if (values.select)
|
|
145
|
+
checkInstallationSelection(context, { file: values['installation-file'], replace: values.replace });
|
|
146
|
+
const selected = async (result) => values.select ? { ...result, installation: await selectInstallation(context, { file: values['installation-file'], replace: values.replace }) } : result;
|
|
147
|
+
const brokerFiles = { tokenFile: values['token-file'], userFile: values['user-file'], passwordFile: values['password-file'],
|
|
148
|
+
caFile: values['ca-file'], serverName: values['server-name'] };
|
|
149
|
+
if (command === 'broker' && action === 'migrate')
|
|
150
|
+
return migrateBroker(context, adapter, { ...brokerFiles,
|
|
151
|
+
brokerUrl: required('broker-url'), apply: values.apply });
|
|
73
152
|
if (command === 'init' && !action)
|
|
74
|
-
return initialize(context, { agentId: required('agent-id'), brokerUrl: required('broker-url'),
|
|
75
|
-
if (command === 'invite' && !action)
|
|
76
|
-
|
|
153
|
+
return selected(await initialize(context, { agentId: required('agent-id'), brokerUrl: required('broker-url'), ...brokerFiles }));
|
|
154
|
+
if (command === 'invite' && !action) {
|
|
155
|
+
if (values['broker-url'] !== undefined && values.broker !== undefined)
|
|
156
|
+
throw new Error('cli.broker-options-conflict');
|
|
157
|
+
return invite(context, values.out, { brokerUrl: values['broker-url'] ?? values.broker, printSecret: values['print-secret'] });
|
|
158
|
+
}
|
|
77
159
|
if (command === 'join' && !action)
|
|
78
|
-
return join(context, { agentId: required('agent-id'), inviteFile:
|
|
160
|
+
return selected(await join(context, { agentId: required('agent-id'), inviteFile: values['invite-file'],
|
|
161
|
+
invitation: await onboardingInput('invite'), replyOut: values['reply-out'], ...brokerFiles }));
|
|
79
162
|
if (command === 'add-peer' && !action)
|
|
80
|
-
return importPeer(context,
|
|
163
|
+
return importPeer(context, values['reply-file'], await onboardingInput('reply'));
|
|
81
164
|
if (command === 'status' && !action) {
|
|
82
165
|
const status = await readStatus({ context, adapter });
|
|
83
166
|
return values.line ? rawCliOutput(renderStatusLine(status)) : status;
|
|
@@ -87,8 +170,6 @@ export async function main(args, adapter = platformAdapter()) {
|
|
|
87
170
|
if (command === 'outbox' && ['dismiss', 'restore'].includes(action))
|
|
88
171
|
return setOutboxDismissed(context, required('msg-id'), required('expected-state'), required('expected-agent'), action === 'dismiss');
|
|
89
172
|
if (command === 'mcp' && action === 'serve') {
|
|
90
|
-
if (values['data-dir'] === undefined)
|
|
91
|
-
throw new Error('cli.required-option:data-dir');
|
|
92
173
|
process.env.DATA_DIR = context.dataDir;
|
|
93
174
|
process.env.MURMUR_DATA_DIR = context.dataDir;
|
|
94
175
|
process.env.MURMUR_STORE_PATH = context.storePath;
|
|
@@ -97,8 +178,11 @@ export async function main(args, adapter = platformAdapter()) {
|
|
|
97
178
|
return rawCliOutput('');
|
|
98
179
|
}
|
|
99
180
|
if (command === 'logs' && action === 'path') {
|
|
100
|
-
if (process.platform === 'win32')
|
|
101
|
-
|
|
181
|
+
if (process.platform === 'win32') {
|
|
182
|
+
if (!adapter.logDirectory)
|
|
183
|
+
throw new Error('logs.windows-native-location-unavailable');
|
|
184
|
+
return readLogPath(context, adapter);
|
|
185
|
+
}
|
|
102
186
|
return readLogPath(context);
|
|
103
187
|
}
|
|
104
188
|
if (command === 'doctor' && !action)
|
|
@@ -115,11 +199,24 @@ export async function main(args, adapter = platformAdapter()) {
|
|
|
115
199
|
return checkReplyTest(context, required('test-token'));
|
|
116
200
|
if (command === 'wake' && ['pause', 'resume'].includes(action))
|
|
117
201
|
return setWakeEnabled(context, adapter, action === 'resume', values.apply);
|
|
202
|
+
if (command === 'wake' && action === 'dismiss')
|
|
203
|
+
return dismissWake(context, required('msg-id'), required('expected-agent'));
|
|
118
204
|
if (command === 'inbox' && action === 'read')
|
|
119
205
|
return readInbox(context, values.limit === undefined ? 20 : Number(values.limit));
|
|
120
206
|
if (command === 'inbox' && action === 'mark-read')
|
|
121
207
|
return markInboxRead(context);
|
|
122
208
|
if (command === 'service' && ['install', 'start', 'stop', 'uninstall'].includes(action)) {
|
|
209
|
+
if (values['replace-previous']) {
|
|
210
|
+
// One elevated command: remove the previous installation's Service, then install this one.
|
|
211
|
+
if (action !== 'install')
|
|
212
|
+
throw new Error('cli.replace-previous-only-for-install');
|
|
213
|
+
if (!adapter.removePrevious)
|
|
214
|
+
throw new Error('service.replace-previous-unavailable');
|
|
215
|
+
await adapter.removePrevious(context);
|
|
216
|
+
}
|
|
217
|
+
// Evaluated after a removal, so a process that outlived the removed Service still blocks install.
|
|
218
|
+
if ((await readStatus({ context, adapter })).service.state === 'running-unmanaged')
|
|
219
|
+
throw new Error('service.running-unmanaged');
|
|
123
220
|
const operation = adapter[action];
|
|
124
221
|
if (!operation)
|
|
125
222
|
throw new Error('service.uninstall-unavailable');
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { PlatformAdapter, ServiceContext } from './types.js';
|
|
2
2
|
export { sameClientFileIdentity } from './file-identity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read-only: what Claude Code carries for this profile, for doctor's wake stage (#293).
|
|
5
|
+
* `current` means the installed Stop hook is exactly the one this runtime writes; it says
|
|
6
|
+
* nothing about a live session having been woken, which is a separate proof.
|
|
7
|
+
*/
|
|
8
|
+
export declare function claudeWakeHookState(c: ServiceContext, adapter: PlatformAdapter): Promise<'current' | 'outdated' | 'absent'>;
|
|
3
9
|
/** Read-only preview: even a missing parent directory is not created. */
|
|
4
10
|
export declare function previewClientConfiguration(c: ServiceContext, adapter: PlatformAdapter, clientId: string): Promise<{
|
|
5
11
|
wakeHook?: {
|
|
12
|
+
repointed?: string[] | undefined;
|
|
6
13
|
settingsPath: string;
|
|
7
14
|
action: "replace" | "unchanged" | "add";
|
|
8
15
|
} | undefined;
|
|
@@ -11,6 +18,7 @@ export declare function previewClientConfiguration(c: ServiceContext, adapter: P
|
|
|
11
18
|
configPath: string;
|
|
12
19
|
agentId: string;
|
|
13
20
|
dataDir: string;
|
|
21
|
+
serverName: string;
|
|
14
22
|
action: string;
|
|
15
23
|
planId: string;
|
|
16
24
|
configExisted: boolean;
|
|
@@ -21,19 +29,10 @@ export declare function previewClientConfiguration(c: ServiceContext, adapter: P
|
|
|
21
29
|
* also install the Stop wake hook, so a delivered message wakes the session without a human turn.
|
|
22
30
|
*/
|
|
23
31
|
export declare function configureClient(c: ServiceContext, adapter: PlatformAdapter, clientId: string, replace?: boolean, expectedPlan?: string): Promise<{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
29
|
-
configPath: string;
|
|
30
|
-
changed: boolean;
|
|
31
|
-
backup: null;
|
|
32
|
-
restartRequired: boolean;
|
|
33
|
-
} | {
|
|
34
|
-
planId?: undefined;
|
|
35
|
-
agentId?: undefined;
|
|
36
|
-
dataDir?: undefined;
|
|
32
|
+
serverName: string;
|
|
33
|
+
planId?: string | undefined;
|
|
34
|
+
agentId?: string | undefined;
|
|
35
|
+
dataDir?: string | undefined;
|
|
37
36
|
schema: string;
|
|
38
37
|
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
39
38
|
configPath: string;
|
|
@@ -43,46 +42,15 @@ export declare function configureClient(c: ServiceContext, adapter: PlatformAdap
|
|
|
43
42
|
} | {
|
|
44
43
|
restartRequired: boolean;
|
|
45
44
|
instruction: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
serverName: string;
|
|
46
|
+
planId?: string | undefined;
|
|
47
|
+
agentId?: string | undefined;
|
|
48
|
+
dataDir?: string | undefined;
|
|
49
49
|
schema: string;
|
|
50
50
|
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
51
51
|
configPath: string;
|
|
52
52
|
changed: boolean;
|
|
53
53
|
backup: string | null;
|
|
54
|
-
} | {
|
|
55
|
-
restartRequired: boolean;
|
|
56
|
-
instruction: string;
|
|
57
|
-
planId?: undefined;
|
|
58
|
-
agentId?: undefined;
|
|
59
|
-
dataDir?: undefined;
|
|
60
|
-
schema: string;
|
|
61
|
-
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
62
|
-
configPath: string;
|
|
63
|
-
changed: boolean;
|
|
64
|
-
backup: string | null;
|
|
65
|
-
} | {
|
|
66
|
-
changed: boolean;
|
|
67
|
-
wakeHook: {
|
|
68
|
-
settingsPath: string;
|
|
69
|
-
action: "unchanged";
|
|
70
|
-
changed: boolean;
|
|
71
|
-
backup: null;
|
|
72
|
-
} | {
|
|
73
|
-
settingsPath: string;
|
|
74
|
-
action: "replace" | "add";
|
|
75
|
-
changed: boolean;
|
|
76
|
-
backup: string | null;
|
|
77
|
-
};
|
|
78
|
-
planId: string;
|
|
79
|
-
agentId: string;
|
|
80
|
-
dataDir: string;
|
|
81
|
-
schema: string;
|
|
82
|
-
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
83
|
-
configPath: string;
|
|
84
|
-
backup: null;
|
|
85
|
-
restartRequired: boolean;
|
|
86
54
|
} | {
|
|
87
55
|
changed: boolean;
|
|
88
56
|
wakeHook: {
|
|
@@ -90,15 +58,18 @@ export declare function configureClient(c: ServiceContext, adapter: PlatformAdap
|
|
|
90
58
|
action: "unchanged";
|
|
91
59
|
changed: boolean;
|
|
92
60
|
backup: null;
|
|
61
|
+
repointed: string[];
|
|
93
62
|
} | {
|
|
94
63
|
settingsPath: string;
|
|
95
64
|
action: "replace" | "add";
|
|
96
65
|
changed: boolean;
|
|
97
66
|
backup: string | null;
|
|
67
|
+
repointed: string[];
|
|
98
68
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
69
|
+
serverName: string;
|
|
70
|
+
planId?: string | undefined;
|
|
71
|
+
agentId?: string | undefined;
|
|
72
|
+
dataDir?: string | undefined;
|
|
102
73
|
schema: string;
|
|
103
74
|
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
104
75
|
configPath: string;
|
|
@@ -111,39 +82,20 @@ export declare function configureClient(c: ServiceContext, adapter: PlatformAdap
|
|
|
111
82
|
action: "unchanged";
|
|
112
83
|
changed: boolean;
|
|
113
84
|
backup: null;
|
|
85
|
+
repointed: string[];
|
|
114
86
|
} | {
|
|
115
87
|
settingsPath: string;
|
|
116
88
|
action: "replace" | "add";
|
|
117
89
|
changed: boolean;
|
|
118
90
|
backup: string | null;
|
|
91
|
+
repointed: string[];
|
|
119
92
|
};
|
|
120
93
|
restartRequired: boolean;
|
|
121
94
|
instruction: string;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
127
|
-
configPath: string;
|
|
128
|
-
backup: string | null;
|
|
129
|
-
} | {
|
|
130
|
-
changed: boolean;
|
|
131
|
-
wakeHook: {
|
|
132
|
-
settingsPath: string;
|
|
133
|
-
action: "unchanged";
|
|
134
|
-
changed: boolean;
|
|
135
|
-
backup: null;
|
|
136
|
-
} | {
|
|
137
|
-
settingsPath: string;
|
|
138
|
-
action: "replace" | "add";
|
|
139
|
-
changed: boolean;
|
|
140
|
-
backup: string | null;
|
|
141
|
-
};
|
|
142
|
-
restartRequired: boolean;
|
|
143
|
-
instruction: string;
|
|
144
|
-
planId?: undefined;
|
|
145
|
-
agentId?: undefined;
|
|
146
|
-
dataDir?: undefined;
|
|
95
|
+
serverName: string;
|
|
96
|
+
planId?: string | undefined;
|
|
97
|
+
agentId?: string | undefined;
|
|
98
|
+
dataDir?: string | undefined;
|
|
147
99
|
schema: string;
|
|
148
100
|
client: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
149
101
|
configPath: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as TOML from '@iarna/toml';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
|
-
import { lstat, mkdir, open, rename, rmdir, stat, unlink } from 'node:fs/promises';
|
|
3
|
+
import { lstat, mkdir, open, realpath, rename, rmdir, stat, unlink } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { createHash, randomUUID } from 'node:crypto';
|
|
6
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -10,11 +10,69 @@ import { protectPrivateFile, preparePrivateReplacement } from './private-file.js
|
|
|
10
10
|
export { sameClientFileIdentity } from './file-identity.js';
|
|
11
11
|
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
12
12
|
async function selectedClient(c, adapter, clientId) {
|
|
13
|
-
const
|
|
13
|
+
const clients = await adapter.detectClients(c);
|
|
14
|
+
const client = clients.find(item => item.id === clientId);
|
|
14
15
|
if (!client || !client.installed)
|
|
15
16
|
throw new Error('client.not-detected');
|
|
16
17
|
if (!client.configPath || !path.isAbsolute(client.configPath))
|
|
17
18
|
throw new Error('client.config-path-unverified');
|
|
19
|
+
if (c.clientProjectDir) {
|
|
20
|
+
if (clientId !== 'claude-code')
|
|
21
|
+
throw new Error('client.project-only-for-claude-code');
|
|
22
|
+
if (!path.isAbsolute(c.clientProjectDir) || !(await stat(c.clientProjectDir).catch(() => null))?.isDirectory())
|
|
23
|
+
throw new Error('client.project-directory-required');
|
|
24
|
+
// An inherited global/ancestor hook would still wake other chats. Refuse before
|
|
25
|
+
// writing anything; never silently remove a person's existing integration.
|
|
26
|
+
const parents = new Set([path.dirname(client.configPath)]);
|
|
27
|
+
let parent = path.dirname(c.clientProjectDir);
|
|
28
|
+
while (true) {
|
|
29
|
+
parents.add(parent);
|
|
30
|
+
const next = path.dirname(parent);
|
|
31
|
+
if (next === parent)
|
|
32
|
+
break;
|
|
33
|
+
parent = next;
|
|
34
|
+
}
|
|
35
|
+
// Local settings merge their hooks with project settings. They must not leave
|
|
36
|
+
// a second reader behind even in the selected project itself.
|
|
37
|
+
const local = await readClientFile(path.join(c.clientProjectDir, '.claude', 'settings.local.json'));
|
|
38
|
+
if (local.text.includes('wake-drain-claude'))
|
|
39
|
+
throw new Error('client.inherited-wake-hook-conflict');
|
|
40
|
+
for (const dir of parents) {
|
|
41
|
+
if (dir === c.clientProjectDir)
|
|
42
|
+
throw new Error('client.project-must-be-dedicated');
|
|
43
|
+
for (const name of ['settings.json', 'settings.local.json']) {
|
|
44
|
+
const file = await readClientFile(path.join(dir, '.claude', name));
|
|
45
|
+
if (file.text.includes('wake-drain-claude'))
|
|
46
|
+
throw new Error('client.inherited-wake-hook-conflict');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Desktop forwards Chat/user MCP registrations ahead of project entries.
|
|
50
|
+
// Refuse an occupied dedicated name instead of selecting a global identity.
|
|
51
|
+
// Code's local scope lives under projects[path] in the same user file and
|
|
52
|
+
// outranks .mcp.json too. Inspect both path spellings without changing the
|
|
53
|
+
// selected path used for service identity, folder name or wake lane.
|
|
54
|
+
const projectPaths = new Set([c.clientProjectDir, await realpath(c.clientProjectDir)]);
|
|
55
|
+
for (const global of clients.filter(item => ['claude-code', 'claude-desktop'].includes(item.id))) {
|
|
56
|
+
if (!global.configPath || !path.isAbsolute(global.configPath))
|
|
57
|
+
continue;
|
|
58
|
+
const file = await readClientFile(global.configPath);
|
|
59
|
+
const { original, key } = clientDocument(global, file.text);
|
|
60
|
+
if (original[key]?.[mcpEntryName(c)] !== undefined)
|
|
61
|
+
throw new Error('client.inherited-mcp-entry-conflict');
|
|
62
|
+
if (global.id === 'claude-code' && object(original.projects)) {
|
|
63
|
+
for (const projectPath of projectPaths) {
|
|
64
|
+
const local = original.projects[projectPath];
|
|
65
|
+
if (local === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
if (!object(local) || local.mcpServers !== undefined && !object(local.mcpServers))
|
|
68
|
+
throw new Error('client.mcp-table-invalid');
|
|
69
|
+
if (local.mcpServers?.[mcpEntryName(c)] !== undefined)
|
|
70
|
+
throw new Error('client.inherited-mcp-entry-conflict');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { ...client, configPath: path.join(c.clientProjectDir, '.mcp.json') };
|
|
75
|
+
}
|
|
18
76
|
return { ...client, configPath: client.configPath };
|
|
19
77
|
}
|
|
20
78
|
async function readClientFile(file) {
|
|
@@ -67,13 +125,29 @@ const hookPath = (value) => `"${value.replaceAll('\\', '/')}"`;
|
|
|
67
125
|
// Eight hours after each turn instead of the drain's 20-minute default: a message that arrives
|
|
68
126
|
// during a working day still wakes the session (docs/wake-native.md, known limitation).
|
|
69
127
|
const WAKE_WINDOW_SECONDS = 28800;
|
|
128
|
+
const projectLane = (c) => c.clientProjectDir
|
|
129
|
+
? createHash('sha256').update(c.clientProjectDir).digest('hex').slice(0, 8) : null;
|
|
130
|
+
const mcpEntryName = (c) => c.clientProjectDir ? `murmur-${projectLane(c)}` : 'murmur';
|
|
70
131
|
/** The node wake drain (docs/wake-native.md): polls the store after each turn and wakes the session. */
|
|
71
132
|
function desiredWakeHook(c) {
|
|
72
|
-
|
|
73
|
-
|
|
133
|
+
// Claude Code ends a hook without its own `timeout` after 600 s (hooks reference, asyncRewake);
|
|
134
|
+
// the entry carries the same window the drain script is asked for, or the script never gets it.
|
|
135
|
+
const lane = projectLane(c);
|
|
136
|
+
return { type: 'command', asyncRewake: true, timeout: WAKE_WINDOW_SECONDS,
|
|
137
|
+
command: `${hookPath(c.nodePath)} --no-warnings ${hookPath(path.join(c.repoRoot, 'scripts', 'wake-drain-claude.mjs'))} --db ${hookPath(c.storePath)} --max-seconds ${WAKE_WINDOW_SECONDS}${lane ? ` --session-key ${lane}` : ''}` };
|
|
74
138
|
}
|
|
75
139
|
const isMurmurWakeHook = (hook) => object(hook) && typeof hook.command === 'string' && hook.command.includes('wake-drain-claude');
|
|
76
|
-
|
|
140
|
+
const wakeGroups = (value) => Array.isArray(value) && value.every(group => object(group) && Array.isArray(group.hooks));
|
|
141
|
+
// The drain path inside a hook command, quoted or bare. Outside Stop it is the only part we
|
|
142
|
+
// rewrite, so flags and timeouts a person chose keep working.
|
|
143
|
+
const wakeScript = /"[^"]*wake-drain-claude[^"]*"|[^\s"]*wake-drain-claude[^\s"]*/;
|
|
144
|
+
const wakeScriptOf = (command) => command.match(wakeScript)?.[0].replaceAll('"', '').replaceAll('\\', '/');
|
|
145
|
+
/**
|
|
146
|
+
* Plan the Stop hook edit; only Murmur's own wake hook is ever added, kept or replaced.
|
|
147
|
+
* Hooks under other events keep their own flags and are only repointed at the script this
|
|
148
|
+
* runtime ships, so one settings file never runs two versions of the drain against the same
|
|
149
|
+
* session cursors (#294). Their events are reported, because they were written by hand.
|
|
150
|
+
*/
|
|
77
151
|
function planWakeHook(c, text) {
|
|
78
152
|
let settings;
|
|
79
153
|
try {
|
|
@@ -83,16 +157,29 @@ function planWakeHook(c, text) {
|
|
|
83
157
|
throw new Error('client.settings-parse-failed');
|
|
84
158
|
}
|
|
85
159
|
if (!object(settings) || (settings.hooks !== undefined && !object(settings.hooks))
|
|
86
|
-
|| (settings.hooks?.Stop !== undefined &&
|
|
87
|
-
|| !settings.hooks.Stop.every((group) => object(group) && Array.isArray(group.hooks)))))
|
|
160
|
+
|| (settings.hooks?.Stop !== undefined && !wakeGroups(settings.hooks.Stop)))
|
|
88
161
|
throw new Error('client.hooks-invalid');
|
|
89
162
|
const entry = desiredWakeHook(c), groups = settings.hooks?.Stop ?? [];
|
|
90
163
|
const ours = groups.flatMap(group => group.hooks.filter(isMurmurWakeHook));
|
|
91
|
-
|
|
92
|
-
|
|
164
|
+
const drain = path.join(c.repoRoot, 'scripts', 'wake-drain-claude.mjs');
|
|
165
|
+
const installed = drain.replaceAll('\\', '/');
|
|
166
|
+
// An event we cannot read as hook groups is left alone entirely: it is not ours to reshape.
|
|
167
|
+
const others = Object.entries(settings.hooks ?? {}).filter(([event, value]) => event !== 'Stop' && wakeGroups(value));
|
|
168
|
+
const repointed = others.filter(([, value]) => value
|
|
169
|
+
.some(group => group.hooks.some((hook) => isMurmurWakeHook(hook) && wakeScriptOf(hook.command) !== installed)))
|
|
170
|
+
.map(([event]) => String(event));
|
|
171
|
+
if (ours.length === 1 && isDeepStrictEqual(ours[0], entry) && !repointed.length) {
|
|
172
|
+
return { action: 'unchanged', next: settings, repointed };
|
|
173
|
+
}
|
|
93
174
|
const kept = groups.map(group => ({ ...group, hooks: group.hooks.filter((hook) => !isMurmurWakeHook(hook)) })).filter(group => group.hooks.length);
|
|
94
|
-
const
|
|
95
|
-
|
|
175
|
+
const hooks = { ...settings.hooks, Stop: [...kept, { hooks: [entry] }] };
|
|
176
|
+
for (const [event, value] of others) {
|
|
177
|
+
if (!repointed.includes(event))
|
|
178
|
+
continue;
|
|
179
|
+
hooks[event] = value.map(group => ({ ...group, hooks: group.hooks.map((hook) => isMurmurWakeHook(hook) ? { ...hook, command: hook.command.replace(wakeScript, hookPath(drain)) } : hook) }));
|
|
180
|
+
}
|
|
181
|
+
const next = { ...settings, hooks };
|
|
182
|
+
return { action: ours.length || repointed.length ? 'replace' : 'add', next, repointed };
|
|
96
183
|
}
|
|
97
184
|
/** Write settings.json the same guarded way as the MCP entry: lock, private backup, atomic rename. */
|
|
98
185
|
async function configureWakeHook(c, file, before) {
|
|
@@ -103,9 +190,9 @@ async function configureWakeHook(c, file, before) {
|
|
|
103
190
|
const current = await readClientFile(file);
|
|
104
191
|
if (!isDeepStrictEqual(current, before))
|
|
105
192
|
throw new Error('client.plan-stale');
|
|
106
|
-
const { action, next } = planWakeHook(c, current.text);
|
|
193
|
+
const { action, next, repointed } = planWakeHook(c, current.text);
|
|
107
194
|
if (action === 'unchanged')
|
|
108
|
-
return { settingsPath: file, action, changed: false, backup: null };
|
|
195
|
+
return { settingsPath: file, action, changed: false, backup: null, repointed };
|
|
109
196
|
const serialized = JSON.stringify(next, null, 2) + '\n';
|
|
110
197
|
const backup = current.existed ? `${file}.murmur-backup-${randomUUID()}` : null;
|
|
111
198
|
if (backup) {
|
|
@@ -137,27 +224,81 @@ async function configureWakeHook(c, file, before) {
|
|
|
137
224
|
finally {
|
|
138
225
|
await unlink(temporary).catch(() => { });
|
|
139
226
|
}
|
|
140
|
-
return { settingsPath: file, action, changed: true, backup };
|
|
227
|
+
return { settingsPath: file, action, changed: true, backup, repointed };
|
|
141
228
|
}
|
|
142
229
|
finally {
|
|
143
230
|
await rmdir(lock);
|
|
144
231
|
}
|
|
145
232
|
}
|
|
146
233
|
function desiredEntry(c) {
|
|
234
|
+
const lane = projectLane(c);
|
|
147
235
|
return { command: c.nodePath, args: [path.join(c.repoRoot, 'packages', 'mcp-server', 'dist', 'src', 'index.js')],
|
|
148
|
-
env: { DATA_DIR: c.dataDir, MURMUR_STORE_PATH: c.storePath
|
|
236
|
+
env: { DATA_DIR: c.dataDir, MURMUR_DATA_DIR: c.dataDir, MURMUR_STORE_PATH: c.storePath,
|
|
237
|
+
MURMUR_CHANNEL_ROSTER_PATH: path.join(c.dataDir, 'channel-roster.db'),
|
|
238
|
+
...(lane ? { MURMUR_WAKE_SESSION_KEY: lane } : {}) } };
|
|
239
|
+
}
|
|
240
|
+
function mcpChange(c, original, key) {
|
|
241
|
+
const entry = desiredEntry(c), name = mcpEntryName(c), previous = original[key]?.[name];
|
|
242
|
+
const servers = { ...original[key] }, legacy = servers.murmur;
|
|
243
|
+
// Only migrate the old project registration for this exact profile. Other
|
|
244
|
+
// servers and identities remain intact, and replacement keeps a raw backup.
|
|
245
|
+
const legacyOwned = !!c.clientProjectDir && object(legacy) && object(legacy.env)
|
|
246
|
+
&& legacy.env.DATA_DIR === c.dataDir && legacy.env.MURMUR_STORE_PATH === c.storePath
|
|
247
|
+
&& typeof legacy.command === 'string' && Array.isArray(legacy.args) && legacy.args.length === 1
|
|
248
|
+
&& typeof legacy.args[0] === 'string' && /[/\\]packages[/\\]mcp-server[/\\]dist[/\\]src[/\\]index\.js$/.test(legacy.args[0]);
|
|
249
|
+
if (legacyOwned)
|
|
250
|
+
delete servers.murmur;
|
|
251
|
+
servers[name] = entry;
|
|
252
|
+
const action = legacyOwned ? 'replace' : isDeepStrictEqual(previous, entry) ? 'unchanged' : previous === undefined ? 'add' : 'replace';
|
|
253
|
+
return { entry, name, action, next: { ...original, [key]: servers } };
|
|
149
254
|
}
|
|
150
255
|
async function planFor(c, client, current, settings) {
|
|
151
256
|
const config = await loadConfig(c), { original, key } = clientDocument(client, current.text);
|
|
152
|
-
const entry =
|
|
153
|
-
const
|
|
154
|
-
|
|
257
|
+
const { entry, name, action: entryAction } = mcpChange(c, original, key);
|
|
258
|
+
const plannedHook = settings && planWakeHook(c, settings.text);
|
|
259
|
+
// The preview names the hand-written events it would repoint, so the person reads them before
|
|
260
|
+
// confirming rather than finding a changed command afterwards (#294).
|
|
261
|
+
const wakeHook = plannedHook && { settingsPath: claudeSettingsPath(client.configPath), action: plannedHook.action,
|
|
262
|
+
...(plannedHook.repointed.length ? { repointed: plannedHook.repointed } : {}) };
|
|
263
|
+
// The plan's action speaks for both files: an app that sees 'replace' asks the person and
|
|
264
|
+
// passes --replace, so a Stop hook written by an earlier version (no timeout, #273) is
|
|
265
|
+
// upgraded instead of failing with client.wake-hook-conflict while the MCP entry is unchanged.
|
|
266
|
+
const action = wakeHook?.action === 'replace' ? 'replace' : entryAction === 'unchanged' && wakeHook?.action === 'add' ? 'add' : entryAction;
|
|
155
267
|
// Bind confirmation to the target, exact bytes and selected identity/runtime.
|
|
156
268
|
// No existing commands, environment values, auth or config contents leave the engine.
|
|
157
269
|
const planId = createHash('sha256').update(JSON.stringify([client.id, client.configPath, current,
|
|
158
|
-
config.agentId, config.keys.signing.publicKey, config.keys.encryption.publicKey, entry, settings ?? null])).digest('hex');
|
|
270
|
+
config.agentId, config.keys.signing.publicKey, config.keys.encryption.publicKey, name, entry, settings ?? null])).digest('hex');
|
|
159
271
|
return { schema: 'murmur.client-plan/1', client: client.id, configPath: client.configPath,
|
|
160
|
-
agentId: config.agentId, dataDir: c.dataDir, action, planId, configExisted: current.existed, restartRequired: true, ...(wakeHook ? { wakeHook } : {}) };
|
|
272
|
+
agentId: config.agentId, dataDir: c.dataDir, serverName: name, action, planId, configExisted: current.existed, restartRequired: true, ...(wakeHook ? { wakeHook } : {}) };
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Read-only: what Claude Code carries for this profile, for doctor's wake stage (#293).
|
|
276
|
+
* `current` means the installed Stop hook is exactly the one this runtime writes; it says
|
|
277
|
+
* nothing about a live session having been woken, which is a separate proof.
|
|
278
|
+
*/
|
|
279
|
+
export async function claudeWakeHookState(c, adapter) {
|
|
280
|
+
const client = await selectedClient(c, adapter, 'claude-code').catch(() => null);
|
|
281
|
+
if (!client?.configPath)
|
|
282
|
+
return 'absent';
|
|
283
|
+
const settings = await readClientFile(claudeSettingsPath(client.configPath)).catch(() => null);
|
|
284
|
+
if (!settings?.existed)
|
|
285
|
+
return 'absent';
|
|
286
|
+
let parsed;
|
|
287
|
+
try {
|
|
288
|
+
parsed = settings.text.trim() ? JSON.parse(settings.text) : {};
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return 'absent';
|
|
292
|
+
}
|
|
293
|
+
if (!object(parsed) || !object(parsed.hooks) || !wakeGroups(parsed.hooks.Stop))
|
|
294
|
+
return 'absent';
|
|
295
|
+
// One settings file serves every profile on the machine, so only a hook that names this
|
|
296
|
+
// profile's store says anything about this doctor run; another profile's is not ours to judge.
|
|
297
|
+
const ours = parsed.hooks.Stop.flatMap(group => group.hooks.filter(isMurmurWakeHook))
|
|
298
|
+
.filter(hook => hook.command.includes(hookPath(c.storePath)));
|
|
299
|
+
if (!ours.length)
|
|
300
|
+
return 'absent';
|
|
301
|
+
return ours.some(hook => isDeepStrictEqual(hook, desiredWakeHook(c))) ? 'current' : 'outdated';
|
|
161
302
|
}
|
|
162
303
|
/** Read-only preview: even a missing parent directory is not created. */
|
|
163
304
|
export async function previewClientConfiguration(c, adapter, clientId) {
|
|
@@ -197,14 +338,13 @@ async function configureMcpEntry(c, client, replace, expectedPlan, settings) {
|
|
|
197
338
|
const plan = expectedPlan === undefined ? undefined : await planFor(c, client, current, settings);
|
|
198
339
|
if (plan && plan.planId !== expectedPlan)
|
|
199
340
|
throw new Error('client.plan-stale');
|
|
200
|
-
const { original, key, parse } = clientDocument(client, text)
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
341
|
+
const { original, key, parse } = clientDocument(client, text);
|
|
342
|
+
const { name, action, next } = mcpChange(c, original, key);
|
|
343
|
+
const confirmed = { ...(plan ? { planId: plan.planId, agentId: plan.agentId, dataDir: plan.dataDir } : {}), serverName: name };
|
|
344
|
+
if (action === 'unchanged')
|
|
204
345
|
return { schema: 'murmur.client/1', client: clientId, configPath: file, changed: false, backup: null, restartRequired: true, ...confirmed };
|
|
205
|
-
if (
|
|
346
|
+
if (action === 'replace' && !replace)
|
|
206
347
|
throw new Error('client.murmur-entry-conflict');
|
|
207
|
-
const next = { ...original, [key]: { ...original[key], murmur: entry } };
|
|
208
348
|
const serialized = client.format === 'json' ? JSON.stringify(next, null, 2) + '\n' : TOML.stringify(next);
|
|
209
349
|
if (!isDeepStrictEqual(parse(serialized), next))
|
|
210
350
|
throw new Error('client.config-roundtrip-failed');
|