Skip to content

Commit d8a2087

Browse files
committed
feat(tool): add interactive terminal tool with persistent PTY sessions
Introduces a new terminal tool with action-based session management: - run (default): backward-compatible one-shot execution - create: start persistent PTY session, returns sessionId - send: write input to existing session (commands, control sequences) - read: cursor-based incremental output reading - close: terminate session and cleanup resources Sessions stored via InstanceState for per-directory isolation with FIFO eviction at max 20 sessions. Fixes PowerShell exit code by using \ instead of \True on Windows. Closes anomalyco#23759
1 parent f033d2d commit d8a2087

7 files changed

Lines changed: 1038 additions & 0 deletions

File tree

‎bun.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/opencode/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"devDependencies": {
4444
"@babel/core": "7.28.4",
45+
"@babel/types": "7.29.0",
4546
"@effect/language-service": "0.84.2",
4647
"@octokit/webhooks-types": "7.6.1",
4748
"@opencode-ai/script": "workspace:*",

‎packages/opencode/src/tool/registry.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PlanExitTool } from "./plan"
22
import { Session } from "../session"
33
import { QuestionTool } from "./question"
44
import { BashTool } from "./bash"
5+
import { TerminalTool } from "./terminal"
56
import { EditTool } from "./edit"
67
import { GlobTool } from "./glob"
78
import { GrepTool } from "./grep"
@@ -32,6 +33,7 @@ import { Glob } from "@opencode-ai/shared/util/glob"
3233
import path from "path"
3334
import { pathToFileURL } from "url"
3435
import { Effect, Layer, Context } from "effect"
36+
import { Pty } from "@/pty"
3537
import { FetchHttpClient, HttpClient } from "effect/unstable/http"
3638
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
3739
import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
@@ -86,6 +88,7 @@ export const layer: Layer.Layer<
8688
| Bus.Service
8789
| HttpClient.HttpClient
8890
| ChildProcessSpawner
91+
| Pty.Service
8992
| Ripgrep.Service
9093
| Format.Service
9194
| Truncate.Service
@@ -108,6 +111,7 @@ export const layer: Layer.Layer<
108111
const webfetch = yield* WebFetchTool
109112
const websearch = yield* WebSearchTool
110113
const bash = yield* BashTool
114+
const terminal = yield* TerminalTool
111115
const codesearch = yield* CodeSearchTool
112116
const globtool = yield* GlobTool
113117
const writetool = yield* WriteTool
@@ -189,6 +193,7 @@ export const layer: Layer.Layer<
189193
const tool = yield* Effect.all({
190194
invalid: Tool.init(invalid),
191195
bash: Tool.init(bash),
196+
terminal: Tool.init(terminal),
192197
read: Tool.init(read),
193198
glob: Tool.init(globtool),
194199
grep: Tool.init(greptool),
@@ -212,6 +217,7 @@ export const layer: Layer.Layer<
212217
tool.invalid,
213218
...(questionEnabled ? [tool.question] : []),
214219
tool.bash,
220+
tool.terminal,
215221
tool.read,
216222
tool.glob,
217223
tool.grep,
@@ -344,6 +350,7 @@ export const defaultLayer = Layer.suspend(() =>
344350
Layer.provide(Format.defaultLayer),
345351
Layer.provide(CrossSpawnSpawner.defaultLayer),
346352
Layer.provide(Ripgrep.defaultLayer),
353+
Layer.provide(Pty.defaultLayer),
347354
Layer.provide(Truncate.defaultLayer),
348355
),
349356
)

0 commit comments

Comments
 (0)