refactor(web): composer context imports live in useComposerContextImport#23048

merged1
refactor/split2-composer-stash
refactor/split2-composer-attachments
opened4d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 4d ago

Context pasted or dropped into the composer goes through about 280 lines of import code in the composer body. That covers copied terminal output, review comments, annotations, threads, images and files, and the same code restores stash entries that carry records.

useComposerContextImport now holds that code:

  • runAttachmentImport, which downloads and re-uploads a copied image or file
  • importAttachmentRecord
  • importContextRecords
  • importContextFragment
  • countReservedAttachments
  • downloadAttachmentBlob, which only the import uses

The hook reads the draft-store adders itself instead of taking them from the composer. It returns the import functions, their existing stable forms, the slot counter, and loadThreadTranscript, which thread drops still use. It is called where the import code started, so hook and effect order are unchanged. This PR adds no useStableCallback.

Filebeforeafter
ChatComposer.tsx4,8604,570
useComposerContextImport.ts398

Renders are unchanged. This layer moves logic, not render boundaries.

Tested:

  • apps/web typecheck and lint on the touched files.
  • React Compiler: 0 bailouts on both files.
  • Hands-on in a dev build. Pasting an image attaches it and adds its inline chip. Stashing that prompt and restoring it brings back the image and the chip, which goes through importContextRecords.
  • Not tested by hand: pasting a context fragment copied from another composer. The headless browser could not round-trip the clipboard.

🤖 Generated with Claude Code

Checks

30 successful · 9 skipped
All checks passed
d7b37b8

Added 1 commit

  • refactor(web): composer context imports live in useComposerContextImportd7b37b8
Synced from GitHub

Approvability

Verdict: Approved at d7b37b8

Macroscope's review found this PR approvable — This is a focused extraction of existing composer context-import and attachment-counting logic into a dedicated hook, with unchanged call sites and behavior. It introduces no new capability, schema change, product-default change, or static-analysis override.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 6a7a6116-3716-47cb-af73-1c5cb7161c11
📥 Commits

Reviewing files that changed from the base of the PR and between 25fa572eba1b8a200711bee4bb5b3acc7e39e5c0 and d7b37b81c32eeb84d581993d1906bd32d907feaa.

📒 Files selected for processing: 2
  • apps/web/src/components/chat/ChatComposer.tsx
  • apps/web/src/components/chat/useComposerContextImport.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

ChatComposer now delegates context imports to useComposerContextImport. The hook handles attachment retrieval, draft and attachment limits, context-record deduplication and ID reminting, foreign-thread filtering, and transcript loading.

Changes: Composer context import

Layer / File(s)Summary
Attachment import workflow
apps/web/src/components/chat/useComposerContextImport.ts, apps/web/src/components/chat/ChatComposer.tsx
The hook counts reserved attachments and handles copied-file reuse or source-environment downloads. It checks the draft target and attachment limit, tracks pending work, and reports download failures.
Context-record import
apps/web/src/components/chat/useComposerContextImport.ts
The hook orders annotations before screenshots, detects equivalent payloads, remints conflicting IDs, rewrites references, filters foreign threads, and exposes import callbacks and transcript loading.
Composer integration
apps/web/src/components/chat/ChatComposer.tsx
The component replaces its inline import logic with the hook and passes draft, attachment, pending-work, context-record, and file-insertion state. It removes related legacy imports and the local download helper.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Suggested reviewers: maria-rcks

Merge Risk: ⚪ Minimal · up to d7b37

This is a refactor that moves composer context-import code into its own hook without intended behavior changes. No concrete regression was identified, so the merge risk is minimal. Context fragments copied between composers are the one path that was not hand-tested.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check nameStatusExplanationResolution
Description checkWarningThe description clearly explains the refactor and includes focused verification results. It does not follow the required template structure because it omits the Problem and Scope and approval sections…Add the required Problem, Change, Scope and approval, and Verification headings. Describe the prior problem and expected behavior. Link the triaged issue or maintainer approval, or explain why this focused refactor qualifies for an exemptio…
Passed Passed checks: 3 passed
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely identifies the main change: moving composer context-import logic into useComposerContextImport.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the refactor and includes focused verification results. It does not follow the required template structure because it omits the Problem and Scope and approval sections, and it does not provide the required issue or maintainer-approval information. The verification section is also not explicitly labeled.

Resolution

Add the required Problem, Change, Scope and approval, and Verification headings. Describe the prior problem and expected behavior. Link the triaged issue or maintainer approval, or explain why this focused refactor qualifies for an exemption. Keep the reported test results under Verification and state the untested cross-composer clipboard case.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.