Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Closed
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
7 changes: 7 additions & 0 deletions packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export namespace SessionProcessor {
let attempt = 0
let needsCompaction = false
let stepStart = 0 // kilocode_change
let shouldStopAfterTool = false

const result = {
get message() {
Expand Down Expand Up @@ -190,6 +191,10 @@ export namespace SessionProcessor {
},
})

if (value.output.metadata?.stop === true) {
shouldStopAfterTool = true
}

delete toolcalls[value.toolCallId]
}
break
Expand Down Expand Up @@ -358,6 +363,7 @@ export namespace SessionProcessor {
continue
}
if (needsCompaction) break
if (shouldStopAfterTool) break
}
} catch (e: any) {
log.error("process", {
Expand Down Expand Up @@ -424,6 +430,7 @@ export namespace SessionProcessor {
if (needsCompaction) return "compact"
if (blocked) return "stop"
if (input.assistantMessage.error) return "stop"
if (shouldStopAfterTool) return "stop"
return "continue"
}
},
Expand Down
22 changes: 18 additions & 4 deletions packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,25 @@ export namespace ToolRegistry {
worktree: Instance.worktree,
} as unknown as PluginToolContext
const result = await def.execute(args as any, pluginCtx)
const out = await Truncate.output(result, {}, initCtx?.agent)
if (typeof result === "string") {
const out = await Truncate.output(result, {}, initCtx?.agent)
return {
title: id,
output: out.truncated ? out.content : result,
metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
}
}
if (typeof result !== "object" || result === null || !("output" in result))
throw new Error(`Tool ${id} returned unexpected value: ${typeof result}`)
const out = await Truncate.output(result.output, {}, initCtx?.agent)
return {
title: "",
output: out.truncated ? out.content : result,
metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
title: result.title ?? id,
output: out.truncated ? out.content : result.output,
metadata: {
...(result.metadata ?? {}),
truncated: out.truncated,
outputPath: out.truncated ? out.outputPath : undefined,
},
}
},
}),
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ type AskInput = {
metadata: { [key: string]: any }
}

export type ToolResult = string | { title?: string; output: string; metadata?: Record<string, any> }

export function tool<Args extends z.ZodRawShape>(input: {
description: string
args: Args
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
}) {
return input
}
Expand Down
Loading