diff --git a/modules/pi/default.nix b/modules/pi/default.nix index 79c8b89..2f8a659 100644 --- a/modules/pi/default.nix +++ b/modules/pi/default.nix @@ -56,9 +56,6 @@ "${pkgs.gondolin.pi-extension}/extensions/pi-gondolin.ts" ]; quietStartup = "header"; - skills = [ - ./skills - ]; tuiMode = "regular"; }; }; @@ -78,8 +75,9 @@ gondolin-build-nix-image ]; - # Custom agents, and to specify the models + # Custom agents and skills remain mutable, out-of-store resources. file."${config-dir}/agents".source = config.lib.file.mkOutOfStoreSymlink ./agents; + file."${config-dir}/skills".source = config.lib.file.mkOutOfStoreSymlink ./skills; }; }; } diff --git a/packages/by-name/gondolin/pi-gondolin.ts b/packages/by-name/gondolin/pi-gondolin.ts index 9aa05d0..7b54b78 100644 --- a/packages/by-name/gondolin/pi-gondolin.ts +++ b/packages/by-name/gondolin/pi-gondolin.ts @@ -21,9 +21,14 @@ import { import { RealFSProvider, VM } from "@earendil-works/gondolin"; const GUEST_WORKSPACE = "/workspace"; -// Keep global extension state in Pi's configured agent directory. This -// respects PI_CODING_AGENT_DIR rather than assuming an XDG/home-directory path. -const REGISTRY_PATH = path.join(getAgentDir(), "gondolin-images.json"); +// Gondolin images run as root, whose home directory is /root. Mount only Pi's +// skills there, rather than exposing the complete Pi configuration directory. +const GUEST_SKILLS_DIR = "/root/.config/pi/agent/skills"; +// Keep global extension state in Pi's configured agent directory. This respects +// PI_CODING_AGENT_DIR rather than assuming an XDG/home-directory path. +const AGENT_DIR = getAgentDir(); +const SKILLS_DIR = path.join(AGENT_DIR, "skills"); +const REGISTRY_PATH = path.join(AGENT_DIR, "gondolin-images.json"); type ImageDefinition = { name: string; @@ -93,13 +98,21 @@ function shQuote(value: string): string { return `'${value.replace(/'/g, "'\\''")}'`; } +function pathInMount(localPath: string, localRoot: string, guestRoot: string): string | undefined { + const rel = path.relative(localRoot, localPath); + if (rel === "") return guestRoot; + if (rel.startsWith("..") || path.isAbsolute(rel)) return undefined; + return path.posix.join(guestRoot, ...rel.split(path.sep)); +} + function toGuestPath(localCwd: string, localPath: string): string { - const rel = path.relative(localCwd, localPath); - if (rel === "") return GUEST_WORKSPACE; - if (rel.startsWith("..") || path.isAbsolute(rel)) { - throw new Error(`path escapes workspace: ${localPath}`); - } - return path.posix.join(GUEST_WORKSPACE, ...rel.split(path.sep)); + const workspacePath = pathInMount(localPath, localCwd, GUEST_WORKSPACE); + if (workspacePath) return workspacePath; + + const skillsPath = pathInMount(localPath, SKILLS_DIR, GUEST_SKILLS_DIR); + if (skillsPath) return skillsPath; + + throw new Error(`path escapes mounted filesystems: ${localPath}`); } function createGondolinReadOps(vm: VM, localCwd: string): ReadOperations { @@ -225,6 +238,7 @@ export default function (pi: ExtensionAPI) { vfs: { mounts: { [GUEST_WORKSPACE]: new RealFSProvider(localCwd), + [GUEST_SKILLS_DIR]: new RealFSProvider(SKILLS_DIR), }, }, });