fix(tui): accept goal requests during active turns (#5981)

* fix(tui): accept goal requests during active turns

* fix(goal): reuse live input routing and remove busy guards

* test(goal): cover followup streams across iteration budgets

* refactor(goal): expand slash commands into hidden agent input

* fix(goal): keep generated input permission scoped to users

* refactor(agent): encapsulate goal input permission scope

* refactor(goal): preserve task text without prompt wrapper

* test(goal): consolidate coverage and exercise restart recovery

* test(goal): wait for recovery reply without task registry race
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-30 13:08:13 +08:00
1 parent b46d4dfd7d
commit 99ba062a97
15 files changed
+613 -360

No files matched your search

+3 -11
View File
@@ -2227,8 +2227,8 @@ export class NanobotTui {
this.markSubmitUnsent()
return
}
if (this.activeTurn && lifecycle === "agent_turn") {
this.status.content = "A turn is already running · Ctrl+C to stop"
if (lifecycle === "agent_turn") {
this.sendPrompt({ content, options }, this.activeTurn)
return
}
let turnId: string
@@ -2247,15 +2247,7 @@ export class NanobotTui {
if (!silent && lifecycle !== "stop_active_turn") this.transcript.user(content)
if (!silent) this.recordPrompt(content)
if (lifecycle === "agent_turn") {
this.host.reportTitle(content)
this.activeTurnId = turnId
this.finalMessage = ""
this.turnHadAnswer = false
this.activeLabel = "Thinking"
this.currentFileEdits = []
this.setActive(true)
} else if (lifecycle === "finalize_active_turn") {
if (lifecycle === "finalize_active_turn") {
this.activeTurnId = null
this.transcript.finishStream(this.turnHadAnswer ? "" : this.finalMessage)
this.transcript.finishActivity()
+49
View File
@@ -407,6 +407,55 @@ describe("NanobotTui composer", () => {
expect(disposed).toBeTrue()
})
test.each(["enter", "tab"])("submits a running goal with %s", async (key) => {
const sent: string[] = []
setup = await createRenderer({ width: 88, height: 24, screenMode: "alternate-screen" })
const transport = client(sent)
transport.send = (content) => {
sent.push(content)
return sent.length === 1 ? "active" : "followup"
}
const app = NanobotTui.mount(
setup.renderer, options, transport,
new MockTreeSitterClient({ autoResolveTimeout: 0 }),
)
app.accept({ event: "attached", chat_id: "chat" })
const ui = app as unknown as {
ready: boolean
activeTurnId: string | null
composer: TextareaRenderable
commandMenu: { setCommands(commands: SlashCommand[]): void }
queuePreview: { root: { visible: boolean } }
}
await waitUntil(() => ui.ready)
ui.commandMenu.setCommands([{
command: "/goal",
title: "Goal",
description: "Start sustained work",
argHint: "<goal>",
lifecycle: "agent_turn_with_args",
acceptsArgs: true,
}])
ui.composer.setText("Discuss the migration plan")
setup.mockInput.pressEnter()
await waitUntil(() => sent.length === 1)
await waitUntil(() => ui.activeTurnId === "active")
const goal = "/goal implement the plan we discussed"
ui.composer.setText(goal)
if (key === "enter") setup.mockInput.pressEnter()
else setup.mockInput.pressTab()
await waitUntil(() => ui.composer.plainText === "")
expect(sent).toEqual(key === "enter" ? ["Discuss the migration plan", goal] : ["Discuss the migration plan"])
expect(ui.activeTurnId).toBe("active")
expect(ui.queuePreview.root.visible).toBe(key === "tab")
app.accept({ event: "turn_end", chat_id: "chat", turn_id: "active" })
await waitUntil(() => sent.length === 2)
expect(sent).toEqual(["Discuss the migration plan", goal])
expect(ui.queuePreview.root.visible).toBeFalse()
})
test("steers with Enter, queues with Tab, and restores queued text with Alt+Up", async () => {
const sent: string[] = []
const sentOptions: MessageOptions[] = []