Skip to content

Commit 235efc2

Browse files
sahrizviclaude
andcommitted
fix(workspace): a skill whose SKILL.md cannot be checked is unreadable, not absent
Only `ENOENT`/`ENOTDIR` from the `stat` means a folder is not a skill; any other failure (`EACCES`, `EIO`) lists it as unreadable, and a snapshot of only such skills is "unknown" rather than "none". Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV
1 parent 96b8931 commit 235efc2

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/workspace/contents.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ async function readSnapshot(root: string): Promise<WorkspaceSkill[] | null | "un
106106
entries.map((e) =>
107107
fs.stat(path.join(root, e, "SKILL.md")).then(
108108
(f) => `${e}:${f.mtimeMs}:${f.size}`,
109-
() => `${e}:-`,
109+
// Only a confirmed absence means "not a skill"; any other failure (EACCES, EIO) is a skill we could not read.
110+
(err: NodeJS.ErrnoException) => (err?.code === "ENOENT" || err?.code === "ENOTDIR" ? `${e}:-` : `${e}:?`),
110111
),
111112
),
112113
)
@@ -121,6 +122,7 @@ async function readSnapshot(root: string): Promise<WorkspaceSkill[] | null | "un
121122
// A folder with no SKILL.md is not a skill (stamped "-" above).
122123
if (files[i].endsWith(":-")) continue
123124
try {
125+
if (files[i].endsWith(":?")) throw new Error("SKILL.md could not be checked")
124126
const md = await ConfigMarkdown.parse(path.join(root, entry, "SKILL.md"))
125127
const name = label((md.data as Record<string, unknown>)?.name, 80)
126128
if (!name) throw new Error("no name")

‎packages/opencode/test/altimate/workspace/contents.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,30 @@ describe("workspace skills", () => {
321321
}
322322
})
323323

324+
test("a skill whose SKILL.md cannot even be checked is unreadable, not absent", async () => {
325+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-contents-"))
326+
const locked = path.join(root, "locked")
327+
try {
328+
for (const d of ["good", "locked"]) fs.mkdirSync(path.join(root, d))
329+
fs.writeFileSync(path.join(root, "good", "SKILL.md"), "---\nname: good\ndescription: fine\n---\nbody\n")
330+
fs.writeFileSync(path.join(locked, "SKILL.md"), "---\nname: locked\ndescription: hidden\n---\nbody\n")
331+
fs.chmodSync(locked, 0o000) // stat of locked/SKILL.md now fails with EACCES, not ENOENT
332+
Contents.setSnapshotForTests({ root: () => root, workspaceId: async () => 35 })
333+
const skills = await Contents.workspaceSkills("/project", 35)
334+
if (!Array.isArray(skills)) throw new Error(`expected a list, got ${JSON.stringify(skills)}`)
335+
expect(skills.map((x) => [x.name, x.unreadable === true])).toEqual([
336+
["good", false],
337+
["locked", true],
338+
])
339+
// When it is the only skill, the answer is "could not be read", never "no skills".
340+
fs.rmSync(path.join(root, "good"), { recursive: true })
341+
expect(await Contents.workspaceSkills("/project", 35)).toBe("unknown")
342+
} finally {
343+
fs.chmodSync(locked, 0o700)
344+
fs.rmSync(root, { recursive: true, force: true })
345+
}
346+
})
347+
324348
test("an in-place SKILL.md edit is picked up without a new snapshot", async () => {
325349
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-contents-"))
326350
try {

0 commit comments

Comments
 (0)