Browse Source

fix(core): ignore empty agent files (#40302)

Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com>
opencode-agent[bot] 1 week ago
parent
commit
8df03aa1bc

+ 1 - 1
packages/core/src/config/plugin/agent.ts

@@ -58,7 +58,7 @@ export const Plugin = define({
           const files = yield* discover(fs, entry.path)
           return yield* Effect.forEach(files, (file) =>
             fs.readFileStringSafe(file.filepath).pipe(
-              Effect.map((content) => content && decode(file, content)),
+              Effect.map((content) => (content ? decode(file, content) : undefined)),
               Effect.catch(() => Effect.succeed(undefined)),
             ),
           ).pipe(

+ 2 - 0
packages/core/test/config/agent.test.ts

@@ -266,6 +266,7 @@ permissions:
 Use native v2 fields.`,
             )
             await fs.writeFile(path.join(tmp.path, "agents", "disabled.md"), "---\ndisabled: true\n---\nDisabled")
+            await fs.writeFile(path.join(tmp.path, "agents", "empty.md"), "")
             await fs.writeFile(path.join(tmp.path, "modes", "plan.md"), "Make a plan.")
           })
           const agents = yield* Agent.Service
@@ -295,6 +296,7 @@ Use native v2 fields.`,
             permissions: [...defaultPermissions, { action: "edit", resource: "*", effect: "deny" }],
           })
           expect(yield* agents.get(Agent.ID.make("disabled"))).toBeUndefined()
+          expect(yield* agents.get(Agent.ID.make("empty"))).toBeUndefined()
           expect(yield* agents.get(Agent.ID.make("plan"))).toMatchObject({ system: "Make a plan.", mode: "primary" })
         }),
       ),