Plan for Clipboard Tool
This document outlines the plan to add a "copy to clipboard" tool to Code Bandit.
1. Recommended Library: clipboardy
After reviewing the available options, the recommended library is clipboardy.
Reasoning:
- Cross-Platform: Works on macOS, Windows, and Linux.
- Actively Maintained: Ensures compatibility and security.
- ESM Support: Aligns with our project's module system.
- Simple API: Provides a straightforward
writeSync method that is easy to integrate.
2. Implementation Steps
The implementation will follow the existing pattern for creating tools in this project using the tool function from @langchain/core/tools.
Step 1: Add Dependency
Add clipboardy as a project dependency.
Step 2: Create Tool File
Create a new file to house the clipboard-related tool: src/ai/tools/clipboard-tools.ts.
Step 3: Implement the Tool
In the new src/ai/tools/clipboard-tools.ts file, define the core function and then wrap it with LangChain's tool utility.
import { tool } from "@langchain/core/tools";
import clipboard from "clipboardy";
import { z } from "zod";
// Define the core function for the tool
function copyToClipboard({ data }: { data: string }): string {
try {
clipboard.writeSync(data);
return "Successfully copied to clipboard.";
} catch (error: any) {
return "ERROR: Tool `copyToClipboard` failed with: " + error.message;
}
}
// Create the LangChain tool
const copyToClipboardTool = tool(copyToClipboard, {
name: "copyToClipboard",
description: "Copies the given text to the system clipboard. Use this when the user wants to copy content for use outside of the terminal.",
schema: z.object({
data: z.string().describe("The text content to copy to the clipboard."),
}),
});
// Export the tool for integration
export { copyToClipboardTool };
Step 4: Integrate the New Tool
Update the tool loader at src/ai/tools/loader.ts to include the new copyToClipboardTool.
// src/ai/tools/loader.ts
// ... other imports
import { copyToClipboardTool } from './clipboard-tools.js';
import { getTools as getCommandExecutionTools } from './command-execution-tools.js';
import { getTools as getFileSystemTools } from './file-system-tools.js';
export function getTools(props: { includeDestructiveTools?: boolean }) {
const fileSystemTools = getFileSystemTools(props);
const commandExecutionTools = getCommandExecutionTools();
return {
...fileSystemTools,
...commandExecutionTools,
copyToClipboard: copyToClipboardTool, // Add the new tool to the exported list
};
}
CLIPBOARD_FEATURE_ANALYSIS.md
CLIPBOARD_IMPLEMENTATION_SUMMARY.md
clipboard-tool-plan.md
GITHUB_ISSUE_CLIPBOARD_TOOL.md
Plan for Clipboard Tool
This document outlines the plan to add a "copy to clipboard" tool to Code Bandit.
1. Recommended Library:
clipboardyAfter reviewing the available options, the recommended library is clipboardy.
Reasoning:
writeSyncmethod that is easy to integrate.2. Implementation Steps
The implementation will follow the existing pattern for creating tools in this project using the
toolfunction from@langchain/core/tools.Step 1: Add Dependency
Add
clipboardyas a project dependency.Step 2: Create Tool File
Create a new file to house the clipboard-related tool:
src/ai/tools/clipboard-tools.ts.Step 3: Implement the Tool
In the new
src/ai/tools/clipboard-tools.tsfile, define the core function and then wrap it with LangChain'stoolutility.Step 4: Integrate the New Tool
Update the tool loader at
src/ai/tools/loader.tsto include the newcopyToClipboardTool.CLIPBOARD_FEATURE_ANALYSIS.md
CLIPBOARD_IMPLEMENTATION_SUMMARY.md
clipboard-tool-plan.md
GITHUB_ISSUE_CLIPBOARD_TOOL.md