@integrity-labs/agt-cli 0.28.1260 → 0.28.1262
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.
- package/dist/{api-client-PXVHBJBB.js → api-client-DQ7YV5IG.js} +3 -3
- package/dist/bin/agt.js +7 -7
- package/dist/{chunk-UKZ3NXB7.js → chunk-5BXIXSSH.js} +2 -2
- package/dist/{chunk-7EEU3X3T.js → chunk-6YWVKLHF.js} +3 -3
- package/dist/{chunk-E7DKUEXC.js → chunk-CEJNJ6NF.js} +3 -3
- package/dist/{chunk-LLVL6LIB.js → chunk-HJWOXFJM.js} +2 -2
- package/dist/{chunk-UQLSI3C7.js → chunk-KJ5OCCSJ.js} +98 -6
- package/dist/chunk-KJ5OCCSJ.js.map +1 -0
- package/dist/{chunk-NABJJPLW.js → chunk-PIKXAEVA.js} +525 -254
- package/dist/chunk-PIKXAEVA.js.map +1 -0
- package/dist/{claude-code-updater-OXTQF5E5.js → claude-code-updater-JQLNRK25.js} +3 -3
- package/dist/{claude-pair-runtime-BBOAF76W.js → claude-pair-runtime-BJ3EAWEJ.js} +3 -3
- package/dist/lib/manager-worker.js +580 -427
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/mcp/direct-chat-channel.js +94 -2
- package/dist/mcp/index.js +94 -2
- package/dist/mcp/origami.js +94 -2
- package/dist/mcp/slack-channel.js +94 -2
- package/dist/mcp/teams-channel.js +218 -82
- package/dist/mcp/telegram-channel.js +252 -2
- package/dist/{persistent-session-XPDKIBEM.js → persistent-session-YNHYNCNA.js} +4 -4
- package/dist/{responsiveness-probe-4B6Y2446.js → responsiveness-probe-57RV3U2H.js} +4 -4
- package/dist/{session-auth-dead-4C7AK3A6.js → session-auth-dead-A3TO2N63.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-NABJJPLW.js.map +0 -1
- package/dist/chunk-UQLSI3C7.js.map +0 -1
- /package/dist/{api-client-PXVHBJBB.js.map → api-client-DQ7YV5IG.js.map} +0 -0
- /package/dist/{chunk-UKZ3NXB7.js.map → chunk-5BXIXSSH.js.map} +0 -0
- /package/dist/{chunk-7EEU3X3T.js.map → chunk-6YWVKLHF.js.map} +0 -0
- /package/dist/{chunk-E7DKUEXC.js.map → chunk-CEJNJ6NF.js.map} +0 -0
- /package/dist/{chunk-LLVL6LIB.js.map → chunk-HJWOXFJM.js.map} +0 -0
- /package/dist/{claude-code-updater-OXTQF5E5.js.map → claude-code-updater-JQLNRK25.js.map} +0 -0
- /package/dist/{claude-pair-runtime-BBOAF76W.js.map → claude-pair-runtime-BJ3EAWEJ.js.map} +0 -0
- /package/dist/{persistent-session-XPDKIBEM.js.map → persistent-session-YNHYNCNA.js.map} +0 -0
- /package/dist/{responsiveness-probe-4B6Y2446.js.map → responsiveness-probe-57RV3U2H.js.map} +0 -0
- /package/dist/{session-auth-dead-4C7AK3A6.js.map → session-auth-dead-A3TO2N63.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
exchangeApiKey,
|
|
3
3
|
getApiKey,
|
|
4
4
|
getHost
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6YWVKLHF.js";
|
|
6
6
|
import {
|
|
7
7
|
LATE_BOUND_VARS,
|
|
8
8
|
PLATFORM_DENY_PERMISSIONS,
|
|
@@ -25,11 +25,11 @@ import {
|
|
|
25
25
|
shellQuote,
|
|
26
26
|
withheldRemoteMcpMessage,
|
|
27
27
|
withheldRemoteMcpReasonFor
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-CEJNJ6NF.js";
|
|
29
29
|
import {
|
|
30
30
|
readDailySessionPin,
|
|
31
31
|
sessionTranscriptDir
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-HJWOXFJM.js";
|
|
33
33
|
import {
|
|
34
34
|
classifyUnanswerablePane,
|
|
35
35
|
isConsumerTermsDialogVisible,
|
|
@@ -101,7 +101,7 @@ import {
|
|
|
101
101
|
scanConfigForLiteralSecrets,
|
|
102
102
|
worseConnectivityOutcome,
|
|
103
103
|
wrapScheduledTaskPrompt
|
|
104
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-KJ5OCCSJ.js";
|
|
105
105
|
import {
|
|
106
106
|
claudeJsonPathFor,
|
|
107
107
|
effectiveClaudeJsonPath,
|
|
@@ -1148,15 +1148,152 @@ function orderTitlesForDescription(entries) {
|
|
|
1148
1148
|
}
|
|
1149
1149
|
|
|
1150
1150
|
// ../../packages/core/dist/provisioning/frameworks/claudecode/index.js
|
|
1151
|
-
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4, existsSync as existsSync4, chmodSync as chmodSync4, readdirSync, rmSync as rmSync2, copyFileSync, lstatSync, realpathSync, symlinkSync, readlinkSync, renameSync as renameSync4, opendirSync } from "fs";
|
|
1152
|
-
import { join as
|
|
1151
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4, existsSync as existsSync4, chmodSync as chmodSync4, readdirSync, rmSync as rmSync2, copyFileSync, lstatSync as lstatSync2, realpathSync as realpathSync2, symlinkSync, readlinkSync as readlinkSync2, renameSync as renameSync4, opendirSync as opendirSync2 } from "fs";
|
|
1152
|
+
import { join as join6, relative as relative2, dirname as dirname3 } from "path";
|
|
1153
|
+
|
|
1154
|
+
// ../../packages/core/dist/provisioning/frameworks/claudecode/scratch-file-sweep.js
|
|
1155
|
+
import { closeSync, constants, lstatSync, openSync, opendirSync, readlinkSync, realpathSync, rmdirSync, unlinkSync as unlinkSync2 } from "fs";
|
|
1156
|
+
import { join as join3, relative } from "path";
|
|
1157
|
+
var WHOLE_TREE_DIR_NAMES = /* @__PURE__ */ new Set(["node_modules", ".venv", "venv"]);
|
|
1158
|
+
var SCRATCH_FILE_SWEEP_ENTRY_BUDGET = 2e5;
|
|
1159
|
+
var lastChange = (s) => Math.max(s.mtimeMs, s.ctimeMs);
|
|
1160
|
+
function sweepScratchFiles(scratchDir, opts) {
|
|
1161
|
+
const result = { files: 0, bytes: 0, emptyDirs: 0, wholeTreesKept: 0, truncated: false };
|
|
1162
|
+
let budget = opts.entryBudget ?? SCRATCH_FILE_SWEEP_ENTRY_BUDGET;
|
|
1163
|
+
let realScratch;
|
|
1164
|
+
try {
|
|
1165
|
+
if (!lstatSync(scratchDir).isDirectory())
|
|
1166
|
+
return result;
|
|
1167
|
+
realScratch = realpathSync(scratchDir);
|
|
1168
|
+
} catch {
|
|
1169
|
+
return result;
|
|
1170
|
+
}
|
|
1171
|
+
const placeInScratch = (dir) => join3(realScratch, relative(scratchDir, dir));
|
|
1172
|
+
const stillInside = (dir) => {
|
|
1173
|
+
try {
|
|
1174
|
+
return realpathSync(dir) === placeInScratch(dir);
|
|
1175
|
+
} catch {
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
const removeFrom = (dir, name, remove) => {
|
|
1180
|
+
if (!opts.remove)
|
|
1181
|
+
return stillInside(dir);
|
|
1182
|
+
let fd;
|
|
1183
|
+
try {
|
|
1184
|
+
fd = openSync(dir, constants.O_RDONLY | constants.O_DIRECTORY);
|
|
1185
|
+
} catch {
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
const pinned = `/proc/self/fd/${fd}`;
|
|
1190
|
+
let actual;
|
|
1191
|
+
try {
|
|
1192
|
+
actual = readlinkSync(pinned);
|
|
1193
|
+
} catch {
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
if (actual !== placeInScratch(dir))
|
|
1197
|
+
return false;
|
|
1198
|
+
opts.beforeRemove?.(join3(dir, name));
|
|
1199
|
+
remove(join3(pinned, name));
|
|
1200
|
+
return true;
|
|
1201
|
+
} finally {
|
|
1202
|
+
closeSync(fd);
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
const childrenOf = (dir) => {
|
|
1206
|
+
try {
|
|
1207
|
+
const handle = opendirSync(dir);
|
|
1208
|
+
const names = [];
|
|
1209
|
+
try {
|
|
1210
|
+
for (let entry = handle.readSync(); entry !== null; entry = handle.readSync()) {
|
|
1211
|
+
if (names.length >= budget) {
|
|
1212
|
+
result.truncated = true;
|
|
1213
|
+
break;
|
|
1214
|
+
}
|
|
1215
|
+
names.push(entry.name);
|
|
1216
|
+
}
|
|
1217
|
+
} finally {
|
|
1218
|
+
handle.closeSync();
|
|
1219
|
+
}
|
|
1220
|
+
return names;
|
|
1221
|
+
} catch {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
const walk = (dir) => {
|
|
1226
|
+
opts.beforeCheck?.(dir);
|
|
1227
|
+
if (!stillInside(dir))
|
|
1228
|
+
return 1;
|
|
1229
|
+
const names = childrenOf(dir);
|
|
1230
|
+
if (names === null)
|
|
1231
|
+
return 1;
|
|
1232
|
+
let left = names.length;
|
|
1233
|
+
if (names.includes(".git") || names.includes("pyvenv.cfg") || names.includes("HEAD") && names.includes("objects")) {
|
|
1234
|
+
result.wholeTreesKept += 1;
|
|
1235
|
+
return left || 1;
|
|
1236
|
+
}
|
|
1237
|
+
for (const name of names) {
|
|
1238
|
+
if (result.truncated || budget-- <= 0) {
|
|
1239
|
+
result.truncated = true;
|
|
1240
|
+
return left || 1;
|
|
1241
|
+
}
|
|
1242
|
+
const full = join3(dir, name);
|
|
1243
|
+
let stat;
|
|
1244
|
+
try {
|
|
1245
|
+
stat = lstatSync(full);
|
|
1246
|
+
} catch {
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
if (!stat.isDirectory()) {
|
|
1250
|
+
if (lastChange(stat) >= opts.cutoff)
|
|
1251
|
+
continue;
|
|
1252
|
+
try {
|
|
1253
|
+
opts.beforeCheck?.(full);
|
|
1254
|
+
if (!removeFrom(dir, name, unlinkSync2))
|
|
1255
|
+
return left || 1;
|
|
1256
|
+
result.files += 1;
|
|
1257
|
+
result.bytes += stat.size;
|
|
1258
|
+
left -= 1;
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
if (WHOLE_TREE_DIR_NAMES.has(name)) {
|
|
1264
|
+
result.wholeTreesKept += 1;
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
const removedBefore = result.files + result.emptyDirs;
|
|
1268
|
+
if (walk(full) > 0)
|
|
1269
|
+
continue;
|
|
1270
|
+
if (result.files + result.emptyDirs > removedBefore)
|
|
1271
|
+
continue;
|
|
1272
|
+
if (lastChange(stat) >= opts.cutoff)
|
|
1273
|
+
continue;
|
|
1274
|
+
try {
|
|
1275
|
+
opts.beforeCheck?.(full);
|
|
1276
|
+
if (!removeFrom(dir, name, rmdirSync))
|
|
1277
|
+
return left || 1;
|
|
1278
|
+
result.emptyDirs += 1;
|
|
1279
|
+
left -= 1;
|
|
1280
|
+
} catch {
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return left;
|
|
1284
|
+
};
|
|
1285
|
+
walk(scratchDir);
|
|
1286
|
+
return result;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// ../../packages/core/dist/provisioning/frameworks/claudecode/index.js
|
|
1153
1290
|
import { homedir as homedir3, tmpdir } from "os";
|
|
1154
1291
|
import { execFile } from "child_process";
|
|
1155
1292
|
|
|
1156
1293
|
// ../../packages/core/dist/integrations/xurl-config.js
|
|
1157
|
-
import { chmodSync as chmodSync2, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, unlinkSync as
|
|
1294
|
+
import { chmodSync as chmodSync2, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
1158
1295
|
import { homedir } from "os";
|
|
1159
|
-
import { dirname, join as
|
|
1296
|
+
import { dirname, join as join4 } from "path";
|
|
1160
1297
|
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
1161
1298
|
var XURL_FILE_MODE = 384;
|
|
1162
1299
|
var XURL_AGT_APP_PREFIX = "agt-";
|
|
@@ -1275,7 +1412,7 @@ function buildAgtXurlApps(integrations) {
|
|
|
1275
1412
|
}
|
|
1276
1413
|
function getXurlStorePath() {
|
|
1277
1414
|
const home = process.env["HOME"] ?? process.env["USERPROFILE"] ?? homedir();
|
|
1278
|
-
return
|
|
1415
|
+
return join4(home, ".xurl");
|
|
1279
1416
|
}
|
|
1280
1417
|
function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath()) {
|
|
1281
1418
|
const agtApps = buildAgtXurlApps(integrations);
|
|
@@ -1303,7 +1440,7 @@ function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath
|
|
|
1303
1440
|
renameSync2(tmpPath, filePath);
|
|
1304
1441
|
} catch (err) {
|
|
1305
1442
|
try {
|
|
1306
|
-
|
|
1443
|
+
unlinkSync3(tmpPath);
|
|
1307
1444
|
} catch {
|
|
1308
1445
|
}
|
|
1309
1446
|
throw err;
|
|
@@ -1316,9 +1453,9 @@ function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath
|
|
|
1316
1453
|
}
|
|
1317
1454
|
|
|
1318
1455
|
// ../../packages/core/dist/integrations/framer-credentials.js
|
|
1319
|
-
import { chmodSync as chmodSync3, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync, statSync, unlinkSync as
|
|
1456
|
+
import { chmodSync as chmodSync3, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync, statSync, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
1320
1457
|
import { homedir as homedir2 } from "os";
|
|
1321
|
-
import { dirname as dirname2, join as
|
|
1458
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
1322
1459
|
var FRAMER_PROJECTS_CONFIG_VERSION = 2;
|
|
1323
1460
|
var BARE_PROJECT_ID = /^[A-Za-z0-9]{20}$/u;
|
|
1324
1461
|
var SLUGGED_PROJECT_ID = /^.+--([A-Za-z0-9]+)/u;
|
|
@@ -1417,7 +1554,7 @@ function mergeFramerProjectsConfig(existing, inputs, options = {}) {
|
|
|
1417
1554
|
var FRAMER_FILE_MODE = 384;
|
|
1418
1555
|
var MANAGED_SIDECAR_NAME = ".augmented-managed-projects.json";
|
|
1419
1556
|
function sidecarPathFor(projectsPath) {
|
|
1420
|
-
return
|
|
1557
|
+
return join5(dirname2(projectsPath), MANAGED_SIDECAR_NAME);
|
|
1421
1558
|
}
|
|
1422
1559
|
function readManagedIds(projectsPath) {
|
|
1423
1560
|
try {
|
|
@@ -1435,7 +1572,7 @@ function writeManagedIds(projectsPath, ids) {
|
|
|
1435
1572
|
try {
|
|
1436
1573
|
if (ids.length === 0) {
|
|
1437
1574
|
try {
|
|
1438
|
-
|
|
1575
|
+
unlinkSync4(target);
|
|
1439
1576
|
} catch {
|
|
1440
1577
|
}
|
|
1441
1578
|
return;
|
|
@@ -1493,9 +1630,9 @@ function asString2(value) {
|
|
|
1493
1630
|
function getFramerProjectsPath() {
|
|
1494
1631
|
const xdg = process.env["XDG_CONFIG_HOME"];
|
|
1495
1632
|
if (xdg)
|
|
1496
|
-
return
|
|
1633
|
+
return join5(xdg, "framer", "projects.json");
|
|
1497
1634
|
const home = process.env["HOME"] ?? process.env["USERPROFILE"] ?? homedir2();
|
|
1498
|
-
return
|
|
1635
|
+
return join5(home, ".config", "framer", "projects.json");
|
|
1499
1636
|
}
|
|
1500
1637
|
function buildFramerCredentialInputs(integrations) {
|
|
1501
1638
|
const inputs = [];
|
|
@@ -1545,7 +1682,7 @@ function writeFramerStoreForIntegrations(integrations, filePath = getFramerProje
|
|
|
1545
1682
|
renameSync3(tmpPath, filePath);
|
|
1546
1683
|
} catch (err) {
|
|
1547
1684
|
try {
|
|
1548
|
-
|
|
1685
|
+
unlinkSync4(tmpPath);
|
|
1549
1686
|
} catch {
|
|
1550
1687
|
}
|
|
1551
1688
|
throw err;
|
|
@@ -2355,7 +2492,7 @@ var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
|
2355
2492
|
var SECRET_FILE_MODE = 384;
|
|
2356
2493
|
function writeEnvIntegrationsForAgent(codeName, args) {
|
|
2357
2494
|
const agentDir = getAgentDir(codeName);
|
|
2358
|
-
const envPath =
|
|
2495
|
+
const envPath = join6(agentDir, ".env.integrations");
|
|
2359
2496
|
let existing = null;
|
|
2360
2497
|
try {
|
|
2361
2498
|
existing = readFileSync5(envPath, "utf-8");
|
|
@@ -2372,7 +2509,7 @@ function writeEnvIntegrationsForAgent(codeName, args) {
|
|
|
2372
2509
|
try {
|
|
2373
2510
|
const projectDir = getProjectDir2(codeName);
|
|
2374
2511
|
mkdirSync4(projectDir, { recursive: true });
|
|
2375
|
-
const dest =
|
|
2512
|
+
const dest = join6(projectDir, ".env.integrations");
|
|
2376
2513
|
writeFileSync5(dest, content, { mode: SECRET_FILE_MODE });
|
|
2377
2514
|
try {
|
|
2378
2515
|
chmodSync4(dest, SECRET_FILE_MODE);
|
|
@@ -2393,7 +2530,7 @@ var MIGRATABLE_FIELD_TO_ENV_VAR = {
|
|
|
2393
2530
|
AGT_API_KEY: "AGT_API_KEY"
|
|
2394
2531
|
};
|
|
2395
2532
|
function migrateExistingLiteralSecrets(codeName) {
|
|
2396
|
-
const mcpJsonPath =
|
|
2533
|
+
const mcpJsonPath = join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
2397
2534
|
let config;
|
|
2398
2535
|
try {
|
|
2399
2536
|
config = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
@@ -2402,7 +2539,7 @@ function migrateExistingLiteralSecrets(codeName) {
|
|
|
2402
2539
|
}
|
|
2403
2540
|
let existingEnvKeys = /* @__PURE__ */ new Set();
|
|
2404
2541
|
try {
|
|
2405
|
-
existingEnvKeys = new Set(parseEnvFileEntries(readFileSync5(
|
|
2542
|
+
existingEnvKeys = new Set(parseEnvFileEntries(readFileSync5(join6(getAgentDir(codeName), ".env.integrations"), "utf-8")).keys());
|
|
2406
2543
|
} catch {
|
|
2407
2544
|
}
|
|
2408
2545
|
const updates = {};
|
|
@@ -2465,8 +2602,8 @@ function assertValidAgentId(agentId) {
|
|
|
2465
2602
|
}
|
|
2466
2603
|
function resolveRealAgentPath(codeNamePath) {
|
|
2467
2604
|
try {
|
|
2468
|
-
if (
|
|
2469
|
-
return
|
|
2605
|
+
if (lstatSync2(codeNamePath).isSymbolicLink()) {
|
|
2606
|
+
return realpathSync2(codeNamePath);
|
|
2470
2607
|
}
|
|
2471
2608
|
} catch {
|
|
2472
2609
|
}
|
|
@@ -2476,11 +2613,11 @@ function ensureIdKeyedLayout(codeName, agentId) {
|
|
|
2476
2613
|
assertValidCodeName(codeName);
|
|
2477
2614
|
assertValidAgentId(agentId);
|
|
2478
2615
|
const home = getHomeDir();
|
|
2479
|
-
const codeNamePath =
|
|
2480
|
-
const idPath =
|
|
2616
|
+
const codeNamePath = join6(home, ".augmented", codeName);
|
|
2617
|
+
const idPath = join6(home, ".augmented", agentId);
|
|
2481
2618
|
let state;
|
|
2482
2619
|
try {
|
|
2483
|
-
state =
|
|
2620
|
+
state = lstatSync2(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
2484
2621
|
} catch {
|
|
2485
2622
|
state = "absent";
|
|
2486
2623
|
}
|
|
@@ -2488,7 +2625,7 @@ function ensureIdKeyedLayout(codeName, agentId) {
|
|
|
2488
2625
|
return codeNamePath;
|
|
2489
2626
|
}
|
|
2490
2627
|
if (state === "symlink") {
|
|
2491
|
-
const target =
|
|
2628
|
+
const target = readlinkSync2(codeNamePath);
|
|
2492
2629
|
if (target !== agentId) {
|
|
2493
2630
|
throw new Error(`Codename symlink ${codeNamePath} points at "${target}", expected "${agentId}"; refusing to provision over a mismatched id-keyed layout.`);
|
|
2494
2631
|
}
|
|
@@ -2500,18 +2637,18 @@ function ensureIdKeyedLayout(codeName, agentId) {
|
|
|
2500
2637
|
return idPath;
|
|
2501
2638
|
}
|
|
2502
2639
|
function stagedMigrationLinkPath(home, codeName) {
|
|
2503
|
-
return
|
|
2640
|
+
return join6(home, ".augmented", `.${codeName}.migrating`);
|
|
2504
2641
|
}
|
|
2505
2642
|
function cleanupStaleStagedLink(staged) {
|
|
2506
2643
|
try {
|
|
2507
|
-
if (
|
|
2644
|
+
if (lstatSync2(staged).isSymbolicLink())
|
|
2508
2645
|
rmSync2(staged, { force: true });
|
|
2509
2646
|
} catch {
|
|
2510
2647
|
}
|
|
2511
2648
|
}
|
|
2512
2649
|
function isSymlinkTo(path, target) {
|
|
2513
2650
|
try {
|
|
2514
|
-
return
|
|
2651
|
+
return lstatSync2(path).isSymbolicLink() && readlinkSync2(path) === target;
|
|
2515
2652
|
} catch {
|
|
2516
2653
|
return false;
|
|
2517
2654
|
}
|
|
@@ -2520,18 +2657,18 @@ function migrateAgentDirToIdKeyed(codeName, agentId, opts = {}) {
|
|
|
2520
2657
|
assertValidCodeName(codeName);
|
|
2521
2658
|
assertValidAgentId(agentId);
|
|
2522
2659
|
const home = opts.home ?? getHomeDir();
|
|
2523
|
-
const codeNamePath =
|
|
2524
|
-
const idPath =
|
|
2660
|
+
const codeNamePath = join6(home, ".augmented", codeName);
|
|
2661
|
+
const idPath = join6(home, ".augmented", agentId);
|
|
2525
2662
|
const staged = stagedMigrationLinkPath(home, codeName);
|
|
2526
2663
|
let codeNameKind;
|
|
2527
2664
|
try {
|
|
2528
|
-
codeNameKind =
|
|
2665
|
+
codeNameKind = lstatSync2(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
2529
2666
|
} catch {
|
|
2530
2667
|
codeNameKind = "absent";
|
|
2531
2668
|
}
|
|
2532
2669
|
const idExists = existsSync4(idPath);
|
|
2533
2670
|
if (codeNameKind === "symlink") {
|
|
2534
|
-
const target =
|
|
2671
|
+
const target = readlinkSync2(codeNamePath);
|
|
2535
2672
|
if (target !== agentId) {
|
|
2536
2673
|
throw new Error(`Codename symlink ${codeNamePath} points at "${target}", expected "${agentId}"; refusing to migrate.`);
|
|
2537
2674
|
}
|
|
@@ -2559,14 +2696,14 @@ function migrateAgentDirToIdKeyed(codeName, agentId, opts = {}) {
|
|
|
2559
2696
|
}
|
|
2560
2697
|
function getAgentDir(codeName) {
|
|
2561
2698
|
assertValidCodeName(codeName);
|
|
2562
|
-
return resolveRealAgentPath(
|
|
2699
|
+
return resolveRealAgentPath(join6(getHomeDir(), ".augmented", codeName));
|
|
2563
2700
|
}
|
|
2564
2701
|
var migratedCodeNames = /* @__PURE__ */ new Set();
|
|
2565
2702
|
function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
2566
2703
|
assertValidCodeName(codeName);
|
|
2567
2704
|
if (migratedCodeNames.has(codeName))
|
|
2568
2705
|
return;
|
|
2569
|
-
const legacyRoot =
|
|
2706
|
+
const legacyRoot = join6(getHomeDir(), ".augmented", codeName, "claudecode");
|
|
2570
2707
|
if (!existsSync4(legacyRoot)) {
|
|
2571
2708
|
migratedCodeNames.add(codeName);
|
|
2572
2709
|
return;
|
|
@@ -2579,8 +2716,8 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
2579
2716
|
const walkAndMigrate = (srcDir, destDir) => {
|
|
2580
2717
|
mkdirSync4(destDir, { recursive: true });
|
|
2581
2718
|
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
2582
|
-
const src =
|
|
2583
|
-
const dest =
|
|
2719
|
+
const src = join6(srcDir, entry.name);
|
|
2720
|
+
const dest = join6(destDir, entry.name);
|
|
2584
2721
|
if (entry.isDirectory()) {
|
|
2585
2722
|
walkAndMigrate(src, dest);
|
|
2586
2723
|
continue;
|
|
@@ -2620,13 +2757,13 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
2620
2757
|
}
|
|
2621
2758
|
}
|
|
2622
2759
|
function syncGitHubBrokerCredentialTooling(projectDir, enabled) {
|
|
2623
|
-
const binDir =
|
|
2760
|
+
const binDir = join6(projectDir, GITHUB_BROKER_BIN_DIR);
|
|
2624
2761
|
if (!enabled) {
|
|
2625
2762
|
rmSync2(binDir, { recursive: true, force: true });
|
|
2626
2763
|
return {};
|
|
2627
2764
|
}
|
|
2628
|
-
const helperPath =
|
|
2629
|
-
const shimPath =
|
|
2765
|
+
const helperPath = join6(binDir, GIT_CREDENTIAL_HELPER_BASENAME);
|
|
2766
|
+
const shimPath = join6(binDir, GH_SHIM_BASENAME);
|
|
2630
2767
|
mkdirSync4(binDir, { recursive: true });
|
|
2631
2768
|
writeFileSync5(helperPath, renderGitCredentialHelper(), { mode: BROKER_SCRIPT_MODE });
|
|
2632
2769
|
chmodSync4(helperPath, BROKER_SCRIPT_MODE);
|
|
@@ -2635,10 +2772,10 @@ function syncGitHubBrokerCredentialTooling(projectDir, enabled) {
|
|
|
2635
2772
|
return buildGitCredentialEnv(helperPath);
|
|
2636
2773
|
}
|
|
2637
2774
|
function getProjectDir2(codeName) {
|
|
2638
|
-
return
|
|
2775
|
+
return join6(getAgentDir(codeName), "project");
|
|
2639
2776
|
}
|
|
2640
2777
|
function reapLegacyTokenFile(codeName, onWarn = void 0) {
|
|
2641
|
-
const tokenFilePath =
|
|
2778
|
+
const tokenFilePath = join6(getAgentDir(codeName), ".tokens.json");
|
|
2642
2779
|
try {
|
|
2643
2780
|
rmSync2(tokenFilePath, { force: true });
|
|
2644
2781
|
return true;
|
|
@@ -2648,13 +2785,42 @@ function reapLegacyTokenFile(codeName, onWarn = void 0) {
|
|
|
2648
2785
|
}
|
|
2649
2786
|
}
|
|
2650
2787
|
function getScratchDir(codeName) {
|
|
2651
|
-
return
|
|
2788
|
+
return join6(getAgentDir(codeName), "scratch");
|
|
2652
2789
|
}
|
|
2653
2790
|
function getAgentTmpDir(codeName) {
|
|
2654
2791
|
return agentTmpDirFor(getAgentDir(codeName));
|
|
2655
2792
|
}
|
|
2656
|
-
|
|
2793
|
+
var TREE_RULE_ONLY = { held: false, perFile: false, dryRun: false };
|
|
2794
|
+
var scratchSweepPolicyResolver = () => TREE_RULE_ONLY;
|
|
2795
|
+
function setScratchSweepPolicyResolver(resolver) {
|
|
2796
|
+
scratchSweepPolicyResolver = resolver;
|
|
2797
|
+
}
|
|
2798
|
+
var SCRATCH_FILE_SWEEP_INTERVAL_MS = 60 * 60 * 1e3;
|
|
2799
|
+
var SCRATCH_DRY_RUN_INTERVAL_MS = 6 * 60 * 60 * 1e3;
|
|
2800
|
+
var lastFileSweepAt = /* @__PURE__ */ new Map();
|
|
2801
|
+
function runScratchFileSweep(codeName, now, cutoff, remove) {
|
|
2802
|
+
const last = lastFileSweepAt.get(codeName);
|
|
2803
|
+
if (last !== void 0 && now - last < (remove ? SCRATCH_FILE_SWEEP_INTERVAL_MS : SCRATCH_DRY_RUN_INTERVAL_MS))
|
|
2804
|
+
return 0;
|
|
2805
|
+
lastFileSweepAt.set(codeName, now);
|
|
2806
|
+
const r = sweepScratchFiles(getScratchDir(codeName), { cutoff, remove });
|
|
2807
|
+
process.stderr.write(`[scratch] [${remove ? "sweep-per-file" : "sweep-dry-run"}] agent=${codeName} ${remove ? "removed" : "would_remove"}_files=${r.files} ${remove ? "removed" : "would_remove"}_bytes=${r.bytes} empty_dirs=${r.emptyDirs} whole_trees_kept=${r.wholeTreesKept} truncated=${r.truncated}
|
|
2808
|
+
`);
|
|
2809
|
+
return remove ? r.files + r.emptyDirs : 0;
|
|
2810
|
+
}
|
|
2811
|
+
function sweepScratchDir(codeName, now = Date.now(), policy = scratchSweepPolicyResolver(codeName)) {
|
|
2812
|
+
if (policy.held)
|
|
2813
|
+
return 0;
|
|
2657
2814
|
const scratchDir = getScratchDir(codeName);
|
|
2815
|
+
try {
|
|
2816
|
+
if (lstatSync2(scratchDir).isSymbolicLink()) {
|
|
2817
|
+
process.stderr.write(`[scratch] [sweep-refused] agent=${codeName} reason=scratch-is-a-symlink
|
|
2818
|
+
`);
|
|
2819
|
+
return 0;
|
|
2820
|
+
}
|
|
2821
|
+
} catch {
|
|
2822
|
+
return 0;
|
|
2823
|
+
}
|
|
2658
2824
|
let removed = 0;
|
|
2659
2825
|
let entries;
|
|
2660
2826
|
try {
|
|
@@ -2664,7 +2830,7 @@ function sweepScratchDir(codeName, now = Date.now()) {
|
|
|
2664
2830
|
}
|
|
2665
2831
|
const cutoff = now - SCRATCH_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
|
|
2666
2832
|
for (const entry of entries) {
|
|
2667
|
-
const full =
|
|
2833
|
+
const full = join6(scratchDir, entry);
|
|
2668
2834
|
try {
|
|
2669
2835
|
if (isFreshWithin(full, cutoff))
|
|
2670
2836
|
continue;
|
|
@@ -2673,6 +2839,8 @@ function sweepScratchDir(codeName, now = Date.now()) {
|
|
|
2673
2839
|
} catch {
|
|
2674
2840
|
}
|
|
2675
2841
|
}
|
|
2842
|
+
if (policy.perFile || policy.dryRun)
|
|
2843
|
+
removed += runScratchFileSweep(codeName, now, cutoff, policy.perFile);
|
|
2676
2844
|
return removed;
|
|
2677
2845
|
}
|
|
2678
2846
|
var STRANDED_ARTEFACT_TMP_PREFIXES = [
|
|
@@ -2692,7 +2860,7 @@ function sweepStrandedArtefactTmpDirs(now = Date.now()) {
|
|
|
2692
2860
|
for (const entry of entries) {
|
|
2693
2861
|
if (!STRANDED_ARTEFACT_TMP_PREFIXES.some((prefix) => entry.startsWith(prefix)))
|
|
2694
2862
|
continue;
|
|
2695
|
-
const full =
|
|
2863
|
+
const full = join6(root, entry);
|
|
2696
2864
|
try {
|
|
2697
2865
|
if (isFreshWithin(full, cutoff))
|
|
2698
2866
|
continue;
|
|
@@ -2713,7 +2881,7 @@ function isFreshWithin(path, cutoff) {
|
|
|
2713
2881
|
const current = queue.pop();
|
|
2714
2882
|
let stat;
|
|
2715
2883
|
try {
|
|
2716
|
-
stat =
|
|
2884
|
+
stat = lstatSync2(current);
|
|
2717
2885
|
} catch {
|
|
2718
2886
|
return true;
|
|
2719
2887
|
}
|
|
@@ -2723,7 +2891,7 @@ function isFreshWithin(path, cutoff) {
|
|
|
2723
2891
|
continue;
|
|
2724
2892
|
let dir;
|
|
2725
2893
|
try {
|
|
2726
|
-
dir =
|
|
2894
|
+
dir = opendirSync2(current);
|
|
2727
2895
|
} catch {
|
|
2728
2896
|
return true;
|
|
2729
2897
|
}
|
|
@@ -2732,7 +2900,7 @@ function isFreshWithin(path, cutoff) {
|
|
|
2732
2900
|
const child = dir.readSync();
|
|
2733
2901
|
if (child === null)
|
|
2734
2902
|
break;
|
|
2735
|
-
queue.push(
|
|
2903
|
+
queue.push(join6(current, child.name));
|
|
2736
2904
|
budget -= 1;
|
|
2737
2905
|
}
|
|
2738
2906
|
} catch {
|
|
@@ -2749,8 +2917,8 @@ function isFreshWithin(path, cutoff) {
|
|
|
2749
2917
|
function syncMcpToProject(codeName, provisionContent) {
|
|
2750
2918
|
const agentDir = getAgentDir(codeName);
|
|
2751
2919
|
const projectDir = getProjectDir2(codeName);
|
|
2752
|
-
const provisionMcpPath =
|
|
2753
|
-
const projectMcpPath =
|
|
2920
|
+
const provisionMcpPath = join6(agentDir, "provision", ".mcp.json");
|
|
2921
|
+
const projectMcpPath = join6(projectDir, ".mcp.json");
|
|
2754
2922
|
let content = provisionContent ?? null;
|
|
2755
2923
|
if (content === null) {
|
|
2756
2924
|
try {
|
|
@@ -2784,7 +2952,7 @@ function syncMcpToProject(codeName, provisionContent) {
|
|
|
2784
2952
|
}
|
|
2785
2953
|
var INTEGRATIONS_SUMMARY_FILE = "integrations-summary.json";
|
|
2786
2954
|
function integrationsSummaryPath(codeName) {
|
|
2787
|
-
return
|
|
2955
|
+
return join6(getAgentDir(codeName), "provision", INTEGRATIONS_SUMMARY_FILE);
|
|
2788
2956
|
}
|
|
2789
2957
|
function writeIntegrationsSummaryForAgent(codeName, summaries) {
|
|
2790
2958
|
const target = integrationsSummaryPath(codeName);
|
|
@@ -2806,7 +2974,7 @@ function readIntegrationsSummaryForAgent(codeName) {
|
|
|
2806
2974
|
function renderChannelMessageHandlerForAgent(codeName) {
|
|
2807
2975
|
const agentDir = getAgentDir(codeName);
|
|
2808
2976
|
const projectDir = getProjectDir2(codeName);
|
|
2809
|
-
const provisionMcpPath =
|
|
2977
|
+
const provisionMcpPath = join6(agentDir, "provision", ".mcp.json");
|
|
2810
2978
|
let mcpServerKeys;
|
|
2811
2979
|
try {
|
|
2812
2980
|
const config = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
@@ -2817,7 +2985,7 @@ function renderChannelMessageHandlerForAgent(codeName) {
|
|
|
2817
2985
|
const integrations = readIntegrationsSummaryForAgent(codeName);
|
|
2818
2986
|
const content = buildChannelMessageHandlerAgent({ mcpServerKeys, integrations });
|
|
2819
2987
|
for (const baseDir of [agentDir, projectDir]) {
|
|
2820
|
-
const target =
|
|
2988
|
+
const target = join6(baseDir, ".claude", "agents", "channel-message-handler.md");
|
|
2821
2989
|
try {
|
|
2822
2990
|
mkdirSync4(dirname3(target), { recursive: true });
|
|
2823
2991
|
writeFileSync5(target, content);
|
|
@@ -2840,7 +3008,7 @@ function writeMcpJsonGuarded(codeName, path, config) {
|
|
|
2840
3008
|
return true;
|
|
2841
3009
|
}
|
|
2842
3010
|
function readExistingMcpEnvVar(codeName, serverId, envKey) {
|
|
2843
|
-
const mcpJsonPath =
|
|
3011
|
+
const mcpJsonPath = join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
2844
3012
|
try {
|
|
2845
3013
|
const raw = readFileSync5(mcpJsonPath, "utf-8");
|
|
2846
3014
|
const config = JSON.parse(raw);
|
|
@@ -2946,8 +3114,8 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2946
3114
|
const SKILLS_START = SKILLS_INDEX_SECTION_START;
|
|
2947
3115
|
const SKILLS_END = SKILLS_INDEX_SECTION_END;
|
|
2948
3116
|
for (const file of artifactFiles) {
|
|
2949
|
-
const src =
|
|
2950
|
-
const dest =
|
|
3117
|
+
const src = join6(provisionDir, file);
|
|
3118
|
+
const dest = join6(projectDir, file);
|
|
2951
3119
|
try {
|
|
2952
3120
|
const srcContent = readFileSync5(src, "utf-8");
|
|
2953
3121
|
if (file === "CLAUDE.md" && existsSync4(dest)) {
|
|
@@ -2973,15 +3141,15 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2973
3141
|
} catch {
|
|
2974
3142
|
}
|
|
2975
3143
|
}
|
|
2976
|
-
const skillsDir =
|
|
2977
|
-
const destSkillsDir =
|
|
3144
|
+
const skillsDir = join6(provisionDir, ".claude", "skills");
|
|
3145
|
+
const destSkillsDir = join6(projectDir, ".claude", "skills");
|
|
2978
3146
|
try {
|
|
2979
3147
|
if (existsSync4(destSkillsDir)) {
|
|
2980
3148
|
const srcFolders = existsSync4(skillsDir) ? new Set(readdirSync(skillsDir)) : /* @__PURE__ */ new Set();
|
|
2981
3149
|
for (const folder of readdirSync(destSkillsDir)) {
|
|
2982
3150
|
if (folder.startsWith("knowledge-") || folder === "core-knowledge" && !srcFolders.has(folder)) {
|
|
2983
3151
|
try {
|
|
2984
|
-
rmSync2(
|
|
3152
|
+
rmSync2(join6(destSkillsDir, folder), { recursive: true });
|
|
2985
3153
|
} catch {
|
|
2986
3154
|
}
|
|
2987
3155
|
}
|
|
@@ -2989,11 +3157,11 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2989
3157
|
}
|
|
2990
3158
|
if (existsSync4(skillsDir)) {
|
|
2991
3159
|
for (const skillFolder of readdirSync(skillsDir)) {
|
|
2992
|
-
const srcSkillFile =
|
|
3160
|
+
const srcSkillFile = join6(skillsDir, skillFolder, "SKILL.md");
|
|
2993
3161
|
if (!existsSync4(srcSkillFile))
|
|
2994
3162
|
continue;
|
|
2995
|
-
const destFolder =
|
|
2996
|
-
const destFile =
|
|
3163
|
+
const destFolder = join6(destSkillsDir, skillFolder);
|
|
3164
|
+
const destFile = join6(destFolder, "SKILL.md");
|
|
2997
3165
|
const srcContent = readFileSync5(srcSkillFile, "utf-8");
|
|
2998
3166
|
try {
|
|
2999
3167
|
if (existsSync4(destFile) && readFileSync5(destFile, "utf-8") === srcContent)
|
|
@@ -3006,8 +3174,8 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3006
3174
|
}
|
|
3007
3175
|
} catch {
|
|
3008
3176
|
}
|
|
3009
|
-
const agentsDir =
|
|
3010
|
-
const destAgentsDir =
|
|
3177
|
+
const agentsDir = join6(provisionDir, ".claude", "agents");
|
|
3178
|
+
const destAgentsDir = join6(projectDir, ".claude", "agents");
|
|
3011
3179
|
try {
|
|
3012
3180
|
if (existsSync4(agentsDir)) {
|
|
3013
3181
|
const sourceAgentFiles = new Set(readdirSync(agentsDir).filter((f) => f.endsWith(".md")));
|
|
@@ -3018,14 +3186,14 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3018
3186
|
if (sourceAgentFiles.has(destFile))
|
|
3019
3187
|
continue;
|
|
3020
3188
|
try {
|
|
3021
|
-
rmSync2(
|
|
3189
|
+
rmSync2(join6(destAgentsDir, destFile));
|
|
3022
3190
|
} catch {
|
|
3023
3191
|
}
|
|
3024
3192
|
}
|
|
3025
3193
|
}
|
|
3026
3194
|
for (const agentFile of sourceAgentFiles) {
|
|
3027
|
-
const srcPath =
|
|
3028
|
-
const destPath =
|
|
3195
|
+
const srcPath = join6(agentsDir, agentFile);
|
|
3196
|
+
const destPath = join6(destAgentsDir, agentFile);
|
|
3029
3197
|
const srcContent = readFileSync5(srcPath, "utf-8");
|
|
3030
3198
|
try {
|
|
3031
3199
|
if (existsSync4(destPath) && readFileSync5(destPath, "utf-8") === srcContent)
|
|
@@ -3038,8 +3206,8 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3038
3206
|
}
|
|
3039
3207
|
} catch {
|
|
3040
3208
|
}
|
|
3041
|
-
const workflowsDir =
|
|
3042
|
-
const destWorkflowsDir =
|
|
3209
|
+
const workflowsDir = join6(provisionDir, ".claude", "workflows");
|
|
3210
|
+
const destWorkflowsDir = join6(projectDir, ".claude", "workflows");
|
|
3043
3211
|
try {
|
|
3044
3212
|
const sourceWorkflowFiles = existsSync4(workflowsDir) ? new Set(readdirSync(workflowsDir).filter((f) => f.endsWith(".js"))) : /* @__PURE__ */ new Set();
|
|
3045
3213
|
if (existsSync4(destWorkflowsDir)) {
|
|
@@ -3049,14 +3217,14 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3049
3217
|
if (sourceWorkflowFiles.has(destFile))
|
|
3050
3218
|
continue;
|
|
3051
3219
|
try {
|
|
3052
|
-
rmSync2(
|
|
3220
|
+
rmSync2(join6(destWorkflowsDir, destFile));
|
|
3053
3221
|
} catch {
|
|
3054
3222
|
}
|
|
3055
3223
|
}
|
|
3056
3224
|
}
|
|
3057
3225
|
for (const workflowFile of sourceWorkflowFiles) {
|
|
3058
|
-
const srcPath =
|
|
3059
|
-
const destPath =
|
|
3226
|
+
const srcPath = join6(workflowsDir, workflowFile);
|
|
3227
|
+
const destPath = join6(destWorkflowsDir, workflowFile);
|
|
3060
3228
|
const srcContent = readFileSync5(srcPath, "utf-8");
|
|
3061
3229
|
try {
|
|
3062
3230
|
if (existsSync4(destPath) && readFileSync5(destPath, "utf-8") === srcContent)
|
|
@@ -3068,8 +3236,8 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3068
3236
|
}
|
|
3069
3237
|
} catch {
|
|
3070
3238
|
}
|
|
3071
|
-
const agentMcpPath =
|
|
3072
|
-
const projectMcpPath =
|
|
3239
|
+
const agentMcpPath = join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
3240
|
+
const projectMcpPath = join6(projectDir, ".mcp.json");
|
|
3073
3241
|
try {
|
|
3074
3242
|
const agentMcp = JSON.parse(readFileSync5(agentMcpPath, "utf-8"));
|
|
3075
3243
|
let projectMcp;
|
|
@@ -3095,8 +3263,8 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3095
3263
|
const agentDir = getAgentDir(codeName);
|
|
3096
3264
|
for (const envFile of [".env", ".env.integrations"]) {
|
|
3097
3265
|
try {
|
|
3098
|
-
const content = readFileSync5(
|
|
3099
|
-
const envDest =
|
|
3266
|
+
const content = readFileSync5(join6(agentDir, envFile), "utf-8");
|
|
3267
|
+
const envDest = join6(projectDir, envFile);
|
|
3100
3268
|
writeFileSync5(envDest, content, { mode: SECRET_FILE_MODE });
|
|
3101
3269
|
try {
|
|
3102
3270
|
chmodSync4(envDest, SECRET_FILE_MODE);
|
|
@@ -3106,12 +3274,12 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3106
3274
|
}
|
|
3107
3275
|
}
|
|
3108
3276
|
try {
|
|
3109
|
-
const gitDir =
|
|
3110
|
-
const hookSrc =
|
|
3277
|
+
const gitDir = join6(projectDir, ".git");
|
|
3278
|
+
const hookSrc = join6(provisionDir, ".git-hooks", "pre-commit");
|
|
3111
3279
|
if (existsSync4(gitDir) && existsSync4(hookSrc)) {
|
|
3112
|
-
const hooksDir =
|
|
3280
|
+
const hooksDir = join6(gitDir, "hooks");
|
|
3113
3281
|
mkdirSync4(hooksDir, { recursive: true });
|
|
3114
|
-
const hookDest =
|
|
3282
|
+
const hookDest = join6(hooksDir, "pre-commit");
|
|
3115
3283
|
const srcContent = readFileSync5(hookSrc, "utf-8");
|
|
3116
3284
|
const upToDate = existsSync4(hookDest) && readFileSync5(hookDest, "utf-8") === srcContent;
|
|
3117
3285
|
if (!upToDate)
|
|
@@ -3123,9 +3291,9 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
3123
3291
|
}
|
|
3124
3292
|
function provisionStopHook(codeName) {
|
|
3125
3293
|
const projectDir = getProjectDir2(codeName);
|
|
3126
|
-
const claudeDir =
|
|
3294
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
3127
3295
|
mkdirSync4(claudeDir, { recursive: true });
|
|
3128
|
-
const hookScriptPath =
|
|
3296
|
+
const hookScriptPath = join6(claudeDir, "agt-stop-hook.sh");
|
|
3129
3297
|
const hookScript = [
|
|
3130
3298
|
"#!/bin/bash",
|
|
3131
3299
|
"# Auto-generated by Augmented \u2014 captures persistent session task results.",
|
|
@@ -3170,7 +3338,7 @@ function provisionStopHook(codeName) {
|
|
|
3170
3338
|
"exit 0"
|
|
3171
3339
|
].join("\n") + "\n";
|
|
3172
3340
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3173
|
-
const ghostHookPath =
|
|
3341
|
+
const ghostHookPath = join6(claudeDir, "agt-ghost-reply-hook.sh");
|
|
3174
3342
|
const jqNormalizeContent = '(.message.content // .content // []) | if type == "string" then [{type: "text", text: .}] elif type == "array" then . else [] end';
|
|
3175
3343
|
const ghostHookScript = [
|
|
3176
3344
|
"#!/bin/bash",
|
|
@@ -3340,6 +3508,85 @@ function provisionStopHook(codeName) {
|
|
|
3340
3508
|
"# A stale tag must not correlate anything: drop it so the per-source dispatch",
|
|
3341
3509
|
"# and the sole-pending-marker fallback both see no target.",
|
|
3342
3510
|
'if [ "$SYS_WAKE_LAST" = "1" ]; then CHANNEL_TAG=""; fi',
|
|
3511
|
+
"# ENG-11890: publish end-of-turn text ONLY from a turn the pending inbound",
|
|
3512
|
+
"# actually triggered. Live repro (Scout, 16 Nov): an unanswered Telegram",
|
|
3513
|
+
"# question left its marker open; the next turn was a SCHEDULED CARD, and its",
|
|
3514
|
+
'# plain-text notes ("Quiet hourly check, so I suppressed delivery...") were',
|
|
3515
|
+
"# posted to the person as the reply. The newest-tag correlation above cannot",
|
|
3516
|
+
"# tell those apart: a replayed or mid-turn inbound can be the newest <channel>",
|
|
3517
|
+
"# tag in a turn something else started.",
|
|
3518
|
+
"#",
|
|
3519
|
+
"# So classify the turn by its FIRST inbound record after the previous",
|
|
3520
|
+
"# end_turn, by its OPENING envelope only (CodeRabbit, #7599): the record must",
|
|
3521
|
+
"# START with a <channel ...> tag, and only that tag's own attributes decide,",
|
|
3522
|
+
'# so a [Task: ...] that quotes "<channel " stays `task`, and a body quoting',
|
|
3523
|
+
'# requires_reply="false" cannot turn a real inbound into a notice. The tag is read',
|
|
3524
|
+
'# attribute by attribute (name="value", scanned left to right), so text INSIDE',
|
|
3525
|
+
"# a value such as thread_context is never taken for an attribute. A real tag is",
|
|
3526
|
+
'# `channel`; a DIRECT-CHAT tag with requires_reply="false" (the notice rail',
|
|
3527
|
+
"# scheduled cards and /loop ticks arrive on) is `notice`. NOT expects_reply",
|
|
3528
|
+
"# alone (Obi Wan f7fd49ffb8f8): Slack auto-followed (discretionary) inbounds",
|
|
3529
|
+
'# carry expects_reply="false" too, and their markers cannot replay, so',
|
|
3530
|
+
"# skipping them would lose the ENG-6319 recovery for good. A",
|
|
3531
|
+
"# `[Task: ...]` inject is `task`; any other text (a plain system inject) is",
|
|
3532
|
+
"# `other`. Only `channel` may recover. The previous end_turn is the last one",
|
|
3533
|
+
"# from a DIFFERENT message that a real inbound follows (Obi Wan b979d45eae20,",
|
|
3534
|
+
"# 3fe445e51a0c): a multi-block final message writes several end_turn records,",
|
|
3535
|
+
"# and a block-turn-end continuation is followed only by hook feedback, so",
|
|
3536
|
+
"# neither may be taken as the boundary. The boundary end_turn must be one whose",
|
|
3537
|
+
"# FIRST following user text record (compact summaries skipped) is a real inbound: a blocked end_turn is",
|
|
3538
|
+
"# followed first by the block feedback, so a replay that lands after that",
|
|
3539
|
+
"# feedback cannot re-open the turn (CodeRabbit, #7599). Synthetic records are skipped BY",
|
|
3540
|
+
"# CONTENT, never by isMeta (Obi Wan 20407ffa542a): Claude Code writes the real",
|
|
3541
|
+
"# <channel> inbound records with isMeta:true (measured on a live agent",
|
|
3542
|
+
"# transcript, 31/31). Skipped: the compact summary (isCompactSummary,",
|
|
3543
|
+
"# isVisibleInTranscriptOnly), this hook's own two block reasons and Claude",
|
|
3544
|
+
`# Code's "Stop hook feedback" wrapper, slash-command echoes, and the`,
|
|
3545
|
+
"# interrupt marker. Fails OPEN to today's behaviour as",
|
|
3546
|
+
"# `unknown` when the previous end_turn is not in the tail, so this can only",
|
|
3547
|
+
"# remove a post, never add one. It skips only a marker the replay scanner will",
|
|
3548
|
+
"# re-push (turn_gate_skips), so the inbound is re-delivered and answered.",
|
|
3549
|
+
`TURN_TRIGGER=$(jq -rs 'def ctext: (.message.content // .content // []) | if type=="string" then . elif type=="array" then (map(select(type=="object" and .type=="text") | .text) | join(" ")) else "" end; def isasst: ((.type // "") == "assistant") or ((.role // "") == "assistant"); def synthetic: test("^\\\\s*(Stop hook feedback|You composed a reply but did not send it|You have [0-9]+ conversation\\\\(s\\\\) you did not answer|<command-name>|<local-command-|\\\\[Request interrupted)"); def inbound($r): (($r.type // "") == "user") and (($r.isCompactSummary // false) != true) and (($r.isVisibleInTranscriptOnly // false) != true) and (($r | ctext) as $x | ($x | length) > 0 and (($x | synthetic) | not)); . as $all | [range(0; $all|length) | select($all[.] | isasst)] as $ai | if ($ai|length) == 0 then "unknown" else ($ai | last) as $f | ($all[$f].message.id // null) as $fid | ([ $ai[] | select(. < $f) | select(($all[.].message.stop_reason // "") == "end_turn") | select(($fid == null) or (($all[.].message.id // null) != $fid)) | . as $e | ([ range($e + 1; $f) | select((($all[.].type // "") == "user") and (($all[.].isCompactSummary // false) != true) and (($all[.].isVisibleInTranscriptOnly // false) != true) and (($all[.] | ctext | length) > 0)) ] | first) as $u | select($u != null and inbound($all[$u])) ] | last) as $p | if $p == null then "unknown" else ([ range($p + 1; $f) | select(inbound($all[.])) | ($all[.] | ctext | gsub("[\\\\n\\\\r]+"; " ")) ] | first) as $t | if $t == null then "unknown" elif ($t | test("^\\\\s*<channel [^>]*>")) then ((($t | capture("^\\\\s*(?<h><channel [^>]*>)") | .h) | [scan("([A-Za-z_][A-Za-z0-9_]*)=\\\\x22([^\\\\x22]*)\\\\x22")]) as $a | if ($a | any(.[0] == "source" and .[1] == "direct-chat")) and ($a | any(.[0] == "requires_reply" and .[1] == "false")) then "notice" else "channel" end) elif ($t | test("^\\\\s*\\\\[Task: [A-Za-z0-9_-]+\\\\]")) then "task" else "other" end end end' "$RECENT_FILE" 2>/dev/null || echo unknown)`,
|
|
3550
|
+
"TURN_NOT_INBOUND=0",
|
|
3551
|
+
'case "${TURN_TRIGGER:-unknown}" in notice|task|other) TURN_NOT_INBOUND=1 ;; esac',
|
|
3552
|
+
"# The gate may only skip a marker that WILL be re-delivered (Obi Wan",
|
|
3553
|
+
"# b76cf6f36491 and the Slack discretionary observation on #7599): a skipped reply",
|
|
3554
|
+
"# is safe only if replay re-asks it. So it applies only to a marker the replay",
|
|
3555
|
+
"# scanner would re-push (markerReplayable in ack-reaction.ts: replay on, a push",
|
|
3556
|
+
"# payload, not discretionary). Teams and direct-chat have no replay scanner and",
|
|
3557
|
+
"# are never gated. channel-replay is resolved like the orient hook (env > the",
|
|
3558
|
+
"# manager flags cache > compiled default true).",
|
|
3559
|
+
"TURN_GATE_MAX_REPLAYS=3",
|
|
3560
|
+
"GATE_REPLAY_ON=true",
|
|
3561
|
+
'# CodeRabbit (#7599): trim and lowercase first, as the MCP envBoolean does, so " FALSE " means off.',
|
|
3562
|
+
`case "$(printf '%s' "\${AGT_CHANNEL_REPLAY_ENABLED:-}" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')" in`,
|
|
3563
|
+
" true|1|yes|on) GATE_REPLAY_ON=true ;;",
|
|
3564
|
+
" false|0|no|off) GATE_REPLAY_ON=false ;;",
|
|
3565
|
+
" *)",
|
|
3566
|
+
" # Obi Wan (#7599 observation, 45597e9d6898): the channel MCP picks ONE cache",
|
|
3567
|
+
" # (flags-cache-read.ts defaultFlagsCachePath: the per-agent mirror at",
|
|
3568
|
+
" # ~/.augmented/<AGT_AGENT_ID>/ unless the host-wide file is fresher or the",
|
|
3569
|
+
" # mirror has no flags map). Rather than re-implement that choice in bash,",
|
|
3570
|
+
" # be STRICTER: skipping a recovery is the risky act, so replay counts as off",
|
|
3571
|
+
" # if ANY readable candidate says channel-replay is false. Whichever file the",
|
|
3572
|
+
" # MCP chose, the hook can then never think replay is on while the MCP thinks",
|
|
3573
|
+
" # it is off. No readable value anywhere means the compiled default (true).",
|
|
3574
|
+
' for _gate_fc in ${AGT_AGENT_ID:+"$(dirname "$AGENT_DIR")/$AGT_AGENT_ID/flags-cache.json"} "$AGENT_DIR/flags-cache.json" "$(dirname "$AGENT_DIR")/flags-cache.json"; do',
|
|
3575
|
+
` if [ -f "$_gate_fc" ] && [ "$(jq -r '.flags["channel-replay"] | tostring' "$_gate_fc" 2>/dev/null || echo null)" = "false" ]; then GATE_REPLAY_ON=false; fi`,
|
|
3576
|
+
" done",
|
|
3577
|
+
" ;;",
|
|
3578
|
+
"esac",
|
|
3579
|
+
"turn_gate_skips() {",
|
|
3580
|
+
" # $1 = the marker this recovery would answer. True (0) = skip the post.",
|
|
3581
|
+
' [ "$TURN_NOT_INBOUND" = "1" ] || return 1',
|
|
3582
|
+
' [ "$GATE_REPLAY_ON" = "true" ] || return 1',
|
|
3583
|
+
' [ -n "$1" ] && [ -f "$1" ] || return 1',
|
|
3584
|
+
" # Obi Wan 3438965dd00b: a marker whose replays are used up will never be",
|
|
3585
|
+
" # re-pushed (shouldReplayMarker refuses replay_count >= MAX_MARKER_REPLAYS), so",
|
|
3586
|
+
" # it is not gated either. TURN_GATE_MAX_REPLAYS must equal MAX_MARKER_REPLAYS in",
|
|
3587
|
+
" # packages/mcp/src/ack-reaction.ts; a test pins the two together.",
|
|
3588
|
+
` [ "$(jq -r --argjson max "$TURN_GATE_MAX_REPLAYS" 'if (.payload != null) and ((.discretionary // false) != true) and ((.replay_count // 0) < $max) then "yes" else "no" end' "$1" 2>/dev/null || echo no)" = "yes" ]`,
|
|
3589
|
+
"}",
|
|
3343
3590
|
'TAG_SOURCE=""',
|
|
3344
3591
|
`if [ -n "$CHANNEL_TAG" ]; then TAG_SOURCE=$(echo "$CHANNEL_TAG" | grep -oE 'source="[^"]+"' | head -1 | sed 's/source="\\(.*\\)"/\\1/' || true); fi`,
|
|
3345
3592
|
"# ENG-6567: one context line per Stop that reached here (non-empty assistant",
|
|
@@ -3458,6 +3705,7 @@ function provisionStopHook(codeName) {
|
|
|
3458
3705
|
' marker_name="$(safe_id "$chat_id")__$(safe_id "$msg_id").json"',
|
|
3459
3706
|
' local marker_path="${TG_MARKER_DIR}/${marker_name}"',
|
|
3460
3707
|
' if [ ! -f "$marker_path" ]; then log_ghost "telegram skip=no_pending_marker chat=$(safe_id "$chat_id")"; return; fi',
|
|
3708
|
+
' if turn_gate_skips "$marker_path"; then log_ghost "skip=turn_not_triggered_by_inbound trigger=${TURN_TRIGGER} fn=${FUNCNAME[0]}"; return; fi',
|
|
3461
3709
|
" # ENG-7805 (fm2): confirm-before-clear. Cap re-fire with a per-marker ledger and",
|
|
3462
3710
|
" # LEAVE the marker for the consumer to clear on confirmed send. Ledger-first",
|
|
3463
3711
|
" # fail-safe (same as recover_directchat_for / block-turn-end): if the ledger",
|
|
@@ -3523,6 +3771,7 @@ function provisionStopHook(codeName) {
|
|
|
3523
3771
|
" shopt -s nullglob",
|
|
3524
3772
|
' for f in "$SL_MARKER_DIR"/${prefix}*.json; do if [ -z "$marker_path" ]; then marker_path="$f"; fi; done',
|
|
3525
3773
|
' if [ -z "$marker_path" ]; then log_ghost "slack skip=no_pending_marker channel=$(safe_id "$channel") thread=$(safe_id "$thread_ts")"; return; fi',
|
|
3774
|
+
' if turn_gate_skips "$marker_path"; then log_ghost "skip=turn_not_triggered_by_inbound trigger=${TURN_TRIGGER} fn=${FUNCNAME[0]}"; return; fi',
|
|
3526
3775
|
' local _sl_iid="" _sl_recv=""',
|
|
3527
3776
|
` _sl_iid=$(jq -r '.inbound_id // ""' "$marker_path" 2>/dev/null || echo ""); _sl_recv=$(jq -r '.received_at // ""' "$marker_path" 2>/dev/null || echo "")`,
|
|
3528
3777
|
' case "$(delivery_ledger_verdict "$_sl_iid" "$thread_ts" "$_sl_recv")" in',
|
|
@@ -3609,6 +3858,9 @@ function provisionStopHook(codeName) {
|
|
|
3609
3858
|
" # internal wake \u2014 the tag that selected this target belongs to an older",
|
|
3610
3859
|
" # conversation, and the text is board housekeeping, not a reply to anyone.",
|
|
3611
3860
|
' if [ "$SYS_WAKE_LAST" = "1" ]; then log_ghost "skip=system_wake_last_no_recovery fn=${FUNCNAME[0]}"; return; fi',
|
|
3861
|
+
" # ENG-11890 (Obi Wan 431c6ddee844): NOT gated on TURN_NOT_INBOUND. Teams has no",
|
|
3862
|
+
" # re-delivery, so a reply skipped here could never be re-asked; it keeps",
|
|
3863
|
+
" # today's behaviour (and its consumer-side narration guard).",
|
|
3612
3864
|
' local conversation_id="$1" reply_to_id="$2" service_url="$3"',
|
|
3613
3865
|
' if [ -z "$conversation_id" ] || [ -z "$service_url" ]; then return; fi',
|
|
3614
3866
|
" # ENG-6727 (mode 1): scoped same-turn guard. Suppress only if the agent",
|
|
@@ -4059,7 +4311,7 @@ function provisionStopHook(codeName) {
|
|
|
4059
4311
|
].join("\n") + "\n";
|
|
4060
4312
|
writeFileSync5(ghostHookPath, ghostHookScript, { mode: 493 });
|
|
4061
4313
|
const backlogHookPath = provisionBacklogPullHook(codeName);
|
|
4062
|
-
const settingsPath =
|
|
4314
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
4063
4315
|
let settings = {};
|
|
4064
4316
|
try {
|
|
4065
4317
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -4080,25 +4332,25 @@ function provisionStopHook(codeName) {
|
|
|
4080
4332
|
}
|
|
4081
4333
|
function provisionIsolationHook(codeName, agentId) {
|
|
4082
4334
|
const homeDir = getHomeDir();
|
|
4083
|
-
const augmentedBase =
|
|
4335
|
+
const augmentedBase = join6(homeDir, ".augmented");
|
|
4084
4336
|
if (/["'$`\\\n]/.test(augmentedBase)) {
|
|
4085
4337
|
throw new Error(`provisionIsolationHook: home directory contains shell metacharacters: ${JSON.stringify(augmentedBase)}`);
|
|
4086
4338
|
}
|
|
4087
4339
|
const projectDir = getProjectDir2(codeName);
|
|
4088
|
-
const claudeDir =
|
|
4340
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
4089
4341
|
mkdirSync4(claudeDir, { recursive: true });
|
|
4090
4342
|
const hasAgentId = agentId !== void 0;
|
|
4091
4343
|
if (hasAgentId)
|
|
4092
4344
|
assertValidAgentId(agentId);
|
|
4093
4345
|
const augmentedBaseRe = augmentedBase.replace(/[.[\]()*+?{}|^$]/g, "\\$&");
|
|
4094
|
-
const claudeProjectsBase =
|
|
4346
|
+
const claudeProjectsBase = join6(homeDir, ".claude", "projects");
|
|
4095
4347
|
const claudeProjectsBaseRe = claudeProjectsBase.replace(/[.[\]()*+?{}|^$]/g, "\\$&");
|
|
4096
4348
|
const mangledBase = augmentedBase.replace(/[^a-zA-Z0-9]/g, "-");
|
|
4097
4349
|
const ownAgentDir = getAgentDir(codeName);
|
|
4098
|
-
const logFile =
|
|
4350
|
+
const logFile = join6(ownAgentDir, "isolation.log");
|
|
4099
4351
|
const idAllowClause = hasAgentId ? ` && [ "$AGENT_DIR" != "${agentId}" ]` : "";
|
|
4100
4352
|
const idAllowClause2 = hasAgentId ? ` || [ "$OWNER" = "${agentId}" ]` : "";
|
|
4101
|
-
const hookScriptPath =
|
|
4353
|
+
const hookScriptPath = join6(claudeDir, "agt-isolation-hook.sh");
|
|
4102
4354
|
const hookScript = [
|
|
4103
4355
|
"#!/bin/bash",
|
|
4104
4356
|
"# Auto-generated by Augmented.",
|
|
@@ -4374,7 +4626,7 @@ function provisionIsolationHook(codeName, agentId) {
|
|
|
4374
4626
|
"exit 0"
|
|
4375
4627
|
].join("\n") + "\n";
|
|
4376
4628
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
4377
|
-
const settingsPath =
|
|
4629
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
4378
4630
|
let settings = {};
|
|
4379
4631
|
try {
|
|
4380
4632
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -4396,9 +4648,9 @@ function provisionIsolationHook(codeName, agentId) {
|
|
|
4396
4648
|
}
|
|
4397
4649
|
function provisionBacklogPullHook(codeName) {
|
|
4398
4650
|
const projectDir = getProjectDir2(codeName);
|
|
4399
|
-
const claudeDir =
|
|
4651
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
4400
4652
|
mkdirSync4(claudeDir, { recursive: true });
|
|
4401
|
-
const hookScriptPath =
|
|
4653
|
+
const hookScriptPath = join6(claudeDir, "agt-backlog-pull-hook.sh");
|
|
4402
4654
|
const hookScript = `#!/usr/bin/env bash
|
|
4403
4655
|
# Auto-generated by Augmented (CS-1549) \u2014 Stop hook: don't end a turn idle
|
|
4404
4656
|
# beside a non-empty backlog. Fail-open on every path; blocks at most once per
|
|
@@ -4574,9 +4826,9 @@ exit 0
|
|
|
4574
4826
|
}
|
|
4575
4827
|
function provisionAutoKanbanProgressHook(codeName) {
|
|
4576
4828
|
const projectDir = getProjectDir2(codeName);
|
|
4577
|
-
const claudeDir =
|
|
4829
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
4578
4830
|
mkdirSync4(claudeDir, { recursive: true });
|
|
4579
|
-
const hookScriptPath =
|
|
4831
|
+
const hookScriptPath = join6(claudeDir, "agt-auto-kanban-progress-hook.sh");
|
|
4580
4832
|
const hookScript = `#!/usr/bin/env bash
|
|
4581
4833
|
# Auto-generated by Augmented (ENG-6179 / ENG-6241) \u2014 PostToolUse auto-progress.
|
|
4582
4834
|
# Maps the agent's latest tool action onto its active in-thread kanban progress
|
|
@@ -4692,7 +4944,7 @@ BODY="$(jq -nc --arg a "$AGENT_ID" --arg s "$STEP" '{agent_id:$a, step:$s}' 2>/d
|
|
|
4692
4944
|
exit 0
|
|
4693
4945
|
`;
|
|
4694
4946
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
4695
|
-
const settingsPath =
|
|
4947
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
4696
4948
|
let settings = {};
|
|
4697
4949
|
try {
|
|
4698
4950
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -4711,9 +4963,9 @@ exit 0
|
|
|
4711
4963
|
}
|
|
4712
4964
|
function provisionChannelProgressHook(codeName) {
|
|
4713
4965
|
const projectDir = getProjectDir2(codeName);
|
|
4714
|
-
const claudeDir =
|
|
4966
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
4715
4967
|
mkdirSync4(claudeDir, { recursive: true });
|
|
4716
|
-
const hookScriptPath =
|
|
4968
|
+
const hookScriptPath = join6(claudeDir, "agt-channel-progress-hook.sh");
|
|
4717
4969
|
const hookScript = `#!/usr/bin/env bash
|
|
4718
4970
|
# Auto-generated by Augmented (ENG-6567 Phase 2) \u2014 PostToolUse channel-progress
|
|
4719
4971
|
# heartbeat. Writes a throttled local {step, updated_at_ms} the channel MCP reads
|
|
@@ -4780,7 +5032,7 @@ fi
|
|
|
4780
5032
|
exit 0
|
|
4781
5033
|
`;
|
|
4782
5034
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
4783
|
-
const settingsPath =
|
|
5035
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
4784
5036
|
let settings = {};
|
|
4785
5037
|
try {
|
|
4786
5038
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -5164,14 +5416,14 @@ function classifyCommand(words0, loop, depth) {
|
|
|
5164
5416
|
`;
|
|
5165
5417
|
var LONG_COMMAND_MAX_FOREGROUND_TIMEOUT_MS = 18e4;
|
|
5166
5418
|
function provisionRootRmHook(codeName) {
|
|
5167
|
-
provisionRootRmHookAt(
|
|
5419
|
+
provisionRootRmHookAt(join6(getProjectDir2(codeName), ".claude"));
|
|
5168
5420
|
}
|
|
5169
5421
|
function provisionLongCommandHook(codeName) {
|
|
5170
5422
|
const projectDir = getProjectDir2(codeName);
|
|
5171
|
-
const claudeDir =
|
|
5423
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
5172
5424
|
mkdirSync4(claudeDir, { recursive: true });
|
|
5173
|
-
const hookScriptPath =
|
|
5174
|
-
const jsPath =
|
|
5425
|
+
const hookScriptPath = join6(claudeDir, LONG_COMMAND_HOOK_FILENAME);
|
|
5426
|
+
const jsPath = join6(claudeDir, LONG_COMMAND_HOOK_JS_FILENAME);
|
|
5175
5427
|
writeFileSync5(jsPath, LONG_COMMAND_HOOK_JS.replace("__BOUND__", String(LONG_COMMAND_BOUNDED_TIMEOUT_MS)), { mode: 420 });
|
|
5176
5428
|
const hookScript = [
|
|
5177
5429
|
"#!/usr/bin/env bash",
|
|
@@ -5181,7 +5433,7 @@ function provisionLongCommandHook(codeName) {
|
|
|
5181
5433
|
`exec node '${jsPath.replace(/'/g, `'\\''`)}'`
|
|
5182
5434
|
].join("\n") + "\n";
|
|
5183
5435
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
5184
|
-
const settingsPath =
|
|
5436
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
5185
5437
|
let settings = {};
|
|
5186
5438
|
try {
|
|
5187
5439
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -5202,11 +5454,11 @@ function provisionLongCommandHook(codeName) {
|
|
|
5202
5454
|
}
|
|
5203
5455
|
function provisionOrientHook(codeName) {
|
|
5204
5456
|
const projectDir = getProjectDir2(codeName);
|
|
5205
|
-
const claudeDir =
|
|
5457
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
5206
5458
|
mkdirSync4(claudeDir, { recursive: true });
|
|
5207
5459
|
const agentDir = getAgentDir(codeName);
|
|
5208
|
-
const codeRoots = [
|
|
5209
|
-
const hookScriptPath =
|
|
5460
|
+
const codeRoots = [join6(getHomeDir(), "code"), join6(agentDir, "code")];
|
|
5461
|
+
const hookScriptPath = join6(claudeDir, "agt-orient-hook.sh");
|
|
5210
5462
|
const hookScript = [
|
|
5211
5463
|
"#!/bin/bash",
|
|
5212
5464
|
"# Auto-generated by Augmented (ENG-5397) \u2014 SessionStart orientation hook.",
|
|
@@ -5479,7 +5731,7 @@ function provisionOrientHook(codeName) {
|
|
|
5479
5731
|
"exit 0"
|
|
5480
5732
|
].join("\n") + "\n";
|
|
5481
5733
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
5482
|
-
const settingsPath =
|
|
5734
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
5483
5735
|
let settings = {};
|
|
5484
5736
|
try {
|
|
5485
5737
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -5506,11 +5758,11 @@ function provisionOrientHook(codeName) {
|
|
|
5506
5758
|
}
|
|
5507
5759
|
function provisionPreCompactHook(codeName) {
|
|
5508
5760
|
const projectDir = getProjectDir2(codeName);
|
|
5509
|
-
const claudeDir =
|
|
5761
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
5510
5762
|
mkdirSync4(claudeDir, { recursive: true });
|
|
5511
5763
|
const agentDir = getAgentDir(codeName);
|
|
5512
5764
|
const jqNormalizeContent = '(.message.content // .content // []) | if type == "string" then [{type: "text", text: .}] elif type == "array" then . else [] end';
|
|
5513
|
-
const hookScriptPath =
|
|
5765
|
+
const hookScriptPath = join6(claudeDir, "agt-pre-compact-hook.sh");
|
|
5514
5766
|
const hookScript = [
|
|
5515
5767
|
"#!/bin/bash",
|
|
5516
5768
|
"# Auto-generated by Augmented (ENG-7339) - PreCompact courtesy notice.",
|
|
@@ -5616,7 +5868,7 @@ function provisionPreCompactHook(codeName) {
|
|
|
5616
5868
|
].join("\n") + "\n";
|
|
5617
5869
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
5618
5870
|
chmodSync4(hookScriptPath, 493);
|
|
5619
|
-
const settingsPath =
|
|
5871
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
5620
5872
|
let settings = {};
|
|
5621
5873
|
try {
|
|
5622
5874
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -5643,10 +5895,10 @@ function provisionPreCompactHook(codeName) {
|
|
|
5643
5895
|
}
|
|
5644
5896
|
function provisionSessionStateHook(codeName) {
|
|
5645
5897
|
const projectDir = getProjectDir2(codeName);
|
|
5646
|
-
const claudeDir =
|
|
5898
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
5647
5899
|
mkdirSync4(claudeDir, { recursive: true });
|
|
5648
5900
|
const agentDir = getAgentDir(codeName);
|
|
5649
|
-
const hookScriptPath =
|
|
5901
|
+
const hookScriptPath = join6(claudeDir, "agt-session-state-hook.sh");
|
|
5650
5902
|
const hookScript = `#!/usr/bin/env bash
|
|
5651
5903
|
# Auto-generated by Augmented (ENG-6233 / ENG-6268) \u2014 SessionStart session-state
|
|
5652
5904
|
# recorder. Writes the model + session origin (which only the agent's own
|
|
@@ -5724,7 +5976,7 @@ fi
|
|
|
5724
5976
|
exit 0
|
|
5725
5977
|
`;
|
|
5726
5978
|
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
5727
|
-
const settingsPath =
|
|
5979
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
5728
5980
|
let settings = {};
|
|
5729
5981
|
try {
|
|
5730
5982
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -5846,7 +6098,7 @@ function buildSettingsJson(input) {
|
|
|
5846
6098
|
const projectDir = getProjectDir2(agent.code_name);
|
|
5847
6099
|
const agentDir = getAgentDir(agent.code_name);
|
|
5848
6100
|
const homeDir = getHomeDir();
|
|
5849
|
-
const codenameAliasDir =
|
|
6101
|
+
const codenameAliasDir = join6(homeDir, ".augmented", agent.code_name);
|
|
5850
6102
|
settings["allowedDirectories"] = [
|
|
5851
6103
|
.../* @__PURE__ */ new Set([
|
|
5852
6104
|
projectDir,
|
|
@@ -5855,7 +6107,7 @@ function buildSettingsJson(input) {
|
|
|
5855
6107
|
// Agent's config dir (.env, schedules, registration)
|
|
5856
6108
|
codenameAliasDir,
|
|
5857
6109
|
// Codename symlink alias (== agentDir for legacy agents)
|
|
5858
|
-
|
|
6110
|
+
join6(homeDir, ".augmented", "_mcp"),
|
|
5859
6111
|
// Shared MCP binaries
|
|
5860
6112
|
"/tmp"
|
|
5861
6113
|
// Temp files
|
|
@@ -5955,7 +6207,7 @@ ${integrationsBlock}`;
|
|
|
5955
6207
|
function renderAugmentedWorkerForAgent(codeName) {
|
|
5956
6208
|
const agentDir = getAgentDir(codeName);
|
|
5957
6209
|
const projectDir = getProjectDir2(codeName);
|
|
5958
|
-
const provisionMcpPath =
|
|
6210
|
+
const provisionMcpPath = join6(agentDir, "provision", ".mcp.json");
|
|
5959
6211
|
let mcpServerKeys;
|
|
5960
6212
|
try {
|
|
5961
6213
|
const config = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
@@ -5966,7 +6218,7 @@ function renderAugmentedWorkerForAgent(codeName) {
|
|
|
5966
6218
|
const integrations = readIntegrationsSummaryForAgent(codeName);
|
|
5967
6219
|
const content = buildAugmentedWorkerAgent({ mcpServerKeys, integrations });
|
|
5968
6220
|
for (const baseDir of [agentDir, projectDir]) {
|
|
5969
|
-
const target =
|
|
6221
|
+
const target = join6(baseDir, ".claude", "agents", "augmented-worker.md");
|
|
5970
6222
|
try {
|
|
5971
6223
|
mkdirSync4(dirname3(target), { recursive: true });
|
|
5972
6224
|
writeFileSync5(target, content);
|
|
@@ -5995,8 +6247,8 @@ function buildPostizMcpEntry(integration) {
|
|
|
5995
6247
|
}
|
|
5996
6248
|
function buildMcpJson(input) {
|
|
5997
6249
|
const mcpServers = {};
|
|
5998
|
-
const turnInitiatorFile =
|
|
5999
|
-
const localMcpPath =
|
|
6250
|
+
const turnInitiatorFile = join6(getAgentDir(input.agent.code_name), ".current-turn-initiator.json");
|
|
6251
|
+
const localMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "index.js");
|
|
6000
6252
|
mcpServers["augmented"] = {
|
|
6001
6253
|
command: "node",
|
|
6002
6254
|
args: [localMcpPath],
|
|
@@ -6049,7 +6301,7 @@ function buildMcpJson(input) {
|
|
|
6049
6301
|
const xeroIntegration = input.integrations?.find((i) => i.definition_id === "xero");
|
|
6050
6302
|
if (xeroIntegration) {
|
|
6051
6303
|
const brokerMode = Boolean(xeroIntegration.id);
|
|
6052
|
-
const localXeroMcpPath =
|
|
6304
|
+
const localXeroMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "xero.js");
|
|
6053
6305
|
mcpServers["xero"] = {
|
|
6054
6306
|
command: "node",
|
|
6055
6307
|
args: [localXeroMcpPath],
|
|
@@ -6089,7 +6341,7 @@ function buildMcpJson(input) {
|
|
|
6089
6341
|
// getProjectDir (the ADR-0049 seam), not the MCP child's inherited
|
|
6090
6342
|
// cwd, so the path stays correct if Claude Code ever spawns the
|
|
6091
6343
|
// server from somewhere else.
|
|
6092
|
-
XERO_EXPORT_DIR:
|
|
6344
|
+
XERO_EXPORT_DIR: join6(getProjectDir2(input.agent.code_name), "xero-exports"),
|
|
6093
6345
|
PATH: process.env["PATH"] ?? "",
|
|
6094
6346
|
HOME: process.env["HOME"] ?? ""
|
|
6095
6347
|
}
|
|
@@ -6100,8 +6352,8 @@ function buildMcpJson(input) {
|
|
|
6100
6352
|
mcpServers["postiz"] = buildPostizMcpEntry(postizIntegration);
|
|
6101
6353
|
}
|
|
6102
6354
|
const remoteOAuthProxyPaths = {
|
|
6103
|
-
proxyPath:
|
|
6104
|
-
tokenFile:
|
|
6355
|
+
proxyPath: join6(getHomeDir(), ".augmented", "_mcp", "remote-oauth-proxy.js"),
|
|
6356
|
+
tokenFile: join6(getProjectDir2(input.agent.code_name), ".env.integrations")
|
|
6105
6357
|
};
|
|
6106
6358
|
for (const integration of input.integrations ?? []) {
|
|
6107
6359
|
const connectionKey = integration.connection_key;
|
|
@@ -6187,7 +6439,7 @@ function buildMcpJson(input) {
|
|
|
6187
6439
|
}
|
|
6188
6440
|
const hasAdminDebug = input.integrations?.some((i) => i.definition_id === "augmented-admin") ?? false;
|
|
6189
6441
|
if (hasAdminDebug) {
|
|
6190
|
-
const localAdminMcpPath =
|
|
6442
|
+
const localAdminMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-admin.js");
|
|
6191
6443
|
mcpServers["augmented-admin"] = {
|
|
6192
6444
|
command: "node",
|
|
6193
6445
|
args: [localAdminMcpPath],
|
|
@@ -6201,7 +6453,7 @@ function buildMcpJson(input) {
|
|
|
6201
6453
|
}
|
|
6202
6454
|
const hasSupport = input.integrations?.some((i) => i.definition_id === "augmented-support") ?? false;
|
|
6203
6455
|
if (hasSupport) {
|
|
6204
|
-
const localSupportMcpPath =
|
|
6456
|
+
const localSupportMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-support.js");
|
|
6205
6457
|
mcpServers["augmented-support"] = {
|
|
6206
6458
|
command: "node",
|
|
6207
6459
|
args: [localSupportMcpPath],
|
|
@@ -6215,7 +6467,7 @@ function buildMcpJson(input) {
|
|
|
6215
6467
|
}
|
|
6216
6468
|
const hasHelpKb = input.integrations?.some((i) => i.definition_id === "augmented-help-kb") ?? false;
|
|
6217
6469
|
if (hasHelpKb) {
|
|
6218
|
-
const localHelpKbMcpPath =
|
|
6470
|
+
const localHelpKbMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-help-kb.js");
|
|
6219
6471
|
mcpServers["augmented-help-kb"] = {
|
|
6220
6472
|
command: "node",
|
|
6221
6473
|
args: [localHelpKbMcpPath],
|
|
@@ -6229,7 +6481,7 @@ function buildMcpJson(input) {
|
|
|
6229
6481
|
}
|
|
6230
6482
|
const origamiIntegration = input.integrations?.find((i) => i.definition_id === "origami");
|
|
6231
6483
|
if (origamiIntegration?.stdioMcp === true && origamiIntegration.id) {
|
|
6232
|
-
const localOrigamiMcpPath =
|
|
6484
|
+
const localOrigamiMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "origami.js");
|
|
6233
6485
|
mcpServers["origami"] = {
|
|
6234
6486
|
command: "node",
|
|
6235
6487
|
args: [localOrigamiMcpPath],
|
|
@@ -6248,7 +6500,7 @@ function buildMcpJson(input) {
|
|
|
6248
6500
|
agentId: input.agent.agent_id,
|
|
6249
6501
|
agentCodeName: input.agent.code_name,
|
|
6250
6502
|
config: computerUseIntegration.config,
|
|
6251
|
-
proxyPath:
|
|
6503
|
+
proxyPath: join6(getHomeDir(), ".augmented", "_mcp", "computer-use-proxy.js"),
|
|
6252
6504
|
agentDir: getAgentDir(input.agent.code_name)
|
|
6253
6505
|
});
|
|
6254
6506
|
if (rendered.entry) {
|
|
@@ -6498,27 +6750,27 @@ ${sections}`
|
|
|
6498
6750
|
},
|
|
6499
6751
|
async getRegisteredAgents(_profile) {
|
|
6500
6752
|
const homeDir = getHomeDir();
|
|
6501
|
-
const augDir =
|
|
6753
|
+
const augDir = join6(homeDir, ".augmented");
|
|
6502
6754
|
const agents = /* @__PURE__ */ new Set();
|
|
6503
6755
|
try {
|
|
6504
6756
|
const entries = readdirSync(augDir);
|
|
6505
6757
|
for (const entry of entries) {
|
|
6506
6758
|
if (entry.startsWith("_") || entry.startsWith("."))
|
|
6507
6759
|
continue;
|
|
6508
|
-
const agentRoot =
|
|
6760
|
+
const agentRoot = join6(augDir, entry);
|
|
6509
6761
|
let st;
|
|
6510
6762
|
try {
|
|
6511
|
-
st =
|
|
6763
|
+
st = lstatSync2(agentRoot);
|
|
6512
6764
|
} catch {
|
|
6513
6765
|
continue;
|
|
6514
6766
|
}
|
|
6515
6767
|
if (st.isSymbolicLink() || !st.isDirectory())
|
|
6516
6768
|
continue;
|
|
6517
|
-
if (!existsSync4(
|
|
6769
|
+
if (!existsSync4(join6(agentRoot, "registration.json")))
|
|
6518
6770
|
continue;
|
|
6519
6771
|
let codeName = entry;
|
|
6520
6772
|
try {
|
|
6521
|
-
const reg = JSON.parse(readFileSync5(
|
|
6773
|
+
const reg = JSON.parse(readFileSync5(join6(agentRoot, "registration.json"), "utf8"));
|
|
6522
6774
|
if (reg && typeof reg.code_name === "string" && reg.code_name) {
|
|
6523
6775
|
codeName = reg.code_name;
|
|
6524
6776
|
}
|
|
@@ -6539,7 +6791,7 @@ ${sections}`
|
|
|
6539
6791
|
const projectDir = getProjectDir2(codeName);
|
|
6540
6792
|
mkdirSync4(agentDir, { recursive: true });
|
|
6541
6793
|
mkdirSync4(projectDir, { recursive: true });
|
|
6542
|
-
writeFileSync5(
|
|
6794
|
+
writeFileSync5(join6(agentDir, "registration.json"), JSON.stringify({
|
|
6543
6795
|
code_name: codeName,
|
|
6544
6796
|
agent_id: agentId ?? null,
|
|
6545
6797
|
team_dir: teamDir,
|
|
@@ -6558,10 +6810,10 @@ ${sections}`
|
|
|
6558
6810
|
async deregisterAgent(codeName) {
|
|
6559
6811
|
try {
|
|
6560
6812
|
const agentDir = getAgentDir(codeName);
|
|
6561
|
-
const regFile =
|
|
6813
|
+
const regFile = join6(agentDir, "registration.json");
|
|
6562
6814
|
if (existsSync4(regFile)) {
|
|
6563
|
-
const { unlinkSync:
|
|
6564
|
-
|
|
6815
|
+
const { unlinkSync: unlinkSync7 } = await import("fs");
|
|
6816
|
+
unlinkSync7(regFile);
|
|
6565
6817
|
}
|
|
6566
6818
|
return true;
|
|
6567
6819
|
} catch {
|
|
@@ -6584,7 +6836,7 @@ ${sections}`
|
|
|
6584
6836
|
}
|
|
6585
6837
|
}
|
|
6586
6838
|
if (envLines.length > 1) {
|
|
6587
|
-
const envPath =
|
|
6839
|
+
const envPath = join6(agentDir, ".env");
|
|
6588
6840
|
writeFileSync5(envPath, envLines.join("\n") + "\n");
|
|
6589
6841
|
chmodSync4(envPath, SECRET_FILE_MODE);
|
|
6590
6842
|
}
|
|
@@ -6648,7 +6900,7 @@ ${sections}`
|
|
|
6648
6900
|
if (!botToken)
|
|
6649
6901
|
return missingCredentialField("bot_token");
|
|
6650
6902
|
const allowedChats = config["allowed_chats"];
|
|
6651
|
-
const localTelegramChannel =
|
|
6903
|
+
const localTelegramChannel = join6(getHomeDir(), ".augmented", "_mcp", "telegram-channel.js");
|
|
6652
6904
|
const resolvedAgtHostForTelegram = process.env["AGT_HOST"]?.trim() || "https://api.augmented.team";
|
|
6653
6905
|
const resolvedAgtApiKeyForTelegram = process.env["AGT_API_KEY"]?.trim();
|
|
6654
6906
|
writeEnvIntegrationsForAgent(codeName, {
|
|
@@ -6663,7 +6915,7 @@ ${sections}`
|
|
|
6663
6915
|
...options?.agentId ? { AGT_AGENT_ID: options.agentId } : {},
|
|
6664
6916
|
...tzEnv,
|
|
6665
6917
|
// ENG-6582 (D16): stamp the verified turn initiator for broker MCPs.
|
|
6666
|
-
AGT_TURN_INITIATOR_FILE:
|
|
6918
|
+
AGT_TURN_INITIATOR_FILE: join6(getAgentDir(codeName), ".current-turn-initiator.json")
|
|
6667
6919
|
};
|
|
6668
6920
|
if (allowedChats && allowedChats.length > 0) {
|
|
6669
6921
|
telegramEnv.TELEGRAM_ALLOWED_CHATS = allowedChats.join(",");
|
|
@@ -6738,7 +6990,7 @@ ${sections}`
|
|
|
6738
6990
|
args: [localTelegramChannel],
|
|
6739
6991
|
env: telegramEnv
|
|
6740
6992
|
};
|
|
6741
|
-
const provisionMcpPath =
|
|
6993
|
+
const provisionMcpPath = join6(agentDir, "provision", ".mcp.json");
|
|
6742
6994
|
mkdirSync4(dirname3(provisionMcpPath), { recursive: true });
|
|
6743
6995
|
let mcpConfig2 = { mcpServers: {} };
|
|
6744
6996
|
try {
|
|
@@ -6756,13 +7008,13 @@ ${sections}`
|
|
|
6756
7008
|
}
|
|
6757
7009
|
if (isPersistent && (channelId === "discord" || channelId === "slack")) {
|
|
6758
7010
|
let wrotePersistentCredential = false;
|
|
6759
|
-
const channelDir =
|
|
7011
|
+
const channelDir = join6(getHomeDir(), ".claude", "channels", channelId);
|
|
6760
7012
|
if (channelId === "discord")
|
|
6761
7013
|
mkdirSync4(channelDir, { recursive: true });
|
|
6762
7014
|
if (channelId === "discord") {
|
|
6763
7015
|
const botToken = config["bot_token"];
|
|
6764
7016
|
if (botToken) {
|
|
6765
|
-
writeFileSync5(
|
|
7017
|
+
writeFileSync5(join6(channelDir, ".env"), `DISCORD_BOT_TOKEN=${botToken}
|
|
6766
7018
|
`);
|
|
6767
7019
|
wrotePersistentCredential = true;
|
|
6768
7020
|
}
|
|
@@ -6826,7 +7078,7 @@ ${sections}`
|
|
|
6826
7078
|
...appToken ? { SLACK_APP_TOKEN: appToken } : {}
|
|
6827
7079
|
}, ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"])
|
|
6828
7080
|
});
|
|
6829
|
-
const localSlackChannel =
|
|
7081
|
+
const localSlackChannel = join6(getHomeDir(), ".augmented", "_mcp", "slack-channel.js");
|
|
6830
7082
|
const slackAvatarEnvUrl = resolveAvatarEnvUrl(options?.agentAvatarUrl).url;
|
|
6831
7083
|
const slackEntry = {
|
|
6832
7084
|
command: existsSync4(localSlackChannel) ? "node" : "npx",
|
|
@@ -6921,10 +7173,10 @@ ${sections}`
|
|
|
6921
7173
|
...pingAllowedUsers.length > 0 ? { SLACK_PING_ALLOWED_USERS: pingAllowedUsers.join(",") } : {},
|
|
6922
7174
|
// ENG-6563 (D16): stamp the verified turn initiator so broker MCPs
|
|
6923
7175
|
// can forward it when the agent files an approval mid-turn.
|
|
6924
|
-
AGT_TURN_INITIATOR_FILE:
|
|
7176
|
+
AGT_TURN_INITIATOR_FILE: join6(agentDir, ".current-turn-initiator.json")
|
|
6925
7177
|
}
|
|
6926
7178
|
};
|
|
6927
|
-
const provisionMcpPath =
|
|
7179
|
+
const provisionMcpPath = join6(agentDir, "provision", ".mcp.json");
|
|
6928
7180
|
mkdirSync4(dirname3(provisionMcpPath), { recursive: true });
|
|
6929
7181
|
let mcpConfig2 = { mcpServers: {} };
|
|
6930
7182
|
try {
|
|
@@ -6939,7 +7191,7 @@ ${sections}`
|
|
|
6939
7191
|
}
|
|
6940
7192
|
syncMcpToProject(codeName);
|
|
6941
7193
|
wrotePersistentCredential = true;
|
|
6942
|
-
const staleChannelsPath =
|
|
7194
|
+
const staleChannelsPath = join6(getProjectDir2(codeName), ".mcp-channels.json");
|
|
6943
7195
|
if (existsSync4(staleChannelsPath)) {
|
|
6944
7196
|
try {
|
|
6945
7197
|
rmSync2(staleChannelsPath, { force: true });
|
|
@@ -6953,7 +7205,7 @@ ${sections}`
|
|
|
6953
7205
|
}
|
|
6954
7206
|
return CHANNEL_WRITE_OK;
|
|
6955
7207
|
}
|
|
6956
|
-
const mcpJsonPath =
|
|
7208
|
+
const mcpJsonPath = join6(agentDir, "provision", ".mcp.json");
|
|
6957
7209
|
mkdirSync4(dirname3(mcpJsonPath), { recursive: true });
|
|
6958
7210
|
let mcpConfig;
|
|
6959
7211
|
try {
|
|
@@ -6976,7 +7228,7 @@ ${sections}`
|
|
|
6976
7228
|
const appToken = config["app_token"];
|
|
6977
7229
|
if (!botToken)
|
|
6978
7230
|
return missingCredentialField("bot_token");
|
|
6979
|
-
const localSlackChannel =
|
|
7231
|
+
const localSlackChannel = join6(getHomeDir(), ".augmented", "_mcp", "slack-channel.js");
|
|
6980
7232
|
const slackThreadAutoFollow = config["thread_auto_follow"];
|
|
6981
7233
|
const slackAutoFollowEnv = slackThreadAutoFollow && slackThreadAutoFollow !== "off" ? { SLACK_THREAD_AUTO_FOLLOW: slackThreadAutoFollow } : {};
|
|
6982
7234
|
const slackChannelResponseMode = config["channel_response_mode"];
|
|
@@ -7065,7 +7317,7 @@ ${sections}`
|
|
|
7065
7317
|
...slackAgtAuthEnv,
|
|
7066
7318
|
...tzEnv,
|
|
7067
7319
|
// ENG-6563 (D16): stamp the verified turn initiator for broker MCPs.
|
|
7068
|
-
AGT_TURN_INITIATOR_FILE:
|
|
7320
|
+
AGT_TURN_INITIATOR_FILE: join6(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
7069
7321
|
// ENG-6155: avatar URL → bot Slack profile photo (see persistent
|
|
7070
7322
|
// branch above). Mirrored here so oneshot-mode agents get it too.
|
|
7071
7323
|
// ENG-6245: slackAvatarEnvUrl is null for data-URI / oversized values.
|
|
@@ -7090,7 +7342,7 @@ ${sections}`
|
|
|
7090
7342
|
...slackAgtAuthEnv,
|
|
7091
7343
|
...tzEnv,
|
|
7092
7344
|
// ENG-6563 (D16): stamp the verified turn initiator for broker MCPs.
|
|
7093
|
-
AGT_TURN_INITIATOR_FILE:
|
|
7345
|
+
AGT_TURN_INITIATOR_FILE: join6(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
7094
7346
|
// ENG-6155: avatar URL → bot Slack profile photo (see persistent
|
|
7095
7347
|
// branch above). Mirrored here so oneshot-mode agents get it too.
|
|
7096
7348
|
// ENG-6245: slackAvatarEnvUrl is null for data-URI / oversized values.
|
|
@@ -7104,12 +7356,12 @@ ${sections}`
|
|
|
7104
7356
|
if (!appId || !clientSecret) {
|
|
7105
7357
|
return missingCredentialField(!appId ? "app_id" : "client_secret");
|
|
7106
7358
|
}
|
|
7107
|
-
const localTeamsChannel =
|
|
7359
|
+
const localTeamsChannel = join6(getHomeDir(), ".augmented", "_mcp", "teams-channel.js");
|
|
7108
7360
|
const agentDirMs = getAgentDir(codeName);
|
|
7109
7361
|
try {
|
|
7110
|
-
mkdirSync4(
|
|
7111
|
-
mkdirSync4(
|
|
7112
|
-
mkdirSync4(
|
|
7362
|
+
mkdirSync4(join6(agentDirMs, "msteams-pending-inbound", ".markers"), { recursive: true });
|
|
7363
|
+
mkdirSync4(join6(agentDirMs, "msteams-pending-interactions"), { recursive: true });
|
|
7364
|
+
mkdirSync4(join6(agentDirMs, "msteams-recovery-outbox"), { recursive: true });
|
|
7113
7365
|
} catch {
|
|
7114
7366
|
}
|
|
7115
7367
|
const tenantId = config["tenant_id"] ?? "common";
|
|
@@ -7191,7 +7443,7 @@ ${sections}`
|
|
|
7191
7443
|
}
|
|
7192
7444
|
if (channelId === "whatsapp") {
|
|
7193
7445
|
const provider = config["provider"] ?? "kapso";
|
|
7194
|
-
const localWhatsappChannel =
|
|
7446
|
+
const localWhatsappChannel = join6(getHomeDir(), ".augmented", "_mcp", "whatsapp-channel.js");
|
|
7195
7447
|
if (provider === "baileys") {
|
|
7196
7448
|
mcpServers["whatsapp"] = {
|
|
7197
7449
|
command: "node",
|
|
@@ -7211,7 +7463,7 @@ ${sections}`
|
|
|
7211
7463
|
const phoneNumberId = config["phone_number_id"];
|
|
7212
7464
|
if (projectApiKey && phoneNumberId) {
|
|
7213
7465
|
try {
|
|
7214
|
-
mkdirSync4(
|
|
7466
|
+
mkdirSync4(join6(getAgentDir(codeName), "whatsapp-pending-inbound"), { recursive: true });
|
|
7215
7467
|
} catch {
|
|
7216
7468
|
}
|
|
7217
7469
|
writeEnvIntegrationsForAgent(codeName, {
|
|
@@ -7243,7 +7495,7 @@ ${sections}`
|
|
|
7243
7495
|
return CHANNEL_WRITE_OK;
|
|
7244
7496
|
},
|
|
7245
7497
|
hasChannelCredentials(codeName, channelId) {
|
|
7246
|
-
const provisionMcpPath =
|
|
7498
|
+
const provisionMcpPath = join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
7247
7499
|
if (!existsSync4(provisionMcpPath))
|
|
7248
7500
|
return false;
|
|
7249
7501
|
try {
|
|
@@ -7255,7 +7507,7 @@ ${sections}`
|
|
|
7255
7507
|
},
|
|
7256
7508
|
removeChannelCredentials(codeName, channelId) {
|
|
7257
7509
|
const agentDir = getAgentDir(codeName);
|
|
7258
|
-
const mcpJsonPath =
|
|
7510
|
+
const mcpJsonPath = join6(agentDir, "provision", ".mcp.json");
|
|
7259
7511
|
modifyJsonConfig(mcpJsonPath, (config) => {
|
|
7260
7512
|
const mcpServers = config["mcpServers"];
|
|
7261
7513
|
if (!mcpServers || !(channelId in mcpServers))
|
|
@@ -7267,7 +7519,7 @@ ${sections}`
|
|
|
7267
7519
|
},
|
|
7268
7520
|
async updateAgentModel(codeName, model) {
|
|
7269
7521
|
const agentDir = getAgentDir(codeName);
|
|
7270
|
-
const settingsPath =
|
|
7522
|
+
const settingsPath = join6(agentDir, "provision", "settings.json");
|
|
7271
7523
|
let changed = false;
|
|
7272
7524
|
modifyJsonConfig(settingsPath, (config) => {
|
|
7273
7525
|
config["model"] = model;
|
|
@@ -7285,12 +7537,12 @@ ${sections}`
|
|
|
7285
7537
|
seedProfileConfig(codeName) {
|
|
7286
7538
|
const agentDir = getAgentDir(codeName);
|
|
7287
7539
|
const projectDir = getProjectDir2(codeName);
|
|
7288
|
-
mkdirSync4(
|
|
7540
|
+
mkdirSync4(join6(agentDir, "provision"), { recursive: true });
|
|
7289
7541
|
mkdirSync4(projectDir, { recursive: true });
|
|
7290
7542
|
},
|
|
7291
7543
|
syncScheduledTasks(codeName, tasks) {
|
|
7292
7544
|
const agentDir = getAgentDir(codeName);
|
|
7293
|
-
const schedulesPath =
|
|
7545
|
+
const schedulesPath = join6(agentDir, "schedules.json");
|
|
7294
7546
|
const mapped = mapScheduledTasks(tasks);
|
|
7295
7547
|
mkdirSync4(agentDir, { recursive: true });
|
|
7296
7548
|
writeFileSync5(schedulesPath, JSON.stringify({ schedules: mapped }, null, 2));
|
|
@@ -7413,7 +7665,7 @@ ${sections}`
|
|
|
7413
7665
|
xeroEnv.AGT_AGENT_ID = agentId;
|
|
7414
7666
|
xeroEnv.AGT_INTEGRATION_ID = xeroIntegration.id;
|
|
7415
7667
|
}
|
|
7416
|
-
const localXeroMcpPath =
|
|
7668
|
+
const localXeroMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "xero.js");
|
|
7417
7669
|
this.writeMcpServer(codeName, "xero", {
|
|
7418
7670
|
command: "node",
|
|
7419
7671
|
args: [localXeroMcpPath],
|
|
@@ -7425,8 +7677,8 @@ ${sections}`
|
|
|
7425
7677
|
this.writeMcpServer(codeName, "postiz", buildPostizMcpEntry(postizIntegration));
|
|
7426
7678
|
}
|
|
7427
7679
|
const remoteOAuthProxyPaths = {
|
|
7428
|
-
proxyPath:
|
|
7429
|
-
tokenFile:
|
|
7680
|
+
proxyPath: join6(getHomeDir(), ".augmented", "_mcp", "remote-oauth-proxy.js"),
|
|
7681
|
+
tokenFile: join6(getProjectDir2(codeName), ".env.integrations")
|
|
7430
7682
|
};
|
|
7431
7683
|
for (const integration of integrations) {
|
|
7432
7684
|
const connectionKey = integration.connection_key;
|
|
@@ -7485,7 +7737,7 @@ ${sections}`
|
|
|
7485
7737
|
// ENG-6586 (D16): keep incremental cloud-broker wiring in sync with
|
|
7486
7738
|
// buildMcpJson so agents that add cloud-broker post-provision still
|
|
7487
7739
|
// forward the per-turn initiator.
|
|
7488
|
-
AGT_TURN_INITIATOR_FILE:
|
|
7740
|
+
AGT_TURN_INITIATOR_FILE: join6(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
7489
7741
|
PATH: process.env["PATH"] ?? "",
|
|
7490
7742
|
HOME: process.env["HOME"] ?? ""
|
|
7491
7743
|
}
|
|
@@ -7509,7 +7761,7 @@ ${sections}`
|
|
|
7509
7761
|
// ENG-6563 (D16): keep incremental xero-broker wiring in sync with
|
|
7510
7762
|
// buildMcpJson so agents that add xero-broker post-provision still
|
|
7511
7763
|
// forward the per-turn initiator.
|
|
7512
|
-
AGT_TURN_INITIATOR_FILE:
|
|
7764
|
+
AGT_TURN_INITIATOR_FILE: join6(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
7513
7765
|
PATH: process.env["PATH"] ?? "",
|
|
7514
7766
|
HOME: process.env["HOME"] ?? ""
|
|
7515
7767
|
}
|
|
@@ -7518,7 +7770,7 @@ ${sections}`
|
|
|
7518
7770
|
}
|
|
7519
7771
|
const hasAdminDebug = integrations.some((i) => i.definition_id === "augmented-admin");
|
|
7520
7772
|
if (hasAdminDebug) {
|
|
7521
|
-
const localAdminMcpPath =
|
|
7773
|
+
const localAdminMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-admin.js");
|
|
7522
7774
|
this.writeMcpServer(codeName, "augmented-admin", {
|
|
7523
7775
|
command: "node",
|
|
7524
7776
|
args: [localAdminMcpPath],
|
|
@@ -7532,7 +7784,7 @@ ${sections}`
|
|
|
7532
7784
|
}
|
|
7533
7785
|
const hasSupport = integrations.some((i) => i.definition_id === "augmented-support");
|
|
7534
7786
|
if (hasSupport) {
|
|
7535
|
-
const localSupportMcpPath =
|
|
7787
|
+
const localSupportMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-support.js");
|
|
7536
7788
|
this.writeMcpServer(codeName, "augmented-support", {
|
|
7537
7789
|
command: "node",
|
|
7538
7790
|
args: [localSupportMcpPath],
|
|
@@ -7546,7 +7798,7 @@ ${sections}`
|
|
|
7546
7798
|
}
|
|
7547
7799
|
const hasHelpKb = integrations.some((i) => i.definition_id === "augmented-help-kb");
|
|
7548
7800
|
if (hasHelpKb) {
|
|
7549
|
-
const localHelpKbMcpPath =
|
|
7801
|
+
const localHelpKbMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "augmented-help-kb.js");
|
|
7550
7802
|
this.writeMcpServer(codeName, "augmented-help-kb", {
|
|
7551
7803
|
command: "node",
|
|
7552
7804
|
args: [localHelpKbMcpPath],
|
|
@@ -7562,7 +7814,7 @@ ${sections}`
|
|
|
7562
7814
|
const origamiStdioAgentId = resolveBrokerAgentId(codeName) ?? agentId;
|
|
7563
7815
|
const origamiStdioExpected = Boolean(origamiStdio?.stdioMcp === true && origamiStdio.id);
|
|
7564
7816
|
if (origamiStdioExpected && origamiStdioAgentId) {
|
|
7565
|
-
const localOrigamiMcpPath =
|
|
7817
|
+
const localOrigamiMcpPath = join6(getHomeDir(), ".augmented", "_mcp", "origami.js");
|
|
7566
7818
|
this.writeMcpServer(codeName, "origami", {
|
|
7567
7819
|
command: "node",
|
|
7568
7820
|
args: [localOrigamiMcpPath],
|
|
@@ -7583,7 +7835,7 @@ ${sections}`
|
|
|
7583
7835
|
agentId: computerUseAgentId,
|
|
7584
7836
|
agentCodeName: codeName,
|
|
7585
7837
|
config: computerUseRow.config,
|
|
7586
|
-
proxyPath:
|
|
7838
|
+
proxyPath: join6(getHomeDir(), ".augmented", "_mcp", "computer-use-proxy.js"),
|
|
7587
7839
|
agentDir: getAgentDir(codeName)
|
|
7588
7840
|
});
|
|
7589
7841
|
if (rendered.entry) {
|
|
@@ -7707,7 +7959,7 @@ ${sections}`
|
|
|
7707
7959
|
}
|
|
7708
7960
|
}
|
|
7709
7961
|
const projectDir = getProjectDir2(codeName);
|
|
7710
|
-
const claudeMdPath =
|
|
7962
|
+
const claudeMdPath = join6(projectDir, "CLAUDE.md");
|
|
7711
7963
|
try {
|
|
7712
7964
|
const existing = readFileSync5(claudeMdPath, "utf-8");
|
|
7713
7965
|
const renderSection = options?.renderClaudeMdSection === true;
|
|
@@ -7728,10 +7980,10 @@ ${sections}`
|
|
|
7728
7980
|
if (updated !== existing)
|
|
7729
7981
|
writeFileSync5(claudeMdPath, updated);
|
|
7730
7982
|
const agentDir2 = getAgentDir(codeName);
|
|
7731
|
-
const envSrc =
|
|
7983
|
+
const envSrc = join6(agentDir2, ".env.integrations");
|
|
7732
7984
|
try {
|
|
7733
7985
|
const envContent = readFileSync5(envSrc, "utf-8");
|
|
7734
|
-
const envDest =
|
|
7986
|
+
const envDest = join6(projectDir, ".env.integrations");
|
|
7735
7987
|
writeFileSync5(envDest, envContent, { mode: SECRET_FILE_MODE });
|
|
7736
7988
|
try {
|
|
7737
7989
|
chmodSync4(envDest, SECRET_FILE_MODE);
|
|
@@ -7746,8 +7998,8 @@ ${sections}`
|
|
|
7746
7998
|
},
|
|
7747
7999
|
writeMcpServer(codeName, serverId, config) {
|
|
7748
8000
|
const agentDir = getAgentDir(codeName);
|
|
7749
|
-
const mcpJsonPath =
|
|
7750
|
-
mkdirSync4(
|
|
8001
|
+
const mcpJsonPath = join6(agentDir, "provision", ".mcp.json");
|
|
8002
|
+
mkdirSync4(join6(agentDir, "provision"), { recursive: true });
|
|
7751
8003
|
let mcpConfig;
|
|
7752
8004
|
try {
|
|
7753
8005
|
mcpConfig = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
@@ -7794,7 +8046,7 @@ ${sections}`
|
|
|
7794
8046
|
}
|
|
7795
8047
|
},
|
|
7796
8048
|
getMcpPath(codeName) {
|
|
7797
|
-
return
|
|
8049
|
+
return join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
7798
8050
|
},
|
|
7799
8051
|
/**
|
|
7800
8052
|
* ENG-7994: the declared servers from `provision/.mcp.json`. Mirrors what the
|
|
@@ -7805,7 +8057,7 @@ ${sections}`
|
|
|
7805
8057
|
readMcpServers(codeName) {
|
|
7806
8058
|
let parsed;
|
|
7807
8059
|
try {
|
|
7808
|
-
parsed = JSON.parse(readFileSync5(
|
|
8060
|
+
parsed = JSON.parse(readFileSync5(join6(getAgentDir(codeName), "provision", ".mcp.json"), "utf-8"));
|
|
7809
8061
|
} catch {
|
|
7810
8062
|
return {};
|
|
7811
8063
|
}
|
|
@@ -7817,13 +8069,13 @@ ${sections}`
|
|
|
7817
8069
|
return mcpServers;
|
|
7818
8070
|
},
|
|
7819
8071
|
syncMcpMirror(codeName) {
|
|
7820
|
-
const provisionMcpPath =
|
|
8072
|
+
const provisionMcpPath = join6(getAgentDir(codeName), "provision", ".mcp.json");
|
|
7821
8073
|
let content;
|
|
7822
8074
|
try {
|
|
7823
8075
|
content = readFileSync5(provisionMcpPath, "utf-8");
|
|
7824
8076
|
} catch (err) {
|
|
7825
8077
|
const missing = err.code === "ENOENT";
|
|
7826
|
-
if (!missing || existsSync4(
|
|
8078
|
+
if (!missing || existsSync4(join6(getProjectDir2(codeName), ".mcp.json"))) {
|
|
7827
8079
|
noteMcpWriteFailure(codeName);
|
|
7828
8080
|
process.stderr.write(`[claudecode] MCP mirror repair for '${codeName}': provision/.mcp.json ${missing ? "is missing" : "is unreadable"} while a project mirror exists; the mirror cannot be repaired from it
|
|
7829
8081
|
`);
|
|
@@ -7840,7 +8092,7 @@ ${sections}`
|
|
|
7840
8092
|
readMcpServersOrNull(codeName) {
|
|
7841
8093
|
let raw;
|
|
7842
8094
|
try {
|
|
7843
|
-
raw = readFileSync5(
|
|
8095
|
+
raw = readFileSync5(join6(getAgentDir(codeName), "provision", ".mcp.json"), "utf-8");
|
|
7844
8096
|
} catch (err) {
|
|
7845
8097
|
return err.code === "ENOENT" ? {} : null;
|
|
7846
8098
|
}
|
|
@@ -7861,7 +8113,7 @@ ${sections}`
|
|
|
7861
8113
|
},
|
|
7862
8114
|
removeMcpServer(codeName, serverId) {
|
|
7863
8115
|
const agentDir = getAgentDir(codeName);
|
|
7864
|
-
const mcpJsonPath =
|
|
8116
|
+
const mcpJsonPath = join6(agentDir, "provision", ".mcp.json");
|
|
7865
8117
|
let mcpConfig;
|
|
7866
8118
|
try {
|
|
7867
8119
|
mcpConfig = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
@@ -7883,17 +8135,17 @@ ${sections}`
|
|
|
7883
8135
|
const READ_WRITE_MODE = 420;
|
|
7884
8136
|
const agentDir = getAgentDir(codeName);
|
|
7885
8137
|
const projectDir = getProjectDir2(codeName);
|
|
7886
|
-
for (const baseDir of [
|
|
7887
|
-
const skillDir =
|
|
8138
|
+
for (const baseDir of [join6(agentDir, "skills"), join6(projectDir, ".claude", "skills")]) {
|
|
8139
|
+
const skillDir = join6(baseDir, skillId);
|
|
7888
8140
|
mkdirSync4(skillDir, { recursive: true });
|
|
7889
8141
|
for (const file of files) {
|
|
7890
8142
|
assertSafeRelativePath(file.relativePath);
|
|
7891
|
-
const filePath =
|
|
7892
|
-
const rel =
|
|
8143
|
+
const filePath = join6(skillDir, file.relativePath);
|
|
8144
|
+
const rel = relative2(skillDir, filePath);
|
|
7893
8145
|
if (rel.startsWith("..") || rel === "") {
|
|
7894
8146
|
throw new Error(`Path traversal detected: ${file.relativePath} resolves outside ${skillDir}`);
|
|
7895
8147
|
}
|
|
7896
|
-
mkdirSync4(
|
|
8148
|
+
mkdirSync4(join6(filePath, ".."), { recursive: true });
|
|
7897
8149
|
if (isPluginManaged && existsSync4(filePath)) {
|
|
7898
8150
|
try {
|
|
7899
8151
|
chmodSync4(filePath, READ_WRITE_MODE);
|
|
@@ -7912,7 +8164,7 @@ ${sections}`
|
|
|
7912
8164
|
},
|
|
7913
8165
|
installPlugin(codeName, pluginId, pluginPath, pluginConfig) {
|
|
7914
8166
|
const agentDir = getAgentDir(codeName);
|
|
7915
|
-
const pluginsJsonPath =
|
|
8167
|
+
const pluginsJsonPath = join6(agentDir, "plugins.json");
|
|
7916
8168
|
mkdirSync4(agentDir, { recursive: true });
|
|
7917
8169
|
let pluginsConfig;
|
|
7918
8170
|
try {
|
|
@@ -7945,11 +8197,11 @@ ${sections}`
|
|
|
7945
8197
|
assertValidCodeName(codeName);
|
|
7946
8198
|
assertValidCodeName(plugin.slug);
|
|
7947
8199
|
const projectDir = getProjectDir2(codeName);
|
|
7948
|
-
const claudeDir =
|
|
8200
|
+
const claudeDir = join6(projectDir, ".claude");
|
|
7949
8201
|
mkdirSync4(claudeDir, { recursive: true });
|
|
7950
8202
|
const sourceSpec = options?.scriptSource ?? `augmented-plugin:${plugin.slug}`;
|
|
7951
8203
|
this.installPlugin(codeName, plugin.slug, sourceSpec, contextValues);
|
|
7952
|
-
const installedDir =
|
|
8204
|
+
const installedDir = join6(projectDir, ".claude", "plugins", plugin.slug);
|
|
7953
8205
|
for (const skill of plugin.skills) {
|
|
7954
8206
|
const skillId = skill.id;
|
|
7955
8207
|
assertValidCodeName(skillId);
|
|
@@ -7961,7 +8213,7 @@ ${sections}`
|
|
|
7961
8213
|
}
|
|
7962
8214
|
const scriptsConfig = plugin.scripts;
|
|
7963
8215
|
if (scriptsConfig?.hooks) {
|
|
7964
|
-
const settingsPath =
|
|
8216
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
7965
8217
|
let settings = {};
|
|
7966
8218
|
try {
|
|
7967
8219
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -8001,7 +8253,7 @@ ${sections}`
|
|
|
8001
8253
|
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
8002
8254
|
}
|
|
8003
8255
|
if (plugin.allowed_tools.length > 0) {
|
|
8004
|
-
const settingsPath =
|
|
8256
|
+
const settingsPath = join6(claudeDir, "settings.local.json");
|
|
8005
8257
|
let settings = {};
|
|
8006
8258
|
try {
|
|
8007
8259
|
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
@@ -8019,14 +8271,14 @@ ${sections}`
|
|
|
8019
8271
|
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
8020
8272
|
}
|
|
8021
8273
|
if (contextValues && Object.keys(contextValues).length > 0) {
|
|
8022
|
-
const configDir =
|
|
8274
|
+
const configDir = join6(projectDir, `.${plugin.slug}`);
|
|
8023
8275
|
mkdirSync4(configDir, { recursive: true });
|
|
8024
|
-
writeFileSync5(
|
|
8276
|
+
writeFileSync5(join6(configDir, "config.json"), JSON.stringify(contextValues, null, 2));
|
|
8025
8277
|
}
|
|
8026
8278
|
},
|
|
8027
8279
|
executePluginHook(ctx) {
|
|
8028
8280
|
assertValidCodeName(ctx.codeName);
|
|
8029
|
-
const agentRootDir =
|
|
8281
|
+
const agentRootDir = join6(getHomeDir(), ".augmented", ctx.codeName);
|
|
8030
8282
|
const projectDir = getProjectDir2(ctx.codeName);
|
|
8031
8283
|
mkdirSync4(agentRootDir, { recursive: true });
|
|
8032
8284
|
mkdirSync4(projectDir, { recursive: true });
|
|
@@ -8083,7 +8335,7 @@ function jsonOutput(data) {
|
|
|
8083
8335
|
}
|
|
8084
8336
|
|
|
8085
8337
|
// src/lib/atomic-write.ts
|
|
8086
|
-
import { closeSync, fchmodSync, fchownSync, fsyncSync, openSync, writeFileSync as writeFileSync6, renameSync as renameSync5, mkdirSync as mkdirSync5, unlinkSync as
|
|
8338
|
+
import { closeSync as closeSync2, fchmodSync, fchownSync, fsyncSync, openSync as openSync2, writeFileSync as writeFileSync6, renameSync as renameSync5, mkdirSync as mkdirSync5, unlinkSync as unlinkSync5 } from "fs";
|
|
8087
8339
|
import { dirname as dirname4 } from "path";
|
|
8088
8340
|
function atomicWriteFileSync(path, data, own) {
|
|
8089
8341
|
const dirPath = dirname4(path);
|
|
@@ -8092,7 +8344,7 @@ function atomicWriteFileSync(path, data, own) {
|
|
|
8092
8344
|
mkdirSync5(dirPath, { recursive: true });
|
|
8093
8345
|
} catch {
|
|
8094
8346
|
}
|
|
8095
|
-
const fd =
|
|
8347
|
+
const fd = openSync2(tmpPath, "w", 420);
|
|
8096
8348
|
try {
|
|
8097
8349
|
try {
|
|
8098
8350
|
writeFileSync6(fd, data);
|
|
@@ -8108,22 +8360,22 @@ function atomicWriteFileSync(path, data, own) {
|
|
|
8108
8360
|
} catch {
|
|
8109
8361
|
}
|
|
8110
8362
|
} finally {
|
|
8111
|
-
|
|
8363
|
+
closeSync2(fd);
|
|
8112
8364
|
}
|
|
8113
8365
|
renameSync5(tmpPath, path);
|
|
8114
8366
|
} catch (err) {
|
|
8115
8367
|
try {
|
|
8116
|
-
|
|
8368
|
+
unlinkSync5(tmpPath);
|
|
8117
8369
|
} catch {
|
|
8118
8370
|
}
|
|
8119
8371
|
throw err;
|
|
8120
8372
|
}
|
|
8121
8373
|
try {
|
|
8122
|
-
const dirFd =
|
|
8374
|
+
const dirFd = openSync2(dirPath, "r");
|
|
8123
8375
|
try {
|
|
8124
8376
|
fsyncSync(dirFd);
|
|
8125
8377
|
} finally {
|
|
8126
|
-
|
|
8378
|
+
closeSync2(dirFd);
|
|
8127
8379
|
}
|
|
8128
8380
|
} catch {
|
|
8129
8381
|
}
|
|
@@ -8132,9 +8384,9 @@ function atomicWriteFileSync(path, data, own) {
|
|
|
8132
8384
|
// src/lib/feature-flags-host.ts
|
|
8133
8385
|
import { existsSync as existsSync5, readFileSync as readFileSync6, rmSync as rmSync3, statSync as statSync2 } from "fs";
|
|
8134
8386
|
import { homedir as homedir4 } from "os";
|
|
8135
|
-
import { join as
|
|
8387
|
+
import { join as join7 } from "path";
|
|
8136
8388
|
function defaultFlagsCachePath(configDir) {
|
|
8137
|
-
return
|
|
8389
|
+
return join7(configDir, "flags-cache.json");
|
|
8138
8390
|
}
|
|
8139
8391
|
function readFlagsCache(path) {
|
|
8140
8392
|
try {
|
|
@@ -8192,6 +8444,7 @@ function resolveAllFlags(heartbeatFlags, env = process.env) {
|
|
|
8192
8444
|
(definition) => resolveFlagFromLayers(definition, heartbeatFlags, env)
|
|
8193
8445
|
);
|
|
8194
8446
|
}
|
|
8447
|
+
var PER_AGENT_FLAG_EVALUATION_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
8195
8448
|
var HostFlagStore = class {
|
|
8196
8449
|
heartbeatFlags = {};
|
|
8197
8450
|
/**
|
|
@@ -8220,6 +8473,9 @@ var HostFlagStore = class {
|
|
|
8220
8473
|
* flag ships dark, so it stays empty and every agent resolves host-wide).
|
|
8221
8474
|
*/
|
|
8222
8475
|
booleanFlagsByAgent = {};
|
|
8476
|
+
/** ENG-11877: agents the latest heartbeat really evaluated. Null until one says, or when it failed. */
|
|
8477
|
+
perAgentFlagsEvaluated = null;
|
|
8478
|
+
perAgentFlagsEvaluatedAt = 0;
|
|
8223
8479
|
/**
|
|
8224
8480
|
* The `flags_schema_version` from the most recent heartbeat, retained so a
|
|
8225
8481
|
* per-agent-map write (which carries no schema version of its own) persists
|
|
@@ -8409,12 +8665,12 @@ var HostFlagStore = class {
|
|
|
8409
8665
|
* The in-memory state stays authoritative and the next heartbeat retries.
|
|
8410
8666
|
*/
|
|
8411
8667
|
persistPerAgentCaches(updatedAt) {
|
|
8412
|
-
const root =
|
|
8668
|
+
const root = join7(homedir4(), ".augmented");
|
|
8413
8669
|
for (const agentId of this.mirrorAgentIds) {
|
|
8414
8670
|
try {
|
|
8415
|
-
const dir =
|
|
8671
|
+
const dir = join7(root, agentId);
|
|
8416
8672
|
if (!existsSync5(dir)) continue;
|
|
8417
|
-
writeFlagsCache(
|
|
8673
|
+
writeFlagsCache(join7(dir, "flags-cache.json"), {
|
|
8418
8674
|
schema_version: this.lastSchemaVersion,
|
|
8419
8675
|
updated_at: updatedAt,
|
|
8420
8676
|
flags: this.flagsForAgent(agentId),
|
|
@@ -8428,7 +8684,7 @@ var HostFlagStore = class {
|
|
|
8428
8684
|
} catch (err) {
|
|
8429
8685
|
let removed = "left in place";
|
|
8430
8686
|
try {
|
|
8431
|
-
rmSync3(
|
|
8687
|
+
rmSync3(join7(root, agentId, "flags-cache.json"), { force: true, recursive: true });
|
|
8432
8688
|
removed = "stale mirror removed";
|
|
8433
8689
|
} catch (rmErr) {
|
|
8434
8690
|
removed = `stale mirror could NOT be removed: ${rmErr.message}`;
|
|
@@ -8500,6 +8756,18 @@ var HostFlagStore = class {
|
|
|
8500
8756
|
if (resolved && typeof resolved.value === "boolean") return resolved.value;
|
|
8501
8757
|
return definition?.flagType === "boolean" ? definition.defaultValue : false;
|
|
8502
8758
|
}
|
|
8759
|
+
/**
|
|
8760
|
+
* ENG-11877: can this agent's per-agent flags be trusted right now? `confirmed`:
|
|
8761
|
+
* the latest heartbeat evaluated it. `not-evaluated`: it evaluated others, not this
|
|
8762
|
+
* one (only active agents are evaluated). `unknown`: no evaluation to go on, or
|
|
8763
|
+
* the last one is too old. A failed heartbeat updates nothing here, so without the
|
|
8764
|
+
* age check an outage would leave stale answers trusted for as long as it lasted.
|
|
8765
|
+
*/
|
|
8766
|
+
perAgentFlagState(agentId, nowMs = Date.now()) {
|
|
8767
|
+
if (this.perAgentFlagsEvaluated === null) return "unknown";
|
|
8768
|
+
if (nowMs - this.perAgentFlagsEvaluatedAt > PER_AGENT_FLAG_EVALUATION_MAX_AGE_MS) return "unknown";
|
|
8769
|
+
return this.perAgentFlagsEvaluated.has(agentId) ? "confirmed" : "not-evaluated";
|
|
8770
|
+
}
|
|
8503
8771
|
/**
|
|
8504
8772
|
* ENG-7891 / ADR-0049 slice 3: resolve a BOOLEAN flag FOR A SPECIFIC AGENT.
|
|
8505
8773
|
* Precedence mirrors {@link getStringForAgent}:
|
|
@@ -8571,7 +8839,9 @@ var HostFlagStore = class {
|
|
|
8571
8839
|
* value until the next heartbeat rather than rehydrating a stale opt-in for a
|
|
8572
8840
|
* one-way-door migration.
|
|
8573
8841
|
*/
|
|
8574
|
-
applyBooleanFlagsByAgent(map) {
|
|
8842
|
+
applyBooleanFlagsByAgent(map, evaluatedAgentIds, nowMs = Date.now()) {
|
|
8843
|
+
this.perAgentFlagsEvaluated = Array.isArray(evaluatedAgentIds) ? new Set(evaluatedAgentIds.filter((id) => typeof id === "string")) : null;
|
|
8844
|
+
this.perAgentFlagsEvaluatedAt = nowMs;
|
|
8575
8845
|
if (!map || typeof map !== "object") {
|
|
8576
8846
|
const before = this.booleanFlagsByAgent;
|
|
8577
8847
|
this.booleanFlagsByAgent = {};
|
|
@@ -10327,7 +10597,7 @@ function verdictForUnavailableMcpConfig(cause, ctx) {
|
|
|
10327
10597
|
}
|
|
10328
10598
|
|
|
10329
10599
|
// src/lib/connectivity-probe-context.ts
|
|
10330
|
-
import { delimiter as pathDelimiter, join as
|
|
10600
|
+
import { delimiter as pathDelimiter, join as join8 } from "path";
|
|
10331
10601
|
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
10332
10602
|
import { homedir as homedir5 } from "os";
|
|
10333
10603
|
|
|
@@ -11262,7 +11532,7 @@ function resolveHttpServerEntry(entry, env) {
|
|
|
11262
11532
|
}
|
|
11263
11533
|
function readMcpServerEntry(projectDir, serverKey) {
|
|
11264
11534
|
try {
|
|
11265
|
-
const raw = readFileSync7(
|
|
11535
|
+
const raw = readFileSync7(join8(projectDir, ".mcp.json"), "utf-8");
|
|
11266
11536
|
const servers = JSON.parse(raw).mcpServers ?? {};
|
|
11267
11537
|
return servers[serverKey] ?? null;
|
|
11268
11538
|
} catch {
|
|
@@ -11272,7 +11542,7 @@ function readMcpServerEntry(projectDir, serverKey) {
|
|
|
11272
11542
|
function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
11273
11543
|
let servers;
|
|
11274
11544
|
try {
|
|
11275
|
-
const raw = readFileSync7(
|
|
11545
|
+
const raw = readFileSync7(join8(projectDir, ".mcp.json"), "utf-8");
|
|
11276
11546
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
11277
11547
|
} catch {
|
|
11278
11548
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -11284,7 +11554,7 @@ function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
|
11284
11554
|
}
|
|
11285
11555
|
function resolveDeclaredServerKey(projectDir, definitionId, derivedKey) {
|
|
11286
11556
|
try {
|
|
11287
|
-
const raw = readFileSync7(
|
|
11557
|
+
const raw = readFileSync7(join8(projectDir, ".mcp.json"), "utf-8");
|
|
11288
11558
|
const servers = JSON.parse(raw).mcpServers ?? {};
|
|
11289
11559
|
const declared = Object.keys(servers);
|
|
11290
11560
|
if (derivedKey !== definitionId && derivedKey !== sanitizeServerKey(definitionId)) {
|
|
@@ -11326,7 +11596,7 @@ function resolveStdioServerEntry(entry, env) {
|
|
|
11326
11596
|
function readMcpStdioServerConfig(projectDir, serverKey, env) {
|
|
11327
11597
|
let servers;
|
|
11328
11598
|
try {
|
|
11329
|
-
const raw = readFileSync7(
|
|
11599
|
+
const raw = readFileSync7(join8(projectDir, ".mcp.json"), "utf-8");
|
|
11330
11600
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
11331
11601
|
} catch {
|
|
11332
11602
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -11354,13 +11624,13 @@ function toolkitPathDirs() {
|
|
|
11354
11624
|
const home = process.env.HOME?.trim() || homedir5();
|
|
11355
11625
|
return [
|
|
11356
11626
|
...PROBE_TOOLKIT_PATH_DIRS,
|
|
11357
|
-
...PROBE_HOME_RELATIVE_PATH_SEGMENTS.map((seg) =>
|
|
11627
|
+
...PROBE_HOME_RELATIVE_PATH_SEGMENTS.map((seg) => join8(home, seg))
|
|
11358
11628
|
];
|
|
11359
11629
|
}
|
|
11360
11630
|
function buildProbeEnv(projectDir, agentId) {
|
|
11361
11631
|
const probeEnv = { ...process.env };
|
|
11362
11632
|
try {
|
|
11363
|
-
const envIntPath =
|
|
11633
|
+
const envIntPath = join8(projectDir, ".env.integrations");
|
|
11364
11634
|
if (existsSync6(envIntPath)) {
|
|
11365
11635
|
Object.assign(probeEnv, parseEnvIntegrations(readFileSync7(envIntPath, "utf-8")));
|
|
11366
11636
|
}
|
|
@@ -11370,7 +11640,7 @@ function buildProbeEnv(projectDir, agentId) {
|
|
|
11370
11640
|
probeEnv.AGT_AGENT_ID = agentId.trim();
|
|
11371
11641
|
}
|
|
11372
11642
|
try {
|
|
11373
|
-
const agentBinDir =
|
|
11643
|
+
const agentBinDir = join8(projectDir, ".claude", "agt-bin");
|
|
11374
11644
|
if (existsSync6(agentBinDir)) {
|
|
11375
11645
|
const parts = probeEnv.PATH ? probeEnv.PATH.split(pathDelimiter) : [];
|
|
11376
11646
|
parts.unshift(agentBinDir);
|
|
@@ -11769,7 +12039,7 @@ var TunnelWatcher = class {
|
|
|
11769
12039
|
// src/lib/session-tool-bind-probe-host.ts
|
|
11770
12040
|
import { execFileSync as syncExecFile } from "child_process";
|
|
11771
12041
|
import { readFileSync as readFileSync8 } from "fs";
|
|
11772
|
-
import { join as
|
|
12042
|
+
import { join as join9 } from "path";
|
|
11773
12043
|
import { dirname as dirname5 } from "path";
|
|
11774
12044
|
function termsRestrictedServerKeys(integrations, isRestricted = isProbeRestrictedByProviderTerms) {
|
|
11775
12045
|
const keys = /* @__PURE__ */ new Set();
|
|
@@ -11813,7 +12083,7 @@ async function gatherSessionToolBindProbe(agent, integrations, projectDir, opts)
|
|
|
11813
12083
|
if (integrations.length === 0) return null;
|
|
11814
12084
|
let mcpRaw = null;
|
|
11815
12085
|
try {
|
|
11816
|
-
mcpRaw = readFileSync8(
|
|
12086
|
+
mcpRaw = readFileSync8(join9(projectDir, ".mcp.json"), "utf-8");
|
|
11817
12087
|
} catch {
|
|
11818
12088
|
mcpRaw = null;
|
|
11819
12089
|
}
|
|
@@ -11917,7 +12187,7 @@ var SLACK_MCP_SERVER_KEY = "slack";
|
|
|
11917
12187
|
function readSlackTransportDownKeys(projectDir) {
|
|
11918
12188
|
const none = /* @__PURE__ */ new Set();
|
|
11919
12189
|
try {
|
|
11920
|
-
const raw = readFileSync8(
|
|
12190
|
+
const raw = readFileSync8(join9(dirname5(projectDir), SLACK_SOCKET_STATE_FILENAME), "utf-8");
|
|
11921
12191
|
const state = parseSlackSocketState(raw, Date.now());
|
|
11922
12192
|
return isSlackInboundTransportDown(state, SLACK_TRANSPORT_DOWN_AFTER_MS) ? /* @__PURE__ */ new Set([SLACK_MCP_SERVER_KEY]) : none;
|
|
11923
12193
|
} catch {
|
|
@@ -12004,7 +12274,7 @@ function describeWorkerModuleFailure(err) {
|
|
|
12004
12274
|
// src/lib/drain-transcript-flush.ts
|
|
12005
12275
|
import { existsSync as existsSync7, readdirSync as readdirSync2 } from "fs";
|
|
12006
12276
|
import { homedir as homedir6 } from "os";
|
|
12007
|
-
import { dirname as dirname6, join as
|
|
12277
|
+
import { dirname as dirname6, join as join10, relative as relative3, sep } from "path";
|
|
12008
12278
|
import { spawn as spawn2 } from "child_process";
|
|
12009
12279
|
|
|
12010
12280
|
// src/lib/host-archive-address.ts
|
|
@@ -12048,7 +12318,7 @@ function readHostArchiveAddress(path) {
|
|
|
12048
12318
|
|
|
12049
12319
|
// src/lib/drain-transcript-flush.ts
|
|
12050
12320
|
function sessionsBaseDir() {
|
|
12051
|
-
return
|
|
12321
|
+
return join10(homedir6(), ".claude", "projects");
|
|
12052
12322
|
}
|
|
12053
12323
|
var PER_FILE_UPLOAD_TIMEOUT_MS = 3e4;
|
|
12054
12324
|
var UPLOAD_CONCURRENCY = 4;
|
|
@@ -12059,7 +12329,7 @@ function listJsonlFiles(dir) {
|
|
|
12059
12329
|
const out = [];
|
|
12060
12330
|
const walk = (d) => {
|
|
12061
12331
|
for (const entry of readdirSync2(d, { withFileTypes: true })) {
|
|
12062
|
-
const full =
|
|
12332
|
+
const full = join10(d, entry.name);
|
|
12063
12333
|
if (entry.isDirectory()) walk(full);
|
|
12064
12334
|
else if (entry.isFile() && entry.name.endsWith(".jsonl")) out.push(full);
|
|
12065
12335
|
}
|
|
@@ -12071,12 +12341,12 @@ function listJsonlFiles(dir) {
|
|
|
12071
12341
|
return out;
|
|
12072
12342
|
}
|
|
12073
12343
|
function transcriptObjectKey(keyPrefix, baseDir, file) {
|
|
12074
|
-
const rel =
|
|
12344
|
+
const rel = relative3(baseDir, file).split(sep).join("/");
|
|
12075
12345
|
if (!rel || rel.startsWith("../") || rel === "..") return null;
|
|
12076
12346
|
return `${keyPrefix.replace(/\/+$/, "")}/${rel}`;
|
|
12077
12347
|
}
|
|
12078
12348
|
function drainManifestObjectKey(keyPrefix, baseDir, transcriptDir) {
|
|
12079
|
-
return transcriptObjectKey(keyPrefix, baseDir,
|
|
12349
|
+
return transcriptObjectKey(keyPrefix, baseDir, join10(transcriptDir, DRAIN_MANIFEST_FILENAME));
|
|
12080
12350
|
}
|
|
12081
12351
|
async function flushAgentTranscriptsOnDrain(codeName, deps) {
|
|
12082
12352
|
const dir = deps.resolveTranscriptDir(codeName);
|
|
@@ -12228,7 +12498,7 @@ function drainTranscriptFlushDeps(log2) {
|
|
|
12228
12498
|
// tree — the thing host-archive-address.ts's header warns about.
|
|
12229
12499
|
readSourceLayout: (codeName) => {
|
|
12230
12500
|
const agentDir = dirname6(getProjectDir(codeName));
|
|
12231
|
-
const codeNameDir =
|
|
12501
|
+
const codeNameDir = join10(homedir6(), ".augmented", codeName);
|
|
12232
12502
|
return { layout: agentDir === codeNameDir ? "codename-keyed" : "id-keyed", agentDir };
|
|
12233
12503
|
},
|
|
12234
12504
|
readSessionPin: (codeName) => readDailySessionPin(codeName),
|
|
@@ -12315,7 +12585,7 @@ function decidePin(opts) {
|
|
|
12315
12585
|
|
|
12316
12586
|
// src/commands/setup.ts
|
|
12317
12587
|
import { existsSync as existsSync9, readFileSync as readFileSync11, writeFileSync as writeFileSync8, mkdirSync as mkdirSync7, accessSync, constants as fsConstants } from "fs";
|
|
12318
|
-
import { join as
|
|
12588
|
+
import { join as join12, dirname as dirname7 } from "path";
|
|
12319
12589
|
import { homedir as homedir7 } from "os";
|
|
12320
12590
|
import chalk3 from "chalk";
|
|
12321
12591
|
import ora from "ora";
|
|
@@ -12347,15 +12617,15 @@ function table(headers, rows) {
|
|
|
12347
12617
|
}
|
|
12348
12618
|
|
|
12349
12619
|
// src/lib/watchdog.ts
|
|
12350
|
-
import { readFileSync as readFileSync10, writeFileSync as writeFileSync7, unlinkSync as
|
|
12351
|
-
import { join as
|
|
12620
|
+
import { readFileSync as readFileSync10, writeFileSync as writeFileSync7, unlinkSync as unlinkSync6, existsSync as existsSync8, mkdirSync as mkdirSync6, openSync as openSync3, closeSync as closeSync3, chmodSync as chmodSync5 } from "fs";
|
|
12621
|
+
import { join as join11 } from "path";
|
|
12352
12622
|
import { spawn as spawn3, execFileSync as execFileSync3 } from "child_process";
|
|
12353
|
-
var DEFAULT_CONFIG_DIR =
|
|
12623
|
+
var DEFAULT_CONFIG_DIR = join11(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
12354
12624
|
function getManagerPaths(configDir) {
|
|
12355
12625
|
return {
|
|
12356
|
-
pidFile:
|
|
12357
|
-
stateFile:
|
|
12358
|
-
logFile:
|
|
12626
|
+
pidFile: join11(configDir, "manager.pid"),
|
|
12627
|
+
stateFile: join11(configDir, "manager-state.json"),
|
|
12628
|
+
logFile: join11(configDir, "manager.log")
|
|
12359
12629
|
};
|
|
12360
12630
|
}
|
|
12361
12631
|
function ensureDir(configDir) {
|
|
@@ -12378,7 +12648,7 @@ function readPidFile(configDir) {
|
|
|
12378
12648
|
}
|
|
12379
12649
|
function removePidFile(configDir) {
|
|
12380
12650
|
try {
|
|
12381
|
-
|
|
12651
|
+
unlinkSync6(getManagerPaths(configDir).pidFile);
|
|
12382
12652
|
} catch {
|
|
12383
12653
|
}
|
|
12384
12654
|
}
|
|
@@ -12423,7 +12693,7 @@ function readStateFile(configDir) {
|
|
|
12423
12693
|
}
|
|
12424
12694
|
function removeStateFile(configDir) {
|
|
12425
12695
|
try {
|
|
12426
|
-
|
|
12696
|
+
unlinkSync6(getManagerPaths(configDir).stateFile);
|
|
12427
12697
|
} catch {
|
|
12428
12698
|
}
|
|
12429
12699
|
}
|
|
@@ -12447,7 +12717,7 @@ function startWatchdog(opts) {
|
|
|
12447
12717
|
if (opts.detached) {
|
|
12448
12718
|
ensureDir(configDir);
|
|
12449
12719
|
const { logFile } = getManagerPaths(configDir);
|
|
12450
|
-
const logFd =
|
|
12720
|
+
const logFd = openSync3(logFile, "a", 384);
|
|
12451
12721
|
try {
|
|
12452
12722
|
chmodSync5(logFile, 384);
|
|
12453
12723
|
} catch {
|
|
@@ -12463,7 +12733,7 @@ function startWatchdog(opts) {
|
|
|
12463
12733
|
}
|
|
12464
12734
|
);
|
|
12465
12735
|
child.unref();
|
|
12466
|
-
|
|
12736
|
+
closeSync3(logFd);
|
|
12467
12737
|
if (!child.pid) {
|
|
12468
12738
|
throw new Error("Failed to spawn detached manager process");
|
|
12469
12739
|
}
|
|
@@ -12547,15 +12817,15 @@ function detectShellProfile() {
|
|
|
12547
12817
|
const shell = process.env["SHELL"] ?? "";
|
|
12548
12818
|
const home = homedir7();
|
|
12549
12819
|
if (shell.includes("zsh")) {
|
|
12550
|
-
return
|
|
12820
|
+
return join12(home, ".zshrc");
|
|
12551
12821
|
}
|
|
12552
12822
|
if (shell.includes("fish")) {
|
|
12553
|
-
const fishConfig =
|
|
12823
|
+
const fishConfig = join12(home, ".config", "fish", "config.fish");
|
|
12554
12824
|
return fishConfig;
|
|
12555
12825
|
}
|
|
12556
|
-
const bashrc =
|
|
12826
|
+
const bashrc = join12(home, ".bashrc");
|
|
12557
12827
|
if (existsSync9(bashrc)) return bashrc;
|
|
12558
|
-
return
|
|
12828
|
+
return join12(home, ".bash_profile");
|
|
12559
12829
|
}
|
|
12560
12830
|
function maybeWriteSystemWideEnv(apiUrl, apiKey, consoleUrl) {
|
|
12561
12831
|
const empty = { etcEnvironment: false, profileD: false, bashrc: false };
|
|
@@ -12830,7 +13100,7 @@ async function setupCommand(token, options = {}) {
|
|
|
12830
13100
|
const managerSpinner = ora({ text: "Starting manager daemon\u2026", isSilent: json });
|
|
12831
13101
|
managerSpinner.start();
|
|
12832
13102
|
try {
|
|
12833
|
-
const configDir =
|
|
13103
|
+
const configDir = join12(homedir7(), ".augmented");
|
|
12834
13104
|
const { pid } = startWatchdog({ intervalMs: 1e4, configDir, detached: true });
|
|
12835
13105
|
managerSpinner.succeed(`Manager started (PID ${pid})`);
|
|
12836
13106
|
} catch (err) {
|
|
@@ -12869,8 +13139,8 @@ async function setupCommand(token, options = {}) {
|
|
|
12869
13139
|
|
|
12870
13140
|
// src/commands/manager.ts
|
|
12871
13141
|
import chalk4 from "chalk";
|
|
12872
|
-
import { existsSync as existsSync10, realpathSync as
|
|
12873
|
-
import { join as
|
|
13142
|
+
import { existsSync as existsSync10, realpathSync as realpathSync3 } from "fs";
|
|
13143
|
+
import { join as join13 } from "path";
|
|
12874
13144
|
import { homedir as homedir8, userInfo } from "os";
|
|
12875
13145
|
import { spawn as spawn4 } from "child_process";
|
|
12876
13146
|
function normalizePinInEnv(env) {
|
|
@@ -12915,7 +13185,7 @@ function managerStartCommand(opts) {
|
|
|
12915
13185
|
process.exitCode = 1;
|
|
12916
13186
|
return;
|
|
12917
13187
|
}
|
|
12918
|
-
const configDir = opts.configDir ??
|
|
13188
|
+
const configDir = opts.configDir ?? join13(homedir8(), ".augmented");
|
|
12919
13189
|
if (opts.supervise) {
|
|
12920
13190
|
if (json) {
|
|
12921
13191
|
jsonOutput({ ok: false, error: "--supervise is not supported with --json" });
|
|
@@ -13011,7 +13281,7 @@ function runSupervisorLoop(intervalSec, configDir) {
|
|
|
13011
13281
|
}
|
|
13012
13282
|
async function managerStopCommand(opts = {}) {
|
|
13013
13283
|
const json = isJsonMode();
|
|
13014
|
-
const configDir = opts.configDir ??
|
|
13284
|
+
const configDir = opts.configDir ?? join13(homedir8(), ".augmented");
|
|
13015
13285
|
try {
|
|
13016
13286
|
const result = await stopWatchdog(configDir);
|
|
13017
13287
|
if (!result.stopped && !result.pid) {
|
|
@@ -13039,7 +13309,7 @@ async function managerStopCommand(opts = {}) {
|
|
|
13039
13309
|
}
|
|
13040
13310
|
function managerStatusCommand(opts = {}) {
|
|
13041
13311
|
const json = isJsonMode();
|
|
13042
|
-
const configDir = opts.configDir ??
|
|
13312
|
+
const configDir = opts.configDir ?? join13(homedir8(), ".augmented");
|
|
13043
13313
|
const status = getManagerStatus(configDir);
|
|
13044
13314
|
if (!status) {
|
|
13045
13315
|
if (json) {
|
|
@@ -13131,7 +13401,7 @@ function resolveStableAgtBin(rawPath) {
|
|
|
13131
13401
|
for (const candidate of candidates) {
|
|
13132
13402
|
if (!existsSync10(candidate)) continue;
|
|
13133
13403
|
try {
|
|
13134
|
-
|
|
13404
|
+
realpathSync3(candidate);
|
|
13135
13405
|
return candidate;
|
|
13136
13406
|
} catch {
|
|
13137
13407
|
}
|
|
@@ -13149,7 +13419,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
13149
13419
|
process.exitCode = 1;
|
|
13150
13420
|
return;
|
|
13151
13421
|
}
|
|
13152
|
-
const configDir = opts.configDir ??
|
|
13422
|
+
const configDir = opts.configDir ?? join13(homedir8(), ".augmented");
|
|
13153
13423
|
const rawAgtBin = process.argv[1];
|
|
13154
13424
|
if (!rawAgtBin) {
|
|
13155
13425
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -13162,7 +13432,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
13162
13432
|
if (process.platform === "darwin") {
|
|
13163
13433
|
const home = homedir8();
|
|
13164
13434
|
const protectedRoots = ["Documents", "Downloads", "Desktop", "Movies", "Music", "Pictures"];
|
|
13165
|
-
const offending = protectedRoots.map((r) =>
|
|
13435
|
+
const offending = protectedRoots.map((r) => join13(home, r)).find((p) => agtBin === p || agtBin.startsWith(`${p}/`));
|
|
13166
13436
|
if (offending) {
|
|
13167
13437
|
const msg = `agt binary at ${agtBin} sits inside a macOS TCC-protected folder (${offending}). launchd-spawned processes cannot read files there and the manager would EPERM on startup. Either install agt globally (\`npm install -g @integrity-labs/agt-cli\`) or copy the dist outside protected folders before running this command.`;
|
|
13168
13438
|
if (json) jsonOutput({ ok: false, error: msg });
|
|
@@ -13228,7 +13498,7 @@ async function managerInstallSystemUnitCommand(opts = {}) {
|
|
|
13228
13498
|
return;
|
|
13229
13499
|
}
|
|
13230
13500
|
const user = opts.user ?? "root";
|
|
13231
|
-
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" :
|
|
13501
|
+
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" : join13("/home", user, ".augmented"));
|
|
13232
13502
|
const rawAgtBin = process.argv[1];
|
|
13233
13503
|
if (!rawAgtBin) {
|
|
13234
13504
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -13455,6 +13725,7 @@ export {
|
|
|
13455
13725
|
parseRmPolicy,
|
|
13456
13726
|
migrateAgentDirToIdKeyed,
|
|
13457
13727
|
reapLegacyTokenFile,
|
|
13728
|
+
setScratchSweepPolicyResolver,
|
|
13458
13729
|
provisionStopHook,
|
|
13459
13730
|
provisionIsolationHook,
|
|
13460
13731
|
provisionAutoKanbanProgressHook,
|
|
@@ -13537,4 +13808,4 @@ export {
|
|
|
13537
13808
|
managerInstallSystemUnitCommand,
|
|
13538
13809
|
managerUninstallSystemUnitCommand
|
|
13539
13810
|
};
|
|
13540
|
-
//# sourceMappingURL=chunk-
|
|
13811
|
+
//# sourceMappingURL=chunk-PIKXAEVA.js.map
|