Skip to content

feat(terminal): restore the last 10 commands per tab on reopen - #51

Merged
arifintahu merged 8 commits into
mainfrom
feat/command-history
Nov 16, 2026
Merged

arifintahu merged 8 commits into
mainfrom
feat/command-history

Conversation

@arifintahu

@arifintahu arifintahu commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

What and why

Closes #50. A reopened tab starts with an empty shell history, so Up recalls nothing from before the close. Each pane now keeps its last 10 commands in session.json and the new shell's own history is seeded with them, so Up and Ctrl+R work as usual (Git Bash, WSL, pwsh; not cmd).

  • Capture: the prompt hooks emit each new command as OSC 133;E;<nonce>;<percent-encoded command>. The nonce is a per-session secret passed in EMBER_NONCE and kept in an unexported shell variable, so a mark printed by a program (cat, curl, ssh output) is ignored and cannot plant a command for the next restore.
  • Record: pushPaneCommand filters (empty, leading space, multi-line, over 1000 chars, obvious secrets such as token=, password:, Authorization), drops a consecutive duplicate and keeps the newest 10. SavedPane.history is additive; SESSION_VERSION stays 1.
  • Restore: the list goes spawnPane -> session_create -> HookInput.restore_history -> env EMBER_HIST (newest 10, lines over 1000 chars dropped). The hook loads it with history -s / AddToHistory on the first prompt. The seeds are marked as saved (history -a /dev/null, PSReadLine SaveNothing) so they are not appended to the user's history file again. EMBER_HIST and EMBER_NONCE are only set where the hook is installed, since the hook is what unsets them.

Known gaps (not filed): session.json is plain text and the secret filter is best effort (misses --password x, curl -u user:pass, URL credentials, bare token prefixes); a few control characters are not encoded in the bash hook; a failed split's history can attach to the next split; Clear-History in pwsh makes the prompt error once; pasting a multi-line script into bash records its last 10 lines; Git Bash spawns one history 1 subshell after each command (about 14 ms measured).

How you checked it

CI runs only after a merge, so these are checked locally:

  • cargo fmt --check, cargo clippy -- -D warnings and cargo test pass (111 tests)
  • pnpm turbo check test build and pnpm version:check pass (181 frontend tests; 9 svelte-check warnings, all in ProfileEditor.svelte, untouched)
  • Bug fixes have a test that failed before the fix
  • No secrets, personal paths or machine names in the diff
  • Docs and CHANGELOG.md updated if behaviour changed

Also checked: bash_hook_end_to_end runs the real hook in Git Bash (encoding, nonce, leading-space command kept for the app to drop, empty Enter silent, seeds literal and not written to HISTFILE; skipped where Git Bash is missing). The WSL bash hook and the pwsh 7 hook were exercised from scripts. A fresh-context review found no critical issues; its four important findings are fixed here.

Checked in the running dev build (pnpm dev, Git Bash tab, clean session.json): ran echo first-cmd, echo 'a;b%c', echo hidden-leading-space, export TOKEN=abc123, echo last-cmd. session.json saved only echo first-cmd, echo 'a;b%c', echo last-cmd (leading-space and TOKEN= lines skipped, ; and % intact). After close and reopen, Up recalled echo last-cmd, echo 'a;b%c', echo first-cmd in that order. A second close and reopen left the same three entries (no duplicates). Git Bash did not write these commands to ~/.bash_history on tab close, so this is the only place they persist.

Not verified: WSL, pwsh and split panes in the running app (hooks exercised from scripts only), PSReadLine seeding in a real interactive pwsh, and macOS.

@arifintahu
arifintahu merged commit 7c066d1 into main Nov 16, 2026
4 checks passed
@arifintahu
arifintahu deleted the feat/command-history branch November 23, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: restore the last 10 commands per tab on reopen

2 participants