omni-notify-mcp 1.3.477 → 1.3.481

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.
@@ -63,12 +63,14 @@ const boundOf = (key) => listConversations().find((c) => c.chat === key && c.she
63
63
  const sidesOf = (key) => listConversations().filter((c) => c.chat === key && c.forkOf !== undefined && c.state !== "closed" && c.shelf === undefined);
64
64
  /** A conversation in the middle of a turn, or holding a message stored for its next one. */
65
65
  const busy = (c) => turnInFlight(readEvents(c.id), c) !== undefined;
66
- /** The bound chat's main conversation while it is free (#4584); while it is busy undefined, so the message runs at once in a new conversation forked from it and never waits behind the reply under way. */
67
- const freeBound = (key) => {
66
+ /** The busy main conversation a message forks beside (#4584): an OpenCode one never forks, since each fork is a new OpenCode process left behind it, so its message queues on it instead. */
67
+ const forkedFrom = (key) => {
68
68
  const main = boundOf(key);
69
69
  // NULL-OK: field main is OPTIONAL and therefore it is ok to check for NULL
70
- return main === undefined || !busy(main) ? main : undefined;
70
+ return main !== undefined && main.provider !== "opencode" && busy(main) ? main : undefined;
71
71
  };
72
+ /** The bound chat's main conversation, unless it is busy and forks (#4584): then undefined, so the message runs at once in a new conversation forked from it and never waits behind the reply under way. */
73
+ const freeBound = (key) => (forkedFrom(key) === undefined ? boundOf(key) : undefined);
72
74
  /** The bound chat: ONE main conversation at the workspace root, every message goes on with it, or beside it in a fork while it is busy (#4584); a stop pauses the one at work, /new opens the next one at once. */
73
75
  const ONE = {
74
76
  conversationOf: boundOf,
@@ -88,11 +90,7 @@ const ONE = {
88
90
  return `⏹ Stopped${forks === 0 ? "" : `, with ${parallel}`}. Your next message picks the conversation up where it stopped.`;
89
91
  },
90
92
  folderOf: () => rootFolder(),
91
- forkOf: (key) => {
92
- const main = boundOf(key);
93
- // NULL-OK: field main is OPTIONAL and therefore it is ok to check for NULL
94
- return main !== undefined && busy(main) ? main.sessionId : undefined;
95
- },
93
+ forkOf: (key) => forkedFrom(key)?.sessionId,
96
94
  async renew(key, platform, end, provider) {
97
95
  for (const c of ONE.allOf(key)) {
98
96
  end(c.id);
@@ -170,7 +168,9 @@ export class AgentGateway {
170
168
  for (const [turn, sent] of owed) {
171
169
  const pending = readEvents(c.id).filter((e) => e.turn === Number(turn) && e.n > sent && e.role !== "user").map((e) => ({ ...e, id: c.id }));
172
170
  // OWNER: ITER/LOOP — a thread that cannot be reached is shown on its conversation and the next owed turn is still carried on.
173
- void this.awaitTurn(c.id, Number(turn), partsRelay((part) => door(c, part), carriageOf(c.platform, c.chat ?? "")), pending).catch((err) => appendEvent(c.id, { role: "system", kind: "status", text: `❌ The answer could not be sent to this ${c.platform} thread after the BN restart: ${err instanceof Error ? err.message : String(err)}` }));
171
+ const answered = this.awaitTurn(c.id, Number(turn), partsRelay((part) => door(c, part), carriageOf(c.platform, c.chat ?? "")), pending);
172
+ // NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
173
+ void (c.forkOf === undefined ? answered : answered.finally(() => this.end(c.id))).catch((err) => appendEvent(c.id, { role: "system", kind: "status", text: `❌ The answer could not be sent to this ${c.platform} thread after the BN restart: ${err instanceof Error ? err.message : String(err)}` }));
174
174
  }
175
175
  }
176
176
  /** No chat message waiting on its conversation's creation: the gateway can pass to another process without losing one. A turn under way never holds it — the next build takes a cut turn up again on its session and sends its answer to its chat (#2116, #4584). */
@@ -290,9 +290,13 @@ export class AgentGateway {
290
290
  // NULL-OK: field open is OPTIONAL and therefore it is ok to check for NULL
291
291
  const slack = origin.slack !== undefined && open?.slack !== undefined ? { ...origin.slack, readTs: open.slack.readTs } : origin.slack;
292
292
  const turn = {};
293
- const [creation] = await Promise.allSettled([createdIn(project, act.kind === "say" ? act.provider : undefined, () => key, (on) => {
293
+ // NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
294
+ const provider = forkOf !== undefined ? open.provider : act.kind === "say" ? act.provider : undefined;
295
+ const [creation] = await Promise.allSettled([createdIn(project, provider, () => key, (on) => {
294
296
  const created = startConversation({ platform, chat: key, slack, email: origin.email, ...on, forkOf, text: act.text, receivedMs: monotonicMs() - arrived });
295
- turn.answered = this.awaitTurn(created.id, 1, relayOf(created.id, 1, false, forkOf !== undefined));
297
+ const answered = this.awaitTurn(created.id, 1, relayOf(created.id, 1, false, forkOf !== undefined));
298
+ // NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
299
+ turn.answered = forkOf === undefined ? answered : answered.finally(() => this.end(created.id));
296
300
  turn.id = created.id;
297
301
  return created;
298
302
  })]);
@@ -421,8 +425,9 @@ export function chatTurnText(key, text, context) {
421
425
  if (bound === undefined)
422
426
  return [brief, ...context, text].join("\n\n");
423
427
  // A message beside a main conversation whose session is not written yet runs in a session of its own, which has not had the brief.
424
- const first = !readEvents(bound.id).some((e) => e.role === "user") || (busy(bound) && !bound.started);
425
- return [...(first ? [brief] : []), ...answeredBeside(key, bound), ...(busy(bound) ? [BESIDE] : []), ...context, text].join("\n\n");
428
+ const beside = forkedFrom(key) !== undefined;
429
+ const first = !readEvents(bound.id).some((e) => e.role === "user") || (beside && !bound.started);
430
+ return [...(first ? [brief] : []), ...answeredBeside(key, bound), ...(beside ? [BESIDE] : []), ...context, text].join("\n\n");
426
431
  }
427
432
  /** The Claude CLI's own folder of session transcripts. */
428
433
  function claudeProjects() {
@@ -1,59 +1,59 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { spawn } = require("child_process");
6
-
7
- const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
8
-
9
- function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
10
- return [
11
- deploy,
12
- "--domain", domain,
13
- ...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
14
- // NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
15
- "--project-root", projectRoot ?? home,
16
- "--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
17
- "--notify-dir", doorsDir,
18
- ];
19
- }
20
-
21
- function runDeploy({ node, args, cwd, env, onOutput }) {
22
- return new Promise((resolve, reject) => {
23
- const child = spawn(node, args, { windowsHide: true, cwd, env });
24
- child.stdout.on("data", (chunk) => onOutput(String(chunk)));
25
- child.stderr.on("data", (chunk) => onOutput(String(chunk)));
26
- child.on("error", reject);
27
- child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
28
- });
29
- }
30
-
31
- const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
32
-
33
- function writeRecord(file, record) {
34
- const staged = `${file}.${process.pid}.tmp`;
35
- fs.writeFileSync(staged, JSON.stringify(record, null, 2));
36
- try {
37
- fs.renameSync(staged, file);
38
- } catch (err) {
39
- fs.rmSync(staged, { force: true });
40
- throw err;
41
- }
42
- }
43
-
44
- async function runRecorded(recordFile, recordText) {
45
- const record = { ...JSON.parse(recordText), pid: process.pid };
46
- const log = recordFile.replace(/\.json$/, ".log");
47
- const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
48
- try {
49
- const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
50
- write({ endedAt: new Date().toISOString(), ...ended });
51
- } catch (err) {
52
- // OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
53
- write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
54
- }
55
- }
56
-
57
- if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
58
-
59
- module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { spawn } = require("child_process");
6
+
7
+ const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
8
+
9
+ function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
10
+ return [
11
+ deploy,
12
+ "--domain", domain,
13
+ ...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
14
+ // NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
15
+ "--project-root", projectRoot ?? home,
16
+ "--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
17
+ "--notify-dir", doorsDir,
18
+ ];
19
+ }
20
+
21
+ function runDeploy({ node, args, cwd, env, onOutput }) {
22
+ return new Promise((resolve, reject) => {
23
+ const child = spawn(node, args, { windowsHide: true, cwd, env });
24
+ child.stdout.on("data", (chunk) => onOutput(String(chunk)));
25
+ child.stderr.on("data", (chunk) => onOutput(String(chunk)));
26
+ child.on("error", reject);
27
+ child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
28
+ });
29
+ }
30
+
31
+ const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
32
+
33
+ function writeRecord(file, record) {
34
+ const staged = `${file}.${process.pid}.tmp`;
35
+ fs.writeFileSync(staged, JSON.stringify(record, null, 2));
36
+ try {
37
+ fs.renameSync(staged, file);
38
+ } catch (err) {
39
+ fs.rmSync(staged, { force: true });
40
+ throw err;
41
+ }
42
+ }
43
+
44
+ async function runRecorded(recordFile, recordText) {
45
+ const record = { ...JSON.parse(recordText), pid: process.pid };
46
+ const log = recordFile.replace(/\.json$/, ".log");
47
+ const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
48
+ try {
49
+ const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
50
+ write({ endedAt: new Date().toISOString(), ...ended });
51
+ } catch (err) {
52
+ // OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
53
+ write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
54
+ }
55
+ }
56
+
57
+ if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
58
+
59
+ module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
package/dist/notify.js CHANGED
@@ -1196,11 +1196,16 @@ function bindTelegramChat(chat) {
1196
1196
  throw new Error(`the binding to chat ${chat} did not hold in ${CONFIG_PATH}`);
1197
1197
  log("·", "telegram", `this bot is bound to chat ${chat}: every message from it reaches the BN conversation, every other sender is refused`);
1198
1198
  }
1199
- const TELEGRAM_PROVIDER = "opencode";
1199
+ /** Telegram runs on the CLI `telegram.provider` in config.json names, else on the shared subscription-first pick (Claude while its subscription has room, then the next with room; a refusal says why). */
1200
+ const TELEGRAM_PROVIDERS = ["claude", "codex", "copilot", "opencode"];
1201
+ function telegramProvider() {
1202
+ const named = loadConfig().telegram?.provider;
1203
+ return typeof named === "string" && TELEGRAM_PROVIDERS.includes(named) ? named : undefined;
1204
+ }
1200
1205
  function setTelegramProvider(name) {
1201
1206
  if (name === undefined)
1202
- return `🤖 Provider for new conversations: ${TELEGRAM_PROVIDER} (fixed)`;
1203
- return `❌ Telegram always runs on ${TELEGRAM_PROVIDER}; /provider cannot change it.`;
1207
+ return `🤖 Provider for new conversations: ${telegramProvider() ?? "the subscription with room"} (set telegram.provider in config.json to change it)`;
1208
+ return `❌ Telegram runs on ${telegramProvider() ?? "the subscription with room"}; /provider cannot change it - set telegram.provider in config.json.`;
1204
1209
  }
1205
1210
  const storyTopics = new StoryTopics(join(CONFIG_DIR, "story-topics.json"));
1206
1211
  const topicCalls = (token) => ({ call: (method, body) => telegramCall(tgApi(token, method), method, body) });
@@ -1236,7 +1241,7 @@ function openAsksContext() {
1236
1241
  /** One said thing of the bound chat goes to its one conversation, its turn streamed back into the chat. */
1237
1242
  function toTelegramConversation(token, chat, act, thread, replyTo) {
1238
1243
  // #4586 — a topic is its own conversation (the story's); the plain chat keeps its one.
1239
- const routed = act.kind === "stop" ? act : { ...act, provider: TELEGRAM_PROVIDER };
1244
+ const routed = act.kind === "stop" ? act : { ...act, provider: telegramProvider() };
1240
1245
  toOneChat(thread === undefined ? `telegram:${chat}` : `telegram:${chat}:${thread}`, "telegram", routed, telegramMessenger(token, chat, thread, replyTo));
1241
1246
  }
1242
1247
  /** One said thing of one of Meni's one chats — Telegram, or his Slack direct message — goes to its one conversation, its turn streamed back into that chat. */