Skip to content

fix(cli): collapse only large pasted chunks instead of the whole prompt - #2529

Closed
francip wants to merge 1 commit into
NousResearch:mainfrom
kortexa-ai:kortexa/fix-paste-collapse-detection
Closed

fix(cli): collapse only large pasted chunks instead of the whole prompt#2529
francip wants to merge 1 commit into
NousResearch:mainfrom
kortexa-ai:kortexa/fix-paste-collapse-detection

Conversation

@francip

@francip francip commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Note: This PR was authored and tested by Avery - a Hermes agent, with guidance from @francip.


What Changed

Fixed Hermes CLI paste collapsing so it only collapses the actual pasted chunk instead of collapsing the entire in-progress prompt based on total buffer size.

Files: cli.py, hermes_cli/paste_collapse.py, tests/test_cli_paste_collapse.py

Changes:

  • moved paste-collapse decisions into the BracketedPaste handler, where the actual pasted text is available
  • added a small helper module for paste-collapse logic:
    • should_collapse_pasted_text
    • write_pasted_text_reference
    • materialize_paste_for_insertion
    • expand_paste_references
  • removed the old whole-buffer on_text_changed collapse heuristic
  • updated submit-time expansion so inline paste references inside a larger draft expand before being sent to the agent

Why

Paste collapsing is useful for genuinely large pasted blocks, but the previous implementation used the total prompt content as the trigger. That meant a user could type a long multi-line draft, paste a tiny snippet, and have the whole prompt unexpectedly collapsed into a [Pasted text ...] reference.

This change makes the behavior match user intent:

  • small pasted snippets stay inline
  • large pasted chunks collapse cleanly
  • surrounding draft text is preserved
  • users can keep editing around the inserted placeholder

Example

Before:

  1. type a long multi-line prompt manually
  2. paste a single word
  3. the entire prompt could collapse

After:

  • only genuinely large pasted chunks collapse
  • a small paste into a large draft does not collapse the whole prompt
  • inline paste references still expand before send

Screenshot

Fixed Hermes CLI paste collapsing behavior

Fixed behavior: a large pasted chunk is collapsed into a placeholder while the surrounding draft remains intact and editable.

How to Test

python -m cli

Then try:

  1. type a 6–7 line prompt manually
  2. paste a single word
  3. confirm the prompt stays editable and does not collapse

Then try:

  1. paste a genuinely large multi-line block
  2. confirm only the pasted chunk is replaced by a [Pasted text ...] placeholder
  3. keep typing before or after the placeholder
  4. submit and confirm the full pasted content reaches the agent

Validation

Automated:

source venv/bin/activate
python -m pytest tests/test_cli_paste_collapse.py tests/test_cli_init.py tests/test_cli_provider_resolution.py tests/test_cli_secret_capture.py -q

Result: 42 passed

Regression coverage added:

  • collapse decision is based on pasted chunk size, not total buffer size
  • tiny paste into large existing draft does not collapse
  • large paste collapses only the inserted chunk
  • surrounding draft text is preserved
  • slash-command input still bypasses collapse
  • inline paste references expand before send
  • missing paste files degrade safely

Platforms Tested

✅ macOS CLI

This change is isolated to CLI paste handling and paste-reference expansion, so it should remain portable across platforms using the same prompt_toolkit flow.

@francip
francip force-pushed the kortexa/fix-paste-collapse-detection branch 3 times, most recently from 3f62814 to 32874a3 Compare March 27, 2026 16:40
@francip
francip force-pushed the kortexa/fix-paste-collapse-detection branch 5 times, most recently from 7d97edf to a74152c Compare April 5, 2026 01:16
@francip
francip force-pushed the kortexa/fix-paste-collapse-detection branch 4 times, most recently from 42d3117 to 13168b8 Compare April 11, 2026 03:06
@francip
francip force-pushed the kortexa/fix-paste-collapse-detection branch from 13168b8 to 684e66c Compare April 15, 2026 06:45
@francip
francip force-pushed the kortexa/fix-paste-collapse-detection branch from 684e66c to 91531b1 Compare April 20, 2026 03:09
@francip

francip commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by upstream #3065 (feat(cli): preserve user input on multiline paste) and its follow-ups. The paste-collapse behavior change is already on main; remaining diff was only refactoring, not worth the churn.

@francip francip closed this Apr 20, 2026
@francip
francip deleted the kortexa/fix-paste-collapse-detection branch April 20, 2026 03:16
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.

1 participant