@yeaft/webchat-agent 0.0.135 → 0.0.137

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 (3) hide show
  1. package/connection.js +27 -12
  2. package/crew.js +11 -33
  3. package/package.json +1 -1
package/connection.js CHANGED
@@ -420,7 +420,10 @@ async function handleMessage(msg) {
420
420
  const pid = process.pid;
421
421
  const configDir = getConfigDir();
422
422
  mkdirSync(configDir, { recursive: true });
423
+ const logDir = join(configDir, 'logs');
424
+ mkdirSync(logDir, { recursive: true });
423
425
  const batPath = join(configDir, 'upgrade.bat');
426
+ const logPath = join(logDir, 'upgrade.log');
424
427
  const isPm2 = !!process.env.pm_id;
425
428
  const installDirWin = installDir.replace(/\//g, '\\');
426
429
 
@@ -430,14 +433,18 @@ async function handleMessage(msg) {
430
433
  `set PID=${pid}`,
431
434
  `set PKG=${pkgName}@latest`,
432
435
  `set INSTALL_DIR=${installDirWin}`,
436
+ `set LOGFILE=${logPath}`,
433
437
  `set MAX_WAIT=30`,
434
438
  `set COUNT=0`,
439
+ '',
440
+ ':: Redirect all output to log file',
441
+ 'echo [Upgrade] Started at %date% %time% > "%LOGFILE%"',
435
442
  ':WAIT_LOOP',
436
443
  'tasklist /FI "PID eq %PID%" 2>NUL | find /I "%PID%" >NUL',
437
444
  'if errorlevel 1 goto PID_EXITED',
438
445
  'set /A COUNT+=1',
439
446
  'if %COUNT% GEQ %MAX_WAIT% (',
440
- ' echo [Upgrade] Timeout waiting for PID %PID% to exit after 60s',
447
+ ' echo [Upgrade] Timeout waiting for PID %PID% to exit after 60s >> "%LOGFILE%"',
441
448
  ' goto PID_EXITED',
442
449
  ')',
443
450
  'timeout /T 2 /NOBREAK >NUL',
@@ -446,10 +453,10 @@ async function handleMessage(msg) {
446
453
  ];
447
454
 
448
455
  if (isPm2) {
449
- // pm2 可能已自动重启旧代码(exit 1 触发),先 stop 释放文件锁
456
+ // pm2 可能已自动重启旧代码(exit 触发),先 stop 释放文件锁
450
457
  batLines.push(
451
- 'echo [Upgrade] Stopping pm2 agent to release file locks...',
452
- 'call pm2 stop yeaft-agent 2>NUL',
458
+ 'echo [Upgrade] Stopping pm2 agent to release file locks... >> "%LOGFILE%"',
459
+ 'call pm2 stop yeaft-agent >> "%LOGFILE%" 2>&1',
453
460
  'timeout /T 3 /NOBREAK >NUL',
454
461
  );
455
462
  }
@@ -459,23 +466,26 @@ async function handleMessage(msg) {
459
466
  : 'cd /d "%INSTALL_DIR%" && call npm install %PKG%';
460
467
 
461
468
  batLines.push(
462
- 'echo [Upgrade] Installing %PKG%...',
463
- npmBatCmd,
469
+ 'echo [Upgrade] Installing %PKG%... >> "%LOGFILE%"',
470
+ `${npmBatCmd} >> "%LOGFILE%" 2>&1`,
464
471
  'if errorlevel 1 (',
465
- ' echo [Upgrade] npm install failed with exit code %errorlevel%',
466
- ') else (',
467
- ' echo [Upgrade] Successfully installed %PKG%',
472
+ ' echo [Upgrade] npm install failed with exit code %errorlevel% >> "%LOGFILE%"',
473
+ ' goto CLEANUP',
468
474
  ')',
475
+ 'echo [Upgrade] Successfully installed %PKG% >> "%LOGFILE%"',
469
476
  );
470
477
 
471
478
  if (isPm2) {
472
479
  batLines.push(
473
- 'echo [Upgrade] Starting agent via pm2...',
474
- 'call pm2 start yeaft-agent',
480
+ 'echo [Upgrade] Starting agent via pm2... >> "%LOGFILE%"',
481
+ 'call pm2 start yeaft-agent >> "%LOGFILE%" 2>&1',
475
482
  );
476
483
  }
477
484
 
478
- batLines.push(`del /F /Q "${batPath}"`);
485
+ batLines.push(
486
+ ':CLEANUP',
487
+ `del /F /Q "${batPath}"`,
488
+ );
479
489
 
480
490
  writeFileSync(batPath, batLines.join('\r\n'));
481
491
  const child = spawn('cmd.exe', ['/c', batPath], {
@@ -486,6 +496,11 @@ async function handleMessage(msg) {
486
496
  child.unref();
487
497
  console.log(`[Agent] Spawned upgrade script (PID wait for ${pid}, pm2=${isPm2}, dir=${installDir}): ${batPath}`);
488
498
  sendToServer({ type: 'upgrade_agent_ack', success: true, version: latestVersion, pendingRestart: true });
499
+
500
+ if (isPm2) {
501
+ // PM2 环境:先同步 pm2 stop 防止 autorestart 竞态,再 exit
502
+ try { execSync('pm2 stop yeaft-agent', { timeout: 5000 }); } catch {}
503
+ }
489
504
  } else {
490
505
  // Linux/macOS: 生成 detached shell 脚本,先停止服务再升级再启动
491
506
  // 避免在升级过程中 systemd 不断重启已删除的旧版本
package/crew.js CHANGED
@@ -1567,25 +1567,6 @@ export async function handleCrewHumanInput(msg) {
1567
1567
  }
1568
1568
 
1569
1569
  if (target) {
1570
- // 检查目标角色是否正在忙
1571
- const targetState = session.roleStates.get(target);
1572
- if (targetState?.turnActive) {
1573
- if (msg.interrupt) {
1574
- // 中断模式:立即打断角色
1575
- await interruptRole(session, target, buildHumanContent('人工消息(中断):', message), 'human');
1576
- } else {
1577
- // 排队
1578
- session.humanMessageQueue.push({ target, content: message, timestamp: Date.now() });
1579
- console.log(`[Crew] Human message queued for ${target} (busy)`);
1580
- sendCrewMessage({
1581
- type: 'crew_message_queued',
1582
- sessionId: session.id,
1583
- target,
1584
- queueLength: session.humanMessageQueue.filter(m => m.target === target).length
1585
- });
1586
- }
1587
- return;
1588
- }
1589
1570
  await dispatchToRole(session, target, buildHumanContent('人工消息:', message), 'human');
1590
1571
  return;
1591
1572
  }
@@ -1594,20 +1575,6 @@ export async function handleCrewHumanInput(msg) {
1594
1575
  // 没有 @ 指定目标,默认发给决策者(PM)
1595
1576
  const target = targetRole || session.decisionMaker;
1596
1577
 
1597
- // 检查目标是否忙
1598
- const targetState = session.roleStates.get(target);
1599
- if (targetState?.turnActive) {
1600
- session.humanMessageQueue.push({ target, content, timestamp: Date.now() });
1601
- console.log(`[Crew] Human message queued for ${target} (busy)`);
1602
- sendCrewMessage({
1603
- type: 'crew_message_queued',
1604
- sessionId: session.id,
1605
- target,
1606
- queueLength: session.humanMessageQueue.filter(m => m.target === target).length
1607
- });
1608
- return;
1609
- }
1610
-
1611
1578
  await dispatchToRole(session, target, buildHumanContent('人工消息:', content), 'human');
1612
1579
  }
1613
1580
 
@@ -1976,11 +1943,22 @@ function sendCrewOutput(session, roleName, outputType, rawMessage, extra = {}) {
1976
1943
  if (Array.isArray(content)) {
1977
1944
  for (const block of content) {
1978
1945
  if (block.type === 'tool_use') {
1946
+ // Save trimmed toolInput for restore — only key fields, skip large content
1947
+ const input = block.input || {};
1948
+ const trimmedInput = {};
1949
+ if (input.file_path) trimmedInput.file_path = input.file_path;
1950
+ if (input.command) trimmedInput.command = input.command.substring(0, 200);
1951
+ if (input.pattern) trimmedInput.pattern = input.pattern;
1952
+ if (input.old_string) trimmedInput.old_string = input.old_string.substring(0, 100);
1953
+ if (input.new_string) trimmedInput.new_string = input.new_string.substring(0, 100);
1954
+ if (input.url) trimmedInput.url = input.url;
1955
+ if (input.query) trimmedInput.query = input.query;
1979
1956
  session.uiMessages.push({
1980
1957
  role: roleName, roleIcon, roleName: displayName,
1981
1958
  type: 'tool',
1982
1959
  toolName: block.name,
1983
1960
  toolId: block.id,
1961
+ toolInput: Object.keys(trimmedInput).length > 0 ? trimmedInput : null,
1984
1962
  content: `${block.name} ${block.input?.file_path || block.input?.command?.substring(0, 60) || ''}`,
1985
1963
  hasResult: false,
1986
1964
  taskId, taskTitle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",