Skip to content

feat: add '/cp' command to copy last response to clipboard #2049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

07pepa
Copy link

@07pepa 07pepa commented Jun 21, 2025

This feature is for clai package.

It adds /cp command (analogus to linux cp command) to clai that coppies model output to clipboard as is.

TL DR what was done:

  • added new clai dependency: pyperclip
  • added handler in clai for comand /cp to store data to clipboard
  • added documentation
  • added unit tests
  • tested manualy

@Copilot Copilot AI review requested due to automatic review settings June 21, 2025 15:13
Copy link
Contributor

hyperlint-ai bot commented Jun 21, 2025

PR Change Summary

Added a new command to the clai package that allows users to copy the last response to the clipboard.

  • Introduced the /cp command to copy model output to clipboard
  • Added the pyperclip dependency for clipboard functionality
  • Updated documentation to include the new command
  • Implemented unit tests for the new feature

Modified Files

  • clai/README.md
  • docs/cli.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@07pepa 07pepa marked this pull request as draft June 21, 2025 15:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new /cp command to copy the last chat response to the clipboard, including dependency updates, CLI handling, documentation, and tests.

  • Introduces pyperclip as a new CLI dependency
  • Implements /cp in handle_slash_command and updates auto-suggestions
  • Updates docs, adds unit tests for the new behavior

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_cli.py Imported pyperclip, added tests for /cp command
pydantic_ai_slim/pyproject.toml Added pyperclip>=1.9.0 to the cli dependencies
pydantic_ai_slim/pydantic_ai/_cli.py Imported pyperclip, updated help and handler for /cp, modified auto-suggestions
docs/cli.md Documented the /cp command
clai/README.md Documented the /cp command
Comments suppressed due to low confidence (1)

tests/test_cli.py:215

  • [nitpick] Consider adding a test case where messages[-1].parts contains only non-text parts to cover the 'No text content to copy.' branch and ensure that no clipboard write occurs.
def test_handle_slash_command_copy():

@07pepa 07pepa force-pushed the add-coppy-to-clipboard-comand branch 6 times, most recently from b32f526 to 620e858 Compare June 21, 2025 16:13
@07pepa 07pepa force-pushed the add-coppy-to-clipboard-comand branch from 620e858 to ccc9422 Compare June 21, 2025 16:28
@07pepa 07pepa marked this pull request as ready for review June 21, 2025 16:39
except IndexError:
console.print('[dim]No output available to copy.[/dim]')
else:
text_to_copy = ''.join(part.content for part in parts if part.part_kind == 'text')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'll want to put 1 or 2 newlines in between text from different parts, as they may not join cleanly.

@DouweM
Copy link
Contributor

DouweM commented Jun 23, 2025

@07pepa Thanks, nice feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants