name: t3-composer-suggestions-workflow
description: Use when adding, changing, debugging, or reviewing T3 Code chat composer suggestions, ChatView input behavior, @ file mentions, // skill mentions, / slash commands, /model selection, ComposerCommandMenu, ComposerPromptEditor, composer trigger detection, prompt replacement, or keyboard navigation in the composer. Trigger on ChatView composer, composer menu, mention picker, file mention, skill mention, double slash, slash command, model command, prompt editor, Lexical composer, inline composer chip, or detectComposerTrigger.
T3 Composer Suggestions Workflow
Use this skill when the chat composer recognizes a token, shows a suggestion menu, inserts a prompt reference, or renders an inline composer chip.
The composer has a few separate concerns. Keep them separate when making changes:
- trigger detection: pure text/cursor logic
- suggestion data: React Query hooks or local item builders
- menu rendering:
ComposerCommandMenu - prompt mutation: replacement ranges and cursor updates
- inline display: Lexical mention nodes and chips
Primary Files
Core trigger and prompt logic:
apps/web/src/composer-logic.tsapps/web/src/composer-editor-mentions.tsapps/web/src/components/ComposerPromptEditor.tsxapps/web/src/components/composerInlineChip.ts
Chat composer wiring:
apps/web/src/components/ChatView.tsxapps/web/src/components/chat/ComposerCommandMenu.tsxapps/web/src/components/chat/composerSuggestionItems.tsapps/web/src/components/chat/ProviderModelPicker.tsxapps/web/src/components/chat/composerProviderRegistry.tsx
Data hooks used by suggestions:
apps/web/src/lib/projectReactQuery.tsapps/web/src/lib/skillReactQuery.tsapps/web/src/lib/providerReactQuery.ts
Tests:
apps/web/src/composer-logic.test.tsapps/web/src/components/ChatView.browser.tsxapps/web/src/components/chat/composerSuggestionItems.test.ts- nearby
*.browser.tsxtests for provider/model picker behavior
Current Trigger Model
detectComposerTrigger(text, cursor) owns token recognition:
@query-> path suggestions//query-> skill suggestions/queryat line start -> slash command suggestions/model queryat line start -> model suggestions
Do not add trigger parsing directly in ChatView or UI components. Extend composer-logic.ts first, then wire the UI around the new trigger kind.
Cursor values are tricky because the editor collapses inline mention nodes to a single visible character while prompt text stores expanded references. Use existing helpers:
expandCollapsedComposerCursorcollapseExpandedComposerCursorclampCollapsedComposerCursorisCollapsedCursorAdjacentToInlineToken
Suggestion Source Rules
Prefer source-specific helpers over inline mapping in ChatView.
Existing item builders live in:
apps/web/src/components/chat/composerSuggestionItems.ts
Use or extend:
buildPathComposerItemsbuildSkillComposerItemsbuildSlashCommandComposerItemsbuildModelComposerItems
If adding a new suggestion type, add a source builder and focused tests beside it. Keep ChatView responsible for orchestration, not per-source item shaping.
React Query Rules
Use shared query option or hook helpers for remote data.
Good patterns:
- file/path suggestions:
projectSearchEntriesQueryOptions - skill suggestions:
useSkillSuggestions - provider/model data: server config/provider helpers already consumed by
ChatView
Query keys must include every input that changes the result. Use enabled to avoid fetching when the trigger kind is inactive, but do not use enabled to hide incomplete cache keys.
When passing optional values into option helpers under exactOptionalPropertyTypes, omit absent properties instead of passing explicit undefined.
Prompt Replacement Rules
Selection replacement happens around the active trigger range.
In ChatView, inspect:
resolveActiveComposerTriggeronSelectComposerItemextendReplacementRangeForTrailingSpaceapplyPromptReplacement
Rules:
- Re-read the active editor snapshot before applying a selection.
- Use the current trigger range from
resolveActiveComposerTrigger(), not stale state from render. - Preserve the trailing-space behavior so selecting an item does not create double spaces.
- For prompt references, use source helpers like
buildSkillPromptReference()instead of hand-building strings inChatView. - After a successful selection, clear
composerHighlightedItemId.
Menu Behavior
ComposerCommandMenu is intentionally generic. Keep source-specific labels and descriptions in item builders unless the menu itself needs a reusable rendering capability.
When changing keyboard behavior, inspect:
composerMenuItemsRefactiveComposerMenuItemRefnudgeComposerMenuHighlightonComposerCommandKey
Cover ArrowUp, ArrowDown, Enter, Tab, and Escape when behavior changes.
Inline Composer Display
ComposerPromptEditor uses Lexical custom nodes for inline tokens.
For @... references:
- parsing starts in
composer-editor-mentions.ts - node rendering is in
ComposerPromptEditor.tsx - shared chip classes are in
composerInlineChip.ts
Do not implement a second inline-token parser in the editor component. Update composer-editor-mentions.ts or shared reference helpers.
Validation
At minimum:
bun fmt
bun lint
bun typecheck
For trigger/replacement logic, add or update focused tests:
cd apps/web
bun run test src/composer-logic.test.ts
For menu item mapping:
cd apps/web
bun run test src/components/chat/composerSuggestionItems.test.ts
For full browser interaction, prefer existing browser tests in ChatView.browser.tsx when the change affects real clicking, typing, or sending.
Never run bun test; use bun run test.
Footguns
- Do not put trigger parsing in
ChatView. - Do not map source entries to menu items inline in
ChatViewwhen a builder helper can own it. - Do not mutate prompt text without checking the latest editor snapshot.
- Do not forget collapsed-vs-expanded cursor conversion around inline tokens.
- Do not break
//versus/distinction;//planis a skill query, not/plan. - Do not change selected skill/file prompt text without checking sent-message copy behavior.
- Do not create source-specific rendering branches in
ComposerCommandMenuunless the item union needs a new reusable type. - Do not bypass
bun fmt,bun lint, andbun typecheck.