omni-notify-mcp 1.3.324 → 1.3.326

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/dist/daemon.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * notify, always on — the one process per machine that starts at login.
3
+ * notify's daemon — the one process per machine, started by the boot supervisor.
4
4
  *
5
5
  * It runs the same server code as the stdio bridge (`startNotifyServer`) with no MCP client attached, so it
6
6
  * competes for the gateway port like every other BN process, and the one that binds it polls the channels,
@@ -13,33 +13,48 @@ import { spawn } from "child_process";
13
13
  import { existsSync, readFileSync, renameSync, writeFileSync, mkdirSync } from "fs";
14
14
  import { join } from "path";
15
15
  import { fileURLToPath } from "url";
16
- import { ALWAYS_ON_PATH, CONFIG_DIR, PACKAGE_VERSION, startNotifyServer, yieldGateway } from "./notify.js";
16
+ import { DAEMON_BEAT_PATH, CONFIG_DIR, PACKAGE_VERSION, startNotifyServer, yieldGateway } from "./notify.js";
17
17
  import { startNotifyDoor } from "./gateway/notifyDoor.js";
18
- import { announceTakeover } from "./shared/webhost/originHandover.js";
18
+ import { announceTakeover, inThisBoot } from "./shared/webhost/originHandover.js";
19
19
  import { TunnelRunner } from "./gateway/tunnel.js";
20
20
  const HEARTBEAT_MS = 10_000;
21
+ /** the beat's name in the release before: a box that has not run this release's activation still has that release's lifecycle staged, which reads only this name, so for one release the beat is written under both. */
22
+ const OLD_BEAT_PATH = join(CONFIG_DIR, "always-on.json");
21
23
  function beat(pid = process.pid) {
22
24
  mkdirSync(CONFIG_DIR, { recursive: true });
23
- const staged = `${ALWAYS_ON_PATH}.${process.pid}.tmp`;
24
- writeFileSync(staged, JSON.stringify({ pid, at: Date.now(), version: PACKAGE_VERSION }));
25
- renameSync(staged, ALWAYS_ON_PATH);
25
+ const text = JSON.stringify({ pid, at: Date.now(), version: PACKAGE_VERSION });
26
+ for (const file of [DAEMON_BEAT_PATH, OLD_BEAT_PATH]) {
27
+ const staged = `${file}.${process.pid}.tmp`;
28
+ writeFileSync(staged, text);
29
+ renameSync(staged, file);
30
+ }
26
31
  }
27
- /** Run by the launchd job or systemd unit vscode-extension/alwaysOn.js installs, or on Windows by the login session's supervise loop in alwaysOn.js or the boot task's vscode-extension/originSupervisor.js, each of which starts it again when it exits. On Windows that supervisor is this process's IPC parent: the channel is open only while it lives, so a dead supervisor, or a reused pid, never reads as supervised. */
32
+ /** The boot supervisor's login entry: launchd's label and systemd's unit. the release before registered it under the old names, which a daemon it started is told by for one release. */
33
+ const ENTRY_LABELS = ["com.bullseye.BullseyeMcpOrigins", "com.bullseye.BullseyeNotifyAlwaysOn"];
34
+ const ENTRY_UNITS = ["bullseye-mcp-origins.service", "bullseye-notify-always-on.service"];
35
+ /** BN's lifecycle in the config dir, then its name in the release before, which that release's activation staged, read for one release. */
36
+ const SUPERVISE_LOOPS = [join(CONFIG_DIR, "bnDaemon.js"), join(CONFIG_DIR, "alwaysOn.js")];
37
+ /** The Stop the panel writes, then its name in the release before, read for one release. */
38
+ const STOP_FILES = [join(CONFIG_DIR, "daemon-stop.json"), join(CONFIG_DIR, "always-on-desired.json")];
39
+ /** Run by the boot supervisor (BullseyeShared workspace-mcp/originSupervisor.js, under the login starter every Bullseye extension installs), or on Windows by the login session's supervise loop in bnDaemon.js, each of which starts it again when it exits. On Windows that supervisor is this process's IPC parent: the channel is open only while it lives, so a dead supervisor, or a reused pid, never reads as supervised. */
28
40
  function supervised() {
29
41
  if (process.platform === "win32")
30
42
  return process.connected === true;
31
- return process.platform === "darwin"
32
- ? process.env.XPC_SERVICE_NAME === "com.bullseye.BullseyeNotifyAlwaysOn"
33
- : process.platform === "linux" && readFileSync("/proc/self/cgroup", "utf8").includes("bullseye-notify-always-on.service");
43
+ if (process.platform === "darwin")
44
+ return ENTRY_LABELS.includes(process.env.XPC_SERVICE_NAME ?? "");
45
+ if (process.platform !== "linux")
46
+ return false;
47
+ const cgroup = readFileSync("/proc/self/cgroup", "utf8");
48
+ return ENTRY_UNITS.some((unit) => cgroup.includes(unit));
34
49
  }
35
50
  /** Who starts the installed build after this unsupervised process exits: on Windows the supervise loop the login entry and the boot task keep in the config dir, which owns every run after this one; elsewhere the same entry, started again. */
36
51
  function successor() {
37
52
  const self = fileURLToPath(import.meta.url);
38
53
  if (process.platform !== "win32")
39
54
  return spawn(process.execPath, [...process.execArgv, self], { detached: true, stdio: "ignore", windowsHide: true });
40
- const loop = join(CONFIG_DIR, "alwaysOn.js");
41
- if (!existsSync(loop))
42
- throw new Error(`the supervise loop is not in the config dir at ${loop} — the login entry and the boot task copy it there, so nothing can own the next run`);
55
+ const loop = SUPERVISE_LOOPS.find((file) => existsSync(file));
56
+ if (loop === undefined)
57
+ throw new Error(`the supervise loop is not in the config dir at ${SUPERVISE_LOOPS[0]} — the login entry and the boot task copy it there, so nothing can own the next run`);
43
58
  return spawn(process.execPath, [loop, "supervise", self], { detached: true, stdio: "ignore", windowsHide: true });
44
59
  }
45
60
  /** The installed build has replaced this one on disk: a supervised process only exits and its owner starts that build; an unsupervised one starts its successor and names it in the heartbeat before it exits, so no other owner starts a second build meanwhile, and on Windows the supervise loop reads that beat as the claim on its first run. */
@@ -53,22 +68,30 @@ function replaceWithInstalledBuild() {
53
68
  }
54
69
  process.exit(0);
55
70
  }
56
- /** The Stop the panel pressed is this machine's own setting, so a process a login entry started after it reads the same file and starts nothing. Absent, the machine has never been stopped and starts as it always has. */
57
- function stoppedByHand() {
58
- const desired = join(CONFIG_DIR, "always-on-desired.json");
59
- if (!existsSync(desired))
60
- return false;
61
- let pressed;
71
+ function pressedIn(file) {
72
+ if (!existsSync(file))
73
+ return undefined;
62
74
  try {
63
- pressed = JSON.parse(readFileSync(desired, "utf8"));
75
+ return { ...JSON.parse(readFileSync(file, "utf8")), file };
64
76
  }
65
77
  catch (err) {
66
- throw new Error(`${desired} is not readable JSON, so whether a Stop was pressed on this machine cannot be known — ${err.message}`);
78
+ throw new Error(`${file} is not readable JSON, so whether a Stop was pressed on this machine cannot be known — ${err.message}`);
67
79
  }
68
- return pressed.desired === "stopped";
80
+ }
81
+ /** The Stop the panel pressed is this machine's own setting until a Start or the next boot (#3849 Q782), so a process a login entry started after it in this boot reads the same file and starts nothing. Absent, the machine has never been stopped and starts as it always has. */
82
+ function stoppedByHand() {
83
+ const [now, old] = STOP_FILES.map(pressedIn);
84
+ const pressed = old !== undefined && (now === undefined || (old.at ?? -Infinity) > (now.at ?? -Infinity)) ? old : now;
85
+ if (pressed === undefined)
86
+ return false;
87
+ if (pressed.desired !== "stopped")
88
+ return false;
89
+ if (typeof pressed.at !== "number")
90
+ throw new Error(`${pressed.file} names a Stop with no time it was pressed, so whether it was pressed in this boot cannot be known`);
91
+ return inThisBoot(pressed.at);
69
92
  }
70
93
  if (stoppedByHand()) {
71
- console.log("[BOOT] BullseyeNotify always-on — a Stop was pressed on this machine; nothing started, and nothing beats until Start is pressed in the panel.");
94
+ console.log("[BOOT] BullseyeNotify daemon — a Stop was pressed on this machine; nothing started, and nothing beats until Start is pressed in the panel or the machine reboots.");
72
95
  process.exit(0);
73
96
  }
74
97
  // The shared hand-over (src/shared/webhost/originHandover.js ensureResidentDoor) puts a later release on the chat door: the new build is started with --takeover over an IPC channel, says it waits, and binds once this build lets the door go.
@@ -678,7 +678,7 @@ async function listView(shelf) {
678
678
  }
679
679
  `;
680
680
  /** A service page's own half (#3849): once signed in, the gateway's `/screen/open` keeps the sign-in for the page's own
681
- * requests and names the one page this host's always-on service draws, and the visitor goes straight to it — no VS Code
681
+ * requests and names the one page this host's own service draws, and the visitor goes straight to it — no VS Code
682
682
  * window is chosen or needed. */
683
683
  const SERVICE_SCRIPT = String.raw `
684
684
  var main = document.getElementById("main"), title = document.getElementById("title"), btnRefresh = document.getElementById("refresh");
@@ -708,7 +708,7 @@ async function home() {
708
708
  }
709
709
  `;
710
710
  /** The page each service host of the public gateway serves (#2873): BN's look and BN's sign-in, then the page the
711
- * service's always-on process draws. The line under the header names the process that answered. */
711
+ * service's daemon draws. The line under the header names the process that answered. */
712
712
  export function serviceHtml({ name, host }) {
713
713
  const me = servingIdentity();
714
714
  const safe = (text) => text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
@@ -25,11 +25,11 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
25
25
  import { createMcpServer, sessionIdentity } from "../notify.js";
26
26
  import { answerShutdown, healthBody, TAKEOVER_BIND } from "../shared/webhost/originHandover.js";
27
27
  /** BN's own port block: 7470 is the gateway, so the chat tools take the next free one. */
28
- // GATE: the door's port may be moved ONLY under the test gate, so a suite drives a real always-on process on a port it owns; without the gate it is 7475 and no environment can redirect it. vscode-extension/alwaysOn.js probes the same rule.
28
+ // GATE: the door's port may be moved ONLY under the test gate, so a suite drives a real daemon on a port it owns; without the gate it is 7475 and no environment can redirect it. vscode-extension/bnDaemon.js probes the same rule.
29
29
  export const NOTIFY_DOOR_PORT = process.env.NOTIFY_MCP_TEST_ENDPOINTS === "1" && Number(process.env.NOTIFY_DOOR_PORT) > 0 ? Number(process.env.NOTIFY_DOOR_PORT) : 7475;
30
30
  export const NOTIFY_DOOR_PATH = "/mcp";
31
31
  const RETRY_MS = 5_000;
32
- /** The name the always-on process answers `/health` with: the `server` the boot task's supervisor hands BN's port over by (vscode-extension/originSupervisor.js ORIGINS). */
32
+ /** The name the daemon answers `/health` with: the `server` the boot task's supervisor hands BN's port over by (BullseyeShared workspace-mcp/originSupervisor.js ORIGINS). */
33
33
  export const NOTIFY_SERVER = "bullseye-notify";
34
34
  function headerOf(req, name) {
35
35
  const value = req.headers[name];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The Notify panel's logic, owned by the always-on service (#3512): the settings the notify server reads, how a value
2
+ * The Notify panel's logic, owned by the service (#3512): the settings the notify server reads, how a value
3
3
  * is checked and written, the conversation On/Off switch, and the one-line state of the channels. The VS Code panel and
4
4
  * the web page are thin clients of the routes in restDoor.ts — neither holds a copy of anything here, and neither needs
5
5
  * a VS Code window for it.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * BN's Settings and Public access pages (#3512), served by the always-on service beside the conversation page. They hold
2
+ * BN's Settings and Public access pages (#3512), served by the service beside the conversation page. They hold
3
3
  * no logic: each draws what a bearer route answers (`GET /v1/panel`, `GET /v1/public-access`) and sends every click back
4
4
  * to one (`POST /v1/settings`, `POST /v1/conversation-switch`, `POST /v1/public-access/<step>`). The VS Code panel frames
5
5
  * these very pages, so the panel and a browser with every editor closed show the same thing from the same service.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The Public access wizard (#2100), owned by the always-on service (#3512). It walks a user through creating a Cloudflare
2
+ * The Public access wizard (#2100), owned by the service (#3512). It walks a user through creating a Cloudflare
3
3
  * Tunnel, saves the token beside the gateway's own secret in config.json, downloads cloudflared into BN's folder, shows
4
4
  * this process running it (tunnel.ts) and checks the public hostname end to end. A cloudflared tunnel this machine already
5
5
  * has is detected and named, and the wizard will not start a second one. The VS Code panel and the web page are thin
@@ -23,7 +23,7 @@ const ATTEMPTS = 3;
23
23
  // GATE: a request that has sent nothing for this long is abandoned as a network failure.
24
24
  const IDLE_MS = 30_000;
25
25
  const REDIRECTS = 5;
26
- // GATE: a gateway-state beat older than this is presumed dead; it is vscode-extension/alwaysOn.js's own STALE_MS.
26
+ // GATE: a gateway-state beat older than this is presumed dead; it is vscode-extension/bnDaemon.js's own STALE_MS.
27
27
  const STALE_MS = 30_000;
28
28
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
29
29
  const HOSTNAME = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The HTTP/REST door of the Agent Gateway (design section g). The always-on process owns the port; every call
2
+ * The HTTP/REST door of the Agent Gateway (design section g). The daemon owns the port; every call
3
3
  * carries the conversation id and one bearer token from `config.json` (`agentGateway.token`), and nothing is
4
4
  * kept in the connection, so a restart between a send and its read loses nothing. No request is held longer
5
5
  * than the 55 s every blocking BN call is capped at, so starting work and reading its answer are separate calls.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The Cloudflare Tunnel connector of the Agent Gateway (#2100). The always-on process that holds the gateway door
2
+ * The Cloudflare Tunnel connector of the Agent Gateway (#2100). The daemon that holds the gateway door
3
3
  * also runs `cloudflared tunnel run` as its windowless child, so a user's own hostname reaches the door without a
4
4
  * hand-built tunnel. The token is `agentGateway.tunnel.token` in `config.json` — beside `agentGateway.token`, the
5
5
  * gateway secret this process already reads there — written by the extension's Public access wizard, and it reaches
package/dist/notify.js CHANGED
@@ -742,7 +742,7 @@ function takeSharedEntriesForSelf(saved) {
742
742
  for (const { deliveredTo, ...entry } of saved) {
743
743
  if (deliveredTo.includes(deliveredKey(SELF_TAG)) || alreadyDelivered(entry, SELF_TAG))
744
744
  continue;
745
- // The always-on process is the machine's queue: it holds every chat's undelivered entry in memory, tagged ones
745
+ // The daemon is the machine's queue: it holds every chat's undelivered entry in memory, tagged ones
746
746
  // included, because the HTTP chats it serves are the only readers of a tagged entry and each drains its own by
747
747
  // tag. A bridge (one host) takes only what is addressed to it. An entry a chat already drained is marked per tag
748
748
  // in the shared file, and that mark is what keeps a second reader from delivering it again.
@@ -959,7 +959,7 @@ function queueInboxEntry(entry) {
959
959
  }
960
960
  function ingestChatEntry(entry) {
961
961
  const { waiters } = ingestInboxEntry(entry, entry.origin ?? "telegram");
962
- // The always-on process serves no session of its own, so it cannot say who is connected — only that the shared inbox holds the message.
962
+ // The daemon serves no session of its own, so it cannot say who is connected — only that the shared inbox holds the message.
963
963
  if (QUEUE_ONLY)
964
964
  return entry.tag
965
965
  ? `📬 Queued for @${entry.tag}. Delivered when that session is connected.`
@@ -1135,7 +1135,7 @@ async function startTelegramListener() {
1135
1135
  }
1136
1136
  }
1137
1137
  }
1138
- // ── Slack inbound poller (always-on; folds slack-poll.sh → #16) ────────────────
1138
+ // ── Slack inbound poller (the daemon's; folds slack-poll.sh → #16) ────────────────
1139
1139
  function decodeB64Fields(obj) {
1140
1140
  if (Array.isArray(obj))
1141
1141
  return obj.map(decodeB64Fields);
@@ -2443,7 +2443,7 @@ export function createMcpServer(clientId, sessionTag) {
2443
2443
  }
2444
2444
  // ── Every host runs its own copy of this process ──────────────────────────────
2445
2445
  //
2446
- // Claude Code, GitHub Copilot Chat, Codex and the always-on daemon each run this program, so several can be
2446
+ // Claude Code, GitHub Copilot Chat, Codex and the daemon each run this program, so several can be
2447
2447
  // alive on one machine. What they must SHARE — the inbox — lives on disk under CONFIG_DIR. What only ONE may do —
2448
2448
  // the channel pollers, the REST/MCP door and the agent conversations — belongs to the process that binds the
2449
2449
  // gateway port: the OS lets exactly one succeed, every other process stays dormant and retries, and the first
@@ -2508,15 +2508,22 @@ function startOwnedWork() {
2508
2508
  AgentGateway.instance().boot();
2509
2509
  log("·", "listener", `this process (pid ${process.pid}, build ${PACKAGE_VERSION}) owns the Telegram, Slack, Discord and Teams pollers, the ntfy and SMS pollers, the agent's email door, and the agent conversations`);
2510
2510
  }
2511
- // GATE: an always-on beat older than this is presumed dead; it is vscode-extension/alwaysOn.js's own STALE_MS.
2511
+ // GATE: a daemon's beat older than this is presumed dead; it is vscode-extension/bnDaemon.js's own STALE_MS.
2512
2512
  const DAEMON_BEAT_STALE_MS = 30_000;
2513
- /** Written by the always-on process (daemon.ts) on its beat, read by vscode-extension/alwaysOn.js. */
2514
- export const ALWAYS_ON_PATH = join(CONFIG_DIR, "always-on.json");
2513
+ /** Written by the daemon (daemon.ts) on its beat, read by vscode-extension/bnDaemon.js. */
2514
+ export const DAEMON_BEAT_PATH = join(CONFIG_DIR, "daemon.json");
2515
+ /** the beat's name in the release before, read for one release so a daemon of that build is never read as gone. */
2516
+ const OLD_DAEMON_BEAT_PATH = join(CONFIG_DIR, "always-on.json");
2517
+ /** The later of the beat and the one under its old name, or undefined when neither was written. */
2518
+ function latestBeat() {
2519
+ const [beat, old] = [DAEMON_BEAT_PATH, OLD_DAEMON_BEAT_PATH].map((file) => (existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined));
2520
+ return old !== undefined && (beat === undefined || old.at > beat.at) ? old : beat;
2521
+ }
2515
2522
  /** An always-on process is alive and beating — of the given build, when one is named. */
2516
2523
  function daemonBeats(version) {
2517
- if (!existsSync(ALWAYS_ON_PATH))
2524
+ const beat = latestBeat();
2525
+ if (beat === undefined)
2518
2526
  return false;
2519
- const beat = JSON.parse(readFileSync(ALWAYS_ON_PATH, "utf8"));
2520
2527
  if (Date.now() - beat.at >= DAEMON_BEAT_STALE_MS || (version !== undefined && beat.version !== version))
2521
2528
  return false;
2522
2529
  try {
@@ -2541,15 +2548,15 @@ let supersededSaid = false;
2541
2548
  /** The next release asked for the chat door over `POST /shutdown` (the shared hand-over): this process is superseded by it as it is by a newer manifest, though no manifest beside it moved. */
2542
2549
  let yielding = false;
2543
2550
  let reaskOwnership = () => { };
2544
- /** The always-on process's answer to the hand-over's `POST /shutdown`: the gateway passes to the release that asked, through the same step-aside a newer manifest triggers, so the pollers drain before the port is let go. */
2551
+ /** The daemon's answer to the hand-over's `POST /shutdown`: the gateway passes to the release that asked, through the same step-aside a newer manifest triggers, so the pollers drain before the port is let go. */
2545
2552
  export function yieldGateway() {
2546
2553
  yielding = true;
2547
2554
  reaskOwnership();
2548
2555
  }
2549
2556
  /**
2550
2557
  * Once the extension installs a newer build, this process is superseded and the gateway passes to the installed build:
2551
- * a superseded process never takes it while an always-on process beats, and one that holds it steps aside once no
2552
- * answer is in flight — the always-on process at once, since it starts the installed build in its place, and a
2558
+ * a superseded process never takes it while a daemon beats, and one that holds it steps aside once no
2559
+ * answer is in flight — the daemon at once, since it starts the installed build in its place, and a
2553
2560
  * bridge once the installed build's always-on process beats to take it over.
2554
2561
  */
2555
2562
  function tryOwnGateway(polling, host) {