omni-notify-mcp 1.3.378 → 1.3.380
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.
|
@@ -41,18 +41,18 @@ export const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
|
41
41
|
const LOOPBACK_ADDRESSES = new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
|
|
42
42
|
const PROXY_HEADERS = ["cf-connecting-ip", "cf-ray", "cdn-loop", "x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-real-ip", "forwarded"];
|
|
43
43
|
export const HOST_RE = /^(\[[0-9a-fA-F:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?$/;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
if (!names.every((name) => name.endsWith(`.${domain}`)))
|
|
50
|
-
throw new Error(`the owner passkey origins must share one domain: ${names.join(", ")}`);
|
|
51
|
-
return domain;
|
|
44
|
+
const FALLBACK_OWNER_HOSTS = ["bn.bullseyecalc.com", "fv.bullseyecalc.com", "bb.bullseyecalc.com", "da.bullseyecalc.com"];
|
|
45
|
+
function ownerDomain(names) {
|
|
46
|
+
const parents = names.map((name) => name.split(".").slice(1).join("."));
|
|
47
|
+
const rpID = [...new Set(parents)].sort((a, b) => parents.filter((p) => p === b).length - parents.filter((p) => p === a).length)[0];
|
|
48
|
+
return { rpID, outside: names.filter((name) => name !== rpID && !name.endsWith(`.${rpID}`)) };
|
|
52
49
|
}
|
|
53
50
|
// GATE: an owner passkey signs in only on these service origins, the install's own names from its config; any other origin is refused.
|
|
54
|
-
export
|
|
55
|
-
|
|
51
|
+
export function ownerRegistry() {
|
|
52
|
+
const names = readGatewaySettings()?.hosts ?? FALLBACK_OWNER_HOSTS;
|
|
53
|
+
const { rpID, outside } = ownerDomain(names);
|
|
54
|
+
return { origins: names.filter((name) => !outside.includes(name)).map((name) => `https://${name}`), rpID, outside };
|
|
55
|
+
}
|
|
56
56
|
const OWNER_RP_NAME = "Bullseye";
|
|
57
57
|
// GATE: a lock file nobody can read as a lock (half written, damaged) is taken over once it is this old; a readable lock is only ever taken from a holder that is gone.
|
|
58
58
|
const OWNER_LOCK_UNREADABLE_MS = 30_000;
|
|
@@ -378,7 +378,7 @@ export function createSignInDoor({ storeFile, product, short, home, host: doorHo
|
|
|
378
378
|
const readOwners = () => readOwnersFile(ownerFile());
|
|
379
379
|
// An owner passkey is registered on the owner rpID and signs in to every service the gateway serves on it, so a service added later needs no new registration.
|
|
380
380
|
const ownerCredentials = () => readOwners().credentials;
|
|
381
|
-
const ownerReaches = (base) => base === `https://${doorHost}` &&
|
|
381
|
+
const ownerReaches = (base) => base === `https://${doorHost}` && ownerRegistry().origins.includes(base);
|
|
382
382
|
function rememberRetirement() {
|
|
383
383
|
if (!ownsStore)
|
|
384
384
|
return;
|
|
@@ -539,7 +539,7 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
539
539
|
throw new GatewayError(403, "the owner passkey is registered only on its approved service origin");
|
|
540
540
|
const owners = readOwners();
|
|
541
541
|
const options = await generateRegistrationOptions({
|
|
542
|
-
rpName: OWNER_RP_NAME, rpID:
|
|
542
|
+
rpName: OWNER_RP_NAME, rpID: ownerRegistry().rpID, userName: hostname(), userDisplayName: hostname(), userID: Buffer.from(owners.userId, "base64url"), timeout: CEREMONY_TIMEOUT_MS,
|
|
543
543
|
attestationType: "none", authenticatorSelection: { residentKey: "required", userVerification: "required" },
|
|
544
544
|
excludeCredentials: owners.credentials.filter((credential) => credential.id !== approved.replaces).map(({ id, transports }) => ({ id, transports })),
|
|
545
545
|
});
|
|
@@ -550,7 +550,7 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
550
550
|
async function ownerRegisterVerify(req, body, challenge) {
|
|
551
551
|
const ceremony = takeCeremony(challenge, "owner-register");
|
|
552
552
|
const result = await verified("enrolment", () => verifyRegistrationResponse({
|
|
553
|
-
response: body.response, expectedChallenge: challenge, expectedOrigin: ceremony.origin, expectedRPID:
|
|
553
|
+
response: body.response, expectedChallenge: challenge, expectedOrigin: ceremony.origin, expectedRPID: ownerRegistry().rpID, requireUserVerification: true,
|
|
554
554
|
}));
|
|
555
555
|
if (!result.verified)
|
|
556
556
|
throw new GatewayError(401, "passkey enrolment refused: the response did not verify");
|
|
@@ -591,7 +591,7 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
591
591
|
const owners = ownerReaches(base) ? ownerCredentials() : [];
|
|
592
592
|
const legacy = new URL(base).hostname;
|
|
593
593
|
const passkeys = owners.length > 0 ? owners : legacyRetired(readStore()) ? [] : readStore().passkeys.filter((passkey) => passkey.rpID === legacy);
|
|
594
|
-
const rpID = owners.length > 0 ?
|
|
594
|
+
const rpID = owners.length > 0 ? ownerRegistry().rpID : legacy;
|
|
595
595
|
if (passkeys.length === 0)
|
|
596
596
|
throw new GatewayError(401, `no passkey is enrolled for ${rpID}`);
|
|
597
597
|
// GATE: the sign-in names exactly the enrolled credentials, by id only — no transport and no hint — so the browser offers the saved vault passkey with its fingerprint and can never lead with the phone/QR path (#3087) or a retired per-site key (#3108).
|
|
@@ -607,7 +607,7 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
607
607
|
// NULL-OK: field ownerCounters is OPTIONAL and therefore it is ok to check for NULL
|
|
608
608
|
const counter = readStore().ownerCounters?.[credential.id] ?? credential.counter;
|
|
609
609
|
const result = await verified("sign-in", () => verifyAuthenticationResponse({
|
|
610
|
-
response, expectedChallenge: challenge, expectedOrigin: origin, expectedRPID:
|
|
610
|
+
response, expectedChallenge: challenge, expectedOrigin: origin, expectedRPID: ownerRegistry().rpID, requireUserVerification: true,
|
|
611
611
|
// NULL-OK: field transports is OPTIONAL and therefore it is ok to check for NULL
|
|
612
612
|
credential: { id: credential.id, publicKey: Buffer.from(credential.publicKey, "base64url"), counter, ...(credential.transports ? { transports: credential.transports } : {}) },
|
|
613
613
|
}));
|
|
@@ -626,7 +626,7 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
626
626
|
const challenge = signedChallenge(body.response);
|
|
627
627
|
const ceremony = takeCeremony(challenge, "login");
|
|
628
628
|
const response = body.response;
|
|
629
|
-
if (ceremony.rpID ===
|
|
629
|
+
if (ceremony.rpID === ownerRegistry().rpID)
|
|
630
630
|
return ownerLoginVerify(response, challenge, ceremony.origin);
|
|
631
631
|
const passkey = readStore().passkeys.find((p) => p.id === response.id && p.rpID === ceremony.rpID);
|
|
632
632
|
if (passkey === undefined)
|
|
@@ -810,7 +810,8 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
810
810
|
const sessions = Object.entries(store.sessions).filter(([, s]) => s.exp > now && standing(approvalOfCredential(s.credentialId), store))
|
|
811
811
|
.map(([key, s]) => ({ ref: key.slice(0, SESSION_REF_LENGTH), signedInWith: approvalOfCredential(s.credentialId).slice(0, 24), exp: s.exp }));
|
|
812
812
|
const enrollments = [...tickets.entries()].filter(([, ticket]) => ticket.exp > now).map(([key, ticket]) => ({ ref: key.slice(0, SESSION_REF_LENGTH), host: ticket.host, exp: ticket.exp }));
|
|
813
|
-
const
|
|
813
|
+
const registry = ownerRegistry();
|
|
814
|
+
const owner = { rpID: registry.rpID, origins: registry.origins, outside: registry.outside, legacyRetired: legacyRetired(store), credentials: readOwners().credentials.map(({ id, device, createdAt }) => ({ id, device, createdAt })) };
|
|
814
815
|
return { locked: locked(store), sms: smsReachesOwner(), passkeys: store.passkeys.map(({ id, rpID, device, createdAt }) => ({ id, rpID, device, createdAt })), owner, authenticator, sessions, enrollments };
|
|
815
816
|
}
|
|
816
817
|
/** Revokes one session by its reference, or every session when none is given; the next request carrying it is refused. Returns how many went. */
|
|
@@ -968,5 +969,5 @@ ${locked(store) ? "" : `<p class="mut">Until an owner passkey is registered, not
|
|
|
968
969
|
return { handlePasskey, admin, refusalOfRequest, bearerAdmitted, sessionSignIn, sessionExpiresAt, personId, sessionApproval, approvalStands, signInEnrolled, tokenStands, doorState };
|
|
969
970
|
}
|
|
970
971
|
/** BN's own door: its store is `agent-passkeys.json` beside BN's config. */
|
|
971
|
-
const bn = createSignInDoor({ storeFile: join(CONFIG_DIR, "agent-passkeys.json"), product: "BullseyeNotify", short: "BN", home: "Open BN chat", host:
|
|
972
|
+
const bn = createSignInDoor({ storeFile: join(CONFIG_DIR, "agent-passkeys.json"), product: "BullseyeNotify", short: "BN", home: "Open BN chat", host: readGatewaySettings()?.host ?? "bn.bullseyecalc.com", ownerFile: () => join(CONFIG_DIR, "owner-passkeys.json"), ownsStore: process.env.NOTIFY_MCP_DOOR_READONLY !== "1" });
|
|
972
973
|
export const { handlePasskey, admin, refusalOfRequest, bearerAdmitted, sessionSignIn, sessionExpiresAt, personId, sessionApproval, approvalStands, signInEnrolled, tokenStands, doorState } = bn;
|
|
@@ -1355,18 +1355,7 @@ export function startMsOfProcStart(procStart) {
|
|
|
1355
1355
|
// A stamp before 1970 is not a start any running process reported — the record is read as having no stamp at all.
|
|
1356
1356
|
return Number.isFinite(ms) && ms > 0 ? ms : undefined;
|
|
1357
1357
|
}
|
|
1358
|
-
/**
|
|
1359
|
-
* #2019 — STOP THE PROCESS THAT OWNS `pid` AND THE START `startedAt` NOW, AND EVERYTHING UNDER IT. The start is the
|
|
1360
|
-
* live session record's own `procStart` (see {@link startMsOfProcStart}), so the same identity rule the stop door
|
|
1361
|
-
* above keeps is kept here: the table is read again, the row is matched by pid AND start — a pid the OS handed to a
|
|
1362
|
-
* new process is never killed — and its subtree is taken from that same reading, deepest first, one pid at a time.
|
|
1363
|
-
* A pid that is already gone takes nothing.
|
|
1364
|
-
*/
|
|
1365
|
-
export async function stopProcessById(pid, startedAt, deps) {
|
|
1366
|
-
const table = await deps.sample();
|
|
1367
|
-
return stopSubtree(table, table.find((p) => p.pid === pid && Math.abs(p.startedAt - startedAt) <= SAME_START_MS), deps);
|
|
1368
|
-
}
|
|
1369
|
-
/** One reading's subtree, killed deepest first — the walk both stop doors share. */
|
|
1358
|
+
/** One reading's subtree, killed deepest first. */
|
|
1370
1359
|
async function stopSubtree(table, top, deps) {
|
|
1371
1360
|
if (top === undefined) {
|
|
1372
1361
|
return { gone: true, killed: [], failed: [] };
|
|
@@ -1835,12 +1824,9 @@ const EFFORT_ORDER = ["XS", "S", "M", "L", "XL"];
|
|
|
1835
1824
|
/** 🔴 #4116 — the act a blocked worker waits on, in words. */
|
|
1836
1825
|
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
1837
1826
|
export const blockedAct = (worker) => (worker.needs === undefined ? "an act its job record does not name" : worker.needs);
|
|
1838
|
-
/** 🔴 #4156 — who runs a story the queue's own worker holds, as a board's badge names it: running,
|
|
1827
|
+
/** 🔴 #4156 — who runs a story the queue's own worker holds, as a board's badge names it: running, or stopped on the act it needs. */
|
|
1839
1828
|
export function workerRunner(worker) {
|
|
1840
|
-
|
|
1841
|
-
return `${worker.provider} worker, stopped until it gets ${blockedAct(worker)}`;
|
|
1842
|
-
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
1843
|
-
return worker.parkedAt === undefined ? `${worker.provider} worker` : `${worker.provider} worker, parked`;
|
|
1829
|
+
return worker.blocked === true ? `${worker.provider} worker, stopped until it gets ${blockedAct(worker)}` : `${worker.provider} worker`;
|
|
1844
1830
|
}
|
|
1845
1831
|
export const storyQueueDir = (board) => path.join(board, ".fleetview", "queue");
|
|
1846
1832
|
const requestFile = (board, id) => path.join(storyQueueDir(board), "requests", `${id}.json`);
|
|
@@ -1850,8 +1836,10 @@ const lockFile = (board) => path.join(storyQueueDir(board), "entries.lock");
|
|
|
1850
1836
|
const servedFile = (board) => path.join(storyQueueDir(board), "served.json");
|
|
1851
1837
|
/** 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. */
|
|
1852
1838
|
export function requestIdOf(fields) {
|
|
1853
|
-
const { storyId, title, pri, effort, provider, model, name, brief, eligible, origin, place, pressedAt } = fields;
|
|
1854
|
-
|
|
1839
|
+
const { storyId, title, pri, effort, provider, model, name, brief, eligible, origin, place, pressedAt, forced } = fields;
|
|
1840
|
+
// NULL-OK: field forced is OPTIONAL and therefore it is ok to check for NULL
|
|
1841
|
+
const facts = [STORY_QUEUE_WIRE, storyId, title, pri, effort, provider, model, name, brief, eligible, origin, place ?? null, pressedAt ?? null, ...(forced === undefined ? [] : [forced])];
|
|
1842
|
+
return createHash("sha256").update(JSON.stringify(facts)).digest("hex").slice(0, 16);
|
|
1855
1843
|
}
|
|
1856
1844
|
const sleepSync = (ms) => {
|
|
1857
1845
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -1938,13 +1926,16 @@ export const ACK_LATE_SAID_MS = 2 * 60 * 60_000;
|
|
|
1938
1926
|
/**
|
|
1939
1927
|
* BB's ONE scheduling act: the story's request written beside the board. A request FV already acknowledged is left alone;
|
|
1940
1928
|
* 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
|
|
1941
|
-
* placement
|
|
1929
|
+
* placement and his ⚡ Force start stay on the request until FV has acknowledged it, so a later AUTO START submission never drops them.
|
|
1942
1930
|
*/
|
|
1943
1931
|
export function submitStory(board, given, now) {
|
|
1944
1932
|
const standing = readableRequest(board, given.storyId);
|
|
1945
1933
|
const ack = readStoryAck(board, given.storyId);
|
|
1946
1934
|
const standingAcked = standing !== undefined && ack?.requestId === standing.requestId;
|
|
1947
|
-
const
|
|
1935
|
+
const kept = given.place === undefined && standing?.place !== undefined && !standingAcked ? { ...given, place: standing.place, pressedAt: standing.pressedAt, origin: standing.origin } : given;
|
|
1936
|
+
const placed =
|
|
1937
|
+
// NULL-OK: field forced is OPTIONAL and therefore it is ok to check for NULL
|
|
1938
|
+
kept.forced === undefined && standing?.forced !== undefined && !standingAcked && kept.eligible ? { ...kept, forced: standing.forced } : kept;
|
|
1948
1939
|
// his press stays his while the story stays eligible: AUTO START resubmitting it, or turning off, never takes it back
|
|
1949
1940
|
const fields = standing?.origin === "press" && standing.eligible && placed.eligible ? { ...placed, origin: "press" } : placed;
|
|
1950
1941
|
const requestId = requestIdOf(fields);
|
|
@@ -1971,7 +1962,7 @@ export function markQueueTrouble(board, why, now, version) {
|
|
|
1971
1962
|
return;
|
|
1972
1963
|
writeWhole(board, servedFile(board), { pid: process.pid, at: now, version, trouble: why });
|
|
1973
1964
|
}
|
|
1974
|
-
/** FleetView's queue beat stopped on a defect: the board is marked not driven with that defect, so BB
|
|
1965
|
+
/** FleetView's queue beat stopped on a defect: the board is marked not driven with that defect, so BB starts none of its stories until a FleetView pass drives it. */
|
|
1975
1966
|
export function markQueueStopped(board, why, now, version) {
|
|
1976
1967
|
// NULL-OK: field newerDriver is OPTIONAL and therefore it is ok to check for NULL
|
|
1977
1968
|
if (newerDriver(board, version) !== undefined)
|
|
@@ -2158,8 +2149,24 @@ function applyRequest(store, r, now) {
|
|
|
2158
2149
|
placeAt(store, e, 0);
|
|
2159
2150
|
step(e, now, "placed", "his Start press put it first in line");
|
|
2160
2151
|
}
|
|
2152
|
+
// NULL-OK: field forced is OPTIONAL and therefore it is ok to check for NULL
|
|
2153
|
+
if (r.forced !== undefined && r.eligible) {
|
|
2154
|
+
if (e.state === "starting" || e.state === "running")
|
|
2155
|
+
step(e, now, "updated", "his ⚡ Force start had nothing to start — a worker is already at work on it");
|
|
2156
|
+
else
|
|
2157
|
+
forceEntry(e, now, HIS_PRESS);
|
|
2158
|
+
}
|
|
2161
2159
|
return undefined;
|
|
2162
2160
|
}
|
|
2161
|
+
/** 🔴 #4156 — his ⚡ Force start on an entry in line: it starts on the next pass past the lane limit, a ⏸ Stop and the machine's session cap; the request that carries it (#4177) and the queue's own ⚡ press both force it here. */
|
|
2162
|
+
function forceEntry(e, now, by) {
|
|
2163
|
+
e.state = "queued";
|
|
2164
|
+
delete e.nextTryAt;
|
|
2165
|
+
e.forced = true;
|
|
2166
|
+
e.forcedBy = by;
|
|
2167
|
+
e.why = `${by} ⚡ Force start starts it on the next pass, past the lane limit, a ⏸ Stop and the cap of ${BOX_SESSION_CAP} agent sessions on this machine`;
|
|
2168
|
+
step(e, now, "placed", e.why);
|
|
2169
|
+
}
|
|
2163
2170
|
/** The provider refused to start a story's worker: its own words, which the entry carries and the queue starts again on its backoff. */
|
|
2164
2171
|
export class WorkerNotStarted extends Error {
|
|
2165
2172
|
/** Whether the queue starts it again on its backoff. */
|
|
@@ -2183,6 +2190,8 @@ export class WorkerRefused extends WorkerNotStarted {
|
|
|
2183
2190
|
this.name = "WorkerRefused";
|
|
2184
2191
|
}
|
|
2185
2192
|
}
|
|
2193
|
+
// GATE: the agent sessions this machine runs at once — a 17th start or wake stays queued until one ends; only his ⚡ Force start passes it
|
|
2194
|
+
export const BOX_SESSION_CAP = 16;
|
|
2186
2195
|
// GATE: the first wait before a parked worker is woken in its own session; doubled for each earlier wake up to WAKE_DOUBLINGS, so a worker that keeps stopping is woken less often but is never given up on
|
|
2187
2196
|
export const WAKE_BASE_MS = 60_000;
|
|
2188
2197
|
// GATE: how many times the wait doubles — past it a parked worker is woken every WAKE_BASE_MS * 2^WAKE_DOUBLINGS (32 min)
|
|
@@ -2199,10 +2208,12 @@ If a decision only Meni can make stands in the way, record it on #${storyId} wit
|
|
|
2199
2208
|
/** 🔴 #4123 — what a parked worker is told when the queue wakes it in its own session. */
|
|
2200
2209
|
export const wakeMessage = (storyId) => `FleetView's story queue woke you: #${storyId} is still OPEN on the board and you are its one worker. Re-read it with bullseye-backlog \`get\` and carry it to \`ship\` in this turn.
|
|
2201
2210
|
${workerStanding(storyId)}`;
|
|
2202
|
-
/** 🔴 #
|
|
2211
|
+
/** 🔴 #4192 — the story a {@link wakeMessage} woke its worker for; the woken worker's folder is that story's board. */
|
|
2212
|
+
export const WOKEN_STORY = /^FleetView's story queue woke you: #(\d+) /;
|
|
2213
|
+
/** 🔴 #4123 — the brief a queue worker is started with: the story's own brief first, so its job is still found by its first line, then where a worker with no session above it stands. */
|
|
2203
2214
|
export const workerBrief = (entry) => `${entry.brief}
|
|
2204
2215
|
|
|
2205
|
-
FleetView's story queue started you on #${entry.storyId}, and no
|
|
2216
|
+
FleetView's story queue started you on #${entry.storyId}, and no session stands above you; report on the story. Where the brief above speaks of a session to report to — a finding sent up, a turn end that hands you back — nobody is there to take it: a finding with no tie to this story is appended to #${entry.storyId}'s Remaining line — read it with bullseye-backlog \`get\`, then \`update\` it with the old text plus the finding, pinned with the \`expectHash\` the read gave — and the review, the land, the release and the ship are yours.
|
|
2206
2217
|
${workerStanding(entry.storyId)}`;
|
|
2207
2218
|
// GATE: how many times one story's worker is started before the queue gives up on it and its entry stops in `failed` — each start that ends with the story still open is one
|
|
2208
2219
|
export const WORKER_ATTEMPTS = 3;
|
|
@@ -2300,6 +2311,9 @@ function retireable(worker, reading, now) {
|
|
|
2300
2311
|
/** 🔴 #4143 — whether the worker's conversation is in the archive, wholly or cut off half-way — an archive or a bring-back alike — so its returning story must bring it back before anything is started, and a story that ships again archives it again. */
|
|
2301
2312
|
// NULL-OK: field archivedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2302
2313
|
const inArchive = (worker) => worker !== undefined && (worker.archivedAt !== undefined || worker.archiving === true);
|
|
2314
|
+
/** 🔴 #4188 — a queued row that keeps a parked worker no process runs: it waits in line, to be woken in its own session — it is no running worker, and it has one to wake. */
|
|
2315
|
+
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2316
|
+
const parkedInLine = (e) => e.state === "queued" && e.worker?.parkedAt !== undefined && !inArchive(e.worker);
|
|
2303
2317
|
/** 🔴 #4143 — an archive or bring-back is tried at once, and one that was refused only after the wake's wait for its run of refusals. */
|
|
2304
2318
|
// NULL-OK: field archiveRefused is OPTIONAL and therefore it is ok to check for NULL
|
|
2305
2319
|
const archiveDue = (holder, now) => holder.archiveRefused === undefined || now >= holder.archiveRefused.at + wakeDelayMs(holder.archiveRefused.times - 1);
|
|
@@ -2465,13 +2479,19 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2465
2479
|
step(e, now, "retry", e.why);
|
|
2466
2480
|
continue;
|
|
2467
2481
|
}
|
|
2468
|
-
|
|
2482
|
+
const waiting = parkedInLine(e);
|
|
2483
|
+
if (e.state !== "starting" && e.state !== "running" && !waiting)
|
|
2469
2484
|
continue;
|
|
2470
2485
|
const w = world.worker(e, board);
|
|
2471
2486
|
// NULL-OK: field found is OPTIONAL and therefore it is ok to check for NULL
|
|
2472
2487
|
if (e.worker === undefined && w.found !== undefined)
|
|
2473
2488
|
e.worker = w.found;
|
|
2474
2489
|
if (!w.alive) {
|
|
2490
|
+
if (waiting) {
|
|
2491
|
+
delete e.forced;
|
|
2492
|
+
delete e.forcedBy;
|
|
2493
|
+
}
|
|
2494
|
+
delete e.worker?.parkedAt;
|
|
2475
2495
|
step(e, now, "worker-ended", w.why);
|
|
2476
2496
|
afterWorker(e, now, w.why);
|
|
2477
2497
|
continue;
|
|
@@ -2511,6 +2531,12 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2511
2531
|
if (w.parked === undefined) {
|
|
2512
2532
|
delete e.worker?.parkedAt;
|
|
2513
2533
|
delete e.worker?.stoppedAt;
|
|
2534
|
+
if (waiting) {
|
|
2535
|
+
e.state = "running";
|
|
2536
|
+
delete e.forced;
|
|
2537
|
+
delete e.forcedBy;
|
|
2538
|
+
step(e, now, "started", `its worker ${e.worker.jobId} runs again — ${w.why}`);
|
|
2539
|
+
}
|
|
2514
2540
|
continue;
|
|
2515
2541
|
}
|
|
2516
2542
|
const worker = e.worker;
|
|
@@ -2538,7 +2564,8 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2538
2564
|
step(e, now, "parked", `its ${worker.provider} worker ${worker.jobId}'s turn is over with the story open, so it is woken in its own session from ${new Date(now + parkedWaitMs(worker, w.parked)).toISOString()}`);
|
|
2539
2565
|
}
|
|
2540
2566
|
if (!w.parked.live) {
|
|
2541
|
-
|
|
2567
|
+
e.state = "queued";
|
|
2568
|
+
if (e.forced === true || now >= worker.parkedAt + parkedWaitMs(worker, w.parked))
|
|
2542
2569
|
wakeable.set(e, w.parked.sessionId);
|
|
2543
2570
|
continue;
|
|
2544
2571
|
}
|
|
@@ -2575,7 +2602,7 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2575
2602
|
// NULL-OK: field idle is OPTIONAL and therefore it is ok to check for NULL
|
|
2576
2603
|
if (idle === undefined)
|
|
2577
2604
|
continue;
|
|
2578
|
-
const open = e.state === "running";
|
|
2605
|
+
const open = e.state === "running" || e.state === "queued";
|
|
2579
2606
|
const kept = e.worker === idle;
|
|
2580
2607
|
// NULL-OK: field stoppedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2581
2608
|
const again = idle.stoppedAt !== undefined;
|
|
@@ -2610,18 +2637,30 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2610
2637
|
if (sessionId !== undefined) {
|
|
2611
2638
|
const parked = e.worker;
|
|
2612
2639
|
const held = world.heldBy(e.storyId);
|
|
2640
|
+
const unwoken = (why) => {
|
|
2641
|
+
const changed = e.why !== why || e.state !== "queued";
|
|
2642
|
+
e.why = why;
|
|
2643
|
+
e.state = "queued";
|
|
2644
|
+
if (changed)
|
|
2645
|
+
step(e, now, "parked", `${why} — no process runs its session, so the story waits in line and is no running worker`);
|
|
2646
|
+
};
|
|
2613
2647
|
// NULL-OK: field held is OPTIONAL and therefore it is ok to check for NULL
|
|
2614
2648
|
if (held !== undefined) {
|
|
2615
|
-
|
|
2649
|
+
unwoken(`${held} works it, so its parked worker ${parked.jobId} is not woken beside it`);
|
|
2616
2650
|
continue;
|
|
2617
2651
|
}
|
|
2618
2652
|
// NULL-OK: field halted is OPTIONAL and therefore it is ok to check for NULL
|
|
2619
|
-
if (halted !== undefined) {
|
|
2620
|
-
|
|
2653
|
+
if (halted !== undefined && e.forced !== true) {
|
|
2654
|
+
unwoken(`its worker ${parked.jobId} is parked, and ${halted}`);
|
|
2621
2655
|
continue;
|
|
2622
2656
|
}
|
|
2623
|
-
if (lanes >= world.limit) {
|
|
2624
|
-
|
|
2657
|
+
if (lanes >= world.limit && e.forced !== true) {
|
|
2658
|
+
unwoken(`its worker ${parked.jobId} is parked, and ${lanes} lanes run with the lane limit at ${world.limit}, so it is woken when one finishes`);
|
|
2659
|
+
continue;
|
|
2660
|
+
}
|
|
2661
|
+
const sessions = world.boxSessions();
|
|
2662
|
+
if (sessions >= BOX_SESSION_CAP && e.forced !== true) {
|
|
2663
|
+
unwoken(`its worker ${parked.jobId} is parked, and ${sessions} agent sessions run on this machine with the cap at ${BOX_SESSION_CAP}, so it is woken when one ends`);
|
|
2625
2664
|
continue;
|
|
2626
2665
|
}
|
|
2627
2666
|
lanes += 1;
|
|
@@ -2629,6 +2668,9 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2629
2668
|
try {
|
|
2630
2669
|
const woken = await world.wake(e, board, sessionId, wakeMessage(e.storyId));
|
|
2631
2670
|
e.worker = { ...woken, wakes, ...keptSession(parked) };
|
|
2671
|
+
e.state = "running";
|
|
2672
|
+
delete e.forced;
|
|
2673
|
+
delete e.forcedBy;
|
|
2632
2674
|
e.why = `its ${woken.provider} worker ${woken.jobId} was woken in its own session (wake ${wakes}), with ${lanes} of ${world.limit} lanes running`;
|
|
2633
2675
|
step(e, now, "woken", e.why);
|
|
2634
2676
|
}
|
|
@@ -2639,6 +2681,9 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2639
2681
|
// OWNER: ITER/LOOP — the session still ran when it was woken, so Claude Code started a copy, which took the message and was stopped: the session's own process never got it, so the worker stays parked and is stopped and woken again; the next entry is read.
|
|
2640
2682
|
lanes -= 1;
|
|
2641
2683
|
e.worker = { ...parked, startedAt: now, parkedAt: now, wakes };
|
|
2684
|
+
e.state = "queued";
|
|
2685
|
+
delete e.forced;
|
|
2686
|
+
delete e.forcedBy;
|
|
2642
2687
|
e.why = `its worker ${parked.jobId} was NOT woken: ${err.message}`;
|
|
2643
2688
|
step(e, now, "parked", e.why);
|
|
2644
2689
|
save();
|
|
@@ -2649,6 +2694,9 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2649
2694
|
if (after.alive && (after.parked === undefined || after.parked.live)) {
|
|
2650
2695
|
// OWNER: ITER/LOOP — the wake's answer was lost (a timeout on a busy box) but a process now runs the worker's session, so the wake landed: the entry keeps that worker and no second one is started; the next entry is read.
|
|
2651
2696
|
e.worker = { provider: parked.provider, startedAt: now, jobId: parked.jobId, wakes, ...keptSession(parked) };
|
|
2697
|
+
e.state = "running";
|
|
2698
|
+
delete e.forced;
|
|
2699
|
+
delete e.forcedBy;
|
|
2652
2700
|
e.why = `its worker ${parked.jobId} was woken in its own session (wake ${wakes}), though its answer was: ${err.message}`;
|
|
2653
2701
|
step(e, now, "woken", e.why);
|
|
2654
2702
|
}
|
|
@@ -2656,6 +2704,9 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2656
2704
|
// OWNER: ITER/LOOP — the wake's answer was lost and no process has recorded the session yet, so the worker stays parked and is read again next pass; it is never ended on a missing answer, which would start a second worker beside a wake that landed late; the next entry is read.
|
|
2657
2705
|
lanes -= 1;
|
|
2658
2706
|
e.worker = { ...parked, startedAt: now, parkedAt: now, wakes };
|
|
2707
|
+
e.state = "queued";
|
|
2708
|
+
delete e.forced;
|
|
2709
|
+
delete e.forcedBy;
|
|
2659
2710
|
e.why = `its worker ${parked.jobId}'s wake got no answer, so it stays parked and is read again: ${err.message}`;
|
|
2660
2711
|
step(e, now, "parked", e.why);
|
|
2661
2712
|
}
|
|
@@ -2664,6 +2715,8 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2664
2715
|
lanes -= 1;
|
|
2665
2716
|
const why = `its ${parked.provider} worker ${parked.jobId} could not be woken: ${err.message}`;
|
|
2666
2717
|
delete e.worker;
|
|
2718
|
+
delete e.forced;
|
|
2719
|
+
delete e.forcedBy;
|
|
2667
2720
|
step(e, now, "worker-ended", why);
|
|
2668
2721
|
afterWorker(e, now, why);
|
|
2669
2722
|
}
|
|
@@ -2694,26 +2747,54 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2694
2747
|
e.why = `${lanes} lanes run and the lane limit is ${world.limit}, so it starts when one finishes`;
|
|
2695
2748
|
continue;
|
|
2696
2749
|
}
|
|
2697
|
-
|
|
2698
|
-
if (
|
|
2699
|
-
|
|
2700
|
-
e.state = "running";
|
|
2701
|
-
e.why = `its ${e.worker.provider} worker ${e.worker.jobId} still runs, so no second worker is started`;
|
|
2702
|
-
step(e, now, "started", e.why);
|
|
2750
|
+
const sessions = world.boxSessions();
|
|
2751
|
+
if (sessions >= BOX_SESSION_CAP && e.forced !== true) {
|
|
2752
|
+
e.why = `${sessions} agent sessions run on this machine and the cap is ${BOX_SESSION_CAP}, so it starts when one ends`;
|
|
2703
2753
|
continue;
|
|
2704
2754
|
}
|
|
2755
|
+
// NULL-OK: field worker is OPTIONAL and therefore it is ok to check for NULL
|
|
2756
|
+
if (e.worker !== undefined) {
|
|
2757
|
+
const reading = world.worker(e, board);
|
|
2758
|
+
if (reading.alive) {
|
|
2759
|
+
// NULL-OK: field parked is OPTIONAL and therefore it is ok to check for NULL
|
|
2760
|
+
if (reading.parked !== undefined) {
|
|
2761
|
+
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2762
|
+
if (e.worker.parkedAt === undefined) {
|
|
2763
|
+
e.worker.parkedAt = now;
|
|
2764
|
+
e.state = "queued";
|
|
2765
|
+
delete e.nextTryAt;
|
|
2766
|
+
e.why = `its ${e.worker.provider} worker ${e.worker.jobId}'s session has ${reading.parked.live ? "a process at its prompt" : "no process"}, so it waits in line and is woken in its own session — no second worker is started`;
|
|
2767
|
+
step(e, now, "parked", e.why);
|
|
2768
|
+
}
|
|
2769
|
+
else if (e.state !== "queued") {
|
|
2770
|
+
e.state = "queued";
|
|
2771
|
+
delete e.nextTryAt;
|
|
2772
|
+
}
|
|
2773
|
+
continue;
|
|
2774
|
+
}
|
|
2775
|
+
delete e.forced;
|
|
2776
|
+
delete e.forcedBy;
|
|
2777
|
+
e.state = "running";
|
|
2778
|
+
e.why = `its ${e.worker.provider} worker ${e.worker.jobId} still runs, so no second worker is started`;
|
|
2779
|
+
step(e, now, "started", e.why);
|
|
2780
|
+
continue;
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2705
2783
|
const taken = world.seat(e);
|
|
2706
2784
|
if (taken !== undefined) {
|
|
2707
2785
|
e.why = `${taken} works it, so the queue starts no second worker`;
|
|
2708
2786
|
continue;
|
|
2709
2787
|
}
|
|
2788
|
+
// NULL-OK: field forcedBy is OPTIONAL and therefore it is ok to check for NULL
|
|
2789
|
+
const forcer = e.forcedBy ?? "an unrecorded presser's";
|
|
2710
2790
|
// NULL-OK: field halted is OPTIONAL and therefore it is ok to check for NULL
|
|
2711
|
-
const forced = e.forced === true && (halted !== undefined || lanes >= world.limit);
|
|
2791
|
+
const forced = e.forced === true && (halted !== undefined || lanes >= world.limit || sessions >= BOX_SESSION_CAP);
|
|
2712
2792
|
delete e.forced;
|
|
2793
|
+
delete e.forcedBy;
|
|
2713
2794
|
e.state = "starting";
|
|
2714
2795
|
e.attempts += 1;
|
|
2715
2796
|
delete e.worker;
|
|
2716
|
-
step(e, now, "selected", `start ${e.attempts}${e.attempts > WORKER_ATTEMPTS ? ", past the attempts a story is given" : ` of ${WORKER_ATTEMPTS}`}, with ${lanes} of ${world.limit} lanes running${forced ? ` —
|
|
2797
|
+
step(e, now, "selected", `start ${e.attempts}${e.attempts > WORKER_ATTEMPTS ? ", past the attempts a story is given" : ` of ${WORKER_ATTEMPTS}`}, with ${lanes} of ${world.limit} lanes running${forced ? ` — ${forcer} ⚡ Force start, past ${halted !== undefined ? "the queue's ⏸ Stop" : lanes >= world.limit ? "the lane limit" : `the cap of ${BOX_SESSION_CAP} agent sessions on this machine`}` : ""}`);
|
|
2717
2798
|
save();
|
|
2718
2799
|
lanes += 1;
|
|
2719
2800
|
try {
|
|
@@ -2751,6 +2832,10 @@ export async function driveStoryQueue(board, world, now) {
|
|
|
2751
2832
|
return store;
|
|
2752
2833
|
});
|
|
2753
2834
|
}
|
|
2835
|
+
/** 🔴 #4188 — whose press a queue act records when no agent session made it: Meni's own, from the panel or the gateway-signed web page. */
|
|
2836
|
+
export const HIS_PRESS = "his";
|
|
2837
|
+
/** 🔴 #4188 — how a queue act names an agent session that made it, never as Meni. */
|
|
2838
|
+
export const agentPress = (sessionId) => `agent session ${sessionId}'s`;
|
|
2754
2839
|
/** 🔴 #4156 — a press on one story of the queue that does not apply to it as it stands: the words say why and what it reads. */
|
|
2755
2840
|
export class StoryPressRefused extends Error {
|
|
2756
2841
|
constructor(message) {
|
|
@@ -2761,11 +2846,11 @@ export class StoryPressRefused extends Error {
|
|
|
2761
2846
|
/**
|
|
2762
2847
|
* 🔴 #4156 — HIS PRESS ON ONE STORY OF FLEETVIEW'S QUEUE, under the queue's lock: ✕ Remove takes it out of the line (BullseyeBacklog's
|
|
2763
2848
|
* next new request puts it back), ↻ Retry puts a failed or retrying story back in line with its attempts reset, ⚡ Force start starts
|
|
2764
|
-
* it on the next pass past the lane limit
|
|
2849
|
+
* it on the next pass past the lane limit, a ⏸ Stop and the machine's cap of sixteen agent sessions, 🔔 Nudge ends the wait it stands on (a retry's backoff, a parked worker's wake delay), and
|
|
2765
2850
|
* 🔓 Unblock answers what holds it — the queue keeps no hold of its own on a story. A press that does not apply throws
|
|
2766
2851
|
* {@link StoryPressRefused}; one on a story no longer in line throws {@link NotInQueue}. Answers what it did, in words.
|
|
2767
2852
|
*/
|
|
2768
|
-
export async function pressStory(board, storyId, press, now) {
|
|
2853
|
+
export async function pressStory(board, storyId, press, now, by) {
|
|
2769
2854
|
return withQueueLock(board, now, async () => {
|
|
2770
2855
|
const store = readQueueStore(board);
|
|
2771
2856
|
const e = store.entries.find((x) => x.storyId === storyId && IN_LINE.has(x.state));
|
|
@@ -2780,7 +2865,8 @@ export async function pressStory(board, storyId, press, now) {
|
|
|
2780
2865
|
throw new StoryPressRefused(`#${storyId} has a worker at work — ✕ Remove takes a waiting story out of the line, and ⛔ Kill on its lane stops a worker`);
|
|
2781
2866
|
e.state = "withdrawn";
|
|
2782
2867
|
delete e.forced;
|
|
2783
|
-
e.
|
|
2868
|
+
delete e.forcedBy;
|
|
2869
|
+
e.why = `${by} ✕ Remove took it out of the line — BullseyeBacklog's next new request for it puts it back`;
|
|
2784
2870
|
step(e, now, "withdrawn", e.why);
|
|
2785
2871
|
did = `#${storyId} is out of the line`;
|
|
2786
2872
|
}
|
|
@@ -2790,36 +2876,32 @@ export async function pressStory(board, storyId, press, now) {
|
|
|
2790
2876
|
e.state = "queued";
|
|
2791
2877
|
e.attempts = 0;
|
|
2792
2878
|
delete e.nextTryAt;
|
|
2793
|
-
e.why =
|
|
2879
|
+
e.why = `${by} ↻ Retry put it back in line with its attempts reset`;
|
|
2794
2880
|
step(e, now, "retry", e.why);
|
|
2795
2881
|
did = `#${storyId} is back in line`;
|
|
2796
2882
|
}
|
|
2797
2883
|
else if (press === "force") {
|
|
2798
2884
|
if (working)
|
|
2799
2885
|
throw new StoryPressRefused(`#${storyId} already has a worker at work, so there is nothing to force`);
|
|
2800
|
-
e
|
|
2801
|
-
|
|
2802
|
-
e.forced = true;
|
|
2803
|
-
e.why = "his ⚡ Force start starts it on the next pass, past the lane limit and a ⏸ Stop";
|
|
2804
|
-
step(e, now, "placed", e.why);
|
|
2805
|
-
did = `#${storyId} starts on the next pass, past the lane limit`;
|
|
2886
|
+
forceEntry(e, now, by);
|
|
2887
|
+
did = `#${storyId} starts on the next pass, past the lane limit and the cap of ${BOX_SESSION_CAP} agent sessions`;
|
|
2806
2888
|
}
|
|
2807
2889
|
else if (press === "nudge") {
|
|
2808
|
-
const parked =
|
|
2890
|
+
const parked = working || parkedInLine(e) ? e.worker : undefined;
|
|
2809
2891
|
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2810
2892
|
if (parked?.parkedAt !== undefined) {
|
|
2811
2893
|
parked.parkedAt = now - wakeDelayMs(parked.wakes ?? 0);
|
|
2812
|
-
e.why =
|
|
2894
|
+
e.why = `${by} 🔔 Nudge ended its parked worker ${parked.jobId}'s wake delay, so it is woken on the next pass${afterStop}`;
|
|
2813
2895
|
did = `#${storyId}'s worker is woken on the next pass${afterStop}`;
|
|
2814
2896
|
// NULL-OK: field nextTryAt is OPTIONAL and therefore it is ok to check for NULL
|
|
2815
2897
|
}
|
|
2816
2898
|
else if (e.nextTryAt !== undefined && e.nextTryAt > now) {
|
|
2817
2899
|
e.nextTryAt = now;
|
|
2818
|
-
e.why =
|
|
2900
|
+
e.why = `${by} 🔔 Nudge ended its wait, so it is tried on the next pass${afterStop}`;
|
|
2819
2901
|
did = `#${storyId} is tried on the next pass${afterStop}`;
|
|
2820
2902
|
}
|
|
2821
2903
|
else {
|
|
2822
|
-
throw new StoryPressRefused(`#${storyId} waits on nothing a nudge ends — it reads: ${e.why}${e.state === "queued" ?
|
|
2904
|
+
throw new StoryPressRefused(`#${storyId} waits on nothing a nudge ends — it reads: ${e.why}${e.state === "queued" ? `; ⚡ Force start runs it past the lane limit and the cap of ${BOX_SESSION_CAP} agent sessions` : ""}`);
|
|
2823
2905
|
}
|
|
2824
2906
|
step(e, now, "retry", e.why);
|
|
2825
2907
|
}
|
|
@@ -2840,14 +2922,16 @@ export async function setStoryQueueStopped(board, stopped, by, now) {
|
|
|
2840
2922
|
return false;
|
|
2841
2923
|
if (stopped)
|
|
2842
2924
|
store.stopped = { at: now, by };
|
|
2843
|
-
else
|
|
2925
|
+
else {
|
|
2926
|
+
store.lifted = { at: now, by, stoppedBy: store.stopped.by };
|
|
2844
2927
|
delete store.stopped;
|
|
2928
|
+
}
|
|
2845
2929
|
writeWhole(board, storeFile(board), store);
|
|
2846
2930
|
return true;
|
|
2847
2931
|
});
|
|
2848
2932
|
}
|
|
2849
2933
|
/** His placement of one story in FleetView's queue: a 0-based place, or `auto` to hand it back to priority and size. */
|
|
2850
|
-
export async function placeStory(board, storyId, place, now) {
|
|
2934
|
+
export async function placeStory(board, storyId, place, now, by) {
|
|
2851
2935
|
return withQueueLock(board, now, async () => {
|
|
2852
2936
|
const store = readQueueStore(board);
|
|
2853
2937
|
const e = store.entries.find((x) => x.storyId === storyId && IN_LINE.has(x.state));
|
|
@@ -2857,7 +2941,7 @@ export async function placeStory(board, storyId, place, now) {
|
|
|
2857
2941
|
delete e.manual;
|
|
2858
2942
|
else
|
|
2859
2943
|
placeAt(store, e, place);
|
|
2860
|
-
step(e, now, "placed", place === "auto" ?
|
|
2944
|
+
step(e, now, "placed", place === "auto" ? `${by} move handed it back to priority and size` : `${by} move put it at place ${place + 1}`);
|
|
2861
2945
|
writeWhole(board, storeFile(board), store);
|
|
2862
2946
|
return e;
|
|
2863
2947
|
});
|
|
@@ -3076,6 +3160,9 @@ function timelineStepOf(line) {
|
|
|
3076
3160
|
}
|
|
3077
3161
|
/** 🔴 #4123 — the job states whose turn is over: a process still holding one waits at the prompt, working nothing. */
|
|
3078
3162
|
const TURN_OVER = new Set(["done", "blocked", "stopped"]);
|
|
3163
|
+
/** 🔴 #4123 — whether a job still has background tasks of its own running, which wake it when they finish. */
|
|
3164
|
+
// NULL-OK: field inFlight is OPTIONAL and therefore it is ok to check for NULL
|
|
3165
|
+
const waitsOnTasks = (job) => job.inFlight !== undefined && job.inFlight.tasks + job.inFlight.queued + job.inFlight.drainableMonitors > 0;
|
|
3079
3166
|
/**
|
|
3080
3167
|
* A story worker's liveness: a `claude --bg` job, with the moment its transcript last moved. 🔴 #4123 — a job whose turn is
|
|
3081
3168
|
* over (`done` or `blocked`, with no background task of its own still running) or whose process the daemon retired is
|
|
@@ -3110,11 +3197,9 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
|
3110
3197
|
return { alive: false, ...progress, why: said };
|
|
3111
3198
|
return { alive: true, ...progress, parked: { sessionId: job.sessionId, live, failed: true, ...(live ? {} : { killed: true }) }, why: `${said} — it was killed mid-work and its session worked after it was started, so it is parked and woken there` };
|
|
3112
3199
|
}
|
|
3113
|
-
// NULL-OK: field inFlight is OPTIONAL and therefore it is ok to check for NULL
|
|
3114
|
-
const waitsOnTasks = job.inFlight !== undefined && job.inFlight.tasks + job.inFlight.queued + job.inFlight.drainableMonitors > 0;
|
|
3115
3200
|
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
3116
3201
|
const blocked = job.state === "blocked" ? { blocked: true, ...(job.needs === undefined ? {} : { needs: job.needs }) } : {};
|
|
3117
|
-
if (live && (!TURN_OVER.has(job.state) || waitsOnTasks))
|
|
3202
|
+
if (live && (!TURN_OVER.has(job.state) || waitsOnTasks(job)))
|
|
3118
3203
|
return { alive: true, ...progress, why: `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
|
|
3119
3204
|
const how = live ? `its turn ended ${job.state} and its process waits at the prompt` : `it reads ${job.state} and no process on this machine runs session ${job.sessionId}`;
|
|
3120
3205
|
return { alive: true, ...progress, ...blocked, parked: { sessionId: job.sessionId, live, ...(!live && !TURN_OVER.has(job.state) ? { killed: true } : {}) }, why: `its job ${worker.jobId} is parked — ${how}` };
|
|
@@ -3141,15 +3226,102 @@ export function wakeStoryWorker(sessionId, message, board, cli, now) {
|
|
|
3141
3226
|
});
|
|
3142
3227
|
});
|
|
3143
3228
|
}
|
|
3144
|
-
/**
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3229
|
+
/**
|
|
3230
|
+
* 🔴 #4192 — the workers Claude Code's daemon holds, by job id, read from its own `daemon/roster.json`. The daemon starts a held
|
|
3231
|
+
* worker's process again, replaying its brief, whenever that process dies — measured on HP 2026-11-18: 18 sessions ended by pid were
|
|
3232
|
+
* back with new pids and the same ids within a minute — so a worker leaves only through the daemon's own stop. None when no daemon
|
|
3233
|
+
* has run here; `torn` while the daemon is rewriting it.
|
|
3234
|
+
*/
|
|
3235
|
+
export function daemonWorkers(home = claudeHome()) {
|
|
3236
|
+
const roster = claudeRecordOf(path.join(home, "daemon", "roster.json"));
|
|
3237
|
+
if (roster === "torn")
|
|
3238
|
+
return "torn";
|
|
3239
|
+
return roster === "gone" ? new Map() : new Map(Object.entries(roster.workers));
|
|
3240
|
+
}
|
|
3241
|
+
/** 🔴 #4192 — whether Claude Code's daemon holds `jobId`, or its roster is mid-rewrite and so is read as holding it: the daemon's own roster, never the session registry, decides if a worker still needs its stop. */
|
|
3242
|
+
export function daemonHolds(jobId, home = claudeHome()) {
|
|
3243
|
+
const held = daemonWorkers(home);
|
|
3244
|
+
return held === "torn" || held.has(jobId);
|
|
3245
|
+
}
|
|
3246
|
+
// GATE: how long a stop waits for Claude Code's daemon to take the worker off its roster after `claude stop` answered — the daemon confirms the stop first and rewrites the roster after; past it the stop is read as not taken
|
|
3247
|
+
const DAEMON_RELEASE_WAIT_MS = 5_000;
|
|
3248
|
+
/** 🔴 #4192 — whether the daemon still holds `jobId` once it has had its wait to let it go; a torn roster is read again. */
|
|
3249
|
+
async function daemonStillHolds(jobId, home) {
|
|
3250
|
+
const until = Date.now() + DAEMON_RELEASE_WAIT_MS;
|
|
3251
|
+
for (;;) {
|
|
3252
|
+
const held = daemonWorkers(home);
|
|
3253
|
+
if (held !== "torn" && !held.has(jobId))
|
|
3254
|
+
return false;
|
|
3255
|
+
if (Date.now() >= until)
|
|
3256
|
+
return true;
|
|
3257
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
/**
|
|
3261
|
+
* 🔴 #4123/#4192 — ends a `claude --bg` job's process through Claude Code's daemon, leaving its session on disk to be woken. Never by
|
|
3262
|
+
* pid: the daemon starts a killed worker again with its brief. A worker the daemon holds whose job record was deleted is still named
|
|
3263
|
+
* to `claude stop`, which finds a session by its folder under `jobs/`: the folder is made for the stop and removed after it. The stop
|
|
3264
|
+
* is taken only once the daemon's roster no longer holds the worker — `claude stop` from a process below the daemon's privilege
|
|
3265
|
+
* answers "stopped" while the session runs on, so from there it is refused unsent. A stop that answers "no session" while another
|
|
3266
|
+
* stop of the same worker took it is taken, and a `jobs/` folder holding no record is removed once the daemon has let its worker go.
|
|
3267
|
+
*/
|
|
3268
|
+
export async function stopStoryWorker(jobId, cli, home = claudeHome()) {
|
|
3269
|
+
const below = elevatedDaemonNote(home);
|
|
3270
|
+
if (below !== "")
|
|
3271
|
+
throw new WorkerNotStarted(`claude stop ${jobId} was not sent${below}`, true);
|
|
3272
|
+
const held = daemonWorkers(home);
|
|
3273
|
+
const heldAtStart = held !== "torn" && held.has(jobId);
|
|
3274
|
+
const folder = path.join(home, "jobs", jobId);
|
|
3275
|
+
const named = heldAtStart && !fs.existsSync(folder);
|
|
3276
|
+
if (named)
|
|
3277
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
3278
|
+
let refused;
|
|
3279
|
+
try {
|
|
3280
|
+
refused = await new Promise((resolve) => {
|
|
3281
|
+
execFile(cli.cmd, [...cli.args, "stop", jobId], { windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
3282
|
+
resolve(err === null ? null : `claude stop ${jobId} failed (${err.message.split("\n")[0]}) — ${`${stdout}${stderr}`.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`);
|
|
3283
|
+
});
|
|
3151
3284
|
});
|
|
3152
|
-
}
|
|
3285
|
+
}
|
|
3286
|
+
finally {
|
|
3287
|
+
if (named)
|
|
3288
|
+
fs.rmSync(folder, { recursive: true, force: true });
|
|
3289
|
+
}
|
|
3290
|
+
if (await daemonStillHolds(jobId, home))
|
|
3291
|
+
throw new WorkerNotStarted(refused ?? `claude stop ${jobId} answered, but Claude Code's daemon still holds its worker after ${DAEMON_RELEASE_WAIT_MS / 1000} s`);
|
|
3292
|
+
if (refused !== null && !heldAtStart)
|
|
3293
|
+
throw new WorkerNotStarted(refused);
|
|
3294
|
+
if (fs.existsSync(folder) && !fs.existsSync(path.join(folder, "state.json")))
|
|
3295
|
+
fs.rmSync(folder, { recursive: true, force: true });
|
|
3296
|
+
}
|
|
3297
|
+
/**
|
|
3298
|
+
* 🔴 #4192 — the daemon's workers past their turn: the job's record is gone, or its turn is over with no task in flight, so the daemon
|
|
3299
|
+
* would only start its process again to replay its brief. A worker mid-turn finishes its own last acts and is read again, as is one
|
|
3300
|
+
* whose record or the roster itself is caught mid-rewrite.
|
|
3301
|
+
*/
|
|
3302
|
+
export function parkedDaemonWorkers(home = claudeHome()) {
|
|
3303
|
+
const held = daemonWorkers(home);
|
|
3304
|
+
if (held === "torn")
|
|
3305
|
+
return [];
|
|
3306
|
+
return [...held].filter(([jobId]) => {
|
|
3307
|
+
const job = jobRecordOf(jobId, home);
|
|
3308
|
+
return job === "gone" || (job !== "torn" && TURN_OVER.has(job.state) && !waitsOnTasks(job));
|
|
3309
|
+
}).map(([jobId, worker]) => ({ jobId, worker }));
|
|
3310
|
+
}
|
|
3311
|
+
/** 🔴 #4190 — why a stop is not taken: when Claude Code's daemon (pid in `daemon.lock`) is itself refused a signal, it runs at a higher privilege than this process, and so does every background session under it; only the resident FleetView server, started at that same privilege, ends them (FleetView's `stopSession`). Empty when the daemon is reachable. */
|
|
3312
|
+
export function elevatedDaemonNote(home) {
|
|
3313
|
+
const lock = claudeRecordOf(path.join(home, "daemon.lock"));
|
|
3314
|
+
if (typeof lock === "string")
|
|
3315
|
+
return "";
|
|
3316
|
+
try {
|
|
3317
|
+
process.kill(lock.pid, 0);
|
|
3318
|
+
return "";
|
|
3319
|
+
}
|
|
3320
|
+
catch (err) {
|
|
3321
|
+
if (err.code !== "EPERM")
|
|
3322
|
+
return "";
|
|
3323
|
+
return ` — the claude daemon (pid ${lock.pid}, daemon.lock) runs at a higher privilege than this process, where a stop answers "stopped" and is not taken, so its sessions are ended only through the resident FleetView server, which starts them at that privilege (FleetView's stopSession)`;
|
|
3324
|
+
}
|
|
3153
3325
|
}
|
|
3154
3326
|
/** 🔴 #4143 — where a done story's conversation is kept: under `archive/projects/`, beside `projects/` rather than in it, so neither `claude --resume` nor the VS Code chat history lists it. */
|
|
3155
3327
|
export const archivedTranscriptOf = (transcript, home = claudeHome()) => path.join(home, "archive", "projects", path.basename(path.dirname(transcript)), path.basename(transcript));
|
|
@@ -3194,12 +3366,18 @@ const DISK_REFUSALS = new Set(["EPERM", "EBUSY", "EACCES"]);
|
|
|
3194
3366
|
* is handed to `record`, then the conversation is moved, and only then `claude rm` deletes the record (measured on HP: it
|
|
3195
3367
|
* removes the job with its transcript already gone and keeps whatever the archive holds), so a refused move leaves the
|
|
3196
3368
|
* record for the next try. A process still running the session refuses it, since that process would write its transcript
|
|
3197
|
-
* back where the history lists read.
|
|
3369
|
+
* back where the history lists read. 🔴 #4192 — a worker Claude Code's daemon still holds is first stopped through the daemon:
|
|
3370
|
+
* the daemon would start its process again, brief and all, with its job record gone and no `claude stop` left to name it.
|
|
3198
3371
|
*/
|
|
3199
3372
|
export async function retireStoryWorker(worker, cli, record, home = claudeHome()) {
|
|
3200
3373
|
const job = jobRecordOf(worker.jobId, home);
|
|
3201
3374
|
if (job === "torn")
|
|
3202
3375
|
throw new WorkerNotStarted(`its job ${worker.jobId}'s record was caught mid-rewrite, so it is archived later`);
|
|
3376
|
+
const held = daemonWorkers(home);
|
|
3377
|
+
if (held === "torn")
|
|
3378
|
+
throw new WorkerNotStarted(`Claude Code's daemon roster was caught mid-rewrite, so its job ${worker.jobId} is archived later`);
|
|
3379
|
+
if (held.has(worker.jobId))
|
|
3380
|
+
await stopStoryWorker(worker.jobId, cli, home);
|
|
3203
3381
|
// NULL-OK: field linkScanPath is OPTIONAL and therefore it is ok to check for NULL
|
|
3204
3382
|
const session = worker.session ?? (job === "gone" || job.linkScanPath === undefined ? undefined : { id: job.sessionId, transcript: job.linkScanPath });
|
|
3205
3383
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -174,14 +174,23 @@ function boxFile(root, tool) {
|
|
|
174
174
|
const dir = path.join(os.homedir(), ".bullseye", "settings");
|
|
175
175
|
return sameRoot(root, toolHome()) ? path.join(dir, `${tool}.box.json`) : path.join(dir, path.basename(root).toLowerCase(), `${tool}.box.json`);
|
|
176
176
|
}
|
|
177
|
-
/** The file's bytes, or undefined when it is not there; any other failure to read THROWS,
|
|
178
|
-
function bytesOf(file
|
|
177
|
+
/** The file's bytes, or undefined when it is not there; any other failure to read THROWS the operating system's own error, so a write it refuses is never taken for a file that does not parse. */
|
|
178
|
+
function bytesOf(file) {
|
|
179
179
|
try {
|
|
180
180
|
return fs.readFileSync(file);
|
|
181
181
|
}
|
|
182
182
|
catch (err) {
|
|
183
|
-
if (err.code
|
|
184
|
-
|
|
183
|
+
if (err.code !== "ENOENT")
|
|
184
|
+
throw err;
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** The file's bytes for a reading, or undefined when it is not there; a file the operating system will not read THROWS SyntaxError naming it, as a reading reports one that does not parse. */
|
|
189
|
+
function readBytesOf(file, what) {
|
|
190
|
+
try {
|
|
191
|
+
return bytesOf(file);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
185
194
|
throw new SyntaxError(`${file} could not be read as ${what}: ${err.message}`);
|
|
186
195
|
}
|
|
187
196
|
}
|
|
@@ -217,16 +226,16 @@ function parsedSettings(file, text) {
|
|
|
217
226
|
/** `tool`'s settings in workspace `root`, with its box-only part (`box`, empty while this box keeps none) and `base` — the sha256 of the bytes both were read from, which a write names. An absent settings file THROWS SettingsUndefined, naming it: a workspace never falls back on another's or on a machine default. */
|
|
218
227
|
function readSettings(root, tool) {
|
|
219
228
|
const file = settingsFile(root, tool);
|
|
220
|
-
const bytes =
|
|
229
|
+
const bytes = readBytesOf(file, `${tool}'s settings`);
|
|
221
230
|
if (bytes === undefined)
|
|
222
231
|
throw new SettingsUndefined(`${tool} has no settings in ${root} yet (${file}) — they are written by its migration or its first saved change`);
|
|
223
232
|
const local = boxFile(root, tool);
|
|
224
|
-
const boxBytes =
|
|
233
|
+
const boxBytes = readBytesOf(local, `${tool}'s box-only settings`);
|
|
225
234
|
return { file, base: baseOf(bytes, boxBytes), ...parsedSettings(file, bytes.toString("utf8")), box: parsedBox(local, boxBytes) };
|
|
226
235
|
}
|
|
227
236
|
/** The base a write is made from: the sha256 of the settings file's and the box-only file's bytes, or "undefined" when neither exists yet. */
|
|
228
237
|
function settingsBase(root, tool) {
|
|
229
|
-
return baseOf(bytesOf(settingsFile(root, tool)
|
|
238
|
+
return baseOf(bytesOf(settingsFile(root, tool)), bytesOf(boxFile(root, tool)));
|
|
230
239
|
}
|
|
231
240
|
function serialized(value) {
|
|
232
241
|
return `${JSON.stringify({ schema: SETTINGS_SCHEMA, settings: value.settings, ui: value.ui, secrets: value.secrets }, null, 2)}\n`;
|
|
@@ -387,10 +396,10 @@ function writtenSettings(root, tool, change, base) {
|
|
|
387
396
|
const now = settingsBase(root, tool);
|
|
388
397
|
if (now !== base)
|
|
389
398
|
throw new SettingsMoved(`${file} changed since it was read (base ${base.slice(0, 12)}, now ${now.slice(0, 12)}) — read it again and make the change from what it holds now`);
|
|
390
|
-
const shared = bytesOf(file
|
|
399
|
+
const shared = bytesOf(file);
|
|
391
400
|
if (shared === undefined && Object.keys(change).every((section) => section === "box"))
|
|
392
401
|
throw new SettingsUndefined(`${tool} has no settings in ${root} yet (${file}) — a box-only value is written with the settings that name it, never alone`);
|
|
393
|
-
const current = { ...(shared === undefined ? { settings: {}, ui: {}, secrets: {} } : parsedSettings(file, shared.toString("utf8"))), box: parsedBox(local, bytesOf(local
|
|
402
|
+
const current = { ...(shared === undefined ? { settings: {}, ui: {}, secrets: {} } : parsedSettings(file, shared.toString("utf8"))), box: parsedBox(local, bytesOf(local)) };
|
|
394
403
|
for (const section of Object.keys(change)) {
|
|
395
404
|
if (!SECTIONS.includes(section) && section !== "box")
|
|
396
405
|
throw new TypeError(`a settings change names only ${SECTIONS.join(", ")}, box, not "${section}"`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.380",
|
|
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",
|