GeezerVison is showing github.com — feat(app): steer the next queued prompt with Mod+Enter by usrnk1 · Pull Request #63111 · anomalyco/opencode
feat(app): steer the next queued prompt with Mod+Enter
#63111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.ts
(7)
.tsx
(3)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -512,7 +512,6 @@ test.describe("location", () => {
test("an app launch that never answers releases the Open in controls", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 })
await page.clock.install()
const mock = await mockWorkspace(page, {
...workspace,
Expand All
@@ -534,6 +533,8 @@ test.describe("location", () => {
await expectSessionTitle(page, "Location session")
await page.getByRole("button", { name: "Toggle review", exact: true }).click()
await expect(page.getByRole("complementary", { name: "Review and files", exact: true })).toBeFocused()
// Control the launch timeout, not the page's initial focus and panel animation.
await page.clock.install()
const open = page.getByRole("button", { name: "Open in VS Code", exact: true })
await open.click()
await expect(page.getByLabel("Opened paths")).toContainText("Visual Studio Code")
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -264,6 +264,54 @@ test("Alt+Enter queues a follow-up first without steering, regardless of the fol
await expect(page.getByRole("tooltip")).toContainText("Queue first")
})
for (const behavior of ["queue", "steer"] as const) {
test(`an empty Mod+Enter steers only the first queued prompt (${behavior} preference)`, async ({ page }) => {
const mock = createQueueMock(["Follow-up A", "Follow-up B", "Follow-up C"])
const view = await openQueue(page, mock, behavior)
const steer = await holdRoute(page, new RegExp(`/api/session/${sessionID}/inbox/inb_seed_1(\\?|$)`), {
method: "PATCH",
})
await view.input.press("Enter")
await view.input.press("Alt+Enter")
await expect(view.rows.locator('[data-action="session-queue-edit"]')).toHaveText([
"Follow-up A",
"Follow-up B",
"Follow-up C",
])
expect(mock.changes).toEqual([])
await view.input.press("ControlOrMeta+Enter")
await expect(view.rows.locator('[data-action="session-queue-edit"]')).toHaveText(["Follow-up B", "Follow-up C"])
await steer.arrived
// A second press while A is still being steered must not jump to B.
await view.input.press("ControlOrMeta+Enter")
steer.release()
await expect.poll(() => mock.changes).toEqual([{ inboxID: "inb_seed_1", action: "steer" }])
await expect(view.rows.locator('[data-action="session-queue-edit"]')).toHaveText(["Follow-up B", "Follow-up C"])
expect(mock.prompts).toEqual([])
})
}
for (const mode of ["parked", "shell"] as const) {
test(`empty Mod+Enter leaves the queue alone when ${mode}`, async ({ page }) => {
const mock = createQueueMock(["Keep queued"])
const view = await openQueue(page, mock, "queue", undefined, mode === "parked" ? "idle" : "running")
if (mode === "shell") {
await view.input.pressSequentially("!")
await expect(view.composer.locator('[data-action="composer-exit-shell"]')).toBeVisible()
}
await view.input.press("ControlOrMeta+Enter")
await expect(view.rows.locator('[data-action="session-queue-edit"]')).toHaveText(["Keep queued"])
expect(mock.changes).toEqual([])
})
}
test("a blank Enter leaves the running session alone while Stop still interrupts it, as in the TUI", async ({
page,
}) => {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -53,6 +53,8 @@ export type ComposerQueue = {
editFirst: () => boolean
// Moves an admitted follow-up ahead of the queued prompts, using the queue's serialized reorder.
first: (inboxID: string) => void
// Steers the next prompt only while the queue is idle; never skips a busy first row.
steerFirst: () => void
}
export type ComposerSession = {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -124,6 +124,7 @@ function TouchComposer(props: { state: State }) {
cancelEdit: () => record("Cancelled the edit"),
editFirst: () => false,
first() {},
steerFirst() {},
}
const editor = createComposerEditor({
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -242,6 +242,7 @@ function ComposerStory(props: {
cancelEdit() {},
editFirst: () => false,
first() {},
steerFirst() {},
}
: undefined,
onSubmit: () => {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -558,6 +558,14 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
return
}
// With no draft to send, the explicit alternate shortcut acts on the next queued prompt.
// Plain Enter, touch's primary send and an empty shell composer still do nothing.
if (submitOptions?.alternate && mode() === "normal" && blank()) {
if (adapter.working() && submitView().canSubmit && prompt.context.items().length === 0) queue?.steerFirst()
return
}
void submission.submit(new Event("submit"), submitOptions)
},
onStop: () => void submission.stop(),
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -106,6 +106,24 @@ describe("queue first shares the serialized reorder", () => {
)
})
test("steer-first ignores an open edit and a disposed or empty queue", () => {
const editing = transitionQueue(createQueueState([one, two]), {
type: "edit.start",
id: one.id,
reverted: false,
draft: draft("my draft"),
}).state
const disposed = transitionQueue(createQueueState([one, two]), { type: "dispose" }).state
for (const state of [editing, disposed, createQueueState([])]) {
const result = transitionQueue(state, { type: "steer-first.requested" })
expect(result.state).toBe(state)
expect(result.effects).toEqual([])
}
})
describe("an edit always returns the draft it replaced", () => {
test("when the server delivers the prompt being edited", () => {
const result = replay(createQueueState([one, two]), [
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -143,6 +143,7 @@ export type QueueEvent =
| { readonly type: "reorder.requested"; readonly inboxIDs: readonly string[]; readonly reverted: boolean }
| { readonly type: "first.requested"; readonly id: string; readonly reverted: boolean }
| { readonly type: "steer.requested"; readonly id: string }
| { readonly type: "steer-first.requested" }
| { readonly type: "remove.requested"; readonly id: string }
| { readonly type: "undo.requested"; readonly id: string; readonly mode: "normal" | "shell" }
| { readonly type: "mutation.moved"; readonly attempt: number; readonly moved: Readonly<Record<string, string>> }
Expand Down
Expand Up
@@ -246,6 +247,14 @@ export function transitionQueue(state: QueueState, event: QueueEvent): QueueTran
if (event.type === "steer.requested") return request(state, { type: "steer", id: event.id })
if (event.type === "steer-first.requested") {
if (state.status !== "idle") return unchanged(state)
const first = selectQueueRows(state)[0]
return first && !first.pending ? request(state, { type: "steer", id: first.id }) : unchanged(state)
}
if (event.type === "remove.requested") return request(state, { type: "remove", id: event.id })
if (event.type === "undo.requested") return undo(state, event)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -9,9 +9,11 @@ import { Button } from "@opencode/ui/button"
import { Icon } from "@opencode/ui/icon"
import { IconButton } from "@opencode/ui/icon-button"
import { Loader } from "@opencode/ui/loader"
import { Keybind } from "@opencode/ui/keybind"
import { Tooltip } from "@opencode/ui/tooltip"
import { prefersReducedMotion } from "@opencode/ui/motion"
import { useLanguage } from "@/runtime/i18n/language"
import { formatKeybind } from "@/shell/commands/command"
import type { SessionQueueView } from "./queue"
import type { QueueRow } from "./queue-machine"
import {
Expand Down
Expand Up
@@ -254,7 +256,14 @@ function SessionQueueRow(props: { queue: SessionQueueView; id: string; row: Queu
<Tooltip
placement="top"
inactive={!props.queue.working()}
value={language.t("session.queue.steerTooltip")}
value={
<div class="flex items-center gap-4">
<span>{language.t("session.queue.steerTooltip")}</span>
<Show when={props.index === 0}>
<Keybind keys={[formatKeybind("mod", language.t), "↵"]} variant="neutral" />
</Show>
</div>
}
>
<Button
data-action="session-queue-steer"
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -472,6 +472,7 @@ export function createSessionQueue(input: {
undoing: () => view().undoing,
working: input.working,
steer: (id: string) => dispatch({ type: "steer.requested", id }),
steerFirst: () => dispatch({ type: "steer-first.requested" }),
remove: (id: string) => dispatch({ type: "remove.requested", id }),
undo: (id: string) => dispatch({ type: "undo.requested", id, mode: input.draft.mode.current() }),
edit,
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.