Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(skills): log skill market failures so a proxy refusal is diagnosable

vastsacc4bdac7db3f
diff --git a/apps/desktop/electron/main/ipc/register.ts b/apps/desktop/electron/main/ipc/register.ts
index 7fe3f920a..14d4345b0 100644
--- a/apps/desktop/electron/main/ipc/register.ts
+++ b/apps/desktop/electron/main/ipc/register.ts
@@ -361,6 +361,7 @@ export function registerIpcHandlers(dependencies: RegisterIpcDependencies) {
activeUserSubagentDocuments,
stripWinLongPrefix,
sendToRenderer,
+ logger,
});
diff --git a/apps/desktop/electron/main/ipc/skills-ipc.ts b/apps/desktop/electron/main/ipc/skills-ipc.ts
index d5ab88301..bc2c81572 100644
--- a/apps/desktop/electron/main/ipc/skills-ipc.ts
+++ b/apps/desktop/electron/main/ipc/skills-ipc.ts
@@ -1,13 +1,15 @@
import { dialog, shell } from "electron";
-import { IPC, type ActivationScope, type AgentCapabilityQuery, type UserSkillRecord, type UserSubagentRecord } from "@pi-desktop/shared";
+import { ErrorCodes, IPC, type ActivationScope, type AgentCapabilityQuery, type UserSkillRecord, type UserSubagentRecord } from "@pi-desktop/shared";
import { loadSubagentDefinitions, type UserSubagentDocument } from "@pi-desktop/agent-runtime";
import type { HostProcess } from "../host-process";
+import type { Logger } from "../logger";
import {
fetchSkillMarketDocument,
searchSkillMarket,
type SkillMarketDocument,
type SkillMarketSearchResult,
} from "../skill-market-catalog";
+import { skillMarketFailureDetail, skillMarketHost } from "../skill-market-scan";
import type { IpcRegistrar } from "./types";
export type SkillsIpcDependencies = {
@@ -19,6 +21,7 @@ export type SkillsIpcDependencies = {
sendToRenderer: (channel: string, payload?: unknown) => void;
searchSkillMarket: (query: string, sources: { id: string; name: string; url: string }[]) => Promise<SkillMarketSearchResult>;
fetchSkillMarketDocument: (entry: { id: string; name: string; url: string }) => Promise<SkillMarketDocument>;
+ logger: Pick<Logger, "app">;
};
/** Register user-owned skill and subagent definition channels. */
@@ -31,7 +34,36 @@ export function registerSkillsIpc({
sendToRenderer,
searchSkillMarket,
fetchSkillMarketDocument,
+ logger,
}: SkillsIpcDependencies): void {
+ /*
+ The market's two channels are the only place that knows why a source went
+ quiet, and they previously reported nothing outside the panel. A refusal
+ from the public-network guard (issue #419: a proxy that answers DNS itself
+ resolves a public host to a non-public address, so the local pre-check
+ refuses a URL the browser reaches) was therefore impossible to diagnose
+ from a user's logs. `diagnostics` is the category spec 09 gives to blocked
+ requests; the payload is host + source + kind only, never the full URL.
+ */
+ const logSourceFailure = (
+ source: { name?: unknown; url?: unknown },
+ kind: "policy" | "network",
+ ) => {
+ const host = skillMarketHost(source.url);
+ logger.app("diagnostics", "warn", "skill market source produced no entries", {
+ ...(kind === "policy" ? { code: ErrorCodes.NETWORK_POLICY_BLOCKED } : {}),
+ event: "skillMarket.sourceFailed",
+ data: {
+ ...(typeof source.name === "string" && source.name ? { source: source.name } : {}),
+ ...(host ? { host } : {}),
+ kind,
+ },
+ });
+ };
+ const marketFailureKind = (
+ result: SkillMarketSearchResult,
+ name: string,
+ ): "policy" | "network" => (result.failureKinds?.[name] === "policy" ? "policy" : "network");
let host: HostProcess | null = null;
const handle = (channel: string, fn: (...args: any[]) => Promise<any>) => {
registrar.handle(channel, async (...args) => {
@@ -45,13 +77,37 @@ export function registerSkillsIpc({
// registers outside the host-bound wrapper.
registrar.handle(
IPC.invoke.skillMarketSearch,
- async ({ query, sources }: { query?: string; sources?: { id: string; name: string; url: string }[] } = {}) =>
- searchSkillMarket(query ?? "", Array.isArray(sources) ? sources : []),
+ async ({ query, sources }: { query?: string; sources?: { id: string; name: string; url: string }[] } = {}) => {
+ const requested = Array.isArray(sources) ? sources : [];
+ const result = await searchSkillMarket(query ?? "", requested);
+ // One record per source that produced nothing. The panel shows the names,
+ // so without this the reason and the host exist nowhere a user can reach.
+ for (const name of result.failedSources ?? []) {
+ logSourceFailure(
+ requested.find((source) => source?.name === name) ?? { name },
+ marketFailureKind(result, name),
+ );
+ }
+ return result;
+ },
);
registrar.handle(
IPC.invoke.skillMarketFetch,
- async ({ entry }: { entry: { id: string; name: string; url: string } }) =>
- fetchSkillMarketDocument(entry),
+ async ({ entry }: { entry: { id: string; name: string; url: string } }) => {
+ try {
+ return await fetchSkillMarketDocument(entry);
+ } catch (error) {
+ // The install sheet shows this refusal; the log is what makes it
+ // diagnosable after the fact, and it survives the sheet closing.
+ const detail = skillMarketFailureDetail(entry, error);
+ logger.app("diagnostics", "warn", "skill market document fetch failed", {
+ ...(detail.kind === "policy" ? { code: ErrorCodes.NETWORK_POLICY_BLOCKED } : {}),
+ event: "skillMarket.documentFailed",
+ data: detail,
+ });
+ throw error;
+ }
+ },
);
// --- Skills the user owns -------------------------------------------------
diff --git a/apps/desktop/electron/main/skill-market-scan.ts b/apps/desktop/electron/main/skill-market-scan.ts
index b1c91b97f..aeee16678 100644
--- a/apps/desktop/electron/main/skill-market-scan.ts
+++ b/apps/desktop/electron/main/skill-market-scan.ts
@@ -47,12 +47,47 @@ const GITHUB_REPO = /^https:\/\/github\.com\/([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:[
const JSDELIVR_GH = /^https:\/\/cdn\.jsdelivr\.net\/gh\/([^/]+)\/([^/]+)@([^/]+)\/(.+)$/;
const SKILL_FILE = /(?:^|\/)SKILL\.md$/;
-function classifyFailure(error: unknown): SkillMarketFailureKind {
+/**
+ * Why a request failed, exported so the IPC boundary and the aggregator share
+ * one classifier instead of re-deriving it (issue #419).
+ */
+export function classifySkillMarketFailure(error: unknown): SkillMarketFailureKind {
// Structural check so this module keeps no dependency on the client's
// `node:dns` import and stays testable as a pure module.
return isPublicNetworkPolicyFailure(error) ? "policy" : "network";
}
+/**
+ * Bare hostname for a diagnostics record, or undefined when the URL cannot be
+ * parsed. Never a path, query, port or credential: a catalog source URL is
+ * user-supplied and the log line only needs to name the host that was refused.
+ */
+export function skillMarketHost(url: unknown): string | undefined {
+ if (typeof url !== "string") return undefined;
+ try {
+ return new URL(url).hostname.toLowerCase() || undefined;
+ } catch {
+ return undefined;
+ }
+}
+
+/**
+ * The diagnostics payload for one failed catalog source. Built here, not at the
+ * call site, so the shape is unit-testable without Electron and so every
+ * failure record carries the same fields.
+ */
+export function skillMarketFailureDetail(
+ source: { name?: unknown; url?: unknown },
+ error: unknown,
+): { source?: string; host?: string; kind: SkillMarketFailureKind } {
+ const host = skillMarketHost(source.url);
+ return {
+ ...(typeof source.name === "string" && source.name ? { source: source.name } : {}),
+ ...(host ? { host } : {}),
+ kind: classifySkillMarketFailure(error),
+ };
+}
+
const SKILL_CATEGORY_KEYWORDS: ReadonlyArray<readonly [SkillCatalogCategory, string[]]> = [
["data", ["data", "sql", "database", "postgres", "mongo", "redis", "analytics", "dataset", "spreadsheet", "excel", "xlsx", "csv", "dashboard", "chart", "visualization"]],
["workflow", ["workflow", "review", "planning", "brainstorm", "checklist", "process", "sop", "handoff", "standup", "retro", "discernment", "verification", "triage", "audit", "security", "incident"]],
@@ -202,7 +237,7 @@ export function createSkillMarketAggregator(request: CatalogRequest) {
if (result.status === "rejected") {
const name = usable[index].name;
failedSources.push(name);
- markFailure(name, classifyFailure(result.reason));
+ markFailure(name, classifySkillMarketFailure(result.reason));
return;
}
for (const entry of result.value) {
diff --git a/apps/desktop/test/skill-market-scan.test.mjs b/apps/desktop/test/skill-market-scan.test.mjs
index 7f81ce740..a9b24f8b3 100644
--- a/apps/desktop/test/skill-market-scan.test.mjs
+++ b/apps/desktop/test/skill-market-scan.test.mjs
@@ -1,6 +1,14 @@
import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
import test from "node:test";
-import { createSkillMarketAggregator } from "../electron/main/skill-market-scan.ts";
+import { fileURLToPath } from "node:url";
+import {
+ classifySkillMarketFailure,
+ createSkillMarketAggregator,
+ skillMarketFailureDetail,
+ skillMarketHost,
+} from "../electron/main/skill-market-scan.ts";
import { PublicNetworkPolicyError } from "../electron/main/public-https-fetch.ts";
const source = {
@@ -146,3 +154,69 @@ test("a repeated display name keeps the refusal, and a hostile name stays own",
assert.equal(result.failureKinds.__proto__, "policy");
assert.deepEqual(Object.values(result.failureKinds), ["policy", "policy"]);
});
+
+test("a diagnostics record names the host, never the URL or its credentials", () => {
+ // Issue #419: the market's failures wrote nothing to the app log, so a user
+ // behind a proxy had no way to report which host was refused. The record is
+ // built here so its shape is fixed and its redaction is testable.
+ assert.deepEqual(
+ skillMarketFailureDetail(
+ { name: "anthropics/skills", url: "https://user:[email protected]:8443/org/repo?token=abc#x" },
+ new PublicNetworkPolicyError("hostname resolves to a private address"),
+ ),
+ { source: "anthropics/skills", host: "github.com", kind: "policy" },
+ );
+ // A transport failure is not a refusal.
+ assert.equal(
+ skillMarketFailureDetail(source, new Error("responded 502")).kind,
+ "network",
+ );
+ // A source the syntactic guard never let out still logs its name.
+ assert.deepEqual(
+ skillMarketFailureDetail({ name: "broken", url: "http://insecure.example" }, undefined),
+ { source: "broken", host: "insecure.example", kind: "network" },
+ );
+ // An unparseable or missing URL must not produce a host field, and must not
+ // throw while a failure is being reported.
+ assert.equal(skillMarketHost(undefined), undefined);
+ assert.equal(skillMarketHost("not a url"), undefined);
+ assert.equal(skillMarketHost(42), undefined);
+ assert.deepEqual(skillMarketFailureDetail({}, new Error("x")), { kind: "network" });
+});
+
+test("the classifier matches the aggregator's own classification", async () => {
+ // One classifier, so the log line and the panel can never disagree.
+ const policy = new PublicNetworkPolicyError("hostname does not resolve: x.example");
+ assert.equal(classifySkillMarketFailure(policy), "policy");
+ assert.equal(classifySkillMarketFailure(new Error("fetch failed")), "network");
+ const aggregator = createSkillMarketAggregator(async () => {
+ throw policy;
+ });
+ const result = await aggregator.search("", [source]);
+ assert.equal(result.failureKinds["anthropics/skills"], classifySkillMarketFailure(policy));
+});
+
+test("both market channels report their failures to the app log", () => {
+ // `skills-ipc.ts` imports Electron, so the wiring is asserted on the source:
+ // the refusal reason, the host and the stable code must all reach the log,
+ // and the log must not carry the full URL.
+ const src = readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), "../electron/main/ipc/skills-ipc.ts"),
+ "utf8",
+ );
+ assert.match(src, /import type \{ Logger \} from "\.\.\/logger"/);
+ assert.match(src, /logger: Pick<Logger, "app">/);
+ assert.match(src, /logger\.app\("diagnostics", "warn", "skill market source produced no entries"/);
+ assert.match(src, /logger\.app\("diagnostics", "warn", "skill market document fetch failed"/);
+ assert.match(src, /event: "skillMarket\.sourceFailed"/);
+ assert.match(src, /event: "skillMarket\.documentFailed"/);
+ assert.match(src, /code: ErrorCodes\.NETWORK_POLICY_BLOCKED/);
+ assert.match(src, /host: skillMarketHost\(source\.url\)|const host = skillMarketHost\(source\.url\)/);
+ assert.doesNotMatch(src, /data: \{ url|url: source\.url/);
+ // The registration site must supply the logger, or the wiring above is dead.
+ const register = readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), "../electron/main/ipc/register.ts"),
+ "utf8",
+ );
+ assert.match(register, /registerSkillsIpc\(\{[\s\S]*?logger,[\s\S]*?\}\)/);
+});
diff --git a/docs/spec/03-runtime/09-logging-and-observability.md b/docs/spec/03-runtime/09-logging-and-observability.md
index c4eb90aab..b98e78f2f 100644
--- a/docs/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/spec/03-runtime/09-logging-and-observability.md
@@ -51,7 +51,15 @@ The application categories are:
- `provider` — provider/model discovery, retries, and cache failures
- `persistence` — transcript and outbox persistence failures
- `updater` — updater diagnostics and errors
-- `diagnostics` — blocked navigation, menu, and template diagnostics
+- `diagnostics` — blocked navigation, menu, template, and outbound-fetch
+ diagnostics. The skill market's two channels record one
+ `skillMarket.sourceFailed` / `skillMarket.documentFailed` record per source
+ or document that produced nothing, with `source`, `host` and `kind`
+ (`policy` for a public-network-guard refusal, `network` otherwise) in `data`
+ and `NETWORK_POLICY_BLOCKED` in `code` for a refusal. The record carries the
+ host name only — never the URL, its path, query or credentials — because a
+ catalog source URL is user-supplied and the refused host is the whole
+ diagnostic value (issue #419).
- `runtime` — host/sidecar lifecycle, uncategorized child output, and
main-process `uncaughtException` / `unhandledRejection` records
diff --git a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
index f9863c186..94989ac56 100644
--- 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 @@ host 和 agent stderr 使用标记进行分类;无法分类的子进程输出
- `provider` — provider/model 发现、重试和缓存失败
- `persistence` — 成绩单和发件箱持久化失败
- `updater` — 更新器诊断和错误
-- `diagnostics` — 阻止导航、菜单和模板诊断
+- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host` 与 `kind`(被公共网络守卫拒绝为 `policy`,其余为 `network`),被拒绝时 `code` 为 `NETWORK_POLICY_BLOCKED`。记录中只保留主机名 —— 绝不包含 URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,而被拒绝的主机正是全部诊断价值所在(issue #419)。
- `runtime` — host/sidecar 生命周期、未分类的子进程输出,以及主进程
`uncaughtException` / `unhandledRejection` 记录