omni-notify-mcp 1.3.369 → 1.3.371
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/README.md +1 -1
- package/dist/daemon.js +1 -1
- package/dist/desk.js +268 -0
- package/dist/gateway/chatPage.js +10 -2
- package/dist/gateway/mcpDoor.js +3 -3
- package/dist/gateway/passkeyDoor.js +159 -134
- package/dist/gateway/restDoor.js +7 -2
- package/dist/messaging/notificationEngine.js +10 -7
- package/dist/notify.js +8 -62
- package/dist/shared/agentSession.js +337 -4
- package/dist/shared/webhost/autoSwitch.cjs +12 -5
- package/dist/shared/webhost/userSession.js +178 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ entirely server-side.
|
|
|
109
109
|
| `ask` | `question` (≤500), `timeout_seconds` (30–3600, default 300) | Sends the question over Telegram and **blocks** until you answer. The wait is clamped to the caller's own transport limit, so it returns `NO REPLY YET` and leaves the question open rather than reporting it as ignored; the answer arrives in the inbox. |
|
|
110
110
|
| `poll` | — | Drains queued inbox messages for this session; returns `inbox:empty` when there are none. |
|
|
111
111
|
| `wait_for_inbox` | `timeout_seconds` (5–55, default 50) | Blocks and returns the moment you type, as a tool *result* — the delivery path that works in every MCP client. Returns already-queued messages immediately. |
|
|
112
|
-
| `get_idle_seconds` | — | How long since the last keyboard/mouse input, as one of two DIFFERENT answers: `idle: measured N seconds …`, or `idle: could not measure — user activity unknown, so activity gating is skipped`. |
|
|
112
|
+
| `get_idle_seconds` | — | How long since the logged-on user's last keyboard/mouse input, read in his own session, as one of two DIFFERENT answers: `idle: measured N seconds …`, or `idle: could not measure — <why> — user activity unknown, so activity gating is skipped`. |
|
|
113
113
|
| `get_idle_config` | — | `{ enabled, thresholdSeconds, alwaysDesktopWhenActive }`. |
|
|
114
114
|
| `get_delivery_status` | — | `{ process, healthy, channels, carriage, reason }` from real transport readings, not from config or from the process being alive. `healthy` is true only when every enabled channel has been MEASURED able to carry. |
|
|
115
115
|
| `get_dnd_status` | — | `{ active, reason }` where reason is `disabled`, `manual`, `schedule` or `off`. |
|
package/dist/daemon.js
CHANGED
|
@@ -47,7 +47,7 @@ function successor() {
|
|
|
47
47
|
return spawn(process.execPath, [...process.execArgv, self], { detached: true, stdio: "ignore", windowsHide: true });
|
|
48
48
|
if (!existsSync(SUPERVISE_LOOP))
|
|
49
49
|
throw new Error(`the supervise loop is not in the config dir at ${SUPERVISE_LOOP} — the login entry and the boot task copy it there, so nothing can own the next run`);
|
|
50
|
-
return spawn(process.execPath, [SUPERVISE_LOOP, "supervise"
|
|
50
|
+
return spawn(process.execPath, [SUPERVISE_LOOP, "supervise"], { detached: true, stdio: "ignore", windowsHide: true });
|
|
51
51
|
}
|
|
52
52
|
/** The installed build has replaced this one on disk: a supervised process only exits and its owner starts that build; an unsupervised one starts its successor and names it in the heartbeat before it exits, so no other owner starts a second build meanwhile, and on Windows the supervise loop reads that beat as the claim on its first run. */
|
|
53
53
|
function replaceWithInstalledBuild() {
|
package/dist/desk.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4142 — BN's desk: the one BN process that runs in the logged-on user's own Windows session. The boot task runs the daemon in
|
|
3
|
+
* session 0, which has none of his keyboard, mouse, screen or speakers — GetLastInputInfo there reads the services session's own
|
|
4
|
+
* last input, so the "idle" it gives is the time since the machine booted, a banner draws on no desktop and a voice plays to no
|
|
5
|
+
* one. The daemon asks the desk over a named pipe instead; a desk that does not answer is started in his session through the
|
|
6
|
+
* shared user-session launcher, and a machine with no logon session of his has no desk and says so. On macOS and Linux the
|
|
7
|
+
* daemon runs in his own login, so each act is taken in-process.
|
|
8
|
+
*
|
|
9
|
+
* Started as `node desk.(m)js --serve-desk <config dir>`, this module serves the desk; imported, it is the daemon's client.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import { connect, createServer } from "net";
|
|
13
|
+
import { existsSync, readFileSync } from "fs";
|
|
14
|
+
import { tmpdir } from "os";
|
|
15
|
+
import { dirname, extname, join } from "path";
|
|
16
|
+
import { fileURLToPath } from "url";
|
|
17
|
+
import { execFile, spawn } from "child_process";
|
|
18
|
+
import notifier from "node-notifier";
|
|
19
|
+
import { idleReading, idleUnmeasured } from "./messaging/notificationEngine.js";
|
|
20
|
+
import { NoUserSession, OsCallTimedOut, startInUserSession } from "./shared/webhost/userSession.js";
|
|
21
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
22
|
+
/** The desk's own entry beside this module, in whichever build this is: `dist/desk.js` of the npm package, `dist/desk.mjs` beside the extension's bundled daemon, `doors/dist/desk.js` beside the gateway's doors. */
|
|
23
|
+
const DESK_ENTRY = join(dirname(SELF), `desk${extname(SELF)}`);
|
|
24
|
+
const VERSION = JSON.parse(readFileSync(join(dirname(SELF), "..", "package.json"), "utf8")).version;
|
|
25
|
+
/** The Windows idle probe the build ships at `../scripts/` beside it. */
|
|
26
|
+
const IDLE_PROBE = join(dirname(SELF), "..", "scripts", "idle-check.ps1");
|
|
27
|
+
const SERVE_FLAG = "--serve-desk";
|
|
28
|
+
const CHECK_FLAG = "--check-desk";
|
|
29
|
+
// GATE: how long a desk just started in the user's session has to answer on its pipe before the ask says it could not be reached.
|
|
30
|
+
const DESK_START_MS = 20_000;
|
|
31
|
+
// GATE: how long one ask waits for the desk's answer before the ask says the desk did not answer.
|
|
32
|
+
const DESK_ANSWER_MS = 10_000;
|
|
33
|
+
// GATE: how often the desk looks whether its config dir still exists; a desk whose config dir is gone (a suite's, removed) leaves.
|
|
34
|
+
const DESK_OWNER_LOOK_MS = 60_000;
|
|
35
|
+
/** The desk could not be asked: no logon session is open, it did not start, or it did not answer. */
|
|
36
|
+
export class DeskUnreachable extends Error {
|
|
37
|
+
}
|
|
38
|
+
const deskKey = (configDir) => createHash("sha256").update(configDir).digest("hex").slice(0, 12);
|
|
39
|
+
const deskPipe = (configDir) => `\\\\.\\pipe\\bullseye-notify-desk-${deskKey(configDir)}`;
|
|
40
|
+
/** The name every one-shot task that starts this config dir's desk in the user's session begins with; a suite's own config dir names its own. */
|
|
41
|
+
export const deskTask = (configDir) => `BullseyeNotifyDesk-${deskKey(configDir)}`;
|
|
42
|
+
/** One ask over the pipe: the desk's answer, or "absent" when nothing listens on it. */
|
|
43
|
+
function askOnce(configDir, request) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const socket = connect(deskPipe(configDir));
|
|
46
|
+
let reply = "";
|
|
47
|
+
let settled = false;
|
|
48
|
+
const settle = (outcome) => {
|
|
49
|
+
if (settled)
|
|
50
|
+
return;
|
|
51
|
+
settled = true;
|
|
52
|
+
socket.destroy();
|
|
53
|
+
outcome();
|
|
54
|
+
};
|
|
55
|
+
socket.setEncoding("utf8");
|
|
56
|
+
socket.setTimeout(DESK_ANSWER_MS, () => settle(() => reject(new DeskUnreachable(`the desk on ${deskPipe(configDir)} did not answer within ${DESK_ANSWER_MS / 1000} s`))));
|
|
57
|
+
socket.once("connect", () => socket.write(`${JSON.stringify({ ...request, version: VERSION })}\n`));
|
|
58
|
+
socket.on("data", (chunk) => {
|
|
59
|
+
reply += chunk;
|
|
60
|
+
if (reply.includes("\n"))
|
|
61
|
+
settle(() => resolve(JSON.parse(reply.slice(0, reply.indexOf("\n")))));
|
|
62
|
+
});
|
|
63
|
+
socket.once("close", () => settle(() => reject(new DeskUnreachable(`the desk on ${deskPipe(configDir)} closed the ask before it answered`))));
|
|
64
|
+
socket.once("error", (err) => settle(() => (err.code === "ENOENT" ? resolve("absent") : reject(new DeskUnreachable(`the desk on ${deskPipe(configDir)} could not be asked — ${err.message}`)))));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** The one start under way per config dir, so two asks that both find no desk start one between them. */
|
|
68
|
+
const starting = new Map();
|
|
69
|
+
/** Why a desk this process started did not come up, per config dir: a desk that cannot come up is started once, never again on every ask; a desk that comes up after all clears it. */
|
|
70
|
+
const parked = new Map();
|
|
71
|
+
async function startDesk(configDir) {
|
|
72
|
+
try {
|
|
73
|
+
await startInUserSession(deskTask(configDir), process.execPath, [DESK_ENTRY, SERVE_FLAG, configDir]);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (err instanceof NoUserSession)
|
|
77
|
+
throw new DeskUnreachable(err.message);
|
|
78
|
+
if (err instanceof OsCallTimedOut)
|
|
79
|
+
throw new DeskUnreachable(`the desk could not be started in the user's session yet — ${err.message} — the next ask starts it again`);
|
|
80
|
+
if (!(err instanceof Error))
|
|
81
|
+
throw err;
|
|
82
|
+
throw parkedBecause(configDir, `the desk could not be started in the user's session — ${err.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function parkedBecause(configDir, why) {
|
|
86
|
+
const said = `${why} — this BN process does not start it again until it restarts`;
|
|
87
|
+
parked.set(configDir, said);
|
|
88
|
+
return new DeskUnreachable(said);
|
|
89
|
+
}
|
|
90
|
+
/** What a load of the desk's own entry says in this session: a desk that dies before it listens leaves no trace in the user's session, and the same build loaded here prints why. */
|
|
91
|
+
function loadCheck() {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
execFile(process.execPath, [DESK_ENTRY, CHECK_FLAG], { encoding: "utf-8", windowsHide: true, timeout: DESK_ANSWER_MS }, (failed, _out, err) => {
|
|
94
|
+
resolve(failed === null ? "its entry loads cleanly here, so it stopped in the user's session itself" : `its entry ${DESK_ENTRY} does not load — ${(err || failed.message).trim().split(/\r?\n/).slice(0, 3).join(" ")}`);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** The desk's answer to `request`, starting the desk first when none listens; throws DeskUnreachable with why it could not be asked. */
|
|
99
|
+
async function ask(configDir, request) {
|
|
100
|
+
const first = await askOnce(configDir, request);
|
|
101
|
+
if (first !== "absent") {
|
|
102
|
+
parked.delete(configDir);
|
|
103
|
+
return answered(first);
|
|
104
|
+
}
|
|
105
|
+
const held = parked.get(configDir);
|
|
106
|
+
// NULL-OK: field held is OPTIONAL and therefore it is ok to check for NULL
|
|
107
|
+
if (held !== undefined)
|
|
108
|
+
throw new DeskUnreachable(held);
|
|
109
|
+
if (!starting.has(configDir))
|
|
110
|
+
starting.set(configDir, startAndListen(configDir).finally(() => starting.delete(configDir)));
|
|
111
|
+
await starting.get(configDir);
|
|
112
|
+
const again = await askOnce(configDir, request);
|
|
113
|
+
if (again === "absent")
|
|
114
|
+
throw new DeskUnreachable(`the desk listened on ${deskPipe(configDir)} and left before it answered`);
|
|
115
|
+
return answered(again);
|
|
116
|
+
}
|
|
117
|
+
/** Whether anything listens on the config dir's desk pipe now. */
|
|
118
|
+
function listening(configDir) {
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const socket = connect(deskPipe(configDir));
|
|
121
|
+
socket.once("connect", () => { socket.destroy(); resolve(true); });
|
|
122
|
+
socket.once("error", () => resolve(false));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/** Starts the desk and resolves once it listens, so every ask that found no desk waits on this one start; a desk that does not listen in time is parked with why. */
|
|
126
|
+
async function startAndListen(configDir) {
|
|
127
|
+
await startDesk(configDir);
|
|
128
|
+
const until = Date.now() + DESK_START_MS;
|
|
129
|
+
while (!(await listening(configDir))) {
|
|
130
|
+
if (Date.now() >= until)
|
|
131
|
+
throw parkedBecause(configDir, `the desk was started in the user's session but did not listen on ${deskPipe(configDir)} within ${DESK_START_MS / 1000} s — ${await loadCheck()}`);
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function answered(answer) {
|
|
136
|
+
// NULL-OK: field failed is OPTIONAL and therefore it is ok to check for NULL
|
|
137
|
+
if (answer.failed !== undefined)
|
|
138
|
+
throw new DeskUnreachable(answer.failed);
|
|
139
|
+
return answer;
|
|
140
|
+
}
|
|
141
|
+
/** The user's idle time where he is: the desk's reading on Windows, the session's own elsewhere; a reading that cannot be taken is "could not measure" with why, never a number. */
|
|
142
|
+
export async function idleNow(configDir) {
|
|
143
|
+
try {
|
|
144
|
+
if (process.platform === "win32")
|
|
145
|
+
return idleReading(secondsOf(await ask(configDir, { ask: "idle" })));
|
|
146
|
+
return idleReading(await sessionIdleSeconds());
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
// OWNER: the reading's producer — IdleReading's two outcomes are a number and "could not measure", which both callers (the routing and get_idle_seconds) render as given; a desk or probe that could not read is the second, with its reason
|
|
150
|
+
if (!(err instanceof Error))
|
|
151
|
+
throw err;
|
|
152
|
+
return idleUnmeasured(err.message);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function secondsOf(answer) {
|
|
156
|
+
// NULL-OK: field seconds is OPTIONAL and therefore it is ok to check for NULL
|
|
157
|
+
if (answer.seconds === undefined)
|
|
158
|
+
throw new DeskUnreachable("the desk answered the idle ask with no count of seconds");
|
|
159
|
+
return answer.seconds;
|
|
160
|
+
}
|
|
161
|
+
/** The desktop banner, drawn where the user is; throws why it could not be. */
|
|
162
|
+
export async function showBanner(configDir, title, message) {
|
|
163
|
+
if (process.platform === "win32")
|
|
164
|
+
await ask(configDir, { ask: "banner", title, message });
|
|
165
|
+
else
|
|
166
|
+
await bannerHere(title, message);
|
|
167
|
+
}
|
|
168
|
+
/** Windows: a voice file played through the desk, where the user's speakers are. */
|
|
169
|
+
export async function playVoice(configDir, file) {
|
|
170
|
+
await ask(configDir, { ask: "play", file });
|
|
171
|
+
}
|
|
172
|
+
/** macOS: ioreg's HIDIdleTime (nanoseconds); Linux: xprintidle (milliseconds). */
|
|
173
|
+
function sessionIdleSeconds() {
|
|
174
|
+
const [file, args] = process.platform === "darwin" ? ["/bin/sh", ["-c", "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"]] : ["xprintidle", []];
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
execFile(file, args, { encoding: "utf-8", windowsHide: true, timeout: DESK_ANSWER_MS }, (failed, out, err) => {
|
|
177
|
+
if (failed !== null)
|
|
178
|
+
return reject(new Error(`${file} could not read the last input — ${(err || failed.message).trim()}`));
|
|
179
|
+
const value = Number(out.trim());
|
|
180
|
+
if (!Number.isInteger(value) || value < 0)
|
|
181
|
+
return reject(new Error(`${file} printed "${out.trim()}", not a count`));
|
|
182
|
+
resolve(process.platform === "darwin" ? value : Math.floor(value / 1000));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// ── The desk itself, in the user's session ─────────────────────────────────────
|
|
187
|
+
/** GetLastInputInfo of this session, through the bundled probe. */
|
|
188
|
+
function idleSecondsHere() {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
execFile("powershell", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", IDLE_PROBE], { encoding: "utf-8", windowsHide: true, cwd: tmpdir(), timeout: DESK_ANSWER_MS }, (failed, out, err) => {
|
|
191
|
+
if (failed !== null)
|
|
192
|
+
return reject(new Error(`${IDLE_PROBE} could not read the last input — ${(err || failed.message).trim()}`));
|
|
193
|
+
const seconds = Number(out.trim());
|
|
194
|
+
if (!Number.isInteger(seconds) || seconds < 0)
|
|
195
|
+
return reject(new Error(`${IDLE_PROBE} printed "${out.trim()}", not a count of seconds`));
|
|
196
|
+
resolve(seconds);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function bannerHere(title, message) {
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
notifier.notify({ title, message, sound: false }, (err) => (err ? reject(err) : resolve()));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/** Plays a voice file through Windows' media player and resolves once it has started. */
|
|
206
|
+
function playHere(file) {
|
|
207
|
+
const script = `Add-Type -AssemblyName presentationCore; $p = New-Object System.Windows.Media.MediaPlayer; $done = $false; Register-ObjectEvent $p MediaEnded -Action { $script:done = $true } | Out-Null; $p.Open([uri]'${file.replace(/'/g, "''")}'); $p.Play(); while (-not $done) { Start-Sleep -Milliseconds 200 }`;
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
spawn("powershell", ["-NoProfile", "-Command", script], { windowsHide: true, stdio: "ignore", cwd: tmpdir() }).once("spawn", () => resolve()).once("error", reject);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function act(request) {
|
|
213
|
+
if (request.ask === "idle")
|
|
214
|
+
return idleSecondsHere().then((seconds) => ({ seconds }));
|
|
215
|
+
if (request.ask === "banner")
|
|
216
|
+
return bannerHere(request.title, request.message).then(() => ({}));
|
|
217
|
+
return playHere(request.file).then(() => ({}));
|
|
218
|
+
}
|
|
219
|
+
/** One ask on the pipe: answered with the act's outcome; an ask from another build is answered and then this desk leaves, so the next ask starts that build's desk. */
|
|
220
|
+
function answer(socket) {
|
|
221
|
+
let line = "";
|
|
222
|
+
socket.setEncoding("utf8");
|
|
223
|
+
// OWNER: an asker that left before its answer cannot be told — the desk goes on serving the next ask
|
|
224
|
+
socket.on("error", () => socket.destroy());
|
|
225
|
+
socket.on("data", (chunk) => {
|
|
226
|
+
line += chunk;
|
|
227
|
+
if (!line.includes("\n"))
|
|
228
|
+
return;
|
|
229
|
+
let request;
|
|
230
|
+
try {
|
|
231
|
+
request = JSON.parse(line.slice(0, line.indexOf("\n")));
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
if (!(err instanceof SyntaxError))
|
|
235
|
+
throw err;
|
|
236
|
+
// OWNER: the pipe is the desk's own boundary — a line that is not an ask is answered with why, and the desk goes on serving the next ask
|
|
237
|
+
socket.end(`${JSON.stringify({ failed: `the desk was sent a line that is not an ask — ${err.message}` })}\n`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
void act(request).then((outcome) => outcome, (failed) => {
|
|
241
|
+
// OWNER: the ask is this act's trigger root — a probe, banner or player that failed is answered to the daemon with why, and the desk goes on serving
|
|
242
|
+
if (!(failed instanceof Error))
|
|
243
|
+
throw failed;
|
|
244
|
+
return { failed: failed.message };
|
|
245
|
+
}).then((outcome) => socket.end(`${JSON.stringify(outcome)}\n`, () => {
|
|
246
|
+
if (request.version !== VERSION)
|
|
247
|
+
process.exit(0);
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/** The desk: holds this config dir's pipe for as long as the user's session lasts and its config dir exists; a desk that finds the pipe held by another leaves, because that one serves. */
|
|
252
|
+
function serveDesk(configDir) {
|
|
253
|
+
const server = createServer(answer);
|
|
254
|
+
setInterval(() => {
|
|
255
|
+
if (!existsSync(configDir))
|
|
256
|
+
process.exit(0);
|
|
257
|
+
}, DESK_OWNER_LOOK_MS).unref();
|
|
258
|
+
server.once("error", (err) => {
|
|
259
|
+
if (err.code !== "EADDRINUSE")
|
|
260
|
+
throw err;
|
|
261
|
+
process.exit(0);
|
|
262
|
+
});
|
|
263
|
+
server.listen(deskPipe(configDir));
|
|
264
|
+
}
|
|
265
|
+
if (process.argv[2] === SERVE_FLAG)
|
|
266
|
+
serveDesk(process.argv[3]);
|
|
267
|
+
if (process.argv[2] === CHECK_FLAG)
|
|
268
|
+
process.exit(0);
|
package/dist/gateway/chatPage.js
CHANGED
|
@@ -180,14 +180,22 @@ async function signIn(notice) {
|
|
|
180
180
|
main.append(message);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
// GATE: how long the page waits before asking the gateway again about its sign-in after a failed check.
|
|
184
|
+
var RECHECK_MS = 3000;
|
|
183
185
|
async function resumeSignIn() {
|
|
184
186
|
var response = await fetch("/passkey/session", {headers:{authorization:"Bearer " + token}});
|
|
185
|
-
if (
|
|
187
|
+
if (response.status === 401) { signIn("Your sign-in expired or was revoked. Sign in again."); return; }
|
|
188
|
+
if (!response.ok) throw new Error("the gateway answered " + response.status);
|
|
186
189
|
var session = await response.json();
|
|
187
190
|
keep(token, session.expiresIn === null ? 0 : Date.now() + session.expiresIn * 1000);
|
|
188
191
|
home();
|
|
189
192
|
}
|
|
190
|
-
function
|
|
193
|
+
function recheckSignIn(err) {
|
|
194
|
+
show("signin", "Sign in");
|
|
195
|
+
main.append(el("div", "system", "Could not reach the gateway (" + err.message + ") — your sign-in is kept; checking again…"));
|
|
196
|
+
setTimeout(startSignIn, RECHECK_MS);
|
|
197
|
+
}
|
|
198
|
+
function startSignIn() { if (token) resumeSignIn().catch(recheckSignIn); else signIn(""); }`;
|
|
191
199
|
/**
|
|
192
200
|
* The conversations half of BN's one page: the list he manages — the table, its per-row actions and the project picker.
|
|
193
201
|
* It is carried from the deleted Conversations page (#3401) into the native CLI page because that capability lives
|
package/dist/gateway/mcpDoor.js
CHANGED
|
@@ -58,13 +58,13 @@ function stagedLifecycle() {
|
|
|
58
58
|
return file;
|
|
59
59
|
}
|
|
60
60
|
/** The press itself, run in a process of its own: the row's own act, whose outcome is read afterwards with act=state. */
|
|
61
|
-
const LIFECYCLE_ACTOR = "require(process.argv[1]).row(
|
|
61
|
+
const LIFECYCLE_ACTOR = "require(process.argv[1]).row().act(process.argv[2]).then(() => process.exit(0), () => process.exit(1))";
|
|
62
62
|
/** A launcher that starts the actor detached and exits at once, so no live parent links the actor to this daemon: the Stop inside a Restart ends this daemon's whole process tree, and an actor still in it would die before it started BN again. */
|
|
63
63
|
const LIFECYCLE_LAUNCHER = `require("child_process").spawn(process.execPath, ["-e", ${JSON.stringify(LIFECYCLE_ACTOR)}, ...process.argv.slice(1)], { detached: true, stdio: "ignore", windowsHide: true }).unref()`;
|
|
64
64
|
/** Start, Stop and Restart end or replace the process answering this very call, so they run in a process that outlives it; the outcome is read afterwards with act=state. */
|
|
65
65
|
function pressLifecycle(file, press) {
|
|
66
66
|
return new Promise((resolve, reject) => {
|
|
67
|
-
const launcher = spawn(process.execPath, ["-e", LIFECYCLE_LAUNCHER, file,
|
|
67
|
+
const launcher = spawn(process.execPath, ["-e", LIFECYCLE_LAUNCHER, file, press], { stdio: "ignore", windowsHide: true });
|
|
68
68
|
launcher.once("error", (err) => reject(new GatewayError(500, `the ${press} could not be launched — ${err.message}`)));
|
|
69
69
|
launcher.once("exit", (code) => (code === 0 ? resolve({ pressed: press, running: true, next: "read the outcome with bn_lifecycle act=state" }) : reject(new GatewayError(500, `the ${press} could not be launched — its launcher exited ${code}`))));
|
|
70
70
|
});
|
|
@@ -352,7 +352,7 @@ function buildServer(caller, base, offer) {
|
|
|
352
352
|
}));
|
|
353
353
|
server.tool("bn_lifecycle", "BN's own Start, Stop and Restart as the dashboard row and the panel run them. act=state reads the measured state (running, stopped, unreachable ...) with its words and what a Stop would cut. start, stop and restart are pressed in a process that outlives this call — a Stop or Restart ends the process answering you — and the outcome is read afterwards with act=state; a Stop stays until Start. Restart takes and builds the newest main first, exactly as the row does.", { act: z.enum(["state", "start", "stop", "restart"]) }, ({ act: press }) => panelAct(async () => {
|
|
354
354
|
const file = stagedLifecycle();
|
|
355
|
-
return press === "state" ? createRequire(file)(file).row(
|
|
355
|
+
return press === "state" ? createRequire(file)(file).row().state() : pressLifecycle(file, press);
|
|
356
356
|
}));
|
|
357
357
|
return server;
|
|
358
358
|
}
|