omni-notify-mcp 1.3.495 → 1.3.497

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.
@@ -24,12 +24,17 @@ const COMMAND_RE = /^\/?(new|stop)(@\w+)?$/i;
24
24
  const FINAL_KINDS = new Set(["answer", "failed", "stopped", "archived", "deleted"]);
25
25
  // GATE: the port AgenticBullseye serves on (#4196 Section 9); NOTIFY_AGENT_CLUSTER_URL names another ONLY under the test gate, so a suite drives the real carriage on a cluster it owns, and without the gate no environment can redirect it.
26
26
  const CLUSTER_URL = "http://127.0.0.1:7481";
27
+ let residentCluster;
28
+ /** The daemon publishes its own door only while it owns the runtime listener. */
29
+ export function setResidentCluster(resolve) {
30
+ residentCluster = resolve;
31
+ }
27
32
  // GATE: a refused connection to AB is tried five times, waiting 0.5, 1, 2 and 4 s — the bound AB's own call into BN takes (AgenticBullseye wire.ts BN_CALL_TRIES) — then AB is unreachable.
28
33
  const CLUSTER_CALL_TRIES = 5;
29
34
  const CLUSTER_FIRST_WAIT_MS = 500;
30
35
  /** AgenticBullseye's base URL: the one this machine runs, or the stand-in a suite names under the test gate. */
31
36
  export function clusterBase() {
32
- return process.env.NOTIFY_MCP_TEST_ENDPOINTS === "1" && process.env.NOTIFY_AGENT_CLUSTER_URL ? process.env.NOTIFY_AGENT_CLUSTER_URL.replace(/\/+$/, "") : CLUSTER_URL;
37
+ return process.env.NOTIFY_MCP_TEST_ENDPOINTS === "1" && process.env.NOTIFY_AGENT_CLUSTER_URL ? process.env.NOTIFY_AGENT_CLUSTER_URL.replace(/\/+$/, "") : residentCluster?.() ?? CLUSTER_URL;
33
38
  }
34
39
  /** The gateway bearer every call to AB carries; with no `agentGateway.token` in config.json BN has no way into AB and says so. */
35
40
  export function clusterToken() {
package/dist/daemon.js CHANGED
@@ -13,7 +13,9 @@ import { createWriteStream, existsSync, readFileSync, mkdirSync, renameSync } fr
13
13
  import { join } from "path";
14
14
  import { fileURLToPath } from "url";
15
15
  import { DAEMON_BEAT_PATH, CONFIG_DIR, DAEMON_TAG, PACKAGE_VERSION, smsReachesOwner, startNotifyServer, takePendingInbox, textOwner, writeRecordFile, yieldGateway } from "./notify.js";
16
- import { startNotifyDoor } from "./gateway/notifyDoor.js";
16
+ import { AgentRuntime } from "./gateway/agentRuntime.js";
17
+ import { NOTIFY_DOOR_PORT, startNotifyDoor } from "./gateway/notifyDoor.js";
18
+ import { setResidentCluster } from "./agentGateway.js";
17
19
  import { announceTakeover, inThisBoot } from "./shared/webhost/originHandover.js";
18
20
  import { TunnelRunner } from "./gateway/tunnel.js";
19
21
  const HEARTBEAT_MS = 10_000;
@@ -123,14 +125,21 @@ function keepConsole() {
123
125
  const takeover = process.argv.includes("--takeover");
124
126
  /** Whether this process writes the heartbeat: the next release only from the moment it holds the chat door, so a takeover that never lands leaves the serving build's beat alone; and a build that let the door go no longer, so the release that took it is the one beat. */
125
127
  let beating = !takeover;
128
+ let ownsNotifyDoor = false;
129
+ const agentRuntime = new AgentRuntime();
130
+ setResidentCluster(() => ownsNotifyDoor && agentRuntime.serving ? "http://127.0.0.1:" + NOTIFY_DOOR_PORT : undefined);
126
131
  keepConsole();
127
132
  // The server's own timers are unref'd, so this beat and the door hold the process until it is stopped.
128
133
  if (beating)
129
134
  beat();
130
135
  /** Each tick reads the Stop first, beating or not: a press in a window that may not end this process — the boot task's, in session 0, or one still draining its gateway after a hand-over — stops it all the same, within one tick. */
131
136
  const beatTimer = setInterval(() => {
132
- if (stoppedByHand())
133
- process.exit(0);
137
+ if (stoppedByHand()) {
138
+ void agentRuntime.close().then(() => process.exit(0));
139
+ return;
140
+ }
141
+ if (ownsNotifyDoor)
142
+ agentRuntime.acquire();
134
143
  if (beating)
135
144
  beat();
136
145
  }, HEARTBEAT_MS);
@@ -147,19 +156,24 @@ const daemonHost = {
147
156
  },
148
157
  findOtherOwner: async (port) => (await import("./gateway/lanProbe.js")).findOtherBn(port),
149
158
  onDoorOwned: (port) => {
150
- // #4231 — BN holds no agent CLI: the cluster keeps every chat CLI and its background subagents (#4814), so a BN release never waits on one.
151
159
  tunnel.beat(port, undefined);
152
160
  setInterval(() => tunnel.beat(port, undefined), HEARTBEAT_MS);
153
161
  },
154
- onSuperseded: () => (handedOver === undefined ? replaceWithInstalledBuild() : void handedOver.then(() => process.exit(0))),
162
+ prepareHandover: () => agentRuntime.prepareHandover(),
163
+ onSuperseded: () => {
164
+ void agentRuntime.close().then(() => handedOver === undefined ? replaceWithInstalledBuild() : handedOver.then(() => process.exit(0)));
165
+ },
155
166
  };
156
167
  startNotifyServer(daemonHost);
157
168
  takePendingInbox();
158
- startNotifyDoor(() => { beating = true; beat(); }, undefined, {
169
+ startNotifyDoor(() => { ownsNotifyDoor = true; beating = true; beat(); agentRuntime.acquire(); }, undefined, {
170
+ agentRuntime,
159
171
  version: PACKAGE_VERSION,
160
172
  takeover,
173
+ onUnbound: () => { ownsNotifyDoor = false; beating = false; },
161
174
  onShutdown: (closed) => {
162
175
  beating = false;
176
+ ownsNotifyDoor = false;
163
177
  handedOver = closed;
164
178
  yieldGateway();
165
179
  },
@@ -168,6 +182,6 @@ startNotifyDoor(() => { beating = true; beat(); }, undefined, {
168
182
  if (takeover)
169
183
  announceTakeover();
170
184
  for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
171
- process.on(signal, () => process.exit(0));
185
+ process.once(signal, () => { void agentRuntime.close().then(() => process.exit(0)); });
172
186
  }
173
187
  process.on("exit", () => tunnel.stop());
@@ -0,0 +1,171 @@
1
+ import { createServer } from "node:http";
2
+ import { existsSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { holdOf } from "../shared/webhost/originHandover.js";
7
+ /** Existing remote links and older clients address this port. Binding it excludes every preceding owner. */
8
+ const COMPATIBILITY_PORT = 7481;
9
+ const runtimeRoot = () => join(process.env.NOTIFY_MCP_CONFIG_DIR || join(homedir(), ".notify-mcp"), "agent-runtime");
10
+ async function closeListener(server) {
11
+ if (!server.listening)
12
+ return;
13
+ const closed = new Promise(resolve => server.close(() => resolve()));
14
+ server.closeAllConnections();
15
+ await closed;
16
+ }
17
+ export class AgentRuntime {
18
+ listener;
19
+ lease;
20
+ opening;
21
+ closing;
22
+ leaving = false;
23
+ lastError = "";
24
+ loadedEntry;
25
+ failed = new Map();
26
+ /** Called by the owner of the notification door on bind and on its recovery heartbeat. */
27
+ acquire() {
28
+ if (this.leaving || this.closing)
29
+ return;
30
+ try {
31
+ if (holdOf("agentic-bullseye").desired !== "running") {
32
+ if (this.listener || this.opening)
33
+ void this.close(false);
34
+ return;
35
+ }
36
+ if (this.opening)
37
+ return;
38
+ const releases = join(runtimeRoot(), "releases");
39
+ if (!existsSync(releases))
40
+ return;
41
+ const versions = readdirSync(releases, { withFileTypes: true }).filter(item => item.isDirectory() && /^\d+\.\d+\.\d+$/.test(item.name));
42
+ const newest = versions.sort((a, b) => b.name.localeCompare(a.name, "en", { numeric: true }))[0];
43
+ if (!newest)
44
+ return;
45
+ const marker = join(runtimeRoot(), "managed-by-notify");
46
+ const good = existsSync(marker) ? readFileSync(marker, "utf8").trim() : undefined;
47
+ const available = (version) => (this.failed.get(version)?.retryAt ?? 0) <= Date.now();
48
+ const chosen = available(newest.name) ? newest.name : versions.find(item => item.name === good && available(item.name))?.name;
49
+ if (!chosen)
50
+ return;
51
+ const entry = join(releases, chosen, "dist", "residentRuntime.js");
52
+ if (this.listener) {
53
+ if (this.loadedEntry !== entry && this.canHandOver())
54
+ void this.close(false);
55
+ return;
56
+ }
57
+ this.opening = this.open(entry, chosen, marker).catch((error) => {
58
+ const attempts = (this.failed.get(chosen)?.attempts ?? 0) + 1;
59
+ const waitMs = Math.min(600_000, 30_000 * 2 ** Math.min(attempts - 1, 5));
60
+ this.failed.set(chosen, { attempts, retryAt: Date.now() + waitMs });
61
+ this.report(error);
62
+ }).finally(() => { this.opening = undefined; });
63
+ }
64
+ catch (error) {
65
+ this.report(error);
66
+ }
67
+ }
68
+ async open(entry, version, marker) {
69
+ const server = createServer();
70
+ const acquired = await new Promise((resolve, reject) => {
71
+ const failed = (error) => error.code === "EADDRINUSE" ? resolve(false) : reject(error);
72
+ server.once("error", failed);
73
+ server.listen(COMPATIBILITY_PORT, "127.0.0.1", () => {
74
+ server.off("error", failed);
75
+ resolve(true);
76
+ });
77
+ });
78
+ if (!acquired)
79
+ return;
80
+ this.listener = server;
81
+ try {
82
+ if (this.leaving || this.closing)
83
+ return;
84
+ const runtime = createRequire(import.meta.url)(entry);
85
+ this.lease = await runtime.mountCluster(server, "BullseyeNotif");
86
+ this.loadedEntry = entry;
87
+ // The marker survives a resident restart. Consumers and startup registrations then stay on this owner.
88
+ if (!existsSync(marker) || readFileSync(marker, "utf8").trim() !== version) {
89
+ const temporary = marker + "." + process.pid;
90
+ writeFileSync(temporary, version + "\n", { mode: 0o600 });
91
+ renameSync(temporary, marker);
92
+ }
93
+ this.failed.delete(version);
94
+ this.lastError = "";
95
+ }
96
+ catch (error) {
97
+ try {
98
+ await this.lease?.close();
99
+ }
100
+ finally {
101
+ this.lease = undefined;
102
+ this.loadedEntry = undefined;
103
+ await closeListener(server);
104
+ this.listener = undefined;
105
+ }
106
+ throw error;
107
+ }
108
+ }
109
+ report(error) {
110
+ const message = error instanceof Error ? error.message : String(error);
111
+ if (message !== this.lastError)
112
+ console.error("[notify] agent runtime unavailable: " + message);
113
+ this.lastError = message;
114
+ }
115
+ get serving() {
116
+ return !!this.lease && this.listener?.listening === true && !this.closing;
117
+ }
118
+ /** Called before a routine replacement releases either public door. An active owner keeps serving. */
119
+ canHandOver() {
120
+ return !this.opening && !this.lease?.handoverHolders().length;
121
+ }
122
+ prepareHandover() {
123
+ if (!this.canHandOver())
124
+ return false;
125
+ void this.close();
126
+ return true;
127
+ }
128
+ request(req, res) {
129
+ if (!this.serving || !this.listener) {
130
+ res.writeHead(503, { "content-type": "application/json" });
131
+ res.end(JSON.stringify({ error: this.lastError || "The resident has not acquired the agent runtime" }));
132
+ return;
133
+ }
134
+ if (req.url === "/v1/agent-mcp")
135
+ req.url = "/mcp";
136
+ this.listener.emit("request", req, res);
137
+ }
138
+ upgrade(req, socket, head) {
139
+ if (this.serving && this.listener)
140
+ this.listener.emit("upgrade", req, socket, head);
141
+ else
142
+ socket.end("HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\n");
143
+ }
144
+ close(leaving = true) {
145
+ if (leaving)
146
+ this.leaving = true;
147
+ if (!this.closing)
148
+ this.closing = this.drain().finally(() => { this.closing = undefined; });
149
+ return this.closing;
150
+ }
151
+ async drain() {
152
+ if (this.opening)
153
+ await this.opening;
154
+ const server = this.listener;
155
+ const lease = this.lease;
156
+ this.lease = undefined;
157
+ try {
158
+ if (server) {
159
+ server.removeAllListeners("upgrade");
160
+ server.on("upgrade", (_req, socket) => socket.end("HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\n"));
161
+ }
162
+ if (lease)
163
+ await lease.close();
164
+ }
165
+ finally {
166
+ if (server)
167
+ await closeListener(server);
168
+ this.listener = undefined;
169
+ }
170
+ }
171
+ }
@@ -95,16 +95,27 @@ export function startNotifyDoor(onBound, port = NOTIFY_DOOR_PORT, resident) {
95
95
  const path = new URL(req.url ?? "/", "http://door").pathname;
96
96
  if (resident !== undefined && path === "/health") {
97
97
  res.writeHead(200, { "content-type": "application/json" });
98
- res.end(healthBody(NOTIFY_SERVER, port, resident.version));
98
+ const health = healthBody(NOTIFY_SERVER, port, resident.version);
99
+ res.end(resident.agentRuntime ? JSON.stringify({ ...JSON.parse(health), agentRuntime: resident.agentRuntime.serving }) : health);
100
+ return;
101
+ }
102
+ if (path === "/shutdown" && req.method === "POST" && req.headers.origin === undefined &&
103
+ resident?.agentRuntime && !resident.agentRuntime.canHandOver()) {
104
+ refuse(res, 409, "Active agent work still holds this resident");
99
105
  return;
100
106
  }
101
107
  if (resident !== undefined && answerShutdown(req, res, server, NOTIFY_SERVER, port, resident.version, (closed) => {
102
108
  stopping = true;
103
109
  bound = false;
110
+ resident.onUnbound?.();
104
111
  say(`the next release asked for the chat door on ${port}; build ${resident.version} lets it go`);
105
112
  resident.onShutdown(closed);
106
113
  }))
107
114
  return;
115
+ if (resident?.agentRuntime && (path === "/agents/" || path === "/terminal" || path.startsWith("/v1/"))) {
116
+ resident.agentRuntime.request(req, res);
117
+ return;
118
+ }
108
119
  if (path !== NOTIFY_DOOR_PATH) {
109
120
  refuse(res, 404, `the notify MCP door answers on ${NOTIFY_DOOR_PATH}`);
110
121
  return;
@@ -118,6 +129,15 @@ export function startNotifyDoor(onBound, port = NOTIFY_DOOR_PORT, resident) {
118
129
  res.end();
119
130
  });
120
131
  });
132
+ if (resident?.agentRuntime) {
133
+ const runtime = resident.agentRuntime;
134
+ server.on("upgrade", (request, socket, head) => {
135
+ if (/^\/v1\/terminals\/[^/?]+\/ws$/.test(request.url ?? ""))
136
+ runtime.upgrade(request, socket, head);
137
+ else
138
+ socket.end("HTTP/1.1 404 Not Found\r\nConnection: close\r\n\r\n");
139
+ });
140
+ }
121
141
  server.on("error", (err) => {
122
142
  attempting = false;
123
143
  const cause = err.code ?? err.message;
@@ -125,6 +145,7 @@ export function startNotifyDoor(onBound, port = NOTIFY_DOOR_PORT, resident) {
125
145
  // The listener failed after it was serving: close it before clearing the flag, or the retry timer
126
146
  // asks for a port this very process still holds and answers EADDRINUSE to itself for ever.
127
147
  bound = false;
148
+ resident?.onUnbound?.();
128
149
  lastCause = "";
129
150
  server.close();
130
151
  say(`the chat door on ${port} stopped serving (${cause}); rebinding`);
package/dist/notify.js CHANGED
@@ -3918,6 +3918,8 @@ function tryOwnGateway(polling, host) {
3918
3918
  void stepAside(polling, host);
3919
3919
  return;
3920
3920
  }
3921
+ if (host.prepareHandover && !host.prepareHandover())
3922
+ return;
3921
3923
  host.onSuperseded();
3922
3924
  return;
3923
3925
  }
@@ -4005,6 +4007,11 @@ async function stepAside(polling, host) {
4005
4007
  return;
4006
4008
  }
4007
4009
  }
4010
+ if (host.prepareHandover && !host.prepareHandover()) {
4011
+ if (polling)
4012
+ startPollers();
4013
+ return;
4014
+ }
4008
4015
  const held = door;
4009
4016
  door = undefined;
4010
4017
  await new Promise((resolve, reject) => {
@@ -314,6 +314,13 @@ async function stopServing(port, health, siblingPid) {
314
314
  if (answered.ok && answered.status >= 200 && answered.status < 300) {
315
315
  return true;
316
316
  }
317
+ if (answered.ok && answered.status === 409)
318
+ return "busy";
319
+ // Only a missing shutdown route identifies an older server. A busy owner can explicitly refuse handover.
320
+ if (!answered.ok || (answered.status !== 404 && answered.status !== 405)) {
321
+ console.error(`[bullseye] the resident on 127.0.0.1:${port} could not hand over (${answered.ok ? "HTTP " + answered.status : answered.why}); its process keeps serving`);
322
+ return false;
323
+ }
317
324
  const listening = ownerOfPort(port);
318
325
  if (listening === undefined || listening === siblingPid || (health.pid !== undefined && health.pid !== listening)) {
319
326
  console.error(`[bullseye] the resident server on 127.0.0.1:${port} (${health.version}) does not answer the stop door, and ${listening === undefined ? "no process was found holding the port" : listening === siblingPid ? `the port is now held by this release's own waiting process (pid ${listening})` : `the port is held by pid ${listening} while /health named ${health.pid}`} — nothing was signalled, so it keeps serving this release`);
@@ -425,7 +432,12 @@ async function takeThePort(door, health) {
425
432
  return { state: "failed", why: `the new build ${wanted} never reached the point of waiting for 127.0.0.1:${port} — ${reached.why}; ${health.version} is still serving` };
426
433
  }
427
434
  next.unref();
428
- if (!(await stopServing(port, health, next.pid))) {
435
+ const stopped = await stopServing(port, health, next.pid);
436
+ if (stopped === "busy") {
437
+ next.kill();
438
+ return { state: "left alone", why: `the resident on ${port} refused replacement while its work is active` };
439
+ }
440
+ if (!stopped) {
429
441
  if (await servesUntil(port, server, wanted, BIND_BOUND_MS)) {
430
442
  console.error(`[bullseye] the resident server on 127.0.0.1:${port} took this release: ${health.version} → ${wanted}`);
431
443
  return { state: "serving", version: wanted };
@@ -532,7 +544,7 @@ function healthBody(server, port, version) {
532
544
  * gateway pollers) passes `onStopping`: it is handed the listener's close in place of the exit, and ends itself.
533
545
  * #4827 — `drainMs` (default 3 s) is how long a still-open connection is let live before it is cut, so a door whose callers hold a long call (a ship mid-commit) can set a longer bound than the page-socket one.
534
546
  */
535
- function answerShutdown(req, res, httpServer, server, port, version, onStopping, drainMs = DRAIN_BOUND_MS) {
547
+ function answerShutdown(req, res, httpServer, server, port, version, onStopping, drainMs = DRAIN_BOUND_MS, beforeClose) {
536
548
  if ((req.url ?? "/").split("?")[0] !== "/shutdown")
537
549
  return false;
538
550
  if (req.headers.origin !== undefined) {
@@ -547,18 +559,24 @@ function answerShutdown(req, res, httpServer, server, port, version, onStopping,
547
559
  }
548
560
  res.writeHead(202, { "content-type": "application/json" });
549
561
  res.end(JSON.stringify({ ok: true, stopping: true, server, port, version }), () => {
550
- const closed = new Promise((resolve) => httpServer.close(() => resolve()));
551
- httpServer.closeIdleConnections();
552
- if (onStopping !== undefined) {
553
- setTimeout(() => httpServer.closeAllConnections(), drainMs).unref();
554
- onStopping(closed);
555
- return;
556
- }
557
- void closed.then(() => hardExit(0));
558
- setTimeout(() => {
559
- httpServer.closeAllConnections();
560
- hardExit(0);
561
- }, DRAIN_BOUND_MS).unref();
562
+ const release = () => {
563
+ const closed = new Promise((resolve) => httpServer.close(() => resolve()));
564
+ httpServer.closeIdleConnections();
565
+ if (onStopping !== undefined) {
566
+ setTimeout(() => httpServer.closeAllConnections(), drainMs).unref();
567
+ onStopping(closed);
568
+ return;
569
+ }
570
+ void closed.then(() => hardExit(0));
571
+ setTimeout(() => {
572
+ httpServer.closeAllConnections();
573
+ hardExit(0);
574
+ }, DRAIN_BOUND_MS).unref();
575
+ };
576
+ if (beforeClose === undefined)
577
+ release();
578
+ else
579
+ void beforeClose().then(release, error => console.error(`[${server}] kept port ${port} because its owner could not finish handing over: ${error.message}`));
562
580
  });
563
581
  return true;
564
582
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.495",
3
+ "version": "1.3.497",
4
4
  "homepage": "https://www.npmjs.com/package/omni-notify-mcp",
5
5
  "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.",
6
6
  "main": "dist/daemon.js",