omni-notify-mcp 1.3.488 → 1.3.490
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 +43 -11
- package/dist/notify.js +120 -27
- package/dist/shared/webhost/bullseyeWebHost.js +37 -24
- package/dist/shared/webhost/userSession.js +28 -13
- package/dist/shared/webhost/workspaceList.js +119 -9
- package/package.json +1 -1
package/dist/agentGateway.js
CHANGED
|
@@ -12,6 +12,7 @@ import { randomUUID } from "crypto";
|
|
|
12
12
|
import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from "fs";
|
|
13
13
|
import { homedir } from "os";
|
|
14
14
|
import { join } from "path";
|
|
15
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
15
16
|
import { choicesOf, StreamedReply } from "./messaging/messenger.js";
|
|
16
17
|
import { GatewayError, readGatewaySettings } from "./notify.js";
|
|
17
18
|
import { toolLine } from "./shared/toolLine.js";
|
|
@@ -45,11 +46,11 @@ export function clusterUnreachable(err) {
|
|
|
45
46
|
return new GatewayError(503, `AgenticBullseye at ${clusterBase()} could not be reached (${cause}); the agent conversations run there`);
|
|
46
47
|
}
|
|
47
48
|
/** One call to AB under the gateway bearer: AB's JSON answer, or AB's own refusal as a GatewayError carrying its status and words. */
|
|
48
|
-
export async function clusterCall(method, path, body) {
|
|
49
|
+
export async function clusterCall(method, path, body, signal) {
|
|
49
50
|
let answer;
|
|
50
51
|
for (let attempt = 1;; attempt++) {
|
|
51
52
|
try {
|
|
52
|
-
answer = await fetch(`${clusterBase()}${path}`, { method, headers: { authorization: `Bearer ${clusterToken()}`, ...(body === undefined ? {} : { "content-type": "application/json" }) }, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
53
|
+
answer = await fetch(`${clusterBase()}${path}`, { method, headers: { authorization: `Bearer ${clusterToken()}`, ...(body === undefined ? {} : { "content-type": "application/json" }) }, body: body === undefined ? undefined : JSON.stringify(body), signal });
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
56
|
catch (err) {
|
|
@@ -60,10 +61,18 @@ export async function clusterCall(method, path, body) {
|
|
|
60
61
|
// OWNER: ITER/LOOP — a refused connection never reached AB (it is restarting), so it is tried again after a pause; any other failure, or the last try, is AB unreachable, thrown as the 503 naming it.
|
|
61
62
|
if (!refused || attempt === CLUSTER_CALL_TRIES)
|
|
62
63
|
throw clusterUnreachable(err);
|
|
63
|
-
await
|
|
64
|
+
await delay(CLUSTER_FIRST_WAIT_MS << (attempt - 1), undefined, { signal });
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
let text;
|
|
68
|
+
try {
|
|
69
|
+
text = await answer.text();
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (!(err instanceof TypeError))
|
|
73
|
+
throw err;
|
|
74
|
+
throw clusterUnreachable(err);
|
|
75
|
+
}
|
|
67
76
|
let parsed;
|
|
68
77
|
try {
|
|
69
78
|
parsed = JSON.parse(text);
|
|
@@ -84,6 +93,17 @@ export async function clusterCall(method, path, body) {
|
|
|
84
93
|
function carriage(op, body) {
|
|
85
94
|
return clusterCall("POST", `/v1/chat/${op}`, body);
|
|
86
95
|
}
|
|
96
|
+
async function chatCallWithDeadline(op, body) {
|
|
97
|
+
const signal = AbortSignal.timeout(2000);
|
|
98
|
+
try {
|
|
99
|
+
return await clusterCall("POST", `/v1/chat/${op}`, body, signal);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (!signal.aborted)
|
|
103
|
+
throw err;
|
|
104
|
+
throw new GatewayError(504, "AgenticBullseye did not answer in time.");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
87
107
|
export class AgentGateway {
|
|
88
108
|
static self;
|
|
89
109
|
static instance() {
|
|
@@ -123,19 +143,31 @@ export class AgentGateway {
|
|
|
123
143
|
if (!text.startsWith(AGENT_PREFIX) && !COMMAND_RE.test(text))
|
|
124
144
|
return undefined;
|
|
125
145
|
// NULL-OK: field act is OPTIONAL and therefore it is ok to check for NULL
|
|
126
|
-
return (await
|
|
146
|
+
return (await chatCallWithDeadline("classify", { key, raw })).act ?? undefined;
|
|
127
147
|
}
|
|
128
148
|
/** A message inside a thread the agent holds is all for the agent: `/new` and `/stop` act, anything else is said, with or without `!`. */
|
|
129
149
|
async classifyInThread(key, raw) {
|
|
130
|
-
return (await
|
|
150
|
+
return (await chatCallWithDeadline("classifyInThread", { key, raw })).act;
|
|
131
151
|
}
|
|
132
152
|
/** A message of Meni's one chat is all for its one conversation (#4453); `bare` says the chat cannot type a slash, so a bare "new" or "stop" is a command there. */
|
|
133
153
|
async classifyChat(raw, bare) {
|
|
134
|
-
return (await
|
|
154
|
+
return (await chatCallWithDeadline("classifyChat", { raw, bare })).act;
|
|
135
155
|
}
|
|
136
156
|
/** The text one message of Meni's one chat is sent as: the bound conversation's brief on its first turn, then what the chat knows around it, then his own words. */
|
|
137
157
|
async turnText(key, text, context) {
|
|
138
|
-
return (await
|
|
158
|
+
return (await chatCallWithDeadline("turnText", { key, text, context })).text;
|
|
159
|
+
}
|
|
160
|
+
async workingStatus(key, platform) {
|
|
161
|
+
try {
|
|
162
|
+
const { text } = await chatCallWithDeadline("workingStatus", { key, platform });
|
|
163
|
+
return text;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
// OWNER: the status read answers its originating chat even when the cluster cannot report the turn.
|
|
167
|
+
if (!(err instanceof GatewayError))
|
|
168
|
+
throw err;
|
|
169
|
+
return err.status === 504 ? "BN received your message. The agent did not report its status in time." : "BN received your message. The agent's status is unavailable.";
|
|
170
|
+
}
|
|
139
171
|
}
|
|
140
172
|
/**
|
|
141
173
|
* A message's act as AB classifies it; one AB could not classify (unreachable, or refused with its reason) has that
|
|
@@ -158,15 +190,15 @@ export class AgentGateway {
|
|
|
158
190
|
return (await carriage("emailTaken", { messageId })).taken;
|
|
159
191
|
}
|
|
160
192
|
async openSlackThreads() {
|
|
161
|
-
return (await
|
|
193
|
+
return (await chatCallWithDeadline("openSlackThreads", {})).conversations;
|
|
162
194
|
}
|
|
163
195
|
/** Every conversation AB holds, each marked `working` while a turn of it is under way: the Slack Home tab and the Slack thread reader list them. */
|
|
164
196
|
async conversations() {
|
|
165
|
-
return (await
|
|
197
|
+
return (await chatCallWithDeadline("conversations", {})).conversations;
|
|
166
198
|
}
|
|
167
199
|
/** Records how far a Slack thread has been read. */
|
|
168
200
|
async markSlackRead(key, readTs) {
|
|
169
|
-
await
|
|
201
|
+
await chatCallWithDeadline("markSlackRead", { key, readTs });
|
|
170
202
|
}
|
|
171
203
|
/**
|
|
172
204
|
* Hands one addressed message to AB with its own way back held under a fresh reply id. A plain reply resolves once the
|
package/dist/notify.js
CHANGED
|
@@ -1096,7 +1096,7 @@ function ingestDropFolder() {
|
|
|
1096
1096
|
rejectDrop(path, name, err instanceof Error ? err.message : String(err));
|
|
1097
1097
|
continue;
|
|
1098
1098
|
}
|
|
1099
|
-
taken.push({ path, marker, entry });
|
|
1099
|
+
taken.push({ path, marker, name, entry });
|
|
1100
1100
|
queued = true;
|
|
1101
1101
|
}
|
|
1102
1102
|
finally {
|
|
@@ -1112,6 +1112,8 @@ function ingestDropFolder() {
|
|
|
1112
1112
|
retryUnreadDrops(unread);
|
|
1113
1113
|
if (taken.length === 0)
|
|
1114
1114
|
return;
|
|
1115
|
+
for (const { entry, name } of taken)
|
|
1116
|
+
copyUrgentAlertToChat(entry.text, name);
|
|
1115
1117
|
persistInboxQueue(taken.map(({ entry }) => entry));
|
|
1116
1118
|
for (const { path, marker } of taken) {
|
|
1117
1119
|
unlinkSync(path);
|
|
@@ -1120,6 +1122,32 @@ function ingestDropFolder() {
|
|
|
1120
1122
|
log("·", "inbox-drop", `queued ${taken.length} message${taken.length === 1 ? "" : "s"} from ${INBOX_DROP_IN_DIR}`);
|
|
1121
1123
|
syncInboxFromDisk();
|
|
1122
1124
|
}
|
|
1125
|
+
const URGENT_ALERT_TIER = /\[(WARN|CRITICAL)\]/;
|
|
1126
|
+
// GATE: the largest slice of an urgent alert sent in one chat message, under Telegram's 4096-character cap; slices are cut at exact offsets so the chat receives the drop's text unchanged.
|
|
1127
|
+
const COPY_PART_CHARS = 4000;
|
|
1128
|
+
function copyUrgentAlertToChat(text, drop) {
|
|
1129
|
+
const headline = text.split("\n")[0];
|
|
1130
|
+
const refuse = (where, err) => recordReach("telegram", false, "an urgent alert copy", `NOT copied from ${drop} to ${where} (${headline}): ${err instanceof Error ? err.message : String(err)}`);
|
|
1131
|
+
void (async () => {
|
|
1132
|
+
const tg = loadConfig().telegram;
|
|
1133
|
+
if (tg?.copyUrgentAlerts !== true || !URGENT_ALERT_TIER.test(text))
|
|
1134
|
+
return;
|
|
1135
|
+
if (!Array.isArray(tg.chatIds))
|
|
1136
|
+
throw new Error("telegram.chatIds is not a list");
|
|
1137
|
+
for (const chat of tg.chatIds) {
|
|
1138
|
+
void (async () => {
|
|
1139
|
+
for (let at = 0; at < text.length;) {
|
|
1140
|
+
let end = Math.min(at + COPY_PART_CHARS, text.length);
|
|
1141
|
+
if (end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1]))
|
|
1142
|
+
end--; // never cut a surrogate pair (an emoji) in two
|
|
1143
|
+
await telegramSendTo(tg.token, chat, text.slice(at, end));
|
|
1144
|
+
at = end;
|
|
1145
|
+
}
|
|
1146
|
+
recordReach("telegram", true, "an urgent alert copy", `copied to chat ${chat}: ${headline}`);
|
|
1147
|
+
})().catch((err) => refuse(`chat ${chat}`, err)); // OWNER: the copy is an extra leg; its refusal is recorded with the drop and the headline while Slack and email keep their own legs
|
|
1148
|
+
}
|
|
1149
|
+
})().catch((err) => refuse("the telegram chats", err)); // OWNER: a config that cannot be read or a chat list that is not a list is the copy's own refusal, recorded; the drop still queues
|
|
1150
|
+
}
|
|
1123
1151
|
function ingestInboxEntry(entry, source) {
|
|
1124
1152
|
const waiters = takeWaitersFor(entry.tag);
|
|
1125
1153
|
if (waiters.length > 0) {
|
|
@@ -1303,6 +1331,14 @@ function telegramContext(msg) {
|
|
|
1303
1331
|
// NULL-OK: field replied is OPTIONAL and therefore it is ok to check for NULL
|
|
1304
1332
|
if (replied !== undefined)
|
|
1305
1333
|
lines.push(`He is replying to this earlier message in the chat: «${replied.slice(0, 800)}»`);
|
|
1334
|
+
const sender = msg.from;
|
|
1335
|
+
// NULL-OK: field sender is OPTIONAL and therefore it is ok to check for NULL
|
|
1336
|
+
if (sender !== undefined) {
|
|
1337
|
+
const name = [sender.first_name, sender.last_name].filter((part) => typeof part === "string" && part.length > 0).join(" ");
|
|
1338
|
+
const username = typeof sender.username === "string" && sender.username.length > 0 ? ` @${sender.username}` : "";
|
|
1339
|
+
const senderId = sender.id === undefined ? "" : ` (id ${String(sender.id)})`;
|
|
1340
|
+
lines.push(`Telegram sender: ${name || "unnamed"}${username}${senderId}`);
|
|
1341
|
+
}
|
|
1306
1342
|
return [...lines, ...openAsksContext()];
|
|
1307
1343
|
}
|
|
1308
1344
|
/** Every question another session waits on, told to the one chat's conversation so it can pass his answer on. */
|
|
@@ -1325,6 +1361,19 @@ function toOneChat(key, platform, act, messenger) {
|
|
|
1325
1361
|
log("→", trail, `NOT DELIVERED to ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1326
1362
|
});
|
|
1327
1363
|
}
|
|
1364
|
+
function isWorkingProbe(text) {
|
|
1365
|
+
return /^(?:!\s*)?working\?$/i.test(text.trim());
|
|
1366
|
+
}
|
|
1367
|
+
async function answerWorkingProbe(key, platform, reply) {
|
|
1368
|
+
const status = await AgentGateway.instance().workingStatus(key, platform);
|
|
1369
|
+
await reply(status);
|
|
1370
|
+
}
|
|
1371
|
+
async function answerSlackThreadProbe(token, channel, threadTs, ts) {
|
|
1372
|
+
if (!firstRouting(channel, ts))
|
|
1373
|
+
return;
|
|
1374
|
+
const view = slackChannelChat(token, channel).inThread(threadTs);
|
|
1375
|
+
await answerWorkingProbe(`slack:${channel}:${threadTs}`, "slack", (part) => view.send(part));
|
|
1376
|
+
}
|
|
1328
1377
|
/** One update of the bot: a message of the bound chat, or a tap on one of its buttons. */
|
|
1329
1378
|
async function takeTelegramUpdate(token, update) {
|
|
1330
1379
|
const chatIds = loadConfig().telegram?.chatIds ?? [];
|
|
@@ -1375,6 +1424,11 @@ async function takeTelegramUpdate(token, update) {
|
|
|
1375
1424
|
log("←", "telegram", saved === undefined ? text : `${text} [file ${saved}]`);
|
|
1376
1425
|
// A message written inside a topic is never the plain chat's last inbound, so a later plain notification never replies into that topic.
|
|
1377
1426
|
noteTelegramInbound(msg.message_id, chat, Date.now(), thread !== undefined);
|
|
1427
|
+
if (typeof msg.text === "string" && isWorkingProbe(text)) {
|
|
1428
|
+
const key = thread === undefined ? `telegram:${chat}` : `telegram:${chat}:${thread}`;
|
|
1429
|
+
await answerWorkingProbe(key, "telegram", (part) => telegramMessenger(token, chat, thread, msg.message_id).alongside().send(part));
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1378
1432
|
if (/^\/start(@\w+)?$/i.test(text.trim())) {
|
|
1379
1433
|
await messenger.send(TELEGRAM_WELCOME);
|
|
1380
1434
|
return;
|
|
@@ -1587,14 +1641,18 @@ async function startTelegramListener() {
|
|
|
1587
1641
|
tgLastErrorCount = 0;
|
|
1588
1642
|
}
|
|
1589
1643
|
for (const update of updates) {
|
|
1590
|
-
POLL_CURSORS.set(cursorKey, String(update.update_id));
|
|
1591
|
-
tgPollOffset = update.update_id + 1;
|
|
1592
1644
|
tgLastUpdateAt = Date.now();
|
|
1645
|
+
let acted = true;
|
|
1593
1646
|
await takeTelegramUpdate(token, update).catch((err) => {
|
|
1594
|
-
|
|
1647
|
+
acted = false;
|
|
1648
|
+
// OWNER: ITER/LOOP — one update that cannot be acted on is logged with its reason and remains pending for retry before later updates are read.
|
|
1595
1649
|
const classified = err instanceof TelegramRefused || err instanceof TelegramUnreachable || err instanceof TelegramUnknown;
|
|
1596
1650
|
log("·", "telegram", `update ${update.update_id} was not acted on, its reply NOT DELIVERED: ${err instanceof Error ? err.message : String(err)}${classified || !(err instanceof Error) ? "" : `\n${err.stack}`}`);
|
|
1597
1651
|
});
|
|
1652
|
+
if (!acted)
|
|
1653
|
+
break;
|
|
1654
|
+
POLL_CURSORS.set(cursorKey, String(update.update_id));
|
|
1655
|
+
tgPollOffset = update.update_id + 1;
|
|
1598
1656
|
}
|
|
1599
1657
|
}
|
|
1600
1658
|
catch (err) {
|
|
@@ -2198,6 +2256,11 @@ async function answerSlackAgentMessage(token, channel, m, owner) {
|
|
|
2198
2256
|
}
|
|
2199
2257
|
const stripped = text.replace(/<@[A-Za-z0-9]+>/g, "");
|
|
2200
2258
|
const key = `slack:${channel}:${m.ts}`;
|
|
2259
|
+
if (isWorkingProbe(stripped)) {
|
|
2260
|
+
log("←", "agent:slack", text);
|
|
2261
|
+
await answerWorkingProbe(slackDmKey(channel, undefined), "slack", (part) => slackPostInThread(token, channel, String(m.ts), part));
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2201
2264
|
const gateway = AgentGateway.instance();
|
|
2202
2265
|
const act = await gateway.classified(() => gateway.classify(key, stripped), (part) => slackPostInThread(token, channel, String(m.ts), part));
|
|
2203
2266
|
if (act === "answered")
|
|
@@ -2220,6 +2283,11 @@ async function pollAgentThreads(token, owner, threads) {
|
|
|
2220
2283
|
throw new Error(`conversations.replies: ${json.error ?? "unknown"}`);
|
|
2221
2284
|
const fresh = (json.messages ?? []).filter((m) => Number(m.ts) > Number(readTs)).sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
2222
2285
|
for (const m of fresh) {
|
|
2286
|
+
if (isHumanSlackMessage(m) && m.user === owner && isWorkingProbe(slackPlain(String(m.text))) && String(m.ts) !== threadTs) {
|
|
2287
|
+
await answerSlackThreadProbe(token, channel, threadTs, String(m.ts));
|
|
2288
|
+
await gateway.markSlackRead(c.chat, String(m.ts));
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2223
2291
|
await gateway.markSlackRead(c.chat, String(m.ts));
|
|
2224
2292
|
if (!isHumanSlackMessage(m))
|
|
2225
2293
|
continue;
|
|
@@ -2285,10 +2353,10 @@ async function routeSlackInbox(m, reply) {
|
|
|
2285
2353
|
async function pollSlackOnce(token, channel) {
|
|
2286
2354
|
const cursor = slackBusCursor(channel);
|
|
2287
2355
|
const reply = (text) => slackBusReply(token, channel, text);
|
|
2288
|
-
const json = await slackCall(SLACK_API_BASE, token, `conversations.history?channel=${encodeURIComponent(channel)}&
|
|
2356
|
+
const json = await slackCall(SLACK_API_BASE, token, `conversations.history?channel=${encodeURIComponent(channel)}&limit=50`, {});
|
|
2289
2357
|
const all = json.messages ?? [];
|
|
2290
2358
|
const human = all
|
|
2291
|
-
.filter(m =>
|
|
2359
|
+
.filter(m => Number(m.ts) > Number(cursor.value) && isHumanSlackMessage(m))
|
|
2292
2360
|
.sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
2293
2361
|
const isAsk = (m) => String(m.text ?? "").replace(/<@[A-Za-z0-9]+>/g, "").toLowerCase().trim().startsWith(AGENT_PREFIX);
|
|
2294
2362
|
// Every message meant for the agent — his own words and a '!'-prefixed ask — not bus commands or a message addressed to a connected client.
|
|
@@ -2340,6 +2408,19 @@ async function pollSlackOnce(token, channel) {
|
|
|
2340
2408
|
}
|
|
2341
2409
|
}
|
|
2342
2410
|
cursor.moveTo(all.reduce((acc, m) => (Number(m.ts) > Number(acc) ? String(m.ts) : acc), cursor.value));
|
|
2411
|
+
const threadReplies = slackThreadsWithReplies(channel, all, slackChannelProbesFrom);
|
|
2412
|
+
if (threadReplies.length > 0 && human.length === 0)
|
|
2413
|
+
await findOwner();
|
|
2414
|
+
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2415
|
+
if (owner !== undefined) {
|
|
2416
|
+
const authorized = owner;
|
|
2417
|
+
for (const threadTs of threadReplies) {
|
|
2418
|
+
await readSlackThread(token, channel, threadTs, async (m) => {
|
|
2419
|
+
if (m.user === authorized && isWorkingProbe(slackPlain(String(m.text))))
|
|
2420
|
+
await answerSlackThreadProbe(token, channel, threadTs, String(m.ts));
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2343
2424
|
try {
|
|
2344
2425
|
const threads = await AgentGateway.instance().openSlackThreads();
|
|
2345
2426
|
if (threads.length > 0 && human.length === 0)
|
|
@@ -2400,7 +2481,8 @@ function cursorPast(cursor, ts) {
|
|
|
2400
2481
|
}
|
|
2401
2482
|
/** The place the poll has read to in one thread of the direct message (#4585), kept across restarts. */
|
|
2402
2483
|
const SLACK_THREAD_CURSOR = "slack-dm-thread:";
|
|
2403
|
-
const
|
|
2484
|
+
const slackChannelProbesFrom = Date.now() / 1000;
|
|
2485
|
+
const slackThreadCursor = (channel, threadTs, after = Number(threadTs)) => POLL_CURSORS.cursor(`${SLACK_THREAD_CURSOR}${channel}:${threadTs}`, () => String(Math.max(Number(threadTs), after)));
|
|
2404
2486
|
/** The direct-message chat of each bot token, opened once per process. */
|
|
2405
2487
|
const slackDms = new Map();
|
|
2406
2488
|
/** Why the direct message cannot be read with this bot token; it is not tried again until the token changes or BN restarts. */
|
|
@@ -2476,6 +2558,11 @@ async function takeSlackDmMessage(dm, owner, m, threadTs) {
|
|
|
2476
2558
|
const view = threadTs === undefined ? dm : slackDmThread(dm, threadTs);
|
|
2477
2559
|
const text = slackPlain(String(m.text));
|
|
2478
2560
|
log("←", "agent:slack", text);
|
|
2561
|
+
if (isWorkingProbe(text)) {
|
|
2562
|
+
const target = threadTs === String(m.ts) ? slackDmKey(dm.channel, undefined) : key;
|
|
2563
|
+
await answerWorkingProbe(target, "slack", (part) => view.send(part));
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2479
2566
|
const picked = view.choiceFor(text);
|
|
2480
2567
|
// NULL-OK: field picked is OPTIONAL and therefore it is ok to check for NULL
|
|
2481
2568
|
const providerCmd = picked === undefined ? text.trim().match(PROVIDER_COMMAND) : null;
|
|
@@ -2514,7 +2601,8 @@ async function pollSlackDm(token) {
|
|
|
2514
2601
|
await takeSlackDmMessage(dm, owner, m, threaded ? String(m.ts) : undefined);
|
|
2515
2602
|
}
|
|
2516
2603
|
SLACK_DM_CURSOR.moveTo(newTop.reduce((acc, m) => (Number(m.ts) > Number(acc) ? String(m.ts) : acc), SLACK_DM_CURSOR.value));
|
|
2517
|
-
|
|
2604
|
+
for (const threadTs of slackThreadsWithReplies(dm.channel, all))
|
|
2605
|
+
await readSlackDmThread(token, dm, owner, threadTs);
|
|
2518
2606
|
if (threaded && Date.now() - slackThreadsReadAt >= SLACK_LIVE_POLL_MS) {
|
|
2519
2607
|
slackThreadsReadAt = Date.now();
|
|
2520
2608
|
await pollSlackDmThreads(token, dm, owner);
|
|
@@ -2537,44 +2625,49 @@ const SLACK_THREAD_KEPT_MS = 7 * 24 * 3_600_000;
|
|
|
2537
2625
|
* Reads one thread of the direct message from its cursor: each new reply of his goes on in that thread's conversation. A thread Slack
|
|
2538
2626
|
* will not read is named once per reason; one whose parent message is gone is let go.
|
|
2539
2627
|
*/
|
|
2540
|
-
async function readSlackThread(token,
|
|
2541
|
-
const
|
|
2628
|
+
async function readSlackThread(token, channel, threadTs, take) {
|
|
2629
|
+
const key = `${channel}:${threadTs}`;
|
|
2630
|
+
const cursor = slackThreadCursor(channel, threadTs);
|
|
2542
2631
|
let read;
|
|
2543
2632
|
try {
|
|
2544
|
-
read = await slackCall(SLACK_API_BASE, token, "conversations.replies", { channel
|
|
2545
|
-
slackThreadUnread.delete(
|
|
2633
|
+
read = await slackCall(SLACK_API_BASE, token, "conversations.replies", { channel, ts: threadTs, oldest: cursor.value, limit: 100 });
|
|
2634
|
+
slackThreadUnread.delete(key);
|
|
2546
2635
|
}
|
|
2547
2636
|
catch (err) {
|
|
2548
2637
|
if (!(err instanceof SlackRefused) && !(err instanceof SlackUnknown) && !(err instanceof SlackUnreachable))
|
|
2549
2638
|
throw err;
|
|
2550
2639
|
// OWNER: ITER/LOOP — one thread Slack will not read now is named once per reason and the next thread is still read; a thread whose parent is gone has its cursor let go.
|
|
2551
|
-
if (slackThreadUnread.get(
|
|
2552
|
-
log("·", "slack:error", `thread ${
|
|
2553
|
-
slackThreadUnread.set(
|
|
2640
|
+
if (slackThreadUnread.get(key) !== err.message)
|
|
2641
|
+
log("·", "slack:error", `Slack thread ${key} was not read: ${err.message}`);
|
|
2642
|
+
slackThreadUnread.set(key, err.message);
|
|
2554
2643
|
if (err instanceof SlackRefused && err.error === "thread_not_found") {
|
|
2555
|
-
slackThreadsGone.add(
|
|
2556
|
-
POLL_CURSORS.delete(`${SLACK_THREAD_CURSOR}${
|
|
2644
|
+
slackThreadsGone.add(key);
|
|
2645
|
+
POLL_CURSORS.delete(`${SLACK_THREAD_CURSOR}${key}`);
|
|
2557
2646
|
}
|
|
2558
2647
|
return;
|
|
2559
2648
|
}
|
|
2560
2649
|
const replies = (read.messages ?? []).filter((m) => String(m.ts) !== threadTs && Number(m.ts) > Number(cursor.value));
|
|
2561
2650
|
for (const m of replies.filter(isHumanSlackMessage).sort((a, b) => Number(a.ts) - Number(b.ts))) {
|
|
2562
2651
|
cursorPast(cursor, String(m.ts));
|
|
2563
|
-
|
|
2564
|
-
await takeSlackDmMessage(dm, owner, m, threadTs);
|
|
2652
|
+
await take(m);
|
|
2565
2653
|
}
|
|
2566
2654
|
for (const m of replies)
|
|
2567
2655
|
cursorPast(cursor, String(m.ts));
|
|
2568
2656
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2657
|
+
async function readSlackDmThread(token, dm, owner, threadTs) {
|
|
2658
|
+
await readSlackThread(token, dm.channel, threadTs, async (m) => {
|
|
2659
|
+
if (firstRouting(dm.channel, String(m.ts)))
|
|
2660
|
+
await takeSlackDmMessage(dm, owner, m, threadTs);
|
|
2661
|
+
});
|
|
2662
|
+
}
|
|
2663
|
+
/** The history marks a thread's parent with `latest_reply`, so a thread with nothing new costs no call. */
|
|
2664
|
+
function slackThreadsWithReplies(channel, recent, after) {
|
|
2665
|
+
return recent
|
|
2572
2666
|
.filter((m) => m.thread_ts !== undefined && String(m.thread_ts) === String(m.ts) && m.latest_reply !== undefined)
|
|
2573
2667
|
.filter((m) => Date.now() - Number(m.latest_reply) * 1000 < SLACK_THREAD_READ_MS)
|
|
2574
|
-
.filter((m) => !slackThreadsGone.has(`${
|
|
2575
|
-
.filter((m) => Number(m.latest_reply) > Number(slackThreadCursor(
|
|
2576
|
-
|
|
2577
|
-
await readSlackThread(token, dm, owner, String(m.ts));
|
|
2668
|
+
.filter((m) => !slackThreadsGone.has(`${channel}:${m.ts}`))
|
|
2669
|
+
.filter((m) => Number(m.latest_reply) > Number(slackThreadCursor(channel, String(m.ts), after).value))
|
|
2670
|
+
.map((m) => String(m.ts));
|
|
2578
2671
|
}
|
|
2579
2672
|
/**
|
|
2580
2673
|
* Reads the threads of the direct message whose conversation spoke in the last day, newest first: each new reply of his goes on in
|
|
@@ -2591,7 +2684,7 @@ async function pollSlackDmThreads(token, dm, owner) {
|
|
|
2591
2684
|
const threads = [...day.slice(start), ...day.slice(0, start)].slice(0, SLACK_THREADS_A_PASS);
|
|
2592
2685
|
slackThreadTurn = start + threads.length;
|
|
2593
2686
|
for (const threadTs of threads)
|
|
2594
|
-
await
|
|
2687
|
+
await readSlackDmThread(token, dm, owner, threadTs);
|
|
2595
2688
|
const tooOld = Date.now() / 1000 - SLACK_THREAD_KEPT_MS / 1000;
|
|
2596
2689
|
for (const key of POLL_CURSORS.keys())
|
|
2597
2690
|
if (key.startsWith(`${SLACK_THREAD_CURSOR}${dm.channel}:`) && Number(key.split(":").pop()) < tooOld)
|
|
@@ -492,7 +492,7 @@ class ServedWebview {
|
|
|
492
492
|
* message runs under. `saidOnce` says a failure that persists across the watch's ticks is told to this browser once.
|
|
493
493
|
*/
|
|
494
494
|
viewerOf(socket) {
|
|
495
|
-
const viewer = { search: socket.at, base: socket.base, signal: socket.viewLife.signal, post: (message) => postTo([socket], message, this.served) };
|
|
495
|
+
const viewer = { search: socket.at, base: socket.base, ownerApproved: socket.ownerApproved === true, signal: socket.viewLife.signal, post: (message) => postTo([socket], message, this.served) };
|
|
496
496
|
viewer.guard = (work, options = {}) => this.guarded(socket, viewer, work, options.saidOnce === true);
|
|
497
497
|
return viewer;
|
|
498
498
|
}
|
|
@@ -1133,6 +1133,18 @@ class WebHost {
|
|
|
1133
1133
|
socket.end("HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n");
|
|
1134
1134
|
return;
|
|
1135
1135
|
}
|
|
1136
|
+
if (this.screenOwnerProved) {
|
|
1137
|
+
try {
|
|
1138
|
+
socket.ownerApproved = this.screenOwnerProved(request, this.port);
|
|
1139
|
+
}
|
|
1140
|
+
catch (err) {
|
|
1141
|
+
if (!(err instanceof Error))
|
|
1142
|
+
throw err;
|
|
1143
|
+
console.error("Screen owner proof refused:", err.message);
|
|
1144
|
+
socket.end("HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n");
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1136
1148
|
socket.base = base;
|
|
1137
1149
|
const accept = crypto.createHash("sha1").update(key + WS_GUID).digest("base64");
|
|
1138
1150
|
socket.write(`HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ${accept}\r\n\r\n`);
|
|
@@ -1179,6 +1191,7 @@ class ServiceHost extends WebHost {
|
|
|
1179
1191
|
this.listed = options.workspaces;
|
|
1180
1192
|
this.current = options.currentOf;
|
|
1181
1193
|
this.machine = options.machine === true;
|
|
1194
|
+
this.screenOwnerProved = options.screenOwnerProved;
|
|
1182
1195
|
}
|
|
1183
1196
|
/** Takes the page requests and sockets of `server`, which already listens on `port` for the service. */
|
|
1184
1197
|
answerOn(server, port) {
|
|
@@ -1247,32 +1260,32 @@ function indexPage(host, base) {
|
|
|
1247
1260
|
const rows = [...host.pages.values()]
|
|
1248
1261
|
.map((page) => `<li><a href="${escapeAttribute(base === undefined ? page.url : `${base}/${encodeURIComponent(page.name)}/${page.search}`)}">${page.live ? "🟢" : "⚪"} ${escapeAttribute(page.title)}</a></li>`)
|
|
1249
1262
|
.join("");
|
|
1250
|
-
return `<!DOCTYPE html><html><head><meta charset="utf-8">${PHONE_VIEWPORT}<title>${escapeAttribute(host.extension)}</title></head>
|
|
1263
|
+
return `<!DOCTYPE html><html><head><meta charset="utf-8">${PHONE_VIEWPORT}<title>${escapeAttribute(host.extension)}</title></head>
|
|
1251
1264
|
<body style="font:14px system-ui,sans-serif;padding:24px;background:#1e1e1e;color:#ccc"><div>${escapeAttribute(host.extension)} · ${escapeAttribute(host.label)}</div><ul>${rows}</ul></body></html>`;
|
|
1252
1265
|
}
|
|
1253
1266
|
function closedPage(extension, page) {
|
|
1254
|
-
return `<!DOCTYPE html><html><head><meta charset="utf-8">${PHONE_VIEWPORT}<title>${escapeAttribute(extension)} · ${escapeAttribute(page.title)}</title></head>
|
|
1255
|
-
<body style="font:14px system-ui,sans-serif;padding:24px;background:#1e1e1e;color:#ccc">⚪ ${escapeAttribute(page.title)} is not open in VS Code right now, so there is nothing to show here — this page loads it the moment it opens.<div id="said" style="margin-top:8px"></div>
|
|
1256
|
-
<script>${CONNECTION_SOURCE}</script><script>(function () {
|
|
1257
|
-
var WHAT = "this page's live connection to its host";
|
|
1258
|
-
var kept = window.bullseyeConnection.keep({
|
|
1259
|
-
what: WHAT, path: "/__bullseye/health",
|
|
1260
|
-
open: function () { return new WebSocket((location.protocol === "https:" ? "wss:" : "ws:") + "//" + location.host + "/__bullseye/ws?page=${encodeURIComponent(page.name)}"); },
|
|
1261
|
-
attach: function (connect, later) {
|
|
1262
|
-
fetch("/__bullseye/health", { cache: "no-store", signal: AbortSignal.timeout(8000) }).then(function (r) {
|
|
1263
|
-
if (r.ok) connect(); else if (r.status === 401) window.bullseyeConnection.signInAgain(); else later();
|
|
1264
|
-
}, later);
|
|
1265
|
-
},
|
|
1266
|
-
opened: function () {
|
|
1267
|
-
document.getElementById("said").textContent = "";
|
|
1268
|
-
fetch("/__bullseye/health", { cache: "no-store" }).then(function (r) { return r.json(); }).then(function (health) { if (health.pages[${JSON.stringify(page.name)}].live) location.reload(); }, function (error) { console.warn("[Bullseye connection] Page availability unread: " + error.message); });
|
|
1269
|
-
},
|
|
1270
|
-
message: function (socket, event) { if (JSON.parse(String(event.data)).type === "reload") location.reload(); },
|
|
1271
|
-
down: function () { document.getElementById("said").textContent = "⏳ Reconnecting"; },
|
|
1272
|
-
closed: function () { return false; },
|
|
1273
|
-
ping: function (socket) { socket.send('{"type":"ping"}'); }
|
|
1274
|
-
});
|
|
1275
|
-
kept.connect();
|
|
1267
|
+
return `<!DOCTYPE html><html><head><meta charset="utf-8">${PHONE_VIEWPORT}<title>${escapeAttribute(extension)} · ${escapeAttribute(page.title)}</title></head>
|
|
1268
|
+
<body style="font:14px system-ui,sans-serif;padding:24px;background:#1e1e1e;color:#ccc">⚪ ${escapeAttribute(page.title)} is not open in VS Code right now, so there is nothing to show here — this page loads it the moment it opens.<div id="said" style="margin-top:8px"></div>
|
|
1269
|
+
<script>${CONNECTION_SOURCE}</script><script>(function () {
|
|
1270
|
+
var WHAT = "this page's live connection to its host";
|
|
1271
|
+
var kept = window.bullseyeConnection.keep({
|
|
1272
|
+
what: WHAT, path: "/__bullseye/health",
|
|
1273
|
+
open: function () { return new WebSocket((location.protocol === "https:" ? "wss:" : "ws:") + "//" + location.host + "/__bullseye/ws?page=${encodeURIComponent(page.name)}"); },
|
|
1274
|
+
attach: function (connect, later) {
|
|
1275
|
+
fetch("/__bullseye/health", { cache: "no-store", signal: AbortSignal.timeout(8000) }).then(function (r) {
|
|
1276
|
+
if (r.ok) connect(); else if (r.status === 401) window.bullseyeConnection.signInAgain(); else later();
|
|
1277
|
+
}, later);
|
|
1278
|
+
},
|
|
1279
|
+
opened: function () {
|
|
1280
|
+
document.getElementById("said").textContent = "";
|
|
1281
|
+
fetch("/__bullseye/health", { cache: "no-store" }).then(function (r) { return r.json(); }).then(function (health) { if (health.pages[${JSON.stringify(page.name)}].live) location.reload(); }, function (error) { console.warn("[Bullseye connection] Page availability unread: " + error.message); });
|
|
1282
|
+
},
|
|
1283
|
+
message: function (socket, event) { if (JSON.parse(String(event.data)).type === "reload") location.reload(); },
|
|
1284
|
+
down: function () { document.getElementById("said").textContent = "⏳ Reconnecting"; },
|
|
1285
|
+
closed: function () { return false; },
|
|
1286
|
+
ping: function (socket) { socket.send('{"type":"ping"}'); }
|
|
1287
|
+
});
|
|
1288
|
+
kept.connect();
|
|
1276
1289
|
})();</script></body></html>`;
|
|
1277
1290
|
}
|
|
1278
1291
|
function codeDefect(err) {
|
|
@@ -29,7 +29,7 @@ function run(file, args) {
|
|
|
29
29
|
if (failed === null)
|
|
30
30
|
resolve(out);
|
|
31
31
|
else
|
|
32
|
-
reject(failed.killed ? new OsCallTimedOut(callFailed(file, args, failed, err).message) : callFailed(file, args, failed, err));
|
|
32
|
+
reject(failed.killed ? new OsCallTimedOut(callFailed(file, args, failed, err).message) : Object.assign(callFailed(file, args, failed, err), { exitCode: failed.code }));
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -46,9 +46,10 @@ async function runRepeatable(file, args) {
|
|
|
46
46
|
await new Promise((resolve) => setTimeout(resolve, 1_000 * tried));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
/** The
|
|
50
|
-
const sessionQuery = () => [path.join(system32(), "
|
|
51
|
-
|
|
49
|
+
/** The quser query whose rows are the logon sessions on this machine, console, remote desktop and disconnected alike; an ssh-only box has none, because its ssh logons run in session 0. It replaces a tasklist USERNAME filter, which opens every process's owner and does not return under the Least-privilege token on a busy box. */
|
|
50
|
+
const sessionQuery = () => [path.join(system32(), "quser.exe"), []];
|
|
51
|
+
/** Whether quser's rows name a logon session of this account — "No User exists" (exit 1, no rows) is none. */
|
|
52
|
+
const listsThisAccount = (rows) => rows.split(/\r?\n/).slice(1).some((row) => row.replace(/^[\s>]+/, "").split(/\s+/)[0].toLowerCase() === os.userInfo().username.toLowerCase());
|
|
52
53
|
/** The tasklist query of this process's own row, which any token may read: the account's USERNAME filter opens every process's owner and does not return under the login session's own Least-privilege token. */
|
|
53
54
|
const ownRowQuery = () => [path.join(system32(), "tasklist.exe"), ["/fi", `PID eq ${process.pid}`, "/fo", "csv", "/nh"]];
|
|
54
55
|
/** The Windows session in this process's own tasklist row. */
|
|
@@ -66,7 +67,14 @@ async function userSessionOpen() {
|
|
|
66
67
|
if (sessionIn(await runRepeatable(own, ownArgs)) !== 0)
|
|
67
68
|
return true;
|
|
68
69
|
const [file, args] = sessionQuery();
|
|
69
|
-
|
|
70
|
+
try {
|
|
71
|
+
return listsThisAccount(await runRepeatable(file, args));
|
|
72
|
+
}
|
|
73
|
+
catch (failed) {
|
|
74
|
+
if (failed.exitCode === 1)
|
|
75
|
+
return false;
|
|
76
|
+
throw failed;
|
|
77
|
+
}
|
|
70
78
|
}
|
|
71
79
|
/** userSessionOpen, for a caller that cannot wait on the event loop. */
|
|
72
80
|
function userSessionOpenSync() {
|
|
@@ -75,19 +83,26 @@ function userSessionOpenSync() {
|
|
|
75
83
|
const call = ([file, args]) => execFileSync(file, args, { windowsHide: true, encoding: "utf8", timeout: OS_CALL_MS });
|
|
76
84
|
if (sessionIn(call(ownRowQuery())) !== 0)
|
|
77
85
|
return true;
|
|
78
|
-
|
|
86
|
+
try {
|
|
87
|
+
return listsThisAccount(call(sessionQuery()));
|
|
88
|
+
}
|
|
89
|
+
catch (failed) {
|
|
90
|
+
if (failed.status === 1)
|
|
91
|
+
return false;
|
|
92
|
+
throw failed;
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
const xmlText = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
81
96
|
const quoted = (part) => (/[\s"]/.test(part) ? `"${part.replace(/"/g, '\\"')}"` : part);
|
|
82
97
|
/** The task's definition: the account's interactive token at the Least-privilege run level and Normal priority — the default below-normal priority leaves a program it starts unscheduled on a busy box — no trigger; the program runs under a headless console host, so a console program draws no window. A definition file, never /tr, because /tr stops at 261 characters. */
|
|
83
98
|
function taskXml(user, file, args) {
|
|
84
|
-
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
85
|
-
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
86
|
-
<RegistrationInfo><Description>Starts a Bullseye program in the logged-on user's own session, from a resident server that runs with no window.</Description></RegistrationInfo>
|
|
87
|
-
<Principals><Principal id="Author"><UserId>${xmlText(user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>
|
|
88
|
-
<Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><Priority>4</Priority><Enabled>true</Enabled></Settings>
|
|
89
|
-
<Actions Context="Author"><Exec><Command>${xmlText(path.join(system32(), "conhost.exe"))}</Command><Arguments>${xmlText(["--headless", file, ...args].map(quoted).join(" "))}</Arguments></Exec></Actions>
|
|
90
|
-
</Task>
|
|
99
|
+
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
100
|
+
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
101
|
+
<RegistrationInfo><Description>Starts a Bullseye program in the logged-on user's own session, from a resident server that runs with no window.</Description></RegistrationInfo>
|
|
102
|
+
<Principals><Principal id="Author"><UserId>${xmlText(user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>
|
|
103
|
+
<Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><Priority>4</Priority><Enabled>true</Enabled></Settings>
|
|
104
|
+
<Actions Context="Author"><Exec><Command>${xmlText(path.join(system32(), "conhost.exe"))}</Command><Arguments>${xmlText(["--headless", file, ...args].map(quoted).join(" "))}</Arguments></Exec></Actions>
|
|
105
|
+
</Task>
|
|
91
106
|
`;
|
|
92
107
|
}
|
|
93
108
|
let launches = 0;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { execFile } = require("child_process");
|
|
3
3
|
const crypto = require("crypto");
|
|
4
4
|
const fs = require("fs");
|
|
5
|
+
const { isIP } = require("net");
|
|
5
6
|
const os = require("os");
|
|
6
7
|
const path = require("path");
|
|
7
8
|
/** #3849 — the BullseyeVSC checkout, which owns every Bullseye service and holds the one workspace list they all read. */
|
|
@@ -13,7 +14,7 @@ const CHECKOUT = {
|
|
|
13
14
|
listFile: () => path.join(vscRoot(), "workspaces.json"),
|
|
14
15
|
noList: (file) => `the BullseyeVSC checkout holds no workspace list (${file}) — pull BullseyeVSC, or add the folders on Bullseye Control`,
|
|
15
16
|
settingsFileOf: (listed, tool) => path.join(listed.root, ".bullseye", "settings", `${tool}.json`),
|
|
16
|
-
publish:
|
|
17
|
+
publish: publishFile,
|
|
17
18
|
toolHome: () => vscRoot(),
|
|
18
19
|
homeFileOf: () => undefined,
|
|
19
20
|
holdsToolHome: () => workspacesHere().some((w) => sameRoot(w.root, vscRoot())),
|
|
@@ -28,8 +29,17 @@ const LOCAL = {
|
|
|
28
29
|
homeFileOf: (root, tool) => (sameRoot(root, LOCAL.toolHome()) ? path.join(LOCAL.toolHome(), "settings", `${tool}.json`) : undefined),
|
|
29
30
|
holdsToolHome: () => true,
|
|
30
31
|
};
|
|
32
|
+
/** #4827 — what one event-loop turn has already read: the server asks for the list on every settings call, and each ask cost an existsSync and a statSync per listed root. Dropped at the next turn, and by a save. */
|
|
33
|
+
let turn;
|
|
34
|
+
function workspaceTurn() {
|
|
35
|
+
if (turn === undefined) {
|
|
36
|
+
turn = { store: fs.existsSync(vscRoot()) ? CHECKOUT : LOCAL, list: undefined };
|
|
37
|
+
setImmediate(() => { turn = undefined; }).unref();
|
|
38
|
+
}
|
|
39
|
+
return turn;
|
|
40
|
+
}
|
|
31
41
|
function store() {
|
|
32
|
-
return
|
|
42
|
+
return workspaceTurn().store;
|
|
33
43
|
}
|
|
34
44
|
/** #3849 — the root a machine-wide tool (BS, BU) keeps its own settings under: the BullseyeVSC checkout, or ~/.bullseye on a box without one. Its readSettings, writeSettings and publishSettings take this root like a workspace's. */
|
|
35
45
|
function toolHome() {
|
|
@@ -71,7 +81,22 @@ function nameKey(entry) {
|
|
|
71
81
|
return path.basename(homeRelative(entry) ? entry : path.resolve(entry)).toLowerCase();
|
|
72
82
|
}
|
|
73
83
|
function listedWorkspaces() {
|
|
74
|
-
const
|
|
84
|
+
const current = workspaceTurn();
|
|
85
|
+
if (current.list === undefined) {
|
|
86
|
+
try {
|
|
87
|
+
current.list = { entries: readListed(current.store.listFile()) };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (!(error instanceof SyntaxError))
|
|
91
|
+
throw error;
|
|
92
|
+
current.list = { error };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if ("error" in current.list)
|
|
96
|
+
throw current.list.error;
|
|
97
|
+
return current.list.entries.map((entry) => ({ ...entry }));
|
|
98
|
+
}
|
|
99
|
+
function readListed(file) {
|
|
75
100
|
let text;
|
|
76
101
|
try {
|
|
77
102
|
text = fs.readFileSync(file, "utf8");
|
|
@@ -110,6 +135,7 @@ function listedWorkspaces() {
|
|
|
110
135
|
return { label: present ? labelOf(root) : path.basename(root), root, path: entry.path, present };
|
|
111
136
|
});
|
|
112
137
|
}
|
|
138
|
+
/** @returns {{ label: string, root: string }[]} The named workspaces available on this machine. */
|
|
113
139
|
function workspacesHere() {
|
|
114
140
|
return listedWorkspaces().filter((w) => w.present).map(({ label, root }) => ({ label, root }));
|
|
115
141
|
}
|
|
@@ -139,7 +165,12 @@ function saveWorkspaces(folders) {
|
|
|
139
165
|
entries.push({ path: entry });
|
|
140
166
|
}
|
|
141
167
|
const file = workspacesFile();
|
|
142
|
-
underLock(file, () =>
|
|
168
|
+
underLock(file, () => writeWorkspaceList(file, listText(entries)));
|
|
169
|
+
}
|
|
170
|
+
function writeWorkspaceList(file, text) {
|
|
171
|
+
writeAtomically(file, text);
|
|
172
|
+
if (turn !== undefined)
|
|
173
|
+
turn.list = undefined;
|
|
143
174
|
}
|
|
144
175
|
function listText(entries) {
|
|
145
176
|
return `${JSON.stringify({ workspaces: entries }, null, 2)}\n`;
|
|
@@ -168,8 +199,24 @@ function settingsFile(root, tool) {
|
|
|
168
199
|
const listed = workspacesHere().find((w) => sameRoot(w.root, root));
|
|
169
200
|
if (listed === undefined)
|
|
170
201
|
throw new WorkspaceNotListed(`${root} is not a workspace on this machine's list (${workspacesFile()}) — settings are kept only for a listed workspace`);
|
|
202
|
+
if (tool === "da" && sameRoot(root, vscRoot()))
|
|
203
|
+
return localDeepAgentFile(CHECKOUT.settingsFileOf(listed, tool));
|
|
171
204
|
return store().settingsFileOf(listed, tool);
|
|
172
205
|
}
|
|
206
|
+
/** Keep the existing settings and sign-ins through the checkout's removal of its legacy da.json. */
|
|
207
|
+
function localDeepAgentFile(legacy) {
|
|
208
|
+
const local = path.join(LOCAL.toolHome(), "settings", "da.json");
|
|
209
|
+
if (fs.existsSync(local) || !fs.existsSync(legacy))
|
|
210
|
+
return local;
|
|
211
|
+
underLock(local, () => {
|
|
212
|
+
if (bytesOf(local) !== undefined)
|
|
213
|
+
return;
|
|
214
|
+
const old = bytesOf(legacy);
|
|
215
|
+
if (old !== undefined)
|
|
216
|
+
writeAtomically(local, serialized(parsedSettings(legacy, old.toString("utf8"))));
|
|
217
|
+
});
|
|
218
|
+
return local;
|
|
219
|
+
}
|
|
173
220
|
const digest = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
|
174
221
|
/** #3849 — the part of `tool`'s settings that belongs to this box alone (a login it signed in with itself): kept in its own ~/.bullseye/settings, never published and never merged, so no other box's copy can replace it. */
|
|
175
222
|
function boxFile(root, tool) {
|
|
@@ -331,7 +378,7 @@ function writeAtomically(file, text) {
|
|
|
331
378
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
332
379
|
const staged = `${file}.${process.pid}.tmp`;
|
|
333
380
|
try {
|
|
334
|
-
fs.writeFileSync(staged, text);
|
|
381
|
+
fs.writeFileSync(staged, text, { mode: 0o600 });
|
|
335
382
|
}
|
|
336
383
|
catch (failed) {
|
|
337
384
|
fs.rmSync(staged, { force: true });
|
|
@@ -638,7 +685,7 @@ async function settleHere(root, rel, text, commit) {
|
|
|
638
685
|
* refused because origin moved is fetched and cut again after a backoff, up to PUBLISH_ATTEMPTS; any other git failure THROWS. Resolves with the pushed
|
|
639
686
|
* commit, or null when origin already holds the file.
|
|
640
687
|
*/
|
|
641
|
-
async function publishFile(root, file, merge, subject) {
|
|
688
|
+
async function publishFile(root, file, merge, subject, write = writeAtomically) {
|
|
642
689
|
const rel = `${(await git(path.dirname(file), ["rev-parse", "--show-prefix"])).trim()}${path.basename(file)}`;
|
|
643
690
|
const published = path.join((await git(root, ["rev-parse", "--absolute-git-dir"])).trim(), "bullseye", "published", rel.split("/").join("__"));
|
|
644
691
|
for (let attempt = 1;; attempt++) {
|
|
@@ -650,7 +697,7 @@ async function publishFile(root, file, merge, subject) {
|
|
|
650
697
|
const oursText = fs.readFileSync(file, "utf8");
|
|
651
698
|
const joined = merge(baseText, oursText, theirsText);
|
|
652
699
|
if (joined.text !== oursText)
|
|
653
|
-
|
|
700
|
+
write(file, joined.text);
|
|
654
701
|
return joined;
|
|
655
702
|
});
|
|
656
703
|
if (contested.length > 0)
|
|
@@ -690,6 +737,8 @@ async function publishFile(root, file, merge, subject) {
|
|
|
690
737
|
}
|
|
691
738
|
/** Carries `tool`'s settings of workspace `root` to every box through its repo, merged key by key with another box's change; a box with no BullseyeVSC checkout carries nothing and resolves null. */
|
|
692
739
|
function publishSettings(root, tool) {
|
|
740
|
+
if (tool === "da" && sameRoot(root, toolHome()))
|
|
741
|
+
return Promise.resolve(null);
|
|
693
742
|
const file = settingsFile(root, tool);
|
|
694
743
|
const parse = (text) => (text === null ? EMPTY : parsedSettings(file, text));
|
|
695
744
|
return store().publish(root, file, (base, ours, theirs) => {
|
|
@@ -701,7 +750,7 @@ function publishSettings(root, tool) {
|
|
|
701
750
|
/** Carries the workspace list to every box through the BullseyeVSC repo, merged folder by folder with another box's change; a box with no BullseyeVSC checkout carries nothing and resolves null. */
|
|
702
751
|
function publishWorkspaces() {
|
|
703
752
|
const parse = (text) => (text === null ? [] : JSON.parse(text).workspaces);
|
|
704
|
-
return store().publish(vscRoot(), workspacesFile(), (base, ours, theirs) => ({ text: listText(mergeList(parse(base), parse(ours), parse(theirs))), contested: [] }), "workspace list");
|
|
753
|
+
return store().publish(vscRoot(), workspacesFile(), (base, ours, theirs) => ({ text: listText(mergeList(parse(base), parse(ours), parse(theirs))), contested: [] }), "workspace list", writeWorkspaceList);
|
|
705
754
|
}
|
|
706
755
|
/** #3849 — a machine-wide tool's (BS, BU) saved settings under toolHome(): undefined while no list is defined, the BullseyeVSC checkout is off it or the tool has saved none yet; any other failure THROWS. */
|
|
707
756
|
function savedSettings(tool) {
|
|
@@ -725,4 +774,65 @@ function savedSettings(tool) {
|
|
|
725
774
|
throw err;
|
|
726
775
|
}
|
|
727
776
|
}
|
|
728
|
-
|
|
777
|
+
const SSH_ALIAS = /^[a-z0-9_.][a-z0-9_.-]*$/i;
|
|
778
|
+
const remoteHostsFile = () => path.join(os.homedir(), ".bullseye", "settings", "fv-hosts.json");
|
|
779
|
+
const sshDestination = (name) => SSH_ALIAS.test(name) || isIP(name) === 6;
|
|
780
|
+
function remoteAlias(name) {
|
|
781
|
+
return sshDestination(name)
|
|
782
|
+
&& name.toLowerCase() !== os.hostname().toLowerCase()
|
|
783
|
+
&& !/^(?:localhost\.?|0\.0\.0\.0|::1?)$/i.test(name)
|
|
784
|
+
&& !(isIP(name) === 4 && name.startsWith("127."));
|
|
785
|
+
}
|
|
786
|
+
function sshHostAliases(config = path.join(os.homedir(), ".ssh", "config")) {
|
|
787
|
+
const raw = readBytesOf(config, "SSH config");
|
|
788
|
+
if (raw === undefined)
|
|
789
|
+
return [];
|
|
790
|
+
const names = new Map();
|
|
791
|
+
for (const line of raw.toString("utf8").split(/\r?\n/)) {
|
|
792
|
+
const name = /^\s*Host\s+(\S+)/i.exec(line)?.[1];
|
|
793
|
+
if (name !== undefined && sshDestination(name) && !/^hp-laptop$/i.test(name) && !names.has(name.toLowerCase()))
|
|
794
|
+
names.set(name.toLowerCase(), name);
|
|
795
|
+
}
|
|
796
|
+
return [...names.values()];
|
|
797
|
+
}
|
|
798
|
+
function readRemoteHostChoices(file) {
|
|
799
|
+
const bytes = readBytesOf(file, "FleetView hosts");
|
|
800
|
+
if (bytes === undefined)
|
|
801
|
+
return {};
|
|
802
|
+
const choices = parsedBox(file, bytes);
|
|
803
|
+
if (Object.entries(choices).some(([name, enabled]) => !sshDestination(name) || name !== name.toLowerCase() || typeof enabled !== "boolean")) {
|
|
804
|
+
throw new SyntaxError(`FleetView hosts in ${file} must map lowercase SSH aliases to true or false`);
|
|
805
|
+
}
|
|
806
|
+
return choices;
|
|
807
|
+
}
|
|
808
|
+
function remoteHostChoices() {
|
|
809
|
+
const current = workspaceTurn();
|
|
810
|
+
current.remoteHostChoices ??= readRemoteHostChoices(remoteHostsFile());
|
|
811
|
+
return current.remoteHostChoices;
|
|
812
|
+
}
|
|
813
|
+
function remoteHosts() {
|
|
814
|
+
const hosts = new Map(sshHostAliases().map((name) => [name.toLowerCase(), name]));
|
|
815
|
+
for (const [name, enabled] of Object.entries(remoteHostChoices())) {
|
|
816
|
+
const alias = name.toLowerCase();
|
|
817
|
+
if (enabled && remoteAlias(alias))
|
|
818
|
+
hosts.set(alias, hosts.get(alias) ?? alias);
|
|
819
|
+
else
|
|
820
|
+
hosts.delete(alias);
|
|
821
|
+
}
|
|
822
|
+
return [...hosts.values()];
|
|
823
|
+
}
|
|
824
|
+
function setRemoteHost(typed, enabled) {
|
|
825
|
+
const name = typeof typed === "string" ? typed.trim().toLowerCase() : "";
|
|
826
|
+
if (!sshDestination(name))
|
|
827
|
+
throw new SyntaxError("Enter an SSH alias, hostname or IP address without a user name, port, spaces or wildcards.");
|
|
828
|
+
if (enabled && !remoteAlias(name))
|
|
829
|
+
throw new SyntaxError("Enter a host other than this machine.");
|
|
830
|
+
const file = remoteHostsFile();
|
|
831
|
+
underLock(file, () => {
|
|
832
|
+
const choices = readRemoteHostChoices(file);
|
|
833
|
+
writeAtomically(file, `${JSON.stringify({ schema: SETTINGS_SCHEMA, box: { ...choices, [name]: enabled } }, null, 2)}\n`);
|
|
834
|
+
});
|
|
835
|
+
delete workspaceTurn().remoteHostChoices;
|
|
836
|
+
return name;
|
|
837
|
+
}
|
|
838
|
+
module.exports = { vscRoot, workspacesFile, publishWorkspaces, WorkspacesUndefined, listedWorkspaces, workspacesHere, listBase, saveWorkspaces, sameRoot, SettingsUndefined, SettingsMoved, SettingsLocked, WorkspaceNotListed, settingsFile, readSettings, savedSettings, AutoStartUnread, savedAutoStart, writeAutoStart, autoStartOnAt, autoStartOff, toolHome, settingsBase, writeSettings, setSettings, publishSettings, alive, sshHostAliases, remoteHostsFile, remoteHostChoices, remoteHosts, setRemoteHost };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.490",
|
|
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",
|