Skip to content

Feat/auto copy last code block element - #800

Open
AryanNandanwar wants to merge 4 commits into
Nano-Collective:mainfrom
AryanNandanwar:feat/auto-copy-last-code-block-element
Open

Feat/auto copy last code block element#800
AryanNandanwar wants to merge 4 commits into
Nano-Collective:mainfrom
AryanNandanwar:feat/auto-copy-last-code-block-element

Conversation

@AryanNandanwar

Copy link
Copy Markdown

Description

Adds a keyboard-friendly way to copy AI output from the Nanocoder VS Code chat webview (closes #759).

In the sidebar chat you can:

  • Type /copy to copy the last full assistant response to the clipboard
  • Type /copy code to copy only the last fenced code block (<pre><code> in the messages DOM)
  • Use Ctrl+Alt+Shift+C / Cmd+Alt+Shift+C (or Nanocoder: Copy Last Code Block from the Command Palette) to copy the last code block

Copy is scoped to assistant messages only (via an agent-markdown marker), so user echoes and thought boxes are ignored. The webview finds the text; the extension host writes it with vscode.env.clipboard.writeText and shows a short in-webview toast.

The chosen hotkey avoids conflicts with VS Code’s Ctrl+Shift+C (external terminal) and Cursor’s Ctrl+Alt+C (confetti). Terminal CLI /copy behavior is unchanged.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

(Webview UI lives under plugins/vscode/, which is outside the root AVA/Biome suite; verified via TypeScript check, extension build, and manual testing below.)

Manual Testing

  • Tested in Nanocoder VS Code/Cursor chat webview (ACP session)
  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Manual checks:

  • /copy copies the last full assistant response
  • /copy code copies the last fenced code block (indentation preserved, no extra trailing blank line)
  • Empty chat shows a clear empty-state toast
  • User-typed / thought-box code blocks are not selected
  • Hotkey / Command Palette path copies the last code block when the chat view is focused
  • Extension packages successfully (pnpm run build:vscode)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

@AryanNandanwar

Copy link
Copy Markdown
Author

I'll update it with the changeset

@AryanNandanwar
AryanNandanwar marked this pull request as draft August 6, 2026 18:05
@AryanNandanwar
AryanNandanwar marked this pull request as ready for review August 6, 2026 18:06
@AryanNandanwar

Copy link
Copy Markdown
Author

Hey @akramcodez Please review this when you get the time.

@akramcodez

Copy link
Copy Markdown
Collaborator

Hi @AryanNandanwar, thanks for taking this on and for the detailed PR description!

I reviewed the code and noticed a major discrepancy between the plan you outlined in the issue thread and the actual implementation in this PR.

1. Architecture Flaw: Backend vs. Frontend Clipboard

  • What is wrong: The PR uses the clipboardy npm package inside source/acp/acp-agent.ts (the backend CLI engine) to write to the clipboard.
  • Why it is wrong: Nanocoder's ACP backend often runs in isolated environments (like DevContainers, Docker, WSL, or remote SSH). If you use clipboardy on the backend, it will attempt to write to the remote server's clipboard (which often fails or goes nowhere), rather than the user's local operating system clipboard.
  • What should be done: As you originally proposed in the issue thread, this must be handled entirely on the VS Code frontend. The webview should use DOM querying to find the code block text, send a postMessage to the extension host (plugins/vscode/src/chat-webview-provider.ts), and then the extension host must use vscode.env.clipboard.writeText(text). Please revert the changes to source/acp/acp-agent.ts and source/commands/copy.ts.

2. Unrelated File Commits

  • What is wrong: The PR includes several unrelated files: .devcontainer/devcontainer-lock.json, .gitignore, badges/forks.svg, and badges/npm-downloads-monthly.svg.
  • What should be done: These look like accidental commits. Please revert these files so the PR only contains changes strictly related to the feature.

3. Test Coverage

  • What is wrong: The PR description states "New features include passing tests in .spec.ts/tsx files", but no test files were actually added or modified in the diff.
  • What should be done: If this is implemented purely in the Webview (which lacks a test harness right now), it's okay to note that it's manually tested. Just uncheck the automated tests box so the PR description accurately reflects the code.

Once the clipboard logic is moved to vscode.env.clipboard.writeText and the unrelated files are dropped, we can get this merged!

@AryanNandanwar

Copy link
Copy Markdown
Author

Thanks for the feedback@akramcodez ! I'll update the PR accordingly

@AryanNandanwar
AryanNandanwar force-pushed the feat/auto-copy-last-code-block-element branch from 048f98a to 0d2ee7d Compare August 8, 2026 13:46
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.

[Feature] Auto-Copy Last Code Block Command

2 participants