omni-notify-mcp 1.3.352 → 1.3.354
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.
|
@@ -254,14 +254,14 @@ export class PublicAccessWizard {
|
|
|
254
254
|
: gw.token
|
|
255
255
|
? { severity: "warning", text: "⚠️ A gateway token is set, but BN's background process has not reported the door in the last 30 seconds — it is not running, or it is a build from before this wizard and reports after it restarts." }
|
|
256
256
|
: { severity: "warning", text: "🎯 No gateway token yet, so the door is closed. Create one." };
|
|
257
|
-
const states = { running: "✅ Connected", starting: "⏳ Connecting", exited: "❌ Stopped", failed: "❌ Could not start", "missing-binary": "❌ cloudflared is not installed" };
|
|
257
|
+
const states = { running: "✅ Connected", starting: "⏳ Connecting", exited: "❌ Stopped", failed: "❌ Could not start", "missing-binary": "❌ cloudflared is not installed", held: "⏸ Held" };
|
|
258
258
|
const connectorNote = !saved
|
|
259
259
|
? undefined
|
|
260
260
|
: !state
|
|
261
261
|
? { severity: "warning", text: "⚠️ BN's background process has not reported in the last 30 seconds, so the connector's state is not known." }
|
|
262
262
|
: !connector
|
|
263
263
|
? { severity: "warning", text: "⏳ The token is saved; the background process starts the connector on its next beat (within 10 seconds)." }
|
|
264
|
-
: { severity: running ? "good" : connector.state === "starting" ? "warning" : "error", text: `${states[connector.state]} — ${connector.detail}` };
|
|
264
|
+
: { severity: running ? "good" : connector.state === "starting" || connector.state === "held" ? "warning" : "error", text: `${states[connector.state]} — ${connector.detail}` };
|
|
265
265
|
const tunnelId = saved ? parseTunnelToken(tunnel.token).tunnelId : undefined;
|
|
266
266
|
const note6 = this.notes[6];
|
|
267
267
|
const steps = [
|
package/dist/gateway/tunnel.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { execFileSync, spawn } from "child_process";
|
|
13
13
|
import { existsSync, mkdirSync, readFileSync, readlinkSync, renameSync, writeFileSync } from "fs";
|
|
14
|
+
import { homedir } from "os";
|
|
14
15
|
import { join } from "path";
|
|
15
16
|
import { CONFIG_DIR } from "../notify.js";
|
|
16
17
|
// Read by src/gateway/publicAccess.ts, which names both paths by the same rule.
|
|
@@ -29,6 +30,21 @@ function readTunnelSetup() {
|
|
|
29
30
|
return undefined;
|
|
30
31
|
return { token: tunnel.token, savedAt: typeof tunnel.savedAt === "number" ? tunnel.savedAt : 0 };
|
|
31
32
|
}
|
|
33
|
+
const boxFilePath = () => join(process.env.BULLSEYE_HOME ?? join(homedir(), ".bullseye"), "settings", "bn.box.json");
|
|
34
|
+
const UNREADABLE_BOX_FILE = new Set(["ENOENT", "EACCES", "EPERM", "EISDIR", "EBUSY"]);
|
|
35
|
+
/**
|
|
36
|
+
* Why this box may not run the connector, or undefined when its own `bn.box.json` declares it PROD — the one box whose connector may serve the public tunnel; that file is never carried to another box.
|
|
37
|
+
* Its own reader, not workspaceList's box store: that store's readSettings refuses while the tool has no shared settings file (bn has none), its boxFile is not exported, and it ignores BULLSEYE_HOME. A file that cannot be read THROWS, for the beat to carry as the held reading.
|
|
38
|
+
*/
|
|
39
|
+
function holdReason() {
|
|
40
|
+
const path = boxFilePath();
|
|
41
|
+
if (!existsSync(path))
|
|
42
|
+
return "held: not PROD — no bn.box.json on this box declares it, so it starts no cloudflared";
|
|
43
|
+
const box = JSON.parse(readFileSync(path, "utf8"));
|
|
44
|
+
if (box.schema !== 1 || typeof box.box !== "object" || box.box === null)
|
|
45
|
+
throw new SyntaxError('it is not a box-only settings file ({ "schema": 1, "box": {…} })');
|
|
46
|
+
return box.box["bn.prod"] === true ? undefined : "held: not PROD — bn.prod is not true in bn.box.json, so this box starts no cloudflared";
|
|
47
|
+
}
|
|
32
48
|
/** The executable a pid runs, or undefined when no such process is left. */
|
|
33
49
|
function executableOf(pid) {
|
|
34
50
|
if (process.platform === "win32") {
|
|
@@ -66,6 +82,23 @@ export class TunnelRunner {
|
|
|
66
82
|
this.setup = setup;
|
|
67
83
|
this.reading = undefined;
|
|
68
84
|
}
|
|
85
|
+
let held;
|
|
86
|
+
try {
|
|
87
|
+
held = setup ? holdReason() : undefined;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
// OWNER: the beat is the trigger root and a box file it cannot read or parse is carried as the held reading, which the wizard and the Output channel state, and the next beat reads the file again; any other failure is rethrown.
|
|
91
|
+
if (!(err instanceof SyntaxError) && !UNREADABLE_BOX_FILE.has(err.code ?? ""))
|
|
92
|
+
throw err;
|
|
93
|
+
held = `held: ${boxFilePath()} could not be read (${err.message}) — a box that cannot prove it is PROD starts no cloudflared`;
|
|
94
|
+
}
|
|
95
|
+
if (held !== undefined) {
|
|
96
|
+
this.stop();
|
|
97
|
+
this.reading = { state: "held", detail: held, pid: null };
|
|
98
|
+
}
|
|
99
|
+
else if (this.reading?.state === "held") {
|
|
100
|
+
this.reading = undefined;
|
|
101
|
+
}
|
|
69
102
|
// NULL-OK: field setup is OPTIONAL and therefore it is ok to check for NULL
|
|
70
103
|
if (setup && !this.child && this.reading === undefined)
|
|
71
104
|
this.start(setup.token);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
5
|
import * as path from "node:path";
|
|
5
6
|
export function isProcessAlive(pid) {
|
|
6
7
|
try {
|
|
@@ -1522,3 +1523,573 @@ export class OpenCodeTurn extends JsonlCliTurn {
|
|
|
1522
1523
|
}
|
|
1523
1524
|
}
|
|
1524
1525
|
}
|
|
1526
|
+
/**
|
|
1527
|
+
* 🔴 #4098 — THE STORY QUEUE: BullseyeBacklog says which stories are eligible, FleetView owns the queue that works them.
|
|
1528
|
+
*
|
|
1529
|
+
* Meni, 2026-11-14: BB's ONLY scheduling job is to notify FV about eligible stories and their changes; FV owns the
|
|
1530
|
+
* persistent ordered queue, the worker launch, its retries and its completion, with no VS Code window and no chat. So the
|
|
1531
|
+
* two meet on disk beside the board, in `<board>/.fleetview/queue/`, and neither needs the other to be up when it writes:
|
|
1532
|
+
*
|
|
1533
|
+
* - `requests/<story>.json` — BB's one standing request per story ({@link StoryRequest}): versioned, and named by a
|
|
1534
|
+
* `requestId` that is the hash of everything it says, so the same facts submitted twice are the same request.
|
|
1535
|
+
* - `acks/<story>.json` — FV's answer ({@link StoryAck}): the request it applied, the entry's state and its place.
|
|
1536
|
+
* A request whose id no ack names is NOT in FV's queue — BB writes it again until one does.
|
|
1537
|
+
* - `entries.json` — FV's queue ({@link QueueStore}), one entry per story, written only under `entries.lock`.
|
|
1538
|
+
*/
|
|
1539
|
+
export const STORY_QUEUE_WIRE = 1;
|
|
1540
|
+
const PRI_ORDER = ["P0", "P1", "P2", "P3", "P4", "P5"];
|
|
1541
|
+
const EFFORT_ORDER = ["XS", "S", "M", "L", "XL"];
|
|
1542
|
+
export const storyQueueDir = (board) => path.join(board, ".fleetview", "queue");
|
|
1543
|
+
const requestFile = (board, id) => path.join(storyQueueDir(board), "requests", `${id}.json`);
|
|
1544
|
+
const ackFile = (board, id) => path.join(storyQueueDir(board), "acks", `${id}.json`);
|
|
1545
|
+
const storeFile = (board) => path.join(storyQueueDir(board), "entries.json");
|
|
1546
|
+
const lockFile = (board) => path.join(storyQueueDir(board), "entries.lock");
|
|
1547
|
+
const servedFile = (board) => path.join(storyQueueDir(board), "served.json");
|
|
1548
|
+
/** The id of a request: the hash of the facts that decide its entry, so the same facts are one request however often they are sent — its `why` rides beside them and never makes a new one. */
|
|
1549
|
+
export function requestIdOf(fields) {
|
|
1550
|
+
const { storyId, title, pri, effort, provider, model, name, brief, eligible, origin, place, pressedAt } = fields;
|
|
1551
|
+
return createHash("sha256").update(JSON.stringify([STORY_QUEUE_WIRE, storyId, title, pri, effort, provider, model, name, brief, eligible, origin, place ?? null, pressedAt ?? null])).digest("hex").slice(0, 16);
|
|
1552
|
+
}
|
|
1553
|
+
const sleepSync = (ms) => {
|
|
1554
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
1555
|
+
};
|
|
1556
|
+
// GATE: how many times a write whose rename another process's open handle refused is tried before the refusal is the caller's
|
|
1557
|
+
const RENAME_TRIES = 5;
|
|
1558
|
+
/** One queue file written whole: a reader sees the old bytes or the new, never half; the queue folder keeps itself out of git. */
|
|
1559
|
+
function writeWhole(board, file, value) {
|
|
1560
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1561
|
+
const ignore = path.join(storyQueueDir(board), ".gitignore");
|
|
1562
|
+
if (!fs.existsSync(ignore))
|
|
1563
|
+
fs.writeFileSync(ignore, "*\n");
|
|
1564
|
+
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
1565
|
+
fs.writeFileSync(tmp, JSON.stringify(value, null, 1));
|
|
1566
|
+
for (let attempt = 1;; attempt++) {
|
|
1567
|
+
try {
|
|
1568
|
+
fs.renameSync(tmp, file);
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
catch (err) {
|
|
1572
|
+
const code = err.code;
|
|
1573
|
+
if ((code !== "EPERM" && code !== "EBUSY" && code !== "EACCES") || attempt === RENAME_TRIES) {
|
|
1574
|
+
fs.rmSync(tmp, { force: true });
|
|
1575
|
+
throw err;
|
|
1576
|
+
}
|
|
1577
|
+
// OWNER: ITER/LOOP — Windows refuses a rename over a file another process holds open for that instant; the RECOURSE is the same rename a moment later, and the last refusal is thrown to the caller.
|
|
1578
|
+
sleepSync(20 * attempt);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
/** A queue file's value, or undefined when it does not exist yet; a torn or foreign file throws. */
|
|
1583
|
+
function readJson(file) {
|
|
1584
|
+
let text;
|
|
1585
|
+
try {
|
|
1586
|
+
text = fs.readFileSync(file, "utf8");
|
|
1587
|
+
}
|
|
1588
|
+
catch (err) {
|
|
1589
|
+
if (err.code !== "ENOENT")
|
|
1590
|
+
throw err;
|
|
1591
|
+
// NULL-OK: field file is OPTIONAL and therefore it is ok to check for NULL
|
|
1592
|
+
return undefined;
|
|
1593
|
+
}
|
|
1594
|
+
return JSON.parse(text);
|
|
1595
|
+
}
|
|
1596
|
+
export const readStoryAck = (board, storyId) => readJson(ackFile(board, storyId));
|
|
1597
|
+
export const readStoryRequest = (board, storyId) => readJson(requestFile(board, storyId));
|
|
1598
|
+
/** A request as it stands, or undefined when there is none or its file is not JSON (a hand edit) — the caller writes it again whole. */
|
|
1599
|
+
function readableRequest(board, storyId) {
|
|
1600
|
+
try {
|
|
1601
|
+
return readStoryRequest(board, storyId);
|
|
1602
|
+
}
|
|
1603
|
+
catch (err) {
|
|
1604
|
+
if (!(err instanceof SyntaxError))
|
|
1605
|
+
throw err;
|
|
1606
|
+
// NULL-OK: field request is OPTIONAL and therefore it is ok to check for NULL
|
|
1607
|
+
return undefined;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
/** Every story BB holds a request for on this board. */
|
|
1611
|
+
export function requestedStories(board) {
|
|
1612
|
+
const dir = path.join(storyQueueDir(board), "requests");
|
|
1613
|
+
if (!fs.existsSync(dir))
|
|
1614
|
+
return [];
|
|
1615
|
+
return fs.readdirSync(dir).filter((f) => /^\d+\.json$/.test(f)).map((f) => Number(f.slice(0, -".json".length)));
|
|
1616
|
+
}
|
|
1617
|
+
// 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
|
+
export const ACK_LATE_MS = 60_000;
|
|
1619
|
+
/**
|
|
1620
|
+
* BB's ONE scheduling act: the story's request written beside the board. A request FV already acknowledged is left alone;
|
|
1621
|
+
* 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
|
|
1622
|
+
* placement stays on the request until FV has acknowledged it, so a later AUTO START submission never drops it.
|
|
1623
|
+
*/
|
|
1624
|
+
export function submitStory(board, given, now) {
|
|
1625
|
+
const standing = readableRequest(board, given.storyId);
|
|
1626
|
+
const ack = readStoryAck(board, given.storyId);
|
|
1627
|
+
const standingAcked = standing !== undefined && ack?.requestId === standing.requestId;
|
|
1628
|
+
const placed = given.place === undefined && standing?.place !== undefined && !standingAcked ? { ...given, place: standing.place, pressedAt: standing.pressedAt, origin: standing.origin } : given;
|
|
1629
|
+
// his press stays his while the story stays eligible: AUTO START resubmitting it, or turning off, never takes it back
|
|
1630
|
+
const fields = standing?.origin === "press" && standing.eligible && placed.eligible ? { ...placed, origin: "press" } : placed;
|
|
1631
|
+
const requestId = requestIdOf(fields);
|
|
1632
|
+
if (standing !== undefined && ack?.requestId === requestId)
|
|
1633
|
+
return { request: standing, written: false, acked: ack };
|
|
1634
|
+
if (standing?.requestId === requestId && now - standing.submittedAt < ACK_LATE_MS)
|
|
1635
|
+
return { request: standing, written: false, unackedMs: now - standing.submittedAt };
|
|
1636
|
+
const request = { v: STORY_QUEUE_WIRE, requestId, submittedAt: now, ...fields };
|
|
1637
|
+
writeWhole(board, requestFile(board, given.storyId), request);
|
|
1638
|
+
return { request, written: true, ...(standing?.requestId === requestId ? { unackedMs: now - standing.submittedAt } : {}) };
|
|
1639
|
+
}
|
|
1640
|
+
/** 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. */
|
|
1641
|
+
export function markQueueTrouble(board, why, now) {
|
|
1642
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now, trouble: why });
|
|
1643
|
+
}
|
|
1644
|
+
/** 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. */
|
|
1645
|
+
export function markQueueStopped(board, why, now) {
|
|
1646
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now, stopped: why });
|
|
1647
|
+
}
|
|
1648
|
+
/** 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}). */
|
|
1649
|
+
export function queueServed(board) {
|
|
1650
|
+
const beat = readJson(servedFile(board));
|
|
1651
|
+
// NULL-OK: field beat is OPTIONAL and therefore it is ok to check for NULL
|
|
1652
|
+
if (beat === undefined)
|
|
1653
|
+
return { served: false, why: `FleetView's story queue has never driven ${board}` };
|
|
1654
|
+
if (!isProcessAlive(beat.pid))
|
|
1655
|
+
return { served: false, why: `the FleetView process ${beat.pid} that drove ${board}'s story queue has exited` };
|
|
1656
|
+
// NULL-OK: field stopped is OPTIONAL and therefore it is ok to check for NULL
|
|
1657
|
+
if (beat.stopped !== undefined)
|
|
1658
|
+
return { served: false, why: `FleetView process ${beat.pid} stopped driving ${board}'s story queue: ${beat.stopped}` };
|
|
1659
|
+
// NULL-OK: field trouble is OPTIONAL and therefore it is ok to check for NULL
|
|
1660
|
+
return beat.trouble === undefined ? { served: true } : { served: true, trouble: beat.trouble };
|
|
1661
|
+
}
|
|
1662
|
+
/** Another process holds the board's queue lock right now: this pass leaves the queue to it. */
|
|
1663
|
+
export class QueueBusy extends Error {
|
|
1664
|
+
constructor(board, holder) {
|
|
1665
|
+
super(`FleetView's story queue on ${board} is being driven by ${holder}`);
|
|
1666
|
+
this.name = "QueueBusy";
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
/** Runs `drive` holding the board's queue lock, which one process holds at a time; a lock whose process is gone is taken over, and a live holder's never is. */
|
|
1670
|
+
export async function withQueueLock(board, now, drive) {
|
|
1671
|
+
const file = lockFile(board);
|
|
1672
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1673
|
+
for (let attempt = 0;; attempt++) {
|
|
1674
|
+
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
1675
|
+
fs.writeFileSync(tmp, JSON.stringify({ pid: process.pid, at: now }));
|
|
1676
|
+
try {
|
|
1677
|
+
fs.linkSync(tmp, file);
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
catch (err) {
|
|
1681
|
+
if (err.code !== "EEXIST")
|
|
1682
|
+
throw err;
|
|
1683
|
+
if (attempt > 0)
|
|
1684
|
+
throw new QueueBusy(board, "a driver that took the lock as this one cleared a dead holder's");
|
|
1685
|
+
const held = readJson(file);
|
|
1686
|
+
// NULL-OK: field held is OPTIONAL and therefore it is ok to check for NULL
|
|
1687
|
+
if (held !== undefined && isProcessAlive(held.pid))
|
|
1688
|
+
throw new QueueBusy(board, `process ${held.pid} since ${new Date(held.at).toISOString()}`);
|
|
1689
|
+
takeDeadLock(board, file, held);
|
|
1690
|
+
}
|
|
1691
|
+
finally {
|
|
1692
|
+
fs.rmSync(tmp, { force: true });
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
try {
|
|
1696
|
+
return await drive();
|
|
1697
|
+
}
|
|
1698
|
+
finally {
|
|
1699
|
+
fs.rmSync(file, { force: true });
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
/** A dead holder's lock moved aside under a name of this process's own; a lock that is not the one read (another driver took it meanwhile) is put back and the pass leaves the queue to that driver. */
|
|
1703
|
+
function takeDeadLock(board, file, held) {
|
|
1704
|
+
const aside = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.dead`;
|
|
1705
|
+
try {
|
|
1706
|
+
fs.renameSync(file, aside);
|
|
1707
|
+
}
|
|
1708
|
+
catch (err) {
|
|
1709
|
+
if (err.code !== "ENOENT")
|
|
1710
|
+
throw err;
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
const moved = readJson(aside);
|
|
1714
|
+
if (moved?.pid === held?.pid && moved?.at === held?.at) {
|
|
1715
|
+
fs.rmSync(aside, { force: true });
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
try {
|
|
1719
|
+
fs.linkSync(aside, file);
|
|
1720
|
+
}
|
|
1721
|
+
catch (err) {
|
|
1722
|
+
if (err.code !== "EEXIST")
|
|
1723
|
+
throw err;
|
|
1724
|
+
}
|
|
1725
|
+
fs.rmSync(aside, { force: true });
|
|
1726
|
+
throw new QueueBusy(board, `process ${moved?.pid}, which took the lock while this one cleared a dead holder's`);
|
|
1727
|
+
}
|
|
1728
|
+
export function readQueueStore(board) {
|
|
1729
|
+
return readJson(storeFile(board)) ?? { v: STORY_QUEUE_WIRE, nextSeq: 1, entries: [] };
|
|
1730
|
+
}
|
|
1731
|
+
const IN_LINE = new Set(["queued", "starting", "running", "retrying", "failed"]);
|
|
1732
|
+
const rankIn = (order, value) => order.indexOf(value);
|
|
1733
|
+
/**
|
|
1734
|
+
* The queue's order: automatic entries P0 → P5, then XS → XL inside a priority, then arrival; each entry he placed sits at
|
|
1735
|
+
* exactly the place he chose, and the automatic entries fill around it. Only entries in line are ordered.
|
|
1736
|
+
*/
|
|
1737
|
+
export function queueOrder(store) {
|
|
1738
|
+
const line = store.entries.filter((e) => IN_LINE.has(e.state));
|
|
1739
|
+
const auto = line.filter((e) => e.manual === undefined).sort((a, b) => rankIn(PRI_ORDER, a.pri) - rankIn(PRI_ORDER, b.pri) || rankIn(EFFORT_ORDER, a.effort) - rankIn(EFFORT_ORDER, b.effort) || a.seq - b.seq);
|
|
1740
|
+
const placed = line.filter((e) => e.manual !== undefined).sort((a, b) => a.manual - b.manual || a.seq - b.seq);
|
|
1741
|
+
const out = [...auto];
|
|
1742
|
+
for (const e of placed)
|
|
1743
|
+
out.splice(Math.min(e.manual, out.length), 0, e);
|
|
1744
|
+
return out;
|
|
1745
|
+
}
|
|
1746
|
+
/** His placement of `e` at the 0-based place `k`: every other entry he placed at `k` or after moves down one, so no two of his places tie and his newest move holds the place he chose. */
|
|
1747
|
+
function placeAt(store, e, k) {
|
|
1748
|
+
for (const o of store.entries)
|
|
1749
|
+
if (o !== e && o.manual !== undefined && o.manual >= k)
|
|
1750
|
+
o.manual += 1;
|
|
1751
|
+
e.manual = k;
|
|
1752
|
+
}
|
|
1753
|
+
const step = (e, at, stage, detail) => {
|
|
1754
|
+
e.trace.push({ at, stage, detail });
|
|
1755
|
+
};
|
|
1756
|
+
/** Why a request cannot be queued at all, or undefined: the wire version and the two fields its order is made of, checked at this boundary. */
|
|
1757
|
+
function refusalOf(r) {
|
|
1758
|
+
if (r.v !== STORY_QUEUE_WIRE)
|
|
1759
|
+
return `request wire v${r.v} is not v${STORY_QUEUE_WIRE}, which this FleetView reads — update FleetView or BullseyeBacklog so both speak one version`;
|
|
1760
|
+
if (rankIn(PRI_ORDER, r.pri) === -1)
|
|
1761
|
+
return `priority "${r.pri}" is none of ${PRI_ORDER.join(" ")}`;
|
|
1762
|
+
if (rankIn(EFFORT_ORDER, r.effort) === -1)
|
|
1763
|
+
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`;
|
|
1766
|
+
return undefined;
|
|
1767
|
+
}
|
|
1768
|
+
/** One request applied to the store: an entry made, updated, withdrawn or put back in line; answers the refusal when it cannot be queued. */
|
|
1769
|
+
function applyRequest(store, r, now) {
|
|
1770
|
+
const refused = refusalOf(r);
|
|
1771
|
+
if (refused !== undefined)
|
|
1772
|
+
return refused;
|
|
1773
|
+
let e = store.entries.find((x) => x.storyId === r.storyId);
|
|
1774
|
+
if (e?.requestId === r.requestId)
|
|
1775
|
+
return undefined;
|
|
1776
|
+
const fields = { title: r.title, pri: r.pri, effort: r.effort, provider: r.provider, model: r.model, name: r.name, brief: r.brief, eligible: r.eligible, why: r.why };
|
|
1777
|
+
// NULL-OK: field e is OPTIONAL and therefore it is ok to check for NULL
|
|
1778
|
+
if (e === undefined) {
|
|
1779
|
+
if (!r.eligible)
|
|
1780
|
+
return undefined;
|
|
1781
|
+
e = { storyId: r.storyId, requestId: r.requestId, seq: store.nextSeq++, state: "queued", attempts: 0, trace: [], ...fields };
|
|
1782
|
+
store.entries.push(e);
|
|
1783
|
+
step(e, now, "acknowledged", `${r.origin === "press" ? "his Start press" : "AUTO START"} submitted it ${r.pri} ${r.effort} — ${r.why}`);
|
|
1784
|
+
}
|
|
1785
|
+
else {
|
|
1786
|
+
const before = `${e.pri} ${e.effort}`;
|
|
1787
|
+
const moved = before !== `${r.pri} ${r.effort}`;
|
|
1788
|
+
Object.assign(e, fields, { requestId: r.requestId });
|
|
1789
|
+
step(e, now, "updated", moved ? `priority and size ${before} → ${r.pri} ${r.effort}${e.manual === undefined ? ", its automatic place follows" : ", his placement stays"}` : `request updated — ${r.why}`);
|
|
1790
|
+
if (!r.eligible && (e.state === "queued" || e.state === "retrying" || e.state === "failed")) {
|
|
1791
|
+
e.state = "withdrawn";
|
|
1792
|
+
step(e, now, "withdrawn", r.why);
|
|
1793
|
+
}
|
|
1794
|
+
else if (r.eligible && (e.state === "withdrawn" || e.state === "done" || e.state === "failed")) {
|
|
1795
|
+
if (r.origin === "press" || e.state === "done")
|
|
1796
|
+
e.attempts = 0;
|
|
1797
|
+
e.state = "queued";
|
|
1798
|
+
delete e.nextTryAt;
|
|
1799
|
+
step(e, now, "acknowledged", `eligible again — ${r.why}`);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
if (r.place === "top") {
|
|
1803
|
+
placeAt(store, e, 0);
|
|
1804
|
+
step(e, now, "placed", "his Start press put it first in line");
|
|
1805
|
+
}
|
|
1806
|
+
return undefined;
|
|
1807
|
+
}
|
|
1808
|
+
/** 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
|
+
export class WorkerNotStarted extends Error {
|
|
1810
|
+
constructor(message) {
|
|
1811
|
+
super(message);
|
|
1812
|
+
this.name = "WorkerNotStarted";
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
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
|
|
1816
|
+
export const WORKER_ATTEMPTS = 3;
|
|
1817
|
+
// GATE: the wait before a story whose worker ended is started again: this, doubled for each earlier attempt
|
|
1818
|
+
export const RETRY_BASE_MS = 60_000;
|
|
1819
|
+
/** 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
|
+
function writeAcks(board, store, refusals, applied, now) {
|
|
1821
|
+
const order = queueOrder(store);
|
|
1822
|
+
for (const [storyId, requestId] of applied) {
|
|
1823
|
+
const e = store.entries.find((x) => x.storyId === storyId);
|
|
1824
|
+
const refused = refusals.get(storyId);
|
|
1825
|
+
const at = e === undefined ? -1 : order.indexOf(e);
|
|
1826
|
+
const ack = refused !== undefined
|
|
1827
|
+
? { v: STORY_QUEUE_WIRE, requestId, storyId, ackedAt: now, state: "failed", position: null, why: `FleetView refused the request: ${refused}` }
|
|
1828
|
+
: e === undefined || e.requestId !== requestId
|
|
1829
|
+
? { v: STORY_QUEUE_WIRE, requestId, storyId, ackedAt: now, state: "withdrawn", position: null, why: "not eligible, and FleetView holds no entry for it" }
|
|
1830
|
+
: { v: STORY_QUEUE_WIRE, requestId, storyId, ackedAt: now, state: e.state, position: at === -1 ? null : at + 1, why: e.why };
|
|
1831
|
+
const old = readStoryAck(board, storyId);
|
|
1832
|
+
if (old?.requestId === ack.requestId && old.state === ack.state && old.position === ack.position && old.why === ack.why)
|
|
1833
|
+
continue;
|
|
1834
|
+
writeWhole(board, ackFile(board, storyId), ack);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
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) {
|
|
1839
|
+
if (!e.eligible) {
|
|
1840
|
+
e.state = "withdrawn";
|
|
1841
|
+
step(e, now, "withdrawn", e.why);
|
|
1842
|
+
}
|
|
1843
|
+
else if (e.attempts >= WORKER_ATTEMPTS) {
|
|
1844
|
+
e.state = "failed";
|
|
1845
|
+
e.why = `its worker was started ${e.attempts} times and the story is still open — the last: ${why}`;
|
|
1846
|
+
step(e, now, "failed", e.why);
|
|
1847
|
+
}
|
|
1848
|
+
else {
|
|
1849
|
+
e.state = "retrying";
|
|
1850
|
+
e.nextTryAt = now + RETRY_BASE_MS * 2 ** (e.attempts - 1);
|
|
1851
|
+
e.why = `${why}; started again at ${new Date(e.nextTryAt).toISOString()}`;
|
|
1852
|
+
step(e, now, "retry", e.why);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* 🔴 ONE PASS OF FLEETVIEW'S STORY QUEUE ON ONE BOARD, under its lock: every request BB wrote is applied and acknowledged,
|
|
1857
|
+
* every worker is checked (a story shipped closes its entry; a worker that ended with the story still open is started
|
|
1858
|
+
* again after its backoff), and the entries first in line are started while the machine runs fewer lanes than Meni's
|
|
1859
|
+
* limit. An entry is written `starting` BEFORE its worker is launched, so a crash mid-start is found by its story on the
|
|
1860
|
+
* next pass and never gets a second worker.
|
|
1861
|
+
*/
|
|
1862
|
+
export async function driveStoryQueue(board, world, now) {
|
|
1863
|
+
return withQueueLock(board, now, async () => {
|
|
1864
|
+
writeWhole(board, servedFile(board), { pid: process.pid, at: now });
|
|
1865
|
+
const store = readQueueStore(board);
|
|
1866
|
+
const save = () => writeWhole(board, storeFile(board), store);
|
|
1867
|
+
const refusals = new Map();
|
|
1868
|
+
const applied = new Map();
|
|
1869
|
+
for (const id of requestedStories(board)) {
|
|
1870
|
+
const r = readableRequest(board, id);
|
|
1871
|
+
// NULL-OK: field r is OPTIONAL and therefore it is ok to check for NULL
|
|
1872
|
+
if (r === undefined) {
|
|
1873
|
+
refusals.set(id, "its request file is not JSON — BullseyeBacklog writes it again on its next pass");
|
|
1874
|
+
applied.set(id, "unreadable");
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1877
|
+
const refused = applyRequest(store, r, now);
|
|
1878
|
+
if (refused !== undefined)
|
|
1879
|
+
refusals.set(id, refused);
|
|
1880
|
+
applied.set(id, r.requestId);
|
|
1881
|
+
}
|
|
1882
|
+
for (const e of store.entries) {
|
|
1883
|
+
if (e.state === "withdrawn")
|
|
1884
|
+
continue;
|
|
1885
|
+
const closed = world.closedWhy(e.storyId);
|
|
1886
|
+
if (e.state === "done") {
|
|
1887
|
+
// NULL-OK: field closed is OPTIONAL and therefore it is ok to check for NULL
|
|
1888
|
+
if (closed !== undefined || !e.eligible)
|
|
1889
|
+
continue;
|
|
1890
|
+
e.state = "queued";
|
|
1891
|
+
e.attempts = 0;
|
|
1892
|
+
delete e.nextTryAt;
|
|
1893
|
+
e.why = "its story is an open row on the board again";
|
|
1894
|
+
step(e, now, "acknowledged", e.why);
|
|
1895
|
+
continue;
|
|
1896
|
+
}
|
|
1897
|
+
if (closed !== undefined) {
|
|
1898
|
+
e.state = "done";
|
|
1899
|
+
e.why = closed;
|
|
1900
|
+
step(e, now, "closed", closed);
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1903
|
+
if (e.state !== "starting" && e.state !== "running")
|
|
1904
|
+
continue;
|
|
1905
|
+
const w = world.worker(e, board);
|
|
1906
|
+
// NULL-OK: field found is OPTIONAL and therefore it is ok to check for NULL
|
|
1907
|
+
if (e.worker === undefined && w.found !== undefined)
|
|
1908
|
+
e.worker = w.found;
|
|
1909
|
+
if (!w.alive) {
|
|
1910
|
+
step(e, now, "worker-ended", w.why);
|
|
1911
|
+
afterWorker(e, now, w.why);
|
|
1912
|
+
continue;
|
|
1913
|
+
}
|
|
1914
|
+
if (e.state === "starting") {
|
|
1915
|
+
e.state = "running";
|
|
1916
|
+
step(e, now, "started", w.why);
|
|
1917
|
+
}
|
|
1918
|
+
if (w.progressAt !== undefined && e.worker !== undefined && w.progressAt !== e.worker.progressAt) {
|
|
1919
|
+
if (e.worker.progressAt === undefined)
|
|
1920
|
+
step(e, now, "progress", `its work first moved at ${new Date(w.progressAt).toISOString()}`);
|
|
1921
|
+
e.worker.progressAt = w.progressAt;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
save();
|
|
1925
|
+
let lanes = world.lanesRunning();
|
|
1926
|
+
for (const e of queueOrder(store)) {
|
|
1927
|
+
if (!e.eligible || !(e.state === "queued" || (e.state === "retrying" && e.nextTryAt <= now)))
|
|
1928
|
+
continue;
|
|
1929
|
+
const held = world.heldBy(e.storyId);
|
|
1930
|
+
if (held !== undefined) {
|
|
1931
|
+
e.why = `${held} works it, so the queue starts no second worker`;
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1934
|
+
if (lanes >= world.limit) {
|
|
1935
|
+
e.why = `${lanes} lanes run and the lane limit is ${world.limit}, so it starts when one finishes`;
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
// NULL-OK: field worker is OPTIONAL and therefore it is ok to check for NULL
|
|
1939
|
+
if (e.worker !== undefined && world.worker(e, board).alive) {
|
|
1940
|
+
e.state = "running";
|
|
1941
|
+
e.why = `its ${e.provider} worker ${e.worker.jobId} still runs, so no second worker is started`;
|
|
1942
|
+
step(e, now, "started", e.why);
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
e.state = "starting";
|
|
1946
|
+
e.attempts += 1;
|
|
1947
|
+
delete e.worker;
|
|
1948
|
+
step(e, now, "selected", `start ${e.attempts} of ${WORKER_ATTEMPTS}, with ${lanes} of ${world.limit} lanes running`);
|
|
1949
|
+
save();
|
|
1950
|
+
lanes += 1;
|
|
1951
|
+
try {
|
|
1952
|
+
e.worker = await world.launch(e, board);
|
|
1953
|
+
e.why = `its ${e.provider} worker ${e.worker.jobId} was started`;
|
|
1954
|
+
step(e, Date.now(), "started", e.why);
|
|
1955
|
+
}
|
|
1956
|
+
catch (err) {
|
|
1957
|
+
if (!(err instanceof WorkerNotStarted))
|
|
1958
|
+
throw err;
|
|
1959
|
+
const made = world.worker(e, board);
|
|
1960
|
+
// NULL-OK: field found is OPTIONAL and therefore it is ok to check for NULL
|
|
1961
|
+
if (made.alive && made.found !== undefined) {
|
|
1962
|
+
// OWNER: ITER/LOOP — the start answered no job id, yet the provider made the story's job: that job is the entry's worker, so no second one is started.
|
|
1963
|
+
e.worker = made.found;
|
|
1964
|
+
e.why = `its ${e.provider} worker ${made.found.jobId} runs, though its start answered: ${err.message}`;
|
|
1965
|
+
step(e, Date.now(), "started", e.why);
|
|
1966
|
+
save();
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
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.
|
|
1970
|
+
lanes -= 1;
|
|
1971
|
+
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}`);
|
|
1973
|
+
}
|
|
1974
|
+
save();
|
|
1975
|
+
}
|
|
1976
|
+
save();
|
|
1977
|
+
writeAcks(board, store, refusals, applied, now);
|
|
1978
|
+
return store;
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
/** His placement of one story in FleetView's queue: a 0-based place, or `auto` to hand it back to priority and size. */
|
|
1982
|
+
export async function placeStory(board, storyId, place, now) {
|
|
1983
|
+
return withQueueLock(board, now, async () => {
|
|
1984
|
+
const store = readQueueStore(board);
|
|
1985
|
+
const e = store.entries.find((x) => x.storyId === storyId && IN_LINE.has(x.state));
|
|
1986
|
+
if (e === undefined)
|
|
1987
|
+
throw new Error(`#${storyId} is not in FleetView's queue on ${board}, so it has no place to move`);
|
|
1988
|
+
if (place === "auto")
|
|
1989
|
+
delete e.manual;
|
|
1990
|
+
else
|
|
1991
|
+
placeAt(store, e, place);
|
|
1992
|
+
step(e, now, "placed", place === "auto" ? "his move handed it back to priority and size" : `his move put it at place ${place + 1}`);
|
|
1993
|
+
writeWhole(board, storeFile(board), store);
|
|
1994
|
+
return e;
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
const claudeHome = () => process.env.CLAUDE_CONFIG_DIR ?? path.join(homedir(), ".claude");
|
|
1998
|
+
/** A Claude Code record: its JSON, `gone` when Claude Code has none there (deleted, or an entry that is not a record), or `torn` when it was read mid-rewrite — Claude Code rewrites and deletes them in place. */
|
|
1999
|
+
function claudeRecordOf(file) {
|
|
2000
|
+
let text;
|
|
2001
|
+
try {
|
|
2002
|
+
text = fs.readFileSync(file, "utf8");
|
|
2003
|
+
}
|
|
2004
|
+
catch (err) {
|
|
2005
|
+
if (!["ENOENT", "ENOTDIR"].includes(String(err.code)))
|
|
2006
|
+
throw err;
|
|
2007
|
+
return "gone";
|
|
2008
|
+
}
|
|
2009
|
+
try {
|
|
2010
|
+
return JSON.parse(text);
|
|
2011
|
+
}
|
|
2012
|
+
catch (err) {
|
|
2013
|
+
if (!(err instanceof SyntaxError))
|
|
2014
|
+
throw err;
|
|
2015
|
+
return "torn";
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
/** The sessions a live process on this machine runs, read from Claude Code's own session records. */
|
|
2019
|
+
export function liveClaudeSessions(home = claudeHome()) {
|
|
2020
|
+
const dir = path.join(home, "sessions");
|
|
2021
|
+
if (!fs.existsSync(dir))
|
|
2022
|
+
return new Set();
|
|
2023
|
+
const out = new Set();
|
|
2024
|
+
for (const f of fs.readdirSync(dir).filter((n) => /^\d+\.json$/.test(n))) {
|
|
2025
|
+
if (!isProcessAlive(Number(f.slice(0, -".json".length))))
|
|
2026
|
+
continue;
|
|
2027
|
+
const rec = claudeRecordOf(path.join(dir, f));
|
|
2028
|
+
if (typeof rec !== "string")
|
|
2029
|
+
out.add(rec.sessionId);
|
|
2030
|
+
}
|
|
2031
|
+
return out;
|
|
2032
|
+
}
|
|
2033
|
+
const jobRecordOf = (jobId, home) => claudeRecordOf(path.join(home, "jobs", jobId, "state.json"));
|
|
2034
|
+
/** The session a `claude --bg` job runs, or undefined while its record is not there or caught mid-rewrite — the next read has it. */
|
|
2035
|
+
export function claudeJobSession(jobId, home = claudeHome()) {
|
|
2036
|
+
const job = jobRecordOf(jobId, home);
|
|
2037
|
+
// NULL-OK: field job is OPTIONAL and therefore it is ok to check for NULL
|
|
2038
|
+
return typeof job === "string" ? undefined : job.sessionId;
|
|
2039
|
+
}
|
|
2040
|
+
/** The `claude --bg` jobs on this machine started on `storyId` in `board` at or after `since`, oldest first — what a crash mid-start left behind, found by the brief's first line. */
|
|
2041
|
+
export function claudeJobsOfStory(storyId, board, since, home = claudeHome()) {
|
|
2042
|
+
const dir = path.join(home, "jobs");
|
|
2043
|
+
if (!fs.existsSync(dir))
|
|
2044
|
+
return [];
|
|
2045
|
+
const same = (a, b) => path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase();
|
|
2046
|
+
const jobs = fs.readdirSync(dir).flatMap((id) => {
|
|
2047
|
+
const job = jobRecordOf(id, home);
|
|
2048
|
+
return typeof job !== "string" && job.intent.startsWith(`Stories: #${storyId} `) && same(job.cwd, board) ? [{ id, at: Date.parse(job.createdAt) }] : [];
|
|
2049
|
+
});
|
|
2050
|
+
return jobs.filter((j) => j.at >= since).sort((a, b) => a.at - b.at).map((j) => j.id);
|
|
2051
|
+
}
|
|
2052
|
+
// GATE: how long a just-started worker is read as alive before its process has written its own live record (1.4 s measured on HP)
|
|
2053
|
+
export const WORKER_START_GRACE_MS = 2 * 60_000;
|
|
2054
|
+
const mtimeOf = (file) => {
|
|
2055
|
+
try {
|
|
2056
|
+
return fs.statSync(file).mtimeMs;
|
|
2057
|
+
}
|
|
2058
|
+
catch (err) {
|
|
2059
|
+
if (err.code !== "ENOENT")
|
|
2060
|
+
throw err;
|
|
2061
|
+
// NULL-OK: field file is OPTIONAL and therefore it is ok to check for NULL
|
|
2062
|
+
return undefined;
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
/** A story worker's liveness: a `claude --bg` job whose session a live process runs, with the moment its transcript last moved. */
|
|
2066
|
+
export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
2067
|
+
const job = jobRecordOf(worker.jobId, home);
|
|
2068
|
+
if (job === "torn")
|
|
2069
|
+
return { alive: true, why: `its job ${worker.jobId}'s record was caught mid-rewrite, so it is read again on the next pass` };
|
|
2070
|
+
if (job === "gone")
|
|
2071
|
+
return { alive: false, why: `its job ${worker.jobId} is no longer on Claude Code's record` };
|
|
2072
|
+
const at = job.linkScanPath === undefined ? undefined : mtimeOf(job.linkScanPath);
|
|
2073
|
+
const progress = at === undefined ? {} : { progressAt: at };
|
|
2074
|
+
if (job.state === "done" || job.state === "stopped")
|
|
2075
|
+
return { alive: false, ...progress, why: `its job ${worker.jobId} ended ${job.state}` };
|
|
2076
|
+
if (liveClaudeSessions(home).has(job.sessionId))
|
|
2077
|
+
return { alive: true, ...progress, why: `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
|
|
2078
|
+
if (now - worker.startedAt < WORKER_START_GRACE_MS)
|
|
2079
|
+
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` };
|
|
2080
|
+
return { alive: false, ...progress, why: `its job ${worker.jobId} reads ${job.state}, but no process on this machine runs session ${job.sessionId}` };
|
|
2081
|
+
}
|
|
2082
|
+
// GATE: how long a provider CLI is given to answer a worker start before the start is read as refused
|
|
2083
|
+
const LAUNCH_TIMEOUT_MS = 60_000;
|
|
2084
|
+
/** A story's worker, started windowless in the board's folder as a `claude --bg` session whose lifetime is the story's; `cli` is Claude Code's program as this machine runs it. */
|
|
2085
|
+
export function launchStoryWorker(entry, board, cli, now) {
|
|
2086
|
+
return new Promise((resolve, reject) => {
|
|
2087
|
+
execFile(cli.cmd, [...cli.args, "--bg", "--name", entry.name, "--model", entry.model, "--permission-mode", "bypassPermissions", entry.brief], { cwd: board, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
2088
|
+
const said = `${stdout}${stderr}`;
|
|
2089
|
+
const job = /^backgrounded · (\S+) · /m.exec(said);
|
|
2090
|
+
if (job !== null)
|
|
2091
|
+
return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
|
|
2092
|
+
reject(new WorkerNotStarted(`claude --bg ${err === null ? "printed no job id" : `failed (${err.message.split("\n")[0]})`} — ${said.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`));
|
|
2093
|
+
});
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
@@ -650,6 +650,16 @@ function readKeyPlan(home, providerId) {
|
|
|
650
650
|
}
|
|
651
651
|
return plan;
|
|
652
652
|
}
|
|
653
|
+
/**
|
|
654
|
+
* @typedef {"claude" | "copilot" | "codex"} AgentCliId
|
|
655
|
+
* @typedef {{ id: AgentCliId, label: string, protocol: "anthropic" | "openai", subscriptionProvider: string, responsesApi?: true }} AgentCli
|
|
656
|
+
*/
|
|
657
|
+
/** @type {readonly AgentCli[]} */
|
|
658
|
+
const AGENT_CLIS = Object.freeze([
|
|
659
|
+
Object.freeze({ id: "claude", label: "Claude Code", protocol: "anthropic", subscriptionProvider: "anthropic" }),
|
|
660
|
+
Object.freeze({ id: "copilot", label: "GitHub Copilot", protocol: "openai", subscriptionProvider: "github" }),
|
|
661
|
+
Object.freeze({ id: "codex", label: "OpenAI Codex", protocol: "openai", subscriptionProvider: "openai", responsesApi: true }),
|
|
662
|
+
]);
|
|
653
663
|
const OPENCODE_PROVIDER = "opencode";
|
|
654
664
|
// GATE: the key kinds OpenCode is handed, each with the OpenCode provider it names, the ONE environment variable that carries the key and the vendor address it is sent to; a key of any other kind is never offered to OpenCode
|
|
655
665
|
const OPENCODE_KEY_KINDS = Object.freeze({ "claude-api": Object.freeze({ provider: "anthropic", env: "ANTHROPIC_API_KEY", baseEnv: "ANTHROPIC_BASE_URL", base: "https://api.anthropic.com/v1" }) });
|
|
@@ -1550,6 +1560,7 @@ module.exports = {
|
|
|
1550
1560
|
keyPlanPath,
|
|
1551
1561
|
recordKeyPlan,
|
|
1552
1562
|
readKeyPlan,
|
|
1563
|
+
AGENT_CLIS,
|
|
1553
1564
|
OPENCODE_PROVIDER,
|
|
1554
1565
|
OPENCODE_KEY_KINDS,
|
|
1555
1566
|
markKeyRefused,
|
|
@@ -1582,6 +1593,9 @@ if (require.main === module) {
|
|
|
1582
1593
|
case "lock-alive":
|
|
1583
1594
|
process.exitCode = workspaceStore().alive(Number(args[0].split(":")[0])) ? 0 : 1;
|
|
1584
1595
|
break;
|
|
1596
|
+
case "agents":
|
|
1597
|
+
process.stdout.write(JSON.stringify({ agents: AGENT_CLIS }));
|
|
1598
|
+
break;
|
|
1585
1599
|
case "deepagent-settings":
|
|
1586
1600
|
process.stdout.write(JSON.stringify(deepagentSettings()));
|
|
1587
1601
|
break;
|
|
@@ -14,6 +14,9 @@ const BIND_BOUND_MS = 15_000;
|
|
|
14
14
|
const BIND_RETRY_MS = 5;
|
|
15
15
|
// GATE: how often a window re-checks that the machine's origin still answers; a crashed origin is started again, under the machine-wide start lock, within this long of any window being open.
|
|
16
16
|
const WATCH_MS = 30_000;
|
|
17
|
+
// GATE: how many times, and how far apart, a window's watch asks the origin to serve before it reports "not serving" — a window that opens at login races the boot supervisor, which starts the origin a few seconds later.
|
|
18
|
+
const WATCH_ATTEMPTS = 3;
|
|
19
|
+
const WATCH_RETRY_MS = 3_000;
|
|
17
20
|
// GATE: how long a stopping server keeps answering what it already took before it cuts the rest.
|
|
18
21
|
const DRAIN_BOUND_MS = 3_000;
|
|
19
22
|
function ask(port, method, path) {
|
|
@@ -379,8 +382,9 @@ async function servedDoor(port, server) {
|
|
|
379
382
|
}
|
|
380
383
|
/**
|
|
381
384
|
* Watches the machine's one origin for as long as this window lives: an immediate pass, then one per `WATCH_MS`.
|
|
382
|
-
* `origin` = { port, start() -> Promise } where `start` checks the origin serves and throws when it does not. A
|
|
383
|
-
*
|
|
385
|
+
* `origin` = { port, start() -> Promise } where `start` checks the origin serves and throws when it does not. A pass asks
|
|
386
|
+
* `WATCH_ATTEMPTS` times, `WATCH_RETRY_MS` apart, and only a pass whose every attempt failed is reported, once per
|
|
387
|
+
* distinct reason, through `report`. Returns what the window disposes on close.
|
|
384
388
|
*/
|
|
385
389
|
function keepDoor(origin, report) {
|
|
386
390
|
let lastWhy;
|
|
@@ -391,10 +395,22 @@ function keepDoor(origin, report) {
|
|
|
391
395
|
running = true;
|
|
392
396
|
let why;
|
|
393
397
|
try {
|
|
394
|
-
|
|
398
|
+
for (let attempt = 1;; attempt++) {
|
|
399
|
+
try {
|
|
400
|
+
await origin.start();
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
if (!(err instanceof Error))
|
|
405
|
+
throw err;
|
|
406
|
+
if (attempt === WATCH_ATTEMPTS)
|
|
407
|
+
throw err;
|
|
408
|
+
await new Promise((resolve) => setTimeout(resolve, WATCH_RETRY_MS));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
395
411
|
}
|
|
396
412
|
catch (err) {
|
|
397
|
-
// OWNER: the watch timer is this pass's trigger root — a pass
|
|
413
|
+
// OWNER: the watch timer is this pass's trigger root — a pass whose attempts all failed is reported once and the next tick tries again
|
|
398
414
|
if (!(err instanceof Error))
|
|
399
415
|
throw err;
|
|
400
416
|
why = err.message;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.354",
|
|
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",
|