Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { existsSync } from "fs"
export namespace Config {
const log = Log.create({ service: "config" })

// Track install promises per directory so tools can wait for their dependencies
const installPromises = new Map<string, Promise<void>>()

// Custom merge function that concatenates array fields instead of replacing them
function mergeConfigConcatArrays(target: Info, source: Info): Info {
const merged = mergeDeep(target, source)
Expand Down Expand Up @@ -106,6 +109,7 @@ export namespace Config {

const exists = existsSync(path.join(dir, "node_modules"))
const installing = installDependencies(dir)
installPromises.set(dir, installing)
if (!exists) await installing

result.command = mergeDeep(result.command ?? {}, await loadCommand(dir))
Expand Down Expand Up @@ -162,6 +166,7 @@ export namespace Config {
return {
config: result,
directories,
installPromises,
}
})

Expand Down Expand Up @@ -1118,4 +1123,9 @@ export namespace Config {
export async function directories() {
return state().then((x) => x.directories)
}

export async function getInstallPromise(dir: string): Promise<void> {
const promises = await state().then((x) => x.installPromises)
return promises.get(dir) ?? Promise.resolve()
}
}
3 changes: 3 additions & 0 deletions packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export namespace ToolRegistry {
const glob = new Bun.Glob("tool/*.{js,ts}")

for (const dir of await Config.directories()) {
// Wait for dependencies to be installed before loading tools from this directory
await Config.getInstallPromise(dir)

for await (const match of glob.scan({
cwd: dir,
absolute: true,
Expand Down