@integrity-labs/agt-cli 0.27.28 → 0.27.29

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.
@@ -15,7 +15,7 @@ import {
15
15
  provisionOrientHook,
16
16
  provisionStopHook,
17
17
  requireHost
18
- } from "../chunk-2ZTHGYH7.js";
18
+ } from "../chunk-HX74HMG4.js";
19
19
  import {
20
20
  getProjectDir as getProjectDir2,
21
21
  getReadyTasks,
@@ -77,10 +77,10 @@ import {
77
77
 
78
78
  // src/lib/manager-worker.ts
79
79
  import { createHash as createHash3 } from "crypto";
80
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync3, appendFileSync, mkdirSync as mkdirSync2, chmodSync, existsSync as existsSync4, rmSync as rmSync2, readdirSync as readdirSync3, statSync as statSync2, unlinkSync, copyFileSync } from "fs";
80
+ import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, appendFileSync, mkdirSync as mkdirSync3, chmodSync, existsSync as existsSync4, rmSync as rmSync2, readdirSync as readdirSync3, statSync as statSync2, unlinkSync, copyFileSync } from "fs";
81
81
  import https from "https";
82
82
  import { execFileSync as syncExecFile } from "child_process";
83
- import { join as join6, dirname } from "path";
83
+ import { join as join6, dirname as dirname2 } from "path";
84
84
  import { homedir as homedir4 } from "os";
85
85
  import { fileURLToPath } from "url";
86
86
 
@@ -941,6 +941,53 @@ function runCliProbe(binary, args, opts = {}) {
941
941
  });
942
942
  }
943
943
 
944
+ // src/lib/self-update-coalesce.ts
945
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
946
+ import { dirname } from "path";
947
+ var DEFAULT_SELF_UPDATE_COALESCE_MS = 30 * 60 * 1e3;
948
+ function resolveCoalesceWindowMs(env = process.env) {
949
+ const raw = env.AGT_SELF_UPDATE_COALESCE_MS;
950
+ if (raw == null || raw === "") return DEFAULT_SELF_UPDATE_COALESCE_MS;
951
+ const parsed = Number(raw);
952
+ if (!Number.isFinite(parsed) || parsed < 0) return DEFAULT_SELF_UPDATE_COALESCE_MS;
953
+ return Math.trunc(parsed);
954
+ }
955
+ function readLastSelfUpdateAppliedMs(markerPath, now = Date.now(), read = (p) => readFileSync(p, "utf-8")) {
956
+ let raw;
957
+ try {
958
+ raw = read(markerPath);
959
+ } catch {
960
+ return null;
961
+ }
962
+ const v = parseInt(raw.trim(), 10);
963
+ if (!Number.isFinite(v) || v <= 0) return null;
964
+ if (v > now) return null;
965
+ return v;
966
+ }
967
+ function stampLastSelfUpdateApplied(markerPath, now = Date.now(), write = (p, v) => {
968
+ mkdirSync(dirname(p), { recursive: true });
969
+ writeFileSync(p, v);
970
+ }) {
971
+ try {
972
+ write(markerPath, String(now));
973
+ } catch {
974
+ }
975
+ }
976
+ function decideSelfUpdateCoalesce(inputs) {
977
+ const { windowMs, lastAppliedMs, now } = inputs;
978
+ if (windowMs <= 0) return { proceed: true, remainingMs: 0, lastAppliedMs: null };
979
+ if (lastAppliedMs == null) return { proceed: true, remainingMs: 0, lastAppliedMs: null };
980
+ const elapsed = now - lastAppliedMs;
981
+ if (elapsed < 0) return { proceed: true, remainingMs: 0, lastAppliedMs: null };
982
+ if (elapsed >= windowMs) return { proceed: true, remainingMs: 0, lastAppliedMs: null };
983
+ return { proceed: false, remainingMs: windowMs - elapsed, lastAppliedMs };
984
+ }
985
+ function formatCoalesceDeferLogLine(opts) {
986
+ const remainingSec = Math.ceil(opts.remainingMs / 1e3);
987
+ const windowMin = Math.round(opts.windowMs / 6e4);
988
+ return `[self-update] coalescing \u2014 ${opts.installed} \u2192 ${opts.latest} (${opts.channelLabel}) available, deferring for ${remainingSec}s (last restart inside ${windowMin}min window). See ENG-5862. Override with AGT_SELF_UPDATE_COALESCE_MS=0 during incident response.`;
989
+ }
990
+
944
991
  // src/lib/usage-banner-monitor.ts
945
992
  var MIN_CHECK_INTERVAL_MS = 6e4;
946
993
  var PANE_TAIL_LINES_FOR_BANNER = 200;
@@ -997,7 +1044,7 @@ async function maybeReportUsageBanner(args) {
997
1044
  }
998
1045
 
999
1046
  // src/lib/token-usage-monitor.ts
1000
- import { readdirSync, readFileSync, statSync } from "fs";
1047
+ import { readdirSync, readFileSync as readFileSync2, statSync } from "fs";
1001
1048
  import { join } from "path";
1002
1049
  var MIN_CHECK_INTERVAL_MS2 = 6e4;
1003
1050
  var TRANSCRIPT_MTIME_WINDOW_MS = 2 * 24 * 60 * 60 * 1e3;
@@ -1043,7 +1090,7 @@ async function maybeReportTokenUsage(args) {
1043
1090
  }
1044
1091
  let content;
1045
1092
  try {
1046
- content = readFileSync(path, "utf-8");
1093
+ content = readFileSync2(path, "utf-8");
1047
1094
  } catch (err) {
1048
1095
  log2(`[token-usage] read failed for '${codeName}/${name}': ${err.message}`);
1049
1096
  continue;
@@ -1124,7 +1171,7 @@ async function maybeReportTokenUsage(args) {
1124
1171
  }
1125
1172
 
1126
1173
  // src/lib/activity-cache-monitor.ts
1127
- import { existsSync, readFileSync as readFileSync2 } from "fs";
1174
+ import { existsSync, readFileSync as readFileSync3 } from "fs";
1128
1175
  import { homedir } from "os";
1129
1176
  import { join as join2 } from "path";
1130
1177
  var MIN_CHECK_INTERVAL_MS3 = 6e4;
@@ -1176,7 +1223,7 @@ async function maybeReportActivityCache(args) {
1176
1223
  }
1177
1224
  let raw;
1178
1225
  try {
1179
- raw = readFileSync2(STATS_CACHE_PATH, "utf-8");
1226
+ raw = readFileSync3(STATS_CACHE_PATH, "utf-8");
1180
1227
  } catch (err) {
1181
1228
  log2(`[activity-cache] readFileSync failed: ${err.message}`);
1182
1229
  return;
@@ -1743,7 +1790,7 @@ function normalize(value) {
1743
1790
  }
1744
1791
 
1745
1792
  // src/lib/channel-hash-cache.ts
1746
- import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1793
+ import { existsSync as existsSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
1747
1794
  import { join as join4 } from "path";
1748
1795
  var CACHE_FILENAME = "channel-hash-cache.json";
1749
1796
  function getChannelHashCacheFile(configDir) {
@@ -1754,7 +1801,7 @@ function loadChannelHashCache(target, configDir) {
1754
1801
  if (!existsSync2(path)) return;
1755
1802
  let parsed;
1756
1803
  try {
1757
- parsed = JSON.parse(readFileSync3(path, "utf-8"));
1804
+ parsed = JSON.parse(readFileSync4(path, "utf-8"));
1758
1805
  } catch {
1759
1806
  return;
1760
1807
  }
@@ -1768,7 +1815,7 @@ function saveChannelHashCache(source, configDir) {
1768
1815
  const obj = {};
1769
1816
  for (const [key, value] of source) obj[key] = value;
1770
1817
  try {
1771
- writeFileSync(path, JSON.stringify(obj, null, 2));
1818
+ writeFileSync2(path, JSON.stringify(obj, null, 2));
1772
1819
  } catch {
1773
1820
  }
1774
1821
  }
@@ -2299,7 +2346,7 @@ function clearAgentState(agentId, codeName) {
2299
2346
  }
2300
2347
 
2301
2348
  // src/lib/restart-flags.ts
2302
- import { existsSync as existsSync3, mkdirSync, readdirSync as readdirSync2, readFileSync as readFileSync4, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
2349
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync5, renameSync, rmSync, writeFileSync as writeFileSync3 } from "fs";
2303
2350
  import { homedir as homedir3 } from "os";
2304
2351
  import { join as join5 } from "path";
2305
2352
  import { randomUUID } from "crypto";
@@ -2316,7 +2363,7 @@ function readRestartFlags() {
2316
2363
  for (const entry of readdirSync2(dir)) {
2317
2364
  if (!entry.endsWith(".flag")) continue;
2318
2365
  try {
2319
- const raw = readFileSync4(join5(dir, entry), "utf8");
2366
+ const raw = readFileSync5(join5(dir, entry), "utf8");
2320
2367
  const parsed = JSON.parse(raw);
2321
2368
  if (typeof parsed.codeName !== "string" || parsed.codeName.length === 0) {
2322
2369
  parsed.codeName = entry.replace(/\.flag$/, "");
@@ -3015,7 +3062,7 @@ var runningMcpHashes = /* @__PURE__ */ new Map();
3015
3062
  var runningMcpServerKeys = /* @__PURE__ */ new Map();
3016
3063
  function projectMcpHash(_codeName, projectDir) {
3017
3064
  try {
3018
- const raw = readFileSync5(join6(projectDir, ".mcp.json"), "utf-8");
3065
+ const raw = readFileSync6(join6(projectDir, ".mcp.json"), "utf-8");
3019
3066
  return createHash3("sha256").update(canonicalJson(JSON.parse(raw))).digest("hex");
3020
3067
  } catch {
3021
3068
  return null;
@@ -3023,7 +3070,7 @@ function projectMcpHash(_codeName, projectDir) {
3023
3070
  }
3024
3071
  function projectMcpKeys(_codeName, projectDir) {
3025
3072
  try {
3026
- const raw = readFileSync5(join6(projectDir, ".mcp.json"), "utf-8");
3073
+ const raw = readFileSync6(join6(projectDir, ".mcp.json"), "utf-8");
3027
3074
  const parsed = JSON.parse(raw);
3028
3075
  const servers = parsed.mcpServers;
3029
3076
  if (!servers || typeof servers !== "object") return /* @__PURE__ */ new Set();
@@ -3034,7 +3081,7 @@ function projectMcpKeys(_codeName, projectDir) {
3034
3081
  }
3035
3082
  function readMcpHttpServerConfig(projectDir, serverKey) {
3036
3083
  try {
3037
- const raw = readFileSync5(join6(projectDir, ".mcp.json"), "utf-8");
3084
+ const raw = readFileSync6(join6(projectDir, ".mcp.json"), "utf-8");
3038
3085
  const servers = JSON.parse(raw).mcpServers ?? {};
3039
3086
  const entry = servers[serverKey];
3040
3087
  if (entry && typeof entry.url === "string" && (entry.type === "http" || entry.type === void 0)) {
@@ -3208,7 +3255,7 @@ var cachedFrameworkVersion = null;
3208
3255
  var lastVersionCheckAt = 0;
3209
3256
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
3210
3257
  var lastResponsivenessProbeAt = 0;
3211
- var agtCliVersion = true ? "0.27.28" : "dev";
3258
+ var agtCliVersion = true ? "0.27.29" : "dev";
3212
3259
  function resolveBrewPath(execFileSync4) {
3213
3260
  try {
3214
3261
  const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -3303,7 +3350,7 @@ async function ensureToolkitCli(toolkitSlug) {
3303
3350
  toolkitCliEnsured.add(toolkitSlug);
3304
3351
  return;
3305
3352
  }
3306
- brewBinDir = dirname(brewPath);
3353
+ brewBinDir = dirname2(brewPath);
3307
3354
  const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
3308
3355
  log(`[toolkit-install] ${toolkitSlug}: installing via brew (${pkg})\u2026`);
3309
3356
  if (isRoot) {
@@ -3385,7 +3432,7 @@ function ensureClaudeManagedSettings(path = claudeManagedSettingsPath()) {
3385
3432
  try {
3386
3433
  let settings = {};
3387
3434
  if (existsSync4(path)) {
3388
- const raw = readFileSync5(path, "utf-8").trim();
3435
+ const raw = readFileSync6(path, "utf-8").trim();
3389
3436
  if (raw) {
3390
3437
  let parsed;
3391
3438
  try {
@@ -3401,8 +3448,8 @@ function ensureClaudeManagedSettings(path = claudeManagedSettingsPath()) {
3401
3448
  }
3402
3449
  if (settings.channelsEnabled === true) return;
3403
3450
  settings.channelsEnabled = true;
3404
- mkdirSync2(dirname(path), { recursive: true });
3405
- writeFileSync3(path, `${JSON.stringify(settings, null, 2)}
3451
+ mkdirSync3(dirname2(path), { recursive: true });
3452
+ writeFileSync4(path, `${JSON.stringify(settings, null, 2)}
3406
3453
  `);
3407
3454
  log(`[managed-settings] set channelsEnabled:true in ${path} (ENG-5786 \u2014 unblocks Claude Code channels)`);
3408
3455
  } catch (err) {
@@ -3441,7 +3488,7 @@ async function ensureFrameworkBinary(frameworkId) {
3441
3488
  log(`Claude Code install failed: ${err.message}`);
3442
3489
  return;
3443
3490
  }
3444
- const brewBinDir = dirname(brewPath);
3491
+ const brewBinDir = dirname2(brewPath);
3445
3492
  if (!process.env.PATH?.split(":").includes(brewBinDir)) {
3446
3493
  process.env.PATH = `${brewBinDir}:${process.env.PATH ?? ""}`;
3447
3494
  }
@@ -3461,13 +3508,13 @@ function claudeCodeUpgradeMarkerPath() {
3461
3508
  }
3462
3509
  function stampClaudeCodeUpgradeMarker() {
3463
3510
  try {
3464
- writeFileSync3(claudeCodeUpgradeMarkerPath(), String(Date.now()));
3511
+ writeFileSync4(claudeCodeUpgradeMarkerPath(), String(Date.now()));
3465
3512
  } catch {
3466
3513
  }
3467
3514
  }
3468
3515
  function claudeCodeUpgradeThrottled() {
3469
3516
  try {
3470
- const lastCheck = parseInt(readFileSync5(claudeCodeUpgradeMarkerPath(), "utf-8").trim(), 10);
3517
+ const lastCheck = parseInt(readFileSync6(claudeCodeUpgradeMarkerPath(), "utf-8").trim(), 10);
3471
3518
  if (!Number.isFinite(lastCheck)) return false;
3472
3519
  return Date.now() - lastCheck < CLAUDE_CODE_UPGRADE_CHECK_INTERVAL_MS;
3473
3520
  } catch {
@@ -3516,6 +3563,9 @@ ${r.stderr}`;
3516
3563
  });
3517
3564
  }
3518
3565
  var UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
3566
+ function selfUpdateAppliedMarkerPath() {
3567
+ return join6(homedir4(), ".augmented", ".last-self-update-applied");
3568
+ }
3519
3569
  var selfUpdateUpToDateLogged = false;
3520
3570
  var restartAfterUpgrade = false;
3521
3571
  var pendingUpgradeVersion = null;
@@ -3579,6 +3629,22 @@ async function checkAndUpdateCliViaBrew() {
3579
3629
  if (agtOutdated) {
3580
3630
  const installed = agtOutdated.installed_versions?.[0] ?? "unknown";
3581
3631
  const latest = agtOutdated.current_version ?? "unknown";
3632
+ const coalesceWindowMs = resolveCoalesceWindowMs();
3633
+ const coalesce = decideSelfUpdateCoalesce({
3634
+ windowMs: coalesceWindowMs,
3635
+ lastAppliedMs: readLastSelfUpdateAppliedMs(selfUpdateAppliedMarkerPath()),
3636
+ now: Date.now()
3637
+ });
3638
+ if (!coalesce.proceed) {
3639
+ log(formatCoalesceDeferLogLine({
3640
+ installed,
3641
+ latest,
3642
+ channelLabel: "brew",
3643
+ remainingMs: coalesce.remainingMs,
3644
+ windowMs: coalesceWindowMs
3645
+ }));
3646
+ return;
3647
+ }
3582
3648
  log(`[self-update] agt CLI update available: ${installed} \u2192 ${latest}. Upgrading via brew...`);
3583
3649
  try {
3584
3650
  execFileSync4(brewPath, ["upgrade", "integrity-labs/tap/agt"], {
@@ -3586,6 +3652,7 @@ async function checkAndUpdateCliViaBrew() {
3586
3652
  stdio: "pipe"
3587
3653
  });
3588
3654
  log(`[self-update] agt CLI upgraded to ${latest}. Scheduling manager restart so the new binary takes effect.`);
3655
+ stampLastSelfUpdateApplied(selfUpdateAppliedMarkerPath());
3589
3656
  restartAfterUpgrade = true;
3590
3657
  pendingUpgradeVersion = latest;
3591
3658
  } catch (err) {
@@ -3646,6 +3713,22 @@ async function checkAndUpdateCliViaNpm() {
3646
3713
  }
3647
3714
  return;
3648
3715
  }
3716
+ const coalesceWindowMs = resolveCoalesceWindowMs();
3717
+ const coalesce = decideSelfUpdateCoalesce({
3718
+ windowMs: coalesceWindowMs,
3719
+ lastAppliedMs: readLastSelfUpdateAppliedMs(selfUpdateAppliedMarkerPath()),
3720
+ now: Date.now()
3721
+ });
3722
+ if (!coalesce.proceed) {
3723
+ log(formatCoalesceDeferLogLine({
3724
+ installed: agtCliVersion,
3725
+ latest,
3726
+ channelLabel: `npm, channel=${channel}`,
3727
+ remainingMs: coalesce.remainingMs,
3728
+ windowMs: coalesceWindowMs
3729
+ }));
3730
+ return;
3731
+ }
3649
3732
  log(`[self-update] agt CLI update available: ${agtCliVersion} \u2192 ${latest} (channel=${channel}). Upgrading via npm...`);
3650
3733
  const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
3651
3734
  const cmd = isRoot ? "npm" : "sudo";
@@ -3665,6 +3748,7 @@ async function checkAndUpdateCliViaNpm() {
3665
3748
  try {
3666
3749
  execFileSync4(cmd, args, { timeout: 18e4, stdio: "pipe" });
3667
3750
  log(`[self-update] agt CLI upgraded to ${latest}. Scheduling manager restart so the new binary takes effect.`);
3751
+ stampLastSelfUpdateApplied(selfUpdateAppliedMarkerPath());
3668
3752
  restartAfterUpgrade = true;
3669
3753
  pendingUpgradeVersion = latest;
3670
3754
  } catch (err) {
@@ -3741,14 +3825,14 @@ async function applyClaudeAuthToEnv(childEnv, label) {
3741
3825
  }
3742
3826
  function loadGatewayPorts() {
3743
3827
  try {
3744
- return JSON.parse(readFileSync5(GATEWAY_PORTS_FILE, "utf-8"));
3828
+ return JSON.parse(readFileSync6(GATEWAY_PORTS_FILE, "utf-8"));
3745
3829
  } catch {
3746
3830
  return {};
3747
3831
  }
3748
3832
  }
3749
3833
  function saveGatewayPorts(ports) {
3750
- mkdirSync2(AUGMENTED_DIR, { recursive: true });
3751
- writeFileSync3(GATEWAY_PORTS_FILE, JSON.stringify(ports, null, 2));
3834
+ mkdirSync3(AUGMENTED_DIR, { recursive: true });
3835
+ writeFileSync4(GATEWAY_PORTS_FILE, JSON.stringify(ports, null, 2));
3752
3836
  }
3753
3837
  function allocatePort(codeName) {
3754
3838
  const ports = loadGatewayPorts();
@@ -3785,7 +3869,7 @@ function saveChannelHashCache2() {
3785
3869
  function send(msg) {
3786
3870
  if (msg.type === "state-update") {
3787
3871
  try {
3788
- writeFileSync3(getStateFile(), JSON.stringify(msg.state, null, 2));
3872
+ writeFileSync4(getStateFile(), JSON.stringify(msg.state, null, 2));
3789
3873
  } catch {
3790
3874
  }
3791
3875
  }
@@ -3817,7 +3901,7 @@ function log(msg) {
3817
3901
  if (!managerLogPath) {
3818
3902
  try {
3819
3903
  managerLogPath = join6(homedir4(), ".augmented", "manager.log");
3820
- mkdirSync2(dirname(managerLogPath), { recursive: true });
3904
+ mkdirSync3(dirname2(managerLogPath), { recursive: true });
3821
3905
  if (existsSync4(managerLogPath)) {
3822
3906
  chmodSync(managerLogPath, 384);
3823
3907
  }
@@ -3846,7 +3930,7 @@ function sha256(content) {
3846
3930
  }
3847
3931
  function hashFile(filePath) {
3848
3932
  try {
3849
- const content = readFileSync5(filePath, "utf-8");
3933
+ const content = readFileSync6(filePath, "utf-8");
3850
3934
  return sha256(content);
3851
3935
  } catch {
3852
3936
  return null;
@@ -3870,7 +3954,7 @@ function parseSkillFrontmatter(content) {
3870
3954
  return out;
3871
3955
  }
3872
3956
  async function refreshSkillsIndexInClaudeMd(configDir, codeName, log2) {
3873
- const { readdirSync: readdirSync4, readFileSync: rfs, existsSync: ex, writeFileSync: writeFileSync4 } = await import("fs");
3957
+ const { readdirSync: readdirSync4, readFileSync: rfs, existsSync: ex, writeFileSync: writeFileSync5 } = await import("fs");
3874
3958
  const skillsDir = join6(configDir, codeName, "project", ".claude", "skills");
3875
3959
  const claudeMdPath = join6(configDir, codeName, "project", "CLAUDE.md");
3876
3960
  if (!ex(skillsDir) || !ex(claudeMdPath)) return;
@@ -3918,7 +4002,7 @@ ${SKILLS_INDEX_END}`;
3918
4002
  next = current.trimEnd() + "\n\n" + section + "\n";
3919
4003
  }
3920
4004
  if (next !== current) {
3921
- writeFileSync4(claudeMdPath, next, "utf-8");
4005
+ writeFileSync5(claudeMdPath, next, "utf-8");
3922
4006
  log2(`Refreshed skills index in CLAUDE.md for '${codeName}' (${entries.length} skills)`);
3923
4007
  }
3924
4008
  }
@@ -3927,7 +4011,7 @@ async function migrateToProfiles() {
3927
4011
  const sharedConfigPath = join6(homeDir, ".openclaw", "openclaw.json");
3928
4012
  let sharedConfig;
3929
4013
  try {
3930
- sharedConfig = JSON.parse(readFileSync5(sharedConfigPath, "utf-8"));
4014
+ sharedConfig = JSON.parse(readFileSync6(sharedConfigPath, "utf-8"));
3931
4015
  } catch {
3932
4016
  return;
3933
4017
  }
@@ -3950,9 +4034,9 @@ async function migrateToProfiles() {
3950
4034
  const profileAuthDir = join6(profileDir, "agents", codeName, "agent");
3951
4035
  const authFile = join6(sharedAuthDir, "auth-profiles.json");
3952
4036
  if (existsSync4(authFile)) {
3953
- mkdirSync2(profileAuthDir, { recursive: true });
3954
- const authContent = readFileSync5(authFile, "utf-8");
3955
- writeFileSync3(join6(profileAuthDir, "auth-profiles.json"), authContent);
4037
+ mkdirSync3(profileAuthDir, { recursive: true });
4038
+ const authContent = readFileSync6(authFile, "utf-8");
4039
+ writeFileSync4(join6(profileAuthDir, "auth-profiles.json"), authContent);
3956
4040
  }
3957
4041
  allocatePort(codeName);
3958
4042
  migrated++;
@@ -3990,7 +4074,7 @@ function readGatewayToken(codeName) {
3990
4074
  }
3991
4075
  const homeDir = process.env["HOME"] ?? "/tmp";
3992
4076
  try {
3993
- const cfg = JSON.parse(readFileSync5(join6(homeDir, `.openclaw-${codeName}`, "openclaw.json"), "utf-8"));
4077
+ const cfg = JSON.parse(readFileSync6(join6(homeDir, `.openclaw-${codeName}`, "openclaw.json"), "utf-8"));
3994
4078
  return cfg?.gateway?.auth?.token;
3995
4079
  } catch {
3996
4080
  return void 0;
@@ -4002,7 +4086,7 @@ function isGatewayHung(codeName) {
4002
4086
  const jobsPath = join6(homeDir, `.openclaw-${codeName}`, "cron", "jobs.json");
4003
4087
  if (!existsSync4(jobsPath)) return false;
4004
4088
  try {
4005
- const data = JSON.parse(readFileSync5(jobsPath, "utf-8"));
4089
+ const data = JSON.parse(readFileSync6(jobsPath, "utf-8"));
4006
4090
  const jobs = data.jobs ?? data;
4007
4091
  if (!Array.isArray(jobs)) return false;
4008
4092
  const now = Date.now();
@@ -4043,11 +4127,11 @@ async function ensureGatewayRunning(codeName, adapter) {
4043
4127
  const homeDir = process.env["HOME"] ?? "/tmp";
4044
4128
  const configPath = join6(homeDir, `.openclaw-${codeName}`, "openclaw.json");
4045
4129
  if (existsSync4(configPath)) {
4046
- const cfg = JSON.parse(readFileSync5(configPath, "utf-8"));
4130
+ const cfg = JSON.parse(readFileSync6(configPath, "utf-8"));
4047
4131
  if (cfg.gateway?.port !== status.port) {
4048
4132
  if (!cfg.gateway) cfg.gateway = {};
4049
4133
  cfg.gateway.port = status.port;
4050
- writeFileSync3(configPath, JSON.stringify(cfg, null, 2));
4134
+ writeFileSync4(configPath, JSON.stringify(cfg, null, 2));
4051
4135
  }
4052
4136
  }
4053
4137
  } catch {
@@ -4069,10 +4153,10 @@ async function ensureGatewayRunning(codeName, adapter) {
4069
4153
  const homeDir = process.env["HOME"] ?? "/tmp";
4070
4154
  const configPath = join6(homeDir, `.openclaw-${codeName}`, "openclaw.json");
4071
4155
  if (existsSync4(configPath)) {
4072
- const cfg = JSON.parse(readFileSync5(configPath, "utf-8"));
4156
+ const cfg = JSON.parse(readFileSync6(configPath, "utf-8"));
4073
4157
  if (!cfg.gateway) cfg.gateway = {};
4074
4158
  cfg.gateway.port = port;
4075
- writeFileSync3(configPath, JSON.stringify(cfg, null, 2));
4159
+ writeFileSync4(configPath, JSON.stringify(cfg, null, 2));
4076
4160
  }
4077
4161
  } catch {
4078
4162
  }
@@ -4405,7 +4489,7 @@ async function pollCycle() {
4405
4489
  if (restartAckStateChanged) {
4406
4490
  try {
4407
4491
  const ackedState = { ...state4, agents: agentStates };
4408
- writeFileSync3(getStateFile(), JSON.stringify(ackedState, null, 2));
4492
+ writeFileSync4(getStateFile(), JSON.stringify(ackedState, null, 2));
4409
4493
  } catch (err) {
4410
4494
  log(`[restart] failed to persist ack immediately: ${err.message}`);
4411
4495
  }
@@ -4784,7 +4868,7 @@ async function processAgent(agent, agentStates) {
4784
4868
  try {
4785
4869
  const artifacts = generateArtifacts(agent, refreshData, frameworkAdapter);
4786
4870
  const changedFiles = [];
4787
- mkdirSync2(agentDir, { recursive: true });
4871
+ mkdirSync3(agentDir, { recursive: true });
4788
4872
  for (const artifact of artifacts) {
4789
4873
  const filePath = join6(agentDir, artifact.relativePath);
4790
4874
  let existingHash;
@@ -4806,7 +4890,7 @@ async function processAgent(agent, agentStates) {
4806
4890
  newHash = sha256(stripDynamicSections(artifact.content));
4807
4891
  try {
4808
4892
  const projectClaudeMd = join6(config.configDir, agent.code_name, "project", "CLAUDE.md");
4809
- const existing = readFileSync5(projectClaudeMd, "utf-8");
4893
+ const existing = readFileSync6(projectClaudeMd, "utf-8");
4810
4894
  existingHash = sha256(stripDynamicSections(existing));
4811
4895
  } catch {
4812
4896
  existingHash = null;
@@ -4824,7 +4908,7 @@ async function processAgent(agent, agentStates) {
4824
4908
  const generatorKeys = Object.keys(generatorServers);
4825
4909
  let existingRaw = "";
4826
4910
  try {
4827
- existingRaw = readFileSync5(filePath, "utf-8");
4911
+ existingRaw = readFileSync6(filePath, "utf-8");
4828
4912
  } catch {
4829
4913
  }
4830
4914
  const existingServers = parseMcp(existingRaw);
@@ -4852,8 +4936,8 @@ async function processAgent(agent, agentStates) {
4852
4936
  log(`${verb} '${agent.code_name}': ${fileNames}`);
4853
4937
  for (const file of changedFiles) {
4854
4938
  const filePath = join6(agentDir, file.relativePath);
4855
- mkdirSync2(dirname(filePath), { recursive: true });
4856
- writeFileSync3(filePath, file.content);
4939
+ mkdirSync3(dirname2(filePath), { recursive: true });
4940
+ writeFileSync4(filePath, file.content);
4857
4941
  }
4858
4942
  try {
4859
4943
  const provSkillsDir = join6(agentDir, ".claude", "skills");
@@ -5156,13 +5240,13 @@ async function processAgent(agent, agentStates) {
5156
5240
  try {
5157
5241
  const agentProvisionDir = agentDir;
5158
5242
  const projectDir = join6(homedir4(), ".augmented", agent.code_name, "project");
5159
- mkdirSync2(agentProvisionDir, { recursive: true });
5160
- mkdirSync2(projectDir, { recursive: true });
5243
+ mkdirSync3(agentProvisionDir, { recursive: true });
5244
+ mkdirSync3(projectDir, { recursive: true });
5161
5245
  const provisionMcpPath = join6(agentProvisionDir, ".mcp.json");
5162
5246
  const projectMcpPath = join6(projectDir, ".mcp.json");
5163
5247
  let mcpConfig = { mcpServers: {} };
5164
5248
  try {
5165
- mcpConfig = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
5249
+ mcpConfig = JSON.parse(readFileSync6(provisionMcpPath, "utf-8"));
5166
5250
  if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
5167
5251
  } catch {
5168
5252
  }
@@ -5184,8 +5268,8 @@ async function processAgent(agent, agentStates) {
5184
5268
  }
5185
5269
  };
5186
5270
  const serialized = JSON.stringify(mcpConfig, null, 2);
5187
- writeFileSync3(provisionMcpPath, serialized);
5188
- writeFileSync3(projectMcpPath, serialized);
5271
+ writeFileSync4(provisionMcpPath, serialized);
5272
+ writeFileSync4(projectMcpPath, serialized);
5189
5273
  log(`Channel credentials written for '${agent.code_name}/direct-chat'`);
5190
5274
  }
5191
5275
  const staleChannelsPath = join6(projectDir, ".mcp-channels.json");
@@ -5267,7 +5351,7 @@ async function processAgent(agent, agentStates) {
5267
5351
  const envIntPath = join6(projectDir, ".env.integrations");
5268
5352
  let preWriteEnv;
5269
5353
  try {
5270
- preWriteEnv = readFileSync5(envIntPath, "utf-8");
5354
+ preWriteEnv = readFileSync6(envIntPath, "utf-8");
5271
5355
  } catch {
5272
5356
  preWriteEnv = void 0;
5273
5357
  }
@@ -5280,8 +5364,8 @@ async function processAgent(agent, agentStates) {
5280
5364
  if (fw === "claude-code" && isSessionHealthy(agent.code_name)) {
5281
5365
  try {
5282
5366
  const projectMcpPath = join6(projectDir, ".mcp.json");
5283
- const postWriteEnv = readFileSync5(envIntPath, "utf-8");
5284
- const mcpContent = readFileSync5(projectMcpPath, "utf-8");
5367
+ const postWriteEnv = readFileSync6(envIntPath, "utf-8");
5368
+ const mcpContent = readFileSync6(projectMcpPath, "utf-8");
5285
5369
  const changedVars = diffEnvIntegrations(preWriteEnv, postWriteEnv);
5286
5370
  const mcpJsonForReap = JSON.parse(mcpContent);
5287
5371
  const affectedServerKeys = findMcpServersUsingVars(mcpJsonForReap, changedVars);
@@ -5349,8 +5433,8 @@ async function processAgent(agent, agentStates) {
5349
5433
  const mcpPath = frameworkAdapter.getMcpPath(agent.code_name);
5350
5434
  if (mcpPath) {
5351
5435
  try {
5352
- const { readFileSync: readFileSync6 } = await import("fs");
5353
- const mcpConfig = JSON.parse(readFileSync6(mcpPath, "utf-8"));
5436
+ const { readFileSync: readFileSync7 } = await import("fs");
5437
+ const mcpConfig = JSON.parse(readFileSync7(mcpPath, "utf-8"));
5354
5438
  if (mcpConfig.mcpServers) {
5355
5439
  const managedPrefixes = [
5356
5440
  "composio_",
@@ -5703,7 +5787,7 @@ async function processAgent(agent, agentStates) {
5703
5787
  let mcpJsonParsed = null;
5704
5788
  try {
5705
5789
  const mcpPath = join6(getProjectDir(agent.code_name), ".mcp.json");
5706
- mcpJsonParsed = JSON.parse(readFileSync5(mcpPath, "utf-8"));
5790
+ mcpJsonParsed = JSON.parse(readFileSync6(mcpPath, "utf-8"));
5707
5791
  } catch {
5708
5792
  }
5709
5793
  reapMissingMcpSessions({
@@ -5860,7 +5944,7 @@ async function processAgent(agent, agentStates) {
5860
5944
  const jobsPath = join6(homeDir, `.openclaw-${agent.code_name}`, "cron", "jobs.json");
5861
5945
  if (existsSync4(jobsPath)) {
5862
5946
  try {
5863
- const jobsData = JSON.parse(readFileSync5(jobsPath, "utf-8"));
5947
+ const jobsData = JSON.parse(readFileSync6(jobsPath, "utf-8"));
5864
5948
  const kanbanJob = (jobsData.jobs ?? []).find(
5865
5949
  (j) => typeof j.name === "string" && j.name.includes("kanban-work")
5866
5950
  );
@@ -6043,7 +6127,7 @@ function cleanupCronSessions(sessionsDir, keepCount) {
6043
6127
  const indexPath = join6(sessionsDir, "sessions.json");
6044
6128
  if (!existsSync4(indexPath)) return;
6045
6129
  try {
6046
- const raw = readFileSync5(indexPath, "utf-8");
6130
+ const raw = readFileSync6(indexPath, "utf-8");
6047
6131
  const index = JSON.parse(raw);
6048
6132
  const cronRunKeys = Object.keys(index).filter((k) => k.includes(":cron:") && k.includes(":run:")).map((k) => ({
6049
6133
  key: k,
@@ -6088,7 +6172,7 @@ function cleanupCronSessions(sessionsDir, keepCount) {
6088
6172
  }
6089
6173
  }
6090
6174
  }
6091
- writeFileSync3(indexPath, JSON.stringify(index));
6175
+ writeFileSync4(indexPath, JSON.stringify(index));
6092
6176
  if (toDelete.length > 0) {
6093
6177
  log(`Cleaned ${toDelete.length} cron session(s) and ${deletedFiles} file(s) from ${sessionsDir}`);
6094
6178
  }
@@ -6099,7 +6183,7 @@ var STALE_RUN_TIMEOUT_MS = 5 * 6e4;
6099
6183
  function clearStaleCronRunState(jobsPath) {
6100
6184
  if (!existsSync4(jobsPath)) return;
6101
6185
  try {
6102
- const raw = readFileSync5(jobsPath, "utf-8");
6186
+ const raw = readFileSync6(jobsPath, "utf-8");
6103
6187
  const data = JSON.parse(raw);
6104
6188
  const jobs = data.jobs ?? data;
6105
6189
  if (!Array.isArray(jobs)) return;
@@ -6124,7 +6208,7 @@ function clearStaleCronRunState(jobsPath) {
6124
6208
  }
6125
6209
  }
6126
6210
  if (changed) {
6127
- writeFileSync3(jobsPath, JSON.stringify(data, null, 2));
6211
+ writeFileSync4(jobsPath, JSON.stringify(data, null, 2));
6128
6212
  }
6129
6213
  } catch {
6130
6214
  }
@@ -6428,7 +6512,7 @@ async function executeAndProcessClaudeTask(codeName, agentId, task, prompt) {
6428
6512
  const serverNames = [];
6429
6513
  if (existsSync4(mcpConfigPath)) {
6430
6514
  try {
6431
- const d = JSON.parse(readFileSync5(mcpConfigPath, "utf-8"));
6515
+ const d = JSON.parse(readFileSync6(mcpConfigPath, "utf-8"));
6432
6516
  if (d.mcpServers) serverNames.push(...Object.keys(d.mcpServers));
6433
6517
  } catch {
6434
6518
  }
@@ -6454,7 +6538,7 @@ async function executeAndProcessClaudeTask(codeName, agentId, task, prompt) {
6454
6538
  const envIntPath = join6(projectDir, ".env.integrations");
6455
6539
  if (existsSync4(envIntPath)) {
6456
6540
  try {
6457
- for (const line of readFileSync5(envIntPath, "utf-8").split("\n")) {
6541
+ for (const line of readFileSync6(envIntPath, "utf-8").split("\n")) {
6458
6542
  if (!line || line.startsWith("#") || !line.includes("=")) continue;
6459
6543
  const eqIdx = line.indexOf("=");
6460
6544
  childEnv[line.slice(0, eqIdx)] = line.slice(eqIdx + 1);
@@ -7258,7 +7342,7 @@ ${escapeXml(msg.content)}
7258
7342
  const serverNames = [];
7259
7343
  if (existsSync4(mcpConfigPath)) {
7260
7344
  try {
7261
- const d = JSON.parse(readFileSync5(mcpConfigPath, "utf-8"));
7345
+ const d = JSON.parse(readFileSync6(mcpConfigPath, "utf-8"));
7262
7346
  if (d.mcpServers) serverNames.push(...Object.keys(d.mcpServers));
7263
7347
  } catch {
7264
7348
  }
@@ -7285,7 +7369,7 @@ ${escapeXml(msg.content)}
7285
7369
  const childEnv = { ...process.env };
7286
7370
  if (existsSync4(envIntPath)) {
7287
7371
  try {
7288
- for (const line of readFileSync5(envIntPath, "utf-8").split("\n")) {
7372
+ for (const line of readFileSync6(envIntPath, "utf-8").split("\n")) {
7289
7373
  if (!line || line.startsWith("#") || !line.includes("=")) continue;
7290
7374
  const eqIdx = line.indexOf("=");
7291
7375
  childEnv[line.slice(0, eqIdx)] = line.slice(eqIdx + 1);
@@ -7651,7 +7735,7 @@ function getBuiltInSkillContent(skillId) {
7651
7735
  ];
7652
7736
  for (const candidate of candidates) {
7653
7737
  if (existsSync4(candidate)) {
7654
- const content = readFileSync5(candidate, "utf-8");
7738
+ const content = readFileSync6(candidate, "utf-8");
7655
7739
  const files = [{ relativePath: "SKILL.md", content }];
7656
7740
  builtInSkillCache.set(skillId, files);
7657
7741
  return files;
@@ -8611,7 +8695,7 @@ async function syncMemories(agent, configDir, log2) {
8611
8695
  for (const file of readdirSync3(memoryDir)) {
8612
8696
  if (!file.endsWith(".md")) continue;
8613
8697
  try {
8614
- const raw = readFileSync5(join6(memoryDir, file), "utf-8");
8698
+ const raw = readFileSync6(join6(memoryDir, file), "utf-8");
8615
8699
  const fileHash = createHash3("sha256").update(raw).digest("hex").slice(0, 16);
8616
8700
  currentHashes.set(file, fileHash);
8617
8701
  if (prevHashes.get(file) === fileHash) continue;
@@ -8636,7 +8720,7 @@ async function syncMemories(agent, configDir, log2) {
8636
8720
  } catch (err) {
8637
8721
  for (const mem of changedMemories) {
8638
8722
  for (const [file] of currentHashes) {
8639
- const parsed = parseMemoryFile(readFileSync5(join6(memoryDir, file), "utf-8"), file.replace(/\.md$/, ""));
8723
+ const parsed = parseMemoryFile(readFileSync6(join6(memoryDir, file), "utf-8"), file.replace(/\.md$/, ""));
8640
8724
  if (parsed?.name === mem.name) currentHashes.delete(file);
8641
8725
  }
8642
8726
  }
@@ -8664,7 +8748,7 @@ async function downloadMemories(agent, memoryDir, log2, { force }) {
8664
8748
  lastDownloadHash.set(agent.agent_id, responseHash);
8665
8749
  lastLocalFileHash.set(agent.agent_id, localListHash);
8666
8750
  if (dbMemories.memories?.length) {
8667
- mkdirSync2(memoryDir, { recursive: true });
8751
+ mkdirSync3(memoryDir, { recursive: true });
8668
8752
  let written = 0;
8669
8753
  let overwritten = 0;
8670
8754
  for (let i = 0; i < dbMemories.memories.length; i++) {
@@ -8683,14 +8767,14 @@ ${mem.content}
8683
8767
  if (existsSync4(filePath)) {
8684
8768
  let existing = "";
8685
8769
  try {
8686
- existing = readFileSync5(filePath, "utf-8");
8770
+ existing = readFileSync6(filePath, "utf-8");
8687
8771
  } catch {
8688
8772
  }
8689
8773
  if (existing === desired) continue;
8690
- writeFileSync3(filePath, desired);
8774
+ writeFileSync4(filePath, desired);
8691
8775
  overwritten++;
8692
8776
  } else {
8693
- writeFileSync3(filePath, desired);
8777
+ writeFileSync4(filePath, desired);
8694
8778
  written++;
8695
8779
  }
8696
8780
  }
@@ -8882,7 +8966,7 @@ function startManager(opts) {
8882
8966
  try {
8883
8967
  const stateFile = getStateFile();
8884
8968
  if (existsSync4(stateFile)) {
8885
- const raw = readFileSync5(stateFile, "utf-8");
8969
+ const raw = readFileSync6(stateFile, "utf-8");
8886
8970
  const parsed = JSON.parse(raw);
8887
8971
  if (Array.isArray(parsed.agents)) {
8888
8972
  state4.agents = parsed.agents;
@@ -8961,8 +9045,8 @@ function restartRunningChannelMcps(basenames) {
8961
9045
  }
8962
9046
  function deployMcpAssets() {
8963
9047
  const targetDir = join6(homedir4(), ".augmented", "_mcp");
8964
- mkdirSync2(targetDir, { recursive: true });
8965
- const moduleDir = dirname(fileURLToPath(import.meta.url));
9048
+ mkdirSync3(targetDir, { recursive: true });
9049
+ const moduleDir = dirname2(fileURLToPath(import.meta.url));
8966
9050
  let mcpSourceDir = "";
8967
9051
  let dir = moduleDir;
8968
9052
  for (let i = 0; i < 6; i++) {
@@ -8971,7 +9055,7 @@ function deployMcpAssets() {
8971
9055
  mcpSourceDir = candidate;
8972
9056
  break;
8973
9057
  }
8974
- const parent = dirname(dir);
9058
+ const parent = dirname2(dir);
8975
9059
  if (parent === dir) break;
8976
9060
  dir = parent;
8977
9061
  }
@@ -8983,7 +9067,7 @@ function deployMcpAssets() {
8983
9067
  const fileHash = (p) => {
8984
9068
  try {
8985
9069
  if (!existsSync4(p)) return null;
8986
- return createHash3("sha256").update(readFileSync5(p)).digest("hex");
9070
+ return createHash3("sha256").update(readFileSync6(p)).digest("hex");
8987
9071
  } catch {
8988
9072
  return null;
8989
9073
  }
@@ -9022,14 +9106,14 @@ function deployMcpAssets() {
9022
9106
  for (const subdir of ["provision", "project"]) {
9023
9107
  const mcpJsonPath = join6(agentsDir, entry.name, subdir, ".mcp.json");
9024
9108
  try {
9025
- const raw = readFileSync5(mcpJsonPath, "utf-8");
9109
+ const raw = readFileSync6(mcpJsonPath, "utf-8");
9026
9110
  if (!raw.includes("@integrity-labs/augmented-mcp")) continue;
9027
9111
  const mcpConfig = JSON.parse(raw);
9028
9112
  const augServer = mcpConfig.mcpServers?.["augmented"];
9029
9113
  if (!augServer) continue;
9030
9114
  augServer.command = "node";
9031
9115
  augServer.args = [localMcpPath];
9032
- writeFileSync3(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
9116
+ writeFileSync4(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
9033
9117
  log(`[manager] Patched ${entry.name}/${subdir}/.mcp.json: npx \u2192 node`);
9034
9118
  } catch {
9035
9119
  }