omni-notify-mcp 1.3.326 → 1.3.327

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.
@@ -12,7 +12,11 @@
12
12
  * whether or not the client passes the id back; `new: true` starts a fresh one.
13
13
  */
14
14
  import { AsyncLocalStorage } from "async_hooks";
15
+ import { spawn } from "child_process";
15
16
  import { createHash, randomUUID } from "crypto";
17
+ import { existsSync } from "fs";
18
+ import { createRequire } from "module";
19
+ import { join } from "path";
16
20
  import { performance } from "perf_hooks";
17
21
  import { z } from "zod";
18
22
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -23,14 +27,18 @@ import { PROVIDER_NAMES } from "./providers.js";
23
27
  import { iconsFor } from "./iconDoor.js";
24
28
  import { grantClient, publicBase } from "./oauthDoor.js";
25
29
  import { bearer, personId, sessionSignIn, tokenProves } from "./passkeyDoor.js";
26
- import { consoleSession, terminalArriving } from "./nativeTerminal.js";
30
+ import { closeNativeTerminal, consoleSession, nativeTerminal, terminalArriving } from "./nativeTerminal.js";
31
+ import { dimensions, openTerminal, terminalListing, validFiles } from "./terminalDoor.js";
32
+ import { conversationSwitchRead, panelState, saveConversationSwitch, saveSetting } from "./panel.js";
33
+ import { wizard } from "./publicAccess.js";
27
34
  import { EVENTS_CAPABILITY, serveEvents } from "./mcpEvents.js";
28
- import { PACKAGE_VERSION, readGatewaySettings } from "../notify.js";
35
+ import { CONFIG_DIR, PACKAGE_VERSION, readGatewaySettings } from "../notify.js";
29
36
  const answer = (value) => ({ content: [{ type: "text", text: JSON.stringify(value) }] });
30
37
  /** A refused act is the tool's own error result, never a protocol failure, so the calling agent can read why. */
31
- async function act(run) {
38
+ async function act(run, switchGated = true) {
32
39
  try {
33
- requireConversationEnabled();
40
+ if (switchGated)
41
+ requireConversationEnabled();
34
42
  return answer(await run());
35
43
  }
36
44
  catch (err) {
@@ -40,6 +48,27 @@ async function act(run) {
40
48
  throw err;
41
49
  }
42
50
  }
51
+ /** A panel route that works with the agent-conversation switch Off — the Settings and Public access pages are what turn it On — so it is answered without the switch check `act` makes. */
52
+ const panelAct = (run) => act(run, false);
53
+ /** BN's lifecycle as the extension stages it beside the boot supervisor (bnDaemon.js LIFECYCLE_FILES): the one code the Uber dashboard row and the panel run. */
54
+ function stagedLifecycle() {
55
+ const file = join(CONFIG_DIR, "bnLifecycle.js");
56
+ if (!existsSync(file))
57
+ throw new GatewayError(503, `BN's lifecycle is not staged at ${file} — the extension stages it at activation, so a build that never activated has none`);
58
+ return file;
59
+ }
60
+ /** The press itself, run in a process of its own: the row's own act, whose outcome is read afterwards with act=state. */
61
+ const LIFECYCLE_ACTOR = "require(process.argv[1]).row(process.argv[2]).act(process.argv[3]).then(() => process.exit(0), () => process.exit(1))";
62
+ /** A launcher that starts the actor detached and exits at once, so no live parent links the actor to this daemon: the Stop inside a Restart ends this daemon's whole process tree, and an actor still in it would die before it started BN again. */
63
+ const LIFECYCLE_LAUNCHER = `require("child_process").spawn(process.execPath, ["-e", ${JSON.stringify(LIFECYCLE_ACTOR)}, ...process.argv.slice(1)], { detached: true, stdio: "ignore", windowsHide: true }).unref()`;
64
+ /** Start, Stop and Restart end or replace the process answering this very call, so they run in a process that outlives it; the outcome is read afterwards with act=state. */
65
+ function pressLifecycle(file, press) {
66
+ return new Promise((resolve, reject) => {
67
+ const launcher = spawn(process.execPath, ["-e", LIFECYCLE_LAUNCHER, file, process.argv[1], press], { stdio: "ignore", windowsHide: true });
68
+ launcher.once("error", (err) => reject(new GatewayError(500, `the ${press} could not be launched — ${err.message}`)));
69
+ launcher.once("exit", (code) => (code === 0 ? resolve({ pressed: press, running: true, next: "read the outcome with bn_lifecycle act=state" }) : reject(new GatewayError(500, `the ${press} could not be launched — its launcher exited ${code}`))));
70
+ });
71
+ }
43
72
  /** #3849 — the project names a connection's tools offer, read from the workspace list when the connection is built; a list that cannot be read is offered as its reason, and every call naming a project is then refused with it. */
44
73
  function projectOffer() {
45
74
  try {
@@ -272,6 +301,35 @@ function buildServer(caller, base, offer) {
272
301
  server.tool("agent_stop", "Stop a conversation and free its agent; a later message resumes it.", { id: z.string().min(1) }, ({ id }) => act(() => stopConversation(id)));
273
302
  server.tool("agent_archive", "Archive a conversation: it is stopped and moved off the default list to the Archived list with its transcript kept. agent_list archived=true shows it; a message to it (agent_send or agent_prompt) brings it back and resumes it.", { id: z.string().min(1), restore: z.boolean().default(false).describe("true moves an archived conversation back to the default list instead") }, ({ id, restore }) => act(() => (restore ? unarchiveConversation(id) : archiveConversation(id))));
274
303
  server.tool("agent_delete", "Delete a conversation for good: a running agent is stopped first, then the conversation and its transcript are removed from BN. It cannot be undone — agent_archive keeps the transcript instead.", { id: z.string().min(1) }, ({ id }) => act(() => deleteConversation(id)));
304
+ server.tool("agent_terminals", "The agent CLIs this person has open on this machine (what the CLI page lists) with the CLIs New Agent can open and whether each takes a model; id names one terminal and answers only its facts. A read — it starts nothing.", { id: z.string().min(1).optional().describe("One terminal's conversation id; without it every open terminal is listed beside the CLIs New Agent offers") }, ({ id }) => act(async () => (id === undefined ? terminalListing(personId()) : nativeTerminal(personId(), id).info())));
305
+ server.tool("agent_terminal_open", `New Agent, as the CLI page's button runs it: opens a conversation's own agent CLI and sizes its screen. Name conversation to open the CLI of one that exists (agent_open or agent_start made it); otherwise name BOTH project (exactly one of ${offer.either}) and provider (one of ${PROVIDER_NAMES.join(", ")}) and a new empty conversation is made on them, with no turn and nothing spent.`, {
306
+ conversation: z.string().min(1).optional().describe("An existing conversation id whose own CLI to open"),
307
+ project: projectField(offer).optional(),
308
+ provider: z.string().min(1).optional(),
309
+ model: z.string().min(1).optional(),
310
+ cols: z.number().int().min(1).max(1000).default(100),
311
+ rows: z.number().int().min(1).max(500).default(30),
312
+ }, (body) => act(() => openTerminal(body)));
313
+ server.tool("agent_terminal_close", "Ends a terminal's CLI process, as the CLI page's Close does; the conversation and its transcript stay and a later message resumes it.", { id: z.string().min(1).describe("The terminal's conversation id") }, ({ id }) => act(() => closeNativeTerminal(personId(), id)));
314
+ server.tool("agent_terminal_input", "Types raw keystrokes into a terminal's live CLI — what the CLI page sends for every key, answering a question the CLI waits on included. data is text; binary=true means data is base64 bytes. agent_send is the message door; this one is the keyboard.", { id: z.string().min(1), data: z.string().min(1), binary: z.boolean().default(false) }, ({ id, data, binary }) => act(async () => { await nativeTerminal(personId(), id).input(data, binary); return { id, sent: true }; }));
315
+ server.tool("agent_terminal_resize", "Resizes a terminal's screen to whole columns 1-1000 and rows 1-500, as the CLI page does when its window changes.", { id: z.string().min(1), cols: z.number().int(), rows: z.number().int() }, ({ id, cols, rows }) => act(async () => { const size = dimensions({ cols, rows }); await nativeTerminal(personId(), id).resize(size.cols, size.rows); return { id, ...size }; }));
316
+ server.tool("agent_terminal_files", "Hands files to a terminal's CLI as the CLI page's drop does: each file is written where the CLI can read it and its path is returned, to be named in a message. Each file is a name and its base64 contents.", { id: z.string().min(1), files: z.array(z.object({ name: z.string().min(1), data: z.string() })).min(1) }, ({ id, files }) => act(async () => {
317
+ if (!validFiles(files))
318
+ throw new GatewayError(400, "File transfer failed: expected file names and base64 contents.");
319
+ return { id, paths: await nativeTerminal(personId(), id).inputFiles(files) };
320
+ }));
321
+ server.tool("settings_get", "Everything the Settings page draws, in one reading: the channel state, every group with its rows' current values and next-step line, and the agent-conversation switch. Secrets are returned as stored, as the page shows them to the person who owns this machine.", {}, () => panelAct(() => panelState()));
322
+ server.tool("settings_save", "Saves one Settings row, as the page does: path is the row's key list from settings_get (for example [\"dnd\",\"enabled\"] or [\"telegram\",\"chatIds\"]) and value is checked against that row's kind (on/off, text, list, whole number, HH:MM, days 0-6) before config.json is written and read back. A path that is not a listed row is refused.", { path: z.array(z.string()).min(1), value: z.unknown() }, ({ path, value }) => panelAct(() => saveSetting(path, value)));
323
+ server.tool("conversation_switch", "The agent-conversation On/Off switch the Settings page holds. With no enabled it reads it; enabled=true or false flips it and reads it back. While Off every agent_* act is refused.", { enabled: z.boolean().optional() }, ({ enabled }) => panelAct(() => (enabled === undefined ? conversationSwitchRead() : saveConversationSwitch(enabled))));
324
+ server.tool("public_access", "The Public access wizard's model and its steps. With no step it reads the model. A step is one click: ready (re-look at the machine), createGatewayToken, saveToken (paste = the tunnel token or the command that carries it), install (cloudflared), restartConnector, turnOff, saveHostname (hostname) or check. It answers the model after the step, whose notes say what the step did.", { step: z.enum(["ready", "createGatewayToken", "saveToken", "install", "restartConnector", "turnOff", "saveHostname", "check"]).optional(), paste: z.string().optional(), hostname: z.string().optional() }, ({ step, paste, hostname }) => panelAct(async () => {
325
+ if (step !== undefined)
326
+ await wizard.handle(step, { paste, hostname });
327
+ return wizard.model();
328
+ }));
329
+ server.tool("bn_lifecycle", "BN's own Start, Stop and Restart as the dashboard row and the panel run them. act=state reads the measured state (running, stopped, unreachable ...) with its words and what a Stop would cut. start, stop and restart are pressed in a process that outlives this call — a Stop or Restart ends the process answering you — and the outcome is read afterwards with act=state; a Stop stays until Start. Restart takes and builds the newest main first, exactly as the row does.", { act: z.enum(["state", "start", "stop", "restart"]) }, ({ act: press }) => panelAct(async () => {
330
+ const file = stagedLifecycle();
331
+ return press === "state" ? createRequire(file)(file).row(process.argv[1]).state() : pressLifecycle(file, press);
332
+ }));
275
333
  return server;
276
334
  }
277
335
  const ready = new Map();
@@ -4,12 +4,16 @@ import { closeNativeTerminal, consoleSession, nativeTerminal, nativeTerminals, t
4
4
  import { AgentGateway } from "../agentGateway.js";
5
5
  import { bearer, bearerAdmitted, personId, sessionExpiresAt } from "./passkeyDoor.js";
6
6
  import { PROVIDER_NAMES, providerFor } from "./providers.js";
7
- function dimensions(body) {
7
+ export function dimensions(body) {
8
8
  const cols = Number(body.cols), rows = Number(body.rows);
9
9
  if (!Number.isInteger(cols) || cols <= 0 || cols > 1000 || !Number.isInteger(rows) || rows <= 0 || rows > 500)
10
10
  throw new GatewayError(400, "Terminal size must be whole columns 1-1000 and rows 1-500.");
11
11
  return { cols, rows };
12
12
  }
13
+ /** Whether a transfer names files by name and base64 contents, the one check the socket and the agent_terminal_files tool share. */
14
+ export function validFiles(files) {
15
+ return Array.isArray(files) && files.length > 0 && !files.some((file) => !file || typeof file.name !== "string" || typeof file.data !== "string" || (file.data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(file.data)));
16
+ }
13
17
  export function terminalSockets(server, token) {
14
18
  const sockets = new WebSocketServer({ noServer: true, handleProtocols: () => "bn-terminal" });
15
19
  server.on("upgrade", (req, socket, head) => {
@@ -70,7 +74,7 @@ export function terminalSockets(server, token) {
70
74
  else if (body.kind === "input" && typeof body.data === "string")
71
75
  await terminal.input(body.data, body.binary === true);
72
76
  else if (body.kind === "files") {
73
- if (!Array.isArray(body.files) || !body.files.length || body.files.some((file) => !file || typeof file.name !== "string" || typeof file.data !== "string" || (file.data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(file.data)))) {
77
+ if (!validFiles(body.files)) {
74
78
  ws.send(JSON.stringify({ files: true, error: "File transfer failed: expected file names and base64 contents." }));
75
79
  return;
76
80
  }
@@ -127,6 +131,7 @@ export function terminalSockets(server, token) {
127
131
  * (#3370): another person's id is refused 404 before any byte is streamed.
128
132
  */
129
133
  export async function terminalConsole(req, res, url) {
134
+ requireConversationEnabled();
130
135
  const id = url.pathname.split("/").filter((part) => part.length > 0)[2];
131
136
  const afterRaw = url.searchParams.get("after");
132
137
  const after = afterRaw === null ? undefined : Number(afterRaw);
@@ -198,24 +203,30 @@ function openedNew(id) {
198
203
  throw err;
199
204
  });
200
205
  }
206
+ /** The terminals this person has open with the CLIs New Agent offers: what the page lists and what agent_terminals answers. */
207
+ export async function terminalListing(owner) {
208
+ return { terminals: await nativeTerminals(owner), providers: nativeCatalog() };
209
+ }
210
+ /** New Agent, whole: a conversation made on the CLI and folder the body names (or the one it names), its own CLI opened and sized — what the page's New Agent and agent_terminal_open both run. */
211
+ export async function openTerminal(body) {
212
+ // New Agent makes a conversation exactly as agent_open does — it names BOTH the CLI that runs and the folder it runs
213
+ // in (#3640), neither defaulted — and opens that conversation's own CLI, so a session the browser started and one MCP
214
+ // started are one kind: the same driven CLI, typed into by agent_send and shown here (#3916).
215
+ const terminal = typeof body.conversation === "string" && body.conversation.trim().length > 0 ? await opened(body.conversation.trim()) : await openedNew(newAgent(body));
216
+ const size = dimensions(body);
217
+ await terminal.resize(size.cols, size.rows);
218
+ return terminal.info();
219
+ }
201
220
  export async function terminalRoute(req, url, readJson) {
221
+ requireConversationEnabled();
202
222
  const owner = personId();
203
223
  const parts = url.pathname.split("/").filter(Boolean);
204
224
  const method = req.method;
205
225
  if (parts.length === 2) {
206
226
  if (method === "GET")
207
- return { status: 200, body: { terminals: await nativeTerminals(owner), providers: nativeCatalog() } };
208
- if (method === "POST") {
209
- requireConversationEnabled();
210
- const body = await readJson();
211
- // New Agent makes a conversation exactly as agent_open does — it names BOTH the CLI that runs and the folder it runs
212
- // in (#3640), neither defaulted — and opens that conversation's own CLI, so a session the browser started and one MCP
213
- // started are one kind: the same driven CLI, typed into by agent_send and shown here (#3916).
214
- const terminal = typeof body.conversation === "string" && body.conversation.trim().length > 0 ? await opened(body.conversation.trim()) : await openedNew(newAgent(body));
215
- const size = dimensions(body);
216
- await terminal.resize(size.cols, size.rows);
217
- return { status: 201, body: terminal.info() };
218
- }
227
+ return { status: 200, body: await terminalListing(owner) };
228
+ if (method === "POST")
229
+ return { status: 201, body: await openTerminal(await readJson()) };
219
230
  }
220
231
  const terminal = nativeTerminal(owner, parts[2]);
221
232
  if (parts.length === 3 && method === "DELETE")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.326",
3
+ "version": "1.3.327",
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",