@whyshu/argent 0.1.18 → 0.1.20

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/lib/index.mjs +31 -4
  2. package/package.json +2 -2
package/lib/index.mjs CHANGED
@@ -8,11 +8,12 @@
8
8
  * · 状态自检(版本/profile/runner 配置/端口)。
9
9
  * ⛔ 不读写任何凭据内容(runner.json 由首跑引导写,权限 600)。
10
10
  */
11
- import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, cpSync, readdirSync } from 'node:fs';
11
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, cpSync, readdirSync, chmodSync } from 'node:fs';
12
12
  import { spawnSync } from 'node:child_process';
13
13
  import { homedir, hostname as osHostname } from 'node:os';
14
14
  import { dirname, join, resolve } from 'node:path';
15
15
  import { fileURLToPath } from 'node:url';
16
+ import { createRequire } from 'node:module';
16
17
 
17
18
  export const DSH_EXACT_VERSION = '0.2.1-rc.2';
18
19
  export const PROFILE_NAME = 'argent';
@@ -86,18 +87,41 @@ export const PUBLISHED_BUNDLE_VERSIONS = {
86
87
  };
87
88
 
88
89
 
89
- /** 发布模式随启动器安装的 runtime(@whyshu/argent-engine)根目录;本地联调回退 dist。 */
90
+ /**
91
+ * 发布模式随启动器安装的 runtime(@whyshu/argent-engine)根目录;本地联调回退 dist。
92
+ *
93
+ * ⚠️ 2026-10-30 事故(客户机 0.1.18):npm 11 **没有把引擎提升到顶层**,而是嵌套在
94
+ * `<prefix>/node_modules/@whyshu/argent/node_modules/@whyshu/argent-engine/`。
95
+ * 旧实现只探测"提升后"的 4 个固定路径 ⇒ `argent runtime install` 直接 exit 2,
96
+ * 客户机升级链路第一步就断(rc.5 的日报定时器脚本落不了地)。
97
+ *
98
+ * 修法:**先用模块解析**(`require.resolve`,提升/嵌套/符号链接/pnpm 布局都天然命中),
99
+ * 再保留显式候选(含"嵌套在启动器自己的 node_modules")作为兜底。
100
+ * 两者都按同一判据校验(`engine/scripts` + `engine/VERSION`),⛔ 不靠"目录看起来像"。
101
+ */
90
102
  export function engineRoot({ env = process.env, launcherLib = dirname(fileURLToPath(import.meta.url)) } = {}) {
91
103
  const candidates = [];
92
104
  if (env.ARGENT_ENGINE_ROOT) candidates.push(resolve(env.ARGENT_ENGINE_ROOT));
93
- // npx/global 安装:node_modules/@whyshu/argent-engine/engine
105
+ // ① 模块解析(最可靠):以 launcher/lib 为锚,让 Node 自己按 npm 布局找包
106
+ try {
107
+ const req = createRequire(join(launcherLib, 'index.mjs'));
108
+ const pkgJson = req.resolve('@whyshu/argent-engine/package.json');
109
+ candidates.push(join(dirname(pkgJson), 'engine'));
110
+ } catch { /* 引擎未装/不可解析 ⇒ 继续用显式候选 */ }
111
+ // ② 显式候选(提升布局 / 嵌套在启动器自己 node_modules / 本地联调 dist)
94
112
  candidates.push(resolve(launcherLib, '..', '..', '..', '@whyshu', 'argent-engine', 'engine'));
113
+ candidates.push(resolve(launcherLib, '..', 'node_modules', '@whyshu', 'argent-engine', 'engine'));
95
114
  candidates.push(resolve(launcherLib, '..', '..', 'node_modules', '@whyshu', 'argent-engine', 'engine'));
96
- // 本地仓库联调:dist/argent-engine/engine
97
115
  candidates.push(resolve(launcherLib, '..', '..', 'dist', 'argent-engine', 'engine'));
98
116
  for (const c of candidates) {
99
117
  if (existsSync(join(c, 'scripts')) && existsSync(join(c, 'VERSION'))) return c;
100
118
  }
119
+ // 找不到时给出可执行的诊断(别再让客户只看到一句"请用新版启动器")
120
+ if (env.ARGENT_ENGINE_ROOT) {
121
+ console.error(`[engineRoot] ARGENT_ENGINE_ROOT=${env.ARGENT_ENGINE_ROOT} 不是有效的引擎根(需含 scripts/ 与 VERSION)`)
122
+ }
123
+ console.error(`[engineRoot] 已尝试 ${candidates.length} 个位置(模块解析 + 显式路径)均未命中;`
124
+ + '可执行 `npm ls -g @whyshu/argent-engine --all` 看真实布局,或用 ARGENT_ENGINE_ROOT 显式指定')
101
125
  return '';
102
126
  }
103
127
 
@@ -133,6 +157,9 @@ export function materializeRuntime({ target = join(homedir(), '.argent-dsh'), en
133
157
  }
134
158
  mkdirSync(dirname(dst), { recursive: true });
135
159
  cpSync(src, dst);
160
+ // 2026-10-30:引擎 tgz 里 .sh 曾是 0644(打包器丢了执行位)⇒ 落地后不可执行。
161
+ // 包侧已修;这里再做一次落地归一,保证**旧包**装出来的 runtime 也能跑(幂等,不改内容)。
162
+ if (rel.endsWith('.sh')) { try { chmodSync(dst, (statSync(dst).mode & 0o777) | 0o111) } catch { /* noop */ } }
136
163
  copied += 1;
137
164
  };
138
165
  for (const rel of files) copyFile(join(engine, rel), join(target, rel), rel);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyshu/argent",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Argent 启动器:一条命令启动「打包好的 dsh + Argent 插件/角色预设」,并管理本机 runner 常驻。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@deepseek-ai/dsh": "0.2.1-rc.2",
18
- "@whyshu/argent-engine": "0.8.0-rc.5"
18
+ "@whyshu/argent-engine": "0.8.0-rc.6"
19
19
  },
20
20
  "files": [
21
21
  "bin/",