Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(skills): match plugin workspace folders across Windows path spellings
liuzixiang7955f42d6513
diff --git a/apps/desktop/electron/main/builtin-skills.ts b/apps/desktop/electron/main/builtin-skills.tsindex 11e3fb22b..25dd349d1 100644--- a/apps/desktop/electron/main/builtin-skills.ts+++ b/apps/desktop/electron/main/builtin-skills.ts@@ -5,6 +5,7 @@ import { GEN_UI_SKILL_ID } from "@pi-desktop/shared";import type { PluginSkillDef } from "@pi-desktop/agent-runtime";import type { LoadedSkillDocument } from "./skill-document";import { getModuleDirectory } from "./module-path";+import { pluginWorkspaceContains } from "./plugin-workspace-contains";/*** Skills PI-Desktop ships itself.@@ -68,8 +69,7 @@ export function isPluginWorkspace(// An unparseable manifest is not evidence either way.}}- const prefix = workspacePath.endsWith("/") ? workspacePath : `${workspacePath}/`;- return pluginPaths.some((path) => path === workspacePath || path.startsWith(prefix));+ return pluginPaths.some((pluginPath) => pluginWorkspaceContains(workspacePath, pluginPath));}/** Front matter carries the skill's title and applicability line. */diff --git a/apps/desktop/electron/main/plugin-workspace-contains.ts b/apps/desktop/electron/main/plugin-workspace-contains.tsnew file mode 100644index 000000000..fa28d22f4--- /dev/null+++ b/apps/desktop/electron/main/plugin-workspace-contains.ts@@ -0,0 +1,24 @@+/**+ * Containment for the plugin-workspace probe. The two spellings come from+ * different worlds — the plugin folder from a native dialog (backslashes on+ * Windows), the workspace from the host (which may persist `//?/X:/…` or a+ * forward-slash variant) — so both are unified before comparing: separators+ * fold to `/`, the Windows verbatim prefix (`\\?\X:\` in either spelling)+ * drops away, and comparison stays case-sensitive only on Linux, matching the+ * worktree ref folding. Kept dependency free so its test can drive it+ * directly.+ */+export function pluginWorkspaceContains(+ workspacePath: string,+ pluginPath: string,+): boolean {+ const fold = (value: string) => {+ const unified = value.replace(/\\/g, "/").replace(/\/+$/, "");+ const stripped = unified.replace(/^\/\/\?\/(?=[a-z]:\/)/i, "");+ return process.platform === "linux" ? stripped : stripped.toLowerCase();+ };+ const workspace = fold(workspacePath);+ if (!workspace) return false;+ const plugin = fold(pluginPath);+ return plugin === workspace || plugin.startsWith(`${workspace}/`);+}diff --git a/apps/desktop/test/plugin-workspace-contains.test.mjs b/apps/desktop/test/plugin-workspace-contains.test.mjsnew file mode 100644index 000000000..f6a66630a--- /dev/null+++ b/apps/desktop/test/plugin-workspace-contains.test.mjs@@ -0,0 +1,33 @@+import assert from "node:assert/strict";+import test from "node:test";+import "./helpers/ts-import-hooks.mjs";+import { pluginWorkspaceContains } from "../electron/main/plugin-workspace-contains.ts";++test("plugin workspace containment unifies Windows separator spellings", () => {+ // The plugin folder arrives from a native dialog, the workspace from the+ // host; before the fix the probe built a "/"-suffixed prefix and never+ // matched a backslashed plugin path on Windows.+ assert.equal(pluginWorkspaceContains("C:/dev/repo", "C:\\dev\\repo\\plugins\\my-plugin"), true);+ assert.equal(pluginWorkspaceContains("C:\\dev\\repo", "C:\\dev\\repo\\plugins\\my-plugin"), true);+ assert.equal(pluginWorkspaceContains("C:/dev/repo", "C:/dev/repo/plugins/my-plugin"), true);+ // The host's `//?/X:/…` long-path spelling normalizes away.+ assert.equal(pluginWorkspaceContains("//?/C:/dev/repo", "C:\\dev\\repo\\plugins\\p"), true);+ // The plugin loaded from the workspace root itself counts.+ assert.equal(pluginWorkspaceContains("C:/dev/repo", "C:\\dev\\repo"), true);+ // Case folds everywhere but Linux, like the worktree ref folding.+ const caseFolds = process.platform !== "linux";+ assert.equal(+ pluginWorkspaceContains("C:/Dev/Repo", "c:\\dev\\REPO\\plugins\\p") === caseFolds,+ true,+ );+});++test("plugin workspace containment keeps the prefix boundary", () => {+ // A sibling that merely shares a textual prefix must not count.+ assert.equal(pluginWorkspaceContains("C:/dev/repo", "C:/dev/repo-x/plugin"), false);+ assert.equal(pluginWorkspaceContains("/home/dev/repo", "/home/dev/repo-x/plugin"), false);+ assert.equal(pluginWorkspaceContains("/home/dev/repo", "/home/dev/repo/plugin"), true);+ assert.equal(pluginWorkspaceContains("/home/dev/repo", "/elsewhere/plugin"), false);+ // Trailing separators on either side do not break the comparison.+ assert.equal(pluginWorkspaceContains("/home/dev/repo/", "/home/dev/repo/plugin"), true);+});