@trim21/personal-pi-extensions 0.0.242 → 0.0.243

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.
package/README.md CHANGED
@@ -17,6 +17,14 @@
17
17
  | [question](#question) | opencode 风格的提问工具,阻塞式询问用户选择 |
18
18
  | [talk](#talk) | session 间消息传递,SQLite 邮箱 + 双向 ask 时间戳仲裁 |
19
19
 
20
+ > **两套工具风格,按预期只启用其中一套**:本包同时提供 opencode 风格
21
+ > (小写 `read`/`edit`/`write`/`bash`/`todowrite`/`question`)与 Claude Code
22
+ > 风格(大写 `Read`/`Edit`/`Write`/`Bash`/`Grep`/`Glob`/`TodoWrite`/
23
+ > `AskUserQuestion`)两套工具集,二者共享 bwrap 沙箱与写保护实现。两套同时
24
+ > 启用会带来预期外的冗余:同名命令重复注册(如 `/bwrap` 出现 `/bwrap:1`
25
+ > 后缀)、系统提示重复注入。请只启用其中一套:在 `~/.pi/agent/settings.json`
26
+ > 的 `defaultTools` 中只列出一套,或启动时用 `--exclude-tools` 排除另一套。
27
+
20
28
  ---
21
29
 
22
30
  ## bwrap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.242",
3
+ "version": "0.0.243",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -320,5 +320,3 @@ export class BwrapRuntime {
320
320
  export function createBwrapRuntime(): BwrapRuntime {
321
321
  return new BwrapRuntime();
322
322
  }
323
-
324
- export const bwrapRuntime = createBwrapRuntime();
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
6
 
7
- import { bwrapRuntime } from "../bwrap/runtime.js";
7
+ import { type BwrapRuntime, createBwrapRuntime } from "../bwrap/runtime.js";
8
8
  import { resolveWorkdir } from "../lib/path.js";
9
9
 
10
10
  const DEFAULT_TIMEOUT_MS = 120_000;
@@ -13,8 +13,15 @@ const MAX_TIMEOUT_MS = 600_000;
13
13
  /** Bash tool guidance, kept in markdown so it reads like documentation. */
14
14
  const BASH_PROMPT = readFileSync(fileURLToPath(new URL("bash.md", import.meta.url)), "utf8").trim();
15
15
 
16
- export function registerShellTools(pi: ExtensionAPI): void {
17
- bwrapRuntime.setup(pi);
16
+ /**
17
+ * runtime 由调用方注入:扩展工厂持有一个实例(不依赖模块级全局状态),
18
+ * 测试可注入预置模式的实例。状态随扩展实例生命周期,session 切换重建即重置。
19
+ */
20
+ export function registerShellTools(
21
+ pi: ExtensionAPI,
22
+ runtime: BwrapRuntime = createBwrapRuntime(),
23
+ ): void {
24
+ runtime.setup(pi);
18
25
  pi.registerTool({
19
26
  name: "Bash",
20
27
  promptSnippet: "execute command",
@@ -58,7 +65,7 @@ export function registerShellTools(pi: ExtensionAPI): void {
58
65
  const cwd = params.workdir ? await resolveWorkdir(params.workdir, ctx.cwd) : ctx.cwd;
59
66
 
60
67
  try {
61
- return await bwrapRuntime.execute({
68
+ return await runtime.execute({
62
69
  ctx: { ...ctx, cwd },
63
70
  toolCallId: id,
64
71
  command: params.command,
@@ -1,14 +1,17 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { Type } from "typebox";
3
3
 
4
- import { bwrapRuntime } from "../bwrap/runtime.js";
4
+ import { createBwrapRuntime } from "../bwrap/runtime.js";
5
5
  import { resolveWorkdir } from "../lib/path.js";
6
6
 
7
7
  const DEFAULT_TIMEOUT_MS = 120_000;
8
8
  const MAX_TIMEOUT_MS = 600_000;
9
9
 
10
10
  export default function opencodeBash(pi: ExtensionAPI): void {
11
- bwrapRuntime.setup(pi);
11
+ // 每个扩展实例持有自己的 runtime:不依赖模块级全局状态,状态随扩展
12
+ // 实例生命周期(进程启动 / /reload / session 切换时工厂重建即重置)。
13
+ const runtime = createBwrapRuntime();
14
+ runtime.setup(pi);
12
15
  pi.registerTool({
13
16
  name: "bash",
14
17
  label: "bash",
@@ -52,7 +55,7 @@ export default function opencodeBash(pi: ExtensionAPI): void {
52
55
  const cwd = params.workdir ? await resolveWorkdir(params.workdir, ctx.cwd) : ctx.cwd;
53
56
 
54
57
  try {
55
- return await bwrapRuntime.execute({
58
+ return await runtime.execute({
56
59
  ctx: { ...ctx, cwd },
57
60
  toolCallId: id,
58
61
  command: params.command,
@@ -54,9 +54,9 @@ const MAX_PROGRESS_LINES = 5;
54
54
  * built-in tool, the matching opencode extension is loaded via `-e` so the
55
55
  * subagent uses the enhanced implementation instead of the built-in one.
56
56
  *
57
- * The bash override also carries the bwrap sandbox: opencode/bash.ts calls
58
- * bwrapRuntime.setup() and runs commands through bwrapRuntime.execute(), so
59
- * agents that declare the bash tool get sandboxing automatically. Agents
57
+ * The bash override also carries the bwrap sandbox: opencode/bash.ts creates
58
+ * its own bwrap runtime instance and runs commands through runtime.execute(),
59
+ * so agents that declare the bash tool get sandboxing automatically. Agents
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
  *