@bolloon/bolloon-agent 0.1.18 → 0.1.19

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.
@@ -238,25 +238,38 @@ function checkNpmOutdated() {
238
238
  }
239
239
  }
240
240
  /**
241
- * 自动更新 npm 包
241
+ * 自动更新 npm 包 (legacy: 只传包名, 让 npm 按本地 semver 约束判断 — 不可靠)
242
+ * 新代码应使用 updatePackagesWithVersion 并传 name@version
242
243
  */
243
244
  async function updatePackages(packages) {
244
- // 记录更新前的版本,用于事后判断"是否真的升级了"
245
- // 与 getInstalledVersion 的"优先读全局"保持一致 —— install 也用 -g,
246
- // 否则判断和执行落在不同的目录,永远改不到那个被读取的版本号。
247
245
  const targets = packages && packages.length > 0 ? packages : ['@bolloon/bolloon-agent'];
246
+ // 旧 API 没有 version, 加一个空 placeholder 走相同路径
247
+ return updatePackagesWithVersion(targets);
248
+ }
249
+ /**
250
+ * 自动更新 npm 包, 传 `name@version` 形式的目标让 npm install 不被本地
251
+ * package.json 的 semver 约束卡住 (旧版只传 name 时, npm 看到本地
252
+ * package.json 里 "^0.1.17" 已经满足就判 up to date, 永远升不上去)
253
+ */
254
+ async function updatePackagesWithVersion(packagesWithVersion) {
255
+ // 解析 `name@version` 形式, 提取 name 用于 before/after 校验
256
+ const parsed = packagesWithVersion.map(spec => {
257
+ const at = spec.lastIndexOf('@');
258
+ if (at <= 0)
259
+ return { name: spec, version: '' };
260
+ return { name: spec.slice(0, at), version: spec.slice(at + 1) };
261
+ });
262
+ const targets = parsed.map(p => p.name);
248
263
  const before = new Map();
249
264
  for (const p of targets)
250
265
  before.set(p, getInstalledVersion(p));
251
- const isGlobal = !packages || packages.length === 0;
252
- const args = isGlobal
253
- ? ['npm', 'install', '-g', ...targets]
254
- : ['npm', 'install', ...targets, '--save'];
266
+ // targetsWithVersion 直接拼命令 - 包含具体版本号, 不会被本地约束拦截
267
+ const args = ['npm', 'install', '-g', ...packagesWithVersion];
255
268
  log(`\n${CYAN}📦 正在更新包...${RESET}\n`, RESET);
256
269
  try {
257
270
  execSync(args.join(' '), {
258
271
  encoding: 'utf-8',
259
- timeout: 300000, // 5分钟超时
272
+ timeout: 300000,
260
273
  stdio: 'inherit',
261
274
  cwd: process.cwd()
262
275
  });
@@ -269,22 +282,16 @@ async function updatePackages(packages) {
269
282
  error: e.message
270
283
  };
271
284
  }
272
- // install 退出码 0 并不等于"真的升上去了""up to date" 也是 0)。
273
- // 重新读取磁盘版本,只有真的达到目标 latest 之一才算 updated。
285
+ // install 退出码 0 并不等于"真的升上去了" ("up to date" 也是 0)。
286
+ // 重新读取磁盘版本, 只有真的达到 latest 之一才算 updated。
274
287
  const upgraded = [];
275
- const failed = [];
276
- for (const p of targets) {
277
- const after = getInstalledVersion(p);
278
- const was = before.get(p);
288
+ for (const p of parsed) {
289
+ const after = getInstalledVersion(p.name);
290
+ const was = before.get(p.name);
279
291
  if (after && was && compareVersions(was, after) < 0) {
280
- upgraded.push(p);
281
- }
282
- else if (after && was && compareVersions(was, after) === 0) {
283
- // 版本没变 —— install 跑过但没改动;不当作"刚升级"
284
- }
285
- else {
286
- failed.push(p);
292
+ upgraded.push(p.name);
287
293
  }
294
+ // 版本没变 = npm 仍判 up to date; 不当成功
288
295
  }
289
296
  if (upgraded.length > 0) {
290
297
  return {
@@ -322,7 +329,10 @@ export async function checkAndUpdate() {
322
329
  log(` 当前版本: ${bolloonInfo.version}\n`, RESET);
323
330
  log(` 最新版本: ${bolloonInfo.latest}\n\n`, RESET);
324
331
  // 自动更新
325
- const result = await updatePackages(bolloonInfo.packages.map(p => p.name));
332
+ // 关键: 把目标版本号也传过去, 否则 `npm install -g @bolloon/bolloon-agent`
333
+ // 会按本地 package.json 的 "^0.1.17" 约束去判断, 永远装不上去
334
+ const targetsWithVersion = bolloonInfo.packages.map(p => `${p.name}@${p.latest}`);
335
+ const result = await updatePackagesWithVersion(targetsWithVersion);
326
336
  if (result.success) {
327
337
  log(`\n${GREEN}✅ 更新成功!请重新启动应用${RESET}\n`, RESET);
328
338
  // 提示用户重启
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolloon/bolloon-agent",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "type": "module",
5
5
  "description": "P2P AI Document Agent - 全局安装后执行 `bolloon` 启动产品",
6
6
  "main": "dist/cli.js",
@@ -32,7 +32,7 @@
32
32
  "src/constraint-runtime"
33
33
  ],
34
34
  "dependencies": {
35
- "@bolloon/bolloon-agent": "^0.1.18",
35
+ "@bolloon/bolloon-agent": "^0.1.19",
36
36
  "@bolloon/constraint-runtime": "0.1.0",
37
37
  "@chainsafe/libp2p-noise": "^17.0.0",
38
38
  "@chainsafe/libp2p-yamux": "^8.0.1",
@@ -280,27 +280,40 @@ function checkNpmOutdated(): OutdatedPackage[] {
280
280
  }
281
281
 
282
282
  /**
283
- * 自动更新 npm 包
283
+ * 自动更新 npm 包 (legacy: 只传包名, 让 npm 按本地 semver 约束判断 — 不可靠)
284
+ * 新代码应使用 updatePackagesWithVersion 并传 name@version
284
285
  */
285
286
  async function updatePackages(packages?: string[]): Promise<UpdateResult> {
286
- // 记录更新前的版本,用于事后判断"是否真的升级了"
287
- // 与 getInstalledVersion 的"优先读全局"保持一致 —— install 也用 -g,
288
- // 否则判断和执行落在不同的目录,永远改不到那个被读取的版本号。
289
287
  const targets = packages && packages.length > 0 ? packages : ['@bolloon/bolloon-agent'];
288
+ // 旧 API 没有 version, 加一个空 placeholder 走相同路径
289
+ return updatePackagesWithVersion(targets);
290
+ }
291
+
292
+ /**
293
+ * 自动更新 npm 包, 传 `name@version` 形式的目标让 npm install 不被本地
294
+ * package.json 的 semver 约束卡住 (旧版只传 name 时, npm 看到本地
295
+ * package.json 里 "^0.1.17" 已经满足就判 up to date, 永远升不上去)
296
+ */
297
+ async function updatePackagesWithVersion(packagesWithVersion: string[]): Promise<UpdateResult> {
298
+ // 解析 `name@version` 形式, 提取 name 用于 before/after 校验
299
+ const parsed = packagesWithVersion.map(spec => {
300
+ const at = spec.lastIndexOf('@');
301
+ if (at <= 0) return { name: spec, version: '' };
302
+ return { name: spec.slice(0, at), version: spec.slice(at + 1) };
303
+ });
304
+ const targets = parsed.map(p => p.name);
290
305
  const before = new Map<string, string | null>();
291
306
  for (const p of targets) before.set(p, getInstalledVersion(p));
292
307
 
293
- const isGlobal = !packages || packages.length === 0;
294
- const args = isGlobal
295
- ? ['npm', 'install', '-g', ...targets]
296
- : ['npm', 'install', ...targets, '--save'];
308
+ // targetsWithVersion 直接拼命令 - 包含具体版本号, 不会被本地约束拦截
309
+ const args = ['npm', 'install', '-g', ...packagesWithVersion];
297
310
 
298
311
  log(`\n${CYAN}📦 正在更新包...${RESET}\n`, RESET);
299
312
 
300
313
  try {
301
314
  execSync(args.join(' '), {
302
315
  encoding: 'utf-8',
303
- timeout: 300000, // 5分钟超时
316
+ timeout: 300000,
304
317
  stdio: 'inherit',
305
318
  cwd: process.cwd()
306
319
  });
@@ -313,20 +326,16 @@ async function updatePackages(packages?: string[]): Promise<UpdateResult> {
313
326
  };
314
327
  }
315
328
 
316
- // install 退出码 0 并不等于"真的升上去了""up to date" 也是 0)。
317
- // 重新读取磁盘版本,只有真的达到目标 latest 之一才算 updated。
329
+ // install 退出码 0 并不等于"真的升上去了" ("up to date" 也是 0)。
330
+ // 重新读取磁盘版本, 只有真的达到 latest 之一才算 updated。
318
331
  const upgraded: string[] = [];
319
- const failed: string[] = [];
320
- for (const p of targets) {
321
- const after = getInstalledVersion(p);
322
- const was = before.get(p);
332
+ for (const p of parsed) {
333
+ const after = getInstalledVersion(p.name);
334
+ const was = before.get(p.name);
323
335
  if (after && was && compareVersions(was, after) < 0) {
324
- upgraded.push(p);
325
- } else if (after && was && compareVersions(was, after) === 0) {
326
- // 版本没变 —— install 跑过但没改动;不当作"刚升级"
327
- } else {
328
- failed.push(p);
336
+ upgraded.push(p.name);
329
337
  }
338
+ // 版本没变 = npm 仍判 up to date; 不当成功
330
339
  }
331
340
 
332
341
  if (upgraded.length > 0) {
@@ -376,7 +385,10 @@ export async function checkAndUpdate(): Promise<{
376
385
  log(` 最新版本: ${bolloonInfo.latest}\n\n`, RESET);
377
386
 
378
387
  // 自动更新
379
- const result = await updatePackages(bolloonInfo.packages.map(p => p.name));
388
+ // 关键: 把目标版本号也传过去, 否则 `npm install -g @bolloon/bolloon-agent`
389
+ // 会按本地 package.json 的 "^0.1.17" 约束去判断, 永远装不上去
390
+ const targetsWithVersion = bolloonInfo.packages.map(p => `${p.name}@${p.latest}`);
391
+ const result = await updatePackagesWithVersion(targetsWithVersion);
380
392
 
381
393
  if (result.success) {
382
394
  log(`\n${GREEN}✅ 更新成功!请重新启动应用${RESET}\n`, RESET);