Skip to content

feat(cosh): add Tab-completion for shell mode#131

Merged
samchu-zsl merged 1 commit intoalibaba:mainfrom
kongche-jbw:feature/cosh/command-autocomplete
Apr 9, 2026
Merged

feat(cosh): add Tab-completion for shell mode#131
samchu-zsl merged 1 commit intoalibaba:mainfrom
kongche-jbw:feature/cosh/command-autocomplete

Conversation

@kongche-jbw
Copy link
Copy Markdown
Collaborator

  • Implement useShellCompletion hook with command completion ($PATH executables, 30s cache) and file-system path completion (supports ~/, absolute and relative paths; directories suffixed with /)
  • Integrate shell completion into InputPrompt: Tab triggers/accepts completion, arrow keys navigate suggestions, Enter always falls through to execute the command without interception

Description

Add Tab-key auto-completion for cosh shell mode (!).

When the user enters shell mode by typing !, pressing Tab now:

  • Completes command names (executables on $PATH) when the cursor
    is on the first token; results are cached for 30 s to avoid repeated
    directory scans.
  • Completes file-system paths on subsequent tokens, supporting
    ~/-prefixed, absolute and relative paths; directories are displayed
    with a trailing / and kept open for further tab-navigation.
  • Does not block Enter — the command is always executable
    regardless of completion state.
  • Does not interfere with the existing @-file (AT-mode)
    completion inside shell mode; Tab falls through to the regular
    handler when AT suggestions are already visible.

Related Issue

closes #22

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • cosh (copilot-shell)
  • sec-core (agent-sec-core)
  • skill (os-skills)
  • sight (agentsight)
  • Multiple / Project-wide

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • For cosh: Lint passes, type check passes, and tests pass
  • For sec-core (Rust): cargo clippy -- -D warnings and cargo fmt --check pass
  • For sec-core (Python): Ruff format and pytest pass
  • For skill: Skill directory structure is valid and shell scripts pass syntax check
  • For sight: cargo clippy -- -D warnings and cargo fmt --check pass
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

  1. Start cosh (npm run start in src/copilot-shell)
  2. Type ! to enter shell mode
  3. Type a partial command (e.g. gi) and press Tab → command list
    appears; / to navigate, Tab again to accept
  4. Type a partial path (e.g. ls ~/) and press Tab → file-system
    completions appear; directories are suffixed with /
  5. Press Tab on a directory suggestion to navigate deeper
  6. Press Enter at any time → command executes immediately
  7. In regular (non-shell) mode, type @filename → dropdown appears,
    Tab accepts as before (no regression)

Additional Notes

  • PATH scan is done synchronously but only on the first Tab press;
    results are cached for 30 s at module level.
  • Max suggestions per trigger: 100 (prevents UI overflow).
  • New file: packages/cli/src/ui/hooks/useShellCompletion.ts

- Implement useShellCompletion hook with command completion ($PATH
  executables, 30s cache) and file-system path completion (supports
  ~/, absolute and relative paths; directories suffixed with /)
- Integrate shell completion into InputPrompt: Tab triggers/accepts
  completion, arrow keys navigate suggestions, Enter always falls
  through to execute the command without interception
@kongche-jbw kongche-jbw self-assigned this Apr 8, 2026
@kongche-jbw kongche-jbw added the component:cosh src/copilot-shell/ label Apr 8, 2026
@kongche-jbw kongche-jbw requested a review from samchu-zsl April 8, 2026 09:45
Copy link
Copy Markdown
Collaborator

@samchu-zsl samchu-zsl left a comment

Choose a reason for hiding this comment

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

A performance concern: will processing a large number of files - say, 10k or more - in the directory impact UI responsiveness?

@samchu-zsl samchu-zsl requested a review from casparant April 9, 2026 02:49
@kongche-jbw
Copy link
Copy Markdown
Collaborator Author

A performance concern: will processing a large number of files - say, 10k or more - in the directory impact UI responsiveness?

Thanks for raising this! Since completions are only triggered on explicit Tab press (not on every keystroke), which limits exposure. I've filed this as a follow-up optimization item — moving the directory scan to an async path (or a Worker thread) to keep the UI fully responsive regardless of directory size.

Copy link
Copy Markdown
Collaborator

@samchu-zsl samchu-zsl left a comment

Choose a reason for hiding this comment

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

Basic functionality LGTM. Remaining performance optimizations will be tracked in the issue.

@samchu-zsl samchu-zsl merged commit c5f92a4 into alibaba:main Apr 9, 2026
10 checks passed
@samchu-zsl
Copy link
Copy Markdown
Collaborator

Progress on this optimization is being tracked in GitHub issue #138.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cosh):命令模式支持自动补全

2 participants