AI Code
Code an agent writes, changes and runs: a streaming file with line numbers, a hunk-by-hunk diff with keep and undo, and a terminal with an exit status.
"use client"
import * as React from "react"
import { Check, Copy, FileCode, FileDiff, Terminal, Undo2 } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Mark,
Pill,
Roll,
} from "@/lib/ai-kit"
const CSS = `
.aik-cd-win{width:min(100%,400px);border-radius:16px;background:var(--aik-card);box-shadow:var(--aik-sh-card);overflow:hidden;min-width:0}
.aik-cd-bar{display:flex;align-items:center;gap:8px;height:40px;padding:0 6px 0 12px;border-bottom:1px solid var(--aik-line);font-size:12.5px;min-width:0}
.aik-cd-tab{display:inline-flex;align-items:center;gap:6px;font:500 12.5px var(--aik-mono);min-width:0;overflow:hidden;white-space:nowrap}
.aik-cd-tab .ic{color:var(--aik-text-3)}
.aik-cd-grow{flex:1}
.aik-cd-bar .aik-pill{height:20px;font-size:11.5px}
.aik-cd-scroll{overflow-x:auto;background:var(--aik-sunk);scrollbar-width:thin}
.aik-cd-code{margin:0;padding:12px 16px 12px 0;font:12.5px/20px var(--aik-mono);counter-reset:cdl;min-height:184px;inline-size:max-content;min-inline-size:100%}
.aik-cd-l{display:block;position:relative;padding-left:44px;min-height:20px;white-space:pre;counter-increment:cdl}
.aik-cd-l::before{content:counter(cdl);position:absolute;left:0;inline-size:30px;text-align:right;color:var(--aik-text-3)}
.aik-cd-k{color:var(--aik-purple)}
.aik-cd-f{color:var(--aik-blue)}
.aik-cd-s{color:var(--aik-green)}
.aik-cd-n{color:var(--aik-amber)}
.aik-cd-c{color:var(--aik-text-3)}
.aik-cd-tk{animation:aik-word var(--aik-d-enter) var(--aik-ease-out) both}
.aik-cd-copy > *{transition:opacity var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-state) var(--aik-ease-out)}
.aik-cd-copy{display:inline-grid;place-items:center}
.aik-cd-copy > *{grid-area:1/1}
.aik-cd-copy .ic:last-child{opacity:0;transform:scale(.4);color:var(--aik-green)}
.aik-cd-copy[data-ok] .ic:first-child{opacity:0;transform:scale(.4)}
.aik-cd-copy[data-ok] .ic:last-child{opacity:1;transform:none}
.aik-cd-cnt{display:inline-flex;gap:6px;font:500 12px var(--aik-mono)}
.aik-cd-cnt .aik-cd-add{color:var(--aik-green)}
.aik-cd-cnt .aik-cd-del{color:var(--aik-red)}
.aik-cd-bar .aik-roll{font-size:12px;color:var(--aik-text-3);line-height:16px;margin-right:6px}
.aik-cd-hunk + .aik-cd-hunk{border-top:1px solid var(--aik-line)}
.aik-cd-hh{display:flex;align-items:center;gap:4px;height:36px;padding:0 6px 0 12px;font:11.5px var(--aik-mono);color:var(--aik-text-3)}
.aik-cd-res{display:none;align-items:center;gap:6px;font:500 12px var(--aik-sans);color:var(--aik-text-2);padding-right:6px}
.aik-cd-hunk:not([data-st="open"]) .aik-cd-hh .aik-btn{display:none}
.aik-cd-hunk:not([data-st="open"]) .aik-cd-res{display:inline-flex;animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both}
.aik-cd-lines{overflow-x:auto;background:var(--aik-sunk);padding-block:4px;scrollbar-width:thin}
.aik-cd-d{display:grid;grid-template-columns:28px minmax(0,1fr);min-height:22px;font:12.5px/22px var(--aik-mono);white-space:pre;inline-size:max-content;min-inline-size:100%;padding-right:12px;transition:background var(--aik-d-state)}
.aik-cd-d i{font-style:normal;text-align:center;color:var(--aik-text-3)}
.aik-cd-d code{font:inherit}
.aik-cd-d[data-t="add"]{background:color-mix(in oklab,var(--aik-green) 13%,transparent)}
.aik-cd-d[data-t="add"] i{color:var(--aik-green)}
.aik-cd-d[data-t="del"]{background:color-mix(in oklab,var(--aik-red) 12%,transparent)}
.aik-cd-d[data-t="del"] i{color:var(--aik-red)}
.aik-cd-d[data-t="del"] code{color:var(--aik-text-2);text-decoration:line-through;text-decoration-color:color-mix(in oklab,var(--aik-red) 55%,transparent)}
.aik-cd-diff[data-fresh] .aik-cd-d{animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both;animation-delay:calc(var(--i)*var(--aik-stagger))}
.aik-cd-hunk[data-leaving="kept"] .aik-cd-d[data-t="del"],.aik-cd-hunk[data-leaving="undone"] .aik-cd-d[data-t="add"]{animation:aik-out var(--aik-d-exit) var(--aik-ease-in) both}
.aik-cd-hunk[data-st="kept"] .aik-cd-d[data-t="del"],.aik-cd-hunk[data-st="undone"] .aik-cd-d[data-t="add"]{display:none}
.aik-cd-hunk[data-st="kept"] .aik-cd-d[data-t="add"],.aik-cd-hunk[data-st="undone"] .aik-cd-d[data-t="del"]{background:transparent}
.aik-cd-hunk[data-st="kept"] .aik-cd-d i,.aik-cd-hunk[data-st="undone"] .aik-cd-d i{visibility:hidden}
.aik-cd-hunk[data-st="undone"] .aik-cd-d[data-t="del"] code{color:var(--aik-text);text-decoration:none}
.aik-cd-term .aik-cd-bar > .ic{color:var(--aik-text-3)}
.aik-cd-term .aik-cd-bar .mono{font-size:12.5px;font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-cd-term .aik-pill .aik-mark{inline-size:14px;block-size:14px}
.aik-cd-out{background:var(--aik-sunk);padding:12px 14px;min-height:164px;font:12.5px/20px var(--aik-mono);display:grid;align-content:start;overflow-x:auto;scrollbar-width:thin}
.aik-cd-o{white-space:pre;color:var(--aik-text-2)}
.aik-cd-o.cmd{color:var(--aik-text)}
.aik-cd-o.cmd::before{content:"$ ";color:var(--aik-text-3)}
.aik-cd-o.ok::before{content:"✓ ";color:var(--aik-green)}
.aik-cd-o.err{color:var(--aik-red)}
.aik-cd-o.err::before{content:"✗ "}
.aik-cd-o.end{color:var(--aik-text)}
.aik-cd-copy > svg{grid-area:1/1;transition:opacity var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-state) var(--aik-ease-out)}
.aik-cd-copy > svg:last-child{opacity:0;transform:scale(.4);color:var(--aik-green)}
.aik-cd-copy[data-ok] > svg:first-child{opacity:0;transform:scale(.4)}
.aik-cd-copy[data-ok] > svg:last-child{opacity:1;transform:none}
.aik-cd-tab svg,.aik-cd-term .aik-cd-bar > svg{color:var(--aik-text-3)}
.aik-cd-res svg{color:var(--aik-text-3)}
.aik-cd-l .aik-caret{vertical-align:-.2em}
.aik-cd-o{animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both}
.aik-cd-o .aik-caret{vertical-align:-.2em}
.aik-cd-empty{padding:12px 16px 12px 44px;color:var(--aik-text-3);font:12.5px/20px var(--aik-mono)}
`
/** How long a losing line stays mounted while it fades, matching `--aik-d-exit`. */
const EXIT_MS = 160
export interface AiCodeSpan {
text: string
/** Syntax role. Plain text when omitted. */
kind?: "keyword" | "function" | "string" | "number" | "comment"
}
/** One line of code as a list of coloured spans. */
export type AiCodeLine = AiCodeSpan[]
const KIND_CLASS = {
keyword: "aik-cd-k",
function: "aik-cd-f",
string: "aik-cd-s",
number: "aik-cd-n",
comment: "aik-cd-c",
} as const
const plain = (lines: AiCodeLine[]) =>
lines.map((line) => line.map((span) => span.text).join("")).join("\n")
function CopyButton({
text,
label,
onCopy,
}: {
text: string
label: string
onCopy?: () => void
}) {
const [copied, setCopied] = React.useState(false)
React.useEffect(() => {
if (!copied) return
const timer = window.setTimeout(() => setCopied(false), 1400)
return () => window.clearTimeout(timer)
}, [copied])
return (
<button
type="button"
className="aik-btn icon sm ghost aik-cd-copy"
aria-label={copied ? "Copied" : label}
data-ok={copied ? "" : undefined}
onClick={async () => {
try {
await navigator.clipboard.writeText(text)
} catch {
// Clipboard access can be refused; the button still confirms the press.
}
setCopied(true)
onCopy?.()
}}
>
<Copy size={14} />
<Check size={14} />
</button>
)
}
export interface AiCodeStreamProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"children"
> {
filename: string
/** The code so far. Append spans and lines as tokens arrive. */
lines: AiCodeLine[]
/** `writing` shows a caret after the last token; `saved` settles the pill. */
status?: "writing" | "saved"
/** Called after the code was copied to the clipboard. */
onCopy?: () => void
}
/** A file streaming in: line numbers count up and tokens arrive in syntax colour behind a caret. */
export function AiCodeStream({
filename,
lines,
status = "saved",
onCopy,
className,
...rest
}: AiCodeStreamProps) {
const writing = status === "writing"
return (
<div {...rest} className={cx("aik aik-cd-win", className)}>
<AiKitStyles />
<AiStyle id="ai-code" css={CSS} />
<div className="aik-cd-bar">
<span className="aik-cd-tab">
<FileCode size={14} />
{filename}
</span>
<span className="aik-cd-grow" />
<Pill status={writing ? "run" : "done"}>
{writing ? "Writing" : "Saved"}
</Pill>
<CopyButton text={plain(lines)} label="Copy code" onCopy={onCopy} />
</div>
<div className="aik-cd-scroll" tabIndex={0} aria-label={filename}>
<pre className="aik-cd-code" aria-busy={writing}>
{lines.map((line, at) => (
<span key={at} className="aik-cd-l">
{line.map((span, index) => (
<span
key={index}
className={cx(
"aik-cd-tk",
span.kind && KIND_CLASS[span.kind]
)}
>
{span.text}
</span>
))}
{writing && at === lines.length - 1 ? (
<i className="aik-caret" />
) : null}
</span>
))}
{lines.length === 0 ? (
<span className="aik-cd-l">
{writing ? <i className="aik-caret" /> : null}
</span>
) : null}
</pre>
</div>
</div>
)
}
export interface AiDiffLine {
type: "add" | "del" | "ctx"
text: string
}
export interface AiDiffHunk {
id: string
/** The hunk header, such as "@@ 12,4". */
header: string
lines: AiDiffLine[]
/** `open` awaits a decision; `kept` and `undone` are settled. */
state?: "open" | "kept" | "undone"
}
export interface AiDiffProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"children"
> {
filename: string
hunks: AiDiffHunk[]
/** Called when a hunk is kept or undone. Update that hunk's `state` in response. */
onResolve?: (id: string, state: "kept" | "undone") => void
}
const GUTTER = { add: "+", del: "−", ctx: " " } as const
/** A diff you accept hunk by hunk: the losing lines fade out and the rest settle into plain code. */
export function AiDiff({
filename,
hunks,
onResolve,
className,
...rest
}: AiDiffProps) {
const [leaving, setLeaving] = React.useState<
Record<string, "kept" | "undone">
>({})
const timers = React.useRef<number[]>([])
React.useEffect(
() => () => timers.current.forEach((timer) => window.clearTimeout(timer)),
[]
)
const resolve = (id: string, state: "kept" | "undone") => {
onResolve?.(id, state)
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return
setLeaving((now) => ({ ...now, [id]: state }))
timers.current.push(
window.setTimeout(() => {
setLeaving((now) => {
const next = { ...now }
delete next[id]
return next
})
}, EXIT_MS)
)
}
let added = 0
let removed = 0
let open = 0
for (const hunk of hunks) {
if ((hunk.state ?? "open") === "open") open++
for (const line of hunk.lines) {
if (line.type === "add") added++
else if (line.type === "del") removed++
}
}
let row = 0
return (
<div
{...rest}
className={cx("aik aik-cd-win aik-cd-diff", className)}
data-fresh=""
>
<AiKitStyles />
<AiStyle id="ai-code" css={CSS} />
<div className="aik-cd-bar">
<span className="aik-cd-tab">
<FileDiff size={14} />
{filename}
</span>
<span className="aik-cd-cnt">
<span className="aik-cd-add">+{added}</span>
<span className="aik-cd-del">−{removed}</span>
</span>
<span className="aik-cd-grow" />
<Roll>
{open === 0
? "All resolved"
: `${open} ${open === 1 ? "hunk" : "hunks"} left`}
</Roll>
</div>
{hunks.map((hunk) => {
const state = hunk.state ?? "open"
const going = leaving[hunk.id]
return (
<div
key={hunk.id}
className="aik-cd-hunk"
data-st={going ? "open" : state}
data-leaving={going}
>
<div className="aik-cd-hh">
<span>{hunk.header}</span>
<span className="aik-cd-grow" />
{state === "open" ? (
<>
<button
type="button"
className="aik-btn sm ghost"
onClick={() => resolve(hunk.id, "undone")}
>
Undo
</button>
<button
type="button"
className="aik-btn sm pri"
onClick={() => resolve(hunk.id, "kept")}
>
Keep
</button>
</>
) : (
<span className="aik-cd-res" role="status">
{state === "kept" ? (
<Mark status="done" />
) : (
<Undo2 size={14} />
)}
<span>{state === "kept" ? "Kept" : "Undone"}</span>
</span>
)}
</div>
<div className="aik-cd-lines">
{hunk.lines.map((line, at) => (
<div
key={at}
className="aik-cd-d"
data-t={line.type}
style={{ "--i": row++ } as React.CSSProperties}
>
<i aria-hidden="true">{GUTTER[line.type]}</i>
<code>{line.text}</code>
</div>
))}
</div>
</div>
)
})}
</div>
)
}
export interface AiTerminalLine {
text: string
/** `ok` and `err` add a tick or cross; `end` is the closing summary. */
kind?: "out" | "ok" | "err" | "end"
}
export interface AiTerminalProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"children"
> {
/** The command, shown in the header. */
command: string
/** The command as typed so far. Defaults to the whole command. */
typed?: string
/** Output lines, in the order they arrived. */
lines: AiTerminalLine[]
status: "running" | "done" | "failed"
/** The header pill once finished, such as "Exit 0 · 3.8s". */
exit?: string
}
/** A command, its output arriving line by line, and a header pill that ends on an exit status. */
export function AiTerminal({
command,
typed,
lines,
status,
exit,
className,
...rest
}: AiTerminalProps) {
const running = status === "running"
const typing = running && typed !== undefined && typed.length < command.length
return (
<div {...rest} className={cx("aik aik-cd-win aik-cd-term", className)}>
<AiKitStyles />
<AiStyle id="ai-code" css={CSS} />
<div className="aik-cd-bar">
<Terminal size={14} />
<span className="aik-mono">{command}</span>
<span className="aik-cd-grow" />
<Pill status={running ? "run" : status === "done" ? "done" : "fail"}>
<Mark
status={running ? "run" : status === "done" ? "done" : "fail"}
/>
<span>
{running
? "Running"
: (exit ?? (status === "done" ? "Done" : "Failed"))}
</span>
</Pill>
</div>
<div
className="aik-cd-out"
role="log"
aria-live="polite"
tabIndex={0}
aria-label={`Output of ${command}`}
>
<span className="aik-cd-o cmd" style={{ animation: "none" }}>
{typed ?? command}
{typing ? <i className="aik-caret" /> : null}
</span>
{lines.map((line, at) => (
<span
key={at}
className={cx("aik-cd-o", line.kind !== "out" && line.kind)}
>
{line.text}
</span>
))}
</div>
</div>
)
}
Installation
One command adds ai-code and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/ai-code.json
ai-code-demo
"use client"
import * as React from "react"
import { AiDemo } from "@/lib/ai-demo"
import { typeInto, useAiLoop } from "@/lib/ai-kit"
import {
AiCodeStream,
AiDiff,
AiTerminal,
type AiCodeLine,
type AiDiffHunk,
type AiTerminalLine,
} from "@/registry/tween/ai-code"
const FILE: AiCodeLine[] = [
[
{ text: "export", kind: "keyword" },
{ text: " " },
{ text: "function", kind: "keyword" },
{ text: " " },
{ text: "Hero", kind: "function" },
{ text: "() {" },
],
[
{ text: " " },
{ text: "const", kind: "keyword" },
{ text: " ref = " },
{ text: "useRef", kind: "function" },
{ text: "(" },
{ text: "null", kind: "keyword" },
{ text: ")" },
],
[
{ text: " " },
{ text: "useReveal", kind: "function" },
{ text: "(ref, {" },
],
[{ text: " stagger: " }, { text: "0.05", kind: "number" }, { text: "," }],
[
{ text: " ease: " },
{ text: '"power3.out"', kind: "string" },
{ text: "," },
],
[{ text: " })" }],
[
{ text: " " },
{ text: "return", kind: "keyword" },
{ text: " <" },
{ text: "h1", kind: "function" },
{ text: " ref={ref}>Motion, considered.</" },
{ text: "h1", kind: "function" },
{ text: ">" },
],
[{ text: "}" }],
]
function Stream() {
const root = React.useRef<HTMLDivElement>(null)
const [lines, setLines] = React.useState<AiCodeLine[]>(FILE)
const [status, setStatus] = React.useState<"writing" | "saved">("saved")
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
setStatus("writing")
setLines([])
await sleep(500)
for (let row = 0; row < FILE.length; row++) {
const full = FILE[row] ?? []
for (let end = 1; end <= full.length; end++) {
setLines([...FILE.slice(0, row), full.slice(0, end)])
await sleep((full[end - 1]?.text.trim() ? 90 : 20) + end * 4)
}
await sleep(120)
}
setStatus("saved")
await sleep(2600)
},
{ gap: 500, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerDown={() => {
setHands(true)
setLines(FILE)
setStatus("saved")
}}
>
<AiCodeStream filename="hero.tsx" lines={lines} status={status} />
</div>
)
}
const HUNKS: AiDiffHunk[] = [
{
id: "stagger",
header: "@@ 12,4",
lines: [
{ type: "ctx", text: "useReveal(ref, {" },
{ type: "del", text: " stagger: 0.1," },
{ type: "add", text: " stagger: 0.05," },
{ type: "add", text: ' ease: "power3.out",' },
],
},
{
id: "markup",
header: "@@ 21,2",
lines: [
{ type: "del", text: "<h1>Motion.</h1>" },
{ type: "add", text: "<h1 ref={ref}>Motion, considered.</h1>" },
{ type: "add", text: "<p>Built for products.</p>" },
],
},
]
type Verdicts = Record<string, "open" | "kept" | "undone">
function Diff() {
const root = React.useRef<HTMLDivElement>(null)
const [verdicts, setVerdicts] = React.useState<Verdicts>({})
const [round, setRound] = React.useState(0)
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
setVerdicts({})
setRound((now) => now + 1)
await sleep(1900)
setVerdicts({ stagger: "kept" })
await sleep(1500)
setVerdicts({ stagger: "kept", markup: "undone" })
await sleep(2600)
},
{ gap: 500, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerDown={() => setHands(true)}
>
<AiDiff
key={round}
filename="hero.tsx"
hunks={HUNKS.map((hunk) => ({
...hunk,
state: verdicts[hunk.id] ?? "open",
}))}
onResolve={(id, state) =>
setVerdicts((now) => ({ ...now, [id]: state }))
}
/>
{hands && HUNKS.every((hunk) => verdicts[hunk.id]) ? (
<button
type="button"
className="aik-btn sm ghost"
style={{ justifySelf: "start", marginTop: 8 }}
onClick={() => setVerdicts({})}
>
Reset the diff
</button>
) : null}
</div>
)
}
const COMMAND = "pnpm build:registry"
const GOOD: AiTerminalLine[] = [
{ text: "synced 104 example dependencies", kind: "ok" },
{ text: "wrote registry/__index__.tsx", kind: "ok" },
{ text: "wrote public/r, 104 items", kind: "ok" },
{ text: "generated llms.txt", kind: "ok" },
{ text: "Done in 3.8s", kind: "end" },
]
const BAD: AiTerminalLine[] = [
{ text: "synced 104 example dependencies", kind: "ok" },
{ text: "missing file: example/ai-code-demo.tsx", kind: "err" },
{ text: "Failed after 1.2s", kind: "end" },
]
function Term() {
const root = React.useRef<HTMLDivElement>(null)
const [typed, setTyped] = React.useState(COMMAND)
const [lines, setLines] = React.useState<AiTerminalLine[]>(GOOD)
const [status, setStatus] = React.useState<"running" | "done" | "failed">(
"done"
)
const [exit, setExit] = React.useState("Exit 0 · 3.8s")
const turn = React.useRef(0)
useAiLoop(
root,
async ({ sleep }) => {
const fails = turn.current++ % 2 === 1
const script = fails ? BAD : GOOD
setStatus("running")
setLines([])
await typeInto(setTyped, COMMAND, sleep, 34)
await sleep(500)
for (let end = 1; end <= script.length; end++) {
setLines(script.slice(0, end))
await sleep(520)
}
setExit(fails ? "Exit 1 · 1.2s" : "Exit 0 · 3.8s")
setStatus(fails ? "failed" : "done")
await sleep(2600)
},
{ gap: 500 }
)
return (
<div ref={root} style={{ display: "grid", width: "min(100%, 400px)" }}>
<AiTerminal
command={COMMAND}
typed={typed}
lines={lines}
status={status}
exit={exit}
/>
</div>
)
}
export function AiCodeDemo({ only }: { only?: string }) {
return (
<AiDemo
only={only}
tabs={[
{ name: "Stream", node: <Stream /> },
{ name: "Diff", node: <Diff /> },
{ name: "Terminal", node: <Term /> },
]}
/>
)
}
Installation
Usage
import { AiCodeStream, AiDiff, AiTerminal } from "@/components/ui/ai-code"<AiCodeStream
filename="hero.tsx"
status={writing ? "writing" : "saved"}
lines={[
[{ text: "const", kind: "keyword" }, { text: " stagger = " }, { text: "0.05", kind: "number" }],
]}
/>
<AiDiff
filename="hero.tsx"
hunks={hunks}
onResolve={(id, state) => setState(id, state)}
/>
<AiTerminal
command="pnpm build:registry"
lines={[{ text: "wrote public/r, 104 items", kind: "ok" }]}
status="done"
exit="Exit 0 · 3.8s"
/>Code is passed as data: each line is a list of { text, kind } spans, so you can feed it from any tokenizer and nothing is injected as HTML.
Versions
AiCodeStreamis a file being written. Line numbers count up, tokens fade in with syntax colour, a caret follows the last token whilestatusiswriting, and the copy button copies the plain text.AiDiffshows added and removed lines per hunk with Keep and Undo.onResolvefires on press; set that hunk'sstateand the losing lines fade out while the rest settle into plain code. The header counts what is left.AiTerminalshows a command and its output as a live log. The header pill reads Running, then ends onexitin green or red.
Props
AiCodeStream
| Prop | Type | Default | Description |
|---|---|---|---|
filename | string | Shown in the tab. | |
lines | { text, kind? }[][] | The code so far. kind is keyword, function, string, number or comment. | |
status | "writing" | "saved" | "saved" | Writing shows the caret and a blue pill. |
onCopy | () => void | Called after the code is copied. |
AiDiff
| Prop | Type | Default | Description |
|---|---|---|---|
filename | string | Shown in the tab. | |
hunks | { id, header, lines, state? }[] | Each line is { type: "add" | "del" | "ctx", text }. | |
onResolve | (id: string, state: "kept" | "undone") => void | Called from Keep and Undo. |
AiTerminal
| Prop | Type | Default | Description |
|---|---|---|---|
command | string | The command, shown in the header. | |
typed | string | The command as typed so far, for a typing effect. | |
lines | { text, kind? }[] | Output lines. kind is out, ok, err or end. | |
status | "running" | "done" | "failed" | Drives the header pill. | |
exit | string | The pill's text once finished. |