@astrofoundry/pi-astro 0.40.39 → 0.40.40
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.
|
@@ -22,6 +22,7 @@ describe("approvals", () => {
|
|
|
22
22
|
expect(isRisky("network", ["unifi", "mira", "nat-write", "POST", "{}"])).toBe(true);
|
|
23
23
|
expect(isRisky("network", ["unifi", "37", "nat"])).toBe(false);
|
|
24
24
|
expect(isRisky("network", ["unifi", "mira", "app-policy-delete", "0123456789abcdef01234567"])).toBe(true);
|
|
25
|
+
expect(isRisky("network", ["unifi", "mira", "portforward-delete", "0123456789abcdef01234567", "qb"])).toBe(true);
|
|
25
26
|
expect(isRisky("network", ["unifi", "mira", "client-fixed-ip", "0123456789abcdef01234567", "{}"])).toBe(true);
|
|
26
27
|
expect(isRisky("network", ["unifi", "mira", "syslog", '{"ip":"10.0.90.10"}'])).toBe(true);
|
|
27
28
|
expect(isRisky("network", ["unifi", "mira", "device-network", "0123456789abcdef01234567", "{}"])).toBe(true);
|
|
@@ -33,7 +33,7 @@ export const RISKY: Readonly<Record<string, readonly RegExp[]>> = {
|
|
|
33
33
|
],
|
|
34
34
|
identity: [/^zitadel\s+(DELETE|POST|PUT|PATCH)\b/, /^dmz\s+(deploy-config|pomerium-restart|render|lego-renew)\b/],
|
|
35
35
|
// Every UniFi write, on either console.
|
|
36
|
-
network: [/^unifi\s+\S+\s+(write|nat-write|device-network|app-policy-delete|client-fixed-ip|syslog)\b/],
|
|
36
|
+
network: [/^unifi\s+\S+\s+(write|nat-write|device-network|app-policy-delete|portforward-delete|client-fixed-ip|syslog)\b/],
|
|
37
37
|
dns: [
|
|
38
38
|
/^technitium\s+primary\s+(zone-create|zone-catalog|zone-delete|record-add|record-update|record-delete|cluster-init|cluster-delete|cluster-remove|server-domain)\b/,
|
|
39
39
|
/^technitium\s+node\s+\S+\s+(server-domain|stale-zone-delete)\b/,
|
package/package.json
CHANGED
package/skills/network/SKILL.md
CHANGED
|
@@ -99,6 +99,8 @@ Behavior learned on the live consoles:
|
|
|
99
99
|
|
|
100
100
|
`app-policy-delete <policyId> <name>` deletes a firewall policy that the official API lists with `id: null`, such as rules converted from the old firewall (Mira's `BLOCK INTERNET` rows on 2026-10-31). Find its 24-hex `_id` and exact `name` with `app-get /v2/api/site/default/firewall-policies`; the name shows in the approval, and the wrapper deletes nothing unless the live policy carries that name. Every other policy change goes through `write`.
|
|
101
101
|
|
|
102
|
+
`portforward-delete <ruleId> <name>` deletes a port forward; the official API has no port forward endpoints. Find the 24-hex `_id` and exact `name` with `app-get /api/s/default/rest/portforward`; the wrapper deletes nothing unless the live rule carries that name.
|
|
103
|
+
|
|
102
104
|
`device-network` changes only a device's management network and address: a PUT of `/api/s/default/rest/device/<deviceId>` whose body may hold just `mgmt_network_id` and `config_network`. Both sites use the same layout: the uplink port stays native Default with all VLANs tagged, and each device sits on Management with a static address and the local DNS nodes.
|
|
103
105
|
|
|
104
106
|
```json
|
package/specialists/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Call one with `/run astro.<name> -- <task>` or through the `subagent` tool (both
|
|
|
26
26
|
- Every call is logged in `/Users/specialist/.specialists/audit.log`.
|
|
27
27
|
- 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.
|
|
28
28
|
|
|
29
|
-
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`); it cannot change Site Magic. `security` is read-only. `identity` deploys only `config.yaml` to the DMZ. `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.
|
|
29
|
+
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. `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
30
|
|
|
31
31
|
## Enable specialists on a host
|
|
32
32
|
|
|
@@ -132,7 +132,7 @@ Host: Cortex (macOS on Apple silicon; Homebrew git; the specialists' Node, trend
|
|
|
132
132
|
{ "agent": "astro.dns", "tool": "dns", "service": "dns", "timeoutMs": 660000 },
|
|
133
133
|
{ "agent": "astro.edge", "tool": "edge", "service": "edge", "timeoutMs": 300000 },
|
|
134
134
|
{ "agent": "astro.security", "tool": "security", "service": "security", "timeoutMs": 120000 },
|
|
135
|
-
{ "agent": "astro.backup", "tool": "backup", "service": "backup", "timeoutMs":
|
|
135
|
+
{ "agent": "astro.backup", "tool": "backup", "service": "backup", "timeoutMs": 3660000 },
|
|
136
136
|
{ "agent": "astro.proxmox", "tool": "proxmox", "service": "proxmox", "timeoutMs": 1320000 },
|
|
137
137
|
{ "agent": "astro.inference", "tool": "inference", "service": "inference", "timeoutMs": 1260000 },
|
|
138
138
|
{ "agent": "astro.media", "tool": "media", "service": "media", "timeoutMs": 660000 } ] }
|
|
@@ -88,6 +88,8 @@ ${Object.values(UNIFI_READS)
|
|
|
88
88
|
unifi <37|mira> syslog <json> [--local] set the console's activity log export (keys this_controller, ip, port, contents, log_all_contents, enabled)
|
|
89
89
|
unifi <37|mira> app-policy-delete <policyId> <name> [--local]
|
|
90
90
|
delete a firewall policy the official API lists without an id
|
|
91
|
+
unifi <37|mira> portforward-delete <ruleId> <name> [--local]
|
|
92
|
+
delete a port forward (the official API has none)
|
|
91
93
|
unifi <37|mira> nat [--local] the console's NAT rules (Policy Table; not in the official API)
|
|
92
94
|
unifi <37|mira> nat-write POST <json> | PUT <ruleId> <json> | DELETE <ruleId> <description> [--local]
|
|
93
95
|
unifi <37|mira> fingerprint the local console's certificate fingerprint (for the pin)
|
|
@@ -282,6 +284,17 @@ export function appPolicyDelete(args: string[]): UnifiWrite {
|
|
|
282
284
|
return { method: "DELETE", path: `${POLICIES_PATH}/${id}`, target: { id, name } };
|
|
283
285
|
}
|
|
284
286
|
|
|
287
|
+
export const PORT_FORWARDS_PATH = "/api/s/default/rest/portforward";
|
|
288
|
+
|
|
289
|
+
/** `portforward-delete <ruleId> <name>`: a port forward, which the official API does not list. */
|
|
290
|
+
export function portForwardDelete(args: string[]): UnifiWrite {
|
|
291
|
+
const [id, name, ...extra] = args;
|
|
292
|
+
if (id === undefined || !NAT_ID.test(id) || name === undefined || name.trim() === "" || extra.length > 0) {
|
|
293
|
+
throw new UsageError(`portforward-delete <24-hex ruleId> <name>, both from app-get ${PORT_FORWARDS_PATH}`);
|
|
294
|
+
}
|
|
295
|
+
return { method: "DELETE", path: `${PORT_FORWARDS_PATH}/${id}`, target: { id, name } };
|
|
296
|
+
}
|
|
297
|
+
|
|
285
298
|
/** `nat-write POST <json>`, `nat-write PUT <ruleId> <json>`, or `nat-write DELETE <ruleId> <description>`. */
|
|
286
299
|
export function natWrite(args: string[]): UnifiWrite {
|
|
287
300
|
const [method, first, second, ...extra] = args;
|
|
@@ -398,7 +411,9 @@ async function requireLiveName(site: Site, config: SiteConfig, local: boolean, l
|
|
|
398
411
|
} catch {
|
|
399
412
|
throw new ServiceError(`${listPath} did not answer JSON; nothing deleted`);
|
|
400
413
|
}
|
|
401
|
-
|
|
414
|
+
// The classic /api/s/ paths wrap their list in `data`; the /v2/ paths answer a bare array.
|
|
415
|
+
const rows = Array.isArray(list) ? list : (list as { data?: unknown } | null)?.data;
|
|
416
|
+
const live = Array.isArray(rows) ? (rows as Record<string, unknown>[]).find((o) => o._id === target.id) : undefined;
|
|
402
417
|
if (live === undefined) throw new ServiceError(`${target.id} is not in ${listPath} on ${site}; nothing deleted`);
|
|
403
418
|
if (live[field] !== target.name) throw new ServiceError(`${target.id} has ${field} ${JSON.stringify(live[field])}, not ${JSON.stringify(target.name)}; nothing deleted`);
|
|
404
419
|
}
|
|
@@ -454,6 +469,12 @@ async function unifi(args: string[]): Promise<number> {
|
|
|
454
469
|
if (call.target) await requireLiveName(site, config, local, POLICIES_PATH, "name", call.target);
|
|
455
470
|
return printAnswer(await siteRequest(site, config, local, call.path, call.method, undefined, "app"), `UniFi ${site} policy`);
|
|
456
471
|
}
|
|
472
|
+
if (rest[0] === "portforward-delete") {
|
|
473
|
+
const call = portForwardDelete(rest.slice(1));
|
|
474
|
+
const config = readSite(site);
|
|
475
|
+
if (call.target) await requireLiveName(site, config, local, PORT_FORWARDS_PATH, "name", call.target);
|
|
476
|
+
return printAnswer(await siteRequest(site, config, local, call.path, call.method, undefined, "app"), `UniFi ${site} port forward`);
|
|
477
|
+
}
|
|
457
478
|
if (rest[0] === "device-network") {
|
|
458
479
|
const call = deviceNetworkWrite(rest.slice(1));
|
|
459
480
|
return printAnswer(await siteRequest(site, readSite(site), local, call.path, call.method, call.body, "app"), `UniFi ${site} device`);
|
|
@@ -11,7 +11,7 @@ import { buildInferenceRemote, command as inferenceCommand } from "./inference/r
|
|
|
11
11
|
import { MAX_ADD_IDS, MAX_EXCLUDE_IDS, buildTrendarrCall, interpretRun, parseImdbIds, 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
|
-
import { appGetPath, appPolicyDelete, clientFixedIpWrite, syslogChanges, buildPulsarRemote, cloudPath, deviceNetworkWrite, NAT_PATH, natWrite, parseQuery, parseSiteArgs, redactUnifi, unifiPath, unifiWrite, command as networkCommand } from "./network/run.ts";
|
|
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";
|
|
15
15
|
import { buildHostRemote, splitHost, needsConfirm, parseSetPairs, parseVmid, validateApiPath as validatePvePath, command as proxmoxCommand } from "./proxmox/run.ts";
|
|
16
16
|
import { banLength, buildObsRemote, compactDecisions, parseGoDuration, summariseAlerts, summariseVulns, summariseWazuh, vulnEvents, wazuhEvents, command as securityCommand } from "./security/run.ts";
|
|
17
17
|
|
|
@@ -126,6 +126,9 @@ describe("network wrapper", () => {
|
|
|
126
126
|
expect(() => appPolicyDelete([id])).toThrow(UsageError);
|
|
127
127
|
expect(() => appPolicyDelete([id, " "])).toThrow(UsageError);
|
|
128
128
|
expect(() => appPolicyDelete(["611cef69-df2e-4498-9845-8685daee84f3", "BLOCK INTERNET"])).toThrow(UsageError);
|
|
129
|
+
expect(portForwardDelete([id, "qb"])).toEqual({ method: "DELETE", path: `/api/s/default/rest/portforward/${id}`, target: { id, name: "qb" } });
|
|
130
|
+
expect(() => portForwardDelete([id])).toThrow(UsageError);
|
|
131
|
+
expect(() => portForwardDelete(["../x", "qb"])).toThrow(UsageError);
|
|
129
132
|
const fixed = JSON.stringify({ use_fixedip: true, fixed_ip: "10.1.50.50", network_id: "0123456789abcdef01234567" });
|
|
130
133
|
expect(clientFixedIpWrite(["0123456789abcdef01234567", fixed])).toEqual({ method: "PUT", path: "/api/s/default/rest/user/0123456789abcdef01234567", body: fixed });
|
|
131
134
|
expect(() => clientFixedIpWrite(["0123456789abcdef01234567", JSON.stringify({ name: "x" })])).toThrow(/body keys/);
|
|
@@ -912,6 +915,18 @@ describe("network deletes check the live name", () => {
|
|
|
912
915
|
expect(calls.filter((c) => c.startsWith("DELETE"))).toHaveLength(1);
|
|
913
916
|
});
|
|
914
917
|
|
|
918
|
+
it("deletes a port forward only under its live name in the classic data list", async () => {
|
|
919
|
+
const calls: string[] = [];
|
|
920
|
+
vi.stubGlobal("fetch", async (url: string, init?: RequestInit) => {
|
|
921
|
+
calls.push(`${init?.method ?? "GET"} ${new URL(url).pathname}`);
|
|
922
|
+
return new Response(JSON.stringify(init?.method === "DELETE" ? { meta: { rc: "ok" }, data: [] } : { meta: { rc: "ok" }, data: [{ _id: id, name: "qb" }] }));
|
|
923
|
+
});
|
|
924
|
+
await expect(networkCommand(["unifi", "mira", "portforward-delete", id, "Plex"])).rejects.toThrow(/"qb", not "Plex"; nothing deleted/);
|
|
925
|
+
expect(calls.some((c) => c.startsWith("DELETE"))).toBe(false);
|
|
926
|
+
await networkCommand(["unifi", "mira", "portforward-delete", id, "qb"]);
|
|
927
|
+
expect(calls.filter((c) => c.startsWith("DELETE"))).toEqual([expect.stringMatching(/\/api\/s\/default\/rest\/portforward\/[0-9a-f]{24}$/)]);
|
|
928
|
+
});
|
|
929
|
+
|
|
915
930
|
it("changes only the syslog keys and keeps the rest of the live setting", async () => {
|
|
916
931
|
expect(syslogChanges(['{"ip":"10.0.90.10","port":"514"}'])).toEqual({ ip: "10.0.90.10", port: "514" });
|
|
917
932
|
expect(() => syslogChanges(['{"x_secret":"a"}'])).toThrow(UsageError);
|