A desktop coding agent with free access to frontier models.
TypeScript
fix: read linked global config
ogsamratd18635e84ec0
diff --git a/apps/server/src/user-skill-paths.test.ts b/apps/server/src/user-skill-paths.test.tsindex 8fb5004e..ee6d40f6 100644--- a/apps/server/src/user-skill-paths.test.ts+++ b/apps/server/src/user-skill-paths.test.ts@@ -1,5 +1,5 @@import { afterEach, describe, expect, test } from "bun:test";-import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";+import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";@@ -80,6 +80,13 @@ describe("user skill folders", () => {await writeFile(file, bytes);expect(await userGlobalSkillPaths(process.env)).toEqual(["~/my-skills", "/abs/team"]);expect(await readFile(file, "utf8")).toBe(bytes);+ // A config kept elsewhere and linked in (a dotfile manager) is read, as the engine reads it.+ await rm(file);+ const linked = join(home, "dotfiles", "opencode.json");+ await mkdir(join(home, "dotfiles"), { recursive: true });+ await writeFile(linked, JSON.stringify({ skills: { paths: ["/linked"] } }));+ await symlink(linked, join(dir, "opencode.json"));+ expect(await userGlobalSkillPaths(process.env)).toEqual(["/linked"]);expect(mergeSkillPaths(["/app"], ["/app", "/a"], undefined, ["/b"])).toEqual(["/app", "/a", "/b"]);});diff --git a/apps/server/src/user-skill-paths.ts b/apps/server/src/user-skill-paths.tsindex 6e516712..4ba726d7 100644--- a/apps/server/src/user-skill-paths.ts+++ b/apps/server/src/user-skill-paths.ts@@ -12,10 +12,14 @@* own.* The user's files are only read, never written.*/+import { stat } from "node:fs/promises";import { homedir } from "node:os";import { join } from "node:path";import { readJsoncFile } from "./jsonc.js";+/** Larger global config files are not read for skill folders. */+const MAX_CONFIG_BYTES = 1024 * 1024;+function isRecord(value: unknown): value is Record<string, unknown> {return typeof value === "object" && value !== null && !Array.isArray(value);}@@ -40,7 +44,11 @@ export async function userGlobalSkillPaths(env: NodeJS.ProcessEnv = process.env)const dir = engineGlobalConfigDir(env);let paths: string[] = [];for (const name of ["config.json", "opencode.json", "opencode.jsonc"]) {- const read = await readJsoncFile<unknown>(join(dir, name), undefined, { allowInvalid: true, regularFileOnly: true }).catch(() => null);+ const file = join(dir, name);+ // Followed like the engine follows it (a dotfile manager's link), and only a file of a sane size.+ const info = await stat(file).catch(() => null);+ if (!info?.isFile() || info.size > MAX_CONFIG_BYTES) continue;+ const read = await readJsoncFile<unknown>(file, undefined, { allowInvalid: true }).catch(() => null);const listed = configSkillPaths(read?.data);if (listed) paths = listed;}