omni-notify-mcp 1.3.481 → 1.3.483
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 +42 -8
- package/dist/gateway/panel.js +6 -1
- package/dist/messaging/storyTopics.js +78 -55
- package/dist/notify.js +80 -21
- package/dist/shared/agentSession.js +54 -317
- package/dist/shared/conversation/agentReaper.js +1 -1
- package/dist/shared/webhost/autoSwitch.cjs +28 -10
- package/package.json +1 -1
package/dist/agentGateway.js
CHANGED
|
@@ -123,6 +123,17 @@ export const SLACK_DM = "slack:dm:";
|
|
|
123
123
|
function carriageOf(platform, key) {
|
|
124
124
|
return key.startsWith(SLACK_DM) ? ONE : CARRIAGE[platform];
|
|
125
125
|
}
|
|
126
|
+
/** The turns a conversation hands the one replacing it on another provider: his messages and its answers, newest last, each cut to fit. */
|
|
127
|
+
const CARRIED_TURNS = 8;
|
|
128
|
+
const CARRIED_CHARS = 1500;
|
|
129
|
+
function carriedOver(from, to) {
|
|
130
|
+
const said = readEvents(from.id).filter((e) => e.role === "user" || e.kind === "answer").slice(-CARRIED_TURNS);
|
|
131
|
+
if (said.length === 0)
|
|
132
|
+
return undefined;
|
|
133
|
+
// A stored message of his ends with his own words (the brief and context ride before them), so the end of each turn is what is kept.
|
|
134
|
+
const lines = said.map((e) => `${e.role === "user" ? "He said" : `${from.provider} answered`}: ${e.text.length > CARRIED_CHARS ? `(cut)… ${e.text.slice(-CARRIED_CHARS)}` : e.text}`);
|
|
135
|
+
return `(BN: he switched this chat from ${from.provider} to ${to}. This conversation goes on from the one ${from.provider} held — its latest turns, read them as this chat's history:\n${lines.join("\n\n")})`;
|
|
136
|
+
}
|
|
126
137
|
const COMMAND_RE = /^\/?(new|stop)(@\w+)?$/i;
|
|
127
138
|
const FINAL_KINDS = new Set(["answer", "failed", "stopped", "archived", "deleted"]);
|
|
128
139
|
export class AgentGateway {
|
|
@@ -261,17 +272,35 @@ export class AgentGateway {
|
|
|
261
272
|
this.end(c.id);
|
|
262
273
|
return reply(carriage.stopped(stopped, carriage.allOf(key).filter((c) => !stopped.includes(c)).length));
|
|
263
274
|
}
|
|
264
|
-
if (act.kind === "new")
|
|
265
|
-
|
|
275
|
+
if (act.kind === "new") {
|
|
276
|
+
try {
|
|
277
|
+
return reply(await carriage.renew(key, platform, (id) => this.end(id), act.provider));
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
if (!(err instanceof GatewayError))
|
|
281
|
+
throw err;
|
|
282
|
+
// OWNER: the message is the trigger root — a fresh conversation the gateway refused (its CLI does not answer, no subscription has room) is answered to the chat with the reason, never silence.
|
|
283
|
+
return reply(`❌ NOT STARTED — ${err.message}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
266
286
|
if (act.text === "")
|
|
267
287
|
return reply("Send `! <your message>` to talk to the agent.");
|
|
268
288
|
const replaced = open !== undefined && act.provider !== undefined && open.provider !== act.provider;
|
|
269
|
-
|
|
289
|
+
// #4671 — a provider switch keeps the thread: the conversation it replaces hands its latest turns to the new one, so nothing said is lost.
|
|
290
|
+
const carried = replaced ? carriedOver(open, act.provider) : undefined;
|
|
291
|
+
// The conversations it replaces end only once the new one is made: a provider that refuses leaves the chat on the one it had, every turn kept.
|
|
292
|
+
const retire = () => {
|
|
293
|
+
if (!replaced)
|
|
294
|
+
return;
|
|
270
295
|
for (const c of carriage.allOf(key)) {
|
|
271
296
|
this.end(c.id);
|
|
272
297
|
archiveConversation(c.id);
|
|
273
298
|
}
|
|
274
|
-
}
|
|
299
|
+
};
|
|
300
|
+
// The one chat's brief rides the first turn of a conversation; the replacing one has had none, so it is given it with the turns carried over.
|
|
301
|
+
// NULL-OK: field carried is OPTIONAL and therefore it is ok to check for NULL
|
|
302
|
+
const said = carried === undefined ? act.text : [...(carriage === ONE ? [chatBrief(key.startsWith(SLACK_DM) ? "Slack" : "Telegram")] : []), carried, act.text].join("\n\n");
|
|
303
|
+
const switched = (id) => (replaced ? [this.told(id, 1, `🔀 Switched from ${open.provider} to ${act.provider} — the conversation goes on there, its last turns carried over.`)] : []);
|
|
275
304
|
const target = replaced ? undefined : carriage.routeOf(key, act.text);
|
|
276
305
|
const forkOf = replaced ? undefined : carriage.forkOf(key);
|
|
277
306
|
// NULL-OK: field target is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -293,8 +322,9 @@ export class AgentGateway {
|
|
|
293
322
|
// NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
|
|
294
323
|
const provider = forkOf !== undefined ? open.provider : act.kind === "say" ? act.provider : undefined;
|
|
295
324
|
const [creation] = await Promise.allSettled([createdIn(project, provider, () => key, (on) => {
|
|
296
|
-
|
|
297
|
-
const
|
|
325
|
+
retire();
|
|
326
|
+
const created = startConversation({ platform, chat: key, slack, email: origin.email, ...on, forkOf, text: said, receivedMs: monotonicMs() - arrived });
|
|
327
|
+
const answered = this.awaitTurn(created.id, 1, relayOf(created.id, 1, false, forkOf !== undefined), switched(created.id));
|
|
298
328
|
// NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
|
|
299
329
|
turn.answered = forkOf === undefined ? answered : answered.finally(() => this.end(created.id));
|
|
300
330
|
turn.id = created.id;
|
|
@@ -302,8 +332,12 @@ export class AgentGateway {
|
|
|
302
332
|
})]);
|
|
303
333
|
if (creation.status === "rejected") {
|
|
304
334
|
// NULL-OK: field id is OPTIONAL and therefore it is ok to check for NULL
|
|
305
|
-
if (turn.id === undefined)
|
|
306
|
-
|
|
335
|
+
if (turn.id === undefined) {
|
|
336
|
+
if (!(creation.reason instanceof GatewayError))
|
|
337
|
+
throw creation.reason;
|
|
338
|
+
// OWNER: the message is the trigger root — a conversation the gateway refused to start (the named CLI does not answer, no subscription has room, the other owner holds it) is answered to the chat with the reason, never thrown past the poll loop into silence.
|
|
339
|
+
return reply(replaced ? `❌ NOT SWITCHED to ${act.provider} — ${creation.reason.message}\nThis chat stays on ${open.provider}, everything said in it kept, until ${act.provider} answers or another provider is chosen. This message was not sent: send it again then.` : `❌ NOT STARTED — ${creation.reason.message}\nThis message was not sent: send it again once a provider answers.`);
|
|
340
|
+
}
|
|
307
341
|
const reason = creation.reason instanceof Error ? creation.reason.message : String(creation.reason);
|
|
308
342
|
process.stderr.write(`[agent-gateway] conversation ${turn.id.slice(0, 8)}: the unread-room notice could not be written (${reason}); the turn runs on and its answer is delivered\n`);
|
|
309
343
|
this.deliver(this.told(turn.id, 1, `⚠️ No CLI was named and DeepAgent's subscription room could not be read; that notice could not be written to this conversation: ${reason}`));
|
package/dist/gateway/panel.js
CHANGED
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
import { createHash } from "crypto";
|
|
8
8
|
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
9
9
|
import { dirname, join } from "path";
|
|
10
|
-
import { CONFIG_DIR, deliveryReport, isDndActive } from "../notify.js";
|
|
10
|
+
import { CHAT_PROVIDERS, CONFIG_DIR, deliveryReport, isDndActive } from "../notify.js";
|
|
11
11
|
import { MESSENGER_SETUPS } from "../messaging/setup.js";
|
|
12
12
|
import { extensionModule } from "./extensionModule.js";
|
|
13
13
|
import { GatewayError, conversationEnabled, setConversationEnabled, writeRecordFile } from "./conversationOwner.js";
|
|
14
14
|
import { TELEGRAM_PARSE_MODES } from "../messaging/telegramFormat.js";
|
|
15
15
|
const channelReading = () => extensionModule("channelReading.cjs");
|
|
16
16
|
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
17
|
+
/** #4617 — the agent CLI a one chat runs on: auto is the subscription-first pick; /provider in the chat writes the same field. */
|
|
18
|
+
const CHAT_PROVIDER_CHOICES = ["auto", ...CHAT_PROVIDERS];
|
|
19
|
+
const chatProviderRow = (chat) => ({ path: [chat, "provider"], label: "Agent provider", kind: "choice", choices: CHAT_PROVIDER_CHOICES, fallback: "auto", hint: "The agent CLI this chat's conversation runs on. auto (default) takes the subscription with room first. Changing it switches the open conversation on its next message, its latest turns carried over; /provider in the chat reads and changes it too." });
|
|
17
20
|
// Every config field the notify server reads, one editable row each. A field the server no longer reads is not listed: a control for it would change nothing.
|
|
18
21
|
export const SETTINGS = [
|
|
19
22
|
{ title: "🔕 Master", rows: [
|
|
@@ -29,6 +32,7 @@ export const SETTINGS = [
|
|
|
29
32
|
{ path: ["telegram", "enabled"], label: "Enabled", kind: "toggle" },
|
|
30
33
|
{ path: ["telegram", "token"], label: "Bot token", kind: "secret", hint: "From @BotFather after /newbot, shaped like 123456:ABC-DEF... Pasting it switches Telegram on; the first message you send the bot binds your chat." },
|
|
31
34
|
{ path: ["telegram", "parseMode"], label: "Formatting", kind: "choice", choices: TELEGRAM_PARSE_MODES, fallback: "HTML", hint: "HTML (default) turns an agent's markdown bold, italics, code, links and bullets into Telegram formatting. MarkdownV2 sends the text as written for Telegram's own markdown. none sends plain text." },
|
|
35
|
+
chatProviderRow("telegram"),
|
|
32
36
|
] },
|
|
33
37
|
{ guide: { summary: "Connect Slack", steps: ["Go to api.slack.com/apps, open your app (or Create New App).", "Easiest: Incoming Webhooks, Add New Webhook to Workspace, pick the channel, copy the URL into Webhook URL.", "Or: OAuth & Permissions, add the chat:write scope, install the app, copy the Bot User OAuth Token (xoxb-), invite the bot to the channel, and list the channel id.", "Switch Enabled to On."], need: [["slack.botToken", "slack.webhookUrl"]] }, messenger: "slack", title: "💬 Slack", rows: [
|
|
34
38
|
{ path: ["slack", "enabled"], label: "Enabled", kind: "toggle" },
|
|
@@ -38,6 +42,7 @@ export const SETTINGS = [
|
|
|
38
42
|
{ path: ["slack", "configRefreshToken"], label: "Configuration refresh token", kind: "secret", hint: "Generated with the configuration token. BN renews the 12-hour token with it, so setup keeps working." },
|
|
39
43
|
{ path: ["slack", "channels"], label: "Channels (comma-separated)", kind: "list", hint: "Channel ids like C0123ABCD (Slack: channel name, View channel details, bottom of the About tab). Invite the bot to each channel first." },
|
|
40
44
|
{ path: ["slack", "webhookUrl"], label: "Webhook URL", kind: "secret", hint: "Simplest option: https://hooks.slack.com/services/... from your app, Incoming Webhooks, Add New Webhook to Workspace." },
|
|
45
|
+
chatProviderRow("slack"),
|
|
41
46
|
] },
|
|
42
47
|
{ guide: { summary: "AWS End User Messaging credentials", steps: ["AWS Console, IAM: create a user allowed `sms-voice:SendTextMessage`; copy its Access Key ID and Secret.", "AWS End User Messaging, Phone numbers, request a number; it becomes your From number.", "Paste the key, secret, region and From number below, then add recipients under Send to.", "Switch Enabled to On."], need: [["sms.accessKeyId"], ["sms.secretAccessKey"], ["sms.region"], ["sms.originationNumber"], ["sms.to"]] }, title: "📱 SMS (AWS)", rows: [
|
|
43
48
|
{ path: ["sms", "enabled"], label: "Enabled", kind: "toggle" },
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
2
2
|
import { dirname } from "path";
|
|
3
|
-
import { TelegramRefused } from "./messenger.js";
|
|
3
|
+
import { TelegramRefused, TelegramUnreachable } from "./messenger.js";
|
|
4
4
|
/**
|
|
5
5
|
* #4586 — one Telegram topic per story inside the one bound chat. BN creates a story's topic (createForumTopic, which Bot API 9.3+ allows
|
|
6
6
|
* in a private chat with topic mode on), sends that story's messages into it (message_thread_id), reads a message he writes inside a topic
|
|
7
|
-
* as that story's, and closes the topic when the story ships. A chat that refuses topics keeps the plain chat: nothing here ever blocks a send
|
|
7
|
+
* as that story's, and closes the topic when the story ships. A chat that refuses topics keeps the plain chat: nothing here ever blocks a send,
|
|
8
|
+
* and every refusal or store write that fails is said on BN's console trail (#4660), never silently.
|
|
8
9
|
*/
|
|
9
10
|
/** The story a message is about: its board decision link names it, else its headline does ("#4123 ..." / "Story #4123"); undefined for a plain message. */
|
|
10
11
|
export function storyOfMessage(text) {
|
|
@@ -22,86 +23,109 @@ export function shippedStory(text) {
|
|
|
22
23
|
}
|
|
23
24
|
export class StoryTopics {
|
|
24
25
|
file;
|
|
25
|
-
|
|
26
|
+
trail;
|
|
27
|
+
data;
|
|
26
28
|
/** Chats Telegram refused a topic in, until when: the plain chat is the whole path there meanwhile. */
|
|
27
29
|
refused = new Map();
|
|
28
|
-
|
|
30
|
+
/** Topics this process forgot (Telegram no longer has them): a merge never brings them back from this process's own older copy. */
|
|
31
|
+
forgotten = new Map();
|
|
32
|
+
constructor(file, trail) {
|
|
29
33
|
this.file = file;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
34
|
+
this.trail = trail;
|
|
35
|
+
this.data = this.onDisk();
|
|
36
|
+
}
|
|
37
|
+
/** The store as another process (a build handing over) may have left it: none yet is empty, an unreadable one is said on the trail and read as empty. */
|
|
38
|
+
onDisk() {
|
|
39
|
+
if (!existsSync(this.file))
|
|
40
|
+
return {};
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(readFileSync(this.file, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
// OWNER: the topic store is a routing aid, never a send's gate — an unreadable store is said on the trail and read as empty, so the plain chat or a fresh topic carries the message.
|
|
46
|
+
this.trail(`topic store ${this.file} unreadable, read as empty: ${err instanceof Error ? err.message : String(err)}`);
|
|
47
|
+
return {};
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
/** One change, written read-merge-write so another process's entries are never dropped (#4733); a write that fails keeps the change in memory and is said on the trail (#4744). */
|
|
51
|
+
persist(change) {
|
|
52
|
+
const disk = this.onDisk();
|
|
53
|
+
const merged = { ...disk, ...this.data };
|
|
54
|
+
// A topic another process closed stays closed here too; one this process forgot is never written back from its old copy.
|
|
55
|
+
for (const [key, t] of Object.entries(disk))
|
|
56
|
+
if (t.closed === true)
|
|
57
|
+
merged[key] = t;
|
|
58
|
+
for (const [key, thread] of this.forgotten)
|
|
59
|
+
if (merged[key]?.thread === thread)
|
|
60
|
+
delete merged[key];
|
|
61
|
+
change(merged);
|
|
62
|
+
this.data = merged;
|
|
41
63
|
try {
|
|
42
|
-
|
|
64
|
+
mkdirSync(dirname(this.file), { recursive: true });
|
|
65
|
+
const staged = `${this.file}.${process.pid}.tmp`;
|
|
66
|
+
writeFileSync(staged, JSON.stringify(merged, null, 2));
|
|
67
|
+
renameSync(staged, this.file);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// OWNER: a topic note that cannot be written must not cost the message its send — the change holds in memory for this process and the failure is said on the trail.
|
|
71
|
+
this.trail(`topic store ${this.file} not written, the change holds only in this process: ${err instanceof Error ? err.message : String(err)}`);
|
|
43
72
|
}
|
|
44
|
-
catch { /* no store yet */ }
|
|
45
|
-
mkdirSync(dirname(this.file), { recursive: true });
|
|
46
|
-
const staged = `${this.file}.tmp`;
|
|
47
|
-
writeFileSync(staged, JSON.stringify(this.data, null, 2));
|
|
48
|
-
renameSync(staged, this.file);
|
|
49
73
|
}
|
|
50
74
|
/** The open topic of a story in a chat, if BN made one. */
|
|
51
75
|
threadOf(chat, story) {
|
|
52
76
|
const t = this.data[`${chat}:${story}`];
|
|
53
77
|
return t === undefined || t.closed === true ? undefined : t.thread;
|
|
54
78
|
}
|
|
55
|
-
/** The story a topic (thread) of a chat belongs to. */
|
|
79
|
+
/** The story a topic (thread) of a chat belongs to — a closed one's too, so his late message in it is still read as that story's. */
|
|
56
80
|
storyOf(chat, thread) {
|
|
57
81
|
for (const [key, t] of Object.entries(this.data))
|
|
58
82
|
if (key.startsWith(`${chat}:`) && t.thread === thread)
|
|
59
83
|
return Number(key.slice(chat.length + 1));
|
|
60
84
|
return undefined;
|
|
61
85
|
}
|
|
62
|
-
/** The story's topic, created on first use; undefined when this chat cannot hold topics (the caller then sends to the plain chat). */
|
|
86
|
+
/** The story's topic, created on first use; undefined when this chat cannot hold topics or the story's topic is closed (the caller then sends to the plain chat). */
|
|
63
87
|
async ensure(api, chat, story, name) {
|
|
64
88
|
const known = this.threadOf(chat, story);
|
|
65
89
|
if (known !== undefined)
|
|
66
90
|
return known;
|
|
67
|
-
// A
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Reopened so the message is never sent into a closed topic; a ship notice closes it again after.
|
|
71
|
-
try {
|
|
72
|
-
await api.call("reopenForumTopic", { chat_id: chat, message_thread_id: closed.thread });
|
|
73
|
-
closed.closed = false;
|
|
74
|
-
this.save();
|
|
75
|
-
}
|
|
76
|
-
catch { /* a topic that cannot be reopened is still tried: the sender falls back to the plain chat on a refusal */ }
|
|
77
|
-
return closed.thread;
|
|
78
|
-
}
|
|
91
|
+
// A shipped story's topic stays closed: a later message naming it goes to the plain chat, never reopening it or making a second one (#4725).
|
|
92
|
+
if (this.data[`${chat}:${story}`] !== undefined)
|
|
93
|
+
return undefined;
|
|
79
94
|
if ((this.refused.get(chat) ?? 0) > Date.now())
|
|
80
95
|
return undefined;
|
|
96
|
+
let made;
|
|
81
97
|
try {
|
|
82
|
-
|
|
83
|
-
const thread = Number(made?.message_thread_id);
|
|
84
|
-
if (!Number.isInteger(thread)) {
|
|
85
|
-
this.refused.set(chat, Date.now() + 600_000);
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
this.data[`${chat}:${story}`] = { thread };
|
|
89
|
-
this.save();
|
|
90
|
-
return thread;
|
|
98
|
+
made = await api.call("createForumTopic", { chat_id: chat, name: name.slice(0, 128) });
|
|
91
99
|
}
|
|
92
100
|
catch (err) {
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
if (!(err instanceof TelegramRefused) && !(err instanceof TelegramUnreachable))
|
|
102
|
+
throw err;
|
|
103
|
+
// OWNER: ITER/LOOP — a topic Telegram will not make costs this message only its topic: the plain chat carries it and why is said on the trail (#4660). Only Telegram's own refusal pauses topics; a network failure or a 429 is no verdict on the chat.
|
|
104
|
+
const pauses = err instanceof TelegramRefused && err.status !== 429;
|
|
105
|
+
if (pauses)
|
|
95
106
|
this.refused.set(chat, Date.now() + 600_000);
|
|
107
|
+
this.trail(`topic for #${story} REFUSED in chat ${chat}: ${err.message}; the plain chat carries it${pauses ? ", topics paused 10 min" : ""}`);
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const thread = Number(made?.message_thread_id);
|
|
111
|
+
if (!Number.isInteger(thread)) {
|
|
112
|
+
this.refused.set(chat, Date.now() + 600_000);
|
|
113
|
+
this.trail(`topic for #${story} NOT made in chat ${chat}: createForumTopic answered no message_thread_id (${JSON.stringify(made)}); the plain chat carries it, topics paused 10 min`);
|
|
96
114
|
return undefined;
|
|
97
115
|
}
|
|
116
|
+
this.forgotten.delete(`${chat}:${story}`);
|
|
117
|
+
this.persist((store) => { store[`${chat}:${story}`] = { thread }; });
|
|
118
|
+
this.trail(`topic ${thread} made for #${story} in chat ${chat}`);
|
|
119
|
+
return thread;
|
|
98
120
|
}
|
|
99
121
|
/** A topic Telegram no longer has (he deleted it): forgotten, so the next message makes a fresh one and nothing keeps failing. */
|
|
100
122
|
forget(chat, story) {
|
|
101
|
-
|
|
123
|
+
const key = `${chat}:${story}`;
|
|
124
|
+
if (this.data[key] === undefined)
|
|
102
125
|
return;
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
this.forgotten.set(key, this.data[key].thread);
|
|
127
|
+
this.persist((store) => { delete store[key]; });
|
|
128
|
+
this.trail(`topic of #${story} in chat ${chat} is gone from Telegram: forgotten, the next message makes a fresh one`);
|
|
105
129
|
}
|
|
106
130
|
/** Closes a story's topic once it ships; the mapping stays so his late message in it is still read as that story's. */
|
|
107
131
|
async close(api, chat, story) {
|
|
@@ -111,16 +135,15 @@ export class StoryTopics {
|
|
|
111
135
|
try {
|
|
112
136
|
await api.call("closeForumTopic", { chat_id: chat, message_thread_id: t.thread });
|
|
113
137
|
}
|
|
114
|
-
catch {
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (!(err instanceof TelegramRefused) && !(err instanceof TelegramUnreachable))
|
|
140
|
+
throw err;
|
|
141
|
+
// OWNER: the ship notice already went out; a topic Telegram will not close stays open and why is said on the trail.
|
|
142
|
+
this.trail(`topic ${t.thread} of #${story} NOT closed in chat ${chat}: ${err.message}`);
|
|
115
143
|
return false;
|
|
116
144
|
}
|
|
117
|
-
t.closed
|
|
118
|
-
|
|
119
|
-
this.save();
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
// The topic is closed in Telegram, and so it stays in memory; only the note of it could not be written (the file is held).
|
|
123
|
-
}
|
|
145
|
+
this.persist((store) => { store[`${chat}:${story}`] = { thread: t.thread, closed: true }; });
|
|
146
|
+
this.trail(`topic ${t.thread} of #${story} closed in chat ${chat}: its story shipped`);
|
|
124
147
|
return true;
|
|
125
148
|
}
|
|
126
149
|
}
|
package/dist/notify.js
CHANGED
|
@@ -495,7 +495,8 @@ async function sendNotification(message, priority, client, buttons, topic) {
|
|
|
495
495
|
({ response: r, unformatted: plain } = await postTelegramMessage(tgApi(cfg.telegram.token, "sendMessage"), body, mode));
|
|
496
496
|
}
|
|
497
497
|
else if (r.ok && thread !== undefined && topic !== undefined && topic.ships) {
|
|
498
|
-
|
|
498
|
+
// OWNER: ITER/LOOP — the ship notice is delivered; an undocumented answer to the close is logged whole, the topic stays open.
|
|
499
|
+
void storyTopics.close(topicCalls(cfg.telegram.token), chatId, topic.story).catch((err) => log("·", "telegram:topic", `topic of #${topic.story} NOT closed: ${err instanceof Error ? err.message : String(err)}`));
|
|
499
500
|
}
|
|
500
501
|
if (r.ok) {
|
|
501
502
|
sent++;
|
|
@@ -1185,29 +1186,67 @@ const TELEGRAM_WELCOME = "🔗 This chat is your BN agent now.\n\nWrite anything
|
|
|
1185
1186
|
function boundTelegramChat(chatIds, chat, sender) {
|
|
1186
1187
|
return chatIds.includes(chat) && sender === chat;
|
|
1187
1188
|
}
|
|
1188
|
-
/**
|
|
1189
|
-
function
|
|
1189
|
+
/** One section of config.json changed in place, written as a staged file renamed over it; the caller reads its change back. */
|
|
1190
|
+
function writeConfigSection(name, change) {
|
|
1190
1191
|
const raw = existsSync(CONFIG_PATH) ? JSON.parse(readFileSync(CONFIG_PATH, "utf-8")) : {};
|
|
1191
|
-
|
|
1192
|
+
const section = { ...(raw[name] ?? {}) };
|
|
1193
|
+
change(section);
|
|
1194
|
+
raw[name] = section;
|
|
1192
1195
|
const staged = `${CONFIG_PATH}.${process.pid}.tmp`;
|
|
1193
1196
|
writeFileSync(staged, JSON.stringify(raw, null, 2));
|
|
1194
1197
|
renameSync(staged, CONFIG_PATH);
|
|
1198
|
+
}
|
|
1199
|
+
/** Binds the bot to this private chat, written straight into config.json, and read back. */
|
|
1200
|
+
function bindTelegramChat(chat) {
|
|
1201
|
+
writeConfigSection("telegram", (section) => { section.chatIds = [chat]; });
|
|
1195
1202
|
if (!(loadConfig().telegram?.chatIds ?? []).includes(chat))
|
|
1196
1203
|
throw new Error(`the binding to chat ${chat} did not hold in ${CONFIG_PATH}`);
|
|
1197
1204
|
log("·", "telegram", `this bot is bound to chat ${chat}: every message from it reaches the BN conversation, every other sender is refused`);
|
|
1198
1205
|
}
|
|
1199
|
-
/**
|
|
1200
|
-
const
|
|
1201
|
-
function
|
|
1202
|
-
const named = loadConfig()
|
|
1203
|
-
return typeof named === "string" &&
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
+
/** A one chat runs on the CLI `<platform>.provider` in config.json names, else on the shared subscription-first pick (Claude while its subscription has room, then the next with room; a refusal says why). */
|
|
1207
|
+
export const CHAT_PROVIDERS = ["claude", "codex", "copilot", "opencode"];
|
|
1208
|
+
function chatProvider(platform) {
|
|
1209
|
+
const named = loadConfig()[platform]?.provider;
|
|
1210
|
+
return typeof named === "string" && CHAT_PROVIDERS.includes(named) ? named : undefined;
|
|
1211
|
+
}
|
|
1212
|
+
/** The `/provider` command of a one chat (#4617, #4671): bare, it reads the provider and the choices; with a name it switches the chat to it from its next message, the conversation's latest turns carried over; `auto` hands it back to the subscription-first pick. */
|
|
1213
|
+
const PROVIDER_COMMAND = /^\/?provider(?:@\w+)?(?:\s+(\S+))?$/i;
|
|
1214
|
+
function switchChatProvider(platform, name) {
|
|
1215
|
+
const now = chatProvider(platform) ?? "auto (the subscription with room)";
|
|
1216
|
+
const choices = `Choices: ${[...CHAT_PROVIDERS, "auto"].map((p) => `/provider ${p}`).join(" · ")}`;
|
|
1217
|
+
// NULL-OK: field name is OPTIONAL and therefore it is ok to check for NULL
|
|
1206
1218
|
if (name === undefined)
|
|
1207
|
-
return `🤖
|
|
1208
|
-
|
|
1219
|
+
return `🤖 This chat runs on ${now}.\n${choices}\nTo change the subscription or key a provider uses, just ask: the agent switches it with DeepAgent.`;
|
|
1220
|
+
const wanted = name.toLowerCase();
|
|
1221
|
+
if (wanted !== "auto" && !CHAT_PROVIDERS.includes(wanted))
|
|
1222
|
+
return `❌ No provider called "${name}". ${choices}`;
|
|
1223
|
+
writeConfigSection(platform, (section) => {
|
|
1224
|
+
if (wanted === "auto")
|
|
1225
|
+
delete section.provider;
|
|
1226
|
+
else
|
|
1227
|
+
section.provider = wanted;
|
|
1228
|
+
});
|
|
1229
|
+
const held = chatProvider(platform);
|
|
1230
|
+
if ((wanted === "auto" ? undefined : wanted) !== held)
|
|
1231
|
+
throw new Error(`${platform}.provider=${wanted} did not hold in ${CONFIG_PATH} (it reads ${held ?? "auto"})`);
|
|
1232
|
+
log("·", platform, `provider for this chat set to ${wanted}`);
|
|
1233
|
+
return wanted === "auto"
|
|
1234
|
+
? "✅ Auto: a new conversation takes the subscription with room first; the one open now stays on its provider until /new."
|
|
1235
|
+
: `✅ ${wanted} from your next message — this conversation goes on there with its latest turns carried over.`;
|
|
1236
|
+
}
|
|
1237
|
+
/** His /provider answered in the chat it came from: the switch, or why it did not happen — never silence. */
|
|
1238
|
+
function providerAnswer(platform, name) {
|
|
1239
|
+
try {
|
|
1240
|
+
return switchChatProvider(platform, name);
|
|
1241
|
+
}
|
|
1242
|
+
catch (err) {
|
|
1243
|
+
// OWNER: the message is the trigger root — a provider choice that could not be written is answered in his chat with the reason and logged; the chat keeps its provider.
|
|
1244
|
+
const why = err instanceof Error ? err.message : String(err);
|
|
1245
|
+
log("·", platform, `provider NOT switched: ${why}`);
|
|
1246
|
+
return `❌ NOT SWITCHED — ${why}. This chat keeps ${chatProvider(platform) ?? "auto"}.`;
|
|
1247
|
+
}
|
|
1209
1248
|
}
|
|
1210
|
-
const storyTopics = new StoryTopics(join(CONFIG_DIR, "story-topics.json"));
|
|
1249
|
+
const storyTopics = new StoryTopics(join(CONFIG_DIR, "story-topics.json"), (line) => log("·", "telegram:topic", line));
|
|
1211
1250
|
const topicCalls = (token) => ({ call: (method, body) => telegramCall(tgApi(token, method), method, body) });
|
|
1212
1251
|
function topicOfMessage(text) {
|
|
1213
1252
|
const story = storyOfMessage(text);
|
|
@@ -1241,14 +1280,15 @@ function openAsksContext() {
|
|
|
1241
1280
|
/** One said thing of the bound chat goes to its one conversation, its turn streamed back into the chat. */
|
|
1242
1281
|
function toTelegramConversation(token, chat, act, thread, replyTo) {
|
|
1243
1282
|
// #4586 — a topic is its own conversation (the story's); the plain chat keeps its one.
|
|
1244
|
-
|
|
1245
|
-
toOneChat(thread === undefined ? `telegram:${chat}` : `telegram:${chat}:${thread}`, "telegram", routed, telegramMessenger(token, chat, thread, replyTo));
|
|
1283
|
+
toOneChat(thread === undefined ? `telegram:${chat}` : `telegram:${chat}:${thread}`, "telegram", act, telegramMessenger(token, chat, thread, replyTo));
|
|
1246
1284
|
}
|
|
1247
|
-
/** One said thing of one of Meni's one chats — Telegram, or his Slack direct message — goes to its one conversation, its turn streamed back into that chat. */
|
|
1285
|
+
/** One said thing of one of Meni's one chats — Telegram, or his Slack direct message — goes to its one conversation on the provider that chat runs on, its turn streamed back into that chat. */
|
|
1248
1286
|
function toOneChat(key, platform, act, messenger) {
|
|
1249
1287
|
const trail = `agent:${platform}`;
|
|
1288
|
+
// #4671 — every act but a stop carries the chat's provider, so a message, a tapped choice and /new all start on the one /provider chose.
|
|
1289
|
+
const routed = act.kind === "stop" ? act : { ...act, provider: chatProvider(platform) };
|
|
1250
1290
|
// OWNER: ITER/LOOP — the agent's answer outlives this message; the conversation reports its own failure into the chat, and a send that fails is logged here.
|
|
1251
|
-
void AgentGateway.instance().handle(key, platform,
|
|
1291
|
+
void AgentGateway.instance().handle(key, platform, routed, streamedChat(messenger, (line) => log("→", trail, line))).catch((err) => {
|
|
1252
1292
|
log("→", trail, `NOT DELIVERED to ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1253
1293
|
});
|
|
1254
1294
|
}
|
|
@@ -1307,9 +1347,9 @@ async function takeTelegramUpdate(token, update) {
|
|
|
1307
1347
|
await messenger.send(TELEGRAM_WELCOME);
|
|
1308
1348
|
return;
|
|
1309
1349
|
}
|
|
1310
|
-
const providerCmd = text.trim().match(
|
|
1350
|
+
const providerCmd = text.trim().match(PROVIDER_COMMAND);
|
|
1311
1351
|
if (providerCmd !== null) {
|
|
1312
|
-
await messenger.send(
|
|
1352
|
+
await messenger.send(providerAnswer("telegram", providerCmd[1]));
|
|
1313
1353
|
return;
|
|
1314
1354
|
}
|
|
1315
1355
|
// #4494 — a digit he replied to a board decision message with is that decision's pick, and #4123 other words its answer, whatever else waits on him.
|
|
@@ -2370,6 +2410,12 @@ function takeSlackDmMessage(dm, owner, m, threadTs) {
|
|
|
2370
2410
|
// NULL-OK: field picked is OPTIONAL and therefore it is ok to check for NULL
|
|
2371
2411
|
if (picked !== undefined)
|
|
2372
2412
|
return toOneChat(key, "slack", { kind: "say", text: chatTurnText(key, picked, [`He picked this choice on your last question: «${picked}»`, ...openAsksContext()]) }, view);
|
|
2413
|
+
const providerCmd = text.trim().match(PROVIDER_COMMAND);
|
|
2414
|
+
if (providerCmd !== null) {
|
|
2415
|
+
// OWNER: ITER/LOOP — the answer to his /provider goes back into the chat it came from; a send Slack refuses is logged and the next message is read.
|
|
2416
|
+
void view.send(providerAnswer("slack", providerCmd[1])).catch((err) => log("→", "agent:slack", `the /provider answer was not delivered: ${err instanceof Error ? err.message : String(err)}`));
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2373
2419
|
const act = AgentGateway.instance().classifyChat(text, true);
|
|
2374
2420
|
toOneChat(key, "slack", act.kind === "say" ? { kind: "say", text: chatTurnText(key, act.text, openAsksContext()) } : act, view);
|
|
2375
2421
|
}
|
|
@@ -3331,12 +3377,25 @@ export function createMcpServer(clientId, sessionTag) {
|
|
|
3331
3377
|
const askPrefix = `❓ [${clientId}]`;
|
|
3332
3378
|
const replyHint = "\n\nTap an answer, reply to this message, or just tell BN in your own words.";
|
|
3333
3379
|
const reply_markup = options.length === 0 ? undefined : { inline_keyboard: options.map((label, i) => [{ text: label, callback_data: `q|${short}|${i}` }]) };
|
|
3380
|
+
// #4711 (folded into #4671) — a question about a story goes into that story's topic, as its notifications do.
|
|
3381
|
+
const askTopic = topicOfMessage(question);
|
|
3334
3382
|
for (const chatId of cfg.telegram.chatIds) {
|
|
3383
|
+
// NULL-OK: field askTopic is OPTIONAL and therefore it is ok to check for NULL
|
|
3384
|
+
const thread = askTopic === undefined ? undefined : await storyThreadFor(cfg.telegram.token, chatId, askTopic);
|
|
3385
|
+
const body = { chat_id: chatId, text: `${askPrefix} ${question}${replyHint}`, reply_markup, ...(thread === undefined ? {} : { message_thread_id: thread }) };
|
|
3335
3386
|
// A non-2xx Telegram response does NOT reject this fetch — only a
|
|
3336
3387
|
// network-level failure does — so this used to silently do nothing
|
|
3337
3388
|
// on e.g. a revoked token: no error, no log line, just a question
|
|
3338
3389
|
// the user never saw and no clue why. Story #443: check r.ok too.
|
|
3339
|
-
await postTelegramMessage(tgApi(cfg.telegram.token, "sendMessage"),
|
|
3390
|
+
await postTelegramMessage(tgApi(cfg.telegram.token, "sendMessage"), body, telegramParseMode(cfg))
|
|
3391
|
+
.then(async (sent) => {
|
|
3392
|
+
// NULL-OK: field thread is OPTIONAL and therefore it is ok to check for NULL
|
|
3393
|
+
if (sent.response.ok || thread === undefined || sent.response.status !== 400 || !/thread not found|TOPIC_DELETED|TOPIC_CLOSED/i.test(await sent.response.clone().text()))
|
|
3394
|
+
return sent;
|
|
3395
|
+
// The topic is gone or closed: the question goes to the plain chat, never lost to a topic.
|
|
3396
|
+
const { message_thread_id: _gone, ...plain } = body;
|
|
3397
|
+
return postTelegramMessage(tgApi(cfg.telegram.token, "sendMessage"), plain, telegramParseMode(cfg));
|
|
3398
|
+
})
|
|
3340
3399
|
.then(async ({ response: r, unformatted }) => {
|
|
3341
3400
|
if (r.ok) {
|
|
3342
3401
|
telegramSent = true;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
-
import
|
|
3
|
+
import fs from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { Agent } from "node:http";
|
|
6
|
-
import
|
|
6
|
+
import net from "node:net";
|
|
7
7
|
import { homedir, tmpdir } from "node:os";
|
|
8
|
-
import
|
|
8
|
+
import path from "node:path";
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
import { Duplex } from "node:stream";
|
|
12
12
|
import { Worker } from "node:worker_threads";
|
|
13
13
|
import { CLUSTER_OWNER, OwnershipUnreadable, startOwnerOf } from "./providerOwnership.js";
|
|
14
|
-
import { AutoStartUnread,
|
|
14
|
+
import { AutoStartUnread, sameRoot, savedAutoStart, workspacesHere } from "./workspaceList.js";
|
|
15
15
|
export function isProcessAlive(pid) {
|
|
16
16
|
try {
|
|
17
17
|
process.kill(pid, 0);
|
|
@@ -2983,7 +2983,6 @@ export const blockedAct = (worker) => (worker.needs === undefined ? "an act its
|
|
|
2983
2983
|
export function workerRunner(worker) {
|
|
2984
2984
|
return worker.blocked === true ? `${worker.provider} worker, stopped until it gets ${blockedAct(worker)}` : `${worker.provider} worker`;
|
|
2985
2985
|
}
|
|
2986
|
-
const STOP_AUTHOR_WORDS = { press: "his ⏸ Stop press", emergency: "emergency stop of every board, not his press", caller: "a caller of the stop verb, not his press" };
|
|
2987
2986
|
export const storyQueueDir = (board) => path.join(board, ".fleetview", "queue");
|
|
2988
2987
|
/** 🔴 #4595 — the folders the deleted hand-over wrote beside the queue (BullseyeBacklog's requests, FleetView's acks): a pass removes any it finds. */
|
|
2989
2988
|
const handOverDirs = (board) => ["requests", "acks"].map((d) => path.join(storyQueueDir(board), d));
|
|
@@ -3130,7 +3129,7 @@ function derived(fields, now) {
|
|
|
3130
3129
|
}
|
|
3131
3130
|
/**
|
|
3132
3131
|
* 🔴 #4595 — FLEETVIEW'S OWN DECISION OF WHAT STARTS, made on every pass from the board's startable read: a story his press stands on is
|
|
3133
|
-
* eligible as his press unless the board refuses a press of it;
|
|
3132
|
+
* eligible as his press unless the board refuses a press of it; with this board's AUTO START on, every
|
|
3134
3133
|
* story the board lets AUTO START start is eligible as AUTO START's; everything else is ineligible with the one reason. An entry the line
|
|
3135
3134
|
* still holds for a story the read no longer lists is asked out in the board's words, and the presses and removals of such a story are
|
|
3136
3135
|
* dropped with it. A read the board could not give derives nothing, so nothing is withdrawn on a failed read.
|
|
@@ -3138,20 +3137,11 @@ function derived(fields, now) {
|
|
|
3138
3137
|
export function boardRequests(board, store, reading, now, closedWhy) {
|
|
3139
3138
|
if ("unread" in reading)
|
|
3140
3139
|
return [];
|
|
3141
|
-
carryOldRemoves(store);
|
|
3142
3140
|
const held = autoStartHeld(board);
|
|
3143
|
-
// the turn-on time is read only while AUTO START reads on, so a file the hold above already named unreadable never stops the pass
|
|
3144
|
-
const onAt = held === undefined ? autoStartOnAt(board) : undefined;
|
|
3145
|
-
// NULL-OK: field onAt is OPTIONAL and therefore it is ok to check for NULL
|
|
3146
|
-
if (onAt !== undefined && store.removed !== undefined)
|
|
3147
|
-
for (const [key, r] of Object.entries(store.removed))
|
|
3148
|
-
if (r.at < onAt)
|
|
3149
|
-
delete store.removed[key];
|
|
3150
3141
|
const listed = new Set(reading.stories.map((s) => s.storyId));
|
|
3151
3142
|
const requests = reading.stories.map((s) => {
|
|
3152
3143
|
const key = String(s.storyId);
|
|
3153
3144
|
const press = store.presses?.[key];
|
|
3154
|
-
const removed = store.removed?.[key];
|
|
3155
3145
|
const base = { storyId: s.storyId, title: s.title, pri: s.pri, effort: s.effort, name: s.name, ...(s.ruling === undefined ? {} : { ruling: s.ruling }) };
|
|
3156
3146
|
const entry = store.entries.find((x) => x.storyId === s.storyId);
|
|
3157
3147
|
// 🔴 #4762 — with AUTO START off a Start press already spent (its worker ended, or it was withdrawn) never brings its story back into line: only a newer press does
|
|
@@ -3160,14 +3150,13 @@ export function boardRequests(board, store, reading, now, closedWhy) {
|
|
|
3160
3150
|
if (press !== undefined && s.pressRefusal === undefined && !spent) {
|
|
3161
3151
|
return derived({ ...base, brief: briefFor(s, press.by), eligible: true, why: PRESSED_WHY[press.by], origin: originOf(press.by), by: press.by, ...(press.by === "press" ? { pressedAt: press.at } : {}), ...(press.top === true ? { place: "top" } : {}), ...(press.forced === undefined ? {} : { forced: press.forced }) }, now);
|
|
3162
3152
|
}
|
|
3163
|
-
// 🔴 #4811 — an agent's ⚡ Force start is an order to start like his press: eligible on the press refusal alone, never held by AUTO START
|
|
3153
|
+
// 🔴 #4811 — an agent's ⚡ Force start is an order to start like his press: eligible on the press refusal alone, never held by AUTO START or the auto refusal; applyRequest's ahead block starts it as the agent's
|
|
3164
3154
|
const ahead = store.forcesAhead?.[key];
|
|
3165
3155
|
// NULL-OK: field ahead is OPTIONAL and therefore it is ok to check for NULL
|
|
3166
3156
|
if (press === undefined && ahead !== undefined && s.pressRefusal === undefined) {
|
|
3167
3157
|
return derived({ ...base, brief: briefFor(s, "auto"), eligible: true, why: `${ahead.by} ⚡ Force start`, origin: "auto", by: "auto" }, now);
|
|
3168
3158
|
}
|
|
3169
|
-
|
|
3170
|
-
const why = press !== undefined ? (spent ? `${held}; his Start press on it is spent` : s.pressRefusal) : removed !== undefined ? `${removed.by} ✕ Remove took it out of the line — his Start press puts it back` : held ?? s.autoRefusal;
|
|
3159
|
+
const why = press !== undefined ? (spent ? `${held}; his Start press on it is spent` : s.pressRefusal) : held ?? s.autoRefusal;
|
|
3171
3160
|
// NULL-OK: field why is OPTIONAL and therefore it is ok to check for NULL
|
|
3172
3161
|
return derived({ ...base, brief: briefFor(s, "auto"), eligible: why === undefined, why: why ?? "ready on the board", origin: "auto", by: "auto" }, now);
|
|
3173
3162
|
});
|
|
@@ -3177,8 +3166,8 @@ export function boardRequests(board, store, reading, now, closedWhy) {
|
|
|
3177
3166
|
continue;
|
|
3178
3167
|
requests.push(derived({ storyId: e.storyId, title: e.title, pri: e.pri, effort: e.effort, name: e.name, brief: e.brief, eligible: false, why: "it is no longer an OUTSTANDING story on the board", origin: "auto", by: "auto", ...(e.ruling === undefined ? {} : { ruling: e.ruling }) }, now));
|
|
3179
3168
|
}
|
|
3180
|
-
// a press
|
|
3181
|
-
for (const kept of [store.presses, store.
|
|
3169
|
+
// a press stands while its story is open on the board — a read taken before it was made, or a story a 🚧 holds, never drops it; the board closing the story does
|
|
3170
|
+
for (const kept of [store.presses, store.forcesAhead])
|
|
3182
3171
|
for (const key of Object.keys(kept ?? {}))
|
|
3183
3172
|
if (!listed.has(Number(key)) && closedWhy(Number(key)) !== undefined)
|
|
3184
3173
|
delete kept[key];
|
|
@@ -3211,23 +3200,6 @@ export function slotRequests(requests, store, lanes, held) {
|
|
|
3211
3200
|
const unslotted = new Set(requests.filter((r) => r.eligible && r.origin === "press" && r.forced === undefined && !inLine.has(r.storyId) && !held(r.storyId) && !admitted.has(r)).map((r) => r.storyId));
|
|
3212
3201
|
return { requests: requests.filter((r) => !r.eligible || inLine.has(r.storyId) || admitted.has(r)), unslotted };
|
|
3213
3202
|
}
|
|
3214
|
-
/** 🔴 #4595 — an entry his ✕ Remove withdrew before removals were kept on the store: its removal is recorded once, at the step that withdrew it, so the pull pass keeps it out until his Start press or his AUTO START turned on. */
|
|
3215
|
-
function carryOldRemoves(store) {
|
|
3216
|
-
if (store.removalsCarried === true)
|
|
3217
|
-
return;
|
|
3218
|
-
store.removalsCarried = true;
|
|
3219
|
-
for (const e of store.entries) {
|
|
3220
|
-
const key = String(e.storyId);
|
|
3221
|
-
// 🔴 #4812 — a recorded withdrawal (`withdrawn-<time>` request) with the ✕ Remove words: the words alone never make a removal
|
|
3222
|
-
if (e.state !== "withdrawn" || !e.requestId.startsWith("withdrawn-") || store.removed?.[key] !== undefined || store.presses?.[key] !== undefined)
|
|
3223
|
-
continue;
|
|
3224
|
-
const said = /^(.+?) ✕ Remove took it out of the line/.exec(e.why);
|
|
3225
|
-
if (said === null)
|
|
3226
|
-
continue;
|
|
3227
|
-
const at = [...e.trace].reverse().find((t) => t.stage === "withdrawn")?.at ?? e.trace[e.trace.length - 1].at;
|
|
3228
|
-
store.removed = { ...store.removed, [key]: { at, by: said[1] } };
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
3203
|
/**
|
|
3232
3204
|
* 🔴 #4232 — the beat the last pass on a board left. A beat with no `driver` was written before the field existed, when only FleetView drove. Its writer still
|
|
3233
3205
|
* runs only while a process with its pid runs that had started by the beat's own moment: a pid the OS handed a process started after the beat never wrote it.
|
|
@@ -3661,8 +3633,15 @@ function takeDeadLock(board, file, held) {
|
|
|
3661
3633
|
export function readQueueStore(board) {
|
|
3662
3634
|
const stored = readJson(storeFile(board));
|
|
3663
3635
|
// NULL-OK: field stored is OPTIONAL and therefore it is ok to check for NULL
|
|
3664
|
-
|
|
3665
|
-
}
|
|
3636
|
+
if (stored === undefined)
|
|
3637
|
+
return { v: STORY_QUEUE_WIRE, nextSeq: 1, entries: [] };
|
|
3638
|
+
// 🔴 #4799 — the records of the deleted queue acts (⏸ Stop and its lifts, ✕ Remove and its carry) are read off an old store and never written back, so no store keeps them after its next pass
|
|
3639
|
+
for (const gone of LEGACY_QUEUE_FIELDS)
|
|
3640
|
+
delete stored[gone];
|
|
3641
|
+
return withoutRepeatedSteps(stored);
|
|
3642
|
+
}
|
|
3643
|
+
/** 🔴 #4799 — the store fields only the deleted queue acts wrote: ⏸ Stop (`stopped`, `lifted`, `halted`) and ✕ Remove (`removed`, `removalsCarried`). */
|
|
3644
|
+
const LEGACY_QUEUE_FIELDS = ["stopped", "lifted", "halted", "removed", "removalsCarried"];
|
|
3666
3645
|
/** 🔴 #4581 — the two ways work stands still that ask FleetView's progress checker: Meni, 2026-11-27, *"fv for queue without agents and for bb stories without agents or queue"*. */
|
|
3667
3646
|
export const CLOG_TRIGGERS = ["queue without agents", "stories without agents or queue"];
|
|
3668
3647
|
// GATE: how long a stuck set must stand before the progress check is asked — a pass about to start it, or a hand-over in flight, is never checked
|
|
@@ -3794,13 +3773,6 @@ export function queueOrder(store) {
|
|
|
3794
3773
|
}
|
|
3795
3774
|
/** 🔴 #4162 — whether `e` is a worker killed mid-work, parked in line until it is woken in its own session: its story is still being worked, so {@link queueOrder} moves it, never back, into the first places that are not his (a story he placed, or pressed Start or ⚡ on), keeping its order among other killed workers, and a lane its kill freed goes back to it; once he places it himself after its kill it stays where he put it, while a place he gave before the kill does not hold it back. The kill mark counts only beside the park it was written with, so any later park, wake or failure voids it. */
|
|
3796
3775
|
const killedInLine = (e) => e.state === "queued" && e.worker?.parkedAt !== undefined && e.worker.killedAt === e.worker.parkedAt;
|
|
3797
|
-
/** His order of the whole waiting line: each story is stamped with its place in `order`, so the order holds whichever story starts, finishes or arrives — a story he never placed waits behind the ones he ordered, by priority and size. */
|
|
3798
|
-
function stampOrder(order) {
|
|
3799
|
-
order.forEach((e, place) => {
|
|
3800
|
-
e.manual = place;
|
|
3801
|
-
e.ordered = true;
|
|
3802
|
-
});
|
|
3803
|
-
}
|
|
3804
3776
|
/** His placement of `e` at the 0-based place `k` among the waiting stories: every other entry he placed at `k` or after moves down one, so no two of his places tie and his newest move holds the place he chose. */
|
|
3805
3777
|
function placeAt(store, e, k) {
|
|
3806
3778
|
for (const o of store.entries)
|
|
@@ -3936,7 +3908,7 @@ function applyRequest(store, r, now) {
|
|
|
3936
3908
|
step(e, now, "updated", e.why);
|
|
3937
3909
|
}
|
|
3938
3910
|
else if (r.eligible && !newPress && (e.state === "failed" || e.state === "withdrawn") && neverRecordedSpent(e)) {
|
|
3939
|
-
// 🔴 #4485 — a story reported for a never-recorded worker, withdrawn while its decision was open and asked for again, goes back to failed: only his press
|
|
3911
|
+
// 🔴 #4485 — a story reported for a never-recorded worker, withdrawn while its decision was open and asked for again, goes back to failed: only his press starts it
|
|
3940
3912
|
const reported = `the board asks for it again, but ${NEVER_RECORDED_REPORT} — its worker never recorded itself after its one restart for that cause`;
|
|
3941
3913
|
if (e.state !== "failed") {
|
|
3942
3914
|
e.state = "failed";
|
|
@@ -4001,7 +3973,7 @@ function applyRequest(store, r, now) {
|
|
|
4001
3973
|
}
|
|
4002
3974
|
return undefined;
|
|
4003
3975
|
}
|
|
4004
|
-
/** 🔴 #4156 — his ⚡ Force start on an entry in line: it starts on the next pass
|
|
3976
|
+
/** 🔴 #4156 — his ⚡ Force start on an entry in line: it starts on the next pass; the request that carries it (#4177) and the queue's own ⚡ press both force it here. */
|
|
4005
3977
|
function forceEntry(e, now, by, eventAt = now) {
|
|
4006
3978
|
// 🔴 #4799 — a ⚡ Force start is an explicit order to start: it lifts the 🛑 Stop that held the row, never reports ok and leaves it held (the row stayed withdrawn under the same Stop)
|
|
4007
3979
|
if (e.handStop !== undefined) {
|
|
@@ -4691,7 +4663,7 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
4691
4663
|
step(e, now, "archived", `its story is no longer an open row on the board, so its conversation ${session.id} left every history list for the archive`);
|
|
4692
4664
|
save();
|
|
4693
4665
|
});
|
|
4694
|
-
// 🔴 #4761 — a ⚡ Force start ORDER outlives the start that spent its mark: back in line with no worker (it ended, or its start failed), the order is armed again on this pass, so the story restarts without a new press and AUTO START never holds it; one that left the line (
|
|
4666
|
+
// 🔴 #4761 — a ⚡ Force start ORDER outlives the start that spent its mark: back in line with no worker (it ended, or its start failed), the order is armed again on this pass, so the story restarts without a new press and AUTO START never holds it; one that left the line (🛑 Stop, the story's end) is dropped
|
|
4695
4667
|
for (const e of store.entries) {
|
|
4696
4668
|
if (e.forceOrder === undefined)
|
|
4697
4669
|
continue;
|
|
@@ -4932,10 +4904,10 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
4932
4904
|
}
|
|
4933
4905
|
if (e.state === "failed") {
|
|
4934
4906
|
const gaveUp = e.trace.filter((t) => t.stage === "failed").pop();
|
|
4935
|
-
// 🔴 #4485 — a story reported for a worker that never recorded itself, after its one restart, waits for his press
|
|
4907
|
+
// 🔴 #4485 — a story reported for a worker that never recorded itself, after its one restart, waits for his press: no re-arm starts it a third time on the same cause
|
|
4936
4908
|
if (!e.eligible || gaveUp === undefined || (world.resolveRoute === undefined && neverRecordedSpent(e)))
|
|
4937
4909
|
continue;
|
|
4938
|
-
// 🔴 #4642 — A STORY WHOSE WORKERS KEEP ENDING `stopped` IS NEVER STARTED AGAIN: past WORKER_ATTEMPTS such ends the cause is outside the story — something stops its worker — so a fourth start is spent to be stopped again. It keeps this `failed` row with its reason, and only his Start press
|
|
4910
|
+
// 🔴 #4642 — A STORY WHOSE WORKERS KEEP ENDING `stopped` IS NEVER STARTED AGAIN: past WORKER_ATTEMPTS such ends the cause is outside the story — something stops its worker — so a fourth start is spent to be stopped again. It keeps this `failed` row with its reason, and only his Start press puts it back in line.
|
|
4939
4911
|
if ((e.stoppedStarts ?? 0) >= WORKER_ATTEMPTS) {
|
|
4940
4912
|
const said = `its worker was stopped ${e.stoppedStarts} times and the story is still open, so it is not started again — only his ▶ Start press puts it back in line`;
|
|
4941
4913
|
if (e.why !== said) {
|
|
@@ -4947,7 +4919,7 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
4947
4919
|
// 🔴 #4642 — AND A ROW A PASS KEEPS FINDING WEDGED IS NOT STARTED AGAIN EITHER, and this guard is what makes its row's own words true: the wedge
|
|
4948
4920
|
// block sets this `failed` row past {@link WORKER_ATTEMPTS} givings-back, and WITHOUT a guard here the general re-arm below would offer it to the line
|
|
4949
4921
|
// again after {@link rearmDelayMs} and spend another start to be wedged again — one start per cycle, forever. It keeps this row with its reason, and
|
|
4950
|
-
// only his ▶ Start press
|
|
4922
|
+
// only his ▶ Start press or a ⚡ Force start puts it back in line. The words are the same ones the wedge block writes, so the row is not
|
|
4951
4923
|
// rewritten on every pass.
|
|
4952
4924
|
if ((e.wedgeGives ?? 0) > WORKER_ATTEMPTS) {
|
|
4953
4925
|
const said = `it was found with no worker of its own recorded for the start it spent ${e.wedgeGives} times running, so something stops its own start and it rests here — only his ▶ Start press puts it back in line`;
|
|
@@ -5227,7 +5199,7 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
5227
5199
|
continue;
|
|
5228
5200
|
}
|
|
5229
5201
|
if (e.neverRecorded > NEVER_RECORDED_RESTARTS) {
|
|
5230
|
-
// 🔴 #4485 — the restart for this cause was spent and its worker never recorded itself either: reported with the cause, never started again on it until his press
|
|
5202
|
+
// 🔴 #4485 — the restart for this cause was spent and its worker never recorded itself either: reported with the cause, never started again on it until his press (a story the board no longer asks for rests withdrawn with the same words, and a later ask puts it back to failed)
|
|
5231
5203
|
e.state = e.eligible ? "failed" : "withdrawn";
|
|
5232
5204
|
delete e.nextTryAt;
|
|
5233
5205
|
e.why = `${w.why} — restarted once already for the same cause and that worker never recorded itself either, so it is not started again; ${NEVER_RECORDED_REPORT}`;
|
|
@@ -5500,16 +5472,14 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
5500
5472
|
}
|
|
5501
5473
|
save();
|
|
5502
5474
|
// NULL-OK: field stopped is OPTIONAL and therefore it is ok to check for NULL
|
|
5503
|
-
const halted = store.stopped === undefined ? undefined : `the queue is stopped (${store.stopped.by}; ${store.stopped.author === undefined ? "author not recorded" : STOP_AUTHOR_WORDS[store.stopped.author]}), so nothing more starts or wakes until ▶ Run`;
|
|
5504
5475
|
const unscheduled = autoStartHeld(board);
|
|
5505
5476
|
const heldWhy = (e, waking = false) => {
|
|
5506
|
-
// 🔴 #4499 — his answer to the question its worker waits on is his own word on that story, so AUTO START off never holds the wake that carries it
|
|
5477
|
+
// 🔴 #4499 — his answer to the question its worker waits on is his own word on that story, so AUTO START off never holds the wake that carries it
|
|
5507
5478
|
const answer = e.worker?.question;
|
|
5508
5479
|
const humanAnswer = (unhanded(answer) !== undefined && answer?.approval !== true) || (e.lastWorkerAnswer !== undefined && e.lastWorkerAnswer.approval !== true);
|
|
5509
5480
|
// 🔴 #4601 — his Start press (or board-carried Force) stands: it wakes the parked session after every turn, and never restarts an ended worker
|
|
5510
5481
|
const manual = unscheduled !== undefined && !hisOwn(e) && !(waking && e.startPressedAt !== undefined && e.pressSpent !== true) && !humanAnswer ? unscheduled : undefined;
|
|
5511
|
-
|
|
5512
|
-
return e.forced === true ? manual : halted ?? manual;
|
|
5482
|
+
return e.forced === true ? undefined : manual;
|
|
5513
5483
|
};
|
|
5514
5484
|
// NULL-OK: field lanes is OPTIONAL and therefore it is ok to check for NULL
|
|
5515
5485
|
let running = lanes?.running ?? 0;
|
|
@@ -5883,10 +5853,9 @@ async function passHeld(board, world, now, yieldsToPresses = true) {
|
|
|
5883
5853
|
}
|
|
5884
5854
|
// NULL-OK: field forcedBy is OPTIONAL and therefore it is ok to check for NULL
|
|
5885
5855
|
const forcer = e.forcedBy ?? "an unrecorded presser's";
|
|
5886
|
-
// NULL-OK: field
|
|
5887
|
-
const forced = e.forced === true &&
|
|
5888
|
-
|
|
5889
|
-
const forcedPast = halted !== undefined ? "the queue's ⏸ Stop" : "AUTO START being off";
|
|
5856
|
+
// NULL-OK: field unscheduled is OPTIONAL and therefore it is ok to check for NULL
|
|
5857
|
+
const forced = e.forced === true && unscheduled !== undefined;
|
|
5858
|
+
const forcedPast = "AUTO START being off";
|
|
5890
5859
|
const full = laneHeld(e);
|
|
5891
5860
|
// NULL-OK: field full is OPTIONAL and therefore it is ok to check for NULL
|
|
5892
5861
|
if (full !== undefined) {
|
|
@@ -6090,8 +6059,6 @@ export class StoryPressRefused extends Error {
|
|
|
6090
6059
|
function forceAhead(board, store, storyId, now, by, wasInLine = false) {
|
|
6091
6060
|
if (by === HIS_PRESS) {
|
|
6092
6061
|
store.presses = { ...store.presses, [String(storyId)]: { at: now, by: "press", forced: now } };
|
|
6093
|
-
if (store.removed !== undefined)
|
|
6094
|
-
delete store.removed[String(storyId)];
|
|
6095
6062
|
}
|
|
6096
6063
|
else
|
|
6097
6064
|
store.forcesAhead = { ...store.forcesAhead, [String(storyId)]: { at: now, by } };
|
|
@@ -6100,7 +6067,7 @@ function forceAhead(board, store, storyId, now, by, wasInLine = false) {
|
|
|
6100
6067
|
}
|
|
6101
6068
|
/**
|
|
6102
6069
|
* 🔴 #4595 — HIS START PRESS, MADE ON FLEETVIEW DIRECTLY: kept on the queue's store by story, so every pass derives the story's request from it
|
|
6103
|
-
* while the story is OUTSTANDING on the board — with AUTO START off too
|
|
6070
|
+
* while the story is OUTSTANDING on the board — with AUTO START off too. `top` asks for the
|
|
6104
6071
|
* first place in line, `forced` for a ⚡ Force start riding on it. Never refused because the queue is driven: recorded beside the queue
|
|
6105
6072
|
* for the pass that holds its lock. Answers what it did, in words.
|
|
6106
6073
|
*/
|
|
@@ -6126,8 +6093,6 @@ function startHeld(board, storyId, at, start) {
|
|
|
6126
6093
|
const store = readQueueStore(board);
|
|
6127
6094
|
const key = String(storyId);
|
|
6128
6095
|
store.presses = { ...store.presses, [key]: { at, ...start } };
|
|
6129
|
-
if (store.removed !== undefined)
|
|
6130
|
-
delete store.removed[key];
|
|
6131
6096
|
if (store.pressRefused !== undefined)
|
|
6132
6097
|
delete store.pressRefused[key];
|
|
6133
6098
|
writeStore(board, store);
|
|
@@ -6136,9 +6101,8 @@ function startHeld(board, storyId, at, start) {
|
|
|
6136
6101
|
: `#${storyId}'s ⚡ Force start starts it on FleetView's next pass, past this workspace's lane limit, pausing the running story with the least progress`;
|
|
6137
6102
|
}
|
|
6138
6103
|
/**
|
|
6139
|
-
* 🔴 #4156 — HIS PRESS ON ONE STORY OF FLEETVIEW'S QUEUE, under the queue's lock:
|
|
6140
|
-
* next
|
|
6141
|
-
* it on the next pass past a ⏸ Stop, and 🔔 Nudge ends the wait it stands on (a retry's backoff, a parked worker's wake delay). A press
|
|
6104
|
+
* 🔴 #4156 — HIS PRESS ON ONE STORY OF FLEETVIEW'S QUEUE, under the queue's lock: ⚡ Force start starts
|
|
6105
|
+
* it on the next pass past the lane limit, 🛑 Stop worker asks its worker to stop, and ⛔ Kill ends its worker. A press
|
|
6142
6106
|
* that does not apply throws
|
|
6143
6107
|
* {@link StoryPressRefused}; one on a story not in line throws {@link NotInQueue}, except 🔴 #4522 a ⚡ Force start, which takes in the board's standing request or keeps the force for the request to come. Answers what it did, in words.
|
|
6144
6108
|
*/
|
|
@@ -6160,7 +6124,7 @@ export async function pressStory(board, storyId, press, now, by, requestHandledB
|
|
|
6160
6124
|
}
|
|
6161
6125
|
}
|
|
6162
6126
|
/**
|
|
6163
|
-
* 🔴 #4761 — HIS PRESS ON SEVERAL STORIES OF ONE BOARD AS ONE OPERATION: every story is pressed under ONE hold of the queue's lock, so a hundred
|
|
6127
|
+
* 🔴 #4761 — HIS PRESS ON SEVERAL STORIES OF ONE BOARD AS ONE OPERATION: every story is pressed under ONE hold of the queue's lock, so a hundred presses cost one wait and one pass of the disk, never a hundred waits behind the queue's pass.
|
|
6164
6128
|
* Another driver holding the lock records every press beside the queue and takes them in together, once. Answers each story's own words, a refusal as `ok: false`.
|
|
6165
6129
|
*/
|
|
6166
6130
|
export async function pressStories(board, ids, press, now, by) {
|
|
@@ -6202,7 +6166,7 @@ export async function pressStories(board, ids, press, now, by) {
|
|
|
6202
6166
|
}
|
|
6203
6167
|
}
|
|
6204
6168
|
/** 🔴 #4592 — how a press reads in the words that tell him it was recorded for the driver. */
|
|
6205
|
-
const PRESS_LABEL = {
|
|
6169
|
+
const PRESS_LABEL = { force: "⚡ Force start", stop: "🛑 Stop worker", kill: "⛔ Kill" };
|
|
6206
6170
|
/** 🔴 #4592 — the one look a recorded press takes at the lock before it answers: the holder may have let go meanwhile, so it is taken in at once and answered as a direct press answers; never a second wait in line behind it. */
|
|
6207
6171
|
async function handedToDriver(board, name, now, said) {
|
|
6208
6172
|
try {
|
|
@@ -6221,61 +6185,6 @@ async function handedToDriver(board, name, now, said) {
|
|
|
6221
6185
|
}
|
|
6222
6186
|
return said;
|
|
6223
6187
|
}
|
|
6224
|
-
export function shiftedTogether(pending, moved, delta) {
|
|
6225
|
-
const out = pending.slice();
|
|
6226
|
-
const up = delta < 0;
|
|
6227
|
-
for (let step = 0; step < Math.abs(delta) && step < out.length; step++) {
|
|
6228
|
-
let changed = false;
|
|
6229
|
-
const walk = up ? out.map((_, i) => i) : out.map((_, i) => out.length - 1 - i);
|
|
6230
|
-
for (const i of walk) {
|
|
6231
|
-
const j = up ? i - 1 : i + 1;
|
|
6232
|
-
if (moved.has(out[i]) && j >= 0 && j < out.length && !moved.has(out[j])) {
|
|
6233
|
-
[out[i], out[j]] = [out[j], out[i]];
|
|
6234
|
-
changed = true;
|
|
6235
|
-
}
|
|
6236
|
-
}
|
|
6237
|
-
if (!changed)
|
|
6238
|
-
break;
|
|
6239
|
-
}
|
|
6240
|
-
return out;
|
|
6241
|
-
}
|
|
6242
|
-
export function droppedBefore(pending, moved, anchor) {
|
|
6243
|
-
if (anchor !== undefined && (!pending.includes(anchor) || moved.has(anchor)))
|
|
6244
|
-
throw new StoryPressRefused(`${String(anchor)} is not a waiting row that stays where it is, so nothing was dropped before it`);
|
|
6245
|
-
const rest = pending.filter((id) => !moved.has(id));
|
|
6246
|
-
const at = anchor === undefined ? rest.length : rest.indexOf(anchor);
|
|
6247
|
-
return [...rest.slice(0, at), ...pending.filter((id) => moved.has(id)), ...rest.slice(at)];
|
|
6248
|
-
}
|
|
6249
|
-
/** The row a drop lands before, as a waiting row: a row that already started, drawn above the waiting ones, stands for the first waiting row drawn after it, so a drop at the very top of the strip puts the rows first in line. */
|
|
6250
|
-
function firstWaitingFrom(anchor, drawn, waiting, moved) {
|
|
6251
|
-
if (anchor === undefined || waiting.includes(anchor) || drawn === undefined || !drawn.includes(anchor))
|
|
6252
|
-
return anchor;
|
|
6253
|
-
return drawn.slice(drawn.indexOf(anchor)).find((id) => waiting.includes(id) && !moved.has(id));
|
|
6254
|
-
}
|
|
6255
|
-
/** 🔴 #4592 — what a move decides over the waiting stories: the new order and the stories he moved. */
|
|
6256
|
-
function movedLine(m) {
|
|
6257
|
-
const moved = new Set(m.ids);
|
|
6258
|
-
return (waiting) => ({ next: "delta" in m.how ? shiftedTogether(waiting, moved, m.how.delta) : droppedBefore(waiting, moved, firstWaitingFrom(m.how.before ?? undefined, m.visible, waiting, moved)), moved });
|
|
6259
|
-
}
|
|
6260
|
-
const movedLineWords = (ids, line) => ids.map((id) => `#${id} is now ${line.indexOf(id) + 1} of ${line.length} in FleetView's story queue`).join(" | ");
|
|
6261
|
-
/**
|
|
6262
|
-
* 🔴 #4592 — HIS MOVE OF WAITING STORIES, never refused because the queue is driven: made under the lock when it is free, and
|
|
6263
|
-
* otherwise recorded beside the queue for the pass that holds it to make before it lets go (or the next one).
|
|
6264
|
-
*/
|
|
6265
|
-
export async function moveStories(board, ids, how, visible, by, now) {
|
|
6266
|
-
const move = { ids: [...ids], how, ...(visible === undefined ? {} : { visible: [...visible] }) };
|
|
6267
|
-
try {
|
|
6268
|
-
return movedLineWords(ids, await placeWaiting(board, now, by, movedLine(move), visible));
|
|
6269
|
-
}
|
|
6270
|
-
catch (err) {
|
|
6271
|
-
if (!(err instanceof QueueBusy))
|
|
6272
|
-
throw err;
|
|
6273
|
-
// OWNER: ITER/LOOP — another driver holds the queue's lock for its pass: his move is recorded beside the queue and the pass that holds the lock makes it before it lets go (or the next pass does) — never refused.
|
|
6274
|
-
const name = `move-${now}-${Math.random().toString(36).slice(2, 8)}`;
|
|
6275
|
-
writeWhole(board, pressFile(board, name), { press: "move", at: now, by, move });
|
|
6276
|
-
return handedToDriver(board, name, now, `the move of ${ids.map((id) => `#${id}`).join(", ")} is recorded — ${err.message}, and the queue's pass makes it — the pass holding the queue now before it lets go, or the next one`);
|
|
6277
|
-
}
|
|
6278
|
-
}
|
|
6279
6188
|
const pressDir = (board) => path.join(storyQueueDir(board), "presses");
|
|
6280
6189
|
const pressFile = (board, name) => path.join(pressDir(board), `${name}.json`);
|
|
6281
6190
|
/** 🔴 #4529/#4592 — the presses recorded while another driver held the queue's lock: `<story>.<press>`, a move's `move-…`, and the bare `<story>` an older build wrote for a ⚡ Force start. */
|
|
@@ -6283,6 +6192,7 @@ function pendingPresses(board) {
|
|
|
6283
6192
|
const dir = pressDir(board);
|
|
6284
6193
|
if (!fs.existsSync(dir))
|
|
6285
6194
|
return [];
|
|
6195
|
+
// 🔴 #4799 — the record names of the deleted presses (✕ Remove, ↻ Retry, 🔔 Nudge, a move) are still matched, so an old record is answered "not a press this queue knows" and let go, never left in the folder
|
|
6286
6196
|
return fs.readdirSync(dir).filter((f) => /^(\d+(\.(force|remove|retry|nudge|stop|kill|start))?|move-[\w-]+)\.json$/.test(f)).map((f) => f.slice(0, -".json".length));
|
|
6287
6197
|
}
|
|
6288
6198
|
/**
|
|
@@ -6326,23 +6236,14 @@ async function takePendingPresses(board, now) {
|
|
|
6326
6236
|
continue;
|
|
6327
6237
|
}
|
|
6328
6238
|
const press = pending.press;
|
|
6329
|
-
if (typeof pending.by !== "string" || typeof pending.at !== "number" || (press !== "
|
|
6239
|
+
if (typeof pending.by !== "string" || typeof pending.at !== "number" || (press !== "start" && !(press !== undefined && Object.prototype.hasOwnProperty.call(PRESS_LABEL, press)))) {
|
|
6330
6240
|
answered.set(name, new StoryPressRefused(`the recorded press ${name} is not a press this queue knows, so it was dropped`));
|
|
6331
6241
|
release();
|
|
6332
6242
|
continue;
|
|
6333
6243
|
}
|
|
6334
6244
|
const by = pending.by;
|
|
6335
|
-
// a move is not idempotent: its record is let go before it is made, so a failed release can never make it twice
|
|
6336
|
-
if (press === "move")
|
|
6337
|
-
release();
|
|
6338
6245
|
try {
|
|
6339
|
-
if (press === "
|
|
6340
|
-
// NULL-OK: field move is OPTIONAL and therefore it is ok to check for NULL
|
|
6341
|
-
if (pending.move === undefined)
|
|
6342
|
-
throw new StoryPressRefused(`the recorded move ${name} names no stories, so it was dropped`);
|
|
6343
|
-
answered.set(name, movedLineWords(pending.move.ids, placeWaitingHeld(board, now, by, movedLine(pending.move), pending.move.visible)));
|
|
6344
|
-
}
|
|
6345
|
-
else if (press === "start") {
|
|
6246
|
+
if (press === "start") {
|
|
6346
6247
|
// NULL-OK: field start is OPTIONAL and therefore it is ok to check for NULL
|
|
6347
6248
|
if (pending.start === undefined)
|
|
6348
6249
|
throw new StoryPressRefused(`the recorded Start press ${name} names no start, so it was dropped`);
|
|
@@ -6362,8 +6263,8 @@ async function takePendingPresses(board, now) {
|
|
|
6362
6263
|
// OWNER: ITER/LOOP — the recorded press does not apply (the story is not in line, or is at work, or the board says it is not to be started): its words are kept on the story's entry and returned as the refusal; the next record is pressed.
|
|
6363
6264
|
answered.set(name, err);
|
|
6364
6265
|
const store = readQueueStore(board);
|
|
6365
|
-
const hit =
|
|
6366
|
-
const label = press === "
|
|
6266
|
+
const hit = [id];
|
|
6267
|
+
const label = press === "start" ? "Start press" : PRESS_LABEL[press];
|
|
6367
6268
|
let wrote = false;
|
|
6368
6269
|
for (const e of store.entries.filter((x) => hit.includes(x.storyId) && IN_LINE.has(x.state))) {
|
|
6369
6270
|
step(e, now, "updated", `${by} ${label}, recorded while another driver held the queue, was not applied — ${err.message}`);
|
|
@@ -6386,86 +6287,27 @@ async function pressHeld(board, storyId, press, now, by, requestHandledByOwner =
|
|
|
6386
6287
|
if (e === undefined) {
|
|
6387
6288
|
const left = store.entries.find((x) => x.storyId === storyId);
|
|
6388
6289
|
// NULL-OK: field left is OPTIONAL and therefore it is ok to check for NULL
|
|
6389
|
-
// 🔴 #4761 — a
|
|
6390
|
-
|
|
6391
|
-
if (press === "force" && (left === undefined || putBack(left)))
|
|
6290
|
+
// 🔴 #4761/#4799 — a ⚡ Force start on a story no lane works (none ever did, its 🛑 Stop, AUTO START off, or a start no lane took) is kept and started by the next pass; one the board says is not to be started stays refused
|
|
6291
|
+
if (press === "force" && (left === undefined || left.state === "withdrawn" || left.state === "done"))
|
|
6392
6292
|
return forceAhead(board, store, storyId, eventAt, by, left !== undefined);
|
|
6393
|
-
// 🔴 #4761 — ↻ Retry on a story that left the line (his ✕ Remove, AUTO START off) puts it back in line as his Start press does, never "nothing was done"
|
|
6394
|
-
if (press === "retry" && putBack(left))
|
|
6395
|
-
return startHeld(board, storyId, eventAt, { by: "press" });
|
|
6396
6293
|
throw new NotInQueue(board, storyId, left);
|
|
6397
6294
|
}
|
|
6398
6295
|
const working = e.state === "starting" || e.state === "running";
|
|
6399
|
-
// NULL-OK: field stopped is OPTIONAL and therefore it is ok to check for NULL
|
|
6400
|
-
const afterStop = store.stopped === undefined ? "" : " after ▶ Run lifts the queue's ⏸ Stop";
|
|
6401
6296
|
let did;
|
|
6402
|
-
|
|
6403
|
-
const held = autoStartHeld(board);
|
|
6404
|
-
// NULL-OK: field held is OPTIONAL and therefore it is ok to check for NULL
|
|
6405
|
-
if (held !== undefined && !hisOwn(e))
|
|
6406
|
-
throw new StoryPressRefused(`#${storyId}: ${held} — ${verb} starts and wakes nothing on its own`);
|
|
6407
|
-
};
|
|
6408
|
-
if (press === "remove") {
|
|
6409
|
-
// 🔴 #4592 — ✕ Remove is unconditional: a worker at work is told to stop (⛔ Kill's own record, whose delivery the pass keeps asking for) and the row leaves the line in the same press, never a refusal
|
|
6410
|
-
if (working && e.worker !== undefined) {
|
|
6411
|
-
let told = "its worker could not be told to stop";
|
|
6412
|
-
try {
|
|
6413
|
-
told = await pressHeld(board, storyId, "kill", now, by, requestHandledByOwner, ownerAction, eventAt);
|
|
6414
|
-
}
|
|
6415
|
-
catch (err) {
|
|
6416
|
-
if (!(err instanceof StoryPressRefused))
|
|
6417
|
-
throw err;
|
|
6418
|
-
// OWNER: ITER/LOOP — the worker's stop did not apply as it stands (one already asked, or none to ask): the row still leaves the line, and the stop's words go on the answer.
|
|
6419
|
-
told = err.message;
|
|
6420
|
-
}
|
|
6421
|
-
const fresh = readQueueStore(board);
|
|
6422
|
-
const gone = fresh.entries.find((x) => x.storyId === storyId && IN_LINE.has(x.state));
|
|
6423
|
-
// NULL-OK: field gone is OPTIONAL and therefore it is ok to check for NULL
|
|
6424
|
-
if (gone !== undefined) {
|
|
6425
|
-
gone.state = "withdrawn";
|
|
6426
|
-
gone.pressSpent = true;
|
|
6427
|
-
delete gone.forced;
|
|
6428
|
-
delete gone.forcedBy;
|
|
6429
|
-
delete gone.forceOrder;
|
|
6430
|
-
gone.why = `${by} ✕ Remove took it out of the line with its worker at work — his Start press puts it back`;
|
|
6431
|
-
gone.requestId = `withdrawn-${now}`;
|
|
6432
|
-
step(gone, now, "withdrawn", gone.why);
|
|
6433
|
-
removedFromLine(fresh, storyId, eventAt, by);
|
|
6434
|
-
writeStore(board, fresh);
|
|
6435
|
-
}
|
|
6436
|
-
return `#${storyId} is out of the line — ${told}`;
|
|
6437
|
-
}
|
|
6438
|
-
e.state = "withdrawn";
|
|
6439
|
-
e.pressSpent = true;
|
|
6440
|
-
delete e.forced;
|
|
6441
|
-
delete e.forcedBy;
|
|
6442
|
-
delete e.forceOrder;
|
|
6443
|
-
e.why = `${by} ✕ Remove took it out of the line — his Start press puts it back`;
|
|
6444
|
-
e.requestId = `withdrawn-${now}`;
|
|
6445
|
-
step(e, now, "withdrawn", e.why);
|
|
6446
|
-
removedFromLine(store, storyId, eventAt, by);
|
|
6447
|
-
did = `#${storyId} is out of the line`;
|
|
6448
|
-
}
|
|
6449
|
-
else if (press === "retry") {
|
|
6450
|
-
if (e.state !== "failed" && e.state !== "retrying")
|
|
6451
|
-
throw new StoryPressRefused(`#${storyId} is ${e.state}, and ↻ Retry puts back only a failed or retrying story`);
|
|
6452
|
-
startsNothingOnItsOwn("↻ Retry");
|
|
6453
|
-
e.state = "queued";
|
|
6454
|
-
e.attempts = 0;
|
|
6455
|
-
delete e.neverRecorded;
|
|
6456
|
-
delete e.stoppedStarts;
|
|
6457
|
-
delete e.wedgeGives;
|
|
6458
|
-
delete e.accountRefused;
|
|
6459
|
-
delete e.accountRefusals;
|
|
6460
|
-
delete e.nextTryAt;
|
|
6461
|
-
e.why = `${by} ↻ Retry put it back in line with its attempts reset`;
|
|
6462
|
-
step(e, now, "retry", e.why);
|
|
6463
|
-
did = `#${storyId} is back in line`;
|
|
6464
|
-
}
|
|
6465
|
-
else if (press === "force") {
|
|
6297
|
+
if (press === "force") {
|
|
6466
6298
|
if (working)
|
|
6467
6299
|
throw new StoryPressRefused(`#${storyId} already has a worker at work, so there is nothing to force`);
|
|
6468
|
-
|
|
6300
|
+
// 🔴 #4799 — the force is kept beside the row as forceAhead keeps it, so the next pass derives an eligible request from it whatever AUTO START says: a row still in line under AUTO START off is never withdrawn with the force on it.
|
|
6301
|
+
// His rides on his Start press (applyRequest sees it already applied: no second force); an agent's waits in forcesAhead, whose ahead block forces the row as the agent's.
|
|
6302
|
+
const key = String(storyId);
|
|
6303
|
+
if (by === HIS_PRESS) {
|
|
6304
|
+
forceEntry(e, now, by, eventAt);
|
|
6305
|
+
// 🔴 #4762 — a fresh press: his ⚡ is a newer press than the one his worker spent, so AUTO START off never reads it as spent
|
|
6306
|
+
// NULL-OK: field presses is OPTIONAL and therefore it is ok to check for NULL
|
|
6307
|
+
store.presses = { ...store.presses, [key]: { ...store.presses?.[key], at: eventAt, by: "press", forced: eventAt } };
|
|
6308
|
+
}
|
|
6309
|
+
else
|
|
6310
|
+
store.forcesAhead = { ...store.forcesAhead, [key]: { at: eventAt, by } };
|
|
6469
6311
|
did = `#${storyId} starts on the next pass, past this workspace's lane limit, pausing the running story with the least progress`;
|
|
6470
6312
|
}
|
|
6471
6313
|
else if (press === "stop" || press === "kill") {
|
|
@@ -6484,29 +6326,6 @@ async function pressHeld(board, storyId, press, now, by, requestHandledByOwner =
|
|
|
6484
6326
|
step(e, now, "stop-asked", e.why);
|
|
6485
6327
|
did = told.did;
|
|
6486
6328
|
}
|
|
6487
|
-
else if (press === "nudge") {
|
|
6488
|
-
startsNothingOnItsOwn("🔔 Nudge");
|
|
6489
|
-
const parked = working || parkedInLine(e) ? e.worker : undefined;
|
|
6490
|
-
// NULL-OK: field parkedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
6491
|
-
if (parked?.parkedAt !== undefined) {
|
|
6492
|
-
const killed = killedInLine(e);
|
|
6493
|
-
parked.parkedAt = now - wakeDelayMs(parked.wakes ?? 0);
|
|
6494
|
-
if (killed)
|
|
6495
|
-
parked.killedAt = parked.parkedAt;
|
|
6496
|
-
e.why = `${by} 🔔 Nudge ended its parked worker ${parked.jobId}'s wake delay, so it is woken on the next pass${afterStop}`;
|
|
6497
|
-
did = `#${storyId}'s worker is woken on the next pass${afterStop}`;
|
|
6498
|
-
// NULL-OK: field nextTryAt is OPTIONAL and therefore it is ok to check for NULL
|
|
6499
|
-
}
|
|
6500
|
-
else if (e.nextTryAt !== undefined && e.nextTryAt > now) {
|
|
6501
|
-
e.nextTryAt = now;
|
|
6502
|
-
e.why = `${by} 🔔 Nudge ended its wait, so it is tried on the next pass${afterStop}`;
|
|
6503
|
-
did = `#${storyId} is tried on the next pass${afterStop}`;
|
|
6504
|
-
}
|
|
6505
|
-
else {
|
|
6506
|
-
throw new StoryPressRefused(`#${storyId} waits on nothing a nudge ends — it reads: ${e.why}${e.state === "queued" ? "; ⚡ Force start runs it past a ⏸ Stop" : ""}`);
|
|
6507
|
-
}
|
|
6508
|
-
step(e, now, "retry", e.why);
|
|
6509
|
-
}
|
|
6510
6329
|
else {
|
|
6511
6330
|
throw new StoryPressRefused(`${String(press)} is not a press FleetView's queue knows; #${storyId} reads: ${e.why}`);
|
|
6512
6331
|
}
|
|
@@ -6514,13 +6333,6 @@ async function pressHeld(board, storyId, press, now, by, requestHandledByOwner =
|
|
|
6514
6333
|
return did;
|
|
6515
6334
|
}
|
|
6516
6335
|
}
|
|
6517
|
-
/** 🔴 #4595 — his ✕ Remove keeps the story out of the line: his Start press on it is spent, and AUTO START never takes it back in until his next Start press or his AUTO START turned on. */
|
|
6518
|
-
function removedFromLine(store, storyId, at, by) {
|
|
6519
|
-
const key = String(storyId);
|
|
6520
|
-
if (store.presses !== undefined)
|
|
6521
|
-
delete store.presses[key];
|
|
6522
|
-
store.removed = { ...store.removed, [key]: { at, by } };
|
|
6523
|
-
}
|
|
6524
6336
|
/** 🔴 #4595 — why this board's AUTO START holds every story but his presses — off, or its choice in the workspace's fv.json unreadable — or undefined while it is on. */
|
|
6525
6337
|
export function autoStartHeld(board) {
|
|
6526
6338
|
const hold = "so only his Start press or ⚡ Force start starts or wakes a story";
|
|
@@ -6567,81 +6379,6 @@ function pressedFor(e) {
|
|
|
6567
6379
|
// NULL-OK: field landedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
6568
6380
|
return e.startPressedAt > (e.landedAt ?? e.worker?.startedAt ?? -Infinity);
|
|
6569
6381
|
}
|
|
6570
|
-
/** 🔴 #4156 — his ▶ Run or ⏸ Stop on the board's queue: stopped, nothing more starts or wakes until he runs it again; workers already running carry on. Answers whether it changed. */
|
|
6571
|
-
export async function setStoryQueueStopped(board, stopped, by, now, author = "caller") {
|
|
6572
|
-
return withQueueLock(board, now, async () => {
|
|
6573
|
-
const store = readQueueStore(board);
|
|
6574
|
-
// NULL-OK: field stopped is OPTIONAL and therefore it is ok to check for NULL
|
|
6575
|
-
if ((store.stopped !== undefined) === stopped)
|
|
6576
|
-
return false;
|
|
6577
|
-
if (stopped)
|
|
6578
|
-
store.stopped = { at: now, by, author };
|
|
6579
|
-
else {
|
|
6580
|
-
store.lifted = { at: now, by, stoppedBy: store.stopped.by, stoppedAuthor: store.stopped.author };
|
|
6581
|
-
delete store.stopped;
|
|
6582
|
-
}
|
|
6583
|
-
writeStore(board, store);
|
|
6584
|
-
return true;
|
|
6585
|
-
});
|
|
6586
|
-
}
|
|
6587
|
-
/** His placement of one story in FleetView's queue: a 0-based place, or `auto` to hand it back to priority and size. */
|
|
6588
|
-
export async function placeStory(board, storyId, place, now, by) {
|
|
6589
|
-
return withQueueLock(board, now, async () => {
|
|
6590
|
-
const store = readQueueStore(board);
|
|
6591
|
-
const e = store.entries.find((x) => x.storyId === storyId && IN_LINE.has(x.state));
|
|
6592
|
-
if (e === undefined)
|
|
6593
|
-
throw new NotInQueue(board, storyId, store.entries.find((x) => x.storyId === storyId));
|
|
6594
|
-
if (place === "auto") {
|
|
6595
|
-
delete e.manual;
|
|
6596
|
-
delete e.ordered;
|
|
6597
|
-
delete e.hisPlace;
|
|
6598
|
-
delete e.killStamp;
|
|
6599
|
-
}
|
|
6600
|
-
else
|
|
6601
|
-
placeAt(store, e, Math.max(0, place - store.entries.filter((x) => IN_LINE.has(x.state) && !WAITING_STATES.has(x.state)).length));
|
|
6602
|
-
step(e, now, "placed", place === "auto" ? `${by} move handed it back to priority and size` : `${by} move put it at place ${place + 1}`);
|
|
6603
|
-
writeStore(board, store);
|
|
6604
|
-
return e;
|
|
6605
|
-
});
|
|
6606
|
-
}
|
|
6607
|
-
/**
|
|
6608
|
-
* 🔴 #4354 — HIS MOVE OF ONE OR SEVERAL WAITING STORIES, ATOMIC AND MINIMAL: under ONE lock the line is read, `decide` is handed the waiting
|
|
6609
|
-
* stories (the ones named in `visible` when given) in their order and answers the new order and which stories moved, and the store is
|
|
6610
|
-
* written ONCE with each moved story, and each story he placed before, put at the place it holds in the new line — so a queue pass never
|
|
6611
|
-
* reads half a move, and a story that arrives later still sorts by priority and size around the places he pinned. Throws {@link NotInQueue}
|
|
6612
|
-
* for a story the line does not wait on; a move that changes nothing writes nothing; answers the new waiting order.
|
|
6613
|
-
*/
|
|
6614
|
-
export async function placeWaiting(board, now, by, decide, visible) {
|
|
6615
|
-
return withQueueLock(board, now, async () => placeWaitingHeld(board, now, by, decide, visible));
|
|
6616
|
-
}
|
|
6617
|
-
/** {@link placeWaiting}'s move, run by a caller that already holds the queue's lock. */
|
|
6618
|
-
function placeWaitingHeld(board, now, by, decide, visible) {
|
|
6619
|
-
{
|
|
6620
|
-
const store = readQueueStore(board);
|
|
6621
|
-
const line = queueOrder(store).filter((e) => WAITING_STATES.has(e.state));
|
|
6622
|
-
const waiting = line.filter((e) => visible === undefined || visible.includes(e.storyId)).map((e) => e.storyId);
|
|
6623
|
-
const { next, moved } = decide(waiting);
|
|
6624
|
-
for (const id of moved)
|
|
6625
|
-
if (!waiting.includes(id))
|
|
6626
|
-
throw new NotInQueue(board, id, store.entries.find((x) => x.storyId === id));
|
|
6627
|
-
if (next.join() === waiting.join())
|
|
6628
|
-
return waiting;
|
|
6629
|
-
const refill = next.slice();
|
|
6630
|
-
const ordered = line.map((e) => (waiting.includes(e.storyId) ? refill.shift() : e.storyId));
|
|
6631
|
-
stampOrder(ordered.map((id) => line.find((e) => e.storyId === id)));
|
|
6632
|
-
for (const e of line)
|
|
6633
|
-
if (killedInLine(e) && e.hisPlace !== true && !moved.has(e.storyId))
|
|
6634
|
-
e.killStamp = e.worker.killedAt;
|
|
6635
|
-
else
|
|
6636
|
-
delete e.killStamp;
|
|
6637
|
-
for (const id of moved)
|
|
6638
|
-
line.find((e) => e.storyId === id).hisPlace = true;
|
|
6639
|
-
for (const id of moved)
|
|
6640
|
-
step(line.find((e) => e.storyId === id), now, "placed", `${by} move put it at place ${ordered.indexOf(id) + 1}`);
|
|
6641
|
-
writeStore(board, store);
|
|
6642
|
-
return queueOrder(store).filter((e) => waiting.includes(e.storyId)).map((e) => e.storyId);
|
|
6643
|
-
}
|
|
6644
|
-
}
|
|
6645
6382
|
/** 🔴 #4154 — FleetView's investigator ruled ABORT on the worker `jobId` of this story: its entry leaves the line, so the stopped worker is never woken, and his next Start press brings the story back; undefined when no entry in line runs that worker. */
|
|
6646
6383
|
export async function withdrawStory(board, storyId, jobId, why, now) {
|
|
6647
6384
|
return withQueueLock(board, now, async () => {
|
|
@@ -35,7 +35,7 @@ function run(file, args, timeoutMs, env = process.env) {
|
|
|
35
35
|
/** Every process on the machine; throws {@link ProcessTableUnread} when the table cannot be read, never answers an empty one for it. */
|
|
36
36
|
export async function processTable() {
|
|
37
37
|
if (process.platform === "win32") {
|
|
38
|
-
const script = "Get-CimInstance Win32_Process | ForEach-Object { [pscustomobject]@{ p = $_.ProcessId; pp = $_.ParentProcessId; n = $_.Name; c = $_.CommandLine } } | ConvertTo-Json -Compress";
|
|
38
|
+
const script = "[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false; Get-CimInstance Win32_Process | ForEach-Object { [pscustomobject]@{ p = $_.ProcessId; pp = $_.ParentProcessId; n = $_.Name; c = $_.CommandLine } } | ConvertTo-Json -Compress";
|
|
39
39
|
const { code, out } = await run("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script], TABLE_READ_MS);
|
|
40
40
|
const text = out.trim();
|
|
41
41
|
if (code !== 0 || !text.startsWith("["))
|
|
@@ -1171,14 +1171,28 @@ function identitiesHere() {
|
|
|
1171
1171
|
* @returns {{ identityId: string, named: string, model: string, env: Record<string, string>, modelRefusalId?: string }}
|
|
1172
1172
|
*/
|
|
1173
1173
|
function opencodeRoute(home, wanted, now = Date.now(), identities = identitiesHere()) {
|
|
1174
|
-
const passed = [];
|
|
1175
1174
|
const byok = readOpencodeRoute(home) === "byok";
|
|
1175
|
+
const route = (asked) => {
|
|
1176
|
+
const passed = [];
|
|
1177
|
+
if (byok)
|
|
1178
|
+
return opencodeKeyRoute(home, asked, now, identities, passed);
|
|
1179
|
+
return opencodeFreeRoute(home, asked, now, passed) ?? opencodeKeyRoute(home, asked, now, identities, passed);
|
|
1180
|
+
};
|
|
1181
|
+
if (wanted !== undefined)
|
|
1182
|
+
return route(wanted);
|
|
1176
1183
|
const picked = readOpencodeModel(home) || undefined;
|
|
1177
1184
|
const fits = picked !== undefined && !(byok && splitWanted(picked).asked === OPENCODE_PROVIDER);
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1185
|
+
if (fits) {
|
|
1186
|
+
try {
|
|
1187
|
+
return route(picked);
|
|
1188
|
+
}
|
|
1189
|
+
catch (cause) {
|
|
1190
|
+
// OWNER: the launch owns a saved default it cannot use — try the current route's default; explicit launch arguments stay exact
|
|
1191
|
+
if (!(cause instanceof NoOpenCodeKey))
|
|
1192
|
+
throw cause;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return route(undefined);
|
|
1182
1196
|
}
|
|
1183
1197
|
function opencodeStoreEnv(home) {
|
|
1184
1198
|
const store = path.join(home, ".bullseye", "opencode");
|
|
@@ -1186,7 +1200,9 @@ function opencodeStoreEnv(home) {
|
|
|
1186
1200
|
}
|
|
1187
1201
|
function splitWanted(wanted) {
|
|
1188
1202
|
const cut = wanted === undefined ? -1 : wanted.indexOf("/");
|
|
1189
|
-
|
|
1203
|
+
const prefix = cut === -1 ? undefined : wanted.slice(0, cut);
|
|
1204
|
+
const qualified = prefix === OPENCODE_PROVIDER || Object.values(OPENCODE_KEY_KINDS).some((kind) => kind.provider === prefix);
|
|
1205
|
+
return qualified ? { asked: prefix, bare: wanted.slice(cut + 1) } : { asked: undefined, bare: wanted };
|
|
1190
1206
|
}
|
|
1191
1207
|
/**
|
|
1192
1208
|
* OpenCode's free tier as every surface reads it — the route, DeepAgent's panel row and provider_room: the free models its catalogue names, the ones with no fresh failure, each failed one with why, and why the whole tier is passed over when it is.
|
|
@@ -1259,14 +1275,16 @@ const OPENCODE_KEY_REFUSAL_TYPES = Object.freeze(new Set(["provider.auth", "prov
|
|
|
1259
1275
|
/**
|
|
1260
1276
|
* An error OpenCode reported in one of its JSON events, read once for every reader — BN, the shared OpenCodeTurn and DeepAgent's Test: the provider's own message,
|
|
1261
1277
|
* its HTTP status when it sent one, whether it refused the key or account, and the line every surface shows.
|
|
1262
|
-
* @param {{ name?: string, data?: { message?: string, statusCode?: number } } | undefined} error
|
|
1278
|
+
* @param {{ type?: string, message?: string, status?: number, name?: string, data?: { message?: string, statusCode?: number } } | undefined} error
|
|
1263
1279
|
* @returns {{ message: string, status: number | undefined, keyRefusal: boolean, said: string }}
|
|
1264
1280
|
*/
|
|
1265
1281
|
function opencodeEventError(error) {
|
|
1266
1282
|
const data = error?.data ?? {};
|
|
1267
|
-
const
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1283
|
+
const type = error?.type ?? error?.name;
|
|
1284
|
+
const message = error?.message ?? data.message ?? type ?? "the CLI reported an error";
|
|
1285
|
+
const stated = error?.status ?? data.statusCode;
|
|
1286
|
+
const status = typeof stated === "number" ? stated : undefined;
|
|
1287
|
+
return { message, status, keyRefusal: (status !== undefined && OPENCODE_KEY_REFUSAL_STATUSES.has(status)) || OPENCODE_KEY_REFUSAL_WORDS.test(message) || OPENCODE_KEY_REFUSAL_TYPES.has(type), said: status === undefined ? message : `${message} (HTTP ${status})` };
|
|
1270
1288
|
}
|
|
1271
1289
|
/**
|
|
1272
1290
|
* What a failure on a free model means for the turn, decided once for every OpenCode runner (BN, the shared OpenCodeTurn and through it ai_failover):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.483",
|
|
4
4
|
"homepage": "https://www.npmjs.com/package/omni-notify-mcp",
|
|
5
5
|
"description": "Reach your AI agents from anywhere — and let them reach you. One resident process on 127.0.0.1:7475 serves the whole tool surface to Claude Code, GitHub Copilot Chat and Codex: desktop, Telegram, Slack, ntfy, Discord, Teams and SMS are configured in one file, and agents notify you when long work finishes or a decision is needed, ask you a question and wait for your answer, and receive and reply to the messages you send them — with Do Not Disturb and idle detection deciding what actually gets through.",
|
|
6
6
|
"main": "dist/daemon.js",
|