The Worklog TUI now includes full integration with OpenCode, an AI-powered coding assistant. This integration allows you to interact with OpenCode directly from the TUI, with support for real-time streaming responses, session persistence, and interactive user input.
- Press
oorOfrom anywhere in the TUI to open the OpenCode dialog - The dialog provides a text area for entering prompts and commands
- The OpenCode server automatically starts when you open the dialog
- Server status is displayed in the dialog header:
[-]- Server stopped[~]- Server starting[OK] Port: 51625- Server running[X]- Server error
- Default port: Let OpenCode choose (override with
OPENCODE_SERVER_PORT)
- Type
/to see available slash commands - 28 commands available including:
/help- Get help/edit- Edit files/create- Create new files/test- Run tests/fix- Fix issues- And many more...
- Autocomplete suggestions appear below the input with an arrow indicator (↳) and a
[Tab]hint - The input dialog grows by one row to accommodate the suggestion hint
- Press Tab to accept the suggestion (inserts the command with a trailing space)
- The dialog shrinks back to its normal size when the suggestion is cleared
- Autocomplete only triggers on single-line input starting with
/ - Exact command matches do not show a suggestion
The autocomplete logic is extracted into src/tui/opencode-autocomplete.ts as a
standalone, testable module. The controller wires it to the textarea and
suggestion hint widget at startup via initAutocomplete(). Key integration
points:
onSuggestionChangecallback — fires when a suggestion appears or disappears, triggeringupdateOpencodeInputLayout()to resize the dialog.applyOpencodeCompactLayout()— dynamically repositions the suggestion hint below the textarea and adds an extra row to the dialog when a suggestion is active.renderSuggestion()— callsshow()/hide()on the hint widget so blessed renders it correctly in compact mode.
- Sessions persist across multiple prompts
- Each TUI session maintains its own OpenCode conversation context
- Session ID is displayed at the start of each response
- Responses stream in real-time using Server-Sent Events (SSE)
- See text as it's generated
- Tool usage is highlighted in yellow
- Tool results shown in green
- When OpenCode needs user input, an input field appears automatically
- Input types are clearly labeled:
- "Yes/No Input" for boolean questions
- "Password Input" for sensitive data
- "Input Required" for general text
- User responses are shown in cyan in the conversation
- Press Escape to cancel input mode
- Prefix a prompt with
!to run a local shell command in the project root - Output streams directly into the response pane as raw stdout/stderr
- The command displays in orange and output in white
- Press
Ctrl+Cwhile the prompt is focused to cancel a running shell command
- The prompt input box grows as long lines wrap within the terminal
- Auto-resize caps at a maximum height; beyond that, the input scrolls
- Manual resize via
Ctrl+Enterstill works when adding explicit newlines
- Press
oto open the OpenCode dialog - Wait for the server status to show
[OK](server health uses/global/health) - Type your prompt or slash command
- Press
Ctrl+Sto send (or click the Send button) - The response will appear in a pane at the bottom of the screen
-
In the dialog:
Ctrl+S- Send promptTab- Accept autocomplete suggestionEnter- Send promptEscape- Close dialogCtrl+C- Cancel running!command
-
In the response pane:
- Arrow keys or vim keys (
j/k) - Scroll through response qorEscape- Close pane- Click
[x]in top-right to close
- Arrow keys or vim keys (
-
When input is required:
- Type your response
Enter- Submit inputEscape- Cancel input
What is the purpose of this repository?
/edit src/commands/tui.ts
Add a comment explaining the openOpencodeDialog function
Review the following code and suggest improvements:
[paste code]
Focus on performance and readability.
OPENCODE_SERVER_PORT- Override the server port (if unset, OpenCode chooses)
Note: Worklog’s OpenCode client does not currently attach auth headers, so enabling OpenCode server auth will likely prevent the TUI from connecting.
The server is managed automatically, but you can also:
- Start manually:
opencode serve --port $OPENCODE_SERVER_PORT - Check if running:
lsof -i :$OPENCODE_SERVER_PORT - View server API docs:
http://localhost:$OPENCODE_SERVER_PORT/doc
- Uses OpenCode's HTTP API for session and message management
- Endpoints used:
POST /session- Create new sessionPOST /session/{id}/prompt_async- Send promptsGET /event- SSE stream for responsesPOST /session/{id}/input- Send user input
- Server starts automatically when opening dialog (API-only mode)
- Connection errors displayed in red
- Graceful degradation for network issues
- TUI controller:
src/tui/controller.ts - OpenCode pane component:
src/tui/components/opencode-pane.ts - Autocomplete module:
src/tui/opencode-autocomplete.ts - Constants (commands, layout):
src/tui/constants.ts - OpenCode client:
src/tui/opencode-client.ts - Integration tests:
tests/tui/opencode-integration.test.ts - Autocomplete unit tests:
tests/tui/autocomplete.test.ts - Widget integration tests:
tests/tui/autocomplete-widget.test.ts - Layout integration tests:
tests/tui/opencode-layout-integration.test.ts
- Check if port 51625 is already in use:
lsof -i :51625 - Try a different port:
export OPENCODE_SERVER_PORT=4096 - Ensure OpenCode is installed:
which opencode
- Check server status indicator in dialog header
- Verify server is running:
ps aux | grep "opencode serve" - Check for errors in response pane
- Ensure the input field is focused (green border)
- Check that server connection is active
- Try reopening the OpenCode dialog
- Sessions are maintained per TUI instance
- Restarting TUI will create a new session
- Previous conversations are not persisted to disk
# Run the test script
./test-tui.sh
# Test input simulation
./test-input.shnpm run build
npm test- Server logs: The server runs with stdio inherited
- Check response pane for error messages
- Use
curlto test server endpoints directly
Planned improvements include:
- Session history and persistence
- Multiple concurrent sessions
- File upload support
- Custom themes for responses
- Export conversation to markdown
- Integration with work item context
- WL-0MKW7SLB30BFCL5O - Epic: OpenCode server + interactive 'O' pane
- WL-0MKW1GUSC1DSWYGS - Slash command autocomplete
- WL-0MKWCW9K610XPQ1P - Auto-start OpenCode server
- WL-0MKWCQQIW0ZP4A67 - Send prompts to server
- WL-0MKWE048418NPBKL - Enable user input for agents
For more information about OpenCode, visit: https://opencode.ai/docs/
!ls