Skip to content

refactor(chat-core): share the attachment picker - #20178

Merged
buluoray merged 2 commits into
mainfrom
feat/chat-core-pc-attach-review
Oct 15, 2026
Merged

buluoray merged 2 commits into
mainfrom
feat/chat-core-pc-attach-review

Conversation

@buluoray

@buluoray buluoray commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Keep attachment handling consistent across chat surfaces without changing app permissions or losing staged files when a send fails.

ChatEmbed has its own file-selection and attachment lifecycle implementation. Fixes to that implementation do not reach the main composer, while the two file inputs repeat the same selection/reset behavior.

Why it matters

One attachment fix should not require separate picker changes for the dashboard and an app embed. The extraction keeps the working upload, staged-file and send-recovery behavior while putting the shared behavior in store-free chat-core code.

Not a goal

  • Add attachment features, permission grants or automatic upload opt-in.
  • Change authentication, upload policy, polling or transcript transport.
  • Redesign composer chrome or move the dashboard's draft persistence, file mentions and cancel controls into a new state owner.
  • Implement the independent stop-button or optimistic-message phases.

What changed (motivation → approach → change)

Duplicated file-input handling → one small store-free Attach atom → both ChatInput and ChatEmbed supply their real staging callbacks to it. The atom forwards each host's input ref, id, accept hint, multiple/hidden attributes and resets selection after a pick; existing triggers and focus-return logic remain in place.

Only the picker is shared. The embed's staging, paste/drop policy, in-flight uploads, abort cleanup, late-result fencing and failed-send recovery stay in the SDK's useEmbedAttachments, unchanged from #19917, beside its explicit upload grant and scoped raw transport. No Redux Provider, router or default dashboard network client is introduced.

Remaining under #19994: sharing the attachment lifecycle itself (staging, upload holds, cancellation, failed-send recovery) between ChatEmbed and the main chat is not done here. It needs a real second writer on the main-chat side, so it stays open as follow-up work under #19994.

The existing shared multipart builder, file preview strip and outgoing-turn builder are reused. The existing send-recovery and app onSend metadata paths remain intact.

Design: chat-core RFC, layer 4 / P3-f. This is the attachment slice, P-c.

Base

Targets main at bcedb90c32 (the #19917 merge). #20102 and #19917 are both merged. The earlier temporary base tmp/chat-core-pc-deps-20102-19917 is no longer used; the P-c commits were rebased off it onto main with conflicts resolved to main's merged code, so useEmbedAttachments.ts and atoms.tsx are byte-identical to main.

Files changed: 12 files, +257/-16, the same P-c content as before the rebase. The second commit also updates the mutation script anchor to main's ComposerSend uploading prop.

Backwards compatibility

Compatible: host upload opt-in, scoped API checks, onSend(message, meta), paste/drop handling, staged paths, failed-send recovery and cancellation remain in place, in the SDK hook #19917 ships. Dashboard staging still uses its existing persistence/mention/recovery writers.

Reader: website/src/components/ChatInput.tsx:usePasteTokens — chat — the private handleFileInputChange member moves to ComposerAttach; the same onUploadFiles callback receives selected files, with focus-return and accept-hint regressions passing.
Reader: website/src/app-sdk/ChatEmbed.tsx:useEmbedAttachments — app — the hook and its return contract are unchanged from #19917; only its file input is now ComposerAttach. Attachment tests cover opt-in refusal and send recovery.

Tests

Validation on the rebased tree (24622d67c6, same tree as c1254fa38c, base main bcedb90c32):

  • Targeted vitest (src/chat-core/composer, src/test/ChatEmbed*, src/components/chat-input, src/test/ChatInput*): 1124 passed, 3 failed. The 3 failures are in ChatInput.approval.test.tsx (approval bar) and fail identically on a clean detached checkout of main bcedb90c32; they are not from this diff.
  • TypeScript check and targeted ESLint pass.
  • 5/5 deliberate mutations caught: picker reset, picker writer, permission bypass, file-only sends, upload hold. Each failure was a matching behavior assertion.
  • All five screenshots recaptured on the rebased tree and inspected individually; they match the images below, so the attachments were kept.
  • Broad local-gate.py selection was inspected, not executed: 816 backend / 425 frontend files. Focused tests above were run instead; full/main-base validation remains pending.

Manual verification

Mounted real ChatEmbed with real AppApiProvider and React Query, no Redux Provider or router. Fixed fake data/API only; no real gateway chat or upload was sent. Five scenes rerun from the tree committed as this head, opened and inspected individually: desktop dark, 390px light, refused-send recovery, denied upload and file-only queue. Browser assertions verify staged files, send enablement, restored text and no horizontal overflow. No page errors or visible overlap found.

Native OS file-picker dialogs and real gateway authorization are not verified by this harness. The preview server binds loopback and closes with its browser in finally.

Screenshots / video

Shared attachment picker and staged file, dark desktop

Staged file, light 390px viewport

Refused send keeps the draft and attachment

Permission denial and file-only queue

Upload opt-in denied, light 390px viewport

File-only queue, dark 390px viewport

Related Issues

Refs #19994 (P-c)

Builds on #20102 and #19917 (both merged).

Pattern harvest

Not generalizable: this is an extraction onto the existing chat-core boundary; behavior is pinned by component regressions and deliberate mutations, not a new cross-repository rule.

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)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 9ec62aa38efe688f5fb2802eef5387f64c06b255 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the three ChatInput.approval.test.tsx failures the description calls pre-existing also fail on current main, not just on bcedb90c32.

[DESIGN-REVIEWED] 9ec62aa

Description read

[DESCRIPTION-READ] a03467457db16a3962940fc8030a13112a20322875ebb80b05a73a806e462324

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 9ec62aa38efe688f5fb2802eef5387f64c06b255 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Nothing to check.

[UX-REVIEWED] 9ec62aa

Description read

[DESCRIPTION-READ] 36a52ff10ecd063f2fbdd942ec165a6ced3d649b35254e7edc13a269a1738251

That sha256 names everything this verdict read: the PR description, plus the 8 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9ec62aa38efe688f5fb2802eef5387f64c06b255 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9ec62aa

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 9ec62aa38efe688f5fb2802eef5387f64c06b255: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 9ec62aa38efe688f5fb2802eef5387f64c06b255 — 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: CONCERNS

mutate-chat-core-attach.mjs is the repo's first and only mutation script. Nothing calls it, and it pins string anchors inside files this PR leaves byte-identical.

Not justified as shipped

  • Item 5 — zero consumers: the PR's mutation proof ('pending || uploading || !hasContent' in atoms.tsx, 'if (!granted) {' in useEmbedAttachments.ts) is committed as a script. I grepped website/scripts for mutate-* and found 1 file, this one. No package.json, CI or doc entry runs it, so it does its job once and then becomes surface that throws Missing mutation anchor on the next edit to either file.
    Subtraction: delete website/scripts/mutate-chat-core-attach.mjs and keep the 5/5 result in the PR description.
    Clears when: the script is deleted, or a counted runner invokes it.
  • Item 4 — zero consumers: the new data-composer-attach attribute has 0 non-test readers (grepped composer-attach across website/src and website/e2e).
    Subtraction: drop the attribute and the one assertion on it in ChatEmbed.attachments.test.tsx:308. The chat-embed-file-input testid already finds the input.
    Clears when: the attribute is removed, or something outside tests reads it.

What this change ships

Inventory (6 items) — 4 justified

Intent: one file-picker fix should reach both the dashboard composer and the app embed. This is an ADDITION (a refactor extraction under RFC P3-f, partial).

  1. Dashboard composer's file input now goes through the shared ComposerAttach picker — justified
  2. App embed's file input now goes through the same picker — justified
  3. usePasteTokens no longer returns handleFileInputChange — justified
  4. New data-composer-attach marker on both inputs — zero consumers
  5. New mutation-testing script — zero consumers
  6. New capture page and screenshot script for the embed — justified

[FIRST-PRINCIPLES-REVIEWED] 9ec62aa

Description read

[DESCRIPTION-READ] ddf3a9d181c155445822c55c55ce4549bc91965e4aa05664e23679526bf18c4d

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9ec62aa38efe688f5fb2802eef5387f64c06b255 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9ec62aa

Verdict parsed from the review's SHA-scoped output markers for commit 9ec62aa38efe688f5fb2802eef5387f64c06b255.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 9ec62aa38efe688f5fb2802eef5387f64c06b255: <one-sentence reason>

@buluoray

Copy link
Copy Markdown
Contributor Author
  • needs-a-decision — Item 2: lifecycle sharing

Verified: useComposerAttachments has only one production consumer, useEmbedAttachments. ComposerAttach is shared by ChatInput and ChatEmbed; the lifecycle is relocated, not yet shared across hosts.
Maintainer decision needed: should P-c retain this store-free extraction as the requested migration slice, or narrow to the shared picker and return lifecycle ownership to the SDK? The latter removes the injected upload/deniedNotice seam but retracts the current lifecycle-migration promise. Adding a dashboard lifecycle consumer instead requires reconciling its existing persistence, mention, recovery and cross-surface arrival writers; that is substantially broader than this picker extraction.
Recommendation: retain the shared picker, fold the single-consumer lifecycle back into the SDK, and explicitly approve that scope correction before changing code/spec/description. Holding this head; no advisory-only push or override.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • rebutted — Item 4: mutation runner has no consumer

The script is an explicitly invoked validation tool, not a runtime API: node scripts/mutate-chat-core-attach.mjs . It was run on this exact published head; seven mutations caused the matching behavior assertions to fail, followed by a clean 94-test run after restoration.
No CI or npm entry currently invokes it, and the PR does not claim automatic mutation coverage. Keeping a reproducible manual check is useful; deleting it because static code has no caller would remove the way to repeat the evidence. No new CI job or package script is being added merely to satisfy a caller count.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • needs-a-decision — shared upload lifecycle suggestion

Confirmed the scope distinction: only the picker currently serves both ChatInput and ChatEmbed. The lifecycle hook serves the embed alone; no second adopter is claimed or scheduled here.
The First Principles Item 2 disposition asks the maintainer to choose between keeping the requested lifecycle relocation and narrowing the phase to the truly shared picker. No speculative second consumer, spec-only cosmetic push, or silent change to the frozen goal will be made while that decision is open.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • rebutted — native picker verification as completed evidence

The requested native OS picker check has not been performed, and no screenshot shows ChatInput; both limits remain explicit. The evidence establishes browser setInputFiles behavior and embed layout, not an OS-native dialog.
ChatInput keeps its existing fileInputRef, input id, accept hint, onUploadFiles writer and focus-return handlers. The focused main-composer paste, focus-return and accept tests pass, and the shared input test catches removal of its reset or writer.
This PASS suggestion remains a manual verification limitation before main readiness, not a claimed native-platform pass or grounds to change the shared visual design.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 14, 2026
buluoray added a commit that referenced this pull request Oct 14, 2026
…state in the SDK

Per the owner's scope choice on #20178, the embed's staging, upload holds,
cancellation and failed-send recovery return to useEmbedAttachments
unchanged from #19917. Sharing that lifecycle stays open under #19994.

Refs #19994 (P-c)
@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 Oct 14, 2026
buluoray added a commit that referenced this pull request Oct 14, 2026
…state in the SDK

Per the owner's scope choice on #20178, the embed's staging, upload holds,
cancellation and failed-send recovery return to useEmbedAttachments
unchanged from #19917. Sharing that lifecycle stays open under #19994.

Refs #19994 (P-c)
@buluoray
buluoray force-pushed the feat/chat-core-pc-attach-review branch from 9ab3962 to c1254fa Compare October 14, 2026 20:57
@buluoray
buluoray changed the base branch from tmp/chat-core-pc-deps-20102-19917 to main October 14, 2026 20:57
@buluoray
buluoray marked this pull request as ready for review October 14, 2026 20:57
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 14, 2026 20:57
@buluoray
buluoray requested a review from CrysisDeu October 14, 2026 20:57
buluoray added a commit that referenced this pull request Oct 14, 2026
…state in the SDK

Per the owner's scope choice on #20178, the embed's staging, upload holds,
cancellation and failed-send recovery return to useEmbedAttachments
unchanged from #19917. Sharing that lifecycle stays open under #19994.

Refs #19994 (P-c)
@buluoray
buluoray force-pushed the feat/chat-core-pc-attach-review branch from c1254fa to 24622d6 Compare October 14, 2026 21:41
@buluoray buluoray changed the title refactor(chat-core): share attachment picker and staging refactor(chat-core): share the attachment picker Oct 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author
  • fixed — Item 6: title promised shared staging

The PR title is now refactor(chat-core): share the attachment picker. Only metadata changed; the head is still 24622d67c6.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • rebutted — Item 4: mutation runner has no consumer

The script runs by hand: node scripts/mutate-chat-core-attach.mjs <out-dir>. On this head, all 5 mutations were caught. Anchor drift is not silent: an anchor that no longer matches makes the script throw Missing mutation anchor: <name>. That happened once during this rebase, when main renamed uploadPending to uploading, and the anchor was updated. No CI or npm entry is added, and the PR does not claim automatic mutation coverage. Deleting the script would remove the way to repeat the evidence.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 14, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES at 24622d6.

The code change is sound. ComposerAttach calls onFiles only for a non-empty pick and resets the input, which matches both handlers it replaces (Attach.tsx#L11-L25). Upload grants and send recovery stay in useEmbedAttachments. The lifecycle deferral is tracked in #19994 (P-c). CI is green.

One doc defect needs a fix. It was raised by both the Opus finding and the Design suggestion on this head, and neither has a reply. In the RFC, the new Attach-slice paragraph sits between **P3 — Composer.** and the phase's own definition. The bullet now opens with slice status and leaves 'ChatInput extraction with capability flags; SideChat and ChatEmbed adopt it.' hanging on its own line (rfc-chat-core-extraction.md#L83-L91). Smallest fix: put the definition sentence back right after the bold label, and move the Attach-slice note into the phase's Status: text.

After that push, please also re-post the UX disposition on the native file-picker check for the new head. The current one names 473efed.

I read the diff and the tests but did not run them.

— crew-pr-reviewer (r102)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 15, 2026
@buluoray
buluoray enabled auto-merge (squash) October 15, 2026 02:48
@buluoray
buluoray disabled auto-merge October 15, 2026 15:42
buluoray added a commit that referenced this pull request Oct 15, 2026
…state in the SDK

Per the owner's scope choice on #20178, the embed's staging, upload holds,
cancellation and failed-send recovery return to useEmbedAttachments
unchanged from #19917. Sharing that lifecycle stays open under #19994.

Refs #19994 (P-c)
@buluoray
buluoray force-pushed the feat/chat-core-pc-attach-review branch from 24622d6 to 3cc83e2 Compare October 15, 2026 15:43
@buluoray

Copy link
Copy Markdown
Contributor Author
  • fixed — RFC P3 entry order (rfc-chat-core-extraction.md:83)

The definition sentence ChatInput extraction with capability flags; SideChat and ChatEmbed adopt it. is back right after P3 — Composer., and the Attach-slice note now sits inside the phase's Status: text, before the #8651 follow-on. Docs-only change, folded into commit 2 at 3cc83e2; no code changed.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • fixed — Attach-slice status placed after the P3 definition

Same edit as the Opus finding: the P3 bullet opens with its definition again, and the Attach-slice status moved into Status:. The retitle suggestion was already applied earlier. Docs-only change at 3cc83e2.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • rebutted — native picker verification as completed evidence

Re-posted for 3cc83e2; the only change since 473efed is docs (RFC ordering) and the rebase onto main, so this disposition stands unchanged.
The requested native OS picker check has not been performed, and no screenshot shows ChatInput; both limits remain explicit. The evidence establishes browser setInputFiles behavior and embed layout, not an OS-native dialog.
ChatInput keeps its existing fileInputRef, input id, accept hint, onUploadFiles writer and focus-return handlers. The focused main-composer paste, focus-return and accept tests pass, and the shared input test catches removal of its reset or writer.
This PASS suggestion remains a manual verification limitation before main readiness, not a claimed native-platform pass or grounds to change the shared visual design.

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]: @iamwhatever re review 5526995321 — fixed at 3cc83e2. The P3 bullet opens with its definition again; the Attach-slice note moved into the phase's Status: text. Folded into commit 2 (still 2 commits; tree diff vs 24622d6 is that one RFC file only). Replied to the Opus finding and the Design suggestion, and re-posted the UX native-picker disposition for the new head.

@buluoray
buluoray requested a review from iamwhatever October 15, 2026 15:44
@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 Oct 15, 2026
@buluoray
buluoray enabled auto-merge (squash) October 15, 2026 17:01
Route ChatInput and ChatEmbed file selection through one store-free
Attach atom. Keep real host staging writers and leave dashboard draft
persistence, mentions, cancellation and chrome in their current hosts.

Move embed staging, file gestures and upload lifecycle into chat-core;
retain only permission checks and scoped upload transport at the SDK
edge. Keep existing send recovery and host onSend metadata contracts.

Refs #19994 (P-c)

Dependency review draft only: based on temporary integration commit
1994c94, which preserves pinned #20102
and #19917. This commit does not claim their implementation. Rebuild on
then-current main after those prerequisites merge; no auto-merge.

Validation: 94 targeted tests pass with shuffled seed 19994; tsc passes.
Five real-component fake-data captures rechecked at desktop and 390px.
…state in the SDK

Per the owner's scope choice on #20178, the embed's staging, upload holds,
cancellation and failed-send recovery return to useEmbedAttachments
unchanged from #19917. Sharing that lifecycle stays open under #19994.

Refs #19994 (P-c)
@buluoray
buluoray force-pushed the feat/chat-core-pc-attach-review branch from 3cc83e2 to 9ec62aa Compare October 15, 2026 17:38
@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 Oct 15, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@buluoray
buluoray merged commit d56fab8 into main Oct 15, 2026
103 checks passed
@buluoray
buluoray deleted the feat/chat-core-pc-attach-review branch October 15, 2026 21:34
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants