Skip to content

feat(tui): include shell commands in input history - #1295

Merged
liruifengv merged 9 commits into
mainfrom
feat/shell-input-history
Jul 2, 2026
Merged

feat(tui): include shell commands in input history#1295
liruifengv merged 9 commits into
mainfrom
feat/shell-input-history

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — no related issue; the problem is described below. The approach was discussed and agreed on before implementation.

Problem

The TUI input box supports a shell mode (type ! in an empty box) and input history recall ( / ). Previously, shell commands were deliberately excluded from input history: because the ! is not stored in the text buffer, a recalled shell command would resurface as a bare command in prompt mode and be sent to the agent instead of being executed. As a result, users could not recall previous shell commands at all.

What changed

Shell commands are now saved to input history with a leading ! marker so they can be told apart from prompts. History recall is mode-aware:

  • Recalling a !-prefixed entry strips the ! and restores bash mode, so the command runs as a shell command again.
  • In shell mode, only cycles through previous shell commands.
  • In a normal prompt, browses all history (prompts and shell commands) and switches the editor's mode to match the recalled entry.

This reuses the existing !-prefix convention and is implemented by shadowing the editor's built-in history navigation with a mode-aware version, leaving the rest of the input pipeline unchanged. Existing history entries without a leading ! keep working as prompts, so no migration is needed. Tests and the interaction guides (English and Chinese) are updated accordingly.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Shell commands entered through the `!` prompt are now saved to input history. Recalling one restores bash mode, and in bash mode Up only cycles through previous shell commands while a normal prompt browses all history.
Note that shell commands are now saved to input history and can be recalled in Shell mode, in both the English and Chinese interaction guides.
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a1645f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/pi-tui Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@4a1645f
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4a1645f

commit: 4a1645f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8df8965117

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/components/editor/custom-editor.ts Outdated
Comment thread apps/kimi-code/src/tui/components/editor/custom-editor.ts Outdated
Add two first-class hooks to the editor's history navigation: setHistoryFilter to limit which entries Up/Down visit, and onRecall to decorate a recalled entry before it is shown. Draft restore, direction-aware cursor placement, and undo behavior are unchanged.
Replace the CustomEditor navigateHistory shadow with pi-tui's setHistoryFilter + onRecall hooks, wired in the editor-keyboard controller. This keeps pi-tui's draft-restore and direction-aware cursor behavior intact (the shadow dropped both) and moves the shell/prompt filtering and mode-restore logic into the business layer.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 839a855dc3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/controllers/editor-keyboard.ts
Add onHistoryDraftSave/onHistoryDraftRestore hooks so hosts can stash their own state when entering history browsing and restore it when the user navigates back to the draft. The saved host state is discarded when browsing ends any other way (typing, submit), mirroring the editor draft lifecycle.
Wire pi-tui's history draft save/restore hooks to the editor input mode. Without this, recalling a shell entry and then pressing Down back to an empty draft left the editor in bash mode, so the next typed message was submitted as a shell command.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

Fire onHistoryDraftSave before the history filter runs when entering browse, so the host's filter can read the browse-entry mode rather than a mode that changes as entries are recalled. The captured state is still only committed once a matching entry is found.
Lock the history filter to the input mode captured when entering browse. Previously the filter read inputMode live, so after recalling a shell entry (which flips to bash mode) a second Up would only show shell commands.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fcaececa21

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d11eb9733

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/controllers/editor-keyboard.ts
Comment thread apps/kimi-code/src/utils/history/input-history.ts Outdated
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9af718351

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/utils/history/input-history.ts Outdated
Comment thread apps/kimi-code/src/tui/controllers/editor-keyboard.ts
@liruifengv
liruifengv force-pushed the feat/shell-input-history branch from d7ee8f6 to fcaecec Compare July 2, 2026 09:47
@liruifengv
liruifengv merged commit 77eb3a9 into main Jul 2, 2026
9 checks passed
@liruifengv
liruifengv deleted the feat/shell-input-history branch July 2, 2026 09:59
@github-actions github-actions Bot mentioned this pull request Jul 2, 2026
RealKai42 added a commit that referenced this pull request Jul 2, 2026
Resolve overlap with #1295 (paste-test editor stub gains setHistoryFilter
alongside the new sessionDir harness option) and fold #1296's read-media
coordinate warning into the downsampling tip to avoid a duplicated bullet.
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.

1 participant