@murmurv2/cli 2.12.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/README.md +65 -24
- package/package.json +7 -6
- package/runtime/bin/murmur-svc.exe +0 -0
- package/runtime/npm-runtime-manifest.json +175 -79
- 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 +3 -2
- 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/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.js +113 -10
- package/runtime/packages/setup/dist/src/clients.d.ts +33 -81
- package/runtime/packages/setup/dist/src/clients.js +159 -25
- package/runtime/packages/setup/dist/src/commands.d.ts +1 -0
- package/runtime/packages/setup/dist/src/commands.js +18 -6
- package/runtime/packages/setup/dist/src/config.d.ts +8 -0
- package/runtime/packages/setup/dist/src/config.js +58 -10
- package/runtime/packages/setup/dist/src/connect.d.ts +143 -0
- package/runtime/packages/setup/dist/src/connect.js +128 -0
- 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/doctor.d.ts +30 -0
- package/runtime/packages/setup/dist/src/doctor.js +72 -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/message-status.d.ts +1 -0
- package/runtime/packages/setup/dist/src/message-status.js +3 -0
- package/runtime/packages/setup/dist/src/onboarding.d.ts +11 -6
- package/runtime/packages/setup/dist/src/onboarding.js +92 -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 +247 -9
- package/runtime/packages/setup/dist/src/platform/linux.js +156 -12
- 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 +48 -8
- 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 +9 -0
- package/runtime/packages/setup/dist/src/status.js +7 -3
- package/runtime/packages/setup/dist/src/types.d.ts +11 -1
- 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 +36 -4
- package/runtime/scripts/daemon-contacts.mjs +1 -1
- package/runtime/scripts/murmur-auth-token.mjs +140 -0
- package/runtime/scripts/murmur-daemon.mjs +27 -8
- package/runtime/scripts/murmur-jetstream-advisory.mjs +27 -0
- package/runtime/scripts/murmur-shell-send.mjs +7 -3
- package/runtime/scripts/owner-review-store.mjs +54 -0
- package/runtime/scripts/wake-drain-claude.mjs +124 -7
- package/runtime/scripts/wake-monitor.mjs +49 -10
|
@@ -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";
|
|
@@ -13,16 +14,21 @@ const DEFAULT_TURN_COMPLETION_TIMEOUT_MS = 180000;
|
|
|
13
14
|
const DEFAULT_UNOBSERVABLE_TIMEOUT_MS = 300000;
|
|
14
15
|
const SESSION_LOG_POLL_INTERVAL_MS = 1000;
|
|
15
16
|
const SESSION_LOG_TAIL_BYTES = 8 * 1024 * 1024;
|
|
17
|
+
export const NO_REPLY_REQUIRED = '[[MURMUR_NO_REPLY_REQUIRED]]';
|
|
16
18
|
|
|
17
19
|
const shellQuote = (value) => `'${String(value ?? "").replace(/'/g, "'\\''")}'`;
|
|
18
20
|
|
|
19
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.`];
|
|
20
25
|
if (peer?.relayFinalToMurmur === true) {
|
|
21
26
|
return [
|
|
22
27
|
"",
|
|
23
28
|
"[MURMUR REPLY RELAY]",
|
|
24
29
|
"If this Murmur message asks for a reply, put only the reply body in your final answer.",
|
|
25
30
|
"Do not call tools to send Murmur yourself; the local daemon will relay your final answer back through Murmur.",
|
|
31
|
+
`If the message requires no substantive reply under the existing owner instructions (for example ACK, thanks, or an explicit no-reply notice), return exactly ${NO_REPLY_REQUIRED} as your final answer. This is a local completion receipt and is never sent to the peer. Do not use it for an unanswered question, missing access, or a failed task.`,
|
|
26
32
|
];
|
|
27
33
|
}
|
|
28
34
|
|
|
@@ -570,6 +576,9 @@ const sendRelayReply = (peer = {}, payload = {}, finalText = "", { msgId } = {})
|
|
|
570
576
|
...process.env,
|
|
571
577
|
DATA_DIR: peer.dataDir,
|
|
572
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",
|
|
573
582
|
},
|
|
574
583
|
timeout: 30000,
|
|
575
584
|
},
|
|
@@ -659,7 +668,11 @@ export const createCodexAppServerInjector = ({
|
|
|
659
668
|
const socketPath = peer?.socketPath || peer?.target;
|
|
660
669
|
if (!socketPath) throw new Error(`codex-app-server-socket-missing:${payload.from}`);
|
|
661
670
|
|
|
662
|
-
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
|
+
}
|
|
663
676
|
const replyMsgId = relayEnabled ? deriveRelayReplyMsgId(payload.msgId) : null;
|
|
664
677
|
if (relayEnabled && (await relayAlreadyQueued(peer, replyMsgId))) {
|
|
665
678
|
// A previous attempt got as far as queueing the reply and then died before the
|
|
@@ -682,7 +695,7 @@ export const createCodexAppServerInjector = ({
|
|
|
682
695
|
const text = buildCodexTurnText(payload, peer);
|
|
683
696
|
const threadStartBinding = peer?.threadStartBinding ?? (resolveThreadStartBinding ? await resolveThreadStartBinding(payload, peer) : null);
|
|
684
697
|
const bindingMetadata = threadStartBinding?.metadata ?? {};
|
|
685
|
-
const shouldResumeThread = peer?.resume === true || (peer?.resume !== false &&
|
|
698
|
+
const shouldResumeThread = peer?.resume === true || (peer?.resume !== false && (relayEnabled || reviewOnly));
|
|
686
699
|
let threadPath = accepted?.sessionPath ?? null;
|
|
687
700
|
const resumeThread = async (threadId) => {
|
|
688
701
|
if (!threadId || peer?.resume === false) return;
|
|
@@ -713,7 +726,7 @@ export const createCodexAppServerInjector = ({
|
|
|
713
726
|
const startTurn = async (threadId) => {
|
|
714
727
|
// A configuration change must not turn an accepted receipt back into a
|
|
715
728
|
// fire-and-forget start. Observe it even if reply relay was disabled later.
|
|
716
|
-
if (relayEnabled || accepted) {
|
|
729
|
+
if (relayEnabled || reviewOnly || accepted) {
|
|
717
730
|
const result = await client.startTurnAndWaitForFinal(turnParams(threadId), {
|
|
718
731
|
completionTimeoutMs: Number(peer?.replyTimeoutMs) || DEFAULT_TURN_COMPLETION_TIMEOUT_MS,
|
|
719
732
|
sessionPath: threadPath,
|
|
@@ -752,8 +765,19 @@ export const createCodexAppServerInjector = ({
|
|
|
752
765
|
{ retryable: status === "failed" },
|
|
753
766
|
);
|
|
754
767
|
}
|
|
755
|
-
if (!relayEnabled) return result;
|
|
768
|
+
if (!relayEnabled && !reviewOnly) return result;
|
|
756
769
|
const finalText = String(result?.finalText || "").trim();
|
|
770
|
+
if (finalText === NO_REPLY_REQUIRED && result?.status !== 'completed') {
|
|
771
|
+
throw Object.assign(new Error('codex-app-server-no-reply-completion-unverified'), {retryable:false});
|
|
772
|
+
}
|
|
773
|
+
if (finalText === NO_REPLY_REQUIRED) {
|
|
774
|
+
const receipt = await turns.get(payload.msgId);
|
|
775
|
+
if (receipt) await turns.set({...receipt, outcome:'no_reply_required'});
|
|
776
|
+
log('info', 'Codex app-server wake completed without a reply by explicit decision', {
|
|
777
|
+
msgId: payload.msgId, threadId, turnId: result.turnId, source: result.source,
|
|
778
|
+
});
|
|
779
|
+
return { ...result, finalText: null, replyMsgId: null, outcome: 'no_reply_required' };
|
|
780
|
+
}
|
|
757
781
|
if (!finalText) {
|
|
758
782
|
// #106 — the turn ended and there is nothing to relay. That is not a relay;
|
|
759
783
|
// logging it as one is how the peer waited six hours believing it was answered.
|
|
@@ -771,6 +795,14 @@ export const createCodexAppServerInjector = ({
|
|
|
771
795
|
{ retryable: false },
|
|
772
796
|
);
|
|
773
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
|
+
}
|
|
774
806
|
const relayResult = await relay(peer, payload, finalText, { msgId: replyMsgId });
|
|
775
807
|
log("info", "Codex app-server wake final relayed", {
|
|
776
808
|
msgId: payload.msgId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentConfigCache } from '
|
|
1
|
+
import { AgentConfigCache } from '@murmurv2/mcp-server/dist/src/agent-config.js';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
3
|
|
|
4
4
|
const key = value => typeof value === 'string' && Buffer.from(value, 'base64').length === 32
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* murmur-auth-token.mjs — Mint and verify roster-backed MURMUR-AUTH bearer tokens.
|
|
4
|
+
* Private keys are read only from 0600 files; never pass private keys on argv.
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import {
|
|
10
|
+
decodeAuthToken,
|
|
11
|
+
encodeAuthToken,
|
|
12
|
+
formatAddress,
|
|
13
|
+
parseAddress,
|
|
14
|
+
signAuthToken,
|
|
15
|
+
verifyAuthToken,
|
|
16
|
+
} from "@murmurv2/federation";
|
|
17
|
+
import { readPrivateJson } from "./secure-state.mjs";
|
|
18
|
+
import { loadRosterStoreFromBundle } from "./auth-security.mjs";
|
|
19
|
+
|
|
20
|
+
const HERE = fileURLToPath(import.meta.url);
|
|
21
|
+
|
|
22
|
+
function parseArgs(argv) {
|
|
23
|
+
const [subcommand, ...rest] = argv;
|
|
24
|
+
const opts = {};
|
|
25
|
+
for (let i = 0; i < rest.length; i++) {
|
|
26
|
+
const arg = rest[i];
|
|
27
|
+
if (!arg.startsWith("--")) throw new Error(`Unexpected argument: ${arg}`);
|
|
28
|
+
const key = arg.slice(2);
|
|
29
|
+
if (key === "token-stdin") {
|
|
30
|
+
opts.tokenStdin = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const val = rest[++i];
|
|
34
|
+
if (!val || val.startsWith("--")) throw new Error(`Missing value for --${key}`);
|
|
35
|
+
opts[key] = val;
|
|
36
|
+
}
|
|
37
|
+
return { subcommand, opts };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function runAuthTokenCli(argv, stdinText = null) {
|
|
41
|
+
const { subcommand, opts } = parseArgs(argv);
|
|
42
|
+
if (subcommand === "mint") {
|
|
43
|
+
for (const req of ["issuer", "subject", "audience", "signing-key-file"]) {
|
|
44
|
+
if (!opts[req]) throw new Error(`Missing --${req}`);
|
|
45
|
+
}
|
|
46
|
+
const ttlSec = opts["ttl-seconds"] ? Number(opts["ttl-seconds"]) : 3600;
|
|
47
|
+
if (!Number.isInteger(ttlSec) || ttlSec <= 0 || ttlSec > 365 * 86400) {
|
|
48
|
+
throw new Error("Invalid --ttl-seconds");
|
|
49
|
+
}
|
|
50
|
+
const scopes = (opts.scopes ?? "murmur:send").split(",").map((s) => s.trim()).filter(Boolean);
|
|
51
|
+
const keyMaterial = await readPrivateJson(path.resolve(opts["signing-key-file"]));
|
|
52
|
+
const signingPrivateKey = keyMaterial?.signingPrivateKey ?? keyMaterial?.keys?.signing?.privateKey;
|
|
53
|
+
if (typeof signingPrivateKey !== "string" || signingPrivateKey.length === 0) {
|
|
54
|
+
throw new Error("signing-key-file missing signingPrivateKey");
|
|
55
|
+
}
|
|
56
|
+
const nowMs = opts.now ? Date.parse(opts.now) : Date.now();
|
|
57
|
+
if (!Number.isFinite(nowMs)) throw new Error("Invalid --now");
|
|
58
|
+
const localOrg = opts["local-org"] ?? "local";
|
|
59
|
+
const issuedAt = new Date(nowMs).toISOString();
|
|
60
|
+
const expiresAt = new Date(nowMs + ttlSec * 1000).toISOString();
|
|
61
|
+
const signed = await signAuthToken(
|
|
62
|
+
{
|
|
63
|
+
issuer: parseAddress(opts.issuer, localOrg),
|
|
64
|
+
subject: parseAddress(opts.subject, localOrg),
|
|
65
|
+
audience: parseAddress(opts.audience, localOrg),
|
|
66
|
+
scopes,
|
|
67
|
+
issuedAt,
|
|
68
|
+
expiresAt,
|
|
69
|
+
...(opts.nonce ? { nonce: opts.nonce } : {}),
|
|
70
|
+
},
|
|
71
|
+
signingPrivateKey,
|
|
72
|
+
);
|
|
73
|
+
const token = encodeAuthToken(signed);
|
|
74
|
+
return {
|
|
75
|
+
exitCode: 0,
|
|
76
|
+
output: {
|
|
77
|
+
ok: true,
|
|
78
|
+
issuer: formatAddress(signed.issuer),
|
|
79
|
+
subject: formatAddress(signed.subject),
|
|
80
|
+
audience: formatAddress(signed.audience),
|
|
81
|
+
scopes: signed.scopes,
|
|
82
|
+
issuedAt: signed.issuedAt,
|
|
83
|
+
expiresAt: signed.expiresAt,
|
|
84
|
+
token,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (subcommand === "verify") {
|
|
90
|
+
if (!opts["roster-file"]) throw new Error("Missing --roster-file");
|
|
91
|
+
const rawToken = (opts["token-file"]
|
|
92
|
+
? fs.readFileSync(path.resolve(opts["token-file"]), "utf8")
|
|
93
|
+
: opts.tokenStdin
|
|
94
|
+
? (stdinText ?? fs.readFileSync(0, "utf8"))
|
|
95
|
+
: "").trim();
|
|
96
|
+
if (!rawToken) throw new Error("Supply --token-stdin or --token-file");
|
|
97
|
+
const rosters = await loadRosterStoreFromBundle(path.resolve(opts["roster-file"]));
|
|
98
|
+
let decoded;
|
|
99
|
+
try {
|
|
100
|
+
decoded = decodeAuthToken(rawToken);
|
|
101
|
+
} catch {
|
|
102
|
+
return { exitCode: 1, output: { accepted: false, reason: "malformed" } };
|
|
103
|
+
}
|
|
104
|
+
const localOrg = opts["local-org"] ?? "local";
|
|
105
|
+
const scopes = opts.scopes ? opts.scopes.split(",").map((s) => s.trim()).filter(Boolean) : undefined;
|
|
106
|
+
const verdict = await verifyAuthToken(decoded, rosters, {
|
|
107
|
+
...(opts.audience ? { audience: parseAddress(opts.audience, localOrg) } : {}),
|
|
108
|
+
...(opts.subject ? { requiredSubject: parseAddress(opts.subject, localOrg) } : {}),
|
|
109
|
+
...(scopes ? { requiredScopes: scopes } : {}),
|
|
110
|
+
...(opts.now ? { now: opts.now } : {}),
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
exitCode: verdict.accepted ? 0 : 1,
|
|
114
|
+
output: verdict.accepted
|
|
115
|
+
? {
|
|
116
|
+
accepted: true,
|
|
117
|
+
issuer: formatAddress(decoded.issuer),
|
|
118
|
+
subject: formatAddress(decoded.subject),
|
|
119
|
+
audience: formatAddress(decoded.audience),
|
|
120
|
+
scopes: decoded.scopes,
|
|
121
|
+
expiresAt: decoded.expiresAt,
|
|
122
|
+
}
|
|
123
|
+
: verdict,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
throw new Error("Usage: node scripts/murmur-auth-token.mjs <mint|verify> [options]");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === HERE) {
|
|
131
|
+
runAuthTokenCli(process.argv.slice(2))
|
|
132
|
+
.then(({ exitCode, output }) => {
|
|
133
|
+
console.log(JSON.stringify(output));
|
|
134
|
+
process.exitCode = exitCode;
|
|
135
|
+
})
|
|
136
|
+
.catch((err) => {
|
|
137
|
+
console.error(JSON.stringify({ ok: false, error: err.message }));
|
|
138
|
+
process.exitCode = 1;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
SQLiteMessageStore,
|
|
14
14
|
stableAckPayload,
|
|
15
15
|
stableEnvelopePayload,
|
|
16
|
+
resolveInstallation,
|
|
17
|
+
installationStorePath,
|
|
18
|
+
normalizeAuthor,
|
|
16
19
|
} from "@murmurv2/core";
|
|
17
20
|
import { decryptPayload, signEnvelope, verifyEnvelopeSignature } from "@murmurv2/security";
|
|
18
21
|
import { NotifyQueue, flushNotifyQueue, normalizeNotifyTargets, enqueuePeerNotification } from "./notify-router.mjs";
|
|
@@ -26,6 +29,7 @@ import { flushTick } from "./daemon-flush-tick.mjs";
|
|
|
26
29
|
import { createDaemonObservation } from "./daemon-observation.mjs";
|
|
27
30
|
import { createLinkWatch } from "./daemon-link-watch.mjs";
|
|
28
31
|
import { normalizeAckSecurity } from "./ack-security.mjs";
|
|
32
|
+
import { createDaemonInboundAuthorizer } from "./auth-security.mjs";
|
|
29
33
|
import { classifyVerifiedDoctorMessage, createDoctorResponder } from "./doctor-protocol.mjs";
|
|
30
34
|
// vault-guard: optional content policy hook (not included in OSS release)
|
|
31
35
|
|
|
@@ -38,7 +42,10 @@ const log = (level, msg, data) => {
|
|
|
38
42
|
observeLog(level, msg, data);
|
|
39
43
|
};
|
|
40
44
|
|
|
41
|
-
const dataDir = process.env
|
|
45
|
+
const { dataDir } = resolveInstallation({ env: process.env, requireConfig: true });
|
|
46
|
+
// Hooks inherit this process's pinned choice even if a person later selects another installation.
|
|
47
|
+
process.env.DATA_DIR = dataDir;
|
|
48
|
+
process.env.MURMUR_DATA_DIR = dataDir;
|
|
42
49
|
const configPath = path.join(dataDir, "agent-config.json");
|
|
43
50
|
|
|
44
51
|
let config;
|
|
@@ -53,8 +60,12 @@ try {
|
|
|
53
60
|
process.exit(1);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
const { agentId, natsUrl, natsToken, subject, keys } = config;
|
|
57
|
-
const dbPath =
|
|
63
|
+
const { agentId, natsUrl, natsToken, natsUser, natsPassword, natsTls, subject, keys } = config;
|
|
64
|
+
const dbPath = installationStorePath(dataDir, 'murmur.db', process.env.MURMUR_STORE_PATH);
|
|
65
|
+
// Refuse conflicting installation paths before any SQLite store is opened.
|
|
66
|
+
const channelRosterConfig = config.channelRoster || {};
|
|
67
|
+
const channelRosterEnabled = channelRosterConfig.enabled ?? process.env.MURMUR_CHANNEL_ROSTER === "1";
|
|
68
|
+
const channelRosterPath = channelRosterConfig.path || installationStorePath(dataDir, 'channel-roster.db', process.env.MURMUR_CHANNEL_ROSTER_PATH);
|
|
58
69
|
const flushIntervalMs = Number(process.env.FLUSH_INTERVAL_MS) || 2000;
|
|
59
70
|
const jetstreamConfig = config.jetstream || {};
|
|
60
71
|
const jetstreamEnabled = jetstreamConfig.enabled ?? process.env.MURMUR_JETSTREAM === "1";
|
|
@@ -85,6 +96,7 @@ const ackSecurityConfig = config.ackSecurity || {};
|
|
|
85
96
|
const ackPolicy = normalizeAckSecurity(config, process.env, log);
|
|
86
97
|
const emitSignedAcks = ackPolicy.emitSigned;
|
|
87
98
|
const requireSignedAcks = ackPolicy.requireSigned;
|
|
99
|
+
const authPolicy = await createDaemonInboundAuthorizer({ config, env: process.env, dataDir, log });
|
|
88
100
|
const maxAckAgeMs = optionalPositiveInteger(
|
|
89
101
|
"ack-max-age-ms",
|
|
90
102
|
firstDefined(ackSecurityConfig.maxAgeMs, process.env.MURMUR_ACK_MAX_AGE_MS),
|
|
@@ -130,6 +142,7 @@ log("info", "Daemon starting", {
|
|
|
130
142
|
...ackPolicy,
|
|
131
143
|
maxAgeMs: maxAckAgeMs,
|
|
132
144
|
},
|
|
145
|
+
authz: authPolicy.summary,
|
|
133
146
|
ackWindow,
|
|
134
147
|
wake: { enabled: wakeConfig.enabled, mode: wakeConfig.mode, hookConfigured: Boolean(config.onReceive) },
|
|
135
148
|
notifyTargets: effectiveNotifyTargets.map((t) => `${t.type}:${t.channel}`),
|
|
@@ -155,9 +168,6 @@ const nativeLeaseGate = leaseStore
|
|
|
155
168
|
: null;
|
|
156
169
|
if (scopedChannelsEnabled) log("info", "Scoped-channels native lease gate enabled", { ttlMs: nativeLeaseTtlMs });
|
|
157
170
|
|
|
158
|
-
const channelRosterConfig = config.channelRoster || {};
|
|
159
|
-
const channelRosterEnabled = channelRosterConfig.enabled ?? process.env.MURMUR_CHANNEL_ROSTER === "1";
|
|
160
|
-
const channelRosterPath = channelRosterConfig.path || process.env.MURMUR_CHANNEL_ROSTER_PATH || path.join(dataDir, "channel-roster.db");
|
|
161
171
|
const channelRosterStore = channelRosterEnabled ? new ChannelRosterStore(channelRosterPath) : null;
|
|
162
172
|
const subjectRoutes = channelSubjectRoutes(subject, agentId, config.subjectScoping);
|
|
163
173
|
if (subjectRoutes.length > 1) {
|
|
@@ -198,7 +208,11 @@ const broker = new NatsBroker({
|
|
|
198
208
|
connectBaseBackoffMs: 2000,
|
|
199
209
|
url: natsUrl,
|
|
200
210
|
token: natsToken,
|
|
211
|
+
user: natsUser,
|
|
212
|
+
password: natsPassword,
|
|
213
|
+
tls: natsTls,
|
|
201
214
|
jetstream: jetstreamEnabled,
|
|
215
|
+
jetstreamProvisioning: jetstreamConfig.provisioning,
|
|
202
216
|
stream: jetstreamEnabled ? jetstreamStream : undefined,
|
|
203
217
|
streamSubjects: jetstreamSubjects,
|
|
204
218
|
jetstreamMaxDeliver,
|
|
@@ -235,7 +249,7 @@ const wakeMonitor = new WakeMonitor({
|
|
|
235
249
|
...wakeConfig,
|
|
236
250
|
deliveries: msgStore,
|
|
237
251
|
leaseGate: nativeLeaseGate,
|
|
238
|
-
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, log }),
|
|
252
|
+
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, timeoutMs: wakeConfig.auditHookTimeoutMs, log }),
|
|
239
253
|
hook: createShellHook({ command: config.onReceive, timeoutMs: wakeConfig.hookTimeoutMs, log }),
|
|
240
254
|
injector: async (payload, peer) => {
|
|
241
255
|
if (peer.mode === "codex_app_server") {
|
|
@@ -250,7 +264,7 @@ const wakeMonitor = new WakeMonitor({
|
|
|
250
264
|
const proxyWakeMonitor = new WakeMonitor({
|
|
251
265
|
...wakeConfig,
|
|
252
266
|
initialCursor: inboundCursor(),
|
|
253
|
-
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, log }),
|
|
267
|
+
auditHook: createAuditShellHook({ command: wakeConfig.auditHook, timeoutMs: wakeConfig.auditHookTimeoutMs, log }),
|
|
254
268
|
hook: createShellHook({ command: config.proxyOnReceive, timeoutMs: wakeConfig.hookTimeoutMs, log }),
|
|
255
269
|
leaseGate: nativeLeaseGate,
|
|
256
270
|
injector: async (payload, peer) => {
|
|
@@ -335,6 +349,8 @@ const onMessage = async (envelope) => {
|
|
|
335
349
|
senderMemberId: envelope.senderMemberId,
|
|
336
350
|
addresseeMemberId: envelope.addresseeMemberId,
|
|
337
351
|
wakeEligible,
|
|
352
|
+
// Sender-reported author, unsigned: stored with the row before the ACK; malformed -> unknown.
|
|
353
|
+
author: normalizeAuthor(envelope.author),
|
|
338
354
|
});
|
|
339
355
|
if (stored.duplicate) {
|
|
340
356
|
// Crash window "receiver committed, ACK lost": the sender (or JetStream) delivered
|
|
@@ -448,6 +464,7 @@ try {
|
|
|
448
464
|
consumerId: agentId,
|
|
449
465
|
dedupe: store,
|
|
450
466
|
onMessage,
|
|
467
|
+
...(authPolicy.authorize ? { authorize: authPolicy.authorize } : {}),
|
|
451
468
|
...(emitSignedAcks ? { signAck } : {}),
|
|
452
469
|
});
|
|
453
470
|
log("info", "Subscribed", route);
|
|
@@ -531,6 +548,8 @@ try {
|
|
|
531
548
|
broker,
|
|
532
549
|
outbox: store,
|
|
533
550
|
jetstreamEnabled,
|
|
551
|
+
advisoryDlq: jetstreamConfig.advisoryDlq,
|
|
552
|
+
provisioning: jetstreamConfig.provisioning,
|
|
534
553
|
log,
|
|
535
554
|
});
|
|
536
555
|
|
|
@@ -1,10 +1,37 @@
|
|
|
1
|
+
// Advisory DLQ correlation subscribes to broker-wide `$JS.EVENT.ADVISORY.*` subjects and
|
|
2
|
+
// reads the dead message back with STREAM.MSG.GET. A restricted runtime role
|
|
3
|
+
// (`jetstream.provisioning: "client"`, see docs/nats-transport-security.md) has neither
|
|
4
|
+
// permission by design, so for that role the feature is off unless the operator turns it
|
|
5
|
+
// on explicitly with `jetstream.advisoryDlq: true` after granting those subjects.
|
|
6
|
+
export function resolveAdvisoryDlqEnabled({ advisoryDlq, provisioning } = {}) {
|
|
7
|
+
if (advisoryDlq === true) return { enabled: true, reason: "explicit" };
|
|
8
|
+
if (advisoryDlq === false) return { enabled: false, reason: "explicit" };
|
|
9
|
+
if (provisioning === "client") return { enabled: false, reason: "client-provisioning" };
|
|
10
|
+
return { enabled: true, reason: "default" };
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
export async function startJetStreamAdvisoryDlqIfEnabled({
|
|
2
14
|
broker,
|
|
3
15
|
outbox,
|
|
4
16
|
jetstreamEnabled,
|
|
17
|
+
advisoryDlqEnabled,
|
|
18
|
+
advisoryDlq,
|
|
19
|
+
provisioning,
|
|
5
20
|
log = () => {},
|
|
6
21
|
}) {
|
|
7
22
|
if (!jetstreamEnabled) return undefined;
|
|
23
|
+
const decision =
|
|
24
|
+
advisoryDlqEnabled === undefined
|
|
25
|
+
? resolveAdvisoryDlqEnabled({ advisoryDlq, provisioning })
|
|
26
|
+
: { enabled: Boolean(advisoryDlqEnabled), reason: "explicit" };
|
|
27
|
+
if (!decision.enabled) {
|
|
28
|
+
if (decision.reason === "client-provisioning") {
|
|
29
|
+
log("info", "JetStream advisory DLQ correlation disabled for client provisioning", {
|
|
30
|
+
hint: 'set jetstream.advisoryDlq: true after granting $JS.EVENT.ADVISORY.> and STREAM.MSG.GET to this role',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
8
35
|
const subscription = await broker.startJetStreamAdvisoryDlq({ outbox });
|
|
9
36
|
log("info", "JetStream advisory DLQ correlation started");
|
|
10
37
|
return subscription;
|
|
@@ -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 } 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
|
|
|
@@ -51,9 +51,9 @@ if (!text) {
|
|
|
51
51
|
process.exit(1);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const dataDir = process.env
|
|
54
|
+
const { dataDir } = resolveInstallation({ env: process.env, requireConfig: true });
|
|
55
55
|
const configPath = path.join(dataDir, "agent-config.json");
|
|
56
|
-
const dbPath =
|
|
56
|
+
const dbPath = installationStorePath(dataDir, 'murmur.db', process.env.MURMUR_STORE_PATH);
|
|
57
57
|
|
|
58
58
|
let cfg;
|
|
59
59
|
try {
|
|
@@ -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
|
+
}
|