@trim21/personal-pi-extensions 0.1.527 → 0.1.528

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/bwrap/core.ts +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.527",
3
+ "version": "0.1.528",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
package/src/bwrap/core.ts CHANGED
@@ -2,6 +2,7 @@ import { type ChildProcess, spawn } from "node:child_process";
2
2
  import { constants, type Dirent, existsSync, readFileSync } from "node:fs";
3
3
  import { access as fsAccess, readdir, realpath, stat } from "node:fs/promises";
4
4
  import { delimiter, join } from "node:path";
5
+ import process from "node:process";
5
6
  import { fileURLToPath } from "node:url";
6
7
 
7
8
  import { StringEnum } from "@earendil-works/pi-ai";
@@ -353,6 +354,15 @@ async function realpathOrSelf(path: string): Promise<string> {
353
354
 
354
355
  export async function buildBwrapArgs(resolved: ResolvedBwrap, cwd: string): Promise<string[]> {
355
356
  const args = ["--new-session", "--die-with-parent", "--unshare-user", "--unshare-pid"];
357
+ // 沙箱进程以调用方(pi)的 uid/gid 运行,而不是 userns 里的 0。
358
+ // net-allowlist 模式下命令先经 nsenter 进入 holder 的 userns(unshare -r 把 pi 的 uid 映射成 0),
359
+ // bwrap 默认继承该 uid 会让沙箱内 id/stat 自称 root、与宿主视角不一致;
360
+ // 直接模式(无 holder)下这两个值本就等于 bwrap 的 real uid,等价于默认行为。
361
+ const uid = process.getuid?.();
362
+ const gid = process.getgid?.();
363
+ if (uid !== undefined && gid !== undefined) {
364
+ args.push("--uid", String(uid), "--gid", String(gid));
365
+ }
356
366
  // --*-bind-try:配置的路径不存在时忽略该项而不是让整条命令失败
357
367
  for (const path of resolved.writablePaths) {
358
368
  const absolutePath = await realpathOrSelf(resolveBwrapPath(path, cwd));