omni-notify-mcp 1.3.346 → 1.3.348

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.
@@ -40,6 +40,9 @@ const CLI_COMMAND_START = /^[!/]/;
40
40
  const ENTER_EVERY_MS = 1_000;
41
41
  // GATE: how many Ctrl+U presses clear one line of text the CLI put back into its input box — measured on Claude CLI 2.1.322: one press empties the line, the next joins it to the line above.
42
42
  const CLEARS_PER_LINE = 2;
43
+ /** A turn that failed because its CLI can no longer run (a key the vendor refused): BN ends the CLI, and whoever holds the session may carry the same turn on a fresh one. */
44
+ export class CliEnded extends AgentTurnFailed {
45
+ }
43
46
  export class CliSession {
44
47
  spec;
45
48
  provider;
@@ -55,6 +58,9 @@ export class CliSession {
55
58
  ending = false;
56
59
  /** The sink of the driver's message from the moment it is asked until it ends — also while it waits behind a prompt typed in the browser — so activity of any prompt counts as the CLI at work. */
57
60
  listening;
61
+ markGone;
62
+ /** Settles once the CLI has ended and everything watching it is let go: a session that moves a turn to a fresh CLI waits on it. */
63
+ gone = new Promise((done) => { this.markGone = done; });
58
64
  constructor(spec, provider, resumes) {
59
65
  this.spec = spec;
60
66
  this.provider = provider;
@@ -82,6 +88,7 @@ export class CliSession {
82
88
  void this.lost(turn.sink).then(turn.reject);
83
89
  }
84
90
  this.spec.onGone();
91
+ this.markGone();
85
92
  });
86
93
  }
87
94
  /** What the turn held beside its Enter presses is let go as it ends. */
@@ -393,7 +400,7 @@ export class LoggedCliSession extends CliSession {
393
400
  const whose = this.open.shift();
394
401
  if (whose === "mine" && turn !== undefined) {
395
402
  if (news.kind === "failed")
396
- this.settle(turn, () => turn.reject(new AgentTurnFailed(news.why, `❌ The agent's turn did not end with an answer: ${news.why}`)));
403
+ this.settle(turn, () => turn.reject(news.endsCli === true ? new CliEnded(news.why) : new AgentTurnFailed(news.why, `❌ The agent's turn did not end with an answer: ${news.why}`)));
397
404
  else if (news.kind === "silent" || news.answer.trim() === "")
398
405
  this.settle(turn, () => turn.reject(new AgentTurnFailed("the agent ended its turn with no text", "❌ The agent ended its turn with no text — nothing was answered.")));
399
406
  else
@@ -24,7 +24,9 @@ function invocation(command, args) {
24
24
  const script = /"%dp0%[\\/]([^"\r\n]+\.m?js)"/i.exec(shim);
25
25
  if (script)
26
26
  return { command: process.execPath, args: [resolve(dirname(executable), script[1]), ...args] };
27
- return { command: process.env.ComSpec || "cmd.exe", args: ["/d", "/s", "/c", '""' + executable + '" ' + args.map((arg) => '"' + arg + '"').join(" ") + '"'] };
27
+ const binary = /^"%dp0%[\\/]([^"\r\n]+\.exe)"[ \t]+%\*[ \t]*$/im.exec(shim);
28
+ if (binary)
29
+ return { command: resolve(dirname(executable), binary[1]), args };
28
30
  }
29
31
  return { command: executable, args };
30
32
  }
@@ -10,8 +10,9 @@
10
10
  *
11
11
  * The CLI runs on the key and store `opencodeRoute` names, chosen when its CLI opens. A key the vendor refuses — a
12
12
  * refusing `session.error`, or the `retry` status the CLI reports while it retries a rate limit in silence — is recorded
13
- * where every switcher reads it, the turn fails naming that key, and the CLI is ended: the next message reopens the
14
- * session with `-s` on a fresh route, which skips the refused key.
13
+ * where every switcher reads it and the CLI is ended; the SAME turn then carries on in a fresh CLI that resumes the
14
+ * session with `-s` on a new route, which skips the refused key, told to carry on from the last message (Meni's ruling
15
+ * on Q808, #4079). With no key left to run on, the turn fails in the route's own words.
15
16
  */
16
17
  import { randomUUID } from "crypto";
17
18
  import { existsSync, mkdirSync, readdirSync, rmSync } from "fs";
@@ -19,7 +20,7 @@ import { homedir } from "os";
19
20
  import { join } from "path";
20
21
  import autoSwitch from "../shared/webhost/autoSwitch.cjs";
21
22
  import { KEY_REFUSAL_STATUSES, KEY_REFUSAL_WORDS } from "../shared/agentSession.js";
22
- import { LoggedCliSession } from "./cliSession.js";
23
+ import { CliEnded, LoggedCliSession } from "./cliSession.js";
23
24
  import { CONFIG_DIR } from "../notify.js";
24
25
  // GATE: the words of a retry status that mean the provider rate-limited THIS key; any other retry (a 5xx, a dropped connection) is the CLI riding out a fault the key did not cause
25
26
  const RATE_LIMITED = /rate.?limit|too many requests/i;
@@ -78,9 +79,9 @@ class OpenCodeLog {
78
79
  ended() {
79
80
  rmSync(this.file, { force: true });
80
81
  }
81
- /** The vendor refused the key this CLI runs on: it is recorded as refused, and the turn fails naming it and ends the CLI. */
82
+ /** The vendor refused the key this CLI runs on: it is recorded as refused, and the turn ends the CLI naming it so the session can carry the turn on the next key. */
82
83
  refused(said) {
83
- const why = `${this.key.named} was refused by the provider (${said}), so BN ended this CLI; the next message continues the session on the next key.`;
84
+ const why = `${this.key.named} was refused by the provider (${said}), so BN moves this turn on to the next key.`;
84
85
  this.key.refuse(said);
85
86
  return [{ kind: "failed", why, endsCli: true }];
86
87
  }
@@ -165,10 +166,84 @@ function opencodeCli(spec) {
165
166
  refusal: () => undefined,
166
167
  };
167
168
  }
169
+ const KEY_RETRY_PROMPT = "The provider refused the key your last reply was being written on, so that reply never arrived. Carry on from the last message.";
170
+ /**
171
+ * One OpenCode conversation: a LoggedCliSession on one key, and the same turn carried on to the next key when the vendor
172
+ * refuses that one — the refused CLI is ended and awaited, a fresh one resumes the session on a new route, and it is told
173
+ * to carry on (or given the original prompt when the refused CLI never wrote a session).
174
+ */
175
+ class OpenCodeSession {
176
+ spec;
177
+ inner;
178
+ /** The session id the CLI wrote, or the record's own when it was already written. */
179
+ written;
180
+ carrying = false;
181
+ stopped = false;
182
+ /** The driver already heard that the CLI running now is gone, so no turn may be carried on in a CLI it no longer tracks. */
183
+ told = false;
184
+ constructor(spec) {
185
+ this.spec = spec;
186
+ this.written = spec.started ? spec.sessionId : undefined;
187
+ this.inner = this.launch();
188
+ }
189
+ launch() {
190
+ this.told = false;
191
+ const own = {
192
+ ...this.spec,
193
+ // NULL-OK: field written is OPTIONAL and therefore it is ok to check for NULL
194
+ started: this.written !== undefined,
195
+ sessionId: this.written ?? this.spec.sessionId,
196
+ onGone: () => {
197
+ if (this.carrying)
198
+ return;
199
+ this.told = true;
200
+ this.spec.onGone();
201
+ },
202
+ learned: (id) => { this.written = id; this.spec.learned(id); },
203
+ };
204
+ return new LoggedCliSession(own, opencodeCli(own));
205
+ }
206
+ get pid() { return this.inner.pid; }
207
+ get working() { return this.inner.working; }
208
+ quiet() { return this.inner.quiet(); }
209
+ end() { this.stopped = true; return this.inner.end(); }
210
+ async ask(prompt, sink, timeoutMs, token) {
211
+ let said = prompt;
212
+ for (;;) {
213
+ try {
214
+ return await this.inner.ask(said, sink, timeoutMs, token);
215
+ }
216
+ catch (err) {
217
+ // OWNER: ITER/LOOP — a key the vendor refused already ended its CLI and is recorded; the same turn runs on the next key, and any other failure, a stop or a cancel is rethrown to the turn's caller
218
+ if (!(err instanceof CliEnded) || this.stopped || this.told || token.isCancellationRequested)
219
+ throw err;
220
+ sink.activity(err.message);
221
+ this.carrying = true;
222
+ try {
223
+ await this.inner.gone;
224
+ if (this.stopped)
225
+ throw err;
226
+ // NULL-OK: field written is OPTIONAL and therefore it is ok to check for NULL
227
+ const before = this.written !== undefined;
228
+ this.inner = this.launch();
229
+ said = before ? KEY_RETRY_PROMPT : prompt;
230
+ }
231
+ catch (failure) {
232
+ this.stopped = true;
233
+ this.spec.onGone();
234
+ throw failure;
235
+ }
236
+ finally {
237
+ this.carrying = false;
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
168
243
  export const opencodeProvider = {
169
244
  name: "opencode",
170
245
  label: "OpenCode",
171
246
  command: "opencode",
172
247
  nativeArgs: (model) => model ? ["-m", model] : [],
173
- open: (spec) => new LoggedCliSession(spec, opencodeCli(spec)),
248
+ open: (spec) => new OpenCodeSession(spec),
174
249
  };
package/dist/notify.js CHANGED
@@ -1024,7 +1024,7 @@ function ingestDropFolder() {
1024
1024
  if (!existsSync(INBOX_DROP_IN_DIR))
1025
1025
  return;
1026
1026
  mkdirSync(INBOX_DROP_CLAIM_DIR, { recursive: true });
1027
- const arrivals = [];
1027
+ const taken = [];
1028
1028
  const unread = [];
1029
1029
  for (const name of readdirSync(INBOX_DROP_IN_DIR).filter((f) => f.endsWith(".json"))) {
1030
1030
  const path = join(INBOX_DROP_IN_DIR, name);
@@ -1032,6 +1032,7 @@ function ingestDropFolder() {
1032
1032
  try {
1033
1033
  if (!claimDrop(marker))
1034
1034
  continue;
1035
+ let queued = false;
1035
1036
  try {
1036
1037
  let raw;
1037
1038
  try {
@@ -1061,11 +1062,12 @@ function ingestDropFolder() {
1061
1062
  rejectDrop(path, name, err instanceof Error ? err.message : String(err));
1062
1063
  continue;
1063
1064
  }
1064
- unlinkSync(path);
1065
- arrivals.push(entry);
1065
+ taken.push({ path, marker, entry });
1066
+ queued = true;
1066
1067
  }
1067
1068
  finally {
1068
- rmSync(marker, { force: true });
1069
+ if (!queued)
1070
+ rmSync(marker, { force: true });
1069
1071
  }
1070
1072
  }
1071
1073
  catch (err) {
@@ -1074,10 +1076,14 @@ function ingestDropFolder() {
1074
1076
  }
1075
1077
  }
1076
1078
  retryUnreadDrops(unread);
1077
- if (arrivals.length === 0)
1079
+ if (taken.length === 0)
1078
1080
  return;
1079
- persistInboxQueue(arrivals);
1080
- log("·", "inbox-drop", `queued ${arrivals.length} message${arrivals.length === 1 ? "" : "s"} from ${INBOX_DROP_IN_DIR}`);
1081
+ persistInboxQueue(taken.map(({ entry }) => entry));
1082
+ for (const { path, marker } of taken) {
1083
+ unlinkSync(path);
1084
+ rmSync(marker, { force: true });
1085
+ }
1086
+ log("·", "inbox-drop", `queued ${taken.length} message${taken.length === 1 ? "" : "s"} from ${INBOX_DROP_IN_DIR}`);
1081
1087
  syncInboxFromDisk();
1082
1088
  }
1083
1089
  function ingestInboxEntry(entry, source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.346",
3
+ "version": "1.3.348",
4
4
  "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.",
5
5
  "main": "dist/daemon.js",
6
6
  "type": "module",