Skip to content

Commit 1fef395

Browse files
committed
fix(cli): pass input in tool_end chunks and simplify overwrite logic (#81)
1 parent a0338d1 commit 1fef395

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎packages/opencode/src/cli/lite/index.ts‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ async function handleCustomCommand(name: string, args: string) {
383383
const startTime = Date.now()
384384
isOperationInProgress = true
385385
let lastChunkWasToolStart = false
386-
let lastToolSummary = ""
387386
let lastChunkType: string | null = null
388387
let lastToolName = ""
389388
let lastToolArg = ""
@@ -445,7 +444,6 @@ async function handleCustomCommand(name: string, args: string) {
445444
write(`${display}\n`)
446445
}
447446

448-
lastToolSummary = arg
449447
lastChunkWasToolStart = true
450448
lastChunkType = "tool"
451449
}
@@ -454,15 +452,14 @@ async function handleCustomCommand(name: string, args: string) {
454452
const tool = chunk.tool.trim()
455453
const arg = summarizeInput(tool, chunk.input)
456454
const cols = process.stdout.columns || 80
455+
const summary = arg ? ` ${arg}` : ""
456+
const line = `${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}${fg.gray}${summary}${style.reset}`
457+
const display = line.length > cols ? line.slice(0, cols - 1) + "…" : line
457458

458-
if (lastChunkWasToolStart && lastToolSummary === arg) {
459-
const count = repeatCount + 1
460-
const countText = count > 1 ? ` (×${count})` : ""
461-
const line = `${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}${fg.gray}${arg ? ` ${arg}` : ""}${countText}${style.reset}`
462-
const display = line.length > cols ? line.slice(0, cols - 1) + "…" : line
459+
if (lastChunkType === "tool") {
463460
write(`\x1b[1A\r\x1b[2K${display}\n`)
464461
} else {
465-
write(`${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}\n`)
462+
write(`${display}\n`)
466463
}
467464

468465
lastChunkWasToolStart = false
@@ -509,7 +506,6 @@ async function handleMessage(message: string) {
509506
const startTime = Date.now()
510507
isOperationInProgress = true
511508
let lastChunkWasToolStart = false
512-
let lastToolSummary = ""
513509
let lastChunkType: string | null = null
514510
let lastToolName = ""
515511
let lastToolArg = ""
@@ -571,7 +567,6 @@ async function handleMessage(message: string) {
571567
write(`${display}\n`)
572568
}
573569

574-
lastToolSummary = arg
575570
lastChunkWasToolStart = true
576571
lastChunkType = "tool"
577572
}
@@ -580,15 +575,14 @@ async function handleMessage(message: string) {
580575
const tool = chunk.tool.trim()
581576
const arg = summarizeInput(tool, chunk.input)
582577
const cols = process.stdout.columns || 80
578+
const summary = arg ? ` ${arg}` : ""
579+
const line = `${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}${fg.gray}${summary}${style.reset}`
580+
const display = line.length > cols ? line.slice(0, cols - 1) + "…" : line
583581

584-
if (lastChunkWasToolStart && lastToolSummary === arg) {
585-
const count = repeatCount + 1
586-
const countText = count > 1 ? ` (×${count})` : ""
587-
const line = `${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}${fg.gray}${arg ? ` ${arg}` : ""}${countText}${style.reset}`
588-
const display = line.length > cols ? line.slice(0, cols - 1) + "…" : line
582+
if (lastChunkType === "tool") {
589583
write(`\x1b[1A\r\x1b[2K${display}\n`)
590584
} else {
591-
write(`${fg.green}✓${style.reset} ${fg.cyan}${tool}${style.reset}\n`)
585+
write(`${display}\n`)
592586
}
593587

594588
lastChunkWasToolStart = false

‎packages/opencode/src/cli/lite/session.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ export async function* chat(message: string, options?: ChatOptions): AsyncGenera
6565
if (part.state.status === "running") {
6666
chunks.push({ type: "tool_start", tool: part.tool, input: part.state.input, sessionID })
6767
} else if (part.state.status === "completed") {
68-
chunks.push({ type: "tool_end", tool: part.tool, output: part.state.output, sessionID })
68+
chunks.push({
69+
type: "tool_end",
70+
tool: part.tool,
71+
input: part.state.input,
72+
output: part.state.output,
73+
sessionID,
74+
})
6975
}
7076
wake()
7177
} else if (part.type === "step-finish") {
@@ -197,7 +203,13 @@ export async function* command(cmd: string, args: string, options?: ChatOptions)
197203
if (part.state.status === "running") {
198204
chunks.push({ type: "tool_start", tool: part.tool, input: part.state.input, sessionID })
199205
} else if (part.state.status === "completed") {
200-
chunks.push({ type: "tool_end", tool: part.tool, output: part.state.output, sessionID })
206+
chunks.push({
207+
type: "tool_end",
208+
tool: part.tool,
209+
input: part.state.input,
210+
output: part.state.output,
211+
sessionID,
212+
})
201213
}
202214
wake()
203215
} else if (part.type === "step-finish") {

0 commit comments

Comments
 (0)