omni-notify-mcp 1.3.359 → 1.3.361

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.
@@ -1,8 +1,10 @@
1
1
  import { execFile, spawn, spawnSync } from "node:child_process";
2
2
  import { createHash } from "node:crypto";
3
3
  import * as fs from "node:fs";
4
+ import { Agent } from "node:http";
4
5
  import { homedir, tmpdir } from "node:os";
5
6
  import * as path from "node:path";
7
+ import { Duplex } from "node:stream";
6
8
  export function isProcessAlive(pid) {
7
9
  try {
8
10
  process.kill(pid, 0);
@@ -176,6 +178,258 @@ export function ownerBoundLaunch(invocation, ownerPid, cwd, guardDir) {
176
178
  args: [path.join(guardDir, "ownerGuard.cjs"), String(ownerPid), encoded(invocation.cmd), encoded(JSON.stringify(invocation.args)), encoded(cwd)],
177
179
  };
178
180
  }
181
+ // GATE: how long one request to the native Codex daemon may take before it is refused with that wait named — the daemon answers these in well under a second
182
+ const CODEX_REQUEST_MS = 10_000;
183
+ // GATE: how long one Codex CLI command (`login status`, `app-server daemon start`) may run before its tree is ended and refused with that wait named — each answers in about a second
184
+ const CODEX_CLI_MS = 60_000;
185
+ /** 🔴 #3951 — the Codex CLI or its daemon could not be reached, refused a request, or answered outside its documented outcomes; the message carries its words. */
186
+ export class CodexControlFailed extends Error {
187
+ }
188
+ /** The native Codex daemon answered a request with an error, so what it was asked was not done. */
189
+ export class CodexRefused extends CodexControlFailed {
190
+ }
191
+ /**
192
+ * 🔴 #3504/#3951 — THE ONE CONTROL OF THE NATIVE CODEX DAEMON every Bullseye host shares: FleetView's window posts a press into
193
+ * a Codex main through it, and a host with no window brings the daemon up, reuses the board's live Codex main or opens ONE,
194
+ * and posts into it the same way (Meni, Q796: "Service creates one Codex main, then posts"). It speaks the daemon's own
195
+ * app-server protocol over `codex app-server proxy`, bound to this process by the owner guard, so it never runs a second
196
+ * app server or a `codex exec`.
197
+ */
198
+ export class CodexControl {
199
+ proxy;
200
+ socket;
201
+ opening;
202
+ nextId = 0;
203
+ generation = 0;
204
+ pending = new Map();
205
+ project;
206
+ guardDir;
207
+ cli;
208
+ constructor(project, guardDir, cli = { cmd: "codex", args: [] }) {
209
+ this.project = project;
210
+ this.guardDir = guardDir;
211
+ this.cli = cli;
212
+ }
213
+ /** The Codex CLI's own word on this box's sign-in: signed in, not signed in, or not installed — anything else it says is refused. */
214
+ async login() {
215
+ const ran = await this.run(["login", "status"]);
216
+ if (ran.code === 0)
217
+ return { signedIn: true };
218
+ if (ran.code === 1 && /not logged in/i.test(ran.said))
219
+ return { signedIn: false, why: `the Codex CLI on this box is not signed in ("codex login status" says: ${ran.said.split(/\r?\n/).pop()})` };
220
+ if (ran.code === 96 || ran.code === 127)
221
+ return { signedIn: false, why: `the Codex CLI could not be started on this box, so no Codex login exists here (${ran.said})` };
222
+ throw new CodexControlFailed(`"codex login status" ended ${ran.code}: ${ran.said || "it printed nothing"}`);
223
+ }
224
+ /** The native daemon running on this box: started when it is not, left alone when it is (`codex app-server daemon start` is both). */
225
+ async daemonUp() {
226
+ const ran = await this.run(["app-server", "daemon", "start"]);
227
+ if (ran.code !== 0)
228
+ throw new CodexControlFailed(`"codex app-server daemon start" ended ${ran.code}: ${ran.said || "it printed nothing"}`);
229
+ }
230
+ /** Every Codex main the daemon holds loaded right now, each with the threads it spawned and whether it is mid-turn. */
231
+ async mains() {
232
+ await this.open();
233
+ const loaded = (await this.request("thread/loaded/list", {}));
234
+ const threads = await Promise.all(loaded.data.map(async (threadId) => (await this.request("thread/read", { threadId, includeTurns: false })).thread));
235
+ const rootOf = (thread) => {
236
+ const seen = new Set();
237
+ let current = thread;
238
+ while (!seen.has(current.id)) {
239
+ seen.add(current.id);
240
+ const parentId = typeof current.source === "object" ? current.source.subAgent?.thread_spawn?.parent_thread_id : undefined;
241
+ if (parentId === undefined)
242
+ return current.id;
243
+ const parent = threads.find((candidate) => candidate.id === parentId);
244
+ if (parent === undefined)
245
+ return parentId;
246
+ current = parent;
247
+ }
248
+ throw new CodexControlFailed("the native Codex daemon reported a cycle in its parent links");
249
+ };
250
+ return threads
251
+ .filter((thread) => thread.source === "vscode" || thread.source === "cli")
252
+ .map((thread) => ({
253
+ threadId: thread.id,
254
+ cwd: thread.cwd,
255
+ // NULL-OK: field name is OPTIONAL and therefore it is ok to check for NULL
256
+ name: thread.name ?? `Codex ${thread.id.slice(0, 8)}`,
257
+ ownedThreadIds: threads.filter((child) => child.id !== thread.id && rootOf(child) === thread.id).map((child) => child.id),
258
+ working: thread.status.type === "active",
259
+ }));
260
+ }
261
+ /** A new Codex main opened in `cwd` under `name` — the one a host with no live Codex main for its board opens, idle until a press is posted into it. */
262
+ async startMain(cwd, name) {
263
+ await this.open();
264
+ const started = (await this.request("thread/start", { cwd }));
265
+ await this.request("thread/name/set", { threadId: started.thread.id, name });
266
+ return { threadId: started.thread.id, cwd: started.thread.cwd, name, ownedThreadIds: [], working: false };
267
+ }
268
+ /**
269
+ * 🔴 #3951 — THE ONE CODEX MAIN OF A BOARD, for a host with no window (Meni, Q796: "Service creates one Codex main, then
270
+ * posts"): the daemon is brought up, a live Codex main whose folder `reaches` is reused, and only when none is alive is ONE
271
+ * opened in `cwd` under `name`.
272
+ */
273
+ async mainFor(reaches, cwd, name) {
274
+ await this.daemonUp();
275
+ const live = (await this.mains()).find((m) => reaches(m.cwd));
276
+ // NULL-OK: field live is OPTIONAL and therefore it is ok to check for NULL
277
+ return live !== undefined ? { main: live, opened: false } : { main: await this.startMain(cwd, name), opened: true };
278
+ }
279
+ /** `message` posted into the main's thread as his next turn: steered into the turn it is running, else started as a new one; `beforeSend` runs right before it goes and may refuse it by throwing. */
280
+ async post(threadId, message, beforeSend = () => { }) {
281
+ await this.open();
282
+ const input = [{ type: "text", text: message }];
283
+ const active = await this.activeTurn(threadId);
284
+ beforeSend();
285
+ if (active !== undefined)
286
+ await this.request("turn/steer", { threadId, expectedTurnId: active.id, input });
287
+ else
288
+ await this.request("turn/start", { threadId, input });
289
+ }
290
+ dispose() {
291
+ ++this.generation;
292
+ this.failPending(new CodexControlFailed("the native Codex control connection was closed by its owner"));
293
+ this.socket?.terminate();
294
+ this.proxy?.kill();
295
+ this.socket = undefined;
296
+ this.opening = undefined;
297
+ }
298
+ /** The CLI behind this process's owner guard, which also finds the CLI's .cmd shim on Windows. */
299
+ bound(invocation) {
300
+ return ownerBoundLaunch(invocation, process.pid, this.project, this.guardDir);
301
+ }
302
+ run(args) {
303
+ const launch = this.bound({ cmd: this.cli.cmd, args: [...this.cli.args, ...args] });
304
+ return new Promise((resolve, reject) => {
305
+ const child = spawn(launch.cmd, launch.args, { cwd: this.project, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" } });
306
+ let said = "";
307
+ child.stdout.on("data", (chunk) => (said += chunk.toString("utf8")));
308
+ child.stderr.on("data", (chunk) => (said += chunk.toString("utf8")));
309
+ const bound = setTimeout(() => {
310
+ killTree(child);
311
+ reject(new CodexControlFailed(`"codex ${args.join(" ")}" did not end within ${CODEX_CLI_MS / 1000} seconds, so its process tree was ended: ${said.trim() || "it printed nothing"}`));
312
+ }, CODEX_CLI_MS);
313
+ child.on("error", (cause) => {
314
+ clearTimeout(bound);
315
+ reject(cause);
316
+ });
317
+ child.on("exit", (code, signal) => {
318
+ clearTimeout(bound);
319
+ if (code === null)
320
+ reject(new CodexControlFailed(`"codex ${args.join(" ")}" was ended by ${signal}: ${said.trim() || "it printed nothing"}`));
321
+ else
322
+ resolve({ code, said: said.trim() });
323
+ });
324
+ });
325
+ }
326
+ open() {
327
+ // NULL-OK: field opening is OPTIONAL and therefore it is ok to check for NULL
328
+ if (this.opening !== undefined)
329
+ return this.opening;
330
+ if (this.socket !== undefined && this.socket.readyState === this.socket.OPEN)
331
+ return Promise.resolve();
332
+ const generation = ++this.generation;
333
+ this.opening = import("ws").then(({ default: Socket }) => new Promise((resolve, reject) => {
334
+ const launch = this.bound({ cmd: this.cli.cmd, args: [...this.cli.args, "app-server", "proxy"] });
335
+ const proxy = (this.proxy = spawn(launch.cmd, launch.args, { cwd: this.project, windowsHide: true, stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" } }));
336
+ const stream = Duplex.from({ readable: proxy.stdout, writable: proxy.stdin });
337
+ const connection = Object.assign(stream, { connecting: false, setTimeout: () => stream, setNoDelay: () => stream, setKeepAlive: () => stream });
338
+ const agent = new Agent();
339
+ agent.createConnection = () => connection;
340
+ const socket = (this.socket = new Socket("ws://localhost/", { agent, handshakeTimeout: CODEX_REQUEST_MS }));
341
+ let said = "";
342
+ proxy.stderr.on("data", (chunk) => (said += chunk.toString("utf8")));
343
+ const ended = new Promise((done) => {
344
+ proxy.once("exit", (code) => done(`the native Codex control proxy ended (exit ${code}): ${said.trim() || "it printed nothing"}`));
345
+ proxy.once("error", (cause) => done(`the native Codex control proxy could not be started: ${cause.message}`));
346
+ });
347
+ let initialized = false;
348
+ const failed = (cause) => {
349
+ if (!initialized)
350
+ void ended.then((why) => reject(new CodexControlFailed(`${cause.message}; ${why}`)));
351
+ if (this.generation === generation) {
352
+ this.socket = undefined;
353
+ this.failPending(cause instanceof CodexControlFailed ? cause : new CodexControlFailed(`the native Codex control connection failed: ${cause.message}`));
354
+ }
355
+ socket.terminate();
356
+ proxy.kill();
357
+ };
358
+ proxy.on("error", failed);
359
+ stream.on("error", failed);
360
+ proxy.on("exit", () => failed(new CodexControlFailed("the native Codex control proxy exited")));
361
+ socket.on("error", failed);
362
+ socket.on("close", () => failed(new CodexControlFailed("the native Codex control connection closed")));
363
+ socket.on("message", (data) => {
364
+ if (this.generation !== generation)
365
+ return;
366
+ let message;
367
+ try {
368
+ message = JSON.parse(data.toString());
369
+ }
370
+ catch (cause) {
371
+ if (!(cause instanceof SyntaxError))
372
+ throw cause;
373
+ failed(cause);
374
+ return;
375
+ }
376
+ // NULL-OK: field id is OPTIONAL and therefore it is ok to check for NULL
377
+ if (message.id === undefined)
378
+ return;
379
+ const pending = this.pending.get(message.id);
380
+ // NULL-OK: field pending is OPTIONAL and therefore it is ok to check for NULL
381
+ if (pending === undefined)
382
+ return;
383
+ clearTimeout(pending.timer);
384
+ this.pending.delete(message.id);
385
+ // NULL-OK: field error is OPTIONAL and therefore it is ok to check for NULL
386
+ if (message.error !== undefined)
387
+ pending.reject(new CodexRefused(message.error.message));
388
+ else
389
+ pending.resolve(message.result);
390
+ });
391
+ socket.once("open", () => {
392
+ void this.request("initialize", { clientInfo: { name: "bullseye", version: "1.0.0" }, capabilities: { experimentalApi: true } }).then(() => {
393
+ socket.send(JSON.stringify({ method: "initialized", params: {} }));
394
+ initialized = true;
395
+ resolve();
396
+ }, failed);
397
+ });
398
+ })).finally(() => {
399
+ if (this.generation === generation)
400
+ this.opening = undefined;
401
+ });
402
+ return this.opening;
403
+ }
404
+ failPending(cause) {
405
+ for (const pending of this.pending.values()) {
406
+ clearTimeout(pending.timer);
407
+ pending.reject(cause);
408
+ }
409
+ this.pending.clear();
410
+ }
411
+ request(method, params) {
412
+ const socket = this.socket;
413
+ if (socket === undefined || socket.readyState !== socket.OPEN)
414
+ return Promise.reject(new CodexControlFailed("the native Codex control connection is not open"));
415
+ const id = ++this.nextId;
416
+ return new Promise((resolve, reject) => {
417
+ const timer = setTimeout(() => {
418
+ this.pending.delete(id);
419
+ reject(new CodexControlFailed(`native Codex ${method} did not answer within ${CODEX_REQUEST_MS / 1000} seconds`));
420
+ }, CODEX_REQUEST_MS);
421
+ this.pending.set(id, { resolve, reject, timer });
422
+ socket.send(JSON.stringify({ id, method, params }));
423
+ });
424
+ }
425
+ async activeTurn(threadId) {
426
+ const { thread } = (await this.request("thread/read", { threadId, includeTurns: false }));
427
+ if (thread.status.type !== "active")
428
+ return undefined;
429
+ const turns = (await this.request("thread/turns/list", { threadId, limit: 1, sortDirection: "desc", itemsView: "notLoaded" }));
430
+ return turns.data.find((turn) => turn.status === "inProgress");
431
+ }
432
+ }
179
433
  // GATE: how long a CLI tree gets to exit on SIGTERM before it is SIGKILLed — POSIX only; Windows stops it at once
180
434
  const KILL_GRACE_MS = 2_000;
181
435
  export function killTree(child) {
@@ -1614,8 +1868,17 @@ export function requestedStories(board) {
1614
1868
  return [];
1615
1869
  return fs.readdirSync(dir).filter((f) => /^\d+\.json$/.test(f)).map((f) => Number(f.slice(0, -".json".length)));
1616
1870
  }
1871
+ /** 🔴 #3951 — every story FleetView's story queue stopped on the board, with the queue's own words: the ack that answers its standing request reads `failed`. */
1872
+ export function storyQueueStops(board) {
1873
+ return requestedStories(board).flatMap((id) => {
1874
+ const ack = readStoryAck(board, id);
1875
+ return ack?.state === "failed" && ack.requestId === readStoryRequest(board, id)?.requestId ? [[id, `FleetView's story queue could not start it: ${ack.why}`]] : [];
1876
+ });
1877
+ }
1617
1878
  // GATE: how long a request no ack names waits before BB writes it again — FV acks within one beat, so past this the request or its ack was lost, or FV is down
1618
1879
  export const ACK_LATE_MS = 60_000;
1880
+ // GATE: how long an unacknowledged request may stand before the board's OWN SURFACE says FleetView has not answered it — a reading of the page's words, never a re-send, so a beat that lags no longer tells Meni FleetView is down while it is working
1881
+ export const ACK_LATE_SAID_MS = 2 * 60 * 60_000;
1619
1882
  /**
1620
1883
  * BB's ONE scheduling act: the story's request written beside the board. A request FV already acknowledged is left alone;
1621
1884
  * one waiting on its ack is written again once {@link ACK_LATE_MS} has passed (a lost request or a lost ack); a press's
@@ -1761,8 +2024,8 @@ function refusalOf(r) {
1761
2024
  return `priority "${r.pri}" is none of ${PRI_ORDER.join(" ")}`;
1762
2025
  if (rankIn(EFFORT_ORDER, r.effort) === -1)
1763
2026
  return `size "${r.effort}" is none of ${EFFORT_ORDER.join(" ")}`;
1764
- if (r.eligible && r.provider !== "claude")
1765
- return `provider "${r.provider}" is not started by this queue — a Codex-owned story goes to FleetView's one Codex main (#3951), never to a worker of its own`;
2027
+ if (r.eligible && r.provider !== "claude" && r.provider !== "codex")
2028
+ return `provider "${r.provider}" is not started by this queue — it starts Claude workers and posts Codex-owned stories into the board's one Codex main`;
1766
2029
  return undefined;
1767
2030
  }
1768
2031
  /** One request applied to the store: an entry made, updated, withdrawn or put back in line; answers the refusal when it cannot be queued. */
@@ -1807,15 +2070,30 @@ function applyRequest(store, r, now) {
1807
2070
  }
1808
2071
  /** The provider refused to start a story's worker: its own words, which the entry carries and the queue starts again on its backoff. */
1809
2072
  export class WorkerNotStarted extends Error {
1810
- constructor(message) {
2073
+ /** Whether the queue starts it again on its backoff. */
2074
+ retried = true;
2075
+ /** Whether the provider answered that the start never reached it, so a worker recorded right before the send stands for nothing. */
2076
+ unsent;
2077
+ constructor(message, unsent = false) {
1811
2078
  super(message);
2079
+ this.unsent = unsent;
1812
2080
  this.name = "WorkerNotStarted";
1813
2081
  }
1814
2082
  }
1815
- // GATE: how many times one story's worker is started before its entry stops in `failed` with the reason — each start that ends with the story still open is one
2083
+ /** 🔴 #3951 — the provider cannot start the story as this box stands (its CLI has no login): the entry stops `failed` with the provider's words at once, spends no attempt, and the box is read again after {@link RETRY_BASE_MS}, so a login made later starts it. */
2084
+ export class WorkerRefused extends WorkerNotStarted {
2085
+ retried = false;
2086
+ constructor(message) {
2087
+ super(message);
2088
+ this.name = "WorkerRefused";
2089
+ }
2090
+ }
2091
+ // GATE: how many times one story's worker is started before the queue gives up on it and its entry stops in `failed` — each start that ends with the story still open is one
1816
2092
  export const WORKER_ATTEMPTS = 3;
1817
2093
  // GATE: the wait before a story whose worker ended is started again: this, doubled for each earlier attempt
1818
2094
  export const RETRY_BASE_MS = 60_000;
2095
+ // GATE: the wait before a story the queue gave up on is offered to the line again: this, doubled for each start past WORKER_ATTEMPTS
2096
+ export const REARM_BASE_MS = RETRY_BASE_MS * 2 ** WORKER_ATTEMPTS;
1819
2097
  /** The acks the passes' requests call for: one per request read, carrying its entry's state and place, rewritten only when one of them changed. */
1820
2098
  function writeAcks(board, store, refusals, applied, now) {
1821
2099
  const order = queueOrder(store);
@@ -1834,14 +2112,22 @@ function writeAcks(board, store, refusals, applied, now) {
1834
2112
  writeWhole(board, ackFile(board, storyId), ack);
1835
2113
  }
1836
2114
  }
1837
- /** A worker that ended with its story still open: started again after its backoff, or stopped in `failed` past {@link WORKER_ATTEMPTS}. */
1838
- function afterWorker(e, now, why) {
2115
+ /** A worker that ended with its story still open: started again after its backoff, stopped in `failed` past {@link WORKER_ATTEMPTS}, or at once when its provider refused it as the box stands (`retried` false), read again after the first backoff. */
2116
+ function afterWorker(e, now, why, retried = true) {
1839
2117
  if (!e.eligible) {
1840
2118
  e.state = "withdrawn";
1841
2119
  step(e, now, "withdrawn", e.why);
1842
2120
  }
2121
+ else if (!retried) {
2122
+ e.state = "failed";
2123
+ e.attempts -= 1;
2124
+ e.nextTryAt = now + RETRY_BASE_MS;
2125
+ e.why = `${why}; the box is read again at ${new Date(e.nextTryAt).toISOString()}`;
2126
+ step(e, now, "failed", e.why);
2127
+ }
1843
2128
  else if (e.attempts >= WORKER_ATTEMPTS) {
1844
2129
  e.state = "failed";
2130
+ delete e.nextTryAt;
1845
2131
  e.why = `its worker was started ${e.attempts} times and the story is still open — the last: ${why}`;
1846
2132
  step(e, now, "failed", e.why);
1847
2133
  }
@@ -1900,6 +2186,18 @@ export async function driveStoryQueue(board, world, now) {
1900
2186
  step(e, now, "closed", closed);
1901
2187
  continue;
1902
2188
  }
2189
+ if (e.state === "failed") {
2190
+ const gaveUp = e.trace.filter((t) => t.stage === "failed").pop();
2191
+ if (!e.eligible || gaveUp === undefined)
2192
+ continue;
2193
+ if (now - gaveUp.at < REARM_BASE_MS * 2 ** (e.attempts - WORKER_ATTEMPTS))
2194
+ continue;
2195
+ e.state = "queued";
2196
+ delete e.nextTryAt;
2197
+ e.why = `the queue gave up on it ${Math.round((now - gaveUp.at) / 60_000)}m ago and the story is still open, so it is offered to the line again`;
2198
+ step(e, now, "retry", e.why);
2199
+ continue;
2200
+ }
1903
2201
  if (e.state !== "starting" && e.state !== "running")
1904
2202
  continue;
1905
2203
  const w = world.worker(e, board);
@@ -1924,7 +2222,8 @@ export async function driveStoryQueue(board, world, now) {
1924
2222
  save();
1925
2223
  let lanes = world.lanesRunning();
1926
2224
  for (const e of queueOrder(store)) {
1927
- if (!e.eligible || !(e.state === "queued" || (e.state === "retrying" && e.nextTryAt <= now)))
2225
+ // NULL-OK: field nextTryAt is OPTIONAL and therefore it is ok to check for NULL
2226
+ if (!e.eligible || !(e.state === "queued" || ((e.state === "retrying" || e.state === "failed") && e.nextTryAt !== undefined && e.nextTryAt <= now)))
1928
2227
  continue;
1929
2228
  const held = world.heldBy(e.storyId);
1930
2229
  if (held !== undefined) {
@@ -1945,17 +2244,22 @@ export async function driveStoryQueue(board, world, now) {
1945
2244
  e.state = "starting";
1946
2245
  e.attempts += 1;
1947
2246
  delete e.worker;
1948
- step(e, now, "selected", `start ${e.attempts} of ${WORKER_ATTEMPTS}, with ${lanes} of ${world.limit} lanes running`);
2247
+ step(e, now, "selected", `start ${e.attempts}${e.attempts > WORKER_ATTEMPTS ? ", past the attempts a story is given" : ` of ${WORKER_ATTEMPTS}`}, with ${lanes} of ${world.limit} lanes running`);
1949
2248
  save();
1950
2249
  lanes += 1;
1951
2250
  try {
1952
- e.worker = await world.launch(e, board);
2251
+ e.worker = await world.launch(e, board, (sent) => {
2252
+ e.worker = sent;
2253
+ save();
2254
+ });
1953
2255
  e.why = `its ${e.provider} worker ${e.worker.jobId} was started`;
1954
2256
  step(e, Date.now(), "started", e.why);
1955
2257
  }
1956
2258
  catch (err) {
1957
2259
  if (!(err instanceof WorkerNotStarted))
1958
2260
  throw err;
2261
+ if (err.unsent)
2262
+ delete e.worker;
1959
2263
  const made = world.worker(e, board);
1960
2264
  // NULL-OK: field found is OPTIONAL and therefore it is ok to check for NULL
1961
2265
  if (made.alive && made.found !== undefined) {
@@ -1966,10 +2270,10 @@ export async function driveStoryQueue(board, world, now) {
1966
2270
  save();
1967
2271
  continue;
1968
2272
  }
1969
- // OWNER: ITER/LOOP — the provider refused this story's start, so its entry carries the provider's words and is started again on its backoff like a worker that ended; the next entry in line is started.
2273
+ // OWNER: ITER/LOOP — the provider refused this story's start, so its entry carries the provider's words and is started again on its backoff like a worker that ended, or stops failed when the provider refused it for good; the next entry in line is started.
1970
2274
  lanes -= 1;
1971
2275
  step(e, Date.now(), "worker-ended", `its ${e.provider} worker could not be started: ${err.message}`);
1972
- afterWorker(e, now, `its ${e.provider} worker could not be started: ${err.message}`);
2276
+ afterWorker(e, now, `its ${e.provider} worker could not be started: ${err.message}`, err.retried);
1973
2277
  }
1974
2278
  save();
1975
2279
  }
@@ -2093,3 +2397,26 @@ export function launchStoryWorker(entry, board, cli, now) {
2093
2397
  });
2094
2398
  });
2095
2399
  }
2400
+ /**
2401
+ * 🔴 #3951 — A CODEX-OWNED STORY'S START (Meni, Q796: "Service creates one Codex main, then posts"): the box's Codex login is
2402
+ * read, a live Codex main whose folder `reaches` the board is reused or ONE is opened in the board's folder under `name`, and
2403
+ * `message` is posted into it — never a Claude chat, a `codex exec` or a second app server; `record` is handed the worker right
2404
+ * before the post is sent. No login is {@link WorkerRefused}; a daemon that cannot be reached or refuses is
2405
+ * {@link WorkerNotStarted}, started again on the queue's backoff.
2406
+ */
2407
+ export async function postCodexStory(control, board, reaches, name, message, now, record) {
2408
+ try {
2409
+ const login = await control.login();
2410
+ if (!login.signedIn)
2411
+ throw new WorkerRefused(login.why);
2412
+ const { main } = await control.mainFor(reaches, board, name);
2413
+ const worker = { provider: "codex", startedAt: now, jobId: main.threadId };
2414
+ await control.post(main.threadId, message, () => record(worker));
2415
+ return worker;
2416
+ }
2417
+ catch (err) {
2418
+ if (!(err instanceof CodexControlFailed))
2419
+ throw err;
2420
+ throw new WorkerNotStarted(err.message, err instanceof CodexRefused);
2421
+ }
2422
+ }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const crypto = require("crypto");
2
3
  const fs = require("fs");
3
4
  const http = require("http");
4
5
  const os = require("os");
@@ -66,6 +67,43 @@ function takeStartLock(origin) {
66
67
  }
67
68
  return undefined;
68
69
  }
70
+ /** Whether `file` exists, asked without blocking the event loop; any failure but "not there" is thrown. */
71
+ const existsAsync = (file) => fs.promises.access(file).then(() => true, (failed) => {
72
+ if (failed.code === "ENOENT")
73
+ return false;
74
+ throw failed;
75
+ });
76
+ /** Writes `content` (text or bytes) to `file` through a staged rename unless the file already holds exactly those bytes; true when it wrote. Every file call is asynchronous, and the staged name is unique to the call because every Bullseye extension of one window shares its process id. */
77
+ async function writeIfChangedAsync(file, content) {
78
+ const bytes = Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8");
79
+ const held = await fs.promises.readFile(file).catch((failed) => {
80
+ if (failed.code === "ENOENT")
81
+ return undefined;
82
+ throw failed;
83
+ });
84
+ if (held !== undefined && Buffer.compare(held, bytes) === 0)
85
+ return false;
86
+ await fs.promises.mkdir(path.dirname(file), { recursive: true });
87
+ const staged = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
88
+ await fs.promises.writeFile(staged, bytes);
89
+ await fs.promises.rename(staged, file);
90
+ return true;
91
+ }
92
+ /** The first runnable node on PATH, found without a child process; undefined when none is. */
93
+ async function nodeOnPath() {
94
+ const exe = process.platform === "win32" ? "node.exe" : "node";
95
+ for (const entry of (process.env.PATH ?? "").split(path.delimiter).map((dir) => dir.replace(/^"(.*)"$/, "$1")).filter((dir) => dir !== "")) {
96
+ const file = path.join(entry, exe);
97
+ const found = await fs.promises.stat(file).catch((failed) => {
98
+ if (["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(failed.code))
99
+ return undefined;
100
+ throw failed;
101
+ });
102
+ if (found !== undefined && found.isFile() && (process.platform === "win32" || (found.mode & 0o111) !== 0))
103
+ return file;
104
+ }
105
+ return undefined;
106
+ }
69
107
  /** #3849 Q782 — whether a moment `at` (ms epoch) falls in this boot: Meni's Stop holds until his Start or the machine's next boot, and a supervisor's start failure stands only until a new build or the next boot. */
70
108
  function inThisBoot(at) {
71
109
  return at >= Date.now() - os.uptime() * 1000;
@@ -511,4 +549,4 @@ function listenWithHandover(httpServer, { server, port, version, onServing }) {
511
549
  httpServer.once("listening", onServing);
512
550
  httpServer.listen(port, "127.0.0.1");
513
551
  }
514
- module.exports = { inThisBoot, takeStartLock, bundleRelease, spawnBundle, residentLogFile, keepDoor, servedDoor, ensureResidentDoor, doorAnswer, servesUntil, healthBody, answerShutdown, announceTakeover, TAKEOVER_BIND, listenWithHandover, holdOf, holdStopped, releaseHold };
552
+ module.exports = { existsAsync, writeIfChangedAsync, nodeOnPath, inThisBoot, takeStartLock, bundleRelease, spawnBundle, residentLogFile, keepDoor, servedDoor, ensureResidentDoor, doorAnswer, servesUntil, healthBody, answerShutdown, announceTakeover, TAKEOVER_BIND, listenWithHandover, holdOf, holdStopped, releaseHold };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.359",
3
+ "version": "1.3.361",
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",