Repository navigation
feat(native): composer context chips and terminal Add to chat - #80
Conversation
…ch, shared excerpt text, keyboard chips
|
Review findings addressed in ca721ea (rebased on
Gates: clippy ✓, |
131d733 to
ca721ea
Compare
|
Follow-up fixed in 2b60e34. Escape handling moved from the chip trigger onto the chip row (their common ancestor), so Escape closes the details from the trigger or the X. Escape from the prompt still goes through the composer's Escape action. Checked offscreen: click the chip, Tab to the X (popover open, |
Problem
The native composer had no context chips: a thread picked from the
@menu sat in the prompt as a rawt3-context://link, and there was no way to hand terminal output to the chat. The web lets you select terminal text, choose Add to chat, and get an inline chip with a details popover whose excerpt rides along as aTerminalContextRecord.Approach
Rules (
crates/core/src/composer/context.rs, tests mirror the TS):lib/terminalContext.ts(label,formatTerminalContextReference,normalizeTerminalContextText, expiry, legacy\uFFFCplaceholder migration),terminalContextRecord,normalizeTerminalContextForThreadand the same-lines dedup fromcomposerDraftStore.ts, the link edits oflib/composerContextReferences.ts(insert at the caret with the web's spacing, remove with one space),terminalSelectionLineRange, andderiveComposerSendState/snapshotComposerSend/buildExpiredTerminalContextToastCopy.buildMessageContextnow carries linked terminal records first (terminal, thread, attachments, as the web orders them). Drafts and stash entries persist linked excerpts with their text (PersistedTerminalContextDraftshape); an entry without text restores expired.Emulator::selection_rows: selection rows counted from the top of the scrollback, the screen coordinates the web'sgetSelectionPositionuses.Terminal entry points (
crates/app/src/terminal/pane.rs,drawer.rs):observeSelectionActions+showSelectionAction): after a drag selection it opens at the pointer with Add to chat / Copy; after a double or triple click it waits 500ms. Dismissed by a click outside, a key, a scroll, or blur.Terminal 1 lines 5-6), links it at the composer's caret (one undoable edit), and moves focus to the prompt. Adding the same lines of the same terminal twice is a no-op.h_flexcenters children); offscreen renders gave the pane a one-row grid without it.Chips (
crates/app/src/composer/context.rs):ContextChipShelllook: 14px, 500 weight, 14px icon in the kind's ink; label underlines on hover when the chip opens something. The prompt is a plain textarea, so each linked context shows as a chip in a row above it, in prompt order, with a 14px X (ContextChipAction) that removes the link. Deleting the link text removes the chip; undo brings both back (records are kept until send).TerminalContextInlineChippopover (384 wide, compact): terminal icon, terminal label,Lines 5–6, and the captured text in mono onmuted, scrolling at 320px. Expired: invalid ink, not clickable, the web's tooltip.UnresolvedContextChip(dashed circle, current color, the web's tooltip).Theme (
scripts/gen-theme.ts): the web solves chip inks at runtime (contextChipVariables). The generator now runs the same OKLCH lightness solve per palette (culori for parsing, the web's gamut map and contrast math), addingcontext_chip_terminal,_thread,_environmentand_invalid. All 48 values (4 tokens × 12 palettes) matchcontextChipVariablesrun in vitest exactly.Ledger
CO-CONTEXT:
todo→partial, Nativecrates/core/src/composer/context.rs, crates/app/src/composer/context.rs, crates/app/src/terminal/pane.rs, Issue #77. Web source now also listscontextChipParts.tsx,composerContextPresentation.tsx,chat/TerminalContextInlineChip.tsx,lib/terminalContext.ts,lib/contextChipAccents.ts.Gaps:
composerContextClipboard).Evidence
Offscreen renders (snapshot renderer with #72's gestures) against the smoke server, thread "Native client showcase", and one real window by PID:
/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/before-context-menu-dark.png//private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-context-menu-dark.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-selection-menu-dark.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/before-composer-dark.png//private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-chips-dark.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-chip-dark.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-popover-dark.png//private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-popover-light.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots77/after-real-window.pngThe test terminal was closed afterwards (
terminal_probe --close, new flag).Wire (
composer_probe --send --provider devReplay;--sendnow links a terminal excerpt and stops and archives its thread):The excerpt's text went in as
\r\n$ cargo test -p t3-core\r\ntest result: ok\nand was normalized.Tests:
crates/core/src/composer/context/tests.rs(13, including the web's legacy-id and placeholder cases), plus cases added to the draft round-trip (excerpts persist with text; a textless entry restores expired; placeholder migration),message_context(terminal records lead, unlinked ones stay home), andselection_and_scrollback(scrollback-relative rows).Gates:
cargo clippy --workspace --all-targets -- -D warnings✓,cargo test --workspace✓,node scripts/gen-theme.ts --check✓,node --test parity/sync.test.ts✓,node ../../apps/native/conformance/generate.ts --check✓. Rebased onnativeat #72.Closes #77