Repository navigation
Closed
Description
Add the core message box: a controlled textarea with highlighted @mention and /command tokens, keyboard-driven suggestions, and a submit button that turns into Stop while the agent replies. The toolbar comes next (#103).
Part of #94.
Why
The message box is where people talk to agents. It has to keep native editing, undo and IME behaviour while still highlighting tokens, and it must never hold the draft itself: the text belongs to the host.
What
src/ui/prompt-input.tsx:PromptInput(value,onValueChange,onSubmit),PromptInputTextarea,PromptInputSuggestions,PromptInputSuggestion,PromptInputSubmit(status,onStop).src/lib/prompt-tokens.ts: find the@or/token at the caret, and split text into highlighted segments.src/hooks/use-prompt-input.ts: active token, suggestion index, key handling.stories/chat/prompt-input.stories.tsx: plain, suggestions open, replying.e2e/fixtures.tsx: aprompt-inputscenario that records submits, withe2e/prompt-input.spec.ts.- Unit tests beside the lib module and the hook; exports in
src/index.ts.
Technique
- Highlighting: a native
<textarea>with transparent text over anaria-hiddenmirror<div>that renders the same text with tokens highlighted. The mirror copies the textarea's font, padding, wrapping and scroll position. Nocontenteditable. - Sizing:
field-sizing: contentwhereCSS.supports("field-sizing", "content"); elsewhere a measured fallback that sets the height fromscrollHeightup to the max. The fallback is a distinct, separately tested piece.
Requirements
- R29: fully controlled; every feature is opt-in by including its part.
- R30: overlay mirror with scroll kept in sync;
field-sizingwith a measured fallback; never submits during IME composition. - R31: suggestions driven from the keyboard through
usePromptInput; Send turns into Stop while busy. - R5–R12: the shared component rules.
Constraints
- No hidden state: the text belongs to the host.
- The old
ChatComposerandChatInputstay until Remove the old chat components #110 deletes them. - The shared rules in Replace the chat components with a stateless Conversation family #94 apply: no new dependency or peer, no optional-peer import, token-only styling, no change to existing modules, additions only to
src/index.tsande2e/fixtures.tsx.
Done when
- Unit tests cover:
- Tokens: the caret inside
@adfinds the mention; an email address is not a mention;/counts only at the start of a line. - Keys: ArrowDown/ArrowUp wrap, Enter picks, Escape closes, Enter with no list submits, Shift+Enter inserts a newline.
- Tokens: the caret inside
- Browser spec covers:
- The mirror's highlighted token sits under the typed token after typing and after scrolling a long draft.
- Enter during IME composition does not submit.
- Send becomes Stop while
statusis streaming and callsonStop. - With
field-sizingforced off, the textarea grows to its max and then scrolls.
- No serious or critical axe violation in the new stories, in light or dark.
bun run check,bun run build,bun run test:e2eandbun run dep-guardpass.
Metadata
Metadata
Assignees
Labels
No labels
Activity