@zhushanwen/pi-subagent-cli 0.1.1

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.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ // bin/pi-subagent-cli.mjs
3
+ //
4
+ // pi 引擎 CLI 入口(manifest bin)。加载顺序 dist-first(MF-5 修复,约束 C-proc-11):
5
+ // 1. dist/main.js —— tsup 产物(pnpm build / CI 构建段产出)。npm 发布形态
6
+ // (publishConfig + files 双形态约定,同 subagent-core D4)恒走这里;
7
+ // 2. src/main.ts —— 仅 workspace 开发形态回退:pnpm symlink 的 realpath 在
8
+ // node_modules 外,node ≥23.6 原生 type-stripping 可加载 .ts。npm 安装形态
9
+ // realpath 在 node_modules 内,Node 拒绝对其做 type-stripping——回退必然
10
+ // 失败,故该分支以 node_modules 路径段判据禁用,dist 缺失时输出可操作错误
11
+ // (发现面 canExecute 只查 X_OK 位、派发期才真正加载本文件,坏形态必须在
12
+ // 入口显式失败,不允许静默走入注定炸的分支)。
13
+
14
+ import { existsSync } from "node:fs";
15
+ import { dirname, join } from "node:path";
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+
18
+ const here = dirname(fileURLToPath(import.meta.url));
19
+ const distEntry = join(here, "../dist/main.js");
20
+ const srcEntry = join(here, "../src/main.ts");
21
+
22
+ // dynamic import 只接受 URL:裸绝对路径在 Windows(盘符 `C:\...` 被解析成协议)
23
+ // 报 ERR_UNSUPPORTED_ESM_URL_SCHEME,必须经 pathToFileURL 转 file:/// URL。
24
+ if (existsSync(distEntry)) {
25
+ await import(pathToFileURL(distEntry).href);
26
+ } else if (existsSync(srcEntry) && !here.split(/[\\/]/).includes("node_modules")) {
27
+ await import(pathToFileURL(srcEntry).href);
28
+ } else {
29
+ console.error(
30
+ [
31
+ `[pi-subagent-cli] engine entry not found: ${distEntry}`,
32
+ "",
33
+ "The installed package is missing its dist/ build output — a packaging",
34
+ "defect of the installed version, not a local setup issue. Fix:",
35
+ " - npm install: reinstall a healthy published version",
36
+ " (npm i @zhushanwen/pi-subagent-cli@latest)",
37
+ " - workspace checkout: pnpm --filter @zhushanwen/pi-subagent-cli build",
38
+ ].join("\n"),
39
+ );
40
+ process.exit(1);
41
+ }