Skip to content

Commit b0aee51

Browse files
committed
feat(opencode): implement Ink TUI foundation (anomalyco#11763, anomalyco#11764, anomalyco#11766, anomalyco#11767, anomalyco#11776)
Phase 1 of Ink-based TUI rewrite: - Setup Ink/React dependencies with SolidJS coexistence - Theme system with consistent color tokens - App component with useReducer state management - ToolDisplay and TaskDisplay components - Comprehensive TDD test coverage (57 tests) All tests pass, typecheck clean. Fixes anomalyco#11763 Fixes anomalyco#11764 Fixes anomalyco#11766 Fixes anomalyco#11767 Fixes anomalyco#11776
1 parent 4c3fd85 commit b0aee51

24 files changed

Lines changed: 1264 additions & 55 deletions

‎AGENTS.md‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,39 @@ git add . && git commit -m "feat(opencode): implement feature (#123)"
323323

324324
# 5. Push and create PR
325325
git push -u origin feature/issue-123-description
326-
gh pr create --base dev
326+
gh pr create --base dev --title "feat(opencode): implement feature (#123)" --body "Fixes #123"
327+
# Code review happens on the PR before merge
327328
```
328329

329330
---
330331

331-
## Auto-Merge Policy
332+
## PR Workflow
332333

333-
After code-review-specialist approval AND CI passes:
334+
### Code Review Requirements
334335

335-
- Squash merge immediately
336-
- Delete feature branch
337-
- Close linked issue
336+
- PRs require code-review-specialist approval before merge
337+
- Code review happens via GitHub PR review functionality
338+
- Reviews check: style compliance, test coverage, security, architecture
339+
- If CHANGES_REQUESTED: fix issues and re-request review
340+
- If APPROVED: proceed with merge when CI passes
338341

339-
Do not wait for additional approvals on reviewed PRs.
342+
### Auto-Merge Policy
343+
344+
- PRs in APPROVED state with all CI checks passing:
345+
- PR creator: Squash merge immediately
346+
- GitHub: Auto-deletes feature branch
347+
- Close linked issue
348+
- PRs in PENDING or CHANGES_REQUESTED: MUST NOT be merged
349+
- If CI fails after approval: Fix issues, re-push, approval must be re-requested
350+
- Do not wait for additional approvals on reviewed PRs
351+
352+
### PR Batching
353+
354+
- Related issues can be combined into single PR when:
355+
- They share a logical unit of work
356+
- Combined changes are under 500 lines
357+
- All issues are from same epic
358+
- Each PR must reference all included issues with "Fixes #X" syntax
340359

341360
---
342361

@@ -372,6 +391,12 @@ packages/opencode/
372391
3. Refactor
373392
4. Repeat
374393

394+
### Coverage Requirements
395+
396+
- All new code must have tests written BEFORE implementation
397+
- Minimum 80% coverage for new code
398+
- Tests must be in corresponding test/ directory
399+
375400
Run tests: `bun test` or `bun test --coverage`
376401

377402
---
@@ -468,12 +493,9 @@ Built-in tools: File operations, shell execution, search (glob, grep), web fetch
468493

469494
## CI Workflows
470495

471-
| Workflow | Trigger | Purpose |
472-
| ------------- | ---------------- | -------------------- |
473-
| typecheck.yml | PR | Type checking |
474-
| test.yml | PR, push to main | Unit and E2E tests |
475-
| review.yml | PR | Automated review |
476-
| deploy.yml | Push to main | Deploy to production |
496+
| Workflow | Trigger | Purpose |
497+
| -------- | ---------------- | -------------------- |
498+
| ci.yml | PR, push to main | Type check and tests |
477499

478500
Monitor with: `gh run watch [run-id]`
479501

@@ -531,8 +553,8 @@ bun run typecheck && bun test
531553

532554
### Before Merging
533555

534-
- CI passes
535-
- Code review approved
556+
- PR is in APPROVED state
557+
- All CI checks pass
536558
- Issue requirements met
537559
- Conventional commit used
538560

‎bun.lock‎

Lines changed: 89 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"@babel/plugin-transform-react-jsx": "7.28.6",
6868
"@babel/preset-react": "7.28.5",
6969
"@tsconfig/bun": "catalog:",
70+
"@types/babel__preset-env": "7.10.0",
7071
"@types/react": "19.2.10",
7172
"husky": "9.1.7",
7273
"prettier": "3.6.2",
@@ -79,6 +80,7 @@
7980
"@opencode-ai/plugin": "workspace:*",
8081
"@opencode-ai/script": "workspace:*",
8182
"@opencode-ai/sdk": "workspace:*",
83+
"react": "19.2.4",
8284
"typescript": "catalog:"
8385
},
8486
"repository": {

‎packages/opencode/bunfig.ink.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ink-specific config without SolidJS preload
2+
# This lets Bun handle React JSX natively for Ink apps

‎packages/opencode/global.d.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ declare module "@babel/preset-typescript" {
1212
export default function preset(api: ConfigAPI, options?: PluginOptions): PluginObj<unknown> | void
1313
}
1414

15+
declare module "@babel/preset-react" {
16+
import type { ConfigAPI, PluginObj } from "@babel/core"
17+
type PluginOptions = object | undefined | false
18+
19+
export default function preset(api: ConfigAPI, options?: PluginOptions): PluginObj<unknown> | void
20+
}
21+
1522
declare module "@opentui/solid/scripts/solid-plugin" {
1623
import type { BunPlugin } from "bun"
1724

‎packages/opencode/package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"typecheck": "tsgo --noEmit",
1010
"test": "bun test",
11-
"test:ink": "bun run src/cli/ink/test.tsx",
11+
"dev:ink": "bun --no-plugins src/cli/ink/test.tsx",
12+
"test:ink": "bun test test/cli/ink/",
1213
"build": "bun run script/build.ts",
1314
"build:lite": "bun run script/build-lite.ts",
1415
"dev": "bun run --conditions=browser ./src/index.ts",
@@ -43,6 +44,7 @@
4344
"@types/turndown": "5.0.5",
4445
"@types/yargs": "17.0.33",
4546
"@typescript/native-preview": "catalog:",
47+
"ink-testing-library": "4.0.0",
4648
"typescript": "catalog:",
4749
"vscode-languageserver-types": "3.17.5",
4850
"why-is-node-running": "3.2.2",
@@ -113,6 +115,7 @@
113115
"opentui-spinner": "0.0.6",
114116
"partial-json": "0.1.7",
115117
"react": "19.2.4",
118+
"react-dom": "19.2.4",
116119
"remeda": "catalog:",
117120
"solid-js": "catalog:",
118121
"strip-ansi": "7.1.2",

‎packages/opencode/preload.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { plugin, type BunPlugin } from "bun"
22
import { transformAsync } from "@babel/core"
33
import solid from "babel-preset-solid"
4+
import react from "@babel/preset-react"
45
import ts from "@babel/preset-typescript"
56

67
const inkExcludedPlugin: BunPlugin = {
@@ -35,15 +36,25 @@ const inkExcludedPlugin: BunPlugin = {
3536
return undefined
3637
}
3738

38-
const normalized = Bun.pathToFileURL(args.path).href
39+
const code = await Bun.file(args.path).text()
3940

40-
if (normalized.includes("cli/ink/")) {
41-
const code = await Bun.file(args.path).text()
42-
return { contents: code, loader: "tsx" }
41+
// Detect if file imports from Ink (React-based)
42+
const isInkFile = /from\s*["']ink["']/.test(code) || /require\(["']ink["']\)/.test(code)
43+
44+
if (isInkFile) {
45+
// Transform with Babel React preset
46+
const result = await transformAsync(code, {
47+
filename: args.path,
48+
presets: [
49+
["@babel/preset-react", { runtime: "automatic", importSource: "react" }],
50+
[ts, { isTSX: true, allExtensions: true }],
51+
],
52+
})
53+
return { contents: result?.code ?? "", loader: "js" }
4354
}
4455

4556
try {
46-
const code = await Bun.file(args.path).text()
57+
// Transform with SolidJS preset
4758
const transforms = await transformAsync(code, {
4859
filename: args.path,
4960
presets: [
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** @jsxImportSource react */
2+
import React, { useReducer } from "react"
3+
import type { ReactElement } from "react"
4+
import { Box, Text } from "ink"
5+
import { appReducer, initialState } from "./state/reducer"
6+
import { theme } from "./theme"
7+
8+
export const App = () => {
9+
const [state, dispatch] = useReducer(appReducer, initialState)
10+
11+
return (
12+
<Box flexDirection="column">
13+
{/* Streaming content */}
14+
{state.streaming.text && (
15+
<Box>
16+
<Text>{state.streaming.text}</Text>
17+
</Box>
18+
)}
19+
20+
{/* Input prompt */}
21+
<Box>
22+
<Text color={theme.prompt.agent}>{state.session.agent}</Text>
23+
<Text color={theme.prompt.separator}> {theme.prompt.symbol} </Text>
24+
</Box>
25+
</Box>
26+
)
27+
}
28+
29+
export default App
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/** @jsxImportSource react */
2+
import { Box, Text } from "ink"
3+
import Spinner from "ink-spinner"
4+
import type { Task, Tool } from "../state/types"
5+
import { theme } from "../theme"
6+
7+
interface TaskDisplayProps {
8+
task: Task
9+
agent: string
10+
elapsed?: number
11+
}
12+
13+
export const TaskDisplay = ({ task, agent, elapsed }: TaskDisplayProps) => {
14+
const colors = task.state === "completed" ? theme.task.completed : theme.task.running
15+
const tools = Array.from(task.childTools.values())
16+
const runningTools = tools.filter((t) => t.state === "running")
17+
18+
return (
19+
<Box flexDirection="column">
20+
<Box>
21+
<Text color={colors.icon} bold>
22+
{task.state === "running" ? <Spinner type="dots" /> : "✓"}
23+
</Text>
24+
<Text dimColor> task </Text>
25+
<Text color={colors.text}>@{agent}:</Text>
26+
<Text> {task.description}</Text>
27+
{elapsed && elapsed > 0 && <Text dimColor> ({elapsed}s)</Text>}
28+
</Box>
29+
{runningTools.length > 0 && (
30+
<>
31+
{runningTools.map((tool, index) => (
32+
<Box key={tool.id} marginLeft={2}>
33+
<Text dimColor>→ </Text>
34+
<Text>{tool.name}: </Text>
35+
<Text dimColor>{getToolSummary(tool)}</Text>
36+
</Box>
37+
))}
38+
</>
39+
)}
40+
</Box>
41+
)
42+
}
43+
44+
const getToolSummary = (tool: Tool): string => {
45+
if (!tool?.input) return "starting"
46+
const values = Object.values(tool.input)
47+
if (values.length === 0) return "starting"
48+
const firstValue = values[0]
49+
if (typeof firstValue === "string") return firstValue.slice(0, 40)
50+
if (typeof firstValue === "number" || typeof firstValue === "boolean") return String(firstValue)
51+
if (firstValue === null) return "null"
52+
return "running"
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/** @jsxImportSource react */
2+
import { Box, Text } from "ink"
3+
import Spinner from "ink-spinner"
4+
import type { Tool } from "../state/types"
5+
import { theme } from "../theme"
6+
7+
interface ToolDisplayProps {
8+
tool: Tool
9+
}
10+
11+
export const ToolDisplay = ({ tool }: ToolDisplayProps) => {
12+
const colors = tool.state === "pending" ? { icon: "gray", text: "gray" } : theme.tool[tool.state]
13+
14+
const stateIcons: Record<Tool["state"], string | null> = {
15+
pending: "○",
16+
running: null,
17+
completed: "✓",
18+
error: "✗",
19+
}
20+
21+
const icon = stateIcons[tool.state] ?? ""
22+
23+
const getDisplayInput = () => {
24+
const inputValues = Object.values(tool.input ?? {})
25+
const inputValue = inputValues[0]
26+
if (inputValue === null || inputValue === undefined) return ""
27+
28+
const value = String(inputValue)
29+
return value.slice(0, 50)
30+
}
31+
32+
const displayInput = getDisplayInput()
33+
34+
return (
35+
<Box aria-label={`Tool ${tool.name} in ${tool.state} state`}>
36+
{tool.state === "running" ? <Spinner type="dots" /> : <Text color={colors.icon}>{icon}</Text>}
37+
<Text color={colors.text}> {tool.name}</Text>
38+
{displayInput && <Text dimColor> {displayInput}</Text>}
39+
</Box>
40+
)
41+
}

0 commit comments

Comments
 (0)