Skip to content

feat(history): skip commands typed with a leading space - #990

Merged
Kuddev merged 3 commits into
Kuddev:mainfrom
drchiodo:feat/issue-988-history-leading-space-20261114
Nov 16, 2026
Merged

Kuddev merged 3 commits into
Kuddev:mainfrom
drchiodo:feat/issue-988-history-leading-space-20261114

Conversation

@drchiodo

@drchiodo drchiodo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Result / 用户结果

Part 1 of #988. Part 2, the setting that keeps history off disk, is #991.

A command typed with a leading space now stays out of Pebrel's suggestion history, both in memory and in pebrel_history*.jsonl. You can run something like mysql -p... without Pebrel saving it.

This is Pebrel's own rule, close to bash with HISTCONTROL=ignorespace and zsh with HIST_IGNORE_SPACE. Those shells only do it when configured, and PSReadLine does not do it at all. The shells' own history files are untouched.

Design / 设计边界

  • Responsibility and affected modules:
    • NebulaHistory::record owns the rule: a raw line that starts with a space returns before append and before the in-memory insert.
    • The GPUI Enter path (gpui_shell/terminal/suggest.rs) and the legacy one (display/completion.rs, completion_context::record_completion_command) trimmed the line before recording it. They now pass the raw line and keep the trimmed copy for the tab icon (last_committed) and environment tracking.
    • The PSReadLine report in completion_shell_report already passed the raw line.
  • display/input_state.rs: the CMD prompt fallback, used when no OSC 133;B boundary marks where the input starts, cannot tell from the grid whether a space after > belongs to a $P$G prompt or was typed. It now asks the keystroke mirror (line_buf): it drops one space only when the rest of the line is exactly what was typed. When the mirror is empty or does not match (history recall, native completion, cursor edits), the space stays, and history skips the line. Pebrel-launched cmd emits the boundary, so this only matters for nested or foreign cmd sessions.
  • Why this belongs here; interfaces that remain unchanged: one authority in NebulaHistory::record; no caller decides on its own. The history file format does not change.
  • Dependency, data-format, threading, or lifetime changes: none.
  • Compatibility and migration/fallback behavior:
    • Existing history loads as before.
    • Every Pebrel shell integration (PowerShell, pointer.sh, pointer.ps1, cmd) emits OSC 133;B after the full prompt, trailing space included. A normal command therefore never starts with a space on the boundary path.
    • One trade-off remains in the CMD fallback without a boundary: with a $P$G prompt, a line the mirror cannot confirm (recalled, completed or edited with the cursor) stays out of history even without a typed space. Pebrel prefers losing that entry to recording a line the user may have hidden.

Evidence / 验证依据

  • Commands and actual results, on Windows 11 x64:
    • cargo test -p nebula --bin pebrel --features gpui-shell,gpui-test-support --locked -- input_state prompt completion history suggest leading_space: 277 passed.
    • One test failed: platform::local_paths::tests::completion_directory_quotes_survive_native_cmd_and_powershell_arguments. It fails the same way on upstream/main without this change on my machine.
    • python scripts/check_architecture.py --base 09e5eb47: passes.
    • rustfmt --check on the changed files: clean.
  • Not run: the full workspace suite, any Unix build. The non-Windows branch of the legacy commit path is only compiled by CI.
  • Regression tests: what fails before the fix?
    • nebula_history::leading_space_commands_stay_out_of_memory_and_disk: record directly.
    • completion_context::leading_space_submissions_stay_out_of_grid_and_native_history: grid Enter plus the PSReadLine confirmation, then a PSReadLine-only line. It also checks that a normal command is still recorded.
    • terminal::suggest::enter_skips_history_only_for_a_leading_space: the GPUI Enter path, including the tab-icon text and a normal command with a trailing space.
    • cmd_prompt_without_boundary_keeps_a_typed_leading_space_for_history: feeds the terminal grid without a boundary. It covers a C:\work> prompt and a C:\work> prompt, each with ordinary input and with a typed leading space, plus history recall without a mirror on both. echo private after C:\work> keeps its space, which the review reproduced as recorded on 85edffbb.
  • UI changes: none.
  • Hot-path changes: one extra String clone per Enter.

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. (No new messages.)
  • Governance changes include a counterexample, corrected contract, tests, and a maintainer-reviewed decision. (No governance changes.)

A leading space now keeps a command out of Pebrel's suggestion history,
both in memory and in pebrel_history*.jsonl. This matches bash with
HISTCONTROL=ignorespace and zsh with HIST_IGNORE_SPACE, and gives you a
way to run a command with a secret argument without saving it to disk.

NebulaHistory::record owns the rule. The GPUI and legacy Enter paths
used to trim the line before recording it, so they now pass the raw
line and keep the trimmed copy for the tab icon and environment
tracking. The PSReadLine report already passed the raw line.

Refs Kuddev#988
A CMD prompt such as `$P$G ` puts a space between `>` and the input.
Without an OSC 133;B boundary, the CMD fallback in prompt_line_snapshot
kept that space, so every command looked like a leading-space opt-out
and history stopped for that session. Strip one space after `>`, as the
arrow prompt branch already does.

Pebrel-launched cmd emits the boundary, so this affects nested or
foreign cmd sessions only.

Refs Kuddev#988
@drchiodo
drchiodo marked this pull request as ready for review November 14, 2026 03:08
@drchiodo
drchiodo requested a review from Kuddev as a code owner November 14, 2026 03:08

@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.

I reproduced the CMD fallback gap on 85edffbb with the terminal grid and the history writer against isolated files. With a plain C:\work> prompt and no OSC 133;B boundary, typing echo private produces C:\work> echo private. The fallback in nebula_app/src/display/input_state.rs removes the user's space, and Pebrel writes echo private to its history. With an OSC 133;B boundary the same command stays out of the file. A normal command after a prompt with a separator still records correctly.

Please use input evidence to distinguish the prompt's separator from a typed space. If the fallback cannot establish which it was, skip recording the ambiguous line. Please cover the plain prompt and a prompt with a trailing separator, each with ordinary input and with a user-typed leading space, plus a history-recall case without a current typed mirror.

Without an OSC 133;B boundary, the CMD fallback dropped any space after
`>`. With a plain `C:\work>` prompt, ` echo private` lost its space and
went into history. Drop the space only when the rest of the line matches
the keystroke mirror exactly, which identifies a `$P$G ` separator. Recall,
completion and cursor edits keep the space, so history skips the line.

The grid test covers a prompt with and without a trailing separator, each
with ordinary input, a typed leading space, and history recall.
@drchiodo

Copy link
Copy Markdown
Contributor Author

Thanks for the repro. In 453018e, the CMD fallback drops the space after > only when the rest of the line matches the keystroke mirror (line_buf) exactly, which identifies a $P$G separator. When the mirror is empty or does not match, the space stays and history skips the line.

cmd_prompt_without_boundary_keeps_a_typed_leading_space_for_history feeds the grid without a boundary. It covers C:\work> and C:\work> , each with ordinary input and with a typed leading space, plus history recall without a mirror on both. echo private after C:\work> now keeps its space.

Trade-off: with a $P$G prompt and no boundary, a recalled, completed or cursor-edited line stays out of history even without a typed space. I noted it in the description.

@Kuddev
Kuddev merged commit 8224162 into Kuddev:main Nov 16, 2026
14 checks passed
@drchiodo
drchiodo deleted the feat/issue-988-history-leading-space-20261114 branch November 16, 2026 12:22
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.

2 participants