A command chosen in /help or /status goes through the typed line's guard
ci / check (push) Canceled after 0s
ci / check (push) Canceled after 0s
They ran the command directly, past submit()'s mid-task check: /new, /compact, /undo, /model and the rest could start while a reply ran. A menu now hands the line to the same function a typed line goes through. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+38
-5
No files matched your search
@@ -301,6 +301,7 @@ export function Root(p: { app: Runtime; view: View; theme: Theme; onQuit: () =>
|
||||
share: undefined as Share | undefined,
|
||||
continueTask: () => continueTask(),
|
||||
sendAs: (prompt: string, shown: string, opts?: { model?: string; mode?: string }) => void sendAs(prompt, shown, opts),
|
||||
runLine: (line: string) => submit(line),
|
||||
setInput(text: string) {
|
||||
input?.setText(text)
|
||||
input?.gotoBufferEnd()
|
||||
|
||||
+6
-5
@@ -50,6 +50,9 @@ export interface CommandCtx extends Ctx {
|
||||
/** Send a prompt shown as `shown`, with a model/mode for this prompt only. */
|
||||
sendAs?(prompt: string, shown: string, opts?: { model?: string; mode?: string; attachFrom?: string }): void
|
||||
openDialog(spec: DialogSpec): void
|
||||
/** Run a line as if it had been typed and sent — a command chosen in a menu goes through the
|
||||
* same checks as one typed (not mid-reply, and so on). false: refused. */
|
||||
runLine(line: string): boolean | void
|
||||
setMode(m: Mode): void
|
||||
setEffort(e: Level): void
|
||||
setTheme(name: string): void
|
||||
@@ -191,7 +194,8 @@ export const COMMANDS: Command[] = [
|
||||
name: "help",
|
||||
description: "commands and keys",
|
||||
run(c) {
|
||||
openHelp(c, COMMANDS, HELP_KEYS, (cmd) => void cmd.run(c, ""))
|
||||
// Through the same door as a typed line: what may not start mid-reply is refused there.
|
||||
openHelp(c, COMMANDS, HELP_KEYS, (cmd) => void c.runLine(`/${cmd.name}`))
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -203,10 +207,7 @@ export const COMMANDS: Command[] = [
|
||||
name: "status",
|
||||
description: "everything in one place: the server and login, the session, the project, the MCP servers, this terminal",
|
||||
run(c) {
|
||||
openStatus(c, (line) => {
|
||||
const [name = "", ...rest] = line.split(" ")
|
||||
void findCommand(name)?.run(c, rest.join(" "))
|
||||
})
|
||||
openStatus(c, (line) => void c.runLine(`/${line}`))
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -169,3 +169,34 @@ test("without a menu the same commands are plain text: /permissions and /status
|
||||
expect(s).toMatch(/- trusted: no: .*\(needs attention\)/)
|
||||
expect(s).toContain("- servers: none configured")
|
||||
})
|
||||
|
||||
test("a command chosen in a menu goes through the same guard as one typed: not while a reply runs", async () => {
|
||||
const { delta, usage } = await import("../fake-provider.ts")
|
||||
t = await tui([{ chunks: [delta({ content: "Slow" }), delta({ content: "ly" }), delta({ content: " going" }), delta({ content: " on" }), delta({ content: " and on." }), usage(100, 5)], gapMs: 500 }], { width: 110, height: 40 })
|
||||
await t.input.typeText("go")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Slow")).toBe(true)
|
||||
const session = t.app.engine.sessionId
|
||||
const messages = t.app.engine.messages.length
|
||||
// /help → /new, while the reply streams.
|
||||
await t.input.typeText("/help")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Help — commands and keys")).toBe(true)
|
||||
for (const ch of "/new") t.input.pressKey(ch)
|
||||
await t.settle()
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("wait for the reply to finish (esc stops it)")).toBe(true)
|
||||
expect(t.app.engine.sessionId).toBe(session)
|
||||
expect(t.app.engine.messages.length).toBeGreaterThanOrEqual(messages)
|
||||
// /status → the model row → /model, likewise.
|
||||
await t.input.typeText("/status")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("This program")).toBe(true)
|
||||
for (let i = 0; i < 2; i++) t.input.pressArrow("down")
|
||||
await t.settle()
|
||||
t.input.pressEnter()
|
||||
await t.settle(150)
|
||||
expect(t.frame()).not.toContain("fake/other") // the model picker did not open
|
||||
expect(t.frame().split("wait for the reply to finish").length - 1).toBe(2)
|
||||
expect(await t.until("and on.")).toBe(true)
|
||||
}, 30_000)
|
||||
Reference in new issue
Block a user