Skip to content

feat(desktop): SHA-256 dedup of image attachments + inline dup notice#3123

Open
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:feat/attach-dedup
Open

feat(desktop): SHA-256 dedup of image attachments + inline dup notice#3123
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:feat/attach-dedup

Conversation

@HUQIANTAO
Copy link
Copy Markdown
Contributor

The composer's image paste/drop handlers were naive: drop the same file twice and you'd get two chips, two @path references, and the kernel would process the same image twice.

Add lib/attachDedup.ts: a small SHA-256 helper (via Web Crypto Subtle) and a DedupIndex that lives for the composer's lifetime. The index is hash-keyed when crypto.subtle is available, path-keyed as a fallback when it isn't.

The dedup check runs BEFORE the data-URL round-trip; a duplicate paste of a 5MB photo skips the encoding step entirely. A small inline 'X already attached' note fades in next to the chips when a paste was a duplicate.

@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 4, 2026
The composer's image paste/drop handlers were naive: drop the same
file twice (or paste the same clipboard twice) and you'd get two
chips, two @path references in the message, and the kernel would
process the same image twice. The user expectation is one chip.

Add lib/attachDedup.ts: a small SHA-256 helper (via Web Crypto
Subtle) and a DedupIndex that lives for the composer's lifetime.
The index is hash-keyed when crypto.subtle is available, path-keyed
as a fallback when it isn't (a weaker dedup — same content from two
different paths won't match — but the common 'dropped the same
file twice' case is covered).

The dedup check runs BEFORE the data-URL round-trip in
attachImageFiles; a duplicate paste of a 5MB photo skips the
encoding step entirely. The kernel's SavePastedImage and
AttachmentDataURL are only called for the first occurrence.

A small inline 'X already attached' note fades in next to the
attachment chips when a paste/drops was a duplicate, so the user
understands why their second paste didn't add a second chip. The
note clears after 2.2s.

The index resets automatically when the composer unmounts, which
happens on newSession() in App — so a new session starts with a
fresh palette, matching the user's mental model.
@HUQIANTAO HUQIANTAO force-pushed the feat/attach-dedup branch from 75f3eb2 to b56033e Compare June 5, 2026 01:44
@HUQIANTAO HUQIANTAO requested a review from SivanCola as a code owner June 5, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant