Repository navigation
feat(history): skip commands typed with a leading space - #990
Conversation
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
Kuddev
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the repro. In 453018e, the CMD fallback drops the space after
Trade-off: with a |
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 likemysql -p...without Pebrel saving it.This is Pebrel's own rule, close to bash with
HISTCONTROL=ignorespaceand zsh withHIST_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 / 设计边界
NebulaHistory::recordowns the rule: a raw line that starts with a space returns beforeappendand before the in-memory insert.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.completion_shell_reportalready 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$Gprompt 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.NebulaHistory::record; no caller decides on its own. The history file format does not change.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.$P$Gprompt, 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 / 验证依据
cargo test -p nebula --bin pebrel --features gpui-shell,gpui-test-support --locked -- input_state prompt completion history suggest leading_space: 277 passed.platform::local_paths::tests::completion_directory_quotes_survive_native_cmd_and_powershell_arguments. It fails the same way onupstream/mainwithout this change on my machine.python scripts/check_architecture.py --base 09e5eb47: passes.rustfmt --checkon the changed files: clean.nebula_history::leading_space_commands_stay_out_of_memory_and_disk:recorddirectly.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 aC:\work>prompt and aC:\work>prompt, each with ordinary input and with a typed leading space, plus history recall without a mirror on both.echo privateafterC:\work>keeps its space, which the review reproduced as recorded on85edffbb.Stringclone per Enter.Required Review / 必须确认
CONTRIBUTING.md,docs/architecture.md, anddocs/project-constraints.md.python3 scripts/check_architecture.py --base <PR-base-commit>passes; budgets were not inflated to fit the change.