Created
April 24, 2026 20:05
-
-
Save paul-english/92dfcfba28d297097686b8ad64a1e330 to your computer and use it in GitHub Desktop.
UV plugin for opencode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ~/.opencode/plugins/uv-enforcer.ts | |
| import type { Plugin } from "@opencode-ai/plugin" | |
| function rewrite(cmd: string): string { | |
| return cmd | |
| .replace(/^\s*pip3?\s+install\s+(.+)$/m, "uv add $1") | |
| .replace(/^\s*python3?\s+(-m\s+.+)$/m, "uv run python $1") | |
| .replace(/^\s*python3?\s+(.+\.py(?:\s+.*)?)$/m, "uv run python $1") | |
| .replace(/^\s*pytest(\s|$)/m, "uv run pytest$1") | |
| } | |
| export const UvEnforcer: Plugin = async () => { | |
| return { | |
| "tool.execute.before": async (input, output) => { | |
| if (input.tool !== "bash") return | |
| const original = output.args.command | |
| const rewritten = rewrite(original) | |
| if (rewritten !== original) { | |
| output.args.command = rewritten | |
| } | |
| }, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment