GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): restore the live draft after browsing prompt history by jlongster · Pull Request #63262 · anomalyco/opencode

Conversation

@jlongster

@jlongster jlongster commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Related to #45209. With the newest saved command pwd showing, press Down once more to return to the unsent draft. On dev the composer goes blank and switches to Build. With the fix it shows the edited echo pen draft in Shell mode.

Type of change

  • Bug fix

What does this PR do?

Keep the shared list of saved prompts, and give each composer its own history position and live draft. Capture the draft when leaving it and restore it on return. Compare against a saved item only while browsing one, so a distinct nonempty draft can also enter history.

How did you verify your code works?

Three of five native composer traces failed on 1002a979f9. All five passed on 8cc97cbb5b. The controls covered direct editing and protection of an edited recalled entry.

Screenshots / recordings

Before (dev 1002a979f9) and after (fix 394f40dcc9), side by side

Real TUI with a simulated model. With echo pen and pwd in history, start a shell draft, browse ↑ ×3, then ↓ ×3 back past the newest entry. Left: dev leaves a blank Build prompt. Right: the fix brings back the echo pen draft in Shell mode. MP4

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jlongster
fix(tui): restore the live draft after browsing prompt history
8cc97cb
User decisions:
- Preserve the unsent edited draft and its mode
- Keep the upstream patch limited to production code
@github-actions github-actions Bot added the contributor label Nov 11, 2026
@jlongster
fix(tui): reset history browsing on composer reset and copy recalled …
394f40d
…entries

User decisions:
- Apply the review's fixes to the prompt history PR
@jlongster
jlongster marked this pull request as ready for review November 12, 2026 17:16
opencodejr[bot]
opencodejr Bot reviewed Nov 12, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the bug. In the TUI on base, coming back from history with Down empties the composer and loses the draft. With this PR the draft comes back with its mode. The prompt tests pass (86/86), the new composer tests fail on base and pass here, and tsc -b is clean for packages/tui.

Public API: unchanged. usePromptHistory is internal to the TUI and the history file format is the same.

One behaviour change to know about: Up from a nonempty draft (cursor at the start) now opens history. Before, it did nothing unless the draft happened to match the oldest entry. Down brings the draft back, so nothing is lost and this matches how shells behave.

Only other note: the new composer test file is large for what it checks (see the inline comment).

Before

After

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/tui/test/prompt/history-composer.test.tsx Outdated
@@ -0,0 +1,240 @@
import { TextareaRenderable } from "@opentui/core"

@opencodejr opencodejr Bot Nov 12, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is 240 lines, with a hand-rolled fetch mock and five long key-sequence scenarios, and none of them checks the headline case directly: draft → Up → Down restores the draft text and its mode. Could it be cut to that case plus one reset case (e.g. clearing a recalled entry)? The stash pop/list scenario and the paste-mutation scenario mostly repeat what the provider test in history-provider.test.tsx already covers, so they could be dropped.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jlongster jlongster Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut this from 240 lines to 50 and removed the fetch mock. Two tests remain: draft → Up → Down restores the text and shell mode, and clearing a recalled entry leaves the composer empty on Down. I dropped the stash and paste scenarios since the provider test covers the underlying reset and copy behavior. The round-trip test fails on base (Up leaves echo pen in the composer) and passes here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

opencodejr[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

@opencodejr opencodejr Bot Nov 12, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trimmed file at e2cbe610 looks right. It has 50 lines, no fetch mock, history is seeded through prompt-history.jsonl, and both tests pass on the PR head. The remaining issue is that the round-trip test fails on base at the Up step, before it reaches the Down step where the reported bug happens. So it doesn't actually show that the fix restores the draft.

Why it fails at Up: on base, move() only lets Up through when the composer text matches store.history.at(store.index) (packages/tui/src/prompt/history.tsx:112-114). With index at 0, that is the oldest saved entry. A draft of echo pen with only previous saved fails that check, so Up does nothing. That's the "Up leaves echo pen in the composer" failure you saw. Pressing Up more times doesn't help (I tried up to 5). Your PR recording works on dev only because echo pen was already saved.

Fix: save echo pen as the oldest entry in shell mode. Base then lets Up through, and the test fails where the bug is:

-  await Bun.write(file, JSON.stringify({ text: "previous", pasted: [] }))
+  await Bun.write(
+    file,
+    [
+      JSON.stringify({ text: "echo pen", pasted: [], mode: "shell" }),
+      JSON.stringify({ text: "previous", pasted: [] }),
+    ].join("\n"),
+  )

With that change:

  • Base: Up shows previous, then Down fails with Expected: "echo pen", Received: "". That is the blank prompt from the PR's before/after recording.
  • PR head: both tests pass.

The clearing test also fails at Up on base (Received: "unsent"). That's fine because it covers new reset behavior, not the original bug.

What I ran: throwaway worktrees of pr/head and pr/base (with the head test file copied in), running bun test on both test files:

  • PR head as pushed: 6 of 6 pass.
  • Base as pushed: both composer tests fail at Up.
  • With the change above: base fails at Down, and head passes both tests.

I didn't change anything in repo/ (the shared checkout is still at 394f40dc, and the bun.lock change was already there). I removed the worktrees afterwards.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jlongster jlongster Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeded echo pen in normal mode as the oldest entry. On base (1002a979f9), Up now recalls previous, and the final Down leaves the composer empty: Expected: "echo pen", Received: "". On this branch, Down restores echo pen in Shell mode. Both tests pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

opencodejr[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

@opencodejr opencodejr Bot Nov 12, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed at b59efcd6. The round-trip test now fails on base at the step where the bug happens, and both tests pass on the branch.

  • Base 1002a979f9, with the head test file copied in: Up recalls previous, then Down fails with Expected: "echo pen", Received: "". The clearing test also fails on base, at Up (Received: "unsent"). That's expected because it covers the new reset behaviour.
  • PR head: both composer tests and the 4 provider tests pass.

Saving echo pen in normal mode is a better choice than shell mode. The Shell frame check can then only pass if the draft's mode is restored, because no saved entry was in Shell mode.

I ran these in temporary worktrees and removed them afterwards. Nothing in repo/ changed; the bun.lock change there was already present and I left it alone.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jlongster added 2 commits November 12, 2026 18:22
@jlongster
test(tui): reduce history composer tests to the headline and reset cases
e2cbe61
User decisions:
- Keep the draft text and mode round trip and one clear/reset case
- Drop the stash and paste scenarios covered by the provider test
@jlongster
test(tui): reproduce the empty draft on the final Down
b59efcd
User decisions:
- Seed history so Up succeeds on base and Down exposes the empty composer
- Distinguish the saved entry from the shell draft by mode
- Keep the composer suite at two tests
opencodejr[bot]
opencodejr Bot reviewed Nov 12, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test point is addressed: history-composer.test.tsx is now a small file covering the headline case (draft text and Shell mode come back on the last Down) and one reset case. Both tests fail on base and pass here, consistently across three runs. Source is unchanged since my last review, so the earlier verification still holds. Public API is unchanged. Nothing new to raise.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jlongster
jlongster merged commit 89e66ae into dev Nov 12, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@jlongster
jlongster deleted the restore-history-draft branch November 12, 2026 18:33
simonklee added a commit that referenced this pull request Nov 13, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
be210f8
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 13, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
da705f9
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 14, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
f0698f0
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 14, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
8ff0edf
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 15, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
4d27151
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 15, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
52908f4
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 16, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
7f9b4c2
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 16, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
c1ffa3b
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 17, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
c1e9b11
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 17, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
0c43e96
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
simonklee added a commit that referenced this pull request Nov 18, 2026
@simonklee
fix(cli-rs): restore the live draft after browsing prompt history
a0ad7ff
Port of #63262. Each prompt keeps its own history cursor and saves the draft, with its mode, when Up leaves it; Down past the newest entry brings it back. Up from a typed prompt now recalls the newest entry. Submitting, clearing, stashing and setting the prompt reset the cursor.
@521ox 521ox mentioned this pull request Nov 18, 2026
tui: popping a stashed Shell draft in Build mode submits it as a regular prompt #64630
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jlongster
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.