omni-notify-mcp 1.3.377 โ†’ 1.3.378

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.
@@ -2172,6 +2172,9 @@ export class WorkerNotStarted extends Error {
2172
2172
  this.name = "WorkerNotStarted";
2173
2173
  }
2174
2174
  }
2175
+ /** ๐Ÿ”ด #4142 โ€” a wake found the session still running: Claude Code started a copy of it, which took the message and was stopped, so the session's own process never received it. */
2176
+ export class SessionStillRunning extends WorkerNotStarted {
2177
+ }
2175
2178
  /** ๐Ÿ”ด #3951 โ€” the provider cannot start the story as this box stands (its CLI has no login): the entry stops `failed` with the provider's words at once, spends no attempt, and the box is read again after {@link RETRY_BASE_MS}, so a login made later starts it. */
2176
2179
  export class WorkerRefused extends WorkerNotStarted {
2177
2180
  retried = false;
@@ -2186,6 +2189,10 @@ export const WAKE_BASE_MS = 60_000;
2186
2189
  export const WAKE_DOUBLINGS = 5;
2187
2190
  /** ๐Ÿ”ด #4123 โ€” how long after its turn ended a worker woken `wakes` times before is woken again. */
2188
2191
  export const wakeDelayMs = (wakes) => WAKE_BASE_MS * 2 ** Math.min(wakes, WAKE_DOUBLINGS);
2192
+ /** ๐Ÿ”ด #4162 โ€” its process was killed mid-work and its session went on working past its start grace after its last start or wake: nothing ended its turn and nothing of its own failed, so it neither backs off nor spends a start (#4164). */
2193
+ const killedAfterWork = (worker, parked) => parked.killed === true && worker.progressAt !== undefined && worker.progressAt - worker.startedAt >= WORKER_START_GRACE_MS;
2194
+ /** ๐Ÿ”ด #4162 โ€” how long a parked worker waits before it is woken: none when {@link killedAfterWork}, else {@link wakeDelayMs} โ€” so a session that dies on waking, whose only write is the wake's own message, still backs off and never wakes in a loop. */
2195
+ export const parkedWaitMs = (worker, parked) => (killedAfterWork(worker, parked) ? 0 : wakeDelayMs(worker.wakes ?? 0));
2189
2196
  /** ๐Ÿ”ด #4123 โ€” where every queue worker stands, said at its start and at each wake: what it clears itself, and how a decision of Meni's reaches him and comes back. */
2190
2197
  const workerStanding = (storyId) => `A stop you named that you or another agent can clear (a board write refused, the board MCP not loaded yet, a release step) is yours to clear now โ€” never a reason to end your turn. A run the box's CPU ceiling refuses is handled as its refusal says; never stop or kill a process to make room.
2191
2198
  If a decision only Meni can make stands in the way, record it on #${storyId} with bullseye-backlog \`ask\` and ask him with the notify MCP \`ask\` tool, which reaches his email and text; when its wait ends unanswered, keep calling \`wait_for_inbox\` until his reply arrives, then \`rule\` his answer onto #${storyId} verbatim, apply it and go on. End your turn only once the story is shipped.`;
@@ -2482,7 +2489,7 @@ export async function driveStoryQueue(board, world, now) {
2482
2489
  delete e.worker.needs;
2483
2490
  else
2484
2491
  e.worker.needs = w.needs;
2485
- e.why = `its ${e.provider} worker ${e.worker.jobId} stopped and needs an act before it goes on: ${blockedAct(e.worker)}`;
2492
+ e.why = `its ${e.worker.provider} worker ${e.worker.jobId} stopped and needs an act before it goes on: ${blockedAct(e.worker)}`;
2486
2493
  step(e, now, "blocked", e.why);
2487
2494
  }
2488
2495
  else {
@@ -2508,14 +2515,14 @@ export async function driveStoryQueue(board, world, now) {
2508
2515
  }
2509
2516
  const worker = e.worker;
2510
2517
  if (!e.eligible) {
2511
- const why = `its ${e.provider} worker ${worker.jobId}'s turn is over and the story is no longer the queue's to work, so it is not woken`;
2518
+ const why = `its ${worker.provider} worker ${worker.jobId}'s turn is over and the story is no longer the queue's to work, so it is not woken`;
2512
2519
  step(e, now, "worker-ended", why);
2513
2520
  afterWorker(e, now, why);
2514
2521
  idle = idleWorker(worker, () => w, now);
2515
2522
  break judge;
2516
2523
  }
2517
2524
  // NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
2518
- if (worker.parkedAt === undefined && w.parked.failed === true) {
2525
+ if (worker.parkedAt === undefined && w.parked.failed === true && !killedAfterWork(worker, w.parked)) {
2519
2526
  if (e.attempts >= WORKER_ATTEMPTS) {
2520
2527
  idle = idleWorker(worker, () => w, now);
2521
2528
  delete e.worker;
@@ -2528,10 +2535,10 @@ export async function driveStoryQueue(board, world, now) {
2528
2535
  // NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
2529
2536
  if (worker.parkedAt === undefined) {
2530
2537
  worker.parkedAt = now;
2531
- step(e, now, "parked", `its ${e.provider} worker ${worker.jobId}'s turn is over with the story open, so it is woken in its own session from ${new Date(now + wakeDelayMs(worker.wakes ?? 0)).toISOString()}`);
2538
+ 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()}`);
2532
2539
  }
2533
2540
  if (!w.parked.live) {
2534
- if (now >= worker.parkedAt + wakeDelayMs(worker.wakes ?? 0))
2541
+ if (now >= worker.parkedAt + parkedWaitMs(worker, w.parked))
2535
2542
  wakeable.set(e, w.parked.sessionId);
2536
2543
  continue;
2537
2544
  }
@@ -2628,6 +2635,15 @@ export async function driveStoryQueue(board, world, now) {
2628
2635
  catch (err) {
2629
2636
  if (!(err instanceof WorkerNotStarted))
2630
2637
  throw err;
2638
+ if (err instanceof SessionStillRunning) {
2639
+ // 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
+ lanes -= 1;
2641
+ e.worker = { ...parked, startedAt: now, parkedAt: now, wakes };
2642
+ e.why = `its worker ${parked.jobId} was NOT woken: ${err.message}`;
2643
+ step(e, now, "parked", e.why);
2644
+ save();
2645
+ continue;
2646
+ }
2631
2647
  const after = world.worker(e, board);
2632
2648
  // NULL-OK: field parked is OPTIONAL and therefore it is ok to check for NULL
2633
2649
  if (after.alive && (after.parked === undefined || after.parked.live)) {
@@ -2639,14 +2655,14 @@ export async function driveStoryQueue(board, world, now) {
2639
2655
  else if (!err.unsent) {
2640
2656
  // 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.
2641
2657
  lanes -= 1;
2642
- e.worker = { ...parked, parkedAt: now, wakes };
2658
+ e.worker = { ...parked, startedAt: now, parkedAt: now, wakes };
2643
2659
  e.why = `its worker ${parked.jobId}'s wake got no answer, so it stays parked and is read again: ${err.message}`;
2644
2660
  step(e, now, "parked", e.why);
2645
2661
  }
2646
2662
  else {
2647
2663
  // OWNER: ITER/LOOP โ€” Claude Code refused to wake this story's session and no process runs it, so the worker has ended: its entry carries the provider's words and a fresh worker is started on its backoff; the next entry is read.
2648
2664
  lanes -= 1;
2649
- const why = `its ${e.provider} worker ${parked.jobId} could not be woken: ${err.message}`;
2665
+ const why = `its ${parked.provider} worker ${parked.jobId} could not be woken: ${err.message}`;
2650
2666
  delete e.worker;
2651
2667
  step(e, now, "worker-ended", why);
2652
2668
  afterWorker(e, now, why);
@@ -2678,16 +2694,22 @@ export async function driveStoryQueue(board, world, now) {
2678
2694
  e.why = `${lanes} lanes run and the lane limit is ${world.limit}, so it starts when one finishes`;
2679
2695
  continue;
2680
2696
  }
2681
- // NULL-OK: field halted is OPTIONAL and therefore it is ok to check for NULL
2682
- const forced = e.forced === true && (halted !== undefined || lanes >= world.limit);
2683
- delete e.forced;
2684
2697
  // NULL-OK: field worker is OPTIONAL and therefore it is ok to check for NULL
2685
2698
  if (e.worker !== undefined && world.worker(e, board).alive) {
2699
+ delete e.forced;
2686
2700
  e.state = "running";
2687
2701
  e.why = `its ${e.worker.provider} worker ${e.worker.jobId} still runs, so no second worker is started`;
2688
2702
  step(e, now, "started", e.why);
2689
2703
  continue;
2690
2704
  }
2705
+ const taken = world.seat(e);
2706
+ if (taken !== undefined) {
2707
+ e.why = `${taken} works it, so the queue starts no second worker`;
2708
+ continue;
2709
+ }
2710
+ // 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);
2712
+ delete e.forced;
2691
2713
  e.state = "starting";
2692
2714
  e.attempts += 1;
2693
2715
  delete e.worker;
@@ -2926,6 +2948,19 @@ export function claudeJobsOfStory(storyId, board, since, home = claudeHome()) {
2926
2948
  });
2927
2949
  return jobs.filter((j) => j.at >= since).sort((a, b) => a.at - b.at).map((j) => j.id);
2928
2950
  }
2951
+ /** ๐Ÿ”ด #4143 โ€” the jobs, in any folder, whose brief opens with the same `Stories: #N โ€” <title>` line as `brief`: a story's job started in a worktree or a nested repo, which {@link claudeJobsOfStory} never finds in the board's folder, is still that story's. */
2952
+ export function claudeJobsBriefed(brief, home = claudeHome()) {
2953
+ const dir = path.join(home, "jobs");
2954
+ if (!fs.existsSync(dir))
2955
+ return [];
2956
+ const first = brief.split("\n")[0];
2957
+ if (!/^Stories: #\d+ โ€” \S/.test(first))
2958
+ return [];
2959
+ return fs.readdirSync(dir).filter((id) => {
2960
+ const job = jobRecordOf(id, home);
2961
+ return typeof job !== "string" && job.intent.split("\n")[0] === first;
2962
+ });
2963
+ }
2929
2964
  // 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)
2930
2965
  export const WORKER_START_GRACE_MS = 2 * 60_000;
2931
2966
  const mtimeOf = (file) => {
@@ -2951,7 +2986,59 @@ function goneWorker(worker, now, home) {
2951
2986
  return { alive: true, why: `${gone}, and a process runs its session ${worker.session.id}, so it is still this story's worker` };
2952
2987
  if (now - worker.startedAt < WORKER_START_GRACE_MS)
2953
2988
  return { alive: true, why: `${gone}, and it was started ${Math.round((now - worker.startedAt) / 1000)}s ago, so its process may not have recorded its session ${worker.session.id} yet` };
2954
- return { alive: true, parked: { sessionId: worker.session.id, live: false }, why: `${gone} โ€” its session ${worker.session.id} is on disk and no process runs it, so it is parked and woken there` };
2989
+ const cut = turnCutOff(worker.session.transcript);
2990
+ return { alive: true, parked: { sessionId: worker.session.id, live: false, ...(cut ? { killed: true } : {}) }, why: `${gone} โ€” its session ${worker.session.id} is on disk and no process runs it${cut ? ", and its last turn was cut off mid-work" : ""}, so it is parked and woken there` };
2991
+ }
2992
+ // GATE: how many bytes of a transcript one backward read takes while it looks for the last assistant record โ€” the reads go on to the file's start, so nothing is ever left unread
2993
+ const TRANSCRIPT_READ_BYTES = 64 * 1024;
2994
+ /**
2995
+ * ๐Ÿ”ด #4162 โ€” whether a session's last assistant record stopped on a tool call (`stop_reason: "tool_use"`) it never saw answered: its process was
2996
+ * killed mid-work. Read backward from the end, a block at a time, so a session of tens of megabytes costs one block on a beat; a line cut at a
2997
+ * block's start is carried into the next read, and the last line Claude Code is still appending says nothing yet.
2998
+ */
2999
+ function turnCutOff(transcript) {
3000
+ const fd = fs.openSync(transcript, "r");
3001
+ try {
3002
+ let at = fs.fstatSync(fd).size;
3003
+ let carry = Buffer.alloc(0);
3004
+ while (at > 0) {
3005
+ const length = Math.min(at, TRANSCRIPT_READ_BYTES);
3006
+ at -= length;
3007
+ const block = Buffer.alloc(length);
3008
+ fs.readSync(fd, block, 0, length, at);
3009
+ const text = Buffer.concat([block, carry]);
3010
+ const first = text.indexOf(0x0a);
3011
+ carry = at > 0 && first >= 0 ? text.subarray(0, first) : at > 0 ? text : Buffer.alloc(0);
3012
+ const whole = at > 0 ? (first >= 0 ? text.subarray(first + 1) : Buffer.alloc(0)) : text;
3013
+ const stop = lastAssistantStop(whole.toString("utf8"));
3014
+ if (stop !== "none")
3015
+ return stop === "tool_use";
3016
+ }
3017
+ return false;
3018
+ }
3019
+ finally {
3020
+ fs.closeSync(fd);
3021
+ }
3022
+ }
3023
+ /** The stop reason of the last whole assistant record in `lines`, its absence as "absent", or "none" when no assistant record is in them. */
3024
+ function lastAssistantStop(lines) {
3025
+ for (const line of lines.split("\n").reverse()) {
3026
+ if (!line.includes('"type":"assistant"'))
3027
+ continue;
3028
+ let record;
3029
+ try {
3030
+ record = JSON.parse(line);
3031
+ }
3032
+ catch (err) {
3033
+ if (!(err instanceof SyntaxError))
3034
+ throw err;
3035
+ // OWNER: ITER/LOOP โ€” Claude Code is mid-append to its last line: that line says nothing yet, and the one before it is read.
3036
+ continue;
3037
+ }
3038
+ if (record.type === "assistant")
3039
+ return String(record.message.stop_reason ?? "absent");
3040
+ }
3041
+ return "none";
2955
3042
  }
2956
3043
  /** ๐Ÿ”ด #4123 โ€” a job's last whole timeline step, which ends `failed` for a provider's refusal and mid-work for a job killed with the daemon, and whether a step after it is caught mid-append. */
2957
3044
  function lastTimelineStep(jobId, home) {
@@ -3021,7 +3108,7 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
3021
3108
  return { alive: true, ...progress, why: `${said} โ€” its timeline's last step is still being written by its running process, so it is read again on the next pass` };
3022
3109
  if (step.state === "failed" || at === undefined || at <= worker.startedAt)
3023
3110
  return { alive: false, ...progress, why: said };
3024
- return { alive: true, ...progress, parked: { sessionId: job.sessionId, live, failed: true }, why: `${said} โ€” it was killed mid-work and its session worked after it was started, so it is parked and woken there` };
3111
+ 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` };
3025
3112
  }
3026
3113
  // NULL-OK: field inFlight is OPTIONAL and therefore it is ok to check for NULL
3027
3114
  const waitsOnTasks = job.inFlight !== undefined && job.inFlight.tasks + job.inFlight.queued + job.inFlight.drainableMonitors > 0;
@@ -3030,14 +3117,24 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
3030
3117
  if (live && (!TURN_OVER.has(job.state) || waitsOnTasks))
3031
3118
  return { alive: true, ...progress, why: `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
3032
3119
  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}`;
3033
- return { alive: true, ...progress, ...blocked, parked: { sessionId: job.sessionId, live }, why: `its job ${worker.jobId} is parked โ€” ${how}` };
3120
+ 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}` };
3034
3121
  }
3122
+ /** The job id `claude --bg` prints: `backgrounded ยท <id> ยท <name>` for a start under a name, and `backgrounded ยท <id>` alone for a resume, which passes none. */
3123
+ const BACKGROUNDED = /^backgrounded ยท (\S+)/m;
3124
+ /** What `claude --bg --resume` adds when the session it was handed still runs, having started a second process on that session: `note: session <id> is already running in the background, so this started a copy as <copy>.` */
3125
+ const STARTED_A_COPY = /session (\S+) is already running in the background, so this started a copy as ([^\s.]+)/;
3035
3126
  /** ๐Ÿ”ด #4123 โ€” wakes a parked `claude --bg` session in place with `message`: passed no flags, Claude Code continues the same job with its own saved options. */
3036
3127
  export function wakeStoryWorker(sessionId, message, board, cli, now) {
3037
3128
  return new Promise((resolve, reject) => {
3038
3129
  execFile(cli.cmd, [...cli.args, "--bg", "--resume", sessionId, message], { cwd: board, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
3039
3130
  const said = `${stdout}${stderr}`;
3040
- const job = /^backgrounded ยท (\S+) ยท /m.exec(said);
3131
+ const copy = STARTED_A_COPY.exec(said);
3132
+ if (copy !== null) {
3133
+ const started = `claude --bg --resume found session ${copy[1]} still running, so it started a copy as ${copy[2]}, which took the message`;
3134
+ stopStoryWorker(copy[2], cli).then(() => reject(new SessionStillRunning(`${started} and was stopped โ€” the session's own process never received the message`)), (err) => reject(new SessionStillRunning(`${started}, and stopping that copy failed (${err.message}) โ€” the copy still runs with the message beside the session's own process`)));
3135
+ return;
3136
+ }
3137
+ const job = BACKGROUNDED.exec(said);
3041
3138
  if (job !== null)
3042
3139
  return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
3043
3140
  reject(new WorkerNotStarted(`claude --bg --resume ${err === null ? "printed no job id" : `failed (${err.message.split("\n")[0]})`} โ€” ${said.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`, err !== null && err.killed !== true));
@@ -3130,9 +3227,12 @@ export async function retireStoryWorker(worker, cli, record, home = claudeHome()
3130
3227
  * still holds at its prompt is stopped, one still mid-turn is let finish, and either refuses this pass naming it, so the
3131
3228
  * story is archived once every process of it has gone; answers what of the worker's own conversation moved.
3132
3229
  */
3133
- export async function retireStory(storyId, board, worker, cli, record, home = claudeHome()) {
3230
+ export async function retireStory(entry, board, worker, cli, record, home = claudeHome()) {
3231
+ const storyId = entry.storyId;
3134
3232
  const held = [];
3135
- for (const jobId of claudeJobsOfStory(storyId, board, 0, home).filter((id) => id !== worker.jobId)) {
3233
+ const earlier = new Set([...claudeJobsOfStory(storyId, board, 0, home), ...claudeJobsBriefed(entry.brief, home)]);
3234
+ earlier.delete(worker.jobId);
3235
+ for (const jobId of earlier) {
3136
3236
  const job = jobRecordOf(jobId, home);
3137
3237
  if (job !== "torn" && job !== "gone" && liveClaudeSessions(home).has(job.sessionId)) {
3138
3238
  const atPrompt = TURN_OVER.has(job.state);
@@ -3246,7 +3346,7 @@ export function launchClaudeJob(name, model, brief, cwd, cli, now) {
3246
3346
  return new Promise((resolve, reject) => {
3247
3347
  execFile(cli.cmd, [...cli.args, "--bg", "--name", name, "--model", model, "--permission-mode", "bypassPermissions", brief], { cwd, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
3248
3348
  const said = `${stdout}${stderr}`;
3249
- const job = /^backgrounded ยท (\S+) ยท /m.exec(said);
3349
+ const job = BACKGROUNDED.exec(said);
3250
3350
  if (job !== null)
3251
3351
  return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
3252
3352
  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"}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.3.377",
3
+ "version": "1.3.378",
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",