@astrofoundry/pi-astro 0.40.59 → 0.40.61
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/extensions/astro-discord/commands.ts +3 -0
- package/extensions/astro-discord/daily-run.test.ts +10 -2
- package/extensions/astro-discord/daily-run.ts +6 -1
- package/extensions/astro-discord/discord.test.ts +8 -0
- package/extensions/astro-discord/index.ts +14 -11
- package/package.json +1 -1
- package/specialists/identity/run.ts +2 -2
- package/specialists/wrappers.test.ts +1 -0
|
@@ -15,6 +15,8 @@ export interface CommandContext {
|
|
|
15
15
|
trigger: Trigger;
|
|
16
16
|
/** True when the message replies to one of the bot's messages. */
|
|
17
17
|
repliedToBot: boolean;
|
|
18
|
+
/** The specialist the replied-to bot message names, such as a morning-run problem's. */
|
|
19
|
+
repliedSpecialist?: string | null;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -35,6 +37,7 @@ export function parseCommand(content: string, context: CommandContext): Command
|
|
|
35
37
|
if (word === "config") return { kind: "config", args: rest };
|
|
36
38
|
const named = word.replace(/^astro\./, "");
|
|
37
39
|
if (context.specialists.includes(named)) return runCommand(named, text.slice(first.length).trim());
|
|
40
|
+
if (context.repliedSpecialist && context.specialists.includes(context.repliedSpecialist)) return runCommand(context.repliedSpecialist, text);
|
|
38
41
|
if (context.specialists.length === 1) return runCommand(context.specialists[0], text);
|
|
39
42
|
if (addressed) return { kind: "needs-prefix", specialists: [...context.specialists] };
|
|
40
43
|
return { kind: "none" };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import type { ArcaneReport } from "./daily-report.ts";
|
|
3
3
|
import type { ToolsReport } from "./tools-report.ts";
|
|
4
|
-
import { agoSeconds, arcaneSummary, guestOwner, backupStatus, dnsStatus, macosStatus, edgeStatus, identityStatus, pomeriumButtonId, wazuhRelease, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
4
|
+
import { agoSeconds, arcaneSummary, guestOwner, backupStatus, dnsStatus, macosStatus, edgeStatus, identityStatus, pomeriumButtonId, wazuhRelease, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemSpecialist, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
5
5
|
|
|
6
6
|
const EDGE = `nginx active
|
|
7
7
|
wg-quick@wg0 active
|
|
@@ -87,7 +87,7 @@ describe("morning status lines", () => {
|
|
|
87
87
|
expect(updatesStatus({ synapse: "Listing..." })).toEqual({ area: "Updates", line: "1 host up to date after the nightly run" });
|
|
88
88
|
const wazuh = updatesStatus({ technitium2: held, synapse: "Listing..." });
|
|
89
89
|
expect(wazuh.line).toBe("2 hosts up to date after the nightly run; Wazuh 4.14.10 is out (agents held at 4.14.9)");
|
|
90
|
-
expect(wazuh.problem).toMatch(/^Updates: Wazuh 4\.14\.10 is out:
|
|
90
|
+
expect(wazuh.problem).toMatch(/^Updates: Wazuh 4\.14\.10 is out: Claude Code on the Mac upgrades the manager/);
|
|
91
91
|
const left = updatesStatus({ arcane: vm, radius: null });
|
|
92
92
|
expect(left).toMatchObject({
|
|
93
93
|
line: "still waiting after the nightly run: arcane 1; no update list from radius; Wazuh 4.14.9 is out (agents held at 4.14.7)",
|
|
@@ -213,6 +213,14 @@ describe("morning summary", () => {
|
|
|
213
213
|
expect(problemText({ area: "Updates", line: "x", problem: "Updates: no update list from radius" }, ["1"])).toBe("⚠️ **Updates** · Updates: no update list from radius\nFound by the morning run; the proxmox specialist can look into it here.\n<@1>");
|
|
214
214
|
expect(problemText({ area: "macOS", line: "x", problem: "macOS: no macOS update list from Nexus" }, ["1"])).toBe("⚠️ **macOS** · macOS: no macOS update list from Nexus\nFound by the morning run; ask about it here.\n<@1>");
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
it("reads back the specialist a problem names, also after a button note", () => {
|
|
218
|
+
const text = problemText({ area: "Updates", line: "x", problem: "Updates: no update list from radius" }, ["1"]);
|
|
219
|
+
expect(problemSpecialist(text)).toBe("proxmox");
|
|
220
|
+
expect(problemSpecialist(`${text}\n♻️ SPACE-X reboots in one minute, started by <@1>; its guests restart with it.`)).toBe("proxmox");
|
|
221
|
+
expect(problemSpecialist(problemText({ area: "macOS", line: "x", problem: "macOS: x" }, ["1"]))).toBeNull();
|
|
222
|
+
expect(problemSpecialist("Several specialists live here")).toBeNull();
|
|
223
|
+
});
|
|
216
224
|
});
|
|
217
225
|
|
|
218
226
|
describe("report summaries", () => {
|
|
@@ -188,7 +188,7 @@ export function updatesStatus(hosts: Readonly<Record<string, string | null>>): A
|
|
|
188
188
|
wazuh ? `Wazuh ${wazuh.to} is out (agents held at ${wazuh.from})` : null,
|
|
189
189
|
].filter(Boolean);
|
|
190
190
|
const packages = (h: { packages: string[] }) => `${h.packages.slice(0, 4).join(", ")}${h.packages.length > 4 ? ", ..." : ""}`;
|
|
191
|
-
const wazuhText = wazuh ? `Wazuh ${wazuh.to} is out:
|
|
191
|
+
const wazuhText = wazuh ? `Wazuh ${wazuh.to} is out: Claude Code on the Mac upgrades the manager (\`observability/compose.yaml\`, then \`deploy.sh\`), then the agents (\`scripts/wazuh-agents/deploy.sh --upgrade\`); an agent must never be newer than the manager` : null;
|
|
192
192
|
const problems = [left.length > 0 ? `${left.map((h) => `${h.name} (${packages(h)})`).join("; ")} did not install overnight` : null, unknown.length > 0 ? `no update list from ${unknown.join(", ")}` : null, wazuhText].filter(Boolean);
|
|
193
193
|
const items: SummaryItem[] = [
|
|
194
194
|
...left.map((h) => ({ owner: guestOwner(h.name), text: `${h.name}: ${packages(h)} did not install overnight` })),
|
|
@@ -471,6 +471,11 @@ export function summaryText(s: Summary): string {
|
|
|
471
471
|
/** Areas read by a specialist of another name, or by none: Cortex's macOS is this host's own. */
|
|
472
472
|
const AREA_SPECIALIST: Readonly<Record<string, string | null>> = { Updates: "proxmox", macOS: null };
|
|
473
473
|
|
|
474
|
+
/** The specialist a morning-run problem message names, so a reply to it goes there without a prefix. */
|
|
475
|
+
export function problemSpecialist(content: string): string | null {
|
|
476
|
+
return /^Found by the morning run; the (\S+) specialist can look into it here\.$/m.exec(content)?.[1] ?? null;
|
|
477
|
+
}
|
|
478
|
+
|
|
474
479
|
/** The tagged message for one area's problem in its routed channel. */
|
|
475
480
|
export function problemText(a: AreaStatus, owners: readonly string[]): string {
|
|
476
481
|
const specialist = Object.hasOwn(AREA_SPECIALIST, a.area) ? AREA_SPECIALIST[a.area] : a.area.toLowerCase();
|
|
@@ -113,6 +113,14 @@ describe("commands", () => {
|
|
|
113
113
|
expect(parseCommand("", many)).toEqual({ kind: "none" });
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
it("sends a reply to a message that names a specialist there, without a prefix", () => {
|
|
117
|
+
const reply = { ...many, repliedToBot: true, repliedSpecialist: "edge" };
|
|
118
|
+
expect(parseCommand("Do it", reply)).toEqual({ kind: "run", specialist: "edge", task: "Do it", fresh: false });
|
|
119
|
+
expect(parseCommand("dns list the zones", reply)).toEqual({ kind: "run", specialist: "dns", task: "list the zones", fresh: false });
|
|
120
|
+
expect(parseCommand("Do it", { ...reply, repliedSpecialist: "proxmox" })).toEqual({ kind: "needs-prefix", specialists: ["dns", "edge"] });
|
|
121
|
+
expect(parseCommand("Do it", { ...reply, repliedSpecialist: null })).toEqual({ kind: "needs-prefix", specialists: ["dns", "edge"] });
|
|
122
|
+
});
|
|
123
|
+
|
|
116
124
|
it("needs no prefix with one specialist and asks for one when addressed with several", () => {
|
|
117
125
|
expect(parseCommand("list the projects", one)).toEqual({ kind: "run", specialist: "arcane", task: "list the projects", fresh: false });
|
|
118
126
|
expect(parseCommand("arcane list the projects", one)).toEqual({ kind: "run", specialist: "arcane", task: "list the projects", fresh: false });
|
|
@@ -79,7 +79,7 @@ import { ArcaneWatch } from "./arcane-watch-monitor.ts";
|
|
|
79
79
|
import { parseSnapshot } from "./arcane-watch.ts";
|
|
80
80
|
import { type Applied, autoFailureText, foremanTask, stackProblems, stackUpdateAnswer, SUPERVISE_DELAY_MS, SUPERVISE_LIMIT_MS } from "./supervise.ts";
|
|
81
81
|
import { stackPlan, toolPlan } from "./update-policy.ts";
|
|
82
|
-
import { type AreaStatus, arcaneSummary, backupStatus, type DnsUpgrade, dnsStatus, macosStatus, edgeStatus, identityStatus, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemText, type ProxmoxHost, proxmoxStatus, type ReportLine, type Route, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
82
|
+
import { type AreaStatus, arcaneSummary, backupStatus, type DnsUpgrade, dnsStatus, macosStatus, edgeStatus, identityStatus, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemSpecialist, problemText, type ProxmoxHost, proxmoxStatus, type ReportLine, type Route, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
83
83
|
import { type InvestigationRequest, SecurityMonitor } from "./security-monitor.ts";
|
|
84
84
|
import { nasOutage, readSecurityState } from "./security.ts";
|
|
85
85
|
|
|
@@ -453,6 +453,7 @@ class Bridge {
|
|
|
453
453
|
// In a request's thread the work continues without a mention.
|
|
454
454
|
trigger: threaded && inThread ? "always" : channel.settings.trigger,
|
|
455
455
|
repliedToBot: message.referenced_message?.author?.id === this.botUserId,
|
|
456
|
+
repliedSpecialist: message.referenced_message?.author?.id === this.botUserId ? problemSpecialist(message.referenced_message.content ?? "") : null,
|
|
456
457
|
});
|
|
457
458
|
if (command.kind === "none") return;
|
|
458
459
|
const allowed = channel.settings.everyone ? present : allowedSpecialists(this.config, userId, present);
|
|
@@ -1450,16 +1451,17 @@ class Bridge {
|
|
|
1450
1451
|
await this.rest.ephemeralReply(interaction.id, interaction.token, `${host.name} is already rebooting.`);
|
|
1451
1452
|
return;
|
|
1452
1453
|
}
|
|
1453
|
-
|
|
1454
|
-
if (status !== null && /^reboot-needed:\s*no\s*$/m.test(status)) {
|
|
1455
|
-
await this.rest.ephemeralReply(interaction.id, interaction.token, `${host.name} no longer needs a reboot.`);
|
|
1456
|
-
return;
|
|
1457
|
-
}
|
|
1454
|
+
// Discord drops a click not answered within three seconds, and a host's status check can take longer.
|
|
1458
1455
|
await this.rest.deferUpdate(interaction.id, interaction.token);
|
|
1459
1456
|
const channelId = interaction.channel_id ?? this.config.adminChannelId;
|
|
1460
1457
|
const messageId = interaction.message?.id;
|
|
1461
1458
|
this.rebooting.add(host.id);
|
|
1462
1459
|
try {
|
|
1460
|
+
const status = await this.runEntry("proxmox", userId, [...host.prefix, "host-status"], 3 * 60_000).catch(() => null);
|
|
1461
|
+
if (status !== null && /^reboot-needed:\s*no\s*$/m.test(status)) {
|
|
1462
|
+
await this.rest.followUp(this.config.applicationId, interaction.token, { content: `${host.name} no longer needs a reboot.`, flags: EPHEMERAL }).catch(() => undefined);
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1463
1465
|
log(`reboot ${host.name} by ${userId}`);
|
|
1464
1466
|
await this.runEntry("proxmox", userId, [...host.prefix, "host-reboot", "--confirm"], 2 * 60_000);
|
|
1465
1467
|
const note = `♻️ ${host.name} reboots in one minute, started by <@${userId}>; its guests restart with it.`;
|
|
@@ -1502,16 +1504,17 @@ class Bridge {
|
|
|
1502
1504
|
await this.rest.ephemeralReply(interaction.id, interaction.token, "A Pomerium upgrade is already running.");
|
|
1503
1505
|
return;
|
|
1504
1506
|
}
|
|
1505
|
-
|
|
1506
|
-
if (check.installed === tag) {
|
|
1507
|
-
await this.rest.ephemeralReply(interaction.id, interaction.token, `Pomerium already runs ${tag}.`);
|
|
1508
|
-
return;
|
|
1509
|
-
}
|
|
1507
|
+
// Discord drops a click not answered within three seconds; the check on the DMZ can take longer.
|
|
1510
1508
|
await this.rest.deferUpdate(interaction.id, interaction.token);
|
|
1511
1509
|
const channelId = interaction.channel_id ?? this.config.adminChannelId;
|
|
1512
1510
|
const messageId = interaction.message?.id;
|
|
1513
1511
|
this.pomeriumUpgrading = true;
|
|
1514
1512
|
try {
|
|
1513
|
+
const check = (await this.runEntry("identity", userId, ["dmz", "pomerium-check"], 2 * 60_000).then((out) => JSON.parse(out) as { installed?: unknown }).catch(() => null)) ?? {};
|
|
1514
|
+
if (check.installed === tag) {
|
|
1515
|
+
await this.rest.followUp(this.config.applicationId, interaction.token, { content: `Pomerium already runs ${tag}.`, flags: EPHEMERAL }).catch(() => undefined);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1515
1518
|
log(`pomerium upgrade to ${tag} by ${userId}`);
|
|
1516
1519
|
if (messageId) await this.rest.editMessage(channelId, messageId, `${interaction.message?.content ?? ""}\n⏳ Pomerium ${tag} is installing, started by <@${userId}>.`.slice(0, 1900), []).catch(() => undefined);
|
|
1517
1520
|
const out = await this.runEntry("identity", userId, ["dmz", "pomerium-upgrade", tag], POMERIUM_UPGRADE_MS);
|
package/package.json
CHANGED
|
@@ -147,9 +147,9 @@ export function publishedSha256(checksums: string): string {
|
|
|
147
147
|
return sum;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/** `pomerium: 0.33.1+01af7466f` as `v0.33.1`. */
|
|
150
|
+
/** `0.34.0+3b6f4c1d` (since Pomerium 0.34) or `pomerium: 0.33.1+01af7466f` as `v0.34.0` or `v0.33.1`. */
|
|
151
151
|
export function installedRelease(output: string): string | null {
|
|
152
|
-
const m =
|
|
152
|
+
const m = /^(?:pomerium:\s*)?v?(\d+\.\d+\.\d+)/.exec(output.trim());
|
|
153
153
|
return m ? `v${m[1]}` : null;
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -101,6 +101,7 @@ describe("identity wrapper", () => {
|
|
|
101
101
|
expect(publishedSha256(`${"0".repeat(64)} pomerium-darwin-arm64.tar.gz\n${sum} pomerium-linux-amd64.tar.gz\n`)).toBe(sum);
|
|
102
102
|
expect(() => publishedSha256(`${"0".repeat(64)} pomerium-darwin-arm64.tar.gz\n`)).toThrow(/no sha256/);
|
|
103
103
|
expect(installedRelease("pomerium: 0.33.1+01af7466f\nenvoy: 20260618180819-16ede7a56f2f\n")).toBe("v0.33.1");
|
|
104
|
+
expect(installedRelease("0.34.0+3b6f4c1d\nenvoy version 1.36.2 (Apache-2.0)\nLicensed under the terms of the Apache License 2.0\n")).toBe("v0.34.0");
|
|
104
105
|
expect(installedRelease("command not found")).toBeNull();
|
|
105
106
|
});
|
|
106
107
|
|