diff options
| author | Kit Langton <[email protected]> | 2026-04-10 23:18:30 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-10 23:18:30 -0400 |
| commit | 4341ab838e3494b5d640780b1c59d6305aa59e95 (patch) | |
| tree | 99b8ef6ca3faae42826047367722243badfdd3ff | |
| parent | cd004cf0b28aa49344da2d5947a78703d30bcaf1 (diff) | |
| download | opencode-4341ab838e3494b5d640780b1c59d6305aa59e95.tar.gz opencode-4341ab838e3494b5d640780b1c59d6305aa59e95.zip | |
refactor(tool): use Session.Service directly in TaskTool (#21975)
| -rw-r--r-- | packages/opencode/src/tool/task.ts | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts index d0eaaf6f2..4e176391c 100644 --- a/packages/opencode/src/tool/task.ts +++ b/packages/opencode/src/tool/task.ts @@ -36,6 +36,7 @@ export const TaskTool = Tool.define( Effect.gen(function* () { const agent = yield* Agent.Service const config = yield* Config.Service + const sessions = yield* Session.Service const run = Effect.fn("TaskTool.execute")(function* (params: z.infer<typeof parameters>, ctx: Tool.Context) { const cfg = yield* config.get() @@ -62,44 +63,41 @@ export const TaskTool = Tool.define( const taskID = params.task_id const session = taskID - ? yield* Effect.promise(() => { - const id = SessionID.make(taskID) - return Session.get(id).catch(() => undefined) - }) + ? yield* sessions.get(SessionID.make(taskID)).pipe( + Effect.catchCause(() => Effect.succeed(undefined)), + ) : undefined const nextSession = session ?? - (yield* Effect.promise(() => - Session.create({ - parentID: ctx.sessionID, - title: params.description + ` (@${next.name} subagent)`, - permission: [ - ...(canTodo - ? [] - : [ - { - permission: "todowrite" as const, - pattern: "*" as const, - action: "deny" as const, - }, - ]), - ...(canTask - ? [] - : [ - { - permission: id, - pattern: "*" as const, - action: "deny" as const, - }, - ]), - ...(cfg.experimental?.primary_tools?.map((item) => ({ - pattern: "*", - action: "allow" as const, - permission: item, - })) ?? []), - ], - }), - )) + (yield* sessions.create({ + parentID: ctx.sessionID, + title: params.description + ` (@${next.name} subagent)`, + permission: [ + ...(canTodo + ? [] + : [ + { + permission: "todowrite" as const, + pattern: "*" as const, + action: "deny" as const, + }, + ]), + ...(canTask + ? [] + : [ + { + permission: id, + pattern: "*" as const, + action: "deny" as const, + }, + ]), + ...(cfg.experimental?.primary_tools?.map((item) => ({ + pattern: "*", + action: "allow" as const, + permission: item, + })) ?? []), + ], + })) const msg = yield* Effect.sync(() => MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID })) if (msg.info.role !== "assistant") return yield* Effect.fail(new Error("Not an assistant message")) |
