@integrity-labs/agt-cli 0.28.13 → 0.28.14
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.
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
provisionStopHook,
|
|
23
23
|
requireHost,
|
|
24
24
|
safeWriteJsonAtomic
|
|
25
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-REFMPKKL.js";
|
|
26
26
|
import {
|
|
27
27
|
getProjectDir as getProjectDir2,
|
|
28
28
|
getReadyTasks,
|
|
@@ -104,11 +104,11 @@ import {
|
|
|
104
104
|
|
|
105
105
|
// src/lib/manager-worker.ts
|
|
106
106
|
import { createHash as createHash4 } from "crypto";
|
|
107
|
-
import { readFileSync as readFileSync11, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4, existsSync as
|
|
107
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4, existsSync as existsSync7, rmSync as rmSync3, readdirSync as readdirSync5, statSync as statSync4, unlinkSync, copyFileSync } from "fs";
|
|
108
108
|
import https from "https";
|
|
109
109
|
import { execFileSync as syncExecFile } from "child_process";
|
|
110
|
-
import { join as
|
|
111
|
-
import { homedir as
|
|
110
|
+
import { join as join13, dirname as dirname3 } from "path";
|
|
111
|
+
import { homedir as homedir7 } from "os";
|
|
112
112
|
import { fileURLToPath } from "url";
|
|
113
113
|
|
|
114
114
|
// src/lib/mcp-config-drift.ts
|
|
@@ -3802,6 +3802,61 @@ async function execFilePromiseLong(cmd, args, opts) {
|
|
|
3802
3802
|
});
|
|
3803
3803
|
}
|
|
3804
3804
|
|
|
3805
|
+
// src/lib/manager/model.ts
|
|
3806
|
+
function resolveModelChain(refreshData) {
|
|
3807
|
+
const agent = refreshData.agent;
|
|
3808
|
+
const modelDefaults = refreshData.model_defaults;
|
|
3809
|
+
const platform2 = modelDefaults?.platform ?? {};
|
|
3810
|
+
const org = modelDefaults?.org ?? {};
|
|
3811
|
+
function resolve(tier) {
|
|
3812
|
+
const agentField = `${tier}_model`;
|
|
3813
|
+
const platformField = `default_${tier}_model`;
|
|
3814
|
+
const agentVal = agent?.[agentField];
|
|
3815
|
+
if (agentVal) return agentVal;
|
|
3816
|
+
const orgVal = org?.[platformField];
|
|
3817
|
+
if (orgVal) return orgVal;
|
|
3818
|
+
const platformVal = platform2?.[platformField];
|
|
3819
|
+
if (platformVal) return platformVal;
|
|
3820
|
+
return void 0;
|
|
3821
|
+
}
|
|
3822
|
+
return {
|
|
3823
|
+
primary: resolve("primary"),
|
|
3824
|
+
secondary: resolve("secondary"),
|
|
3825
|
+
tertiary: resolve("tertiary")
|
|
3826
|
+
};
|
|
3827
|
+
}
|
|
3828
|
+
|
|
3829
|
+
// src/lib/manager/claude-auth.ts
|
|
3830
|
+
import { existsSync as existsSync5, rmSync } from "fs";
|
|
3831
|
+
import { join as join11 } from "path";
|
|
3832
|
+
import { homedir as homedir5 } from "os";
|
|
3833
|
+
async function applyClaudeAuthToEnv(childEnv, label) {
|
|
3834
|
+
const apiKey = getApiKey();
|
|
3835
|
+
if (!apiKey) {
|
|
3836
|
+
throw new Error("AGT_API_KEY is not set");
|
|
3837
|
+
}
|
|
3838
|
+
const exchange = await exchangeApiKey(apiKey, false, { forceRefresh: true });
|
|
3839
|
+
if (exchange.claudeAuthMode === "api_key") {
|
|
3840
|
+
if (!exchange.anthropicApiKey) {
|
|
3841
|
+
throw new Error("claude_auth_mode=api_key but /host/exchange returned no decrypted key");
|
|
3842
|
+
}
|
|
3843
|
+
childEnv.ANTHROPIC_API_KEY = exchange.anthropicApiKey;
|
|
3844
|
+
const claudeDir = join11(homedir5(), ".claude");
|
|
3845
|
+
for (const filename of [".credentials.json", "credentials.json"]) {
|
|
3846
|
+
const p = join11(claudeDir, filename);
|
|
3847
|
+
if (existsSync5(p)) {
|
|
3848
|
+
try {
|
|
3849
|
+
rmSync(p, { force: true });
|
|
3850
|
+
log(`[${label}] Removed ${p} (api_key mode \u2014 preventing OAuth fallback)`);
|
|
3851
|
+
} catch {
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
} else {
|
|
3856
|
+
delete childEnv.ANTHROPIC_API_KEY;
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3805
3860
|
// src/lib/wedge-detection.ts
|
|
3806
3861
|
var DEFAULTS = {
|
|
3807
3862
|
inboundWaitSeconds: 120,
|
|
@@ -3941,24 +3996,24 @@ function partitionActionableByPoison(actionable, states, config2) {
|
|
|
3941
3996
|
}
|
|
3942
3997
|
|
|
3943
3998
|
// src/lib/restart-flags.ts
|
|
3944
|
-
import { existsSync as
|
|
3945
|
-
import { homedir as
|
|
3946
|
-
import { join as
|
|
3999
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, readdirSync as readdirSync4, readFileSync as readFileSync10, renameSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
4000
|
+
import { homedir as homedir6 } from "os";
|
|
4001
|
+
import { join as join12 } from "path";
|
|
3947
4002
|
import { randomUUID } from "crypto";
|
|
3948
4003
|
function restartFlagsDir() {
|
|
3949
|
-
return
|
|
4004
|
+
return join12(homedir6(), ".augmented", "restart-flags");
|
|
3950
4005
|
}
|
|
3951
4006
|
function flagPath(codeName) {
|
|
3952
|
-
return
|
|
4007
|
+
return join12(restartFlagsDir(), `${codeName}.flag`);
|
|
3953
4008
|
}
|
|
3954
4009
|
function readRestartFlags() {
|
|
3955
4010
|
const dir = restartFlagsDir();
|
|
3956
|
-
if (!
|
|
4011
|
+
if (!existsSync6(dir)) return [];
|
|
3957
4012
|
const out = [];
|
|
3958
4013
|
for (const entry of readdirSync4(dir)) {
|
|
3959
4014
|
if (!entry.endsWith(".flag")) continue;
|
|
3960
4015
|
try {
|
|
3961
|
-
const raw = readFileSync10(
|
|
4016
|
+
const raw = readFileSync10(join12(dir, entry), "utf8");
|
|
3962
4017
|
const parsed = JSON.parse(raw);
|
|
3963
4018
|
if (typeof parsed.codeName !== "string" || parsed.codeName.length === 0) {
|
|
3964
4019
|
parsed.codeName = entry.replace(/\.flag$/, "");
|
|
@@ -3976,8 +4031,8 @@ function readRestartFlags() {
|
|
|
3976
4031
|
}
|
|
3977
4032
|
function deleteRestartFlag(codeName) {
|
|
3978
4033
|
const path = flagPath(codeName);
|
|
3979
|
-
if (
|
|
3980
|
-
|
|
4034
|
+
if (existsSync6(path)) {
|
|
4035
|
+
rmSync2(path, { force: true });
|
|
3981
4036
|
}
|
|
3982
4037
|
}
|
|
3983
4038
|
|
|
@@ -4506,8 +4561,8 @@ function applyRestartAcks(args) {
|
|
|
4506
4561
|
var GATEWAY_PORT_BASE = 18800;
|
|
4507
4562
|
var GATEWAY_PORT_STEP = 10;
|
|
4508
4563
|
var GATEWAY_PORT_MAX = 18899;
|
|
4509
|
-
var AUGMENTED_DIR =
|
|
4510
|
-
var GATEWAY_PORTS_FILE =
|
|
4564
|
+
var AUGMENTED_DIR = join13(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
4565
|
+
var GATEWAY_PORTS_FILE = join13(AUGMENTED_DIR, "gateway-ports.json");
|
|
4511
4566
|
var CHANNEL_SWEEP_INTERVAL_MS = (() => {
|
|
4512
4567
|
const raw = parseInt(process.env["AGT_CHANNEL_SWEEP_INTERVAL_MS"] ?? "", 10);
|
|
4513
4568
|
if (!Number.isFinite(raw)) return 5 * 60 * 1e3;
|
|
@@ -4882,7 +4937,7 @@ var runningMcpServerKeys = /* @__PURE__ */ new Map();
|
|
|
4882
4937
|
var runningChannelSecretHashes = /* @__PURE__ */ new Map();
|
|
4883
4938
|
function projectMcpHash(_codeName, projectDir) {
|
|
4884
4939
|
try {
|
|
4885
|
-
const raw = readFileSync11(
|
|
4940
|
+
const raw = readFileSync11(join13(projectDir, ".mcp.json"), "utf-8");
|
|
4886
4941
|
return createHash4("sha256").update(canonicalJson(JSON.parse(raw))).digest("hex");
|
|
4887
4942
|
} catch {
|
|
4888
4943
|
return null;
|
|
@@ -4890,7 +4945,7 @@ function projectMcpHash(_codeName, projectDir) {
|
|
|
4890
4945
|
}
|
|
4891
4946
|
function projectMcpKeys(_codeName, projectDir) {
|
|
4892
4947
|
try {
|
|
4893
|
-
const raw = readFileSync11(
|
|
4948
|
+
const raw = readFileSync11(join13(projectDir, ".mcp.json"), "utf-8");
|
|
4894
4949
|
const parsed = JSON.parse(raw);
|
|
4895
4950
|
const servers = parsed.mcpServers;
|
|
4896
4951
|
if (!servers || typeof servers !== "object") return /* @__PURE__ */ new Set();
|
|
@@ -4901,7 +4956,7 @@ function projectMcpKeys(_codeName, projectDir) {
|
|
|
4901
4956
|
}
|
|
4902
4957
|
function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
4903
4958
|
try {
|
|
4904
|
-
const raw = readFileSync11(
|
|
4959
|
+
const raw = readFileSync11(join13(projectDir, ".mcp.json"), "utf-8");
|
|
4905
4960
|
const servers = JSON.parse(raw).mcpServers ?? {};
|
|
4906
4961
|
const entry = servers[serverKey];
|
|
4907
4962
|
if (entry && typeof entry.url === "string" && (entry.type === "http" || entry.type === void 0)) {
|
|
@@ -4929,8 +4984,8 @@ async function runAgentConnectivityProbes(agent, integrations, projectDir) {
|
|
|
4929
4984
|
if (integrations.length === 0) return;
|
|
4930
4985
|
const probeEnv = { ...process.env };
|
|
4931
4986
|
try {
|
|
4932
|
-
const envIntPath =
|
|
4933
|
-
if (
|
|
4987
|
+
const envIntPath = join13(projectDir, ".env.integrations");
|
|
4988
|
+
if (existsSync7(envIntPath)) {
|
|
4934
4989
|
Object.assign(probeEnv, parseEnvIntegrations(readFileSync11(envIntPath, "utf-8")));
|
|
4935
4990
|
}
|
|
4936
4991
|
} catch {
|
|
@@ -5119,7 +5174,7 @@ function checkMcpConfigDriftAndScheduleRestart(codeName, projectDir) {
|
|
|
5119
5174
|
function projectChannelSecretHash(projectDir) {
|
|
5120
5175
|
try {
|
|
5121
5176
|
const entries = parseEnvIntegrations(
|
|
5122
|
-
readFileSync11(
|
|
5177
|
+
readFileSync11(join13(projectDir, ".env.integrations"), "utf-8")
|
|
5123
5178
|
);
|
|
5124
5179
|
return channelSecretValueHash(entries, CHANNEL_SECRET_ENV_KEYS);
|
|
5125
5180
|
} catch {
|
|
@@ -5211,7 +5266,7 @@ var cachedMaintenanceWindow = null;
|
|
|
5211
5266
|
var lastVersionCheckAt = 0;
|
|
5212
5267
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
5213
5268
|
var lastResponsivenessProbeAt = 0;
|
|
5214
|
-
var agtCliVersion = true ? "0.28.
|
|
5269
|
+
var agtCliVersion = true ? "0.28.14" : "dev";
|
|
5215
5270
|
function resolveBrewPath(execFileSync4) {
|
|
5216
5271
|
try {
|
|
5217
5272
|
const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -5224,7 +5279,7 @@ function resolveBrewPath(execFileSync4) {
|
|
|
5224
5279
|
"/usr/local/bin/brew"
|
|
5225
5280
|
];
|
|
5226
5281
|
for (const path of fallbacks) {
|
|
5227
|
-
if (
|
|
5282
|
+
if (existsSync7(path)) return path;
|
|
5228
5283
|
}
|
|
5229
5284
|
return null;
|
|
5230
5285
|
}
|
|
@@ -5234,7 +5289,7 @@ function claudeBinaryInstalled(execFileSync4) {
|
|
|
5234
5289
|
"/opt/homebrew/bin/claude",
|
|
5235
5290
|
"/usr/local/bin/claude"
|
|
5236
5291
|
];
|
|
5237
|
-
if (canonical.some((path) =>
|
|
5292
|
+
if (canonical.some((path) => existsSync7(path))) return true;
|
|
5238
5293
|
try {
|
|
5239
5294
|
execFileSync4("which", ["claude"], { timeout: 5e3 });
|
|
5240
5295
|
return true;
|
|
@@ -5387,7 +5442,7 @@ function claudeManagedSettingsPath() {
|
|
|
5387
5442
|
function ensureClaudeManagedSettings(path = claudeManagedSettingsPath()) {
|
|
5388
5443
|
try {
|
|
5389
5444
|
let settings = {};
|
|
5390
|
-
if (
|
|
5445
|
+
if (existsSync7(path)) {
|
|
5391
5446
|
const raw = readFileSync11(path, "utf-8").trim();
|
|
5392
5447
|
if (raw) {
|
|
5393
5448
|
let parsed;
|
|
@@ -5450,7 +5505,7 @@ async function ensureFrameworkBinary(frameworkId) {
|
|
|
5450
5505
|
if (!process.env.PATH?.split(":").includes(brewBinDir)) {
|
|
5451
5506
|
process.env.PATH = `${brewBinDir}:${process.env.PATH ?? ""}`;
|
|
5452
5507
|
}
|
|
5453
|
-
if (
|
|
5508
|
+
if (existsSync7("/home/linuxbrew/.linuxbrew/bin/claude")) {
|
|
5454
5509
|
log("Claude Code installed successfully");
|
|
5455
5510
|
} else {
|
|
5456
5511
|
log("Claude Code install completed but binary not found at expected path \u2014 check brew logs");
|
|
@@ -5462,7 +5517,7 @@ async function ensureFrameworkBinary(frameworkId) {
|
|
|
5462
5517
|
var CLAUDE_CODE_UPGRADE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
5463
5518
|
var claudeCodeUpgradeInFlight = false;
|
|
5464
5519
|
function claudeCodeUpgradeMarkerPath() {
|
|
5465
|
-
return
|
|
5520
|
+
return join13(homedir7(), ".augmented", ".last-claude-code-upgrade-check");
|
|
5466
5521
|
}
|
|
5467
5522
|
function stampClaudeCodeUpgradeMarker() {
|
|
5468
5523
|
try {
|
|
@@ -5525,7 +5580,7 @@ ${r.stderr}`;
|
|
|
5525
5580
|
}
|
|
5526
5581
|
var UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
5527
5582
|
function selfUpdateAppliedMarkerPath() {
|
|
5528
|
-
return
|
|
5583
|
+
return join13(homedir7(), ".augmented", ".last-self-update-applied");
|
|
5529
5584
|
}
|
|
5530
5585
|
var selfUpdateUpToDateLogged = false;
|
|
5531
5586
|
var restartAfterUpgrade = false;
|
|
@@ -5548,7 +5603,7 @@ async function checkAndUpdateCli() {
|
|
|
5548
5603
|
const isNpmGlobal = !isBrewFormula && resolvedPath.includes("node_modules");
|
|
5549
5604
|
if (!isBrewFormula && !isNpmGlobal) return;
|
|
5550
5605
|
const { readFileSync: readF, writeFileSync: writeF } = await import("fs");
|
|
5551
|
-
const markerPath =
|
|
5606
|
+
const markerPath = join13(homedir7(), ".augmented", ".last-update-check");
|
|
5552
5607
|
try {
|
|
5553
5608
|
const lastCheck = parseInt(readF(markerPath, "utf-8").trim(), 10);
|
|
5554
5609
|
if (Date.now() - lastCheck < UPDATE_CHECK_INTERVAL_MS) return;
|
|
@@ -5803,41 +5858,15 @@ async function checkClaudeAuth() {
|
|
|
5803
5858
|
return false;
|
|
5804
5859
|
}
|
|
5805
5860
|
}
|
|
5806
|
-
async function applyClaudeAuthToEnv(childEnv, label) {
|
|
5807
|
-
const apiKey = getApiKey();
|
|
5808
|
-
if (!apiKey) {
|
|
5809
|
-
throw new Error("AGT_API_KEY is not set");
|
|
5810
|
-
}
|
|
5811
|
-
const exchange = await exchangeApiKey(apiKey, false, { forceRefresh: true });
|
|
5812
|
-
if (exchange.claudeAuthMode === "api_key") {
|
|
5813
|
-
if (!exchange.anthropicApiKey) {
|
|
5814
|
-
throw new Error("claude_auth_mode=api_key but /host/exchange returned no decrypted key");
|
|
5815
|
-
}
|
|
5816
|
-
childEnv.ANTHROPIC_API_KEY = exchange.anthropicApiKey;
|
|
5817
|
-
const claudeDir = join12(homedir6(), ".claude");
|
|
5818
|
-
for (const filename of [".credentials.json", "credentials.json"]) {
|
|
5819
|
-
const p = join12(claudeDir, filename);
|
|
5820
|
-
if (existsSync6(p)) {
|
|
5821
|
-
try {
|
|
5822
|
-
rmSync2(p, { force: true });
|
|
5823
|
-
log(`[${label}] Removed ${p} (api_key mode \u2014 preventing OAuth fallback)`);
|
|
5824
|
-
} catch {
|
|
5825
|
-
}
|
|
5826
|
-
}
|
|
5827
|
-
}
|
|
5828
|
-
} else {
|
|
5829
|
-
delete childEnv.ANTHROPIC_API_KEY;
|
|
5830
|
-
}
|
|
5831
|
-
}
|
|
5832
5861
|
var evalEmptyMcpConfigPath = null;
|
|
5833
5862
|
function ensureEvalEmptyMcpConfig() {
|
|
5834
|
-
if (evalEmptyMcpConfigPath &&
|
|
5835
|
-
const dir =
|
|
5863
|
+
if (evalEmptyMcpConfigPath && existsSync7(evalEmptyMcpConfigPath)) return evalEmptyMcpConfigPath;
|
|
5864
|
+
const dir = join13(homedir7(), ".augmented");
|
|
5836
5865
|
try {
|
|
5837
5866
|
mkdirSync4(dir, { recursive: true });
|
|
5838
5867
|
} catch {
|
|
5839
5868
|
}
|
|
5840
|
-
const p =
|
|
5869
|
+
const p = join13(dir, ".eval-empty-mcp.json");
|
|
5841
5870
|
writeFileSync4(p, JSON.stringify({ mcpServers: {} }));
|
|
5842
5871
|
evalEmptyMcpConfigPath = p;
|
|
5843
5872
|
return p;
|
|
@@ -5863,7 +5892,7 @@ async function runEvalClaude(prompt, model) {
|
|
|
5863
5892
|
""
|
|
5864
5893
|
];
|
|
5865
5894
|
const { stdout } = await execFilePromiseLong(resolveClaudeBinary(), args, {
|
|
5866
|
-
cwd:
|
|
5895
|
+
cwd: homedir7(),
|
|
5867
5896
|
timeout: 12e4,
|
|
5868
5897
|
stdin: "ignore",
|
|
5869
5898
|
env: childEnv,
|
|
@@ -5942,10 +5971,10 @@ function freePort(codeName) {
|
|
|
5942
5971
|
}
|
|
5943
5972
|
}
|
|
5944
5973
|
function getStateFile() {
|
|
5945
|
-
return
|
|
5974
|
+
return join13(config?.configDir ?? join13(process.env["HOME"] ?? "/tmp", ".augmented"), "manager-state.json");
|
|
5946
5975
|
}
|
|
5947
5976
|
function channelHashCacheDir() {
|
|
5948
|
-
return config?.configDir ??
|
|
5977
|
+
return config?.configDir ?? join13(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
5949
5978
|
}
|
|
5950
5979
|
function loadChannelHashCache2() {
|
|
5951
5980
|
loadChannelHashCache(agentState.knownChannelConfigHashes, channelHashCacheDir());
|
|
@@ -5956,7 +5985,7 @@ function saveChannelHashCache2() {
|
|
|
5956
5985
|
var _channelQuarantineStore = null;
|
|
5957
5986
|
function channelQuarantineStore() {
|
|
5958
5987
|
if (!_channelQuarantineStore) {
|
|
5959
|
-
const dir = config?.configDir ??
|
|
5988
|
+
const dir = config?.configDir ?? join13(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
5960
5989
|
_channelQuarantineStore = new ChannelQuarantineStore(defaultQuarantinePath(dir));
|
|
5961
5990
|
}
|
|
5962
5991
|
return _channelQuarantineStore;
|
|
@@ -5964,7 +5993,7 @@ function channelQuarantineStore() {
|
|
|
5964
5993
|
var _hostFlagStore = null;
|
|
5965
5994
|
function hostFlagStore() {
|
|
5966
5995
|
if (!_hostFlagStore) {
|
|
5967
|
-
const dir = config?.configDir ??
|
|
5996
|
+
const dir = config?.configDir ?? join13(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
5968
5997
|
_hostFlagStore = new HostFlagStore({ cachePath: defaultFlagsCachePath(dir), log });
|
|
5969
5998
|
}
|
|
5970
5999
|
return _hostFlagStore;
|
|
@@ -6016,12 +6045,12 @@ function parseSkillFrontmatter(content) {
|
|
|
6016
6045
|
}
|
|
6017
6046
|
async function refreshSkillsIndexInClaudeMd(configDir, codeName, log2) {
|
|
6018
6047
|
const { readdirSync: readdirSync6, readFileSync: rfs, existsSync: ex, writeFileSync: writeFileSync5 } = await import("fs");
|
|
6019
|
-
const skillsDir =
|
|
6020
|
-
const claudeMdPath =
|
|
6048
|
+
const skillsDir = join13(configDir, codeName, "project", ".claude", "skills");
|
|
6049
|
+
const claudeMdPath = join13(configDir, codeName, "project", "CLAUDE.md");
|
|
6021
6050
|
if (!ex(skillsDir) || !ex(claudeMdPath)) return;
|
|
6022
6051
|
const entries = [];
|
|
6023
6052
|
for (const dir of readdirSync6(skillsDir).sort()) {
|
|
6024
|
-
const skillFile =
|
|
6053
|
+
const skillFile = join13(skillsDir, dir, "SKILL.md");
|
|
6025
6054
|
if (!ex(skillFile)) continue;
|
|
6026
6055
|
try {
|
|
6027
6056
|
const { name, description } = parseSkillFrontmatter(rfs(skillFile, "utf-8"));
|
|
@@ -6069,7 +6098,7 @@ ${SKILLS_INDEX_END}`;
|
|
|
6069
6098
|
}
|
|
6070
6099
|
async function migrateToProfiles() {
|
|
6071
6100
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6072
|
-
const sharedConfigPath =
|
|
6101
|
+
const sharedConfigPath = join13(homeDir, ".openclaw", "openclaw.json");
|
|
6073
6102
|
let sharedConfig;
|
|
6074
6103
|
try {
|
|
6075
6104
|
sharedConfig = JSON.parse(readFileSync11(sharedConfigPath, "utf-8"));
|
|
@@ -6085,19 +6114,19 @@ async function migrateToProfiles() {
|
|
|
6085
6114
|
const codeName = agentEntry["id"];
|
|
6086
6115
|
if (!codeName) continue;
|
|
6087
6116
|
if (codeName === "main") continue;
|
|
6088
|
-
const profileDir =
|
|
6089
|
-
if (
|
|
6117
|
+
const profileDir = join13(homeDir, `.openclaw-${codeName}`);
|
|
6118
|
+
if (existsSync7(join13(profileDir, "openclaw.json"))) continue;
|
|
6090
6119
|
log(`Migrating agent '${codeName}' to per-agent profile`);
|
|
6091
6120
|
if (adapter.seedProfileConfig) {
|
|
6092
6121
|
adapter.seedProfileConfig(codeName);
|
|
6093
6122
|
}
|
|
6094
|
-
const sharedAuthDir =
|
|
6095
|
-
const profileAuthDir =
|
|
6096
|
-
const authFile =
|
|
6097
|
-
if (
|
|
6123
|
+
const sharedAuthDir = join13(homeDir, ".openclaw", "agents", codeName, "agent");
|
|
6124
|
+
const profileAuthDir = join13(profileDir, "agents", codeName, "agent");
|
|
6125
|
+
const authFile = join13(sharedAuthDir, "auth-profiles.json");
|
|
6126
|
+
if (existsSync7(authFile)) {
|
|
6098
6127
|
mkdirSync4(profileAuthDir, { recursive: true });
|
|
6099
6128
|
const authContent = readFileSync11(authFile, "utf-8");
|
|
6100
|
-
writeFileSync4(
|
|
6129
|
+
writeFileSync4(join13(profileAuthDir, "auth-profiles.json"), authContent);
|
|
6101
6130
|
}
|
|
6102
6131
|
allocatePort(codeName);
|
|
6103
6132
|
migrated++;
|
|
@@ -6106,28 +6135,6 @@ async function migrateToProfiles() {
|
|
|
6106
6135
|
log(`Migration complete: ${migrated} agent(s) migrated to per-agent profiles`);
|
|
6107
6136
|
}
|
|
6108
6137
|
}
|
|
6109
|
-
function resolveModelChain(refreshData) {
|
|
6110
|
-
const agent = refreshData.agent;
|
|
6111
|
-
const modelDefaults = refreshData.model_defaults;
|
|
6112
|
-
const platform2 = modelDefaults?.platform ?? {};
|
|
6113
|
-
const org = modelDefaults?.org ?? {};
|
|
6114
|
-
function resolve(tier) {
|
|
6115
|
-
const agentField = `${tier}_model`;
|
|
6116
|
-
const platformField = `default_${tier}_model`;
|
|
6117
|
-
const agentVal = agent?.[agentField];
|
|
6118
|
-
if (agentVal) return agentVal;
|
|
6119
|
-
const orgVal = org?.[platformField];
|
|
6120
|
-
if (orgVal) return orgVal;
|
|
6121
|
-
const platformVal = platform2?.[platformField];
|
|
6122
|
-
if (platformVal) return platformVal;
|
|
6123
|
-
return void 0;
|
|
6124
|
-
}
|
|
6125
|
-
return {
|
|
6126
|
-
primary: resolve("primary"),
|
|
6127
|
-
secondary: resolve("secondary"),
|
|
6128
|
-
tertiary: resolve("tertiary")
|
|
6129
|
-
};
|
|
6130
|
-
}
|
|
6131
6138
|
function readGatewayToken(codeName) {
|
|
6132
6139
|
const adapter = resolveAgentFramework(codeName);
|
|
6133
6140
|
if (adapter.readGatewayToken) {
|
|
@@ -6135,7 +6142,7 @@ function readGatewayToken(codeName) {
|
|
|
6135
6142
|
}
|
|
6136
6143
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6137
6144
|
try {
|
|
6138
|
-
const cfg = JSON.parse(readFileSync11(
|
|
6145
|
+
const cfg = JSON.parse(readFileSync11(join13(homeDir, `.openclaw-${codeName}`, "openclaw.json"), "utf-8"));
|
|
6139
6146
|
return cfg?.gateway?.auth?.token;
|
|
6140
6147
|
} catch {
|
|
6141
6148
|
return void 0;
|
|
@@ -6144,8 +6151,8 @@ function readGatewayToken(codeName) {
|
|
|
6144
6151
|
var GATEWAY_HUNG_TIMEOUT_MS = 5 * 6e4;
|
|
6145
6152
|
function isGatewayHung(codeName) {
|
|
6146
6153
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6147
|
-
const jobsPath =
|
|
6148
|
-
if (!
|
|
6154
|
+
const jobsPath = join13(homeDir, `.openclaw-${codeName}`, "cron", "jobs.json");
|
|
6155
|
+
if (!existsSync7(jobsPath)) return false;
|
|
6149
6156
|
try {
|
|
6150
6157
|
const data = JSON.parse(readFileSync11(jobsPath, "utf-8"));
|
|
6151
6158
|
const jobs = data.jobs ?? data;
|
|
@@ -6180,14 +6187,14 @@ async function ensureGatewayRunning(codeName, adapter) {
|
|
|
6180
6187
|
}
|
|
6181
6188
|
await new Promise((r) => setTimeout(r, 2e3));
|
|
6182
6189
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6183
|
-
const cronJobsPath =
|
|
6190
|
+
const cronJobsPath = join13(homeDir, `.openclaw-${codeName}`, "cron", "jobs.json");
|
|
6184
6191
|
clearStaleCronRunState(cronJobsPath);
|
|
6185
6192
|
} else {
|
|
6186
6193
|
if (status.port) {
|
|
6187
6194
|
try {
|
|
6188
6195
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6189
|
-
const configPath =
|
|
6190
|
-
if (
|
|
6196
|
+
const configPath = join13(homeDir, `.openclaw-${codeName}`, "openclaw.json");
|
|
6197
|
+
if (existsSync7(configPath)) {
|
|
6191
6198
|
const cfg = JSON.parse(readFileSync11(configPath, "utf-8"));
|
|
6192
6199
|
if (cfg.gateway?.port !== status.port) {
|
|
6193
6200
|
if (!cfg.gateway) cfg.gateway = {};
|
|
@@ -6212,8 +6219,8 @@ async function ensureGatewayRunning(codeName, adapter) {
|
|
|
6212
6219
|
gatewaysStartedThisCycle.add(codeName);
|
|
6213
6220
|
try {
|
|
6214
6221
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
6215
|
-
const configPath =
|
|
6216
|
-
if (
|
|
6222
|
+
const configPath = join13(homeDir, `.openclaw-${codeName}`, "openclaw.json");
|
|
6223
|
+
if (existsSync7(configPath)) {
|
|
6217
6224
|
const cfg = JSON.parse(readFileSync11(configPath, "utf-8"));
|
|
6218
6225
|
if (!cfg.gateway) cfg.gateway = {};
|
|
6219
6226
|
cfg.gateway.port = port;
|
|
@@ -6751,7 +6758,7 @@ async function pollCycle() {
|
|
|
6751
6758
|
}
|
|
6752
6759
|
killAgentChannelProcesses(prev.codeName, { log });
|
|
6753
6760
|
freePort(prev.codeName);
|
|
6754
|
-
const agentDir =
|
|
6761
|
+
const agentDir = join13(adapter.getAgentDir(prev.codeName), "provision");
|
|
6755
6762
|
await cleanupAgentFiles(prev.codeName, agentDir);
|
|
6756
6763
|
clearAgentCaches(prev.agentId, prev.codeName);
|
|
6757
6764
|
}
|
|
@@ -6837,10 +6844,10 @@ async function pollCycle() {
|
|
|
6837
6844
|
// pending-inbound marker. Best-effort: a write failure is logged by
|
|
6838
6845
|
// the watchdog, never fails the poll cycle.
|
|
6839
6846
|
signalGiveUp: (codeName) => {
|
|
6840
|
-
const dir =
|
|
6841
|
-
if (!
|
|
6847
|
+
const dir = join13(homedir7(), ".augmented", codeName);
|
|
6848
|
+
if (!existsSync7(dir)) return;
|
|
6842
6849
|
atomicWriteFileSync(
|
|
6843
|
-
|
|
6850
|
+
join13(dir, "watchdog-give-up.json"),
|
|
6844
6851
|
JSON.stringify({ gave_up_at: (/* @__PURE__ */ new Date()).toISOString() })
|
|
6845
6852
|
);
|
|
6846
6853
|
}
|
|
@@ -6967,7 +6974,7 @@ async function processAgent(agent, agentStates) {
|
|
|
6967
6974
|
}
|
|
6968
6975
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
6969
6976
|
const adapter = resolveAgentFramework(agent.code_name);
|
|
6970
|
-
let agentDir =
|
|
6977
|
+
let agentDir = join13(adapter.getAgentDir(agent.code_name), "provision");
|
|
6971
6978
|
if (agent.status === "draft" || agent.status === "paused") {
|
|
6972
6979
|
if (previousKnownStatus !== agent.status) {
|
|
6973
6980
|
log(`Agent '${agent.code_name}' is ${agent.status}, skipping provisioning`);
|
|
@@ -7019,7 +7026,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7019
7026
|
const residuals = {
|
|
7020
7027
|
gatewayRunning: gatewayLiveness.running,
|
|
7021
7028
|
portAllocated: Object.prototype.hasOwnProperty.call(ports, agent.code_name),
|
|
7022
|
-
provisionDirExists:
|
|
7029
|
+
provisionDirExists: existsSync7(agentDir)
|
|
7023
7030
|
};
|
|
7024
7031
|
if (!hasRevokedResiduals(residuals)) {
|
|
7025
7032
|
agentStates.push({
|
|
@@ -7171,7 +7178,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7171
7178
|
const frameworkId = refreshData.agent.framework ?? "openclaw";
|
|
7172
7179
|
agentFrameworkCache.set(agent.code_name, frameworkId);
|
|
7173
7180
|
const frameworkAdapter = getFramework(frameworkId);
|
|
7174
|
-
agentDir =
|
|
7181
|
+
agentDir = join13(frameworkAdapter.getAgentDir(agent.code_name), "provision");
|
|
7175
7182
|
cacheAgentDeliveryMetadata(agent.code_name, refreshData);
|
|
7176
7183
|
if (frameworkAdapter.migrateSecretStorage && !migratedSecretStorage.has(agent.code_name)) {
|
|
7177
7184
|
try {
|
|
@@ -7214,7 +7221,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7214
7221
|
const changedFiles = [];
|
|
7215
7222
|
mkdirSync4(agentDir, { recursive: true });
|
|
7216
7223
|
for (const artifact of artifacts) {
|
|
7217
|
-
const filePath =
|
|
7224
|
+
const filePath = join13(agentDir, artifact.relativePath);
|
|
7218
7225
|
let existingHash;
|
|
7219
7226
|
let newHash;
|
|
7220
7227
|
let writeContent = artifact.content;
|
|
@@ -7233,7 +7240,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7233
7240
|
};
|
|
7234
7241
|
newHash = sha256(stripDynamicSections(artifact.content));
|
|
7235
7242
|
try {
|
|
7236
|
-
const projectClaudeMd =
|
|
7243
|
+
const projectClaudeMd = join13(config.configDir, agent.code_name, "project", "CLAUDE.md");
|
|
7237
7244
|
const existing = readFileSync11(projectClaudeMd, "utf-8");
|
|
7238
7245
|
existingHash = sha256(stripDynamicSections(existing));
|
|
7239
7246
|
} catch {
|
|
@@ -7274,12 +7281,12 @@ async function processAgent(agent, agentStates) {
|
|
|
7274
7281
|
}
|
|
7275
7282
|
}
|
|
7276
7283
|
if (changedFiles.length > 0) {
|
|
7277
|
-
const isFirst = !
|
|
7284
|
+
const isFirst = !existsSync7(join13(agentDir, "CHARTER.md"));
|
|
7278
7285
|
const verb = isFirst ? "Provisioning" : "Updating";
|
|
7279
7286
|
const fileNames = changedFiles.map((f) => f.relativePath).join(", ");
|
|
7280
7287
|
log(`${verb} '${agent.code_name}': ${fileNames}`);
|
|
7281
7288
|
for (const file of changedFiles) {
|
|
7282
|
-
const filePath =
|
|
7289
|
+
const filePath = join13(agentDir, file.relativePath);
|
|
7283
7290
|
mkdirSync4(dirname3(filePath), { recursive: true });
|
|
7284
7291
|
if (file.relativePath === ".mcp.json") {
|
|
7285
7292
|
safeWriteJsonAtomic(filePath, file.content, { mode: 384 });
|
|
@@ -7288,12 +7295,12 @@ async function processAgent(agent, agentStates) {
|
|
|
7288
7295
|
}
|
|
7289
7296
|
}
|
|
7290
7297
|
try {
|
|
7291
|
-
const provSkillsDir =
|
|
7292
|
-
if (
|
|
7298
|
+
const provSkillsDir = join13(agentDir, ".claude", "skills");
|
|
7299
|
+
if (existsSync7(provSkillsDir)) {
|
|
7293
7300
|
for (const folder of readdirSync5(provSkillsDir)) {
|
|
7294
7301
|
if (folder.startsWith("knowledge-")) {
|
|
7295
7302
|
try {
|
|
7296
|
-
|
|
7303
|
+
rmSync3(join13(provSkillsDir, folder), { recursive: true });
|
|
7297
7304
|
} catch {
|
|
7298
7305
|
}
|
|
7299
7306
|
}
|
|
@@ -7306,7 +7313,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7306
7313
|
const trackedFiles2 = frameworkAdapter.driftTrackedFiles();
|
|
7307
7314
|
const hashes = /* @__PURE__ */ new Map();
|
|
7308
7315
|
for (const file of trackedFiles2) {
|
|
7309
|
-
const h = hashFile(
|
|
7316
|
+
const h = hashFile(join13(agentDir, file));
|
|
7310
7317
|
if (h) hashes.set(file, h);
|
|
7311
7318
|
}
|
|
7312
7319
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -7324,14 +7331,14 @@ async function processAgent(agent, agentStates) {
|
|
|
7324
7331
|
}
|
|
7325
7332
|
if (Array.isArray(refreshData.workflows)) {
|
|
7326
7333
|
try {
|
|
7327
|
-
const provWorkflowsDir =
|
|
7328
|
-
if (
|
|
7334
|
+
const provWorkflowsDir = join13(agentDir, ".claude", "workflows");
|
|
7335
|
+
if (existsSync7(provWorkflowsDir)) {
|
|
7329
7336
|
const expected = new Set(refreshData.workflows.map((w) => `${w.name}.js`));
|
|
7330
7337
|
for (const file of readdirSync5(provWorkflowsDir)) {
|
|
7331
7338
|
if (!file.endsWith(".js")) continue;
|
|
7332
7339
|
if (expected.has(file)) continue;
|
|
7333
7340
|
try {
|
|
7334
|
-
|
|
7341
|
+
rmSync3(join13(provWorkflowsDir, file));
|
|
7335
7342
|
} catch {
|
|
7336
7343
|
}
|
|
7337
7344
|
}
|
|
@@ -7388,10 +7395,10 @@ async function processAgent(agent, agentStates) {
|
|
|
7388
7395
|
}
|
|
7389
7396
|
let lastDriftCheckAt = now;
|
|
7390
7397
|
const written = agentState.writtenHashes.get(agent.agent_id);
|
|
7391
|
-
if (written &&
|
|
7398
|
+
if (written && existsSync7(agentDir)) {
|
|
7392
7399
|
const driftedFiles = [];
|
|
7393
7400
|
for (const [file, expectedHash] of written) {
|
|
7394
|
-
const localHash = hashFile(
|
|
7401
|
+
const localHash = hashFile(join13(agentDir, file));
|
|
7395
7402
|
if (localHash && localHash !== expectedHash) {
|
|
7396
7403
|
driftedFiles.push(file);
|
|
7397
7404
|
}
|
|
@@ -7402,7 +7409,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7402
7409
|
try {
|
|
7403
7410
|
const localHashes = {};
|
|
7404
7411
|
for (const file of driftedFiles) {
|
|
7405
|
-
localHashes[file] = hashFile(
|
|
7412
|
+
localHashes[file] = hashFile(join13(agentDir, file));
|
|
7406
7413
|
}
|
|
7407
7414
|
await api.post("/host/drift", {
|
|
7408
7415
|
agent_id: agent.agent_id,
|
|
@@ -7726,24 +7733,24 @@ async function processAgent(agent, agentStates) {
|
|
|
7726
7733
|
if (agentSessionMode === "persistent" && (agentFrameworkCache.get(agent.code_name) ?? "openclaw") === "claude-code") {
|
|
7727
7734
|
try {
|
|
7728
7735
|
const agentProvisionDir = agentDir;
|
|
7729
|
-
const projectDir =
|
|
7736
|
+
const projectDir = join13(homedir7(), ".augmented", agent.code_name, "project");
|
|
7730
7737
|
mkdirSync4(agentProvisionDir, { recursive: true });
|
|
7731
7738
|
mkdirSync4(projectDir, { recursive: true });
|
|
7732
|
-
const provisionMcpPath =
|
|
7733
|
-
const projectMcpPath =
|
|
7739
|
+
const provisionMcpPath = join13(agentProvisionDir, ".mcp.json");
|
|
7740
|
+
const projectMcpPath = join13(projectDir, ".mcp.json");
|
|
7734
7741
|
let mcpConfig = { mcpServers: {} };
|
|
7735
7742
|
try {
|
|
7736
7743
|
mcpConfig = JSON.parse(readFileSync11(provisionMcpPath, "utf-8"));
|
|
7737
7744
|
if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
|
|
7738
7745
|
} catch {
|
|
7739
7746
|
}
|
|
7740
|
-
const localDirectChatChannel =
|
|
7747
|
+
const localDirectChatChannel = join13(homedir7(), ".augmented", "_mcp", "direct-chat-channel.js");
|
|
7741
7748
|
const directChatTeamSettings = refreshData.team?.settings;
|
|
7742
7749
|
const directChatTz = (() => {
|
|
7743
7750
|
const tz = directChatTeamSettings?.["timezone"];
|
|
7744
7751
|
return typeof tz === "string" && tz.trim() !== "" ? tz.trim() : void 0;
|
|
7745
7752
|
})();
|
|
7746
|
-
if (
|
|
7753
|
+
if (existsSync7(localDirectChatChannel)) {
|
|
7747
7754
|
const directChatEnv = {
|
|
7748
7755
|
AGT_HOST: requireHost(),
|
|
7749
7756
|
// ENG-5901 Track D: templated — the manager exports the real
|
|
@@ -7767,10 +7774,10 @@ async function processAgent(agent, agentStates) {
|
|
|
7767
7774
|
log(`Channel credentials written for '${agent.code_name}/direct-chat'`);
|
|
7768
7775
|
}
|
|
7769
7776
|
}
|
|
7770
|
-
const staleChannelsPath =
|
|
7771
|
-
if (
|
|
7777
|
+
const staleChannelsPath = join13(projectDir, ".mcp-channels.json");
|
|
7778
|
+
if (existsSync7(staleChannelsPath)) {
|
|
7772
7779
|
try {
|
|
7773
|
-
|
|
7780
|
+
rmSync3(staleChannelsPath, { force: true });
|
|
7774
7781
|
} catch {
|
|
7775
7782
|
}
|
|
7776
7783
|
}
|
|
@@ -7832,7 +7839,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7832
7839
|
}
|
|
7833
7840
|
if (process.env.AGT_CONNECTIVITY_PROBE_ENABLED === "true") {
|
|
7834
7841
|
try {
|
|
7835
|
-
const probeProjectDir =
|
|
7842
|
+
const probeProjectDir = join13(homedir7(), ".augmented", agent.code_name, "project");
|
|
7836
7843
|
await runAgentConnectivityProbes(agent, integrations, probeProjectDir);
|
|
7837
7844
|
} catch (err) {
|
|
7838
7845
|
log(`Connectivity probe failed for '${agent.code_name}': ${err.message}`);
|
|
@@ -7850,8 +7857,8 @@ async function processAgent(agent, agentStates) {
|
|
|
7850
7857
|
recordConfigChurnEvent(agent.agent_id, agent.code_name, FLAP_CHANNEL_INTEGRATIONS, intMembership);
|
|
7851
7858
|
}
|
|
7852
7859
|
if (intHash !== prevIntHash) {
|
|
7853
|
-
const projectDir =
|
|
7854
|
-
const envIntPath =
|
|
7860
|
+
const projectDir = join13(homedir7(), ".augmented", agent.code_name, "project");
|
|
7861
|
+
const envIntPath = join13(projectDir, ".env.integrations");
|
|
7855
7862
|
let preWriteEnv;
|
|
7856
7863
|
try {
|
|
7857
7864
|
preWriteEnv = readFileSync11(envIntPath, "utf-8");
|
|
@@ -7866,7 +7873,7 @@ async function processAgent(agent, agentStates) {
|
|
|
7866
7873
|
let rotationHandled = true;
|
|
7867
7874
|
if (fw === "claude-code" && isSessionHealthy(agent.code_name)) {
|
|
7868
7875
|
try {
|
|
7869
|
-
const projectMcpPath =
|
|
7876
|
+
const projectMcpPath = join13(projectDir, ".mcp.json");
|
|
7870
7877
|
const postWriteEnv = readFileSync11(envIntPath, "utf-8");
|
|
7871
7878
|
const mcpContent = readFileSync11(projectMcpPath, "utf-8");
|
|
7872
7879
|
const changedVars = diffEnvIntegrations(preWriteEnv, postWriteEnv);
|
|
@@ -8050,8 +8057,8 @@ async function processAgent(agent, agentStates) {
|
|
|
8050
8057
|
if (agent.status === "active") {
|
|
8051
8058
|
if (frameworkAdapter.installPlugin) {
|
|
8052
8059
|
try {
|
|
8053
|
-
const pluginPath =
|
|
8054
|
-
if (
|
|
8060
|
+
const pluginPath = join13(process.cwd(), "packages", "openclaw-plugin-augmented", "src", "index.ts");
|
|
8061
|
+
if (existsSync7(pluginPath)) {
|
|
8055
8062
|
frameworkAdapter.installPlugin(agent.code_name, "augmented", pluginPath, {
|
|
8056
8063
|
agtHost: requireHost(),
|
|
8057
8064
|
agtApiKey: getApiKey() ?? void 0,
|
|
@@ -8116,21 +8123,21 @@ async function processAgent(agent, agentStates) {
|
|
|
8116
8123
|
}
|
|
8117
8124
|
}
|
|
8118
8125
|
try {
|
|
8119
|
-
const { readdirSync: readdirSync6, rmSync:
|
|
8120
|
-
const { homedir:
|
|
8126
|
+
const { readdirSync: readdirSync6, rmSync: rmSync4 } = await import("fs");
|
|
8127
|
+
const { homedir: homedir8 } = await import("os");
|
|
8121
8128
|
const frameworkId2 = frameworkAdapter.id;
|
|
8122
8129
|
const candidateSkillDirs = [
|
|
8123
8130
|
// Claude Code — framework runtime tree
|
|
8124
|
-
|
|
8131
|
+
join13(homedir8(), ".augmented", agent.code_name, "skills"),
|
|
8125
8132
|
// Claude Code — project tree
|
|
8126
|
-
|
|
8133
|
+
join13(homedir8(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
8127
8134
|
// OpenClaw — framework runtime tree
|
|
8128
|
-
|
|
8135
|
+
join13(homedir8(), `.openclaw-${agent.code_name}`, "skills"),
|
|
8129
8136
|
// Defensive: legacy provision-side path, not currently an
|
|
8130
8137
|
// install target but cheap to sweep.
|
|
8131
|
-
|
|
8138
|
+
join13(agentDir, ".claude", "skills")
|
|
8132
8139
|
];
|
|
8133
|
-
const existingDirs = candidateSkillDirs.filter((d) =>
|
|
8140
|
+
const existingDirs = candidateSkillDirs.filter((d) => existsSync7(d));
|
|
8134
8141
|
const discoveredEntries = /* @__PURE__ */ new Set();
|
|
8135
8142
|
for (const dir of existingDirs) {
|
|
8136
8143
|
try {
|
|
@@ -8144,9 +8151,9 @@ async function processAgent(agent, agentStates) {
|
|
|
8144
8151
|
}
|
|
8145
8152
|
const removeSkillFolder = (entry, reason) => {
|
|
8146
8153
|
for (const dir of existingDirs) {
|
|
8147
|
-
const p =
|
|
8148
|
-
if (
|
|
8149
|
-
|
|
8154
|
+
const p = join13(dir, entry);
|
|
8155
|
+
if (existsSync7(p)) {
|
|
8156
|
+
rmSync4(p, { recursive: true, force: true });
|
|
8150
8157
|
}
|
|
8151
8158
|
}
|
|
8152
8159
|
log(`Removed ${reason} '${entry}' for '${agent.code_name}' (framework=${frameworkId2})`);
|
|
@@ -8172,18 +8179,18 @@ async function processAgent(agent, agentStates) {
|
|
|
8172
8179
|
log(`Installed global skill '${skillId}' for '${agent.code_name}'`);
|
|
8173
8180
|
}
|
|
8174
8181
|
if (plan.removes.length) {
|
|
8175
|
-
const { rmSync:
|
|
8176
|
-
const { homedir:
|
|
8182
|
+
const { rmSync: rmSync4 } = await import("fs");
|
|
8183
|
+
const { homedir: homedir8 } = await import("os");
|
|
8177
8184
|
const globalSkillDirs = [
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8185
|
+
join13(homedir8(), ".augmented", agent.code_name, "skills"),
|
|
8186
|
+
join13(homedir8(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
8187
|
+
join13(homedir8(), `.openclaw-${agent.code_name}`, "skills"),
|
|
8188
|
+
join13(agentDir, ".claude", "skills")
|
|
8182
8189
|
];
|
|
8183
8190
|
for (const id of plan.removes) {
|
|
8184
8191
|
for (const dir of globalSkillDirs) {
|
|
8185
|
-
const p =
|
|
8186
|
-
if (
|
|
8192
|
+
const p = join13(dir, id);
|
|
8193
|
+
if (existsSync7(p)) rmSync4(p, { recursive: true, force: true });
|
|
8187
8194
|
}
|
|
8188
8195
|
agentState.knownSkillHashes.delete(`global-skill:${agent.agent_id}:${id}`);
|
|
8189
8196
|
log(`Removed unpublished global skill '${id}' for '${agent.code_name}'`);
|
|
@@ -8358,7 +8365,7 @@ async function processAgent(agent, agentStates) {
|
|
|
8358
8365
|
const sess = getSessionState(agent.code_name);
|
|
8359
8366
|
let mcpJsonParsed = null;
|
|
8360
8367
|
try {
|
|
8361
|
-
const mcpPath =
|
|
8368
|
+
const mcpPath = join13(getProjectDir(agent.code_name), ".mcp.json");
|
|
8362
8369
|
mcpJsonParsed = JSON.parse(readFileSync11(mcpPath, "utf-8"));
|
|
8363
8370
|
} catch {
|
|
8364
8371
|
}
|
|
@@ -8568,8 +8575,8 @@ async function processAgent(agent, agentStates) {
|
|
|
8568
8575
|
lastWorkTriggerAt.set(agent.code_name, triggerTs);
|
|
8569
8576
|
if (agentFw === "openclaw" && gatewayRunning && gatewayPort) {
|
|
8570
8577
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
8571
|
-
const jobsPath =
|
|
8572
|
-
if (
|
|
8578
|
+
const jobsPath = join13(homeDir, `.openclaw-${agent.code_name}`, "cron", "jobs.json");
|
|
8579
|
+
if (existsSync7(jobsPath)) {
|
|
8573
8580
|
try {
|
|
8574
8581
|
const jobsData = JSON.parse(readFileSync11(jobsPath, "utf-8"));
|
|
8575
8582
|
const kanbanJob = (jobsData.jobs ?? []).find(
|
|
@@ -8705,10 +8712,10 @@ In progress for ${age} minutes \u2014 auto-failed`).catch(() => {
|
|
|
8705
8712
|
}
|
|
8706
8713
|
}
|
|
8707
8714
|
const trackedFiles = frameworkAdapter.driftTrackedFiles();
|
|
8708
|
-
if (trackedFiles.length > 0 &&
|
|
8715
|
+
if (trackedFiles.length > 0 && existsSync7(agentDir)) {
|
|
8709
8716
|
const hashes = /* @__PURE__ */ new Map();
|
|
8710
8717
|
for (const file of trackedFiles) {
|
|
8711
|
-
const h = hashFile(
|
|
8718
|
+
const h = hashFile(join13(agentDir, file));
|
|
8712
8719
|
if (h) hashes.set(file, h);
|
|
8713
8720
|
}
|
|
8714
8721
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -8742,17 +8749,17 @@ function cleanupStaleSessions(codeName) {
|
|
|
8742
8749
|
lastCleanupAt.set(codeName, Date.now());
|
|
8743
8750
|
const homeDir = process.env["HOME"] ?? "/tmp";
|
|
8744
8751
|
for (const agentDir of ["main", codeName]) {
|
|
8745
|
-
const sessionsDir =
|
|
8752
|
+
const sessionsDir = join13(homeDir, `.openclaw-${codeName}`, "agents", agentDir, "sessions");
|
|
8746
8753
|
cleanupCronSessions(sessionsDir, CRON_SESSION_KEEP_COUNT);
|
|
8747
8754
|
}
|
|
8748
|
-
const cronRunsDir =
|
|
8755
|
+
const cronRunsDir = join13(homeDir, `.openclaw-${codeName}`, "cron", "runs");
|
|
8749
8756
|
cleanupOldFiles(cronRunsDir, CRON_RUN_RETENTION_DAYS, ".jsonl");
|
|
8750
|
-
const cronJobsPath =
|
|
8757
|
+
const cronJobsPath = join13(homeDir, `.openclaw-${codeName}`, "cron", "jobs.json");
|
|
8751
8758
|
clearStaleCronRunState(cronJobsPath);
|
|
8752
8759
|
}
|
|
8753
8760
|
function cleanupCronSessions(sessionsDir, keepCount) {
|
|
8754
|
-
const indexPath =
|
|
8755
|
-
if (!
|
|
8761
|
+
const indexPath = join13(sessionsDir, "sessions.json");
|
|
8762
|
+
if (!existsSync7(indexPath)) return;
|
|
8756
8763
|
try {
|
|
8757
8764
|
const raw = readFileSync11(indexPath, "utf-8");
|
|
8758
8765
|
const index = JSON.parse(raw);
|
|
@@ -8767,9 +8774,9 @@ function cleanupCronSessions(sessionsDir, keepCount) {
|
|
|
8767
8774
|
for (const entry of toDelete) {
|
|
8768
8775
|
delete index[entry.key];
|
|
8769
8776
|
if (entry.sessionId) {
|
|
8770
|
-
const sessionFile =
|
|
8777
|
+
const sessionFile = join13(sessionsDir, `${entry.sessionId}.jsonl`);
|
|
8771
8778
|
try {
|
|
8772
|
-
if (
|
|
8779
|
+
if (existsSync7(sessionFile)) {
|
|
8773
8780
|
unlinkSync(sessionFile);
|
|
8774
8781
|
deletedFiles++;
|
|
8775
8782
|
}
|
|
@@ -8789,8 +8796,8 @@ function cleanupCronSessions(sessionsDir, keepCount) {
|
|
|
8789
8796
|
delete index[parentKey];
|
|
8790
8797
|
if (parentSessionId) {
|
|
8791
8798
|
try {
|
|
8792
|
-
const f =
|
|
8793
|
-
if (
|
|
8799
|
+
const f = join13(sessionsDir, `${parentSessionId}.jsonl`);
|
|
8800
|
+
if (existsSync7(f)) {
|
|
8794
8801
|
unlinkSync(f);
|
|
8795
8802
|
deletedFiles++;
|
|
8796
8803
|
}
|
|
@@ -8808,7 +8815,7 @@ function cleanupCronSessions(sessionsDir, keepCount) {
|
|
|
8808
8815
|
}
|
|
8809
8816
|
var STALE_RUN_TIMEOUT_MS = 5 * 6e4;
|
|
8810
8817
|
function clearStaleCronRunState(jobsPath) {
|
|
8811
|
-
if (!
|
|
8818
|
+
if (!existsSync7(jobsPath)) return;
|
|
8812
8819
|
try {
|
|
8813
8820
|
const raw = readFileSync11(jobsPath, "utf-8");
|
|
8814
8821
|
const data = JSON.parse(raw);
|
|
@@ -8841,13 +8848,13 @@ function clearStaleCronRunState(jobsPath) {
|
|
|
8841
8848
|
}
|
|
8842
8849
|
}
|
|
8843
8850
|
function cleanupOldFiles(dir, maxAgeDays, ext) {
|
|
8844
|
-
if (!
|
|
8851
|
+
if (!existsSync7(dir)) return;
|
|
8845
8852
|
const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1e3;
|
|
8846
8853
|
let removed = 0;
|
|
8847
8854
|
try {
|
|
8848
8855
|
for (const f of readdirSync5(dir)) {
|
|
8849
8856
|
if (!f.endsWith(ext)) continue;
|
|
8850
|
-
const fullPath =
|
|
8857
|
+
const fullPath = join13(dir, f);
|
|
8851
8858
|
try {
|
|
8852
8859
|
const st = statSync4(fullPath);
|
|
8853
8860
|
if (st.mtimeMs < cutoff) {
|
|
@@ -8887,7 +8894,7 @@ var inFlightClaudeTasks = /* @__PURE__ */ new Set();
|
|
|
8887
8894
|
var claudeTaskConcurrency = /* @__PURE__ */ new Map();
|
|
8888
8895
|
var MAX_CLAUDE_CONCURRENCY = 2;
|
|
8889
8896
|
function claudePidFilePath() {
|
|
8890
|
-
return
|
|
8897
|
+
return join13(homedir7(), ".augmented", "manager-claude-pids.json");
|
|
8891
8898
|
}
|
|
8892
8899
|
var inFlightClaudePids = /* @__PURE__ */ new Map();
|
|
8893
8900
|
function registerClaudeSpawn(record) {
|
|
@@ -9227,7 +9234,7 @@ async function fireScheduledTaskViaKanban(codeName, agentId, task, prompt) {
|
|
|
9227
9234
|
}
|
|
9228
9235
|
async function executeAndProcessClaudeTask(codeName, agentId, task, prompt) {
|
|
9229
9236
|
const projectDir = getProjectDir2(codeName);
|
|
9230
|
-
const mcpConfigPath =
|
|
9237
|
+
const mcpConfigPath = join13(projectDir, ".mcp.json");
|
|
9231
9238
|
let runId = null;
|
|
9232
9239
|
let kanbanItemId = null;
|
|
9233
9240
|
let taskResult;
|
|
@@ -9235,9 +9242,9 @@ async function executeAndProcessClaudeTask(codeName, agentId, task, prompt) {
|
|
|
9235
9242
|
const priorRuns = await fetchPriorScheduledRuns(agentId, task.taskId);
|
|
9236
9243
|
prompt = wrapScheduledTaskPrompt(prompt, { priorRuns });
|
|
9237
9244
|
try {
|
|
9238
|
-
const claudeMdPath =
|
|
9245
|
+
const claudeMdPath = join13(projectDir, "CLAUDE.md");
|
|
9239
9246
|
const serverNames = [];
|
|
9240
|
-
if (
|
|
9247
|
+
if (existsSync7(mcpConfigPath)) {
|
|
9241
9248
|
try {
|
|
9242
9249
|
const d = JSON.parse(readFileSync11(mcpConfigPath, "utf-8"));
|
|
9243
9250
|
if (d.mcpServers) serverNames.push(...Object.keys(d.mcpServers));
|
|
@@ -9258,12 +9265,12 @@ async function executeAndProcessClaudeTask(codeName, agentId, task, prompt) {
|
|
|
9258
9265
|
"--allowedTools",
|
|
9259
9266
|
allowedTools
|
|
9260
9267
|
];
|
|
9261
|
-
if (
|
|
9268
|
+
if (existsSync7(claudeMdPath)) {
|
|
9262
9269
|
claudeArgs.push("--system-prompt-file", claudeMdPath);
|
|
9263
9270
|
}
|
|
9264
9271
|
const childEnv = { ...process.env };
|
|
9265
|
-
const envIntPath =
|
|
9266
|
-
if (
|
|
9272
|
+
const envIntPath = join13(projectDir, ".env.integrations");
|
|
9273
|
+
if (existsSync7(envIntPath)) {
|
|
9267
9274
|
try {
|
|
9268
9275
|
Object.assign(childEnv, parseEnvIntegrations(readFileSync11(envIntPath, "utf-8")));
|
|
9269
9276
|
} catch {
|
|
@@ -9437,8 +9444,8 @@ var claudeAuthTupleBySession = /* @__PURE__ */ new Map();
|
|
|
9437
9444
|
async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
|
|
9438
9445
|
const codeName = agent.code_name;
|
|
9439
9446
|
const projectDir = getProjectDir(codeName);
|
|
9440
|
-
const mcpConfigPath =
|
|
9441
|
-
const claudeMdPath =
|
|
9447
|
+
const mcpConfigPath = join13(projectDir, ".mcp.json");
|
|
9448
|
+
const claudeMdPath = join13(projectDir, "CLAUDE.md");
|
|
9442
9449
|
if (restartBreaker.isTripped(codeName)) {
|
|
9443
9450
|
const trip = restartBreaker.getTrip(codeName);
|
|
9444
9451
|
return {
|
|
@@ -10037,7 +10044,7 @@ async function processDirectChatMessage(agent, msg) {
|
|
|
10037
10044
|
if (isSessionHealthy(agent.codeName)) {
|
|
10038
10045
|
if (hostFlagStore().getBoolean("direct-chat-doorbell")) {
|
|
10039
10046
|
try {
|
|
10040
|
-
const doorbell = directChatDoorbellPath(agent.agentId,
|
|
10047
|
+
const doorbell = directChatDoorbellPath(agent.agentId, homedir7());
|
|
10041
10048
|
mkdirSync4(dirname3(doorbell), { recursive: true });
|
|
10042
10049
|
writeFileSync4(doorbell, String(Date.now()));
|
|
10043
10050
|
log(`[direct-chat] Doorbell rung for '${agent.codeName}' (msg=${msg.id}) \u2014 in-session MCP will pull via the cursor`);
|
|
@@ -10083,9 +10090,9 @@ ${escapeXml(msg.content)}
|
|
|
10083
10090
|
log(`[direct-chat] One-shot spawn for '${agent.codeName}' (msg=${msg.id}; host in-flight=${directChatSpawnGate.hostInFlight}, queued=${directChatSpawnGate.queuedCount})`);
|
|
10084
10091
|
const { getProjectDir: ccProjectDir } = await import("../claude-scheduler-FATCLHDM.js");
|
|
10085
10092
|
const projDir = ccProjectDir(agent.codeName);
|
|
10086
|
-
const mcpConfigPath =
|
|
10093
|
+
const mcpConfigPath = join13(projDir, ".mcp.json");
|
|
10087
10094
|
const serverNames = [];
|
|
10088
|
-
if (
|
|
10095
|
+
if (existsSync7(mcpConfigPath)) {
|
|
10089
10096
|
try {
|
|
10090
10097
|
const d = JSON.parse(readFileSync11(mcpConfigPath, "utf-8"));
|
|
10091
10098
|
if (d.mcpServers) serverNames.push(...Object.keys(d.mcpServers));
|
|
@@ -10106,13 +10113,13 @@ ${escapeXml(msg.content)}
|
|
|
10106
10113
|
"--allowedTools",
|
|
10107
10114
|
allowedTools
|
|
10108
10115
|
];
|
|
10109
|
-
const chatClaudeMd =
|
|
10110
|
-
if (
|
|
10116
|
+
const chatClaudeMd = join13(projDir, "CLAUDE.md");
|
|
10117
|
+
if (existsSync7(chatClaudeMd)) {
|
|
10111
10118
|
chatArgs.push("--system-prompt-file", chatClaudeMd);
|
|
10112
10119
|
}
|
|
10113
|
-
const envIntPath =
|
|
10120
|
+
const envIntPath = join13(projDir, ".env.integrations");
|
|
10114
10121
|
const childEnv = { ...process.env };
|
|
10115
|
-
if (
|
|
10122
|
+
if (existsSync7(envIntPath)) {
|
|
10116
10123
|
try {
|
|
10117
10124
|
Object.assign(childEnv, parseEnvIntegrations(readFileSync11(envIntPath, "utf-8")));
|
|
10118
10125
|
} catch {
|
|
@@ -10492,11 +10499,11 @@ function getBuiltInSkillContent(skillId) {
|
|
|
10492
10499
|
if (builtInSkillCache.has(skillId)) return builtInSkillCache.get(skillId);
|
|
10493
10500
|
try {
|
|
10494
10501
|
const candidates = [
|
|
10495
|
-
|
|
10496
|
-
|
|
10502
|
+
join13(process.cwd(), "skills", skillId, "SKILL.md"),
|
|
10503
|
+
join13(new URL(".", import.meta.url).pathname, "..", "..", "..", "..", "skills", skillId, "SKILL.md")
|
|
10497
10504
|
];
|
|
10498
10505
|
for (const candidate of candidates) {
|
|
10499
|
-
if (
|
|
10506
|
+
if (existsSync7(candidate)) {
|
|
10500
10507
|
const content = readFileSync11(candidate, "utf-8");
|
|
10501
10508
|
const files = [{ relativePath: "SKILL.md", content }];
|
|
10502
10509
|
builtInSkillCache.set(skillId, files);
|
|
@@ -11399,8 +11406,8 @@ function parseMemoryFile(raw, fallbackName) {
|
|
|
11399
11406
|
};
|
|
11400
11407
|
}
|
|
11401
11408
|
async function syncMemories(agent, configDir, log2) {
|
|
11402
|
-
const projectDir =
|
|
11403
|
-
const memoryDir =
|
|
11409
|
+
const projectDir = join13(configDir, agent.code_name, "project");
|
|
11410
|
+
const memoryDir = join13(projectDir, "memory");
|
|
11404
11411
|
const isFreshSync = pendingFreshMemorySync.has(agent.agent_id);
|
|
11405
11412
|
if (isFreshSync) {
|
|
11406
11413
|
log2(`[memory-sync] Fresh-sync requested for '${agent.code_name}' \u2014 pulling DB first`);
|
|
@@ -11411,14 +11418,14 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
11411
11418
|
}
|
|
11412
11419
|
pendingFreshMemorySync.delete(agent.agent_id);
|
|
11413
11420
|
}
|
|
11414
|
-
if (
|
|
11421
|
+
if (existsSync7(memoryDir)) {
|
|
11415
11422
|
const prevHashes = memoryFileHashes.get(agent.agent_id) ?? /* @__PURE__ */ new Map();
|
|
11416
11423
|
const currentHashes = /* @__PURE__ */ new Map();
|
|
11417
11424
|
const changedMemories = [];
|
|
11418
11425
|
for (const file of readdirSync5(memoryDir)) {
|
|
11419
11426
|
if (!file.endsWith(".md")) continue;
|
|
11420
11427
|
try {
|
|
11421
|
-
const raw = readFileSync11(
|
|
11428
|
+
const raw = readFileSync11(join13(memoryDir, file), "utf-8");
|
|
11422
11429
|
const fileHash = createHash4("sha256").update(raw).digest("hex").slice(0, 16);
|
|
11423
11430
|
currentHashes.set(file, fileHash);
|
|
11424
11431
|
if (prevHashes.get(file) === fileHash) continue;
|
|
@@ -11443,7 +11450,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
11443
11450
|
} catch (err) {
|
|
11444
11451
|
for (const mem of changedMemories) {
|
|
11445
11452
|
for (const [file] of currentHashes) {
|
|
11446
|
-
const parsed = parseMemoryFile(readFileSync11(
|
|
11453
|
+
const parsed = parseMemoryFile(readFileSync11(join13(memoryDir, file), "utf-8"), file.replace(/\.md$/, ""));
|
|
11447
11454
|
if (parsed?.name === mem.name) currentHashes.delete(file);
|
|
11448
11455
|
}
|
|
11449
11456
|
}
|
|
@@ -11456,7 +11463,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
11456
11463
|
}
|
|
11457
11464
|
}
|
|
11458
11465
|
async function downloadMemories(agent, memoryDir, log2, { force }) {
|
|
11459
|
-
const localFiles =
|
|
11466
|
+
const localFiles = existsSync7(memoryDir) ? readdirSync5(memoryDir).filter((f) => f.endsWith(".md")).sort() : [];
|
|
11460
11467
|
const localListHash = createHash4("sha256").update(localFiles.join(",")).digest("hex").slice(0, 16);
|
|
11461
11468
|
const prevLocalHash = lastLocalFileHash.get(agent.agent_id);
|
|
11462
11469
|
const prevDownload = lastDownloadHash.get(agent.agent_id);
|
|
@@ -11478,7 +11485,7 @@ async function downloadMemories(agent, memoryDir, log2, { force }) {
|
|
|
11478
11485
|
const mem = dbMemories.memories[i];
|
|
11479
11486
|
const rawSlug = mem.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").slice(0, 60);
|
|
11480
11487
|
const slug = rawSlug || `memory-${i}`;
|
|
11481
|
-
const filePath =
|
|
11488
|
+
const filePath = join13(memoryDir, `${slug}.md`);
|
|
11482
11489
|
const desired = `---
|
|
11483
11490
|
name: ${JSON.stringify(mem.name)}
|
|
11484
11491
|
type: ${mem.type}
|
|
@@ -11487,7 +11494,7 @@ description: ${JSON.stringify(mem.content.slice(0, 200))}
|
|
|
11487
11494
|
|
|
11488
11495
|
${mem.content}
|
|
11489
11496
|
`;
|
|
11490
|
-
if (
|
|
11497
|
+
if (existsSync7(filePath)) {
|
|
11491
11498
|
let existing = "";
|
|
11492
11499
|
try {
|
|
11493
11500
|
existing = readFileSync11(filePath, "utf-8");
|
|
@@ -11514,9 +11521,9 @@ ${mem.content}
|
|
|
11514
11521
|
}
|
|
11515
11522
|
}
|
|
11516
11523
|
async function cleanupAgentFiles(codeName, agentDir) {
|
|
11517
|
-
if (
|
|
11524
|
+
if (existsSync7(agentDir)) {
|
|
11518
11525
|
try {
|
|
11519
|
-
|
|
11526
|
+
rmSync3(agentDir, { recursive: true, force: true });
|
|
11520
11527
|
log(`Removed provision directory for '${codeName}'`);
|
|
11521
11528
|
} catch (err) {
|
|
11522
11529
|
log(`Failed to remove provision dir for '${codeName}': ${err.message}`);
|
|
@@ -11744,7 +11751,7 @@ function startManager(opts) {
|
|
|
11744
11751
|
config = opts;
|
|
11745
11752
|
try {
|
|
11746
11753
|
const stateFile = getStateFile();
|
|
11747
|
-
if (
|
|
11754
|
+
if (existsSync7(stateFile)) {
|
|
11748
11755
|
const raw = readFileSync11(stateFile, "utf-8");
|
|
11749
11756
|
const parsed = JSON.parse(raw);
|
|
11750
11757
|
if (Array.isArray(parsed.agents)) {
|
|
@@ -11766,7 +11773,7 @@ function startManager(opts) {
|
|
|
11766
11773
|
log(`[startup] state rehydration failed (continuing with empty state): ${err.message}`);
|
|
11767
11774
|
}
|
|
11768
11775
|
log(
|
|
11769
|
-
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${
|
|
11776
|
+
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${join13(homedir7(), ".augmented", "manager.log")}`
|
|
11770
11777
|
);
|
|
11771
11778
|
deployMcpAssets();
|
|
11772
11779
|
reapOrphanChannelMcps({ log });
|
|
@@ -11897,14 +11904,14 @@ function restartRunningChannelMcps(basenames) {
|
|
|
11897
11904
|
}
|
|
11898
11905
|
}
|
|
11899
11906
|
function deployMcpAssets() {
|
|
11900
|
-
const targetDir =
|
|
11907
|
+
const targetDir = join13(homedir7(), ".augmented", "_mcp");
|
|
11901
11908
|
mkdirSync4(targetDir, { recursive: true });
|
|
11902
11909
|
const moduleDir = dirname3(fileURLToPath(import.meta.url));
|
|
11903
11910
|
let mcpSourceDir = "";
|
|
11904
11911
|
let dir = moduleDir;
|
|
11905
11912
|
for (let i = 0; i < 6; i++) {
|
|
11906
|
-
const candidate =
|
|
11907
|
-
if (
|
|
11913
|
+
const candidate = join13(dir, "dist", "mcp");
|
|
11914
|
+
if (existsSync7(join13(candidate, "index.js"))) {
|
|
11908
11915
|
mcpSourceDir = candidate;
|
|
11909
11916
|
break;
|
|
11910
11917
|
}
|
|
@@ -11919,7 +11926,7 @@ function deployMcpAssets() {
|
|
|
11919
11926
|
const changedBasenames = [];
|
|
11920
11927
|
const fileHash = (p) => {
|
|
11921
11928
|
try {
|
|
11922
|
-
if (!
|
|
11929
|
+
if (!existsSync7(p)) return null;
|
|
11923
11930
|
return createHash4("sha256").update(readFileSync11(p)).digest("hex");
|
|
11924
11931
|
} catch {
|
|
11925
11932
|
return null;
|
|
@@ -11947,9 +11954,9 @@ function deployMcpAssets() {
|
|
|
11947
11954
|
// natural session restart.
|
|
11948
11955
|
"augmented-admin.js"
|
|
11949
11956
|
]) {
|
|
11950
|
-
const src =
|
|
11951
|
-
const dst =
|
|
11952
|
-
if (!
|
|
11957
|
+
const src = join13(mcpSourceDir, file);
|
|
11958
|
+
const dst = join13(targetDir, file);
|
|
11959
|
+
if (!existsSync7(src)) continue;
|
|
11953
11960
|
const before = fileHash(dst);
|
|
11954
11961
|
try {
|
|
11955
11962
|
copyFileSync(src, dst);
|
|
@@ -11966,14 +11973,14 @@ function deployMcpAssets() {
|
|
|
11966
11973
|
log(`[manager] Bundle(s) updated: ${changedBasenames.join(", ")} \u2014 signalling running instances to restart`);
|
|
11967
11974
|
restartRunningChannelMcps(changedBasenames);
|
|
11968
11975
|
}
|
|
11969
|
-
const localMcpPath =
|
|
11976
|
+
const localMcpPath = join13(targetDir, "index.js");
|
|
11970
11977
|
try {
|
|
11971
|
-
const agentsDir =
|
|
11972
|
-
if (
|
|
11978
|
+
const agentsDir = join13(homedir7(), ".augmented", "agents");
|
|
11979
|
+
if (existsSync7(agentsDir)) {
|
|
11973
11980
|
for (const entry of readdirSync5(agentsDir, { withFileTypes: true })) {
|
|
11974
11981
|
if (!entry.isDirectory()) continue;
|
|
11975
11982
|
for (const subdir of ["provision", "project"]) {
|
|
11976
|
-
const mcpJsonPath =
|
|
11983
|
+
const mcpJsonPath = join13(agentsDir, entry.name, subdir, ".mcp.json");
|
|
11977
11984
|
try {
|
|
11978
11985
|
const raw = readFileSync11(mcpJsonPath, "utf-8");
|
|
11979
11986
|
if (!raw.includes("@integrity-labs/augmented-mcp")) continue;
|