@murmurv2/cli 2.13.0 → 2.14.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/package.json +3 -3
- package/runtime/bin/murmur-svc.exe +0 -0
- package/runtime/npm-runtime-manifest.json +57 -37
- package/runtime/package.json +1 -1
- package/runtime/packages/setup/dist/src/autoreply.d.ts +23 -0
- package/runtime/packages/setup/dist/src/autoreply.js +71 -0
- package/runtime/packages/setup/dist/src/cli.js +47 -1
- package/runtime/packages/setup/dist/src/clients.d.ts +5 -5
- package/runtime/packages/setup/dist/src/commands.d.ts +1 -0
- package/runtime/packages/setup/dist/src/commands.js +17 -5
- package/runtime/packages/setup/dist/src/connect.d.ts +5 -5
- package/runtime/packages/setup/dist/src/connect.js +3 -1
- package/runtime/packages/setup/dist/src/conversations.d.ts +193 -0
- package/runtime/packages/setup/dist/src/conversations.js +674 -0
- package/runtime/packages/setup/dist/src/platform/darwin.js +12 -0
- package/runtime/packages/setup/dist/src/platform/linux.js +24 -10
- package/runtime/packages/setup/dist/src/platform/windows.js +26 -7
- package/runtime/packages/setup/dist/src/types.d.ts +1 -1
- package/runtime/packages/setup/package.json +1 -1
- package/runtime/scripts/codex-app-server-wake.mjs +23 -4
- package/runtime/scripts/murmur-daemon.mjs +5 -2
- package/runtime/scripts/murmur-shell-send.mjs +5 -1
- package/runtime/scripts/owner-review-store.mjs +54 -0
- package/runtime/scripts/wake-monitor.mjs +49 -10
|
@@ -483,6 +483,14 @@ export function createDarwinAdapter(options = {}) {
|
|
|
483
483
|
}
|
|
484
484
|
const claudeCli = await hasExecutable("claude");
|
|
485
485
|
const bundledCode = !claudeCli && await hasBundledClaudeCode();
|
|
486
|
+
const hasDirectory = async (dirPath) => (await fs.stat(dirPath).catch(() => null))?.isDirectory() === true;
|
|
487
|
+
let cursorApp = false;
|
|
488
|
+
for (const dir of appDirs) {
|
|
489
|
+
if (await hasDirectory(path.join(absolute(dir, "applicationDir"), "Cursor.app"))) {
|
|
490
|
+
cursorApp = true;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
486
494
|
return [
|
|
487
495
|
{ id: "claude-code", installed: claudeCli || bundledCode, configPath: claudeConfig, format: "json",
|
|
488
496
|
...(bundledCode ? { detail: "Claude Code in the Claude desktop application" } : {}),
|
|
@@ -490,6 +498,10 @@ export function createDarwinAdapter(options = {}) {
|
|
|
490
498
|
{ id: "claude-desktop", installed: claudeDesktop, configPath: path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json"), format: "json" },
|
|
491
499
|
{ id: "codex-cli", installed: await hasExecutable("codex"), configPath: codexConfig, format: "toml" },
|
|
492
500
|
{ id: "codex-desktop", installed: await hasApp(["Codex.app", "ChatGPT.app"], "com.openai.codex"), configPath: codexConfig, format: "toml" },
|
|
501
|
+
{ id: "cursor", installed: (await hasExecutable("cursor")) || (await hasExecutable("agent")) || cursorApp || (await hasDirectory(path.join(home, ".cursor"))),
|
|
502
|
+
configPath: path.join(home, ".cursor", "mcp.json"), format: "json" },
|
|
503
|
+
{ id: "gemini", installed: (await hasExecutable("agy")) || (await hasExecutable("gemini")) || (await hasDirectory(path.join(home, ".gemini"))),
|
|
504
|
+
configPath: path.join(home, ".gemini", "config", "mcp_config.json"), format: "json" },
|
|
493
505
|
];
|
|
494
506
|
}
|
|
495
507
|
return { manager: "launchd", status, install, start, stop, detectClients, profileUsage,
|
|
@@ -283,27 +283,41 @@ export function createLinuxAdapter(options = {}) {
|
|
|
283
283
|
await run(["stop", unit(c)]);
|
|
284
284
|
},
|
|
285
285
|
async detectClients() {
|
|
286
|
-
const
|
|
287
|
-
for (const [id, command, configPath, format] of [
|
|
288
|
-
["claude-code", "claude", env.CLAUDE_CONFIG_DIR ? null : path.join(home, ".claude.json"), "json"],
|
|
289
|
-
["codex-cli", "codex", path.join(env.CODEX_HOME || path.join(home, ".codex"), "config.toml"), "toml"],
|
|
290
|
-
]) {
|
|
291
|
-
let installed = false;
|
|
286
|
+
const hasExecutable = async (command) => {
|
|
292
287
|
for (const candidate of (env.PATH ?? "").split(path.delimiter)) {
|
|
293
288
|
if (!path.isAbsolute(candidate))
|
|
294
289
|
continue;
|
|
295
290
|
try {
|
|
296
291
|
const file = path.join(candidate, command);
|
|
297
292
|
await access(file, constants.X_OK);
|
|
298
|
-
if ((await stat(file)).isFile())
|
|
299
|
-
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
293
|
+
if ((await stat(file)).isFile())
|
|
294
|
+
return true;
|
|
302
295
|
}
|
|
303
296
|
catch { }
|
|
304
297
|
}
|
|
298
|
+
return false;
|
|
299
|
+
};
|
|
300
|
+
const hasDirectory = async (dirPath) => (await stat(dirPath).catch(() => null))?.isDirectory() === true;
|
|
301
|
+
const rows = [];
|
|
302
|
+
for (const [id, command, configPath, format] of [
|
|
303
|
+
["claude-code", "claude", env.CLAUDE_CONFIG_DIR ? null : path.join(home, ".claude.json"), "json"],
|
|
304
|
+
["codex-cli", "codex", path.join(env.CODEX_HOME || path.join(home, ".codex"), "config.toml"), "toml"],
|
|
305
|
+
]) {
|
|
306
|
+
const installed = await hasExecutable(command);
|
|
305
307
|
rows.push({ id, installed, configPath, format, ...(configPath === null ? { detail: "Custom Claude profile requires client verification" } : {}) });
|
|
306
308
|
}
|
|
309
|
+
rows.push({
|
|
310
|
+
id: "cursor",
|
|
311
|
+
installed: (await hasExecutable("cursor")) || (await hasExecutable("agent")) || (await hasDirectory(path.join(home, ".cursor"))),
|
|
312
|
+
configPath: path.join(home, ".cursor", "mcp.json"),
|
|
313
|
+
format: "json",
|
|
314
|
+
});
|
|
315
|
+
rows.push({
|
|
316
|
+
id: "gemini",
|
|
317
|
+
installed: (await hasExecutable("agy")) || (await hasExecutable("gemini")) || (await hasDirectory(path.join(home, ".gemini"))),
|
|
318
|
+
configPath: path.join(home, ".gemini", "config", "mcp_config.json"),
|
|
319
|
+
format: "json",
|
|
320
|
+
});
|
|
307
321
|
return rows;
|
|
308
322
|
},
|
|
309
323
|
profileUsage,
|
|
@@ -249,25 +249,44 @@ export function createWindowsAdapter(options = {}) {
|
|
|
249
249
|
}
|
|
250
250
|
},
|
|
251
251
|
async detectClients() {
|
|
252
|
-
const
|
|
253
|
-
for (const [id, command, configPath, format] of [
|
|
254
|
-
['claude-code', 'claude', env.CLAUDE_CONFIG_DIR ? null : paths.join(home, '.claude.json'), 'json'],
|
|
255
|
-
['codex-cli', 'codex', paths.join(env.CODEX_HOME || paths.join(home, '.codex'), 'config.toml'), 'toml'],
|
|
256
|
-
]) {
|
|
257
|
-
let installed = false;
|
|
252
|
+
const hasExecutable = async (command) => {
|
|
258
253
|
for (const dir of (env.PATH ?? env.Path ?? '').split(';')) {
|
|
259
254
|
if (!paths.isAbsolute(dir))
|
|
260
255
|
continue;
|
|
261
256
|
for (const suffix of ['.exe', '.cmd', '.bat']) {
|
|
262
257
|
try {
|
|
263
258
|
if ((await stat(paths.join(dir, command + suffix))).isFile())
|
|
264
|
-
|
|
259
|
+
return true;
|
|
265
260
|
}
|
|
266
261
|
catch { }
|
|
267
262
|
}
|
|
268
263
|
}
|
|
264
|
+
return false;
|
|
265
|
+
};
|
|
266
|
+
const hasDirectory = async (dirPath) => (await stat(dirPath).catch(() => null))?.isDirectory() === true;
|
|
267
|
+
const joinFs = process.platform === 'win32' || /^[A-Za-z]:/.test(home) || home.includes('\\') ? paths.join : path.join;
|
|
268
|
+
const rows = [];
|
|
269
|
+
for (const [id, command, configPath, format] of [
|
|
270
|
+
['claude-code', 'claude', env.CLAUDE_CONFIG_DIR ? null : paths.join(home, '.claude.json'), 'json'],
|
|
271
|
+
['codex-cli', 'codex', paths.join(env.CODEX_HOME || paths.join(home, '.codex'), 'config.toml'), 'toml'],
|
|
272
|
+
]) {
|
|
273
|
+
const installed = await hasExecutable(command);
|
|
269
274
|
rows.push({ id, installed, configPath: configPath && paths.isAbsolute(configPath) ? configPath : null, format });
|
|
270
275
|
}
|
|
276
|
+
const cursorConfig = paths.join(home, '.cursor', 'mcp.json');
|
|
277
|
+
rows.push({
|
|
278
|
+
id: 'cursor',
|
|
279
|
+
installed: (await hasExecutable('cursor')) || (await hasExecutable('agent')) || (await hasDirectory(joinFs(home, '.cursor'))),
|
|
280
|
+
configPath: paths.isAbsolute(cursorConfig) ? cursorConfig : null,
|
|
281
|
+
format: 'json',
|
|
282
|
+
});
|
|
283
|
+
const geminiConfig = paths.join(home, '.gemini', 'config', 'mcp_config.json');
|
|
284
|
+
rows.push({
|
|
285
|
+
id: 'gemini',
|
|
286
|
+
installed: (await hasExecutable('agy')) || (await hasExecutable('gemini')) || (await hasDirectory(joinFs(home, '.gemini'))),
|
|
287
|
+
configPath: paths.isAbsolute(geminiConfig) ? geminiConfig : null,
|
|
288
|
+
format: 'json',
|
|
289
|
+
});
|
|
271
290
|
return rows;
|
|
272
291
|
},
|
|
273
292
|
};
|
|
@@ -25,7 +25,7 @@ export interface ServiceSnapshot {
|
|
|
25
25
|
detail?: string;
|
|
26
26
|
}
|
|
27
27
|
export interface ClientDetection {
|
|
28
|
-
id: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop";
|
|
28
|
+
id: "claude-code" | "claude-desktop" | "codex-cli" | "codex-desktop" | "cursor" | "gemini";
|
|
29
29
|
installed: boolean;
|
|
30
30
|
configPath: string | null;
|
|
31
31
|
format: "json" | "toml";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@murmurv2/cli","private":true,"version":"2.
|
|
1
|
+
{"name":"@murmurv2/cli","private":true,"version":"2.14.0","type":"module","main":"dist/src/index.js","types":"dist/src/index.d.ts"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
|
+
import { readOwnerReview, persistOwnerReview } from "./owner-review-store.mjs";
|
|
2
3
|
import { buildChannelThreadStartBinding } from "@murmurv2/core";
|
|
3
4
|
import { execFile } from "node:child_process";
|
|
4
5
|
import { createHash } from "node:crypto";
|
|
@@ -18,6 +19,9 @@ export const NO_REPLY_REQUIRED = '[[MURMUR_NO_REPLY_REQUIRED]]';
|
|
|
18
19
|
const shellQuote = (value) => `'${String(value ?? "").replace(/'/g, "'\\''")}'`;
|
|
19
20
|
|
|
20
21
|
const buildReplyHint = (payload, peer = {}) => {
|
|
22
|
+
if (peer?.ownerReviewOnly === true) return ["", "[LOCAL OWNER REVIEW]",
|
|
23
|
+
"Prepare a source-bound working reply draft and any question that needs the owner. Your final answer is saved only in the local owner inbox; it is not sent to the peer. Do not use tools to send messages.",
|
|
24
|
+
`For an ACK/thanks/no-reply notice only, return exactly ${NO_REPLY_REQUIRED}. Do not use it for an unanswered question, failed task or missing access.`];
|
|
21
25
|
if (peer?.relayFinalToMurmur === true) {
|
|
22
26
|
return [
|
|
23
27
|
"",
|
|
@@ -572,6 +576,9 @@ const sendRelayReply = (peer = {}, payload = {}, finalText = "", { msgId } = {})
|
|
|
572
576
|
...process.env,
|
|
573
577
|
DATA_DIR: peer.dataDir,
|
|
574
578
|
MURMUR_STORE_PATH: peer.storePath,
|
|
579
|
+
// The relayed reply is Codex's: the envelope reports it (unsigned author hint).
|
|
580
|
+
MURMUR_AUTHOR_KIND: "assistant",
|
|
581
|
+
MURMUR_AUTHOR_APP: "codex",
|
|
575
582
|
},
|
|
576
583
|
timeout: 30000,
|
|
577
584
|
},
|
|
@@ -661,7 +668,11 @@ export const createCodexAppServerInjector = ({
|
|
|
661
668
|
const socketPath = peer?.socketPath || peer?.target;
|
|
662
669
|
if (!socketPath) throw new Error(`codex-app-server-socket-missing:${payload.from}`);
|
|
663
670
|
|
|
664
|
-
const
|
|
671
|
+
const reviewOnly = peer?.ownerReviewOnly === true;
|
|
672
|
+
const relayEnabled = !reviewOnly && peer?.relayFinalToMurmur === true;
|
|
673
|
+
if (reviewOnly && readOwnerReview(peer, payload)) {
|
|
674
|
+
return { finalText: null, replyMsgId: null, outcome: 'owner_review_required', source: 'owner-review-idempotent' };
|
|
675
|
+
}
|
|
665
676
|
const replyMsgId = relayEnabled ? deriveRelayReplyMsgId(payload.msgId) : null;
|
|
666
677
|
if (relayEnabled && (await relayAlreadyQueued(peer, replyMsgId))) {
|
|
667
678
|
// A previous attempt got as far as queueing the reply and then died before the
|
|
@@ -684,7 +695,7 @@ export const createCodexAppServerInjector = ({
|
|
|
684
695
|
const text = buildCodexTurnText(payload, peer);
|
|
685
696
|
const threadStartBinding = peer?.threadStartBinding ?? (resolveThreadStartBinding ? await resolveThreadStartBinding(payload, peer) : null);
|
|
686
697
|
const bindingMetadata = threadStartBinding?.metadata ?? {};
|
|
687
|
-
const shouldResumeThread = peer?.resume === true || (peer?.resume !== false &&
|
|
698
|
+
const shouldResumeThread = peer?.resume === true || (peer?.resume !== false && (relayEnabled || reviewOnly));
|
|
688
699
|
let threadPath = accepted?.sessionPath ?? null;
|
|
689
700
|
const resumeThread = async (threadId) => {
|
|
690
701
|
if (!threadId || peer?.resume === false) return;
|
|
@@ -715,7 +726,7 @@ export const createCodexAppServerInjector = ({
|
|
|
715
726
|
const startTurn = async (threadId) => {
|
|
716
727
|
// A configuration change must not turn an accepted receipt back into a
|
|
717
728
|
// fire-and-forget start. Observe it even if reply relay was disabled later.
|
|
718
|
-
if (relayEnabled || accepted) {
|
|
729
|
+
if (relayEnabled || reviewOnly || accepted) {
|
|
719
730
|
const result = await client.startTurnAndWaitForFinal(turnParams(threadId), {
|
|
720
731
|
completionTimeoutMs: Number(peer?.replyTimeoutMs) || DEFAULT_TURN_COMPLETION_TIMEOUT_MS,
|
|
721
732
|
sessionPath: threadPath,
|
|
@@ -754,7 +765,7 @@ export const createCodexAppServerInjector = ({
|
|
|
754
765
|
{ retryable: status === "failed" },
|
|
755
766
|
);
|
|
756
767
|
}
|
|
757
|
-
if (!relayEnabled) return result;
|
|
768
|
+
if (!relayEnabled && !reviewOnly) return result;
|
|
758
769
|
const finalText = String(result?.finalText || "").trim();
|
|
759
770
|
if (finalText === NO_REPLY_REQUIRED && result?.status !== 'completed') {
|
|
760
771
|
throw Object.assign(new Error('codex-app-server-no-reply-completion-unverified'), {retryable:false});
|
|
@@ -784,6 +795,14 @@ export const createCodexAppServerInjector = ({
|
|
|
784
795
|
{ retryable: false },
|
|
785
796
|
);
|
|
786
797
|
}
|
|
798
|
+
if (reviewOnly && result?.status !== "completed") throw Object.assign(new Error("owner-review-completion-unverified"), {retryable:false});
|
|
799
|
+
if (reviewOnly) {
|
|
800
|
+
// The operator sink runs outside the model sandbox and cannot send.
|
|
801
|
+
persistOwnerReview(peer, payload, finalText);
|
|
802
|
+
const receipt = await turns.get(payload.msgId);
|
|
803
|
+
if (receipt) await turns.set({ ...receipt, outcome: 'owner_review_required' });
|
|
804
|
+
return { ...result, finalText: null, replyMsgId: null, outcome: 'owner_review_required' };
|
|
805
|
+
}
|
|
787
806
|
const relayResult = await relay(peer, payload, finalText, { msgId: replyMsgId });
|
|
788
807
|
log("info", "Codex app-server wake final relayed", {
|
|
789
808
|
msgId: payload.msgId,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
stableEnvelopePayload,
|
|
16
16
|
resolveInstallation,
|
|
17
17
|
installationStorePath,
|
|
18
|
+
normalizeAuthor,
|
|
18
19
|
} from "@murmurv2/core";
|
|
19
20
|
import { decryptPayload, signEnvelope, verifyEnvelopeSignature } from "@murmurv2/security";
|
|
20
21
|
import { NotifyQueue, flushNotifyQueue, normalizeNotifyTargets, enqueuePeerNotification } from "./notify-router.mjs";
|
|
@@ -248,7 +249,7 @@ const wakeMonitor = new WakeMonitor({
|
|
|
248
249
|
...wakeConfig,
|
|
249
250
|
deliveries: msgStore,
|
|
250
251
|
leaseGate: nativeLeaseGate,
|
|
251
|
-
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, log }),
|
|
252
|
+
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, timeoutMs: wakeConfig.auditHookTimeoutMs, log }),
|
|
252
253
|
hook: createShellHook({ command: config.onReceive, timeoutMs: wakeConfig.hookTimeoutMs, log }),
|
|
253
254
|
injector: async (payload, peer) => {
|
|
254
255
|
if (peer.mode === "codex_app_server") {
|
|
@@ -263,7 +264,7 @@ const wakeMonitor = new WakeMonitor({
|
|
|
263
264
|
const proxyWakeMonitor = new WakeMonitor({
|
|
264
265
|
...wakeConfig,
|
|
265
266
|
initialCursor: inboundCursor(),
|
|
266
|
-
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, log }),
|
|
267
|
+
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, timeoutMs: wakeConfig.auditHookTimeoutMs, log }),
|
|
267
268
|
hook: createShellHook({ command: config.proxyOnReceive, timeoutMs: wakeConfig.hookTimeoutMs, log }),
|
|
268
269
|
leaseGate: nativeLeaseGate,
|
|
269
270
|
injector: async (payload, peer) => {
|
|
@@ -348,6 +349,8 @@ const onMessage = async (envelope) => {
|
|
|
348
349
|
senderMemberId: envelope.senderMemberId,
|
|
349
350
|
addresseeMemberId: envelope.addresseeMemberId,
|
|
350
351
|
wakeEligible,
|
|
352
|
+
// Sender-reported author, unsigned: stored with the row before the ACK; malformed -> unknown.
|
|
353
|
+
author: normalizeAuthor(envelope.author),
|
|
351
354
|
});
|
|
352
355
|
if (stored.duplicate) {
|
|
353
356
|
// Crash window "receiver committed, ACK lost": the sender (or JetStream) delivered
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { SQLiteDedupeOutboxStore, SQLiteMessageStore, stableEnvelopePayload, resolveMessageSubject, resolveInstallation, installationStorePath } from "@murmurv2/core";
|
|
8
|
+
import { SQLiteDedupeOutboxStore, SQLiteMessageStore, stableEnvelopePayload, resolveMessageSubject, resolveInstallation, installationStorePath, normalizeAuthor } from "@murmurv2/core";
|
|
9
9
|
import { encryptPayload, signEnvelope } from "@murmurv2/security";
|
|
10
10
|
import { readPrivateJson } from "./secure-state.mjs";
|
|
11
11
|
|
|
@@ -106,6 +106,9 @@ try {
|
|
|
106
106
|
signature: "",
|
|
107
107
|
...routing,
|
|
108
108
|
};
|
|
109
|
+
// The caller says how it sends (an automatic responder sets MURMUR_AUTHOR_KIND=auto); otherwise unknown.
|
|
110
|
+
const author = normalizeAuthor({ kind: process.env.MURMUR_AUTHOR_KIND, app: process.env.MURMUR_AUTHOR_APP ?? "shell" });
|
|
111
|
+
if (author) envelope.author = author;
|
|
109
112
|
envelope.signature = await signEnvelope(
|
|
110
113
|
stableEnvelopePayload(envelope),
|
|
111
114
|
cfg.keys.signing.privateKey,
|
|
@@ -130,6 +133,7 @@ try {
|
|
|
130
133
|
createdAt,
|
|
131
134
|
transport: "nats",
|
|
132
135
|
...routing,
|
|
136
|
+
author,
|
|
133
137
|
});
|
|
134
138
|
|
|
135
139
|
process.stdout.write(
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Local operator sink. A completed model turn is a draft, never permission to send it.
|
|
2
|
+
import { constants, closeSync, fsyncSync, fstatSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
5
|
+
|
|
6
|
+
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
7
|
+
const failure = () => Object.assign(new Error('owner-review-source-invalid'), { retryable: false });
|
|
8
|
+
|
|
9
|
+
function binding(peer, payload) {
|
|
10
|
+
if (!uuid.test(payload?.msgId ?? '') || !peer?.dataDir || !peer?.storePath
|
|
11
|
+
|| path.dirname(path.resolve(peer.storePath)) !== path.resolve(peer.dataDir)) throw failure();
|
|
12
|
+
const db = new DatabaseSync(peer.storePath, { readOnly: true });
|
|
13
|
+
try {
|
|
14
|
+
const row = db.prepare('SELECT sender, conversation_id, created_at FROM local_messages WHERE msg_id=? AND direction=\'inbound\'').get(payload.msgId);
|
|
15
|
+
if (!row || row.sender !== payload.from || row.conversation_id !== payload.conversationId) throw failure();
|
|
16
|
+
return { source_id: payload.msgId, peer: row.sender, conversation: row.conversation_id, source_date: row.created_at };
|
|
17
|
+
} finally { db.close(); }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function read(file) {
|
|
21
|
+
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
22
|
+
try {
|
|
23
|
+
const info = fstatSync(fd);
|
|
24
|
+
if (!info.isFile() || info.size > 131072 || (info.mode & 0o077) !== 0) throw failure();
|
|
25
|
+
return JSON.parse(readFileSync(fd, 'utf8'));
|
|
26
|
+
} finally { closeSync(fd); }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readOwnerReview(peer, payload) {
|
|
30
|
+
const source = binding(peer, payload);
|
|
31
|
+
let record;
|
|
32
|
+
try { record = read(path.join(peer.dataDir, `owner-inbox-${payload.msgId}.json`)); }
|
|
33
|
+
catch (err) { if (err.code === 'ENOENT') return null; throw err; }
|
|
34
|
+
if (record.schema !== 'murmur.owner-review/1' || record.privacy !== 'owner-only-local'
|
|
35
|
+
|| record.peer_send_authorized !== false || record.native_final_relay !== 'suppress'
|
|
36
|
+
|| Object.entries(source).some(([key, value]) => record.source?.[key] !== value)) throw failure();
|
|
37
|
+
return record;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function persistOwnerReview(peer, payload, draft) {
|
|
41
|
+
const source = binding(peer, payload);
|
|
42
|
+
if (typeof draft !== 'string' || !draft.trim() || Buffer.byteLength(draft) > 65536) throw failure();
|
|
43
|
+
const record = { schema: 'murmur.owner-review/1', privacy: 'owner-only-local', source,
|
|
44
|
+
status: 'awaiting_review', next_actor: 'owner', observed_at: new Date().toISOString(),
|
|
45
|
+
peer_reply_draft: draft, owner_decision: null, peer_send_authorized: false,
|
|
46
|
+
peer_delivery: null, native_final_relay: 'suppress' };
|
|
47
|
+
const file = path.join(peer.dataDir, `owner-inbox-${payload.msgId}.json`);
|
|
48
|
+
let fd;
|
|
49
|
+
try { fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600); }
|
|
50
|
+
catch (err) { if (err.code === 'EEXIST') return readOwnerReview(peer, payload); throw err; }
|
|
51
|
+
try { writeFileSync(fd, JSON.stringify(record) + '\n'); fsyncSync(fd); }
|
|
52
|
+
finally { closeSync(fd); }
|
|
53
|
+
return record;
|
|
54
|
+
}
|
|
@@ -17,6 +17,10 @@ export const normalizeWakeConfig = (config = {}) => {
|
|
|
17
17
|
if (!Number.isSafeInteger(hookTimeoutMs) || hookTimeoutMs < 1 || hookTimeoutMs > 2147483647) {
|
|
18
18
|
throw new Error("wake-hook-timeout-invalid");
|
|
19
19
|
}
|
|
20
|
+
const auditHookTimeoutMs = wake.auditHookTimeoutMs === undefined ? 10000 : wake.auditHookTimeoutMs;
|
|
21
|
+
if (!Number.isSafeInteger(auditHookTimeoutMs) || auditHookTimeoutMs < 1 || auditHookTimeoutMs > 2147483647) {
|
|
22
|
+
throw new Error("wake-audit-hook-timeout-invalid");
|
|
23
|
+
}
|
|
20
24
|
const peers = Object.fromEntries(
|
|
21
25
|
Object.entries(ensureObject(wake.peers)).map(([agentId, peer]) => {
|
|
22
26
|
const value = ensureObject(peer);
|
|
@@ -30,6 +34,7 @@ export const normalizeWakeConfig = (config = {}) => {
|
|
|
30
34
|
if (typeof value.murmurRoot === "string" && value.murmurRoot.trim()) normalized.murmurRoot = value.murmurRoot.trim();
|
|
31
35
|
if (typeof value.dataDir === "string" && value.dataDir.trim()) normalized.dataDir = value.dataDir.trim();
|
|
32
36
|
if (typeof value.storePath === "string" && value.storePath.trim()) normalized.storePath = value.storePath.trim();
|
|
37
|
+
if (value.ownerReviewOnly === true) normalized.ownerReviewOnly = true;
|
|
33
38
|
if (value.relayFinalToMurmur === true) normalized.relayFinalToMurmur = true;
|
|
34
39
|
// Without this the injector's `peer.resume === false` opt-out is unreachable
|
|
35
40
|
// from a real config: normalization used to drop the field entirely.
|
|
@@ -59,6 +64,7 @@ export const normalizeWakeConfig = (config = {}) => {
|
|
|
59
64
|
return {
|
|
60
65
|
enabled: wake.enabled !== false,
|
|
61
66
|
hookTimeoutMs,
|
|
67
|
+
auditHookTimeoutMs,
|
|
62
68
|
mode: validMode(wake.mode) ? wake.mode : "stateless",
|
|
63
69
|
peers,
|
|
64
70
|
auditHook: typeof wake.auditHook === "string" && wake.auditHook.trim() ? wake.auditHook.trim() : null,
|
|
@@ -129,12 +135,15 @@ export const createAuditShellHook = ({ command, timeoutMs = 10000, baseEnv = pro
|
|
|
129
135
|
};
|
|
130
136
|
execFile("sh", ["-c", command], { env, timeout: timeoutMs }, (err, stdout) => {
|
|
131
137
|
if (err) {
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
// execFile's message contains the command and captured output. A timeout
|
|
139
|
+
// means admission is unknown; retain durable work without running it.
|
|
140
|
+
const timedOut = err.killed === true && err.signal === "SIGTERM";
|
|
141
|
+
log("warn", "wake audit hook failed", { error: timedOut ? "audit-hook-timeout" : "audit-hook-failed", msgId: payload.msgId });
|
|
142
|
+
resolve(timedOut ? "retry" : "deny");
|
|
134
143
|
return;
|
|
135
144
|
}
|
|
136
145
|
const verdict = String(stdout || "").split(/\r?\n/, 1)[0]?.trim();
|
|
137
|
-
resolve(
|
|
146
|
+
resolve(["deny", "require_approval", "allow", "retry"].includes(verdict) ? verdict : "deny");
|
|
138
147
|
});
|
|
139
148
|
});
|
|
140
149
|
};
|
|
@@ -376,12 +385,24 @@ export class WakeMonitor {
|
|
|
376
385
|
}
|
|
377
386
|
|
|
378
387
|
this.seen.set(key, now);
|
|
379
|
-
if (!prepareOnly && await this.isLoopBreakerBlocked(payload, now)) {
|
|
380
|
-
await settle("muted", { error: "loop-breaker" });
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
388
|
const verdict = await this.audit(payload);
|
|
389
|
+
if (verdict === "retry") {
|
|
390
|
+
// Admission never reached an allow decision. Use the existing durable
|
|
391
|
+
// attempt/deadline fields; no turn, lease, or wake effect has happened.
|
|
392
|
+
const attempts = claim?.attempts ?? 1;
|
|
393
|
+
const retryable = durable && attempts < this.maxAttempts;
|
|
394
|
+
const delayMs = wakeRetryBackoffMs(attempts, this.retryBackoffMs, this.retryBackoffMaxMs);
|
|
395
|
+
await settle(retryable ? "failed" : "dlq", {
|
|
396
|
+
error: "audit-retry",
|
|
397
|
+
...(retryable ? { nextAttemptAt: new Date(this.now() + delayMs).toISOString() } : {}),
|
|
398
|
+
});
|
|
399
|
+
this.log("warn", "WakeMonitor audit admission deferred", {
|
|
400
|
+
msgId: payload.msgId, attempt: attempts, status: retryable ? "failed" : "dlq",
|
|
401
|
+
...(retryable ? { retryInMs: delayMs } : {}),
|
|
402
|
+
});
|
|
403
|
+
if (!retryable) await this.notify?.(payload, durable ? "wake-dlq" : "audit-retry-unavailable");
|
|
404
|
+
return prepareOnly ? { auditRetry: true } : undefined;
|
|
405
|
+
}
|
|
385
406
|
if (verdict === "deny") {
|
|
386
407
|
this.log("warn", "WakeMonitor audit denied wake", { msgId: payload.msgId, conversationId: payload.conversationId, from: payload.from });
|
|
387
408
|
await settle("muted", { error: "audit-deny" });
|
|
@@ -393,6 +414,10 @@ export class WakeMonitor {
|
|
|
393
414
|
await settle("muted", { error: "audit-require-approval" });
|
|
394
415
|
return;
|
|
395
416
|
}
|
|
417
|
+
if (!prepareOnly && await this.isLoopBreakerBlocked(payload, now)) {
|
|
418
|
+
await settle("muted", { error: "loop-breaker" });
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
396
421
|
|
|
397
422
|
// Scoped-channels lease gate (#82): the native daemon wake is a fallback owner.
|
|
398
423
|
// If a live chat session already owns this conversation, mute the native wake so it
|
|
@@ -525,9 +550,23 @@ export class WakeMonitor {
|
|
|
525
550
|
this.enqueuedAt.delete(this.keyFor(payload));
|
|
526
551
|
}
|
|
527
552
|
const ready = [];
|
|
553
|
+
const deferred = [];
|
|
528
554
|
for (const payload of payloads) {
|
|
529
555
|
const run = await this.processPayload(payload, { prepareOnly: true });
|
|
530
|
-
if (run) ready.push({ payload, run });
|
|
556
|
+
if (typeof run === "function") ready.push({ payload, run });
|
|
557
|
+
else if (run?.auditRetry) deferred.push(payload);
|
|
558
|
+
}
|
|
559
|
+
if (previousBatch && deferred.length && ready.length + deferred.length === payloads.length) {
|
|
560
|
+
// A saved batch is one effect. A temporarily unavailable member must not
|
|
561
|
+
// turn its already grouped siblings into permanent policy mutes.
|
|
562
|
+
const attempts = Math.max(...payloads.map((payload) => payload.attempt));
|
|
563
|
+
const retryable = attempts < this.maxAttempts;
|
|
564
|
+
const outcome = { status: retryable ? "failed" : "dlq", error: "audit-retry", now: this.nowIso(),
|
|
565
|
+
...(retryable ? { nextAttemptAt: new Date(this.now() + wakeRetryBackoffMs(attempts, this.retryBackoffMs, this.retryBackoffMaxMs)).toISOString() } : {}) };
|
|
566
|
+
await this.deliveries.settleWakeBatch(payloads.map((payload) => ({ msgId: payload.msgId, input: outcome })));
|
|
567
|
+
await this.advanceCursor(first);
|
|
568
|
+
if (!retryable) for (const { payload } of ready) await this.notify?.(payload, "wake-dlq");
|
|
569
|
+
return;
|
|
531
570
|
}
|
|
532
571
|
if (ready.length === 0) return;
|
|
533
572
|
if (previousBatch && ready.length !== payloads.length) {
|
|
@@ -620,7 +659,7 @@ export class WakeMonitor {
|
|
|
620
659
|
async audit(payload) {
|
|
621
660
|
if (!this.auditHook) return "allow";
|
|
622
661
|
const verdict = await this.auditHook(payload);
|
|
623
|
-
return
|
|
662
|
+
return ["allow", "require_approval", "deny", "retry"].includes(verdict) ? verdict : "deny";
|
|
624
663
|
}
|
|
625
664
|
|
|
626
665
|
async advanceCursor(payload) {
|