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.
- package/package.json +1 -1
- package/scripts/patch-pi.js +30 -12
package/package.json
CHANGED
package/scripts/patch-pi.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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");
|