omni-notify-mcp 1.3.342 → 1.3.344
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agentGateway.js +4 -0
- package/dist/gateway/claudeProvider.js +0 -1
- package/dist/gateway/cliSession.js +7 -4
- package/dist/gateway/codexProvider.js +0 -1
- package/dist/gateway/conversations.js +1 -4
- package/dist/gateway/copilotProvider.js +0 -1
- package/dist/gateway/mcpDoor.js +2 -2
- package/dist/gateway/nativeTerminal.js +1 -0
- package/dist/gateway/opencodeEvents.mjs +13 -0
- package/dist/gateway/opencodeProvider.js +157 -16
- package/dist/gateway/sessionDriver.js +0 -2
- package/dist/gateway/terminalDoor.js +1 -3
- package/dist/notify.js +18 -7
- package/package.json +2 -2
- /package/dist/shared/{autoSwitch.cjs → webhost/autoSwitch.cjs} +0 -0
package/dist/agentGateway.js
CHANGED
|
@@ -15,6 +15,7 @@ import { masterMuted } from "./notify.js";
|
|
|
15
15
|
import { appendEvent, CONVERSATION_MUTED_MESSAGE, conversationRefusal, editOwed, GatewayError, listConversations, monotonicMs, openConversationOf, openConversationsOf, queueNoticeOf, readEvents, resolveProject, routeAsk, stopTargetOf, sendToConversation, startConversation, updateConversation, } from "./gateway/conversations.js";
|
|
16
16
|
import { SessionDriver } from "./gateway/sessionDriver.js";
|
|
17
17
|
import { DEFAULT_PROVIDER } from "./gateway/provider.js";
|
|
18
|
+
import { clearOpenCodeLogs } from "./gateway/opencodeProvider.js";
|
|
18
19
|
import { resendUndelivered, turnEnded } from "./gateway/mcpEvents.js";
|
|
19
20
|
export const AGENT_PREFIX = "!";
|
|
20
21
|
/** A chat: the newest conversation not stopped (`/new` and `/stop` end it), and every line of the turn, the answer split at 500. */
|
|
@@ -48,6 +49,7 @@ function driverOptions() {
|
|
|
48
49
|
const script = process.env.NOTIFY_AGENT_CLI_SCRIPT;
|
|
49
50
|
const copilot = process.env.NOTIFY_AGENT_COPILOT_SCRIPT;
|
|
50
51
|
const codex = process.env.NOTIFY_AGENT_CODEX_SCRIPT;
|
|
52
|
+
const opencode = process.env.NOTIFY_AGENT_OPENCODE_SCRIPT;
|
|
51
53
|
return {
|
|
52
54
|
guardDir,
|
|
53
55
|
spare: process.env.NOTIFY_AGENT_SPARE === "1" ? true : undefined,
|
|
@@ -55,6 +57,7 @@ function driverOptions() {
|
|
|
55
57
|
...(script ? { [DEFAULT_PROVIDER]: { cmd: process.execPath, args: [script] } } : {}),
|
|
56
58
|
...(copilot ? { copilot: { cmd: process.execPath, args: [copilot] } } : {}),
|
|
57
59
|
...(codex ? { codex: { cmd: process.execPath, args: [codex] } } : {}),
|
|
60
|
+
...(opencode ? { opencode: { cmd: process.execPath, args: [opencode] } } : {}),
|
|
58
61
|
},
|
|
59
62
|
capacity: process.env.NOTIFY_AGENT_CAPACITY ? Number(process.env.NOTIFY_AGENT_CAPACITY) : undefined,
|
|
60
63
|
idleMs: process.env.NOTIFY_AGENT_IDLE_MS ? Number(process.env.NOTIFY_AGENT_IDLE_MS) : undefined,
|
|
@@ -83,6 +86,7 @@ export class AgentGateway {
|
|
|
83
86
|
}
|
|
84
87
|
/** Starts the driver in the process that owns the pollers, then takes back every turn the last process owed its thread an answer for. */
|
|
85
88
|
boot() {
|
|
89
|
+
clearOpenCodeLogs();
|
|
86
90
|
this.driver.boot();
|
|
87
91
|
if (this.recovered)
|
|
88
92
|
return;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* commands — is on its own screen and nowhere else.
|
|
8
8
|
*
|
|
9
9
|
* `CliSession` is that one mechanism; each CLI differs only in how it reports a prompt taken and over. Claude Code posts
|
|
10
|
-
* hooks to BN (claudeProvider.ts); Codex and
|
|
10
|
+
* hooks to BN (claudeProvider.ts); Codex, Copilot and OpenCode write a session log BN reads (`LoggedCliSession`, below).
|
|
11
11
|
*/
|
|
12
12
|
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
13
13
|
import { resolve } from "path";
|
|
@@ -61,8 +61,8 @@ export class CliSession {
|
|
|
61
61
|
this.resumes = resumes;
|
|
62
62
|
}
|
|
63
63
|
/** Starts the CLI with its own arguments for this session, held by the person BN's door serves. */
|
|
64
|
-
launch(args) {
|
|
65
|
-
this.terminal = openDrivenTerminal(terminalHolder(), { id: this.spec.id, provider: this.provider, project: this.spec.project, cmd: this.spec.cli.cmd, args: [...this.spec.cli.args, ...args], cols: 100, rows: 30 });
|
|
64
|
+
launch(args, env) {
|
|
65
|
+
this.terminal = openDrivenTerminal(terminalHolder(), { id: this.spec.id, provider: this.provider, project: this.spec.project, cmd: this.spec.cli.cmd, args: [...this.spec.cli.args, ...args], env, cols: 100, rows: 30 });
|
|
66
66
|
}
|
|
67
67
|
/** Called last in a session's constructor, once all it reads is set: the CLI ending ends the turn it held. */
|
|
68
68
|
watchEnd() {
|
|
@@ -248,7 +248,7 @@ export class LoggedCliSession extends CliSession {
|
|
|
248
248
|
this.finder = cli.log.finder(this.since, spec.project);
|
|
249
249
|
if (this.resumes)
|
|
250
250
|
this.bind(cli.log.resumed(spec.sessionId), true);
|
|
251
|
-
this.launch(cli.args(spec, this.resumes));
|
|
251
|
+
this.launch(cli.args(spec, this.resumes), cli.env);
|
|
252
252
|
this.terminal.onSubmit((line) => {
|
|
253
253
|
// NULL-OK: field log is OPTIONAL and therefore it is ok to check for NULL
|
|
254
254
|
if (this.log === undefined)
|
|
@@ -271,6 +271,7 @@ export class LoggedCliSession extends CliSession {
|
|
|
271
271
|
// NULL-OK: field log is OPTIONAL and therefore it is ok to check for NULL
|
|
272
272
|
if (this.log !== undefined)
|
|
273
273
|
reading.delete(this.log);
|
|
274
|
+
this.cli.log.ended?.();
|
|
274
275
|
}
|
|
275
276
|
ready() {
|
|
276
277
|
return this.settled;
|
|
@@ -398,6 +399,8 @@ export class LoggedCliSession extends CliSession {
|
|
|
398
399
|
else
|
|
399
400
|
this.settle(turn, () => turn.resolve(news.answer));
|
|
400
401
|
}
|
|
402
|
+
if (news.kind === "failed" && news.endsCli === true)
|
|
403
|
+
this.end();
|
|
401
404
|
if (this.open.length === 0)
|
|
402
405
|
this.wake();
|
|
403
406
|
return;
|
|
@@ -184,7 +184,6 @@ export const codexProvider = {
|
|
|
184
184
|
label: "Codex",
|
|
185
185
|
command: "codex",
|
|
186
186
|
nativeArgs: (model) => model ? ["-m", model] : [],
|
|
187
|
-
console: true,
|
|
188
187
|
open: (spec) => new LoggedCliSession(spec, codexCli),
|
|
189
188
|
archive: (spec, sessionId) => archiveCodexThread(spec, sessionId, "thread/archive"),
|
|
190
189
|
unarchive: (spec, sessionId) => archiveCodexThread(spec, sessionId, "thread/unarchive"),
|
|
@@ -515,8 +515,7 @@ export function namedProvider(provider) {
|
|
|
515
515
|
return provider;
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
|
-
* Refuses, in words, a conversation with no CLI of its own to open or stream (#3845, #3916): its
|
|
519
|
-
* turn in a process of its own that ends with it, or its record names an agent this gateway does not run.
|
|
518
|
+
* Refuses, in words, a conversation with no CLI of its own to open or stream (#3845, #3916): its record names an agent this gateway does not run.
|
|
520
519
|
*/
|
|
521
520
|
export function requireOwnCli(id) {
|
|
522
521
|
const named = readConversation(id).provider;
|
|
@@ -524,8 +523,6 @@ export function requireOwnCli(id) {
|
|
|
524
523
|
// NULL-OK: field provider is OPTIONAL and therefore it is ok to check for NULL
|
|
525
524
|
if (provider === undefined)
|
|
526
525
|
throw new GatewayError(409, `This conversation's agent is "${named}", which this gateway does not run, so it has no CLI to open.`);
|
|
527
|
-
if (provider.console !== true)
|
|
528
|
-
throw new GatewayError(409, `${provider.label} answers each turn in a process of its own that ends with it, so this conversation has no CLI to open.`);
|
|
529
526
|
}
|
|
530
527
|
/** #3849 — every listed project folder present on this machine, by name, with whether it is a Git repository and holds a board; `list` is the workspace list file they come from. */
|
|
531
528
|
export function listProjects() {
|
|
@@ -123,6 +123,5 @@ export const copilotProvider = {
|
|
|
123
123
|
label: "Copilot",
|
|
124
124
|
command: "copilot",
|
|
125
125
|
nativeArgs: (model) => model ? ["--model", model] : [],
|
|
126
|
-
console: true,
|
|
127
126
|
open: (spec) => new LoggedCliSession(spec, copilotCli(stateDir(spec.name ?? spec.sessionId))),
|
|
128
127
|
};
|
package/dist/gateway/mcpDoor.js
CHANGED
|
@@ -108,7 +108,7 @@ Which tool to call:
|
|
|
108
108
|
- agent_project: sets or switches the project folder a conversation's agent works in, before its first message or between any two turns, also after work in another project. A switch while a turn is running is refused and says which turn.
|
|
109
109
|
- agent_send: a follow-up to a conversation that already exists. It appends the message and returns its position n at once without waiting; n is the turn to read the answer of. A message sent while a turn runs is queued behind that turn, not an interrupt — also while a conversation's agent waits on a question on its own CLI screen, which the user answers on that screen, never by a message to the conversation.
|
|
110
110
|
- agent_wait: the only way to read what happened. It is a read you call, not a notification BN pushes. wait=0 (the default) returns at once with whatever is there; wait up to ${MAX_WAIT_SECONDS} holds the call until a new event arrives. Pass after = the after the previous reply returned, which already counts the line that reply wrote; after=0 reads the log from the start, earlier turns included. The turn you asked for has ended at the first event whose turn is your n and whose kind is answer or failed, or at an event of kind stopped.
|
|
111
|
-
- agent_stream: what the conversation's agent shows AS IT HAPPENS — not only the finished reply. Every conversation on claude, codex or
|
|
111
|
+
- agent_stream: what the conversation's agent shows AS IT HAPPENS — not only the finished reply. Every conversation on claude, codex, copilot or opencode runs in ONE interactive CLI of its own, the same process the browser shows: agent_send and agent_prompt type into it and agent_wait reads each turn's answer off it. agent_stream returns the URL of that CLI's own console output, /v1/terminals/<id>/console, a live Server-Sent Events stream on this same door of frames {seq,ts,kind:"output",text,reset} carrying its raw screen bytes, never a second CLI; attach with a plain HTTP GET, and reconnect with ?after=<seq> of the last frame you read to miss nothing. It is a read: it changes nothing and starts nothing.
|
|
112
112
|
For a long autonomous task, call agent_start, then agent_wait with after=1 and wait=${MAX_WAIT_SECONDS}, again and again with the after each reply returned, until the turn ends; your own reply to the user can be written between reads. A follow-up is agent_send to the same id, then the same agent_wait loop with after = the n it returned.
|
|
113
113
|
To avoid submitting a task twice: agent_start already submitted its text, so do not agent_send the same text after it; a call that timed out or returned working=true has been received and is running, so read on with agent_wait instead of calling agent_prompt, agent_start or agent_send again with the same text.
|
|
114
114
|
To avoid blocking: agent_prompt and agent_wait with wait above 0 each hold the call for up to ${MAX_WAIT_SECONDS} seconds; agent_start, agent_send and agent_wait with wait=0 return at once.
|
|
@@ -276,7 +276,7 @@ function buildServer(caller, base, offer) {
|
|
|
276
276
|
});
|
|
277
277
|
server.tool("agent_project", `Sets or switches the project folder a conversation's agent works in — before its first message, or between any two turns, also after work in another project. The next turn's agent runs in that folder and writes to its board, while the conversation's id, its whole transcript and the agent itself stay: the same session carries on in the new folder with its earlier turns in hand, so this NEVER starts a new agent and never makes a new conversation. A switch is refused at two safe boundaries — while a turn is running, named with the running turn's number, and while a browser CLI is running the conversation's own session, because a running process is never moved under itself. Either refusal leaves the record on its old project.`, { id: z.string().min(1).describe("The conversation id agent_open or agent_start returned, or the 'conversation' agent_prompt returned"), project: projectField(offer).describe(`Exactly one of ${offer.either}, resolved under ${offer.under}; no path is accepted`) }, ({ id, project }) => act(() => setConversationProject(id, project)));
|
|
278
278
|
server.tool("agent_status", "One conversation's project (absent until one is chosen), provider, model and state, with its title (the name its session carries in Claude's session list), its lifecycle (active while a turn runs, is queued or waits on the user's answer; idle when open with no turn; completed once stopped or archived) and beside (the conversation of the same connection it was opened next to, if any).", { id: z.string().min(1) }, ({ id }) => act(() => describeConversation(readConversation(id))));
|
|
279
|
-
server.tool("agent_stream", `Where to attach to a conversation's LIVE stream: what its agent shows AS IT HAPPENS, not only the finished reply that agent_prompt and agent_wait carry. Every conversation on claude, codex or
|
|
279
|
+
server.tool("agent_stream", `Where to attach to a conversation's LIVE stream: what its agent shows AS IT HAPPENS, not only the finished reply that agent_prompt and agent_wait carry. Every conversation on claude, codex, copilot or opencode runs in ONE interactive CLI of its own — the same process the browser shows and agent_send types into — and this returns {conversation, url, after, console:true}, url being that CLI's own console output at /v1/terminals/<id>/console. Attach with a plain HTTP GET; the answer is a Server-Sent Events stream of frames {seq, ts, kind:"output", text, reset} carrying its raw screen bytes (its prompt, tool traces and any question it waits on). Reconnect with ?after=<seq> of the last frame you read and you are handed every byte past it. It is a read — it starts no agent, spends nothing and changes nothing.`, { id: z.string().min(1).describe("The conversation id agent_start, agent_prompt or agent_open returned"), after: z.number().int().min(0).optional().describe("The last frame seq you already have; the stream resumes past it") }, ({ id, after }) => act(() => {
|
|
280
280
|
requireOwnCli(id);
|
|
281
281
|
const url = new URL(`/v1/terminals/${id}/console`, base);
|
|
282
282
|
// NULL-OK: field after is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -125,6 +125,7 @@ export class NativeTerminal {
|
|
|
125
125
|
// A CLI opened in the browser is the person's own interactive session, never a nested child of whatever launched
|
|
126
126
|
// this daemon: inheriting the marker suppresses its transcripts and its connectors on screen.
|
|
127
127
|
delete env.CLAUDE_CODE_CHILD_SESSION;
|
|
128
|
+
Object.assign(env, spec.env);
|
|
128
129
|
this.child.send({ kind: "start", command: spec.cmd, args: spec.args, project: spec.project, cols: spec.cols, rows: spec.rows, env, ownerPid: process.pid });
|
|
129
130
|
}
|
|
130
131
|
/** The record this CLI answers for. */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
// The plugin OpenCode loads in BN's CLI: it appends the bus events a turn is read from, one JSON object per line, to the file `BN_OPENCODE_LOG` names. A tool part is kept only as the fact that one ran.
|
|
4
|
+
const KEPT = /^(session\.(created|error|idle|status)|message\.(updated|part\.updated)|permission\.asked|question\.asked)$/;
|
|
5
|
+
|
|
6
|
+
export const BnEvents = async () => ({
|
|
7
|
+
event: async ({ event }) => {
|
|
8
|
+
if (!KEPT.test(event.type)) return;
|
|
9
|
+
const part = event.properties?.part;
|
|
10
|
+
const row = event.type === "message.part.updated" && part?.type === "tool" ? { type: event.type, properties: { sessionID: event.properties.sessionID, part: { type: "tool" } } } : event;
|
|
11
|
+
appendFileSync(process.env.BN_OPENCODE_LOG, `${JSON.stringify(row)}\n`);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode behind the provider seam (#3847, #3929): every turn of a conversation runs inside that conversation's OWN
|
|
3
|
+
* interactive OpenCode TUI on a pty — never a headless `opencode run` — so the browser and MCP reach ONE process. A turn
|
|
4
|
+
* is typed into it; what it took and how the turn ended are read off a log of the CLI's own bus events, which the plugin
|
|
5
|
+
* shipped beside this file (`opencodeEvents.mjs`) appends as they happen (measured on opencode 1.19.5: `session.created`
|
|
6
|
+
* with the session id, `message.updated` naming each message's role, `message.part.updated` with a user text part for a
|
|
7
|
+
* prompt taken and a text part carrying `time.end` for an assistant reply, `session.status` busy / idle / retry,
|
|
8
|
+
* `session.error`, then `session.idle` when the turn is over). Each CLI start writes a log of its own, so a log is never
|
|
9
|
+
* another CLI's and a resumed session reads only what this CLI wrote.
|
|
10
|
+
*
|
|
11
|
+
* The CLI runs on the key and store `opencodeRoute` names, chosen when its CLI opens. A key the vendor refuses — a
|
|
12
|
+
* refusing `session.error`, or the `retry` status the CLI reports while it retries a rate limit in silence — is recorded
|
|
13
|
+
* where every switcher reads it, the turn fails naming that key, and the CLI is ended: the next message reopens the
|
|
14
|
+
* session with `-s` on a fresh route, which skips the refused key.
|
|
15
|
+
*/
|
|
16
|
+
import { randomUUID } from "crypto";
|
|
17
|
+
import { existsSync, mkdirSync, readdirSync, rmSync } from "fs";
|
|
18
|
+
import { homedir } from "os";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
import autoSwitch from "../shared/webhost/autoSwitch.cjs";
|
|
21
|
+
import { KEY_REFUSAL_STATUSES, KEY_REFUSAL_WORDS } from "../shared/agentSession.js";
|
|
22
|
+
import { LoggedCliSession } from "./cliSession.js";
|
|
23
|
+
import { CONFIG_DIR } from "../notify.js";
|
|
24
|
+
// GATE: the words of a retry status that mean the provider rate-limited THIS key; any other retry (a 5xx, a dropped connection) is the CLI riding out a fault the key did not cause
|
|
25
|
+
const RATE_LIMITED = /rate.?limit|too many requests/i;
|
|
5
26
|
const ROUTE_REFUSALS = new Set(["OPENCODE_NO_KEY", "KEYPLAN_UNREADABLE", "REFUSAL_UNREADABLE"]);
|
|
6
27
|
function routeOf(model, failure) {
|
|
7
28
|
try {
|
|
@@ -13,21 +34,141 @@ function routeOf(model, failure) {
|
|
|
13
34
|
throw failure(err.message);
|
|
14
35
|
}
|
|
15
36
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
/** The plugin OpenCode loads in BN's CLI, shipped beside this module — in dist/gateway for a build, beside the bundled daemon in the extension. */
|
|
38
|
+
const EVENT_PLUGIN = new URL("./opencodeEvents.mjs", import.meta.url);
|
|
39
|
+
/** The folder each CLI start's own log goes in: this daemon's own config dir, so no other daemon on the machine clears a log this one is reading. */
|
|
40
|
+
const logDir = () => join(CONFIG_DIR, "opencode-logs");
|
|
41
|
+
/** The daemon starting: logs a CLI of an earlier daemon left behind belong to no CLI now. */
|
|
42
|
+
export function clearOpenCodeLogs() {
|
|
43
|
+
if (!existsSync(logDir()))
|
|
44
|
+
return;
|
|
45
|
+
for (const name of readdirSync(logDir()))
|
|
46
|
+
rmSync(join(logDir(), name), { force: true });
|
|
47
|
+
}
|
|
48
|
+
/** A string field an event must carry, or a SyntaxError naming the event: OpenCode writes every one of these as a string. */
|
|
49
|
+
function field(event, value, name) {
|
|
50
|
+
if (typeof value !== "string")
|
|
51
|
+
throw new SyntaxError(`an OpenCode ${String(event.type)} event carries no ${name}: ${JSON.stringify(event).slice(0, 200)}`);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/** The log of one OpenCode CLI start, read with what the prompt in flight has said so far. */
|
|
55
|
+
class OpenCodeLog {
|
|
56
|
+
file;
|
|
57
|
+
key;
|
|
58
|
+
/** The log is this CLI start's own: no other CLI writes into it. */
|
|
59
|
+
shared = false;
|
|
60
|
+
/** The session this log's turns belong to: a resumed session's own id, else the first session created without a parent. A sub-agent's session is never it. */
|
|
61
|
+
main;
|
|
62
|
+
roles = new Map();
|
|
63
|
+
taken = new Set();
|
|
64
|
+
/** The last reply text the CLI finished writing this turn. */
|
|
65
|
+
said;
|
|
66
|
+
failure;
|
|
67
|
+
constructor(file, resumedSession, key) {
|
|
68
|
+
this.file = file;
|
|
69
|
+
this.key = key;
|
|
70
|
+
this.main = resumedSession;
|
|
71
|
+
}
|
|
72
|
+
resumed() {
|
|
73
|
+
return existsSync(this.file) ? this.file : undefined;
|
|
74
|
+
}
|
|
75
|
+
finder() {
|
|
76
|
+
return { fresh: () => existsSync(this.file) ? [{ file: this.file, prompts: [] }] : [] };
|
|
77
|
+
}
|
|
78
|
+
ended() {
|
|
79
|
+
rmSync(this.file, { force: true });
|
|
80
|
+
}
|
|
81
|
+
/** The vendor refused the key this CLI runs on: it is recorded as refused, and the turn fails naming it and ends the CLI. */
|
|
82
|
+
refused(said) {
|
|
83
|
+
const why = `${this.key.named} was refused by the provider (${said}), so BN ended this CLI; the next message continues the session on the next key.`;
|
|
84
|
+
this.key.refuse(said);
|
|
85
|
+
return [{ kind: "failed", why, endsCli: true }];
|
|
86
|
+
}
|
|
87
|
+
read(row) {
|
|
88
|
+
const event = row;
|
|
89
|
+
const p = event.properties ?? {};
|
|
90
|
+
if (event.type === "session.created") {
|
|
91
|
+
if (p.info?.parentID !== undefined || this.main !== undefined)
|
|
92
|
+
return [{ kind: "busy" }];
|
|
93
|
+
this.main = field(event, p.info?.id, "info.id");
|
|
94
|
+
return [{ kind: "session", id: this.main }];
|
|
95
|
+
}
|
|
96
|
+
if (this.main === undefined || p.sessionID !== this.main)
|
|
97
|
+
return [{ kind: "busy" }];
|
|
98
|
+
switch (event.type) {
|
|
99
|
+
case "message.updated":
|
|
100
|
+
this.roles.set(field(event, p.info?.id, "info.id"), field(event, p.info?.role, "info.role"));
|
|
101
|
+
return [{ kind: "busy" }];
|
|
102
|
+
case "message.part.updated": {
|
|
103
|
+
if (typeof p.part !== "object" || p.part === null)
|
|
104
|
+
throw new SyntaxError(`an OpenCode message.part.updated event carries no part: ${JSON.stringify(event).slice(0, 200)}`);
|
|
105
|
+
const part = p.part;
|
|
106
|
+
if (part.type !== "text" || part.synthetic === true)
|
|
107
|
+
return [{ kind: "busy" }];
|
|
108
|
+
const message = field(event, part.messageID, "part.messageID");
|
|
109
|
+
const role = this.roles.get(message);
|
|
110
|
+
if (role === undefined)
|
|
111
|
+
throw new SyntaxError(`an OpenCode text part arrived before its message was named: ${JSON.stringify(event).slice(0, 200)}`);
|
|
112
|
+
if (role === "user") {
|
|
113
|
+
if (this.taken.has(message))
|
|
114
|
+
return [{ kind: "busy" }];
|
|
115
|
+
this.taken.add(message);
|
|
116
|
+
this.said = undefined;
|
|
117
|
+
this.failure = undefined;
|
|
118
|
+
return [{ kind: "taken", text: field(event, part.text, "part.text") }];
|
|
119
|
+
}
|
|
120
|
+
if (part.time?.end !== undefined)
|
|
121
|
+
this.said = field(event, part.text, "part.text");
|
|
122
|
+
return [{ kind: "busy" }];
|
|
123
|
+
}
|
|
124
|
+
case "session.status": {
|
|
125
|
+
const retrying = p.status?.type === "retry" ? p.status.message : undefined;
|
|
126
|
+
return typeof retrying === "string" && (RATE_LIMITED.test(retrying) || KEY_REFUSAL_WORDS.test(retrying)) ? this.refused(`rate-limited, being retried by the CLI: ${retrying}`) : [{ kind: "busy" }];
|
|
127
|
+
}
|
|
128
|
+
case "session.error": {
|
|
129
|
+
const said = field(event, p.error?.data?.message ?? p.error?.name, "error message");
|
|
130
|
+
const status = p.error?.data?.statusCode;
|
|
131
|
+
if ((typeof status === "number" && KEY_REFUSAL_STATUSES.has(status)) || KEY_REFUSAL_WORDS.test(said))
|
|
132
|
+
return this.refused(typeof status === "number" ? `${said} (HTTP ${status})` : said);
|
|
133
|
+
this.failure = `OpenCode reported: ${said}`;
|
|
134
|
+
return [{ kind: "busy" }];
|
|
135
|
+
}
|
|
136
|
+
case "permission.asked":
|
|
137
|
+
return [{ kind: "busy" }];
|
|
138
|
+
case "question.asked":
|
|
139
|
+
return [{ kind: "waiting" }];
|
|
140
|
+
case "session.idle": {
|
|
141
|
+
const [said, failure] = [this.said, this.failure];
|
|
142
|
+
[this.said, this.failure] = [undefined, undefined];
|
|
143
|
+
// NULL-OK: field failure is OPTIONAL and therefore it is ok to check for NULL
|
|
144
|
+
if (failure !== undefined)
|
|
145
|
+
return [{ kind: "failed", why: failure }];
|
|
146
|
+
// NULL-OK: field said is OPTIONAL and therefore it is ok to check for NULL
|
|
147
|
+
return said === undefined ? [{ kind: "silent" }] : [{ kind: "over", answer: said }];
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
return [{ kind: "busy" }];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** How BN runs one OpenCode conversation's CLI: the route is read now, so a conversation with no key to run on is refused in words before any CLI starts. */
|
|
155
|
+
function opencodeCli(spec) {
|
|
156
|
+
const route = routeOf(spec.model, (message) => spec.failures.fail(message));
|
|
157
|
+
mkdirSync(logDir(), { recursive: true });
|
|
158
|
+
const file = join(logDir(), `${randomUUID()}.jsonl`);
|
|
159
|
+
const key = { named: route.named, refuse: (reason) => autoSwitch.markKeyRefused(homedir(), route.identityId, reason) };
|
|
160
|
+
return {
|
|
161
|
+
get provider() { return opencodeProvider; },
|
|
162
|
+
args: (_spec, resumes) => ["--auto", "-m", route.model, ...(resumes ? ["-s", spec.sessionId] : [])],
|
|
163
|
+
env: { ...route.env, BN_OPENCODE_LOG: file, OPENCODE_CONFIG_CONTENT: JSON.stringify({ plugin: [EVENT_PLUGIN.href], autoupdate: false }) },
|
|
164
|
+
log: new OpenCodeLog(file, spec.started ? spec.sessionId : undefined, key),
|
|
165
|
+
refusal: () => undefined,
|
|
166
|
+
};
|
|
27
167
|
}
|
|
28
168
|
export const opencodeProvider = {
|
|
29
169
|
name: "opencode",
|
|
30
170
|
label: "OpenCode",
|
|
31
171
|
command: "opencode",
|
|
32
|
-
|
|
172
|
+
nativeArgs: (model) => model ? ["-m", model] : [],
|
|
173
|
+
open: (spec) => new LoggedCliSession(spec, opencodeCli(spec)),
|
|
33
174
|
};
|
|
@@ -466,8 +466,6 @@ export class SessionDriver {
|
|
|
466
466
|
// NULL-OK: field provider is OPTIONAL and therefore it is ok to check for NULL
|
|
467
467
|
if (provider === undefined)
|
|
468
468
|
throw new GatewayError(409, `This conversation's agent is "${c.provider}", which this gateway does not run, so no CLI can be opened on it.`);
|
|
469
|
-
if (provider.console !== true)
|
|
470
|
-
throw new GatewayError(409, `${provider.label} answers each turn in a process of its own that ends with it, so this conversation has no CLI to open.`);
|
|
471
469
|
// NULL-OK: field project is OPTIONAL and therefore it is ok to check for NULL
|
|
472
470
|
if (c.project === undefined)
|
|
473
471
|
throw new GatewayError(409, "This conversation has no workspace: it was made before one was required, and a CLI runs in a folder. Set one with agent_project, then open it.");
|
|
@@ -176,13 +176,11 @@ export async function terminalConsole(req, res, url) {
|
|
|
176
176
|
* has none never puts a Model box on screen that silently does nothing. Both are read off the provider itself.
|
|
177
177
|
*/
|
|
178
178
|
export function nativeCatalog() {
|
|
179
|
-
return PROVIDER_NAMES.map((name) => providerFor(name)).
|
|
179
|
+
return PROVIDER_NAMES.map((name) => providerFor(name)).map((provider) => ({ name: provider.name, label: provider.label, model: provider.nativeArgs !== undefined }));
|
|
180
180
|
}
|
|
181
181
|
/** The conversation New Agent makes: an empty one on the CLI and folder the form named, with no turn and nothing spent. */
|
|
182
182
|
function newAgent(body) {
|
|
183
183
|
const provider = providerFor(namedProvider(body.provider));
|
|
184
|
-
if (provider.console !== true)
|
|
185
|
-
throw new GatewayError(409, `${provider.label} answers each turn in a process of its own that ends with it, so it has no CLI to open here.`);
|
|
186
184
|
const model = typeof body.model === "string" && body.model.trim() ? body.model.trim() : undefined;
|
|
187
185
|
if (model !== undefined && !/^[a-zA-Z0-9._:/-]+$/.test(model))
|
|
188
186
|
throw new GatewayError(400, "Model must be its CLI name, without spaces or shell characters.");
|
package/dist/notify.js
CHANGED
|
@@ -738,11 +738,17 @@ function persistInboxQueue(arrivals = []) {
|
|
|
738
738
|
absorbQueued(merged, entry, [...(inboxDeliveredTo.get(entryKey(entry)) ?? [])]);
|
|
739
739
|
for (const entry of arrivals)
|
|
740
740
|
absorbQueued(merged, entry, []);
|
|
741
|
+
for (const [key, entry] of merged)
|
|
742
|
+
absorbQueued(merged, entry, [...(inboxDeliveredTo.get(key) ?? [])]);
|
|
741
743
|
const name = `${OWN_QUEUE_PREFIX}${Date.now()}${String(queueWrites++).padStart(4, "0")}.json`;
|
|
742
744
|
writeFileSync(join(CONFIG_DIR, `${name}.tmp`), JSON.stringify([...merged.values()]));
|
|
743
745
|
renameSync(join(CONFIG_DIR, `${name}.tmp`), join(CONFIG_DIR, name));
|
|
744
746
|
for (const old of earlier)
|
|
745
747
|
rmSync(join(CONFIG_DIR, old), { force: true });
|
|
748
|
+
const queued = new Set(inboxQueue.map(entryKey));
|
|
749
|
+
for (const key of [...inboxDeliveredTo.keys()])
|
|
750
|
+
if (!queued.has(key))
|
|
751
|
+
inboxDeliveredTo.delete(key);
|
|
746
752
|
// a file nobody wrote for the entry lifetime holds only entries already past it (an entry is never newer than its file's last write); a staging file a dead process left is the same
|
|
747
753
|
const staged = existsSync(CONFIG_DIR) ? readdirSync(CONFIG_DIR).filter((f) => STAGED_QUEUE_FILE.test(f)) : [];
|
|
748
754
|
for (const other of [...queueFileNames().filter((f) => !f.startsWith(OWN_QUEUE_PREFIX)), ...staged]) {
|
|
@@ -751,17 +757,17 @@ function persistInboxQueue(arrivals = []) {
|
|
|
751
757
|
rmSync(join(CONFIG_DIR, other), { force: true });
|
|
752
758
|
}
|
|
753
759
|
}
|
|
754
|
-
// Entries in the shared queue
|
|
755
|
-
// and in the shared file, so it is never taken twice) and handed over.
|
|
760
|
+
// Entries in the shared queue this process does not hold yet, restored with the marks the file carries.
|
|
756
761
|
function takeSharedEntries(saved) {
|
|
757
762
|
const mine = [];
|
|
758
763
|
for (const { deliveredTo, ...entry } of saved) {
|
|
759
|
-
|
|
764
|
+
const key = entryKey(entry);
|
|
765
|
+
if (inboxQueue.some((queued) => entryKey(queued) === key))
|
|
760
766
|
continue;
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
767
|
+
if (entry.tag && (deliveredTo.includes(deliveredKey(entry.tag)) || alreadyDelivered(entry, entry.tag)))
|
|
768
|
+
continue;
|
|
769
|
+
for (const mark of deliveredTo)
|
|
770
|
+
markDelivered(entry, mark === "*" ? undefined : mark);
|
|
765
771
|
mine.push(entry);
|
|
766
772
|
}
|
|
767
773
|
if (mine.length === 0)
|
|
@@ -769,8 +775,13 @@ function takeSharedEntries(saved) {
|
|
|
769
775
|
for (const entry of mine) {
|
|
770
776
|
// Only the entry addressed to this host is recorded as taken by it; a tagged entry another chat owns stays
|
|
771
777
|
// unmarked here and is marked when that chat drains it.
|
|
778
|
+
const takenBefore = alreadyDelivered(entry, SELF_TAG);
|
|
772
779
|
if (matchesSession(entry, SELF_TAG))
|
|
773
780
|
markDelivered(entry, SELF_TAG);
|
|
781
|
+
if (takenBefore) {
|
|
782
|
+
inboxQueue.push(entry);
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
774
785
|
if (entry.origin === "telegram")
|
|
775
786
|
noteTelegramInbound(entry.messageId, entry.chatId, Date.parse(entry.ts));
|
|
776
787
|
handOver(entry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.344",
|
|
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",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"sync-shared": "node -e \"require((process.env.BULLSEYE_SHARED||require('os').homedir()+'/Desktop/BullseyeShared')+'/git-bash/gitBash.js').run(process.argv.slice(1))\" sync-shared.sh",
|
|
16
16
|
"prebuild": "npm run sync-shared",
|
|
17
|
-
"build": "tsc && node -e \"require('fs').copyFileSync('src/shared/webhost/package.json','dist/shared/webhost/package.json')\"",
|
|
17
|
+
"build": "tsc && node -e \"require('fs').copyFileSync('src/shared/webhost/package.json','dist/shared/webhost/package.json');require('fs').copyFileSync('src/gateway/opencodeEvents.mjs','dist/gateway/opencodeEvents.mjs')\"",
|
|
18
18
|
"build:extension": "node vscode-extension/esbuild.js",
|
|
19
19
|
"start": "node dist/daemon.js",
|
|
20
20
|
"test": "npm run build && npm run build:extension && node tests/run-tests.js",
|
|
File without changes
|