feat(webui): complete bang commands and literal output (NAN-291) (#6173)
* feat(webui): complete direct bang shell commands Reuse the gateway user-shell side channel, retain failed drafts without reconnect replay, and preserve literal output across live delivery and history. Highlight the bang prefix before and after sending. NAN-291 * fix(clients): preserve literal shell output through display metadata
This commit is contained in:
1 parent
f23a6d1485
commit
7e5dcb79e0
43 files changed
+805
-100
No files matched your search
+3
-1
@@ -770,7 +770,7 @@ export class NanobotTui {
|
||||
if (this.modelCommandTurns.delete(event.turn_id)) {
|
||||
void this.refreshSessionMetadata(event.chat_id)
|
||||
}
|
||||
if (!silent) this.transcript.assistant(event.text)
|
||||
if (!silent) this.transcript.assistant(event.text, event.render_as)
|
||||
if (!this.activeTurn) this.status.content = "Ready"
|
||||
return
|
||||
}
|
||||
@@ -780,6 +780,8 @@ export class NanobotTui {
|
||||
this.activeLabel = event.kind === "tool_hint" ? "Working" : "Thinking"
|
||||
this.transcript.progress(event.text, event.tool_events)
|
||||
this.setActive(true)
|
||||
} else if (event.render_as === "text") {
|
||||
this.transcript.assistant(event.text, event.render_as)
|
||||
} else {
|
||||
this.finalMessage = event.text
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { ClipboardImageReader } from "../composer/clipboard-image"
|
||||
import { options, client, mount, waitUntil, occurrences } from "./test-support"
|
||||
import { LOCAL_COMMANDS } from "./commands"
|
||||
import type { CommandMenu } from "../menus/command-menu"
|
||||
import type { Transcript } from "../rendering/transcript"
|
||||
|
||||
describe("NanobotTui composer", () => {
|
||||
let setup: TestRendererSetup | undefined
|
||||
@@ -986,8 +987,8 @@ describe("NanobotTui composer", () => {
|
||||
expect(sent).toEqual(["start an active turn"])
|
||||
})
|
||||
|
||||
test("runs bang commands through the gateway without steering the agent", async () => {
|
||||
setup = await createRenderer({ width: 80, height: 24, screenMode: "alternate-screen" })
|
||||
test("runs bang commands through the gateway and copies their literal output without steering the agent", async () => {
|
||||
setup = await createRenderer({ width: 100, height: 32, screenMode: "alternate-screen" })
|
||||
const sent: string[] = []
|
||||
const sentOptions: MessageOptions[] = []
|
||||
const app = NanobotTui.mount(
|
||||
@@ -997,7 +998,9 @@ describe("NanobotTui composer", () => {
|
||||
new MockTreeSitterClient({ autoResolveTimeout: 0 }),
|
||||
)
|
||||
app.accept({ event: "attached", chat_id: "chat" })
|
||||
const ui = app as unknown as { ready: boolean; composer: TextareaRenderable; activeTurn: boolean }
|
||||
const ui = app as unknown as {
|
||||
ready: boolean; composer: TextareaRenderable; activeTurn: boolean; transcript: Transcript
|
||||
}
|
||||
await waitUntil(() => ui.ready)
|
||||
|
||||
app.accept({ event: "goal_status", chat_id: "chat", status: "running" })
|
||||
@@ -1009,9 +1012,32 @@ describe("NanobotTui composer", () => {
|
||||
expect(sentOptions).toEqual([{ userShell: true }])
|
||||
expect(ui.activeTurn).toBe(true)
|
||||
|
||||
app.accept({ event: "message", chat_id: "chat", text: "/tmp/project", turn_id: "turn" })
|
||||
const output = [
|
||||
" __pycache__ `ticks` ``` ````",
|
||||
" <b>HTML</b>",
|
||||
"\\(x_1^2\\)",
|
||||
"```mermaid",
|
||||
"graph TD; A --> B",
|
||||
"```",
|
||||
"",
|
||||
].join("\n")
|
||||
app.accept({ event: "message", chat_id: "chat", text: output, render_as: "text", turn_id: "turn" })
|
||||
await setup.flush()
|
||||
expect(setup.captureCharFrame()).toContain("/tmp/project")
|
||||
const text = ui.transcript.root.getChildren().flatMap((row) => row.getChildren())
|
||||
.find((child) => child instanceof TextRenderable && child.plainText === output)
|
||||
expect(text).toBeInstanceOf(TextRenderable)
|
||||
expect(setup.captureCharFrame()).toContain(" <b>HTML</b>")
|
||||
expect(setup.captureCharFrame()).toContain("\\(x_1^2\\)")
|
||||
expect(setup.captureCharFrame()).toContain("```mermaid")
|
||||
expect(ui.activeTurn).toBe(true)
|
||||
|
||||
let copied = ""
|
||||
setup.renderer.copyToClipboardOSC52 = (value) => { copied = value; return true }
|
||||
if (!(text instanceof TextRenderable)) throw new Error("missing literal shell output")
|
||||
await setup.mockMouse.drag(text.screenX, text.screenY, text.screenX, text.screenY + text.height - 1)
|
||||
expect(setup.renderer.getSelection()?.getSelectedText()).toBe(output)
|
||||
setup.mockInput.pressCtrlC()
|
||||
await waitUntil(() => copied.length > 0)
|
||||
expect(copied).toBe(output)
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test"
|
||||
import { BoxRenderable, CliRenderEvents, TextareaRenderable, TextRenderable } from "@opentui/core"
|
||||
import { BoxRenderable, CliRenderEvents, MarkdownRenderable, TextareaRenderable, TextRenderable } from "@opentui/core"
|
||||
import { MockTreeSitterClient, createTestRenderer, type TestRendererSetup } from "@opentui/core/testing"
|
||||
import { NanobotTui } from "./app"
|
||||
import { options, client, mount, waitUntil, occurrences } from "./test-support"
|
||||
import type { Transcript } from "../rendering/transcript"
|
||||
|
||||
describe("NanobotTui transcript", () => {
|
||||
let setup: TestRendererSetup | undefined
|
||||
@@ -16,9 +17,11 @@ describe("NanobotTui transcript", () => {
|
||||
createTestRenderer(rendererOptions)
|
||||
)
|
||||
test("loads earlier transcript pages in place when PageUp reaches the top", async () => {
|
||||
setup = await createRenderer({ width: 80, height: 22, screenMode: "alternate-screen" })
|
||||
setup = await createRenderer({ width: 100, height: 40, screenMode: "alternate-screen" })
|
||||
const original = globalThis.fetch
|
||||
const requests: string[] = []
|
||||
const oldest = "oldest answer `ticks` __pycache__\n  <b>HTML</b>\n"
|
||||
const recent = "recent answer \\(x_1^2\\)\n```mermaid\ngraph TD; A --> B\n```\n"
|
||||
globalThis.fetch = ((input: string | URL | Request) => {
|
||||
const url = String(input)
|
||||
requests.push(url)
|
||||
@@ -27,12 +30,13 @@ describe("NanobotTui transcript", () => {
|
||||
schemaVersion: 3, projection: "events",
|
||||
events: older
|
||||
? [
|
||||
{ event: "user_message", chat_id: "chat", starts_turn: true, text: "oldest question" },
|
||||
{ event: "stream_end", chat_id: "chat", text: "oldest answer" },
|
||||
{ event: "user_message", chat_id: "chat", starts_turn: false, text: "!cat oldest.log", turn_id: "old-shell" },
|
||||
{ event: "message", chat_id: "chat", text: oldest, render_as: "text", turn_id: "old-shell" },
|
||||
]
|
||||
: [
|
||||
{ event: "user_message", chat_id: "chat", starts_turn: true, text: "recent question" },
|
||||
{ event: "stream_end", chat_id: "chat", text: "recent answer" },
|
||||
{ event: "user_message", chat_id: "chat", starts_turn: false, text: "!cat recent.log", turn_id: "recent-shell" },
|
||||
{ event: "message", chat_id: "chat", text: recent, render_as: "text", turn_id: "recent-shell" },
|
||||
{ event: "stream_end", chat_id: "chat", text: "Normal \\(x_1^2\\)", turn_id: "agent" },
|
||||
],
|
||||
page: older
|
||||
? { has_more_before: false, before_cursor: null }
|
||||
@@ -55,20 +59,48 @@ describe("NanobotTui transcript", () => {
|
||||
await setup.flush()
|
||||
const frame = setup.captureCharFrame()
|
||||
|
||||
expect(frame.indexOf("oldest question")).toBeLessThan(frame.indexOf("recent question"))
|
||||
expect(frame.indexOf("!cat oldest.log")).toBeLessThan(frame.indexOf("!cat recent.log"))
|
||||
expect(frame.indexOf("oldest answer")).toBeLessThan(frame.indexOf("recent answer"))
|
||||
expect((app as unknown as { historyHasMore: boolean }).historyHasMore).toBe(false)
|
||||
const transcript = (app as unknown as { transcript: Transcript }).transcript
|
||||
const cells = transcript.root.getChildren().flatMap((row) => row.getChildren())
|
||||
expect(cells.filter((child) => child instanceof TextRenderable)
|
||||
.map((child) => child.plainText)).toEqual(expect.arrayContaining([oldest, recent]))
|
||||
expect(cells.filter((child) => child instanceof MarkdownRenderable)
|
||||
.map((child) => child.content)).toEqual(["Normal x₁²"])
|
||||
expect(frame).toContain(" <b>HTML</b>")
|
||||
expect(frame).toContain("```mermaid")
|
||||
|
||||
const composer = (app as unknown as { composer: TextareaRenderable }).composer
|
||||
setup.mockInput.pressArrow("up")
|
||||
expect(composer.plainText).toBe("recent question")
|
||||
expect(composer.plainText).toBe("!cat recent.log")
|
||||
setup.mockInput.pressArrow("up")
|
||||
expect(composer.plainText).toBe("oldest question")
|
||||
expect(composer.plainText).toBe("!cat oldest.log")
|
||||
} finally {
|
||||
globalThis.fetch = original
|
||||
}
|
||||
})
|
||||
|
||||
test("shows literal shell output from another client without replacing a pending Markdown reply", async () => {
|
||||
setup = await createRenderer({ width: 100, height: 26, screenMode: "alternate-screen" })
|
||||
const app = mount(setup)
|
||||
app.accept({ event: "goal_status", chat_id: "chat", status: "running", turn_id: "agent" })
|
||||
app.accept({ event: "message", chat_id: "chat", text: "Normal \\(x_1^2\\)", turn_id: "agent" })
|
||||
const output = " __pycache__ `ticks`  <b>HTML</b>\n"
|
||||
app.accept({ event: "message", chat_id: "chat", text: output, render_as: "text", turn_id: "other-shell" })
|
||||
await setup.flush()
|
||||
expect(setup.captureCharFrame()).toContain("__pycache__ `ticks`  <b>HTML</b>")
|
||||
const ui = app as unknown as { activeTurn: boolean; transcript: Transcript }
|
||||
expect(ui.activeTurn).toBe(true)
|
||||
|
||||
app.accept({ event: "turn_end", chat_id: "chat", turn_id: "agent" })
|
||||
await setup.flush()
|
||||
const cells = ui.transcript.root.getChildren().flatMap((row) => row.getChildren())
|
||||
expect(cells.some((child) => child instanceof TextRenderable && child.plainText === output)).toBe(true)
|
||||
expect(cells.some((child) => child instanceof MarkdownRenderable && child.content === "Normal x₁²")).toBe(true)
|
||||
expect(ui.activeTurn).toBe(false)
|
||||
})
|
||||
|
||||
test("replaces streamed drafts with canonical stream-end text", async () => {
|
||||
setup = await createRenderer({ width: 80, height: 20, screenMode: "alternate-screen" })
|
||||
const app = mount(setup)
|
||||
|
||||
Reference in new issue
Block a user