@yeaft/webchat-agent 1.0.46 → 1.0.48

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.
@@ -377,6 +377,17 @@ function spawnWindowsUpgradeScript(pkgName, installDir, isGlobalInstall, latestV
377
377
  * (`getServiceName` / `getLaunchdPlistPath`), so a named instance restarts
378
378
  * `yeaft-agent@<id>` instead of the bare `yeaft-agent` default.
379
379
  *
380
+ * On systemd the script pins XDG_RUNTIME_DIR / DBUS_SESSION_BUS_ADDRESS (the
381
+ * detached upgrade shell may not inherit them, and `systemctl --user` needs
382
+ * them to reach the user manager) and logs + retries a failed restart instead
383
+ * of failing silently.
384
+ *
385
+ * The env-pin is systemd-specific: launchd reaches its manager via the
386
+ * inherited Mach bootstrap port and PM2 via a fixed named pipe, so neither
387
+ * needs these vars. NOTE this is only about the *env* asymmetry — the launchd
388
+ * branch does NOT yet have the same restart-failure logging/retry hardening;
389
+ * that resilience gap is deferred, not "launchd is already safe".
390
+ *
380
391
  * @param {object} opts
381
392
  * @param {string} opts.pkgName npm package name
382
393
  * @param {string} opts.installDir install dir (local install) — used as cwd
@@ -438,6 +449,18 @@ export function buildUnixUpgradeScript({
438
449
  // 停止服务管理器的自动重启
439
450
  if (isSystemd) {
440
451
  shLines.push(
452
+ // `systemctl --user` locates the user manager via XDG_RUNTIME_DIR (and
453
+ // its bus via DBUS_SESSION_BUS_ADDRESS). The agent normally inherits both
454
+ // from its systemd-managed environment, but the detached upgrade shell
455
+ // cannot rely on that always being populated — if either is missing,
456
+ // `systemctl --user` fails with "Failed to connect to bus" and BOTH the
457
+ // stop and the restart silently no-op, stranding the agent offline after
458
+ // upgrade. Pin per-user defaults (keeping any inherited value) before the
459
+ // first systemctl call so the whole sequence can reach the manager.
460
+ 'YEAFT_UID="$(id -u)"',
461
+ 'export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$YEAFT_UID}"',
462
+ 'export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/$YEAFT_UID/bus}"',
463
+ '',
441
464
  '# Stop systemd service to prevent restart loop',
442
465
  `systemctl --user stop "${serviceName}" 2>/dev/null`,
443
466
  'sleep 1',
@@ -472,9 +495,22 @@ export function buildUnixUpgradeScript({
472
495
  // 重新启动服务
473
496
  if (isSystemd) {
474
497
  shLines.push(
475
- '# Restart systemd service',
476
- `systemctl --user start "${serviceName}"`,
477
- 'echo "[Upgrade] Service restarted via systemd"',
498
+ '# Restart systemd service. Capture failure explicitly: a silent',
499
+ '# `systemctl start` failure here is exactly what strands the agent',
500
+ '# offline, so log the exit code + reason and retry once before giving up.',
501
+ `if systemctl --user start "${serviceName}"; then`,
502
+ ' echo "[Upgrade] Service restarted via systemd"',
503
+ 'else',
504
+ ' START_RC=$?',
505
+ ` echo "[Upgrade] systemctl start failed (rc=$START_RC); retrying after reload..."`,
506
+ ' systemctl --user daemon-reload || true',
507
+ ' sleep 2',
508
+ ` if systemctl --user start "${serviceName}"; then`,
509
+ ' echo "[Upgrade] Service restarted via systemd (after retry)"',
510
+ ' else',
511
+ ` echo "[Upgrade] ERROR: systemctl start still failing (rc=$?). Manual start required: systemctl --user start ${serviceName}"`,
512
+ ' fi',
513
+ 'fi',
478
514
  );
479
515
  } else if (isLaunchd) {
480
516
  shLines.push(
@@ -492,7 +528,9 @@ export function buildUnixUpgradeScript({
492
528
 
493
529
  function spawnUnixUpgradeScript(pkgName, installDir, isGlobalInstall, latestVersion, instanceId = DEFAULT_INSTANCE_ID) {
494
530
  const configDir = getConfigDir(instanceId);
495
- mkdirSync(configDir, { recursive: true });
531
+ // Create logs/ too: the generated script's `exec > "$LOGFILE" 2>&1` aborts
532
+ // the whole upgrade silently if that directory is missing.
533
+ mkdirSync(join(configDir, 'logs'), { recursive: true });
496
534
  const shPath = join(configDir, 'upgrade.sh');
497
535
 
498
536
  const script = buildUnixUpgradeScript({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",