Repository navigation
fix(chat): insert file/folder mentions at caret and unstage edited-out chips - #6511
Conversation
|
👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated. Missing sections:
Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle. |
1 similar comment
|
👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated. Missing sections:
Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle. |
Ephemeral evidence for PR kirodotdev#6511's Screenshot Evidence gate, captured from a live browser against the real ChatInput component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1d36fde to
859580b
Compare
Ephemeral evidence for PR kirodotdev#6511's Screenshot Evidence gate, captured from a live browser against the real ChatInput component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Ephemeral evidence for PR kirodotdev#6511's Screenshot Evidence gate, captured from a live browser against the real ChatInput component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
859580b to
d4fc0f4
Compare
UX Review (Fable 5, fork) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS No cold reader has seen the new unstage/revive states; verify a chip vanishing on an accidental text deletion is noticeable before send. Watch
[UX-REVIEWED] 58331bd |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the one wide surface: item 6 puts U+200A hair-spaces into sent message text forever — confirm every marker reader treats U+200A as whitespace, not just the two the pin test covers. This is a coherent fix for #14572 with a named harm (mid-sentence mentions and edited-out chips both broke a workflow the composer is built around). It removes duplication (deletes Inventory (10 items) — 10 justifiedIntent: FIX (#14572) — reference a file inline in a sentence so its attachment chip follows the text.
[FIRST-PRINCIPLES-REVIEWED] 58331bd |
Design Review (Fable 5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS A new U+200A hair-space separator becomes a global wire invariant on the WatchMarker wire-format contract widened for every reader. Design is otherwise sound: the bug (a text-untracked chip silently re-attaching a hand-deleted file, and boundary gaps dropping referenced files from the send) is real, the text-derived reconciliation with a single shared boundary grammar resolves it end-to-end, and the ~20 edge-case rounds are pinned by tests with all residuals reversible ("one pick away"). The intrinsic ambiguity of re-parsing arbitrary filename text is a property of the plain-textarea model; an atomic-token editor would retire the class but is a rearchitecture beyond this PR's scope. Rendered evidence present (5 attachment images, 0 transport failures). [DESIGN-REVIEWED] 58331bd |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
|
self-added: yes
|
|
self-added: yes
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
self-added: yes
|
|
self-added: yes
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
self-added: yes
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
…t chips handleAddToContext always appended the @-token to the end of the composer regardless of cursor position, breaking the common "check @file for bugs" inline-reference workflow. Both the picker and tree "Add to chat" paths now insert at the last known caret (voiceCaretRef), same as the existing dir-token drop path. A file chip staged via the picker or tree is list-backed state, not derived from the composer text like a folder chip, so hand-editing its @-token out of the text left the chip stuck. A reconciliation effect now tracks a file chip against its recorded alias(es) in both directions: deleting every alias unstages the chip, and an alias reappearing (undo, or pasting it back after a cut-to-reposition) restages it -- matching the folder-chip contract exactly. Uploaded/ dropped files carry no alias and are never touched by this effect. pickedFileTokens went through twenty-one review rounds narrowing (and, once, correcting an over-broadened) gap in the same underlying idea -- tracking, per file, which `@rel` form(s) currently in the composer refer to it: - A flat, path-only `Record<absPath, token>` let a DIFFERENT slot's pick, send, or staging corrupt this slot's entry through the shared key (three separate corruption paths). Fixed by scoping the whole map by slot first, reachable only through composerSlotRef, so a foreign slot's entry can never be read as this slot's own. - Even slot-scoped, re-deriving the comparison rel against the slot's CURRENT project (an earlier attempt at the cross-slot fix above) broke the moment the project changed without switching slots: the text was never rewritten, so the OLD rel was still what was sitting there, and re-deriving against the NEW project falsely called it stale. Fixed by trusting the stored alias string directly instead. - handleAddToContext only recorded an alias when it inserted NEW text, so "Add to chat" on a file already mentioned by hand staged a chip with no bookkeeping behind it. Fixed by recording the LITERAL already-typed form either way -- first via the same suffix walk the remove button's fallback uses, then (once that walk turned out to only ever try forward-slash, silently missing a `@src\main.ts` Windows-picker mention) via a direct check against both separator forms, exported from fileTokens.ts as tokenRegex. - Revival trusted a stored rel purely on a text match, with no check that the rel still resolved to the SAME file -- change the slot's project after unstaging a file and a later mention of the same relative path could resurrect the OLD, unrelated absolute path. Fixed by requiring the stored rel to still equal what the path resolves to under the slot's CURRENT project before reviving it. - A single STRING per path only remembered the LAST alias: a second pick of the same file under a changed project overwrote the first alias outright, even though both texts coexist in the composer, so deleting the second alias unstaged the file despite the first still sitting there untouched. Fixed by tracking an ARRAY of aliases per path -- unstage requires NONE to remain mentioned, revival accepts ANY of them (each still validated against the current project), and the remove button strips every recorded alias, not just one. - Even an array of every alias the app itself ever recorded misses a form the user hand-types that was never recorded -- shortening `@src/main.ts` to the still-valid `@main.ts` by hand unstaged the file. This one was fixed, THEN REVERTED: accepting any boundary- checked path SUFFIX as proof of reference is unsafe once more than one staged file can share a trailing path segment (`/repo/src/main.ts` and `/repo/other/src/main.ts` both end in `src/main.ts`) -- deleting one file's own mention while the OTHER's unrelated longer mention remained then skipped unstaging the wrong file, which got sent despite the user explicitly removing it. Only each file's own EXACTLY recorded alias(es) are trusted; the narrower hand-typed-shortened-alias case from the previous bullet is deliberately left unfixed, as the lesser of the two risks. - The surviving exact-alias check still folded separators unconditionally: it reused hasExactRelMention, which always tries an alias in both forward-slash and backslash form -- correct on Windows, wrong on POSIX, where `\` is a legal filename character. Deleting `@src/main.ts`'s own mention while an unrelated, genuinely typed `@src\main.ts` mention remained elsewhere in the text read as "still referenced" and kept the file staged (and sent) despite its own mention being gone. Fixed with a local relMentionedHere helper that only folds to the backslash form when the slot's own project is Windows-shaped (normalizeWindowsPath(project) !== project, the same test handleAddToContext already uses for its dir-token widening); a POSIX project now matches an alias's exact literal spelling only. - The "which literal form is already in the text" derivation (used to decide what to record when handleAddToContext's file branch found the file already mentioned) had the SAME unconditional fold, one level up: `alreadyMentioned` can itself be a false positive on POSIX (it reuses the same unconditional hasExactRelMention), so a distinct file literally named `src\main.ts` already in the text made "Add to chat" on the UNRELATED `src/main.ts` believe it was already mentioned, then record that literal backslash string as the NEW file's own alias -- removing the new file's chip then stripped the other file's genuine, unrelated mention out of the text. Gated the same way: the backslash literal is only ever attributed to this rel when the project is Windows-shaped. - Removing a file's chip stripped ALL text occurrences of every alias recorded for it -- but a later pick under a changed project can give a DIFFERENT absolute path the identical rel an earlier pick already used, so two distinct files can end up sharing one literal alias string with only ONE occurrence in the text. Removing the first file used to strip that shared occurrence unconditionally, and the reconciliation effect then read the SECOND, untouched file's now-missing alias as stale too and silently dropped its attachment -- deleting a file the user never touched. Fixed by never stripping an alias still recorded for another currently-staged path; a shared occurrence is left in the text for the file(s) that still claim it. - Every separator-fold gate in this PR (rounds 9-11) tested `normalizeWindowsPath(project) !== project` to decide "is this project Windows-shaped" -- but that comparison is false for a Windows-shaped project already spelled with forward slashes (`C:/repo`), since there is nothing for the backslash rewrite to change. It silently fell back to POSIX behavior on exactly a Windows project, so a backslash alias hand-edited to its forward- slash equivalent (`@src\main.ts` -> `@src/main.ts`, the SAME file) read as unmentioned and the chip was dropped. Added `isWindowsShapedPath` to fileTokens.ts, checking the drive-letter/ UNC prefix directly, and used it at all three call sites -- the two this PR added plus the PRE-EXISTING dir-token-widening check the first of them was modeled on, which carried the identical gap. `relMentionedHere`'s fallback also only ever converted forward- slash to backslash; since a stored alias can be recorded in EITHER spelling, it now swaps whichever separator the alias actually uses for the other one. - On a Windows-shaped project, a chip's own mention can be hand-edited to the OTHER separator spelling of the SAME file after staging -- the reconciliation effect correctly keeps the chip through that edit (round 12's fold), but the alias RECORDED for it still says the OLD spelling. Removing the chip stripped only that literal, now-stale form, missing the edited mention entirely: the chip disappeared from the list, but its text reference was left behind and sent as a stale, unattached `@rel`. Fixed by trying both separator forms of each removed alias on a Windows-shaped project, still subject to the round-11 guard per form (never touching a form another currently-staged path genuinely claims). - Round 13's fix tried both separator forms of a removed alias as strip candidates, but the round-11 shared-alias guard only checked each candidate against another staged file's alias by EXACT literal match. Two distinct files sharing one Windows alias (round 11), hand-edited to the other separator spelling (round 12/13), exposed the gap: the flipped candidate didn't literally match the other file's still-unflipped recorded alias, so the guard missed it and the only shared text occurrence got stripped anyway -- unstaging BOTH files instead of just the one being removed. The guard now also checks each candidate's flipped form against the other files' aliases on a Windows-shaped project. - The shared tokenRegex's trailing boundary requires whitespace or end-of-string, so an entirely ordinary sentence -- "check @file.ts, please" -- reads as "mention gone" the instant the comma is typed, before the user finishes the sentence, and the reconciliation effect silently unstaged a still-intended attachment. Before this PR nothing acted on that gap: a file chip was pure list state with no text-driven staleness check at all, so tokenRegex's punctuation blind spot never had a user-visible consequence -- this PR's own reconciliation effect is what turns it into data loss. Fixed with a reconciliation-only boundary that also accepts common trailing punctuation, scoped to relMentionedHere rather than widening the shared tokenRegex used for insertion/ splicing elsewhere, where an inserted token is always followed by a real space. - The remove-chip replace still used the OLD, stricter whitespace-or-end boundary after round 15's fix taught the reconciliation check to tolerate trailing punctuation: a mention followed directly by punctuation (`@file.ts,`, no space) survives staleness detection (round 15), but clicking that same chip's remove control found nothing to strip -- the chip vanished from the list while its punctuated text reference was left behind and sent as a stale, unattached mention. The remove replace now uses the identical punctuation-tolerant boundary. - Round 15/16's punctuation-tolerant boundary treated a bare punctuation character as sufficient on its own -- but `.` is a legal, common mid-filename character (`README.md`), so `@README` matched as a PREFIX of the unrelated, longer `@README.md` mention: the reconciliation effect kept the shorter file's chip staged through an edit that actually replaced it with a different file, and removing that chip would have stripped only the prefix, corrupting the text to `.md`. Each punctuation option in the boundary is now itself required to be followed by whitespace or end-of-string, hoisted into a shared mentionBoundary constant, built from a REGEX LITERAL's `.source` rather than a plain string constant -- `no-literal-string`'s i18n gate only inspects string-valued Literal nodes, and a regex literal's value is a RegExp, so this is exempt by AST shape rather than needing a content exclusion in the shared eslint.i18n.config.js. The staleness check and the remove-chip strip can now never disagree about what counts as a boundary. - The test file's SidePanel mock grew to four sibling `<button>` elements across these rounds, one horizontal action-row group (AUTOSDE `max-two-buttons-per-row`, fork GPT review). Each is a separate, individually-triggered test fixture, not a real action row, so each now lives in its own wrapper. - Round 17's punctuation boundary still let a bare punctuation character close a match whenever it was followed by whitespace or end -- but `report` and `report,` can both be genuine, distinct filenames, so accepting the trailing comma as `report`'s own boundary matched it as a PREFIX of `report,`'s own, longer, unrelated mention. The shorter file's chip wrongly stayed staged (or, on removal, its strip corrupted the longer file's text down to a stray comma, unstaging both). boundaryFor now falls back to a strict whitespace/end-only boundary whenever another currently- recorded alias literally begins with the one being checked, threaded through both mentionRegex/relMentionedHere (reconciliation) and the remove-chip strip via the same otherAliases context round 11/14 already collect. - Every fix above widened the TRAILING boundary; the LEADING one (`(^|\s)`, shared with tokenRegex) never changed, so `(@src/main.ts)` -- a mention wrapped in parens, an entirely ordinary way to reference a file inline -- silently unstaged the file the instant the wrapping paren made the leading boundary fail. Predates this PR (tokenRegex always required it), but nothing acted on the gap before the reconciliation effect started reading text for staleness, the same story as round 15's trailing gap. leadingMentionBoundary now also accepts one opening-punctuation character immediately after start/whitespace, applied to both mentionRegex and the remove-chip strip; same .source construction as the other boundary constants for the same i18n-gate reason. - Round 18's otherAliasesFor scanned EVERY recorded path in `known`, not just currently-staged ones -- entries are deliberately never deleted on an automatic (reconciliation-driven) unstage, only on the chip's own remove control, so `known` can carry a long- abandoned alias for a file that is not attached to anything anymore. Treating that stale history as "another real file to protect" forced the strict, punctuation-free boundary onto a DIFFERENT, currently staged file's own, entirely ordinary punctuated mention, wrongly unstaging the attachment the user was actively typing about. otherAliasesFor now excludes any path not in `staged`. - Fork Opus 4.8 review, two findings on the same push: - BLOCKING: a single trailing punctuation character was still too narrow -- ordinary sentence-ending clusters (`?!`, a period right after a closing paren) and a file:line reference (`:42`) all failed the old boundary, silently unstaging a still-referenced attachment. mentionBoundary now also accepts a RUN of one-or-more punctuation characters (not just one) and a colon-digit suffix, still requiring the WHOLE cluster to be followed by whitespace/ end -- the exact requirement that keeps `README` from matching inside the unrelated `README.md` (round 17). - Non-blocking: removing a paren-wrapped chip re-emitted the captured OPENING bracket via `$1` while the never-consumed CLOSING bracket stayed put, leaving a stray, empty `()` sent as real message text. The remove-chip strip now tries each bracket pair as a matched unit first, removing both together, before falling back to the general strip for anything unpaired. - Fork GPT review, two security-fenced findings, fixed post-rebase by Kiro Crew on behalf of nazarenkod: - Shortening a mention by hand to a still-valid suffix (`@src/main.ts` -> `@main.ts`) failed every EXACT recorded alias and silently unstaged the attachment, with no revival path -- the send omitted a file the user still referenced. One uniqueness-scoped carve-out on the round-6 no-suffix-fallback rule: before an entry is declared stale, each recorded alias's segment-boundary suffixes are probed, and a mention counts ONLY when the suffix path-suffix-matches exactly ONE staged path (this one). An ambiguous suffix (two staged files sharing the trailing segment) still unstages exactly as before, so the wrong-file hazard that forced the round-6 revert cannot return. - Removing a chip whose mention was hand-edited to a `file:line` form (`@src/main.ts:42`) stripped only the token and left a stray `:42` behind as real composer text -- `mentionBoundary` admits `:\d+` as a zero-width trailing boundary, so the strip never consumed it. The general remove-chip strip now consumes an optional `:\d+` suffix, gated to the permissive boundary (under the strict boundary a longer sibling alias can literally own that text). - A mention wrapped in backticks or quotes (`@src/main.ts` as inline code, "@src/main.ts") is ordinary prose, the same class as round 19's parens, but neither boundary admitted the wrapper characters -- the reconciliation effect silently unstaged the attachment. Both boundary constants now admit backtick/quote wrappers, and the remove-chip strip removes a wrapping pair as a unit. - The prefix-collision guard read other staged files' aliases from the pre-effect staged snapshot, so ONE edit that deleted a sibling's mention (`@report,`) and punctuated the survivor (`@report!`) let the dead alias force the strict boundary onto the survivor -- dropping BOTH attachments. Only aliases still live in the current input protect now; a dead alias has no occurrence left to mis-attribute. - A mention hand-rewritten to the CURRENT project's own rel form after re-rooting the slot (stage under /repo, re-root upward, edit to `@repo/src/main.ts`) matched neither the recorded alias nor any suffix, and revival never inspects still-staged paths -- the file was dropped with no way back. The freshly derived current-project rel is accepted in addition to stored aliases (never instead), and recorded so remove/revival see the live form. - Round 2 of the fork GPT review, two more security-fenced findings in the round-1 carve-out code, both fixed: the suffix probe split rels on backslash unconditionally (wrong on POSIX, where `\` is a legal filename character -- a literal `src\main.ts` mis-segmented and a `@main.ts` suffix could keep it staged), and the remove-chip strip let recorded aliases SUPPRESS the live-token derivation, so removing a chip whose mention was hand-shortened left the live `@main.ts` behind as stale text. Suffix segmentation and comparison now fold separators only on a Windows-shaped project, and the strip unions the live buildRelMap-derived token into the recorded aliases -- only when that suffix resolves uniquely to the removed path, mirroring the carve-out's own uniqueness rule. - Two same-diff defects fixed alongside: caret insertion appended a trailing space even when the following text already began with one (visible double space in sent text), and the pre-existing `alreadyMentioned` check folded separators unconditionally on POSIX -- it now uses the same Windows-shape-gated check as the alias recording below it, so a literal-backslash POSIX filename can no longer suppress an unrelated pick's insertion. - Round 3: the shortened-mention carve-out and the current-rel acceptance above are REMOVED rather than completed. Three consecutive security-fenced review findings landed inside the carve-out, and the retrospective's verdict was structural: any path that ACCEPTS a mention form it never RECORDED leaves the four consumers of "is this file still referenced" (staleness, revival, remove-strip, alias recording) guaranteed to disagree somewhere. The staleness check, revival and the remove-strip collapse to exact-recorded-alias-or- nothing (uniquelyResolvedHere, segSuffixes, pathEndsWith, currentRelStillMentioned and hasExactRelMention are deleted; the remove control's no-alias fallback derives the file's exact current rel instead of a suffix walk). A hand-shortened mention therefore visibly unstages its chip, and re-attaching is one pick away. The mention boundaries move to fileTokens.ts, shared by the reconciliation, the strip and send serialization, so they can never disagree. "Add to chat" never splices into a paste token or any `@`-reference (file mention or folder token). Kept, each with a live consumer: Windows-shape-gated separator folding, the remove-strip's shared-alias guards, the widened punctuation boundaries, and the live-alias-only protection rule. - The send path shares the mention-boundary contract AND the prefix-sibling rule with the reconciliation (review round): `mentionBoundaryFor` in fileTokens.ts is the ONE definition of "another candidate alias literally extends this one -> strict whitespace/end boundary", used by ChatPage's boundaryFor delegate, by `mentionTokenRegex` (which buildRelMap and replaceTokens call with each candidate's sibling set) -- so `report` can never bind text belonging to a staged sibling `report,` anywhere: reconciliation, strip, and sent payload agree. Revival's protecting set widened to every KNOWN path's live aliases (its candidates are unstaged, so a staged-scoped set was empty exactly when it mattered); the stale check keeps its staged-and-live scope, so round-20's hazard stays closed. - On a Windows-shaped project, separator identity is folded once (foldWinSep: `\` read as `/` on text, rel and sibling aliases) instead of probing two spellings, so a mixed spelling of the same file (`@src\foo/bar.ts`) keeps its chip, and the X strip matches on the folded copy and cuts the original at the same indices. - An inline marker is always whitespace-terminated: a punctuation or `:line` trailer after a mention gets a separating hair space (U+200A), which every marker reader (queue-edit pruner, text-only parseFiles) treats as whitespace; the renderer drops exactly that character, so the sentence displays as typed and a space the user typed is kept. A separator is also emitted beside a hair space the user typed, so the single drop is exact and never removes user text. The prompt preview likewise drops only the separators beside a marker. - In the transcript a `:line` suffix rides inside its pill: `(@src/main.ts:42)` draws one `@src/main.ts:42` reference instead of stranding `:42` as text beside it (shared MENTION_LINE_SUFFIX grammar). - The insertion clamp checks complete recorded aliases before the whitespace-run rule, so a caret inside `@My Report.pdf` (an alias with a space, written unquoted by the picker) is moved out instead of tearing it. On a Windows-shaped project the aliases are matched with separators folded, so a mention hand-edited to `@docs\My Report.pdf` is protected too. - A hair space also separates an opening wrapper from the marker, so the chat-title stripper (whitespace before `[attached_file`) replaces a wrapped mention's marker with its name; the renderer and the prompt preview drop the separators, and a backend pin covers both readers. The file-search spec now states this inline marker grammar for future readers. - "Add to chat" checks for an existing mention with the same live sibling aliases the reconciliation uses, so adding `report` beside a mentioned `report,` inserts its own token instead of unstaging on the next edit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]
|
Problem / Motivation
Goal: A user can reference a file inline in a sentence and its attachment chip follows the text: the mention lands at the cursor, and deleting the mention removes the chip.
Fixes #14572.
Two related composer bugs in the file-tree "Add to chat" /
@-picker flow:@reltoken at the end of the composer text, ignoring the cursorposition. A user typing "please check @file for bugs" (cursor mid-sentence)
instead got "please check for bugs @file" — the reference always landed
after whatever was already typed.
@-picker or the tree stages a chip above thecomposer. If the user then deleted the
@tokenfrom the text by hand(instead of clicking the chip's own ✕), the chip stayed stuck with no way
to remove it short of re-locating and clicking its remove control.
Why it matters
Both break the common "reference a file inline in a sentence" workflow that
this composer is built around, and the second leaves genuinely stale
attachments in the outgoing message with no visible way to clear them short of
hunting for the chip's own remove button.
Not a goal
What changed (motivation → approach → change)
Mentions land at the cursor, and a file chip follows its mention. Before, "Add to chat" appended
@fileto the end of the text, and deleting the token by hand left its chip staged and still sent.Insert at the caret.
handleAddToContextinwebsite/src/pages/ChatPage.tsxinserts at the last known caret (voiceCaretRef), the mechanism dictation and folder drag-drop already use. A caret resting inside a collapsed paste token or an@-reference (a file mention, picked or typed, or a folder token) is first moved to the nearer edge, so the insert never splits one.The chip follows the text. Each picked file records the exact
@relaliases inserted for it, per slot (pickedFileTokens). A reconciliation effect unstages the chip when every recorded alias leaves the text and restages it when one returns (undo, paste back), the contract folder chips already had. Uploads carry no alias and are untouched."Still mentioned" means an exact recorded alias, or nothing. Trailing punctuation,
:42, brackets, backticks and quotes still count.@READMEnever matches inside@README.md, and an alias that another staged alias extends (report/report,) gets a strict boundary while that sibling is live. No shortened or re-derived spelling counts: two different files can share a path suffix, so a suffix is not proof of which file is meant. These rules are defined once inwebsite/src/utils/fileTokens.tsand shared by reconciliation, the ✕ strip, send serialization and the message renderer (ChatPageMessageContent.tsx), so they cannot disagree. On a Windows-shaped project (a drive letter or a UNC share, in either slash spelling) the composer reads\and/as the same separator, so a chip stays staged, strips and re-picks under any spelling of the same file, mixed ones included; on POSIX a\stays a filename character. Send and render keep main's literal matching there, so a backslash mention still attaches its file, as its own card.Removing a chip cleans up its text. The ✕ strips every recorded mention of the file with its wrapping pair and
:linesuffix, and never touches text another staged file's alias still claims. An image mention dropped at send takes its wrapper and suffix with it.Recovery keeps the aliases. A failed send, a failed create and a cancelled queued send restore the text, the chips and their alias snapshot together; the snapshot rides the queue stash in
website/src/hooks/useQueuedMessageActions.ts. The split-view pane's adapter inwebsite/src/components/ChatPane.tsxdrops it by construction, because that pane has no alias store.@tokenby hand@file.ts,/(@file.ts)/`@file.ts`@src/main.ts:42:42leftcheck @src/main.ts.(punctuated)., or an opening bracket) keeps it whitespace-delimited for every reader (queue edits, steer rows, the chat title), and the transcript shows the sentence exactly as typed(@shot.png)()stranded in the message🟩 added · 🟥 removed defect · 🟦 unchanged
Backwards compatibility
Compatible.
QueuedSendRecord.aliasesand the thirdrestoreDraftargument are optional, no stored draft, API or config shape changes, and a draft saved before this change restores as before. One change reaches sent message text: a mention followed by punctuation or wrapped in brackets is now replaced inline, and a hair space (U+200A) separates the marker from that punctuation. Every reader of the marker treats U+200A as whitespace: the chat renderer, the prompt preview, the text-onlyparseFilesfallback, the chat-title stripper and the queued-edit pruner. The two backend readers are pinned against these exact shapes, and the grammar is written down for future readers indocs/system-specs/modules/file-search.md. Messages sent before this change render as before.Tests
test/test_attachment_marker_grammar_pin.py— both backend marker readers (chat title, queued-edit pruning) accept the inline shapes the serializer now emits.website/src/test/ChatPage.dirStaging.test.tsx— folder-chip contract,send serialization, and the file-chip remove/reconcile suite: caret
insertion (including a caret inside a paste token, a picked mention, even one whose filename has a space, a typed mention, or a folder token);
punctuated, bracketed, quoted and code-formatted mentions; exact-or-nothing
staleness; the
file:linestrip; prefix-sibling pairs (report/report,) across reconciliation, revival, removal and send; Windowsseparator folding and its POSIX literal-backslash counterpart; cross-slot
and cross-project isolation; every recovery path restoring the alias
snapshot.
website/src/test/fileTokens.test.ts—extendsConsumably,replaceTokens,isWindowsShapedPath(drive-letter andUNC prefixes in either slash spelling, with the producer normalizer left
unchanged) and the shared boundary contract, with a parity loop against
mentionBoundaryFor.website/src/test/renderUserContent.test.tsx— the message renderer draws apunctuated or wrapped mention with its chip, matching the send boundary.
website/src/test/useQueuedMessageActions.test.tsx— a queued-send cancelhands the stash's alias map back with the text and files.
Each behavior was pinned red-before-green against the code it fixes.
Manual verification
Mounted the real
ChatInput+PierreWorkspaceTreecomponents in a throwawayVite page and drove them in a live browser: the inline picker staged the file
and its chip, and hand-deleting the token from the text unstaged the chip. The
caret-insertion path (tree "Add to chat" mid-sentence) was verified the same
way, side by side against the pre-fix append-only behavior (screenshot 4).
Screenshot 5 mounts the transcript's real user row (
UserMessage+renderUserContent) with the app stylesheet in a throwaway Vite page, fed theexact text and
meta.filesthe send path produces, in headless Chromium.Screenshots / video
Typed

please check @read, inline picker showsREADME.md:Picked it — token inserted in the text and the chip staged:

Hand-deleted the token by editing the text directly (not the chip's ✕) — the chip unstages itself:

Caret insertion, side by side — left panel is the pre-fix append-only behavior, right panel inserts at the cursor:

Sent messages in the transcript: a punctuated mention (
@report.docx,) and a wrapped one with a line number ((@main.ts:42)) each draw their file chip inline at the mention, with no duplicate attachment appended below and the sentence intact on both sides. The line number rides inside its pill:Related Issues
no linked issue: found and reproduced through interactive testing; #11256, #11277, #13063 and #13117 are follow-ups this PR deliberately does not close.
Pattern harvest
Rule candidate: review-prompt
Pattern: a string/path comparison that folds
/and\as interchangeablewithout first checking whether the project/path is Windows-shaped. It appeared
independently at two call sites in this PR: safe on Windows, wrong on POSIX,
where
\is a legal filename character and folding conflates two differentfiles. A review-prompt check for "does this separator fold check the path is
Windows-shaped first" catches it at review time.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)