@reconcrap/boss-recommend-mcp 2.0.49 → 2.0.51

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reconcrap/boss-recommend-mcp",
3
- "version": "2.0.49",
3
+ "version": "2.0.51",
4
4
  "description": "Unified MCP pipeline for recommend-page filtering and screening on Boss Zhipin",
5
5
  "keywords": [
6
6
  "boss",
package/src/cli.js CHANGED
@@ -7,10 +7,10 @@ import { createRequire } from "node:module";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import {
9
9
  assertNoForbiddenCdpCalls,
10
- buildBossChromeLaunchArgs,
11
10
  bringPageToFront,
12
11
  connectToChromeTarget,
13
12
  enableDomains,
13
+ ensureChromeDebugPort,
14
14
  getDocumentRoot,
15
15
  querySelector,
16
16
  sleep as sleepMs
@@ -2209,51 +2209,38 @@ async function launchChrome(options = {}) {
2209
2209
  const port = parsePositivePort(options.port) || parsePositivePort(process.env.BOSS_RECOMMEND_CHROME_PORT) || 9222;
2210
2210
  process.env.BOSS_RECOMMEND_CHROME_PORT = String(port);
2211
2211
  const timing = getLaunchChromeTiming(options);
2212
-
2213
- const initialState = await inspectBossRecommendPageStateCdp(port, {
2214
- timeoutMs: timing.initialTimeoutMs,
2215
- pollMs: timing.pollMs
2216
- });
2217
- if (initialState.state !== "DEBUG_PORT_UNREACHABLE") {
2218
- console.log(`Reusing existing Chrome debug instance on port ${port}`);
2219
- const pageState = await ensureBossRecommendPageReadyCdp(port, {
2220
- attempts: 2,
2221
- inspectTimeoutMs: timing.inspectTimeoutMs,
2222
- pollMs: timing.pollMs,
2223
- settleMs: timing.settleMs
2212
+ const userDataDir = getChromeUserDataDir(port);
2213
+ let chromeGuard = null;
2214
+ try {
2215
+ chromeGuard = await ensureChromeDebugPort({
2216
+ port,
2217
+ url: bossUrl,
2218
+ slowLive: Boolean(options["slow-live"] || options.slowLive),
2219
+ launchIfMissing: true,
2220
+ userDataDir
2224
2221
  });
2225
- if (pageState.ok) {
2226
- console.log("Boss recommend page is ready.");
2227
- const frontResult = await bringBossRecommendTabToFrontCdp(port);
2228
- if (frontResult.ok) {
2229
- console.log(`CDP methods: ${frontResult.method_log.join(", ") || "none"}`);
2230
- }
2231
- } else {
2232
- console.log(pageState.page_state?.message || "Boss recommend page is not ready.");
2222
+ } catch (error) {
2223
+ console.error(error?.message || String(error || "Chrome launch failed"));
2224
+ if (error?.chrome_guard) {
2225
+ console.error(JSON.stringify(error.chrome_guard, null, 2));
2233
2226
  }
2234
- return;
2235
- }
2236
-
2237
- const chromePath = getChromeExecutable();
2238
- if (!chromePath) {
2239
- console.error("Chrome executable not found. Set BOSS_RECOMMEND_CHROME_PATH or install Google Chrome.");
2240
2227
  process.exitCode = 1;
2241
2228
  return;
2242
2229
  }
2243
2230
 
2244
- const userDataDir = getChromeUserDataDir(port);
2245
- const args = buildBossChromeLaunchArgs({ port, userDataDir, url: bossUrl });
2246
- const child = spawn(chromePath, args, {
2247
- detached: true,
2248
- stdio: "ignore",
2249
- windowsHide: false
2250
- });
2251
- child.unref();
2252
- console.log(`Chrome launched with remote debugging port ${port}`);
2253
- console.log(`User data dir: ${userDataDir}`);
2254
- await sleepMs(timing.settleMs + 1200);
2231
+ if (chromeGuard.replaced) {
2232
+ console.log(`Replaced Chrome debug instance on port ${port} because required flags were missing: ${chromeGuard.missing_flags.join(", ")}`);
2233
+ } else if (chromeGuard.launched) {
2234
+ console.log(`Chrome launched with remote debugging port ${port}`);
2235
+ } else {
2236
+ console.log(`Reusing existing Chrome debug instance on port ${port} with required flags`);
2237
+ }
2238
+ console.log(`User data dir: ${chromeGuard.user_data_dir || userDataDir}`);
2239
+ if (chromeGuard.launched || chromeGuard.replaced) {
2240
+ await sleepMs(timing.settleMs + 1200);
2241
+ }
2255
2242
  const pageState = await ensureBossRecommendPageReadyCdp(port, {
2256
- attempts: 6,
2243
+ attempts: chromeGuard.launched || chromeGuard.replaced ? 6 : 2,
2257
2244
  inspectTimeoutMs: timing.inspectTimeoutMs,
2258
2245
  pollMs: timing.pollMs,
2259
2246
  settleMs: timing.settleMs
@@ -2382,15 +2369,30 @@ async function printDoctor(options = {}) {
2382
2369
  const configResolution = getBossScreenConfigResolution(workspaceRoot);
2383
2370
  const calibrationResolution = getFeaturedCalibrationResolutionLocal(workspaceRoot);
2384
2371
  const timing = getLaunchChromeTiming(options);
2372
+ const slowLive = Boolean(options["slow-live"] || options.slowLive);
2373
+ let chromeGuard = null;
2374
+ let chromeGuardError = null;
2375
+ try {
2376
+ chromeGuard = await ensureChromeDebugPort({
2377
+ port,
2378
+ url: bossUrl,
2379
+ slowLive,
2380
+ launchIfMissing: true,
2381
+ userDataDir: getChromeUserDataDir(port)
2382
+ });
2383
+ } catch (error) {
2384
+ chromeGuardError = error;
2385
+ chromeGuard = error?.chrome_guard || null;
2386
+ }
2385
2387
  let pageState = await inspectBossRecommendPageStateCdp(port, {
2386
- timeoutMs: options["slow-live"] || options.slowLive ? timing.initialTimeoutMs : 2000,
2387
- pollMs: options["slow-live"] || options.slowLive ? timing.pollMs : 500
2388
+ timeoutMs: slowLive ? timing.initialTimeoutMs : 2000,
2389
+ pollMs: slowLive ? timing.pollMs : 500
2388
2390
  });
2389
2391
  if (pageState.state === "RECOMMEND_READY") {
2390
2392
  pageState = await verifyRecommendPageStableCdp(port, {
2391
- settleMs: options["slow-live"] || options.slowLive ? timing.settleMs : 800,
2392
- recheckTimeoutMs: options["slow-live"] || options.slowLive ? timing.inspectTimeoutMs : 3000,
2393
- pollMs: options["slow-live"] || options.slowLive ? timing.pollMs : 500
2393
+ settleMs: slowLive ? timing.settleMs : 800,
2394
+ recheckTimeoutMs: slowLive ? timing.inspectTimeoutMs : 3000,
2395
+ pollMs: slowLive ? timing.pollMs : 500
2394
2396
  });
2395
2397
  }
2396
2398
  const resolvedConfigPath = configResolution.resolved_path || configResolution.writable_path;
@@ -2407,6 +2409,28 @@ async function printDoctor(options = {}) {
2407
2409
  ? `检测到配置文件(resolved_path):${resolvedConfigPath}`
2408
2410
  : "用户配置不存在(可通过 `boss-recommend-mcp init-config` 创建模板,或 `boss-recommend-mcp config set` 写入真实值)"
2409
2411
  });
2412
+ const requiredFlags = chromeGuard?.required_flags || [];
2413
+ const missingFlags = chromeGuard?.missing_flags || [];
2414
+ const chromeFlagsOk = Boolean(chromeGuard && !chromeGuardError && chromeGuard.required_flags_ok);
2415
+ checks.push({
2416
+ key: "chrome_required_flags",
2417
+ ok: chromeFlagsOk,
2418
+ path: `http://localhost:${port}`,
2419
+ required_flags: requiredFlags,
2420
+ missing_flags: missingFlags,
2421
+ replaced: Boolean(chromeGuard?.replaced),
2422
+ close_method: chromeGuard?.close_method || null,
2423
+ relaunch: chromeGuard?.relaunch || null,
2424
+ message: chromeFlagsOk
2425
+ ? chromeGuard?.replaced
2426
+ ? `Chrome 调试端口 ${port} 原实例缺少必需 flags,已自动关闭并用正确 flags 重新启动。`
2427
+ : chromeGuard?.launched
2428
+ ? `Chrome 调试端口 ${port} 已用必需 flags 启动。`
2429
+ : `Chrome 调试端口 ${port} 已确认包含必需 flags。`
2430
+ : chromeGuardError
2431
+ ? `Chrome 必需 flags 检查失败:${chromeGuardError.message}`
2432
+ : `Chrome 调试端口 ${port} 未确认包含必需 flags。`
2433
+ });
2410
2434
  checks.push({
2411
2435
  key: "chrome_debug_port",
2412
2436
  ok: pageState.state !== "DEBUG_PORT_UNREACHABLE",