Skip to content

feat(history): add a switch to keep command history off disk - #991

Open
drchiodo wants to merge 6 commits into
Kuddev:mainfrom
drchiodo:feat/issue-988-history-persistence-toggle-20261114
Open

drchiodo wants to merge 6 commits into
Kuddev:mainfrom
drchiodo:feat/issue-988-history-persistence-toggle-20261114

Conversation

@drchiodo

@drchiodo drchiodo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Result / 用户结果

Closes #988, together with #990 for part 1 (leading-space commands).

The Completion group in Settings gets a switch, Save command history to disk, on by default. When you turn it off:

  • new commands stay in memory and keep feeding suggestions until Pebrel exits;
  • nothing is appended to pebrel_history.jsonl, pebrel_history_wsl.jsonl or pebrel_history_ssh.jsonl;
  • saved history still loads and is still suggested, and Clear history remains the way to delete it;
  • open terminals follow the change at once.

One switch covers local, WSL and SSH sessions.

This adds a persisted settings key (command_history_persist). CONTRIBUTING asks for a discussion before a new persisted setting, so I opened this as a draft for that review. The note in architecture/notes/pebrel_app/completion/2026-11-14-command-history-persistence.md records the decision and the rejected options: a separate SSH switch, ignoring saved files, and deleting them on toggle.

Design / 设计边界

  • Responsibility and affected modules:
    • pebrel_settings: command_history_persist, default true, read with bool_on(...).unwrap_or(true) and added to the reset list.
    • nebula_history: a process-wide AtomicBool, starting on, that append checks before opening a file. append is the only writer of the history files.
    • gpui_shell/completion_history::init sets the flag from the settings global at startup, before terminal::init, and updates it from an observer on that global. The Settings pane, reset and backup restore all replace that global.
    • settings_pane.rs: switch_row, override marker, and the save-failure toast.
    • i18n: settings.completion.history.persist and persist_description in the en-US and zh-CN base catalogs, plus search keywords. Other languages fall back to English.
  • Why this belongs here; interfaces that remain unchanged: settings own the value, the history module owns the write, and the GPUI layer only connects them. The history file format does not change.
  • Dependency, data-format, threading, or lifetime changes: one new boolean settings key. The observer lives for the application lifetime.
  • Compatibility and migration/fallback behavior:
    • A missing or invalid value keeps writing history. Reset restores it.
    • The legacy renderer does not apply the switch and keeps writing history.
    • Hand edits to the settings file apply at the next start, like other settings.
    • The switch covers command text only. directory_history.json still stores the working directories of local terminals. Opt-in PEBREL_DEBUG_LOG still logs commands to pebrel_debug.log.

Evidence / 验证依据

  • Commands and actual results, on Windows 11 x64, after merging main at 303a7f4 (which renamed nebula_app to pebrel_app):
    • cargo test -p pebrel-settings --locked: 110 passed.
    • cargo test --manifest-path tools/i18n-contract/Cargo.toml --locked: 24 passed.
    • cargo test -p pebrel --bin pebrel --features gpui-shell,gpui-test-support --locked -- command_history nebula_history i18n completion_history settings_pane: 154 passed.
    • python scripts/tests/test_ci_native_tests.py: 18 passed. cargo nextest is not installed here; cargo test -- --exact on the full path in the new filter runs the switch test and passes.
    • python scripts/check_architecture.py --base 303a7f4e: passes. pebrel_settings/src/lib.rs grows by 4 lines, to 1995, and stays under the cap; the new tests live in reset.rs.
    • rustfmt --check on the changed files: clean.
  • Manual run of a debug build from this branch, on Windows 11 at 96 DPI, with PEBREL_CONFIG_DIR pointing to an empty directory:
    • With the switch off, echo gate-check-off created no history file.
    • After turning it back on, echo gate-check-on was appended to pebrel_history.jsonl, and gate-check-off was not in it.
    • Toggling wrote command_history_persist=0 / =1 to the settings file.
  • Not run: the full workspace suite, any Unix build.
  • Regression tests: what fails before the fix?
    • reset::command_history_persistence_defaults_on_round_trips_and_resets: defaults, invalid values, round trip, reset.
    • nebula_history::disabled_persistence_keeps_new_commands_in_memory_only: with the flag off, a recorded command is suggested but does not reach the SSH history file.
    • command_history_persistence_switch_saves_and_drives_the_write_gate: runs the startup observer, clicks the real switch twice, and checks the saved value, the settings global and the write gate.
    • The two tests that flip the process-wide flag share a lock. The switch test writes the real settings file, so .config/nextest.toml puts it in the theme-studio group with the other settings fixtures, and scripts/tests/test_ci_native_tests.py checks that entry.
  • UI changes: one switch row above Clear history.
    • I checked it by eye in the dark theme (Nord, Italian UI) and the light theme (Paper, Simplified Chinese), on and off.
    • The row lines up with the other switches. The three-line English description and the two-line Chinese one wrap cleanly, and the reset marker appears when the value differs from the default.
    • The Italian UI shows the English text because it-IT.json has none of the command-history strings yet.
    • Not checked: keyboard navigation to the switch, DPI other than 96, other languages.
    • Screenshots (1332x766 window, 96 DPI):
03-row-on
Dark theme, Italian UI (English fallback), switch on
04-row-off
Switch off: reset marker shown
05-light-zh
Light theme, Simplified Chinese, switch off
08-final
Light theme, Simplified Chinese, switch on
  • Hot-path changes: one relaxed atomic load per recorded command.

Required Review / 必须确认

  • I followed CONTRIBUTING.md, docs/architecture.md, and docs/project-constraints.md.
  • I split responsibilities, not arbitrary line ranges; no duplicate behavior authority was added.
  • python3 scripts/check_architecture.py --base <PR-base-commit> passes; budgets were not inflated to fit the change.
  • Tests cover success and failure; platform/feature coverage limitations are stated.
  • New messages use typed i18n IDs and matching placeholders; untranslated content has an explicit fallback.
  • Governance changes include a counterexample, corrected contract, tests, and a maintainer-reviewed decision. (No governance changes.)

Settings > Completion gets "Save command history to disk", on by
default. When you turn it off, new commands stay in memory and keep
feeding suggestions until Pebrel exits, but nothing is appended to
pebrel_history*.jsonl. Saved history still loads, and Clear history
remains the way to delete it. One switch covers local, WSL and SSH
sessions.

nebula_settings stores the command_history_persist key with reset and
round-trip tests. nebula_history checks a process-wide flag before
appending, and the GPUI app sets that flag at startup and from an
observer on the settings global, so open terminals follow the switch
at once. The legacy renderer does not apply it.

The architecture note records the rejected options: a separate SSH
switch, ignoring saved files, and deleting them on toggle.

Closes Kuddev#988
The leading-space branch for Kuddev#988 adds its test at the same spot, so
both PRs would conflict on merge. Moving this one avoids the rebase.
The GPUI switch test now runs completion_history::init and checks the
history write gate after each click, not only the settings global.
Both tests that flip the process-wide gate take a shared lock, so they
cannot see each other's state when they run in parallel.

The note now says that the switch covers command text only:
directory_history.json still stores local working directories. It also
says that hand edits to the settings file apply at the next start, and
it lists both entry points into NebulaHistory::record.

Refs Kuddev#988
@drchiodo

drchiodo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Native tests (macos-26) failed on this PR with 4 of 3540 tests. I think they are flaky and unrelated to this change:

  • gpui_shell::terminal::view::pointer::tests::dragging_across_a_rendered_formula_keeps_hit_mapping_and_copies_source ("the real rendered frame must compact the formula before selection")
  • gpui_shell::terminal::view::reading::tests::native_result_compact_hover_tools_and_copy_feedback (button bounds outside a 6 px tall container)
  • gpui_shell::terminal::view::reading::tests::native_result_mount_preserves_grid_and_isolates_pointer (empty Markdown drag selection)
  • gpui_shell::workspace::terminal_activity::tests::session_failure::failed_startup_keeps_last_tab_diagnostics_and_shell_choice (banner bounds)

Job: https://github.com/Kuddev/pebrel/actions/runs/43547254984/job/132301544185

What I checked:

  • All four are GPUI layout or render-timing assertions in terminal views and the workspace banner. None of them touches command history, settings or completion_history::init, and nextest runs each test in its own process, so the new process-wide flag cannot leak into them.
  • The same macOS suite passed on fix(runtime_api): protect the discovery file and runtime tokens #989, which runs on the same base commit without these changes.
  • Locally on Windows, on this branch, the first three pass. The fourth fails at session_failure.rs:64 on upstream/main (09e5eb4) too, so it is environment-dependent.
  • The scheduled main run on 2026-11-13 also failed on macOS with a different GPUI test (file_editor::tests::returning_to_reader_keeps_source_edits_and_blocks_undo_until_source_is_open).

@drchiodo
drchiodo marked this pull request as ready for review November 14, 2026 07:53
@drchiodo
drchiodo requested a review from Kuddev as a code owner November 14, 2026 07:53

@Kuddev Kuddev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The history switch works in the isolated storage check: local, WSL, and SSH files stay byte-for-byte unchanged while saving is off, and appending resumes when it is turned back on. The new visible-switch test also passed on the refreshed head.

Please put command_history_persistence_switch_saves_and_drives_the_write_gate in the existing theme-studio nextest group (or use an isolated settings path), and update the CI contract test if the group changes. The new fixture writes and restores the same settings file as the font-size fixture. Its Rust mutex only protects tests in the same process. In Ubuntu CI, the switch test finished while the font-size fixture was running, and that fixture read back 96 instead of the expected 4. The shared path and missing nextest group leave a concrete race even if a rerun passes.

The Intel Mac job separately failed a PowerShell pointer test waiting for an editor report. The history PR does not change that PowerShell code; it still needs a green required check on the corrected head.

…xtures

The switch test writes the real settings file. Its Rust mutex only guards
tests in the same process, and nextest runs each test in its own process,
so on Ubuntu CI it raced the font-size fixture, which read back 96 instead
of 4. Add the test to the theme-studio nextest group and pin the entry in
the CI contract test.
@drchiodo

Copy link
Copy Markdown
Contributor Author

Thanks, you're right. My earlier comment looked only at the macOS run and called the failure unrelated; the Ubuntu failure you linked is a race my test caused. In 19b4341, the switch test joins the theme-studio nextest group, and scripts/tests/test_ci_native_tests.py pins the new entry.

The new head needs a green run of the required checks, Intel Mac included.

@drchiodo

Copy link
Copy Markdown
Contributor Author

CI on 19b4341: every required check passes except Native tests (macos-26-intel), which failed 1 of 3546 tests:

  • gpui_shell::terminal::view::pointer::tests::application_mouse::application_drag_stays_with_the_original_pane panicked at application_mouse.rs:252. The drag reports column 41 where the test expects 40.

Job: https://github.com/Kuddev/pebrel/actions/runs/43707790029/job/132792655996

This test covers application mouse reporting and does not touch command history or settings. The previous Intel Mac run on this PR failed a different test (the PowerShell pointer one you mentioned). The switch test now runs in the theme-studio group and passed on Ubuntu.

Could you re-run the failed Intel Mac job? My account can't.

@drchiodo
drchiodo requested a review from Kuddev November 16, 2026 18:08
Main renamed nebula_app to pebrel_app and nebula_settings to
pebrel_settings. Keep both sides of each conflict: the theme-studio
filter, the settings save-failure list and the search keywords. Point the
note's links and the switch test at the new paths.
@drchiodo

Copy link
Copy Markdown
Contributor Author

I merged main (303a7f4) in 12c2f41 to resolve the conflicts from the nebula_app → pebrel_app rename. Every required check passes on the new head, Intel Mac included, so the earlier re-run request no longer applies.

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.

[Feature] Skip leading-space commands in history and allow disabling disk persistence / 忽略前导空格命令并支持关闭命令历史落盘

2 participants