Skip to content

refactor: move completion session/menu infrastructure from shell to dispatcher#2189

Open
curtisman wants to merge 6 commits intomainfrom
copilot/refactor-cli-completion-code
Open

refactor: move completion session/menu infrastructure from shell to dispatcher#2189
curtisman wants to merge 6 commits intomainfrom
copilot/refactor-cli-completion-code

Conversation

@curtisman
Copy link
Copy Markdown
Member

Summary

Moves the completion infrastructure (PartialCompletionSession, SearchMenuBase, prefix tree TST, and related types) from the shell (Electron) package into dispatcher/helpers/completion, making it reusable by both the shell renderer and the CLI.

Changes

Moved to dispatcher

  • PartialCompletionSession (formerly shell/src/renderer/src/partialCompletionSession.tsdispatcher/src/helpers/completion/session.ts)
  • SearchMenuBase, normalizeMatchText, TST (formerly shell/src/renderer/src/prefixTree.ts + searchMenuBase.tsdispatcher/src/helpers/completion/searchMenu.ts)
  • Types: SearchMenuItem, SearchMenuPosition now live in dispatcher and are re-exported by the shell's electronTypes.ts

New CLI search menu

  • CliSearchMenu — terminal adapter for SearchMenuBase that captures trie-filtered items for ghost-text rendering in enhancedConsole.ts

Session-based completions in CLI

  • enhancedConsole.ts now supports a PartialCompletionSession-driven mode alongside the legacy callback mode
  • Keystrokes route through session.update() for proper grammar-aware, direction-sensitive completions
  • CompletionSource<T> union type accepts either a callback or an ICompletionDispatcher

Simplified callers

  • connect.ts and interactive.ts removed ~120 lines of duplicated getCompletionsData() logic
  • Both now pass the dispatcher directly as the completion source

Tests moved

  • All partialCompletion spec files moved from shell/test/ to dispatcher/test/
  • New searchMenuBase.spec.ts validates the base adapter contract
  • Shell retains only switchMode.spec.ts with a slimmed helper
  • Jest config updated with moduleNameMapper for ../src/dist/ resolution

Cleanup

  • Removed shell's action-grammar dev dependency
  • Removed needsSeparatorInAutoMode re-export wrapper (session.ts imports directly)
  • Prettier formatting fixes in fix-dependabot-alerts.mjs

Copilot AI and others added 6 commits April 11, 2026 06:17
…l + CLI to use them

Agent-Logs-Url: https://github.com/microsoft/TypeAgent/sessions/8766b4b5-3498-4828-8c69-9f701f721f2a

Co-authored-by: curtisman <12101885+curtisman@users.noreply.github.com>
…prove comment clarity

Agent-Logs-Url: https://github.com/microsoft/TypeAgent/sessions/8766b4b5-3498-4828-8c69-9f701f721f2a

Co-authored-by: curtisman <12101885+curtisman@users.noreply.github.com>
… wrappers

- Rename debug namespace from typeagent:shell:partial to typeagent:completion:partial
- Narrow barrel export in completion/index.ts (exclude TSTNode)
- Clarify needQuotes comment in SearchMenuItem
- Delete shell re-export files (partialCompletionSession.ts, prefixTree.ts, searchMenuBase.ts)
- Update shell imports to use agent-dispatcher/helpers/completion directly
- Move 8 PartialCompletionSession test suites to dispatcher package
- Fix pre-existing TS2304 in electronTypes.ts (split export type into import + re-export)
- Add moduleNameMapper for subdirectory tests in dispatcher jest config
- Use undefined instead of null for session/menu state in enhancedConsole
- Extract repeated position callback into shared getPos const
- Remove redundant render() calls after session.update() (menu callback handles it)
- Add session.resetToIdle() on Enter path for consistency with Tab
- Add CompletionSource<T> type alias for union parameter
- Trim shell test helpers to minimal subset needed by switchMode tests
- Make jest moduleNameMapper depth-agnostic for src/ imports
- Add SearchMenuBase adapter unit tests
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