footer.view.test.tsx 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. /** @jsxImportSource @opentui/solid */
  2. import { expect, test } from "bun:test"
  3. import { BoxRenderable, RGBA, type RootRenderable } from "@opentui/core"
  4. import { testRender } from "@opentui/solid"
  5. import { createSignal } from "solid-js"
  6. import type { FormInfo } from "@opencode-ai/client/promise"
  7. import { Keymap } from "../../src/context/keymap"
  8. import {
  9. RUN_COMMAND_PANEL_ROWS,
  10. RUN_SUBAGENT_PANEL_ROWS,
  11. RunAgentSelectBody,
  12. RunCommandMenuBody,
  13. RunModelSelectBody,
  14. RunQueuedPromptSelectBody,
  15. RunSettingsBody,
  16. RunSkillSelectBody,
  17. RunSubagentSelectBody,
  18. RunVariantSelectBody,
  19. } from "../../src/mini/footer.command"
  20. import { RunFooterView } from "../../src/mini/footer.view"
  21. import { RunEntryContent } from "../../src/mini/scrollback.writer"
  22. import { RUN_THEME_FALLBACK, type RunTheme } from "../../src/mini/theme"
  23. import type {
  24. FooterState,
  25. FooterSubagentState,
  26. FooterSubagentTab,
  27. FooterView,
  28. MiniSettingChange,
  29. MiniSettings,
  30. RunAgent,
  31. RunCommand,
  32. RunInput,
  33. RunPrompt,
  34. RunProvider,
  35. RunTuiConfig,
  36. StreamCommit,
  37. } from "../../src/mini/types"
  38. import { selectedCommand } from "../../src/mini/footer.prompt"
  39. import { RejectField } from "../../src/mini/footer.permission"
  40. import { createTuiResolvedConfig } from "../fixture/tui-runtime"
  41. const tuiConfig = createTuiResolvedConfig()
  42. function command(input: { name: string; description: string; source?: "command" | "mcp" | "skill" }) {
  43. return {
  44. name: input.name,
  45. description: input.description,
  46. source: input.source,
  47. } satisfies RunCommand
  48. }
  49. function model(input: {
  50. id: string
  51. name: string
  52. status?: "active" | "deprecated"
  53. cost?: number
  54. variants?: Record<string, Record<string, never>>
  55. }) {
  56. return {
  57. name: input.name,
  58. cost: {
  59. input: input.cost ?? 1,
  60. },
  61. status: input.status ?? "active",
  62. variants: input.variants,
  63. } satisfies RunProvider["models"][string]
  64. }
  65. function provider() {
  66. return {
  67. id: "opencode",
  68. name: "opencode",
  69. models: {
  70. "gpt-5": model({ id: "gpt-5", name: "GPT-5", variants: { high: {}, minimal: {} } }),
  71. "gpt-free": model({ id: "gpt-free", name: "GPT Free", cost: 0 }),
  72. old: model({ id: "old", name: "Old Model", status: "deprecated" }),
  73. },
  74. } satisfies RunProvider
  75. }
  76. function subagent(input: {
  77. sessionID: string
  78. label: string
  79. description: string
  80. status?: FooterSubagentTab["status"]
  81. }) {
  82. return {
  83. sessionID: input.sessionID,
  84. label: input.label,
  85. description: input.description,
  86. status: input.status ?? "running",
  87. } satisfies FooterSubagentTab
  88. }
  89. function footerState(input: Partial<FooterState> = {}) {
  90. return createSignal<FooterState>({
  91. phase: "idle",
  92. status: "",
  93. notice: "",
  94. model: "gpt-5",
  95. usage: "",
  96. first: false,
  97. interrupt: 0,
  98. exit: 0,
  99. ...input,
  100. })
  101. }
  102. async function renderFooter(
  103. input: {
  104. tuiConfig?: RunTuiConfig
  105. commands?: RunCommand[]
  106. theme?: () => RunTheme
  107. providers?: RunProvider[]
  108. currentAgent?: string
  109. currentModel?: RunInput["model"]
  110. currentVariant?: string
  111. subagents?: FooterSubagentState
  112. width?: number
  113. height?: number
  114. state?: Partial<FooterState>
  115. onCycle?: () => void
  116. onSubmit?: (prompt: RunPrompt) => boolean
  117. view?: FooterView
  118. onFormReply?: (input: unknown) => void
  119. miniSettings?: MiniSettings
  120. mono?: boolean
  121. onStatus?: (status: string) => void
  122. onMiniSettingChange?: (change: MiniSettingChange) => void
  123. } = {},
  124. ) {
  125. const [view, setView] = createSignal<FooterView>(input.view ?? { type: "prompt" })
  126. const [subagents] = createSignal<FooterSubagentState>(
  127. input.subagents ?? { tabs: [], details: {}, permissions: [], forms: [] },
  128. )
  129. const [state, setState] = footerState(input.state)
  130. const config = input.tuiConfig ?? tuiConfig
  131. const [miniSettings] = createSignal<MiniSettings>(
  132. input.miniSettings ?? {
  133. thinking: "hide",
  134. shell_output: "hide",
  135. turn_summary: "show",
  136. footer: "show",
  137. splash: "show",
  138. mono: false,
  139. },
  140. )
  141. function Harness() {
  142. return (
  143. <Keymap.Provider config={config}>
  144. <RunFooterView
  145. directory={() => "/tmp"}
  146. findFiles={async () => []}
  147. agents={() => []}
  148. references={() => []}
  149. commands={() => input.commands ?? []}
  150. providers={() => input.providers}
  151. currentAgent={() => input.currentAgent ?? "Build"}
  152. currentAgentID={() => input.currentAgent?.toLowerCase() ?? "build"}
  153. currentAgentExplicit={() => input.currentAgent !== undefined}
  154. currentModel={() => input.currentModel}
  155. variants={() => []}
  156. currentVariant={() => input.currentVariant}
  157. state={state}
  158. view={view}
  159. subagent={subagents}
  160. theme={input.theme ?? (() => RUN_THEME_FALLBACK)}
  161. mono={input.mono ?? false}
  162. miniSettings={miniSettings}
  163. onSubmit={input.onSubmit ?? (() => true)}
  164. onPermissionReply={() => {}}
  165. onFormReply={(value) => input.onFormReply?.(value)}
  166. onFormCancel={() => {}}
  167. onCycle={input.onCycle ?? (() => {})}
  168. onInterrupt={() => false}
  169. onEditorOpen={async () => undefined}
  170. onInputClear={() => {}}
  171. onExit={() => {}}
  172. onAgentSelect={() => {}}
  173. onModelSelect={() => {}}
  174. onVariantSelect={() => {}}
  175. onRows={() => {}}
  176. onLayout={() => {}}
  177. onStatus={(status) => input.onStatus?.(status)}
  178. onMiniSettingChange={(change) => input.onMiniSettingChange?.(change)}
  179. />
  180. </Keymap.Provider>
  181. )
  182. }
  183. const app = await testRender(
  184. () => (
  185. <box width={input.width ?? 100} height={input.height ?? 8}>
  186. <Harness />
  187. </box>
  188. ),
  189. { width: input.width ?? 100, height: input.height ?? 8, kittyKeyboard: true },
  190. )
  191. return {
  192. ...app,
  193. setView,
  194. setState,
  195. cleanup() {
  196. app.renderer.currentFocusedRenderable?.blur()
  197. app.renderer.currentFocusedEditor?.blur()
  198. app.renderer.destroy()
  199. },
  200. }
  201. }
  202. test("direct footer shows the default model without the fallback agent", async () => {
  203. const app = await renderFooter({ state: { model: "Default model" } })
  204. try {
  205. await app.renderOnce()
  206. const frame = app.captureCharFrame()
  207. expect(frame).toContain("Default model")
  208. expect(frame).not.toContain("Build")
  209. } finally {
  210. app.cleanup()
  211. }
  212. })
  213. test("direct footer preserves a partial multi-field form draft across permission preemption", async () => {
  214. const request: FormInfo = {
  215. id: "frm_preempted",
  216. sessionID: "ses_child",
  217. title: "Deployment",
  218. fields: [
  219. { key: "service", type: "string", title: "Service", required: true },
  220. { key: "notes", type: "string", title: "Notes", required: true },
  221. ],
  222. }
  223. const app = await renderFooter({
  224. height: 16,
  225. view: { type: "form", request },
  226. })
  227. try {
  228. await app.renderOnce()
  229. "api".split("").forEach((key) => app.mockInput.pressKey(key))
  230. app.mockInput.pressEnter()
  231. await app.renderOnce()
  232. "keep this draft".split("").forEach((key) => app.mockInput.pressKey(key))
  233. expect(app.renderer.currentFocusedEditor?.plainText).toBe("keep this draft")
  234. app.setView({
  235. type: "permission",
  236. request: {
  237. id: "per_preempting",
  238. sessionID: "ses_child",
  239. action: "read",
  240. resources: ["src/index.ts"],
  241. },
  242. })
  243. await app.renderOnce()
  244. expect(app.captureCharFrame()).toContain("Permission required")
  245. app.setView({ type: "form", request })
  246. await app.renderOnce()
  247. expect(app.captureCharFrame()).toContain("2/2")
  248. expect(app.renderer.currentFocusedEditor?.plainText).toBe("keep this draft")
  249. app.setView({ type: "prompt" })
  250. await app.renderOnce()
  251. app.setView({ type: "form", request })
  252. await app.renderOnce()
  253. expect(app.captureCharFrame()).toContain("1/2")
  254. expect(app.renderer.currentFocusedEditor?.plainText).toBe("")
  255. } finally {
  256. app.cleanup()
  257. }
  258. })
  259. function expectPaletteList(list: BoxRenderable, selectedIndex: number) {
  260. expect(list.backgroundColor.toInts()).toEqual((RUN_THEME_FALLBACK.footer.shade as RGBA).toInts())
  261. expect((list.getChildren()[selectedIndex] as BoxRenderable).backgroundColor.toInts()).toEqual(
  262. (RUN_THEME_FALLBACK.footer.selected as RGBA).toInts(),
  263. )
  264. }
  265. function child(root: BoxRenderable | RootRenderable, index: number) {
  266. return root.getChildren()[index] as BoxRenderable
  267. }
  268. function boxPath(root: BoxRenderable | RootRenderable, name: string): BoxRenderable[] | undefined {
  269. for (const item of root.getChildren()) {
  270. if (item.constructor.name === name) return root instanceof BoxRenderable ? [root] : []
  271. if (!(item instanceof BoxRenderable)) continue
  272. const path = boxPath(item, name)
  273. if (path) return root instanceof BoxRenderable ? [root, ...path] : path
  274. }
  275. }
  276. function footerComposerFrame(root: BoxRenderable | RootRenderable) {
  277. return boxPath(root, "TextareaRenderable")!.at(-5)!
  278. }
  279. function footerStatusline(root: BoxRenderable | RootRenderable) {
  280. const status = (RUN_THEME_FALLBACK.footer.status as RGBA).toInts()
  281. const boxes = root.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable)
  282. for (const box of boxes) {
  283. if (box.backgroundColor?.toInts().every((value, index) => value === status[index])) return box
  284. boxes.push(...box.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable))
  285. }
  286. throw new Error("Footer statusline not found")
  287. }
  288. function panelMenu(root: BoxRenderable | RootRenderable) {
  289. const panel = child(child(root, 0), 0)
  290. const content = child(panel, 0)
  291. return child(content.getChildren().at(-1) as BoxRenderable, 0)
  292. }
  293. test("direct footer composer area does not adopt footer surface", async () => {
  294. const surface = RGBA.fromHex("#123456")
  295. const [theme, setTheme] = createSignal(RUN_THEME_FALLBACK)
  296. const app = await renderFooter({ theme })
  297. try {
  298. await app.renderOnce()
  299. const area = child(footerComposerFrame(app.renderer.root), 0)
  300. expect(area.backgroundColor.toInts()).not.toEqual(surface.toInts())
  301. setTheme({
  302. ...RUN_THEME_FALLBACK,
  303. footer: {
  304. ...RUN_THEME_FALLBACK.footer,
  305. surface,
  306. },
  307. })
  308. await app.renderOnce()
  309. expect(area.backgroundColor.toInts()).not.toEqual(surface.toInts())
  310. } finally {
  311. app.cleanup()
  312. }
  313. })
  314. test("run entry content updates when live commit text changes", async () => {
  315. const [commit, setCommit] = createSignal<StreamCommit>({
  316. kind: "tool",
  317. text: "I",
  318. phase: "progress",
  319. source: "tool",
  320. messageID: "msg-1",
  321. partID: "part-1",
  322. tool: "shell",
  323. })
  324. const app = await testRender(
  325. () => (
  326. <box width={80} height={4}>
  327. <RunEntryContent commit={commit()} theme={RUN_THEME_FALLBACK} />
  328. </box>
  329. ),
  330. {
  331. width: 80,
  332. height: 4,
  333. },
  334. )
  335. try {
  336. await app.renderOnce()
  337. expect(app.captureCharFrame()).toContain("I")
  338. setCommit({
  339. kind: "tool",
  340. text: "I need to inspect the codebase",
  341. phase: "progress",
  342. source: "tool",
  343. messageID: "msg-1",
  344. partID: "part-1",
  345. tool: "shell",
  346. })
  347. await app.renderOnce()
  348. expect(app.captureCharFrame()).toContain("I need to inspect the codebase")
  349. } finally {
  350. app.renderer.destroy()
  351. }
  352. })
  353. test("run entry content preserves monochrome markdown grammar", async () => {
  354. const [commit, setCommit] = createSignal<StreamCommit>({
  355. kind: "assistant",
  356. text: "• literal\n\n———\n\narrow →",
  357. phase: "progress",
  358. source: "assistant",
  359. messageID: "msg-1",
  360. partID: "part-1",
  361. })
  362. const app = await testRender(
  363. () => (
  364. <box width={60} height={8}>
  365. <RunEntryContent commit={commit()} theme={RUN_THEME_FALLBACK} opts={{ mono: true }} />
  366. </box>
  367. ),
  368. { width: 60, height: 8 },
  369. )
  370. try {
  371. await app.renderOnce()
  372. const rows = app
  373. .captureCharFrame()
  374. .split("\n")
  375. .map((row) => row.trimEnd())
  376. expect(rows).toContain("* literal")
  377. expect(rows).toContain("------")
  378. expect(rows).toContain("arrow ->")
  379. expect(rows.join("\n")).not.toMatch(/[^\x00-\x7f]/)
  380. setCommit({ ...commit(), text: "- Café\n- arrow →\n- third …" })
  381. await app.renderOnce()
  382. expect(app.captureCharFrame()).toContain("- arrow ->")
  383. expect(app.captureCharFrame()).toContain("- third ...")
  384. setCommit({ ...commit(), text: "| A | B |\n| - | - |\n| Café | → |" })
  385. await app.renderOnce()
  386. expect(app.captureCharFrame()).toContain("Caf?")
  387. expect(app.captureCharFrame()).toContain("->")
  388. setCommit({ ...commit(), text: "| A | B |\n| - | - |\n| Café | … |" })
  389. await app.renderOnce()
  390. expect(app.captureCharFrame()).toContain("...")
  391. setCommit({ ...commit(), text: "```\nCafé → …\n```" })
  392. await app.renderOnce()
  393. expect(app.captureCharFrame()).toContain("Caf? -> ...")
  394. expect(app.captureCharFrame()).not.toMatch(/[^\x00-\x7f]/)
  395. } finally {
  396. app.renderer.destroy()
  397. }
  398. })
  399. test("run entry content eagerly renders final monochrome markdown", async () => {
  400. const app = await testRender(
  401. () => (
  402. <box width={60} height={6}>
  403. <RunEntryContent
  404. commit={{ kind: "tool", text: "", phase: "final", source: "tool", tool: "subagent" }}
  405. body={{ type: "markdown", content: "# Café →\n\n```markdown\nCafé →\n```" }}
  406. theme={RUN_THEME_FALLBACK}
  407. opts={{ mono: true }}
  408. />
  409. </box>
  410. ),
  411. { width: 60, height: 6 },
  412. )
  413. try {
  414. await app.renderOnce()
  415. const frame = app.captureCharFrame()
  416. expect(frame).toContain("# Caf? ->")
  417. expect(frame).toContain("Caf? ->")
  418. expect(frame).not.toMatch(/[^\x00-\x7f]/)
  419. } finally {
  420. app.renderer.destroy()
  421. }
  422. })
  423. test("direct command panel renders grouped actions without catalog commands", async () => {
  424. const [commands] = createSignal<RunCommand[] | undefined>([
  425. command({ name: "review", description: "Review code" }),
  426. command({ name: "deploy", description: "Deploy prompt", source: "mcp" }),
  427. command({ name: "internal", description: "Skill command", source: "skill" }),
  428. ])
  429. const [subagents] = createSignal([])
  430. const [variants] = createSignal(["high", "minimal"])
  431. let status = 0
  432. const app = await testRender(
  433. () => (
  434. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  435. <RunCommandMenuBody
  436. theme={() => RUN_THEME_FALLBACK.footer}
  437. commands={commands}
  438. subagents={subagents}
  439. queued={() => []}
  440. variants={variants}
  441. variantCycle="ctrl+t"
  442. onClose={() => {}}
  443. onAgent={() => {}}
  444. onModel={() => {}}
  445. onEditor={() => {}}
  446. onSkill={() => {}}
  447. onSubagent={() => {}}
  448. onQueued={() => {}}
  449. onVariant={() => {}}
  450. onVariantCycle={() => {}}
  451. onStatus={() => status++}
  452. onSettings={() => {}}
  453. onCommand={() => {}}
  454. onNew={() => {}}
  455. onExit={() => {}}
  456. />
  457. </box>
  458. ),
  459. {
  460. width: 100,
  461. height: RUN_COMMAND_PANEL_ROWS,
  462. },
  463. )
  464. try {
  465. await app.renderOnce()
  466. const frame = app.captureCharFrame()
  467. expect(frame).toContain("Commands")
  468. expect(frame).toMatch(/^ {2}Commands/m)
  469. expect(frame).toContain("Search")
  470. expect(frame).toContain("Session")
  471. expect(frame).toContain("Agent")
  472. expect(frame).toContain("Prompt")
  473. expect(frame).toContain("Open editor")
  474. expect(frame).toContain("/editor")
  475. expect(frame).toContain("Show status")
  476. expect(frame).toContain("Compact session")
  477. expect(frame).toContain("/compact")
  478. expect(frame).toContain("Skills")
  479. expect(frame).toContain("/skills")
  480. expect(frame.match(/\bAgent\b/g)?.length).toBe(1)
  481. expect(frame).not.toContain("┌")
  482. expect(frame).not.toContain("┃")
  483. expect(frame).not.toContain("/internal")
  484. expect(frame).not.toContain("Choose model for future turns")
  485. expect(frame).not.toContain("Cycle reasoning effort for future turns")
  486. expect(frame).not.toContain("Review code")
  487. expect(frame).not.toContain("Commands 8")
  488. await app.mockInput.typeText("agent")
  489. await app.renderOnce()
  490. expect(app.captureCharFrame()).toContain("Switch agent")
  491. app.mockInput.pressKey("u", { ctrl: true })
  492. await app.mockInput.typeText("review")
  493. await app.renderOnce()
  494. expect(app.captureCharFrame()).toContain("No results found")
  495. app.mockInput.pressKey("u", { ctrl: true })
  496. await app.mockInput.typeText("deploy")
  497. await app.renderOnce()
  498. expect(app.captureCharFrame()).toContain("No results found")
  499. app.mockInput.pressKey("u", { ctrl: true })
  500. await app.mockInput.typeText("status")
  501. await app.renderOnce()
  502. expect(app.captureCharFrame()).toContain("Show status")
  503. app.mockInput.pressEnter()
  504. expect(status).toBe(1)
  505. } finally {
  506. app.renderer.destroy()
  507. }
  508. })
  509. test("direct settings panel changes Mini transcript preferences", async () => {
  510. const [settings, setSettings] = createSignal<MiniSettings>({
  511. thinking: "hide",
  512. shell_output: "hide",
  513. turn_summary: "show",
  514. footer: "show",
  515. splash: "show",
  516. mono: false,
  517. })
  518. const app = await testRender(
  519. () => (
  520. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  521. <RunSettingsBody
  522. theme={() => RUN_THEME_FALLBACK.footer}
  523. settings={settings}
  524. onClose={() => {}}
  525. onChange={(change) => {
  526. setSettings((current) => ({ ...current, [change.key]: change.value }))
  527. }}
  528. mono
  529. />
  530. </box>
  531. ),
  532. { width: 100, height: RUN_COMMAND_PANEL_ROWS },
  533. )
  534. try {
  535. await app.renderOnce()
  536. const frame = app.captureCharFrame()
  537. expect(frame).toContain("Settings")
  538. expect(frame).toMatch(/^ Settings/m)
  539. expect(frame).toContain("Thinking")
  540. expect(frame).toContain("Shell")
  541. expect(frame).toContain("Turn summary")
  542. expect(frame).toContain("Footer details")
  543. expect(frame).toContain("Splash")
  544. expect(frame).toContain("Monochrome UI")
  545. expect(frame).toContain("left/right change")
  546. expect(frame).not.toMatch(/[^\x00-\x7F]/)
  547. app.mockInput.pressKey("ARROW_RIGHT")
  548. await app.renderOnce()
  549. expect(settings()).toEqual({
  550. thinking: "show",
  551. shell_output: "hide",
  552. turn_summary: "show",
  553. footer: "show",
  554. splash: "show",
  555. mono: false,
  556. })
  557. app.mockInput.pressKey("ARROW_DOWN")
  558. app.mockInput.pressKey("ARROW_DOWN")
  559. app.mockInput.pressKey("ARROW_RIGHT")
  560. await app.renderOnce()
  561. expect(settings()).toEqual({
  562. thinking: "show",
  563. shell_output: "hide",
  564. turn_summary: "hide",
  565. footer: "show",
  566. splash: "show",
  567. mono: false,
  568. })
  569. app.mockInput.pressKey("ARROW_DOWN")
  570. app.mockInput.pressKey("ARROW_DOWN")
  571. app.mockInput.pressKey("ARROW_RIGHT")
  572. await app.renderOnce()
  573. expect(settings().splash).toBe("hide")
  574. app.mockInput.pressKey("ARROW_DOWN")
  575. app.mockInput.pressKey("ARROW_RIGHT")
  576. await app.renderOnce()
  577. expect(settings().mono).toBe(true)
  578. } finally {
  579. app.renderer.destroy()
  580. }
  581. })
  582. test("direct skill panel renders searchable skill list", async () => {
  583. const [commands] = createSignal<RunCommand[] | undefined>([
  584. command({ name: "review", description: "Review code" }),
  585. command({ name: "internal", description: "Skill command", source: "skill" }),
  586. command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
  587. ])
  588. const selected: string[] = []
  589. const app = await testRender(
  590. () => (
  591. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  592. <RunSkillSelectBody
  593. theme={() => RUN_THEME_FALLBACK.footer}
  594. commands={commands}
  595. onClose={() => {}}
  596. onSelect={(name) => {
  597. selected.push(name)
  598. }}
  599. />
  600. </box>
  601. ),
  602. {
  603. width: 100,
  604. height: RUN_COMMAND_PANEL_ROWS,
  605. },
  606. )
  607. try {
  608. await app.renderOnce()
  609. const frame = app.captureCharFrame()
  610. expect(frame).toContain("Skills")
  611. expect(frame).toContain("Search")
  612. expect(frame).toContain("internal")
  613. expect(frame).not.toContain("/internal")
  614. expect(frame).toContain("formatter")
  615. expect(frame).toContain("Apply formatter fixes")
  616. expect(frame).not.toContain("review")
  617. await app.mockInput.typeText("format")
  618. await app.renderOnce()
  619. expect(app.captureCharFrame()).not.toContain("internal")
  620. app.mockInput.pressEnter()
  621. expect(selected).toEqual(["formatter"])
  622. } finally {
  623. app.renderer.destroy()
  624. }
  625. })
  626. test("direct skill panel truncates long descriptions from the end", async () => {
  627. const [commands] = createSignal<RunCommand[] | undefined>([
  628. command({
  629. name: "terminal-control",
  630. description:
  631. "Control and test terminal applications, REPLs, interactive CLIs, shell processes, OpenTUI applications, or other terminal-backed workflows.",
  632. source: "skill",
  633. }),
  634. ])
  635. const app = await testRender(
  636. () => (
  637. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  638. <RunSkillSelectBody
  639. theme={() => RUN_THEME_FALLBACK.footer}
  640. commands={commands}
  641. onClose={() => {}}
  642. onSelect={() => {}}
  643. />
  644. </box>
  645. ),
  646. {
  647. width: 100,
  648. height: RUN_COMMAND_PANEL_ROWS,
  649. },
  650. )
  651. try {
  652. await app.renderOnce()
  653. const frame = app.captureCharFrame()
  654. expect(frame).toContain("terminal-control")
  655. expect(frame).toContain("Control and test terminal applications")
  656. expect(frame).not.toMatch(/application(?:…|\.\.\.)ocess/)
  657. } finally {
  658. app.renderer.destroy()
  659. }
  660. })
  661. test("direct command panel shows subagent entry when available", async () => {
  662. const [commands] = createSignal<RunCommand[] | undefined>([])
  663. const [subagents] = createSignal([subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })])
  664. const [variants] = createSignal<string[]>([])
  665. const app = await testRender(
  666. () => (
  667. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  668. <RunCommandMenuBody
  669. theme={() => RUN_THEME_FALLBACK.footer}
  670. commands={commands}
  671. subagents={subagents}
  672. queued={() => []}
  673. variants={variants}
  674. variantCycle="ctrl+t"
  675. onClose={() => {}}
  676. onAgent={() => {}}
  677. onModel={() => {}}
  678. onEditor={() => {}}
  679. onSkill={() => {}}
  680. onSubagent={() => {}}
  681. onQueued={() => {}}
  682. onVariant={() => {}}
  683. onVariantCycle={() => {}}
  684. onStatus={() => {}}
  685. onSettings={() => {}}
  686. onCommand={() => {}}
  687. onNew={() => {}}
  688. onExit={() => {}}
  689. />
  690. </box>
  691. ),
  692. {
  693. width: 100,
  694. height: RUN_COMMAND_PANEL_ROWS,
  695. },
  696. )
  697. try {
  698. await app.renderOnce()
  699. const frame = app.captureCharFrame()
  700. expect(frame).toContain("View subagents")
  701. expect(frame).toContain("1 active")
  702. } finally {
  703. app.renderer.destroy()
  704. }
  705. })
  706. test("direct command panel keeps completed subagents available", async () => {
  707. const [commands] = createSignal<RunCommand[] | undefined>([])
  708. const [subagents] = createSignal([
  709. subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" }),
  710. ])
  711. const [variants] = createSignal<string[]>([])
  712. const app = await testRender(
  713. () => (
  714. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  715. <RunCommandMenuBody
  716. theme={() => RUN_THEME_FALLBACK.footer}
  717. commands={commands}
  718. subagents={subagents}
  719. queued={() => []}
  720. variants={variants}
  721. variantCycle="ctrl+t"
  722. onClose={() => {}}
  723. onAgent={() => {}}
  724. onModel={() => {}}
  725. onEditor={() => {}}
  726. onSkill={() => {}}
  727. onSubagent={() => {}}
  728. onQueued={() => {}}
  729. onVariant={() => {}}
  730. onVariantCycle={() => {}}
  731. onStatus={() => {}}
  732. onSettings={() => {}}
  733. onCommand={() => {}}
  734. onNew={() => {}}
  735. onExit={() => {}}
  736. />
  737. </box>
  738. ),
  739. {
  740. width: 100,
  741. height: RUN_COMMAND_PANEL_ROWS,
  742. },
  743. )
  744. try {
  745. await app.renderOnce()
  746. const frame = app.captureCharFrame()
  747. expect(frame).toContain("View subagents")
  748. expect(frame).toContain("1 recent")
  749. } finally {
  750. app.renderer.destroy()
  751. }
  752. })
  753. test("direct subagent panel renders active subagents", async () => {
  754. const [tabs] = createSignal([
  755. subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" }),
  756. subagent({ sessionID: "s-2", label: "General", description: "Write migration plan", status: "completed" }),
  757. ])
  758. const [current] = createSignal<string | undefined>("s-1")
  759. let rows = 0
  760. const app = await testRender(
  761. () => (
  762. <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
  763. <RunSubagentSelectBody
  764. theme={() => RUN_THEME_FALLBACK.footer}
  765. tabs={tabs}
  766. current={current}
  767. onClose={() => {}}
  768. onSelect={() => {}}
  769. onRows={(value) => {
  770. rows = value
  771. }}
  772. />
  773. </box>
  774. ),
  775. {
  776. width: 100,
  777. height: RUN_SUBAGENT_PANEL_ROWS,
  778. },
  779. )
  780. try {
  781. await app.renderOnce()
  782. const frame = app.captureCharFrame()
  783. const list = panelMenu(app.renderer.root)
  784. expect(frame).toContain("Select subagent")
  785. expect(frame).toContain("Inspect auth flow")
  786. expect(frame).toContain("Write migration plan")
  787. expect(frame).toContain("done")
  788. expect(frame).not.toContain("┌")
  789. expect(frame).not.toContain("┃")
  790. expectPaletteList(list, 0)
  791. expect(rows).toBe(8)
  792. } finally {
  793. app.renderer.destroy()
  794. }
  795. })
  796. test("direct subagent panel closes when moving up from the first item", async () => {
  797. const [tabs] = createSignal([
  798. subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" }),
  799. subagent({ sessionID: "s-2", label: "General", description: "Write migration plan" }),
  800. ])
  801. const [current] = createSignal<string | undefined>()
  802. let closed = 0
  803. const app = await testRender(
  804. () => (
  805. <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
  806. <RunSubagentSelectBody
  807. theme={() => RUN_THEME_FALLBACK.footer}
  808. tabs={tabs}
  809. current={current}
  810. onClose={() => closed++}
  811. onSelect={() => {}}
  812. />
  813. </box>
  814. ),
  815. { width: 100, height: RUN_SUBAGENT_PANEL_ROWS },
  816. )
  817. try {
  818. await app.renderOnce()
  819. app.mockInput.pressKey("ARROW_DOWN")
  820. app.mockInput.pressKey("ARROW_UP")
  821. expect(closed).toBe(0)
  822. app.mockInput.pressKey("ARROW_UP")
  823. expect(closed).toBe(1)
  824. } finally {
  825. app.renderer.destroy()
  826. }
  827. })
  828. test("direct pending panel shows durable delivery without edit actions", async () => {
  829. const [prompts] = createSignal([
  830. {
  831. messageID: "m-1",
  832. prompt: { text: "fix the auth test", parts: [] },
  833. delivery: "queue" as const,
  834. admittedSeq: 1,
  835. },
  836. ])
  837. const app = await testRender(
  838. () => (
  839. <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
  840. <RunQueuedPromptSelectBody
  841. theme={() => RUN_THEME_FALLBACK.footer}
  842. prompts={prompts}
  843. onClose={() => {}}
  844. />
  845. </box>
  846. ),
  847. { width: 100, height: RUN_SUBAGENT_PANEL_ROWS },
  848. )
  849. try {
  850. await app.renderOnce()
  851. const frame = app.captureCharFrame()
  852. const list = panelMenu(app.renderer.root)
  853. expect(frame).toContain("Pending work")
  854. expect(frame).toContain("fix the auth test")
  855. expect(frame).toContain("queue")
  856. expect(frame).not.toContain("┌")
  857. expect(frame).not.toContain("┃")
  858. expectPaletteList(list, 0)
  859. expect(frame).not.toContain("edit")
  860. expect(frame).not.toContain("remove")
  861. } finally {
  862. app.renderer.destroy()
  863. }
  864. })
  865. // OpenTUI currently crashes Bun in the full `test/cli/run` directory run here.
  866. // Re-enable after the upstream OpenTUI fix lands in this repo.
  867. test.skip("direct footer recreates the frame across command panel transitions", async () => {
  868. const app = await renderFooter()
  869. try {
  870. await app.renderOnce()
  871. for (let index = 0; index < 3; index++) {
  872. const composerFrame = footerComposerFrame(app.renderer.root)
  873. app.mockInput.pressKey("p", { ctrl: true })
  874. await app.renderOnce()
  875. expect(app.captureCharFrame()).toContain("Commands")
  876. expect(footerComposerFrame(app.renderer.root)).not.toBe(composerFrame)
  877. app.mockInput.pressKey("c", { ctrl: true })
  878. await app.renderOnce()
  879. expect(app.captureCharFrame()).not.toContain("Commands")
  880. expect(app.captureCharFrame()).not.toContain("┃")
  881. expect(app.captureCharFrame()).not.toContain("█")
  882. }
  883. } finally {
  884. app.cleanup()
  885. }
  886. })
  887. test.skip("direct footer dispatches leader variant binding only when leader is registered", async () => {
  888. const calls: string[] = []
  889. const app = await renderFooter({
  890. tuiConfig: createTuiResolvedConfig({ keybinds: { leader: "ctrl+x", variant_cycle: "<leader>t" } }),
  891. onCycle: () => calls.push("cycle"),
  892. })
  893. try {
  894. await app.renderOnce()
  895. app.mockInput.pressKey("t")
  896. expect(calls).toEqual([])
  897. app.mockInput.pressKey("x", { ctrl: true })
  898. app.mockInput.pressKey("t")
  899. expect(calls).toEqual(["cycle"])
  900. } finally {
  901. app.cleanup()
  902. }
  903. })
  904. test("direct footer keeps leader variant binding inactive when leader is disabled", async () => {
  905. const calls: string[] = []
  906. const app = await renderFooter({
  907. tuiConfig: createTuiResolvedConfig({ keybinds: { leader: "none", variant_cycle: "<leader>t" } }),
  908. onCycle: () => calls.push("cycle"),
  909. })
  910. try {
  911. await app.renderOnce()
  912. app.mockInput.pressKey("t")
  913. app.mockInput.pressKey("x", { ctrl: true })
  914. app.mockInput.pressKey("t")
  915. expect(calls).toEqual([])
  916. } finally {
  917. app.cleanup()
  918. }
  919. })
  920. test("direct footer submits slash autocomplete selections without dispatching shell completions", async () => {
  921. const submits: RunPrompt[] = []
  922. const app = await renderFooter({
  923. commands: [command({ name: "review", description: "Review code" })],
  924. onSubmit(prompt) {
  925. submits.push(prompt)
  926. return true
  927. },
  928. })
  929. try {
  930. await app.renderOnce()
  931. "/rev".split("").forEach((key) => app.mockInput.pressKey(key))
  932. await app.renderOnce()
  933. app.mockInput.pressEnter()
  934. await app.renderOnce()
  935. "/rev".split("").forEach((key) => app.mockInput.pressKey(key))
  936. await app.renderOnce()
  937. app.mockInput.pressKey("TAB")
  938. await app.renderOnce()
  939. "/re branch".split("").forEach((key) => app.mockInput.pressKey(key))
  940. Array.from({ length: 7 }).forEach(() => app.mockInput.pressKey("ARROW_LEFT"))
  941. app.mockInput.pressKey("v")
  942. await app.renderOnce()
  943. app.mockInput.pressEnter()
  944. await app.renderOnce()
  945. "/nx".split("").forEach((key) => app.mockInput.pressKey(key))
  946. app.mockInput.pressKey("ARROW_LEFT")
  947. app.mockInput.pressKey("e")
  948. await app.renderOnce()
  949. app.mockInput.pressEnter()
  950. await app.renderOnce()
  951. "/n scratch".split("").forEach((key) => app.mockInput.pressKey(key))
  952. Array.from({ length: 8 }).forEach(() => app.mockInput.pressKey("ARROW_LEFT"))
  953. app.mockInput.pressKey("e")
  954. await app.renderOnce()
  955. app.mockInput.pressEnter()
  956. await app.renderOnce()
  957. app.mockInput.pressKey("!")
  958. "/settings".split("").forEach((key) => app.mockInput.pressKey(key))
  959. await app.renderOnce()
  960. app.mockInput.pressEnter()
  961. await app.renderOnce()
  962. expect(submits).toEqual([
  963. { text: "/review ", parts: [], command: { name: "review", arguments: "" } },
  964. { text: "/review ", parts: [], command: { name: "review", arguments: "" } },
  965. { text: "/review branch", parts: [], command: { name: "review", arguments: "branch" } },
  966. { text: "/new ", parts: [] },
  967. { text: "/new ", parts: [] },
  968. ])
  969. expect(app.renderer.currentFocusedEditor?.plainText).toBe("/settings ")
  970. } finally {
  971. app.cleanup()
  972. }
  973. })
  974. test("direct footer slash autocomplete keeps a real skills command", async () => {
  975. const submits: RunPrompt[] = []
  976. const app = await renderFooter({
  977. commands: [
  978. command({ name: "skills", description: "Run the real skills command" }),
  979. command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
  980. ],
  981. onSubmit(prompt) {
  982. submits.push(prompt)
  983. return true
  984. },
  985. })
  986. try {
  987. await app.renderOnce()
  988. "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
  989. await app.renderOnce()
  990. app.mockInput.pressEnter()
  991. await app.renderOnce()
  992. expect(submits).toEqual([{ text: "/skills ", parts: [], command: { name: "skills", arguments: "" } }])
  993. expect(app.captureCharFrame()).not.toContain("Apply formatter fixes")
  994. } finally {
  995. app.cleanup()
  996. }
  997. })
  998. test("direct footer closes settings with ctrl-c instead of arming exit", async () => {
  999. const app = await renderFooter({ height: 20 })
  1000. try {
  1001. await app.renderOnce()
  1002. "/settings".split("").forEach((key) => app.mockInput.pressKey(key))
  1003. await app.renderOnce()
  1004. app.mockInput.pressEnter()
  1005. await app.renderOnce()
  1006. expect(app.captureCharFrame()).toContain("Shell")
  1007. app.mockInput.pressKey("c", { ctrl: true })
  1008. await app.renderOnce()
  1009. expect(app.captureCharFrame()).not.toContain("Shell")
  1010. expect(app.renderer.currentFocusedEditor?.plainText).toBe("")
  1011. } finally {
  1012. app.cleanup()
  1013. }
  1014. })
  1015. test("selectedCommand validates the bound command and refreshes its arguments", () => {
  1016. expect(selectedCommand("/opencode-ts", { name: "opencode-ts", arguments: "", source: "skill" })).toEqual({
  1017. name: "opencode-ts",
  1018. arguments: "",
  1019. source: "skill",
  1020. })
  1021. expect(selectedCommand("/deploy prod", { name: "deploy", arguments: "" })).toEqual({
  1022. name: "deploy",
  1023. arguments: "prod",
  1024. })
  1025. expect(selectedCommand("/other", { name: "deploy", arguments: "" })).toBeUndefined()
  1026. })
  1027. test("direct footer tags skill slash submissions with their catalog source", async () => {
  1028. const submits: RunPrompt[] = []
  1029. const app = await renderFooter({
  1030. commands: [command({ name: "formatter", description: "Apply formatter fixes", source: "skill" })],
  1031. onSubmit(prompt) {
  1032. submits.push(prompt)
  1033. return true
  1034. },
  1035. })
  1036. try {
  1037. await app.renderOnce()
  1038. "/formatter src".split("").forEach((key) => app.mockInput.pressKey(key))
  1039. await app.renderOnce()
  1040. app.mockInput.pressEnter()
  1041. await app.renderOnce()
  1042. expect(submits).toEqual([
  1043. { text: "/formatter src", parts: [], command: { name: "formatter", arguments: "src", source: "skill" } },
  1044. ])
  1045. } finally {
  1046. app.cleanup()
  1047. }
  1048. })
  1049. // OpenTUI currently segfaults Bun while tearing down this composer-to-skill-panel transition.
  1050. // Re-enable after the upstream renderer teardown fix lands.
  1051. test.skip("direct footer skill picker inserts an editable bound skill command", async () => {
  1052. const submits: RunPrompt[] = []
  1053. const app = await renderFooter({
  1054. commands: [command({ name: "new", description: "Skill named new", source: "skill" })],
  1055. onSubmit(prompt) {
  1056. submits.push(prompt)
  1057. return true
  1058. },
  1059. })
  1060. try {
  1061. await app.renderOnce()
  1062. "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
  1063. await app.renderOnce()
  1064. app.mockInput.pressEnter()
  1065. await app.renderOnce()
  1066. expect(app.captureCharFrame()).toContain("Skill named new")
  1067. app.mockInput.pressEnter()
  1068. await app.renderOnce()
  1069. expect(submits).toEqual([])
  1070. expect(app.captureCharFrame()).toContain("/new")
  1071. "task".split("").forEach((key) => app.mockInput.pressKey(key))
  1072. await app.renderOnce()
  1073. app.mockInput.pressEnter()
  1074. await app.renderOnce()
  1075. expect(submits).toEqual([
  1076. { text: "/new task", parts: [], command: { name: "new", arguments: "task", source: "skill" } },
  1077. ])
  1078. } finally {
  1079. app.cleanup()
  1080. }
  1081. })
  1082. // OpenTUI currently segfaults Bun while tearing down this skill-panel close transition.
  1083. // Re-enable after the upstream renderer teardown fix lands.
  1084. test.skip("direct footer clears the synthetic skills draft when the panel closes", async () => {
  1085. const submits: RunPrompt[] = []
  1086. const app = await renderFooter({
  1087. commands: [command({ name: "formatter", description: "Apply formatter fixes", source: "skill" })],
  1088. onSubmit(prompt) {
  1089. submits.push(prompt)
  1090. return true
  1091. },
  1092. })
  1093. try {
  1094. await app.renderOnce()
  1095. "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
  1096. await app.renderOnce()
  1097. app.mockInput.pressEnter()
  1098. await app.renderOnce()
  1099. expect(app.captureCharFrame()).toContain("Apply formatter fixes")
  1100. app.mockInput.pressKey("c", { ctrl: true })
  1101. await app.renderOnce()
  1102. app.mockInput.pressEnter()
  1103. await app.renderOnce()
  1104. expect(submits).toEqual([])
  1105. expect(app.captureCharFrame()).not.toContain("/skills")
  1106. } finally {
  1107. app.cleanup()
  1108. }
  1109. })
  1110. test("direct footer shows authoritative pending work while running", async () => {
  1111. const [state] = createSignal<FooterState>({
  1112. phase: "running",
  1113. status: "",
  1114. notice: "",
  1115. model: "gpt-5",
  1116. usage: "",
  1117. first: false,
  1118. interrupt: 0,
  1119. exit: 0,
  1120. })
  1121. const [view] = createSignal<FooterView>({ type: "prompt" })
  1122. const [subagents] = createSignal<FooterSubagentState>({
  1123. tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
  1124. details: {},
  1125. permissions: [],
  1126. forms: [],
  1127. })
  1128. function Harness() {
  1129. return (
  1130. <Keymap.Provider config={tuiConfig}>
  1131. <RunFooterView
  1132. directory={() => "/tmp"}
  1133. findFiles={async () => []}
  1134. agents={() => []}
  1135. references={() => []}
  1136. commands={() => []}
  1137. providers={() => undefined}
  1138. currentAgent={() => "Build"}
  1139. currentAgentID={() => "build"}
  1140. currentAgentExplicit={() => false}
  1141. currentModel={() => ({
  1142. providerID: "opencode",
  1143. modelID: "a-model-name-long-enough-to-force-responsive-truncation",
  1144. })}
  1145. variants={() => []}
  1146. currentVariant={() => undefined}
  1147. state={state}
  1148. view={view}
  1149. subagent={subagents}
  1150. queuedPrompts={() => [
  1151. {
  1152. messageID: "m-queued",
  1153. prompt: { text: "follow up", parts: [] },
  1154. delivery: "queue",
  1155. admittedSeq: 1,
  1156. },
  1157. ]}
  1158. theme={() => RUN_THEME_FALLBACK}
  1159. miniSettings={() => ({
  1160. thinking: "hide",
  1161. shell_output: "hide",
  1162. turn_summary: "show",
  1163. footer: "show",
  1164. splash: "show",
  1165. mono: false,
  1166. })}
  1167. mono={false}
  1168. onSubmit={() => true}
  1169. onPermissionReply={() => {}}
  1170. onFormReply={() => {}}
  1171. onFormCancel={() => {}}
  1172. onCycle={() => {}}
  1173. onInterrupt={() => false}
  1174. onEditorOpen={async () => undefined}
  1175. onInputClear={() => {}}
  1176. onExit={() => {}}
  1177. onAgentSelect={() => {}}
  1178. onModelSelect={() => {}}
  1179. onVariantSelect={() => {}}
  1180. onRows={() => {}}
  1181. onLayout={() => {}}
  1182. onStatus={() => {}}
  1183. onMiniSettingChange={() => {}}
  1184. />
  1185. </Keymap.Provider>
  1186. )
  1187. }
  1188. const app = await testRender(
  1189. () => (
  1190. <box width={160} height={8}>
  1191. <Harness />
  1192. </box>
  1193. ),
  1194. {
  1195. width: 160,
  1196. height: 8,
  1197. },
  1198. )
  1199. try {
  1200. await app.renderOnce()
  1201. const frame = app.captureCharFrame()
  1202. const transparent = RGBA.fromValues(0, 0, 0, 0).toInts()
  1203. const tinted = (RUN_THEME_FALLBACK.footer.status as RGBA).toInts()
  1204. const statusline = footerStatusline(app.renderer.root)
  1205. const statusItems = statusline.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable)
  1206. const main = statusItems[0]
  1207. const spinner = main.getChildren()[0]
  1208. const background = statusItems[2]
  1209. const queued = statusItems[3]
  1210. const hint = statusItems.at(-1)!
  1211. expect(spinner).toBeDefined()
  1212. expect(frame).toContain("1 pending")
  1213. expect(frame).toContain("ctrl+b background")
  1214. expect(frame).toContain("ctrl+x q 1 pending")
  1215. expect(frame).toContain("↓ subagents")
  1216. expect(frame).toContain("ctrl+p cmd")
  1217. expect(frame).toContain("subagents · ctrl+p cmd")
  1218. expect(frame).not.toContain("1 agent")
  1219. expect(statusline.backgroundColor.toInts()).toEqual(tinted)
  1220. expect(main.backgroundColor.toInts()).toEqual(transparent)
  1221. expect(background.backgroundColor.toInts()).toEqual(transparent)
  1222. expect(queued.backgroundColor.toInts()).toEqual(transparent)
  1223. expect(hint.backgroundColor.toInts()).toEqual(transparent)
  1224. } finally {
  1225. app.renderer.currentFocusedRenderable?.blur()
  1226. app.renderer.currentFocusedEditor?.blur()
  1227. app.renderer.destroy()
  1228. }
  1229. })
  1230. test("direct footer progressively adds model details after the command hint", async () => {
  1231. for (const expected of [
  1232. { width: 24, agent: false, model: false, variant: false },
  1233. { width: 32, agent: false, model: true, variant: false },
  1234. { width: 40, agent: true, model: true, variant: false },
  1235. { width: 48, agent: true, model: true, variant: true },
  1236. ]) {
  1237. const app = await renderFooter({
  1238. currentAgent: "Plan",
  1239. currentVariant: "xhigh",
  1240. state: { model: "GPT-5" },
  1241. width: expected.width,
  1242. })
  1243. try {
  1244. await app.renderOnce()
  1245. const frame = app.captureCharFrame()
  1246. expect({
  1247. width: expected.width,
  1248. command: frame.includes("ctrl+p cmd"),
  1249. agent: frame.includes("Plan"),
  1250. model: frame.includes("GPT-5"),
  1251. variant: frame.includes("xhigh"),
  1252. }).toEqual({ ...expected, command: true })
  1253. } finally {
  1254. app.cleanup()
  1255. }
  1256. }
  1257. })
  1258. test("direct footer keeps commands and active work ahead of usage under width pressure", async () => {
  1259. const app = await renderFooter({
  1260. currentAgent: "Plan",
  1261. subagents: {
  1262. tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
  1263. details: {},
  1264. permissions: [],
  1265. forms: [],
  1266. },
  1267. state: {
  1268. phase: "running",
  1269. model: "a-model-name-long-enough-to-force-responsive-truncation",
  1270. usage: "159.6K (16%) · $4.23",
  1271. },
  1272. width: 80,
  1273. })
  1274. try {
  1275. await app.renderOnce()
  1276. const frame = app.captureCharFrame()
  1277. expect(frame).toContain("Plan")
  1278. expect(frame).toContain("ctrl+b background")
  1279. expect(frame).toContain("↓ subagents")
  1280. expect(frame).toContain("ctrl+p cmd")
  1281. expect(frame).not.toContain("a-model-name")
  1282. expect(frame).not.toContain("159.6K")
  1283. expect(frame).not.toContain("$4.23")
  1284. } finally {
  1285. app.cleanup()
  1286. }
  1287. })
  1288. test("direct footer keeps the command hint at its minimum width", async () => {
  1289. const app = await renderFooter({ state: { phase: "running" }, width: 10 })
  1290. try {
  1291. await app.renderOnce()
  1292. expect(app.captureCharFrame()).toContain("ctrl+p cmd")
  1293. } finally {
  1294. app.cleanup()
  1295. }
  1296. })
  1297. test("direct footer keeps complete status text ahead of the spinner", async () => {
  1298. const app = await renderFooter({
  1299. tuiConfig: createTuiResolvedConfig({ keybinds: { session_interrupt: "none" } }),
  1300. state: { phase: "running" },
  1301. width: 22,
  1302. })
  1303. try {
  1304. await app.renderOnce()
  1305. expect(app.captureCharFrame()).toContain("interrupt")
  1306. expect(boxPath(footerStatusline(app.renderer.root), "SpinnerRenderable")).toBeUndefined()
  1307. } finally {
  1308. app.cleanup()
  1309. }
  1310. })
  1311. test("direct footer always offers backgrounding for a foreground subagent", async () => {
  1312. const app = await renderFooter({
  1313. subagents: {
  1314. tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
  1315. details: {},
  1316. permissions: [],
  1317. forms: [],
  1318. },
  1319. width: 160,
  1320. })
  1321. try {
  1322. await app.renderOnce()
  1323. const frame = app.captureCharFrame()
  1324. expect(frame).toContain("ctrl+b background · ↓ subagents · ctrl+p cmd")
  1325. expect(frame).not.toContain("queued")
  1326. } finally {
  1327. app.cleanup()
  1328. }
  1329. })
  1330. test("direct footer hides the subagent hint when only completed subagents remain", async () => {
  1331. const app = await renderFooter({
  1332. subagents: {
  1333. tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" })],
  1334. details: {},
  1335. permissions: [],
  1336. forms: [],
  1337. },
  1338. width: 160,
  1339. })
  1340. try {
  1341. await app.renderOnce()
  1342. const frame = app.captureCharFrame()
  1343. expect(frame).toContain("ctrl+p cmd")
  1344. expect(frame).not.toContain("↓ subagents")
  1345. } finally {
  1346. app.cleanup()
  1347. }
  1348. })
  1349. test("direct footer omits interrupt key hint when interrupt is unbound", async () => {
  1350. const app = await renderFooter({
  1351. tuiConfig: createTuiResolvedConfig({ keybinds: { session_interrupt: "none", input_clear: "ctrl+l" } }),
  1352. state: { phase: "running" },
  1353. mono: true,
  1354. })
  1355. try {
  1356. await app.renderOnce()
  1357. const frame = app.captureCharFrame()
  1358. const statusline = frame.split("\n").find((line) => line.includes("interrupt"))
  1359. expect(frame).toContain("interrupt")
  1360. expect(frame).not.toContain("ctrl+l")
  1361. expect(statusline).toMatch(/^\S/)
  1362. } finally {
  1363. app.cleanup()
  1364. }
  1365. })
  1366. test("direct footer shows full usage metadata when room is available", async () => {
  1367. const app = await renderFooter({
  1368. state: { usage: "159.6K (16%) · $4.23" },
  1369. })
  1370. try {
  1371. await app.renderOnce()
  1372. const frame = app.captureCharFrame()
  1373. expect(frame).toContain("159.6K (16%) · $4.23")
  1374. } finally {
  1375. app.cleanup()
  1376. }
  1377. })
  1378. test("direct footer omits usage when it would fill the statusline", async () => {
  1379. const app = await renderFooter({
  1380. state: { phase: "running", model: "GPT-5.6 SoL", usage: "8.4K (1%) · $0.01" },
  1381. currentVariant: "high",
  1382. mono: true,
  1383. width: 66,
  1384. })
  1385. try {
  1386. await app.renderOnce()
  1387. const frame = app.captureCharFrame()
  1388. expect(frame).toContain("esc interrupt")
  1389. expect(frame).toContain("GPT-5.6 SoL high")
  1390. expect(frame).toContain("ctrl+p cmd")
  1391. expect(frame).not.toContain("8.4K")
  1392. } finally {
  1393. app.cleanup()
  1394. }
  1395. })
  1396. test("direct footer hides routine activity and shows explicit notices", async () => {
  1397. let status = ""
  1398. const app = await renderFooter({
  1399. state: { usage: "159.6K (16%) · $4.23" },
  1400. currentAgent: "Plan",
  1401. miniSettings: {
  1402. thinking: "hide",
  1403. shell_output: "hide",
  1404. turn_summary: "show",
  1405. footer: "hide",
  1406. splash: "show",
  1407. mono: true,
  1408. },
  1409. mono: true,
  1410. onStatus: (value) => (status = value),
  1411. width: 160,
  1412. })
  1413. try {
  1414. await app.renderOnce()
  1415. const initial = app.captureCharFrame()
  1416. expect(initial).toContain("ctrl+p cmd")
  1417. expect(initial).not.toContain("Plan")
  1418. expect(initial).not.toContain("gpt-5")
  1419. expect(initial).not.toContain("159.6K")
  1420. app.setState((state) => ({ ...state, phase: "running", status: "assistant responding" }))
  1421. await app.renderOnce()
  1422. const changed = app.captureCharFrame()
  1423. const statusline = footerStatusline(app.renderer.root)
  1424. expect(changed).not.toContain("running")
  1425. expect(changed).not.toContain("assistant responding")
  1426. expect(changed).not.toContain("interrupt")
  1427. expect(changed).not.toContain("gpt-5")
  1428. expect(changed).not.toContain("159.6K")
  1429. expect(boxPath(statusline, "SpinnerRenderable")).toBeUndefined()
  1430. app.mockInput.pressKey("p", { ctrl: true })
  1431. await app.renderOnce()
  1432. await app.mockInput.typeText("status")
  1433. app.mockInput.pressEnter()
  1434. expect(status).toBe("running - agent Plan - gpt-5 - 159.6K (16%) - $4.23")
  1435. app.setState((state) => ({ ...state, notice: "variant high" }))
  1436. await app.renderOnce()
  1437. expect(app.captureCharFrame()).toContain("variant high")
  1438. } finally {
  1439. app.cleanup()
  1440. }
  1441. })
  1442. test("direct footer does not label normal mode as build", async () => {
  1443. const app = await renderFooter()
  1444. try {
  1445. await app.renderOnce()
  1446. const statusline = app
  1447. .captureCharFrame()
  1448. .split("\n")
  1449. .find((line) => line.includes("cmd"))
  1450. expect(statusline).toBeDefined()
  1451. expect(statusline).not.toContain("BUILD")
  1452. } finally {
  1453. app.cleanup()
  1454. }
  1455. })
  1456. test("direct permission rejection submits through keymap return binding", async () => {
  1457. let text = ""
  1458. const submits: string[] = []
  1459. function Harness() {
  1460. return (
  1461. <Keymap.Provider config={tuiConfig}>
  1462. <RejectField
  1463. theme={RUN_THEME_FALLBACK.footer}
  1464. text=""
  1465. disabled={false}
  1466. onChange={(input) => {
  1467. text = input
  1468. }}
  1469. onConfirm={() => {
  1470. submits.push(text)
  1471. }}
  1472. onCancel={() => {}}
  1473. />
  1474. </Keymap.Provider>
  1475. )
  1476. }
  1477. const app = await testRender(
  1478. () => (
  1479. <box width={100} height={18}>
  1480. <Harness />
  1481. </box>
  1482. ),
  1483. { width: 100, height: 18, kittyKeyboard: true },
  1484. )
  1485. try {
  1486. await app.renderOnce()
  1487. "retry".split("").forEach((key) => app.mockInput.pressKey(key))
  1488. await app.renderOnce()
  1489. expect(app.captureCharFrame()).toContain("retry")
  1490. app.mockInput.pressEnter()
  1491. await app.renderOnce()
  1492. expect(submits).toEqual(["retry"])
  1493. } finally {
  1494. app.renderer.currentFocusedRenderable?.blur()
  1495. app.renderer.currentFocusedEditor?.blur()
  1496. app.renderer.destroy()
  1497. }
  1498. })
  1499. test("direct model panel renders current model selector", async () => {
  1500. const [providers] = createSignal<RunProvider[] | undefined>([
  1501. provider(),
  1502. { id: "openai", name: "OpenAI", models: { "gpt-5": model({ id: "gpt-5", name: "GPT-5" }) } },
  1503. ])
  1504. const [current] = createSignal<RunInput["model"]>({ providerID: "opencode", modelID: "gpt-5" })
  1505. const app = await testRender(
  1506. () => (
  1507. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  1508. <RunModelSelectBody
  1509. theme={() => RUN_THEME_FALLBACK.footer}
  1510. providers={providers}
  1511. current={current}
  1512. onClose={() => {}}
  1513. onSelect={() => {}}
  1514. />
  1515. </box>
  1516. ),
  1517. {
  1518. width: 100,
  1519. height: RUN_COMMAND_PANEL_ROWS,
  1520. },
  1521. )
  1522. try {
  1523. await app.renderOnce()
  1524. const frame = app.captureCharFrame()
  1525. const list = panelMenu(app.renderer.root)
  1526. expect(frame).toContain("Select model")
  1527. expect(frame).toContain("Search")
  1528. expect(frame).toContain("opencode")
  1529. expect(frame).toContain("GPT-5")
  1530. expect(frame).toContain("current")
  1531. expect(frame).toContain("GPT Free")
  1532. expect(frame).toContain("Free")
  1533. expect(frame).not.toContain("┌")
  1534. expect(frame).not.toContain("┃")
  1535. expect(frame).not.toContain("Old Model")
  1536. expectPaletteList(list, 2)
  1537. "gpt-5".split("").forEach((key) => app.mockInput.pressKey(key))
  1538. await app.renderOnce()
  1539. const search = app.captureCharFrame()
  1540. expect(search.match(/GPT-5/g)).toHaveLength(2)
  1541. expect(search).toContain("opencode")
  1542. expect(search).toContain("OpenAI")
  1543. } finally {
  1544. app.renderer.destroy()
  1545. }
  1546. })
  1547. test("direct agent panel shows eligible agents and marks the current agent", async () => {
  1548. const [agents] = createSignal<RunAgent[]>([
  1549. { id: "build", name: "Build", description: "Build software", mode: "all", hidden: false },
  1550. { id: "review", name: "Review", description: "Review changes", mode: "primary", hidden: false },
  1551. { id: "explore", name: "Explore", mode: "subagent", hidden: false },
  1552. { id: "secret", name: "Secret", mode: "all", hidden: true },
  1553. ])
  1554. const [current] = createSignal("review")
  1555. let selected: string | undefined
  1556. const app = await testRender(
  1557. () => (
  1558. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  1559. <RunAgentSelectBody
  1560. theme={() => RUN_THEME_FALLBACK.footer}
  1561. agents={agents}
  1562. current={current}
  1563. onClose={() => {}}
  1564. onSelect={(agent) => (selected = agent)}
  1565. />
  1566. </box>
  1567. ),
  1568. {
  1569. width: 100,
  1570. height: RUN_COMMAND_PANEL_ROWS,
  1571. },
  1572. )
  1573. try {
  1574. await app.renderOnce()
  1575. const frame = app.captureCharFrame()
  1576. expect(frame).toContain("Select agent")
  1577. expect(frame).toContain("build")
  1578. expect(frame).toContain("review")
  1579. expect(frame).toContain("Review changes")
  1580. expect(frame).toContain("current")
  1581. expect(frame).not.toContain("explore")
  1582. expect(frame).not.toContain("secret")
  1583. app.mockInput.pressEnter()
  1584. expect(selected).toBe("review")
  1585. } finally {
  1586. app.renderer.destroy()
  1587. }
  1588. })
  1589. test("direct variant panel renders current variant selector", async () => {
  1590. const [variants] = createSignal(["high", "minimal"])
  1591. const [current] = createSignal<string | undefined>("high")
  1592. const app = await testRender(
  1593. () => (
  1594. <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
  1595. <RunVariantSelectBody
  1596. theme={() => RUN_THEME_FALLBACK.footer}
  1597. variants={variants}
  1598. current={current}
  1599. onClose={() => {}}
  1600. onSelect={() => {}}
  1601. />
  1602. </box>
  1603. ),
  1604. {
  1605. width: 100,
  1606. height: RUN_COMMAND_PANEL_ROWS,
  1607. },
  1608. )
  1609. try {
  1610. await app.renderOnce()
  1611. const frame = app.captureCharFrame()
  1612. const list = panelMenu(app.renderer.root)
  1613. expect(frame).toContain("Select variant")
  1614. expect(frame).toContain("Default")
  1615. expect(frame).toContain("high")
  1616. expect(frame).toContain("minimal")
  1617. expect(frame).toContain("current")
  1618. expect(frame).not.toContain("┌")
  1619. expect(frame).not.toContain("┃")
  1620. expectPaletteList(list, 1)
  1621. } finally {
  1622. app.renderer.destroy()
  1623. }
  1624. })