Skip to content

Commit 14244a5

Browse files
committed
fix(cli): oclite UX improvements — remove debug noise, compact tools, fix scroll and cursor safety (#62, #63, #64, #65, #66)
1 parent 082b8fc commit 14244a5

3 files changed

Lines changed: 83 additions & 89 deletions

File tree

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

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Spinner } from "./spinner"
55
import { chat, command } from "./session"
66
import { formatTokens, formatDuration } from "../metrics"
77
import { Icons } from "../cmd/tui/util/icons"
8-
import { renderTaskPanel, type Task, type AgentStatus } from "./taskpanel"
8+
import { type Task, type AgentStatus } from "./taskpanel"
99
import { renderStatusLine, type StatusLineState } from "./statusline"
10-
import { renderBottomBar, renderPrompt, type BottomBarState } from "./bottombar"
10+
import { renderPrompt, type BottomBarState } from "./bottombar"
1111
import { bootstrap } from "../bootstrap"
1212
import { Log } from "../../util/log"
1313
import { Global } from "../../global"
@@ -59,16 +59,26 @@ async function main() {
5959
level: "ERROR",
6060
})
6161

62+
// Cleanup function
63+
function cleanup() {
64+
write(cursor.show)
65+
process.stdin.setRawMode(false)
66+
}
67+
68+
// Register cleanup before bootstrap
69+
process.on("exit", cleanup)
70+
process.on("SIGINT", () => {
71+
cleanup()
72+
process.exit(0)
73+
})
74+
6275
// Bootstrap with Instance context for current directory
6376
await bootstrap(process.cwd(), async () => {
6477
// Initialize default agent
6578
currentAgent = await Agent.defaultAgent()
6679
const agentList = await Agent.list()
6780

6881
// Setup
69-
write(screen.alt)
70-
write(clear.screen)
71-
write(cursor.home)
7282

7383
// Header
7484
write(`${fg.brightCyan}${style.bold}oclite${style.reset} ${fg.gray}v0.1.0${style.reset}\n`)
@@ -115,6 +125,11 @@ async function main() {
115125
return
116126
}
117127

128+
// Block further input during operation (except Escape and Ctrl+C which are handled above)
129+
if (isOperationInProgress) {
130+
return
131+
}
132+
118133
// Ctrl+T to toggle task panel
119134
if (key.ctrl && key.name === "t") {
120135
tasksVisible = !tasksVisible
@@ -138,19 +153,6 @@ async function main() {
138153
editor.render(renderPrompt(currentAgent))
139154
}
140155
})
141-
142-
// Cleanup on exit
143-
function cleanup() {
144-
write(cursor.show)
145-
write(screen.main)
146-
process.stdin.setRawMode(false)
147-
}
148-
149-
process.on("exit", cleanup)
150-
process.on("SIGINT", () => {
151-
cleanup()
152-
process.exit(0)
153-
})
154156
})
155157
}
156158

@@ -357,55 +359,52 @@ async function handleCustomCommand(name: string, args: string) {
357359
isOperationInProgress = true
358360

359361
try {
360-
process.stderr.write(`[DEBUG] handleCustomCommand: Starting with name="${name}", args="${args}"\n`)
361362
const options = {
362363
model: currentModel || undefined,
363364
agent: currentAgent,
364365
sessionID: currentSessionID || undefined,
365366
}
366367

367-
process.stderr.write(`[DEBUG] handleCustomCommand: Created options, starting iteration\n`)
368-
for await (const chunk of command(name, args, options)) {
369-
process.stderr.write(`[DEBUG] handleCustomCommand: Received chunk type="${chunk.type}"\n`)
370-
if (chunk.type === "start" && chunk.sessionID && !currentSessionID) {
371-
currentSessionID = chunk.sessionID
372-
}
368+
try {
369+
for await (const chunk of command(name, args, options)) {
370+
if (chunk.type === "start" && chunk.sessionID && !currentSessionID) {
371+
currentSessionID = chunk.sessionID
372+
}
373373

374-
if (first && chunk.type !== "done" && chunk.type !== "start") {
375-
spinner.stop(true)
376-
first = false
377-
write(`${fg.gray}(Esc to cancel)${style.reset}\n`)
378-
}
374+
if (first && chunk.type !== "done" && chunk.type !== "start") {
375+
spinner.stop(true)
376+
first = false
377+
write(`${fg.gray}(Esc to cancel)${style.reset}\n`)
378+
}
379379

380-
if (chunk.type === "text" && chunk.content) {
381-
write(chunk.content)
382-
}
380+
if (chunk.type === "text" && chunk.content) {
381+
write(chunk.content)
382+
}
383383

384-
if (chunk.type === "tool_start" && chunk.tool?.trim()) {
385-
write(`\n${Icons.taskIcon("progress")} ${chunk.tool}\n`)
386-
}
384+
if (chunk.type === "tool_start" && chunk.tool?.trim()) {
385+
write(`${fg.gray}${chunk.tool?.trim()} ${style.reset}`)
386+
}
387387

388-
if (chunk.type === "tool_end" && chunk.tool?.trim()) {
389-
write(`${Icons.taskIcon("completed")} ${chunk.tool}\n`)
390-
}
388+
if (chunk.type === "tool_end" && chunk.tool?.trim()) {
389+
write(`${fg.gray}✓${style.reset} `)
390+
}
391391

392-
if (chunk.type === "error" && chunk.content) {
393-
const safeContent = chunk.content.replace(/\x1b\[[0-9;]*m/g, "").replace(/[\x00-\x1f\x7f]/g, "")
394-
write(`\n${fg.red}Error: ${safeContent}${style.reset}\n`)
395-
}
392+
if (chunk.type === "error" && chunk.content) {
393+
const safeContent = chunk.content.replace(/\x1b\[[0-9;]*m/g, "").replace(/[\x00-\x1f\x7f]/g, "")
394+
write(`\n${fg.red}Error: ${safeContent}${style.reset}\n`)
395+
}
396396

397-
if (chunk.tokens !== undefined) {
398-
totalTokens += chunk.tokens
397+
if (chunk.tokens !== undefined) {
398+
totalTokens += chunk.tokens
399+
}
399400
}
400-
}
401401

402-
process.stderr.write(`[DEBUG] handleCustomCommand: Iteration complete\n`)
403-
const duration = Date.now() - startTime
404-
write(`\n${fg.gray}${formatDuration(duration)} · ${formatTokens(totalTokens)}${style.reset}\n`)
402+
const duration = Date.now() - startTime
403+
write(`\n${fg.gray}${formatDuration(duration)} · ${formatTokens(totalTokens)}${style.reset}\n`)
404+
} finally {
405+
write(cursor.show)
406+
}
405407
} catch (err) {
406-
process.stderr.write(
407-
`[DEBUG] handleCustomCommand: Caught error: ${err instanceof Error ? err.message : String(err)}\n`,
408-
)
409408
if (first) spinner.stop(false)
410409
const msg = err instanceof Error ? err.message : String(err)
411410
write(`\n${fg.red}Error: ${msg}${style.reset}\n`)
@@ -433,42 +432,45 @@ async function handleMessage(message: string) {
433432
sessionID: currentSessionID || undefined,
434433
}
435434

436-
for await (const chunk of chat(message, options)) {
437-
// Capture sessionID from start chunk for cancellation
438-
if (chunk.type === "start" && chunk.sessionID && !currentSessionID) {
439-
currentSessionID = chunk.sessionID
440-
}
435+
try {
436+
for await (const chunk of chat(message, options)) {
437+
if (chunk.type === "start" && chunk.sessionID && !currentSessionID) {
438+
currentSessionID = chunk.sessionID
439+
}
441440

442-
if (first && chunk.type !== "done" && chunk.type !== "start") {
443-
spinner.stop(true)
444-
first = false
445-
write(`${fg.gray}(Esc to cancel)${style.reset}\n`)
446-
}
441+
if (first && chunk.type !== "done" && chunk.type !== "start") {
442+
spinner.stop(true)
443+
first = false
444+
write(`${fg.gray}(Esc to cancel)${style.reset}\n`)
445+
}
447446

448-
if (chunk.type === "text" && chunk.content) {
449-
write(chunk.content)
450-
}
447+
if (chunk.type === "text" && chunk.content) {
448+
write(chunk.content)
449+
}
451450

452-
if (chunk.type === "tool_start" && chunk.tool?.trim()) {
453-
write(`\n${Icons.taskIcon("progress")} ${chunk.tool}\n`)
454-
}
451+
if (chunk.type === "tool_start" && chunk.tool?.trim()) {
452+
write(`${fg.gray}${chunk.tool?.trim()} ${style.reset}`)
453+
}
455454

456-
if (chunk.type === "tool_end" && chunk.tool?.trim()) {
457-
write(`${Icons.taskIcon("completed")} ${chunk.tool}\n`)
458-
}
455+
if (chunk.type === "tool_end" && chunk.tool?.trim()) {
456+
write(`${fg.gray}✓${style.reset} `)
457+
}
459458

460-
if (chunk.type === "error" && chunk.content) {
461-
const safeContent = chunk.content.replace(/\x1b\[[0-9;]*m/g, "").replace(/[\x00-\x1f\x7f]/g, "")
462-
write(`\n${fg.red}Error: ${safeContent}${style.reset}\n`)
463-
}
459+
if (chunk.type === "error" && chunk.content) {
460+
const safeContent = chunk.content.replace(/\x1b\[[0-9;]*m/g, "").replace(/[\x00-\x1f\x7f]/g, "")
461+
write(`\n${fg.red}Error: ${safeContent}${style.reset}\n`)
462+
}
464463

465-
if (chunk.tokens !== undefined) {
466-
totalTokens += chunk.tokens
464+
if (chunk.tokens !== undefined) {
465+
totalTokens += chunk.tokens
466+
}
467467
}
468-
}
469468

470-
const duration = Date.now() - startTime
471-
write(`\n${fg.gray}${formatDuration(duration)} · ${formatTokens(totalTokens)}${style.reset}\n`)
469+
const duration = Date.now() - startTime
470+
write(`\n${fg.gray}${formatDuration(duration)} · ${formatTokens(totalTokens)}${style.reset}\n`)
471+
} finally {
472+
write(cursor.show)
473+
}
472474
} catch (err) {
473475
if (first) spinner.stop(false)
474476
const msg = err instanceof Error ? err.message : String(err)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,10 @@ export async function* command(cmd: string, args: string, options?: ChatOptions)
221221
arguments: args,
222222
})
223223
.then(() => {
224-
process.stderr.write(`[DEBUG] SessionPrompt.command() succeeded\n`)
225224
promptDone = true
226225
wake()
227226
})
228227
.catch((err) => {
229-
process.stderr.write(
230-
`[DEBUG] SessionPrompt.command() caught error: ${err instanceof Error ? err.message : String(err)}\n`,
231-
)
232228
error = err
233229
promptDone = true
234230
cancelled = true
@@ -254,9 +250,6 @@ export async function* command(cmd: string, args: string, options?: ChatOptions)
254250
try {
255251
await promptPromise
256252
} catch (err) {
257-
process.stderr.write(
258-
`[DEBUG] await promptPromise threw (should not happen): ${err instanceof Error ? err.message : String(err)}\n`,
259-
)
260253
error = err
261254
}
262255

@@ -273,7 +266,6 @@ export async function* command(cmd: string, args: string, options?: ChatOptions)
273266
}
274267
} catch (err) {
275268
const errorMessage = err instanceof Error ? err.message : String(err)
276-
process.stderr.write(`[DEBUG] Unhandled error in command generator: ${errorMessage}\n`)
277269
log.error("command error", { error: errorMessage, sessionID })
278270
yield { type: "error", content: errorMessage, sessionID }
279271
} finally {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Spinner {
1616
this.interval = setInterval(() => {
1717
this.frame = (this.frame + 1) % frames.length
1818
write(`\r${clear.line}${fg.cyan}${frames[this.frame]}${style.reset} ${fg.gray}${this.text}${style.reset}`)
19-
}, 80)
19+
}, 50)
2020
}
2121

2222
update(text: string) {

0 commit comments

Comments
 (0)