omni-notify-mcp 1.3.345 → 1.3.347
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.
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* commands — is on its own screen and nowhere else; a turn waiting on a question there is reported as waiting.
|
|
12
12
|
*/
|
|
13
13
|
import { randomBytes, randomUUID } from "crypto";
|
|
14
|
+
import { createServer } from "http";
|
|
14
15
|
import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync, watch } from "fs";
|
|
15
16
|
import { homedir } from "os";
|
|
16
17
|
import { dirname, join, resolve } from "path";
|
|
@@ -55,9 +56,11 @@ function folderTrusted(folder) {
|
|
|
55
56
|
}
|
|
56
57
|
const BN_REACHES_HIM_ON_THE_PAGE = "mcp__notify__notify,mcp__notify__ask,mcp__notify__reply,mcp__notify__wait_for_inbox";
|
|
57
58
|
/** The path under BN's door a session's hooks are posted to; the key after it names the session. */
|
|
58
|
-
|
|
59
|
+
const CLAUDE_HOOK_PATH = "/v1/claude-hooks/";
|
|
59
60
|
/** The hooks a session's CLI posts: a prompt taken, a tool about to run and one that ran, a notice to the person, a prompt ended, and a prompt that ended in an API failure. */
|
|
60
61
|
const HOOKED = ["UserPromptSubmit", "PreToolUse", "PostToolUse", "Notification", "Stop", "StopFailure"];
|
|
62
|
+
/** The socket addresses a request from this machine itself arrives on. */
|
|
63
|
+
const LOOPBACK = new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
|
|
61
64
|
/** The notices the CLI raises while it waits on the person's own answer on its screen: a permission question, or a question an MCP server asks. */
|
|
62
65
|
const ASKS_THE_PERSON = new Set(["permission_prompt", "elicitation_dialog"]);
|
|
63
66
|
/**
|
|
@@ -67,23 +70,47 @@ const ASKS_THE_PERSON = new Set(["permission_prompt", "elicitation_dialog"]);
|
|
|
67
70
|
* (measured on CLI 2.1.322: a bullseye-backlog handoff claimed a story and started a subagent in one).
|
|
68
71
|
*/
|
|
69
72
|
const FROM_ANOTHER_SESSION = /<cross-session-message[\s>]/;
|
|
70
|
-
/**
|
|
71
|
-
* Where a session's CLI reports its turns: BN's own door, once it is listening. The door binds before the driver boots
|
|
72
|
-
* (notify.ts `bindGatewayPort` then `startOwnedWork`), so every session is opened with a port to report to.
|
|
73
|
-
*/
|
|
74
73
|
const sessions = new Map();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
/** The loopback door the CLIs of this process report to: one per process, bound by the first session that needs it, so a daemon with no public gateway reports to the same door as one with it. */
|
|
75
|
+
let hookServer;
|
|
76
|
+
/** One hook a session's CLI posted, answered: the session's own answer, 404 when the key names no session of this process (it ended, or BN restarted past it), 400 on a body that is not JSON, 403 from anywhere but this machine. */
|
|
77
|
+
function hookAnswered(req, res) {
|
|
78
|
+
const send = (status, body) => { res.writeHead(status, { "content-type": "application/json" }); res.end(JSON.stringify(body)); };
|
|
79
|
+
const key = (req.url ?? "").startsWith(CLAUDE_HOOK_PATH) ? (req.url ?? "").slice(CLAUDE_HOOK_PATH.length) : undefined;
|
|
80
|
+
// NULL-OK: field remoteAddress is OPTIONAL and therefore it is ok to check for NULL
|
|
81
|
+
if (!LOOPBACK.has(req.socket.remoteAddress ?? ""))
|
|
82
|
+
return send(403, { error: "this is served only from the machine it runs on" });
|
|
83
|
+
// NULL-OK: field key is OPTIONAL and therefore it is ok to check for NULL
|
|
84
|
+
if (req.method !== "POST" || key === undefined)
|
|
85
|
+
return send(404, { error: "no agent CLI of this BN process reports at this path" });
|
|
86
|
+
const chunks = [];
|
|
87
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
88
|
+
req.on("end", () => {
|
|
89
|
+
let hook;
|
|
90
|
+
try {
|
|
91
|
+
hook = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (!(err instanceof SyntaxError))
|
|
95
|
+
throw err;
|
|
96
|
+
return send(400, { error: "body must be a JSON object" });
|
|
97
|
+
}
|
|
80
98
|
const session = sessions.get(key);
|
|
81
99
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
82
100
|
if (session === undefined)
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
101
|
+
return send(404, { error: "no agent CLI of this BN process reports at this path" });
|
|
102
|
+
send(200, session(hook));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** The port the loopback door listens on: the bind is synchronous, so a session opened this instant already has it. */
|
|
106
|
+
function hookPort() {
|
|
107
|
+
if (hookServer === undefined) {
|
|
108
|
+
hookServer = createServer(hookAnswered);
|
|
109
|
+
hookServer.listen(0);
|
|
110
|
+
hookServer.unref();
|
|
111
|
+
}
|
|
112
|
+
return hookServer.address().port;
|
|
113
|
+
}
|
|
87
114
|
/**
|
|
88
115
|
* Whether the CLI has written, in the complete lines past `turn.from`, the record it writes once a prompt is over — after
|
|
89
116
|
* every Stop hook let it end (measured on CLI 2.1.322: a Stop a hook refused is followed by `hook_blocking_error` and the
|
|
@@ -115,7 +142,7 @@ class ClaudeCliSession extends CliSession {
|
|
|
115
142
|
if (!folderTrusted(spec.project))
|
|
116
143
|
throw spec.failures.fail(`Claude Code has not been trusted in ${spec.project}, so its CLI would stop on "Do you trust this folder?" before reading any message — run claude in that folder once and answer "Yes, I trust this folder", then send the message again`);
|
|
117
144
|
super(spec, claudeProvider, spec.started || transcriptWritten(spec.sessionId));
|
|
118
|
-
const hook = [{ hooks: [{ type: "http", url: `http://127.0.0.1:${hookPort}${CLAUDE_HOOK_PATH}${this.key}` }] }];
|
|
145
|
+
const hook = [{ hooks: [{ type: "http", url: `http://127.0.0.1:${hookPort()}${CLAUDE_HOOK_PATH}${this.key}` }] }];
|
|
119
146
|
const settings = JSON.stringify({ hooks: Object.fromEntries(HOOKED.map((name) => [name, hook])) });
|
|
120
147
|
sessions.set(this.key, (event) => this.hook(event));
|
|
121
148
|
this.launch([
|
|
@@ -26,9 +26,9 @@ function running(pid) {
|
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
/** The person BN's door serves, who holds every conversation's CLI whichever provider runs it
|
|
29
|
+
/** The person BN's door serves, who holds every conversation's CLI whichever provider runs it. Loaded after the module graph is built: the door reads the config this module's importers are still defining, and it needs no gateway section — a daemon without one holds terminals for the same person. */
|
|
30
30
|
let holder;
|
|
31
|
-
|
|
31
|
+
void import("./passkeyDoor.js").then((door) => { holder = door.personId; });
|
|
32
32
|
export function terminalHolder() { return holder(); }
|
|
33
33
|
/**
|
|
34
34
|
* One interactive CLI on this machine, as a browser sees it (#3351): the CLI runs under a Node IPC worker so its pty
|
|
@@ -24,7 +24,9 @@ function invocation(command, args) {
|
|
|
24
24
|
const script = /"%dp0%[\\/]([^"\r\n]+\.m?js)"/i.exec(shim);
|
|
25
25
|
if (script)
|
|
26
26
|
return { command: process.execPath, args: [resolve(dirname(executable), script[1]), ...args] };
|
|
27
|
-
|
|
27
|
+
const binary = /"%dp0%[\\/]([^"\r\n]+\.exe)"/i.exec(shim);
|
|
28
|
+
if (binary)
|
|
29
|
+
return { command: resolve(dirname(executable), binary[1]), args };
|
|
28
30
|
}
|
|
29
31
|
return { command: executable, args };
|
|
30
32
|
}
|
package/dist/gateway/restDoor.js
CHANGED
|
@@ -14,10 +14,8 @@ import { CHAT_HEADERS } from "./chatPage.js";
|
|
|
14
14
|
import { isIconPath, serveIcon } from "./iconDoor.js";
|
|
15
15
|
import { handleMcp } from "./mcpDoor.js";
|
|
16
16
|
import { MCP_PATH, accessGranted, challenge, handleOAuth, isOAuthPath, publicBase } from "./oauthDoor.js";
|
|
17
|
-
import { bearer, bearerAdmitted, handlePasskey, isPasskeyPath, localOnly
|
|
18
|
-
import { CLAUDE_HOOK_PATH, claudeHooks } from "./claudeProvider.js";
|
|
17
|
+
import { bearer, bearerAdmitted, handlePasskey, isPasskeyPath, localOnly } from "./passkeyDoor.js";
|
|
19
18
|
import { terminalConsole, terminalRoute, terminalSockets } from "./terminalDoor.js";
|
|
20
|
-
import { holdTerminalsFor } from "./nativeTerminal.js";
|
|
21
19
|
import { conversationSwitchRead, panelState, saveConversationSwitch, saveSetting } from "./panel.js";
|
|
22
20
|
import { PANEL_PAGES, panelHtml } from "./panelPage.js";
|
|
23
21
|
import { wizard } from "./publicAccess.js";
|
|
@@ -177,21 +175,6 @@ async function route(req, url, arrivedAt) {
|
|
|
177
175
|
}
|
|
178
176
|
throw new GatewayError(405, "method not allowed here");
|
|
179
177
|
}
|
|
180
|
-
/**
|
|
181
|
-
* `POST /v1/claude-hooks/<key>`: a conversation's own Claude CLI reports its turns here (#3845) — from this machine only,
|
|
182
|
-
* at a path only that session knows — and the reply is the hook's answer to the CLI.
|
|
183
|
-
*/
|
|
184
|
-
async function claudeHookAnswered(req, res, url) {
|
|
185
|
-
if (req.method !== "POST" || !url.pathname.startsWith(CLAUDE_HOOK_PATH))
|
|
186
|
-
return false;
|
|
187
|
-
localOnly(req);
|
|
188
|
-
const answer = claudeHooks.deliver(url.pathname.slice(CLAUDE_HOOK_PATH.length), await readJson(req));
|
|
189
|
-
// NULL-OK: field answer is OPTIONAL and therefore it is ok to check for NULL
|
|
190
|
-
if (answer === undefined)
|
|
191
|
-
throw new GatewayError(404, "no agent CLI of this BN process reports at this path");
|
|
192
|
-
reply(res, 200, answer);
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
178
|
/** A request that failed, answered to its caller: a refusal with its status, anything else logged with its message and answered 500. */
|
|
196
179
|
function answerFailure(req, res, err) {
|
|
197
180
|
if (res.headersSent) {
|
|
@@ -254,8 +237,6 @@ export function startRestDoor(settings) {
|
|
|
254
237
|
workspaces.answer(req, res);
|
|
255
238
|
return;
|
|
256
239
|
}
|
|
257
|
-
if (await claudeHookAnswered(req, res, url))
|
|
258
|
-
return;
|
|
259
240
|
if ((url.pathname === "/settings" || url.pathname === "/public-access") && req.method === "GET") {
|
|
260
241
|
const page = panelHtml(url.pathname);
|
|
261
242
|
res.writeHead(200, { ...CHAT_HEADERS, "content-length": Buffer.byteLength(page) });
|
|
@@ -292,8 +273,6 @@ export function startRestDoor(settings) {
|
|
|
292
273
|
return new Promise((resolve, reject) => {
|
|
293
274
|
server.once("error", reject);
|
|
294
275
|
server.listen(settings.port, "0.0.0.0", () => {
|
|
295
|
-
claudeHooks.listening(server.address().port);
|
|
296
|
-
holdTerminalsFor(personId);
|
|
297
276
|
resolve(server);
|
|
298
277
|
});
|
|
299
278
|
});
|
package/dist/notify.js
CHANGED
|
@@ -1024,7 +1024,7 @@ function ingestDropFolder() {
|
|
|
1024
1024
|
if (!existsSync(INBOX_DROP_IN_DIR))
|
|
1025
1025
|
return;
|
|
1026
1026
|
mkdirSync(INBOX_DROP_CLAIM_DIR, { recursive: true });
|
|
1027
|
-
const
|
|
1027
|
+
const taken = [];
|
|
1028
1028
|
const unread = [];
|
|
1029
1029
|
for (const name of readdirSync(INBOX_DROP_IN_DIR).filter((f) => f.endsWith(".json"))) {
|
|
1030
1030
|
const path = join(INBOX_DROP_IN_DIR, name);
|
|
@@ -1032,6 +1032,7 @@ function ingestDropFolder() {
|
|
|
1032
1032
|
try {
|
|
1033
1033
|
if (!claimDrop(marker))
|
|
1034
1034
|
continue;
|
|
1035
|
+
let queued = false;
|
|
1035
1036
|
try {
|
|
1036
1037
|
let raw;
|
|
1037
1038
|
try {
|
|
@@ -1061,11 +1062,12 @@ function ingestDropFolder() {
|
|
|
1061
1062
|
rejectDrop(path, name, err instanceof Error ? err.message : String(err));
|
|
1062
1063
|
continue;
|
|
1063
1064
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1065
|
+
taken.push({ path, marker, entry });
|
|
1066
|
+
queued = true;
|
|
1066
1067
|
}
|
|
1067
1068
|
finally {
|
|
1068
|
-
|
|
1069
|
+
if (!queued)
|
|
1070
|
+
rmSync(marker, { force: true });
|
|
1069
1071
|
}
|
|
1070
1072
|
}
|
|
1071
1073
|
catch (err) {
|
|
@@ -1074,10 +1076,14 @@ function ingestDropFolder() {
|
|
|
1074
1076
|
}
|
|
1075
1077
|
}
|
|
1076
1078
|
retryUnreadDrops(unread);
|
|
1077
|
-
if (
|
|
1079
|
+
if (taken.length === 0)
|
|
1078
1080
|
return;
|
|
1079
|
-
persistInboxQueue(
|
|
1080
|
-
|
|
1081
|
+
persistInboxQueue(taken.map(({ entry }) => entry));
|
|
1082
|
+
for (const { path, marker } of taken) {
|
|
1083
|
+
unlinkSync(path);
|
|
1084
|
+
rmSync(marker, { force: true });
|
|
1085
|
+
}
|
|
1086
|
+
log("·", "inbox-drop", `queued ${taken.length} message${taken.length === 1 ? "" : "s"} from ${INBOX_DROP_IN_DIR}`);
|
|
1081
1087
|
syncInboxFromDisk();
|
|
1082
1088
|
}
|
|
1083
1089
|
function ingestInboxEntry(entry, source) {
|
|
@@ -361,6 +361,9 @@ export class SchedulerBeat {
|
|
|
361
361
|
// acted on, which is the SAFE direction. It is a subprocess guard, never a throttle on the kill decision, which has
|
|
362
362
|
// no clock at all.
|
|
363
363
|
const SAMPLE_TIMEOUT_MS = 15_000;
|
|
364
|
+
// GATE: how many answer bounds a table reader may owe one answer before it is stopped as hung — inside it the warm
|
|
365
|
+
// reader is kept and its late answer awaited; past it the reader is stopped and the next read starts a fresh one.
|
|
366
|
+
const READER_HUNG_BOUNDS = 4;
|
|
364
367
|
/** #3934 — the variable every lane's shell call is started with, naming the lane; a process inherits it from whatever started it, a detached one included. */
|
|
365
368
|
export const LANE_ENV = "BULLSEYE_LANE";
|
|
366
369
|
/**
|
|
@@ -691,13 +694,15 @@ export class ProcessTableUnreadable extends Error {
|
|
|
691
694
|
function throwProcessRead() {
|
|
692
695
|
throw new ProcessTableUnreadable("the process table could not be read");
|
|
693
696
|
}
|
|
694
|
-
class TableReader {
|
|
697
|
+
export class TableReader {
|
|
695
698
|
launch;
|
|
696
699
|
child;
|
|
697
700
|
queue = Promise.resolve();
|
|
698
701
|
phase = "open";
|
|
699
|
-
|
|
702
|
+
bound;
|
|
703
|
+
constructor(launch, bound = SAMPLE_TIMEOUT_MS) {
|
|
700
704
|
this.launch = launch;
|
|
705
|
+
this.bound = bound;
|
|
701
706
|
}
|
|
702
707
|
close() {
|
|
703
708
|
this.phase = "closed";
|
|
@@ -707,9 +712,28 @@ class TableReader {
|
|
|
707
712
|
}
|
|
708
713
|
}
|
|
709
714
|
read(request) {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
715
|
+
return new Promise((resolve, reject) => {
|
|
716
|
+
let phase = "queued";
|
|
717
|
+
const timer = setTimeout(() => {
|
|
718
|
+
reject(new ProcessTableUnreadable(phase === "sent"
|
|
719
|
+
? `the process table reader did not answer within ${this.bound / 1000} s — it is kept running, and its late answer is dropped`
|
|
720
|
+
: `the process table reader did not answer within ${this.bound / 1000} s — it was still answering an earlier read, so this one was never sent`));
|
|
721
|
+
phase = "abandoned";
|
|
722
|
+
}, this.bound);
|
|
723
|
+
this.queue = this.queue.then(() => {
|
|
724
|
+
if (phase === "abandoned") {
|
|
725
|
+
return undefined;
|
|
726
|
+
}
|
|
727
|
+
phase = "sent";
|
|
728
|
+
return Promise.resolve().then(() => this.ask(request)).then((out) => {
|
|
729
|
+
clearTimeout(timer);
|
|
730
|
+
resolve(out);
|
|
731
|
+
}, (err) => {
|
|
732
|
+
clearTimeout(timer);
|
|
733
|
+
reject(err);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
});
|
|
713
737
|
}
|
|
714
738
|
ask(request) {
|
|
715
739
|
if (this.phase === "closed") {
|
|
@@ -719,11 +743,11 @@ class TableReader {
|
|
|
719
743
|
return new Promise((resolve, reject) => {
|
|
720
744
|
let out = "";
|
|
721
745
|
const settle = () => {
|
|
722
|
-
clearTimeout(
|
|
746
|
+
clearTimeout(hung);
|
|
723
747
|
child.stdout.off("data", onData);
|
|
724
|
-
child.off("exit",
|
|
725
|
-
child.off("error",
|
|
726
|
-
child.stdin.off("error",
|
|
748
|
+
child.off("exit", onExit);
|
|
749
|
+
child.off("error", onSpawnError);
|
|
750
|
+
child.stdin.off("error", onPipeError);
|
|
727
751
|
};
|
|
728
752
|
const onData = (chunk) => {
|
|
729
753
|
out += chunk;
|
|
@@ -733,16 +757,29 @@ class TableReader {
|
|
|
733
757
|
resolve(out.slice(0, end));
|
|
734
758
|
}
|
|
735
759
|
};
|
|
736
|
-
const
|
|
760
|
+
const onExit = (code, signal) => {
|
|
761
|
+
settle();
|
|
762
|
+
reject(new ProcessTableUnreadable(`the process table reader exited before it answered (${signal ?? `exit code ${code}`})`));
|
|
763
|
+
};
|
|
764
|
+
const onSpawnError = (err) => {
|
|
737
765
|
settle();
|
|
738
766
|
this.stop(child);
|
|
739
|
-
reject(new ProcessTableUnreadable(
|
|
767
|
+
reject(new ProcessTableUnreadable(`the process table reader could not be started — ${err.message}`));
|
|
740
768
|
};
|
|
741
|
-
const
|
|
769
|
+
const onPipeError = (err) => {
|
|
770
|
+
settle();
|
|
771
|
+
this.stop(child);
|
|
772
|
+
reject(new ProcessTableUnreadable(`the request could not be written to the process table reader — ${err.message}`));
|
|
773
|
+
};
|
|
774
|
+
const hung = setTimeout(() => {
|
|
775
|
+
settle();
|
|
776
|
+
this.stop(child);
|
|
777
|
+
reject(new ProcessTableUnreadable(`the process table reader owed one answer for ${(this.bound * READER_HUNG_BOUNDS) / 1000} s and was stopped as hung`));
|
|
778
|
+
}, this.bound * READER_HUNG_BOUNDS);
|
|
742
779
|
child.stdout.on("data", onData);
|
|
743
|
-
child.once("exit",
|
|
744
|
-
child.once("error",
|
|
745
|
-
child.stdin.once("error",
|
|
780
|
+
child.once("exit", onExit);
|
|
781
|
+
child.once("error", onSpawnError);
|
|
782
|
+
child.stdin.once("error", onPipeError);
|
|
746
783
|
child.stdin.write(`${request}\n`);
|
|
747
784
|
});
|
|
748
785
|
}
|
|
@@ -785,9 +822,9 @@ export class LaneJobUnreadable extends Error {
|
|
|
785
822
|
why;
|
|
786
823
|
constructor(lane, why) {
|
|
787
824
|
super(`the kernel job of lane ${lane} could not be read — ${why}`);
|
|
825
|
+
this.name = "LaneJobUnreadable";
|
|
788
826
|
this.lane = lane;
|
|
789
827
|
this.why = why;
|
|
790
|
-
this.name = "LaneJobUnreadable";
|
|
791
828
|
}
|
|
792
829
|
}
|
|
793
830
|
/** The job name a lane is known by in every window — its id with every character the request line uses taken out. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.347",
|
|
4
4
|
"description": "Reach your AI agents from anywhere — and let them reach you. One resident process on 127.0.0.1:7475 serves the whole tool surface to Claude Code, GitHub Copilot Chat and Codex: desktop, Telegram, Slack, ntfy, Discord, Teams and SMS are configured in one file, and agents notify you when long work finishes or a decision is needed, ask you a question and wait for your answer, and receive and reply to the messages you send them — with Do Not Disturb and idle detection deciding what actually gets through.",
|
|
5
5
|
"main": "dist/daemon.js",
|
|
6
6
|
"type": "module",
|