omni-notify-mcp 1.3.471 → 1.3.475
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.
package/dist/mcpHosts.cjs
CHANGED
|
@@ -273,7 +273,22 @@ function createHostWriters(env) {
|
|
|
273
273
|
return { path: claudePath, state: "scoped" };
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
// #215 — the ONE helper every Codex server entry on this machine resolves its workspace with: the folder the session's own
|
|
277
|
+
// process runs in. A literal header naming a single folder — what the Codex app wrote into this file for each of these
|
|
278
|
+
// servers — answers every session about that ONE folder whichever workspace it runs in, so the pinned header is removed
|
|
279
|
+
// from every entry here and the helper is written from this one function.
|
|
280
|
+
const codexWorkspaceHelper = (header) => `node -e "process.stdout.write(JSON.stringify({\\"${header}\\":process.cwd()}))"`;
|
|
281
|
+
const CODEX_WORKSPACE_SERVERS = [
|
|
282
|
+
{ server: "bn", header: "x-bullseye-project" },
|
|
283
|
+
{ server: "bullseye-backlog", header: "x-bullseye-project" },
|
|
284
|
+
{ server: "deepagent", header: "x-deepagent-project" },
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
// GATE: how deep a `notify` array's closing bracket may sit below its own key before this file leaves it entirely alone — Codex's own writer keeps it on one line, and a file this deep is one we do not understand.
|
|
288
|
+
const NOTIFY_ARRAY_LINES = 8;
|
|
289
|
+
// The Codex app's own home is an MSIX package under this folder, whose FILES Windows does not let this process tell from files
|
|
290
|
+
// that are gone — a live `AppxManifest.xml` there answers ENOENT. The PACKAGE FOLDER itself answers honestly.
|
|
291
|
+
const WINDOWS_APPS_FOLDER = "windowsapps";
|
|
277
292
|
|
|
278
293
|
function setTomlKey(lines, start, end, key, value) {
|
|
279
294
|
const at = lines.findIndex((l, i) => i > start && i < end && new RegExp(`^\\s*"?${key.replace(/[-]/g, "\\-")}"?\\s*=`).test(l));
|
|
@@ -295,13 +310,116 @@ function createHostWriters(env) {
|
|
|
295
310
|
function tomlTable(lines, header) {
|
|
296
311
|
const headers = tomlHeaders(lines);
|
|
297
312
|
const own = headers.filter((h) => h.path === header);
|
|
298
|
-
if (own.length > 1) throw new Error(`~/.codex/config.toml declares [${header}] ${own.length} times, so it is not valid TOML —
|
|
313
|
+
if (own.length > 1) throw new Error(`~/.codex/config.toml declares [${header}] ${own.length} times, so it is not valid TOML — nothing was written to it; fix that file and reload the window`);
|
|
299
314
|
// NULL-OK: field mcp_servers.bn table is OPTIONAL and therefore it is ok to check for NULL
|
|
300
315
|
if (own.length === 0) return undefined;
|
|
301
316
|
const next = headers.find((h) => h.index > own[0].index);
|
|
302
317
|
return { start: own[0].index, end: next === undefined ? lines.length : next.index };
|
|
303
318
|
}
|
|
304
319
|
|
|
320
|
+
/**
|
|
321
|
+
* One Codex server's own table given the shared helper and no single pinned folder, in place. A server this file does not
|
|
322
|
+
* declare is left undeclared — `bullseye-backlog` and `deepagent` are registered by Codex and DeepAgent, never by this
|
|
323
|
+
* extension — and only bn's headers table is ever created, because only bn's entry is this extension's to write.
|
|
324
|
+
*/
|
|
325
|
+
function scopeCodexServerToSessionFolder(lines, { server, header }) {
|
|
326
|
+
let own = tomlTable(lines, `mcp_servers.${server}`);
|
|
327
|
+
if (own === undefined) return;
|
|
328
|
+
// An inline headers table is not ours to rewrite: bn's own is replaced whole (its bearer goes straight back), but splicing a
|
|
329
|
+
// line out of another app's entry would delete a header of theirs — a bearer included — with nothing put in its place, so a
|
|
330
|
+
// server that carries one inline is left exactly as its own writer wrote it.
|
|
331
|
+
const inline = lines.findIndex((l, i) => i > own.start && i < own.end && /^\s*http_headers\s*=/.test(l));
|
|
332
|
+
if (inline >= 0 && server !== "bn") return;
|
|
333
|
+
if (inline >= 0) lines.splice(inline, 1);
|
|
334
|
+
own = tomlTable(lines, `mcp_servers.${server}`);
|
|
335
|
+
setTomlKey(lines, own.start, own.end, "http_headers_helper", `'${codexWorkspaceHelper(header)}'`);
|
|
336
|
+
let headers = tomlTable(lines, `mcp_servers.${server}.http_headers`);
|
|
337
|
+
if (headers === undefined && server === "bn") {
|
|
338
|
+
own = tomlTable(lines, `mcp_servers.${server}`);
|
|
339
|
+
lines.splice(own.end, 0, ...(lines[own.end - 1] === "" ? [] : [""]), `[mcp_servers.${server}.http_headers]`, ...(own.end < lines.length ? [""] : []));
|
|
340
|
+
headers = tomlTable(lines, `mcp_servers.${server}.http_headers`);
|
|
341
|
+
}
|
|
342
|
+
if (headers === undefined) return;
|
|
343
|
+
const pinned = lines.findIndex((l, i) => i > headers.start && i < headers.end && new RegExp(`^\\s*"?${header}"?\\s*=`).test(l));
|
|
344
|
+
if (pinned >= 0) lines.splice(pinned, 1);
|
|
345
|
+
// A headers table whose only key WAS the pinned folder, with nothing else written in it, holds nothing of anybody's: it goes
|
|
346
|
+
// with the key it carried. A comment left in it is somebody's words about that table, so the table stays and keeps them.
|
|
347
|
+
const left = tomlTable(lines, `mcp_servers.${server}.http_headers`);
|
|
348
|
+
if (left !== undefined && lines.slice(left.start + 1, left.end).every((l) => l.trim() === "")) {
|
|
349
|
+
const from = lines[left.start - 1] === "" ? left.start - 1 : left.start;
|
|
350
|
+
lines.splice(from, left.start - from + 1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Every server of {@link CODEX_WORKSPACE_SERVERS} in this file, each resolving its workspace from the session's own folder. */
|
|
355
|
+
function withCodexWorkspaceHelpers(text) {
|
|
356
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
357
|
+
const lines = text.split(/\r?\n/);
|
|
358
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
359
|
+
for (const server of CODEX_WORKSPACE_SERVERS) scopeCodexServerToSessionFolder(lines, server);
|
|
360
|
+
return `${lines.join(eol)}${eol}`;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Where the file's TOP-LEVEL `notify` array starts, or -1. Anything that opens a table or a multi-line string before it — and
|
|
365
|
+
* therefore any `notify` that follows one — is somebody else's text and is never touched, so a `[desktop]` header, a `"""`
|
|
366
|
+
* block, and even a `'''` hiding inside a basic string all stop this file short of the key.
|
|
367
|
+
*/
|
|
368
|
+
function topLevelNotifyAt(lines) {
|
|
369
|
+
for (let index = 0; index < lines.length; index++) {
|
|
370
|
+
if (/^notify\s*=\s*\[/.test(lines[index])) return index;
|
|
371
|
+
if (/^\s*\[/.test(lines[index]) || /"""|'''/.test(lines[index])) return -1;
|
|
372
|
+
}
|
|
373
|
+
return -1;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Whether the program a `notify` array names is provably gone: the MSIX package folder its own path runs through is no
|
|
378
|
+
* longer there. A program outside such a folder is never removed — this process cannot tell a file it is not allowed to read
|
|
379
|
+
* from a file that is not there, and deleting a working hook would be worse than leaving a dead one.
|
|
380
|
+
*/
|
|
381
|
+
function gonePackageFolder(program) {
|
|
382
|
+
const parts = program.split(/[\\/]+/);
|
|
383
|
+
const at = parts.findIndex((part, index) => index > 0 && part.toLowerCase() === WINDOWS_APPS_FOLDER);
|
|
384
|
+
if (at < 0 || at + 1 >= parts.length) return false;
|
|
385
|
+
try {
|
|
386
|
+
fs.statSync(parts.slice(0, at + 2).join("\\"));
|
|
387
|
+
} catch (err) {
|
|
388
|
+
return err.code === "ENOENT";
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* #215 — a `notify` program this file names but this machine no longer has: Codex runs it on EVERY turn end, so a dead one
|
|
395
|
+
* writes `codex_core::hook_runtime: after_agent hook failed; ... hook_name=legacy_notify error=The system cannot find the
|
|
396
|
+
* path specified. (os error 3)` into Codex.log for the life of the install. The Codex app ships as an MSIX package, and its
|
|
397
|
+
* files answer ENOENT whether they are there or not — which is why only {@link gonePackageFolder} decides here. A bare name
|
|
398
|
+
* Codex resolves on its own PATH, a first element that is not a plain quoted path, and a working program are left as they are.
|
|
399
|
+
*/
|
|
400
|
+
function withoutDeadNotify(text) {
|
|
401
|
+
const lines = text.split(/\r?\n/);
|
|
402
|
+
const at = topLevelNotifyAt(lines);
|
|
403
|
+
if (at < 0) return text;
|
|
404
|
+
let end = at;
|
|
405
|
+
while (end < lines.length && end - at <= NOTIFY_ARRAY_LINES && !/\]/.test(lines[end])) end++;
|
|
406
|
+
if (end >= lines.length || end - at > NOTIFY_ARRAY_LINES) return text;
|
|
407
|
+
const array = /^notify\s*=\s*\[([\s\S]*)\]/.exec(lines.slice(at, end + 1).join("\n"));
|
|
408
|
+
if (array === null) return text;
|
|
409
|
+
// The program is the array's OWN first element and a plain quoted string — `["python3", …]` is Codex's own documented shape
|
|
410
|
+
// too, but that name is resolved on Codex's PATH and never here, so only an absolute path can be judged at all.
|
|
411
|
+
const first = /^\s*(['"])((?:\\[\s\S]|(?!\1)[\s\S])*)\1\s*(?:,|\])/.exec(array[1]);
|
|
412
|
+
if (first === null) return text;
|
|
413
|
+
// A TOML basic string escapes its own backslashes and a literal string escapes nothing; a mis-read path would be a program
|
|
414
|
+
// this file only THINKS is missing.
|
|
415
|
+
const program = first[1] === '"' ? first[2].replace(/\\(["\\])/g, "$1") : first[2];
|
|
416
|
+
if (!/^[A-Za-z]:[\\/]/.test(program) || !gonePackageFolder(program)) return text;
|
|
417
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
418
|
+
const kept = lines.filter((_, i) => i < at || i > end);
|
|
419
|
+
while (kept.length > 0 && kept[kept.length - 1] === "") kept.pop();
|
|
420
|
+
return `${kept.join(eol)}${eol}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
305
423
|
function withCodexGatewayEntry(text, url, token) {
|
|
306
424
|
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
307
425
|
const lines = text.split(/\r?\n/);
|
|
@@ -315,29 +433,31 @@ function createHostWriters(env) {
|
|
|
315
433
|
if (inline >= 0) lines.splice(inline, 1);
|
|
316
434
|
own = tomlTable(lines, "mcp_servers.bn");
|
|
317
435
|
setTomlKey(lines, own.start, own.end, "url", JSON.stringify(url));
|
|
318
|
-
own = tomlTable(lines, "mcp_servers.bn");
|
|
319
|
-
setTomlKey(lines, own.start, own.end, "http_headers_helper", `'${CODEX_WORKSPACE_HELPER}'`);
|
|
320
436
|
let headers = tomlTable(lines, "mcp_servers.bn.http_headers");
|
|
321
437
|
if (headers === undefined) {
|
|
322
438
|
own = tomlTable(lines, "mcp_servers.bn");
|
|
323
439
|
lines.splice(own.end, 0, ...(lines[own.end - 1] === "" ? [] : [""]), "[mcp_servers.bn.http_headers]", ...(own.end < lines.length ? [""] : []));
|
|
324
440
|
headers = tomlTable(lines, "mcp_servers.bn.http_headers");
|
|
325
441
|
}
|
|
326
|
-
const fixed = lines.findIndex((l, i) => i > headers.start && i < headers.end && /^\s*"?x-bullseye-project"?\s*=/.test(l));
|
|
327
|
-
if (fixed >= 0) lines.splice(fixed, 1);
|
|
328
442
|
headers = tomlTable(lines, "mcp_servers.bn.http_headers");
|
|
329
443
|
setTomlKey(lines, headers.start, headers.end, "Authorization", JSON.stringify(`Bearer ${token}`));
|
|
330
|
-
return `${lines.join(eol)}${eol}
|
|
444
|
+
return withCodexWorkspaceHelpers(`${lines.join(eol)}${eol}`);
|
|
331
445
|
}
|
|
332
446
|
|
|
447
|
+
/**
|
|
448
|
+
* Every repair this machine's Codex config needs from us, whether or not a gateway door is configured here: the servers that
|
|
449
|
+
* name their workspace by the session's own folder, and a `notify` program this box no longer has. With a gateway token the
|
|
450
|
+
* bn door is written as well; without one the repairs alone are written, because neither depends on the token.
|
|
451
|
+
*/
|
|
333
452
|
function configureCodexScopedGateway() {
|
|
334
453
|
const codexPath = path.join(env.home(), ".codex", "config.toml");
|
|
335
454
|
const read = contentOf(codexPath);
|
|
455
|
+
if (!fs.existsSync(codexPath)) return { path: codexPath, state: "untouched" };
|
|
336
456
|
const gateway = env.gateway() || {};
|
|
337
|
-
if (typeof gateway.token !== "string" || gateway.token.length === 0 || !fs.existsSync(codexPath)) return { path: codexPath, state: "untouched" };
|
|
338
457
|
const url = `http://127.0.0.1:${typeof gateway.port === "number" ? gateway.port : 7470}/mcp`;
|
|
458
|
+
const token = typeof gateway.token === "string" ? gateway.token : "";
|
|
339
459
|
const raw = fs.readFileSync(codexPath, "utf8");
|
|
340
|
-
const next = withCodexGatewayEntry(raw, url,
|
|
460
|
+
const next = withoutDeadNotify(token.length === 0 ? withCodexWorkspaceHelpers(raw) : withCodexGatewayEntry(raw, url, token));
|
|
341
461
|
if (next === raw) return { path: codexPath, state: "configured" };
|
|
342
462
|
atomicWrite(codexPath, next, read);
|
|
343
463
|
return { path: codexPath, state: "scoped" };
|
package/dist/notify.js
CHANGED
|
@@ -2195,7 +2195,8 @@ async function pollSlackOnce(token, channel) {
|
|
|
2195
2195
|
.filter(m => !m.subtype && !m.bot_id && !m.app_id && m.user && String(m.text ?? "").trim())
|
|
2196
2196
|
.sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
2197
2197
|
const isAsk = (m) => String(m.text ?? "").replace(/<@[A-Za-z0-9]+>/g, "").toLowerCase().trim().startsWith(AGENT_PREFIX);
|
|
2198
|
-
|
|
2198
|
+
// Every message meant for the agent — his own words and a '!'-prefixed ask — not bus commands or a message addressed to a connected client.
|
|
2199
|
+
const forAgent = human.filter((m) => !isSlackBusTraffic(m));
|
|
2199
2200
|
// Meni is found before anything is taken off the channel, so a users.list that fails for a moment throws here and every message is read again; a poll with no human message and no open agent thread never asks.
|
|
2200
2201
|
let owner;
|
|
2201
2202
|
try {
|
|
@@ -2206,9 +2207,11 @@ async function pollSlackOnce(token, channel) {
|
|
|
2206
2207
|
catch (err) {
|
|
2207
2208
|
if (!(err instanceof SlackOwnerUnknown) && !(err instanceof SlackRefused && err.error === "missing_scope"))
|
|
2208
2209
|
throw err;
|
|
2209
|
-
// OWNER: the agent answers only Meni, and Slack will not name him until the app holds users:read — no
|
|
2210
|
-
if (err.message !== slackOwnerRefusal)
|
|
2211
|
-
log("·", "agent:slack", `${
|
|
2210
|
+
// OWNER: the agent answers only Meni, and Slack will not name him until the app holds users:read — no message of his is answered, the reason is said once in the channel and logged once, and the bus goes on.
|
|
2211
|
+
if (err.message !== slackOwnerRefusal) {
|
|
2212
|
+
log("·", "agent:slack", `${forAgent.length} message(s) in ${channel} not answered: ${err.message}`);
|
|
2213
|
+
await reply(`⚠️ Nothing you post in this channel reaches an agent — ${err.message}. Tap Reinstall in BN once that is fixed.`);
|
|
2214
|
+
}
|
|
2212
2215
|
slackOwnerRefusal = err.message;
|
|
2213
2216
|
}
|
|
2214
2217
|
for (const m of human) {
|
|
@@ -2216,12 +2219,16 @@ async function pollSlackOnce(token, channel) {
|
|
|
2216
2219
|
try {
|
|
2217
2220
|
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2218
2221
|
if (isAsk(m)) {
|
|
2222
|
+
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2219
2223
|
if (owner !== undefined)
|
|
2220
2224
|
await answerSlackAgentMessage(token, channel, m, owner);
|
|
2221
2225
|
}
|
|
2222
2226
|
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2223
2227
|
else if (owner !== undefined && m.user === owner && !isSlackBusTraffic(m))
|
|
2224
2228
|
takeSlackDmMessage(slackChannelChat(token, channel), owner, m);
|
|
2229
|
+
// The owner is unknown, so his words cannot be told apart from anyone else's and are answered by nobody — the channel already says why; never the misleading "No agents connected" reply.
|
|
2230
|
+
else if (owner === undefined && !isSlackBusTraffic(m))
|
|
2231
|
+
continue;
|
|
2225
2232
|
else
|
|
2226
2233
|
await routeSlackInbox(m, reply);
|
|
2227
2234
|
}
|
|
@@ -2283,14 +2290,35 @@ const slackThreadCursor = (channel, threadTs) => POLL_CURSORS.cursor(`${SLACK_TH
|
|
|
2283
2290
|
const slackDms = new Map();
|
|
2284
2291
|
/** Why the direct message cannot be read with this bot token; it is not tried again until the token changes or BN restarts. */
|
|
2285
2292
|
let slackDmOff;
|
|
2286
|
-
/**
|
|
2293
|
+
/** The direct-message channel of the workspace owner: Slack's conversations.open once the app holds im:write, else opened by a post to his user id (chat:write alone) that is deleted at once, so his chat is left exactly as it was — no greeting, and the DM still works on a workspace that never granted im:write. */
|
|
2294
|
+
async function openSlackDm(token, owner) {
|
|
2295
|
+
try {
|
|
2296
|
+
return String((await slackCall(SLACK_API_BASE, token, "conversations.open", { users: owner })).channel.id);
|
|
2297
|
+
}
|
|
2298
|
+
catch (err) {
|
|
2299
|
+
if (!(err instanceof SlackRefused) || err.error !== "missing_scope")
|
|
2300
|
+
throw err;
|
|
2301
|
+
}
|
|
2302
|
+
const opened = await slackCall(SLACK_API_BASE, token, "chat.postMessage", { channel: owner, text: "." });
|
|
2303
|
+
const channel = String(opened.channel);
|
|
2304
|
+
try {
|
|
2305
|
+
await slackCall(SLACK_API_BASE, token, "chat.delete", { channel, ts: String(opened.ts) });
|
|
2306
|
+
}
|
|
2307
|
+
catch (err) {
|
|
2308
|
+
// OWNER: a Slack documented refusal or an unreachable Slack when deleting the opener must not cost him the whole direct message — the failure is logged and the DM is opened with the opener line left in place.
|
|
2309
|
+
if (!(err instanceof SlackRefused) && !(err instanceof SlackUnreachable) && !(err instanceof SlackUnknown))
|
|
2310
|
+
throw err;
|
|
2311
|
+
log("·", "slack:error", `the Slack direct message was opened by a post that could not be deleted: ${err.message}`);
|
|
2312
|
+
}
|
|
2313
|
+
return channel;
|
|
2314
|
+
}
|
|
2315
|
+
/** Meni's direct-message chat with the bot: the workspace owner's, opened once per token, its conversation keyed by the channel id. */
|
|
2287
2316
|
async function slackDmOf(token, owner) {
|
|
2288
2317
|
const known = slackDms.get(token);
|
|
2289
2318
|
// NULL-OK: field known is OPTIONAL and therefore it is ok to check for NULL
|
|
2290
2319
|
if (known !== undefined)
|
|
2291
2320
|
return known;
|
|
2292
|
-
const
|
|
2293
|
-
const dm = new SlackMessenger(SLACK_API_BASE, token, String(opened.channel.id), slackSwitchedOn, undefined, undefined, (line) => log("→", "agent:slack", line), slackTappable);
|
|
2321
|
+
const dm = new SlackMessenger(SLACK_API_BASE, token, await openSlackDm(token, owner), slackSwitchedOn, undefined, undefined, (line) => log("→", "agent:slack", line), slackTappable);
|
|
2294
2322
|
slackDms.set(token, dm);
|
|
2295
2323
|
// The thread views post with the token they were made with: a new bot token starts them afresh.
|
|
2296
2324
|
slackThreadViews.clear();
|
|
@@ -9,6 +9,7 @@ import * as path from "node:path";
|
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
import { Duplex } from "node:stream";
|
|
12
|
+
import { Worker } from "node:worker_threads";
|
|
12
13
|
import { CLUSTER_OWNER, OwnershipUnreadable, startOwnerOf } from "./providerOwnership.js";
|
|
13
14
|
import { AutoStartUnread, autoStartOnAt, sameRoot, savedAutoStart, workspacesHere } from "./workspaceList.js";
|
|
14
15
|
export function isProcessAlive(pid) {
|
|
@@ -1831,13 +1832,52 @@ export class ProcessTableUnreadable extends Error {
|
|
|
1831
1832
|
function throwProcessRead() {
|
|
1832
1833
|
throw new ProcessTableUnreadable("the process table could not be read");
|
|
1833
1834
|
}
|
|
1835
|
+
function serveTableReader() {
|
|
1836
|
+
const { parentPort: port, workerData: launch } = require("node:worker_threads");
|
|
1837
|
+
const { spawn } = require("node:child_process");
|
|
1838
|
+
// GATE: the worker claims state 0 before spawning; a stop that has already changed it closes the port without starting a child.
|
|
1839
|
+
if (Atomics.compareExchange(launch.launchState, 0, 0, 1) !== 0) {
|
|
1840
|
+
port.close();
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
const child = spawn(launch.file, [...launch.args], {
|
|
1844
|
+
cwd: launch.cwd,
|
|
1845
|
+
env: launch.env ?? process.env,
|
|
1846
|
+
windowsHide: true,
|
|
1847
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
1848
|
+
});
|
|
1849
|
+
const send = (reply) => port.postMessage(reply);
|
|
1850
|
+
const fail = (error) => {
|
|
1851
|
+
send({ error });
|
|
1852
|
+
port.close();
|
|
1853
|
+
};
|
|
1854
|
+
let output = "";
|
|
1855
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
1856
|
+
output += chunk;
|
|
1857
|
+
const end = output.indexOf(launch.end);
|
|
1858
|
+
if (end !== -1) {
|
|
1859
|
+
send({ output: output.slice(0, end) });
|
|
1860
|
+
output = "";
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
child.once("exit", (code, signal) => fail(`the process table reader exited before it answered (${signal ?? `exit code ${code}`})`));
|
|
1864
|
+
child.once("error", (err) => fail(`the process table reader could not be started — ${err.message}`));
|
|
1865
|
+
child.stdin.on("error", (err) => fail(`the request could not be written to the process table reader — ${err.message}`));
|
|
1866
|
+
port.on("message", (request) => {
|
|
1867
|
+
if (request === null)
|
|
1868
|
+
port.close();
|
|
1869
|
+
else
|
|
1870
|
+
child.stdin.write(`${request}\n`);
|
|
1871
|
+
});
|
|
1872
|
+
port.once("close", () => { child.kill(); });
|
|
1873
|
+
}
|
|
1834
1874
|
/** #14288 — the Windows table reader, bound to the process it serves: it ends the moment that process is gone, whoever still holds its input. */
|
|
1835
1875
|
export function windowsTableLaunch(ownerPid) {
|
|
1836
1876
|
return { file: "powershell", args: ["-NoProfile", "-NonInteractive", "-Command", "Invoke-Expression $env:AGENT_SESSION_WINDOWS_TABLE"], env: { ...process.env, AGENT_SESSION_WINDOWS_TABLE: windowsTableScript(ownerPid) } };
|
|
1837
1877
|
}
|
|
1838
1878
|
export class TableReader {
|
|
1839
1879
|
launch;
|
|
1840
|
-
|
|
1880
|
+
reader;
|
|
1841
1881
|
queue = Promise.resolve();
|
|
1842
1882
|
phase = "open";
|
|
1843
1883
|
bound;
|
|
@@ -1847,9 +1887,9 @@ export class TableReader {
|
|
|
1847
1887
|
}
|
|
1848
1888
|
close() {
|
|
1849
1889
|
this.phase = "closed";
|
|
1850
|
-
// NULL-OK: field
|
|
1851
|
-
if (this.
|
|
1852
|
-
this.stop(this.
|
|
1890
|
+
// NULL-OK: field reader is OPTIONAL and therefore it is ok to check for NULL
|
|
1891
|
+
if (this.reader !== undefined) {
|
|
1892
|
+
this.stop(this.reader);
|
|
1853
1893
|
}
|
|
1854
1894
|
}
|
|
1855
1895
|
read(request) {
|
|
@@ -1880,82 +1920,65 @@ export class TableReader {
|
|
|
1880
1920
|
if (this.phase === "closed") {
|
|
1881
1921
|
return Promise.reject(new ProcessTableUnreadable("the process table reader was closed with the build that owned it"));
|
|
1882
1922
|
}
|
|
1883
|
-
const
|
|
1923
|
+
const reader = this.reader ?? await this.start();
|
|
1924
|
+
const { worker } = reader;
|
|
1884
1925
|
return new Promise((resolve, reject) => {
|
|
1885
|
-
let out = "";
|
|
1886
1926
|
const settle = () => {
|
|
1887
1927
|
clearTimeout(hung);
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
child.stdin.off("error", onPipeError);
|
|
1892
|
-
};
|
|
1893
|
-
const onData = (chunk) => {
|
|
1894
|
-
out += chunk;
|
|
1895
|
-
const end = out.indexOf(TABLE_END);
|
|
1896
|
-
if (end !== -1) {
|
|
1897
|
-
settle();
|
|
1898
|
-
resolve(out.slice(0, end));
|
|
1899
|
-
}
|
|
1928
|
+
worker.off("message", onReply);
|
|
1929
|
+
worker.off("exit", onExit);
|
|
1930
|
+
worker.off("error", onWorkerError);
|
|
1900
1931
|
};
|
|
1901
|
-
const
|
|
1932
|
+
const failed = (error) => {
|
|
1902
1933
|
settle();
|
|
1903
|
-
|
|
1934
|
+
this.stop(reader);
|
|
1935
|
+
reject(new ProcessTableUnreadable(error));
|
|
1904
1936
|
};
|
|
1905
|
-
const
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
reject(new ProcessTableUnreadable(`the request could not be written to the process table reader — ${err.message}`));
|
|
1937
|
+
const onReply = (reply) => {
|
|
1938
|
+
if ("error" in reply) {
|
|
1939
|
+
failed(reply.error);
|
|
1940
|
+
}
|
|
1941
|
+
else {
|
|
1942
|
+
settle();
|
|
1943
|
+
resolve(reply.output);
|
|
1944
|
+
}
|
|
1914
1945
|
};
|
|
1946
|
+
const onExit = (code) => failed(`the process table reader worker exited before it answered (exit code ${code})`);
|
|
1947
|
+
const onWorkerError = (err) => failed(`the process table reader worker failed — ${err.message}`);
|
|
1915
1948
|
const hung = setTimeout(() => {
|
|
1916
|
-
|
|
1917
|
-
this.stop(child);
|
|
1918
|
-
reject(new ProcessTableUnreadable(`the process table reader owed one answer for ${(this.bound * READER_HUNG_BOUNDS) / 1000} s and was stopped as hung`));
|
|
1949
|
+
failed(`the process table reader owed one answer for ${(this.bound * READER_HUNG_BOUNDS) / 1000} s and was stopped as hung`);
|
|
1919
1950
|
}, this.bound * READER_HUNG_BOUNDS);
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
child.stdin.once("error", onPipeError);
|
|
1924
|
-
child.stdin.write(`${request}\n`);
|
|
1951
|
+
worker.once("message", onReply).once("exit", onExit).once("error", onWorkerError);
|
|
1952
|
+
worker.unref();
|
|
1953
|
+
worker.postMessage(request);
|
|
1925
1954
|
});
|
|
1926
1955
|
}
|
|
1927
1956
|
async start() {
|
|
1928
|
-
const
|
|
1957
|
+
const launch = await this.launch();
|
|
1929
1958
|
if (this.phase === "closed") {
|
|
1930
1959
|
throw new ProcessTableUnreadable("the process table reader was closed while its launch was being resolved");
|
|
1931
1960
|
}
|
|
1932
|
-
const
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
stdio: ["pipe", "pipe", "ignore"],
|
|
1937
|
-
});
|
|
1938
|
-
child.stdout.setEncoding("utf8");
|
|
1961
|
+
const launchState = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
1962
|
+
const workerData = { ...launch, cwd: tmpdir(), end: TABLE_END, launchState };
|
|
1963
|
+
const worker = new Worker(`(${serveTableReader.toString()})()`, { eval: true, workerData });
|
|
1964
|
+
const reader = { worker, launchState };
|
|
1939
1965
|
const forget = () => {
|
|
1940
|
-
if (this.
|
|
1941
|
-
this.
|
|
1966
|
+
if (this.reader === reader) {
|
|
1967
|
+
this.reader = undefined;
|
|
1942
1968
|
}
|
|
1943
1969
|
};
|
|
1944
1970
|
// OWNER: a reader that ended or broke between reads answers nothing more — it is dropped, and the next read starts a fresh one.
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
child.stdin.unref();
|
|
1950
|
-
child.stdout.unref();
|
|
1951
|
-
this.child = child;
|
|
1952
|
-
return child;
|
|
1971
|
+
worker.once("exit", forget).once("error", forget);
|
|
1972
|
+
worker.unref();
|
|
1973
|
+
this.reader = reader;
|
|
1974
|
+
return reader;
|
|
1953
1975
|
}
|
|
1954
|
-
stop(
|
|
1955
|
-
if (this.
|
|
1956
|
-
this.
|
|
1976
|
+
stop(reader) {
|
|
1977
|
+
if (this.reader === reader) {
|
|
1978
|
+
this.reader = undefined;
|
|
1979
|
+
Atomics.store(reader.launchState, 0, 2);
|
|
1980
|
+
reader.worker.postMessage(null);
|
|
1957
1981
|
}
|
|
1958
|
-
child.kill();
|
|
1959
1982
|
}
|
|
1960
1983
|
}
|
|
1961
1984
|
/** #3934 — whether this OS lets FleetView count the CPU of a process that ended between two readings: Windows, through each lane's kernel job; elsewhere a process is counted only while a reading sees it. */
|
|
@@ -4171,6 +4194,41 @@ function movedWords(moved) {
|
|
|
4171
4194
|
/** 🔴 #4123 — a parked worker's idle process is stopped at once, and a stop that did not take is tried again only after its wait. */
|
|
4172
4195
|
// NULL-OK: field stoppedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
4173
4196
|
const stopDue = (worker, now) => worker.stoppedAt === undefined || now >= worker.stoppedAt + wakeDelayMs(worker.wakes ?? 0);
|
|
4197
|
+
/**
|
|
4198
|
+
* 🔴 #4559/#4587 — THE RUNNING LANE A CUT OF PRIORITY `cutPri` PAUSES, or undefined when none can be: the lowest priority first and never one above the
|
|
4199
|
+
* cut's own ({@link PRI_ORDER}), then the least progress — the lane's living number, tool steps a minute — then the newest start; and only a worker whose
|
|
4200
|
+
* stop is asked at its next tool call, never one already pausing, parked, on another box, or ended by ⛔ Kill, so nothing is ever killed and the cut is never
|
|
4201
|
+
* itself. ONE chooser, so a ⚡ Force start and a BN chat's request that reaches the queue from outside it pick the same lane.
|
|
4202
|
+
*/
|
|
4203
|
+
export function yieldLaneFor(entries, cutStoryId, cutPri, progress) {
|
|
4204
|
+
const rank = (x) => rankIn(PRI_ORDER, x.pri);
|
|
4205
|
+
const cut = rankIn(PRI_ORDER, cutPri);
|
|
4206
|
+
const pausable = (x) => x.storyId !== cutStoryId && x.state === "running" && x.handStop === undefined && x.worker !== undefined && x.worker.parkedAt === undefined && x.worker.box === undefined && stopRouteOf(x.worker).stop === "asked" && rank(x) >= cut;
|
|
4207
|
+
return entries.filter(pausable).sort((a, b) => rank(b) - rank(a) || progress(a.storyId) - progress(b.storyId) || b.worker.startedAt - a.worker.startedAt)[0];
|
|
4208
|
+
}
|
|
4209
|
+
/**
|
|
4210
|
+
* 🔴 #4587 items 8–11 — A REQUEST THAT REACHES THE QUEUE FROM OUTSIDE IT TAKES ITS SLOT, THE WORKING LANE IS PUT BACK INTACT. A BN chat's lane works a story
|
|
4211
|
+
* of this board directly (outside the queue), so FleetView injects it as a first-class queue row ({@link gateStoryHolders}) and, once that lane takes the
|
|
4212
|
+
* workspace past its lane limit, pauses the lane this request outranks that has made the least progress — the SAME pause a ⚡ Force start makes
|
|
4213
|
+
* ({@link yieldLaneFor}), never a second preemption. The paused lane keeps its story, its worktree, its branch and its worker's own session, goes back in line
|
|
4214
|
+
* with exactly the progress it had, and is woken in its own session when a lane frees. Answers what it did, in words naming both lanes.
|
|
4215
|
+
*/
|
|
4216
|
+
export async function yieldLaneForRequest(board, storyId, pri, progress, now, by) {
|
|
4217
|
+
return withQueueLock(board, now, async () => {
|
|
4218
|
+
const store = readQueueStore(board);
|
|
4219
|
+
const lane = yieldLaneFor(store.entries, storyId, pri, progress);
|
|
4220
|
+
// NULL-OK: field lane is OPTIONAL and therefore it is ok to check for NULL
|
|
4221
|
+
if (lane === undefined)
|
|
4222
|
+
return `#${storyId} (${pri}) takes a lane from no running lane — none on this board is of its priority or lower with a stop asked at its next step`;
|
|
4223
|
+
lane.handStop = { at: now, by, yieldFor: storyId };
|
|
4224
|
+
delete lane.pauseCancelled;
|
|
4225
|
+
const known = progress(lane.storyId);
|
|
4226
|
+
lane.why = `${stopNamed(lane.handStop)}: #${storyId} (${pri}) outranks it and takes its lane, and it is the ${lane.pri} lane with the least progress (${Number.isFinite(known) ? `${known.toFixed(1)} tool steps a minute` : "no transcript reading"}) — its worker ${lane.worker.jobId} is asked to finish its step, write its progress and end its turn, then it keeps its worktree, its branch and its session, goes back in line and is woken in its own session`;
|
|
4227
|
+
step(lane, now, "stop-asked", lane.why);
|
|
4228
|
+
writeStore(board, store);
|
|
4229
|
+
return `#${storyId} (${pri}) takes the lane of #${lane.storyId}, the ${lane.pri} lane with the least progress — its worker ${lane.worker.jobId} is paused at its next step and put back in the queue with its worktree, branch and progress kept`;
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4174
4232
|
/**
|
|
4175
4233
|
* 🔴 ONE PASS OF FLEETVIEW'S STORY QUEUE ON ONE BOARD, under its lock: every request derived from the board's startable read is applied,
|
|
4176
4234
|
* every worker is checked (a story shipped closes its entry; a worker that ended with the story still open is started
|
|
@@ -5020,12 +5078,9 @@ async function passHeld(board, world, now) {
|
|
|
5020
5078
|
// NULL-OK: field short is OPTIONAL and therefore it is ok to check for NULL
|
|
5021
5079
|
if (!overLimit && short === undefined)
|
|
5022
5080
|
return;
|
|
5023
|
-
const rank = (x) => rankIn(PRI_ORDER, x.pri);
|
|
5024
5081
|
// NULL-OK: field progressOf is OPTIONAL and therefore it is ok to check for NULL
|
|
5025
|
-
const progress = (
|
|
5026
|
-
|
|
5027
|
-
const pausable = (x) => x !== cut && x.state === "running" && x.handStop === undefined && x.worker !== undefined && x.worker.parkedAt === undefined && x.worker.box === undefined && stopRouteOf(x.worker).stop === "asked" && rank(x) >= rank(cut);
|
|
5028
|
-
const lane = store.entries.filter(pausable).sort((a, b) => rank(b) - rank(a) || progress(a) - progress(b) || b.worker.startedAt - a.worker.startedAt)[0];
|
|
5082
|
+
const progress = (storyId) => world.progressOf?.(storyId) ?? Number.POSITIVE_INFINITY;
|
|
5083
|
+
const lane = yieldLaneFor(store.entries, cut.storyId, cut.pri, progress);
|
|
5029
5084
|
const over = overLimit ? `${running} lanes run past this workspace's limit of ${lanes.limit}` : short.why;
|
|
5030
5085
|
// NULL-OK: field lane is OPTIONAL and therefore it is ok to check for NULL
|
|
5031
5086
|
if (lane === undefined) {
|
|
@@ -5034,7 +5089,7 @@ async function passHeld(board, world, now) {
|
|
|
5034
5089
|
}
|
|
5035
5090
|
lane.handStop = { at: now, by: `${by} ⚡ Force start of #${cut.storyId}`, yieldFor: cut.storyId };
|
|
5036
5091
|
delete lane.pauseCancelled;
|
|
5037
|
-
const known = progress(lane);
|
|
5092
|
+
const known = progress(lane.storyId);
|
|
5038
5093
|
lane.why = `${stopNamed(lane.handStop)}: ${over}, and it is the ${lane.pri} lane with the least progress (${Number.isFinite(known) ? `${known.toFixed(1)} tool steps a minute` : "no transcript reading"}) — its worker ${lane.worker.jobId} is asked to finish its step, write its progress and end its turn, then it waits in line and is woken in its own session`;
|
|
5039
5094
|
step(lane, now, "stop-asked", lane.why);
|
|
5040
5095
|
step(cut, now, "started", `its ⚡ Force start runs past the limit (${over}), so #${lane.storyId}, the ${lane.pri} lane with the least progress, is paused at its next step for it`);
|
|
@@ -15,6 +15,7 @@ import { EventEmitter } from "events";
|
|
|
15
15
|
import { homedir } from "os";
|
|
16
16
|
import { basename, dirname, join, resolve } from "path";
|
|
17
17
|
import autoSwitch from "../webhost/autoSwitch.cjs";
|
|
18
|
+
import { proveStartProviders } from "./providerProof.js";
|
|
18
19
|
import { workspacesFile, workspacesHere } from "../webhost/workspaceList.js";
|
|
19
20
|
import { CLUSTER_OWNER, OwnershipUnreadable, startOwnerOf } from "../providerOwnership.js";
|
|
20
21
|
/** Thrown for a request the caller got wrong; the door turns it into the status code. */
|
|
@@ -722,12 +723,21 @@ export function createConversationStore(host, registry) {
|
|
|
722
723
|
* The agent CLI a session is CREATED on (#3640): the one its creation named, or — named none (#4157) — the shared
|
|
723
724
|
* subscription-first pick (`autoProvider`, the one FleetView's AUTO runs) over every CLI this gateway runs — at the
|
|
724
725
|
* workspace root only those that load every project's rules there — weighed by DeepAgent's `provider_room` read for the folder.
|
|
726
|
+
*
|
|
727
|
+
* #4621 — AND PINGED FIRST, BY CONSTRUCTION. A provider that reads roomy is not a provider that ANSWERS. The ping rides
|
|
728
|
+
* the ONE reading every picker already takes (`readProviderRooms` asks DeepAgent's door with `prove: true`, and the shared
|
|
729
|
+
* reading treats a provider whose route did not answer as `out`), so this pick — and FleetView's queue and any other app's
|
|
730
|
+
* picker over the same reading — skip a route that does not answer with no second check here. A provider he NAMED by hand
|
|
731
|
+
* takes no room read, so it is proved directly and a refusal is said plainly, never silently swapped for another CLI.
|
|
725
732
|
*/
|
|
726
733
|
async function pickedCli(provider, folder, model) {
|
|
727
734
|
if (provider !== undefined && provider !== "auto" && !(typeof provider === "string" && provider.trim() === "")) {
|
|
728
735
|
const named = namedProvider(provider);
|
|
729
736
|
if (heldElsewhere(host.startOwner, named))
|
|
730
737
|
throw heldBy(host.startOwner, named);
|
|
738
|
+
const [proof] = await proveStartProviders(folder, [named], deepagentDoor());
|
|
739
|
+
if (proof !== undefined && proof.state === "failed")
|
|
740
|
+
throw new GatewayError(503, `${named} does not answer now — ${proof.line}. Your choice was not replaced with another CLI: pick a different provider, or repair this one in DeepAgent, and start again.`);
|
|
731
741
|
return { provider: named };
|
|
732
742
|
}
|
|
733
743
|
const startable = (isRootFolder(folder) ? registry().names.filter((name) => registry().get(name).routesAtRoot === true) : registry().names).filter((name) => !heldElsewhere(host.startOwner, name));
|
|
@@ -749,11 +759,13 @@ export function createConversationStore(host, registry) {
|
|
|
749
759
|
home: homedir(),
|
|
750
760
|
usesKey: (name) => registry().get(name)?.usesKey?.(folder, model) ?? false,
|
|
751
761
|
});
|
|
762
|
+
// #4621 — a provider whose route the ping refused reads `out` on its own reading, so the pick has already moved past it; name every refusal so a start that lands nowhere says why.
|
|
763
|
+
const refused = Object.entries(rooms).flatMap(([id, r]) => (r?.proof?.state === "failed" ? [`${id} does not answer now — ${r.proof.line}`] : []));
|
|
752
764
|
if (picked === undefined)
|
|
753
|
-
throw new GatewayError(503, "Auto has no subscription with room and no permitted, funded key for the eligible CLIs.");
|
|
765
|
+
throw new GatewayError(503, refused.length > 0 ? `no agent CLI answers now: ${refused.join("; ")}` : "Auto has no subscription with room and no permitted, funded key for the eligible CLIs.");
|
|
754
766
|
const unread = [...new Set(Object.values(rooms).flatMap((r) => (r?.state === "unread" ? [r.reason] : [])))];
|
|
755
767
|
const words = Object.entries(rooms).map(([id, r]) => `${id} ${r?.state}`).join(", ") + (unread.length === 0 ? "" : ` — unread: ${unread.join("; ")}`);
|
|
756
|
-
process.stderr.write(`[agent-gateway] no provider named for ${folder}: ${picked} of ${startable.join("/")}, the subscription-first pick over ${words}\n`);
|
|
768
|
+
process.stderr.write(`[agent-gateway] no provider named for ${folder}: ${picked} of ${startable.join("/")}, the subscription-first pick over ${words}${refused.length === 0 ? "" : ` — refused by the ping: ${refused.join("; ")}`}\n`);
|
|
757
769
|
return { provider: picked, ...(unreadBecause === undefined ? {} : { unreadBecause }) };
|
|
758
770
|
}
|
|
759
771
|
/** #4157 — the creations still waiting on their CLI pick, by the chat they are made for: an ask from that chat routes only once they exist, so it is never doubled beside one nor sent past it. */
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4621 — THE PING GATE BEFORE AN AGENT IS CREATED.
|
|
3
|
+
*
|
|
4
|
+
* Meni: *"flawless transition between agentic provider/sub/key at all time"*. A provider's room reading
|
|
5
|
+
* (`provider_room`) says an account has room LEFT; it never says the route ANSWERS — a funded key the provider
|
|
6
|
+
* gates, a revoked login, or a provider whose tool enum refuses the client all read as room with no call ever
|
|
7
|
+
* made. So the start door pings each candidate BEFORE it creates the agent: DeepAgent runs one real model call
|
|
8
|
+
* per provider on the very combination (provider, subscription or key, model) a new agent there would run on,
|
|
9
|
+
* and this returns one row per provider saying whether it answered.
|
|
10
|
+
*
|
|
11
|
+
* A provider the call refused is dropped and the pick moves on; one DeepAgent cannot call right now (its own
|
|
12
|
+
* door gave no answer) is `untestable`, never a failure — an untaken reading is not the same as one that failed.
|
|
13
|
+
*
|
|
14
|
+
* The call goes over DeepAgent's MCP door, the same door `autoSwitch.readProviderRooms` reads room from. The
|
|
15
|
+
* address is mirrored here rather than shared because that module was held by another lane when this landed.
|
|
16
|
+
*/
|
|
17
|
+
const DEEPAGENT_MCP_URL = "http://127.0.0.1:7473/mcp";
|
|
18
|
+
// GATE: how long one `provider_prove` read may take before every row reads untestable — DeepAgent pings its
|
|
19
|
+
// providers in parallel, each bounded at its own 30s, so 45s clears the slowest single pass and no more.
|
|
20
|
+
const PROVE_READ_TIMEOUT_MS = 45_000;
|
|
21
|
+
/**
|
|
22
|
+
* Pings the named providers over DeepAgent's `provider_prove` door and returns one row each. A door that gives
|
|
23
|
+
* no answer, a non-200, or a body that is no reading makes every row `untestable` with the reason — a reading
|
|
24
|
+
* this gate could not take never silently passes a provider as working, and never blocks a start either.
|
|
25
|
+
*/
|
|
26
|
+
export async function proveStartProviders(project, providers, url) {
|
|
27
|
+
const door = url ?? DEEPAGENT_MCP_URL;
|
|
28
|
+
const everyUntestable = (why) => providers.map((provider) => ({ provider, state: "untestable", line: why }));
|
|
29
|
+
let res;
|
|
30
|
+
try {
|
|
31
|
+
res = await fetch(door, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "x-deepagent-project": project },
|
|
34
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_prove", arguments: { providers: [...providers] } } }),
|
|
35
|
+
signal: AbortSignal.timeout(PROVE_READ_TIMEOUT_MS),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (!(err instanceof TypeError) && !(err instanceof Error && err.name === "TimeoutError"))
|
|
40
|
+
throw err;
|
|
41
|
+
const cause = err instanceof Error && err.cause instanceof Error ? ` (${err.cause.message})` : "";
|
|
42
|
+
return everyUntestable(`DeepAgent's ping door at ${door} gave no answer: ${err instanceof Error ? err.message : String(err)}${cause}`);
|
|
43
|
+
}
|
|
44
|
+
if (res.status !== 200)
|
|
45
|
+
return everyUntestable(`provider_prove answered HTTP ${res.status}`);
|
|
46
|
+
let reply;
|
|
47
|
+
try {
|
|
48
|
+
reply = JSON.parse(await res.text());
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (!(err instanceof SyntaxError))
|
|
52
|
+
throw err;
|
|
53
|
+
return everyUntestable("provider_prove's reply is not JSON");
|
|
54
|
+
}
|
|
55
|
+
const body = reply.result?.content?.[0]?.text;
|
|
56
|
+
if (reply.result === undefined || reply.result.isError === true || typeof body !== "string") {
|
|
57
|
+
return everyUntestable(`provider_prove gave no reading: ${String(body ?? reply.error?.message ?? "").slice(0, 200)}`);
|
|
58
|
+
}
|
|
59
|
+
let reading;
|
|
60
|
+
try {
|
|
61
|
+
reading = JSON.parse(body);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (!(err instanceof SyntaxError))
|
|
65
|
+
throw err;
|
|
66
|
+
return everyUntestable("provider_prove's reading is not JSON");
|
|
67
|
+
}
|
|
68
|
+
const rows = Array.isArray(reading.proofs) ? reading.proofs : [];
|
|
69
|
+
return providers.map((provider) => {
|
|
70
|
+
const found = rows.find((row) => row?.provider === provider);
|
|
71
|
+
return found !== undefined && typeof found.state === "string" && typeof found.line === "string"
|
|
72
|
+
? { provider, state: found.state, line: found.line }
|
|
73
|
+
: { provider, state: "untestable", line: "provider_prove did not answer for this provider" };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -551,7 +551,7 @@ class RoomReadError extends Error {
|
|
|
551
551
|
/**
|
|
552
552
|
* @typedef {{ label: string, roomPct: number | undefined, resetsAt: number | undefined, refused: boolean, unread?: string }} AccountRoom
|
|
553
553
|
* @typedef {{ label: string, funds: string }} KeyRoom
|
|
554
|
-
* @typedef {{ live?: string, accounts?: AccountRoom[], keys?: KeyRoom[] }} RoomDetail
|
|
554
|
+
* @typedef {{ live?: string, accounts?: AccountRoom[], keys?: KeyRoom[], proof?: { state: string, line: string } }} RoomDetail
|
|
555
555
|
* @typedef {({ state: "room" } | { state: "out", resetsAtMs: number | undefined } | { state: "unread", reason: string }) & RoomDetail} RoomReading
|
|
556
556
|
* @typedef {Partial<Record<string, RoomReading>>} ProviderRooms
|
|
557
557
|
*/
|
|
@@ -569,7 +569,9 @@ function roomDetailOf(provider, keys, id) {
|
|
|
569
569
|
}));
|
|
570
570
|
// NULL-OK: field keys is OPTIONAL and therefore it is ok to check for NULL
|
|
571
571
|
const runs = keys === undefined ? {} : { keys: keys.filter((k) => Array.isArray(k.agents) && k.agents.includes(id)).map((k) => ({ label: String(k.label ?? k.id), funds: String(k.funds) })) };
|
|
572
|
-
|
|
572
|
+
// #4621 — the one real call that proved this provider's live route, carried onto the reading so a picker that lands elsewhere can say WHY.
|
|
573
|
+
const proof = provider.proof && typeof provider.proof.state === "string" ? { proof: { state: String(provider.proof.state), line: String(provider.proof.line ?? "") } } : {};
|
|
574
|
+
return { ...(typeof provider.live === "string" ? { live: provider.live } : {}), accounts, ...runs, ...proof };
|
|
573
575
|
}
|
|
574
576
|
/** @param {string} provider */
|
|
575
577
|
function runsOnKeys(provider) {
|
|
@@ -635,6 +637,11 @@ function roomReadingOf(provider, now, keys, id) {
|
|
|
635
637
|
}
|
|
636
638
|
const accounts = provider.accounts;
|
|
637
639
|
const detail = roomDetailOf(provider, keys, id);
|
|
640
|
+
// #4621 — A PROVIDER THAT DID NOT ANSWER IS NOT ROOM, whatever its room says: the ping gate, folded into the ONE
|
|
641
|
+
// reading every picker already takes, so a route that refuses a real call is never picked — by construction, with
|
|
642
|
+
// no second check in any door. `state: "out"` is what every picker already treats as "not this one".
|
|
643
|
+
if (provider.proof && provider.proof.state === "failed")
|
|
644
|
+
return { state: "out", resetsAtMs: undefined, ...detail };
|
|
638
645
|
if (accounts.some((a) => a.state === "read" && a.refused !== true && (a.unlimited === true || (typeof a.roomPct === "number" && a.roomPct > 0))))
|
|
639
646
|
return { state: "room", ...detail };
|
|
640
647
|
if (accounts.length === 0 || !accounts.every((a) => a.state === "read" && typeof a.roomPct === "number"))
|
|
@@ -663,8 +670,14 @@ function unreadRooms(reason) {
|
|
|
663
670
|
/**
|
|
664
671
|
* THE one pick of an agent CLI when the caller named none: of `order` the ones `startable` can run, a provider with room
|
|
665
672
|
* first. An automatic conversation can draw on keys only when the eligible subscriptions are spent and DeepAgent's fallback is enabled for a compatible funded key.
|
|
673
|
+
*
|
|
674
|
+
* 🔴 #14742 — MENI'S OWN RULING IS A THIRD WAY ONTO A KEY, and the caller that owns the story's priority and board says so
|
|
675
|
+
* with `permittedFundedKey`: he ruled 2026-11-28 that a funded API key may start a P0 money-path story while his Claude
|
|
676
|
+
* subscription is at its weekly limit. It stands in for "every eligible subscription is spent" and nothing else — a
|
|
677
|
+
* subscription with room still wins, DeepAgent's fallback box must still be on for that provider, and the key must still
|
|
678
|
+
* have usable funds, so the allowance can only ever reach a key that was already permitted and funded.
|
|
666
679
|
* @param {readonly string[]} order @param {ProviderRooms} rooms @param {readonly string[]} startable
|
|
667
|
-
* @param {{ home: string, usesKey: (provider: string) => boolean, confirmedRoom?: boolean }} [billing]
|
|
680
|
+
* @param {{ home: string, usesKey: (provider: string) => boolean, confirmedRoom?: boolean, permittedFundedKey?: boolean }} [billing]
|
|
668
681
|
* @returns {string | undefined}
|
|
669
682
|
*/
|
|
670
683
|
function autoProvider(order, rooms, startable, billing) {
|
|
@@ -674,7 +687,7 @@ function autoProvider(order, rooms, startable, billing) {
|
|
|
674
687
|
const paid = candidates.filter((p) => !metered.has(p));
|
|
675
688
|
const withRoom = paid.filter((p) => rooms[p]?.state === "room");
|
|
676
689
|
const unread = paid.filter((p) => rooms[p]?.state !== "room" && rooms[p]?.state !== "out");
|
|
677
|
-
const allSpent = candidates.every((p) => metered.has(p) && runsOnKeys(p) || rooms[p]?.state === "out");
|
|
690
|
+
const allSpent = billing.permittedFundedKey === true || candidates.every((p) => metered.has(p) && runsOnKeys(p) || rooms[p]?.state === "out");
|
|
678
691
|
const allowedKey = (p) => metered.has(p) && readByokFallback(billing.home, AGENT_CLIS.find((cli) => cli.id === p).subscriptionProvider) && rooms[p]?.keys?.some((k) => k.funds === "usable");
|
|
679
692
|
candidates = withRoom.length > 0 ? withRoom : unread.length > 0 && !billing.confirmedRoom ? unread : allSpent ? candidates.filter(allowedKey) : [];
|
|
680
693
|
if (billing.confirmedRoom)
|
|
@@ -692,7 +705,7 @@ async function roomDoorAnswer(url, project) {
|
|
|
692
705
|
const res = await fetch(url, {
|
|
693
706
|
method: "POST",
|
|
694
707
|
headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "x-deepagent-project": project },
|
|
695
|
-
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_room", arguments: {} } }),
|
|
708
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_room", arguments: { prove: true } } }),
|
|
696
709
|
signal: AbortSignal.timeout(ROOM_READ_TIMEOUT_MS),
|
|
697
710
|
});
|
|
698
711
|
return { status: res.status, body: await res.text() };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.475",
|
|
4
4
|
"homepage": "https://www.npmjs.com/package/omni-notify-mcp",
|
|
5
5
|
"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.",
|
|
6
6
|
"main": "dist/daemon.js",
|