MCPcopy
hub / github.com/anomalyco/opencode / loadDirectory

Function loadDirectory

packages/core/src/config/plugin/command.ts:52–68  ·  view source on GitHub ↗
(fs: FSUtil.Interface, directory: string)

Source from the content-addressed store, hash-verified

50})
51
52function loadDirectory(fs: FSUtil.Interface, directory: string) {
53 return Effect.gen(function* () {
54 const files = yield* fs
55 .glob("{command,commands}/**/*.md", { cwd: directory, absolute: true, dot: true, symlink: true })
56 .pipe(Effect.catch(() => Effect.succeed([] as string[])))
57 return yield* Effect.forEach(files.toSorted(), (filepath) =>
58 fs.readFileStringSafe(filepath).pipe(
59 Effect.map((content) => (content === undefined ? undefined : decode(directory, filepath, content))),
60 Effect.catch(() => Effect.succeed(undefined)),
61 ),
62 ).pipe(
63 Effect.map((commands) =>
64 commands.filter((command): command is { name: string; info: ConfigCommand.Info } => command !== undefined),
65 ),
66 )
67 })
68}
69
70function decode(directory: string, filepath: string, content: string) {
71 const markdown = ConfigMarkdown.parseOption(content)

Callers 1

command.tsFile · 0.85

Calls 2

decodeFunction · 0.70
globMethod · 0.65

Tested by

no test coverage detected