Skip to content

Commit d2eb2a8

Browse files
committed
fix(oclite): fix regression - spinner, user display, help, MCP (#146)
- Add bootstrap spinner with elapsed time before Ink renders - Change version from 1.0 to 0.1 - Add user message display after submit (blue ❯ prefix) - Implement /help command with available commands list - Make MCP initialization non-blocking (lazy load) - Disable input during streaming to prevent race conditions
1 parent d07d9e8 commit d2eb2a8

15 files changed

Lines changed: 302 additions & 52 deletions

File tree

‎packages/opencode/src/cli/ink/App.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const App = (): ReactElement => {
8787
{/* Welcome message - always visible */}
8888
<Box marginBottom={1}>
8989
<Text color="cyan" bold>
90-
oclite v1.0
90+
oclite v0.1
9191
</Text>
9292
<Text dimColor> - Lightweight OpenCode TUI</Text>
9393
</Box>

‎packages/opencode/src/cli/ink/LiteApp.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const LiteApp = (): ReactElement => {
2525
{/* Header */}
2626
<Box marginBottom={1}>
2727
<Text color="cyan" bold>
28-
oclite v1.0
28+
oclite v0.1
2929
</Text>
3030
<Text dimColor> - Lightweight OpenCode TUI</Text>
3131
</Box>

‎packages/opencode/src/cli/ink/commands/handlers/agent.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ export async function agentHandler(args: string[], context: CommandContext): Pro
1313
return
1414
}
1515

16-
context.dispatch({
17-
type: "SET_SESSION",
18-
payload: {
19-
id: context.session.id ?? "default",
20-
agent: agentName,
21-
model: context.session.model,
22-
},
23-
})
16+
try {
17+
context.dispatch({
18+
type: "SET_SESSION",
19+
payload: {
20+
id: context.session.id || "default",
21+
agent: agentName,
22+
model: context.session.model,
23+
},
24+
})
25+
} catch (error) {
26+
console.error("Failed to set agent:", error)
27+
}
2428
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { CommandContext } from "../types"
22

3-
export async function compactHandler(_args: string[], _context: CommandContext): Promise<void> {
4-
// Compact mode toggle implementation pending
3+
export async function compactHandler(_args: string[], context: CommandContext): Promise<void> {
4+
try {
5+
context.dispatch({
6+
type: "STREAM_TEXT",
7+
payload: "\nCompact mode not yet implemented.\n\n",
8+
})
9+
} catch (error) {
10+
console.error("Failed to dispatch compact message:", error)
11+
}
512
}
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
import type { CommandContext } from "../types"
2+
import { getAllCommands } from "../registry"
23

3-
export async function helpHandler(_args: string[], _context: CommandContext): Promise<void> {
4-
// Help display implementation pending - requires UI component
4+
const MAX_COMMANDS = 100
5+
6+
export async function helpHandler(_args: string[], context: CommandContext): Promise<void> {
7+
const allCommands = getAllCommands()
8+
const commands = allCommands.slice(0, MAX_COMMANDS)
9+
10+
let helpText = "\nAvailable commands:\n\n"
11+
12+
for (const cmd of commands) {
13+
helpText += ` /${cmd.name.padEnd(12)} - ${cmd.description}\n`
14+
}
15+
16+
helpText += "\nKeyboard shortcuts:\n"
17+
helpText += " Ctrl+C - Exit\n"
18+
helpText += " Enter - Submit message\n"
19+
helpText += "\n"
20+
21+
try {
22+
context.dispatch({
23+
type: "STREAM_TEXT",
24+
payload: helpText,
25+
})
26+
} catch (error) {
27+
console.error("Failed to dispatch help text:", error)
28+
}
529
}

‎packages/opencode/src/cli/ink/commands/handlers/model.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ export async function modelHandler(args: string[], context: CommandContext): Pro
1313
return
1414
}
1515

16-
context.dispatch({
17-
type: "SET_SESSION",
18-
payload: {
19-
id: context.session.id ?? "default",
20-
agent: context.session.agent,
21-
model: modelName,
22-
},
23-
})
16+
try {
17+
context.dispatch({
18+
type: "SET_SESSION",
19+
payload: {
20+
id: context.session.id || "default",
21+
agent: context.session.agent,
22+
model: modelName,
23+
},
24+
})
25+
} catch (error) {
26+
console.error("Failed to set model:", error)
27+
}
2428
}

‎packages/opencode/src/cli/ink/commands/handlers/session.ts‎

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,61 @@ export async function sessionHandler(args: string[], context: CommandContext): P
1313
return
1414
}
1515

16-
context.dispatch({
17-
type: "SET_SESSION",
18-
payload: {
19-
id: sessionId,
20-
agent: context.session.agent,
21-
model: context.session.model,
22-
},
23-
})
16+
try {
17+
context.dispatch({
18+
type: "SET_SESSION",
19+
payload: {
20+
id: sessionId,
21+
agent: context.session.agent,
22+
model: context.session.model,
23+
},
24+
})
25+
} catch (error) {
26+
console.error("Failed to set session:", error)
27+
}
2428
}
2529

26-
export async function sessionsHandler(_args: string[], _context: CommandContext): Promise<void> {
27-
// Sessions list implementation pending
30+
export async function sessionsHandler(_args: string[], context: CommandContext): Promise<void> {
31+
const currentId = context.session.id || "(no session)"
32+
const helpText = `\nCurrent session: ${currentId}\n\nSession commands:\n /session <id> - Switch to session\n /new - Create new session\n\n`
33+
34+
try {
35+
context.dispatch({
36+
type: "STREAM_TEXT",
37+
payload: helpText,
38+
})
39+
} catch (error) {
40+
console.error("Failed to dispatch session info:", error)
41+
}
2842
}
2943

3044
export async function newSessionHandler(_args: string[], context: CommandContext): Promise<void> {
31-
const sessionId = crypto.randomUUID()
32-
context.dispatch({
33-
type: "SET_SESSION",
34-
payload: {
35-
id: sessionId,
36-
agent: context.session.agent,
37-
model: context.session.model,
38-
},
39-
})
45+
let sessionId: string
46+
try {
47+
sessionId = crypto.randomUUID()
48+
} catch (error) {
49+
console.error("Failed to generate session ID:", error)
50+
try {
51+
context.dispatch({
52+
type: "STREAM_TEXT",
53+
payload: "\nFailed to create session: crypto.randomUUID() unavailable\n\n",
54+
})
55+
} catch (dispatchError) {
56+
console.error("Failed to dispatch error message:", dispatchError)
57+
}
58+
return
59+
}
60+
61+
try {
62+
context.dispatch({
63+
type: "SET_SESSION",
64+
payload: {
65+
id: sessionId,
66+
agent: context.session.agent,
67+
model: context.session.model,
68+
},
69+
})
70+
} catch (error) {
71+
console.error("Failed to set new session:", error)
72+
}
4073
}

‎packages/opencode/src/cli/ink/commands/handlers/submodel.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ export async function submodelHandler(args: string[], context: CommandContext):
2929
return
3030
}
3131

32-
context.dispatch({
33-
type: "SET_SUBAGENT_MODEL",
34-
payload: modelName,
35-
})
32+
try {
33+
context.dispatch({
34+
type: "SET_SUBAGENT_MODEL",
35+
payload: modelName,
36+
})
37+
} catch (error) {
38+
console.error("Failed to set subagent model:", error)
39+
}
3640
}

‎packages/opencode/src/cli/ink/entry.ts‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { Instance } from "@/project/instance"
66
import { InstanceBootstrap } from "@/project/bootstrap"
77
import { Installation } from "@/installation"
88
import { startInkTUI } from "./index.tsx"
9+
import { createSpinner } from "./spinner"
10+
import { Provider } from "@/provider/provider"
11+
import { Agent } from "@/agent/agent"
912

1013
async function main() {
1114
try {
@@ -37,14 +40,37 @@ async function main() {
3740
})
3841
})
3942

43+
// Show spinner during bootstrap
44+
const spinner = createSpinner("Starting oclite...")
45+
4046
// Initialize Instance for SDK integration
41-
await Instance.provide({
42-
directory: process.cwd(),
43-
init: InstanceBootstrap,
44-
fn: async () => {
45-
await startInkTUI()
46-
},
47-
})
47+
try {
48+
await Instance.provide({
49+
directory: process.cwd(),
50+
init: InstanceBootstrap,
51+
fn: async () => {
52+
// ISSUE FIX #6: Add timeout to bootstrap
53+
const bootstrap = Promise.all([Provider.list(), Agent.list()])
54+
const timeout = new Promise((_, reject) => {
55+
setTimeout(() => reject(new Error("Bootstrap timeout after 30s")), 30000)
56+
})
57+
58+
// CRITICAL FIX #1: Error handling with timeout
59+
await Promise.race([bootstrap, timeout])
60+
61+
spinner.stop(true)
62+
63+
// CRITICAL FIX #2: Prevent race condition with stdout flush
64+
await new Promise((resolve) => setTimeout(resolve, 100))
65+
66+
await startInkTUI()
67+
},
68+
})
69+
} catch (error) {
70+
// CRITICAL FIX #1: Ensure cursor restoration on error
71+
spinner.stop(false)
72+
throw error
73+
}
4874
} catch (error) {
4975
console.error("Failed to start oclite:", error)
5076
process.exit(1)

‎packages/opencode/src/cli/ink/hooks/useSDKEvents.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export function useSDKEvents(sessionId: string | null, dispatch: Dispatch<Action
8585
streamingLockRef.current = true
8686

8787
dispatch({ type: "CLEAR_STREAMING" })
88+
dispatch({ type: "ADD_USER_MESSAGE", payload: content })
8889

8990
setIsStreaming(true)
9091

0 commit comments

Comments
 (0)