@integrity-labs/agt-cli 0.28.1311 → 0.28.1313

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 (38) hide show
  1. package/dist/{api-client-LJIV4E3U.js → api-client-OATI5QPI.js} +3 -3
  2. package/dist/bin/agt.js +8 -8
  3. package/dist/bin/agt.js.map +1 -1
  4. package/dist/{chunk-C35ONIOM.js → chunk-4VFHXY7W.js} +2 -2
  5. package/dist/{chunk-LNLKOJC5.js → chunk-ABU3BOHU.js} +10 -10
  6. package/dist/{chunk-LNLKOJC5.js.map → chunk-ABU3BOHU.js.map} +1 -1
  7. package/dist/{chunk-AATR5MO7.js → chunk-BSZRE4X6.js} +38 -6
  8. package/dist/{chunk-AATR5MO7.js.map → chunk-BSZRE4X6.js.map} +1 -1
  9. package/dist/{chunk-PRSMP7YW.js → chunk-JX4S7KFB.js} +2 -2
  10. package/dist/{chunk-DTGNYXYM.js → chunk-JYBRZAAK.js} +8 -1
  11. package/dist/chunk-JYBRZAAK.js.map +1 -0
  12. package/dist/{chunk-NYBVFW7X.js → chunk-NBIS2LOE.js} +3 -3
  13. package/dist/{chunk-H3JMPEH7.js → chunk-ZE6WANYK.js} +11 -4
  14. package/dist/chunk-ZE6WANYK.js.map +1 -0
  15. package/dist/{claude-code-updater-QRAOQLXJ.js → claude-code-updater-OLV2OEVG.js} +3 -3
  16. package/dist/{claude-pair-runtime-ZI2LPY5E.js → claude-pair-runtime-QA3AUNBF.js} +3 -3
  17. package/dist/lib/manager-worker.js +22 -22
  18. package/dist/{manager-supervisor-TD7E6FPC.js → manager-supervisor-NZHBYHWF.js} +2 -2
  19. package/dist/mcp/direct-chat-channel.js +61 -2
  20. package/dist/mcp/slack-channel.js +48 -2
  21. package/dist/mcp/teams-channel.js +48 -2
  22. package/dist/mcp/telegram-channel.js +48 -2
  23. package/dist/{persistent-session-ADLDX7QL.js → persistent-session-K5WFQVXD.js} +4 -4
  24. package/dist/{responsiveness-probe-ETVF2D2O.js → responsiveness-probe-Q5PDMK2L.js} +4 -4
  25. package/dist/{session-auth-dead-36OZTRBJ.js → session-auth-dead-T57ORTYP.js} +3 -3
  26. package/package.json +1 -1
  27. package/dist/chunk-DTGNYXYM.js.map +0 -1
  28. package/dist/chunk-H3JMPEH7.js.map +0 -1
  29. /package/dist/{api-client-LJIV4E3U.js.map → api-client-OATI5QPI.js.map} +0 -0
  30. /package/dist/{chunk-C35ONIOM.js.map → chunk-4VFHXY7W.js.map} +0 -0
  31. /package/dist/{chunk-PRSMP7YW.js.map → chunk-JX4S7KFB.js.map} +0 -0
  32. /package/dist/{chunk-NYBVFW7X.js.map → chunk-NBIS2LOE.js.map} +0 -0
  33. /package/dist/{claude-code-updater-QRAOQLXJ.js.map → claude-code-updater-OLV2OEVG.js.map} +0 -0
  34. /package/dist/{claude-pair-runtime-ZI2LPY5E.js.map → claude-pair-runtime-QA3AUNBF.js.map} +0 -0
  35. /package/dist/{manager-supervisor-TD7E6FPC.js.map → manager-supervisor-NZHBYHWF.js.map} +0 -0
  36. /package/dist/{persistent-session-ADLDX7QL.js.map → persistent-session-K5WFQVXD.js.map} +0 -0
  37. /package/dist/{responsiveness-probe-ETVF2D2O.js.map → responsiveness-probe-Q5PDMK2L.js.map} +0 -0
  38. /package/dist/{session-auth-dead-36OZTRBJ.js.map → session-auth-dead-T57ORTYP.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HOST_ROTATE_KEY_CONFLICT
3
- } from "./chunk-DTGNYXYM.js";
3
+ } from "./chunk-JYBRZAAK.js";
4
4
 
5
5
  // src/lib/config.ts
6
6
  import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
@@ -103,7 +103,7 @@ function exchangeFailureKind(err) {
103
103
  }
104
104
 
105
105
  // src/lib/api-client.ts
106
- var agtCliVersion = true ? "0.28.1311" : "dev";
106
+ var agtCliVersion = true ? "0.28.1313" : "dev";
107
107
  var lastConfigHash = null;
108
108
  function setConfigHash(hash) {
109
109
  lastConfigHash = hash && hash.length > 0 ? hash : null;
@@ -468,4 +468,4 @@ export {
468
468
  api,
469
469
  getHostId
470
470
  };
471
- //# sourceMappingURL=chunk-NYBVFW7X.js.map
471
+ //# sourceMappingURL=chunk-NBIS2LOE.js.map
@@ -384,15 +384,22 @@ async function installSystemUnit(opts) {
384
384
  return { ok: false, error: `systemctl daemon-reload failed: ${err.message}` };
385
385
  }
386
386
  let recoverTimerNote = `Recovery timer ${LINUX_RECOVER_TIMER_NAME} enabled.`;
387
+ const enableArgs = (unit) => opts.deferStart ? ["enable", unit] : ["enable", "--now", unit];
387
388
  try {
388
- execFileSync("systemctl", ["enable", "--now", LINUX_RECOVER_TIMER_NAME], { stdio: "pipe" });
389
+ execFileSync("systemctl", enableArgs(LINUX_RECOVER_TIMER_NAME), { stdio: "pipe" });
389
390
  } catch (err) {
390
391
  recoverTimerNote = `WARNING: could not enable ${LINUX_RECOVER_TIMER_NAME}, so this host will not recover by itself from StartLimitBurst: ${err.message}`;
391
392
  }
392
393
  try {
393
- execFileSync("systemctl", ["enable", "--now", LINUX_UNIT_NAME], { stdio: "pipe" });
394
+ execFileSync("systemctl", enableArgs(LINUX_UNIT_NAME), { stdio: "pipe" });
394
395
  } catch (err) {
395
- return { ok: false, error: `systemctl enable --now failed: ${err.message}` };
396
+ return { ok: false, error: `systemctl ${enableArgs(LINUX_UNIT_NAME).slice(0, -1).join(" ")} failed: ${err.message}` };
397
+ }
398
+ if (opts.deferStart) {
399
+ return {
400
+ ok: true,
401
+ details: `Enabled systemd system unit ${LINUX_UNIT_NAME} at ${LINUX_SYSTEM_UNIT_PATH} without starting it (--defer-start); it starts on the next boot via multi-user.target. ${recoverTimerNote}`
402
+ };
396
403
  }
397
404
  let isActive = "";
398
405
  try {
@@ -836,4 +843,4 @@ export {
836
843
  rewriteSupervisorApiKey,
837
844
  _internals
838
845
  };
839
- //# sourceMappingURL=chunk-H3JMPEH7.js.map
846
+ //# sourceMappingURL=chunk-ZE6WANYK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/manager-supervisor.ts"],"sourcesContent":["/**\n * OS-level supervision for the agt manager daemon (ENG-4593).\n *\n * Hands manager lifecycle off to the OS so a missing process is the OS's\n * problem, not ours. Replaces the in-process `agt manager start\n * --supervise` wrapper from ENG-4488.\n *\n * macOS: launchd LaunchAgent (KeepAlive=true + ThrottleInterval=10)\n * Linux: systemd --user unit (Restart=always + RestartSec=5) [Phase 2]\n * systemd system unit (Restart=on-failure, root) [Phase 3 / ENG-4706]\n *\n * Public surface:\n * - installSupervisor(opts) — write the unit, load/enable it, verify\n * - uninstallSupervisor() — unload/disable + remove the unit (idempotent)\n * - supervisorStatus() — quick readout of whether the OS knows about us\n *\n * - installSystemUnit(opts) — Linux only, root-only. Writes\n * /etc/systemd/system/agt-manager.service\n * so the manager survives EC2 reboot\n * without `loginctl enable-linger`\n * gymnastics. Used by host-bootstrap and\n * the SSM backfill runbook (ENG-4706).\n * - uninstallSystemUnit()\n * - systemUnitStatus()\n *\n * Each platform implementation lives in its own helper. The dispatcher\n * picks one based on `process.platform` and rejects unsupported OSes\n * with a clear error rather than silently no-oping.\n */\n\nimport { execFileSync } from 'node:child_process';\nimport {\n existsSync,\n mkdirSync,\n readFileSync,\n renameSync,\n statSync,\n unlinkSync,\n writeFileSync,\n chmodSync,\n} from 'node:fs';\nimport { homedir, platform } from 'node:os';\nimport { dirname, join } from 'node:path';\n\n// macOS LaunchAgent label and on-disk path. Stable so install/uninstall\n// can find each other without a state file.\nconst MACOS_LABEL = 'team.augmented.agt-manager';\nconst MACOS_PLIST = join(homedir(), 'Library', 'LaunchAgents', `${MACOS_LABEL}.plist`);\n\n// Linux systemd --user unit. Lives under the operator's XDG config so it\n// survives reboot only after `loginctl enable-linger` (we surface that as\n// a follow-up step rather than running it ourselves — needs root).\nconst LINUX_UNIT_NAME = 'agt-manager.service';\nconst LINUX_UNIT_PATH = join(homedir(), '.config', 'systemd', 'user', LINUX_UNIT_NAME);\n// Secrets live in a separate EnvironmentFile (mode 0600) instead of\n// being inlined into the unit body. The unit file itself is still\n// 0600 but plain Environment= lines in it are visible to anything\n// that can read systemd's parsed unit cache (`systemctl show`,\n// `systemd-cgls --all`, etc.). EnvironmentFile content stays private\n// to the systemd manager process.\nconst LINUX_ENV_FILE_PATH = join(homedir(), '.config', 'systemd', 'user', 'agt-manager.env');\n\nexport interface InstallOpts {\n /** Absolute path to the agt binary the supervisor should launch. */\n agtBin: string;\n /** Poll interval passed to `agt manager start`. Min 5 seconds. */\n intervalSec: number;\n /** Manager config directory (where pid/log/state files live). */\n configDir: string;\n /**\n * Environment variables the supervised manager needs at launch time.\n * AGT_HOST and AGT_API_KEY are required for the manager to call the\n * API; AGT_TEAM is optional but typical.\n */\n env: Record<string, string>;\n}\n\nexport type SupervisorPresence =\n | { kind: 'installed'; pid: number | null; details: string }\n | { kind: 'not-installed' }\n | { kind: 'unsupported-platform'; platform: string };\n\n// ---------------------------------------------------------------------------\n// Public dispatcher\n// ---------------------------------------------------------------------------\n\nexport async function installSupervisor(opts: InstallOpts): Promise<{ ok: true; details: string } | { ok: false; error: string }> {\n switch (platform()) {\n case 'darwin':\n return installMacos(opts);\n case 'linux':\n return installLinux(opts);\n default:\n return { ok: false, error: `Unsupported platform: ${platform()}. Supervisor install is macOS / Linux only.` };\n }\n}\n\nexport async function uninstallSupervisor(): Promise<{ ok: true; details: string } | { ok: false; error: string }> {\n switch (platform()) {\n case 'darwin':\n return uninstallMacos();\n case 'linux':\n return uninstallLinux();\n default:\n return { ok: false, error: `Unsupported platform: ${platform()}. Supervisor uninstall is macOS / Linux only.` };\n }\n}\n\nexport function supervisorStatus(): SupervisorPresence {\n switch (platform()) {\n case 'darwin':\n return statusMacos();\n case 'linux':\n return statusLinux();\n default:\n return { kind: 'unsupported-platform', platform: platform() };\n }\n}\n\n// ---------------------------------------------------------------------------\n// macOS — launchd LaunchAgent\n// ---------------------------------------------------------------------------\n\nfunction installMacos(opts: InstallOpts): { ok: true; details: string } | { ok: false; error: string } {\n if (!existsSync(opts.agtBin)) {\n return { ok: false, error: `agt binary not found at ${opts.agtBin}` };\n }\n if (opts.intervalSec < 5) {\n return { ok: false, error: 'intervalSec must be >= 5' };\n }\n if (!opts.env.AGT_HOST || !opts.env.AGT_API_KEY) {\n return { ok: false, error: 'AGT_HOST and AGT_API_KEY must be set in the calling shell so the supervisor can pass them to the manager. Run `agt setup <token>` first.' };\n }\n\n // If a previous version is already loaded, unload it before rewriting\n // the plist — otherwise launchctl bootstrap will fail with EALREADY.\n bestEffort(() => execFileSync('launchctl', ['unload', '-w', MACOS_PLIST], { stdio: 'ignore' }));\n\n // Ensure the LaunchAgents directory exists. macOS creates it on first\n // login, but freshly-installed admin users may not have it yet.\n mkdirSync(dirname(MACOS_PLIST), { recursive: true });\n // 0o600 — plist embeds AGT_API_KEY in EnvironmentVariables. World-\n // readable would expose the host's tlk_ token to every local user.\n writeFileSync(MACOS_PLIST, renderMacosPlist(opts), { mode: 0o600 });\n chmodSync(MACOS_PLIST, 0o600);\n\n try {\n execFileSync('launchctl', ['load', '-w', MACOS_PLIST], { stdio: 'pipe' });\n } catch (err) {\n return { ok: false, error: `launchctl load failed: ${(err as Error).message}` };\n }\n\n // Verify launchd actually picked it up. `list <label>` returns 0 with\n // a plist of the loaded job's metadata; non-zero if not loaded.\n try {\n const out = execFileSync('launchctl', ['list', MACOS_LABEL], { encoding: 'utf-8' });\n return {\n ok: true,\n details: `Loaded launchd LaunchAgent ${MACOS_LABEL}. Logs: ${join(opts.configDir, 'manager.log')}.\\n${out.trim().split('\\n').slice(0, 10).join('\\n')}`,\n };\n } catch (err) {\n return { ok: false, error: `Plist written but launchctl list reported nothing for ${MACOS_LABEL}: ${(err as Error).message}` };\n }\n}\n\nfunction uninstallMacos(): { ok: true; details: string } | { ok: false; error: string } {\n // Both steps are idempotent — unload reports an error if nothing's\n // loaded, removing the file errors if it doesn't exist. Swallow both;\n // the desired end state is \"no LaunchAgent for this label\".\n bestEffort(() => execFileSync('launchctl', ['unload', '-w', MACOS_PLIST], { stdio: 'ignore' }));\n let removed = false;\n if (existsSync(MACOS_PLIST)) {\n try {\n unlinkSync(MACOS_PLIST);\n removed = true;\n } catch (err) {\n return { ok: false, error: `Failed to remove ${MACOS_PLIST}: ${(err as Error).message}` };\n }\n }\n return {\n ok: true,\n details: removed\n ? `Removed ${MACOS_LABEL} from launchd and deleted ${MACOS_PLIST}.`\n : `${MACOS_LABEL} was already uninstalled (no plist at ${MACOS_PLIST}).`,\n };\n}\n\nfunction statusMacos(): SupervisorPresence {\n if (!existsSync(MACOS_PLIST)) return { kind: 'not-installed' };\n // launchctl list emits a 3-column line: PID Status Label. PID is \"-\"\n // when the job is loaded but not currently running.\n try {\n const out = execFileSync('launchctl', ['list', MACOS_LABEL], { encoding: 'utf-8' });\n const pidMatch = /\"PID\"\\s*=\\s*(\\d+);/.exec(out);\n const pid = pidMatch ? Number(pidMatch[1]) : null;\n return { kind: 'installed', pid, details: `Plist: ${MACOS_PLIST}` };\n } catch {\n // File exists but launchctl can't find the label → user removed it\n // out-of-band. Surface as \"not installed\" so re-install just works.\n return { kind: 'not-installed' };\n }\n}\n\nfunction renderMacosPlist(opts: InstallOpts): string {\n // Load the operator's env into the plist so the manager has the same\n // AGT_HOST / AGT_API_KEY / AGT_TEAM the shell session does. launchd\n // does NOT inherit env from the user's shell — anything we don't bake\n // in here won't be visible to the process.\n const envEntries = Object.entries(opts.env)\n .filter(([k, v]) => k.length > 0 && v != null)\n .map(([k, v]) => ` <key>${escapeXml(k)}</key>\\n <string>${escapeXml(v)}</string>`)\n .join('\\n');\n\n const args = [\n 'manager',\n 'start',\n '--interval',\n String(opts.intervalSec),\n '--config-dir',\n opts.configDir,\n ];\n const argsXml = args.map((a) => ` <string>${escapeXml(a)}</string>`).join('\\n');\n\n const logPath = join(opts.configDir, 'manager.log');\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>Label</key>\n <string>${MACOS_LABEL}</string>\n\n <key>ProgramArguments</key>\n <array>\n <string>${escapeXml(opts.agtBin)}</string>\n${argsXml}\n </array>\n\n <key>RunAtLoad</key>\n <true/>\n\n <key>KeepAlive</key>\n <true/>\n\n <!-- Throttle restarts so a crashloop doesn't peg the CPU. 10 seconds\n between launches is enough room for transient API blips while\n still recovering quickly from a real crash. -->\n <key>ThrottleInterval</key>\n <integer>10</integer>\n\n <!-- Where the manager's stdout / stderr land. The manager's logger\n redirects stderr into manager.log itself, but launchd needs an\n explicit destination at the OS level for any pre-logger output\n (e.g., Node startup errors before the watchdog wires up). -->\n <key>StandardOutPath</key>\n <string>${escapeXml(logPath)}</string>\n <key>StandardErrorPath</key>\n <string>${escapeXml(logPath)}</string>\n\n <key>WorkingDirectory</key>\n <string>${escapeXml(opts.configDir)}</string>\n\n <key>EnvironmentVariables</key>\n <dict>\n${envEntries}\n </dict>\n</dict>\n</plist>\n`;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction bestEffort(fn: () => void): void {\n try { fn(); } catch { /* swallow */ }\n}\n\nfunction escapeXml(s: string): string {\n return s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;');\n}\n\n// ---------------------------------------------------------------------------\n// Linux — systemd --user unit\n// ---------------------------------------------------------------------------\n\nfunction installLinux(opts: InstallOpts): { ok: true; details: string } | { ok: false; error: string } {\n if (!existsSync(opts.agtBin)) {\n return { ok: false, error: `agt binary not found at ${opts.agtBin}` };\n }\n if (opts.intervalSec < 5) {\n return { ok: false, error: 'intervalSec must be >= 5' };\n }\n if (!opts.env.AGT_HOST || !opts.env.AGT_API_KEY) {\n return { ok: false, error: 'AGT_HOST and AGT_API_KEY must be set in the calling shell so the supervisor can pass them to the unit. Run `agt setup <token>` first.' };\n }\n\n // Stop any previous instance before rewriting the unit — saves a\n // restart loop while daemon-reload picks up the new file.\n bestEffort(() => execFileSync('systemctl', ['--user', 'stop', LINUX_UNIT_NAME], { stdio: 'ignore' }));\n\n // ~/.config/systemd/user/ is the canonical user-unit path. Create it\n // recursively in case this is a fresh user with no XDG layout yet.\n mkdirSync(dirname(LINUX_UNIT_PATH), { recursive: true, mode: 0o700 });\n // Write the secrets-only env file FIRST (mode 0600) so the unit can\n // reference it via EnvironmentFile=. Non-secret env stays in the\n // unit body via Environment= lines for visibility.\n writeFileSync(LINUX_ENV_FILE_PATH, renderLinuxEnvFile(opts), { mode: 0o600 });\n chmodSync(LINUX_ENV_FILE_PATH, 0o600);\n writeFileSync(LINUX_UNIT_PATH, renderLinuxUnit(opts), { mode: 0o600 });\n chmodSync(LINUX_UNIT_PATH, 0o600);\n\n try {\n execFileSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'pipe' });\n } catch (err) {\n return { ok: false, error: `systemctl --user daemon-reload failed: ${(err as Error).message}` };\n }\n\n // `enable --now` enables the unit at boot AND starts it immediately.\n // Surviving reboot on a headless host additionally requires\n // `loginctl enable-linger <user>` (root-only); we surface that as a\n // post-install hint rather than running it ourselves.\n try {\n execFileSync('systemctl', ['--user', 'enable', '--now', LINUX_UNIT_NAME], { stdio: 'pipe' });\n } catch (err) {\n return { ok: false, error: `systemctl --user enable --now failed: ${(err as Error).message}. (Hint: 'systemctl --user' requires a per-user dbus session; on a fresh SSH login try 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' first.)` };\n }\n\n let isActive = '';\n try {\n isActive = execFileSync('systemctl', ['--user', 'is-active', LINUX_UNIT_NAME], { encoding: 'utf-8' }).trim();\n } catch (err) {\n // is-active exits non-zero for inactive/failed states. Capture its\n // output so the operator sees the real status.\n isActive = ((err as { stdout?: Buffer; stderr?: Buffer }).stdout?.toString() ?? '').trim() || 'unknown';\n }\n\n // Don't claim the install succeeded if the unit ended up failed /\n // inactive / unknown. Without this, the CLI would exit 0 with a\n // green \"supervisor installed\" message while the manager was\n // already broken.\n if (isActive !== 'active') {\n return {\n ok: false,\n error: `systemd loaded ${LINUX_UNIT_NAME} but it did not become active (status: ${isActive}). Run 'systemctl --user status ${LINUX_UNIT_NAME}' or 'journalctl --user -u ${LINUX_UNIT_NAME} -n 50' for details.`,\n };\n }\n\n return {\n ok: true,\n details: `Loaded systemd --user unit ${LINUX_UNIT_NAME} (status: ${isActive}). Logs: ${join(opts.configDir, 'manager.log')}.\\nFor reboot survival on a headless host run as root: 'loginctl enable-linger ${process.env['USER'] ?? '<your-user>'}'`,\n };\n}\n\nfunction uninstallLinux(): { ok: true; details: string } | { ok: false; error: string } {\n // disable --now stops + un-enables in one shot. Both legs are idempotent\n // — disable on a non-existent unit returns 0 with a notice on stderr.\n bestEffort(() => execFileSync('systemctl', ['--user', 'disable', '--now', LINUX_UNIT_NAME], { stdio: 'ignore' }));\n\n let removed = false;\n if (existsSync(LINUX_UNIT_PATH)) {\n try {\n unlinkSync(LINUX_UNIT_PATH);\n removed = true;\n } catch (err) {\n return { ok: false, error: `Failed to remove ${LINUX_UNIT_PATH}: ${(err as Error).message}` };\n }\n }\n // Best-effort cleanup of the secrets-only env file too; we don't\n // want a stale AGT_API_KEY left on disk after uninstall.\n if (existsSync(LINUX_ENV_FILE_PATH)) {\n bestEffort(() => unlinkSync(LINUX_ENV_FILE_PATH));\n }\n\n // Reload so a future install with the same path doesn't reuse the\n // stale unit metadata systemd cached in memory.\n bestEffort(() => execFileSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'ignore' }));\n\n return {\n ok: true,\n details: removed\n ? `Disabled systemd --user unit ${LINUX_UNIT_NAME} and deleted ${LINUX_UNIT_PATH}.`\n : `${LINUX_UNIT_NAME} was already uninstalled (no unit file at ${LINUX_UNIT_PATH}).`,\n };\n}\n\nfunction statusLinux(): SupervisorPresence {\n if (!existsSync(LINUX_UNIT_PATH)) return { kind: 'not-installed' };\n let pid: number | null = null;\n let activeState = 'unknown';\n try {\n const out = execFileSync(\n 'systemctl',\n ['--user', 'show', LINUX_UNIT_NAME, '--property=MainPID,ActiveState'],\n { encoding: 'utf-8' },\n );\n const pidMatch = /^MainPID=(\\d+)/m.exec(out);\n if (pidMatch && pidMatch[1] !== '0') pid = Number(pidMatch[1]);\n const stateMatch = /^ActiveState=(\\S+)/m.exec(out);\n if (stateMatch) activeState = stateMatch[1] ?? 'unknown';\n } catch (err) {\n // The unit file exists but `systemctl --user` couldn't probe it\n // — most often because XDG_RUNTIME_DIR / the per-user dbus isn't\n // available in this shell. Don't lie to the operator about\n // whether the supervisor is installed; report 'installed,\n // unknown state' instead.\n return {\n kind: 'installed',\n pid: null,\n details: `Unit: ${LINUX_UNIT_PATH} (could not query systemd --user: ${(err as Error).message})`,\n };\n }\n return { kind: 'installed', pid, details: `Unit: ${LINUX_UNIT_PATH} (${activeState})` };\n}\n\n// Secrets that go into EnvironmentFile= instead of inline Environment=.\n// Anything in this set is written to LINUX_ENV_FILE_PATH (mode 0600)\n// and stripped from the unit body. Public env (PATH, AGT_HOST, AGT_TEAM)\n// stays inline for visibility in `systemctl show`.\nconst LINUX_SECRET_ENV_KEYS: ReadonlySet<string> = new Set(['AGT_API_KEY']);\n\nfunction renderLinuxUnit(opts: InstallOpts): string {\n // Non-secret env stays in the unit body via Environment= lines;\n // secrets are pulled from the EnvironmentFile= written separately.\n // systemd parses Environment= with a peculiar grammar — quotes are\n // optional but values can't contain literal newlines. We trust the\n // env values we forward and quote everything to be safe with spaces.\n const envLines = Object.entries(opts.env)\n .filter(([k, v]) => k.length > 0 && v != null && !LINUX_SECRET_ENV_KEYS.has(k))\n .map(([k, v]) => `Environment=\"${k}=${escapeForSystemdEnv(v)}\"`)\n .join('\\n');\n\n // ExecStart cannot use shell metacharacters; pass the args explicitly\n // via systemd's array-of-args style (newline-separated wouldn't\n // parse — systemd splits on whitespace within ExecStart). So we\n // shell-quote each arg and join.\n const execArgs = [\n opts.agtBin,\n 'manager',\n 'start',\n '--interval',\n String(opts.intervalSec),\n '--config-dir',\n opts.configDir,\n ]\n .map(shellQuoteForSystemd)\n .join(' ');\n\n const logPath = join(opts.configDir, 'manager.log');\n\n return `# agt manager supervisor (ENG-4593)\n# Managed by \\`agt manager install\\` — edits will be overwritten.\n\n[Unit]\nDescription=Augmented host manager daemon\nAfter=network-online.target\nWants=network-online.target\n# Restart rate-limit lives here per systemd.unit(5). Older systemds\n# tolerated these directives in the service section but newer ones\n# silently ignore them there, leaving the crashloop unprotected.\nStartLimitBurst=5\nStartLimitIntervalSec=60\n\n[Service]\nType=simple\nWorkingDirectory=${opts.configDir}\n${envLines}\nEnvironmentFile=${LINUX_ENV_FILE_PATH}\nExecStart=${execArgs}\n\n# Always come back from any exit; back off 5s between launches so a\n# crashloop can't peg the CPU. The 5/60s window above caps total\n# attempts before systemd marks the unit failed.\nRestart=always\nRestartSec=5\n\n# stdout/stderr → manager.log. journalctl --user -u agt-manager\n# still captures everything; this just gives operators a single file\n# to tail without learning systemd plumbing.\nStandardOutput=append:${logPath}\nStandardError=append:${logPath}\n\n[Install]\nWantedBy=default.target\n`;\n}\n\n/**\n * Render the secrets-only env file referenced by EnvironmentFile= in\n * the unit. Format: `KEY=VALUE` per line (systemd's EnvironmentFile\n * parser doesn't support quoting the value the way Environment= does,\n * but it tolerates literal characters as long as the value has no\n * newline). One key per line; trailing newline.\n */\nfunction renderLinuxEnvFile(opts: InstallOpts): string {\n return Object.entries(opts.env)\n .filter(([k, v]) => LINUX_SECRET_ENV_KEYS.has(k) && v != null)\n .map(([k, v]) => `${k}=${v}\\n`)\n .join('');\n}\n\nfunction escapeForSystemdEnv(value: string): string {\n // Inside an Environment=\"K=V\" line, \" and \\\\ need escaping. Newlines\n // would terminate the directive — reject them upstream.\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\nfunction shellQuoteForSystemd(arg: string): string {\n // systemd's ExecStart parser supports double-quoted strings with\n // backslash escapes, similar to a POSIX shell but no command\n // substitution. Wrap any arg containing whitespace or shell metas.\n if (/^[A-Za-z0-9_./:=-]+$/.test(arg)) return arg;\n return `\"${arg.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n}\n\n// ---------------------------------------------------------------------------\n// Linux — systemd system unit (ENG-4706)\n// ---------------------------------------------------------------------------\n//\n// The `--user` unit above survives reboot only if `loginctl enable-linger`\n// is set per-user. On headless EC2 hosts that's a footgun: a reboot (kernel\n// patch, instance-type change, AWS-initiated maintenance) silently takes\n// every agent on the host offline until an operator manually re-launches\n// the manager. The system unit lives at /etc/systemd/system/, runs as root,\n// and is enabled into multi-user.target — so it comes up automatically at\n// boot just like any other service.\n//\n// Both unit kinds can co-exist; statusLinux() looks at the user one,\n// systemUnitStatus() looks at the system one. The CLI surfaces them as\n// `agt manager install` (user, dev workflow) and `agt manager\n// install-system-unit` (root, host-infra workflow) so the operator\n// chooses explicitly.\n\nconst LINUX_SYSTEM_UNIT_PATH = '/etc/systemd/system/agt-manager.service';\nconst LINUX_SYSTEM_ENV_FILE_PATH = '/etc/agt/agt-manager.env';\n// ENG-11695: resets and restarts the manager after StartLimitBurst latches it.\nconst LINUX_RECOVER_SERVICE_NAME = 'agt-manager-recover.service';\nconst LINUX_RECOVER_TIMER_NAME = 'agt-manager-recover.timer';\nconst LINUX_RECOVER_SERVICE_PATH = `/etc/systemd/system/${LINUX_RECOVER_SERVICE_NAME}`;\nconst LINUX_RECOVER_TIMER_PATH = `/etc/systemd/system/${LINUX_RECOVER_TIMER_NAME}`;\n\nexport interface InstallSystemUnitOpts extends InstallOpts {\n /**\n * Unix user the manager runs as. EC2 default is `root`. Other hosts\n * can run it as a less-privileged user, but the user must own\n * `configDir` and have permission to write to it. Defaults to `root`\n * when omitted (matches the ticket spec).\n */\n user?: string;\n /**\n * ENG-12365: enable both units for boot WITHOUT starting them now. The\n * bootstrap uses this when it is about to reboot into a newer kernel, so the\n * manager's first start is after the reboot and no agent runs across it.\n */\n deferStart?: boolean;\n}\n\nexport async function installSystemUnit(\n opts: InstallSystemUnitOpts,\n): Promise<{ ok: true; details: string } | { ok: false; error: string }> {\n if (platform() !== 'linux') {\n return {\n ok: false,\n error: `installSystemUnit is Linux-only (current platform: ${platform()}). For local dev on macOS use installSupervisor.`,\n };\n }\n if (process.getuid?.() !== 0) {\n return {\n ok: false,\n error: 'installSystemUnit requires root. Re-run with sudo, or call from the EC2 user-data bootstrap which already runs as root.',\n };\n }\n if (!existsSync(opts.agtBin)) {\n return { ok: false, error: `agt binary not found at ${opts.agtBin}` };\n }\n if (opts.intervalSec < 5) {\n return { ok: false, error: 'intervalSec must be >= 5' };\n }\n if (!opts.env.AGT_HOST || !opts.env.AGT_API_KEY) {\n return {\n ok: false,\n error: 'AGT_HOST and AGT_API_KEY must be set so the system unit can pass them through. Run `agt setup <token>` first (it writes them to /etc/environment, which this installer reads).',\n };\n }\n\n // Stop any running instance so daemon-reload picks up the rewritten\n // unit cleanly without a respawn race.\n bestEffort(() => execFileSync('systemctl', ['stop', LINUX_UNIT_NAME], { stdio: 'ignore' }));\n\n // Belt-and-braces (ENG-4706 backfill): kill any pre-existing manager\n // process that wasn't started via systemd. On hosts that were\n // bootstrapped before this PR, the manager runs nohup'd from a one-\n // shot SSM command. Installing the system unit without stopping that\n // older process leaves TWO managers polling Supabase simultaneously —\n // they race on agent ticks, double-inject channel messages, and\n // double-write audit_log rows. SIGTERM gives it 3s to wind down\n // cleanly before the systemd start grabs the supervisor seat.\n // Ignored on hosts that have no rogue manager (the typical fresh-\n // bootstrap path).\n bestEffort(() => {\n const out = execFileSync('pgrep', ['-f', 'agt manager start'], { stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf-8' });\n const pids = out\n .split('\\n')\n .map((s) => s.trim())\n .filter((s) => s.length > 0 && /^\\d+$/.test(s) && Number(s) !== process.pid);\n if (pids.length === 0) return;\n for (const pid of pids) {\n bestEffort(() => process.kill(Number(pid), 'SIGTERM'));\n }\n // Brief settle so the just-killed manager releases its Supabase\n // long-polls before the new one connects. 3s matches the default\n // poll interval; a manager that hasn't shut down in that window\n // gets SIGKILLed below.\n const deadline = Date.now() + 3_000;\n while (Date.now() < deadline) {\n try {\n execFileSync('pgrep', ['-f', 'agt manager start'], { stdio: 'ignore' });\n } catch {\n return;\n }\n // Spin — busy-wait is fine for a 3s ceiling and avoids pulling in\n // a sleep helper. This path runs once at install, never on the\n // hot poll loop.\n }\n // Still alive — escalate.\n for (const pid of pids) {\n bestEffort(() => process.kill(Number(pid), 'SIGKILL'));\n }\n });\n\n // Secrets-only env file lives under /etc/agt/ (root:root, 0600). Same\n // rationale as the user-unit env file: keep AGT_API_KEY out of any\n // tool that reads systemd's parsed unit cache.\n mkdirSync(dirname(LINUX_SYSTEM_ENV_FILE_PATH), { recursive: true, mode: 0o700 });\n writeFileSync(LINUX_SYSTEM_ENV_FILE_PATH, renderLinuxEnvFile(opts), { mode: 0o600 });\n chmodSync(LINUX_SYSTEM_ENV_FILE_PATH, 0o600);\n writeFileSync(LINUX_SYSTEM_UNIT_PATH, renderLinuxSystemUnit(opts), { mode: 0o644 });\n chmodSync(LINUX_SYSTEM_UNIT_PATH, 0o644);\n writeFileSync(LINUX_RECOVER_SERVICE_PATH, renderLinuxRecoverService(), { mode: 0o644 });\n chmodSync(LINUX_RECOVER_SERVICE_PATH, 0o644);\n writeFileSync(LINUX_RECOVER_TIMER_PATH, renderLinuxRecoverTimer(), { mode: 0o644 });\n chmodSync(LINUX_RECOVER_TIMER_PATH, 0o644);\n\n try {\n execFileSync('systemctl', ['daemon-reload'], { stdio: 'pipe' });\n } catch (err) {\n return { ok: false, error: `systemctl daemon-reload failed: ${(err as Error).message}` };\n }\n\n // ENG-11695: enabled BEFORE the manager's own start, so a manager that fails\n // to come up right here is still recovered later. It must not fail the\n // install: the manager runs without it, as it always has, and the failure is\n // reported in the result instead.\n let recoverTimerNote = `Recovery timer ${LINUX_RECOVER_TIMER_NAME} enabled.`;\n // ENG-12365: with deferStart, enable only. The recovery timer starts the\n // manager when it finds it down, so starting it now would start the manager\n // before the reboot the caller is about to make.\n const enableArgs = (unit: string) => (opts.deferStart ? ['enable', unit] : ['enable', '--now', unit]);\n try {\n execFileSync('systemctl', enableArgs(LINUX_RECOVER_TIMER_NAME), { stdio: 'pipe' });\n } catch (err) {\n recoverTimerNote = `WARNING: could not enable ${LINUX_RECOVER_TIMER_NAME}, so this host will not recover by itself from StartLimitBurst: ${(err as Error).message}`;\n }\n\n // `enable --now` enables at boot AND starts immediately. Unlike the\n // --user variant, this needs no enable-linger — multi-user.target\n // pulls us in regardless of any user session.\n try {\n execFileSync('systemctl', enableArgs(LINUX_UNIT_NAME), { stdio: 'pipe' });\n } catch (err) {\n return { ok: false, error: `systemctl ${enableArgs(LINUX_UNIT_NAME).slice(0, -1).join(' ')} failed: ${(err as Error).message}` };\n }\n\n if (opts.deferStart) {\n return {\n ok: true,\n details: `Enabled systemd system unit ${LINUX_UNIT_NAME} at ${LINUX_SYSTEM_UNIT_PATH} without starting it (--defer-start); it starts on the next boot via multi-user.target. ${recoverTimerNote}`,\n };\n }\n\n let isActive = '';\n try {\n isActive = execFileSync('systemctl', ['is-active', LINUX_UNIT_NAME], { encoding: 'utf-8' }).trim();\n } catch (err) {\n isActive = ((err as { stdout?: Buffer; stderr?: Buffer }).stdout?.toString() ?? '').trim() || 'unknown';\n }\n\n if (isActive !== 'active') {\n return {\n ok: false,\n error: `systemd loaded ${LINUX_UNIT_NAME} but it did not become active (status: ${isActive}). Run 'systemctl status ${LINUX_UNIT_NAME}' or 'journalctl -u ${LINUX_UNIT_NAME} -n 50' for details.`,\n };\n }\n\n return {\n ok: true,\n details: `Loaded systemd system unit ${LINUX_UNIT_NAME} at ${LINUX_SYSTEM_UNIT_PATH} (status: ${isActive}). Will auto-start on reboot via multi-user.target. Logs: ${join(opts.configDir, 'manager.log')} and 'journalctl -u ${LINUX_UNIT_NAME}'. ${recoverTimerNote}`,\n };\n}\n\nexport async function uninstallSystemUnit(): Promise<{ ok: true; details: string } | { ok: false; error: string }> {\n if (platform() !== 'linux') {\n return { ok: false, error: `uninstallSystemUnit is Linux-only (current platform: ${platform()}).` };\n }\n if (process.getuid?.() !== 0) {\n return { ok: false, error: 'uninstallSystemUnit requires root.' };\n }\n\n // ENG-11695: recovery goes first, or it could restart what this is removing. The\n // service too, because stopping the timer doesn't stop a run already in progress\n // (Obi Wan b12268328098).\n bestEffort(() => execFileSync('systemctl', ['disable', '--now', LINUX_RECOVER_TIMER_NAME], { stdio: 'ignore' }));\n bestEffort(() => execFileSync('systemctl', ['stop', LINUX_RECOVER_SERVICE_NAME], { stdio: 'ignore' }));\n bestEffort(() => execFileSync('systemctl', ['disable', '--now', LINUX_UNIT_NAME], { stdio: 'ignore' }));\n\n for (const path of [LINUX_RECOVER_TIMER_PATH, LINUX_RECOVER_SERVICE_PATH]) {\n if (existsSync(path)) bestEffort(() => unlinkSync(path));\n }\n\n let removed = false;\n if (existsSync(LINUX_SYSTEM_UNIT_PATH)) {\n try {\n unlinkSync(LINUX_SYSTEM_UNIT_PATH);\n removed = true;\n } catch (err) {\n return { ok: false, error: `Failed to remove ${LINUX_SYSTEM_UNIT_PATH}: ${(err as Error).message}` };\n }\n }\n if (existsSync(LINUX_SYSTEM_ENV_FILE_PATH)) {\n bestEffort(() => unlinkSync(LINUX_SYSTEM_ENV_FILE_PATH));\n }\n\n bestEffort(() => execFileSync('systemctl', ['daemon-reload'], { stdio: 'ignore' }));\n\n return {\n ok: true,\n details: removed\n ? `Disabled systemd system unit ${LINUX_UNIT_NAME} and deleted ${LINUX_SYSTEM_UNIT_PATH}.`\n : `${LINUX_UNIT_NAME} system unit was already uninstalled (no unit file at ${LINUX_SYSTEM_UNIT_PATH}).`,\n };\n}\n\nexport function systemUnitStatus(): SupervisorPresence {\n if (platform() !== 'linux') {\n return { kind: 'unsupported-platform', platform: platform() };\n }\n if (!existsSync(LINUX_SYSTEM_UNIT_PATH)) return { kind: 'not-installed' };\n let pid: number | null = null;\n let activeState = 'unknown';\n try {\n const out = execFileSync(\n 'systemctl',\n ['show', LINUX_UNIT_NAME, '--property=MainPID,ActiveState'],\n { encoding: 'utf-8' },\n );\n const pidMatch = /^MainPID=(\\d+)/m.exec(out);\n if (pidMatch && pidMatch[1] !== '0') pid = Number(pidMatch[1]);\n const stateMatch = /^ActiveState=(\\S+)/m.exec(out);\n if (stateMatch) activeState = stateMatch[1] ?? 'unknown';\n } catch (err) {\n return {\n kind: 'installed',\n pid: null,\n details: `Unit: ${LINUX_SYSTEM_UNIT_PATH} (could not query systemd: ${(err as Error).message})`,\n };\n }\n return { kind: 'installed', pid, details: `Unit: ${LINUX_SYSTEM_UNIT_PATH} (${activeState})` };\n}\n\n/**\n * ENG-6698: ExecStartPre self-heal for a missing/dangling `agt` binary.\n *\n * The incident (agt-aws-1, full-fleet outage): a CLI self-update killed\n * mid-`npm i -g` (npm removes the old package before writing the new) left\n * `/usr/bin/agt` a dangling symlink, so `ExecStart` failed with 203/EXEC and\n * systemd crash-looped the unit to `failed`. With no recovery path the whole\n * fleet went dark until an operator manually reinstalled over SSM.\n *\n * This guard runs before every `ExecStart`: if `agt --version` won't run, it\n * reinstalls the pinned version (ENG-7833, from the unit's AGT_CLI_PIN_VERSION\n * env) or, when unpinned, the SAME release channel (AGT_CLI_RELEASE_CHANNEL,\n * default `latest`) before the manager starts, so a dangling binary self-heals\n * on the next start attempt instead of latching to `failed` with no way back.\n * Preferring the pin here matters: reinstalling the channel tip on a pinned\n * host would silently un-pin it.\n *\n * Two escaping notes that are load-bearing:\n * - systemd does its OWN `${VAR}` expansion on Exec lines (and does not\n * support the POSIX `:-default` form), so every shell `$` is written as\n * `$$` to pass through verbatim to /bin/sh, which then does the\n * `${VAR:-latest}` expansion itself.\n * - the script is one single-quoted `/bin/sh -c` argument with no single\n * quotes inside; `agtBin` is a filesystem path (no single quotes on our\n * hosts) and is double-quoted so a stray space can't split the arg.\n *\n * ENG-11695 (loyalty-host-2, 26 Oct): a reinstall alone can't work on a full\n * disk, or fix a self-referencing link. So when the binary won't run, this now\n * makes room first and relinks afterwards. A healthy host still takes the first\n * `--version` and runs none of it.\n *\n * It has to be inline shell. It runs precisely when `agt` won't execute, so it\n * can't call into this package, and a helper script on disk would add a way for\n * the unit to fail that a healthy host doesn't have today.\n *\n * `procRoot` exists for tests, so they read a fixture and not a shared host's\n * real processes.\n */\nexport function buildSystemUnitRepairExecStartPre(\n agtBin: string,\n user: string,\n opts: { procRoot?: string } = {},\n): string {\n const sudo = user === 'root' ? '' : 'sudo -n ';\n const proc = opts.procRoot ?? '/proc';\n const bin = '\"' + agtBin + '\"';\n // ENG-7833: prefer the pin (AGT_CLI_PIN_VERSION) over the channel so a\n // dangling-binary repair reinstalls the PINNED version, not the channel tip;\n // otherwise the repair would silently un-pin the host on the next start.\n // Nested POSIX `:-`: pin if set, else channel, else `latest`.\n const versionExpansion = '${AGT_CLI_PIN_VERSION:-${AGT_CLI_RELEASE_CHANNEL:-latest}}';\n const installSpec = '\"@integrity-labs/agt-cli@' + versionExpansion + '\"';\n\n // Written as plain POSIX sh, then every `$` is doubled at the end. The unit\n // line constrains what can appear here: no single quote (it would end the\n // `sh -c` argument), no backslash (systemd unescapes inside quotes), and no\n // `%` (systemd specifiers). That is why `tr` takes `[:cntrl:]`, not `\\000`,\n // and why the root comparison is `-ef`, not `stat -c`.\n const script = [\n bin + ' --version >/dev/null 2>&1 || {',\n 'echo \"[agt-manager] agt binary missing/dangling - reinstalling @integrity-labs/agt-cli@' +\n versionExpansion +\n '\";',\n\n // ENG-11695: the shell twin of `anyPackageInstallRunning` and\n // `isPackageInstallArgv` in disk-guard.ts, because this runs when `agt`\n // cannot, so it cannot call them. Cleaning a package cache under a running\n // install can cost that install its binary (Obi Wan b8ed1339eaf2). Same\n // rules: the process itself must be npm/pnpm, a container's install does\n // not count, and a root or a /proc that cannot be read counts as busy. Also the\n // same limit: a non-root manager under `hidepid` can't see root's installs. The\n // fleet's manager runs as root, which hidepid doesn't restrict.\n 'busy() {',\n '[ -r ' + proc + '/self/cmdline ] || return 0;',\n 'for p in ' + proc + '/[0-9]*; do',\n 'c=$(tr \"[:cntrl:]\" \" \" < \"$p/cmdline\" 2>/dev/null) || continue;',\n 'set -f; set -- $c; set +f;',\n '[ $# -gt 0 ] || continue;',\n 'case \"${1##*/}\" in npm|pnpm) shift ;; node|nodejs) case \"${2##*/}\" in npm|npm-cli.js|pnpm|pnpm.js|pnpm.cjs) shift 2 ;; *) continue ;; esac ;; *) continue ;; esac;',\n 'n=0; for a in \"$@\"; do',\n 'case \"$a\" in -*) continue ;; esac;',\n 'case \"$a\" in',\n 'install|i|ci|add|update|upgrade|up) { [ ! -e \"$p/root\" ] || [ \"$p/root\" -ef / ]; } && return 0; break ;;',\n 'run|run-script|exec|x|dlx|test|start) [ \"$n\" = 0 ] && break ;;',\n 'esac;',\n 'n=$((n+1)); [ \"$n\" -ge 2 ] && break;',\n 'done;',\n 'done; return 1; };',\n 'pkgclean() { if busy; then echo \"[agt-manager] skipping $* - an npm/pnpm install is running\"; else \"$@\" >/dev/null 2>&1 || true; fi; };',\n\n // ENG-11695 ask 2: the same safe cleanup as SAFE_CLEANUP_STEPS, at the same\n // threshold as SELF_UPDATE_MIN_FREE_BYTES (1 GiB in KiB). Caches and logs\n // only, nothing deleted by path. Unlike the self-update guard this never\n // refuses the install: the binary is already broken, so there is nothing\n // left for a failed install to lose. A `df` that fails reads as low.\n 'set -- $(df -Pk / 2>/dev/null | tail -1);',\n 'if [ \"${4:-0}\" -lt 1048576 ]; then',\n 'echo \"[agt-manager] under 1 GiB free - running safe cleanup before reinstalling\";',\n // `timeout` goes INSIDE sudo: sudo forwards TERM but can't forward KILL, so a\n // `timeout` outside it kills sudo and leaves the step running, possibly into\n // the install below (Obi Wan 95130c6e0a21).\n sudo + 'timeout -k 10 120 journalctl --vacuum-size=200M >/dev/null 2>&1 || true;',\n 'pkgclean timeout -k 10 120 npm cache clean --force;',\n 'pkgclean timeout -k 10 120 pnpm store prune;',\n ...(sudo ? ['pkgclean sudo -n -H timeout -k 10 120 npm cache clean --force;'] : []),\n 'fi;',\n\n sudo + 'npm install -g ' + installSpec + ' --registry=https://registry.npmjs.org;',\n\n // ENG-11695 ask 1: npm does not always rewrite a link it did not create, so\n // a dangling or self-referencing one can survive a good install. Only ever\n // a link or nothing: a real file at this path is not ours to replace.\n 'if ! ' + bin + ' --version >/dev/null 2>&1; then',\n 't=\"$(' + sudo + 'npm root -g 2>/dev/null)/@integrity-labs/agt-cli/dist/bin/agt.js\";',\n 'if [ -f \"$t\" ] && { [ -L ' + bin + ' ] || [ ! -e ' + bin + ' ]; }; then',\n 'echo \"[agt-manager] relinking ' + agtBin + ' to $t\";',\n sudo + 'ln -sfn \"$t\" ' + bin + ';',\n 'fi;',\n 'fi;',\n\n // The exit status of the whole repair: did it work?\n bin + ' --version >/dev/null 2>&1;',\n '}',\n ].join(' ');\n\n // systemd does its own ${VAR} expansion, so `$` has to reach it as `$$`.\n return \"ExecStartPre=/bin/sh -c '\" + script.replace(/\\$/g, '$$$$') + \"'\";\n}\n\n/**\n * ENG-11695 ask 3: get out of `failed`.\n *\n * Once StartLimitBurst trips, systemd stops trying, and the ExecStartPre repair\n * above never runs again. A timer rather than `OnFailure=`, because a timer's\n * cadence is the bound: at most one episode (StartLimitBurst starts) per\n * interval, whatever the failure does. `OnFailure=` fires on each failure and\n * would need its own limit.\n *\n * `is-failed` leaves a clean `systemctl stop` alone, because that ends `inactive`.\n * It can't tell an operator's stop from a crash once the unit is `failed`, and a\n * stop can end there two ways: the manager was already `failed` (Obi Wan\n * 9ec9691edd4b), or its drain hung and the 15s backstop in stopPolling exited 1\n * (Obi Wan 08df74eca266). So a deliberate hold always means stopping this timer\n * too, and docs/host-infra/README.md says so.\n *\n * Don't close that gap with SuccessExitStatus=1: under Restart=on-failure a real\n * crash that exits 1 would then never restart. And don't filter on the unit's\n * Result here without testing it on a host. A filter that misses what a latched\n * unit actually reports turns off this recovery with no signal, and that costs far\n * more than a hung stop coming back.\n */\nconst RECOVER_INTERVAL = '15min';\n\nfunction renderLinuxRecoverService(): string {\n return `# agt manager recovery (ENG-11695)\n# Managed by \\`agt manager install-system-unit\\` — edits will be overwritten.\n\n[Unit]\nDescription=Restart the Augmented host manager if systemd has latched it to failed\n\n[Service]\nType=oneshot\nExecStart=/bin/sh -c 'systemctl is-failed --quiet ${LINUX_UNIT_NAME} || exit 0; echo \"[agt-manager-recover] ${LINUX_UNIT_NAME} is failed - resetting and starting\"; systemctl reset-failed ${LINUX_UNIT_NAME}; systemctl start --no-block ${LINUX_UNIT_NAME}'\n`;\n}\n\nfunction renderLinuxRecoverTimer(): string {\n return `# agt manager recovery timer (ENG-11695)\n# Managed by \\`agt manager install-system-unit\\` — edits will be overwritten.\n\n[Unit]\nDescription=Check every ${RECOVER_INTERVAL} whether the Augmented host manager is latched to failed\n\n[Timer]\nOnBootSec=${RECOVER_INTERVAL}\nOnUnitActiveSec=${RECOVER_INTERVAL}\nUnit=${LINUX_RECOVER_SERVICE_NAME}\n\n[Install]\nWantedBy=timers.target\n`;\n}\n\nfunction renderLinuxSystemUnit(opts: InstallSystemUnitOpts): string {\n const user = opts.user ?? 'root';\n const home = user === 'root' ? '/root' : `/home/${user}`;\n\n // Non-secret env stays in the unit body via Environment= lines;\n // secrets are pulled from EnvironmentFile= written separately.\n const envLines = Object.entries(opts.env)\n .filter(([k, v]) => k.length > 0 && v != null && !LINUX_SECRET_ENV_KEYS.has(k))\n .map(([k, v]) => `Environment=\"${k}=${escapeForSystemdEnv(v)}\"`)\n .join('\\n');\n\n const execArgs = [\n opts.agtBin,\n 'manager',\n 'start',\n '--interval',\n String(opts.intervalSec),\n '--config-dir',\n opts.configDir,\n ]\n .map(shellQuoteForSystemd)\n .join(' ');\n\n const logPath = join(opts.configDir, 'manager.log');\n\n return `# agt manager supervisor — system unit (ENG-4706)\n# Managed by \\`agt manager install-system-unit\\` — edits will be overwritten.\n#\n# Unlike the sibling --user unit at ~/.config/systemd/user/agt-manager.service,\n# this one is enabled into multi-user.target so it auto-starts on every\n# boot regardless of any user login. Use this on EC2 / headless hosts.\n\n[Unit]\nDescription=Augmented host manager daemon\nAfter=network-online.target\nWants=network-online.target\n# ENG-6698: widened from 5/60s. The ExecStartPre repair below reinstalls a\n# dangling agt binary on each start attempt (~7s of npm + RestartSec), so a\n# transient miss needs several attempts within the window to self-heal before\n# systemd would otherwise latch the unit to \\`failed\\`. 10 tries / 5 min gives\n# the repair room to recover without spinning forever on a genuinely broken host.\n# ENG-11695: if it does latch, ${LINUX_RECOVER_TIMER_NAME} starts another round.\nStartLimitBurst=10\nStartLimitIntervalSec=300\n\n[Service]\nType=simple\nUser=${user}\nWorkingDirectory=${opts.configDir}\nEnvironment=\"HOME=${home}\"\n${envLines}\nEnvironmentFile=${LINUX_SYSTEM_ENV_FILE_PATH}\n# ENG-6698: self-heal a missing/dangling agt binary before starting, so an\n# interrupted self-update can't latch the unit to \\`failed\\` with no recovery.\n${buildSystemUnitRepairExecStartPre(opts.agtBin, user)}\nExecStart=${execArgs}\n# ENG-11695: this limit covers ExecStartPre, and the default 90s can't fit the\n# repair on a full disk. Worst case is 4 cleanup steps x 130s (each under its own\n# \\`timeout -k 10 120\\`, so one that ignores TERM still can't eat the budget) plus\n# 200s for npm. A hung npm is killed here and retried. A healthy start never gets\n# close.\nTimeoutStartSec=720\n\n# on-failure (not always) so a clean \\`systemctl stop\\` doesn't fight a\n# respawn loop. The ExecStartPre repair + the widened StartLimit above turn a\n# dangling-binary crashloop into a self-healing one. Logs land in ${logPath}\n# via the manager's own writer plus journalctl -u ${LINUX_UNIT_NAME}.\nRestart=on-failure\nRestartSec=5\n\nStandardOutput=append:${logPath}\nStandardError=append:${logPath}\n\n[Install]\nWantedBy=multi-user.target\n`;\n}\n\n// ---------------------------------------------------------------------------\n// Rotating AGT_API_KEY in the channels a FUTURE manager process reads\n// (ENG-11642)\n// ---------------------------------------------------------------------------\n//\n// THE SUPERVISOR'S OWN CHANNEL IS THE LOAD-BEARING ONE, and it is not\n// `/etc/environment`. Obi Wan (`188bcf0cc47f`, `a43136702405`) found the first\n// version of the rotation persisting only to `/etc/environment` and\n// `/etc/profile.d/agt.sh` — neither of which any supervisor reads:\n//\n// - the system unit : `EnvironmentFile=/etc/agt/agt-manager.env`\n// - the --user unit : `EnvironmentFile=~/.config/systemd/user/agt-manager.env`\n// - the launchd job : `AGT_API_KEY` baked into the plist's EnvironmentVariables\n//\n// `LINUX_SECRET_ENV_KEYS` strips the key out of the units' inline `Environment=`\n// lines precisely so it comes from the env file instead, and both env files are\n// written ONLY by install. So a rotation that skipped them left the running\n// process working and the next `systemctl restart` — a crash, a reboot, or the\n// frequent CLI self-update restart — booting on the key the ack had just\n// expired. That is the delayed, apparently-unconnected outage the persist-first\n// ordering exists to prevent, moved rather than removed.\n//\n// Rewrite in place rather than re-rendering: `renderLinuxEnvFile` emits\n// AGT_API_KEY alone, and the comment at `manager.ts`'s install-system-unit call\n// records that hosts have hand-added isolation vars to that file and lose them\n// on the next install. A rotation must not repeat that — so only the\n// AGT_API_KEY line moves and every other byte is preserved.\n\n/** What `rewriteSupervisorApiKey` managed to do, per channel. */\nexport interface SupervisorKeyRewrite {\n /** Channels that carried an `AGT_API_KEY` and now carry the new one. */\n rewritten: string[];\n /**\n * Channels that exist and carry an `AGT_API_KEY` this function could not\n * safely leave pointing at the new key. Non-empty means some future process\n * would boot on the OLD key, so the caller must not ack the rotation.\n *\n * It covers three different things on purpose, because the caller's decision\n * is the same for all of them: a write that failed, a file that could not be\n * STATTED or read, and a channel this function refuses to touch at all (the\n * launchd plist — see `refusePlistApiKey`).\n */\n failed: Array<{ path: string; error: string }>;\n /**\n * Channels present on this host that define no `AGT_API_KEY`. They never\n * supplied one, so there is nothing to rotate there — recorded rather than\n * dropped so \"no channel holds the key\" is distinguishable from \"every\n * channel was updated\".\n */\n keyless: string[];\n /**\n * Channels rewritten to the new key and then put BACK to `rollbackTo`\n * because another channel failed. Present only when a rollback key was given.\n */\n rolledBack?: string[];\n}\n\n/** What one channel's handler decided about a file it has just read. */\ntype ChannelDecision =\n /** This file defines no `AGT_API_KEY`; it never supplied one. */\n | { kind: 'no-key' }\n /** Write this text back. */\n | { kind: 'rewrite'; text: string }\n /**\n * This file holds the key and must NOT be rewritten in place. Rewriting it\n * would look like success and leave the key unreachable — worse than failing.\n */\n | { kind: 'refuse'; reason: string };\n\n/**\n * systemd's EnvironmentFile grammar is one `KEY=value` per line, so the line is\n * replaced wholesale. `gm` because a file with two AGT_API_KEY lines would have\n * systemd take the LAST — leaving either behind leaves the old key reachable.\n */\nconst ENV_FILE_API_KEY_LINE = /^[ \\t]*(?:export[ \\t]+)?AGT_API_KEY[ \\t]*=.*$/gm;\n\nfunction rewriteEnvFileApiKey(text: string, rawKey: string): ChannelDecision {\n ENV_FILE_API_KEY_LINE.lastIndex = 0;\n if (!ENV_FILE_API_KEY_LINE.test(text)) return { kind: 'no-key' };\n ENV_FILE_API_KEY_LINE.lastIndex = 0;\n // Function replacement, not a string: `$&` and friends are special in a\n // replacement string, and a key is not a place to find out.\n return {\n kind: 'rewrite',\n text: text.replace(ENV_FILE_API_KEY_LINE, () => `AGT_API_KEY=${rawKey}`),\n };\n}\n\nconst PLIST_API_KEY_VALUE = /<key>AGT_API_KEY<\\/key>\\s*<string>[^<]*<\\/string>/;\n\n/**\n * REFUSES the launchd plist rather than rewriting it, and that is the whole\n * point of this function.\n *\n * CodeRabbit on #7114. Editing the file is necessary and NOT sufficient:\n * `launchctl load` reads the plist once and launchd then serves the registered\n * job definition, so a `KeepAlive` respawn starts the manager with the\n * `AGT_API_KEY` launchd already holds — the old one. Only `launchctl unload` +\n * `load` re-reads it, and unload STOPS the running job, which here is the\n * manager performing the rotation.\n *\n * So a plist rewrite is the worst of the three outcomes: the persist reports\n * success, the ack expires the outgoing key, and the host keeps running on a\n * credential that dies at its next respawn. Refusing instead abandons the\n * rotation with a log line and leaves a working key in force.\n *\n * WHAT IS MISSING, so the next reader does not have to re-derive it: a reload\n * that survives stopping its own process — a detached helper that unloads,\n * loads, and lets the new job start. (The pending ack is persisted across a\n * restart now, so that half exists.) The helper does not, and\n * inventing them inside a review round is how a rotation fix becomes an outage.\n * A macOS host under `agt manager install` therefore cannot routine-rotate;\n * `reason: 'compromised'` is unaffected, since that path never self-rotates.\n */\nfunction refusePlistApiKey(text: string, _rawKey: string): ChannelDecision {\n if (!PLIST_API_KEY_VALUE.test(text)) return { kind: 'no-key' };\n return {\n kind: 'refuse',\n reason:\n 'launchd serves the job definition it loaded, so rewriting the plist would not reach a KeepAlive respawn; a rotation here needs an unload+load this process cannot survive',\n };\n}\n\n/** One channel a supervisor may inject `AGT_API_KEY` from. */\nexport interface SupervisorKeyChannel {\n path: string;\n decide: (text: string, rawKey: string) => ChannelDecision;\n /**\n * The `AGT_API_KEY` this channel would hand the next start, or null. Lets the\n * preflight tell the channel that launched this manager from a stale one\n * that merely sits on disk. A channel without it counts as a key holder\n * whenever it holds a key.\n */\n heldKey?: (text: string) => string | null;\n}\n\n/** The value systemd would read: the LAST `AGT_API_KEY=` line, unquoted. */\nfunction envFileHeldKey(text: string): string | null {\n const lines = [...text.matchAll(ENV_FILE_API_KEY_LINE)];\n const last = lines.at(-1)?.[0];\n if (last === undefined) return null;\n const value = last.slice(last.indexOf('=') + 1).trim();\n const unquoted = /^([\"'])(.*)\\1$/.exec(value)?.[2] ?? value;\n return unquoted || null;\n}\n\nconst SUPERVISOR_KEY_CHANNELS: ReadonlyArray<SupervisorKeyChannel> = [\n { path: MACOS_PLIST, decide: refusePlistApiKey },\n { path: LINUX_ENV_FILE_PATH, decide: rewriteEnvFileApiKey, heldKey: envFileHeldKey },\n { path: LINUX_SYSTEM_ENV_FILE_PATH, decide: rewriteEnvFileApiKey, heldKey: envFileHeldKey },\n];\n\n/**\n * Write via a temp file in the SAME directory then rename, so a crash or a full\n * disk mid-write cannot leave a supervisor env file holding half a key — which\n * no process could authenticate with and nothing would report.\n *\n * All three channels are mode 0600 at install, and `rename` takes the temp\n * file's mode, so the temp file is created 0600 rather than relying on the\n * chmod afterwards.\n */\nfunction writePrivateAtomic(path: string, text: string): void {\n const tmp = `${path}.agt-rotate.${process.pid}.tmp`;\n writeFileSync(tmp, text, { mode: 0o600 });\n try {\n renameSync(tmp, path);\n } catch (err) {\n bestEffort(() => unlinkSync(tmp));\n throw err;\n }\n chmodSync(path, 0o600);\n}\n\n/**\n * Whether a channel file is PRESENT, distinguishing \"absent\" from \"cannot tell\".\n *\n * `existsSync` collapses those two, and CodeRabbit on #7114 found the\n * consequence: `/etc/agt` is mode 0700 root-owned, so a manager running as a\n * non-root `User=` gets EACCES on the lookup, `existsSync` returns false, and\n * the channel holding the outgoing key is SKIPPED — with no `failed` entry, so\n * the persist reports success and the ack expires a key that file still names.\n * A silent skip inside the fix for a silent failure.\n *\n * ONLY ENOENT means absent. Everything else is an error the caller must see —\n * including ENOTDIR, which here means a path component that should be a\n * directory is a file, i.e. a broken host rather than a supervisor that is\n * simply not installed.\n */\nfunction channelPresence(path: string): 'absent' | 'present' | { error: string; permanent: boolean } {\n try {\n statSync(path);\n return 'present';\n } catch (err) {\n const code = (err as NodeJS.ErrnoException)?.code;\n if (code === 'ENOENT') return 'absent';\n return {\n error: `${code ?? 'stat failed'}: cannot tell whether this channel holds AGT_API_KEY`,\n permanent: isPermanentFsError(code),\n };\n }\n}\n\n/**\n * Filesystem errors that the next attempt will hit again. A preflight that\n * skips one of these does not save a retry; it guarantees the persist fails\n * after the mint, every time. On a non-root `User=` manager, `/etc/agt` (0700,\n * root-owned) gives EACCES on every attempt, and a broken path gives ENOTDIR on\n * every attempt (CodeRabbit and Obi Wan `a2fca737943f` / `9bb183e7d09e` on\n * #7114). Anything outside this set is treated as transient.\n */\nconst PERMANENT_FS_ERROR_CODES: ReadonlySet<string> = new Set([\n 'EACCES',\n 'EPERM',\n 'ENOTDIR',\n 'EISDIR',\n 'ELOOP',\n 'ENAMETOOLONG',\n]);\n\nfunction isPermanentFsError(code: string | undefined): boolean {\n return code !== undefined && PERMANENT_FS_ERROR_CODES.has(code);\n}\n\n/**\n * Which supervisor channels would REFUSE a rotated key, read-only.\n *\n * Exists so the caller can find out before minting anything. `rewriteSupervisorApiKey`\n * can only answer the question by doing the work, and on a macOS host the answer\n * is always \"refused\" — so without this the mint happens first, every retry\n * inserts another active key, and the host walks into the server-side cap and\n * 409s permanently (CodeRabbit on #7114).\n *\n * A channel is reported when its write is CERTAIN to fail: the decision refuses\n * it (the launchd plist), or it cannot be statted or read for a reason the next\n * attempt will hit again (`PERMANENT_FS_ERROR_CODES`). A transient stat or read\n * error is still not a reason to skip a mint — the retry may well succeed, and\n * refusing on it would turn a blip into a host that never rotates. If one then\n * fails the persist, the manager keeps the minted key and retries with it.\n *\n * `requireKeyHolder` refuses when NO channel holds `AGT_API_KEY`. That host's\n * manager was started by hand or from a container's environment, and nothing\n * here can change what its next launch reads, so a rotation it acked would\n * leave the next start on the expired key (CodeRabbit on #7114). An earlier\n * version fell back to `/etc/environment`, which `agt manager start` never\n * reads. A channel skipped on a transient error counts as possibly holding the\n * key, so it never triggers this.\n *\n * Passed as `{ runningKeys }`, a channel only counts if the key it holds is one\n * of them: the key this manager is running on, or one it minted for this\n * request. A stale unit file left behind by another install, next to a manager\n * started by hand, holds a different key, and would otherwise vouch for a\n * launch it does not perform (CodeRabbit on #7114). The keys are compared in\n * memory and never logged. A stale file holding the SAME key as a manager\n * started by hand is not caught: nothing on disk tells the two apart.\n */\nexport function supervisorChannelsRefusing(\n channels: ReadonlyArray<SupervisorKeyChannel> = SUPERVISOR_KEY_CHANNELS,\n requireKeyHolder: boolean | { runningKeys: ReadonlyArray<string> } = false,\n): string[] {\n const runningKeys =\n typeof requireKeyHolder === 'object' ? requireKeyHolder.runningKeys.filter((k) => k) : null;\n const refusals: string[] = [];\n let mayHoldKey = false;\n for (const channel of channels) {\n const presence = channelPresence(channel.path);\n if (presence === 'absent') continue;\n if (presence !== 'present') {\n if (presence.permanent) refusals.push(`${channel.path}: ${presence.error}`);\n else mayHoldKey = true;\n continue;\n }\n let current: string;\n try {\n current = readFileSync(channel.path, 'utf-8');\n } catch (err) {\n const code = (err as NodeJS.ErrnoException)?.code;\n if (isPermanentFsError(code)) {\n refusals.push(`${channel.path}: unreadable (${code})`);\n } else {\n mayHoldKey = true;\n }\n continue;\n }\n // The raw key is irrelevant to a refusal, and passing a real one into a\n // read-only probe would be handing a credential to code that has no use\n // for it. The decision functions only inspect the file.\n const decision = channel.decide(current, '');\n if (decision.kind === 'refuse') {\n refusals.push(`${channel.path}: ${decision.reason}`);\n } else if (decision.kind !== 'no-key') {\n const held = channel.heldKey ? channel.heldKey(current) : undefined;\n const launchedThisManager =\n runningKeys === null || held === undefined || (held !== null && runningKeys.includes(held));\n if (launchedThisManager) mayHoldKey = true;\n }\n }\n if (refusals.length === 0 && !mayHoldKey && requireKeyHolder) {\n refusals.push(\n runningKeys === null\n ? 'no supervisor channel holds AGT_API_KEY, so nothing would hand the new key to the next manager start'\n : 'no supervisor channel holds the key this manager is running on, so none of them launched it and nothing would hand the new key to its next start',\n );\n }\n return refusals;\n}\n\n/**\n * Point every supervisor channel on this host at a rotated `AGT_API_KEY`.\n *\n * Keyed on the file being PRESENT rather than on `process.platform`, because\n * the two Linux unit kinds are documented as co-existing — a host carrying both\n * must have both handled, and reading the platform would update one.\n *\n * Fails closed per channel, in every direction: a channel that cannot be\n * statted, cannot be read, cannot be written, or must not be written lands in\n * `failed`, because each of those means a file may still be naming the\n * outgoing key.\n */\nexport function rewriteSupervisorApiKey(\n rawKey: string,\n /**\n * Overridden ONLY by tests. The real list is three absolute paths — two of\n * them outside any temp directory — so the behaviour (preserve every other\n * line, replace all occurrences, mode 0600, write-then-rename, refuse the\n * plist) is only observable against channels a test owns. The real list is\n * pinned separately by `the channel list covers every supervisor this CLI\n * installs`, so an injected list cannot make the paths themselves untested.\n */\n channels: ReadonlyArray<SupervisorKeyChannel> = SUPERVISOR_KEY_CHANNELS,\n /**\n * The key to put back on channels already rewritten when ANOTHER channel\n * fails, so a failed persist leaves no channel half-switched (Obi Wan\n * `c967f8929b33` on #7114). Without it, a host with two channels where one\n * failed restarted on the minted key with no memory of minting it; its next\n * mint got 409 and the rotation stayed armed for good.\n */\n rollbackTo?: string,\n): SupervisorKeyRewrite {\n const out: SupervisorKeyRewrite = { rewritten: [], failed: [], keyless: [] };\n for (const channel of channels) {\n const presence = channelPresence(channel.path);\n if (presence === 'absent') continue;\n if (presence !== 'present') {\n out.failed.push({ path: channel.path, error: presence.error });\n continue;\n }\n let current: string;\n try {\n current = readFileSync(channel.path, 'utf-8');\n } catch (err) {\n out.failed.push({\n path: channel.path,\n error: `unreadable: ${(err as Error)?.message ?? String(err)}`,\n });\n continue;\n }\n const decision = channel.decide(current, rawKey);\n if (decision.kind === 'no-key') {\n out.keyless.push(channel.path);\n continue;\n }\n if (decision.kind === 'refuse') {\n out.failed.push({ path: channel.path, error: `refused: ${decision.reason}` });\n continue;\n }\n if (decision.text === current) {\n // Already this key — a re-run of a persist whose write landed before the\n // ack did. Counted as rewritten: the channel holds the new key, which is\n // the only thing the caller is asking about.\n out.rewritten.push(channel.path);\n continue;\n }\n try {\n writePrivateAtomic(channel.path, decision.text);\n out.rewritten.push(channel.path);\n } catch (err) {\n out.failed.push({ path: channel.path, error: (err as Error)?.message ?? String(err) });\n }\n }\n if (rollbackTo && out.failed.length > 0 && out.rewritten.length > 0) {\n const rewrittenPaths = new Set(out.rewritten);\n const back = rewriteSupervisorApiKey(\n rollbackTo,\n channels.filter((c) => rewrittenPaths.has(c.path)),\n );\n out.rolledBack = back.rewritten;\n for (const f of back.failed) {\n out.failed.push({ path: f.path, error: `rollback to the running key failed: ${f.error}` });\n }\n out.rewritten = out.rewritten.filter((p) => !back.rewritten.includes(p));\n }\n return out;\n}\n\n// Exposed for unit tests / introspection.\nexport const _internals = {\n MACOS_LABEL,\n MACOS_PLIST,\n LINUX_UNIT_NAME,\n LINUX_UNIT_PATH,\n LINUX_ENV_FILE_PATH,\n LINUX_SYSTEM_UNIT_PATH,\n LINUX_SYSTEM_ENV_FILE_PATH,\n LINUX_SECRET_ENV_KEYS,\n renderMacosPlist,\n renderLinuxUnit,\n renderLinuxSystemUnit,\n renderLinuxRecoverService,\n renderLinuxRecoverTimer,\n LINUX_RECOVER_SERVICE_NAME,\n LINUX_RECOVER_TIMER_NAME,\n LINUX_RECOVER_SERVICE_PATH,\n LINUX_RECOVER_TIMER_PATH,\n renderLinuxEnvFile,\n rewriteEnvFileApiKey,\n refusePlistApiKey,\n envFileHeldKey,\n channelPresence,\n isPermanentFsError,\n SUPERVISOR_KEY_CHANNELS,\n escapeXml,\n escapeForSystemdEnv,\n shellQuoteForSystemd,\n readPlist: () => (existsSync(MACOS_PLIST) ? readFileSync(MACOS_PLIST, 'utf-8') : null),\n readUnit: () => (existsSync(LINUX_UNIT_PATH) ? readFileSync(LINUX_UNIT_PATH, 'utf-8') : null),\n readSystemUnit: () => (existsSync(LINUX_SYSTEM_UNIT_PATH) ? readFileSync(LINUX_SYSTEM_UNIT_PATH, 'utf-8') : null),\n readEnvFile: () => (existsSync(LINUX_ENV_FILE_PATH) ? readFileSync(LINUX_ENV_FILE_PATH, 'utf-8') : null),\n readSystemEnvFile: () => (existsSync(LINUX_SYSTEM_ENV_FILE_PATH) ? readFileSync(LINUX_SYSTEM_ENV_FILE_PATH, 'utf-8') : null),\n};\n"],"mappings":";AA8BA,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,gBAAgB;AAClC,SAAS,SAAS,YAAY;AAI9B,IAAM,cAAc;AACpB,IAAM,cAAc,KAAK,QAAQ,GAAG,WAAW,gBAAgB,GAAG,WAAW,QAAQ;AAKrF,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,KAAK,QAAQ,GAAG,WAAW,WAAW,QAA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iBAAiB,OAAO,IAAI;AAAA,EACxF,gBAAgB,MAAO,WAAW,sBAAsB,IAAI,aAAa,wBAAwB,OAAO,IAAI;AAAA,EAC5G,aAAa,MAAO,WAAW,mBAAmB,IAAI,aAAa,qBAAqB,OAAO,IAAI;AAAA,EACnG,mBAAmB,MAAO,WAAW,0BAA0B,IAAI,aAAa,4BAA4B,OAAO,IAAI;AACzH;","names":[]}
@@ -13,9 +13,9 @@ import {
13
13
  probeClaudeInstalls,
14
14
  readsAsNativeInstall,
15
15
  shouldRunClaudeCodeUpdater
16
- } from "./chunk-C35ONIOM.js";
16
+ } from "./chunk-4VFHXY7W.js";
17
17
  import "./chunk-XWVM4KPK.js";
18
- import "./chunk-DTGNYXYM.js";
18
+ import "./chunk-JYBRZAAK.js";
19
19
  import "./chunk-AIUIMEUS.js";
20
20
  import "./chunk-DGUM43GV.js";
21
21
  export {
@@ -34,4 +34,4 @@ export {
34
34
  readsAsNativeInstall,
35
35
  shouldRunClaudeCodeUpdater
36
36
  };
37
- //# sourceMappingURL=claude-code-updater-QRAOQLXJ.js.map
37
+ //# sourceMappingURL=claude-code-updater-OLV2OEVG.js.map
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  redactPaneFrame,
12
12
  sanitizeTerminalFrame
13
- } from "./chunk-DTGNYXYM.js";
13
+ } from "./chunk-JYBRZAAK.js";
14
14
  import {
15
15
  CLAUDE_CONFIG_DIR_ENV,
16
16
  claudeConfigDirFor,
@@ -323,7 +323,7 @@ async function spawnPairSession(session) {
323
323
  return { ok: true };
324
324
  } catch {
325
325
  }
326
- const { resolveClaudeBinary } = await import("./persistent-session-ADLDX7QL.js");
326
+ const { resolveClaudeBinary } = await import("./persistent-session-K5WFQVXD.js");
327
327
  const claudeBin = resolveClaudeBinary();
328
328
  const pairEnv = {
329
329
  ...process.env,
@@ -838,4 +838,4 @@ export {
838
838
  startClaudePair,
839
839
  submitClaudePairCode
840
840
  };
841
- //# sourceMappingURL=claude-pair-runtime-ZI2LPY5E.js.map
841
+ //# sourceMappingURL=claude-pair-runtime-QA3AUNBF.js.map
@@ -70,7 +70,7 @@ import {
70
70
  tripClass,
71
71
  writeEtcEnvironment,
72
72
  writeProfileDScript
73
- } from "../chunk-LNLKOJC5.js";
73
+ } from "../chunk-ABU3BOHU.js";
74
74
  import {
75
75
  ApiError,
76
76
  adoptHostKeyInProcess,
@@ -88,7 +88,7 @@ import {
88
88
  probeHostKey,
89
89
  requireHost,
90
90
  setConfigHash
91
- } from "../chunk-NYBVFW7X.js";
91
+ } from "../chunk-NBIS2LOE.js";
92
92
  import {
93
93
  BLOCKED_ON_PROMPT_DECISION,
94
94
  CHANNEL_SECRET_ENV_KEYS,
@@ -185,7 +185,7 @@ import {
185
185
  webFetchBaselineValue,
186
186
  webFetchRestartNeeded,
187
187
  writeEgressAllowlist
188
- } from "../chunk-AATR5MO7.js";
188
+ } from "../chunk-BSZRE4X6.js";
189
189
  import {
190
190
  isAgentIdle,
191
191
  isStaleForToday,
@@ -197,7 +197,7 @@ import {
197
197
  subagentActivityAgeSeconds,
198
198
  subagentTranscriptDir,
199
199
  transcriptActivityAgeSeconds
200
- } from "../chunk-PRSMP7YW.js";
200
+ } from "../chunk-JX4S7KFB.js";
201
201
  import {
202
202
  classifyUnanswerablePane,
203
203
  focusedConfirmDialogBlock,
@@ -223,7 +223,7 @@ import {
223
223
  runSafeCleanup,
224
224
  tightestDiskStat,
225
225
  withPackageCacheLock
226
- } from "../chunk-C35ONIOM.js";
226
+ } from "../chunk-4VFHXY7W.js";
227
227
  import {
228
228
  parsePsRows,
229
229
  reapOrphanChannelMcps
@@ -352,7 +352,7 @@ import {
352
352
  stabiliseResetInstant,
353
353
  sumTranscriptUsageInWindow,
354
354
  summarizeTranscriptActivity
355
- } from "../chunk-DTGNYXYM.js";
355
+ } from "../chunk-JYBRZAAK.js";
356
356
  import {
357
357
  CLAUDE_CONFIG_DIR_ENV,
358
358
  claudeConfigDirFor,
@@ -363,7 +363,7 @@ import {
363
363
  import {
364
364
  rewriteSupervisorApiKey,
365
365
  supervisorChannelsRefusing
366
- } from "../chunk-H3JMPEH7.js";
366
+ } from "../chunk-ZE6WANYK.js";
367
367
  import {
368
368
  catchUpNote,
369
369
  describeCatchUp,
@@ -16045,7 +16045,7 @@ function createFileMigrationReportIO(codeName, log2) {
16045
16045
  };
16046
16046
  }
16047
16047
  var managerHostPost = async (path, body) => {
16048
- const { api: api2, ApiError: ApiError3 } = await import("../api-client-LJIV4E3U.js");
16048
+ const { api: api2, ApiError: ApiError3 } = await import("../api-client-OATI5QPI.js");
16049
16049
  try {
16050
16050
  const json = await api2.post(path, body);
16051
16051
  return { status: 200, json };
@@ -18215,7 +18215,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
18215
18215
  var dayRolloverInboundHold = /* @__PURE__ */ new Map();
18216
18216
  var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
18217
18217
  async function channelInboundActivityAgeSecondsFor(codeName) {
18218
- const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-ETVF2D2O.js");
18218
+ const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-Q5PDMK2L.js");
18219
18219
  const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
18220
18220
  if (newest === null) return null;
18221
18221
  return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
@@ -19126,7 +19126,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
19126
19126
  var lastVersionCheckAt = 0;
19127
19127
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
19128
19128
  var lastResponsivenessProbeAt = 0;
19129
- var agtCliVersion = true ? "0.28.1311" : "dev";
19129
+ var agtCliVersion = true ? "0.28.1313" : "dev";
19130
19130
  function resolveBrewPath(execFileSync5) {
19131
19131
  try {
19132
19132
  const out = execFileSync5("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -21262,7 +21262,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
21262
21262
  if (codeNames.length === 0) return;
21263
21263
  void (async () => {
21264
21264
  try {
21265
- const { collectDiagnostics } = await import("../persistent-session-ADLDX7QL.js");
21265
+ const { collectDiagnostics } = await import("../persistent-session-K5WFQVXD.js");
21266
21266
  await api.post("/host/heartbeat", {
21267
21267
  host_id: hostId,
21268
21268
  agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -21407,7 +21407,7 @@ async function pollCycleInner() {
21407
21407
  }
21408
21408
  try {
21409
21409
  const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
21410
- const { collectDiagnostics } = await import("../persistent-session-ADLDX7QL.js");
21410
+ const { collectDiagnostics } = await import("../persistent-session-K5WFQVXD.js");
21411
21411
  const recordedSinceHeartbeat = new Set(spawnOutcomesSinceHeartbeat.drain());
21412
21412
  const diagCodeNames = heartbeatDiagnosticsCodeNames(agentState.persistentSessionAgents, recordedSinceHeartbeat);
21413
21413
  const heartbeatSpawnOutcomeFor = spawnOutcomeIfRecorded(spawnOutcomeForDiagnostics, recordedSinceHeartbeat);
@@ -21708,7 +21708,7 @@ async function pollCycleInner() {
21708
21708
  }
21709
21709
  try {
21710
21710
  const desiredClaudeCodeVersion = hbResp?.desired_claude_code_version?.trim();
21711
- const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-QRAOQLXJ.js");
21711
+ const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-OLV2OEVG.js");
21712
21712
  const securityFloor = currentSecurityFloor();
21713
21713
  claudeUpdaterInFlight = true;
21714
21714
  if (desiredClaudeCodeVersion && (claudePairLoop.busy || claudePairingInProgress())) {
@@ -21743,7 +21743,7 @@ async function pollCycleInner() {
21743
21743
  collectPanelessActivityProbes,
21744
21744
  getResponsivenessIntervalMs,
21745
21745
  occupancyQualificationClassifications
21746
- } = await import("../responsiveness-probe-ETVF2D2O.js");
21746
+ } = await import("../responsiveness-probe-Q5PDMK2L.js");
21747
21747
  const probeIntervalMs = getResponsivenessIntervalMs();
21748
21748
  if (now - lastResponsivenessProbeAt > probeIntervalMs) {
21749
21749
  const probeCodeNames = [...agentState.persistentSessionAgents];
@@ -21860,7 +21860,7 @@ async function pollCycleInner() {
21860
21860
  collectResponsivenessProbes,
21861
21861
  livePendingInboundOldestAgeSeconds,
21862
21862
  parkPendingInbound
21863
- } = await import("../responsiveness-probe-ETVF2D2O.js");
21863
+ } = await import("../responsiveness-probe-Q5PDMK2L.js");
21864
21864
  const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
21865
21865
  const wedgeNow = /* @__PURE__ */ new Date();
21866
21866
  const liveAgents = agentState.persistentSessionAgents;
@@ -22149,7 +22149,7 @@ async function pollCycleInner() {
22149
22149
  }
22150
22150
  );
22151
22151
  if (!paneFatalTornDown) continue;
22152
- const { parkPendingInbound } = await import("../responsiveness-probe-ETVF2D2O.js");
22152
+ const { parkPendingInbound } = await import("../responsiveness-probe-Q5PDMK2L.js");
22153
22153
  const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
22154
22154
  paneFatalStreak.delete(codeName);
22155
22155
  paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
@@ -22180,7 +22180,7 @@ async function pollCycleInner() {
22180
22180
  TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
22181
22181
  bindSourceEscalations
22182
22182
  } = await import("../transcript-mount-health-OHE6IVJV.js");
22183
- const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-ADLDX7QL.js");
22183
+ const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-K5WFQVXD.js");
22184
22184
  const mountConfig = resolveTranscriptMountConfig();
22185
22185
  const liveAgents = agentState.persistentSessionAgents;
22186
22186
  for (const tracked of [
@@ -22346,7 +22346,7 @@ async function pollCycleInner() {
22346
22346
  }
22347
22347
  try {
22348
22348
  const { scrapeMcpFailedBannerCount } = await import("../pane-mcp-banner-scraper-VR5QGP3J.js");
22349
- const { probeSessionAuth } = await import("../session-auth-dead-36OZTRBJ.js");
22349
+ const { probeSessionAuth } = await import("../session-auth-dead-T57ORTYP.js");
22350
22350
  const observations = [];
22351
22351
  const pendingCacheCommits = [];
22352
22352
  const modelApiErrorReportingOn = hostFlagStore().getBoolean("model-api-error-reporting");
@@ -27569,7 +27569,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
27569
27569
  if (!refreshData) return;
27570
27570
  const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
27571
27571
  const hostId = await getHostId();
27572
- const parkForRestart = await import("../responsiveness-probe-ETVF2D2O.js").then(
27572
+ const parkForRestart = await import("../responsiveness-probe-Q5PDMK2L.js").then(
27573
27573
  (m) => m.parkPendingInbound,
27574
27574
  (err) => err
27575
27575
  );
@@ -27650,7 +27650,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
27650
27650
  void api.post("/host/restart-ack", { host_id: hostId, agent_id: agentId, restart_requested_at: requestedAt }).catch((err) => log(`[restart-lane] ack failed for '${codeName}': ${err.message}`));
27651
27651
  void (async () => {
27652
27652
  try {
27653
- const { collectDiagnostics } = await import("../persistent-session-ADLDX7QL.js");
27653
+ const { collectDiagnostics } = await import("../persistent-session-K5WFQVXD.js");
27654
27654
  await api.post("/host/heartbeat", {
27655
27655
  host_id: hostId,
27656
27656
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -27703,7 +27703,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
27703
27703
  }
27704
27704
  try {
27705
27705
  const hostId = await getHostId();
27706
- const { collectDiagnostics } = await import("../persistent-session-ADLDX7QL.js");
27706
+ const { collectDiagnostics } = await import("../persistent-session-K5WFQVXD.js");
27707
27707
  await api.post("/host/heartbeat", {
27708
27708
  host_id: hostId,
27709
27709
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -28579,7 +28579,7 @@ async function processClaudePairSessions(agents) {
28579
28579
  snapshotPairConfig,
28580
28580
  // ENG-11659: result -> report body + the manager.log line that records it.
28581
28581
  planPairStartReport
28582
- } = await import("../claude-pair-runtime-ZI2LPY5E.js");
28582
+ } = await import("../claude-pair-runtime-QA3AUNBF.js");
28583
28583
  const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
28584
28584
  for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
28585
28585
  log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);
@@ -9,7 +9,7 @@ import {
9
9
  systemUnitStatus,
10
10
  uninstallSupervisor,
11
11
  uninstallSystemUnit
12
- } from "./chunk-H3JMPEH7.js";
12
+ } from "./chunk-ZE6WANYK.js";
13
13
  import "./chunk-DGUM43GV.js";
14
14
  export {
15
15
  _internals,
@@ -23,4 +23,4 @@ export {
23
23
  uninstallSupervisor,
24
24
  uninstallSystemUnit
25
25
  };
26
- //# sourceMappingURL=manager-supervisor-TD7E6FPC.js.map
26
+ //# sourceMappingURL=manager-supervisor-NZHBYHWF.js.map
@@ -38692,9 +38692,9 @@ function createInboundContextClient(args) {
38692
38692
  cachedTokenExpiresAt = data.expires_at ? new Date(data.expires_at).getTime() - 12e4 : Date.now() + 55 * 6e4;
38693
38693
  return cachedToken;
38694
38694
  }
38695
- async function postOnce(body) {
38695
+ async function postOnce(body, path = "/host/inbound-context") {
38696
38696
  const token = await getToken();
38697
- return fetchImpl(`${base}/host/inbound-context`, {
38697
+ return fetchImpl(`${base}${path}`, {
38698
38698
  method: "POST",
38699
38699
  headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
38700
38700
  body: JSON.stringify(body),
@@ -38726,12 +38726,58 @@ function createInboundContextClient(args) {
38726
38726
  log(`inbound-context: emit threw integration=${args2.sourceIntegration}: ${err.message}`);
38727
38727
  }
38728
38728
  }
38729
+ let activityUnsupportedUntil = 0;
38730
+ async function emitActivity(sessionId) {
38731
+ if (Date.now() < activityUnsupportedUntil) return;
38732
+ const body = { agent_id: agentId, session_id: sessionId };
38733
+ try {
38734
+ let resp = await postOnce(body, "/host/inbound-activity");
38735
+ if (resp.status === 401) {
38736
+ cachedToken = null;
38737
+ cachedTokenExpiresAt = 0;
38738
+ resp = await postOnce(body, "/host/inbound-activity");
38739
+ }
38740
+ if (resp.status === 404) {
38741
+ const text = await resp.text().catch(() => "");
38742
+ if (isRouteJsonError(text)) {
38743
+ log(`inbound-context: activity POST refused (404): ${text.slice(0, 200)}`);
38744
+ return;
38745
+ }
38746
+ const firstPause = activityUnsupportedUntil === 0;
38747
+ activityUnsupportedUntil = Date.now() + ACTIVITY_ROUTE_REPROBE_MS;
38748
+ if (firstPause) {
38749
+ log(
38750
+ `inbound-context: /host/inbound-activity not on this API yet; notices are not recorded, re-checking every ${ACTIVITY_ROUTE_REPROBE_MS / 6e4}m (ENG-12336)`
38751
+ );
38752
+ }
38753
+ return;
38754
+ }
38755
+ if (!resp.ok) {
38756
+ const text = await resp.text().catch(() => "");
38757
+ log(`inbound-context: activity POST failed (${resp.status}): ${text.slice(0, 200)}`);
38758
+ }
38759
+ } catch (err) {
38760
+ log(`inbound-context: activity emit threw: ${err.message}`);
38761
+ }
38762
+ }
38729
38763
  return {
38730
38764
  recordInbound(args2) {
38731
38765
  void emit(args2);
38766
+ },
38767
+ recordActivity(args2) {
38768
+ void emitActivity(args2.sessionId);
38732
38769
  }
38733
38770
  };
38734
38771
  }
38772
+ var ACTIVITY_ROUTE_REPROBE_MS = 10 * 6e4;
38773
+ function isRouteJsonError(text) {
38774
+ try {
38775
+ const parsed = JSON.parse(text);
38776
+ return typeof parsed === "object" && parsed !== null && typeof parsed.error === "string";
38777
+ } catch {
38778
+ return false;
38779
+ }
38780
+ }
38735
38781
 
38736
38782
  // src/direct-chat-inbound-origin.ts
38737
38783
  function directChatInboundOrigin(msg) {
@@ -38744,6 +38790,15 @@ function directChatInboundOrigin(msg) {
38744
38790
  ...msg.sender_id ? { senderId: msg.sender_id } : {}
38745
38791
  };
38746
38792
  }
38793
+ var RECORDED_ACTIVITY_NOTICE_KINDS = ["support_email_reply"];
38794
+ function directChatNoticeActivity(msg) {
38795
+ if (msg.kind !== "notice") return null;
38796
+ const payload = msg.payload && typeof msg.payload === "object" ? msg.payload : {};
38797
+ if (typeof payload.kind !== "string" || !RECORDED_ACTIVITY_NOTICE_KINDS.includes(payload.kind)) return null;
38798
+ if (payload.verified === false) return null;
38799
+ const sessionId = typeof msg.session_id === "string" ? msg.session_id.trim() : "";
38800
+ return sessionId ? { sessionId } : null;
38801
+ }
38747
38802
 
38748
38803
  // src/impersonation.ts
38749
38804
  var ENV_VAR = "AGT_ACT_AS_AGENT_ID";
@@ -59872,6 +59927,10 @@ async function pollForMessages(sinceMs, rehandIds) {
59872
59927
  scheduleDirectChatBusyAck(msg.session_id, msg.id, arrivedWhileBusy);
59873
59928
  }
59874
59929
  writeDirectChatTurnMarker(msg);
59930
+ const noticeActivity = directChatNoticeActivity(msg);
59931
+ if (noticeActivity) {
59932
+ inboundContextClient?.recordActivity(noticeActivity);
59933
+ }
59875
59934
  if (isNotice) {
59876
59935
  try {
59877
59936
  const res2 = await apiPost("/host/direct-chat/consume", {