Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
Merge remote-tracking branch 'origin/main' into fix/skill-market-policy-refusal
vastsad471b131c835
diff --cc apps/desktop/electron/main/ipc/skills-ipc.tsindex ee9656741,1e64bde3e..1a19102e3--- a/apps/desktop/electron/main/ipc/skills-ipc.ts+++ b/apps/desktop/electron/main/ipc/skills-ipc.ts@@@ -81,8 -78,8 +81,9 @@@ export function registerSkillsIpc(...(detail.host ? { host: detail.host } : {}),kind: detail.kind,...(detail.reason ? { reason: detail.reason } : {}),+ ...(detail.address ? { address: detail.address } : {}),...(detail.addressKind ? { addressKind: detail.addressKind } : {}),+ ...(detail.route ? { route: detail.route } : {}),},});};diff --cc apps/desktop/electron/main/public-https-fetch.tsindex 5521847c2,8ae0544dd..2d0638a13--- a/apps/desktop/electron/main/public-https-fetch.ts+++ b/apps/desktop/electron/main/public-https-fetch.ts@@@ -7,8 -9,8 +9,9 @@@ importisSafePublicHttpsUrl,publicNetworkRefusalReason,type PublicNetworkAddressKind,+ type PublicNetworkRefusalDetail,type PublicNetworkRefusalReason,+ type PublicNetworkRoute,} from "@pi-desktop/shared";const DEFAULT_TIMEOUT_MS = 8_000;@@@ -57,15 -70,8 +71,17 @@@ export class PublicNetworkPolicyError ereadonly address?: string;/** The class of `address`, not just the address: it names the cause. */readonly addressKind?: PublicNetworkAddressKind;+ /**+ * The same finding, shaped for the IPC boundary: `wrap()` forwards this object+ * as the renderer's `error.details` (`register.ts`), which is how the panel+ * tells a TUN fake-IP apart from a real private target without parsing an+ * English message. Both arrive under one code — both are refusals the guard+ * decided — so the structured reason is the only honest way to separate them- * (issue #419).++ * (issue #419). The route the hop was judged on travels with it (ADR 0272).+ */+ readonly data: PublicNetworkRefusalDetail;+ /** The route the refusal was judged on, when the guard could read one. */+ readonly route?: PublicNetworkRoute;constructor(message: string, refusal: PublicNetworkRefusal = { reason: "non-public-address" }) {super(message);this.name = PUBLIC_NETWORK_POLICY_ERROR;@@@ -77,12 -84,6 +94,13 @@@refusal.reason === "resolve-failed"? ErrorCodes.NETWORK_RESOLVE_FAILED: ErrorCodes.NETWORK_POLICY_BLOCKED;+ this.data = {+ reason: refusal.reason,+ ...(refusal.host ? { host: refusal.host } : {}),+ ...(refusal.address ? { address: refusal.address } : {}),+ ...(refusal.addressKind ? { addressKind: refusal.addressKind } : {}),++ ...(refusal.route ? { route: refusal.route } : {}),+ };}}diff --cc apps/desktop/electron/main/skill-market-scan.tsindex 8a29fa0e7,6d2b8b15f..61b067677--- a/apps/desktop/electron/main/skill-market-scan.ts+++ b/apps/desktop/electron/main/skill-market-scan.ts@@@ -46,20 -43,19 +47,27 @@@ export type SkillMarketFailureDetail =/** The guard's structured reason, when a guard refusal produced this. */reason?: PublicNetworkRefusalReason;/**- * The class of the address that failed a policy check — `benchmark` for a TUN- * fake-IP, `private` for RFC1918, `loopback` for a redirect to localhost. The- * class is what tells a resolver artifact apart from a real private target.- * The address itself is deliberately not carried.+ * The address the guard resolved `host` to, when a policy check judged one.+ * This is the local resolver's answer — not user input, not a URL component —+ * and it is the most diagnostic field a refusal has: `198.18.0.1` reads as a+ * proxy in fake-IP mode at a glance, which is exactly the case issue #419 is+ * about. Only a well-formed IP literal is carried (see+ * `publicNetworkRefusalDetail`).+ */+ address?: string;+ /**+ * The class of that address — `benchmark` for a TUN fake-IP, `private` for+ * RFC1918, `loopback` for a redirect to localhost. The class is what a caller+ * decides on; the address is what the user recognises.*/addressKind?: PublicNetworkAddressKind;+ /**+ * The route the guard judged the failing address on, when the transport could+ * name one. A fake-IP answer is tolerated on a proxied route because this app+ * never dials it, and refused on a direct or unreadable one because it would+ * (ADR 0272).+ */+ route?: PublicNetworkRoute;};export type SkillMarketSearchResult = {@@@ -150,8 -139,8 +158,9 @@@ export function skillMarketFailureDetai...(host ? { host } : {}),kind: classifySkillMarketFailure(error),...(refusal ? { reason: refusal.reason } : {}),+ ...(refusal?.address ? { address: refusal.address } : {}),...(refusal?.addressKind ? { addressKind: refusal.addressKind } : {}),+ ...(refusal?.route ? { route: refusal.route } : {}),};}@@@ -331,8 -319,8 +340,9 @@@ export function createSkillMarketAggregkind: classifySkillMarketFailure(result.reason),...(host ? { host } : {}),...(refusal ? { reason: refusal.reason } : {}),+ ...(refusal?.address ? { address: refusal.address } : {}),...(refusal?.addressKind ? { addressKind: refusal.addressKind } : {}),+ ...(refusal?.route ? { route: refusal.route } : {}),});return;}diff --cc apps/desktop/src/lib/api.tsindex 52fcc6a3d,eefb7ac79..fecb0c254--- a/apps/desktop/src/lib/api.ts+++ b/apps/desktop/src/lib/api.ts@@@ -734,21 -757,19 +757,18 @@@ export const api =* Why each named source failed, so the market can explain a policy/DNS* refusal instead of reporting every source as merely unreachable.*/- failureKinds?: Record<string, "policy" | "unresolved" | "network">;+ failureKinds?: Record<string, "policy" | "fake-ip" | "unresolved" | "network">;- /**- * The host and the guard's own reason behind each failed source. Without- * it the panel can say a source was refused but not *what* was refused,- * and a policy refusal is a statement about one address (issue #419).- *//**- /**- * The host and the guard's own reason behind each failed source. Without- * it the panel can say a source was refused but not *what* was refused,- * and a policy refusal is a statement about one address. `route` adds- * which route the guard judged that address on, so a fake-IP refusal on a- * direct route reads apart from one on a proxied route (issue #419,- * ADR 0272).+ * The host, the address it resolved to, and the guard's own reason behind+ * each failed source. Without them the panel can say a source was refused+ * but not *what* was refused — and `198.18.0.1` is what tells a user their- * proxy is in fake-IP mode (issue #419).++ * proxy is in fake-IP mode. `route` adds which route the guard judged that++ * address on, so a fake-IP refusal on a direct route reads apart from one++ * on a proxied route (issue #419, ADR 0272).*/failureDetails?: Record<string,- { host?: string; address?: string; reason?: string; addressKind?: string }- { host?: string; reason?: string; addressKind?: string; route?: string }++ { host?: string; address?: string; reason?: string; addressKind?: string; route?: string }>;}>(IPC.invoke.skillMarketSearch, { query, sources }),/** Fetch one catalog document (frontmatter split off) for preview/install. */diff --cc apps/desktop/test/skill-market-policy-refusal.test.mjsindex 51764998d,aa003aa41..97c2dc46c--- a/apps/desktop/test/skill-market-policy-refusal.test.mjs+++ b/apps/desktop/test/skill-market-policy-refusal.test.mjs@@@ -77,12 -84,14 +84,15 @@@ test("a resolver that throws is unresolassert.equal(lookups, 3);});- test("a TUN fake-IP is still refused, and the refusal now names what it refused", async () => {- // Clash's default fake-IP range. The guard keeps refusing it — this is a- // refusal, not an exemption — but it is now its own cause rather than the same- // finding as a real private target, and the record carries the host, the- // reason, the address and its class instead of the one word "private" that fit- // none of the benchmark/CGNAT/loopback cases.+ test("an unreadable route still refuses a TUN fake-IP, and names what it refused", async () => {+ // Clash's default fake-IP range on a client that wires no route resolver at+ // all. The address verdict still lands on the address this app would dial, so+ // it stays a refusal; with a proxied route reported for the hop the same+ // answer is the resolver's artifact and is tolerated (ADR 0272). Either way- // the refusal carries the host, the reason, the class of address, and the- // route it was judged on — instead of the one word "private" that fit none of- // the benchmark/CGNAT/loopback cases.++ // the refusal carries the host, the reason, the address, its class, and the++ // route it was judged on — and it is its own cause rather than the same++ // finding as a real private target — instead of the one word "private" that++ // fit none of the benchmark/CGNAT/loopback cases.const client = createPublicHttpsClient({fetchImpl: async () => {throw new Error("a refused request must never reach the network");@@@ -92,13 -101,13 +102,14 @@@const aggregator = createSkillMarketAggregator(client.request);const result = await aggregator.search("", [composio]);- assert.equal(result.failureKinds[composio.name], "policy");+ assert.equal(result.failureKinds[composio.name], "fake-ip");assert.deepEqual(result.failureDetails[composio.name], {- kind: "policy",+ kind: "fake-ip",reason: "non-public-address",host: SCAN_HOST,+ address: "198.18.0.4",addressKind: "benchmark",+ route: "unknown",});});@@@ -207,113 -216,6 +218,114 @@@ test("all seven built-in sources stay rassert.deepEqual(result.entries, []);assert.deepEqual([...result.failedSources].sort(), sources.map((source) => source.name).sort());for (const source of sources) {- assert.equal(result.failureKinds[source.name], "policy");+ assert.equal(result.failureKinds[source.name], "fake-ip");}});++/**+ * The fake-IP case, which the coordinator's lead puts at the centre of #419.+ *+ * Clash, Mihomo, sing-box and Surge all ship `198.18.0.0/15` — RFC 2544's+ * benchmark range — as their default fake-IP pool. `classifyIpLiteral` is right+ * to call that non-public, and the guard must keep refusing it. But that address+ * is the *proxy's* placeholder for the name, not the target's own address, so+ * collapsing it into the same finding as a real `10.0.0.0/8` target tells the+ * user their catalog source is bad when the thing to change is their proxy mode.+ */++/** The market's verdict for one literal, through the real client and aggregator. */+async function marketKindForAddress(address) {+ const client = createPublicHttpsClient({+ fetchImpl: async () => {+ throw new Error("a refused request must never reach the network");+ },+ lookupImpl: async () => [{ address }],+ });+ return createSkillMarketAggregator(client.request).search("", [composio]);+}++test("a proxy fake-IP is its own cause, not the same finding as a private target", async () => {+ // Both halves of Clash's default pool, so the range and not one address is+ // what gets pinned.+ assert.equal((await marketKindForAddress("198.18.0.1")).failureKinds[composio.name], "fake-ip");+ assert.equal(+ (await marketKindForAddress("198.19.255.254")).failureKinds[composio.name],+ "fake-ip",+ );+ // A real private or loopback target is a different finding, with different+ // advice: that one is about the destination, not about the proxy.+ assert.equal((await marketKindForAddress("127.0.0.1")).failureKinds[composio.name], "policy");+ assert.equal((await marketKindForAddress("10.1.2.3")).failureKinds[composio.name], "policy");+ assert.equal((await marketKindForAddress("192.168.1.10")).failureKinds[composio.name], "policy");+});++test("the fake-IP cause never admits the request", async () => {+ // The whole point of a separate cause is the explanation, never the outcome.+ // This is the assertion that would fail first if the split were implemented as+ // an exemption instead of a label.+ let fetched = 0;+ const client = createPublicHttpsClient({+ fetchImpl: async () => {+ fetched += 1;+ return {+ status: 200,+ ok: true,+ headers: { get: () => null },+ json: async () => ({}),+ text: async () => "",+ };+ },+ lookupImpl: async () => [{ address: "198.18.0.1" }],+ });+ const result = await createSkillMarketAggregator(client.request).search("", [composio]);+ assert.equal(fetched, 0, "a fake-IP answer must never be fetched through");+ assert.deepEqual(result.entries, []);+ assert.deepEqual(result.failedSources, [composio.name]);+ assert.equal(result.failureKinds[composio.name], "fake-ip");+});++test("the refusal names the host and the address, not only the source label", async () => {+ // "Catalog sources were blocked by the app's address check" named nothing. The+ // host and the address it was resolved to are the whole diagnosis: one glance+ // at `198.18.0.1` is what tells a user their proxy is in fake-IP mode.+ const result = await marketKindForAddress("198.18.0.1");+ assert.deepEqual(result.failureDetails[composio.name], {+ kind: "fake-ip",+ reason: "non-public-address",+ host: SCAN_HOST,+ address: "198.18.0.1",+ addressKind: "benchmark",++ route: "unknown",+ });+ const privateTarget = await marketKindForAddress("10.1.2.3");+ assert.equal(privateTarget.failureDetails[composio.name].address, "10.1.2.3");+ assert.equal(privateTarget.failureDetails[composio.name].addressKind, "private");+});++test("a resolver that answered nothing is not a fake-IP and not a verdict", async () => {+ // The three cases the lead asks to keep apart, asserted side by side so a+ // future refactor cannot merge two of them again.+ const judgedFake = await marketKindForAddress("198.18.0.1");+ assert.equal(judgedFake.failureKinds[composio.name], "fake-ip");++ const judgedPrivate = await marketKindForAddress("10.1.2.3");+ assert.equal(judgedPrivate.failureKinds[composio.name], "policy");++ const silent = createPublicHttpsClient({+ fetchImpl: async () => {+ throw new Error("a refused request must never reach the network");+ },+ lookupImpl: async () => [],+ });+ const unanswered = await createSkillMarketAggregator(silent.request).search("", [composio]);+ assert.equal(unanswered.failureKinds[composio.name], "unresolved");++ const syntactic = createSkillMarketAggregator(async () => {+ throw new Error("a syntactically refused source is never requested");+ });+ const refused = await syntactic.search("", [+ { id: "x", name: "x/private", url: "https://10.0.0.8/catalog.json" },+ ]);+ assert.equal(refused.failureKinds["x/private"], "policy");+ assert.equal(refused.failureDetails["x/private"].reason, "url-syntax");+});diff --cc docs/spec/03-runtime/01-ipc-protocol.mdindex 43d3ac6c2,7f438e461..395e9f60f--- a/docs/spec/03-runtime/01-ipc-protocol.md+++ b/docs/spec/03-runtime/01-ipc-protocol.md@@@ -1465,19 -1472,18 +1472,23 @@@ Desktop-only skill market channels (nobuiltin-safe catalog JSON and GitHub repo SKILL.md scans. Source URLs must passthe public-HTTPS policy (ADR 0243). One failing source is dropped; the reststill return. `failureKinds` maps each name in `failedSources` to `policy`- (the guard judged the target's own non-public address), `fake-ip` (it judged a- fake-IP placeholder the local proxy invented for the name — Clash's- `198.18.0.0/15`; still refused, because the guard fails closed, but a condition- of the local network rather than a fact about the source), `unresolved` (the- local DNS lookup returned no answer, so no address was judged), or `network`.- (the public-network guard judged the target and refused it, so the request- never left the process), `unresolved` (the local DNS lookup returned no answer,- so no address was judged — a resolver or proxy condition, not a verdict on the- source), or `network`. `failureDetails` carries the same keys with the host- that actually failed, the guard's own `reason`, the class of the refused- address, and the route that address was judged on (`proxied`, `direct`, or- `unknown` when the transport reported no readable route, ADR 0272), which is- what lets the panel name *what* was refused instead of only which source went- quiet.- `NETWORK_POLICY_BLOCKED` and an unanswered resolver as `NETWORK_RESOLVE_FAILED`- (spec 08 §3.1); the install sheet classifies a failed preview on those two- codes.++ (the guard judged the target's own non-public address and refused it),++ `fake-ip` (it judged a fake-IP placeholder the local proxy invented for the++ name — Clash's `198.18.0.0/15`; still refused on a direct or unreadable route,++ where the guard fails closed and this app would dial that address itself, but a++ condition of the local network rather than a fact about the source),++ `unresolved` (the local DNS lookup returned no answer, so no address was++ judged), or `network`.+ `failureDetails` carries the same keys with the host that actually failed, the- address it resolved to, the guard's own `reason`, and that address's class,- which is what lets the panel name *what* was refused — "your proxy answered- github.com with 198.18.0.1" — instead of only which source went quiet. A judged- refusal and a fake-IP refusal both surface as `NETWORK_POLICY_BLOCKED` (both- are refusals the guard decided), and an unanswered resolver as- `NETWORK_RESOLVE_FAILED` (spec 08 §3.1); the install sheet classifies a failed- preview on those codes together with the structured `reason`.++ address it resolved to, the guard's own `reason`, that address's class, and the++ route the guard judged it on (`proxied`, `direct`, or `unknown` when the++ transport reported no readable route, ADR 0272), which is what lets the panel++ name *what* was refused — "your proxy answered github.com with 198.18.0.1" —++ instead of only which source went quiet. A judged refusal and a fake-IP refusal++ both surface as `NETWORK_POLICY_BLOCKED` (both are refusals the guard decided),++ and an unanswered resolver as `NETWORK_RESOLVE_FAILED` (spec 08 §3.1); the++ install sheet classifies a failed preview on those codes together with the++ structured `reason`.- `pi-desktop/skill/market/fetch` — `{ entry }` → `{ name?, description?, body, resources? }`.Main fetches the document over the same policy, splits frontmatter, and mayattach sibling `.md` files from a jsDelivr listing. The renderer installsdiff --cc docs/spec/03-runtime/09-logging-and-observability.mdindex 3bb670da3,14d7cb09c..d88d69011--- a/docs/spec/03-runtime/09-logging-and-observability.md+++ b/docs/spec/03-runtime/09-logging-and-observability.md@@@ -54,21 -54,23 +54,24 @@@ The application categories are- `diagnostics` — blocked navigation, menu, template, and outbound-fetchdiagnostics. The skill market's two channels record one`skillMarket.sourceFailed` / `skillMarket.documentFailed` record per source- or document that produced nothing, with `source`, `host`, `kind` and — for a- guard refusal — `reason`, `addressKind` and `route` in `data`. `kind` is- `policy` when the guard judged the target, `unresolved` when the local- resolver returned no answer, and `network` otherwise; `code` is- `NETWORK_POLICY_BLOCKED` for the first and `NETWORK_RESOLVE_FAILED` for the- second, so one log line separates "the address is not public" from "the- resolver answered nothing". `reason` names the guard's own branch- (`url-syntax`, `resolve-failed`, `non-public-address`, `redirect-limit`),- `addressKind` the class of the refused address (`benchmark` for a TUN fake-IP,- `private` for RFC1918), and `route` the route that address was judged on- (`proxied`, `direct`, or `unknown` when the transport reported no readable- route), so a fake-IP refusal on a direct route reads apart from one on a route- nobody could read (ADR 0272). The record carries the host name, that class and- that route only — never the address, the URL, its path, query or credentials —- because a catalog source URL is user-supplied, the refused host is the whole- diagnostic value, and the class is what tells a resolver artifact from a real- private target (issue #419).+ or document that produced nothing, with `source`, `host`, `kind`, `address`- and — for a guard refusal — `reason` and `addressKind` in `data`. `kind` is- `policy` when the guard judged the target's own address, `fake-ip` when it++ and — for a guard refusal — `reason`, `addressKind` and `route` in `data`. `kind`++ is `policy` when the guard judged the target's own address, `fake-ip` when it+ judged a placeholder the local proxy invented for the name (Clash's+ `198.18.0.0/15`), `unresolved` when the local resolver returned no answer, and+ `network` otherwise; `code` is `NETWORK_POLICY_BLOCKED` for the first two and+ `NETWORK_RESOLVE_FAILED` for the third, so one log line separates "the address+ is not public" from "a proxy answered with a fake-IP" from "the resolver+ answered nothing". `reason` names the guard's own branch (`url-syntax`,- `resolve-failed`, `non-public-address`, `redirect-limit`) and `addressKind` the++ `resolve-failed`, `non-public-address`, `redirect-limit`), `addressKind` the+ class of the refused address (`benchmark` for a TUN fake-IP, `private` for- RFC1918). The record carries the host name, the address it resolved to and that- class — never the URL, its path, query or credentials — because a catalog- source URL is user-supplied and the refused host and address are the whole- diagnostic value (issue #419).++ RFC1918), and `route` the route that address was judged on (`proxied`, `direct`,++ or `unknown` when the transport reported no readable route), so a fake-IP++ refusal on a direct route reads apart from one on a route nobody could read++ (ADR 0272). The record carries the host name, the address it resolved to, that++ class and that route — never the URL, its path, query or credentials — because a++ catalog source URL is user-supplied and the refused host and address are the++ whole diagnostic value (issue #419).- `runtime` — host/sidecar lifecycle, uncategorized child output, andmain-process `uncaughtException` / `unhandledRejection` recordsdiff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex 36104986c,57b297119..ab48c1b0a--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -12172,18 -12267,17 +12267,21 @@@ plugin-form fixtures in an isolated tempolicy error without fetching the private target. A judged refusal is notretried; a local resolver that answered nothing is, and is reported as`NETWORK_RESOLVE_FAILED` (`kind` `unresolved`) rather than as an address-check- refusal — the guard reached no verdict, so nothing may claim it did. Every- other refusal carries `NETWORK_POLICY_BLOCKED` (spec 08 §3.1) with its- `reason`, the class of the refused address, and the route that address was- judged on, so the install sheet can name the reason and offer a retry instead- of leaving the install button disabled with no explanation, and the market- list can tell a refused source apart from a merely unreachable one. A proxied- hop whose answer is the RFC 2544 fake-IP class is refused on a direct or- unreadable route and accepted on the proxied one, every other non-public class- still refuses on all routes, and each redirect hop is judged on its own route- (ADR 0272).+ refusal — the guard reached no verdict, so nothing may claim it did. An address- in a proxy's fake-IP range (`198.18.0.0/15`, Clash's default) is refused and- not retried, and is reported as `kind` `fake-ip` with `addressKind` `benchmark`- — distinct from a real private target (`kind` `policy`, `addressKind`- `private`), because the guard judged the target in the second case and only the- proxy's placeholder in the first. Every other refusal carries- `NETWORK_POLICY_BLOCKED` (spec 08 §3.1) with its `reason`, the address it- resolved to, and the class of that address, so the install sheet can name the- reason and offer a retry instead of leaving the install button disabled with no- explanation, and the market list can tell a refused source apart from a merely- unreachable one.- - **Specs linked**: `05-security/01-security.md`, ADR 0243,++ in a proxy's fake-IP range (`198.18.0.0/15`, Clash's default) is refused and not++ retried where the guard judged it — a direct or unreadable route — and is++ accepted on the proxied one, and is reported as `kind` `fake-ip` with++ `addressKind` `benchmark` and `reason` `non-public-address` — distinct from a++ real private target (`kind` `policy`, `addressKind` `private`), because the guard++ judged the target in the second case and only the proxy's placeholder in the++ first. Every other refusal carries `NETWORK_POLICY_BLOCKED` (spec 08 §3.1) with++ its `reason`, the address it resolved to, the class of that address, and the++ route it was judged on, so the install sheet can name the reason and offer a++ retry instead of leaving the install button disabled with no explanation, and the++ market list can tell a refused source apart from a merely unreachable one. Every++ other non-public class still refuses on all routes, and each redirect hop is++ judged on its own route (ADR 0272).+ - **Specs linked**: `05-security/01-security.md`, ADR 0243, ADR 0272,`03-runtime/01-ipc-protocol.md` §12b- **Acceptance**: Security, Quality- **Milestone**: M6+diff --cc docs/zh-CN/spec/03-runtime/01-ipc-protocol.mdindex ed2384721,57ebfa32b..be0c56ab3--- a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md+++ b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md@@@ -1214,10 -1216,10 +1216,10 @@@ ASCII slug:frontmatter `name` 能 slu- `pi-desktop/skill/market/search` — `{ query, sources[] }` →`{ entries, failedSources, failureKinds, failureDetails }`。主进程聚合目录 JSON 与 GitHub 仓库 SKILL.md 扫描。源 URL 必须通过公网 HTTPS 策略(ADR 0243)。单源失败只丢掉该源。- `failureKinds` 把 `failedSources` 中的每个名字映射到 `policy`(守卫判定的是目标自身的非公网地址)、`fake-ip`(判定的是本地代理伪造的 fake-IP 占位地址,如 Clash 默认的 `198.18.0.0/15`;仍被拒绝,但这是本地网络的状况而不是源的问题)、`unresolved`(本地 DNS 解析没有返回答案,因此没有判定任何地址)或 `network`。`failureDetails` 以同样的键携带真正失败的主机、解析到的地址、守卫自己的 `reason` 与地址类别;面板据此说明**被拒的是什么**(例如「代理把 github.com 应答为 198.18.0.1」),而不只是哪个源没出结果。- `failureKinds` 把 `failedSources` 中的每个名字映射到 `policy`(公网策略守卫判定了目标并拒绝,请求从未离开进程)、`unresolved`(本地 DNS 解析没有返回答案,因此没有判定任何地址——这是解析器或代理的环境状况,不是对源的判定)或 `network`。`failureDetails` 以同样的键携带真正失败的主机、守卫自己的 `reason`、被拒地址的类别以及判定该地址的线路(`proxied`、`direct`,或传输层读不出线路时的 `unknown`,ADR 0272);面板据此说明**被拒的是什么**,而不只是哪个源没出结果。- 判定型拒绝以 `NETWORK_POLICY_BLOCKED` 暴露,解析器无应答以 `NETWORK_RESOLVE_FAILED` 暴露(spec 08 §3.1);安装面板正是按这两个错误码分类。++ `failureKinds` 把 `failedSources` 中的每个名字映射到 `policy`(守卫判定了目标自身的非公网地址并拒绝)、`fake-ip`(判定的是本地代理伪造的 fake-IP 占位地址,如 Clash 默认的 `198.18.0.0/15`;在直连或读不出线路时仍被拒绝,因为守卫在那里失败关闭、这个应用会自己去连该地址,但这是本地网络的状况而不是源的问题)、`unresolved`(本地 DNS 解析没有返回答案,因此没有判定任何地址)或 `network`。`failureDetails` 以同样的键携带真正失败的主机、解析到的地址、守卫自己的 `reason`、地址类别以及判定该地址的线路(`proxied`、`direct`,或传输层读不出线路时的 `unknown`,ADR 0272);面板据此说明**被拒的是什么**(例如「代理把 github.com 应答为 198.18.0.1」),而不只是哪个源没出结果。+ 判定型拒绝与 fake-IP 拒绝都以 `NETWORK_POLICY_BLOCKED` 暴露(两者都是守卫作出的拒绝),解析器无应答以 `NETWORK_RESOLVE_FAILED` 暴露(spec 08 §3.1);安装面板正是按这些错误码与结构化 `reason` 分类。- `pi-desktop/skill/market/fetch` — `{ entry }` → `{ name?, description?, body, resources? }`。- 主进程按同一策略拉取文档、拆 frontmatter,并可能附上 jsDelivr 目录中的兄弟 `.md`。渲染层通过现有 `skills.create` 安装。该策略即主进程公网网络客户端:语法 URL 防护、DNS 分类、逐跳重定向复核与响应上限——渲染层绝不直接触网。目录 id 会净化为 host `valid_capability_id`。+ 主进程按同一策略拉取文档、拆 frontmatter,并可能附上 jsDelivr 目录中的兄弟 `.md`。渲染层通过现有 `skills.create` 安装。该策略即主进程公网网络客户端:语法 URL 防护、按承载 `net.fetch` 的会话线路判定的逐跳 DNS 分类(ADR 0272)、逐跳重定向复核与响应上限——渲染层绝不直接触网。目录 id 会净化为 host `valid_capability_id`。桌面专用 MCP 市场通道(不是 host RPC)走 Electron IPC:diff --cc docs/zh-CN/spec/03-runtime/09-logging-and-observability.mdindex dc6d9ae4a,77c8240b4..108747c14--- a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md+++ b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md@@@ -52,7 -52,7 +52,7 @@@ host 和 agent stderr 使用标记进�- `provider` — provider/model 发现、重试和缓存失败- `persistence` — 成绩单和发件箱持久化失败- `updater` — 更新器诊断和错误- - `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`、`address`,以及被守卫拒绝时的 `reason` 与 `addressKind`。`kind` 在守卫判定的是目标自身地址时为 `policy`,判定的是本地代理伪造的 fake-IP 占位地址时为 `fake-ip`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前两者为 `NETWORK_POLICY_BLOCKED`,第三者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「目标地址不是公网」「代理用了 fake-IP」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`)。记录会保留主机名、被解析到的地址与该类别 —— 但绝不包含 URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,而被拒绝的主机、地址及其类别正是全部诊断价值所在(issue #419)。-- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`,以及被守卫拒绝时的 `reason`、`addressKind` 与 `route`。`kind` 在守卫判定了目标时为 `policy`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前者为 `NETWORK_POLICY_BLOCKED`,后者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「地址不是公网」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`),`route` 记录该地址是在哪条线路上被判定的(`proxied`、`direct`,或传输层读不出线路时的 `unknown`),因此「直连线路上的 fake-IP 拒绝」与「读不出线路的拒绝」可以区分(ADR 0272)。记录中只保留主机名、该类别与该线路 —— 绝不包含地址、URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,被拒绝的主机正是全部诊断价值所在,而该类别正是区分解析器产物与真实私网目标的依据(issue #419)。++- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`、`address`,以及被守卫拒绝时的 `reason`、`addressKind` 与 `route`。`kind` 在守卫判定的是目标自身地址时为 `policy`,判定的是本地代理伪造的 fake-IP 占位地址时为 `fake-ip`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前两者为 `NETWORK_POLICY_BLOCKED`,第三者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「目标地址不是公网」「代理用了 fake-IP」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`),`route` 记录该地址是在哪条线路上被判定的(`proxied`、`direct`,或传输层读不出线路时的 `unknown`),因此「直连线路上的 fake-IP 拒绝」与「读不出线路的拒绝」可以区分(ADR 0272)。记录会保留主机名、被解析到的地址、该地址的类别与该线路 —— 但绝不包含 URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,而被拒绝的主机、地址及其类别正是全部诊断价值所在(issue #419)。- `runtime` — host/sidecar 生命周期、未分类的子进程输出,以及主进程`uncaughtException` / `unhandledRejection` 记录diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 969a47367,a0ae0965b..1b94384c6--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@@ -7365,13 -7420,13 +7420,13 @@@ runner 会在运行时的隔离临时�#### E2E-SKILL-MARKET-NET-BOUNDARY:技能源公网 HTTPS 策略拒绝私网与回环- - **前提条件**:共享 public-network helper,以及可注入 fetch/DNS 的主进程公网 HTTPS 客户端。- - **步骤**:1)分类 trailing-dot localhost、IPv4 回环、IPv4-mapped IPv6、ULA、link-local、RFC1918 与 `http://`。2)将公网主机名解析到私网 A 记录。3)跟随 Location 为 `https://127.0.0.1/` 的 302。- - **预期**:上述绕过形态全部拒绝;公共 CDN 放行。解析到私网地址或 redirect 到回环会抛出策略错误,且不会请求私网目标。判定型拒绝不重试;本地解析没有返回答案时会重试,并且报为 `NETWORK_RESOLVE_FAILED`(`kind` 为 `unresolved`);解析到本地代理伪造的 fake-IP(如 Clash 默认的 `198.18.0.0/15`)仍被拒绝且不重试,并以 `kind` 为 `fake-ip`、`reason` 为 `non-public-address`、`addressKind` 为 `benchmark` 记录,与真实私网目标(`kind` 为 `policy`、`addressKind` 为 `private`)清楚区分——对后者守卫判定了目标,对前者没有。其余每次拒绝都带上 `NETWORK_POLICY_BLOCKED`(spec 08 §3.1)及其 `reason`、被解析到的地址与地址类别,使安装面板能给出原因并提供重试,而不是让安装按钮无解释地保持禁用;市场列表也能把被拒绝的源与单纯不可达的源区分开。- - **链接规格**:`05-security/01-security.md`、ADR 0243、`03-runtime/01-ipc-protocol.md` §12b+ - **前提条件**:共享 public-network helper,以及可注入 fetch/DNS/线路 的主进程公网 HTTPS 客户端。+ - **步骤**:1)分类 trailing-dot localhost、IPv4 回环、IPv4-mapped IPv6、ULA、link-local、RFC1918 与 `http://`。2)将公网主机名解析到私网 A 记录。3)跟随 Location 为 `https://127.0.0.1/` 的 302。4)报告 `proxied` 线路与 TUN fake-IP 答案(`198.18.0.1`),同一答案在 `DIRECT` 线路、读不出线路、以及列表中含 `DIRECT` 的线路上的表现。5)让第一跳为 `proxied`,其重定向目标为 `direct`。-- **预期**:上述绕过形态全部拒绝;公共 CDN 放行。解析到私网地址或 redirect 到回环会抛出策略错误,且不会请求私网目标。判定型拒绝不重试;本地解析没有返回答案时会重试,并且报为 `NETWORK_RESOLVE_FAILED`(`kind` 为 `unresolved`),而不是报成地址校验拒绝——守卫并未得出判定,任何文案都不得声称它得出了。其余每次拒绝都带上 `NETWORK_POLICY_BLOCKED`(spec 08 §3.1)及其 `reason`、被拒地址的类别与判定该地址的线路,使安装面板能给出原因并提供重试,而不是让安装按钮无解释地保持禁用;市场列表也能把被拒绝的源与单纯不可达的源区分开。若 `proxied` 线路上的答案是 RFC 2544 的 fake-IP 类别,则在 `direct` 或读不出线路时拒绝、在 `proxied` 线路上放行;其他所有非公网类别在任何线路上都拒绝;每一个重定向跳都按自己的线路判定(ADR 0272)。++- **预期**:上述绕过形态全部拒绝;公共 CDN 放行。解析到私网地址或 redirect 到回环会抛出策略错误,且不会请求私网目标。判定型拒绝不重试;本地解析没有返回答案时会重试,并且报为 `NETWORK_RESOLVE_FAILED`(`kind` 为 `unresolved`),而不是报成地址校验拒绝——守卫并未得出判定,任何文案都不得声称它得出了。本地代理伪造的 fake-IP 答案(如 Clash 默认的 `198.18.0.0/15`)在守卫判定它的线路上——`direct` 或读不出线路——仍被拒绝且不重试,并以 `kind` 为 `fake-ip`、`reason` 为 `non-public-address`、`addressKind` 为 `benchmark` 记录,与真实私网目标(`kind` 为 `policy`、`addressKind` 为 `private`)清楚区分——对后者守卫判定了目标,对前者没有;同一答案在 `proxied` 线路上放行。其余每次拒绝都带上 `NETWORK_POLICY_BLOCKED`(spec 08 §3.1)及其 `reason`、被解析到的地址、地址类别与判定该地址的线路,使安装面板能给出原因并提供重试,而不是让安装按钮无解释地保持禁用;市场列表也能把被拒绝的源与单纯不可达的源区分开。其他所有非公网类别在任何线路上都拒绝;每一个重定向跳都按自己的线路判定(ADR 0272)。+ - **链接规格**:`05-security/01-security.md`、ADR 0243、ADR 0272、`03-runtime/01-ipc-protocol.md` §12b- **验收**:Security、Quality- **里程碑**:M6+- - **状态**:已自动化(`pnpm test:e2e:skill-market`、`apps/desktop/test/public-https-fetch.test.mjs`、`apps/desktop/test/skill-market-scan.test.mjs`、`apps/desktop/test/skill-market-failure.test.mjs`、`apps/desktop/test/skill-market-policy-refusal.test.mjs`、`packages/shared/src/public-network.test.ts`)+ - **状态**:已自动化(`pnpm test:e2e:skill-market`、`apps/desktop/test/public-https-fetch.test.mjs`、`apps/desktop/test/public-https-fetch-route.test.mjs`、`apps/desktop/test/skill-market-scan.test.mjs`、`apps/desktop/test/skill-market-failure.test.mjs`、`apps/desktop/test/skill-market-policy-refusal.test.mjs`、`packages/shared/src/public-network.test.ts`)#### E2E-SKILL-MARKET-EXPANSION:相邻 markdown 资源在安装前内联diff --cc packages/shared/src/public-network.test.tsindex d6ee8313f,1ec3a466f..3a2f693be--- a/packages/shared/src/public-network.test.ts+++ b/packages/shared/src/public-network.test.ts@@@ -162,4 -141,96 +164,97 @@@ describe("public network address policyexpect(publicNetworkRefusalDetail(new Error("responded 502"))).toBeUndefined();expect(publicNetworkRefusalDetail(undefined)).toBeUndefined();});++ it("reads the route a proxy list proves, and refuses to guess", () => {+ // ADR 0272: the address verdict follows the route the request will take, so+ // the route has to be read strictly. Only a list with a proxy chain and no+ // `DIRECT` entry proves the app's socket can be a proxy: Chromium may fall+ // back to `DIRECT`, so an offered direct connection is `unknown`, never+ // `proxied`.+ const cases: Array<[unknown, ReturnType<typeof classifyProxyRoute>]> = [+ ["DIRECT", "direct"],+ ["direct", "direct"],+ ["PROXY 127.0.0.1:7890", "proxied"],+ ["SOCKS5 127.0.0.1:1080", "proxied"],+ ["SOCKS 127.0.0.1:1080", "proxied"],+ ["HTTPS proxy.example:443", "proxied"],+ ["SOCKS5 a.example:1, PROXY b.example:2", "proxied"],+ ["PROXY 127.0.0.1:7890; PROXY 127.0.0.1:7891", "proxied"],+ ["PROXY 127.0.0.1:7890; DIRECT", "unknown"],+ ["DIRECT; PROXY 127.0.0.1:7890", "unknown"],+ ["", "unknown"],+ [" ", "unknown"],+ ["MAGIC 127.0.0.1:7890", "unknown"],+ ["PROXY", "unknown"],+ ["PROXY 127.0.0.1:7890; MAGIC x", "unknown"],+ [undefined, "unknown"],+ [null, "unknown"],+ [7890, "unknown"],+ ];+ for (const [proxyList, route] of cases) {+ expect(classifyProxyRoute(proxyList), JSON.stringify(proxyList)).toBe(route);+ }+ });++ it("accepts only the resolver artifact on a proxied route", () => {+ // `benchmark` is a TUN fake-IP answer: an address this app never dials when+ // it is dialing a proxy. Every class that names a real internal target still+ // refuses on both routes, and a direct (or unreadable) route keeps the+ // original rule for all of them.+ expect(isAcceptableResolvedAddress("public", "direct")).toBe(true);+ expect(isAcceptableResolvedAddress("public", "proxied")).toBe(true);+ expect(isAcceptableResolvedAddress("public", "unknown")).toBe(true);+ expect(isAcceptableResolvedAddress("benchmark", "proxied")).toBe(true);+ expect(isAcceptableResolvedAddress("benchmark", "direct")).toBe(false);+ expect(isAcceptableResolvedAddress("benchmark", "unknown")).toBe(false);+ for (const kind of [+ "invalid",+ "unspecified",+ "loopback",+ "private",+ "cgnat",+ "link-local",+ "multicast",+ "reserved",+ "documentation",+ "ula",+ "site-local",+ ] as const) {+ expect(isAcceptableResolvedAddress(kind, "proxied"), kind).toBe(false);+ }+ });++ it("carries the judged route, and drops an unknown one", () => {+ expect(+ publicNetworkRefusalDetail({+ name: PUBLIC_NETWORK_POLICY_ERROR,+ reason: "non-public-address",+ host: "cdn.jsdelivr.net",+ address: "198.18.0.4",+ addressKind: "benchmark",+ route: "direct",+ }),+ ).toEqual({+ reason: "non-public-address",+ host: "cdn.jsdelivr.net",++ address: "198.18.0.4",+ addressKind: "benchmark",+ route: "direct",+ });+ expect(+ publicNetworkRefusalDetail({+ name: PUBLIC_NETWORK_POLICY_ERROR,+ reason: "resolve-failed",+ host: "api.github.com",+ route: "made-up",+ }),+ ).toEqual({ reason: "resolve-failed", host: "api.github.com" });+ expect(+ publicNetworkRefusalDetail({+ name: PUBLIC_NETWORK_POLICY_ERROR,+ reason: "url-syntax",+ route: "proxied",+ }),+ ).toEqual({ reason: "url-syntax", route: "proxied" });+ });});diff --cc packages/shared/src/public-network.tsindex 375932c84,2b91f9ac4..c0ee4919c--- a/packages/shared/src/public-network.ts+++ b/packages/shared/src/public-network.ts@@@ -188,15 -257,14 +257,21 @@@ export type PublicNetworkRefusalDetailreason: PublicNetworkRefusalReason;/** The hostname the guard was classifying, when it got that far. */host?: string;- /** The class of the address that failed the policy, never the address. */+ /**+ * The address that failed the policy, validated as an IP literal before it is+ * carried. It is the local resolver's answer for `host`, not the user's input+ * and not a URL component, and it is the single most diagnostic field a+ * refusal has: `198.18.0.1` reads as a proxy's fake-IP at a glance.+ */+ address?: string;+ /** That address's class, which is what separates a proxy artifact from a target. */addressKind?: PublicNetworkAddressKind;+ /**+ * The route that hop was judged on, when the guard could read one. `direct`+ * is why a fake-IP answer is still a refusal: the app would dial it itself+ * (ADR 0272).+ */+ route?: PublicNetworkRoute;};const PUBLIC_NETWORK_ADDRESS_KINDS: ReadonlyArray<PublicNetworkAddressKind> = [@@@ -215,53 -283,35 +290,66 @@@"site-local",];+ const PUBLIC_NETWORK_ROUTES: ReadonlyArray<PublicNetworkRoute> = ["direct", "proxied", "unknown"];+/**- * What a refusal says about itself: why, which host, which class of address- * failed, and which route the guard judged that hop on. Callers that must- * explain a block — the skill market's classifier and its diagnostics — read- * this instead of parsing the message. `addressKind` travels without the- * address: the class is what separates a resolver artifact (`benchmark`, a TUN- * fake-IP) from a real private target (`private`, RFC1918), and it is not a- * secret.+ * The address classes a local proxy hands back for a name it means to resolve+ * itself, instead of the target's own address. `benchmark` is RFC 2544's+ * `198.18.0.0/15`, which Clash, Mihomo, sing-box and Surge all ship as their+ * default fake-IP pool — and `2001:2::/48` in IPv6.+ *+ * A caller uses this to explain a block correctly, never to lift one: an address+ * in this class still fails `isPublicIpLiteral`, and the guard still refuses it- * (issue #419).++ * unless the route says this app dials a proxy instead of that address++ * (ADR 0272, issue #419).+ */+export function isProxyFakeIpAddress(kind: PublicNetworkAddressKind | undefined): boolean {+ return kind === "benchmark";+}++/**+ * What a refusal says about itself: why, which host, which address it resolved- * to, and which class that address fell into. Callers that must explain a block- * — the skill market's classifier and its diagnostics — read this instead of- * parsing the message.++ * to, which class that address fell into, and which route the guard judged that++ * hop on. Callers that must explain a block — the skill market's classifier and++ * its diagnostics — read this instead of parsing the message.+ *+ * The address and its class travel together: the address is what the user+ * recognises (`198.18.0.1` is unmistakably a proxy's fake-IP) and the class is- * what a machine decides on. Neither is a secret — both are the local resolver's- * answer for a hostname the user supplied — and neither is a URL, a path, a- * query or a credential.++ * what a machine decides on; `route` is what decides whether that fake-IP class++ * was tolerated or refused (ADR 0272). Neither the address nor the class is a++ * secret — both are the local resolver's answer for a hostname the user supplied++ * — and neither is a URL, a path, a query or a credential.*/export function publicNetworkRefusalDetail(error: unknown): PublicNetworkRefusalDetail | undefined {const reason = publicNetworkRefusalReason(error);if (!reason) return undefined;- const source = error as { host?: unknown; address?: unknown; addressKind?: unknown };- const source = error as { host?: unknown; addressKind?: unknown; route?: unknown };++ const source = error as {++ host?: unknown;++ address?: unknown;++ addressKind?: unknown;++ route?: unknown;++ };const host = typeof source.host === "string" && source.host ? source.host : undefined;const addressKind = PUBLIC_NETWORK_ADDRESS_KINDS.includes(source.addressKind as PublicNetworkAddressKind,)? (source.addressKind as PublicNetworkAddressKind): undefined;+ // Only a well-formed IP literal travels: a refusal must never be a channel for+ // putting arbitrary resolver text into a log line or a settings page.+ const address =+ typeof source.address === "string" && classifyIpLiteral(source.address) !== "invalid"+ ? source.address+ : undefined;+ const route = PUBLIC_NETWORK_ROUTES.includes(source.route as PublicNetworkRoute)+ ? (source.route as PublicNetworkRoute)+ : undefined;return {reason,...(host ? { host } : {}),+ ...(address ? { address } : {}),...(addressKind ? { addressKind } : {}),+ ...(route ? { route } : {}),};}