Skip to content

Commit 93cbd41

Browse files
committed
fix(effect): preserve tool deps in task init
1 parent e04038a commit 93cbd41

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

packages/opencode/src/tool/registry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ export namespace ToolRegistry {
8080
const config = yield* Config.Service
8181
const plugin = yield* Plugin.Service
8282

83-
const build = <T extends Tool.Info>(tool: T | Effect.Effect<T, never, any>) =>
84-
Effect.isEffect(tool) ? tool : Effect.succeed(tool)
83+
const build = <T extends Tool.Info, R = never>(
84+
tool: T | Effect.Effect<T, never, R>,
85+
): Effect.Effect<T, never, R> => (Effect.isEffect(tool) ? tool : Effect.succeed(tool))
8586

8687
const state = yield* InstanceState.make<State>(
8788
Effect.fn("ToolRegistry.state")(function* (ctx) {

packages/opencode/src/tool/task.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ export const TaskTool = Tool.defineEffect(
2929
const agent = yield* Agent.Service
3030
const config = yield* Config.Service
3131

32-
const list = Effect.fn("TaskTool.list")(function* (caller?: Tool.InitContext["agent"]) {
33-
const items = yield* agent.list().pipe(Effect.map((items) => items.filter((item) => item.mode !== "primary")))
34-
const filtered = caller
35-
? items.filter((item) => Permission.evaluate("task", item.name, caller.permission).action !== "deny")
36-
: items
37-
return filtered.toSorted((a, b) => a.name.localeCompare(b.name))
38-
})
39-
40-
const desc = Effect.fn("TaskTool.desc")(function* (caller?: Tool.InitContext["agent"]) {
41-
const items = yield* list(caller)
42-
return DESCRIPTION.replace(
43-
"{agents}",
44-
items
45-
.map(
46-
(item) =>
47-
`- ${item.name}: ${item.description ?? "This subagent should only be called manually by the user."}`,
48-
)
49-
.join("\n"),
50-
)
51-
})
52-
5332
const run = Effect.fn("TaskTool.execute")(function* (params: z.infer<typeof parameters>, ctx: Tool.Context) {
5433
const cfg = yield* config.get()
5534

@@ -184,7 +163,26 @@ export const TaskTool = Tool.defineEffect(
184163
})
185164

186165
return async (ctx) => {
187-
const description = await Effect.runPromise(desc(ctx?.agent))
166+
const caller = ctx?.agent
167+
const description = await Effect.runPromise(
168+
Effect.gen(function* () {
169+
const items = yield* agent.list().pipe(Effect.map((items) => items.filter((item) => item.mode !== "primary")))
170+
const filtered = caller
171+
? items.filter((item) => Permission.evaluate("task", item.name, caller.permission).action !== "deny")
172+
: items
173+
174+
return DESCRIPTION.replace(
175+
"{agents}",
176+
filtered
177+
.toSorted((a, b) => a.name.localeCompare(b.name))
178+
.map(
179+
(item) =>
180+
`- ${item.name}: ${item.description ?? "This subagent should only be called manually by the user."}`,
181+
)
182+
.join("\n"),
183+
)
184+
}),
185+
)
188186

189187
return {
190188
description,

0 commit comments

Comments
 (0)