@trim21/personal-pi-extensions 0.1.441 → 0.1.443

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.441",
3
+ "version": "0.1.443",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -24,6 +24,7 @@
24
24
  "test": "vitest run",
25
25
  "test:coverage": "vitest run --coverage",
26
26
  "sandbox": "tsx bin/sandbox.ts",
27
+ "build:holder": "esbuild src/bwrap/holder.ts --format=esm --target=node24 --outfile=src/bwrap/holder.js",
27
28
  "prepare": "husky"
28
29
  },
29
30
  "peerDependencies": {
@@ -42,6 +43,7 @@
42
43
  "@types/turndown": "^5.0.6",
43
44
  "@typescript/native": "npm:typescript@^7.0.2",
44
45
  "@vitest/coverage-v8": "^4.1.10",
46
+ "esbuild": "^0.28.2",
45
47
  "eslint": "^10.8.1",
46
48
  "eslint-config-prettier": "10.1.8",
47
49
  "eslint-plugin-erasable-syntax-only": "0.7.1",
@@ -0,0 +1,47 @@
1
+ import { spawn } from "node:child_process";
2
+ import { dirname } from "node:path";
3
+ import { setTimeout as sleep } from "node:timers/promises";
4
+ const args = process.argv.slice(2);
5
+ const configPath = args[0];
6
+ const mihomoPath = args[1];
7
+ if (!configPath || !mihomoPath) {
8
+ process.exit(2);
9
+ }
10
+ function tap0Exists() {
11
+ return new Promise((resolve) => {
12
+ const child = spawn("ip", ["link", "show", "tap0"], { stdio: "ignore" });
13
+ child.once("exit", (code) => resolve(code === 0));
14
+ child.once("error", () => resolve(false));
15
+ });
16
+ }
17
+ async function waitFor(attempts, delayMs, predicate) {
18
+ for (let i = 0; i < attempts; i++) {
19
+ if (await predicate()) return true;
20
+ await sleep(delayMs);
21
+ }
22
+ return false;
23
+ }
24
+ async function main() {
25
+ await waitFor(100, 100, tap0Exists);
26
+ const mihomo = spawn(mihomoPath, ["-d", dirname(configPath), "-f", configPath], {
27
+ stdio: ["ignore", "inherit", "inherit"]
28
+ });
29
+ const stop = () => {
30
+ mihomo.kill("SIGTERM");
31
+ };
32
+ process.on("SIGTERM", () => {
33
+ stop();
34
+ process.exit(0);
35
+ });
36
+ process.on("SIGINT", () => {
37
+ stop();
38
+ process.exit(0);
39
+ });
40
+ await new Promise((resolve) => mihomo.once("exit", () => resolve()));
41
+ }
42
+ try {
43
+ await main();
44
+ } catch (error) {
45
+ console.error(error);
46
+ process.exit(1);
47
+ }
@@ -44,7 +44,9 @@ export interface NetworkStackExecOptions {
44
44
  }
45
45
 
46
46
  const NAMESERVER_PATTERN = /^\s*nameserver\s+(\S+)/;
47
- const HOLDER_PATH = fileURLToPath(new URL("holder.ts", import.meta.url));
47
+ // 构建产物 holder.js(esbuild 编译):node 对 node_modules 下的 .ts 拒绝 type stripping,
48
+ // 扩展从 npm 包加载时 holder.ts 落在 node_modules 下,直接运行会 ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING
49
+ const HOLDER_PATH = fileURLToPath(new URL("holder.js", import.meta.url));
48
50
  // ip 通常位于 /usr/sbin 或 /sbin,进程默认 PATH 不含它们;node 则依赖宿主完整 PATH
49
51
  const SBIN_PATH_SUFFIX = "/usr/local/sbin:/usr/sbin:/sbin";
50
52