feat(plugin): add tool progress reporting · argszero/opencode@915be9b · GitHub
Skip to content

Commit 915be9b

Browse files
committed
feat(plugin): add tool progress reporting
1 parent 6039f54 commit 915be9b

36 files changed

Lines changed: 196 additions & 92 deletions

packages/core/src/plugin/host.ts

Lines changed: 4 additions & 4 deletions

packages/core/src/plugin/promise.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,22 @@ function fromPromiseTool(tool: AnyTool) {
256256
if ("jsonSchema" in tool)
257257
return Tool.make({
258258
...tool,
259-
execute: (input, context) => Effect.promise(() => tool.execute(input, context)),
259+
execute: (input, context) =>
260+
Effect.promise(() =>
261+
tool.execute(input, {
262+
...context,
263+
progress: (update) => Effect.runPromise(context.progress(update)),
264+
}),
265+
),
260266
})
261267
return Tool.make({
262268
...tool,
263-
execute: (input, context) => Effect.promise(() => tool.execute(input, context)),
269+
execute: (input, context) =>
270+
Effect.promise(() =>
271+
tool.execute(input, {
272+
...context,
273+
progress: (update) => Effect.runPromise(context.progress(update)),
274+
}),
275+
),
264276
})
265277
}

packages/core/src/session/runner/llm.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,18 @@ const layer = Layer.effect(
265265
toolMaterialization.settle({
266266
sessionID: session.id,
267267
agent: agent.id,
268-
assistantMessageID,
268+
messageID: assistantMessageID,
269269
call: event,
270+
progress: (update) =>
271+
serialized(
272+
events.publish(SessionEvent.Tool.Progress, {
273+
sessionID: session.id,
274+
assistantMessageID,
275+
callID: event.id,
276+
structured: { ...update.structured },
277+
content: [...update.content],
278+
}),
279+
),
270280
}),
271281
).pipe(
272282
Effect.flatMap((settlement) =>

packages/core/src/tool-output-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const MANAGED_DIRECTORY = "tool-output"
1818

1919
export interface BoundInput {
2020
readonly sessionID: SessionSchema.ID
21-
readonly toolCallID: string
21+
readonly callID: string
2222
readonly output: ToolOutput
2323
}
2424

packages/core/src/tool/edit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const Plugin = {
122122
return Effect.gen(function* () {
123123
const permissionSource = {
124124
type: "tool" as const,
125-
messageID: context.assistantMessageID,
126-
callID: context.toolCallID,
125+
messageID: context.messageID,
126+
callID: context.callID,
127127
}
128128
if (input.oldString === input.newString) {
129129
return yield* new ToolFailure({

packages/core/src/tool/execute.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ export const create = (registrations: ReadonlyMap<string, Registration>) => {
113113
const index = yield* Ref.getAndUpdate(callIndex, (index) => index + 1)
114114
const output = yield* settle(
115115
registration.tool,
116-
{ type: "tool-call", id: context.toolCallID, name, input },
116+
{ type: "tool-call", id: context.callID, name, input },
117117
{
118118
sessionID: context.sessionID,
119119
agent: context.agent,
120-
assistantMessageID: context.assistantMessageID,
121-
toolCallID: context.toolCallID,
120+
messageID: context.messageID,
121+
callID: context.callID,
122+
progress: context.progress,
122123
},
123124
).pipe(Effect.mapError((failure) => toolError(failure.message, failure)))
124125
const outputFileParts = outputFiles(output)

packages/core/src/tool/glob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const Plugin = {
7272
},
7373
sessionID: context.sessionID,
7474
agent: context.agent,
75-
source: { type: "tool", messageID: context.assistantMessageID, callID: context.toolCallID },
75+
source: { type: "tool", messageID: context.messageID, callID: context.callID },
7676
})
7777
const cwd = path.resolve(location.directory, input.path ?? ".")
7878
yield* fs

packages/core/src/tool/grep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const Plugin = {
9090
},
9191
sessionID: context.sessionID,
9292
agent: context.agent,
93-
source: { type: "tool", messageID: context.assistantMessageID, callID: context.toolCallID },
93+
source: { type: "tool", messageID: context.messageID, callID: context.callID },
9494
})
9595
const target = path.resolve(location.directory, input.path ?? ".")
9696
const info = yield* fs

packages/core/src/tool/hooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export interface BeforeEvent {
1212
readonly tool: string
1313
readonly sessionID: Session.ID
1414
readonly agent: Agent.ID
15-
readonly assistantMessageID: SessionMessage.ID
16-
readonly toolCallID: string
15+
readonly messageID: SessionMessage.ID
16+
readonly callID: string
1717
input: unknown
1818
}
1919

2020
export interface AfterEvent {
2121
readonly tool: string
2222
readonly sessionID: Session.ID
2323
readonly agent: Agent.ID
24-
readonly assistantMessageID: SessionMessage.ID
25-
readonly toolCallID: string
24+
readonly messageID: SessionMessage.ID
25+
readonly callID: string
2626
readonly input: unknown
2727
result: ToolResultValue
2828
output?: ToolOutput

packages/core/src/tool/mcp.ts

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)