omni-notify-mcp 1.3.333 → 1.3.335

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
@@ -13,49 +13,43 @@ 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 { DAEMON_BEAT_PATH, CONFIG_DIR, DAEMON_TAG, PACKAGE_VERSION, startNotifyServer, yieldGateway } from "./notify.js";
16
+ import { DAEMON_BEAT_PATH, CONFIG_DIR, DAEMON_TAG, PACKAGE_VERSION, startNotifyServer, takePendingInbox, yieldGateway } from "./notify.js";
17
17
  import { startNotifyDoor } from "./gateway/notifyDoor.js";
18
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");
23
21
  function beat(pid = process.pid) {
24
22
  mkdirSync(CONFIG_DIR, { recursive: true });
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
- }
23
+ const staged = `${DAEMON_BEAT_PATH}.${process.pid}.tmp`;
24
+ writeFileSync(staged, JSON.stringify({ pid, at: Date.now(), version: PACKAGE_VERSION }));
25
+ renameSync(staged, DAEMON_BEAT_PATH);
31
26
  }
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")];
27
+ /** The boot supervisor's login entry: launchd's label and systemd's unit. */
28
+ const ENTRY_LABEL = "com.bullseye.BullseyeMcpOrigins";
29
+ const ENTRY_UNIT = "bullseye-mcp-origins.service";
30
+ /** BN's lifecycle in the config dir, which the login entry and the boot task keep. */
31
+ const SUPERVISE_LOOP = join(CONFIG_DIR, "bnDaemon.js");
32
+ /** The Stop the panel writes. */
33
+ const STOP_FILE = join(CONFIG_DIR, "daemon-stop.json");
39
34
  /** 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. */
40
35
  function supervised() {
41
36
  if (process.platform === "win32")
42
37
  return process.connected === true;
43
38
  if (process.platform === "darwin")
44
- return ENTRY_LABELS.includes(process.env.XPC_SERVICE_NAME ?? "");
39
+ return process.env.XPC_SERVICE_NAME === ENTRY_LABEL;
45
40
  if (process.platform !== "linux")
46
41
  return false;
47
42
  const cgroup = readFileSync("/proc/self/cgroup", "utf8");
48
- return ENTRY_UNITS.some((unit) => cgroup.includes(unit));
43
+ return cgroup.includes(ENTRY_UNIT);
49
44
  }
50
45
  /** 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. */
51
46
  function successor() {
52
47
  const self = fileURLToPath(import.meta.url);
53
48
  if (process.platform !== "win32")
54
49
  return spawn(process.execPath, [...process.execArgv, self], { detached: true, stdio: "ignore", windowsHide: true });
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`);
58
- return spawn(process.execPath, [loop, "supervise", self], { detached: true, stdio: "ignore", windowsHide: true });
50
+ if (!existsSync(SUPERVISE_LOOP))
51
+ throw new Error(`the supervise loop is not in the config dir at ${SUPERVISE_LOOP} — the login entry and the boot task copy it there, so nothing can own the next run`);
52
+ return spawn(process.execPath, [SUPERVISE_LOOP, "supervise", self], { detached: true, stdio: "ignore", windowsHide: true });
59
53
  }
60
54
  /** 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. */
61
55
  function replaceWithInstalledBuild() {
@@ -72,7 +66,7 @@ function pressedIn(file) {
72
66
  if (!existsSync(file))
73
67
  return undefined;
74
68
  try {
75
- return { ...JSON.parse(readFileSync(file, "utf8")), file };
69
+ return JSON.parse(readFileSync(file, "utf8"));
76
70
  }
77
71
  catch (err) {
78
72
  throw new Error(`${file} is not readable JSON, so whether a Stop was pressed on this machine cannot be known — ${err.message}`);
@@ -80,14 +74,13 @@ function pressedIn(file) {
80
74
  }
81
75
  /** 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
76
  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;
77
+ const pressed = pressedIn(STOP_FILE);
85
78
  if (pressed === undefined)
86
79
  return false;
87
80
  if (pressed.desired !== "stopped")
88
81
  return false;
89
82
  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`);
83
+ throw new Error(`${STOP_FILE} names a Stop with no time it was pressed, so whether it was pressed in this boot cannot be known`);
91
84
  return inThisBoot(pressed.at);
92
85
  }
93
86
  if (stoppedByHand()) {
@@ -112,14 +105,17 @@ const beatTimer = setInterval(() => {
112
105
  let handedOver;
113
106
  // Only the daemon that owns the gateway port runs the connector and publishes its state: a dormant one has nothing for it to reach.
114
107
  const tunnel = new TunnelRunner();
115
- startNotifyServer({
108
+ const daemonHost = {
116
109
  clientId: DAEMON_TAG, tag: DAEMON_TAG, queueOnly: true, emit: async () => { },
117
110
  onDoorOwned: (port) => {
118
111
  tunnel.beat(port);
119
112
  setInterval(() => tunnel.beat(port), HEARTBEAT_MS);
120
113
  },
121
114
  onSuperseded: () => (handedOver === undefined ? replaceWithInstalledBuild() : void handedOver.then(() => process.exit(0))),
122
- });
115
+ };
116
+ startNotifyServer(daemonHost);
117
+ // No MCP client connects here, so nothing can be pushed: the boot take only hands entries to the queue.
118
+ takePendingInbox(daemonHost);
123
119
  startNotifyDoor(() => { beating = true; beat(); }, undefined, {
124
120
  version: PACKAGE_VERSION,
125
121
  takeover,
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
- import { sessionIdentity, startNotifyServer } from "./notify.js";
3
+ import { sessionIdentity, startNotifyServer, takePendingInbox } from "./notify.js";
4
4
  import { startNotifyDoor } from "./gateway/notifyDoor.js";
5
5
  // The explicit name wins, so a host whose config can pass arguments (Copilot's
6
6
  // mcp.json, Codex's config.toml) names its own window instead of inheriting
@@ -17,8 +17,8 @@ const TAG = sessionIdentity({
17
17
  sessionId: process.env.CLAUDE_CODE_SESSION_ID,
18
18
  });
19
19
  // Assigned by startNotifyServer() on the next line and never replaced. It is
20
- // read only from emit(), which no caller can reach before that assignment:
21
- // the entry point starts the disk-sync timer that calls emit.
20
+ // read only from emit(), which runs only after mcp.connect below: the watches
21
+ // fire on later events, and takePendingInbox runs right after connect.
22
22
  let mcp;
23
23
  const host = {
24
24
  clientId: TAG,
@@ -37,5 +37,7 @@ mcp = startNotifyServer(host);
37
37
  startNotifyDoor(() => { });
38
38
  const transport = new StdioServerTransport();
39
39
  await mcp.connect(transport);
40
+ // A channel push is only read by a host that has finished its initialize handshake, so the boot take waits for it.
41
+ mcp.server.oninitialized = () => takePendingInbox(host);
40
42
  process.stdin.on("end", () => process.exit(0));
41
43
  process.stdin.on("close", () => process.exit(0));
package/dist/notify.js CHANGED
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { randomUUID, createHash } from "crypto";
14
14
  import { createServer as createNetServer } from "net";
15
- import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, unlinkSync, renameSync, rmSync, watch } from "fs";
15
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, unlinkSync, linkSync, renameSync, rmSync, watch } from "fs";
16
16
  import { homedir, networkInterfaces, hostname, tmpdir } from "os";
17
17
  import { join, basename, dirname } from "path";
18
18
  import { fileURLToPath } from "url";
@@ -759,13 +759,6 @@ function persistInboxQueue(arrivals = []) {
759
759
  rmSync(join(CONFIG_DIR, other), { force: true });
760
760
  }
761
761
  }
762
- function restoreInboxQueue() {
763
- const saved = readSharedQueue();
764
- if (saved.length === 0)
765
- return;
766
- const taken = takeSharedEntriesForSelf(saved);
767
- log("·", "inbox", `restored ${taken.length} undelivered inbox entr${taken.length === 1 ? "y" : "ies"} of ${saved.length} in ${CONFIG_DIR}`);
768
- }
769
762
  // Entries in the shared queue addressed to THIS host that no process of it has taken yet. Each is
770
763
  // recorded as taken (in memory and in the shared file, so it is never taken twice) and handed over.
771
764
  function takeSharedEntriesForSelf(saved) {
@@ -926,32 +919,113 @@ function reapInboxDrops() {
926
919
  }
927
920
  // The drop folder is how a process that is not this one (the trading app's alerts) hands the notify app a
928
921
  // message, because only the notify app writes its queue. One .json file per message, staged as .tmp and
929
- // renamed by the writer; each is claimed by rename (so exactly one host process takes it), queued UNTAGGED
930
- // so every window sees it, and deleted. An unreadable file is kept as .rejected, never silently dropped.
922
+ // renamed by the writer; each is claimed through an exclusive hard link in the claims folder, so exactly one host process takes it,
923
+ // queued UNTAGGED so every window sees it, and deleted. An unreadable file is kept as .rejected, never silently dropped.
931
924
  const INBOX_DROP_IN_DIR = join(CONFIG_DIR, "inbox-drop");
925
+ const INBOX_DROP_CLAIM_DIR = join(CONFIG_DIR, "inbox-drop-claims");
926
+ function processIsAlive(pid) {
927
+ try {
928
+ process.kill(pid, 0);
929
+ return true;
930
+ }
931
+ catch (err) {
932
+ const code = err.code;
933
+ if (code === "ESRCH")
934
+ return false;
935
+ if (code === "EPERM")
936
+ return true;
937
+ throw err;
938
+ }
939
+ }
940
+ function lockedByAnother(code) {
941
+ return code === "EEXIST" || (process.platform === "win32" && (code === "EPERM" || code === "EACCES" || code === "EBUSY"));
942
+ }
943
+ function createExclusive(target) {
944
+ const staging = `${target}.${process.pid}.tmp`;
945
+ writeFileSync(staging, String(process.pid));
946
+ try {
947
+ linkSync(staging, target);
948
+ return true;
949
+ }
950
+ catch (err) {
951
+ if (lockedByAnother(err.code))
952
+ return false;
953
+ throw err;
954
+ }
955
+ finally {
956
+ rmSync(staging, { force: true });
957
+ }
958
+ }
959
+ function ownerOf(marker) {
960
+ try {
961
+ return Number.parseInt(readFileSync(marker, "utf8"), 10);
962
+ }
963
+ catch (err) {
964
+ const code = err.code;
965
+ if (code === "ENOENT")
966
+ return undefined;
967
+ if (lockedByAnother(code))
968
+ return Number.POSITIVE_INFINITY;
969
+ throw err;
970
+ }
971
+ }
972
+ function claimDrop(marker) {
973
+ if (createExclusive(marker))
974
+ return true;
975
+ const owner = ownerOf(marker);
976
+ if (owner === undefined)
977
+ return createExclusive(marker);
978
+ if (owner === Number.POSITIVE_INFINITY || (owner !== process.pid && processIsAlive(owner)))
979
+ return false;
980
+ const takeover = `${marker}.takeover.${owner}`;
981
+ if (!claimDrop(takeover))
982
+ return false;
983
+ try {
984
+ if (ownerOf(marker) !== owner)
985
+ return false;
986
+ rmSync(marker, { force: true });
987
+ return createExclusive(marker);
988
+ }
989
+ finally {
990
+ rmSync(takeover, { force: true });
991
+ }
992
+ }
932
993
  function ingestDropFolder(host) {
933
994
  if (!existsSync(INBOX_DROP_IN_DIR))
934
995
  return;
996
+ mkdirSync(INBOX_DROP_CLAIM_DIR, { recursive: true });
935
997
  const arrivals = [];
936
998
  for (const name of readdirSync(INBOX_DROP_IN_DIR).filter((f) => f.endsWith(".json"))) {
937
999
  const path = join(INBOX_DROP_IN_DIR, name);
938
- const claimed = `${path}.${process.pid}.claimed`;
939
- try {
940
- renameSync(path, claimed);
941
- }
942
- catch {
943
- continue; // another host process claimed it first
944
- }
1000
+ const marker = join(INBOX_DROP_CLAIM_DIR, `${name}.claim`);
945
1001
  try {
946
- const { text, ts } = JSON.parse(readFileSync(claimed, "utf8"));
947
- if (typeof text !== "string" || text === "")
948
- throw new Error("no text");
949
- arrivals.push({ text, ts: typeof ts === "string" ? ts : new Date().toISOString(), origin: "drop" });
950
- unlinkSync(claimed);
1002
+ if (!claimDrop(marker))
1003
+ continue;
1004
+ try {
1005
+ if (!existsSync(path))
1006
+ continue;
1007
+ let entry;
1008
+ try {
1009
+ const { text, ts } = JSON.parse(readFileSync(path, "utf8"));
1010
+ if (typeof text !== "string" || text === "")
1011
+ throw new Error("no text");
1012
+ entry = { text, ts: typeof ts === "string" ? ts : new Date().toISOString(), origin: "drop" };
1013
+ }
1014
+ catch (err) {
1015
+ renameSync(path, `${path}.rejected`);
1016
+ log("·", "inbox-drop", `${name} is not a well-formed drop and was kept as .rejected: ${err instanceof Error ? err.message : String(err)}`);
1017
+ continue;
1018
+ }
1019
+ unlinkSync(path);
1020
+ arrivals.push(entry);
1021
+ }
1022
+ finally {
1023
+ rmSync(marker, { force: true });
1024
+ }
951
1025
  }
952
1026
  catch (err) {
953
- renameSync(claimed, `${path}.rejected`);
954
- log("·", "inbox-drop", `${name} is not a well-formed drop and was kept as .rejected: ${err instanceof Error ? err.message : String(err)}`);
1027
+ // OWNER: ITER/LOOP — one drop's failed claim or settle must not lose the arrivals already collected — it is logged and the drop stays in the folder for the next pass
1028
+ log("·", "inbox-drop", `${name} could not be claimed or settled and stays in the folder: ${err instanceof Error ? err.message : String(err)}`);
955
1029
  }
956
1030
  }
957
1031
  if (arrivals.length === 0)
@@ -2544,12 +2618,9 @@ function startOwnedWork() {
2544
2618
  const DAEMON_BEAT_STALE_MS = 30_000;
2545
2619
  /** Written by the daemon (daemon.ts) on its beat, read by vscode-extension/bnDaemon.js. */
2546
2620
  export const DAEMON_BEAT_PATH = join(CONFIG_DIR, "daemon.json");
2547
- /** the beat's name in the release before, read for one release so a daemon of that build is never read as gone. */
2548
- const OLD_DAEMON_BEAT_PATH = join(CONFIG_DIR, "always-on.json");
2549
- /** The later of the beat and the one under its old name, or undefined when neither was written. */
2621
+ /** The daemon's last beat, or undefined when it never wrote one. */
2550
2622
  function latestBeat() {
2551
- const [beat, old] = [DAEMON_BEAT_PATH, OLD_DAEMON_BEAT_PATH].map((file) => (existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined));
2552
- return old !== undefined && (beat === undefined || old.at > beat.at) ? old : beat;
2623
+ return existsSync(DAEMON_BEAT_PATH) ? JSON.parse(readFileSync(DAEMON_BEAT_PATH, "utf8")) : undefined;
2553
2624
  }
2554
2625
  /** A daemon is alive and beating — of the given build, when one is named. */
2555
2626
  function daemonBeats(version) {
@@ -2696,7 +2767,6 @@ function syncInboxFromDisk(host) {
2696
2767
  export function startNotifyServer(host) {
2697
2768
  SELF_TAG = host.tag;
2698
2769
  QUEUE_ONLY = host.queueOnly === true;
2699
- restoreInboxQueue();
2700
2770
  importCredsOnStart();
2701
2771
  warnIfNoChannelConfigured(loadConfig());
2702
2772
  refreshReach();
@@ -2741,10 +2811,13 @@ export function startNotifyServer(host) {
2741
2811
  syncInboxFromDisk(host);
2742
2812
  });
2743
2813
  watchDrops();
2744
- ingestDropFolder(host);
2745
- syncInboxFromDisk(host);
2746
2814
  const reapTimer = setInterval(reapInboxDrops, 60 * 60 * 1000);
2747
2815
  ownershipTimer.unref();
2748
2816
  reapTimer.unref();
2749
2817
  return createMcpServer(host.clientId, host.tag);
2750
2818
  }
2819
+ /** Takes in what was queued or dropped before this process started. Called once the server is connected, because every push needs it. */
2820
+ export function takePendingInbox(host) {
2821
+ ingestDropFolder(host);
2822
+ syncInboxFromDisk(host);
2823
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.333",
3
+ "version": "1.3.335",
4
4
  "description": "Reach your AI agents from anywhere — and let them reach you. One stdio process 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/index.js",
6
6
  "type": "module",