Commit 4fa2b6146080

Vincent Demeester <vincent@sbr.pm>
2026-02-17 22:07:21
revert: restored uv.ts extension for Python tooling enforcement
Reverted commit 0a97b73bc3e6 which removed the problematic uv.ts extension. The extension redirects Python tooling commands (pip, poetry, pipenv, virtualenv, conda) to uv equivalents by prepending intercepted-commands to PATH. Intercepted commands remain in place and functional.
1 parent 4423b3e
Changed files (1)
dots
pi
agent
extensions
dots/pi/agent/extensions/uv.ts
@@ -0,0 +1,39 @@
+/**
+ * UV Extension - Redirects Python tooling to uv equivalents
+ *
+ * This extension wraps the bash tool to prepend intercepted-commands to PATH,
+ * which contains shim scripts that intercept common Python tooling commands
+ * and redirect agents to use uv instead.
+ *
+ * Intercepted commands:
+ * - pip/pip3: Blocked with suggestions to use `uv add` or `uv run --with`
+ * - poetry: Blocked with uv equivalents (uv init, uv add, uv sync, uv run)
+ * - pipenv: Blocked with uv equivalents
+ * - virtualenv: Blocked with suggestion to use `uv venv`
+ * - conda: Blocked with uv equivalents (for Python package management)
+ * - python/python3: Redirected to `uv run python`, with special handling to
+ *   block `python -m pip` and `python -m venv`
+ *
+ * Based on mitsuhiko/agent-stuff uv.ts, enhanced with additional interceptors.
+ */
+
+import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
+import { createBashTool } from "@mariozechner/pi-coding-agent";
+import { dirname, join } from "path";
+import { fileURLToPath } from "url";
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const interceptedCommandsPath = join(__dirname, "intercepted-commands");
+
+export default function (pi: ExtensionAPI) {
+  const cwd = process.cwd();
+  const bashTool = createBashTool(cwd, {
+    commandPrefix: `export PATH="${interceptedCommandsPath}:$PATH"`,
+  });
+
+  pi.on("session_start", (_event, ctx) => {
+    ctx.ui.notify("UV interceptor active (pip/poetry/pipenv/virtualenv/conda → uv)", "info");
+  });
+
+  pi.registerTool(bashTool);
+}