@hupan56/wlkj 2.7.0 → 2.7.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.
Files changed (2) hide show
  1. package/bin/cli.js +18 -10
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -58,24 +58,32 @@ function py(script, args = []) {
58
58
  //
59
59
  // 优先: 引擎已装 → 调 common.pip_install (有镜像兜底)
60
60
  // 回退: 引擎没装 → 裸 pip install (install-env 首次场景, 无 Python 工具可用)
61
+ //
62
+ // 实现注意 (修 2.7.0 的真 bug): 不能用字符串拼接构造 Python -c 代码 ——
63
+ // Windows 路径含反斜杠, 拼进 Python 字符串后 \Y \n 等成了非法转义 + 引号丢失,
64
+ // 导致 SyntaxError → 镜像兜底静默失败 → 回退裸 pip → 弱网用户全崩。
65
+ // 改用环境变量传参 (WLKJ_REQ_PATH), Python 侧 os.environ 读, 彻底避开转义地狱。
61
66
  function installPipDeps(pyCmd, reqPath) {
62
67
  const scriptsDir = path.join(process.cwd(), ".qoder", "scripts");
63
68
  const hasTool = fs.existsSync(path.join(scriptsDir, "common", "pip_install.py"));
64
69
  if (hasTool) {
65
- // Python 工具: install_with_fallback(['-r', reqPath]) → 输出结果
70
+ // 用环境变量传 requirements 路径, Python os.environ 读 (跨平台无转义问题)
66
71
  const prog = [
67
- "import sys; sys.path.insert(0, '" + scriptsDir.replace(/\\/g, "\\\\") + "')",
72
+ "import sys, os, json",
73
+ "sys.path.insert(0, os.environ['WLKJ_SCRIPTS_DIR'])",
68
74
  "from common.pip_install import install_with_fallback",
69
- "import json",
70
- "r = install_with_fallback(['-r', " + JSON.stringify(reqPath) + "])",
71
- "print(json.dumps(r, ensure_ascii=False))",
75
+ "r = install_with_fallback(['-r', os.environ['WLKJ_REQ_PATH']])",
76
+ "print('WLKJ_RESULT=' + json.dumps(r, ensure_ascii=False))",
72
77
  ].join("; ");
73
78
  try {
74
- const out = execSync(`${pyCmd} -c "${prog}"`, { encoding: "utf-8", timeout: 600000 });
75
- // 最后一行是 JSON 结果
76
- const lines = out.trim().split("\n");
77
- const jsonLine = lines[lines.length - 1];
78
- const result = JSON.parse(jsonLine);
79
+ const out = execSync(`${pyCmd} -c "${prog}"`, {
80
+ encoding: "utf-8", timeout: 600000,
81
+ env: { ...process.env, WLKJ_SCRIPTS_DIR: scriptsDir, WLKJ_REQ_PATH: reqPath },
82
+ });
83
+ // WLKJ_RESULT= 那行 (避免被 pip 输出干扰)
84
+ const resultLine = out.split("\n").find(l => l.startsWith("WLKJ_RESULT="));
85
+ if (!resultLine) throw new Error("Python 工具无结果输出");
86
+ const result = JSON.parse(resultLine.slice("WLKJ_RESULT=".length));
79
87
  if (result.ok) {
80
88
  console.log(` [OK] Python 依赖已装` + (result.source && result.source !== "default" ? ` (镜像源: ${result.source})` : ""));
81
89
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hupan56/wlkj",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "AI Product R&D Workflow - PRD/Prototype/Search/Task/Report",
5
5
  "bin": {
6
6
  "wlkj": "bin/cli.js"