Skip to content

fix(chat): insert file/folder mentions at caret and unstage edited-out chips - #6511

Merged
NicholasRBowers merged 1 commit into
kirodotdev:mainfrom
nazarenkod:fix/file-chip-caret-and-orphan-cleanup
Sep 28, 2026
Merged

NicholasRBowers merged 1 commit into
kirodotdev:mainfrom
nazarenkod:fix/file-chip-caret-and-orphan-cleanup

Conversation

@nazarenkod

@nazarenkod nazarenkod commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Adding a file or folder via the tree context menu always inserted the
    @rel token at the end of the composer text, ignoring the cursor
    position. 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.
  2. A file added via the inline @-picker or the tree stages a chip above the
    composer. If the user then deleted the @token from 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

  • Keeping mention aliases across a page reload. A chip restored from the saved draft is not reconciled until the file is picked again (#11256).
  • The split-view pane's composer, which keeps its pre-PR behavior (#13117).
  • Keeping mentions intact through the prompt optimizer's rewrite (#13063).
  • Consolidating the composer's older suffix and boundary helpers beyond what this fix needs (#11277).
  • Changing how a picked mention's text edits. It stays ordinary editable text; treating it as one unit is a separate follow-up.

What changed (motivation → approach → change)

Mentions land at the cursor, and a file chip follows its mention. Before, "Add to chat" appended @file to the end of the text, and deleting the token by hand left its chip staged and still sent.

Insert at the caret. handleAddToContext in website/src/pages/ChatPage.tsx inserts 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 @rel aliases 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. @README never 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 in website/src/utils/fileTokens.ts and 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 :line suffix, 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 in website/src/components/ChatPane.tsx drops it by construction, because that pane has no alias store.

Scenario Before After
"Add to chat" with the cursor mid-sentence 🟥 mention appended at the end 🟩 mention lands at the cursor
"Add to chat" with the cursor inside a paste token, a mention or a folder token 🟥 token torn apart 🟩 insert lands at the token's edge
Delete a file's @token by hand 🟥 chip stuck, file still sent 🟩 chip unstages
Paste the token back (undo) 🟥 nothing 🟩 chip restages
@file.ts, / (@file.ts) / `@file.ts` 🟥 silently unstaged 🟩 stays staged
Remove chip of @src/main.ts:42 🟥 stray :42 left 🟩 consumed
Send check @src/main.ts. (punctuated) 🟥 duplicate standalone marker appended 🟩 mention replaced inline; a hair space between the marker and adjacent punctuation (the ., 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
Cancel a queued send, then edit the restored mention 🟥 alias bookkeeping lost — stuck chip resent 🟩 alias snapshot restored with the draft
Send an image whose mention is wrapped, (@shot.png) 🟥 () stranded in the message 🟩 wrapper and suffix dropped with it

🟩 added · 🟥 removed defect · 🟦 unchanged

Backwards compatibility

Compatible. QueuedSendRecord.aliases and the third restoreDraft argument 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-only parseFiles fallback, 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 in docs/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:line strip; prefix-sibling pairs (report /
    report,) across reconciliation, revival, removal and send; Windows
    separator 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 and
    UNC 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 a
    punctuated or wrapped mention with its chip, matching the send boundary.
  • website/src/test/useQueuedMessageActions.test.tsx — a queued-send cancel
    hands 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 + PierreWorkspaceTree components in a throwaway
Vite 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 the
exact text and meta.files the send path produces, in headless Chromium.

Screenshots / video

  1. Typed please check @read, inline picker shows README.md:
    picker open

  2. Picked it — token inserted in the text and the chip staged:
    token and chip

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

  4. Caret insertion, side by side — left panel is the pre-fix append-only behavior, right panel inserts at the cursor:
    caret insertion current vs fixed

  5. 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:

    sent messages with inline mention chips

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 interchangeable
without 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 different
files. A review-prompt check for "does this separator fold check the path is
Windows-shaped first" catches it at review time.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — N/A, composer interaction logic with no dedicated spec doc
  • No secrets, credentials, or internal references in the diff

@nazarenkod
nazarenkod requested review from a team and CrysisDeu August 28, 2026 08:28
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Aug 28, 2026
@dwu96

dwu96 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

👋 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:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

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
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 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:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

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.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Aug 28, 2026
nazarenkod added a commit to nazarenkod/KiroCrew that referenced this pull request Aug 28, 2026
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>
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Aug 28, 2026
@nazarenkod
nazarenkod force-pushed the fix/file-chip-caret-and-orphan-cleanup branch from 1d36fde to 859580b Compare August 29, 2026 07:03
nazarenkod added a commit to nazarenkod/KiroCrew that referenced this pull request Aug 29, 2026
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>
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 29, 2026
nazarenkod added a commit to nazarenkod/KiroCrew that referenced this pull request Aug 29, 2026
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>
@nazarenkod
nazarenkod force-pushed the fix/file-chip-caret-and-orphan-cleanup branch from 859580b to d4fc0f4 Compare August 29, 2026 12:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Aug 29, 2026
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — 🟡 CONCERNS

UX-level review of 58331bd8b79e75676a5a25a845d73cd0a7b0f490 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • Attachment silently dropped outside the edit locus: reconciliation unstages the chip the moment every recorded alias leaves the text (attachment-02 → attachment-03), but the chip sits above the composer while the user's eyes are on the text — an over-eager selection-delete drops the file with no signal at the point of action, and the message sends without it. Low frequency × task-level impact × recoverable (undo revives the chip), so CONCERNS not BLOCK; smallest fix is a brief exit fade or one-shot highlight on the chip row so the removal registers peripherally.

[UX-REVIEWED] 58331bd

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 58331bd8b79e75676a5a25a845d73cd0a7b0f490 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 tokenRegex/hasExactRelMention for one shared boundary grammar) rather than adding a second spelling; every new export in fileTokens.ts has real consumers in ChatPage.tsx and ChatPageMessageContent.tsx; the owning spec (file-search.md) is updated in the same commit. No default of a first-class loop/monitor/agent/skill/command changes, so lens 9 does not fire. The removed hasExactRelMention pin ("deliberately NOT a suffix walk") is preserved, not reversed. The send-path, renderer and wire-format work is derived: caret-insertion newly makes punctuation-adjacent mentions reachable, and the old whitespace-only matcher mishandled them — fixing that is fixing a defect this PR's own change exposes, in scope.

Inventory (10 items) — 10 justified

Intent: FIX (#14572) — reference a file inline in a sentence so its attachment chip follows the text.

  1. Tree/picker mentions insert at the caret instead of always appending — justified
  2. Deleting a mention's text unstages its chip; re-adding restages it — justified
  3. pickedFileTokens becomes slot-scoped with a per-path alias array — justified
  4. Boundary grammar consolidated into shared fileTokens.ts helpers; tokenRegex/hasExactRelMention removed — justified
  5. Punctuated / wrapped / :line mentions stay staged and strip/serialize as a unit — justified
  6. Sent message text gains inline [attached_file N] markers with U+200A separators — justified
  7. Renderer draws punctuated/wrapped/:line mentions as pills; longest-first split — justified
  8. Recovery paths (queued cancel, failed send, failed create) restore the alias snapshot — justified
  9. Windows separator folding (isWindowsShapedPath/foldWinSep) for mention matching — justified
  10. findUnreferencedAttachments uses one rel map so a prefix-sibling can't hide a card — justified

[FIRST-PRINCIPLES-REVIEWED] 58331bd

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of 58331bd8b79e75676a5a25a845d73cd0a7b0f490 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

A new U+200A hair-space separator becomes a global wire invariant on the [attached_file N] <path> marker format, crossing into the Python backend, where any unenumerated reader that splits on ASCII space fails silently.

Watch

Marker wire-format contract widened for every reader.
replaceTokens now inserts MARKER_TRAILER_SEP (U+200A) between a marker's path and an accepted punctuation/:line trailer, and between an opening wrapper and the marker — grounded in fileTokens.ts (export const MARKER_TRAILER_SEP) and the doc's "Every marker reader must treat U+200A as whitespace." A necessary consequence of widening the mention boundary (the send path had to match what reconciliation retains), but it makes "treat U+200A as whitespace" a standing invariant spanning the frontend↔backend seam. A consumer that stops the path at ASCII 0x20 rather than \s/isspace() reads /repo/a.txt\u200a — resolving a nonexistent file, or the queue-edit pruner keeping an attachment an edit deleted. The seam table and test_attachment_marker_grammar_pin.py cover the known readers; the risk is an unlisted one.
Clears when: a human confirms the marker-reader enumeration (seam table + grammar pin) is exhaustive across frontend, backend, and any agent/host-side parser of [attached_file N] <path>, or the pin is extended to whichever reader is not yet covered.

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

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 58331bd8b79e75676a5a25a845d73cd0a7b0f490 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 58331bd

@NicholasRBowers

NicholasRBowers commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

self-added: yes
mechanism: a mention ends only at whitespace or end, after a closing or terminal punctuation run, or at a :line suffix; any other glued continuation names a different file
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Opening punctuation silently unstages referenced files span=608fc6d3a0fd

not a defect: this is the boundary contract working as designed, and the suggested change would reintroduce a defect this lane already had removed. mentionBoundary (website/src/utils/fileTokens.ts:506) ends a mention only at whitespace or end, after a closing or terminal punctuation run, or at a :line suffix. Opening brackets are accepted on the LEADING side (leadingMentionBoundary, :529), which is where ordinary prose puts them. Any other glued continuation names a different token, by the rule this lane forced to keep @README out of @README.md, pinned at ChatPage.dirStaging.test.tsx:983. a.txt(details) and report(1).pdf are both legal filenames.
The suggested fix leaves its own example unchanged. With ([{ added to the punctuation class, @a.txt(details) still fails, because the run is followed by d, not whitespace. Any change that does match @a.txt(details) has to accept an opener before a non-space. That makes @report bind inside the legal @report(1).pdf: the wrong chip stays staged for a file the text no longer names, and removing it strips the text to (1).pdf. That is the corruption the pinned test exists for.
Reaching this state takes a deliberate edit at the mention's end. Both insertion paths leave a trailing space after the mention and park the caret after it ("Add to chat" in ChatPage.tsx and the @-picker in ChatInput.tsx). When the edit happens, the chip visibly leaves the row above the composer at that keystroke, nothing is deleted, and a space or a re-pick restages the file through the reconciliation's revival.
This PR's contract is exact-alias-or-nothing; main never unstages, so no parity claim is made. A bracket-group boundary alternative was evaluated. It would work, but it adds a third boundary form mirrored at three sites and still leaves residuals (unclosed groups flicker, nested groups). That is more grammar for a case the contract already answers with a visible, recoverable unstage.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: yes
mechanism: the serializer also emits its separator beside a hair space the user typed, so the renderer's single drop removes only generated text
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • user-authored hair spaces are deleted span=608fc6d3a0fd

fixed in 75cf45e: a real defect. The renderer drops one hair space on each side of an inline marker, but the serializer emitted its own only when the neighbour was not whitespace. A hair space the user pasted right beside a mention was therefore read as the generated separator and removed.
replaceTokens (website/src/utils/fileTokens.ts) now also emits a separator when the neighbouring character is itself a hair space. The wire then carries the user's hair space plus the generated one, and the renderer removes exactly one. So a separator alone beside a marker is always a generated one, and the drop can never remove user text. The shape follows your fix direction: the separator is emitted wherever a lone one could be mistaken for the user's, and only the generated one is removed.
Pinned red-before-green in fileTokens.test.ts: check␊@a.txt now, check @a.txt␊, please and (␊@a.txt␊), each with a pasted U+200A (shown as ␊), round-trip through send and render byte-for-byte, and parseFiles still resolves the path. The test fails on the previous head.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • A chip restored from the persisted draft behaves differently after a reload span=fb3669bba265

accepted and deferred to #11256, which tracks exactly this: recorded aliases live in memory per mount, so a chip rehydrated from a saved draft has none, and hand-deleting its mention leaves it staged, the way main behaves for every chip. That is the documented KNOWN LIMITATION in ChatPage.tsx. Persisting aliases with the draft is a storage-format change that issue owns.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Exact-or-nothing unstaging with only the chip's disappearance as feedback span=124c7a83f72b

accepted as the intended behavior: a file whose mention no longer names it is dropped, which is this PR's goal. Main's behavior is the opposite failure, where the file stays staged and is sent with nothing in the text referring to it. The chip row sits directly above the textarea (screenshots 2 and 3), and restoring the exact spelling, Ctrl+Z, or a re-pick restages it. The screen-reader half is filed as #14597.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • No blind reader has cold-read the attachments span=a976dec71213

accepted as this lane's fork limitation: the blind read runs only when the branch is pushed into this repository, which is a maintainer's call.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • The chip-text sync parses intent out of editable prose span=8e0b4e25c648

accepted as the interim shape, with its retirement path decided: the atomic-mention follow-up is built on branch fix/picked-mention-one-unit, to open after this PR with its own tracked issue and reproduction. That issue is the one this item's clearing condition names, and this PR's "Not a goal" list links it once filed. Until then the grammar is defined once in fileTokens.ts, and every documented residual is pinned by a test.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Sent message content now carries U+200A separators under a composer-only compatibility claim span=d2a8b9bf816f

accepted, and the sweep this item asks for is done. Every non-test reference to [attached_file / [attached_dir in src/ and website/src/ was checked on this head:

  • Parsers of message text: the renderer and parseFiles (fileTokens.ts), promptPreview (pinnedPrompt.ts, which strips the separator first), _strip_attached_file_tokens (chat_title.py) and _marker_spans (slot_queue_repository.py). All treat U+200A as whitespace, and the two backend ones are pinned in test/test_attachment_marker_grammar_pin.py.
  • QueueStack's hidden-line cue matches only OWN-line markers (^\[attached_(?:file|dir) \d+\] ), which never carry a separator: the separator is inserted only beside an inline mention, and a marker at a line start has a newline, not a hair space, before it.
  • Everything else is a writer (composerDrop.ts builds own-line markers) or a comment (chat_runner.py, chat_delivery.py, chat_handlers.py, chat_utils.py, handlers/files.py, ChatPane.tsx, chatSlice.ts). chatSlice's title helper splits on a Python-whitespace class that already includes U+200A.
    The body's Backwards compatibility section now states the wire change instead of "composer interaction only".

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Extract the reconciliation effect and its helpers into a dedicated hook span=c97e3f3e8e89

accepted and deferred to #11277, which tracks extracting the mention core out of ChatPage.tsx. Moving the effect and its sibling-set helpers is a structural refactor of an already-reviewed state machine. It belongs in its own change with its own tests, not at the end of this bug fix.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: yes
mechanism: the preview strips only the serializer's separators beside a marker; any other hair space is left to whitespace normalization
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Prompt previews delete authored hair spaces span=ef23294b566c

fixed in 1f257a6, as you suggested: promptPreview (website/src/utils/pinnedPrompt.ts) removed every U+200A. Now it removes only the one directly before an [attached_file N] marker and the one directly after its path, which are the only places the serializer puts them. A hair space anywhere else falls to the existing \s+ pass and reads as an ordinary space, so alpha␊beta previews as alpha beta, not alphabeta.
Pinned red-before-green in pinnedPrompt.test.ts: a pasted U+200A between words survives the preview as a space, and the separated marker shapes still preview as typed (see (main.ts) here). The test fails on the previous head.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: yes
mechanism: the caret clamp finds recorded aliases on the separator-folded text, like the reconciliation that keeps the chip staged
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Windows separator edits bypass the spaced-mention caret clamp span=fd89d98b48d2

fixed in cfc10b1, as you suggested: clampOutOfTokens (website/src/pages/ChatPage.tsx) matched recorded aliases with a literal indexOf. On a Windows-shaped project it now folds \ to / on both the text and the aliases (foldWinSep), the same fold the reconciliation uses to keep the chip staged. The fold is a 1:1 character substitution, so the indices found on the folded copy are the original's. A POSIX project is unchanged, because a backslash can be part of a filename there.
The other readers of recorded aliases in this file (the "Add to chat" duplicate check and the reconciliation effect) already go through relMentionedHere, which folds, so the clamp was the last literal match.
Pinned red-before-green in ChatPage.dirStaging.test.tsx: a docs/My Report.pdf pick on a C:/repo project, hand-edited to @docs\My Report.pdf, caret parked inside Report.pdf, then "Add to chat" on a second file. Both chips stay staged and the mention is intact. On the previous head the second chip is lost.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Inline markers are not restored when a queued send is cancelled after a reload span=532e36de23db

accepted and deferred to #14617, which tracks exactly this: after a reload the in-memory queuedSendStash is gone, and restoreQueuedContent re-stages only markers on their own line, so an inline marker stays as raw wire text and its file is not re-staged. The in-session cancel path, which covers the normal case, restores from the stash and is unaffected. Restoring an inline marker needs the typed @rel spelling recorded with the queued message, which is a storage change that issue owns.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Chip state reconciled against free text is what generated the complexity span=7354391ef0e2

accepted as the interim shape, with its retirement path already decided: the atomic-mention follow-up is built on branch fix/picked-mention-one-unit and opens after this PR, with its own tracked issue and reproduction. That issue is the one this item's clearing condition names. Until then the grammar is defined once in fileTokens.ts, and every documented residual is pinned by a test.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: yes
mechanism: the inline marker grammar, including the U+200A separator, is written into the spec that describes the attachment wire format
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • The U+200A separator is an invisible wire contract every future marker reader must honor span=b75c78cc7423

fixed in cfc10b1, meeting this item's clearing condition: docs/system-specs/modules/file-search.md, the spec that already defines the [attached_file N] / [attached_dir N] wire format, now has an "Inline file markers" paragraph. It says when the serializer inserts the hair space, why (whitespace-terminated path, whitespace before the marker), that every reader must treat U+200A as whitespace, that the renderer and prompt preview drop only the separators beside a marker, and that the backend readers are pinned by test/test_attachment_marker_grammar_pin.py. The body's Backwards compatibility section points to it.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Extract the recorded aliases, reconciliation effect and remove-strip into a dedicated hook span=9b120056ca6f

accepted and deferred to #11277, which tracks extracting the mention core out of ChatPage.tsx. Moving the effect and its sibling-set helpers is a structural refactor of an already-reviewed state machine, and it belongs in its own change with its own tests, not at the end of this bug fix.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • A rewritten mention unstages its chip while the text still looks like a mention span=345269e83f4b

accepted as the intended behavior. When a mention no longer names its file exactly, the file is dropped. That is this PR's goal. Main fails the other way: the file stays staged and is sent with nothing in the text that refers to it. The chip row sits directly above the textarea (screenshots 2 and 3), and restoring the exact spelling, Ctrl+Z or picking the file again restages it. Treating a picked mention as one unit that cannot be half-edited is the follow-up the body names under "Not a goal", and screen-reader announcements are filed as #14597.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • The same hand-delete behaves differently after a reload span=3b3ddc7a6f0c

accepted and deferred to #11256, which tracks exactly this. Recorded aliases live in memory for each mount, so a chip rehydrated from a saved draft has none. Hand-deleting its mention leaves it staged, which is how main behaves for every chip, so a reloaded draft is never worse than today. It is the documented KNOWN LIMITATION in ChatPage.tsx and the first "Not a goal" bullet in the body. Persisting aliases with the draft is a storage-format change that belongs to that issue.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • No first-time reader has seen the attachments in this lane span=ebbad7f83c7c

accepted as this lane's fork limitation. The blind read runs only when the branch is pushed into this repository, which is a maintainer's call. The five attachments cover every changed state.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Partial fix leaves the target bug live across a reload span=1f37541ccb1f

accepted, under the third clearing condition this item names: the PR description already scopes the fix to chips staged in the current session. The first "Not a goal" bullet reads "Keeping mention aliases across a page reload. A chip restored from the saved draft is not reconciled until the file is picked again", and links #11256, the issue that persists aliases with the draft. After a reload a chip behaves exactly as it does on main today, so the residual is main's behavior, stated and tracked, not a regression.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Drop staged files with no live mention at send time span=895449328c91

declined. A staged file with no mention is a legitimate send: uploaded and dropped files never get an @ token (the file-search spec: "Uploaded/dropped files have no token and keep a state-only remove"). The renderer shows them as attachment cards through findUnreferencedAttachments (fileTokens.ts). A send-time guard cannot tell those files apart from a reloaded picked chip, because the thing that would tell them apart is the recorded alias, and a reload loses it. The guard would therefore silently drop every upload. The reload gap is closed properly by persisting aliases with the draft (#11256), and the boundary-agreement risk is held by the one shared grammar in fileTokens.ts plus the send/render agreement tests.

…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>
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Attachment silently dropped outside the edit locus span=9e5fa89259f6

not changed here. Dropping the file once its mention leaves the text is this PR's goal, and it is recoverable: Ctrl+Z, retyping the exact mention or picking again restages it. The chip row sits directly above the textarea, so the change is in view (screenshots 2 and 3). An exit fade or highlight would be a new visual behaviour in the composer. It belongs with the follow-up the body names under "Not a goal", which makes a picked mention one unit and changes how a mention is removed in the first place. Screen-reader announcements of the change are filed as #14597.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Marker wire-format contract widened for every reader span=b3df778e6525

accepted; the enumeration this item asks for was done against this diff. Every non-test reference to [attached_file / [attached_dir in src/ and website/src/ was checked:

  • Parsers of message text: the renderer and parseFiles (fileTokens.ts), promptPreview (pinnedPrompt.ts), _strip_attached_file_tokens (chat_title.py) and _marker_spans (slot_queue_repository.py). All treat U+200A as whitespace, and the two backend ones are pinned in test/test_attachment_marker_grammar_pin.py.
  • QueueStack's hidden-line cue matches only own-line markers, which never carry a separator.
  • Everything else is a writer (composerDrop.ts) or a comment. The model reads the marker as text, where U+200A is whitespace.
    The contract is written down in docs/system-specs/modules/file-search.md ("Inline file markers"), so a new reader is told to honour it. The human confirmation this item names is the maintainer's review.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • Design is otherwise sound span=db2ecc0cc041

acknowledged; nothing to change. This paragraph is the lane's overall assessment, not a concern: the bug is real, the one shared boundary grammar resolves it end-to-end, the edge cases are pinned by tests, and the atomic-token editor it mentions is the follow-up this PR's "Not a goal" list names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline file marker keeps trailing punctuation glued to the path on text-only sends

6 participants