Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(web): recall sent prompts with the up arrow #9173

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 13 commits intomain fromrefs/pull/9173/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Closes #1777.

Problem

I often want to copy something I sent earlier in a thread. Today that means scrolling up and selecting text from the timeline. Every terminal and every coding-agent CLI lets you press the up arrow instead.

Fix

Press ArrowUp in an empty composer to get the last prompt you sent in this thread. ArrowUp again goes further back, ArrowDown comes forward, and going past the newest prompt clears the composer.

History is per thread and derived from the thread's user messages on the keypress. Nothing new is stored or synced, so it works the same on web, desktop, and any remote client. Send-time appends (terminal and element context, preview annotations, review comments, the ultrathink prefix) are stripped so you get the text you typed.

Recall stays out of the way of normal editing:

  • With text in the composer, arrows move the caret as usual. Recall only claims the key when the caret is on the first or last visual line and the text is an unedited recalled prompt.
  • Editing a recalled prompt turns it into a normal draft.
  • Modifier keys, IME composition, slash and mention menus, approvals, and pending questions all take priority.

Text only. Attachments are not restored. Mobile has no arrow keys, so it is unchanged.

Why per thread and not global

Codex and OpenCode keep one global history file. That fits a CLI that lives in one directory. T3 Code syncs threads across devices, and a global localStorage history would be per browser and would recall prompts with mentions from other projects. Per thread matches the GUI chat convention (Slack, Discord, ChatGPT) and needs no store.

Prior art

Three earlier attempts at this feature informed the design. Thanks to their authors.

  • #1778 by @PratyushChauhan first wired arrows into the composer command key path. It went stale on conflicts.
  • #4336 by @mfazekas added the first-or-last visual line rule and draft restore.
  • #7952 by @sethwebster is the most complete. The message text stripping and the caret edge measurement here are taken from that branch, and the bot findings on it (duplicate prompts moving the offset, ArrowUp at the oldest entry eating the key, unmount overwriting the draft) shaped this one. This PR resolves the position by message id on every keypress instead of holding an offset, which removes the re-anchoring effects and the attachment restore that those findings came from.

Takeover changes

Two commits added after rebasing on main:

  • A caret at a soft-wrap boundary belongs to two visual lines and the collapsed range reports a rect for each. The edge check took the first rect, so ArrowUp at the start of the second wrapped line recalled an older prompt instead of moving the caret. The check now measures from the edge under test, so an ambiguous caret never claims the key.
  • A typed draft with no active recall never steps, so the handler returns before the DOM measurement and the entry build for that case.

Verification

  • vp test run src/components/chat/composerPromptHistory.test.ts (16 tests)
  • tsgo --noEmit for apps/web
  • vp lint and vp fmt on the touched files
  • Headless Chromium against a worktree copy of real thread data: recall newest and older, forward and clear, typed text ignores arrows, first and last visual line rule on multi-line and soft-wrapped prompts, edit and type-and-delete end browsing, modifier keys and the slash menu keep priority, thread switch resets browsing and keeps each thread's draft.

Built by Claude Fable 5.1 through Claude Code.


Note

Low Risk Composer keyboard UX only; guarded by empty-draft rules, visual-edge checks, and existing menu/approval priorities—no auth, sync, or send-path changes beyond stripping logic for display.

Overview Adds terminal-style prompt recall in the chat composer: ArrowUp on an empty composer walks back through prior user prompts in the current thread; ArrowDown moves forward and clears the field past the newest entry.

History is built on each keypress from promptHistoryMessages (timeline user messages) via new composerPromptHistory helpers that normalize sent text (strip send-time terminal/element blocks, review comments, ultrathink prefix, attachment-only and plan-implementation prompts) and collapse consecutive duplicates by message id. Browsing state resets on thread change or when the composer text no longer matches the recalled string; recall is skipped when attachments, elements, or other composer extras are present.

ComposerPromptEditor exposes isCaretOnVisualEdge (with DOM rect probing for soft wraps) so arrows only hijack navigation when the caret is on the first or last visual line and the draft is empty or an unedited recall. ChatView passes timeline messages into ChatComposer; the attachment-only bootstrap string moves to the shared history module. User docs describe the behavior.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5fe0b5ebb1b09b849df32dafd0b5bef72c6d601c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add prompt recall with up arrow to ChatComposer

Passes the route's timeline messages from ChatView.tsx to ChatComposer through a new prompt-history prop so previously sent prompts can be recalled with the up arrow. Moves the attachment-only bootstrap prompt constant out of ChatView into a shared composer prompt-history module.

Macroscope summarized 5fe0b5e.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.7 KiB+231 B (+1.7%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB+6 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.7 KiB+225 B (+3.4%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB58.5 KiB+1.5 KiB (+2.6%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB+12 B (+0.1%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB+3 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.5 KiB+9 B (+0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.9 KiB+44 B (+0.1%)66.4 KiB✅
      ClaudeLive turn messages910+1 (+11.1%)21✅

      Baseline: df8e0eb · PR result: 5fe0b5e · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low user/composer.md:162

      The documentation incorrectly limits recall to the first line, so it contradicts the ArrowDown behavior for recalled multi-line or wrapped prompts, which is available on the final visual line. Describe the separate first-line and last-line conditions for ArrowUp and ArrowDown.

      the caret is on the first visual line for `ArrowUp` or the last visual line for `ArrowDown`, and the text is an unedited recalled prompt. Editing a recalled
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @docs/user/composer.md around line 162:
      
      The documentation incorrectly limits recall to the first line, so it contradicts the `ArrowDown` behavior for recalled multi-line or wrapped prompts, which is available on the final visual line. Describe the separate first-line and last-line conditions for `ArrowUp` and `ArrowDown`.
    4. t3dotgg(GitHub profile, opens in a new tab)commented

      Note

      🤖 Claude Fable 5.1 responding on behalf of Theo

      Fixed in 29ed148. The docs now state the first-line rule for ArrowUp and the last-line rule for ArrowDown separately, and mention that a composer holding an attachment does not count as empty.

    5. The direction-specific conditions are now present, but please say “first/last visual line” to avoid ambiguity for wrapped prompts.

    6. Note

      🤖 Claude Fable 5.1 responding on behalf of Theo

      Done in a1df922989. The docs now say "first visual line" and "last visual line, counting wrapped lines".

    7. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR adds an always-on prompt-history interaction to the production composer, including new state navigation, sent-message normalization, and browser caret-line measurement. The scope is focused and tested at the helper level, but the new user-facing behavior and nontrivial keyboard/editor integration warrant human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    8. Review fix ready — resolves the open caretLineRect finding (probing the wrapped text neighbour's first visual line instead of the caret's line).

      I verified the Macroscope suggestion locally on top of 8f98814: it applies cleanly and is correct — in the element-container branch the caret sits after the previous child, so the probe now measures the character on the caret's side of the neighbour text node, matching the text-container branch.

      Verification on my side: vp test run apps/web/src/components/chat/composerPromptHistory.test.ts (15 passed), tsgo --noEmit for apps/web, plus lint and format on the touched file.

      --- a/apps/web/src/components/ComposerPromptEditor.tsx
      +++ b/apps/web/src/components/ComposerPromptEditor.tsx
      @@ -962,8 +962,13 @@ function caretLineRect(range: Range): DOMRect | null {
           const neighbourRect = neighbour.getBoundingClientRect();
           if (neighbourRect.height > 0) return neighbourRect;
         } else if (neighbour instanceof Text && neighbour.data.length > 0) {
      +    // Probe the character on the caret's side: a wrapped text node's first
      +    // rect is its first visual line, not necessarily the caret's line.
      +    const isBeforeCaret = neighbour === container.childNodes[range.startOffset - 1];
      +    const probeStart = isBeforeCaret ? neighbour.data.length - 1 : 0;
           const probeRange = document.createRange();
      -    probeRange.selectNodeContents(neighbour);
      +    probeRange.setStart(neighbour, probeStart);
      +    probeRange.setEnd(neighbour, probeStart + 1);
           const probeRect = Array.from(probeRange.getClientRects()).find((rect) => rect.height > 0);
           if (probeRect) return probeRect;
         }

      Suggested commit message: fix(web): probe the caret-side character beside inline chips

    9. Note

      🤖 Claude Fable 5.1 responding on behalf of Theo

      Applied in bf0c7e2, thanks for checking it against the head. The change is the Macroscope suggestion as posted, so the thread is resolved.

    10. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 483a50d8d62ffa6594d09ef47bc16a84f49b78e8. Configure [here](https://www.cursor.com/dashboard/bugbot).
    11. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This note is part of an automated cleanup pass.

      Preserve the text-history cases from #7952 at head b67ba9f3 before merging this feature. Its helper tests distinguish identical prompt text by message ID, preserve exact optimistic promptHistoryText, leave ArrowUp to the editor at the oldest entry, and restore the draft when moving past the newest entry. Keep IME, menus, and attached-context gates. Local feedback submissions must not become recallable prompts. Attachment fetching is outside this text-only scope. These are review cases, not code transferred by this cleanup.

Sign in to join this conversation.