Repository navigation
fix(website): edit a picked file mention as one atomic unit (#14675) - #17353
chenmingwei23 wants to merge 2 commits into
Conversation
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Check by hand in the real composer: after Backspace removes a mention, the caret should sit where the mention began. Undo (Ctrl+Z) should also restore it. The screenshots are headless harness captures. They show the before and after text states, not the real composer. [UX-REVIEWED] 56528d7 Description read[DESCRIPTION-READ] 0d22094e36d37834cf54d229e9d1cfb1d03ae2a3dc76f9d8eeaf09be546014e9 That sha256 names everything this verdict read: the PR description, plus the 7 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 56528d7 Description read[DESCRIPTION-READ] cbb4c2facfb3056389dd853829ced92d567fef68d7fbd972781b0836fd011138 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
What this change shipsInventory (7 items) — 5 justifiedIntent: stop a hand-edit of a picked
[FIRST-PRINCIPLES-REVIEWED] 56528d7 Description read[DESCRIPTION-READ] 3d7dbf0673e724ee9f9eb43892c3ab2b5aa44ce38daf0de8896e93b7a2702cde That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- website/src/components/chat-input/keyboard.ts:164 -- First mention deletion after an identical-draft slot switch cannot be undone (origin: validation) Adjudication (Opus 5.5) — is blocking on each finding proportionate?No findings were open for adjudication. I flagged the one fenced finding, F1. A flag doesn't stop it blocking: it still needs an F1 (fenced): the defect is real, but the harm is closer to LOW than to "data loss".
🏷️ Fenced finding(s) machine-flagged as likely edge caseThe security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override recorded by a repository writer, who must independently verify a rationale before recording it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop. (This lane's comment deliberately carries no override command.)
|
b25bb5a to
392264f
Compare
392264f to
56528d7
Compare
…ev#14675) What broke: after kirodotdev#6511, hand-editing a picked `@src/main.ts` mention broke the chip/text pair. One Backspace at the end turned it into `@src/main.t`; the reconciliation unstaged the chip (the spelling no longer matched a recorded alias), but the half-written reference was left in the composer and sent as plain prose naming a file with no attachment. What changed: a picked file mention is now ONE atomic unit on a hand edit. A Backspace or Delete on or adjacent to a recorded `@mention` removes the whole mention and its chip together, so a half-edited form can never exist. This mirrors the collapsed-paste token, which already deletes as a unit (chat-input/paste.ts handleTokenKey). - fileTokens.ts: new pure `mentionSpanAt(text, at, forward, aliases, winShaped)` returns the span of the mention on/adjacent to the caret. It is the ONE grammar shared by the keystroke, the reconciliation staleness check and the remove-chip strip (fork First Principles review: no second span definition). Occurrences are found through the shared `mentionTokenRegex`, not a raw `indexOf` scan, so a recorded `@a.ts` is never matched inside a longer hand-typed word `@a.tsx` (fork GPT/Opus review: a substring scan would carve it out and strand an `x`). A leading opening wrapper joins the span only when its matching closer follows the mention, so a lone `(` before an unwrapped mention stays and no unbalanced `)` ships (fork GPT/Opus review). - composerFileMentions.ts: `handleMentionKey` (pure, returns `{ value, caret } | null`) calls the shared `mentionSpanAt`. - keyboard.ts / props.ts / ChatInput.tsx / ChatPage.tsx: wire `onMentionKey` into useComposerKeyDown, after the paste-token atom and skipped while the IME is composing. The edit is applied through the composer's own onChange and the caret lands where the mention began. Scoped to recorded aliases and the default textarea composer: a typed or draft-restored `@rel` with no bookkeeping, and a folder token, fall through to the native per-character edit. Tested: 8 cases in ChatPage.dirStaging.test.tsx (Backspace at end/inside, Delete at start, wrapped file:line, sibling untouched, native fall-through, the `@a.tsx` boundary case, and the unbalanced-paren case) and 8 unit cases on the pure `mentionSpanAt` in fileTokens.test.ts. Full suites green: dirStaging (74), fileTokens (106), ChatInput (176), ChatInput.paste (30). tsc and `eslint src` clean. Screenshot evidence (before: half-reference left; after: whole mention removed) committed under temp-screenshots/ and produced by scripts/capture-mention-atomic- delete.mjs over the SHIPPED pure function; the before arm is asserted to reproduce the bug. Fixes kirodotdev#14675
56528d7 to
c1e6cd7
Compare
…eardown flake in test_dashboard_server_coverage, not in this frontend-only diff)
Problem / Motivation
Goal: Editing a picked file mention no longer silently drops the file from the message.
After #6511, picking a file into the composer stages a chip and inserts
@src/main.tsinto the text. Hand-editing the mention broke the pair: one Backspace at the end turned it into@src/main.t, the chip silently unstaged (the spelling no longer matched a recorded alias), but the half-written reference was left in the composer and sent as plain prose — the agent received a message naming a file with no attachment.Why it matters
The chip vanishing is easy to miss while typing, so the user sends a message that points the agent at a file it never received. It happens on every hand-edit of a mention, so it is frequent, silent, and lasting friction.
Not a goal
<textarea>composer (the surface the bug reproduces on and the one the#6511tests exercise); the Lexical editor already handles tokens as editor nodes on a separate path.What changed (motivation → approach → change)
@src/main.tin the text while the chip unstaged.mentionSpanAt(text, at, forward, aliases, winShaped)infileTokens.tsreturns the span of the mention on/adjacent to the caret, andhandleMentionKey(wired intouseComposerKeyDownafter the paste-token atom, IME-safe) removes the whole span through the composer's ownonChange; the existing reconciliation then unstages the chip. The span is found through the sharedmentionTokenRegexandmentionBoundaryFor— the same grammar the chip ✕ (removeFileChip) and the reconciliation already use — chosen over a second hand-rolled definition (First Principles review) so the three can never disagree. A recorded@a.tsis therefore never matched inside a longer hand-typed word@a.tsx, and a leading(is consumed only when its matching)follows the mention (GPT/Opus review).Backwards compatibility
Compatible: adds a keystroke handler on recorded picked-file mentions in the default composer; a mention with no recorded alias, a folder token, and every other key fall through to the native edit exactly as before. Removes nothing: no record, validator, key, or public function is narrowed or deleted —
mentionSpanAtis a new export, andonMentionKeyis a new optional prop.Tests
fileTokens.test.ts— 8 unit cases on the purementionSpanAt: Backspace-at-end, Delete-at-start, caret-inside, the@a.tsxboundary rejection, the:linesuffix, the wrapper-pairing (both(@a.ts:42)consumed and(@a.ts + y)'s(kept), null when no mention is at the caret, and longer-sibling preference.ChatPage.dirStaging.test.tsx— 8 component cases through the real composer stack: Backspace at end / inside, Delete at start, wrapped(@a.ts:42), a staged sibling left untouched, native fall-through when no mention is at the caret, the@a.tsxboundary case, and the unbalanced-paren case.tscandeslint srcclean.Manual verification
Captured headlessly via
website/scripts/capture-mention-atomic-delete.mjs, which drives the shipped purementionSpanAtin Chromium and asserts the before arm reproduces the bug and the after arm fixes it. See Screenshots.Screenshots / video
Before — one Backspace leaves a
@src/main.thalf-reference while the chip unstages (the bug):After (this PR) — one Backspace removes the whole
@src/main.tsand the chip together, no half-reference:Related Issues
Fixes #14675
Pattern harvest
Rule candidate: review-prompt
Pattern: an atomic-delete / token-span scan that uses a raw
indexOf/substring match instead of the module's shared boundary matcher silently claims text inside a longer word and consumes an unmatched wrapper — reuse the one boundary grammar rather than re-deriving it.Checklist
fix: ...)