omni-notify-mcp 1.3.367 → 1.3.368
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,6 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "child_process";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { appendFile } from "fs/promises";
|
|
3
|
+
import { appendFile, readdir, rm } from "fs/promises";
|
|
4
4
|
import { existsSync, mkdtempSync, writeFileSync, createReadStream, rmSync } from "fs";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
6
|
import { join } from "path";
|
|
@@ -26,6 +26,20 @@ function running(pid) {
|
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
/** #4135 — a daemon that ends with terminals open (a release takeover, a crash) never reaches finish(), so every spool is named for the daemon that owns it, and the first terminal a later daemon opens removes each spool whose daemon is gone. */
|
|
30
|
+
const spoolOwner = /^bn-native-(\d+)-/;
|
|
31
|
+
let spoolsSwept = false;
|
|
32
|
+
export async function removeEndedDaemonsSpools() {
|
|
33
|
+
for (const name of await readdir(tmpdir())) {
|
|
34
|
+
const owner = spoolOwner.exec(name);
|
|
35
|
+
if (owner === null || Number(owner[1]) === process.pid || running(Number(owner[1])))
|
|
36
|
+
continue;
|
|
37
|
+
await rm(join(tmpdir(), name), { recursive: true, force: true }).catch((error) => {
|
|
38
|
+
// OWNER: ITER/LOOP — a spool of an ended daemon holds no live terminal; one that will not go is said and left to the next daemon's sweep
|
|
39
|
+
process.stderr.write(`[agent-gateway] the spool ${name} of ended daemon ${owner[1]} was not removed: ${error.message}\n`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
29
43
|
/** The person BN's door serves, who holds every conversation's CLI whichever provider runs it. Loaded after the module graph is built: the door reads the config this module's importers are still defining, and it needs no gateway section — a daemon without one holds terminals for the same person. */
|
|
30
44
|
let holder;
|
|
31
45
|
void import("./passkeyDoor.js").then((door) => { holder = door.personId; });
|
|
@@ -51,7 +65,7 @@ export class NativeTerminal {
|
|
|
51
65
|
pasting = false;
|
|
52
66
|
sequence = 0;
|
|
53
67
|
readers = 0;
|
|
54
|
-
spoolDir = mkdtempSync(join(tmpdir(),
|
|
68
|
+
spoolDir = mkdtempSync(join(tmpdir(), `bn-native-${process.pid}-`));
|
|
55
69
|
spool = join(this.spoolDir, "terminal.ansi");
|
|
56
70
|
writing = Promise.resolve();
|
|
57
71
|
/** The CLI itself said it exited, so its worker disconnected and its pid is gone — nothing is left to kill. */
|
|
@@ -71,6 +85,13 @@ export class NativeTerminal {
|
|
|
71
85
|
this.provider = spec.provider.name;
|
|
72
86
|
this.project = spec.project;
|
|
73
87
|
this.key = spec.id;
|
|
88
|
+
if (!spoolsSwept) {
|
|
89
|
+
spoolsSwept = true;
|
|
90
|
+
removeEndedDaemonsSpools().catch((error) => {
|
|
91
|
+
// OWNER: the first terminal's open is the sweep's trigger root and awaits nothing — a temp dir that cannot be listed is said and the next daemon sweeps again
|
|
92
|
+
process.stderr.write(`[agent-gateway] the spools of ended daemons were not swept: ${error.message}\n`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
74
95
|
this.started = new Promise((resolve) => { this.settleStarted = (refusal) => { clearTimeout(this.startTimer); resolve(refusal); }; });
|
|
75
96
|
this.startTimer = setTimeout(() => this.fail(`${spec.provider.label} was not running ${MAX_WAIT_SECONDS} s after it was asked to start.`), MAX_WAIT_SECONDS * 1000);
|
|
76
97
|
this.screen = new Terminal({ cols: spec.cols, rows: spec.rows, allowProposedApi: true });
|
|
@@ -1903,13 +1903,27 @@ export function submitStory(board, given, now) {
|
|
|
1903
1903
|
writeWhole(board, requestFile(board, given.storyId), request);
|
|
1904
1904
|
return { request, written: true, ...(standing?.requestId === requestId ? { unackedMs: now - standing.submittedAt } : {}) };
|
|
1905
1905
|
}
|
|
1906
|
-
/**
|
|
1907
|
-
|
|
1908
|
-
|
|
1906
|
+
/** 🔴 #4123 — why this FleetView leaves the board alone: a newer FleetView, alive, drives it; none ⇒ undefined. */
|
|
1907
|
+
function newerDriver(board, version) {
|
|
1908
|
+
const beat = readJson(servedFile(board));
|
|
1909
|
+
// NULL-OK: field version is OPTIONAL and therefore it is ok to check for NULL
|
|
1910
|
+
if (beat === undefined || beat.pid === process.pid || beat.version === undefined || !isProcessAlive(beat.pid) || !newerVersion(beat.version, version))
|
|
1911
|
+
return undefined;
|
|
1912
|
+
return `FleetView ${beat.version} (process ${beat.pid}), newer than this FleetView ${version}, which leaves the board to it`;
|
|
1913
|
+
}
|
|
1914
|
+
/** FleetView's pass on this board failed: the reason is put on its mark, so BB's AUTO START switch shows it until a pass succeeds — never over a newer FleetView's mark. */
|
|
1915
|
+
export function markQueueTrouble(board, why, now, version) {
|
|
1916
|
+
// NULL-OK: field newerDriver is OPTIONAL and therefore it is ok to check for NULL
|
|
1917
|
+
if (newerDriver(board, version) !== undefined)
|
|
1918
|
+
return;
|
|
1919
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now, version, trouble: why });
|
|
1909
1920
|
}
|
|
1910
1921
|
/** FleetView's queue beat stopped on a defect: the board is marked not driven with that defect, so BB hands its stories to the board's main session again until a FleetView pass drives it. */
|
|
1911
|
-
export function markQueueStopped(board, why, now) {
|
|
1912
|
-
|
|
1922
|
+
export function markQueueStopped(board, why, now, version) {
|
|
1923
|
+
// NULL-OK: field newerDriver is OPTIONAL and therefore it is ok to check for NULL
|
|
1924
|
+
if (newerDriver(board, version) !== undefined)
|
|
1925
|
+
return;
|
|
1926
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now, version, stopped: why });
|
|
1913
1927
|
}
|
|
1914
1928
|
/** Whether FleetView's story queue drives this board: the process that marked its last pass still runs and its beat has not stopped, with the reason its last pass failed when it did — else why not, in plain words. A live FleetView that stops answering shows as requests its acks never name ({@link ACK_LATE_MS}). */
|
|
1915
1929
|
export function queueServed(board) {
|
|
@@ -1925,6 +1939,17 @@ export function queueServed(board) {
|
|
|
1925
1939
|
// NULL-OK: field trouble is OPTIONAL and therefore it is ok to check for NULL
|
|
1926
1940
|
return beat.trouble === undefined ? { served: true } : { served: true, trouble: beat.trouble };
|
|
1927
1941
|
}
|
|
1942
|
+
/** 🔴 #4123 — whether dotted version `a` is later than `b`, part by part as numbers. */
|
|
1943
|
+
export function newerVersion(a, b) {
|
|
1944
|
+
const pa = a.split(".").map(Number);
|
|
1945
|
+
const pb = b.split(".").map(Number);
|
|
1946
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
1947
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
1948
|
+
if (d !== 0)
|
|
1949
|
+
return d > 0;
|
|
1950
|
+
}
|
|
1951
|
+
return false;
|
|
1952
|
+
}
|
|
1928
1953
|
/** Another process holds the board's queue lock right now: this pass leaves the queue to it. */
|
|
1929
1954
|
export class QueueBusy extends Error {
|
|
1930
1955
|
constructor(board, holder) {
|
|
@@ -2093,6 +2118,16 @@ export class WorkerRefused extends WorkerNotStarted {
|
|
|
2093
2118
|
this.name = "WorkerRefused";
|
|
2094
2119
|
}
|
|
2095
2120
|
}
|
|
2121
|
+
// GATE: the first wait before a parked worker is woken in its own session; doubled for each earlier wake up to WAKE_DOUBLINGS, so a worker that keeps stopping is woken less often but is never given up on
|
|
2122
|
+
export const WAKE_BASE_MS = 60_000;
|
|
2123
|
+
// GATE: how many times the wait doubles — past it a parked worker is woken every WAKE_BASE_MS * 2^WAKE_DOUBLINGS (32 min)
|
|
2124
|
+
export const WAKE_DOUBLINGS = 5;
|
|
2125
|
+
/** 🔴 #4123 — how long after its turn ended a worker woken `wakes` times before is woken again. */
|
|
2126
|
+
export const wakeDelayMs = (wakes) => WAKE_BASE_MS * 2 ** Math.min(wakes, WAKE_DOUBLINGS);
|
|
2127
|
+
/** 🔴 #4123 — what a parked worker is told when the queue wakes it in its own session. */
|
|
2128
|
+
export const wakeMessage = (storyId) => `FleetView's story queue woke you: #${storyId} is still OPEN on the board and you are its one worker. Re-read it with bullseye-backlog \`get\` and carry it to \`ship\` in this turn.
|
|
2129
|
+
A stop you named that you or another agent can clear (a board write refused, the board MCP not loaded yet, a release step) is yours to clear now — never a reason to end your turn. A run the box's CPU ceiling refuses is handled as its refusal says; never stop or kill a process to make room.
|
|
2130
|
+
If a decision only Meni can make stands in the way, record it on #${storyId} with bullseye-backlog \`ask\` and ask him with the notify MCP \`ask\` tool, which reaches his email and text; when its wait ends unanswered, keep calling \`wait_for_inbox\` until his reply arrives, then \`rule\` his answer onto #${storyId} verbatim, apply it and go on. End your turn only once the story is shipped.`;
|
|
2096
2131
|
// 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
|
|
2097
2132
|
export const WORKER_ATTEMPTS = 3;
|
|
2098
2133
|
// GATE: the wait before a story whose worker ended is started again: this, doubled for each earlier attempt
|
|
@@ -2152,11 +2187,16 @@ function afterWorker(e, now, why, retried = true) {
|
|
|
2152
2187
|
*/
|
|
2153
2188
|
export async function driveStoryQueue(board, world, now) {
|
|
2154
2189
|
return withQueueLock(board, now, async () => {
|
|
2155
|
-
|
|
2190
|
+
const newer = newerDriver(board, world.driverVersion);
|
|
2191
|
+
// NULL-OK: field newer is OPTIONAL and therefore it is ok to check for NULL
|
|
2192
|
+
if (newer !== undefined)
|
|
2193
|
+
throw new QueueBusy(board, newer);
|
|
2194
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now, version: world.driverVersion });
|
|
2156
2195
|
const store = readQueueStore(board);
|
|
2157
2196
|
const save = () => writeWhole(board, storeFile(board), store);
|
|
2158
2197
|
const refusals = new Map();
|
|
2159
2198
|
const applied = new Map();
|
|
2199
|
+
const wakeable = new Map();
|
|
2160
2200
|
for (const id of requestedStories(board)) {
|
|
2161
2201
|
const r = readableRequest(board, id);
|
|
2162
2202
|
// NULL-OK: field r is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -2242,10 +2282,102 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2242
2282
|
step(e, now, "progress", `its work first moved at ${new Date(w.progressAt).toISOString()}`);
|
|
2243
2283
|
e.worker.progressAt = w.progressAt;
|
|
2244
2284
|
}
|
|
2285
|
+
// NULL-OK: field parked is OPTIONAL and therefore it is ok to check for NULL
|
|
2286
|
+
if (w.parked === undefined) {
|
|
2287
|
+
delete e.worker?.parkedAt;
|
|
2288
|
+
delete e.worker?.stoppedAt;
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2291
|
+
const worker = e.worker;
|
|
2292
|
+
if (!e.eligible) {
|
|
2293
|
+
const why = `its ${e.provider} worker ${worker.jobId}'s turn is over and the story is no longer the queue's to work, so it is not woken`;
|
|
2294
|
+
step(e, now, "worker-ended", why);
|
|
2295
|
+
afterWorker(e, now, why);
|
|
2296
|
+
continue;
|
|
2297
|
+
}
|
|
2298
|
+
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2299
|
+
if (worker.parkedAt === undefined) {
|
|
2300
|
+
worker.parkedAt = now;
|
|
2301
|
+
step(e, now, "parked", `its ${e.provider} worker ${worker.jobId}'s turn is over with the story open, so it is woken in its own session from ${new Date(now + wakeDelayMs(worker.wakes ?? 0)).toISOString()}`);
|
|
2302
|
+
}
|
|
2303
|
+
if (now < worker.parkedAt + wakeDelayMs(worker.wakes ?? 0))
|
|
2304
|
+
continue;
|
|
2305
|
+
if (!w.parked.live) {
|
|
2306
|
+
wakeable.set(e, w.parked.sessionId);
|
|
2307
|
+
continue;
|
|
2308
|
+
}
|
|
2309
|
+
// NULL-OK: field stoppedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2310
|
+
if (worker.stoppedAt !== undefined && now < worker.stoppedAt + wakeDelayMs(worker.wakes ?? 0))
|
|
2311
|
+
continue;
|
|
2312
|
+
const again = worker.stoppedAt !== undefined;
|
|
2313
|
+
worker.stoppedAt = now;
|
|
2314
|
+
save();
|
|
2315
|
+
try {
|
|
2316
|
+
await world.stop(worker);
|
|
2317
|
+
step(e, now, "parked", again ? `its worker ${worker.jobId}'s session was still held at the prompt after it was stopped, so it was stopped again` : `its worker ${worker.jobId}'s idle process was stopped, so its session is woken once the process has gone`);
|
|
2318
|
+
}
|
|
2319
|
+
catch (err) {
|
|
2320
|
+
if (!(err instanceof WorkerNotStarted))
|
|
2321
|
+
throw err;
|
|
2322
|
+
// OWNER: ITER/LOOP — the provider would not stop this worker's idle process this pass, so it stays parked with the provider's words on its trace and the stop is tried again after its wait; the next entry is read.
|
|
2323
|
+
step(e, now, "parked", `its worker ${worker.jobId}'s idle process could not be stopped, so it is stopped again at ${new Date(now + wakeDelayMs(worker.wakes ?? 0)).toISOString()}: ${err.message}`);
|
|
2324
|
+
}
|
|
2245
2325
|
}
|
|
2246
2326
|
save();
|
|
2247
2327
|
let lanes = world.lanesRunning();
|
|
2248
2328
|
for (const e of queueOrder(store)) {
|
|
2329
|
+
const sessionId = wakeable.get(e);
|
|
2330
|
+
// NULL-OK: field sessionId is OPTIONAL and therefore it is ok to check for NULL
|
|
2331
|
+
if (sessionId !== undefined) {
|
|
2332
|
+
const parked = e.worker;
|
|
2333
|
+
const held = world.heldBy(e.storyId);
|
|
2334
|
+
// NULL-OK: field held is OPTIONAL and therefore it is ok to check for NULL
|
|
2335
|
+
if (held !== undefined) {
|
|
2336
|
+
e.why = `${held} works it, so its parked worker ${parked.jobId} is not woken beside it`;
|
|
2337
|
+
continue;
|
|
2338
|
+
}
|
|
2339
|
+
if (lanes >= world.limit) {
|
|
2340
|
+
e.why = `its worker ${parked.jobId} is parked, and ${lanes} lanes run with the lane limit at ${world.limit}, so it is woken when one finishes`;
|
|
2341
|
+
continue;
|
|
2342
|
+
}
|
|
2343
|
+
lanes += 1;
|
|
2344
|
+
const wakes = (parked.wakes ?? 0) + 1;
|
|
2345
|
+
try {
|
|
2346
|
+
const woken = await world.wake(e, board, sessionId, wakeMessage(e.storyId));
|
|
2347
|
+
e.worker = { ...woken, wakes };
|
|
2348
|
+
e.why = `its ${woken.provider} worker ${woken.jobId} was woken in its own session (wake ${wakes}), with ${lanes} of ${world.limit} lanes running`;
|
|
2349
|
+
step(e, now, "woken", e.why);
|
|
2350
|
+
}
|
|
2351
|
+
catch (err) {
|
|
2352
|
+
if (!(err instanceof WorkerNotStarted))
|
|
2353
|
+
throw err;
|
|
2354
|
+
const after = world.worker(e, board);
|
|
2355
|
+
// NULL-OK: field parked is OPTIONAL and therefore it is ok to check for NULL
|
|
2356
|
+
if (after.alive && (after.parked === undefined || after.parked.live)) {
|
|
2357
|
+
// OWNER: ITER/LOOP — the wake's answer was lost (a timeout on a busy box) but a process now runs the worker's session, so the wake landed: the entry keeps that worker and no second one is started; the next entry is read.
|
|
2358
|
+
e.worker = { provider: parked.provider, startedAt: now, jobId: parked.jobId, wakes };
|
|
2359
|
+
e.why = `its worker ${parked.jobId} was woken in its own session (wake ${wakes}), though its answer was: ${err.message}`;
|
|
2360
|
+
step(e, now, "woken", e.why);
|
|
2361
|
+
}
|
|
2362
|
+
else if (!err.unsent) {
|
|
2363
|
+
// OWNER: ITER/LOOP — the wake's answer was lost and no process has recorded the session yet, so the worker stays parked and is read again next pass; it is never ended on a missing answer, which would start a second worker beside a wake that landed late; the next entry is read.
|
|
2364
|
+
lanes -= 1;
|
|
2365
|
+
e.worker = { ...parked, parkedAt: now, wakes };
|
|
2366
|
+
e.why = `its worker ${parked.jobId}'s wake got no answer, so it stays parked and is read again: ${err.message}`;
|
|
2367
|
+
step(e, now, "parked", e.why);
|
|
2368
|
+
}
|
|
2369
|
+
else {
|
|
2370
|
+
// OWNER: ITER/LOOP — Claude Code refused to wake this story's session and no process runs it, so the worker has ended: its entry carries the provider's words and a fresh worker is started on its backoff; the next entry is read.
|
|
2371
|
+
lanes -= 1;
|
|
2372
|
+
const why = `its ${e.provider} worker ${parked.jobId} could not be woken: ${err.message}`;
|
|
2373
|
+
delete e.worker;
|
|
2374
|
+
step(e, now, "worker-ended", why);
|
|
2375
|
+
afterWorker(e, now, why);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
save();
|
|
2379
|
+
continue;
|
|
2380
|
+
}
|
|
2249
2381
|
// NULL-OK: field nextTryAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2250
2382
|
if (!e.eligible || !(e.state === "queued" || ((e.state === "retrying" || e.state === "failed") && e.nextTryAt !== undefined && e.nextTryAt <= now)))
|
|
2251
2383
|
continue;
|
|
@@ -2390,7 +2522,14 @@ const mtimeOf = (file) => {
|
|
|
2390
2522
|
return undefined;
|
|
2391
2523
|
}
|
|
2392
2524
|
};
|
|
2393
|
-
/**
|
|
2525
|
+
/** 🔴 #4123 — the job states whose turn is over: a process still holding one waits at the prompt, working nothing. */
|
|
2526
|
+
const TURN_OVER = new Set(["done", "blocked", "stopped"]);
|
|
2527
|
+
/**
|
|
2528
|
+
* A story worker's liveness: a `claude --bg` job, with the moment its transcript last moved. 🔴 #4123 — a job whose turn is
|
|
2529
|
+
* over (`done` or `blocked`, with no background task of its own still running) or whose process the daemon retired is
|
|
2530
|
+
* PARKED, alive in its session and woken there; a job Claude Code no longer records, one whose provider call failed, or one
|
|
2531
|
+
* stopped by anyone but the queue has ended.
|
|
2532
|
+
*/
|
|
2394
2533
|
export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
2395
2534
|
const job = jobRecordOf(worker.jobId, home);
|
|
2396
2535
|
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -2401,17 +2540,45 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
|
2401
2540
|
return { alive: false, why: `its job ${worker.jobId} is no longer on Claude Code's record` };
|
|
2402
2541
|
const at = job.linkScanPath === undefined ? undefined : mtimeOf(job.linkScanPath);
|
|
2403
2542
|
const progress = at === undefined ? {} : { progressAt: at };
|
|
2404
|
-
if (job.state === "done" || job.state === "stopped")
|
|
2405
|
-
return { alive: false, ...progress, why: `its job ${worker.jobId} ended ${job.state}` };
|
|
2406
|
-
if (liveClaudeSessions(home).has(job.sessionId)) {
|
|
2407
|
-
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
2408
|
-
if (job.state === "blocked")
|
|
2409
|
-
return { alive: true, ...progress, blocked: true, ...(job.needs === undefined ? {} : { needs: job.needs }), why: `its job ${worker.jobId} is blocked` };
|
|
2410
|
-
return { alive: true, ...progress, why: `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
|
|
2411
|
-
}
|
|
2412
2543
|
if (now - worker.startedAt < WORKER_START_GRACE_MS)
|
|
2413
2544
|
return { alive: true, ...progress, why: `its job ${worker.jobId} was started ${Math.round((now - worker.startedAt) / 1000)}s ago and its process has not recorded itself yet` };
|
|
2414
|
-
|
|
2545
|
+
// NULL-OK: field stoppedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2546
|
+
if (job.state === "stopped" && worker.stoppedAt === undefined)
|
|
2547
|
+
return { alive: false, ...progress, why: `its job ${worker.jobId} ended stopped` };
|
|
2548
|
+
// NULL-OK: field detail is OPTIONAL and therefore it is ok to check for NULL
|
|
2549
|
+
if (job.state === "failed")
|
|
2550
|
+
return { alive: false, ...progress, why: `its job ${worker.jobId} failed: ${job.detail ?? "its record names no cause"}` };
|
|
2551
|
+
const live = liveClaudeSessions(home).has(job.sessionId);
|
|
2552
|
+
// NULL-OK: field inFlight is OPTIONAL and therefore it is ok to check for NULL
|
|
2553
|
+
const waitsOnTasks = job.inFlight !== undefined && job.inFlight.tasks + job.inFlight.queued + job.inFlight.drainableMonitors > 0;
|
|
2554
|
+
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
2555
|
+
const blocked = job.state === "blocked" ? { blocked: true, ...(job.needs === undefined ? {} : { needs: job.needs }) } : {};
|
|
2556
|
+
if (live && (!TURN_OVER.has(job.state) || waitsOnTasks))
|
|
2557
|
+
return { alive: true, ...progress, why: `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
|
|
2558
|
+
const how = live ? `its turn ended ${job.state} and its process waits at the prompt` : `it reads ${job.state} and no process on this machine runs session ${job.sessionId}`;
|
|
2559
|
+
return { alive: true, ...progress, ...blocked, parked: { sessionId: job.sessionId, live }, why: `its job ${worker.jobId} is parked — ${how}` };
|
|
2560
|
+
}
|
|
2561
|
+
/** 🔴 #4123 — wakes a parked `claude --bg` session in place with `message`: passed no flags, Claude Code continues the same job with its own saved options. */
|
|
2562
|
+
export function wakeStoryWorker(sessionId, message, board, cli, now) {
|
|
2563
|
+
return new Promise((resolve, reject) => {
|
|
2564
|
+
execFile(cli.cmd, [...cli.args, "--bg", "--resume", sessionId, message], { cwd: board, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
2565
|
+
const said = `${stdout}${stderr}`;
|
|
2566
|
+
const job = /^backgrounded · (\S+) · /m.exec(said);
|
|
2567
|
+
if (job !== null)
|
|
2568
|
+
return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
|
|
2569
|
+
reject(new WorkerNotStarted(`claude --bg --resume ${err === null ? "printed no job id" : `failed (${err.message.split("\n")[0]})`} — ${said.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`, err !== null && err.killed !== true));
|
|
2570
|
+
});
|
|
2571
|
+
});
|
|
2572
|
+
}
|
|
2573
|
+
/** 🔴 #4123 — stops a parked `claude --bg` job's idle process, leaving its session to be woken. */
|
|
2574
|
+
export function stopStoryWorker(jobId, cli) {
|
|
2575
|
+
return new Promise((resolve, reject) => {
|
|
2576
|
+
execFile(cli.cmd, [...cli.args, "stop", jobId], { windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
2577
|
+
if (err === null)
|
|
2578
|
+
return resolve();
|
|
2579
|
+
reject(new WorkerNotStarted(`claude stop ${jobId} failed (${err.message.split("\n")[0]}) — ${`${stdout}${stderr}`.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`));
|
|
2580
|
+
});
|
|
2581
|
+
});
|
|
2415
2582
|
}
|
|
2416
2583
|
// GATE: how long a provider CLI is given to answer a worker start before the start is read as refused
|
|
2417
2584
|
const LAUNCH_TIMEOUT_MS = 60_000;
|
|
@@ -4,6 +4,7 @@ const fs = require("fs");
|
|
|
4
4
|
const http = require("http");
|
|
5
5
|
const os = require("os");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const zlib = require("zlib");
|
|
7
8
|
const { SHIM_SOURCE } = require("./webviewShim");
|
|
8
9
|
const { workspacesHere } = require("./workspaceList");
|
|
9
10
|
const WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
@@ -196,6 +197,18 @@ function saveTheme(theme) {
|
|
|
196
197
|
function postFrame(message, roots) {
|
|
197
198
|
return JSON.stringify({ type: "post", message: JSON.parse(repoint(JSON.stringify(message), roots)) });
|
|
198
199
|
}
|
|
200
|
+
function postTo(sockets, message, roots) {
|
|
201
|
+
const text = postFrame(message, roots);
|
|
202
|
+
const packed = [...sockets].some((socket) => socket.packed === true) ? zlib.gzipSync(text, { level: 1 }) : Buffer.alloc(0);
|
|
203
|
+
for (const socket of sockets) {
|
|
204
|
+
if (socket.packed === true) {
|
|
205
|
+
writeFrameWithOpcode(socket, 0x2, packed);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
writeFrame(socket, text);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
199
212
|
function cookieOf(request, name) {
|
|
200
213
|
// NULL-OK: field cookie is OPTIONAL and therefore it is ok to check for NULL
|
|
201
214
|
const pair = (request.headers.cookie ?? "").split(";").map((part) => part.trim()).find((part) => part.startsWith(`${name}=`));
|
|
@@ -394,7 +407,7 @@ class ServedWebview {
|
|
|
394
407
|
* message runs under. `saidOnce` says a failure that persists across the watch's ticks is told to this browser once.
|
|
395
408
|
*/
|
|
396
409
|
viewerOf(socket) {
|
|
397
|
-
const viewer = { search: socket.at, base: socket.base, post: (message) =>
|
|
410
|
+
const viewer = { search: socket.at, base: socket.base, post: (message) => postTo([socket], message, this.served) };
|
|
398
411
|
viewer.guard = (work, options = {}) => this.guarded(socket, viewer, work, options.saidOnce === true);
|
|
399
412
|
return viewer;
|
|
400
413
|
}
|
|
@@ -515,10 +528,7 @@ class Page {
|
|
|
515
528
|
if (this.mirror !== from || this.sockets.size === 0) {
|
|
516
529
|
return;
|
|
517
530
|
}
|
|
518
|
-
|
|
519
|
-
for (const socket of this.sockets) {
|
|
520
|
-
writeFrame(socket, frame);
|
|
521
|
-
}
|
|
531
|
+
postTo(this.sockets, message, from.roots());
|
|
522
532
|
}
|
|
523
533
|
received(socket, text) {
|
|
524
534
|
let frame;
|
|
@@ -533,6 +543,10 @@ class Page {
|
|
|
533
543
|
socket.destroy();
|
|
534
544
|
return;
|
|
535
545
|
}
|
|
546
|
+
if (frame !== null && frame.type === "packed") {
|
|
547
|
+
socket.packed = true;
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
536
550
|
// NULL-OK: field mirror is OPTIONAL and therefore it is ok to check for NULL
|
|
537
551
|
if (frame === null || frame.type !== "message" || this.mirror === undefined) {
|
|
538
552
|
return;
|
|
@@ -543,7 +557,7 @@ class Page {
|
|
|
543
557
|
const mirror = this.mirror;
|
|
544
558
|
mirror.pageLoaded(frame.message);
|
|
545
559
|
mirror.dispatch(frame.message, "browser", (message) => {
|
|
546
|
-
|
|
560
|
+
postTo([socket], message, mirror.roots());
|
|
547
561
|
return Promise.resolve(true);
|
|
548
562
|
}, socket);
|
|
549
563
|
}
|
|
@@ -1091,6 +1105,7 @@ class WebHost {
|
|
|
1091
1105
|
socket.write(`HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ${accept}\r\n\r\n`);
|
|
1092
1106
|
socket.setNoDelay(true);
|
|
1093
1107
|
socket.peek = url.searchParams.get("peek") === "1";
|
|
1108
|
+
socket.packed = false;
|
|
1094
1109
|
// NULL-OK: field at is OPTIONAL and therefore it is ok to check for NULL
|
|
1095
1110
|
socket.at = new URLSearchParams(url.searchParams.get("at") ?? "");
|
|
1096
1111
|
const leave = () => page.sockets.delete(socket);
|
|
@@ -271,12 +271,38 @@ const SHIM_SOURCE = String.raw `(function () {
|
|
|
271
271
|
var scheme = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
272
272
|
socket = new WebSocket(scheme + "//" + window.location.host + "/__bullseye/ws?page=" + encodeURIComponent(page) + "&at=" + encodeURIComponent(window.location.search) + (new URLSearchParams(window.location.search).get("bullseye-peek") === null ? "" : "&peek=1"));
|
|
273
273
|
socket.addEventListener("open", function () {
|
|
274
|
+
if (typeof DecompressionStream === "function") {
|
|
275
|
+
socket.send(JSON.stringify({ type: "packed" }));
|
|
276
|
+
}
|
|
274
277
|
while (queue.length > 0) {
|
|
275
278
|
socket.send(queue.shift());
|
|
276
279
|
}
|
|
277
280
|
});
|
|
281
|
+
socket.binaryType = "blob";
|
|
282
|
+
var unpacking = Promise.resolve();
|
|
283
|
+
var unpackingCount = 0;
|
|
278
284
|
socket.addEventListener("message", function (event) {
|
|
279
|
-
|
|
285
|
+
if (typeof event.data === "string" && unpackingCount === 0) {
|
|
286
|
+
handle(event.data);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
unpackingCount += 1;
|
|
290
|
+
var text = typeof event.data === "string" ? Promise.resolve(event.data) : new Response(event.data.stream().pipeThrough(new DecompressionStream("gzip"))).text();
|
|
291
|
+
unpacking = unpacking.then(function () {
|
|
292
|
+
return text;
|
|
293
|
+
}).then(function (unpacked) {
|
|
294
|
+
unpackingCount -= 1;
|
|
295
|
+
queueMicrotask(function () {
|
|
296
|
+
handle(unpacked);
|
|
297
|
+
});
|
|
298
|
+
}, function (err) {
|
|
299
|
+
unpackingCount -= 1;
|
|
300
|
+
notice("__bullseye-page-failed", "");
|
|
301
|
+
document.getElementById("__bullseye-page-failed").textContent = "⚠️ A frame from the host could not be unpacked — " + err.message;
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
function handle(text) {
|
|
305
|
+
var frame = JSON.parse(text);
|
|
280
306
|
if (frame.type === "post") {
|
|
281
307
|
deliver(frame.message);
|
|
282
308
|
} else if (frame.type === "reload") {
|
|
@@ -290,7 +316,7 @@ const SHIM_SOURCE = String.raw `(function () {
|
|
|
290
316
|
failedBar.remove();
|
|
291
317
|
}
|
|
292
318
|
}
|
|
293
|
-
}
|
|
319
|
+
}
|
|
294
320
|
socket.addEventListener("close", function () {
|
|
295
321
|
socket = null;
|
|
296
322
|
window.setTimeout(awaitHost, 1000);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.368",
|
|
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",
|