| 254 | |
| 255 | const MODE_GLOB = new Bun.Glob("mode/*.md") |
| 256 | async function loadMode(dir: string) { |
| 257 | const result: Record<string, Agent> = {} |
| 258 | for await (const item of MODE_GLOB.scan({ |
| 259 | absolute: true, |
| 260 | followSymlinks: true, |
| 261 | dot: true, |
| 262 | cwd: dir, |
| 263 | })) { |
| 264 | const md = await ConfigMarkdown.parse(item) |
| 265 | if (!md.data) continue |
| 266 | |
| 267 | const config = { |
| 268 | name: path.basename(item, ".md"), |
| 269 | ...md.data, |
| 270 | prompt: md.content.trim(), |
| 271 | } |
| 272 | const parsed = Agent.safeParse(config) |
| 273 | if (parsed.success) { |
| 274 | result[config.name] = { |
| 275 | ...parsed.data, |
| 276 | mode: "primary" as const, |
| 277 | } |
| 278 | continue |
| 279 | } |
| 280 | } |
| 281 | return result |
| 282 | } |
| 283 | |
| 284 | const PLUGIN_GLOB = new Bun.Glob("{plugin,plugins}/*.{ts,js}") |
| 285 | async function loadPlugin(dir: string) { |