This guide documents the migration from the legacy OpenCode integration to the new Pi-based agent framework. It is intended for maintainers, reviewers, and anyone working on the TUI codebase.
The TUI previously relied on an OpenCode client for agent interactions (natural language chat, action palette, and agent-driven flows). This has been replaced with the Pi framework, which provides:
- PiAdapter (
src/tui/pi-adapter.ts): The core abstraction replacingOpencodeClient. Provides a clean interface for agent backend communication. - ChatPane (
src/tui/chatPane.ts): A natural language chat interface with keyword-based routing forwlcommands (list, next, show, create, update, close, search, claim). - ActionPalette (
src/tui/actionPalette.ts): A keyboard-first action palette with default actions mapping towlCLI commands. - wl CLI Integration (
src/tui/wl-integration.ts,src/wl-integration/spawn.ts): All work item reads/writes now go through thewlCLI viachild_process.spawn, not direct database access.
docs/opencode-tui.md— legacy OpenCode TUI documentationtests/tui/opencode-triple-keypress.repro.test.ts— reproduction test for OpenCode textarea bugtest/tui-opencode-integration.test.ts— OpenCode integration test suite.opencode/— local OpenCode development directory and its dependenciesdist/opencode-*— compiled OpenCode artifacts (cleaned on rebuild)
opencode-client.ts→pi-adapter.tsopencode-autocomplete.ts→command-autocomplete.tsopencode-sse.ts→ removed (replaced with Pi event handling)opencode-pane.ts→ removed (replaced with ChatPane)
src/tui/controller.ts— replacedOpencodeClientwithPiAdapter, updated key handlerssrc/tui/constants.ts— updated key descriptions and referencessrc/tui/pi-adapter.ts— new PiAdapter implementationsrc/tui/chatPane.ts— new ChatPane componentsrc/tui/actionPalette.ts— new ActionPalette componentREADME.md— added references to Pi agent featuresdocs/tutorials/04-using-the-tui.md— updated tutorial with Pi agent chat and action palette
test/tui-integration.test.ts— still references old dialog labels; needs reviewsrc/pi-audit.ts— contains comments referencing opencode audit; useswlCLI now
Before:
import { OpencodeClient } from './opencode-client.js';After:
import { PiAdapter } from './pi-adapter.js';Before:
const client = new OpencodeClient(port);
client.startServer();
const response = await client.sendPrompt(message);After:
const adapter = new PiAdapter();
await adapter.initialize();
const response = await adapter.sendMessage(message);Before (direct DB access):
const items = db.list({ status: 'open' });
const item = db.get(id);
db.update(id, { status: 'in-progress' });After (wl CLI):
import { runWl } from './wl-integration.js';
const items = await runWl('list', ['--status', 'open']);
const item = await runWl('show', [id]);
await runWl('update', [id, '--status', 'in-progress']);The O key opens the agent chat pane (was "Open OpenCode prompt"). The A key runs the Pi audit (was "Run audit via OpenCode").
npm testAll 157+ tests should pass. Tests that previously depended on OpencodeClient have been migrated to use PiAdapter mocks or runWl wrappers.
E2E tests for agent-driven flows are in tests/e2e/agent-flow.test.ts. They use mocked child_process.spawn for CI safety.
npx vitest run tests/e2e/agent-flow.test.tsA: The Pi framework provides a more robust, extensible, and well-documented agent integration. It eliminates the dependency on a separate OpenCode server process and simplifies the TUI architecture.
A: No. The OpenCode integration has been fully replaced. If you have specific workflows that relied on OpenCode features, please file a feature request to add them via the Pi framework.
A: Yes. The test file test/tui-integration.test.ts still references the old dialog labels. These tests may need updating to reflect the new Pi agent labels.
A: The PiAdapter uses the standard Pi framework configuration. Check the Pi documentation for agent configuration options.
- Pi TUI Design Checklist
- TUI.md — TUI controls and usage
- wl CLI Integration API
- Pi Adapter — source code