Skip to content

fix(cli): smart paste — 6 review fixes (PR #4764 follow-up)#2

Closed
StefanIsMe wants to merge 2 commits intofeat/smart-paste-in-memoryfrom
fix/smart-paste-review-fixes
Closed

fix(cli): smart paste — 6 review fixes (PR #4764 follow-up)#2
StefanIsMe wants to merge 2 commits intofeat/smart-paste-in-memoryfrom
fix/smart-paste-review-fixes

Conversation

@StefanIsMe
Copy link
Copy Markdown
Owner

Summary

Six bugs identified and fixed after review of NousResearch#4764. This is a stacked PR that builds directly on NousResearch#4764 (feat/smart-paste-in-memory).

Changes

# Fix Description
1 DRY _make_paste_marker() Single canonical helper used by all 3 call sites — handle_paste, _on_text_changed, and _reconstruct_pastes — so marker format is always consistent
2 MAX_PASTE_SIZE = 100_000 Pastes > 100 KB inserted as plain text; no OOM risk from hoarding oversized payloads
3 Deletion loop: remove early return any_deleted flag replaces return-inside-loop; a single Delete now clears ALL stale markers per keystroke
4 Fallback stores pasted_portion _on_text_changed now saves text[prev_len:] (just the new chunk), not buf.text in full
5 Unified _PASTE_MARKER_RE _reconstruct_pastes uses one regex matching BOTH [+X line(s)] and [+X char(s)] formats
6 Threshold aligned to 20 chars Both handle_paste (bracketed) and fallback (_on_text_changed) paths now use char_count >= 20

Test plan

  • Paste 20+ char text → collapsed to [+X chars] marker
  • Paste 5 lines of 3 chars each (15 total) → NOT collapsed (below 20-char threshold)
  • Paste 5+ lines totaling 20+ chars → collapsed to [+X lines]
  • Paste > 100 KB text → inserted as plain text (no collapse)
  • Type 20 chars manually → fallback detects it correctly
  • Delete any part of a [+X lines] marker → entire marker is removed
  • Delete part of marker A then marker B in one keystroke → both cleared
  • Type before paste → typed text preserved, only pasted portion is collapsed
  • Submit (Enter) → all markers replaced with full stored text

/cc @NousResearch/hermes-agent

Stefan added 2 commits April 3, 2026 17:22
…er reconstruction

- Replace temp-file paste storage with in-memory _paste_store dict
- Track active paste IDs in _active_paste_ids set for multi-paste support
- Add _reconstruct_pastes() called at submit time to expand markers
- Fix / bypass: now checks pasted_text (not buffer) starts with /
- Add deletion detection: wiping any part of a paste marker wipes the whole block
- Replace buf.insert_text() with buf.text = buf.text + placeholder
  to avoid post-cursor content being pushed to next line
- Remove dependency on _hermes_home/pastes/ temp directory
…back

Six bugs identified during PR NousResearch#4764 review, applied as an atomic commit:

1. DRY _make_paste_marker() helper — all 3 call sites (handle_paste,
   _on_text_changed, _reconstruct_pastes) now share one canonical function,
   eliminating the char vs line format mismatch that broke paste reconstruction.

2. MAX_PASTE_SIZE = 100_000 memory cap — pastes > 100 KB are inserted as
   plain text to prevent OOM from hoarding oversized payloads.

3. Deletion loop: remove early return — replaced with any_deleted flag so
   every active paste_id is checked per keystroke; one Delete can now clear
   multiple stale markers instead of stopping at the first match.

4. Fallback: store pasted_portion not full buffer — _on_text_changed now
   saves text[prev_len:] (the newly pasted chunk) rather than buf.text in
   its entirety, so pre-existing typed content is never hoisted into the
   paste store.

5. Unified _PASTE_MARKER_RE regex — _reconstruct_pastes uses a single regex
   matching both [+X line(s)] and [+X char(s)] formats, making it robust
   against any inconsistency between the bracketed-paste path and the
   fallback detection path.

6. Threshold aligned to 20 chars — both handle_paste and _on_text_changed
   now use char_count >= 20 as the collapse trigger, consistent with the
   documented contract.
@StefanIsMe StefanIsMe added bug Something isn't working enhancement New feature or request labels Apr 4, 2026
@StefanIsMe StefanIsMe force-pushed the feat/smart-paste-in-memory branch 2 times, most recently from a625209 to 3ae7bdf Compare April 5, 2026 06:00
@StefanIsMe StefanIsMe closed this Apr 11, 2026
@StefanIsMe StefanIsMe deleted the fix/smart-paste-review-fixes branch April 11, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant