@trim21/personal-pi-extensions 0.0.231 → 0.0.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/spawn-agent.ts +17 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.231",
3
+ "version": "0.0.232",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -60,9 +60,11 @@ const MAX_PROGRESS_LINES = 5;
60
60
  * without bash need no bwrap setup (there are no commands to sandbox).
61
61
  * (Workspace write protection is embedded in the opencode write/edit tools.)
62
62
  *
63
- * Claude Code style tools (capitalized names, e.g. `Grep`/`Glob`) map to
64
- * their split claude-code files, so a subagent can enable exactly the search
65
- * tools it declares e.g. `Grep` without `Glob`.
63
+ * Claude Code style tools (capitalized names) map to their claude-code
64
+ * files, so a subagent can enable exactly the tools it declares — e.g. `Grep`
65
+ * without `Glob`. The stateful file tools (`Read`/`Edit`/`Write`) share one
66
+ * implementation file (they share a read-snapshot state); the `--tools`
67
+ * allowlist still exposes only the declared subset.
66
68
  */
67
69
  const TOOL_EXTENSION_OVERRIDES: Record<string, string> = {
68
70
  read: "opencode/read.ts",
@@ -71,6 +73,9 @@ const TOOL_EXTENSION_OVERRIDES: Record<string, string> = {
71
73
  bash: "opencode/bash.ts",
72
74
  Grep: "claude-code/grep.ts",
73
75
  Glob: "claude-code/glob.ts",
76
+ Read: "claude-code/files.ts",
77
+ Edit: "claude-code/files.ts",
78
+ Write: "claude-code/files.ts",
74
79
  };
75
80
 
76
81
  // ── schema ───────────────────────────────────────────────────────────────────
@@ -205,10 +210,17 @@ export function buildSubagentArgs(
205
210
  const tools = agent.tools ?? DEFAULT_TOOLS;
206
211
  // Load the opencode override for each built-in tool the agent declares
207
212
  // (read/edit/write), so the subagent uses the enhanced implementation
208
- // instead of the built-in one.
213
+ // instead of the built-in one. Several tool names can map to the same
214
+ // implementation file (e.g. cc Read/Edit/Write → claude-code/files.ts);
215
+ // loading a file twice would run its extension factory twice and create
216
+ // separate closure states, so each file is loaded at most once.
217
+ const loadedOverrideFiles = new Set<string>();
209
218
  for (const tool of tools) {
210
219
  const ext = TOOL_EXTENSION_OVERRIDES[tool];
211
- if (ext) args.push("-e", extensionPath(ext));
220
+ if (ext && !loadedOverrideFiles.has(ext)) {
221
+ loadedOverrideFiles.add(ext);
222
+ args.push("-e", extensionPath(ext));
223
+ }
212
224
  }
213
225
  args.push("--tools", tools.join(","));
214
226
  if (systemPromptPath) args.push("--append-system-prompt", systemPromptPath);