`!`…`` in a command file ran through bash -c with the arguments pasted in and only the hardline checked — for a prompt from the link too, before any mode applied. It is now judged as a bash call of the line in the session's mode and rules and runs only on allow; the arguments are positional parameters and ARGUMENTS in the environment; placeholders are filled in one pass; a substitution has the bash tool's environment and a 10 s limit. Spec: permission/rules.md §6. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
891 lines
46 KiB
TypeScript
891 lines
46 KiB
TypeScript
import type { ScrollBoxRenderable, TextareaRenderable } from "@opentui/core"
|
|
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
|
|
import { createEffect, createMemo, createSignal, on, onCleanup, Show } from "solid-js"
|
|
import { stricterMode, type App as Runtime } from "../app.ts"
|
|
import { basename, resolve } from "node:path"
|
|
import { isLocal } from "../config/paths.ts"
|
|
import type { Mode } from "../config/schema.ts"
|
|
import { levelLabel, type Level } from "../provider/effort.ts"
|
|
import { teamLabel } from "../session/commands.ts"
|
|
import { COMMANDS, findCommand, type CommandCtx } from "./commands.ts"
|
|
import { Dialog, type DialogSpec } from "./components/dialog.tsx"
|
|
import { DisplayPane } from "./components/display_pane.tsx"
|
|
import { Messages, rowId } from "./components/messages.tsx"
|
|
import { cycleTab, effectiveTab, extractBash, extractChanges, extractFiles, extractImages, freshImage, initialNav, isImagePath, resetFollow, stepEntry, type DisplayNavState, type DisplayTab } from "./displays.ts"
|
|
import { placeDisplay, STATUS_FULL_WIDTH, transcriptMode, type TranscriptSetting } from "./layout.ts"
|
|
import { groupRounds, rowIdOf } from "./transcript.ts"
|
|
import { PermissionPrompt } from "./components/permission.tsx"
|
|
import { copiedMessage, copyText, isRemote } from "./clipboard.ts"
|
|
import { QuestionCard } from "./components/question.tsx"
|
|
import { PlanCard } from "./components/plancard.tsx"
|
|
import { PlanPanel } from "./components/plan.tsx"
|
|
import { JobView } from "./components/jobview.tsx"
|
|
import { SubagentView } from "./components/subagent.tsx"
|
|
import { Bus } from "../bus/index.ts"
|
|
import { FocusWatch, noticeSequence, noticeText } from "./notify.ts"
|
|
import { Prompt, type PaletteEntry, type PromptHandle } from "./components/prompt.tsx"
|
|
import { FileIndex } from "../project/files.ts"
|
|
import { attachmentsFor } from "../project/attach.ts"
|
|
import { customCommands, expandCommand, type CustomCommand } from "../project/commands.ts"
|
|
import { skillMessage, slug } from "../skill/index.ts"
|
|
import { keyMatcher, VoiceController } from "../voice/index.ts"
|
|
import { hardlineCommand } from "../permission/hardline.ts"
|
|
import { CONTINUE_PROMPT } from "../session/engine.ts"
|
|
import { bashTool } from "../tool/bash.ts"
|
|
import { MODES } from "../config/schema.ts"
|
|
import { Queued, Spinner } from "./components/spinner.tsx"
|
|
import { mcpWord, StatusBar } from "./components/status.tsx"
|
|
import { currentBranch } from "../git/branch.ts"
|
|
import { Welcome } from "./components/welcome.tsx"
|
|
import { Share, type SharedPrompt } from "../acp/share.ts"
|
|
import { mentionInfo } from "../acp/prompt.ts"
|
|
import { TuiContext, type Ctx } from "./context.ts"
|
|
import { createView, type View } from "./state.ts"
|
|
import { loadTheme, markdownStyle, paintBackground, reasoningStyle, themeNames, type IconSet, type Theme } from "./theme.ts"
|
|
|
|
const CYCLE: Mode[] = ["manual", "edit", "plan"]
|
|
|
|
export function Root(p: { app: Runtime; view: View; theme: Theme; onQuit: () => void; onReload?: (args: string[]) => void }) {
|
|
const renderer = useRenderer()
|
|
const { app, view } = p
|
|
const [theme, setThemeSignal] = createSignal(p.theme)
|
|
let icons: IconSet | undefined = app.loaded.config.icons
|
|
const [background, setBackground] = createSignal(app.loaded.config.theme_background)
|
|
createEffect(() => paintBackground(renderer, theme(), background()))
|
|
const md = createMemo((prev?: ReturnType<typeof markdownStyle>) => {
|
|
prev?.destroy()
|
|
return markdownStyle(theme())
|
|
})
|
|
const thought = createMemo((prev?: ReturnType<typeof reasoningStyle>) => {
|
|
prev?.destroy()
|
|
return reasoningStyle(theme())
|
|
})
|
|
const [dialog, setDialog] = createSignal<DialogSpec>()
|
|
// The engine is not reactive; this signal is bumped whenever its model/mode/effort change.
|
|
const [rev, setRev] = createSignal(0)
|
|
const refresh = () => setRev((n) => n + 1)
|
|
const mode = () => (rev(), app.engine.mode)
|
|
const model = () => (rev(), app.engine.model.ref)
|
|
const effort = () => (rev(), levelLabel(app.engine.model, app.engine.effort))
|
|
// "team 3/4 · 2 working" while the lead has members (team.md, the TUI's status).
|
|
const teamWord = () => (rev(), teamLabel(app.team.team))
|
|
// The status bar follows the MCP servers as they connect (and nothing is said in the transcript).
|
|
onCleanup(app.mcp.onChange(() => refresh()))
|
|
const busy = () => view.state.phase !== "idle"
|
|
const branch = () => (rev(), app.project.gitRoot ? currentBranch(app.project.gitRoot) : undefined)
|
|
// A word in the status bar that goes by itself (a copy): it says something happened without
|
|
// putting a line into the conversation.
|
|
const [flashText, setFlashText] = createSignal<string>()
|
|
let flashTimer: ReturnType<typeof setTimeout> | undefined
|
|
const flash = (text: string, ms = 2500) => {
|
|
setFlashText(text)
|
|
clearTimeout(flashTimer)
|
|
flashTimer = setTimeout(() => setFlashText(undefined), ms)
|
|
}
|
|
onCleanup(() => clearTimeout(flashTimer))
|
|
// A mode changed inside a turn (a plan approved) must reach the status bar; so must a branch the
|
|
// model switched with git.
|
|
app.bus.on((e) => (e.type === "mode" || e.type === "done" || e.type === "team") && refresh())
|
|
app.bus.on((e) => e.type === "flash" && flash(e.text, 6000))
|
|
// The finished-reply notice (notify.ts): a reply that ends, or an answer the agent waits for,
|
|
// while the terminal is not focused — the bell and a desktop notification naming the session.
|
|
const focus = new FocusWatch((ev, fn) => renderer.on(ev, fn))
|
|
/** Raw sequences to the terminal, and the OSC replies it sends back. */
|
|
const writeRaw = (seq: string) => {
|
|
const r = renderer as unknown as { writeOut?: (s: string) => void }
|
|
if (r.writeOut) r.writeOut(seq)
|
|
else process.stdout.write(seq)
|
|
}
|
|
const terminal = { write: writeRaw, subscribeOsc: (h: (sequence: string) => void) => renderer.subscribeOsc(h) }
|
|
const notice = (what: "finished" | "waiting" | "failed") => {
|
|
if (focus.focused || app.loaded.config.notify === false) return
|
|
const id = app.engine.sessionId
|
|
const title = id ? app.store?.session(id)?.title : undefined
|
|
const seq = noticeSequence(noticeText(title, what))
|
|
try {
|
|
writeRaw(seq)
|
|
} catch {}
|
|
}
|
|
app.bus.on((e) => e.type === "done" && e.reason !== "cancelled" && notice(e.reason === "error" ? "failed" : "finished"))
|
|
createEffect(() => (view.state.pending || view.state.question || view.state.plan) && notice("waiting"))
|
|
// A setting changed by the agent, /settings or a command: show it. Theme and icons are drawn here.
|
|
app.bus.on((e) => {
|
|
if (e.type !== "setting") return
|
|
if (e.key === "theme") setThemeSignal(loadTheme(String(e.value), icons).theme)
|
|
if (e.key === "theme_background") setBackground(e.value as "theme" | "terminal")
|
|
if (e.key === "icons") {
|
|
icons = e.value as IconSet
|
|
setThemeSignal(loadTheme(theme().name, icons).theme)
|
|
}
|
|
if (e.key === "displays") setDisplaysEnabled(e.value !== false)
|
|
if (e.key === "transcript") setTranscript((e.value as TranscriptSetting | undefined) ?? "auto")
|
|
refresh()
|
|
})
|
|
app.settings.checks.set("theme", (v) => {
|
|
if (!themeNames().includes(String(v))) throw new Error(`no theme "${v}" — ${themeNames().join(", ")}`)
|
|
})
|
|
let scroll: ScrollBoxRenderable | undefined
|
|
let displayScroll: ScrollBoxRenderable | undefined
|
|
let input: TextareaRenderable | undefined
|
|
let box: PromptHandle | undefined
|
|
const [displaysEnabled, setDisplaysEnabled] = createSignal(app.loaded.config.displays !== false)
|
|
const [displayNav, setDisplayNav] = createSignal<DisplayNavState>(initialNav())
|
|
/** What is selected, as it is copied: a selection in the prompt box in full (a paste placeholder
|
|
* as what it stands for), anything else as it reads. */
|
|
const selectedText = (visible: string) => (visible && input?.hasSelection() && input.getSelectedText() === visible ? (box?.expandedSelection() ?? visible) : visible)
|
|
let quitArmed = 0
|
|
|
|
const dims = useTerminalDimensions()
|
|
// Where the display stands is decided from the terminal's width alone (layout.ts): beside the
|
|
// conversation over the full height, in its place on a narrow terminal, or not at all.
|
|
const [zoomed, setZoomed] = createSignal(false)
|
|
const placement = createMemo(() => placeDisplay({ width: dims().width, enabled: displaysEnabled(), zoomed: zoomed() }))
|
|
const showDisplays = () => placement().mode === "side" || placement().mode === "zoom"
|
|
const [transcript, setTranscript] = createSignal<TranscriptSetting>(app.loaded.config.transcript ?? "auto")
|
|
const compactWanted = createMemo(() => transcriptMode(transcript(), placement().mode) === "compact")
|
|
// What is drawn follows what is wanted one step behind, so the place in the scrollbox can be
|
|
// read off the old rows before they go and found again among the new ones.
|
|
const [compact, setCompact] = createSignal(compactWanted())
|
|
const ctx: Ctx = { app, view, theme, md, thought, dims, compact }
|
|
/** The left column's own size: what stands in it (cards, the prompt) measures itself by this,
|
|
* never by the terminal, which the pane shares. */
|
|
const leftDims = createMemo(() => ({ width: placement().left, height: dims().height }))
|
|
const leftCtx: Ctx = { ...ctx, dims: leftDims }
|
|
/** The transcript's rows change (full ↔ compact): the row at the top stays the row at the top;
|
|
* at the bottom it stays at the bottom. Nothing is run again — both are views of the same items. */
|
|
const switchTranscript = (toCompact: boolean) => {
|
|
const box = scroll
|
|
let target: string | undefined
|
|
let bottom = true
|
|
if (box) {
|
|
bottom = box.scrollTop + box.viewport.height >= box.scrollHeight - 1
|
|
if (!bottom) {
|
|
const top = box.content.getChildren().find((r) => r.id.startsWith("row-") && r.height > 0 && r.y + r.height > box.viewport.y)
|
|
const id = top?.id.slice(4)
|
|
// A call inside a round is found again as its round, and a round as its first call.
|
|
if (id) target = toCompact ? (rowIdOf(groupRounds(view.state.items, { showReasoning: view.state.showReasoning })).get(id) ?? id) : id
|
|
}
|
|
}
|
|
setCompact(toCompact)
|
|
if (!box) return
|
|
let set: number | undefined
|
|
const place = () => {
|
|
if (box.isDestroyed || scroll !== box) return
|
|
// The person scrolled meanwhile: their place now.
|
|
if (set !== undefined && box.scrollTop !== set) return
|
|
if (bottom) box.scrollTo(box.scrollHeight)
|
|
else {
|
|
const row = target ? box.content.findDescendantById(rowId(target)) : undefined
|
|
if (row) box.scrollTo(Math.max(0, row.y - box.content.y))
|
|
}
|
|
set = box.scrollTop
|
|
}
|
|
// After the new rows are laid out — and again once markdown, parsed off the main thread, has
|
|
// its heights.
|
|
for (const ms of [30, 150, 400]) setTimeout(place, ms)
|
|
}
|
|
createEffect(on(compactWanted, (want) => want !== compact() && switchTranscript(want), { defer: true }))
|
|
|
|
// Background jobs: the view's list is the registry's at the start and on every session change
|
|
// (resume, /new), then follows the `job` events.
|
|
const seedJobs = () => view.setJobs(app.jobs().map((j) => app.registry.info(j)))
|
|
seedJobs()
|
|
app.bus.on((e) => e.type === "session" && seedJobs())
|
|
const running = () => app.registry.running(app.jobsSessionId()).length
|
|
// A command job opened from /jobs (its live output), and a subagent entered (its transcript in
|
|
// place of the session's, the prompt box sending to it). One View per entered job, kept: its bus
|
|
// feeds it from the moment it is first entered, its history loaded from the child's messages.
|
|
const [jobPanel, setJobPanel] = createSignal<string>()
|
|
const [entered, setEntered] = createSignal<string>()
|
|
// In a LLeMbas terminal: whether the prompt box takes what is typed now (src/terminal/session.ts).
|
|
createEffect(() => app.terminal?.setAtPrompt(!dialog() && !jobPanel() && !entered()))
|
|
const childViews = new Map<string, View>()
|
|
const enterJob = (id: string) => {
|
|
const job = app.registry.get(app.jobsSessionId(), id)
|
|
if (!job || job.kind !== "subagent") return view.info(`${id} is not a subagent — /jobs lists them`, "warn")
|
|
if (!childViews.has(id)) {
|
|
const v = createView(job.subagent?.bus ?? new Bus())
|
|
v.load(job.subagent?.engine.messages ?? (job.childSessionId && app.store ? app.store.messages(job.childSessionId) : []))
|
|
childViews.set(id, v)
|
|
}
|
|
view.seenJobs(id)
|
|
setEntered(id)
|
|
}
|
|
const leaveJob = () => setEntered(undefined)
|
|
/** What is typed while a subagent is entered goes to it: its inbox while it runs, a new prompt
|
|
* under the same job once it has finished. */
|
|
const sendToJob = (text: string) => {
|
|
const id = entered()!
|
|
const job = app.registry.get(app.jobsSessionId(), id)
|
|
// Spec 3.4.0 §11: a subagent of the tree is read-only; the person speaks through the main agent.
|
|
if (job?.team) return view.info(`${id} is ${job.team}, a subagent of the main agent: its session is read-only — tell the main agent, or /team stop ${job.team}`, "warn")
|
|
if (!job?.subagent) return view.info(`${id} cannot be messaged any more — an earlier process ran it`, "warn")
|
|
if (job.state === "running") {
|
|
job.subagent.send(text)
|
|
flash(`sent to ${id} — it reads it at its next step`)
|
|
} else {
|
|
app.registry.restartSubagent(job)
|
|
childViews.get(id)?.user(text)
|
|
void job.subagent.restart(text)
|
|
flash(`${id} is running again with your message`)
|
|
}
|
|
}
|
|
/** Leaving with jobs running is asked about: `N jobs running — stop them and quit?`. `what`:
|
|
* quit or reload; `then`: what happens once they are stopped (or when none run). */
|
|
const confirmStop = (what: string, then: () => void) => {
|
|
const n = running()
|
|
if (!n) return then()
|
|
const go = () => {
|
|
app.registry.stopAll(app.jobsSessionId())
|
|
then()
|
|
}
|
|
setDialog({
|
|
title: `${n} job${n === 1 ? "" : "s"} running — stop ${n === 1 ? "it" : "them"} and ${what}?`,
|
|
options: [
|
|
{ label: `Stop and ${what}`, value: "yes", description: "a command gets SIGTERM, a subagent is cancelled" },
|
|
{ label: "Cancel", value: "no" },
|
|
],
|
|
hint: `y stop and ${what} · n / esc cancel`,
|
|
keys: [
|
|
{ when: (k) => k.name === "y" && !k.ctrl, run: () => go() },
|
|
{ when: (k) => k.name === "n" && !k.ctrl, run: () => {} },
|
|
],
|
|
onSelect: (v) => v === "yes" && go(),
|
|
})
|
|
}
|
|
const quit = () => confirmStop("quit", () => p.onQuit())
|
|
/** ctrl+b: the foreground command of this step goes to the background now, as it would at its
|
|
* timeout — the call returns with the output so far and the job's id. */
|
|
const backgroundNow = () => {
|
|
const bashRunning = view.state.items.some((it) => it.kind === "tool" && it.name === "bash" && it.status === "running" && !String(it.title ?? "").startsWith("! "))
|
|
if (bashRunning && app.engine.backgroundNow()) flash("moving the command to the background…")
|
|
else flash("no command is running in the foreground")
|
|
}
|
|
|
|
// Voice: the record key, what was heard, replies read aloud.
|
|
const voiceCfg = app.loaded.config.voice
|
|
const recordKey = keyMatcher(voiceCfg?.record_key)
|
|
if (recordKey.warning) view.info(recordKey.warning, "warn")
|
|
const [voiceRev, setVoiceRev] = createSignal(0)
|
|
let meter: ReturnType<typeof setInterval> | undefined
|
|
const voice = new VoiceController(voiceCfg, {
|
|
changed: () => {
|
|
setVoiceRev((n) => n + 1)
|
|
// While recording, the meter and the clock move.
|
|
if (voice.state === "recording" && !meter) meter = setInterval(() => setVoiceRev((n) => n + 1), 150)
|
|
if (voice.state !== "recording" && meter) (clearInterval(meter), (meter = undefined))
|
|
},
|
|
heard: (text) => {
|
|
// Sent as words, never as a command: a transcript that starts with "/" or "!" is still speech.
|
|
if (voiceCfg?.submit === "send" && app.turns.steer(text)) return
|
|
if (voiceCfg?.submit === "send" && !busy()) return void send(text)
|
|
if (!input) return
|
|
// Added at the end, not by setting the whole text: that would turn a paste placeholder in
|
|
// the box into its bare label and lose what it stands for.
|
|
const now = input.plainText
|
|
input.gotoBufferEnd()
|
|
input.insertText(now.trim() && !/\s$/.test(now) ? ` ${text}` : text)
|
|
},
|
|
notice: (m, warn) => view.info(m, warn ? "warn" : undefined),
|
|
})
|
|
onCleanup(() => {
|
|
if (meter) clearInterval(meter)
|
|
void voice.close()
|
|
})
|
|
// A finished reply is read out when replies are spoken.
|
|
app.bus.on((e) => {
|
|
if (e.type !== "done" || e.reason !== "stop" || !voice.speakReplies) return
|
|
const last = [...app.engine.messages].reverse().find((m) => m.role === "assistant")
|
|
const text = last && last.role === "assistant" ? last.parts.map((x) => (x.type === "text" ? x.text : "")).join("") : ""
|
|
if (text.trim()) void voice.speak(text)
|
|
})
|
|
const voiceStatus = () => {
|
|
voiceRev()
|
|
rev()
|
|
if (voice.state === "recording") {
|
|
const bars = " ▁▂▃▄▅▆▇"
|
|
const s = Math.floor(voice.seconds)
|
|
return `● REC ${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")} ${bars[Math.min(7, Math.floor((Math.min(voice.level, 8000) * 7) / 8000))]} ${recordKey.label} stops`
|
|
}
|
|
if (voice.state === "transcribing") return "◉ transcribing"
|
|
if (voice.speaking) return `${theme().icons.speaker} speaking · esc stops`
|
|
if (!voice.canListen && !voice.speakReplies) return ""
|
|
return `${voice.canListen ? `${theme().icons.mic} ${recordKey.label}` : ""}${voice.speakReplies ? `${voice.canListen ? " · " : ""}${theme().icons.speaker} on` : ""}`
|
|
}
|
|
|
|
const cmd: CommandCtx = {
|
|
...ctx,
|
|
voice,
|
|
openDialog: (spec) => setDialog(spec),
|
|
setMode(m: Mode) {
|
|
app.settings.set("mode", m)
|
|
},
|
|
setEffort(e: Level) {
|
|
app.settings.set("effort", e)
|
|
},
|
|
setTheme(name: string) {
|
|
try {
|
|
app.settings.set("theme", name, "global")
|
|
} catch (e) {
|
|
view.info((e as Error).message, "warn")
|
|
}
|
|
},
|
|
setIcons(set: IconSet) {
|
|
app.settings.set("icons", set, "global")
|
|
},
|
|
flash,
|
|
refresh,
|
|
quit,
|
|
reload() {
|
|
if (!p.onReload) return view.info("/reload is not available here", "warn")
|
|
// The new process would not know the jobs; they would run on, orphaned, and their notes be
|
|
// lost — so they are stopped first, after asking.
|
|
confirmStop("reload", () => {
|
|
// Back on this session, with what it was using; everything else comes from the files again.
|
|
const e = app.engine
|
|
const args = [...(isLocal() ? ["-l"] : []), ...(e.sessionId ? ["-s", e.sessionId] : []), "-m", e.model.ref, "--mode", e.mode, "-e", e.effort]
|
|
void app
|
|
.close()
|
|
.catch(() => {})
|
|
.finally(() => {
|
|
app.store?.db.close()
|
|
p.onReload!(args)
|
|
})
|
|
})
|
|
},
|
|
openJob: (id) => setJobPanel(id),
|
|
enterJob,
|
|
setDisplays(action) {
|
|
if (action === "toggle") return toggleDisplay()
|
|
if (action === "off") {
|
|
setDisplaysEnabled(false)
|
|
setZoomed(false)
|
|
return "display off (alt+d or /display on brings it back)"
|
|
}
|
|
setDisplaysEnabled(true)
|
|
// Too narrow for two columns: it opens in the transcript's place.
|
|
setZoomed(true)
|
|
if (action !== "on") selectTab(action)
|
|
const what = action === "on" ? "display" : `display: ${action}`
|
|
return placement().mode === "side" ? `${what} (alt+↑↓ tabs · alt+←→ entry · alt+pgup/pgdn scroll · alt+d hide)` : `${what} — in the transcript's place on this narrow terminal (alt+d: back to the transcript)`
|
|
},
|
|
setTranscript(to) {
|
|
if (to !== "toggle") setTranscript(to)
|
|
else setTranscript(compact() ? "full" : "compact")
|
|
const now = transcriptMode(transcript(), placement().mode)
|
|
return transcript() === "auto" ? `transcript: auto — ${now} now (compact while the display stands beside it)` : `transcript: ${now} (alt+t switches · /transcript auto follows the display)`
|
|
},
|
|
copy: (text: string) => copy(text),
|
|
renderer,
|
|
send: (text: string) => void send(text),
|
|
share: undefined as Share | undefined,
|
|
continueTask: () => continueTask(),
|
|
sendAs: (prompt: string, shown: string, opts?: { model?: string; mode?: string }) => void sendAs(prompt, shown, opts),
|
|
runLine: (line: string) => submit(line),
|
|
runCustom: (name: string, arg: string, typed: string) => {
|
|
const cc = custom().find((x) => x.name === name)
|
|
if (cc) void runCustom(cc, arg, typed)
|
|
return Boolean(cc)
|
|
},
|
|
setInput(text: string) {
|
|
input?.setText(text)
|
|
input?.gotoBufferEnd()
|
|
},
|
|
}
|
|
|
|
const selectTab = (tab: DisplayTab) => setDisplayNav((n) => ({ ...n, tab, pinned: tab !== "live" }))
|
|
/** Alt+D and a bare /display. Beside the conversation: shown ↔ hidden. Too narrow for that:
|
|
* the display in the transcript's place ↔ the transcript (the status bar says it is there). */
|
|
function toggleDisplay(): string {
|
|
if (!displaysEnabled()) {
|
|
setDisplaysEnabled(true)
|
|
setZoomed(true)
|
|
return placement().mode === "side" ? "display shown" : "display (alt+d: back to the transcript)"
|
|
}
|
|
if (placement().mode === "side") {
|
|
setDisplaysEnabled(false)
|
|
setZoomed(false)
|
|
return "display hidden (alt+d shows it)"
|
|
}
|
|
const next = !zoomed()
|
|
setZoomed(next)
|
|
return next ? "display (alt+d: back to the transcript)" : "transcript (alt+d: the display)"
|
|
}
|
|
|
|
const files = new FileIndex(app.project.root)
|
|
const custom = () => customCommands(app.trusted ? app.project.dir : undefined)
|
|
// A skill is also a command, /<its name>, unless a built-in or custom command has the name
|
|
// (then /skill <name> reaches it) — Hermes' rule.
|
|
const skillCommands = () => {
|
|
const taken = new Set(custom().map((c) => c.name))
|
|
return app.skills().filter((s) => !findCommand(slug(s.name)) && !taken.has(slug(s.name)))
|
|
}
|
|
const palette = (): PaletteEntry[] => [
|
|
...COMMANDS.map((c) => ({ name: c.name, args: c.args, description: c.description, source: "builtin" as const })),
|
|
...custom().filter((c) => !findCommand(c.name)).map((c) => ({ name: c.name, description: c.description, source: c.source, args: c.body.includes("$") ? "[args]" : undefined })),
|
|
...skillCommands().map((s) => ({ name: slug(s.name), description: s.description.slice(0, 80), source: "skill" as const, args: "[instruction]" })),
|
|
...app.mcp.prompts().map((m) => ({ name: m.name, description: m.description.slice(0, 80), source: "mcp" as const, args: m.args.length ? m.args.map((a) => `<${a}>`).join(" ") : undefined })),
|
|
]
|
|
|
|
/** Send a prompt: @references attached, snapshots around it. `shown` is what the transcript says.
|
|
* `attachFrom`: where @references are read from, when not all of `text` is the user's — an MCP
|
|
* server's prompt or a skill must not attach ~/.ssh/… by naming it. `given`: a prompt from the web
|
|
* UI, its attachments read already and its turn id its own. */
|
|
const send = (text: string, shown = text, attachFrom = text, given?: Pick<SharedPrompt, "extra" | "attachments" | "turnId">, drawn = shown): Promise<string> => {
|
|
voice.stopSpeaking()
|
|
const atts = given ? [] : attachmentsFor(attachFrom, app.engine.o.toolCtx, app.engine.model.spec.vision === true)
|
|
for (const a of atts) files.used(a.path)
|
|
// `drawn`: what this transcript shows — the box as it looked, a paste placeholder in place of
|
|
// its text. Only here: the session's title, the `prompt` event and everything a server
|
|
// mirrors get `shown`, which holds the words themselves.
|
|
// A picture that was attached is in the display's images tab, by where it is on this disk.
|
|
view.user(drawn, atts.filter((a) => isImagePath(a.path)).map((a) => resolve(app.engine.o.toolCtx.cwd, a.path)))
|
|
setDisplayNav((n) => resetFollow(n))
|
|
if (atts.length) view.info(`attached ${atts.map((a) => (a.image ? `${a.path} (image)` : a.text.includes("not attached") ? `${a.path} (not attached: ${/not attached: ([^)]*)/.exec(a.text)?.[1]})` : a.path)).join(", ")}`)
|
|
if (given?.attachments.length) view.info(`attached ${given.attachments.map((a) => a.name).join(", ")}`)
|
|
scroll?.scrollTo(scroll.scrollHeight)
|
|
const extra = given ? given.extra : atts.flatMap((a) => (a.image ? [a.text, a.image] : [a.text]))
|
|
// Chips for the web UI, when this session is shared: what went with the prompt.
|
|
const attachments = given ? given.attachments : atts.map((a) => mentionInfo(a.path, app.engine.o.toolCtx.cwd))
|
|
return app.turns
|
|
.prompt(text, extra, shown, { ...(given ? { turnId: given.turnId } : {}), attachments })
|
|
.then((reason) => {
|
|
// What was sent during the task and never reached the model: stopped — back into the box,
|
|
// to edit or send; otherwise (queue mode, or a turn that ended first) — sent now. After a
|
|
// tick, so a command's own model and mode (sendAs) are put back first. (A job's note left
|
|
// over the same way is the app's business: app.ts wakes the session with it.)
|
|
const left = app.turns.takeInbox()
|
|
if (!left.length) return reason
|
|
const joined = left.join("\n\n")
|
|
if (reason === "cancelled") {
|
|
const now = (box?.expanded() ?? input?.plainText ?? "").trim()
|
|
input?.setText(now ? `${joined}\n\n${now}` : joined)
|
|
input?.gotoBufferEnd()
|
|
view.info("stopped — what you sent meanwhile is back in the box")
|
|
} else setTimeout(() => void send(joined), 0)
|
|
return reason
|
|
})
|
|
.catch((e) => (view.info((e as Error).message, "warn"), "error"))
|
|
}
|
|
|
|
// The web UI as a second keyboard on this session: shared through the service by itself,
|
|
// or by name with /remote. What it sends runs here as if typed, and is shown as such.
|
|
// What the account's month has cost, in the status bar: read at the start and after a reply,
|
|
// at most once a minute; an instance that cannot say, or nothing priced, leaves nothing there.
|
|
const [spend, setSpend] = createSignal("")
|
|
let spendAt = 0
|
|
const readSpend = (force = false) => {
|
|
if (!force && Date.now() - spendAt < 60_000) return
|
|
spendAt = Date.now()
|
|
void import("../lembas/personal.ts").then((m) => m.accountUsage(5000).then((r) => setSpend(m.spendLabel(r?.usage)))).catch(() => {})
|
|
}
|
|
readSpend(true)
|
|
app.bus.on((e) => e.type === "task" && e.state === "end" && readSpend())
|
|
cmd.setSpend = (text: string) => {
|
|
spendAt = Date.now()
|
|
setSpend(text)
|
|
}
|
|
|
|
const share = new Share(app, {
|
|
prompt: async (input, started) => {
|
|
// Working already: it runs when this turn is done, as a message typed in queue mode
|
|
// would. It used to be refused, and the web UI lost it to an error.
|
|
while (busy() || app.turns.current) await Bun.sleep(150)
|
|
started()
|
|
view.info("↓ from the web UI")
|
|
// Expanded already (a command, @files, uploads); a command's model and mode hold for
|
|
// this prompt only, as when it is typed here.
|
|
if (input.model || input.mode) return sendAs(input.prompt, input.shown, { model: input.model, mode: input.mode, given: input })
|
|
return send(input.prompt, input.shown, "", input)
|
|
},
|
|
action: async (name) => {
|
|
view.info(`↓ /${name} from the web UI`)
|
|
if (name === "compact") {
|
|
const summary = await app.engine.compact()
|
|
view.clear()
|
|
view.info(`compacted in the web UI — the model continues from this summary:\n\n${summary}`)
|
|
return { summary }
|
|
}
|
|
if (name === "undo") {
|
|
const r = app.turns.undo()
|
|
if (r) view.load(app.engine.messages)
|
|
view.info(r ? (r.files.length ? `undone — restored ${r.files.join(", ")}` : "undone — no files had changed") : "nothing to undo in this session")
|
|
return { undone: r ?? null }
|
|
}
|
|
cmd.setMode("plan")
|
|
return { mode: "plan" }
|
|
},
|
|
compact: async () => {
|
|
view.info("compacting… (asked in the web UI)")
|
|
const summary = await app.engine.compact()
|
|
view.clear()
|
|
view.info(`compacted in the web UI — the model continues from this summary:\n\n${summary}`)
|
|
return summary
|
|
},
|
|
deleted: () => {
|
|
app.newSession()
|
|
view.clear()
|
|
view.info("the web UI deleted that session — this is a new one", "warn")
|
|
},
|
|
notice: (text, level) => view.info(text, level),
|
|
changed: () => refresh(),
|
|
rewound: () => view.load(app.engine.messages),
|
|
})
|
|
cmd.share = share
|
|
view.setCardHooks({
|
|
ask: (req, local) => share.ask(req, local),
|
|
question: (req, callId, local) => share.question(req, callId, local),
|
|
plan: (req, callId, local) => share.plan(req, callId, local),
|
|
})
|
|
void share.start()
|
|
onCleanup(() => share.close())
|
|
|
|
const shell = (command: string): boolean | void => {
|
|
if (busy()) return (view.info("still working — esc stops the current reply; !commands wait for it", "warn"), false)
|
|
const hit = hardlineCommand(command, app.engine.o.perm.hardline)
|
|
if (hit) return view.info(`not run — ${hit.description}`, "warn")
|
|
// Not through the engine's events: this is the user's own command, not a model turn, and the
|
|
// view must not go busy for it.
|
|
const id = view.shellStart(command)
|
|
const t0 = performance.now()
|
|
bashTool
|
|
.run({ command, cwd: app.engine.o.toolCtx.cwd }, { ...app.engine.o.toolCtx, signal: new AbortController().signal, bashTimeline: false })
|
|
.then((r) => {
|
|
view.shellEnd(id, r, performance.now() - t0)
|
|
app.engine.pendingContext.push(`<shell command="${command.replaceAll('"', "'")}">\n${r.output}\n</shell>`)
|
|
view.info("the output goes to the model with your next message (ctrl+o shows it here)")
|
|
})
|
|
.catch((e) => view.info(`! failed: ${(e as Error).message}`, "warn"))
|
|
}
|
|
|
|
/** false: refused — the text stays in the box. */
|
|
const submit = (text: string, shown?: string): boolean | void => {
|
|
const t = text.trim()
|
|
// Inside a subagent, what is typed is for it; commands are still the session's.
|
|
if (entered() && !t.startsWith("/")) return void sendToJob(t)
|
|
if (t.startsWith("!") && t.length > 1) return shell(t.slice(1).trim())
|
|
if (t.startsWith("/")) {
|
|
const [name, ...rest] = t.slice(1).split(/\s+/)
|
|
const arg = rest.join(" ")
|
|
const c = findCommand(name ?? "")
|
|
if (c) {
|
|
// Not mid-task: what changes the session under it, and what sends a prompt of its own
|
|
// (that would start a second turn on top of the running one).
|
|
const midTask = ["command", "new", "delete", "compact", "sessions", "model", "undo", "redo", "commit", "diff", "release", "changelog", "init", "checkpoint", "checkpoints", "branch", "reload", "review", "skill"]
|
|
if ((busy() || app.turns.current) && (midTask.includes(c.name) || (c.name === "plan" && arg && arg !== "show"))) return (view.info("wait for the reply to finish (esc stops it)", "warn"), false)
|
|
return void c.run(cmd, arg)
|
|
}
|
|
const cc = custom().find((x) => x.name === name)
|
|
const sk = cc ? undefined : skillCommands().find((s) => slug(s.name) === slug(name ?? ""))
|
|
const mp = cc || sk ? undefined : app.mcp.prompts().find((m) => m.name === name)
|
|
if (!cc && !sk && !mp) return view.info(`no command /${name} — /help lists them`, "warn")
|
|
if (busy() || app.turns.current) return (view.info("still working — esc stops the current reply; commands wait for it", "warn"), false)
|
|
if (mp)
|
|
return void app.mcp
|
|
.promptText(mp, arg)
|
|
.then((text) => void (text.trim() ? sendAs(text, t, { attachFrom: arg }) : view.info(`/${name}: the prompt came back empty`, "warn")))
|
|
.catch((e) => view.info(`/${name}: ${(e as Error).message}`, "warn"))
|
|
if (sk) return void sendAs(skillMessage(sk, arg), t, { attachFrom: arg })
|
|
return void runCustom(cc!, arg, t)
|
|
}
|
|
// While a task runs, a message joins it: at the next step, or after it (queue).
|
|
if (app.turns.steer(t)) return
|
|
if (busy()) return (view.info("still working — esc stops the current reply", "warn"), false)
|
|
// `shown`: the box as it looked, paste placeholders in place of what they stand for — for
|
|
// this transcript alone.
|
|
void send(t, t, t, undefined, shown?.trim() || t)
|
|
}
|
|
|
|
/** The messages waiting to go in, for ↑ in the box. */
|
|
const queueAccess = {
|
|
count: () => app.engine.queued,
|
|
take: (i: number) => app.engine.unqueue(i),
|
|
putBack: (i: number, text: string) => app.engine.putBack(i, text),
|
|
}
|
|
|
|
/** Carry on where it stopped: after esc, a step limit, or an answer that ended too soon. What
|
|
* it had written before a stop is in the history (the engine keeps it), so it can pick up there. */
|
|
const continueTask = () => {
|
|
if (busy() || app.turns.current) return view.info("it is still working — esc stops it; ctrl+g carries on after that", "warn")
|
|
if (!app.engine.messages.length) return view.info("nothing to continue yet — send a prompt first", "warn")
|
|
void send(CONTINUE_PROMPT, "↻ continue")
|
|
}
|
|
|
|
/** Send a prompt with a model and/or mode that hold for this one prompt only. */
|
|
const sendAs = async (prompt: string, shown: string, opts: { model?: string; mode?: string; attachFrom?: string; given?: Parameters<typeof send>[3] } = {}) => {
|
|
const prev = { model: app.engine.model.ref, mode: app.engine.mode, effort: app.engine.effort }
|
|
try {
|
|
if (opts.model) app.switchModel(opts.model, "borrowed")
|
|
if (opts.mode && (MODES as readonly string[]).includes(opts.mode)) app.engine.mode = opts.mode as Mode
|
|
refresh()
|
|
return await send(prompt, shown, opts.attachFrom ?? prompt, opts.given)
|
|
} catch (e) {
|
|
view.info(`${shown.split(" ")[0]}: ${(e as Error).message}`, "warn")
|
|
return "error"
|
|
} finally {
|
|
// The effort as it was too: switching back would set the model's default.
|
|
if (opts.model) app.returnModel(prev)
|
|
app.engine.mode = prev.mode
|
|
refresh()
|
|
}
|
|
}
|
|
|
|
/** A custom command: its expanded body is the prompt; its frontmatter's model and mode hold for
|
|
* this one prompt. */
|
|
const runCustom = (cc: CustomCommand, arg: string, typed: string) =>
|
|
sendAs(expandCommand(cc, arg, app.project.root, app.engine.o.perm.hardline, (line) => app.engine.judgeCommand(line, app.project.root)), typed, {
|
|
// @files come from what was typed, not from the command's own text.
|
|
attachFrom: arg,
|
|
model: cc.model,
|
|
// A project's command may make the mode stricter for its prompt, never looser; your own may.
|
|
mode: cc.source === "project" && cc.mode && (MODES as readonly string[]).includes(cc.mode) ? stricterMode(cc.mode as Mode, app.engine.mode) : cc.mode,
|
|
})
|
|
|
|
const holdToTalk = voiceCfg?.record_mode === "hold"
|
|
let lastPress = 0
|
|
useKeyboard(
|
|
(key) => {
|
|
if (key.eventType === "release") {
|
|
// Hold-to-talk: letting go of the key stops the recording (the modifier may go first).
|
|
if (holdToTalk && voice.state === "recording" && recordKey.released(key)) void voice.toggle()
|
|
return
|
|
}
|
|
// Side display navigation works even while a permission/question/plan card is open so the
|
|
// person can scroll diffs or inspect files/bash output before answering.
|
|
const alt = Boolean(key.meta || (key as { option?: boolean }).option)
|
|
if (alt && !key.ctrl && !dialog() && !jobPanel()) {
|
|
if (key.name === "d") {
|
|
flash(toggleDisplay())
|
|
return key.preventDefault()
|
|
}
|
|
if (key.name === "t") {
|
|
cmd.setTranscript!("toggle")
|
|
flash(`transcript: ${transcriptMode(transcript(), placement().mode)}`)
|
|
return key.preventDefault()
|
|
}
|
|
if (showDisplays()) {
|
|
if (key.name === "up" || key.name === "down") {
|
|
// From the tab that is showing — which may be one the pane went to by itself.
|
|
const shown = effectiveTab(displayNav(), Boolean(view.state.pending?.preview?.diff), freshImage(view.state.items))
|
|
setDisplayNav((n) => cycleTab({ ...n, tab: shown }, key.name === "up" ? -1 : 1))
|
|
return key.preventDefault()
|
|
}
|
|
if (key.name === "left" || key.name === "right") {
|
|
const tab = effectiveTab(displayNav(), Boolean(view.state.pending?.preview?.diff), freshImage(view.state.items))
|
|
if (tab !== "live") {
|
|
const count =
|
|
tab === "files"
|
|
? extractFiles(view.state.items).length
|
|
: tab === "changes"
|
|
? extractChanges(view.state.items, view.state.pending).length
|
|
: tab === "images"
|
|
? extractImages(view.state.items, (x) => x).length
|
|
: extractBash(view.state.items).length
|
|
setDisplayNav((n) => stepEntry(n, tab, key.name === "left" ? -1 : 1, count))
|
|
}
|
|
return key.preventDefault()
|
|
}
|
|
if (key.name === "pageup" || key.name === "pagedown" || key.name === "[" || key.name === "]") {
|
|
const up = key.name === "pageup" || key.name === "["
|
|
// The images tab has nothing to scroll, and the box of the tab before it is gone.
|
|
if (displayScroll && !displayScroll.isDestroyed) displayScroll.scrollBy(up ? -Math.max(1, Math.floor((displayScroll.height || 10) / 2)) : Math.max(1, Math.floor((displayScroll.height || 10) / 2)))
|
|
return key.preventDefault()
|
|
}
|
|
}
|
|
}
|
|
// A card or dialog owns the keyboard: esc there means that card's own thing.
|
|
const overlay = dialog() || jobPanel() || view.state.pending || view.state.question || view.state.plan
|
|
if (!overlay && recordKey.matches(key) && (voice.canListen || voiceCfg)) {
|
|
key.preventDefault()
|
|
// Held down, a key repeats: in hold mode (or any repeat) only the first press counts.
|
|
const now = Date.now()
|
|
const repeat = key.repeated || (holdToTalk && now - lastPress < 500)
|
|
lastPress = now
|
|
if (!repeat) void voice.toggle()
|
|
return
|
|
}
|
|
if (overlay) return keys(key)
|
|
if (key.name === "escape" && voice.state === "recording") {
|
|
void voice.cancel().then(() => view.info("recording cancelled"))
|
|
return key.preventDefault()
|
|
}
|
|
if (key.name === "escape" && voice.speaking) {
|
|
voice.stopSpeaking()
|
|
return key.preventDefault()
|
|
}
|
|
keys(key)
|
|
},
|
|
{ release: holdToTalk },
|
|
)
|
|
|
|
const keys = (key: Parameters<Parameters<typeof useKeyboard>[0]>[0]) => {
|
|
if (dialog() || jobPanel() || view.state.pending || view.state.question || view.state.plan) return
|
|
if (key.name === "escape" && entered()) {
|
|
// Back to the session; the model is not stopped by leaving a subagent.
|
|
leaveJob()
|
|
key.preventDefault()
|
|
} else if (key.name === "escape" && busy()) {
|
|
app.cancel()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "c" && (key.shift || renderer.hasSelection)) {
|
|
// Ctrl+Shift+C (where the terminal passes it on), or Ctrl+C over a selection: copy it.
|
|
const sel = selectedText(renderer.getSelection()?.getSelectedText() ?? "")
|
|
if (sel) copy(sel)
|
|
else flash("nothing selected — drag over text, or /copy the last reply")
|
|
renderer.clearSelection()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "d" && !(input?.plainText ?? "").trim()) {
|
|
// An empty box and ctrl+d: leave, as a shell does.
|
|
quit()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "b") {
|
|
backgroundNow()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "c") {
|
|
// The first press stops the model (if busy); a second within 1.5 s always quits.
|
|
if (Date.now() - quitArmed < 1500) quit()
|
|
else {
|
|
if (busy()) app.cancel()
|
|
quitArmed = Date.now()
|
|
view.info("ctrl+c again to quit")
|
|
}
|
|
key.preventDefault()
|
|
} else if (key.name === "tab" && key.shift) {
|
|
const i = CYCLE.indexOf(app.engine.mode)
|
|
cmd.setMode(CYCLE[(i + 1) % CYCLE.length]!)
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "g") {
|
|
continueTask()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "r") {
|
|
view.toggleReasoning()
|
|
key.preventDefault()
|
|
} else if (key.ctrl && key.name === "o") {
|
|
view.toggleTools()
|
|
key.preventDefault()
|
|
} else if (key.name === "pageup") {
|
|
// Half a screen: a whole one loses the place.
|
|
scroll?.scrollBy(-Math.max(1, Math.floor(scroll.height / 2)))
|
|
key.preventDefault()
|
|
} else if (key.name === "pagedown") {
|
|
scroll?.scrollBy(Math.max(1, Math.floor(scroll.height / 2)))
|
|
key.preventDefault()
|
|
} else if (key.ctrl && (key.name === "up" || key.name === "down")) {
|
|
scroll?.scrollBy(key.name === "up" ? -3 : 3)
|
|
key.preventDefault()
|
|
}
|
|
}
|
|
// What the mouse selects is copied when the button comes up (see clipboard.ts). It is said in
|
|
// the status bar for a moment, never as a line of the transcript: a line there lands in the
|
|
// middle of a reply and splits a thinking block that is still running. Only a copy that could
|
|
// not go anywhere is a transcript line, since it says what to do instead.
|
|
const copy = (text: string) => {
|
|
if (!text) return
|
|
const m = copiedMessage(text.length, copyText(renderer as never, text))
|
|
if (m.warn) view.info(m.text, "warn")
|
|
else flash(m.text)
|
|
}
|
|
const onSelection = (sel: { getSelectedText(): string } | null) => {
|
|
const text = selectedText(sel?.getSelectedText() ?? "")
|
|
if (text.trim()) copy(text)
|
|
}
|
|
renderer.on("selection", onSelection)
|
|
onCleanup(() => renderer.off("selection", onSelection))
|
|
|
|
// The display's header: the session's own words, which the short status bar beside it leaves out.
|
|
const sessionWords = () => ({ model: model(), mode: mode(), effort: effort(), spend: spend(), where: `${isLocal() ? "local " : ""}${basename(app.project.root)}${branch() ? `@${branch()}` : ""}` })
|
|
const pane = (o: { width: number; height: number; zoomed?: boolean }) => (
|
|
<DisplayPane width={o.width} height={o.height} zoomed={o.zoomed} nav={displayNav} onSelectTab={selectTab} scrollRef={(r) => (displayScroll = r)} session={sessionWords} />
|
|
)
|
|
// The display in the transcript's place takes the rows the bottom stack leaves: measured, since
|
|
// the stack's height is its contents'.
|
|
const [zoomRows, setZoomRows] = createSignal(0)
|
|
|
|
return (
|
|
<TuiContext.Provider value={ctx}>
|
|
{/* A row: the left column — the conversation and everything under it — and the display
|
|
pane at the right, over the terminal's full height: beside the prompt and the status bar too. */}
|
|
<box flexDirection="row" width="100%" height="100%">
|
|
<TuiContext.Provider value={leftCtx}>
|
|
<box flexDirection="column" width={placement().left} height="100%" flexShrink={0}>
|
|
<Show
|
|
when={placement().mode === "zoom"}
|
|
fallback={
|
|
<Show
|
|
when={entered()}
|
|
keyed
|
|
fallback={
|
|
<scrollbox
|
|
ref={(r: ScrollBoxRenderable) => (scroll = r)}
|
|
flexGrow={1}
|
|
stickyScroll
|
|
stickyStart="bottom"
|
|
viewportOptions={{ paddingRight: 1 }}
|
|
verticalScrollbarOptions={{ trackOptions: { backgroundColor: theme().colors.panel, foregroundColor: theme().colors.dim } }}
|
|
>
|
|
<Welcome />
|
|
<Messages />
|
|
</scrollbox>
|
|
}
|
|
>
|
|
{(id: string) => <SubagentView id={id} view={childViews.get(id)!} scrollRef={(r) => (scroll = r)} />}
|
|
</Show>
|
|
}
|
|
>
|
|
<box
|
|
flexGrow={1}
|
|
flexDirection="column"
|
|
onSizeChange={function (this: { height: number }) {
|
|
const h = this.height
|
|
// After this layout pass, not inside it.
|
|
if (h > 0 && h !== zoomRows()) setTimeout(() => setZoomRows(h), 0)
|
|
}}
|
|
>
|
|
<Show when={zoomRows() > 0}>{pane({ width: placement().left, height: zoomRows(), zoomed: true })}</Show>
|
|
</box>
|
|
</Show>
|
|
<box flexShrink={0} flexDirection="column">
|
|
<PlanPanel />
|
|
<Show when={view.state.pending}>
|
|
<PermissionPrompt pending={view.state.pending!} />
|
|
</Show>
|
|
<Show when={view.state.question && !view.state.pending}>
|
|
<QuestionCard pending={view.state.question!} />
|
|
</Show>
|
|
<Show when={view.state.plan && !view.state.pending && !view.state.question}>
|
|
<PlanCard pending={view.state.plan!} />
|
|
</Show>
|
|
<Show when={busy() && !view.state.pending && !view.state.question && !view.state.plan}>
|
|
<Spinner />
|
|
</Show>
|
|
<Queued />
|
|
<Prompt focused={() => !dialog() && !jobPanel() && !view.state.pending && !view.state.question && !view.state.plan} busy={busy} commands={palette} files={files} onSubmit={submit} ref={(r) => (input = r)} handle={(h) => (box = h)} remote={() => isRemote(renderer as never)} terminal={terminal} note={(text, warn) => (warn ? view.info(text, "warn") : text.length > 60 ? view.info(text) : flash(text))} queue={queueAccess} onWheel={(dir, lines) => scroll?.scrollBy(dir * lines)} onBackground={backgroundNow} />
|
|
<StatusBar
|
|
mode={mode}
|
|
model={model}
|
|
effort={effort}
|
|
branch={branch()}
|
|
voice={voiceStatus}
|
|
flash={flashText}
|
|
remote={() => (rev(), share.label())}
|
|
spend={spend}
|
|
team={teamWord}
|
|
mcp={() => (rev(), mcpWord(app.mcp.servers.values()))}
|
|
short={() => placement().left < STATUS_FULL_WIDTH}
|
|
hint={() => (placement().mode === "tucked" ? "alt+d display" : "")}
|
|
/>
|
|
</box>
|
|
</box>
|
|
</TuiContext.Provider>
|
|
<Show when={placement().mode === "side"}>{pane({ width: placement().pane, height: dims().height })}</Show>
|
|
<Show when={dialog()}>
|
|
<Dialog spec={dialog()!} close={() => setDialog(undefined)} />
|
|
</Show>
|
|
<Show when={jobPanel()} keyed>
|
|
{(id: string) => <JobView id={id} close={() => setJobPanel(undefined)} />}
|
|
</Show>
|
|
</box>
|
|
</TuiContext.Provider>
|
|
)
|
|
}
|