@astrofoundry/pi-astro 0.40.65 โ†’ 0.40.66

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/agents/media.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: media
3
- description: Manages the movie and series library through the media tool (trendarr), covering weekly trending with IMDb ratings, recommendations from the library, title search, adds to Radarr and Sonarr, and the SABnzbd queue pause state. Use for what is trending, adding a movie or series by name, and pausing or resuming downloads.
3
+ description: Manages the movie and series library through the media tool (trendarr), covering weekly trending with IMDb ratings, recommendations from the library, title search, adds to Radarr and Sonarr, the SABnzbd queue pause state, and imports stuck in the Radarr and Sonarr queues. Use for what is trending, adding a movie or series by name, pausing or resuming downloads, and clearing a stuck import.
4
4
  tools: read, media, subagent
5
5
  skills: media
6
6
  systemPromptMode: replace
@@ -20,5 +20,6 @@ Rules:
20
20
  - Success needs an explicit `added` or `already_exists` in `results`; `already_exists` means it was already there, not newly added. Report every ID of a batch.
21
21
  - Pause or resume downloads only when the task asks for it, then report the returned state. Adding never implies a queue change.
22
22
  - Keep replies short: canonical title and year, and the outcome. When an add returned `sabnzbd_paused: true`, end with "Downloads are paused."; say nothing about the queue otherwise. Outside failures, name no tool or service (SABnzbd, Radarr, Sonarr, trendarr, TMDB, OMDb): say downloads, library, search.
23
- - Library settings, quality profiles, Radarr and Sonarr configuration, and deletions are operator tasks; say so and stop.
23
+ - Remove a queue record only with `queue-remove` after `queue` shows it and its reason, following the skill's stuck-import rules; the tool asks an owner for approval.
24
+ - Library settings, quality profiles, Radarr and Sonarr configuration, and deletions other than a stuck queue record are operator tasks; say so and stop.
24
25
  - Delegate through `subagent` only to another specialist (`astro.arcane` for the media containers on the Arcane VM) and only for that specialist's own area.
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  escalationText,
3
- hostRestartText,
4
3
  observe,
5
4
  parseSnapshot,
6
5
  readWatchState,
@@ -100,10 +99,8 @@ export class ArcaneWatch {
100
99
  const now = this.deps.now();
101
100
  const seen = observe(state, snapshot, now, this.deps.nasOutage(now));
102
101
  for (const note of seen.notes) this.deps.log(`arcane watch: ${note}`);
103
- for (const e of seen.hostRestarts) {
104
- this.deps.log(`arcane watch: ${e.count} of ${e.total} containers restarted between ${e.from} and ${e.to}`);
105
- await this.post(s.channelId, { content: hostRestartText(e, s.timeZone) });
106
- }
102
+ // Docker or the VM restarted every container (the nightly upgrade): the log is enough, nobody has to act.
103
+ for (const e of seen.hostRestarts) this.deps.log(`arcane watch: host-wide restart, ${e.count} of ${e.total} containers restarted between ${e.from} and ${e.to}`);
107
104
  for (const u of seen.unhealthy) {
108
105
  const posted = await this.post(s.channelId, { content: unhealthyText(u, owners, s.timeZone, now), mentionUsers: owners });
109
106
  if (posted) this.deps.log(`arcane watch: ${u.name} ${u.problem} after a redeploy`);
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
5
  import type { WatchedContainer } from "../../specialists/lib/container-watch.ts";
6
6
  import { ArcaneWatch } from "./arcane-watch-monitor.ts";
7
- import { emptyWatchState, escalationText, healthProblem, hostRestartText, observe, parseSnapshot, readWatchState, restartInvestigationTask, unhealthyText, type WatchState } from "./arcane-watch.ts";
7
+ import { emptyWatchState, escalationText, healthProblem, observe, parseSnapshot, readWatchState, restartInvestigationTask, unhealthyText, type WatchState } from "./arcane-watch.ts";
8
8
  import type { DiscordConfig } from "./config.ts";
9
9
  import type { CreateMessage } from "./rest.ts";
10
10
  import type { InvestigationRequest } from "./security-monitor.ts";
@@ -152,12 +152,6 @@ describe("container watch texts", () => {
152
152
  );
153
153
  });
154
154
 
155
- it("names a host-wide restart without tagging anyone", () => {
156
- expect(hostRestartText({ count: 46, total: 52, from: iso(T0), to: iso(T0 + 8_000) }, TZ)).toBe(
157
- "๐Ÿ” **Host-wide restart** ยท 46 of 52 containers restarted at 22 Oct 10:00 CEST, so Docker or the Arcane VM restarted. They do not count as container restarts.",
158
- );
159
- });
160
-
161
155
  it("asks the specialist to read only, within the host's one-day window", () => {
162
156
  const now = T0 + 24 * 60 * MIN;
163
157
  const task = restartInvestigationTask({ name: "syncthing", restarts: [iso(T0 + MIN), iso(now - MIN)] }, now);
@@ -257,7 +251,7 @@ describe("container watch monitor", () => {
257
251
  expect(h.archived).toEqual(["t500"]);
258
252
  });
259
253
 
260
- it("posts a host-wide restart once, untagged, and investigates nothing", async () => {
254
+ it("logs a host-wide restart, posts nothing, and investigates nothing", async () => {
261
255
  const h = harness();
262
256
  const three = ["a", "b", "c"].map((name) => ct({ name, id: name }));
263
257
  h.answer.next = () => JSON.stringify({ containers: three });
@@ -266,9 +260,8 @@ describe("container watch monitor", () => {
266
260
  const started = iso(T0 + 4 * MIN);
267
261
  h.answer.next = () => JSON.stringify({ containers: three.map((c) => ({ ...c, startedAt: started })) });
268
262
  await h.watch.poll(SCHEDULE);
269
- expect(h.messages).toHaveLength(1);
270
- expect(h.messages[0].message.content).toContain("๐Ÿ” **Host-wide restart** ยท 3 of 3 containers");
271
- expect(h.messages[0].message.mentionUsers).toBeUndefined();
263
+ expect(h.messages).toEqual([]);
264
+ expect(h.logs.some((l) => l.includes("host-wide restart, 3 of 3 containers"))).toBe(true);
272
265
  expect(h.investigations).toEqual([]);
273
266
  expect(readWatchState().restarts).toEqual({});
274
267
  });
@@ -218,11 +218,6 @@ export function escalationText(e: Escalation, owners: readonly string[], timeZon
218
218
  ].join("\n");
219
219
  }
220
220
 
221
- /** Untagged: Docker or the VM restarting is planned maintenance far more often than a fault. */
222
- export function hostRestartText(e: HostRestart, timeZone: string): string {
223
- return `๐Ÿ” **Host-wide restart** ยท ${e.count} of ${e.total} containers restarted at ${clockText(e.from, timeZone)}, so Docker or the Arcane VM restarted. They do not count as container restarts.`;
224
- }
225
-
226
221
  export function unhealthyText(u: Unhealthy, owners: readonly string[], timeZone: string, now: number): string {
227
222
  const minutes = Math.round((now - Date.parse(u.since)) / MINUTE);
228
223
  return [
@@ -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, problemSpecialist, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
4
+ import { type AreaStatus, agoSeconds, arcaneSummary, guestOwner, backupStatus, dnsStatus, macosStatus, edgeStatus, identityStatus, pomeriumButtonId, wazuhRelease, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemSpecialist, problemsToPost, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
5
5
 
6
6
  const EDGE = `nginx active
7
7
  wg-quick@wg0 active
@@ -119,6 +119,9 @@ describe("morning status lines", () => {
119
119
  expect(newer.line).toBe("pomerium, nginx, lego-renew.timer active; Pomerium v0.33.1, v0.33.6 available");
120
120
  expect(newer.problem).toContain(`Pomerium v0.33.6 is out (running v0.33.1; notes: <${notes}>)`);
121
121
  expect(newer.buttons).toEqual([{ label: "Update Pomerium to v0.33.6", customId: pomeriumButtonId("v0.33.6") }]);
122
+ expect(newer.once).toBe("pomerium:v0.33.6");
123
+ const failedUnit = DMZ.replace("Active: active (running) since Thu 2026-09-24 17:21:24 CEST; 4 weeks 0 days ago\nโ— nginx", "Active: failed (Result: signal)\nโ— nginx");
124
+ expect(identityStatus(failedUnit, { installed: "v0.33.1", newest: "v0.33.6", update: true, notes }).once).toBeUndefined();
122
125
  expect(identityStatus(DMZ, null).line).toBe("pomerium, nginx, lego-renew.timer active; Pomerium version unknown");
123
126
  });
124
127
 
@@ -128,16 +131,25 @@ describe("morning status lines", () => {
128
131
  expect(dnsStatus({ technitium1: null, technitium2: { status: "error" }, technitium3: { status: "ok" } })).toMatchObject({ problem: "DNS: technitium1 and technitium2 do not answer" });
129
132
  });
130
133
 
131
- it("flags a Mac two macOS minors behind and notes a major without flagging it", () => {
132
- const nexus = "26.5.2\nTitle: Command Line Tools for Xcode 26.6, Version: 26.6, Size: 920431KiB, Recommended: YES,\nTitle: macOS Tahoe 26.7.2, Version: 26.7.2, Size: 3868257KiB, Recommended: YES, Action: restart,\nTitle: macOS 27.2, Version: 27.2, Size: 11319983KiB, Recommended: YES, Action: restart,";
133
- const cortex = "26.6.1\nTitle: macOS Tahoe 26.7.2, Version: 26.7.2, Size: 3168375KiB, Recommended: YES, Action: restart,";
134
- expect(macosStatus([{ name: "Cortex", output: cortex }])).toEqual({ area: "macOS", line: "Cortex 26.6.1, 26.7.2 waiting" });
135
- expect(macosStatus([{ name: "Nexus", output: nexus }, { name: "Cortex", output: null }])).toEqual({
134
+ it("flags any newer macOS of the installed major for its owner and notes a major without flagging it", () => {
135
+ const nexus = "26.7.2\nTitle: Command Line Tools for Xcode 26.6, Version: 26.6, Size: 920431KiB, Recommended: YES,\nTitle: Safari, Version: 27.2, Size: 250130KiB, Recommended: YES,\nTitle: macOS 27.2.1, Version: 27.2.1, Size: 17362949KiB, Recommended: YES, Action: restart,";
136
+ const cortex = "26.7.2\nTitle: macOS Tahoe 26.7.3, Version: 26.7.3, Size: 2506663KiB, Recommended: YES, Action: restart,\nTitle: macOS 27.2.1, Version: 27.2.1, Size: 17362949KiB, Recommended: YES, Action: restart,";
137
+ expect(macosStatus([{ name: "Nexus", output: nexus }])).toEqual({ area: "macOS", line: "Nexus 26.7.2, macOS 27.2.1 offered (major, by hand)" });
138
+ const waiting = "Cortex runs macOS 26.7.2; macOS Tahoe 26.7.3 waits: install it with softwareupdate as a volume owner, then check that Cortex comes back";
139
+ expect(macosStatus([{ name: "Cortex", output: cortex }, { name: "Nexus", output: nexus.replace("Title: Safari", "Title: macOS Tahoe 26.7.3, Version: 26.7.3, Size: 1KiB,\nTitle: Safari") }])).toEqual({
136
140
  area: "macOS",
137
- line: "Nexus 26.5.2, 26.7.2 waiting, macOS 27.2 offered (major, by hand); Cortex unknown",
138
- problem: "macOS: Nexus runs macOS 26.5.2 while 26.7.2 is out; automatic installs are not keeping up; no macOS update list from Cortex",
141
+ line: "Cortex 26.7.2, 26.7.3 waiting, macOS 27.2.1 offered (major, by hand); Nexus 26.7.2, 26.7.3 waiting, macOS 27.2.1 offered (major, by hand)",
142
+ problem: `macOS: ${waiting}; ${waiting.replaceAll("Cortex", "Nexus")}`,
143
+ items: [
144
+ { owner: "Cortex", text: waiting },
145
+ { owner: "Inference", text: waiting.replaceAll("Cortex", "Nexus") },
146
+ ],
139
147
  route: "admin",
148
+ once: "macos:Cortex:26.7.3,Nexus:26.7.3",
140
149
  });
150
+ const unknown = macosStatus([{ name: "Cortex", output: cortex }, { name: "Nexus", output: null }]);
151
+ expect(unknown.items?.at(-1)).toEqual({ owner: "Inference", text: "no macOS update list from Nexus" });
152
+ expect(unknown.once).toBeUndefined();
141
153
  expect(macosStatus([{ name: "Cortex", output: "26.7.2" }]).line).toBe("Cortex 26.7.2");
142
154
  });
143
155
 
@@ -155,8 +167,26 @@ describe("morning status lines", () => {
155
167
  expect(dnsStatus(all, { major: true, from: "15.6.2", to: "16.0.0" }).problem).toMatch(/^DNS: Technitium 16.0.0 is a major release \(running 15.6.2\)/);
156
168
  expect(inferenceStatus("embed \tstate = running \tpid = 80042 health=200\nrerank \tstate = running \tpid = 81670 health=200")).toEqual({ area: "Inference", line: "Nexus embed, rerank running and healthy" });
157
169
  expect(inferenceStatus("embed \tstate = running \tpid = 80042 health=503")).toMatchObject({ problem: "Inference: embed not healthy on Nexus" });
158
- expect(mediaStatus({ sabnzbd_paused: true, warnings: [] })).toEqual({ area: "Media", line: "downloads paused" });
159
- expect(mediaStatus({ sabnzbd_paused: false, warnings: [{ text: "login failed" }] })).toMatchObject({ line: "downloads running, 1 warning", problem: "Media: the downloader shows 1 warning", route: "media" });
170
+ const empty = { records: [], warnings: [] };
171
+ expect(mediaStatus({ sabnzbd_paused: true, warnings: [] }, empty, NOW)).toEqual({ area: "Media", line: "downloads paused" });
172
+ expect(mediaStatus({ sabnzbd_paused: false, warnings: [{ text: "login failed" }] }, empty, NOW)).toMatchObject({ line: "downloads running, 1 warning", problem: "Media: the downloader shows 1 warning", route: "media" });
173
+ expect(mediaStatus({ sabnzbd_paused: false, warnings: [] }, null, NOW)).toMatchObject({ line: "downloads running, import queue unknown", problem: "Media: the import queue check failed" });
174
+ expect(mediaStatus({ sabnzbd_paused: false, warnings: [] }, { records: [], warnings: ["sonarr: sonarr answered 401 to GET /api/v3/queue"] }, NOW)).toMatchObject({ problem: "Media: the import queue of sonarr could not be read", route: "media" });
175
+ });
176
+
177
+ it("names imports that wait in the queue for more than a day, and tags them once", () => {
178
+ const record = (id: number, added: string) => ({ app: "radarr", id, title: "Primetime.2026.REPACK.2160p", state: "importPending", status: "warning", messages: ["Not a Custom Format upgrade for existing movie file(s)."], added, size: 13406787332 });
179
+ const queue = { records: [record(7, "2026-10-22T16:03:52Z"), record(8, "2026-10-23T20:00:00Z")], warnings: [] };
180
+ const item = "Primetime.2026.REPACK.2160p (radarr) waits in the queue since 2026-10-22 (importPending: Not a Custom Format upgrade for existing movie file(s).); reply here to remove it (queue-remove radarr 7)";
181
+ expect(mediaStatus({ sabnzbd_paused: false, warnings: [] }, queue, NOW)).toEqual({
182
+ area: "Media",
183
+ line: "downloads running, 1 import stuck",
184
+ problem: `Media: ${item}`,
185
+ items: [{ owner: "Media", text: item }],
186
+ route: "media",
187
+ once: "queue:radarr:7",
188
+ });
189
+ expect(mediaStatus({ sabnzbd_paused: false, warnings: ["x"] }, queue, NOW).once).toBeUndefined();
160
190
  });
161
191
 
162
192
  it("checks last night's Proxmox archives and the restic check", () => {
@@ -171,7 +201,7 @@ describe("morning status lines", () => {
171
201
  });
172
202
 
173
203
  describe("morning summary", () => {
174
- it("gives each specialist and Cortex one line: all clear, or what needs the owners there, without a mention", () => {
204
+ it("gives each item its own line under its owner and names the owners with nothing open last, without a mention", () => {
175
205
  const text = summaryText({
176
206
  date: "Fri 24 Oct",
177
207
  guildId: "1",
@@ -191,16 +221,23 @@ describe("morning summary", () => {
191
221
  expect(text).toBe(
192
222
  [
193
223
  "**Daily** ยท Fri 24 Oct ยท ๐ŸŸ  3 items need you",
194
- "Security ยท All clear boss!",
195
- "Cortex ยท All clear boss!",
196
- "Arcane ยท stirling-pdf waits for you (major version) ([report](https://discord.com/channels/1/22/32)); arcane: docker-ce did not install overnight (<#11>)",
224
+ "Arcane ยท stirling-pdf waits for you (major version) ([report](https://discord.com/channels/1/22/32))",
225
+ "Arcane ยท arcane: docker-ce did not install overnight (<#11>)",
197
226
  "Backup ยท no Proxmox backup last night for identity (<#11>)",
198
- "Proxmox ยท All clear boss!",
199
- "DNS ยท All clear boss!",
227
+ "All clear: Security, Cortex, Proxmox, DNS",
200
228
  ].join("\n"),
201
229
  );
202
230
  expect(text).not.toContain("<@");
203
- expect(summaryText({ date: "Fri 24 Oct", guildId: "1", routes: { admin: "11", media: "12" }, reports: [], areas: [{ area: "Media", line: "downloads running" }] })).toBe("**Daily** ยท Fri 24 Oct ยท ๐ŸŸข All clear boss!\nMedia ยท All clear boss!");
231
+ expect(summaryText({ date: "Fri 24 Oct", guildId: "1", routes: { admin: "11", media: "12" }, reports: [], areas: [{ area: "Media", line: "downloads running" }] })).toBe("**Daily** ยท Fri 24 Oct ยท ๐ŸŸข All clear boss!\nAll clear: Media");
232
+ });
233
+
234
+ it("tags the owners for a waiting release on its first morning only", () => {
235
+ const pomerium: AreaStatus = { area: "Identity", line: "x", problem: "Identity: Pomerium v0.34.0 is out", once: "pomerium:v0.34.0", route: "admin" };
236
+ const backup: AreaStatus = { area: "Backup", line: "x", problem: "Backup: a backup status check failed", route: "admin" };
237
+ const quiet: AreaStatus = { area: "DNS", line: "x" };
238
+ expect(problemsToPost([pomerium, backup, quiet], [])).toEqual({ post: [pomerium, backup], notified: ["pomerium:v0.34.0"] });
239
+ expect(problemsToPost([pomerium, backup, quiet], ["pomerium:v0.34.0", "macos:Cortex:26.7.3"])).toEqual({ post: [backup], notified: ["pomerium:v0.34.0"] });
240
+ expect(problemsToPost([{ ...pomerium, once: "pomerium:v0.34.1" }], ["pomerium:v0.34.0"]).post).toHaveLength(1);
204
241
  });
205
242
 
206
243
  it("tags the owners for an area's problem in its channel", () => {
@@ -27,6 +27,12 @@ export interface AreaStatus {
27
27
  items?: SummaryItem[];
28
28
  route?: Route;
29
29
  buttons?: AreaButton[];
30
+ /**
31
+ * Set when the problem only waits for the owners, such as a release with its
32
+ * button: its tagged message posts on the first morning with this key, and
33
+ * the summary keeps listing it every morning.
34
+ */
35
+ once?: string;
30
36
  }
31
37
 
32
38
  const HOUR = 3600;
@@ -255,6 +261,7 @@ export function identityStatus(status: string | null, pomerium?: unknown): AreaS
255
261
  line: [unitLine, releaseLine].filter(Boolean).join("; "),
256
262
  ...(problems.length > 0 ? { problem: `Identity: ${problems.join("; ")}`, route: "admin" as const } : {}),
257
263
  ...(newer ? { buttons: [{ label: `Update Pomerium to ${newer.newest}`, customId: pomeriumButtonId(newer.newest) }] } : {}),
264
+ ...(newer && problems.length === 1 ? { once: `pomerium:${newer.newest}` } : {}),
258
265
  };
259
266
  }
260
267
 
@@ -310,13 +317,58 @@ export function inferenceStatus(status: string | null): AreaStatus {
310
317
  return { area: "Inference", line, ...(bad.length > 0 || services.length === 0 ? { problem: `Inference: ${bad.length > 0 ? `${bad.join(", ")} not healthy on Nexus` : "Nexus lists no service"}`, route: "admin" as const } : {}) };
311
318
  }
312
319
 
313
- /** `media sabnzbd status`: paused or downloading, and SABnzbd's own warnings. */
314
- export function mediaStatus(sab: unknown): AreaStatus {
320
+ /** One download that Radarr or Sonarr cannot import, from `media queue`. */
321
+ export interface StuckImport {
322
+ app: string;
323
+ id: number;
324
+ title: string;
325
+ state: string;
326
+ messages: string[];
327
+ added: string;
328
+ }
329
+
330
+ /** An import that waits this long has stopped waiting for anything but the owners. */
331
+ const STUCK_IMPORT_S = 24 * HOUR;
332
+
333
+ function stuckImports(queue: unknown): StuckImport[] | null {
334
+ const records = (queue as { records?: unknown } | null)?.records;
335
+ if (!Array.isArray(records)) return null;
336
+ return (records as Record<string, unknown>[])
337
+ .filter((r) => typeof r.app === "string" && typeof r.id === "number" && typeof r.title === "string" && typeof r.added === "string")
338
+ .map((r) => ({ app: r.app as string, id: r.id as number, title: r.title as string, state: typeof r.state === "string" ? r.state : "?", messages: Array.isArray(r.messages) ? r.messages.filter((m): m is string => typeof m === "string") : [], added: r.added as string }));
339
+ }
340
+
341
+ /** The apps whose queue `media queue` could not read: its warnings start with the app name. */
342
+ function queueWarnings(queue: unknown): string[] {
343
+ const warnings = (queue as { warnings?: unknown } | null)?.warnings;
344
+ return Array.isArray(warnings) ? warnings.filter((w): w is string => typeof w === "string").map((w) => w.split(":")[0]) : [];
345
+ }
346
+
347
+ /** `media sabnzbd status` and `media queue`: paused or downloading, SABnzbd's own warnings, and imports stuck for a day. */
348
+ export function mediaStatus(sab: unknown, queue: unknown, now: number): AreaStatus {
315
349
  const r = sab as { sabnzbd_paused?: unknown; warnings?: unknown } | null;
316
350
  if (!r || typeof r.sabnzbd_paused !== "boolean") return failed("Media", "media", "sabnzbd status");
317
351
  const warnings = Array.isArray(r.warnings) ? r.warnings.length : 0;
318
- const line = `downloads ${r.sabnzbd_paused ? "paused" : "running"}${warnings > 0 ? `, ${warnings} warning${warnings === 1 ? "" : "s"}` : ""}`;
319
- return { area: "Media", line, ...(warnings > 0 ? { problem: `Media: the downloader shows ${warnings} warning${warnings === 1 ? "" : "s"}`, route: "media" as const } : {}) };
352
+ const imports = stuckImports(queue);
353
+ const unread = imports === null ? [] : queueWarnings(queue);
354
+ const stuck = imports?.filter((i) => now / 1000 - Date.parse(i.added) / 1000 > STUCK_IMPORT_S) ?? [];
355
+ const line = [`downloads ${r.sabnzbd_paused ? "paused" : "running"}${warnings > 0 ? `, ${warnings} warning${warnings === 1 ? "" : "s"}` : ""}`, imports === null ? "import queue unknown" : stuck.length > 0 ? `${stuck.length} import${stuck.length === 1 ? "" : "s"} stuck` : null].filter(Boolean).join(", ");
356
+ const items: SummaryItem[] = [
357
+ ...(warnings > 0 ? [{ owner: "Media", text: `the downloader shows ${warnings} warning${warnings === 1 ? "" : "s"}` }] : []),
358
+ ...(imports === null ? [{ owner: "Media", text: "the import queue check failed" }] : []),
359
+ ...unread.map((w) => ({ owner: "Media", text: `the import queue of ${w} could not be read` })),
360
+ ...stuck.map((i) => ({
361
+ owner: "Media",
362
+ text: `${i.title} (${i.app}) waits in the queue since ${i.added.slice(0, 10)} (${i.state}${i.messages[0] ? `: ${i.messages[0].slice(0, 160)}` : ""}); reply here to remove it (queue-remove ${i.app} ${i.id})`,
363
+ })),
364
+ ];
365
+ const onlyStuck = items.length > 0 && items.length === stuck.length;
366
+ return {
367
+ area: "Media",
368
+ line,
369
+ ...(items.length > 0 ? { problem: `Media: ${items.map((i) => i.text).join("; ")}`, items, route: "media" as const } : {}),
370
+ ...(onlyStuck ? { once: `queue:${stuck.map((i) => `${i.app}:${i.id}`).sort().join(",")}` } : {}),
371
+ };
320
372
  }
321
373
 
322
374
  /** Every guest is backed up nightly from 02:00; an archive older than this means last night's run missed it. */
@@ -339,30 +391,48 @@ export interface MacUpdates {
339
391
  output: string | null;
340
392
  }
341
393
 
342
- /** A Mac this many minor releases behind the newest offered one is not keeping up with its automatic installs. */
343
- const MACOS_MINORS_BEHIND = 2;
394
+ /** The summary line each Mac's items go to: Cortex is this host, Nexus is the inference specialist's. */
395
+ const MAC_OWNER: Readonly<Record<string, string>> = { Cortex: "Cortex", Nexus: "Inference" };
344
396
 
345
- /** Each Mac's macOS version and offers: automatic installs cover minors; a major is noted for a manual upgrade. */
397
+ /**
398
+ * Each Mac's macOS version and offers. Apple silicon installs a macOS update
399
+ * only with a volume owner's password, so any newer update of the installed
400
+ * major waits for the owners; a new major is noted for a manual upgrade.
401
+ */
346
402
  export function macosStatus(macs: readonly MacUpdates[]): AreaStatus {
347
403
  const parts: string[] = [];
348
- const problems: string[] = [];
404
+ const items: SummaryItem[] = [];
405
+ const waiting: string[] = [];
349
406
  for (const m of macs) {
407
+ const owner = MAC_OWNER[m.name] ?? "Cortex";
350
408
  if (m.output === null) {
351
409
  parts.push(`${m.name} unknown`);
352
- problems.push(`no macOS update list from ${m.name}`);
410
+ items.push({ owner, text: `no macOS update list from ${m.name}` });
353
411
  continue;
354
412
  }
355
413
  const [installed = "", ...rest] = m.output.split("\n").map((l) => l.trim());
356
- const offers = rest.map((l) => /Title: macOS[^,]*, Version: ([\d.]+)/.exec(l)?.[1]).filter((v): v is string => v !== undefined);
357
- const [major, minor] = installed.split(".").map(Number);
358
- const sameMajor = offers.filter((v) => Number(v.split(".")[0]) === major);
359
- const newestMinor = Math.max(minor ?? 0, ...sameMajor.map((v) => Number(v.split(".")[1] ?? 0)));
360
- const majors = offers.filter((v) => Number(v.split(".")[0]) > major);
361
- const latest = sameMajor.sort((a, b) => a.localeCompare(b, undefined, { numeric: true })).at(-1);
362
- parts.push(`${m.name} ${installed}${latest ? `, ${latest} waiting` : ""}${majors.length > 0 ? `, macOS ${majors[0]} offered (major, by hand)` : ""}`);
363
- if (newestMinor - (minor ?? 0) >= MACOS_MINORS_BEHIND) problems.push(`${m.name} runs macOS ${installed} while ${latest} is out; automatic installs are not keeping up`);
414
+ const offers = rest
415
+ .map((l) => /Title: (macOS[^,]*), Version: ([\d.]+)/.exec(l))
416
+ .filter((x): x is RegExpExecArray => x !== null)
417
+ .map((x) => ({ title: x[1], version: x[2] }));
418
+ const major = Number(installed.split(".")[0]);
419
+ const compare = (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true });
420
+ const newer = offers.filter((o) => Number(o.version.split(".")[0]) === major && compare(o.version, installed) > 0).sort((a, b) => compare(a.version, b.version));
421
+ const majors = offers.filter((o) => Number(o.version.split(".")[0]) > major);
422
+ const latest = newer.at(-1);
423
+ parts.push(`${m.name} ${installed}${latest ? `, ${latest.version} waiting` : ""}${majors.length > 0 ? `, macOS ${majors[0].version} offered (major, by hand)` : ""}`);
424
+ if (latest) {
425
+ items.push({ owner, text: `${m.name} runs macOS ${installed}; ${latest.title} waits: install it with softwareupdate as a volume owner, then check that ${m.name} comes back` });
426
+ waiting.push(`${m.name}:${latest.version}`);
427
+ }
364
428
  }
365
- return { area: "macOS", line: parts.join("; "), ...(problems.length > 0 ? { problem: `macOS: ${problems.join("; ")}`, route: "admin" as const } : {}) };
429
+ const onlyWaiting = items.length > 0 && items.length === waiting.length;
430
+ return {
431
+ area: "macOS",
432
+ line: parts.join("; "),
433
+ ...(items.length > 0 ? { problem: `macOS: ${items.map((i) => i.text).join("; ")}`, items, route: "admin" as const } : {}),
434
+ ...(onlyWaiting ? { once: `macos:${waiting.join(",")}` } : {}),
435
+ };
366
436
  }
367
437
 
368
438
  /** One report the run posted in its own channel, as the summary shows it. */
@@ -462,7 +532,7 @@ function ownerOf(area: string): string {
462
532
  return AREA_OWNER[area] ?? area;
463
533
  }
464
534
 
465
- /** The #daily message: one line per specialist and Cortex, either all clear or what needs the owners there, with no mention. */
535
+ /** The #daily message: one line per item, under the specialist or Cortex that owns it, then the owners with nothing open; no mention. */
466
536
  export function summaryText(s: Summary): string {
467
537
  const lines = new Map<string, string[]>();
468
538
  const add = (owner: string, items: readonly string[]) => lines.set(owner, [...(lines.get(owner) ?? []), ...items]);
@@ -479,7 +549,21 @@ export function summaryText(s: Summary): string {
479
549
  const head = `**Daily** ยท ${s.date} ยท ${count === 0 ? `๐ŸŸข ${ALL_CLEAR}` : `๐ŸŸ  ${count} item${count === 1 ? " needs" : "s need"} you`}`;
480
550
  const rank = (owner: string) => (OWNER_ORDER.includes(owner) ? OWNER_ORDER.indexOf(owner) : OWNER_ORDER.length);
481
551
  const owners = [...lines.keys()].sort((x, y) => rank(x) - rank(y));
482
- return [head, ...owners.map((o) => `${o} ยท ${lines.get(o)?.join("; ") || ALL_CLEAR}`)].join("\n");
552
+ const clear = owners.filter((o) => (lines.get(o) ?? []).length === 0);
553
+ return [head, ...owners.flatMap((o) => (lines.get(o) ?? []).map((item) => `${o} ยท ${item}`)), ...(clear.length > 0 ? [`All clear: ${clear.join(", ")}`] : [])].join("\n");
554
+ }
555
+
556
+ /**
557
+ * The problems whose tagged message posts this morning: all of them, except a
558
+ * problem with a `once` key an earlier morning already posted. `notified` is
559
+ * every `once` key still open, the record for the next morning.
560
+ */
561
+ export function problemsToPost(areas: readonly AreaStatus[], notifiedBefore: readonly string[]): { post: AreaStatus[]; notified: string[] } {
562
+ const problems = areas.filter((a) => a.problem);
563
+ return {
564
+ post: problems.filter((a) => a.once === undefined || !notifiedBefore.includes(a.once)),
565
+ notified: problems.map((a) => a.once).filter((k): k is string => k !== undefined),
566
+ };
483
567
  }
484
568
 
485
569
  /** Areas read by a specialist of another name, or by none: Cortex's macOS is this host's own. */
@@ -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, problemSpecialist, 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, problemsToPost, 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
 
@@ -630,17 +630,21 @@ class Bridge {
630
630
  if (arcane) reports.push(arcaneSummary(readPostedArcane(), date, arcane.channelId));
631
631
  const routes = this.routes();
632
632
  const owners = this.config.owners;
633
- for (const a of areas.filter((x) => x.problem)) {
633
+ // A problem that only waits for the owners tags them on its first morning; the summary lists it every day.
634
+ const prior = readReportState("daily")?.notified;
635
+ const { post, notified } = problemsToPost(areas, Array.isArray(prior) ? prior : []);
636
+ for (const a of areas.filter((x) => x.problem && !post.includes(x))) log(`daily ${date}: ${a.area} problem already posted (${a.once ?? ""})`);
637
+ for (const a of post) {
634
638
  const components = a.buttons ? [{ type: 1, components: a.buttons.map((b) => ({ type: 2, style: 4, label: b.label, custom_id: b.customId })) }] : undefined;
635
639
  await this.rest.createMessage(routes[a.route ?? "admin"], { content: problemText(a, owners), mentionUsers: owners, ...(components ? { components } : {}) }).catch((err) => log(`daily ${date}: ${a.area} problem message failed: ${err instanceof Error ? err.message : String(err)}`));
636
640
  }
637
641
  const label = new Intl.DateTimeFormat("en-GB", { timeZone: schedule.timeZone, weekday: "short", day: "numeric", month: "short" }).format(new Date());
638
642
  const text = summaryText({ date: label, guildId: this.config.guildId, reports, areas, routes });
639
643
  // Recorded only now: a run a crash cut short runs again and skips the reports it already posted.
640
- writeReportState("daily", { date, status: "sending" });
644
+ writeReportState("daily", { date, status: "sending", notified });
641
645
  let first = "";
642
646
  for (const chunk of chunkMessage(text)) first ||= (await this.rest.createMessage(schedule.channelId, { content: chunk })).id;
643
- writeReportState("daily", { date, status: "sent", messageId: first });
647
+ writeReportState("daily", { date, status: "sent", messageId: first, notified });
644
648
  log(`daily ${date}: posted`);
645
649
  }
646
650
 
@@ -727,7 +731,7 @@ class Bridge {
727
731
  );
728
732
  }
729
733
  if (present.has("inference")) areas.push((async () => inferenceStatus(await text("inference", ["nexus-status"])))());
730
- if (present.has(MEDIA)) areas.push((async () => mediaStatus(await json(MEDIA, ["sabnzbd", "status"])))());
734
+ if (present.has(MEDIA)) areas.push((async () => mediaStatus(await json(MEDIA, ["sabnzbd", "status"]), await json(MEDIA, ["queue"]), Date.now()))());
731
735
  areas.push(
732
736
  (async () => {
733
737
  // Cortex is this host; Nexus answers through the inference specialist.
@@ -1401,9 +1405,8 @@ class Bridge {
1401
1405
  /** Restarts one service; the bridge's own restart runs detached, because launchd stops this process with it. */
1402
1406
  private async restartService(p: PendingRestart, byUser: string | null): Promise<void> {
1403
1407
  const who = byUser ? ` by <@${byUser}>` : "";
1404
- const text = `โ™ป๏ธ Restarting ${SERVICE_LABEL[p.service]}${who} for ${p.reasons.join(", ")}.`;
1405
- if (p.prompt) await this.rest.editMessage(p.prompt.channelId, p.prompt.messageId, text, []).catch(() => undefined);
1406
- else await this.rest.createMessage(this.restartChannel(), { content: text.slice(0, 1900) }).catch(() => undefined);
1408
+ // Only the owners' Restart now prompt is edited; a routine restart goes to the log, not to Discord.
1409
+ if (p.prompt) await this.rest.editMessage(p.prompt.channelId, p.prompt.messageId, `โ™ป๏ธ Restarting ${SERVICE_LABEL[p.service]}${who} for ${p.reasons.join(", ")}.`, []).catch(() => undefined);
1407
1410
  const uid = process.getuid?.();
1408
1411
  if (uid === undefined) {
1409
1412
  log(`restart ${p.service}: this platform has no user id for launchctl; restart it by hand`);
@@ -8,6 +8,8 @@ export interface ReportState {
8
8
  /** `skipped`: the Security Daily Report on a Monday, when the weekly report takes its place. */
9
9
  status: "sending" | "sent" | "failed" | "skipped";
10
10
  messageId?: string;
11
+ /** The morning run: `once` keys of the problems it has tagged the owners for, so a waiting release tags them once. */
12
+ notified?: string[];
11
13
  }
12
14
 
13
15
  /** Local date and minutes past midnight in a time zone. */
@@ -479,7 +479,7 @@ export class SecurityMonitor {
479
479
  const state = readSecurityState();
480
480
  const wazuh = wazuhDigest(events, state.origins, (e) => acked(state, e));
481
481
  if (this.deps.stopping()) return;
482
- const data = { until: clockText(new Date(now).toISOString(), s.timeZone).replace(/^\d+ \w+ /, ""), timeZone: s.timeZone, crowdsec, wazuh, found: vulns?.found ?? null, closed: vulns?.closed ?? null, attention, ...images, alerts: state.alerts };
482
+ const data = { until: clockText(new Date(now).toISOString(), s.timeZone).replace(/^\d+ \w+ /, ""), timeZone: s.timeZone, crowdsec, wazuh, found: vulns?.found ?? null, closed: vulns?.closed ?? null, attention, ...images, alerts: state.alerts, guildId: this.deps.config().guildId };
483
483
  writeReportState("security", { date, status: "sending" });
484
484
  const report = dailyCard(data, this.owners());
485
485
  const id = await this.postReport(s.channelId, report);
@@ -529,6 +529,7 @@ export class SecurityMonitor {
529
529
  backups: archives ? { guests: archives, restic: resticText === null ? null : resticStatus(resticText) } : null,
530
530
  ...images,
531
531
  alerts: state.alerts,
532
+ guildId: this.deps.config().guildId,
532
533
  last24h: {
533
534
  bans: lastDay?.count ?? null,
534
535
  wazuh: lastDayEvents?.length ?? null,
@@ -47,6 +47,7 @@ import {
47
47
  needsYou,
48
48
  noteNas,
49
49
  repeatText,
50
+ rebuildItems,
50
51
  resticStatus,
51
52
  section,
52
53
  type VulnEvent,
@@ -401,7 +402,8 @@ describe("Arcane image scans", () => {
401
402
 
402
403
  it("keeps critical findings that have a fix and are not ignored", () => {
403
404
  const facts = parseImageVulns({ totalImages: 57, scannedImages: 3 }, { data: [item(), item({ vulnerabilityId: "CVE-2", ignored: true }), item({ vulnerabilityId: "CVE-3", fixedVersion: "" }), { nonsense: true }] });
404
- expect(facts).toEqual({ scanned: 3, total: 57, critical: [{ id: "CVE-2026-1", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:latest" }] });
405
+ expect(facts).toEqual({ scanned: 3, total: 57, critical: [{ id: "CVE-2026-1", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:latest", os: false }] });
406
+ expect(parseImageVulns({ totalImages: 1, scannedImages: 1 }, { data: [item({ class: "os-pkgs" }), item({ vulnerabilityId: "CVE-4", class: "lang-pkgs" })] })?.critical.map((v) => v.os)).toEqual([true, false]);
405
407
  expect(parseImageVulns({ totalImages: 57 }, { data: [] })).toBeNull();
406
408
  expect(parseImageVulns({ totalImages: 1, scannedImages: 1 }, {})).toBeNull();
407
409
  });
@@ -420,11 +422,11 @@ describe("Arcane image scans", () => {
420
422
  scanned: 57,
421
423
  total: 57,
422
424
  critical: [
423
- { id: "CVE-1", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:latest" },
424
- { id: "CVE-2", pkg: "zlib", image: "ghcr.io/mealie-recipes/mealie:latest" },
425
- { id: "CVE-3", pkg: "glibc", image: "ghcr.io/mealie-recipes/mealie:latest" },
426
- { id: "CVE-4", pkg: "libpq", image: "supabase/postgres:15.8.1.085" },
427
- { id: "CVE-5", pkg: "curl", image: "nginx:latest" },
425
+ { id: "CVE-1", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:latest", os: true },
426
+ { id: "CVE-2", pkg: "zlib", image: "ghcr.io/mealie-recipes/mealie:latest", os: true },
427
+ { id: "CVE-3", pkg: "glibc", image: "ghcr.io/mealie-recipes/mealie:latest", os: true },
428
+ { id: "CVE-4", pkg: "libpq", image: "supabase/postgres:15.8.1.085", os: true },
429
+ { id: "CVE-5", pkg: "curl", image: "nginx:latest", os: true },
428
430
  ],
429
431
  };
430
432
  expect(imageVulnLine(facts, offers, "1549873938140499999")).toBe(
@@ -454,12 +456,12 @@ describe("Arcane image scans", () => {
454
456
  scanned: 20,
455
457
  total: 57,
456
458
  critical: [
457
- { id: "CVE-1", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest" },
458
- { id: "CVE-2", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest" },
459
- { id: "CVE-3", pkg: "zlib", image: "ghcr.io/monadeo/grimoire-server:v0.27.57@sha256:a86042bb83d85203283135f6f2762c85161a0d2458d9a5378e1a59174b946147" },
460
- { id: "CVE-4", pkg: "openssl", image: "ghcr.io/astrofoundry/bigcapital-redis:astrofoundry" },
461
- { id: "CVE-5", pkg: "pyjwt", image: "unclecode/crawl4ai:latest" },
462
- { id: "CVE-6", pkg: "openssl", image: "ghcr.io/hotio/lidarr:pr-plugins" },
459
+ { id: "CVE-1", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest", os: true },
460
+ { id: "CVE-2", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest", os: true },
461
+ { id: "CVE-3", pkg: "zlib", image: "ghcr.io/monadeo/grimoire-server:v0.27.57@sha256:a86042bb83d85203283135f6f2762c85161a0d2458d9a5378e1a59174b946147", os: true },
462
+ { id: "CVE-4", pkg: "openssl", image: "ghcr.io/astrofoundry/bigcapital-redis:astrofoundry", os: true },
463
+ { id: "CVE-5", pkg: "pyjwt", image: "unclecode/crawl4ai:latest", os: true },
464
+ { id: "CVE-6", pkg: "openssl", image: "ghcr.io/hotio/lidarr:pr-plugins", os: true },
463
465
  ],
464
466
  builds,
465
467
  };
@@ -531,16 +533,16 @@ describe("daily report", () => {
531
533
  expect(wazuh.open.map((e) => e.id)).toEqual(["o1"]);
532
534
  const builds = new Map([["ghcr.io/astrofoundry/app:1", { created: 1, newer: false }], ["ghcr.io/astrofoundry/web:1", { created: 1, newer: true }]]);
533
535
  const critical = [
534
- { id: "CVE-1", pkg: "a", image: "ghcr.io/astrofoundry/app:1" },
535
- { id: "CVE-2", pkg: "b", image: "ghcr.io/astrofoundry/app:1" },
536
- { id: "CVE-3", pkg: "c", image: "ghcr.io/astrofoundry/web:1" },
537
- { id: "CVE-4", pkg: "d", image: "docker.io/library/redis:7" },
536
+ { id: "CVE-1", pkg: "a", image: "ghcr.io/astrofoundry/app:1", os: true },
537
+ { id: "CVE-2", pkg: "b", image: "ghcr.io/astrofoundry/app:1", os: true },
538
+ { id: "CVE-3", pkg: "c", image: "ghcr.io/astrofoundry/web:1", os: true },
539
+ { id: "CVE-4", pkg: "d", image: "docker.io/library/redis:7", os: true },
538
540
  ];
539
541
  const data = { until: "06:00 CEST", timeZone: TZ, crowdsec: summary(), wazuh, found: [], closed: [], attention, images: { scanned: 57, total: 57, critical, builds }, offers: new Map(), alerts: [{ key: alertKey(oom), channelId: "c9" }] };
540
- expect(dailyNeeds(data)).toEqual([
541
- "urgent alert not acknowledged: System running out of memory. Availability of the system is in risk on space-x, 20 Oct 08:24 CEST; Acknowledge it in <#c9>",
542
- "rebuild app:1 (2): our images carry critical CVEs that have a fixed version",
543
- ]);
542
+ expect(dailyNeeds(data)).toEqual(["urgent alert not acknowledged: System running out of memory. Availability of the system is in risk on space-x, 20 Oct 08:24 CEST; Acknowledge it in <#c9>"]);
543
+ const linked = { ...data, guildId: "g1", alerts: [{ key: alertKey(oom), channelId: "c9", messageId: "m1" }, { key: alertKey(oom), channelId: "c9", messageId: "m2" }] };
544
+ expect(dailyNeeds(linked)).toEqual(["urgent alert not acknowledged: System running out of memory. Availability of the system is in risk on space-x, 20 Oct 08:24 CEST; Acknowledge it on [the alert](https://discord.com/channels/g1/c9/m2)"]);
545
+ expect(rebuildItems(data.images)).toEqual(["rebuild app:1 (2): their base image packages have critical CVEs with a fixed version"]);
544
546
  expect(dailyCard(data, [OWNER]).components[0].accent_color).toBe(0xe67e22);
545
547
  });
546
548
  });
@@ -603,11 +605,33 @@ describe("weekly report", () => {
603
605
  expect(shown.join("\n")).toContain("- RADIUS CRL: renew within 23 days (warned 19 Oct)");
604
606
  expect(out.components.at(-1)).toEqual({ type: 10, content: `<@${OWNER}>` });
605
607
  const offers = imageOffers([{ stack: "mealie", lines: [{ ref: "ghcr.io/mealie-recipes/mealie:latest" }], actionable: true, state: "offered" }]);
606
- const withImages = weeklyCard({ ...base, offers, images: { scanned: 57, total: 57, critical: [{ id: "CVE-9", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:1" }] } }, [OWNER]);
608
+ const withImages = weeklyCard({ ...base, offers, images: { scanned: 57, total: 57, critical: [{ id: "CVE-9", pkg: "openssl", image: "ghcr.io/mealie-recipes/mealie:1", os: true }] } }, [OWNER]);
607
609
  expect(texts(withImages.components)[1]).toBe("### Needs you\n1. update mealie in the Arcane Daily Report: the newer image replaces one with a critical CVE");
608
610
  expect(needsYou({ ...base, images: null })).toEqual(["1 check of this report failed; the bridge log on Cortex has the reason"]);
609
611
  });
610
612
 
613
+ it("tells base-image rebuilds from dependency updates, and Mac CVEs from stuck unattended-upgrades", () => {
614
+ const own = (id: string, pkg: string, image: string, os: boolean) => ({ id, pkg, image, os });
615
+ const critical = [
616
+ own("CVE-1", "brotli-libs", "ghcr.io/astrofoundry/webapp:1", true),
617
+ own("CVE-2", "tar", "ghcr.io/astrofoundry/server:1", false),
618
+ own("CVE-3", "handlebars", "ghcr.io/astrofoundry/server:1", false),
619
+ own("CVE-4", "handlebars", "ghcr.io/astrofoundry/server:1", false),
620
+ own("CVE-5", "vitest", "ghcr.io/astrofoundry/server:1", false),
621
+ own("CVE-6", "form-data", "ghcr.io/astrofoundry/server:1", false),
622
+ own("CVE-7", "proxy-addr", "ghcr.io/astrofoundry/server:1", false),
623
+ own("CVE-8", "certifi", "ghcr.io/monadeo/grimoire-server:v1", false),
624
+ own("CVE-9", "zlib", "docker.io/library/redis:7", true),
625
+ ];
626
+ const mac: ReportedVuln = { agent: "CORTEX", cve: "CVE-10", package: "macOS", version: "26.7.2", severity: "High", score: 7, fix: true, since: "2026-10-10T00:00:00Z" };
627
+ expect(needsYou({ ...base, images: { scanned: 57, total: 57, critical }, openWithFix: [mac, { ...mac, agent: "NEXUS", cve: "CVE-11" }] })).toEqual([
628
+ "2 macOS CVEs open after 3 days on CORTEX, NEXUS: install the waiting macOS update",
629
+ "rebuild webapp:1 (1): their base image packages have critical CVEs with a fixed version",
630
+ "update dependencies of server:1 (6: form-data, handlebars, proxy-addr, tar +1), grimoire-server:v1 (1: certifi) in their repositories: their language packages have critical CVEs with a fixed version",
631
+ ]);
632
+ expect(rebuildItems(null)).toEqual([]);
633
+ });
634
+
611
635
  it("names each unacknowledged alert and says when it never reached Discord", () => {
612
636
  const setup = event({ id: "s1", rule: "100021", level: 10, timestamp: "2026-10-19T21:31:28.085+0000", path: "/etc/sudoers.d/spc-arcane", event: "added" });
613
637
  const test1 = event({ id: "t1", rule: "100021", level: 10, timestamp: "2026-10-21T21:47:18.458+0000", path: "/etc/sudoers.d/zz-alert-test", event: "added" });
@@ -636,6 +660,10 @@ describe("weekly report", () => {
636
660
  expect(backupGuests([{ vmid: 100, ctime: 20, notes: "arcane" }, { vmid: 101, ctime: 5, notes: "hermes" }, { vmid: 101, ctime: 9, notes: "hermes", protected: 1 }])).toEqual([{ vmid: "100", name: "arcane", last: 20 }]);
637
661
  expect(resticStatus("Result=success\nExecMainStartTimestamp=Sun 2026-10-18 04:00:24 CEST\n")).toEqual({ result: "success", at: "18 Oct 04:00" });
638
662
  expect(resticStatus("nothing")).toBeNull();
663
+ const timer = "NEXT LEFT LAST PASSED UNIT ACTIVATES\nSun 2026-11-15 02:25:00 CET 5 days Sun 2026-11-08 02:25:06 CET - restic-check.timer restic-check.service\n";
664
+ expect(resticStatus(`Result=success\nExecMainStartTimestamp=\nExecMainExitTimestamp=\n${timer}`)).toEqual({ result: "success", at: "8 Nov 02:25" });
665
+ expect(resticStatus("Result=success\nExecMainStartTimestamp=\n- - - - restic-check.timer restic-check.service\n")).toEqual({ result: "success", at: "never ran" });
666
+ expect(resticStatus("Result=success\nExecMainStartTimestamp=\nSun 2026-11-15 02:25:00 CET 5 days - - restic-check.timer restic-check.service\n")).toEqual({ result: "success", at: "never ran" });
639
667
  expect(backupLine(null, 0, TZ)).toBe("Backups ยท the check failed");
640
668
  const crl = event({ rule: "100011", level: 10, timestamp: "2026-10-12T04:00:00.000+0000", log: "radius-crl-alert: days_remaining=30 threshold=30" });
641
669
  expect(crlFromEvents([crl], Date.parse("2026-10-20T04:00:00Z"))).toEqual({ days: 22, warned: crl.timestamp });
@@ -579,6 +579,8 @@ export interface ImageVuln {
579
579
  id: string;
580
580
  pkg: string;
581
581
  image: string;
582
+ /** Trivy class `os-pkgs`: the base image's distribution package, which a rebuild on a fixed base picks up. */
583
+ os: boolean;
582
584
  }
583
585
 
584
586
  /** What `images list` says about one image tag: when it was built, and whether its registry has a newer build. */
@@ -616,7 +618,7 @@ export function parseImageVulns(summary: unknown, list: unknown): ImageVulnFacts
616
618
  for (const v of data as Record<string, unknown>[]) {
617
619
  if (typeof v.vulnerabilityId !== "string" || typeof v.imageName !== "string" || v.ignored === true) continue;
618
620
  if (typeof v.fixedVersion !== "string" || v.fixedVersion.length === 0) continue;
619
- critical.push({ id: v.vulnerabilityId, pkg: typeof v.pkgName === "string" ? v.pkgName : "?", image: v.imageName });
621
+ critical.push({ id: v.vulnerabilityId, pkg: typeof v.pkgName === "string" ? v.pkgName : "?", image: v.imageName, os: v.class === "os-pkgs" });
620
622
  }
621
623
  return { scanned: s.scannedImages, total: s.totalImages, critical };
622
624
  }
@@ -722,17 +724,42 @@ export function imageVulnLine(facts: ImageVulnFacts | null, offers: ReadonlyMap<
722
724
  return parts.join(" ยท ");
723
725
  }
724
726
 
725
- /** Our own images with critical CVEs that have a fix and no newer build in the registry: only our rebuild closes them. */
726
- export function rebuildItem(facts: ImageVulnFacts | null): string | null {
727
- if (!facts) return null;
728
- const counts = new Map<string, number>();
727
+ /** Most package names an image's dependency item shows. */
728
+ const MAX_PACKAGES = 4;
729
+
730
+ /**
731
+ * Our own images with critical CVEs that have a fix and no newer build in the
732
+ * registry, by what closes them: a rebuild picks up fixed base-image packages,
733
+ * while language packages (npm, Python, Go binaries) need a dependency update
734
+ * in the image's repository. Developer work, so only the weekly report lists it.
735
+ */
736
+ export function rebuildItems(facts: ImageVulnFacts | null): string[] {
737
+ if (!facts) return [];
738
+ const os = new Map<string, number>();
739
+ const lang = new Map<string, { n: number; pkgs: Set<string> }>();
729
740
  for (const v of facts.critical) {
730
741
  const build = facts.builds?.get(v.image) ?? facts.builds?.get(v.image.split("@")[0]);
731
- if (isOwnImage(v.image) && !build?.newer) counts.set(v.image, (counts.get(v.image) ?? 0) + 1);
742
+ if (!isOwnImage(v.image) || build?.newer) continue;
743
+ if (v.os) os.set(v.image, (os.get(v.image) ?? 0) + 1);
744
+ else {
745
+ const entry = lang.get(v.image) ?? { n: 0, pkgs: new Set<string>() };
746
+ entry.n++;
747
+ entry.pkgs.add(v.pkg);
748
+ lang.set(v.image, entry);
749
+ }
750
+ }
751
+ const byCount = <T>(m: Map<string, T>, count: (t: T) => number) => [...m.entries()].sort((x, y) => count(y[1]) - count(x[1]) || x[0].localeCompare(y[0]));
752
+ const items: string[] = [];
753
+ if (os.size > 0) items.push(`rebuild ${byCount(os, (n) => n).map(([image, n]) => `${escapeDiscord(shortImageName(image))} (${n})`).join(", ")}: their base image packages have critical CVEs with a fixed version`);
754
+ if (lang.size > 0) {
755
+ const images = byCount(lang, (e) => e.n).map(([image, e]) => {
756
+ const pkgs = [...e.pkgs].sort();
757
+ const shown = pkgs.slice(0, MAX_PACKAGES).map(escapeDiscord).join(", ");
758
+ return `${escapeDiscord(shortImageName(image))} (${e.n}: ${shown}${pkgs.length > MAX_PACKAGES ? ` +${pkgs.length - MAX_PACKAGES}` : ""})`;
759
+ });
760
+ items.push(`update dependencies of ${images.join(", ")} in their repositories: their language packages have critical CVEs with a fixed version`);
732
761
  }
733
- if (counts.size === 0) return null;
734
- const images = [...counts.entries()].sort((x, y) => y[1] - x[1] || x[0].localeCompare(y[0])).map(([image, n]) => `${escapeDiscord(shortImageName(image))} (${n})`);
735
- return `rebuild ${images.join(", ")}: our images carry critical CVEs that have a fixed version`;
762
+ return items;
736
763
  }
737
764
 
738
765
  // ---------------------------------------------------------------- reports
@@ -768,6 +795,9 @@ function card(groups: readonly (readonly string[])[], attention: boolean, mentio
768
795
  return [{ type: 17, accent_color: attention ? ORANGE : GREEN, components }, ...(mention ? [{ type: 10, content: mention }] : [])];
769
796
  }
770
797
 
798
+ /** Where an alert was posted; its message carries the Acknowledge button. */
799
+ export type PostedAlertRef = Pick<PostedAlert, "key" | "channelId"> & { messageId?: string };
800
+
771
801
  export interface DailyData {
772
802
  /** Local time the report covers up to, already formatted (`06:00 CEST`). */
773
803
  until: string;
@@ -782,7 +812,9 @@ export interface DailyData {
782
812
  /** The Arcane Daily Report's channel, linked from offered updates. */
783
813
  arcaneChannelId?: string;
784
814
  /** Alerts posted to Discord, to tell an unacknowledged alert from one that was never posted. */
785
- alerts: readonly Pick<PostedAlert, "key" | "channelId">[];
815
+ alerts: readonly PostedAlertRef[];
816
+ /** The server, for links to the posted alert itself. */
817
+ guildId?: string;
786
818
  }
787
819
 
788
820
  function headline(urgent: number, unexplained: number, health: number, failed: number): string {
@@ -804,14 +836,12 @@ export function dailyNeedsOwner(d: DailyData): boolean {
804
836
  return (d.attention?.issues.length ?? 0) > 0 || failures(d) > 0;
805
837
  }
806
838
 
807
- /** What the owners must act on today: health issues, unexplained changes, open urgent alerts, our images to rebuild, failed checks. */
839
+ /** What the owners must act on today: health issues, unexplained changes, open urgent alerts, failed checks. Our images' CVEs are developer work for the weekly report. */
808
840
  export function dailyNeeds(d: DailyData): string[] {
809
841
  const items: string[] = [];
810
842
  for (const i of d.attention?.issues ?? []) items.push(escapeDiscord(i.message.replace(/\.$/, "")));
811
843
  if (d.wazuh.unexplained.length > 0) items.push(`${d.wazuh.unexplained.length} unexplained deployment change${d.wazuh.unexplained.length === 1 ? "" : "s"}; Investigate on the alert`);
812
- items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone));
813
- const rebuild = rebuildItem(d.images);
814
- if (rebuild) items.push(rebuild);
844
+ items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone, d.guildId));
815
845
  const failed = failures(d);
816
846
  if (failed > 0) items.push(`${failed} check${failed === 1 ? "" : "s"} of this report failed; the bridge log on Cortex has the reason`);
817
847
  return items;
@@ -871,7 +901,9 @@ export interface WeeklyData {
871
901
  offers: ReadonlyMap<string, ImageOffer>;
872
902
  arcaneChannelId?: string;
873
903
  /** Alerts posted to Discord, to tell an unacknowledged alert from one that was never posted. */
874
- alerts: readonly Pick<PostedAlert, "key" | "channelId">[];
904
+ alerts: readonly PostedAlertRef[];
905
+ /** The server, for links to the posted alert itself. */
906
+ guildId?: string;
875
907
  last24h: { bans: number | null; wazuh: number | null; urgent: number; found: number | null; closed: number | null; health: number | null };
876
908
  }
877
909
 
@@ -893,10 +925,25 @@ export function backupGuests(value: unknown): BackupFacts["guests"] | null {
893
925
  .sort((x, y) => x.vmid.localeCompare(y.vmid));
894
926
  }
895
927
 
928
+ const TIMER_TIME = /(\d{4})-(\d{2})-(\d{2}) (\d{2}:\d{2}):\d{2}/g;
929
+
930
+ /**
931
+ * The LAST column of the `systemctl list-timers` line: systemd forgets the
932
+ * service's start time when the host restarts, but the timer keeps it. NEXT
933
+ * comes first and is `-` when nothing is scheduled.
934
+ */
935
+ function timerLastRun(text: string): RegExpExecArray | null {
936
+ const line = text.split("\n").find((l) => /\.timer\s/.test(l));
937
+ if (!line) return null;
938
+ const times = [...line.matchAll(TIMER_TIME)];
939
+ const hasNext = !line.trimStart().startsWith("-");
940
+ return (hasNext ? times[1] : times[0]) ?? null;
941
+ }
942
+
896
943
  /** `restic-check-status`: systemd's `Result=` and the start of the last run, as printed (local time). */
897
944
  export function resticStatus(text: string): BackupFacts["restic"] {
898
945
  const result = /^Result=(\S+)/m.exec(text)?.[1];
899
- const started = /^ExecMainStartTimestamp=\S+ (\d{4})-(\d{2})-(\d{2}) (\d{2}:\d{2})/m.exec(text);
946
+ const started = /^ExecMainStartTimestamp=\S+ (\d{4})-(\d{2})-(\d{2}) (\d{2}:\d{2})/m.exec(text) ?? timerLastRun(text);
900
947
  if (!result) return null;
901
948
  const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
902
949
  return { result, at: started ? `${Number(started[3])} ${months[Number(started[2]) - 1]} ${started[4]}` : "never ran" };
@@ -943,31 +990,40 @@ function crlText(crl: WeeklyData["crl"], timeZone: string): string {
943
990
  }
944
991
 
945
992
  /** One item per open alert key the owners did not acknowledge: what changed, when, and where to acknowledge it, if anywhere. */
946
- function unacknowledgedItems(wazuh: WazuhDigest, alerts: readonly Pick<PostedAlert, "key" | "channelId">[], timeZone: string): string[] {
993
+ function unacknowledgedItems(wazuh: WazuhDigest, alerts: readonly PostedAlertRef[], timeZone: string, guildId?: string): string[] {
947
994
  const groups = new Map<string, WazuhEvent[]>();
948
995
  for (const e of wazuh.open) if (e.rule !== DEPLOYMENT_RULE) groups.set(alertKey(e), [...(groups.get(alertKey(e)) ?? []), e]);
949
996
  return [...groups.entries()].map(([key, events]) => {
950
997
  const last = events.reduce((a, b) => (Date.parse(b.timestamp) > Date.parse(a.timestamp) ? b : a));
951
998
  const what = last.path ? `\`${last.path.replace(/`/g, "'")}\` ${escapeDiscord(last.event ?? "changed")}` : escapeDiscord(issueLabel(last));
952
999
  const when = events.length > 1 ? ` ร— ${events.length}, last ${clockText(last.timestamp, timeZone)}` : `, ${clockText(last.timestamp, timeZone)}`;
953
- const posted = alerts.find((a) => a.key === key);
1000
+ const posted = alerts.filter((a) => a.key === key).at(-1);
954
1001
  const fact = `${what} on ${escapeDiscord(last.agent)}${when}`;
955
- return posted ? `urgent alert not acknowledged: ${fact}; Acknowledge it in <#${posted.channelId}>` : `urgent alert never posted, so it has no Acknowledge button: ${fact}; check that it was expected`;
1002
+ if (!posted) return `urgent alert never posted, so it has no Acknowledge button: ${fact}; check that it was expected`;
1003
+ const where = guildId && posted.messageId ? `on [the alert](https://discord.com/channels/${guildId}/${posted.channelId}/${posted.messageId})` : `in <#${posted.channelId}>`;
1004
+ return `urgent alert not acknowledged: ${fact}; Acknowledge it ${where}`;
956
1005
  });
957
1006
  }
958
1007
 
1008
+ /** The package name Wazuh gives a Mac's operating system in its vulnerability findings. */
1009
+ const MACOS_PACKAGE = "macOS";
1010
+
959
1011
  export function needsYou(d: WeeklyData): string[] {
960
1012
  const items: string[] = [];
961
1013
  for (const i of d.attention?.issues ?? []) items.push(escapeDiscord(i.message.replace(/\.$/, "")));
962
1014
  if (d.wazuh.unexplained.length > 0) items.push(`${d.wazuh.unexplained.length} unexplained deployment change${d.wazuh.unexplained.length === 1 ? "" : "s"} this week; Investigate on the alert`);
963
- items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone));
1015
+ items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone, d.guildId));
964
1016
  if (d.patching && d.patching.rebootPending.length > 0) items.push(`reboot ${d.patching.rebootPending.map(escapeDiscord).join(", ")} to load installed updates`);
965
1017
  const stuck = d.openWithFix.filter((v) => d.now - Date.parse(v.since) > 3 * DAY);
966
- if (stuck.length > 0) items.push(`${stuck.length} CVE${stuck.length === 1 ? "" : "s"} with a fixed version still open after 3 days (${[...new Set(stuck.map((v) => v.agent))].map(escapeDiscord).join(", ")}); unattended-upgrades may be stuck`);
1018
+ const agents = (list: readonly ReportedVuln[]) => [...new Set(list.map((v) => v.agent))].map(escapeDiscord).join(", ");
1019
+ // Wazuh reports a Mac's own CVEs under the package `macOS`; only a macOS update closes them, never unattended-upgrades.
1020
+ const mac = stuck.filter((v) => v.package === MACOS_PACKAGE);
1021
+ const linux = stuck.filter((v) => v.package !== MACOS_PACKAGE);
1022
+ if (linux.length > 0) items.push(`${linux.length} CVE${linux.length === 1 ? "" : "s"} with a fixed version still open after 3 days (${agents(linux)}); unattended-upgrades may be stuck`);
1023
+ if (mac.length > 0) items.push(`${mac.length} macOS CVE${mac.length === 1 ? "" : "s"} open after 3 days on ${agents(mac)}: install the waiting macOS update`);
967
1024
  const offered = offeredImages(d.images, d.offers);
968
1025
  if (offered.length > 0) items.push(`update ${offered.map(escapeDiscord).join(", ")} in the Arcane Daily Report: the newer image replaces one with a critical CVE`);
969
- const rebuild = rebuildItem(d.images);
970
- if (rebuild) items.push(rebuild);
1026
+ items.push(...rebuildItems(d.images));
971
1027
  if (d.crl !== null && d.crl !== "unknown") items.push(`renew the RADIUS CRL (wifi-device.sh renew-crl), ${d.crl.days} days left`);
972
1028
  if (d.backups) {
973
1029
  const stale = d.backups.guests.filter((g) => d.now / 1000 - g.last > STALE_BACKUP_S);
@@ -71,6 +71,8 @@ describe("approvals", () => {
71
71
  expect(isRisky("backup", ["vzdump-run", "107"])).toBe(true);
72
72
  expect(isRisky("media", ["add-movies", "tt1160419"])).toBe(false);
73
73
  expect(isRisky("media", ["sabnzbd", "pause"])).toBe(false);
74
+ expect(isRisky("media", ["queue"])).toBe(false);
75
+ expect(isRisky("media", ["queue-remove", "radarr", "7"])).toBe(true);
74
76
  });
75
77
 
76
78
  it("creates a ticket and polls until decided", async () => {
@@ -47,7 +47,8 @@ export const RISKY: Readonly<Record<string, readonly RegExp[]>> = {
47
47
  inference: [/^(nexus-restart|nexus-start)\b/],
48
48
  // A person solves the challenge in the live view; the Approve button means it is solved.
49
49
  research: [/^captcha-help\b/],
50
- // media has no entry: trendarr cannot delete anything, and adds and queue toggles run on the caller's request.
50
+ // Adds and queue pauses run on the caller's request; removing a queue record deletes its download.
51
+ media: [/^queue-remove\b/],
51
52
  };
52
53
 
53
54
  export function isRisky(service: string, args: readonly string[]): boolean {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.40.65",
3
+ "version": "0.40.66",
4
4
  "description": "Personal pi customizations (extensions, subagents, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -57,6 +57,8 @@ The answer is JSON with `status`: `updated`, `rolled back`, `failed` (with `reas
57
57
 
58
58
  It refuses `arcane` (next section), stopped stacks (a redeploy would start them), a checkout with local or unpushed changes, and held stacks. Held stacks are listed in `update-holds.json` at the root of the GitOps repository, `{ "<stack>": "<reason>" }`; a key `<stack>/<service>` holds one service, which `stack-update` skips while the rest of the stack updates. `update-report` returns them in `holds`, and the daily report shows the reason without a button. Change that file only when the caller asks, through the `git` commands.
59
59
 
60
+ Never stop a stack or a service before `stack-update` to drain it: the redeploy pulls first, then Compose recreates each changed container, and Docker waits the service's `stop_grace_period` after SIGTERM before SIGKILL (Arcane 2.17.3 sets no shorter stop timeout and gives the redeploy its deploy wait plus 30 minutes). A README or ROLLOUT that asks for a graceful drain, such as grimoire-graphile's 750 seconds, is met by `stack-update` itself; a stopped stack is refused.
61
+
60
62
  An update across a major version is refused without `--confirm`: summarise its release notes first (next section), get the caller's go, then run `["stack-update", "<stack>", "--confirm"]`, which asks an owner for approval.
61
63
 
62
64
  ## Release notes
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: media
3
- description: How the media specialist finds trending titles, resolves and adds movies and series, and controls the SABnzbd queue through the media tool (trendarr).
3
+ description: How the media specialist finds trending titles, resolves and adds movies and series, controls the SABnzbd queue through the media tool (trendarr), and clears imports stuck in the Radarr and Sonarr queues.
4
4
  ---
5
5
 
6
6
  # Media specialist
@@ -18,6 +18,8 @@ description: How the media specialist finds trending titles, resolves and adds m
18
18
  | `["add-movies", "tt1160419", "tt0468569"]` | add to Radarr and search (at most 20 IDs) |
19
19
  | `["add-series", "tt0903747"]` | IMDb โ†’ TVDB through TMDB, add to Sonarr and search |
20
20
  | `["sabnzbd", "status"]`, `["sabnzbd", "pause"]`, `["sabnzbd", "resume"]` | queue pause state; `pause` and `resume` act, then report the new state |
21
+ | `["queue"]` | Radarr and Sonarr queue records that wait for a person: an import pending, blocked, or failed |
22
+ | `["queue-remove", "radarr", "7", "--confirm"]` | remove that record and delete its download from SABnzbd, without blocklisting the release; asks an owner for approval |
21
23
 
22
24
  ## Output
23
25
 
@@ -26,6 +28,12 @@ description: How the media specialist finds trending titles, resolves and adds m
26
28
  - `in_library: null` means Radarr or Sonarr could not answer or the series has no TVDB mapping: it is uncertainty, not absence. Try the add; its result decides.
27
29
  - `add-movies`, `add-series`: `{ "results": [{ "imdb_id", "title", "status", "detail" }], "sabnzbd_paused": true|false|null, "warnings": [...] }`. `status` is `added` (search started), `already_exists`, `not_found` (nothing added), or `error` (read `detail`). The tool succeeds even when an ID fails; always read each status.
28
30
  - `sabnzbd`: `{ "sabnzbd_paused": true|false }`.
31
+ - `queue`: `{ "records": [{ "app", "id", "title", "state", "status", "messages", "added", "size" }], "warnings": [...] }`; `state` is `importPending`, `importBlocked`, or `failedPending`, `messages` are Radarr's or Sonarr's reasons. An app that did not answer is a warning, not an empty queue.
32
+ - `queue-remove`: `{ "status": "removed", "app", "id" }`.
33
+
34
+ ## Stuck imports
35
+
36
+ The morning run lists each queue record older than a day under Media, with its reason and the `queue-remove` it needs; the owner's reply to that message comes to you. Run `queue` first and check that the record still exists and its reason. When the reason says the download is not an upgrade of the file already in the library (a lower custom format score, the same quality), removing it loses nothing: say so, then run `queue-remove` with `--confirm`, which asks an owner for approval. For any other reason (a wrong match, an unknown file, a missing episode), report it and ask what the owner wants before removing anything; never import by hand.
29
37
  - `warnings` carries trendarr's own warnings, such as an unreachable Radarr; mention them when they change the answer.
30
38
 
31
39
  ## Resolving a title
@@ -58,11 +58,11 @@ Wrappers ship as TypeScript and run under Node 24 type stripping: erasable synta
58
58
  - `entry/specialist-install.sh` runs as root, so it runs only `/usr/bin`, `/bin`, `/usr/sbin`, `/sbin` and the Node it installed, never Homebrew or anything else the main user can write; it checks that `/usr/local/libexec/specialist-node` (and each `specialist-<tool>` folder) and its parents belong to root and are writable by nobody else. Arguments are checked before the root test (tests exercise that part). Downloads go to a root-only temporary directory and are verified before use: Node against `SHASUMS256.txt` and the LTS flag in `index.json`, npm tarballs against the registry's `sha512` integrity, arcane-cli against the release's checksums file. Inside `/Users/specialist` it works only as `specialist` (`sudo -u specialist -H`), from a staging directory root hands over, so a link the specialist plants cannot redirect a root write. Each component switches by rename after a check (every installed wrapper's `--help`, `--version` of the new binary) and restores the previous copy when the check fails. Older versions are refused; `rollback` swaps current and previous. `python`, `gcloud`, `bw`, and `jq` follow the same rules: version folders under `/usr/local/libexec/specialist-<tool>/` behind the links `current` and `previous`, sealed `root:wheel` and not writable by others, smoke-tested as `specialist` before `current` moves; `python` refuses a switch that breaks the current gcloud. Consumers use the `current` paths: `provision.sh` for `bw` and `jq`, `edge.json` for `gcloud` and `gcloudPython`. Nothing a wrapper runs with secrets may come from Homebrew.
59
59
  - `main()` waits for stdout and stderr to flush before `process.exit`: on a pipe, exiting right after a write drops everything past the 64 KiB buffer, which cut large answers such as `projects list --all` until 2026-09-25 (`lib/flush.test.ts`).
60
60
  - `arcane update-report [--all]` is `lib/image-updates.ts` over `lib/registry.ts`: a fresh `images updates check --all`, then `projects list --all` for the stack and service of each image reference, then the registries' tag lists and manifest digests (anonymous bearer tokens from each registry's challenge; digests by HEAD, which Docker Hub does not count as a pull; lscr.io is read from ghcr.io). A floating or major-series tag is resolved to the release tag whose digest matches the running and the latest build, searching the newest tags of the three commonest release shapes; a fixed tag is compared with the newest tag of the same shape; a digest pin with the newest release. Checks older than one minute before the run count as stale and show as unknown. Private images (anonymous access refused with 401 or 403) are excluded from rows, counts, and table, listed in `privateImages`, and counted in the summary line. The table is fixed-width text for a code block, because Discord renders no Markdown tables. The answer adds `holds` from `update-holds.json` at origin's branch head (`git show`, no working-tree read), or `holdsError` when that file is malformed.
61
- - `arcane stack-update <stack> [--confirm]` (`lib/stack-update.ts` for the pure parts) is deterministic: refuses `arcane`, held stacks (the checkout's `update-holds.json` after `pull --ff-only`; a malformed file is an error; a `<stack>/<service>` key skips that service's rows instead), a dirty or ahead checkout, stopped stacks, and an update across a major version without `--confirm` (which the gate turns into an owner approval). Pending rows come from a fresh per-image check resolved like `update-report`. `edit tag`/`edit digest` rows rewrite `image:` lines that name exactly the old reference (`replaceImageRef`, quoted or not, trailing comment kept) in the sync's `composePath`, then commit, push, and wait for `gitops list` to report success at that commit (20 min, polled every 30 s). Then `projects redeploy <stack> --yes` (35 min), container checks through `containers list --all` and `containers get` (`composeInfo.projectName`, health; 5 min, polled every 15 s; a job that exited with code 0 counts as done whatever health its image's inherited check left, as bigcapital's migration did on 2026-10-28), and a fresh check that each service is current. A failure after a commit reverts, pushes, waits for the sync, redeploys, and checks again (`rolled back`); a pull-only failure stays `failed`. Every outcome prints JSON with `status` and exits 0. Worst case about 125 minutes, so the gate's `timeoutMs` for arcane must exceed it (8,100,000). It holds the `arcane-gitops` lock, so a second checkout call waits up to 2 minutes and then fails as busy; the bridge also runs one Arcane update at a time.
61
+ - `arcane stack-update <stack> [--confirm]` (`lib/stack-update.ts` for the pure parts) is deterministic: refuses `arcane`, held stacks (the checkout's `update-holds.json` after `pull --ff-only`; a malformed file is an error; a `<stack>/<service>` key skips that service's rows instead), a dirty or ahead checkout, stopped stacks, and an update across a major version without `--confirm` (which the gate turns into an owner approval). Pending rows come from a fresh per-image check resolved like `update-report`. `edit tag`/`edit digest` rows rewrite `image:` lines that name exactly the old reference (`replaceImageRef`, quoted or not, trailing comment kept) in the sync's `composePath`, then commit, push, and wait for `gitops list` to report success at that commit (20 min, polled every 30 s). Then `projects redeploy <stack> --yes` (35 min; Arcane v2.17.3 pulls every image, then runs Compose up without a stop timeout, so each recreated container gets its `stop_grace_period` before SIGKILL: grimoire-graphile's 750-second queue drain needs no separate stop, checked against the Arcane and Compose sources on 2026-11-10), container checks through `containers list --all` and `containers get` (`composeInfo.projectName`, health; 5 min, polled every 15 s; a job that exited with code 0 counts as done whatever health its image's inherited check left, as bigcapital's migration did on 2026-10-28), and a fresh check that each service is current. A failure after a commit reverts, pushes, waits for the sync, redeploys, and checks again (`rolled back`); a pull-only failure stays `failed`. Every outcome prints JSON with `status` and exits 0. Worst case about 125 minutes, so the gate's `timeoutMs` for arcane must exceed it (8,100,000). It holds the `arcane-gitops` lock, so a second checkout call waits up to 2 minutes and then fails as busy; the bridge also runs one Arcane update at a time.
62
62
  - `arcane host <command>` runs over the forced-command key of user `spc-arcane` on VM 100. `HOST_COMMANDS` in `lib/arcane-host.ts` must list exactly the operations of `entry/remote/spc-arcane-op.py` (a test compares them); the tracked copies live in the arcane repository's `host/` (`spc-arcane-host-entry`, `spc-arcane-op`, `spc-arcane-sudoers`, `spc-arcane-install.sh`) with the probes in `host/spc-arcane-probes/`. The entry only splits words (letters, digits, space, `._:/+-`) and hands them to `sudo -n /usr/local/sbin/spc-arcane-op`, the one command its sudoers line allows; the op checks the name and every argument and runs the reviewed arcane-ops probes, which print only allowlisted fields. Manager steps (`manager-*`) are internal to `manager-upgrade`/`manager-rollback` and refused through `host`. Nothing on the host deletes data: a manager rollback restores the image and Compose file, not the data volume (R3 stays manual), `db-restore` only fills an empty database, and dumps are never pruned by the tool. `supabase-backup` writes the pre-change backup of `supabase/AGENTS.md` (both databases with `pg_dump -Fc`, each listed and fully decoded by `pg_restore`, `pg_dumpall --globals-only`, and the `supabase-db-config` volume, which must hold `pgsodium_root.key`) into `/var/backups/supabase-upgrades/<UTC>`, the folder of the earlier manual backups. `host-audit` compares the host's hashes with `host/<name>` of the `arcane-gitops` checkout after a pull. The `bigcapital-*` commands run the base-image upgrade of `bigcapital/README.md`: an online backup, a rehearsal on an internal Docker network (restore into the current MariaDB, upgrade with the build's, migrations, server health, Envoy validation; everything it created removed afterwards), the owner-approved switch (stop, quiescent dump, Redis `SAVE`, volume copies compared entry by entry, the stack left stopped for the GitOps commit, the old volumes untouched), and a verify against the switch's row counts and ledger totals.
63
63
  - `arcane manager-upgrade <version>` (`lib/arcane-manager.ts`) follows arcane/AGENTS.md "Manager upgrades": the official image's revision label must equal the release tag's commit (GitHub API), `manager-prepare` records `compose.before.yaml` and every container before the pin commit, the pin goes through the `arcane-gitops` checkout (`git` is exported from `lib/repo.ts` for this), the wait polls `gitops list` and the deployed Compose hash every 30 s for up to 30 minutes, then pull, cold backup, `up -d --no-deps --pull never`, and checks. Any failure before the restart reverts the pin (`stopped`); a failed check after it reverts the pin and runs `manager-rollback` (`rolled back`). The answer always exits 0 with `status`, so the bridge and the agent both see it.
64
64
  - `research` is a pure forced-command wrapper: every call is one JSON request on stdin to `request` on VM 110 (`10.1.100.10`, user `spc-research`, key `SSH_KEY_SANDBOX`), whose entry hands it to `spc-research-op` as `researcher` (tracked in the homelab repository's `06-space-x-proxmox/research/system/`). The op attaches one playwright-cli session per Discord thread (`t<id>`) to the shared Chrome over CDP on `127.0.0.1:9222` and opens its own tab; cookie, storage, `run-code`, and browser lifecycle commands are refused. `script` runs the agent's code in the thread folder as `researcher` (5 minutes), on a VM that reaches only the internet (Mira's Sandbox zone plus the VM's own nftables). Defaults stay on Cortex in `work/research/defaults.json`, out of the sandbox's reach. `captcha-help` is in `RISKY`, so its owner approval is the moment the owner solved the challenge in the live view (`research-browser.37pla.net`); the bridge renders that ticket with the channel's `liveView` link.
65
- - `media` runs trendarr unchanged: `trendarrCli` in `media.json` is its `dist/cli.js`, started with `process.execPath` because sudo's PATH has no node. Each call gets `HOME` set to a fresh `0700` directory under `~/.specialists/work/media/` that holds only `.trendarr/config.json` (`0600`, trendarr's own schema, built from the note fields and `media.json`) and is removed in `finally`; trendarr reads no environment variables and has no config flag, and Node's `os.homedir()` follows `$HOME` on POSIX. Every call passes `--json`; `init` is refused. An add prints trendarr's per-ID `results` and exits 0 even when trendarr exits 1 for a failed ID, because the gate shows only stderr on failure; other failures carry trendarr's stderr without its `warning:` lines, which go into the JSON as `warnings`. The bridge's slash commands and Add buttons call the same wrapper through the entry point (`extensions/astro-discord/media.ts`).
65
+ - `media` runs trendarr unchanged: `trendarrCli` in `media.json` is its `dist/cli.js`, started with `process.execPath` because sudo's PATH has no node. Each call gets `HOME` set to a fresh `0700` directory under `~/.specialists/work/media/` that holds only `.trendarr/config.json` (`0600`, trendarr's own schema, built from the note fields and `media.json`) and is removed in `finally`; trendarr reads no environment variables and has no config flag, and Node's `os.homedir()` follows `$HOME` on POSIX. Every call passes `--json`; `init` is refused. An add prints trendarr's per-ID `results` and exits 0 even when trendarr exits 1 for a failed ID, because the gate shows only stderr on failure; other failures carry trendarr's stderr without its `warning:` lines, which go into the JSON as `warnings`. The bridge's slash commands and Add buttons call the same wrapper through the entry point (`extensions/astro-discord/media.ts`). `queue` and `queue-remove` (since 0.40.66) skip trendarr, which has no queue records: the wrapper calls `/api/v3/queue` of Radarr and Sonarr itself with the note's keys in the `X-Api-Key` header and prints only `stuckRecords` fields (no paths or download ids); `queue-remove` sends `DELETE /api/v3/queue/<id>?removeFromClient=true&blocklist=false`, needs `--confirm`, and is in `RISKY`.
66
66
  - `arcane release-notes <stack>[/<service>]` is `lib/releases.ts`: a single-image check and `resolveRef` give the running and latest versions, `HttpRegistry.labels` reads `org.opencontainers.image.source` from the latest image (index to linux/amd64 manifest to config blob), and the anonymous GitHub releases API (60 requests an hour, up to 3 pages of 100) gives the releases in between, oldest first. `condenseNotes` keeps each release under 12,000 characters by section priority; `capTotal` drops the oldest releases past 40,000 characters in total.
67
67
 
68
68
  ## Gate
@@ -13,7 +13,7 @@ A specialist is a Pi subagent that is the only way to operate one area of the ho
13
13
  | `astro.backup` | vzdump, the shared Restic repository (Pulsar host config, Arcane app backups), GCS offsite from LXC 102 | Status, journals, and manual runs of every layer; `restic-snapshots|stats|ls`, `restic-restore` into `/var/tmp/spc-restore` on Pulsar, `restore-clean` |
14
14
  | `astro.proxmox` | Proxmox VE on Pulsar (37) and SPACE-X (Mira) | API token: `guests`, `guest`, `get <path>`, `tasks`; `start`, `shutdown|reboot|stop --confirm`; snapshots create, delete, rollback; `set` of CPU, memory, options, network. Host key: `host-status`, `host-journal`, `updates`, `host-upgrade` (apt full-upgrade; a new Proxmox VE major is held), `host-reboot --confirm`, `guest-exec <vmid> <status|journal|df|updates>`, `nightly-journal <days>`; `nightly [days]` combines the vzdump tasks with that journal into a table of nightly run times. Every command runs on Pulsar, or on SPACE-X with the `space-x` prefix |
15
15
  | `astro.inference` | MLX embedding and reranking servers on Nexus, Europa health | `nexus-status|start|stop|restart|log|disk`, `macos-updates`; `europa-health` |
16
- | `astro.media` | trendarr over TMDB, OMDb, and the `media` project on VM 100 (Radarr, Sonarr, SABnzbd) | `trending`, `search`, `recommend`, `add-movies`, `add-series` (at most 20 IMDb IDs), `sabnzbd status|pause|resume`; always trendarr's JSON plus its warnings |
16
+ | `astro.media` | trendarr over TMDB, OMDb, and the `media` project on VM 100 (Radarr, Sonarr, SABnzbd) | `trending`, `search`, `recommend`, `add-movies`, `add-series` (at most 20 IMDb IDs), `sabnzbd status|pause|resume`, `queue`, `queue-remove <radarr|sonarr> <id> --confirm`; trendarr's JSON plus its warnings, the queue commands straight from Radarr and Sonarr |
17
17
  | `astro.research` | the research sandbox, VM 110 at Mira (Chrome on a virtual screen, scripts, thread folders), through the forced-command key of user `spc-research`; defaults in `~/.specialists/work/research/defaults.json` | `browser <session> <playwright-cli args>`, `captcha`, `captcha-help` (owner approval: solved in the live view), `script`, `read`, `files`, `toolbox`, `defaults list|set|unset`; the sandbox's JSON |
18
18
 
19
19
  Call one with `/run astro.<name> -- <task>` or through the `subagent` tool (both from the bundled `astro-subagents` extension). `/run` saves the specialist's session under `~/.pi/agent/subagent-sessions/<agent>/`; `/run astro.<name> --continue -- <task>` resumes the last one started from the same directory, so the specialist keeps what it saw. Sessions older than 7 days are deleted. Specialists may call each other once (`maxSubagentDepth: 1`). They run on `openai-codex/gpt-6-astra` with `xhigh` thinking, set by `model` and `thinking` in each `agents/<name>.md`; an agent without these fields inherits the caller's model and thinking. Each tool takes `args`, an array of strings; `["--help"]` lists the subcommands.
@@ -27,7 +27,7 @@ Call one with `/run astro.<name> -- <task>` or through the `subagent` tool (both
27
27
  - Every call is logged in `/Users/specialist/.specialists/audit.log`.
28
28
  - The `specialist-gate` extension registers the tool only inside the matching specialist child and blocks other agents from calling the CLIs or reading `/Users/specialist`. `security-guard` carries the same blocks.
29
29
 
30
- Limits: `network` writes through the UniFi Network API plus a few narrow commands on the Network application's own paths (`nat-write`, `device-network`, `client-fixed-ip`, `syslog`, `app-policy-delete`, `portforward-delete`); it cannot change Site Magic. `security` is read-only. `identity` deploys only `config.yaml` to the DMZ and upgrades Pomerium to an official release whose sha256 matches (`dmz pomerium-upgrade`). `edge` changes only `nginx.conf` on the VPS and can reboot it. `dns` writes zones, records, and the cluster only on the Technitium primary; on another node it only sets the server domain, resyncs a zone, or deletes a stale Secondary zone, and `technitium host` restarts or upgrades one node at a time. `proxmox` cannot create, clone, or destroy guests, change disks, or change the host configuration; on a host it only upgrades packages (`host-upgrade`) and reboots (`host-reboot --confirm`). `backup` cannot change retention or schedules. `inference` cannot start Europa or change models. `media` adds titles and toggles the download queue; it cannot delete anything or change Radarr, Sonarr, or SABnzbd settings.
30
+ Limits: `network` writes through the UniFi Network API plus a few narrow commands on the Network application's own paths (`nat-write`, `device-network`, `client-fixed-ip`, `syslog`, `app-policy-delete`, `portforward-delete`); it cannot change Site Magic. `security` is read-only. `identity` deploys only `config.yaml` to the DMZ and upgrades Pomerium to an official release whose sha256 matches (`dmz pomerium-upgrade`). `edge` changes only `nginx.conf` on the VPS and can reboot it. `dns` writes zones, records, and the cluster only on the Technitium primary; on another node it only sets the server domain, resyncs a zone, or deletes a stale Secondary zone, and `technitium host` restarts or upgrades one node at a time. `proxmox` cannot create, clone, or destroy guests, change disks, or change the host configuration; on a host it only upgrades packages (`host-upgrade`) and reboots (`host-reboot --confirm`). `backup` cannot change retention or schedules. `inference` cannot start Europa or change models. `media` adds titles, toggles the download queue, and removes a stuck queue record with its download after an owner's approval; it cannot delete library files or change Radarr, Sonarr, or SABnzbd settings.
31
31
 
32
32
  ## Enable specialists on a host
33
33
 
@@ -107,8 +107,13 @@ const HELP = `media specialist (trendarr: TMDB trending, OMDb ratings, Radarr an
107
107
  add-movies <imdbId...> add to Radarr monitored and start a search (at most ${MAX_ADD_IDS} IDs)
108
108
  add-series <imdbId...> add to Sonarr monitored and start a search (at most ${MAX_ADD_IDS} IDs)
109
109
  sabnzbd status|pause|resume read or toggle the SABnzbd queue pause state
110
+ queue Radarr and Sonarr queue records a person must handle (importPending, importBlocked,
111
+ failedPending): app, id, title, state, status, messages, added, size
112
+ queue-remove <radarr|sonarr> <id> --confirm
113
+ remove that record and delete its download from SABnzbd, without blocklisting the release
110
114
 
111
- Output is trendarr's JSON plus "warnings" (trendarr's stderr warnings, such as an unreachable Radarr).
115
+ Output is trendarr's JSON plus "warnings" (trendarr's stderr warnings, such as an unreachable Radarr);
116
+ queue and queue-remove call Radarr and Sonarr directly.
112
117
  An add exits 0 even when an ID fails: read each results[].status (added, already_exists, not_found, error).
113
118
  trendarr init and its configuration are operator tasks.`;
114
119
 
@@ -281,11 +286,95 @@ async function runTrendarr(config: MediaConfig, call: TrendarrCall): Promise<{ s
281
286
  }
282
287
  }
283
288
 
289
+ /** Queue states Radarr and Sonarr leave for a person: an import that waits, is blocked, or failed. */
290
+ const STUCK_STATES = ["importPending", "importBlocked", "failedPending"];
291
+ const APPS = ["radarr", "sonarr"] as const;
292
+ export type ArrApp = (typeof APPS)[number];
293
+
294
+ function isApp(value: string | undefined): value is ArrApp {
295
+ return value === "radarr" || value === "sonarr";
296
+ }
297
+
298
+ /** One queue record a person must handle; no API key or download path in it. */
299
+ export interface QueueRecord {
300
+ app: ArrApp;
301
+ id: number;
302
+ title: string;
303
+ state: string;
304
+ status: string;
305
+ messages: string[];
306
+ added: string | null;
307
+ size: number | null;
308
+ }
309
+
310
+ /** The records of one `/api/v3/queue` page that wait for a person. */
311
+ export function stuckRecords(app: ArrApp, page: unknown): QueueRecord[] {
312
+ const records = (page as { records?: unknown } | null)?.records;
313
+ if (!Array.isArray(records)) throw new ServiceError(`${app} returned no queue records`);
314
+ return (records as Record<string, unknown>[])
315
+ .filter((r) => typeof r.id === "number" && typeof r.trackedDownloadState === "string" && STUCK_STATES.includes(r.trackedDownloadState))
316
+ .map((r) => ({
317
+ app,
318
+ id: r.id as number,
319
+ title: typeof r.title === "string" ? r.title : "?",
320
+ state: r.trackedDownloadState as string,
321
+ status: typeof r.trackedDownloadStatus === "string" ? r.trackedDownloadStatus : "?",
322
+ messages: (Array.isArray(r.statusMessages) ? (r.statusMessages as { title?: unknown; messages?: unknown }[]) : []).flatMap((m) => {
323
+ const texts = Array.isArray(m.messages) ? m.messages.filter((t): t is string => typeof t === "string") : [];
324
+ return texts.length > 0 ? texts : typeof m.title === "string" ? [m.title] : [];
325
+ }),
326
+ added: typeof r.added === "string" ? r.added : null,
327
+ size: typeof r.size === "number" ? r.size : null,
328
+ }));
329
+ }
330
+
331
+ /** `queue-remove <radarr|sonarr> <id> --confirm`: the gate asks an owner, because the download is deleted. */
332
+ export function parseQueueRemove(args: string[]): { app: ArrApp; id: number } {
333
+ const usage = "queue-remove <radarr|sonarr> <id> --confirm";
334
+ const rest = args.filter((a) => a !== "--confirm");
335
+ if (rest.length !== 2 || !isApp(rest[0]) || !/^\d{1,10}$/.test(rest[1])) throw new UsageError(usage);
336
+ if (!args.includes("--confirm")) throw new UsageError(`${usage}: it deletes the download from SABnzbd, so it needs --confirm`);
337
+ return { app: rest[0], id: Number(rest[1]) };
338
+ }
339
+
340
+ async function arrRequest(config: MediaConfig, app: ArrApp, method: "GET" | "DELETE", path: string): Promise<unknown> {
341
+ const base = app === "radarr" ? config.radarrUrl : config.sonarrUrl;
342
+ const key = readSecret(SERVICE, app === "radarr" ? "RADARR_API_KEY" : "SONARR_API_KEY");
343
+ const res = await fetch(new URL(path, base), { method, headers: { "X-Api-Key": key, accept: "application/json" }, signal: AbortSignal.timeout(30_000) });
344
+ if (!res.ok) throw new ServiceError(`${app} answered ${res.status} to ${method} ${path.split("?")[0]}`);
345
+ return method === "GET" ? ((await res.json()) as unknown) : null;
346
+ }
347
+
348
+ /** Both apps' queue records that wait for a person; an app that does not answer becomes a warning. */
349
+ async function queueStatus(config: MediaConfig): Promise<{ records: QueueRecord[]; warnings: string[] }> {
350
+ const records: QueueRecord[] = [];
351
+ const warnings: string[] = [];
352
+ for (const app of APPS) {
353
+ try {
354
+ records.push(...stuckRecords(app, await arrRequest(config, app, "GET", "/api/v3/queue?page=1&pageSize=200")));
355
+ } catch (err) {
356
+ warnings.push(`${app}: ${err instanceof Error ? err.message.slice(0, 200) : String(err)}`);
357
+ }
358
+ }
359
+ return { records, warnings };
360
+ }
361
+
284
362
  export async function command(args: string[]): Promise<number> {
285
363
  if (args.length === 0 || args[0] === "--help" || args[0] === "help") {
286
364
  printRaw(HELP);
287
365
  return 0;
288
366
  }
367
+ if (args[0] === "queue") {
368
+ if (args.length !== 1) throw new UsageError("queue takes no arguments");
369
+ printJson(await queueStatus(readConfig<MediaConfig>(SERVICE, SHAPE)));
370
+ return 0;
371
+ }
372
+ if (args[0] === "queue-remove") {
373
+ const { app, id } = parseQueueRemove(args.slice(1));
374
+ await arrRequest(readConfig<MediaConfig>(SERVICE, SHAPE), app, "DELETE", `/api/v3/queue/${id}?removeFromClient=true&blocklist=false`);
375
+ printJson({ status: "removed", app, id });
376
+ return 0;
377
+ }
289
378
  const call = buildTrendarrCall(args);
290
379
  const config = readConfig<MediaConfig>(SERVICE, SHAPE);
291
380
  printJson(interpretRun(call, await runTrendarr(config, call)));
@@ -8,7 +8,7 @@ import { buildNodeRemote, parseJoinArgs, parseParams, parseRecordFilters, techni
8
8
  import { buildVpsRemote, command as edgeCommand, isTransientSshFailure, PUBLIC_ROUTES, routeProbe } from "./edge/run.ts";
9
9
  import { API_PREFIXES, buildDmzRemote, installedRelease, publishedSha256, validateApiPath, command as identityCommand } from "./identity/run.ts";
10
10
  import { buildInferenceRemote, command as inferenceCommand } from "./inference/run.ts";
11
- import { MAX_ADD_IDS, MAX_EXCLUDE_IDS, buildTrendarrCall, interpretRun, parseImdbIds, trendarrConfig, trendarrError, trendarrWarnings, command as mediaCommand } from "./media/run.ts";
11
+ import { MAX_ADD_IDS, MAX_EXCLUDE_IDS, buildTrendarrCall, interpretRun, parseImdbIds, parseQueueRemove, stuckRecords, trendarrConfig, trendarrError, trendarrWarnings, command as mediaCommand } from "./media/run.ts";
12
12
  import { ServiceError, UsageError } from "./lib/errors.ts";
13
13
  import { safeRepoPath, safeWritePath } from "./lib/repo.ts";
14
14
  import { appGetPath, appPolicyDelete, portForwardDelete, clientFixedIpWrite, syslogChanges, buildPulsarRemote, cloudPath, deviceNetworkWrite, NAT_PATH, natWrite, parseQuery, parseSiteArgs, redactUnifi, unifiPath, unifiWrite, command as networkCommand } from "./network/run.ts";
@@ -822,6 +822,24 @@ describe("media wrapper", () => {
822
822
  expect(() => parseImdbIds(Array.from({ length: MAX_ADD_IDS + 1 }, (_, i) => `tt${i + 1}`))).toThrow(/at most/);
823
823
  });
824
824
 
825
+ it("keeps the queue records a person must handle, without anything secret", () => {
826
+ const page = {
827
+ records: [
828
+ { id: 7, title: "Primetime.2026.REPACK.2160p", trackedDownloadState: "importPending", trackedDownloadStatus: "warning", statusMessages: [{ title: "Primetime.2026", messages: ["Not a Custom Format upgrade"] }, { title: "only a title", messages: [] }], added: "2026-11-03T16:03:52Z", size: 13406787332, outputPath: "/scratch/complete/x", downloadId: "SABnzbd_nzo_1" },
829
+ { id: 8, title: "Downloading", trackedDownloadState: "downloading", trackedDownloadStatus: "ok" },
830
+ { title: "no id", trackedDownloadState: "importBlocked" },
831
+ ],
832
+ };
833
+ expect(stuckRecords("radarr", page)).toEqual([
834
+ { app: "radarr", id: 7, title: "Primetime.2026.REPACK.2160p", state: "importPending", status: "warning", messages: ["Not a Custom Format upgrade", "only a title"], added: "2026-11-03T16:03:52Z", size: 13406787332 },
835
+ ]);
836
+ expect(() => stuckRecords("sonarr", { error: "x" })).toThrow(/no queue records/);
837
+ expect(parseQueueRemove(["sonarr", "42", "--confirm"])).toEqual({ app: "sonarr", id: 42 });
838
+ expect(() => parseQueueRemove(["radarr", "42"])).toThrow(/needs --confirm/);
839
+ expect(() => parseQueueRemove(["lidarr", "42", "--confirm"])).toThrow(/radarr\|sonarr/);
840
+ expect(() => parseQueueRemove(["radarr", "4x", "--confirm"])).toThrow(/radarr\|sonarr/);
841
+ });
842
+
825
843
  it("writes trendarr's configuration in its own schema", () => {
826
844
  const config = { trendarrCli: "/x/cli.js", radarrUrl: "http://r:7878", radarrQualityProfileId: 7, radarrRootFolderPath: "/media/movies", sonarrUrl: "http://s:8989", sonarrQualityProfileId: 7, sonarrRootFolderPath: "/media/tv", sonarrMonitor: "all", sabnzbdUrl: "http://z:8084", maxEntries: 10 };
827
845
  expect(trendarrConfig(config, { tmdbAccessToken: "t", omdbApiKey: "o", radarrApiKey: "r", sonarrApiKey: "s", sabnzbdApiKey: "z" })).toEqual({