The panes of a coding agent's workspace: files, a terminal and an editor.
import { Subscription, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schedule, Schema, Stream } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { Terminal, type TerminalEntry } from "./ui/uicontext/components/kit/Shell.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"const ESC = "\u001b"const green = (s: string) => `${ESC}[32m${s}${ESC}[0m`const red = (s: string) => `${ESC}[31m${s}${ESC}[0m`const dim = (s: string) => `${ESC}[2m${s}${ESC}[0m`const bold = (s: string) => `${ESC}[1m${s}${ESC}[0m`const done: ReadonlyArray<TerminalEntry> = [ { id: "install", command: "bun install", cwd: "~/billing", output: [{ text: `${dim("bun install v1.4.2")}\n\n${green("✓")} 367 packages installed ${dim("[412ms]")}` }], exitCode: 0, }, { id: "lint", command: "bun run lint", cwd: "~/billing", output: [ { text: `${bold("src/invoice/tax.ts")}\n 14:7 ${ESC}[33mwarning${ESC}[0m 'rate' is assigned but never used no-unused-vars` }, { text: `\n${ESC}[33m✖ 1 problem (0 errors, 1 warning)${ESC}[0m` }, ], exitCode: 0, },]// the test run's lines, in the order the runner writes themconst LINES: ReadonlyArray<{ readonly text: string; readonly error?: boolean }> = [ { text: dim("bun test v1.4.2") }, { text: `\nsrc/invoice/total.test.ts:\n${green("✓")} sums line items ${dim("[0.4ms]")}` }, { text: `\n${green("✓")} rounds once on the total ${dim("[0.2ms]")}` }, { text: `\n${red("✗")} adds VAT once for EU customers ${dim("[1.1ms]")}`, error: true }, { text: `\n ${red("expect(received).toBe(expected)")}\n Expected: ${green("120.00")}\n Received: ${red("144.00")}`, error: true }, { text: `\n\nsrc/invoice/pdf.test.ts:\nRendering 40 invoices ${"█".repeat(4)}${"░".repeat(16)} 20%\rRendering 40 invoices ${"█".repeat(12)}${"░".repeat(8)} 60%\rRendering 40 invoices ${"█".repeat(20)} 100%` }, { text: `\n${green("✓")} renders every invoice ${dim("[812ms]")}` }, { text: `\n\n ${green("211 pass")}\n ${red("1 fail")}\n Ran 212 tests across 18 files. ${dim("[1.94s]")}` },]const Message = UiSchema.TaggedEnum({ ReceivedLine: { count: Schema.Number }, ClickedRunAgain: {} })// Stands in for the shell's output stream: a line every 350ms.const lines = (run: number) => Subscription.make("test-lines", run, () => Stream.fromIterable(LINES.map((_, i) => i + 1)).pipe( Stream.schedule(Schedule.spaced("350 millis")), Stream.map((count) => Message.ReceivedLine({ count })), ), )const styles = stylex.create({ frame: { display: "grid", gridTemplateRows: "minmax(0, 1fr) auto", gap: space.md, inlineSize: "100%", blockSize: 360 },})export const TestRun = Html.component({ name: "TestRun", model: Schema.Struct({ received: Schema.Number, run: Schema.Number }), message: Message,}).make({ init: () => ({ received: 0, run: 1 }), subscriptions: ($) => ($.model.received < LINES.length ? [lines($.model.run)] : []), update: { ReceivedLine: ($, { count }) => $.evolve({ received: count }), ClickedRunAgain: ($) => $.evolve({ received: 0, run: (n) => n + 1 }), }, view: (h, model) => { const running = model.received < LINES.length return h.div.attrs(sx(styles.frame)).children( Terminal(h, { label: "Terminal", streaming: running, entries: [ ...done, { id: `test-${model.run}`, command: "bun test src/invoice", cwd: "~/billing", output: LINES.slice(0, model.received), exitCode: running ? null : 1 }, ], }), !running && Button(h, { size: "sm" }).on("click", Message.ClickedRunAgain()).children("Run the tests again"), ) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/shellUsage
import { Terminal, type TerminalEntry } from "./ui/uicontext/components/kit/Shell.ts"export const AgentTerminal = <M>(h: Html.H<M>, entries: ReadonlyArray<TerminalEntry>, running: boolean) => Terminal(h, { label: "Terminal", entries, streaming: running })Examples
Before anything runs
While the session starts the terminal shows a placeholder; with nothing run yet it says so and what comes next.
Starting
Nothing run yet
Nothing has run yet
Commands the agent runs show here with their output.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Terminal } from "./ui/uicontext/components/kit/Shell.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ grid: { display: "grid", gap: space.lg, gridTemplateColumns: "repeat(auto-fit, minmax(16rem, 1fr))", inlineSize: "100%" }, pane: { display: "grid", gap: space.xs, blockSize: 200, alignContent: "start" }, label: { margin: 0, fontSize: font.xs, color: color.faint },})export const TerminalStates = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.grid)).children( h.div.attrs(sx(styles.pane)).children( h.p.attrs(sx(styles.label)).children("Starting"), Terminal(h, { label: "Terminal", entries: [], status: "loading" }), ), h.div.attrs(sx(styles.pane)).children( h.p.attrs(sx(styles.label)).children("Nothing run yet"), Terminal(h, { label: "Terminal", entries: [], empty: { title: "Nothing has run yet", hint: "Commands the agent runs show here with their output." }, }), ), )API reference
FileTreeComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | Identifies the tree for agents |
labelrequired | string | — | The tree's accessible name: "Files" |
nodesrequired | FileNode[] | — | The files and folders at the top level, each folder with its children |
status | "loading" | "ready" | "ready" | "loading" shows a placeholder; "ready" by default |
selected | string | null | — | The open file |
defaultOpen | string[] | — | Folders open at first; default the top level |
agentId | string | — | The id agents see this tree by; files:<id> when left out |
Events
| Event | Payload | Description |
|---|---|---|
RequestedOpenFile | { path: string } | The person picked a file to open |
Agent actions
| Action | Description |
|---|---|
ToggledFolder | Open or close a folder by its path |
ClickedFile | Open a file by its path |
FileEditorComponent
Props
| Name | Type | Description |
|---|---|---|
idrequired | string | Identifies the editor in the events it sends |
pathrequired | string | The file's path, shown as the editor's heading |
valuerequired | string | The file's saved text; the person's edits stay a draft until Save |
language | string | "TypeScript", shown in the status bar |
readOnly | string | Why it can't be edited: "The agent is working in this file" |
saveLabel | string | "Save", "Save draft"; leave can without "save" to hide it |
canrequired | "save"[] | "save" when this person may save; read-only without it |
outcome | Outcome | null | The app's answer to the request in flight; its request is the action's id |
agentId | string | The id agents see this editor by; file:<id> when left out |
Events
| Event | Payload | Description |
|---|---|---|
RequestedSave | { id: string; path: string; value: string } | The person saved their draft |
Agent actions
| Action | Description |
|---|---|
UpdatedText | Replace the file's whole text (saved with SubmittedSave) |
SubmittedSave | Save the edited file |
ClickedDiscard | Throw away unsaved edits |
TerminalView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | The log's accessible name: "Terminal" |
entriesrequired | TerminalEntry[] | — | The commands and their output, oldest first |
status | "loading" | "ready" | "ready" | "loading" shows a placeholder; "ready" by default |
empty | { readonly title: string; readonly hint?: string } | — | What shows before anything has run; "Nothing has run yet" when left out |
streaming | boolean | — | Lines are still arriving |
maxLines | number | 400 | Lines of one command's output shown before the rest fold away; 400 by default |
copy | boolean | true | A Copy button on each command, for its prompt and output; true by default |
PaneSwitcherView function
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | The group's accessible name: "Workspace panes" |
panesrequired | ReadonlyArray<{ readonly id: string; readonly label: string; readonly badge?: string }> | The panes to pick from, each with an optional badge: "3" |
selectedrequired | string | The id of the pane showing |
onSelectrequired | (id: string) => Message | The message for picking a pane |
Accessibility
- The file tree is a
nav: folders open and close as disclosures, and the open file is markedaria-current. - The terminal is a focusable
log, so new lines are announced and the keyboard can scroll it. - The editor is a labelled text area; Mod+S saves. The pane switcher is a row of toggle buttons (
aria-pressed).