omni-notify-mcp 1.3.476 → 1.3.481
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 +72 -42
- package/dist/gatewayInstall.cjs +59 -59
- package/dist/messaging/messenger.js +124 -124
- package/dist/notify.js +68 -44
- package/dist/shared/agentSession.js +983 -195
- package/dist/shared/conversation/agentReaper.js +218 -0
- package/dist/shared/conversation/claudeProvider.js +36 -0
- package/dist/shared/conversation/cliSession.js +19 -0
- package/dist/shared/conversation/opencodeEvents/server.mjs +4 -0
- package/dist/shared/conversation/opencodeProvider.js +42 -5
- package/dist/shared/conversation/provider.js +9 -0
- package/dist/shared/conversation/sessionDriver.js +167 -15
- package/dist/shared/webhost/bullseyeWebHost.js +2 -38
- package/dist/shared/webhost/webviewShim.js +1 -44
- package/package.json +1 -1
- package/scripts/shared/ownerGuard.cs +0 -665
- package/scripts/shared/ownerGuard.ps1 +0 -31
package/dist/agentGateway.js
CHANGED
|
@@ -18,6 +18,7 @@ import { choicesOf, StreamedReply } from "./messaging/messenger.js";
|
|
|
18
18
|
import { appendEvent, archiveConversation, conversationRefusal, openConversation, readConversation, createdIn, creationPending, creationsPending, editOwed, GatewayError, listConversations, monotonicMs, openConversationOf, openConversationsOf, queueNoticeOf, readEvents, resolveProject, rootFolder, routeAsk, stopTargetOf, sendToConversation, startConversation, turnInFlight, updateConversation, } from "./gateway/conversationOwner.js";
|
|
19
19
|
import { conversationOwner } from "./gateway/conversationOwner.js";
|
|
20
20
|
import { clearOpenCodeLogs } from "./gateway/conversationOwner.js";
|
|
21
|
+
import { toolLine } from "./shared/conversation/provider.js";
|
|
21
22
|
import { resendUndelivered, turnEnded } from "./gateway/mcpEvents.js";
|
|
22
23
|
export const AGENT_PREFIX = "!";
|
|
23
24
|
/** The thread's newest conversation is ended; the next message opens a fresh one. */
|
|
@@ -30,6 +31,8 @@ async function endNewest(key, _platform, end) {
|
|
|
30
31
|
return stay === 0 ? "🆕 New conversation. Your next ! message starts it." : `🆕 Newest conversation ended. ${stay} other conversation${stay === 1 ? " stays" : "s stay"} open.`;
|
|
31
32
|
}
|
|
32
33
|
const stoppedOfMany = ([stopped], others) => others === 0 ? "⏹ Conversation ended. Your next ! message opens a new one." : `⏹ Conversation ${stopped.id.slice(0, 8)} ended. ${others} other conversation${others === 1 ? " stays" : "s stay"} open.`;
|
|
34
|
+
/** The pieces of a turn shown while they happen and never stored: a tool step started or ended. */
|
|
35
|
+
const LIVE_KINDS = new Set(["step", "stepDone", "stepFailed"]);
|
|
33
36
|
/** Each carried event of a turn sent as its parts. */
|
|
34
37
|
function partsRelay(reply, carriage) {
|
|
35
38
|
return {
|
|
@@ -47,7 +50,7 @@ const CHAT = {
|
|
|
47
50
|
routeOf: routeAsk,
|
|
48
51
|
stopOf: (key) => [stopTargetOf(key)].filter((c) => c !== undefined),
|
|
49
52
|
allOf: openConversationsOf,
|
|
50
|
-
carries: (kind) => kind !== "returned",
|
|
53
|
+
carries: (kind) => kind !== "returned" && !LIVE_KINDS.has(kind),
|
|
51
54
|
parts: (event) => (event.kind === "answer" ? splitForNotify(event.text) : [event.text]),
|
|
52
55
|
stopped: stoppedOfMany,
|
|
53
56
|
renew: endNewest,
|
|
@@ -60,12 +63,14 @@ const boundOf = (key) => listConversations().find((c) => c.chat === key && c.she
|
|
|
60
63
|
const sidesOf = (key) => listConversations().filter((c) => c.chat === key && c.forkOf !== undefined && c.state !== "closed" && c.shelf === undefined);
|
|
61
64
|
/** A conversation in the middle of a turn, or holding a message stored for its next one. */
|
|
62
65
|
const busy = (c) => turnInFlight(readEvents(c.id), c) !== undefined;
|
|
63
|
-
/** The
|
|
64
|
-
const
|
|
66
|
+
/** The busy main conversation a message forks beside (#4584): an OpenCode one never forks, since each fork is a new OpenCode process left behind it, so its message queues on it instead. */
|
|
67
|
+
const forkedFrom = (key) => {
|
|
65
68
|
const main = boundOf(key);
|
|
66
69
|
// NULL-OK: field main is OPTIONAL and therefore it is ok to check for NULL
|
|
67
|
-
return main
|
|
70
|
+
return main !== undefined && main.provider !== "opencode" && busy(main) ? main : undefined;
|
|
68
71
|
};
|
|
72
|
+
/** The bound chat's main conversation, unless it is busy and forks (#4584): then undefined, so the message runs at once in a new conversation forked from it and never waits behind the reply under way. */
|
|
73
|
+
const freeBound = (key) => (forkedFrom(key) === undefined ? boundOf(key) : undefined);
|
|
69
74
|
/** The bound chat: ONE main conversation at the workspace root, every message goes on with it, or beside it in a fork while it is busy (#4584); a stop pauses the one at work, /new opens the next one at once. */
|
|
70
75
|
const ONE = {
|
|
71
76
|
conversationOf: boundOf,
|
|
@@ -85,11 +90,7 @@ const ONE = {
|
|
|
85
90
|
return `⏹ Stopped${forks === 0 ? "" : `, with ${parallel}`}. Your next message picks the conversation up where it stopped.`;
|
|
86
91
|
},
|
|
87
92
|
folderOf: () => rootFolder(),
|
|
88
|
-
forkOf: (key) =>
|
|
89
|
-
const main = boundOf(key);
|
|
90
|
-
// NULL-OK: field main is OPTIONAL and therefore it is ok to check for NULL
|
|
91
|
-
return main !== undefined && busy(main) ? main.sessionId : undefined;
|
|
92
|
-
},
|
|
93
|
+
forkOf: (key) => forkedFrom(key)?.sessionId,
|
|
93
94
|
async renew(key, platform, end, provider) {
|
|
94
95
|
for (const c of ONE.allOf(key)) {
|
|
95
96
|
end(c.id);
|
|
@@ -100,7 +101,7 @@ const ONE = {
|
|
|
100
101
|
return `🆕 Fresh conversation — your next message starts it.${notice === undefined ? "" : `\n${notice.text}`}`;
|
|
101
102
|
},
|
|
102
103
|
};
|
|
103
|
-
const MAILED_KINDS = new Set(["answer", "failed", "stopped"]);
|
|
104
|
+
const MAILED_KINDS = new Set(["answer", "failed", "stopped", "asking"]);
|
|
104
105
|
/** An email thread: its one conversation, a stopped one resumed by the next reply; only what needs Meni is mailed, each whole. */
|
|
105
106
|
const THREADS_ONE = (key) => listConversations().find((c) => c.chat === key);
|
|
106
107
|
const MAIL = {
|
|
@@ -167,7 +168,9 @@ export class AgentGateway {
|
|
|
167
168
|
for (const [turn, sent] of owed) {
|
|
168
169
|
const pending = readEvents(c.id).filter((e) => e.turn === Number(turn) && e.n > sent && e.role !== "user").map((e) => ({ ...e, id: c.id }));
|
|
169
170
|
// OWNER: ITER/LOOP — a thread that cannot be reached is shown on its conversation and the next owed turn is still carried on.
|
|
170
|
-
|
|
171
|
+
const answered = this.awaitTurn(c.id, Number(turn), partsRelay((part) => door(c, part), carriageOf(c.platform, c.chat ?? "")), pending);
|
|
172
|
+
// NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
|
|
173
|
+
void (c.forkOf === undefined ? answered : answered.finally(() => this.end(c.id))).catch((err) => appendEvent(c.id, { role: "system", kind: "status", text: `❌ The answer could not be sent to this ${c.platform} thread after the BN restart: ${err instanceof Error ? err.message : String(err)}` }));
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
176
|
/** No chat message waiting on its conversation's creation: the gateway can pass to another process without losing one. A turn under way never holds it — the next build takes a cut turn up again on its session and sends its answer to its chat (#2116, #4584). */
|
|
@@ -203,7 +206,7 @@ export class AgentGateway {
|
|
|
203
206
|
const said = raw.trim();
|
|
204
207
|
const text = said.replace(/^!\s*/, "");
|
|
205
208
|
const cmd = text.match(COMMAND_RE);
|
|
206
|
-
const commanded = cmd !== null && (bare || text.startsWith("/") || said.startsWith(AGENT_PREFIX));
|
|
209
|
+
const commanded = cmd !== null && (bare || text.startsWith("/") || said.startsWith(AGENT_PREFIX) || cmd[1].toLowerCase() === "stop");
|
|
207
210
|
return commanded ? { kind: cmd[1].toLowerCase() === "new" ? "new" : "stop" } : { kind: "say", text };
|
|
208
211
|
}
|
|
209
212
|
/** A message inside a thread the agent holds is all for the agent: `/new` and `/stop` act, anything else is said, with or without `!`. */
|
|
@@ -242,7 +245,7 @@ export class AgentGateway {
|
|
|
242
245
|
const arrived = monotonicMs();
|
|
243
246
|
const carriage = carriageOf(platform, key);
|
|
244
247
|
const reply = typeof out === "function" ? out : out.say;
|
|
245
|
-
const relayOf = (id, n, queued) => (typeof out === "function" ? partsRelay(out, carriage) : out.turn(id, n, queued));
|
|
248
|
+
const relayOf = (id, n, queued, parallel = false) => (typeof out === "function" ? partsRelay(out, carriage) : out.turn(id, n, queued, parallel));
|
|
246
249
|
const refusal = conversationRefusal();
|
|
247
250
|
if (refusal !== undefined)
|
|
248
251
|
return reply(refusal);
|
|
@@ -287,9 +290,13 @@ export class AgentGateway {
|
|
|
287
290
|
// NULL-OK: field open is OPTIONAL and therefore it is ok to check for NULL
|
|
288
291
|
const slack = origin.slack !== undefined && open?.slack !== undefined ? { ...origin.slack, readTs: open.slack.readTs } : origin.slack;
|
|
289
292
|
const turn = {};
|
|
290
|
-
|
|
293
|
+
// NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
|
|
294
|
+
const provider = forkOf !== undefined ? open.provider : act.kind === "say" ? act.provider : undefined;
|
|
295
|
+
const [creation] = await Promise.allSettled([createdIn(project, provider, () => key, (on) => {
|
|
291
296
|
const created = startConversation({ platform, chat: key, slack, email: origin.email, ...on, forkOf, text: act.text, receivedMs: monotonicMs() - arrived });
|
|
292
|
-
|
|
297
|
+
const answered = this.awaitTurn(created.id, 1, relayOf(created.id, 1, false, forkOf !== undefined));
|
|
298
|
+
// NULL-OK: field forkOf is OPTIONAL and therefore it is ok to check for NULL
|
|
299
|
+
turn.answered = forkOf === undefined ? answered : answered.finally(() => this.end(created.id));
|
|
293
300
|
turn.id = created.id;
|
|
294
301
|
return created;
|
|
295
302
|
})]);
|
|
@@ -350,6 +357,8 @@ export class AgentGateway {
|
|
|
350
357
|
relay.close();
|
|
351
358
|
throw err;
|
|
352
359
|
});
|
|
360
|
+
if (LIVE_KINDS.has(event.kind))
|
|
361
|
+
continue;
|
|
353
362
|
const final = FINAL_KINDS.has(event.kind ?? "");
|
|
354
363
|
if (!closed)
|
|
355
364
|
editOwed(id, (o) => { if (final)
|
|
@@ -416,8 +425,9 @@ export function chatTurnText(key, text, context) {
|
|
|
416
425
|
if (bound === undefined)
|
|
417
426
|
return [brief, ...context, text].join("\n\n");
|
|
418
427
|
// A message beside a main conversation whose session is not written yet runs in a session of its own, which has not had the brief.
|
|
419
|
-
const
|
|
420
|
-
|
|
428
|
+
const beside = forkedFrom(key) !== undefined;
|
|
429
|
+
const first = !readEvents(bound.id).some((e) => e.role === "user") || (beside && !bound.started);
|
|
430
|
+
return [...(first ? [brief] : []), ...answeredBeside(key, bound), ...(beside ? [BESIDE] : []), ...context, text].join("\n\n");
|
|
421
431
|
}
|
|
422
432
|
/** The Claude CLI's own folder of session transcripts. */
|
|
423
433
|
function claudeProjects() {
|
|
@@ -439,17 +449,9 @@ function transcriptOf(sessionId) {
|
|
|
439
449
|
function fsFailure(err) {
|
|
440
450
|
return err instanceof Error && typeof err.code === "string";
|
|
441
451
|
}
|
|
442
|
-
/** A tool step as he reads it: the tool and what it is doing. */
|
|
443
|
-
function stepOf(block) {
|
|
444
|
-
const input = block.input ?? {};
|
|
445
|
-
const what = [input.description, input.command, input.file_path, input.pattern, input.url, input.prompt].find((v) => typeof v === "string" && v.trim() !== "");
|
|
446
|
-
// NULL-OK: field what is OPTIONAL and therefore it is ok to check for NULL
|
|
447
|
-
const shown = what === undefined ? "" : ` — ${what.replace(/\s+/g, " ").slice(0, 90)}`;
|
|
448
|
-
return `🔧 ${String(block.name ?? "tool")}${shown}`;
|
|
449
|
-
}
|
|
450
452
|
/**
|
|
451
|
-
* A conversation's Claude transcript read as it grows while a turn runs: each text block the agent writes
|
|
452
|
-
*
|
|
453
|
+
* A conversation's Claude transcript read as it grows while a turn runs: each text block the agent writes reaches the
|
|
454
|
+
* chat as a message once the agent has gone on to a tool or a next text. The CLI writes one line per block.
|
|
453
455
|
*/
|
|
454
456
|
class TranscriptTail {
|
|
455
457
|
sessionId;
|
|
@@ -543,27 +545,35 @@ class TranscriptTail {
|
|
|
543
545
|
this.log(`transcript ${this.sessionId}: a line is not JSON (${err.message}) — it is left out of the chat's preview`);
|
|
544
546
|
return;
|
|
545
547
|
}
|
|
546
|
-
if (
|
|
548
|
+
if (!Array.isArray(entry.message?.content))
|
|
547
549
|
return;
|
|
548
550
|
for (const block of entry.message.content) {
|
|
549
|
-
if (block.type === "text" && typeof block.text === "string")
|
|
551
|
+
if (entry.type === "assistant" && block.type === "text" && typeof block.text === "string")
|
|
550
552
|
this.reply.wrote(block.text);
|
|
551
|
-
if (block.type === "tool_use")
|
|
552
|
-
this.reply.step(
|
|
553
|
+
if (entry.type === "assistant" && block.type === "tool_use")
|
|
554
|
+
this.reply.step(String(block.id), toolLine(String(block.name ?? "tool"), block.input));
|
|
555
|
+
if (entry.type === "user" && block.type === "tool_result")
|
|
556
|
+
this.reply.stepDone(String(block.tool_use_id), block.is_error !== true);
|
|
553
557
|
}
|
|
554
558
|
}
|
|
555
559
|
}
|
|
556
|
-
/**
|
|
557
|
-
|
|
558
|
-
|
|
560
|
+
/** How long a turn took, in one short line a CLI prints when it ends; empty when the turn was not timed. */
|
|
561
|
+
function tookLine(event) {
|
|
562
|
+
const ms = event.timing?.agentMs ?? event.timing?.totalMs;
|
|
563
|
+
// NULL-OK: field ms is OPTIONAL and therefore it is ok to check for NULL
|
|
564
|
+
if (ms === undefined)
|
|
565
|
+
return "";
|
|
566
|
+
const seconds = Math.max(1, Math.round(ms / 1000));
|
|
567
|
+
return `\n\n⏱ ${seconds < 60 ? `${seconds} s` : `${Math.floor(seconds / 60)} min ${seconds % 60} s`}`;
|
|
568
|
+
}
|
|
569
|
+
/** The bound chat's turns as they happen (#4453): the start line at once, each text the agent finishes as a message of its own, the answer with its choices as buttons. */
|
|
559
570
|
export function streamedChat(messenger, log) {
|
|
560
571
|
return {
|
|
561
|
-
say: (text) => messenger.send(text),
|
|
562
|
-
turn(id, _n,
|
|
563
|
-
const
|
|
572
|
+
say: async (text) => { await messenger.send(text); },
|
|
573
|
+
turn(id, _n, _queued, parallel) {
|
|
574
|
+
const chat = parallel ? messenger.alongside() : messenger;
|
|
575
|
+
const reply = new StreamedReply(chat, log);
|
|
564
576
|
let tail;
|
|
565
|
-
if (!queued)
|
|
566
|
-
reply.begin();
|
|
567
577
|
const ended = () => {
|
|
568
578
|
// NULL-OK: field tail is OPTIONAL and therefore it is ok to check for NULL
|
|
569
579
|
tail?.stop();
|
|
@@ -577,16 +587,35 @@ export function streamedChat(messenger, log) {
|
|
|
577
587
|
async event(event) {
|
|
578
588
|
switch (event.kind) {
|
|
579
589
|
case "start":
|
|
580
|
-
|
|
590
|
+
// The start line stays in the store for the web page; the chat gets no message before the first real output, so nothing sits between his message and his next one.
|
|
581
591
|
// NULL-OK: field tail is OPTIONAL and therefore it is ok to check for NULL
|
|
582
592
|
tail ??= TranscriptTail.of(id, reply, log);
|
|
583
593
|
return;
|
|
594
|
+
case "said":
|
|
595
|
+
reply.said(event.text);
|
|
596
|
+
return;
|
|
597
|
+
case "step":
|
|
598
|
+
// NULL-OK: field uid is OPTIONAL and therefore it is ok to check for NULL
|
|
599
|
+
reply.step(event.uid ?? event.text, event.text);
|
|
600
|
+
return;
|
|
601
|
+
case "stepDone":
|
|
602
|
+
case "stepFailed":
|
|
603
|
+
// NULL-OK: field uid is OPTIONAL and therefore it is ok to check for NULL
|
|
604
|
+
reply.stepDone(event.uid ?? "", event.kind === "stepDone", event.text);
|
|
605
|
+
return;
|
|
606
|
+
case "asking": {
|
|
607
|
+
const { text, choices } = choicesOf(event.text);
|
|
608
|
+
reply.ask(text, choices.map((label, i) => ({ label, data: `b|${id.slice(0, 8)}|${i}` })));
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
584
611
|
case "answer": {
|
|
585
612
|
ended();
|
|
586
613
|
const { text, choices } = choicesOf(event.text);
|
|
587
|
-
return reply.finish(text
|
|
614
|
+
return reply.finish(`${text}${tookLine(event)}`, choices.map((label, i) => ({ label, data: `b|${id.slice(0, 8)}|${i}` })));
|
|
588
615
|
}
|
|
589
616
|
case "failed":
|
|
617
|
+
ended();
|
|
618
|
+
return reply.finish(`${event.text}${tookLine(event)}`);
|
|
590
619
|
case "stopped":
|
|
591
620
|
case "archived":
|
|
592
621
|
case "deleted":
|
|
@@ -597,7 +626,8 @@ export function streamedChat(messenger, log) {
|
|
|
597
626
|
case "restored":
|
|
598
627
|
return;
|
|
599
628
|
default:
|
|
600
|
-
|
|
629
|
+
await chat.send(event.text);
|
|
630
|
+
return;
|
|
601
631
|
}
|
|
602
632
|
},
|
|
603
633
|
};
|
package/dist/gatewayInstall.cjs
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { spawn } = require("child_process");
|
|
6
|
-
|
|
7
|
-
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
8
|
-
|
|
9
|
-
function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
|
|
10
|
-
return [
|
|
11
|
-
deploy,
|
|
12
|
-
"--domain", domain,
|
|
13
|
-
...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
|
|
14
|
-
// NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
|
|
15
|
-
"--project-root", projectRoot ?? home,
|
|
16
|
-
"--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
|
|
17
|
-
"--notify-dir", doorsDir,
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function runDeploy({ node, args, cwd, env, onOutput }) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const child = spawn(node, args, { windowsHide: true, cwd, env });
|
|
24
|
-
child.stdout.on("data", (chunk) => onOutput(String(chunk)));
|
|
25
|
-
child.stderr.on("data", (chunk) => onOutput(String(chunk)));
|
|
26
|
-
child.on("error", reject);
|
|
27
|
-
child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
|
|
32
|
-
|
|
33
|
-
function writeRecord(file, record) {
|
|
34
|
-
const staged = `${file}.${process.pid}.tmp`;
|
|
35
|
-
fs.writeFileSync(staged, JSON.stringify(record, null, 2));
|
|
36
|
-
try {
|
|
37
|
-
fs.renameSync(staged, file);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
fs.rmSync(staged, { force: true });
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function runRecorded(recordFile, recordText) {
|
|
45
|
-
const record = { ...JSON.parse(recordText), pid: process.pid };
|
|
46
|
-
const log = recordFile.replace(/\.json$/, ".log");
|
|
47
|
-
const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
|
|
48
|
-
try {
|
|
49
|
-
const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
|
|
50
|
-
write({ endedAt: new Date().toISOString(), ...ended });
|
|
51
|
-
} catch (err) {
|
|
52
|
-
// OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
|
|
53
|
-
write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
|
|
58
|
-
|
|
59
|
-
module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawn } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
8
|
+
|
|
9
|
+
function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
|
|
10
|
+
return [
|
|
11
|
+
deploy,
|
|
12
|
+
"--domain", domain,
|
|
13
|
+
...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
|
|
14
|
+
// NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
|
|
15
|
+
"--project-root", projectRoot ?? home,
|
|
16
|
+
"--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
|
|
17
|
+
"--notify-dir", doorsDir,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function runDeploy({ node, args, cwd, env, onOutput }) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const child = spawn(node, args, { windowsHide: true, cwd, env });
|
|
24
|
+
child.stdout.on("data", (chunk) => onOutput(String(chunk)));
|
|
25
|
+
child.stderr.on("data", (chunk) => onOutput(String(chunk)));
|
|
26
|
+
child.on("error", reject);
|
|
27
|
+
child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
|
|
32
|
+
|
|
33
|
+
function writeRecord(file, record) {
|
|
34
|
+
const staged = `${file}.${process.pid}.tmp`;
|
|
35
|
+
fs.writeFileSync(staged, JSON.stringify(record, null, 2));
|
|
36
|
+
try {
|
|
37
|
+
fs.renameSync(staged, file);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
fs.rmSync(staged, { force: true });
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function runRecorded(recordFile, recordText) {
|
|
45
|
+
const record = { ...JSON.parse(recordText), pid: process.pid };
|
|
46
|
+
const log = recordFile.replace(/\.json$/, ".log");
|
|
47
|
+
const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
|
|
48
|
+
try {
|
|
49
|
+
const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
|
|
50
|
+
write({ endedAt: new Date().toISOString(), ...ended });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
|
|
53
|
+
write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
|
|
58
|
+
|
|
59
|
+
module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
|