@astrofoundry/pi-astro 0.40.70 → 0.40.71

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/home.md CHANGED
@@ -16,7 +16,7 @@ Rules:
16
16
 
17
17
  - Read first: `status` or `problems` before you explain or change anything. Name what you read, not what you assume.
18
18
  - A part that could not be read is a finding, never a pass. Say which part.
19
- - Change only what the task asks for. `update`, `restart`, and `action` ask an owner for approval in chat; say what you are about to run and why before you call them.
19
+ - Change only what the task asks for. `update`, `restart`, `action`, and `integration-remove` ask an owner for approval in chat; say what you are about to run and why before you call them.
20
20
  - Find the cause before you restart. Read `logs core` or the add-on's log for a failing integration; a restart is the last step, not the first.
21
21
  - Never print a token, a password, or a URL that carries one; summarise such a log line.
22
22
  - Keep replies short: the finding, the cause when you know it, and the one next step. When the owner must act, start with `**Needs you:**`.
@@ -19,6 +19,8 @@ describe("approvals", () => {
19
19
  expect(isRisky("media", ["bazarr", "status"])).toBe(false);
20
20
  expect(isRisky("home", ["action", "light.turn_off", "{}"])).toBe(true);
21
21
  expect(isRisky("home", ["restart"])).toBe(true);
22
+ expect(isRisky("home", ["integration-remove", "01JABCDEFGHJKMNPQRSTVWXYZ0"])).toBe(true);
23
+ expect(isRisky("home", ["integrations", "--failed"])).toBe(false);
22
24
  expect(isRisky("home", ["problems"])).toBe(false);
23
25
  expect(isRisky("home", ["logs", "core", "50"])).toBe(false);
24
26
  expect(isRisky("identity", ["zitadel", "DELETE", "/v2/users/1"])).toBe(true);
@@ -51,7 +51,7 @@ export const RISKY: Readonly<Record<string, readonly RegExp[]>> = {
51
51
  // and a date repair rewrites Jellyfin's "date added" on every item it finds late.
52
52
  media: [/^queue-remove\b/, /^jellyfin\s+date-repair\b/],
53
53
  // Everything that changes Home Assistant: an update, a restart, and any action (lights, locks, scenes).
54
- home: [/^(update|restart|action)\b/],
54
+ home: [/^(update|restart|action|integration-remove)\b/],
55
55
  };
56
56
 
57
57
  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.70",
3
+ "version": "0.40.71",
4
4
  "description": "Personal pi customizations (extensions, subagents, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -14,6 +14,8 @@ Home Assistant OS runs as VM 112 `homeassistant` on SPACE-X at Mira, in the IoT
14
14
  | `["status"]` | versions, Supervisor health, integrations that did not load, repairs, waiting updates, backups, disk, add-ons, entity counts, and the problem list |
15
15
  | `["problems"]` | only what needs a person, one line each, plus the number of unavailable entities |
16
16
  | `["entities"]` | unavailable entities (50); `--state <state>`, `--domain light`, `--max 1..200` |
17
+ | `["integrations"]` | every integration entry with `entry_id`, `domain`, `title`, `state`, `reason`, `disabled_by`; `--failed` keeps those that did not load |
18
+ | `["integration-remove", "<entry_id>", "--confirm"]` | delete one integration entry with its devices and entities; asks an owner. For leftovers such as hardware that no longer exists, never for an integration that only fails for now |
17
19
  | `["logs", "core", "200"]` | the newest lines of Core's log; also `supervisor`, `host`; default 100, at most 400 |
18
20
  | `["logs", "addon", "core_matter_server"]` | one add-on's log, by the slug from `status` |
19
21
  | `["update", "update.home_assistant_core_update", "--confirm"]` | install one waiting update; asks an owner |
@@ -26,6 +28,8 @@ Home Assistant OS runs as VM 112 `homeassistant` on SPACE-X at Mira, in the IoT
26
28
  - `unread` names the parts Home Assistant did not answer; each is also in `problems`. Never report such a part as fine.
27
29
  - `problems`: `{ "problems": [...], "unavailable": n, "version": "..." }`. An empty list means nothing needs a person.
28
30
  - `entities`: `{ "total": n, "entities": [{ "entity", "name", "state" }] }`.
31
+ - `integrations`: `{ "total": n, "integrations": [{ "entry_id", "domain", "title", "state", "reason", "disabled_by" }] }`.
32
+ - `integration-remove`: `{ "status": "removed", "entry_id", "require_restart" }`; restart Core when `require_restart` is true.
29
33
  - `logs`: `{ "lines": [...] }`, newest last.
30
34
  - `update`: `{ "status": "update started", "entity" }`. The install runs in Home Assistant; read `status` again after a few minutes.
31
35
  - `restart`: `{ "status": "restart requested" }`. The tool cannot reach Home Assistant while it restarts.
@@ -63,7 +63,7 @@ Wrappers ship as TypeScript and run under Node 24 type stripping: erasable synta
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
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`. The `jellyfin` commands (since 0.40.68, pure parts in `lib/media-dates.ts`) exist because Jellyfin adds a renamed or moved file as a new item: the library rename of 2026-11-10 turned 873 of 875 episodes into "added today". `date-check` reads every movie, episode, season, and series from `/Items` (one request per type without a limit, because pages of an unsorted list can overlap), Radarr's and Sonarr's files, and each app's whole history from `/api/v3/history/since`; files match by their last path segments (`pathKey`: two for a movie, three for an episode), so the mount points may differ. `planDates` follows the arcane repository's `media/AGENTS.md`: a movie or episode gets its earliest successful import (`firstArrival`; without an import record the earliest of the file's own import date and its rename and deletion records, since a file a disk scan found has none), a season and a series their earliest episode, an empty season its series; only a date more than a day late changes, so a date only ever moves back, and an item Radarr or Sonarr has no file for is reported as unmatched and left alone. `date-repair --confirm` applies the plan through Jellyfin's own `POST /Items/<id>`, the call behind its metadata editor: the item as `GET /Items/<id>?userId=<an administrator>` returns it (without a user id an API key gets 400) with only `DateCreated` changed and `People` left out, because Jellyfin rewrites people only when the request carries them; a test on one episode showed only `DateCreated` and `Etag` differing afterwards. Jellyfin keeps running, and five failed updates stop the run. The API key travels as `Authorization: MediaBrowser Token="<key>"`, the scheme of the server's own `/api-docs/openapi.json` (12.4.0). `bazarr status` reads `/api/system/status` and `/api/system/health` with `X-API-KEY` and prints versions and issues only; the Sonarr and Radarr versions Bazarr reports show that it reaches them. Both read their own config shape (`jellyfinUrl`, `bazarrUrl`), so the trendarr commands run without those keys.
66
- - `home` (since 0.40.70) reaches Home Assistant, VM 112 on SPACE-X at Mira (`homeAssistantUrl` in `home.json`, token `HOMEASSISTANT_TOKEN`), which replaced a Raspberry Pi with a failing SD card on 2026-11-12. `lib/home-assistant.ts` opens the WebSocket API (`/api/websocket`: `auth_required`, `auth` with the token, `auth_ok`), sends commands with ids, and closes; the wrapper runs on the installer's Node, which has a global `WebSocket`. The Supervisor's state (`/supervisor/info`, `/core/info`, `/os/info`, `/host/info`, `/resolution/info`, `/addons`) is reachable only through the `supervisor/api` command, because Core's REST proxy (`/api/hassio/...`) forwards logs and backups and nothing else (`PATHS_ADMIN` in Core's `hassio/http.py`, read at tag 2026.11.1); `logs` uses that proxy with `?lines=`. `status` prints named fields only (`pick`), so add-on options and addresses stay inside. `homeProblems` turns a snapshot into one line per finding: Core not running, safe or recovery mode, an unhealthy or unsupported Supervisor, its resolution issues, integrations that did not load (`setup_error`, `setup_retry`, ...), open repairs, waiting `update.*` entities, a newest backup older than 48 hours or failed for a location, a disk above 85 %; a part that could not be read is a line too (`unread`), never a pass. `update`, `restart`, and `action` (any Home Assistant action with `target` and `data`) change things and are in `RISKY`; the first two also need `--confirm`. Arguments are checked before config and secret are read. The agent has no `read` tool. The morning run reads `home problems` (`homeStatus` in `daily-run.ts`): each line is an item under Home, and the tagged message posts once per set of problems. Cortex reaches `10.1.70.32:8123` through the policies `Home Assistant - from Cortex` on both consoles.
66
+ - `home` (since 0.40.70) reaches Home Assistant, VM 112 on SPACE-X at Mira (`homeAssistantUrl` in `home.json`, token `HOMEASSISTANT_TOKEN`), which replaced a Raspberry Pi with a failing SD card on 2026-11-12. `lib/home-assistant.ts` opens the WebSocket API (`/api/websocket`: `auth_required`, `auth` with the token, `auth_ok`), sends commands with ids, and closes; the wrapper runs on the installer's Node, which has a global `WebSocket`. The Supervisor's state (`/supervisor/info`, `/core/info`, `/os/info`, `/host/info`, `/resolution/info`, `/addons`) is reachable only through the `supervisor/api` command, because Core's REST proxy (`/api/hassio/...`) forwards logs and backups and nothing else (`PATHS_ADMIN` in Core's `hassio/http.py`, read at tag 2026.11.1); `logs` uses that proxy with `?lines=`. `status` prints named fields only (`pick`), so add-on options and addresses stay inside. `homeProblems` turns a snapshot into one line per finding: Core not running, safe or recovery mode, an unhealthy or unsupported Supervisor, its resolution issues, integrations that did not load (`setup_error`, `setup_retry`, ...), open repairs, waiting `update.*` entities, a newest backup older than 48 hours or failed for a location, a disk above 85 %; a part that could not be read is a line too (`unread`), never a pass. `update`, `restart`, `action` (any Home Assistant action with `target` and `data`), and `integration-remove` (since 0.40.71: `DELETE /api/config/config_entries/entry/<id>`, for leftovers such as the Pi's Bluetooth adapter after the move to a VM) change things and are in `RISKY`; all but `action` also need `--confirm`. Arguments are checked before config and secret are read. The agent has no `read` tool. The morning run reads `home problems` (`homeStatus` in `daily-run.ts`): each line is an item under Home, and the tagged message posts once per set of problems. Cortex reaches `10.1.70.32:8123` through the policies `Home Assistant - from Cortex` on both consoles.
67
67
  - `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.
68
68
 
69
69
  ## Gate
@@ -15,7 +15,7 @@ A specialist is a Pi subagent that is the only way to operate one area of the ho
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
16
  | `astro.media` | trendarr over TMDB, OMDb, and the `media` project on VM 100 (Radarr, Sonarr, SABnzbd, Jellyfin, Bazarr) | `trending`, `search`, `recommend`, `add-movies`, `add-series` (at most 20 IMDb IDs), `sabnzbd status|pause|resume`, `queue`, `queue-remove <radarr|sonarr> <id> --confirm`, `jellyfin status|date-check`, `jellyfin date-repair --confirm`, `bazarr status`; trendarr's JSON plus its warnings, the queue, Jellyfin, and Bazarr commands straight from those apps |
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
- | `astro.home` | Home Assistant at Mira (VM 112 on SPACE-X, `10.1.70.32:8123`), through its WebSocket API and log routes with a long-lived access token | `status`, `problems`, `entities`, `logs <core\|supervisor\|host\|addon <slug>>`, `update <update.entity> --confirm`, `restart --confirm`, `action <domain.action> [json]`; named fields only |
18
+ | `astro.home` | Home Assistant at Mira (VM 112 on SPACE-X, `10.1.70.32:8123`), through its WebSocket API and log routes with a long-lived access token | `status`, `problems`, `entities`, `logs <core\|supervisor\|host\|addon <slug>>`, `integrations`, `integration-remove <entry_id> --confirm`, `update <update.entity> --confirm`, `restart --confirm`, `action <domain.action> [json]`; named fields only |
19
19
 
20
20
  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.
21
21
 
@@ -1,6 +1,6 @@
1
1
  import { readConfig } from "../lib/config.ts";
2
2
  import { ServiceError, UsageError } from "../lib/errors.ts";
3
- import { backupSummary, diskUse, entitiesIn, failedIntegrations, haSession, homeProblems, openRepairs, pendingUpdates, tailLines } from "../lib/home-assistant.ts";
3
+ import { backupSummary, diskUse, entitiesIn, failedIntegrations, haSession, homeProblems, integrationRows, openRepairs, pendingUpdates, tailLines } from "../lib/home-assistant.ts";
4
4
  import type { HaCall, HomeSnapshot } from "../lib/home-assistant.ts";
5
5
  import { main } from "../lib/main.ts";
6
6
  import { printJson, printRaw } from "../lib/output.ts";
@@ -20,6 +20,7 @@ const MAX_LOG_LINES = 400;
20
20
  const ENTITY_ID = /^[a-z0-9_]+\.[a-z0-9_]+$/;
21
21
  const ACTION = /^[a-z0-9_]+\.[a-z0-9_]+$/;
22
22
  const ADDON_SLUG = /^[a-z0-9_]+$/;
23
+ const ENTRY_ID = /^[0-9A-Za-z]{20,64}$/;
23
24
  const LOG_SOURCES = ["core", "supervisor", "host"];
24
25
 
25
26
  const HELP = `home specialist (Home Assistant at Mira, through its WebSocket API and log routes)
@@ -31,13 +32,16 @@ const HELP = `home specialist (Home Assistant at Mira, through its WebSocket API
31
32
  entity ids, names, and states (default: state unavailable, 50 of them)
32
33
  logs <core|supervisor|host> [lines]
33
34
  logs addon <slug> [lines] the newest log lines (default 100, at most ${MAX_LOG_LINES})
35
+ integrations [--failed] every integration entry with its id, state, and reason
36
+ integration-remove <entry_id> --confirm
37
+ delete one integration entry, with its devices and entities
34
38
  update <update.entity_id> --confirm
35
39
  install the update of one update entity
36
40
  restart --confirm restart Home Assistant Core
37
41
  action <domain.action> [json]
38
42
  run any Home Assistant action with {"target": {...}, "data": {...}}; in chat it asks an owner
39
43
 
40
- status, problems, and entities change nothing.`;
44
+ status, problems, entities, integrations, and logs change nothing.`;
41
45
 
42
46
  /** The Supervisor's answer to a GET, through Core's `supervisor/api` command. */
43
47
  function supervisorGet(call: HaCall, endpoint: string): Promise<unknown> {
@@ -187,6 +191,20 @@ function confirmed(args: string[], usage: string): string[] {
187
191
  return args.filter((a) => a !== "--confirm");
188
192
  }
189
193
 
194
+ /** `DELETE /api/config/config_entries/entry/<id>`, the call behind an integration's Delete in the UI. */
195
+ async function removeIntegration(config: HomeConfig, token: string, entryId: string): Promise<unknown> {
196
+ const url = new URL(`/api/config/config_entries/entry/${entryId}`, config.homeAssistantUrl);
197
+ let res: Response;
198
+ try {
199
+ res = await fetch(url, { method: "DELETE", headers: { authorization: `Bearer ${token}`, accept: "application/json" }, signal: AbortSignal.timeout(60_000) });
200
+ } catch (err) {
201
+ throw new ServiceError(`home assistant gave no answer to DELETE ${url.pathname}: ${err instanceof Error ? err.message.slice(0, 200) : String(err)}`);
202
+ }
203
+ if (res.status === 404) throw new ServiceError(`home assistant knows no integration entry ${entryId}`);
204
+ if (!res.ok) throw new ServiceError(`home assistant answered ${res.status} to DELETE ${url.pathname}`);
205
+ return (await res.json()) as unknown;
206
+ }
207
+
190
208
  async function logs(config: HomeConfig, token: string, path: string, lines: number): Promise<string[]> {
191
209
  const url = new URL(`/api/hassio/${path}?lines=${lines}`, config.homeAssistantUrl);
192
210
  let res: Response;
@@ -212,8 +230,11 @@ export async function command(args: string[]): Promise<number> {
212
230
  const updateTarget = name === "update" ? confirmed(rest, "update <update.entity_id> --confirm") : null;
213
231
  if (updateTarget !== null && (updateTarget.length !== 1 || !ENTITY_ID.test(updateTarget[0]) || !updateTarget[0].startsWith("update."))) throw new UsageError("update <update.entity_id> --confirm");
214
232
  if (name === "restart" && confirmed(rest, "restart --confirm").length > 0) throw new UsageError("restart --confirm");
233
+ const removeTarget = name === "integration-remove" ? confirmed(rest, "integration-remove <entry_id> --confirm") : null;
234
+ if (removeTarget !== null && (removeTarget.length !== 1 || !ENTRY_ID.test(removeTarget[0]))) throw new UsageError("integration-remove <entry_id> --confirm");
235
+ if (name === "integrations" && rest.some((a) => a !== "--failed")) throw new UsageError("integrations [--failed]");
215
236
  if ((name === "status" || name === "problems") && rest.length > 0) throw new UsageError(`${name} takes no arguments`);
216
- if (!["status", "problems", "entities", "logs", "update", "restart", "action"].includes(name)) throw new UsageError(`unknown command: ${name}`);
237
+ if (!["status", "problems", "entities", "integrations", "integration-remove", "logs", "update", "restart", "action"].includes(name)) throw new UsageError(`unknown command: ${name}`);
217
238
 
218
239
  const config = readConfig<HomeConfig>(SERVICE, SHAPE);
219
240
  const token = readSecret(SERVICE, "HOMEASSISTANT_TOKEN");
@@ -221,11 +242,20 @@ export async function command(args: string[]): Promise<number> {
221
242
  printJson({ lines: await logs(config, token, logQuery.path, logQuery.lines) });
222
243
  return 0;
223
244
  }
245
+ if (removeTarget !== null) {
246
+ const answer = await removeIntegration(config, token, removeTarget[0]);
247
+ printJson({ status: "removed", entry_id: removeTarget[0], require_restart: (answer as { require_restart?: unknown } | null)?.require_restart === true });
248
+ return 0;
249
+ }
224
250
  await haSession(config.homeAssistantUrl, token, async (call) => {
225
251
  if (name === "status") printJson(statusAnswer(await snapshot(call), Date.now()));
226
252
  else if (name === "problems") {
227
253
  const s = await snapshot(call);
228
254
  printJson({ problems: homeProblems(s, Date.now()), unavailable: entitiesIn(s.states).length, version: (s.config as { version?: unknown } | null)?.version ?? null });
255
+ } else if (name === "integrations") {
256
+ const all = integrationRows(await call("config_entries/get"));
257
+ const shown = rest.includes("--failed") ? all.filter((i) => i.disabled_by === null && !["loaded", "not_loaded", "setup_in_progress"].includes(i.state)) : all;
258
+ printJson({ total: all.length, integrations: shown });
229
259
  } else if (entityQuery !== null) {
230
260
  const found = entitiesIn(await call("get_states"), entityQuery.state, entityQuery.domain);
231
261
  printJson({ total: found.length, entities: found.slice(0, entityQuery.max) });
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { backupSummary, diskUse, entitiesIn, failedIntegrations, haSession, homeProblems, openRepairs, pendingUpdates, tailLines } from "./home-assistant.ts";
2
+ import { backupSummary, diskUse, entitiesIn, failedIntegrations, haSession, homeProblems, integrationRows, openRepairs, pendingUpdates, tailLines } from "./home-assistant.ts";
3
3
  import type { HomeSnapshot } from "./home-assistant.ts";
4
4
 
5
5
  type Listener = (event: { data?: string }) => void;
@@ -108,6 +108,12 @@ describe("home assistant findings", () => {
108
108
  ).toEqual([{ domain: "nest", title: "Nest", state: "setup_retry", reason: "Timeout" }]);
109
109
  });
110
110
 
111
+ it("lists integration entries with their ids", () => {
112
+ expect(integrationRows([{ entry_id: "01JABCDEFGHJKMNPQRSTVWXYZ0", domain: "bluetooth", title: "Pi adapter", state: "setup_retry", reason: "not found", disabled_by: null }, { domain: "hue" }])).toEqual([
113
+ { entry_id: "01JABCDEFGHJKMNPQRSTVWXYZ0", domain: "bluetooth", title: "Pi adapter", state: "setup_retry", reason: "not found", disabled_by: null },
114
+ ]);
115
+ });
116
+
111
117
  it("reads repairs, updates, and unavailable entities", () => {
112
118
  expect(openRepairs({ issues: [{ domain: "homeassistant", issue_id: "x", translation_key: "deprecated_yaml", severity: "warning", is_fixable: false }, { domain: "hue", issue_id: "y", ignored: true }] })).toEqual([{ domain: "homeassistant", issue: "deprecated_yaml", severity: "warning", fixable: false }]);
113
119
  const states = [
@@ -134,6 +134,22 @@ export function failedIntegrations(entries: unknown): FailedIntegration[] {
134
134
  .map((e) => ({ domain: text(e.domain) ?? "?", title: text(e.title) ?? "?", state: e.state as string, reason: text(e.reason) }));
135
135
  }
136
136
 
137
+ export interface Integration {
138
+ entry_id: string;
139
+ domain: string;
140
+ title: string;
141
+ state: string;
142
+ reason: string | null;
143
+ disabled_by: string | null;
144
+ }
145
+
146
+ /** Every config entry with the fields a person needs to pick one; `entry_id` is what `integration-remove` takes. */
147
+ export function integrationRows(entries: unknown): Integration[] {
148
+ return rows(entries).flatMap((e) =>
149
+ typeof e.entry_id === "string" ? [{ entry_id: e.entry_id, domain: text(e.domain) ?? "?", title: text(e.title) ?? "?", state: text(e.state) ?? "?", reason: text(e.reason), disabled_by: text(e.disabled_by) }] : [],
150
+ );
151
+ }
152
+
137
153
  export interface Repair {
138
154
  domain: string;
139
155
  issue: string;
@@ -1073,6 +1073,9 @@ describe("home wrapper", () => {
1073
1073
  await expect(homeCommand(["restart"])).rejects.toThrow(/needs --confirm/);
1074
1074
  await expect(homeCommand(["restart", "now", "--confirm"])).rejects.toThrow(/restart --confirm/);
1075
1075
  await expect(homeCommand(["backup"])).rejects.toThrow(/unknown command/);
1076
+ await expect(homeCommand(["integration-remove", "01JABCDEFGHJKMNPQRSTVWXYZ0"])).rejects.toThrow(/needs --confirm/);
1077
+ await expect(homeCommand(["integration-remove", "../x", "--confirm"])).rejects.toThrow(/integration-remove <entry_id>/);
1078
+ await expect(homeCommand(["integrations", "--all"])).rejects.toThrow(/integrations \[--failed\]/);
1076
1079
  });
1077
1080
 
1078
1081
  it("parses entity filters, log sources, and actions", () => {