u1s1-cli 0.16.1 → 0.16.2

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/scripts/patch-pi.js +30 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u1s1-cli",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "u1s1 — 有一说一,最省心的 AI 编程搭子。终端里用中文说需求,AI 帮你读文件、改代码、跑命令。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,22 +11,36 @@
11
11
  * - 永不让安装失败:任何异常只提示,exit 0
12
12
  */
13
13
 
14
- import { readFileSync, writeFileSync } from "node:fs";
14
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
15
15
  import { join, dirname } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
+ import { createRequire } from "node:module";
17
18
 
18
19
  const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
19
- const target = join(
20
- pkgRoot,
21
- "node_modules",
22
- "@earendil-works",
23
- "pi-coding-agent",
24
- "dist",
25
- "modes",
26
- "interactive",
27
- "components",
28
- "assistant-message.js",
29
- );
20
+
21
+ // npm 会把依赖提升到上层 node_modules(全局安装尤其如此),
22
+ // 所以用模块解析算法定位 pi,而不是拼固定相对路径
23
+ function findPiDir() {
24
+ try {
25
+ const req = createRequire(join(pkgRoot, "package.json"));
26
+ return dirname(req.resolve("@earendil-works/pi-coding-agent/package.json"));
27
+ } catch {
28
+ // 兜底:从包根逐级向上找
29
+ let dir = pkgRoot;
30
+ while (true) {
31
+ const candidate = join(dir, "node_modules", "@earendil-works", "pi-coding-agent");
32
+ if (existsSync(candidate)) return candidate;
33
+ const parent = dirname(dir);
34
+ if (parent === dir) return null;
35
+ dir = parent;
36
+ }
37
+ }
38
+ }
39
+
40
+ const piDir = findPiDir();
41
+ const target = piDir
42
+ ? join(piDir, "dist", "modes", "interactive", "components", "assistant-message.js")
43
+ : null;
30
44
 
31
45
  // 每条 [原文, 替换后];与 patches/@earendil-works__pi-coding-agent@0.84.2.patch 等效
32
46
  const REPLACEMENTS = [
@@ -48,6 +62,10 @@ const REPLACEMENTS = [
48
62
  ];
49
63
 
50
64
  try {
65
+ if (!target) {
66
+ console.log("[u1s1] 提示: 未找到 @earendil-works/pi-coding-agent,精简 UI 空行补丁未应用(不影响使用)");
67
+ process.exit(0);
68
+ }
51
69
  let text;
52
70
  try {
53
71
  text = readFileSync(target, "utf8");