run: make minimal mode more minimal (#31227)
This commit is contained in:
parent
914a643ab2
commit
07808bea12
39 changed files with 3109 additions and 930 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
RunCommandMenuBody,
|
||||
RunModelSelectBody,
|
||||
RunQueuedPromptSelectBody,
|
||||
RunSkillSelectBody,
|
||||
RunSubagentSelectBody,
|
||||
RunVariantSelectBody,
|
||||
} from "@/cli/cmd/run/footer.command"
|
||||
|
|
@ -155,13 +156,23 @@ async function renderFooter(
|
|||
tuiConfig?: RunTuiConfig
|
||||
commands?: RunCommand[]
|
||||
theme?: () => RunTheme
|
||||
providers?: RunProvider[]
|
||||
currentModel?: RunInput["model"]
|
||||
currentVariant?: string
|
||||
subagents?: FooterSubagentState
|
||||
backgroundSubagents?: boolean
|
||||
width?: number
|
||||
height?: number
|
||||
state?: Partial<FooterState>
|
||||
onCycle?: () => void
|
||||
onSubmit?: (prompt: RunPrompt) => boolean
|
||||
} = {},
|
||||
) {
|
||||
const [view] = createSignal<FooterView>({ type: "prompt" })
|
||||
const [subagents] = createSignal<FooterSubagentState>({ tabs: [], details: {}, permissions: [], questions: [] })
|
||||
const state = footerState()
|
||||
const [subagents] = createSignal<FooterSubagentState>(
|
||||
input.subagents ?? { tabs: [], details: {}, permissions: [], questions: [] },
|
||||
)
|
||||
const state = footerState(input.state)
|
||||
const config = input.tuiConfig ?? tuiConfig
|
||||
let offKeymap: (() => void) | undefined
|
||||
|
||||
|
|
@ -178,16 +189,16 @@ async function renderFooter(
|
|||
agents={() => []}
|
||||
resources={() => []}
|
||||
commands={() => input.commands ?? []}
|
||||
providers={() => undefined}
|
||||
currentModel={() => undefined}
|
||||
providers={() => input.providers}
|
||||
currentModel={() => input.currentModel}
|
||||
variants={() => []}
|
||||
currentVariant={() => undefined}
|
||||
currentVariant={() => input.currentVariant}
|
||||
state={state}
|
||||
view={view}
|
||||
subagent={subagents}
|
||||
theme={input.theme ?? (() => RUN_THEME_FALLBACK)}
|
||||
tuiConfig={config}
|
||||
backgroundSubagents={true}
|
||||
backgroundSubagents={input.backgroundSubagents ?? true}
|
||||
agent="opencode"
|
||||
onSubmit={input.onSubmit ?? (() => true)}
|
||||
onPermissionReply={() => {}}
|
||||
|
|
@ -195,6 +206,7 @@ async function renderFooter(
|
|||
onQuestionReject={() => {}}
|
||||
onCycle={input.onCycle ?? (() => {})}
|
||||
onInterrupt={() => false}
|
||||
onEditorOpen={async () => undefined}
|
||||
onInputClear={() => {}}
|
||||
onExit={() => {}}
|
||||
onModelSelect={() => {}}
|
||||
|
|
@ -210,11 +222,11 @@ async function renderFooter(
|
|||
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<box width={100} height={8}>
|
||||
<box width={input.width ?? 100} height={input.height ?? 8}>
|
||||
<Harness />
|
||||
</box>
|
||||
),
|
||||
{ width: 100, height: 8, kittyKeyboard: true },
|
||||
{ width: input.width ?? 100, height: input.height ?? 8, kittyKeyboard: true },
|
||||
)
|
||||
|
||||
return {
|
||||
|
|
@ -229,7 +241,14 @@ async function renderFooter(
|
|||
}
|
||||
}
|
||||
|
||||
test("direct footer updates composer background when theme changes", async () => {
|
||||
function expectPaletteList(list: BoxRenderable, selectedIndex: number) {
|
||||
expect(list.backgroundColor.toInts()).toEqual((RUN_THEME_FALLBACK.footer.shade as RGBA).toInts())
|
||||
expect((list.getChildren()[selectedIndex] as BoxRenderable).backgroundColor.toInts()).toEqual(
|
||||
(RUN_THEME_FALLBACK.footer.selected as RGBA).toInts(),
|
||||
)
|
||||
}
|
||||
|
||||
test("direct footer composer area does not adopt footer surface", async () => {
|
||||
const surface = RGBA.fromHex("#123456")
|
||||
const [theme, setTheme] = createSignal(RUN_THEME_FALLBACK)
|
||||
const app = await renderFooter({ theme })
|
||||
|
|
@ -248,7 +267,7 @@ test("direct footer updates composer background when theme changes", async () =>
|
|||
})
|
||||
await app.renderOnce()
|
||||
|
||||
expect(area.backgroundColor.toInts()).toEqual(surface.toInts())
|
||||
expect(area.backgroundColor.toInts()).not.toEqual(surface.toInts())
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
|
|
@ -319,6 +338,8 @@ test("direct command panel renders grouped command palette", async () => {
|
|||
variantCycle="ctrl+t"
|
||||
onClose={() => {}}
|
||||
onModel={() => {}}
|
||||
onEditor={() => {}}
|
||||
onSkill={() => {}}
|
||||
onSubagent={() => {}}
|
||||
onQueued={() => {}}
|
||||
onVariant={() => {}}
|
||||
|
|
@ -341,17 +362,17 @@ test("direct command panel renders grouped command palette", async () => {
|
|||
|
||||
expect(frame).toContain("Commands")
|
||||
expect(frame).toContain("Search")
|
||||
expect(frame).toContain("Suggested")
|
||||
expect(frame).toContain("Switch model")
|
||||
expect(frame).toContain("Variant cycle")
|
||||
expect(frame).toContain("ctrl+t")
|
||||
expect(frame).toContain("Switch model variant")
|
||||
expect(frame).toContain("Session")
|
||||
expect(frame).toContain("New session")
|
||||
expect(frame).toContain("/new")
|
||||
expect(frame).toContain("Project Commands")
|
||||
expect(frame).toContain("review")
|
||||
expect(frame).toContain("/review")
|
||||
expect(frame).toContain("Agent")
|
||||
expect(frame).toContain("Prompt")
|
||||
expect(frame).toContain("Open editor")
|
||||
expect(frame).toContain("/editor")
|
||||
expect(frame).toContain("Switch model")
|
||||
expect(frame).toContain("Skills")
|
||||
expect(frame).toContain("/skills")
|
||||
expect(frame.match(/\bAgent\b/g)?.length).toBe(1)
|
||||
expect(frame).not.toContain("┌")
|
||||
expect(frame).not.toContain("┃")
|
||||
expect(frame).not.toContain("/internal")
|
||||
expect(frame).not.toContain("Choose model for future turns")
|
||||
expect(frame).not.toContain("Cycle reasoning effort for future turns")
|
||||
|
|
@ -362,6 +383,85 @@ test("direct command panel renders grouped command palette", async () => {
|
|||
}
|
||||
})
|
||||
|
||||
test("direct skill panel renders searchable skill list", async () => {
|
||||
const [commands] = createSignal<RunCommand[] | undefined>([
|
||||
command({ name: "review", description: "Review code" }),
|
||||
command({ name: "internal", description: "Skill command", source: "skill" }),
|
||||
command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
|
||||
])
|
||||
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<box width={100} height={RUN_COMMAND_PANEL_ROWS}>
|
||||
<RunSkillSelectBody
|
||||
theme={() => RUN_THEME_FALLBACK.footer}
|
||||
commands={commands}
|
||||
onClose={() => {}}
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</box>
|
||||
),
|
||||
{
|
||||
width: 100,
|
||||
height: RUN_COMMAND_PANEL_ROWS,
|
||||
},
|
||||
)
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("Skills")
|
||||
expect(frame).toContain("Search")
|
||||
expect(frame).toContain("internal")
|
||||
expect(frame).not.toContain("/internal")
|
||||
expect(frame).toContain("formatter")
|
||||
expect(frame).toContain("Apply formatter fixes")
|
||||
expect(frame).not.toContain("review")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct skill panel truncates long descriptions from the end", async () => {
|
||||
const [commands] = createSignal<RunCommand[] | undefined>([
|
||||
command({
|
||||
name: "terminal-control",
|
||||
description:
|
||||
"Control and test terminal applications, REPLs, interactive CLIs, shell processes, OpenTUI applications, or other terminal-backed workflows.",
|
||||
source: "skill",
|
||||
}),
|
||||
])
|
||||
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<box width={100} height={RUN_COMMAND_PANEL_ROWS}>
|
||||
<RunSkillSelectBody
|
||||
theme={() => RUN_THEME_FALLBACK.footer}
|
||||
commands={commands}
|
||||
onClose={() => {}}
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</box>
|
||||
),
|
||||
{
|
||||
width: 100,
|
||||
height: RUN_COMMAND_PANEL_ROWS,
|
||||
},
|
||||
)
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("terminal-control")
|
||||
expect(frame).toContain("Control and test terminal applications")
|
||||
expect(frame).not.toMatch(/application(?:…|\.\.\.)ocess/)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct command panel shows subagent entry when available", async () => {
|
||||
const [commands] = createSignal<RunCommand[] | undefined>([])
|
||||
const [subagents] = createSignal([subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })])
|
||||
|
|
@ -379,6 +479,8 @@ test("direct command panel shows subagent entry when available", async () => {
|
|||
variantCycle="ctrl+t"
|
||||
onClose={() => {}}
|
||||
onModel={() => {}}
|
||||
onEditor={() => {}}
|
||||
onSkill={() => {}}
|
||||
onSubagent={() => {}}
|
||||
onQueued={() => {}}
|
||||
onVariant={() => {}}
|
||||
|
|
@ -406,6 +508,54 @@ test("direct command panel shows subagent entry when available", async () => {
|
|||
}
|
||||
})
|
||||
|
||||
test("direct command panel keeps completed subagents available", async () => {
|
||||
const [commands] = createSignal<RunCommand[] | undefined>([])
|
||||
const [subagents] = createSignal([
|
||||
subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" }),
|
||||
])
|
||||
const [variants] = createSignal<string[]>([])
|
||||
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<box width={100} height={RUN_COMMAND_PANEL_ROWS}>
|
||||
<RunCommandMenuBody
|
||||
theme={() => RUN_THEME_FALLBACK.footer}
|
||||
commands={commands}
|
||||
subagents={subagents}
|
||||
queued={() => []}
|
||||
variants={variants}
|
||||
variantCycle="ctrl+t"
|
||||
onClose={() => {}}
|
||||
onModel={() => {}}
|
||||
onEditor={() => {}}
|
||||
onSkill={() => {}}
|
||||
onSubagent={() => {}}
|
||||
onQueued={() => {}}
|
||||
onVariant={() => {}}
|
||||
onVariantCycle={() => {}}
|
||||
onCommand={() => {}}
|
||||
onNew={() => {}}
|
||||
onExit={() => {}}
|
||||
/>
|
||||
</box>
|
||||
),
|
||||
{
|
||||
width: 100,
|
||||
height: RUN_COMMAND_PANEL_ROWS,
|
||||
},
|
||||
)
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("View subagents")
|
||||
expect(frame).toContain("1 recent")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct subagent panel renders active subagents", async () => {
|
||||
const [tabs] = createSignal([
|
||||
subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" }),
|
||||
|
|
@ -438,11 +588,15 @@ test("direct subagent panel renders active subagents", async () => {
|
|||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
const list = app.renderer.root.findDescendantById("run-direct-footer-subagent-list") as BoxRenderable
|
||||
|
||||
expect(frame).toContain("Select subagent")
|
||||
expect(frame).toContain("Inspect auth flow")
|
||||
expect(frame).toContain("Write migration plan")
|
||||
expect(frame).toContain("done")
|
||||
expect(frame).not.toContain("┌")
|
||||
expect(frame).not.toContain("┃")
|
||||
expectPaletteList(list, 0)
|
||||
expect(rows).toBe(8)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
|
|
@ -471,25 +625,41 @@ test("direct queued prompt panel renders pending prompt actions", async () => {
|
|||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
expect(app.captureCharFrame()).toContain("Queued prompts")
|
||||
expect(app.captureCharFrame()).toContain("fix the auth test")
|
||||
expect(app.captureCharFrame()).toContain("queued")
|
||||
const frame = app.captureCharFrame()
|
||||
const list = app.renderer.root.findDescendantById("run-direct-footer-queued-list") as BoxRenderable
|
||||
|
||||
expect(frame).toContain("Queued prompts")
|
||||
expect(frame).toContain("fix the auth test")
|
||||
expect(frame).toContain("queued")
|
||||
expect(frame).not.toContain("┌")
|
||||
expect(frame).not.toContain("┃")
|
||||
expectPaletteList(list, 0)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
// OpenTUI currently segfaults when the full footer view suite creates several
|
||||
// keymap-backed test renderers in one process. Re-enable after the runtime fix.
|
||||
test.skip("direct footer opens command panel through keymap binding", async () => {
|
||||
// OpenTUI currently crashes Bun in the full `test/cli/run` directory run here.
|
||||
// Re-enable after the upstream OpenTUI fix lands in this repo.
|
||||
test.skip("direct footer recreates the frame across command panel transitions", async () => {
|
||||
const app = await renderFooter()
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressKey("p", { ctrl: true })
|
||||
await app.renderOnce()
|
||||
|
||||
expect(app.captureCharFrame()).toContain("Commands")
|
||||
for (let index = 0; index < 3; index++) {
|
||||
const composerFrame = app.renderer.root.findDescendantById("run-direct-footer-composer-frame") as BoxRenderable
|
||||
app.mockInput.pressKey("p", { ctrl: true })
|
||||
await app.renderOnce()
|
||||
|
||||
expect(app.captureCharFrame()).toContain("Commands")
|
||||
expect(app.renderer.root.findDescendantById("run-direct-footer-composer-frame")).not.toBe(composerFrame)
|
||||
app.mockInput.pressKey("c", { ctrl: true })
|
||||
await app.renderOnce()
|
||||
expect(app.captureCharFrame()).not.toContain("Commands")
|
||||
expect(app.captureCharFrame()).not.toContain("┃")
|
||||
expect(app.captureCharFrame()).not.toContain("█")
|
||||
}
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
|
|
@ -596,6 +766,104 @@ test("direct footer submits slash autocomplete selections without dispatching sh
|
|||
}
|
||||
})
|
||||
|
||||
test("direct footer slash autocomplete keeps a real skills command", async () => {
|
||||
const submits: RunPrompt[] = []
|
||||
const app = await renderFooter({
|
||||
commands: [
|
||||
command({ name: "skills", description: "Run the real skills command" }),
|
||||
command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
|
||||
],
|
||||
onSubmit(prompt) {
|
||||
submits.push(prompt)
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
"/skills".split("").forEach((key) => app.mockInput.pressKey(key))
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(submits).toEqual([{ text: "/skills ", parts: [], command: { name: "skills", arguments: "" } }])
|
||||
expect(app.captureCharFrame()).not.toContain("Apply formatter fixes")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
// OpenTUI currently segfaults Bun while tearing down this composer-to-skill-panel transition.
|
||||
// Re-enable after the upstream renderer teardown fix lands.
|
||||
test.skip("direct footer skill picker inserts an editable bound skill command", async () => {
|
||||
const submits: RunPrompt[] = []
|
||||
const app = await renderFooter({
|
||||
commands: [command({ name: "new", description: "Skill named new", source: "skill" })],
|
||||
onSubmit(prompt) {
|
||||
submits.push(prompt)
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
"/skills".split("").forEach((key) => app.mockInput.pressKey(key))
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(app.captureCharFrame()).toContain("Skill named new")
|
||||
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(submits).toEqual([])
|
||||
expect(app.captureCharFrame()).toContain("/new")
|
||||
|
||||
"task".split("").forEach((key) => app.mockInput.pressKey(key))
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(submits).toEqual([{ text: "/new task", parts: [], command: { name: "new", arguments: "task" } }])
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
// OpenTUI currently segfaults Bun while tearing down this skill-panel close transition.
|
||||
// Re-enable after the upstream renderer teardown fix lands.
|
||||
test.skip("direct footer clears the synthetic skills draft when the panel closes", async () => {
|
||||
const submits: RunPrompt[] = []
|
||||
const app = await renderFooter({
|
||||
commands: [command({ name: "formatter", description: "Apply formatter fixes", source: "skill" })],
|
||||
onSubmit(prompt) {
|
||||
submits.push(prompt)
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
"/skills".split("").forEach((key) => app.mockInput.pressKey(key))
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(app.captureCharFrame()).toContain("Apply formatter fixes")
|
||||
|
||||
app.mockInput.pressKey("c", { ctrl: true })
|
||||
await app.renderOnce()
|
||||
app.mockInput.pressEnter()
|
||||
await app.renderOnce()
|
||||
|
||||
expect(submits).toEqual([])
|
||||
expect(app.captureCharFrame()).not.toContain("/skills")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct footer shows editable prompts and additional queued work while running", async () => {
|
||||
const [state] = createSignal<FooterState>({
|
||||
phase: "running",
|
||||
|
|
@ -630,7 +898,10 @@ test("direct footer shows editable prompts and additional queued work while runn
|
|||
resources={() => []}
|
||||
commands={() => []}
|
||||
providers={() => undefined}
|
||||
currentModel={() => undefined}
|
||||
currentModel={() => ({
|
||||
providerID: "opencode",
|
||||
modelID: "a-model-name-long-enough-to-force-responsive-truncation",
|
||||
})}
|
||||
variants={() => []}
|
||||
currentVariant={() => undefined}
|
||||
state={state}
|
||||
|
|
@ -649,6 +920,7 @@ test("direct footer shows editable prompts and additional queued work while runn
|
|||
onQuestionReject={() => {}}
|
||||
onCycle={() => {}}
|
||||
onInterrupt={() => false}
|
||||
onEditorOpen={async () => undefined}
|
||||
onInputClear={() => {}}
|
||||
onExit={() => {}}
|
||||
onModelSelect={() => {}}
|
||||
|
|
@ -676,10 +948,34 @@ test("direct footer shows editable prompts and additional queued work while runn
|
|||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
expect(app.captureCharFrame()).toContain("interrupt • 1 agent ctrl+x down • ctrl+b background • 1 queued ctrl+x q")
|
||||
expect(app.captureCharFrame()).toContain("2 queued")
|
||||
expect(app.captureCharFrame()).not.toContain("to view")
|
||||
expect(app.captureCharFrame()).not.toContain("edit/remove")
|
||||
const frame = app.captureCharFrame()
|
||||
const transparent = RGBA.fromValues(0, 0, 0, 0).toInts()
|
||||
const tinted = (RUN_THEME_FALLBACK.footer.status as RGBA).toInts()
|
||||
const accent = (RUN_THEME_FALLBACK.footer.statusAccent as RGBA).toInts()
|
||||
const statusline = app.renderer.root.findDescendantById("run-direct-footer-statusline") as BoxRenderable
|
||||
const mode = app.renderer.root.findDescendantById("run-direct-footer-statusline-mode") as BoxRenderable
|
||||
const main = app.renderer.root.findDescendantById("run-direct-footer-statusline-main") as BoxRenderable
|
||||
const spinner = app.renderer.root.findDescendantById("run-direct-footer-status-spinner")
|
||||
const model = app.renderer.root.findDescendantById("run-direct-footer-statusline-model") as BoxRenderable
|
||||
const queued = app.renderer.root.findDescendantById("run-direct-footer-statusline-queued") as BoxRenderable
|
||||
const hint = app.renderer.root.findDescendantById("run-direct-footer-statusline-hint") as BoxRenderable
|
||||
|
||||
expect(spinner).toBeDefined()
|
||||
expect(frame).toContain("a-model-name-long-enough-to-force-responsive-truncation")
|
||||
expect(frame).toContain("3 queued")
|
||||
expect(frame).toContain("ctrl+b background")
|
||||
expect(frame).toContain("ctrl+x q 3 queued")
|
||||
expect(frame).toContain("ctrl+x down subagents")
|
||||
expect(frame).toContain("ctrl+p cmd")
|
||||
expect(frame).toContain("a-model-name-long-enough-to-force-responsive-truncation")
|
||||
expect(frame).toContain("subagents · ctrl+p cmd")
|
||||
expect(frame).not.toContain("1 agent")
|
||||
expect(statusline.backgroundColor.toInts()).toEqual(tinted)
|
||||
expect(mode.backgroundColor.toInts()).toEqual(accent)
|
||||
expect(main.backgroundColor.toInts()).toEqual(transparent)
|
||||
expect(model.backgroundColor.toInts()).toEqual(transparent)
|
||||
expect(queued.backgroundColor.toInts()).toEqual(transparent)
|
||||
expect(hint.backgroundColor.toInts()).toEqual(transparent)
|
||||
} finally {
|
||||
app.renderer.currentFocusedRenderable?.blur()
|
||||
app.renderer.currentFocusedEditor?.blur()
|
||||
|
|
@ -688,6 +984,110 @@ test("direct footer shows editable prompts and additional queued work while runn
|
|||
}
|
||||
})
|
||||
|
||||
test("direct footer separates a lone context hint from model and command hint", async () => {
|
||||
const app = await renderFooter({
|
||||
providers: [provider()],
|
||||
currentModel: { providerID: "opencode", modelID: "gpt-5" },
|
||||
currentVariant: "xhigh",
|
||||
subagents: {
|
||||
tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
|
||||
details: {},
|
||||
permissions: [],
|
||||
questions: [],
|
||||
},
|
||||
backgroundSubagents: false,
|
||||
width: 160,
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("GPT-5")
|
||||
expect(frame).toContain("xhigh · ctrl+x down subagents · ctrl+p cmd")
|
||||
expect(frame).not.toContain("ctrl+b background")
|
||||
expect(frame).not.toContain("queued")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct footer hides the subagent hint when only completed subagents remain", async () => {
|
||||
const app = await renderFooter({
|
||||
providers: [provider()],
|
||||
currentModel: { providerID: "opencode", modelID: "gpt-5" },
|
||||
currentVariant: "xhigh",
|
||||
subagents: {
|
||||
tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" })],
|
||||
details: {},
|
||||
permissions: [],
|
||||
questions: [],
|
||||
},
|
||||
backgroundSubagents: false,
|
||||
width: 160,
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("GPT-5")
|
||||
expect(frame).toContain("xhigh · ctrl+p cmd")
|
||||
expect(frame).not.toContain("ctrl+x down subagents")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct footer omits interrupt key hint when interrupt is unbound", async () => {
|
||||
const app = await renderFooter({
|
||||
tuiConfig: createTuiResolvedConfig({ keybinds: { session_interrupt: "none", input_clear: "ctrl+l" } }),
|
||||
state: { phase: "running" },
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("interrupt")
|
||||
expect(frame).not.toContain("ctrl+l")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct footer shows full usage metadata when room is available", async () => {
|
||||
const app = await renderFooter({
|
||||
state: { usage: "159.6K (16%) · $4.23" },
|
||||
})
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
|
||||
expect(frame).toContain("159.6K (16%) · $4.23")
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct footer mode label keeps left padding without a status pill", async () => {
|
||||
const app = await renderFooter()
|
||||
|
||||
try {
|
||||
await app.renderOnce()
|
||||
const statusline = app
|
||||
.captureCharFrame()
|
||||
.split("\n")
|
||||
.find((line) => line.includes("BUILD") && line.includes("cmd"))
|
||||
|
||||
expect(statusline).toBeDefined()
|
||||
expect(statusline?.startsWith(" BUILD ")).toBe(true)
|
||||
} finally {
|
||||
app.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test("direct question body separates single-select checkmark from label", async () => {
|
||||
const request = {
|
||||
id: "question-1",
|
||||
|
|
@ -876,6 +1276,7 @@ test("direct model panel renders current model selector", async () => {
|
|||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
const list = app.renderer.root.findDescendantById("run-direct-footer-model-list") as BoxRenderable
|
||||
|
||||
expect(frame).toContain("Select model")
|
||||
expect(frame).toContain("Search")
|
||||
|
|
@ -884,7 +1285,10 @@ test("direct model panel renders current model selector", async () => {
|
|||
expect(frame).toContain("current")
|
||||
expect(frame).toContain("GPT Free")
|
||||
expect(frame).toContain("Free")
|
||||
expect(frame).not.toContain("┌")
|
||||
expect(frame).not.toContain("┃")
|
||||
expect(frame).not.toContain("Old Model")
|
||||
expectPaletteList(list, 2)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
|
|
@ -915,12 +1319,16 @@ test("direct variant panel renders current variant selector", async () => {
|
|||
try {
|
||||
await app.renderOnce()
|
||||
const frame = app.captureCharFrame()
|
||||
const list = app.renderer.root.findDescendantById("run-direct-footer-variant-list") as BoxRenderable
|
||||
|
||||
expect(frame).toContain("Select variant")
|
||||
expect(frame).toContain("Default")
|
||||
expect(frame).toContain("high")
|
||||
expect(frame).toContain("minimal")
|
||||
expect(frame).toContain("current")
|
||||
expect(frame).not.toContain("┌")
|
||||
expect(frame).not.toContain("┃")
|
||||
expectPaletteList(list, 1)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
|
|
|
|||
35
packages/opencode/test/cli/run/footer.width.test.ts
Normal file
35
packages/opencode/test/cli/run/footer.width.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { footerWidthPolicy } from "@/cli/cmd/run/footer.width"
|
||||
|
||||
describe("run footer width", () => {
|
||||
test("preserves shared dialog and statusline breakpoints", () => {
|
||||
const narrow = footerWidthPolicy(79)
|
||||
expect(narrow.dialog.narrow).toBe(true)
|
||||
expect(narrow.statusline.showActivityMeta).toBe(false)
|
||||
expect(narrow.statusline.showCommandHint).toBe(true)
|
||||
expect(narrow.statusline.showContextHints).toBe(false)
|
||||
expect(narrow.statusline.contextHintLimit).toBe(0)
|
||||
expect(narrow.statusline.showModel).toBe(false)
|
||||
|
||||
const command = footerWidthPolicy(65)
|
||||
expect(command.statusline.showCommandHint).toBe(false)
|
||||
|
||||
const commandHint = footerWidthPolicy(66)
|
||||
expect(commandHint.statusline.showCommandHint).toBe(true)
|
||||
|
||||
const compact = footerWidthPolicy(80)
|
||||
expect(compact.dialog.narrow).toBe(false)
|
||||
expect(compact.statusline.showActivityMeta).toBe(true)
|
||||
expect(compact.statusline.showContextHints).toBe(true)
|
||||
expect(compact.statusline.contextHintLimit).toBe(1)
|
||||
expect(compact.statusline.showModel).toBe(false)
|
||||
|
||||
const model = footerWidthPolicy(120)
|
||||
expect(model.statusline.contextHintLimit).toBe(2)
|
||||
expect(model.statusline.showModel).toBe(true)
|
||||
|
||||
const spacious = footerWidthPolicy(150)
|
||||
expect(spacious.statusline.contextHintLimit).toBeUndefined()
|
||||
expect(spacious.statusline.showModel).toBe(true)
|
||||
})
|
||||
})
|
||||
101
packages/opencode/test/cli/run/prompt.editor.test.ts
Normal file
101
packages/opencode/test/cli/run/prompt.editor.test.ts
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { realignEditorPromptParts, resolveEditorSlashValue } from "@/cli/cmd/run/prompt.editor"
|
||||
import type { RunPromptPart } from "@/cli/cmd/run/types"
|
||||
|
||||
describe("run prompt editor helpers", () => {
|
||||
test("strips the local /editor command from the initial editor text", () => {
|
||||
expect(resolveEditorSlashValue("/editor")).toBe("")
|
||||
expect(resolveEditorSlashValue("/editor draft message")).toBe("draft message")
|
||||
expect(resolveEditorSlashValue("/editor first line\nsecond line")).toBe("first line\nsecond line")
|
||||
})
|
||||
|
||||
test("realigns file and agent parts after external editing", () => {
|
||||
const filePart = {
|
||||
type: "file",
|
||||
mime: "text/plain",
|
||||
filename: "src/app.ts",
|
||||
url: "file:///src/app.ts",
|
||||
source: {
|
||||
type: "file",
|
||||
path: "src/app.ts",
|
||||
text: {
|
||||
start: 0,
|
||||
end: 11,
|
||||
value: "@src/app.ts",
|
||||
},
|
||||
},
|
||||
} satisfies RunPromptPart
|
||||
const agentPart = {
|
||||
type: "agent",
|
||||
name: "helper",
|
||||
source: {
|
||||
start: 12,
|
||||
end: 19,
|
||||
value: "@helper",
|
||||
},
|
||||
} satisfies RunPromptPart
|
||||
const parts = [filePart, agentPart]
|
||||
|
||||
expect(realignEditorPromptParts("Please check @helper before @src/app.ts", parts)).toEqual([
|
||||
{
|
||||
...filePart,
|
||||
source: {
|
||||
...filePart.source,
|
||||
text: {
|
||||
...filePart.source.text,
|
||||
start: 28,
|
||||
end: 39,
|
||||
value: "@src/app.ts",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
...agentPart,
|
||||
source: {
|
||||
start: 13,
|
||||
end: 20,
|
||||
value: "@helper",
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("drops parts whose virtual text was deleted", () => {
|
||||
const filePart = {
|
||||
type: "file",
|
||||
mime: "text/plain",
|
||||
filename: "src/app.ts",
|
||||
url: "file:///src/app.ts",
|
||||
source: {
|
||||
type: "file",
|
||||
path: "src/app.ts",
|
||||
text: {
|
||||
start: 0,
|
||||
end: 11,
|
||||
value: "@src/app.ts",
|
||||
},
|
||||
},
|
||||
} satisfies RunPromptPart
|
||||
const agentPart = {
|
||||
type: "agent",
|
||||
name: "helper",
|
||||
source: {
|
||||
start: 12,
|
||||
end: 19,
|
||||
value: "@helper",
|
||||
},
|
||||
} satisfies RunPromptPart
|
||||
const parts = [filePart, agentPart]
|
||||
|
||||
expect(realignEditorPromptParts("Only @helper remains", parts)).toEqual([
|
||||
{
|
||||
...agentPart,
|
||||
source: {
|
||||
start: 5,
|
||||
end: 12,
|
||||
value: "@helper",
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
@ -206,6 +206,22 @@ describe("run runtime queue", () => {
|
|||
await task
|
||||
})
|
||||
|
||||
test("shell mode does not emit a turn duration summary", async () => {
|
||||
const ui = footer()
|
||||
|
||||
const task = runPromptQueue({
|
||||
footer: ui.api,
|
||||
run: async () => {
|
||||
ui.api.close()
|
||||
},
|
||||
})
|
||||
|
||||
ui.submit("ls", "shell")
|
||||
await task
|
||||
|
||||
expect(ui.events.some((event) => event.type === "turn.duration")).toBe(false)
|
||||
})
|
||||
|
||||
test("preserves whitespace for initial input", async () => {
|
||||
const ui = footer()
|
||||
const seen: string[] = []
|
||||
|
|
|
|||
238
packages/opencode/test/cli/run/runtime.test.ts
Normal file
238
packages/opencode/test/cli/run/runtime.test.ts
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
import { afterEach, describe, expect, mock, spyOn, test } from "bun:test"
|
||||
import { OpencodeClient } from "@opencode-ai/sdk/v2"
|
||||
import { runInteractiveMode } from "@/cli/cmd/run/runtime"
|
||||
import type { FooterApi, RunProvider } from "@/cli/cmd/run/types"
|
||||
|
||||
type SessionMessage = NonNullable<Awaited<ReturnType<OpencodeClient["session"]["messages"]>>["data"]>[number]
|
||||
|
||||
const provider: RunProvider = {
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
source: "api",
|
||||
env: [],
|
||||
options: {},
|
||||
models: {
|
||||
"gpt-5": {
|
||||
id: "gpt-5",
|
||||
providerID: "openai",
|
||||
api: {
|
||||
id: "openai",
|
||||
url: "https://openai.test",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
name: "Little Frank",
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: true,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: {
|
||||
text: true,
|
||||
audio: false,
|
||||
image: false,
|
||||
video: false,
|
||||
pdf: false,
|
||||
},
|
||||
output: {
|
||||
text: true,
|
||||
audio: false,
|
||||
image: false,
|
||||
video: false,
|
||||
pdf: false,
|
||||
},
|
||||
interleaved: false,
|
||||
},
|
||||
cost: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cache: {
|
||||
read: 0,
|
||||
write: 0,
|
||||
},
|
||||
},
|
||||
limit: {
|
||||
context: 128000,
|
||||
output: 8192,
|
||||
},
|
||||
status: "active",
|
||||
options: {},
|
||||
headers: {},
|
||||
release_date: "2026-01-01",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const transportProviders: RunProvider[][] = []
|
||||
|
||||
function defer<T>() {
|
||||
let resolve!: (value: T | PromiseLike<T>) => void
|
||||
const promise = new Promise<T>((done) => {
|
||||
resolve = done
|
||||
})
|
||||
return { promise, resolve }
|
||||
}
|
||||
|
||||
function ok<T>(data: T) {
|
||||
return Promise.resolve({
|
||||
data,
|
||||
error: undefined,
|
||||
request: new Request("https://opencode.test"),
|
||||
response: new Response(),
|
||||
})
|
||||
}
|
||||
|
||||
function footer(): FooterApi {
|
||||
let closed = false
|
||||
const closes = new Set<() => void>()
|
||||
|
||||
const notify = () => {
|
||||
for (const fn of closes) fn()
|
||||
}
|
||||
|
||||
return {
|
||||
get isClosed() {
|
||||
return closed
|
||||
},
|
||||
onPrompt: () => () => {},
|
||||
onQueuedRemove: () => () => {},
|
||||
onClose(fn) {
|
||||
if (closed) {
|
||||
fn()
|
||||
return () => {}
|
||||
}
|
||||
|
||||
closes.add(fn)
|
||||
return () => {
|
||||
closes.delete(fn)
|
||||
}
|
||||
},
|
||||
event() {},
|
||||
append() {},
|
||||
idle() {
|
||||
return Promise.resolve()
|
||||
},
|
||||
close() {
|
||||
if (closed) {
|
||||
return
|
||||
}
|
||||
|
||||
closed = true
|
||||
notify()
|
||||
},
|
||||
destroy() {
|
||||
if (closed) {
|
||||
return
|
||||
}
|
||||
|
||||
closed = true
|
||||
notify()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
mock.restore()
|
||||
transportProviders.length = 0
|
||||
})
|
||||
|
||||
describe("run interactive runtime", () => {
|
||||
test("waits for provider metadata before eager replay transport bootstrap", async () => {
|
||||
const providersStarted = defer<void>()
|
||||
const providers = defer<void>()
|
||||
|
||||
const sdk = new OpencodeClient()
|
||||
spyOn(sdk.config, "providers").mockImplementation(async () => {
|
||||
providersStarted.resolve()
|
||||
await providers.promise
|
||||
return ok({ providers: [provider], default: {} })
|
||||
})
|
||||
spyOn(sdk.session, "messages").mockImplementation(() =>
|
||||
ok([
|
||||
{
|
||||
info: {
|
||||
id: "msg-user-1",
|
||||
sessionID: "ses-1",
|
||||
role: "user",
|
||||
time: {
|
||||
created: 1,
|
||||
},
|
||||
agent: "build",
|
||||
model: {
|
||||
providerID: "openai",
|
||||
modelID: "gpt-5",
|
||||
variant: undefined,
|
||||
},
|
||||
},
|
||||
parts: [
|
||||
{
|
||||
id: "part-user-1",
|
||||
sessionID: "ses-1",
|
||||
messageID: "msg-user-1",
|
||||
type: "text",
|
||||
text: "hello",
|
||||
},
|
||||
],
|
||||
} satisfies SessionMessage,
|
||||
]),
|
||||
)
|
||||
spyOn(sdk.session, "get").mockRejectedValue(new Error("not needed"))
|
||||
spyOn(sdk.app, "agents").mockImplementation(() => ok([]))
|
||||
spyOn(sdk.experimental.resource, "list").mockImplementation(() => ok({}))
|
||||
spyOn(sdk.command, "list").mockImplementation(() => ok([]))
|
||||
|
||||
const task = runInteractiveMode(
|
||||
{
|
||||
sdk,
|
||||
directory: "/tmp",
|
||||
sessionID: "ses-1",
|
||||
sessionTitle: "Session",
|
||||
resume: true,
|
||||
replay: true,
|
||||
replayLimit: 100,
|
||||
agent: "build",
|
||||
model: {
|
||||
providerID: "openai",
|
||||
modelID: "gpt-5",
|
||||
},
|
||||
variant: undefined,
|
||||
files: [],
|
||||
thinking: true,
|
||||
backgroundSubagents: false,
|
||||
},
|
||||
{
|
||||
createRuntimeLifecycle: async () => ({
|
||||
footer: footer(),
|
||||
onResize: () => () => {},
|
||||
refreshTheme: () => {},
|
||||
resetForReplay: () => Promise.resolve(),
|
||||
close: () => Promise.resolve(),
|
||||
}),
|
||||
streamTransport: Promise.resolve({
|
||||
createSessionTransport: async (input: { providers?: () => RunProvider[]; footer: FooterApi }) => {
|
||||
transportProviders.push(input.providers?.() ?? [])
|
||||
setTimeout(() => {
|
||||
input.footer.close()
|
||||
}, 0)
|
||||
return {
|
||||
runPromptTurn: async () => {},
|
||||
selectSubagent: () => {},
|
||||
replayOnResize: async () => false,
|
||||
close: async () => {},
|
||||
}
|
||||
},
|
||||
formatUnknownError: (error: unknown) => (error instanceof Error ? error.message : String(error)),
|
||||
}),
|
||||
},
|
||||
)
|
||||
|
||||
await providersStarted.promise
|
||||
|
||||
expect(transportProviders).toEqual([])
|
||||
|
||||
providers.resolve()
|
||||
|
||||
await task
|
||||
|
||||
expect(transportProviders).toEqual([[provider]])
|
||||
})
|
||||
})
|
||||
|
|
@ -111,6 +111,23 @@ function reasoning(text: string, phase: StreamCommit["phase"] = "progress"): Str
|
|||
}
|
||||
}
|
||||
|
||||
test("turn summary starts at the left edge", async () => {
|
||||
const out = await setup()
|
||||
|
||||
try {
|
||||
await out.scrollback.writeTurnSummary({ agent: "Build", model: "Little Frank", duration: "2.2s" })
|
||||
|
||||
const commits = claim(out.renderer)
|
||||
try {
|
||||
expect(renderRows(commits.at(-1)!)[0]).toBe("▣ Build · Little Frank · 2.2s")
|
||||
} finally {
|
||||
destroy(commits)
|
||||
}
|
||||
} finally {
|
||||
out.scrollback.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("theme swaps restyle active reasoning without resetting the stream", async () => {
|
||||
const previousSyntax = SyntaxStyle.fromStyles({ default: { fg: "#123456" } })
|
||||
const nextSyntax = SyntaxStyle.fromStyles({ default: { fg: "#abcdef" } })
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { replayLocalRows, replaySession } from "@/cli/cmd/run/session-replay"
|
||||
import type { SessionMessages } from "@/cli/cmd/run/session.shared"
|
||||
import type { RunProvider } from "@/cli/cmd/run/types"
|
||||
|
||||
function userMessage(id: string, text: string): SessionMessages[number] {
|
||||
return {
|
||||
|
|
@ -29,17 +30,23 @@ function userMessage(id: string, text: string): SessionMessages[number] {
|
|||
}
|
||||
}
|
||||
|
||||
function assistantInfo(id: string) {
|
||||
function assistantInfo(
|
||||
id: string,
|
||||
input: {
|
||||
parentID?: string
|
||||
modelID?: string
|
||||
providerID?: string
|
||||
time?: { created: number; completed?: number }
|
||||
} = {},
|
||||
) {
|
||||
return {
|
||||
id,
|
||||
sessionID: "session-1",
|
||||
role: "assistant" as const,
|
||||
time: {
|
||||
created: 2,
|
||||
},
|
||||
parentID: "msg-user-1",
|
||||
modelID: "gpt-5",
|
||||
providerID: "openai",
|
||||
time: input.time ?? { created: 2 },
|
||||
parentID: input.parentID ?? "msg-user-1",
|
||||
modelID: input.modelID ?? "gpt-5",
|
||||
providerID: input.providerID ?? "openai",
|
||||
mode: "chat",
|
||||
agent: "build",
|
||||
path: {
|
||||
|
|
@ -59,9 +66,26 @@ function assistantInfo(id: string) {
|
|||
}
|
||||
}
|
||||
|
||||
function assistantMessage(id: string, text: string): SessionMessages[number] {
|
||||
function assistantMessage(
|
||||
id: string,
|
||||
text: string,
|
||||
input: {
|
||||
parentID?: string
|
||||
modelID?: string
|
||||
providerID?: string
|
||||
time?: { created: number; completed?: number }
|
||||
} = {},
|
||||
): SessionMessages[number] {
|
||||
const time = input.time ?? {
|
||||
created: 200,
|
||||
completed: 3000,
|
||||
}
|
||||
|
||||
return {
|
||||
info: assistantInfo(id),
|
||||
info: assistantInfo(id, {
|
||||
...input,
|
||||
time,
|
||||
}),
|
||||
parts: [
|
||||
{
|
||||
id: `${id}-text`,
|
||||
|
|
@ -70,14 +94,72 @@ function assistantMessage(id: string, text: string): SessionMessages[number] {
|
|||
type: "text",
|
||||
text,
|
||||
time: {
|
||||
start: 2,
|
||||
end: 3,
|
||||
start: time.created,
|
||||
end: time.completed,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
const provider = (name: string): RunProvider =>
|
||||
({
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
source: "api",
|
||||
env: [],
|
||||
options: {},
|
||||
models: {
|
||||
"gpt-5": {
|
||||
id: "gpt-5",
|
||||
providerID: "openai",
|
||||
api: {
|
||||
id: "openai",
|
||||
url: "https://openai.test",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
name,
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: true,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: {
|
||||
text: true,
|
||||
audio: false,
|
||||
image: false,
|
||||
video: false,
|
||||
pdf: false,
|
||||
},
|
||||
output: {
|
||||
text: true,
|
||||
audio: false,
|
||||
image: false,
|
||||
video: false,
|
||||
pdf: false,
|
||||
},
|
||||
interleaved: false,
|
||||
},
|
||||
cost: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cache: {
|
||||
read: 0,
|
||||
write: 0,
|
||||
},
|
||||
},
|
||||
limit: {
|
||||
context: 128000,
|
||||
output: 8192,
|
||||
},
|
||||
status: "active",
|
||||
options: {},
|
||||
headers: {},
|
||||
release_date: "2026-01-01",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
function runningToolMessage(id: string): SessionMessages[number] {
|
||||
return {
|
||||
info: assistantInfo(id),
|
||||
|
|
@ -103,8 +185,74 @@ function runningToolMessage(id: string): SessionMessages[number] {
|
|||
}
|
||||
}
|
||||
|
||||
function shellUserMessage(id: string): SessionMessages[number] {
|
||||
return {
|
||||
info: {
|
||||
id,
|
||||
sessionID: "session-1",
|
||||
role: "user",
|
||||
time: {
|
||||
created: 1,
|
||||
},
|
||||
agent: "build",
|
||||
model: {
|
||||
providerID: "openai",
|
||||
modelID: "gpt-5",
|
||||
},
|
||||
},
|
||||
parts: [
|
||||
{
|
||||
id: `${id}-text`,
|
||||
sessionID: "session-1",
|
||||
messageID: id,
|
||||
type: "text",
|
||||
text: "The following tool was executed by the user",
|
||||
synthetic: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function shellAssistantMessage(id: string, parentID: string): SessionMessages[number] {
|
||||
return {
|
||||
info: assistantInfo(id, {
|
||||
parentID,
|
||||
time: {
|
||||
created: 200,
|
||||
completed: 3000,
|
||||
},
|
||||
}),
|
||||
parts: [
|
||||
{
|
||||
id: `${id}-tool`,
|
||||
sessionID: "session-1",
|
||||
messageID: id,
|
||||
type: "tool",
|
||||
callID: `${id}-call`,
|
||||
tool: "bash",
|
||||
state: {
|
||||
status: "completed",
|
||||
input: {
|
||||
command: "ls",
|
||||
},
|
||||
output: "account.ts\n",
|
||||
title: "",
|
||||
metadata: {
|
||||
output: "account.ts\n",
|
||||
description: "",
|
||||
},
|
||||
time: {
|
||||
start: 200,
|
||||
end: 3000,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
describe("run session replay", () => {
|
||||
test("replays persisted user and assistant history into scrollback commits", () => {
|
||||
test("replays persisted user, assistant, and turn summary history into scrollback commits", () => {
|
||||
const out = replaySession({
|
||||
messages: [
|
||||
userMessage("msg-user-1", "Hello, whats the weather today?"),
|
||||
|
|
@ -131,6 +279,18 @@ describe("run session replay", () => {
|
|||
source: "assistant",
|
||||
messageID: "msg-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
kind: "system",
|
||||
text: "▣ Build · gpt-5 · 2.8s",
|
||||
phase: "final",
|
||||
source: "system",
|
||||
messageID: "msg-1",
|
||||
summary: {
|
||||
agent: "Build",
|
||||
model: "gpt-5",
|
||||
duration: "2.8s",
|
||||
},
|
||||
}),
|
||||
])
|
||||
expect(out.patch).toEqual(
|
||||
expect.objectContaining({
|
||||
|
|
@ -140,6 +300,60 @@ describe("run session replay", () => {
|
|||
)
|
||||
})
|
||||
|
||||
test("uses provider model names for replayed turn summaries when available", () => {
|
||||
const out = replaySession({
|
||||
messages: [
|
||||
userMessage("msg-user-1", "Hello, whats the weather today?"),
|
||||
assistantMessage("msg-1", "What city or ZIP code should I check?"),
|
||||
],
|
||||
permissions: [],
|
||||
questions: [],
|
||||
thinking: true,
|
||||
limits: {},
|
||||
providers: [provider("Little Frank")],
|
||||
})
|
||||
|
||||
expect(out.commits.at(-1)).toEqual(
|
||||
expect.objectContaining({
|
||||
kind: "system",
|
||||
text: "▣ Build · Little Frank · 2.8s",
|
||||
summary: {
|
||||
agent: "Build",
|
||||
model: "Little Frank",
|
||||
duration: "2.8s",
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
test("replays one turn summary for the final assistant in a multi-step turn", () => {
|
||||
const out = replaySession({
|
||||
messages: [
|
||||
userMessage("msg-user-1", "Plan and then answer"),
|
||||
assistantMessage("msg-step-1", "Working", {
|
||||
parentID: "msg-user-1",
|
||||
time: { created: 200, completed: 900 },
|
||||
}),
|
||||
assistantMessage("msg-step-2", "Done", {
|
||||
parentID: "msg-user-1",
|
||||
time: { created: 1000, completed: 3000 },
|
||||
}),
|
||||
],
|
||||
permissions: [],
|
||||
questions: [],
|
||||
thinking: true,
|
||||
limits: {},
|
||||
})
|
||||
|
||||
expect(out.commits.filter((commit) => commit.summary)).toEqual([
|
||||
expect.objectContaining({
|
||||
kind: "system",
|
||||
text: "▣ Build · gpt-5 · 2.0s",
|
||||
messageID: "msg-step-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("keeps the footer in a running state for resumed active tools", () => {
|
||||
const out = replaySession({
|
||||
messages: [runningToolMessage("msg-1")],
|
||||
|
|
@ -157,6 +371,29 @@ describe("run session replay", () => {
|
|||
)
|
||||
})
|
||||
|
||||
test("does not replay turn summaries for shell-mode commands", () => {
|
||||
const out = replaySession({
|
||||
messages: [
|
||||
shellUserMessage("msg-shell-user-1"),
|
||||
shellAssistantMessage("msg-shell-assistant-1", "msg-shell-user-1"),
|
||||
],
|
||||
permissions: [],
|
||||
questions: [],
|
||||
thinking: true,
|
||||
limits: {},
|
||||
})
|
||||
|
||||
expect(out.commits.some((commit) => commit.summary)).toBe(false)
|
||||
expect(out.commits).toContainEqual(
|
||||
expect.objectContaining({
|
||||
kind: "tool",
|
||||
text: "account.ts\n",
|
||||
tool: "bash",
|
||||
toolState: "completed",
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
test("merges failed local rows ahead of later persisted prompts", () => {
|
||||
const persisted = {
|
||||
kind: "user",
|
||||
|
|
|
|||
|
|
@ -1183,7 +1183,7 @@ describe("run stream transport", () => {
|
|||
}
|
||||
})
|
||||
|
||||
test("drops completed historical subagent tabs during bootstrap", async () => {
|
||||
test("keeps completed historical subagent tabs during bootstrap", async () => {
|
||||
const src = eventFeed()
|
||||
const ui = footer()
|
||||
const transport = await createSessionTransport({
|
||||
|
|
@ -1231,7 +1231,7 @@ describe("run stream transport", () => {
|
|||
return item?.type === "stream.subagent" ? item.state : undefined
|
||||
})
|
||||
|
||||
expect(state.tabs).toEqual([])
|
||||
expect(state.tabs).toEqual([expect.objectContaining({ sessionID: "child-1", status: "completed" })])
|
||||
expect(state.details).toEqual({})
|
||||
} finally {
|
||||
src.close()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { entryBody } from "@/cli/cmd/run/entry.body"
|
|||
import {
|
||||
bootstrapSubagentCalls,
|
||||
bootstrapSubagentData,
|
||||
clearFinishedSubagents,
|
||||
createSubagentData,
|
||||
reduceSubagentData,
|
||||
snapshotSubagentData,
|
||||
|
|
@ -50,7 +49,7 @@ function reduce(data: ReturnType<typeof createSubagentData>, event: unknown) {
|
|||
})
|
||||
}
|
||||
|
||||
function taskMessage(sessionID: string, status: "running" | "completed" = "completed"): SessionMessage {
|
||||
function taskMessage(sessionID: string, status: "running" | "completed" | "interrupted" = "completed"): SessionMessage {
|
||||
if (status === "running") {
|
||||
return {
|
||||
parts: [
|
||||
|
|
@ -79,6 +78,35 @@ function taskMessage(sessionID: string, status: "running" | "completed" = "compl
|
|||
}
|
||||
}
|
||||
|
||||
if (status === "interrupted") {
|
||||
return {
|
||||
parts: [
|
||||
{
|
||||
id: `part-${sessionID}`,
|
||||
sessionID: "parent-1",
|
||||
messageID: `msg-${sessionID}`,
|
||||
type: "tool",
|
||||
callID: `call-${sessionID}`,
|
||||
tool: "task",
|
||||
state: {
|
||||
status: "error",
|
||||
input: {
|
||||
description: "Scan reducer paths",
|
||||
subagent_type: "explore",
|
||||
},
|
||||
error: "Tool execution aborted",
|
||||
metadata: {
|
||||
sessionId: sessionID,
|
||||
toolcalls: 4,
|
||||
interrupted: true,
|
||||
},
|
||||
time: { start: 1, end: 2 },
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
parts: [
|
||||
{
|
||||
|
|
@ -234,6 +262,25 @@ describe("run subagent data", () => {
|
|||
expect(snapshot.questions.map((item) => item.id)).toEqual(["question-1"])
|
||||
})
|
||||
|
||||
test("marks interrupted task tabs as cancelled during bootstrap", () => {
|
||||
const data = createSubagentData()
|
||||
|
||||
bootstrapSubagentData({
|
||||
data,
|
||||
messages: [taskMessage("child-1", "interrupted")],
|
||||
children: [{ id: "child-1" }],
|
||||
permissions: [],
|
||||
questions: [],
|
||||
})
|
||||
|
||||
expect(snapshotSubagentData(data).tabs).toEqual([
|
||||
expect.objectContaining({
|
||||
sessionID: "child-1",
|
||||
status: "cancelled",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("captures child activity and blocker metadata in the footer detail state", () => {
|
||||
const data = createSubagentData()
|
||||
|
||||
|
|
@ -437,20 +484,64 @@ describe("run subagent data", () => {
|
|||
])
|
||||
})
|
||||
|
||||
test("clears finished tabs on the next parent prompt", () => {
|
||||
test("marks a running tab cancelled when the child session aborts", () => {
|
||||
const data = createSubagentData()
|
||||
|
||||
bootstrapSubagentData({
|
||||
data,
|
||||
messages: [taskMessage("child-1", "completed"), taskMessage("child-2", "running")],
|
||||
children: [{ id: "child-1" }, { id: "child-2" }],
|
||||
messages: [taskMessage("child-1", "running")],
|
||||
children: [{ id: "child-1" }],
|
||||
permissions: [],
|
||||
questions: [],
|
||||
})
|
||||
|
||||
expect(clearFinishedSubagents(data)).toBe(true)
|
||||
reduce(data, {
|
||||
type: "message.updated",
|
||||
properties: {
|
||||
sessionID: "child-1",
|
||||
info: {
|
||||
id: "msg-assistant-1",
|
||||
sessionID: "child-1",
|
||||
role: "assistant",
|
||||
time: {
|
||||
created: 1,
|
||||
completed: 2,
|
||||
},
|
||||
error: {
|
||||
name: "MessageAbortedError",
|
||||
data: {
|
||||
message: "Aborted",
|
||||
},
|
||||
},
|
||||
parentID: "msg-user-1",
|
||||
providerID: "openai",
|
||||
modelID: "gpt-5",
|
||||
mode: "default",
|
||||
agent: "explore",
|
||||
path: {
|
||||
cwd: "/tmp",
|
||||
root: "/tmp",
|
||||
},
|
||||
cost: 0,
|
||||
tokens: {
|
||||
input: 1,
|
||||
output: 1,
|
||||
reasoning: 0,
|
||||
cache: {
|
||||
read: 0,
|
||||
write: 0,
|
||||
},
|
||||
},
|
||||
finish: "error",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(snapshotSubagentData(data).tabs).toEqual([
|
||||
expect.objectContaining({ sessionID: "child-2", status: "running" }),
|
||||
expect.objectContaining({
|
||||
sessionID: "child-1",
|
||||
status: "cancelled",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -74,8 +74,33 @@ test("returns syntax styles and indexed splash colors", async () => {
|
|||
expectIndexed(theme.splash.right)
|
||||
expectIndexed(theme.splash.leftShadow)
|
||||
expectIndexed(theme.splash.rightShadow)
|
||||
expectIndexed(theme.block.highlight)
|
||||
expectIndexed(theme.block.warning)
|
||||
expectRgba(theme.footer.highlight)
|
||||
expectRgba(theme.footer.statusAccent)
|
||||
expectRgba(theme.footer.surface)
|
||||
expect(expectRgba(theme.footer.statusAccent).toInts()).not.toEqual(expectRgba(theme.footer.status).toInts())
|
||||
} finally {
|
||||
theme.block.syntax?.destroy()
|
||||
theme.block.subtleSyntax?.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("keeps footer surfaces exact while scrollback stays palette matched", async () => {
|
||||
const colors = terminalColors({
|
||||
defaultBackground: "#0f172a",
|
||||
defaultForeground: "#e2e8f0",
|
||||
})
|
||||
const theme = await resolveRunTheme(renderer({ themeMode: "dark", colors }))
|
||||
const exact = resolveTheme(generateSystem(colors, "dark"), "dark")
|
||||
|
||||
try {
|
||||
expect(expectRgba(theme.footer.selected).toInts()).toEqual(expectRgba(exact.backgroundElement).toInts())
|
||||
expect(expectRgba(theme.footer.border).toInts()).toEqual(expectRgba(exact.border).toInts())
|
||||
expect(expectRgba(theme.footer.pane).toInts()).toEqual(expectRgba(exact.backgroundMenu).toInts())
|
||||
expect(expectRgba(theme.footer.selected).intent).toBe("rgb")
|
||||
expectIndexed(theme.block.highlight)
|
||||
expectIndexed(theme.block.warning)
|
||||
} finally {
|
||||
theme.block.syntax?.destroy()
|
||||
theme.block.subtleSyntax?.destroy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue