@integrity-labs/agt-cli 0.28.834 → 0.28.835
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/assets/review/obiwan-auth.mjs +215 -0
- package/dist/assets/review/post-review-findings.mjs +539 -0
- package/dist/bin/agt.js +3 -3
- package/dist/{chunk-LLIAJK4F.js → chunk-REBHUZ7N.js} +2 -2
- package/dist/lib/manager-worker.js +400 -347
- package/dist/lib/manager-worker.js.map +1 -1
- package/package.json +2 -2
- /package/dist/{chunk-LLIAJK4F.js.map → chunk-REBHUZ7N.js.map} +0 -0
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
safeWriteJsonAtomic,
|
|
61
61
|
setConfigHash,
|
|
62
62
|
tripClass
|
|
63
|
-
} from "../chunk-
|
|
63
|
+
} from "../chunk-REBHUZ7N.js";
|
|
64
64
|
import {
|
|
65
65
|
getProjectDir as getProjectDir2,
|
|
66
66
|
getReadyTasks,
|
|
@@ -228,7 +228,7 @@ import {
|
|
|
228
228
|
|
|
229
229
|
// src/lib/manager-worker.ts
|
|
230
230
|
import { createHash as createHash20 } from "crypto";
|
|
231
|
-
import { readFileSync as
|
|
231
|
+
import { readFileSync as readFileSync33, writeFileSync as writeFileSync18, mkdirSync as mkdirSync15, existsSync as existsSync20, rmSync as rmSync8, readdirSync as readdirSync12, statSync as statSync11, unlinkSync as unlinkSync6, renameSync as renameSync11, utimesSync as utimesSync4 } from "fs";
|
|
232
232
|
|
|
233
233
|
// src/lib/atomic-file-replace.ts
|
|
234
234
|
import { copyFileSync, renameSync, unlinkSync } from "fs";
|
|
@@ -254,9 +254,9 @@ function defaultUnique() {
|
|
|
254
254
|
|
|
255
255
|
// src/lib/manager-worker.ts
|
|
256
256
|
import { execFileSync as syncExecFile } from "child_process";
|
|
257
|
-
import { join as
|
|
257
|
+
import { join as join42, dirname as dirname11, delimiter as pathDelimiter } from "path";
|
|
258
258
|
import { homedir as homedir17 } from "os";
|
|
259
|
-
import { fileURLToPath } from "url";
|
|
259
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
260
260
|
|
|
261
261
|
// ../../packages/core/dist/provisioning/channel-policy-env.js
|
|
262
262
|
var TELEGRAM_RESTART_ON_CHANGE_ENV_KEYS = [
|
|
@@ -1847,12 +1847,12 @@ function isPathInsideDir(candidate, dir) {
|
|
|
1847
1847
|
return resolvedCandidate.startsWith(resolvedDir.endsWith(sep) ? resolvedDir : resolvedDir + sep);
|
|
1848
1848
|
}
|
|
1849
1849
|
function findMissingMcpBundles(mcpConfigPath, deps = {}) {
|
|
1850
|
-
const
|
|
1851
|
-
const
|
|
1850
|
+
const existsSync21 = deps.existsSync ?? nodeExistsSync;
|
|
1851
|
+
const readFileSync34 = deps.readFileSync ?? nodeReadFileSync;
|
|
1852
1852
|
const mcpDir = deps.mcpDir ?? getSharedMcpDir();
|
|
1853
1853
|
let parsed;
|
|
1854
1854
|
try {
|
|
1855
|
-
parsed = JSON.parse(
|
|
1855
|
+
parsed = JSON.parse(readFileSync34(mcpConfigPath, "utf-8"));
|
|
1856
1856
|
} catch {
|
|
1857
1857
|
return [];
|
|
1858
1858
|
}
|
|
@@ -1872,7 +1872,7 @@ function findMissingMcpBundles(mcpConfigPath, deps = {}) {
|
|
|
1872
1872
|
if (seenPaths.has(resolvedBundlePath)) continue;
|
|
1873
1873
|
let present;
|
|
1874
1874
|
try {
|
|
1875
|
-
present =
|
|
1875
|
+
present = existsSync21(bundlePath);
|
|
1876
1876
|
} catch {
|
|
1877
1877
|
continue;
|
|
1878
1878
|
}
|
|
@@ -2275,9 +2275,57 @@ function isDirectChatMessageExpired(createdAt, nowMs, maxAgeMs) {
|
|
|
2275
2275
|
return nowMs - created > maxAgeMs;
|
|
2276
2276
|
}
|
|
2277
2277
|
|
|
2278
|
+
// src/lib/review-poster-asset.ts
|
|
2279
|
+
import { copyFileSync as copyFileSync2, chmodSync, existsSync as existsSync2, mkdirSync as mkdirSync4, readFileSync as readFileSync8 } from "fs";
|
|
2280
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
2281
|
+
import { fileURLToPath } from "url";
|
|
2282
|
+
var POSTER_FILENAME = "post-review-findings.mjs";
|
|
2283
|
+
var AUTH_FILENAME = "obiwan-auth.mjs";
|
|
2284
|
+
var ASSET_FILES = [
|
|
2285
|
+
[POSTER_FILENAME, 493],
|
|
2286
|
+
[AUTH_FILENAME, 420]
|
|
2287
|
+
];
|
|
2288
|
+
var REVIEW_ASSET_DIRNAME = "review";
|
|
2289
|
+
function resolveBundledReviewAssetDir() {
|
|
2290
|
+
const moduleDir = dirname5(fileURLToPath(import.meta.url));
|
|
2291
|
+
const candidates = [
|
|
2292
|
+
// Built output: dist/<chunk>.js → dist/assets/review
|
|
2293
|
+
join8(moduleDir, "assets", REVIEW_ASSET_DIRNAME),
|
|
2294
|
+
// Built output sibling case: dist/<sub>/<chunk>.js → dist/assets/review
|
|
2295
|
+
join8(moduleDir, "..", "assets", REVIEW_ASSET_DIRNAME),
|
|
2296
|
+
// Dev source: src/lib/review-poster-asset.ts → ../../assets/review
|
|
2297
|
+
join8(moduleDir, "..", "..", "assets", REVIEW_ASSET_DIRNAME)
|
|
2298
|
+
];
|
|
2299
|
+
for (const candidate of candidates) {
|
|
2300
|
+
if (existsSync2(join8(candidate, POSTER_FILENAME))) return candidate;
|
|
2301
|
+
}
|
|
2302
|
+
throw new Error(
|
|
2303
|
+
`[review-poster] could not locate bundled assets; tried:
|
|
2304
|
+
${candidates.join("\n ")}`
|
|
2305
|
+
);
|
|
2306
|
+
}
|
|
2307
|
+
function reviewPosterDir(codeName) {
|
|
2308
|
+
return join8(getFramework("claude-code").getAgentDir(codeName), REVIEW_ASSET_DIRNAME);
|
|
2309
|
+
}
|
|
2310
|
+
function provisionReviewPoster(codeName, sourceDir = resolveBundledReviewAssetDir()) {
|
|
2311
|
+
const destDir = reviewPosterDir(codeName);
|
|
2312
|
+
mkdirSync4(destDir, { recursive: true });
|
|
2313
|
+
for (const [name, mode] of ASSET_FILES) {
|
|
2314
|
+
const src = join8(sourceDir, name);
|
|
2315
|
+
const dest = join8(destDir, name);
|
|
2316
|
+
if (!existsSync2(src)) {
|
|
2317
|
+
throw new Error(`[review-poster] bundled asset missing: ${src}`);
|
|
2318
|
+
}
|
|
2319
|
+
if (!existsSync2(dest) || !readFileSync8(src).equals(readFileSync8(dest))) {
|
|
2320
|
+
copyFileSync2(src, dest);
|
|
2321
|
+
}
|
|
2322
|
+
chmodSync(dest, mode);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2278
2326
|
// src/lib/id-keyed-migration.ts
|
|
2279
|
-
import { existsSync as
|
|
2280
|
-
import { join as
|
|
2327
|
+
import { existsSync as existsSync3, lstatSync, readlinkSync, renameSync as renameSync2 } from "fs";
|
|
2328
|
+
import { join as join9 } from "path";
|
|
2281
2329
|
import { homedir as homedir3 } from "os";
|
|
2282
2330
|
var ID_KEYED_MIGRATION_FLAG = "id-keyed-layout-migration";
|
|
2283
2331
|
function agentHasActiveWhatsapp(channelConfigs, codeNameDir) {
|
|
@@ -2285,7 +2333,7 @@ function agentHasActiveWhatsapp(channelConfigs, codeNameDir) {
|
|
|
2285
2333
|
return true;
|
|
2286
2334
|
}
|
|
2287
2335
|
try {
|
|
2288
|
-
if (
|
|
2336
|
+
if (existsSync3(join9(codeNameDir, "whatsapp-pending-inbound"))) return true;
|
|
2289
2337
|
} catch {
|
|
2290
2338
|
}
|
|
2291
2339
|
return false;
|
|
@@ -2297,12 +2345,12 @@ function finishTranscriptMove(oldCwd, newCwd, codeName, log2) {
|
|
|
2297
2345
|
let fromExists = false;
|
|
2298
2346
|
let toExists = false;
|
|
2299
2347
|
try {
|
|
2300
|
-
fromExists =
|
|
2348
|
+
fromExists = existsSync3(from);
|
|
2301
2349
|
} catch {
|
|
2302
2350
|
}
|
|
2303
2351
|
if (!fromExists) return;
|
|
2304
2352
|
try {
|
|
2305
|
-
toExists =
|
|
2353
|
+
toExists = existsSync3(to);
|
|
2306
2354
|
} catch {
|
|
2307
2355
|
}
|
|
2308
2356
|
if (toExists) {
|
|
@@ -2317,17 +2365,17 @@ function finishTranscriptMove(oldCwd, newCwd, codeName, log2) {
|
|
|
2317
2365
|
function maybeMigrateAgentToIdKeyedLayout(agent, deps) {
|
|
2318
2366
|
const home = deps.home ?? homedir3();
|
|
2319
2367
|
const { code_name: codeName, agent_id: agentId } = agent;
|
|
2320
|
-
const codeNamePath =
|
|
2321
|
-
const idPath =
|
|
2322
|
-
const oldCwd =
|
|
2323
|
-
const newCwd =
|
|
2368
|
+
const codeNamePath = join9(home, ".augmented", codeName);
|
|
2369
|
+
const idPath = join9(home, ".augmented", agentId);
|
|
2370
|
+
const oldCwd = join9(home, ".augmented", codeName, "project");
|
|
2371
|
+
const newCwd = join9(idPath, "project");
|
|
2324
2372
|
let codeNameKind;
|
|
2325
2373
|
try {
|
|
2326
2374
|
codeNameKind = lstatSync(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
2327
2375
|
} catch {
|
|
2328
2376
|
codeNameKind = "absent";
|
|
2329
2377
|
}
|
|
2330
|
-
const idExists =
|
|
2378
|
+
const idExists = existsSync3(idPath);
|
|
2331
2379
|
try {
|
|
2332
2380
|
if (codeNameKind === "symlink") {
|
|
2333
2381
|
const target = readlinkSync(codeNamePath);
|
|
@@ -2447,8 +2495,8 @@ function collectEnvGates(env) {
|
|
|
2447
2495
|
}
|
|
2448
2496
|
|
|
2449
2497
|
// ../../packages/core/dist/direct-chat/cursor-advance-telemetry.js
|
|
2450
|
-
import { readFileSync as
|
|
2451
|
-
import { join as
|
|
2498
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
2499
|
+
import { join as join10 } from "path";
|
|
2452
2500
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
2453
2501
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
2454
2502
|
if (!agentDir)
|
|
@@ -2456,10 +2504,10 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
2456
2504
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
2457
2505
|
if (key === null)
|
|
2458
2506
|
return;
|
|
2459
|
-
const path =
|
|
2507
|
+
const path = join10(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
2460
2508
|
const counts = {};
|
|
2461
2509
|
try {
|
|
2462
|
-
const parsed = JSON.parse(
|
|
2510
|
+
const parsed = JSON.parse(readFileSync9(path, "utf-8"));
|
|
2463
2511
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2464
2512
|
for (const [k, v] of Object.entries(parsed)) {
|
|
2465
2513
|
if (typeof v === "number" && Number.isInteger(v) && v >= 0)
|
|
@@ -2476,7 +2524,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
2476
2524
|
}
|
|
2477
2525
|
|
|
2478
2526
|
// src/lib/artifact-stream.ts
|
|
2479
|
-
import { join as
|
|
2527
|
+
import { join as join11 } from "path";
|
|
2480
2528
|
import { homedir as homedir4 } from "os";
|
|
2481
2529
|
import { readdir, stat, readFile } from "fs/promises";
|
|
2482
2530
|
var ARTEFACT_ENTRY_FILE = "index.html";
|
|
@@ -2562,7 +2610,7 @@ var ArtifactStreamScanner = class {
|
|
|
2562
2610
|
return;
|
|
2563
2611
|
}
|
|
2564
2612
|
for (const name of names) {
|
|
2565
|
-
const file =
|
|
2613
|
+
const file = join11(this.artifactsDir, name, ARTEFACT_ENTRY_FILE);
|
|
2566
2614
|
const mtime = await this.fsDeps.mtimeMs(file).catch(() => null);
|
|
2567
2615
|
if (mtime === null) continue;
|
|
2568
2616
|
if (this.seenMtime.get(name) === mtime) continue;
|
|
@@ -2593,7 +2641,7 @@ var ArtifactStreamScanner = class {
|
|
|
2593
2641
|
}
|
|
2594
2642
|
};
|
|
2595
2643
|
function artifactsDirFor(codeName) {
|
|
2596
|
-
return
|
|
2644
|
+
return join11(homedir4(), ".augmented", codeName, "artifacts");
|
|
2597
2645
|
}
|
|
2598
2646
|
var nodeArtifactFs = {
|
|
2599
2647
|
async listArtefactNames(artifactsDir) {
|
|
@@ -2861,12 +2909,12 @@ async function maybePollHostUsage(deps) {
|
|
|
2861
2909
|
import { createHash as createHash6 } from "crypto";
|
|
2862
2910
|
import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
|
|
2863
2911
|
import { homedir as homedir6, platform as platform2 } from "os";
|
|
2864
|
-
import { dirname as
|
|
2912
|
+
import { dirname as dirname6, join as join13 } from "path";
|
|
2865
2913
|
|
|
2866
2914
|
// src/lib/claude-auth-detect.ts
|
|
2867
2915
|
import { readFile as readFile2, readdir as readdir2 } from "fs/promises";
|
|
2868
2916
|
import { homedir as homedir5, platform } from "os";
|
|
2869
|
-
import { join as
|
|
2917
|
+
import { join as join12 } from "path";
|
|
2870
2918
|
import { execFile } from "child_process";
|
|
2871
2919
|
import { promisify } from "util";
|
|
2872
2920
|
var execFileAsync = promisify(execFile);
|
|
@@ -2881,16 +2929,16 @@ async function detectClaudeAuth() {
|
|
|
2881
2929
|
}
|
|
2882
2930
|
async function findClaudeCredentialsPaths() {
|
|
2883
2931
|
const candidates = [
|
|
2884
|
-
|
|
2885
|
-
|
|
2932
|
+
join12(homedir5(), ".claude", ".credentials.json"),
|
|
2933
|
+
join12(homedir5(), ".claude", "credentials.json")
|
|
2886
2934
|
];
|
|
2887
2935
|
const isLinuxRoot = platform() === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
2888
2936
|
if (isLinuxRoot) {
|
|
2889
2937
|
try {
|
|
2890
2938
|
const entries = await readdir2("/home", { withFileTypes: true });
|
|
2891
2939
|
for (const entry of entries.filter((entry2) => entry2.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2892
|
-
candidates.push(
|
|
2893
|
-
candidates.push(
|
|
2940
|
+
candidates.push(join12("/home", entry.name, ".claude", ".credentials.json"));
|
|
2941
|
+
candidates.push(join12("/home", entry.name, ".claude", "credentials.json"));
|
|
2894
2942
|
}
|
|
2895
2943
|
} catch {
|
|
2896
2944
|
}
|
|
@@ -2974,7 +3022,7 @@ async function candidateHomes() {
|
|
|
2974
3022
|
try {
|
|
2975
3023
|
const entries = await readdir3("/home", { withFileTypes: true });
|
|
2976
3024
|
for (const entry of entries.filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2977
|
-
homes.push(
|
|
3025
|
+
homes.push(join13("/home", entry.name));
|
|
2978
3026
|
}
|
|
2979
3027
|
} catch {
|
|
2980
3028
|
}
|
|
@@ -2985,7 +3033,7 @@ async function homeOfActiveCredentials() {
|
|
|
2985
3033
|
for (const path of await findClaudeCredentialsPaths()) {
|
|
2986
3034
|
try {
|
|
2987
3035
|
await readFile3(path, "utf-8");
|
|
2988
|
-
return
|
|
3036
|
+
return dirname6(dirname6(path));
|
|
2989
3037
|
} catch {
|
|
2990
3038
|
}
|
|
2991
3039
|
}
|
|
@@ -2994,11 +3042,11 @@ async function homeOfActiveCredentials() {
|
|
|
2994
3042
|
async function claudeConfigCandidatePaths() {
|
|
2995
3043
|
const paths = [];
|
|
2996
3044
|
const configDir = process.env["CLAUDE_CONFIG_DIR"]?.trim();
|
|
2997
|
-
if (configDir) paths.push(
|
|
3045
|
+
if (configDir) paths.push(join13(configDir, ".claude.json"));
|
|
2998
3046
|
const activeHome = await homeOfActiveCredentials();
|
|
2999
|
-
if (activeHome) paths.push(
|
|
3047
|
+
if (activeHome) paths.push(join13(activeHome, ".claude.json"));
|
|
3000
3048
|
for (const home of await candidateHomes()) {
|
|
3001
|
-
const path =
|
|
3049
|
+
const path = join13(home, ".claude.json");
|
|
3002
3050
|
if (!paths.includes(path)) paths.push(path);
|
|
3003
3051
|
}
|
|
3004
3052
|
return paths;
|
|
@@ -3115,11 +3163,11 @@ function diffAuthTuples(recorded, current) {
|
|
|
3115
3163
|
}
|
|
3116
3164
|
|
|
3117
3165
|
// src/lib/account-enforcement-marker.ts
|
|
3118
|
-
import { mkdirSync as
|
|
3166
|
+
import { mkdirSync as mkdirSync5, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
3119
3167
|
import { homedir as homedir7 } from "os";
|
|
3120
|
-
import { join as
|
|
3168
|
+
import { join as join14 } from "path";
|
|
3121
3169
|
function accountEnforcementMarkerPath(codeName) {
|
|
3122
|
-
return
|
|
3170
|
+
return join14(homedir7(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
3123
3171
|
}
|
|
3124
3172
|
function syncAccountEnforcementMarker(codeName, level, log2 = (m) => process.stderr.write(`${m}
|
|
3125
3173
|
`), text) {
|
|
@@ -3127,11 +3175,11 @@ function syncAccountEnforcementMarker(codeName, level, log2 = (m) => process.std
|
|
|
3127
3175
|
clearAccountEnforcementMarker(codeName, log2);
|
|
3128
3176
|
return;
|
|
3129
3177
|
}
|
|
3130
|
-
const dir =
|
|
3131
|
-
const path =
|
|
3178
|
+
const dir = join14(homedir7(), ".augmented", codeName);
|
|
3179
|
+
const path = join14(dir, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
3132
3180
|
const tempPath = `${path}.${process.pid}.tmp`;
|
|
3133
3181
|
try {
|
|
3134
|
-
|
|
3182
|
+
mkdirSync5(dir, { recursive: true });
|
|
3135
3183
|
writeFileSync6(tempPath, serializeAccountEnforcementMarker(level, text), "utf-8");
|
|
3136
3184
|
renameSync3(tempPath, path);
|
|
3137
3185
|
} catch (err) {
|
|
@@ -3153,8 +3201,8 @@ function clearAccountEnforcementMarker(codeName, log2 = (m) => process.stderr.wr
|
|
|
3153
3201
|
}
|
|
3154
3202
|
|
|
3155
3203
|
// src/lib/token-usage-monitor.ts
|
|
3156
|
-
import { readdirSync, readFileSync as
|
|
3157
|
-
import { join as
|
|
3204
|
+
import { readdirSync, readFileSync as readFileSync10, statSync } from "fs";
|
|
3205
|
+
import { join as join15 } from "path";
|
|
3158
3206
|
var MIN_CHECK_INTERVAL_MS2 = 6e4;
|
|
3159
3207
|
var TRANSCRIPT_MTIME_WINDOW_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
3160
3208
|
var MAX_ENTRIES_PER_POST = 200;
|
|
@@ -3183,7 +3231,7 @@ async function maybeReportTokenUsage(args) {
|
|
|
3183
3231
|
if (!name.endsWith(".jsonl")) continue;
|
|
3184
3232
|
const sessionId = name.slice(0, -".jsonl".length);
|
|
3185
3233
|
if (!sessionId) continue;
|
|
3186
|
-
const path =
|
|
3234
|
+
const path = join15(dir, name);
|
|
3187
3235
|
let st;
|
|
3188
3236
|
try {
|
|
3189
3237
|
st = statSync(path);
|
|
@@ -3199,7 +3247,7 @@ async function maybeReportTokenUsage(args) {
|
|
|
3199
3247
|
}
|
|
3200
3248
|
let content;
|
|
3201
3249
|
try {
|
|
3202
|
-
content =
|
|
3250
|
+
content = readFileSync10(path, "utf-8");
|
|
3203
3251
|
} catch (err) {
|
|
3204
3252
|
log2(`[token-usage] read failed for '${codeName}/${name}': ${err.message}`);
|
|
3205
3253
|
continue;
|
|
@@ -3280,8 +3328,8 @@ async function maybeReportTokenUsage(args) {
|
|
|
3280
3328
|
}
|
|
3281
3329
|
|
|
3282
3330
|
// src/lib/workflow-run-reconciler.ts
|
|
3283
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
3284
|
-
import { join as
|
|
3331
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync11, statSync as statSync2 } from "fs";
|
|
3332
|
+
import { join as join16 } from "path";
|
|
3285
3333
|
var MIN_CHECK_INTERVAL_MS3 = 5 * 6e4;
|
|
3286
3334
|
var SETTLE_MS = 3e4;
|
|
3287
3335
|
var TRANSCRIPT_MTIME_WINDOW_MS2 = 2 * 24 * 60 * 60 * 1e3;
|
|
@@ -3300,7 +3348,7 @@ function collectJsonlRecursive(dir, minMtimeMs, out, depth) {
|
|
|
3300
3348
|
return;
|
|
3301
3349
|
}
|
|
3302
3350
|
for (const name of entries) {
|
|
3303
|
-
const p =
|
|
3351
|
+
const p = join16(dir, name);
|
|
3304
3352
|
let st;
|
|
3305
3353
|
try {
|
|
3306
3354
|
st = statSync2(p);
|
|
@@ -3323,7 +3371,7 @@ function enumerateTranscriptFiles(transcriptDir, nowMs, minMtimeMs = nowMs - TRA
|
|
|
3323
3371
|
return out;
|
|
3324
3372
|
}
|
|
3325
3373
|
for (const name of entries) {
|
|
3326
|
-
const path =
|
|
3374
|
+
const path = join16(transcriptDir, name);
|
|
3327
3375
|
let st;
|
|
3328
3376
|
try {
|
|
3329
3377
|
st = statSync2(path);
|
|
@@ -3335,7 +3383,7 @@ function enumerateTranscriptFiles(transcriptDir, nowMs, minMtimeMs = nowMs - TRA
|
|
|
3335
3383
|
continue;
|
|
3336
3384
|
}
|
|
3337
3385
|
if (st.isDirectory()) {
|
|
3338
|
-
collectJsonlRecursive(
|
|
3386
|
+
collectJsonlRecursive(join16(path, "subagents"), minMtimeMs, out, 0);
|
|
3339
3387
|
}
|
|
3340
3388
|
}
|
|
3341
3389
|
return out;
|
|
@@ -3380,7 +3428,7 @@ async function maybeReconcileWorkflowRunTokens(args) {
|
|
|
3380
3428
|
const contents = [];
|
|
3381
3429
|
for (const path of files) {
|
|
3382
3430
|
try {
|
|
3383
|
-
contents.push(
|
|
3431
|
+
contents.push(readFileSync11(path, "utf-8"));
|
|
3384
3432
|
} catch {
|
|
3385
3433
|
}
|
|
3386
3434
|
}
|
|
@@ -3425,8 +3473,8 @@ async function maybeReconcileWorkflowRunTokens(args) {
|
|
|
3425
3473
|
}
|
|
3426
3474
|
|
|
3427
3475
|
// src/lib/conversation-evaluator.ts
|
|
3428
|
-
import { readdirSync as readdirSync3, readFileSync as
|
|
3429
|
-
import { join as
|
|
3476
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
|
|
3477
|
+
import { join as join17 } from "path";
|
|
3430
3478
|
var MIN_CHECK_INTERVAL_MS4 = 5 * 6e4;
|
|
3431
3479
|
var TRANSCRIPT_MTIME_WINDOW_MS3 = 7 * 24 * 60 * 60 * 1e3;
|
|
3432
3480
|
var WINDOW_PAD_MS = 5 * 6e4;
|
|
@@ -3862,7 +3910,7 @@ function readRecentTurns(dir, nowMs) {
|
|
|
3862
3910
|
return;
|
|
3863
3911
|
}
|
|
3864
3912
|
for (const ent of entries) {
|
|
3865
|
-
const full =
|
|
3913
|
+
const full = join17(d, ent.name);
|
|
3866
3914
|
if (ent.isDirectory()) {
|
|
3867
3915
|
visit(full);
|
|
3868
3916
|
continue;
|
|
@@ -3877,7 +3925,7 @@ function readRecentTurns(dir, nowMs) {
|
|
|
3877
3925
|
if (nowMs - mtimeMs > TRANSCRIPT_MTIME_WINDOW_MS3) continue;
|
|
3878
3926
|
let content;
|
|
3879
3927
|
try {
|
|
3880
|
-
content =
|
|
3928
|
+
content = readFileSync12(full, "utf8");
|
|
3881
3929
|
} catch {
|
|
3882
3930
|
continue;
|
|
3883
3931
|
}
|
|
@@ -4250,22 +4298,22 @@ async function reportSkip2(api2, agentId, conversationId, log2, codeName) {
|
|
|
4250
4298
|
|
|
4251
4299
|
// src/lib/tool-call-audit.ts
|
|
4252
4300
|
import { homedir as homedir11 } from "os";
|
|
4253
|
-
import { join as
|
|
4301
|
+
import { join as join22 } from "path";
|
|
4254
4302
|
|
|
4255
4303
|
// src/lib/agent-logging-mode.ts
|
|
4256
|
-
import { readFileSync as
|
|
4304
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
4257
4305
|
import { homedir as homedir8 } from "os";
|
|
4258
|
-
import { join as
|
|
4306
|
+
import { join as join18 } from "path";
|
|
4259
4307
|
var LOGGING_MODES = ["hash-only", "redacted", "full-local"];
|
|
4260
4308
|
function charterPath(codeName, homeDir) {
|
|
4261
4309
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir8());
|
|
4262
4310
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
4263
|
-
return
|
|
4311
|
+
return join18(home, ".augmented", key, "provision", "CHARTER.md");
|
|
4264
4312
|
}
|
|
4265
4313
|
function readAgentLoggingMode(codeName, homeDir) {
|
|
4266
4314
|
let raw;
|
|
4267
4315
|
try {
|
|
4268
|
-
raw =
|
|
4316
|
+
raw = readFileSync13(charterPath(codeName, homeDir), "utf-8");
|
|
4269
4317
|
} catch {
|
|
4270
4318
|
return { mode: null, reason: "no-charter" };
|
|
4271
4319
|
}
|
|
@@ -4289,15 +4337,15 @@ function loggingModeWithholdsTargets(reading) {
|
|
|
4289
4337
|
|
|
4290
4338
|
// src/lib/tool-call-path-salt.ts
|
|
4291
4339
|
import { randomBytes } from "crypto";
|
|
4292
|
-
import { existsSync as
|
|
4340
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync6, readFileSync as readFileSync14, renameSync as renameSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync7 } from "fs";
|
|
4293
4341
|
import { homedir as homedir9 } from "os";
|
|
4294
|
-
import { dirname as
|
|
4342
|
+
import { dirname as dirname7, join as join19 } from "path";
|
|
4295
4343
|
var SALT_BYTES = 32;
|
|
4296
4344
|
var SALT_RE = /^[0-9a-f]{64}$/;
|
|
4297
4345
|
function pathSaltPath(codeName, homeDir) {
|
|
4298
4346
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir9());
|
|
4299
4347
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
4300
|
-
return
|
|
4348
|
+
return join19(home, ".augmented", key, "tool-call-path-salt");
|
|
4301
4349
|
}
|
|
4302
4350
|
function readToolCallPathSalt(codeName, homeDir) {
|
|
4303
4351
|
let file;
|
|
@@ -4307,8 +4355,8 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
4307
4355
|
return null;
|
|
4308
4356
|
}
|
|
4309
4357
|
try {
|
|
4310
|
-
if (
|
|
4311
|
-
const existing =
|
|
4358
|
+
if (existsSync4(file)) {
|
|
4359
|
+
const existing = readFileSync14(file, "utf-8").trim();
|
|
4312
4360
|
if (SALT_RE.test(existing)) return existing;
|
|
4313
4361
|
}
|
|
4314
4362
|
} catch {
|
|
@@ -4316,7 +4364,7 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
4316
4364
|
const salt = randomBytes(SALT_BYTES).toString("hex");
|
|
4317
4365
|
const tmp = `${file}.tmp.${process.pid}`;
|
|
4318
4366
|
try {
|
|
4319
|
-
|
|
4367
|
+
mkdirSync6(dirname7(file), { recursive: true, mode: 448 });
|
|
4320
4368
|
writeFileSync7(tmp, `${salt}
|
|
4321
4369
|
`, { encoding: "utf-8", mode: 384 });
|
|
4322
4370
|
renameSync4(tmp, file);
|
|
@@ -4334,8 +4382,8 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
4334
4382
|
import { statSync as statSync4 } from "fs";
|
|
4335
4383
|
|
|
4336
4384
|
// src/lib/tool-call-extractor.ts
|
|
4337
|
-
import { closeSync, fstatSync, openSync, readFileSync as
|
|
4338
|
-
import { basename as basename2, join as
|
|
4385
|
+
import { closeSync, fstatSync, openSync, readFileSync as readFileSync15, readSync, readdirSync as readdirSync4 } from "fs";
|
|
4386
|
+
import { basename as basename2, join as join20, relative } from "path";
|
|
4339
4387
|
import { StringDecoder } from "string_decoder";
|
|
4340
4388
|
|
|
4341
4389
|
// src/lib/tool-call-redaction.ts
|
|
@@ -4464,7 +4512,7 @@ function redactToolTargetInner(toolName, input, ctx) {
|
|
|
4464
4512
|
var EXTRACTOR_VERSION = "e1";
|
|
4465
4513
|
function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
4466
4514
|
const files = [];
|
|
4467
|
-
const mainAbs =
|
|
4515
|
+
const mainAbs = join20(transcriptDir, `${sessionId}.jsonl`);
|
|
4468
4516
|
files.push({
|
|
4469
4517
|
absPath: mainAbs,
|
|
4470
4518
|
relPath: relative(projectsRoot, mainAbs),
|
|
@@ -4472,7 +4520,7 @@ function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
|
4472
4520
|
isSubagent: false,
|
|
4473
4521
|
subagentId: null
|
|
4474
4522
|
});
|
|
4475
|
-
const subDir =
|
|
4523
|
+
const subDir = join20(transcriptDir, sessionId, "subagents");
|
|
4476
4524
|
let entries;
|
|
4477
4525
|
try {
|
|
4478
4526
|
entries = readdirSync4(subDir);
|
|
@@ -4481,7 +4529,7 @@ function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
|
4481
4529
|
}
|
|
4482
4530
|
for (const name of entries) {
|
|
4483
4531
|
if (!name.endsWith(".jsonl")) continue;
|
|
4484
|
-
const abs =
|
|
4532
|
+
const abs = join20(subDir, name);
|
|
4485
4533
|
const stem = basename2(name, ".jsonl");
|
|
4486
4534
|
files.push({
|
|
4487
4535
|
absPath: abs,
|
|
@@ -4679,9 +4727,9 @@ function extractTranscriptWindow(file, opts, from) {
|
|
|
4679
4727
|
}
|
|
4680
4728
|
|
|
4681
4729
|
// src/lib/tool-call-cursor.ts
|
|
4682
|
-
import { existsSync as
|
|
4730
|
+
import { existsSync as existsSync5, readFileSync as readFileSync16 } from "fs";
|
|
4683
4731
|
import { homedir as homedir10 } from "os";
|
|
4684
|
-
import { join as
|
|
4732
|
+
import { join as join21 } from "path";
|
|
4685
4733
|
var COVERAGE_DISPOSITIONS = [
|
|
4686
4734
|
"ok",
|
|
4687
4735
|
"not_entitled",
|
|
@@ -4736,13 +4784,13 @@ function parseCursorKey(key) {
|
|
|
4736
4784
|
function cursorStatePath(codeName, homeDir) {
|
|
4737
4785
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir10());
|
|
4738
4786
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
4739
|
-
return
|
|
4787
|
+
return join21(home, ".augmented", key, "tool-call-cursors.json");
|
|
4740
4788
|
}
|
|
4741
4789
|
function loadCursors(path) {
|
|
4742
4790
|
const out = /* @__PURE__ */ new Map();
|
|
4743
|
-
if (!
|
|
4791
|
+
if (!existsSync5(path)) return out;
|
|
4744
4792
|
try {
|
|
4745
|
-
const parsed = JSON.parse(
|
|
4793
|
+
const parsed = JSON.parse(readFileSync16(path, "utf-8"));
|
|
4746
4794
|
if (!parsed || parsed.version !== 1 || typeof parsed.files !== "object") return out;
|
|
4747
4795
|
for (const [k, v] of Object.entries(parsed.files)) {
|
|
4748
4796
|
if (!v || typeof v !== "object") continue;
|
|
@@ -5149,7 +5197,7 @@ async function maybeScanToolCalls(args) {
|
|
|
5149
5197
|
log2(`[tool-call-audit] ${codeName}: no path-hash salt available \u2014 file targets withheld`);
|
|
5150
5198
|
}
|
|
5151
5199
|
const home = args.homeDir ?? (process.env["HOME"]?.trim() || homedir11());
|
|
5152
|
-
const projectsRoot = args.projectsRoot ??
|
|
5200
|
+
const projectsRoot = args.projectsRoot ?? join22(home, ".claude", "projects");
|
|
5153
5201
|
const transcriptDir = args.transcriptDir ?? sessionTranscriptDir(getProjectDir(codeName));
|
|
5154
5202
|
const current = peekCurrentSession(codeName);
|
|
5155
5203
|
const sessionIds = current ? [current.sessionId] : [];
|
|
@@ -5178,11 +5226,11 @@ async function maybeScanToolCalls(args) {
|
|
|
5178
5226
|
}
|
|
5179
5227
|
|
|
5180
5228
|
// src/lib/activity-cache-monitor.ts
|
|
5181
|
-
import { existsSync as
|
|
5229
|
+
import { existsSync as existsSync6, readFileSync as readFileSync17 } from "fs";
|
|
5182
5230
|
import { homedir as homedir12 } from "os";
|
|
5183
|
-
import { join as
|
|
5231
|
+
import { join as join23 } from "path";
|
|
5184
5232
|
var MIN_CHECK_INTERVAL_MS7 = 6e4;
|
|
5185
|
-
var STATS_CACHE_PATH =
|
|
5233
|
+
var STATS_CACHE_PATH = join23(homedir12(), ".claude", "stats-cache.json");
|
|
5186
5234
|
var ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
5187
5235
|
var state7 = { lastObservedDate: null, lastCheckedAt: 0 };
|
|
5188
5236
|
function selectNewDailyRows(raw, lastObservedDate) {
|
|
@@ -5225,12 +5273,12 @@ async function maybeReportActivityCache(args) {
|
|
|
5225
5273
|
const nowMs = now.getTime();
|
|
5226
5274
|
if (nowMs - state7.lastCheckedAt < MIN_CHECK_INTERVAL_MS7) return;
|
|
5227
5275
|
state7.lastCheckedAt = nowMs;
|
|
5228
|
-
if (!
|
|
5276
|
+
if (!existsSync6(STATS_CACHE_PATH)) {
|
|
5229
5277
|
return;
|
|
5230
5278
|
}
|
|
5231
5279
|
let raw;
|
|
5232
5280
|
try {
|
|
5233
|
-
raw =
|
|
5281
|
+
raw = readFileSync17(STATS_CACHE_PATH, "utf-8");
|
|
5234
5282
|
} catch (err) {
|
|
5235
5283
|
log2(`[activity-cache] readFileSync failed: ${err.message}`);
|
|
5236
5284
|
return;
|
|
@@ -5479,9 +5527,9 @@ function computeChannelConfigHash(input) {
|
|
|
5479
5527
|
// src/lib/knowledge-cache.ts
|
|
5480
5528
|
import { createHash as createHash9 } from "crypto";
|
|
5481
5529
|
import {
|
|
5482
|
-
existsSync as
|
|
5483
|
-
mkdirSync as
|
|
5484
|
-
readFileSync as
|
|
5530
|
+
existsSync as existsSync7,
|
|
5531
|
+
mkdirSync as mkdirSync7,
|
|
5532
|
+
readFileSync as readFileSync18,
|
|
5485
5533
|
readdirSync as readdirSync5,
|
|
5486
5534
|
renameSync as renameSync5,
|
|
5487
5535
|
rmSync as rmSync3,
|
|
@@ -5489,7 +5537,7 @@ import {
|
|
|
5489
5537
|
utimesSync,
|
|
5490
5538
|
writeFileSync as writeFileSync8
|
|
5491
5539
|
} from "fs";
|
|
5492
|
-
import { join as
|
|
5540
|
+
import { join as join24 } from "path";
|
|
5493
5541
|
var KNOWLEDGE_FETCH_CHUNK = 100;
|
|
5494
5542
|
var CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
5495
5543
|
var SWEEP_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -5498,12 +5546,12 @@ function knowledgeHash(content) {
|
|
|
5498
5546
|
return createHash9("sha256").update(content, "utf8").digest("hex");
|
|
5499
5547
|
}
|
|
5500
5548
|
function cachePath(cacheDir, hash) {
|
|
5501
|
-
return
|
|
5549
|
+
return join24(cacheDir, hash);
|
|
5502
5550
|
}
|
|
5503
5551
|
function readCachedKnowledge(cacheDir, hash) {
|
|
5504
5552
|
const path = cachePath(cacheDir, hash);
|
|
5505
5553
|
try {
|
|
5506
|
-
const content =
|
|
5554
|
+
const content = readFileSync18(path, "utf-8");
|
|
5507
5555
|
try {
|
|
5508
5556
|
const now = /* @__PURE__ */ new Date();
|
|
5509
5557
|
utimesSync(path, now, now);
|
|
@@ -5517,7 +5565,7 @@ function readCachedKnowledge(cacheDir, hash) {
|
|
|
5517
5565
|
function writeCachedKnowledge(cacheDir, hash, content) {
|
|
5518
5566
|
if (knowledgeHash(content) !== hash) return false;
|
|
5519
5567
|
try {
|
|
5520
|
-
|
|
5568
|
+
mkdirSync7(cacheDir, { recursive: true });
|
|
5521
5569
|
const tmp = `${cachePath(cacheDir, hash)}.tmp-${process.pid}`;
|
|
5522
5570
|
writeFileSync8(tmp, content, "utf-8");
|
|
5523
5571
|
renameSync5(tmp, cachePath(cacheDir, hash));
|
|
@@ -5530,9 +5578,9 @@ function sweepKnowledgeCache(cacheDir, now = Date.now()) {
|
|
|
5530
5578
|
if (now - lastSweepAt < SWEEP_INTERVAL_MS) return;
|
|
5531
5579
|
lastSweepAt = now;
|
|
5532
5580
|
try {
|
|
5533
|
-
if (!
|
|
5581
|
+
if (!existsSync7(cacheDir)) return;
|
|
5534
5582
|
for (const name of readdirSync5(cacheDir)) {
|
|
5535
|
-
const path =
|
|
5583
|
+
const path = join24(cacheDir, name);
|
|
5536
5584
|
try {
|
|
5537
5585
|
if (now - statSync5(path).mtimeMs > CACHE_TTL_MS) rmSync3(path, { force: true });
|
|
5538
5586
|
} catch {
|
|
@@ -5582,9 +5630,9 @@ async function resolveKnowledgeFromManifest(args) {
|
|
|
5582
5630
|
// src/lib/memory-cache.ts
|
|
5583
5631
|
import { createHash as createHash10 } from "crypto";
|
|
5584
5632
|
import {
|
|
5585
|
-
existsSync as
|
|
5586
|
-
mkdirSync as
|
|
5587
|
-
readFileSync as
|
|
5633
|
+
existsSync as existsSync8,
|
|
5634
|
+
mkdirSync as mkdirSync8,
|
|
5635
|
+
readFileSync as readFileSync19,
|
|
5588
5636
|
readdirSync as readdirSync6,
|
|
5589
5637
|
renameSync as renameSync6,
|
|
5590
5638
|
rmSync as rmSync4,
|
|
@@ -5592,7 +5640,7 @@ import {
|
|
|
5592
5640
|
utimesSync as utimesSync2,
|
|
5593
5641
|
writeFileSync as writeFileSync9
|
|
5594
5642
|
} from "fs";
|
|
5595
|
-
import { join as
|
|
5643
|
+
import { join as join25 } from "path";
|
|
5596
5644
|
var MEMORY_FETCH_CHUNK = 100;
|
|
5597
5645
|
var CACHE_TTL_MS2 = 30 * 24 * 60 * 60 * 1e3;
|
|
5598
5646
|
var SWEEP_INTERVAL_MS2 = 24 * 60 * 60 * 1e3;
|
|
@@ -5601,12 +5649,12 @@ function memoryHash(content) {
|
|
|
5601
5649
|
return createHash10("sha256").update(content, "utf8").digest("hex");
|
|
5602
5650
|
}
|
|
5603
5651
|
function cachePath2(cacheDir, hash) {
|
|
5604
|
-
return
|
|
5652
|
+
return join25(cacheDir, hash);
|
|
5605
5653
|
}
|
|
5606
5654
|
function readCachedMemory(cacheDir, hash) {
|
|
5607
5655
|
const path = cachePath2(cacheDir, hash);
|
|
5608
5656
|
try {
|
|
5609
|
-
const content =
|
|
5657
|
+
const content = readFileSync19(path, "utf-8");
|
|
5610
5658
|
try {
|
|
5611
5659
|
const now = /* @__PURE__ */ new Date();
|
|
5612
5660
|
utimesSync2(path, now, now);
|
|
@@ -5620,7 +5668,7 @@ function readCachedMemory(cacheDir, hash) {
|
|
|
5620
5668
|
function writeCachedMemory(cacheDir, hash, content) {
|
|
5621
5669
|
if (memoryHash(content) !== hash) return false;
|
|
5622
5670
|
try {
|
|
5623
|
-
|
|
5671
|
+
mkdirSync8(cacheDir, { recursive: true });
|
|
5624
5672
|
const tmp = `${cachePath2(cacheDir, hash)}.tmp-${process.pid}`;
|
|
5625
5673
|
writeFileSync9(tmp, content, "utf-8");
|
|
5626
5674
|
renameSync6(tmp, cachePath2(cacheDir, hash));
|
|
@@ -5633,9 +5681,9 @@ function sweepMemoryCache(cacheDir, now = Date.now()) {
|
|
|
5633
5681
|
if (now - (lastSweepAt2.get(cacheDir) ?? 0) < SWEEP_INTERVAL_MS2) return;
|
|
5634
5682
|
lastSweepAt2.set(cacheDir, now);
|
|
5635
5683
|
try {
|
|
5636
|
-
if (!
|
|
5684
|
+
if (!existsSync8(cacheDir)) return;
|
|
5637
5685
|
for (const name of readdirSync6(cacheDir)) {
|
|
5638
|
-
const path =
|
|
5686
|
+
const path = join25(cacheDir, name);
|
|
5639
5687
|
try {
|
|
5640
5688
|
if (now - statSync6(path).mtimeMs > CACHE_TTL_MS2) rmSync4(path, { force: true });
|
|
5641
5689
|
} catch {
|
|
@@ -5691,9 +5739,9 @@ async function resolveMemoriesFromManifest(args) {
|
|
|
5691
5739
|
// src/lib/skill-cache.ts
|
|
5692
5740
|
import { createHash as createHash11 } from "crypto";
|
|
5693
5741
|
import {
|
|
5694
|
-
existsSync as
|
|
5695
|
-
mkdirSync as
|
|
5696
|
-
readFileSync as
|
|
5742
|
+
existsSync as existsSync9,
|
|
5743
|
+
mkdirSync as mkdirSync9,
|
|
5744
|
+
readFileSync as readFileSync20,
|
|
5697
5745
|
readdirSync as readdirSync7,
|
|
5698
5746
|
renameSync as renameSync7,
|
|
5699
5747
|
rmSync as rmSync5,
|
|
@@ -5701,7 +5749,7 @@ import {
|
|
|
5701
5749
|
utimesSync as utimesSync3,
|
|
5702
5750
|
writeFileSync as writeFileSync10
|
|
5703
5751
|
} from "fs";
|
|
5704
|
-
import { join as
|
|
5752
|
+
import { join as join26 } from "path";
|
|
5705
5753
|
var SKILL_FETCH_CHUNK = 100;
|
|
5706
5754
|
var CACHE_TTL_MS3 = 30 * 24 * 60 * 60 * 1e3;
|
|
5707
5755
|
var SWEEP_INTERVAL_MS3 = 24 * 60 * 60 * 1e3;
|
|
@@ -5710,12 +5758,12 @@ function skillHash(content) {
|
|
|
5710
5758
|
return createHash11("sha256").update(content, "utf8").digest("hex");
|
|
5711
5759
|
}
|
|
5712
5760
|
function cachePath3(cacheDir, hash) {
|
|
5713
|
-
return
|
|
5761
|
+
return join26(cacheDir, hash);
|
|
5714
5762
|
}
|
|
5715
5763
|
function readCachedSkill(cacheDir, hash) {
|
|
5716
5764
|
const path = cachePath3(cacheDir, hash);
|
|
5717
5765
|
try {
|
|
5718
|
-
const content =
|
|
5766
|
+
const content = readFileSync20(path, "utf-8");
|
|
5719
5767
|
try {
|
|
5720
5768
|
const now = /* @__PURE__ */ new Date();
|
|
5721
5769
|
utimesSync3(path, now, now);
|
|
@@ -5729,7 +5777,7 @@ function readCachedSkill(cacheDir, hash) {
|
|
|
5729
5777
|
function writeCachedSkill(cacheDir, hash, content) {
|
|
5730
5778
|
if (skillHash(content) !== hash) return "mismatch";
|
|
5731
5779
|
try {
|
|
5732
|
-
|
|
5780
|
+
mkdirSync9(cacheDir, { recursive: true });
|
|
5733
5781
|
const tmp = `${cachePath3(cacheDir, hash)}.tmp-${process.pid}`;
|
|
5734
5782
|
writeFileSync10(tmp, content, "utf-8");
|
|
5735
5783
|
renameSync7(tmp, cachePath3(cacheDir, hash));
|
|
@@ -5742,9 +5790,9 @@ function sweepSkillCache(cacheDir, now = Date.now()) {
|
|
|
5742
5790
|
if (now - lastSweepAt3 < SWEEP_INTERVAL_MS3) return;
|
|
5743
5791
|
lastSweepAt3 = now;
|
|
5744
5792
|
try {
|
|
5745
|
-
if (!
|
|
5793
|
+
if (!existsSync9(cacheDir)) return;
|
|
5746
5794
|
for (const name of readdirSync7(cacheDir)) {
|
|
5747
|
-
const path =
|
|
5795
|
+
const path = join26(cacheDir, name);
|
|
5748
5796
|
try {
|
|
5749
5797
|
if (now - statSync7(path).mtimeMs > CACHE_TTL_MS3) rmSync5(path, { force: true });
|
|
5750
5798
|
} catch {
|
|
@@ -6031,18 +6079,18 @@ function resolveConditionalResponse(wire, hasCachedBody) {
|
|
|
6031
6079
|
}
|
|
6032
6080
|
|
|
6033
6081
|
// src/lib/channel-hash-cache.ts
|
|
6034
|
-
import { existsSync as
|
|
6035
|
-
import { join as
|
|
6082
|
+
import { existsSync as existsSync10, readFileSync as readFileSync21, writeFileSync as writeFileSync11 } from "fs";
|
|
6083
|
+
import { join as join27 } from "path";
|
|
6036
6084
|
var CACHE_FILENAME = "channel-hash-cache.json";
|
|
6037
6085
|
function getChannelHashCacheFile(configDir) {
|
|
6038
|
-
return
|
|
6086
|
+
return join27(configDir, CACHE_FILENAME);
|
|
6039
6087
|
}
|
|
6040
6088
|
function loadChannelHashCache(target, configDir) {
|
|
6041
6089
|
const path = getChannelHashCacheFile(configDir);
|
|
6042
|
-
if (!
|
|
6090
|
+
if (!existsSync10(path)) return;
|
|
6043
6091
|
let parsed;
|
|
6044
6092
|
try {
|
|
6045
|
-
parsed = JSON.parse(
|
|
6093
|
+
parsed = JSON.parse(readFileSync21(path, "utf-8"));
|
|
6046
6094
|
} catch {
|
|
6047
6095
|
return;
|
|
6048
6096
|
}
|
|
@@ -6062,8 +6110,8 @@ function saveChannelHashCache(source, configDir) {
|
|
|
6062
6110
|
}
|
|
6063
6111
|
|
|
6064
6112
|
// src/lib/sender-policy-baseline.ts
|
|
6065
|
-
import { existsSync as
|
|
6066
|
-
import { join as
|
|
6113
|
+
import { existsSync as existsSync11, readFileSync as readFileSync22 } from "fs";
|
|
6114
|
+
import { join as join28 } from "path";
|
|
6067
6115
|
var BASELINE_FILENAME = "sender-policy-baseline.json";
|
|
6068
6116
|
var SENDER_POLICY_BASELINE_VERSION = 1;
|
|
6069
6117
|
var BASELINE_CONCERNS = [
|
|
@@ -6101,14 +6149,14 @@ function createDeliveryBaselineMaps() {
|
|
|
6101
6149
|
};
|
|
6102
6150
|
}
|
|
6103
6151
|
function getSenderPolicyBaselineFile(configDir) {
|
|
6104
|
-
return
|
|
6152
|
+
return join28(configDir, BASELINE_FILENAME);
|
|
6105
6153
|
}
|
|
6106
6154
|
function loadSenderPolicyBaseline(target, configDir, log2) {
|
|
6107
6155
|
const path = getSenderPolicyBaselineFile(configDir);
|
|
6108
|
-
if (!
|
|
6156
|
+
if (!existsSync11(path)) return;
|
|
6109
6157
|
let parsed;
|
|
6110
6158
|
try {
|
|
6111
|
-
parsed = JSON.parse(
|
|
6159
|
+
parsed = JSON.parse(readFileSync22(path, "utf-8"));
|
|
6112
6160
|
} catch (err) {
|
|
6113
6161
|
log2?.(
|
|
6114
6162
|
`[sender-policy] discarding corrupt ${BASELINE_FILENAME} (${err.message}) - restrictive-policy agents will take one fail-closed restart`
|
|
@@ -6157,8 +6205,8 @@ function saveSenderPolicyBaseline(source, configDir, log2) {
|
|
|
6157
6205
|
}
|
|
6158
6206
|
|
|
6159
6207
|
// src/lib/stuck-streak-store.ts
|
|
6160
|
-
import { existsSync as
|
|
6161
|
-
import { join as
|
|
6208
|
+
import { existsSync as existsSync12, readFileSync as readFileSync23 } from "fs";
|
|
6209
|
+
import { join as join29 } from "path";
|
|
6162
6210
|
var STORE_FILENAME = "stuck-streaks.json";
|
|
6163
6211
|
var STUCK_STREAK_STORE_VERSION = 1;
|
|
6164
6212
|
var STUCK_STREAK_CONCERNS = ["channelSync", "realtimeRebind"];
|
|
@@ -6166,7 +6214,7 @@ function createStuckStreakMaps() {
|
|
|
6166
6214
|
return { channelSync: /* @__PURE__ */ new Map(), realtimeRebind: /* @__PURE__ */ new Map() };
|
|
6167
6215
|
}
|
|
6168
6216
|
function getStuckStreakStoreFile(configDir) {
|
|
6169
|
-
return
|
|
6217
|
+
return join29(configDir, STORE_FILENAME);
|
|
6170
6218
|
}
|
|
6171
6219
|
function isValidPersistedStreak(value) {
|
|
6172
6220
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -6205,10 +6253,10 @@ function buildStuckStreakPayload(source) {
|
|
|
6205
6253
|
}
|
|
6206
6254
|
function loadStuckStreaks(target, configDir, log2) {
|
|
6207
6255
|
const path = getStuckStreakStoreFile(configDir);
|
|
6208
|
-
if (!
|
|
6256
|
+
if (!existsSync12(path)) return;
|
|
6209
6257
|
let parsed;
|
|
6210
6258
|
try {
|
|
6211
|
-
parsed = JSON.parse(
|
|
6259
|
+
parsed = JSON.parse(readFileSync23(path, "utf-8"));
|
|
6212
6260
|
} catch (err) {
|
|
6213
6261
|
log2?.(
|
|
6214
6262
|
`[stuck-streaks] discarding corrupt ${STORE_FILENAME} (${err.message}) \u2014 stuck-streak ages restart from zero and one spurious "recovered" close may follow`
|
|
@@ -6818,7 +6866,7 @@ function planGlobalSkillSync(globalSkills, prevIds, hashOf, knownHash, options)
|
|
|
6818
6866
|
}
|
|
6819
6867
|
|
|
6820
6868
|
// src/lib/manager/integration-skill-cache.ts
|
|
6821
|
-
import { join as
|
|
6869
|
+
import { join as join30 } from "path";
|
|
6822
6870
|
function integrationSkillHashKey(agentId, skillId) {
|
|
6823
6871
|
return `plugin-skill:${agentId}:${skillId}`;
|
|
6824
6872
|
}
|
|
@@ -6834,21 +6882,21 @@ function forgetIntegrationSkill(cache2, agentId, skillId) {
|
|
|
6834
6882
|
function removeIntegrationSkillFolder(opts) {
|
|
6835
6883
|
forgetIntegrationSkill(opts.cache, opts.agentId, opts.entry);
|
|
6836
6884
|
for (const dir of opts.dirs) {
|
|
6837
|
-
opts.removeDir(
|
|
6885
|
+
opts.removeDir(join30(dir, opts.entry));
|
|
6838
6886
|
}
|
|
6839
6887
|
}
|
|
6840
6888
|
|
|
6841
6889
|
// src/lib/manager/managed-skill-manifest.ts
|
|
6842
|
-
import { existsSync as
|
|
6843
|
-
import { dirname as
|
|
6890
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "fs";
|
|
6891
|
+
import { dirname as dirname8, join as join31 } from "path";
|
|
6844
6892
|
var MANIFEST_VERSION = 1;
|
|
6845
6893
|
function managedSkillManifestPath(agentRootDir) {
|
|
6846
|
-
return
|
|
6894
|
+
return join31(agentRootDir, "managed-skills.json");
|
|
6847
6895
|
}
|
|
6848
6896
|
function readManagedSkillManifest(path) {
|
|
6849
6897
|
try {
|
|
6850
|
-
if (!
|
|
6851
|
-
const parsed = JSON.parse(
|
|
6898
|
+
if (!existsSync13(path)) return /* @__PURE__ */ new Set();
|
|
6899
|
+
const parsed = JSON.parse(readFileSync24(path, "utf-8"));
|
|
6852
6900
|
const ids = Array.isArray(parsed?.globalSkillIds) ? parsed.globalSkillIds : [];
|
|
6853
6901
|
return new Set(ids.filter((id) => typeof id === "string" && id.length > 0));
|
|
6854
6902
|
} catch {
|
|
@@ -6857,7 +6905,7 @@ function readManagedSkillManifest(path) {
|
|
|
6857
6905
|
}
|
|
6858
6906
|
function writeManagedSkillManifest(path, ids) {
|
|
6859
6907
|
try {
|
|
6860
|
-
|
|
6908
|
+
mkdirSync10(dirname8(path), { recursive: true });
|
|
6861
6909
|
const body = {
|
|
6862
6910
|
version: MANIFEST_VERSION,
|
|
6863
6911
|
globalSkillIds: [...ids].sort()
|
|
@@ -6977,8 +7025,8 @@ function resolveModelChain(refreshData) {
|
|
|
6977
7025
|
}
|
|
6978
7026
|
|
|
6979
7027
|
// src/lib/manager/claude-auth.ts
|
|
6980
|
-
import { existsSync as
|
|
6981
|
-
import { join as
|
|
7028
|
+
import { existsSync as existsSync14, rmSync as rmSync6 } from "fs";
|
|
7029
|
+
import { join as join32 } from "path";
|
|
6982
7030
|
import { homedir as homedir13 } from "os";
|
|
6983
7031
|
async function applyClaudeAuthToEnv(childEnv, label) {
|
|
6984
7032
|
const apiKey = getApiKey();
|
|
@@ -6991,10 +7039,10 @@ async function applyClaudeAuthToEnv(childEnv, label) {
|
|
|
6991
7039
|
throw new Error("claude_auth_mode=api_key but /host/exchange returned no decrypted key");
|
|
6992
7040
|
}
|
|
6993
7041
|
childEnv.ANTHROPIC_API_KEY = exchange.anthropicApiKey;
|
|
6994
|
-
const claudeDir =
|
|
7042
|
+
const claudeDir = join32(homedir13(), ".claude");
|
|
6995
7043
|
for (const filename of [".credentials.json", "credentials.json"]) {
|
|
6996
|
-
const p =
|
|
6997
|
-
if (
|
|
7044
|
+
const p = join32(claudeDir, filename);
|
|
7045
|
+
if (existsSync14(p)) {
|
|
6998
7046
|
try {
|
|
6999
7047
|
rmSync6(p, { force: true });
|
|
7000
7048
|
log(`[${label}] Removed ${p} (api_key mode \u2014 preventing OAuth fallback)`);
|
|
@@ -7075,8 +7123,8 @@ function heartbeatRuntimeAuthFields(probeVerdict) {
|
|
|
7075
7123
|
}
|
|
7076
7124
|
|
|
7077
7125
|
// src/lib/manager/kanban/parsers.ts
|
|
7078
|
-
import { existsSync as
|
|
7079
|
-
import { join as
|
|
7126
|
+
import { existsSync as existsSync15, readFileSync as readFileSync25 } from "fs";
|
|
7127
|
+
import { join as join33 } from "path";
|
|
7080
7128
|
var STANDUP_TEMPLATES = /* @__PURE__ */ new Set(["daily-standup", "end-of-day-summary"]);
|
|
7081
7129
|
var TASK_UPDATE_TEMPLATES = /* @__PURE__ */ new Set(["hourly-status", "task-update"]);
|
|
7082
7130
|
var PLAN_TEMPLATES = /* @__PURE__ */ new Set(["morning-plan"]);
|
|
@@ -7228,12 +7276,12 @@ function getBuiltInSkillContent(skillId) {
|
|
|
7228
7276
|
if (builtInSkillCache.has(skillId)) return builtInSkillCache.get(skillId);
|
|
7229
7277
|
try {
|
|
7230
7278
|
const candidates = [
|
|
7231
|
-
|
|
7232
|
-
|
|
7279
|
+
join33(process.cwd(), "skills", skillId, "SKILL.md"),
|
|
7280
|
+
join33(new URL(".", import.meta.url).pathname, "..", "..", "..", "..", "..", "..", "skills", skillId, "SKILL.md")
|
|
7233
7281
|
];
|
|
7234
7282
|
for (const candidate of candidates) {
|
|
7235
|
-
if (
|
|
7236
|
-
const content =
|
|
7283
|
+
if (existsSync15(candidate)) {
|
|
7284
|
+
const content = readFileSync25(candidate, "utf-8");
|
|
7237
7285
|
const files = [{ relativePath: "SKILL.md", content }];
|
|
7238
7286
|
builtInSkillCache.set(skillId, files);
|
|
7239
7287
|
return files;
|
|
@@ -7374,19 +7422,19 @@ function formatBoardForPrompt(items, template) {
|
|
|
7374
7422
|
}
|
|
7375
7423
|
|
|
7376
7424
|
// src/lib/manager/kanban/nudge-state-cache.ts
|
|
7377
|
-
import { existsSync as
|
|
7378
|
-
import { join as
|
|
7425
|
+
import { existsSync as existsSync16, readFileSync as readFileSync26, writeFileSync as writeFileSync13 } from "fs";
|
|
7426
|
+
import { join as join34 } from "path";
|
|
7379
7427
|
var CACHE_FILENAME2 = "kanban-nudge-state.json";
|
|
7380
7428
|
var KANBAN_NUDGE_STATE_VERSION = 1;
|
|
7381
7429
|
function getKanbanNudgeStateFile(configDir) {
|
|
7382
|
-
return
|
|
7430
|
+
return join34(configDir, CACHE_FILENAME2);
|
|
7383
7431
|
}
|
|
7384
7432
|
function loadKanbanNudgeState(target, configDir) {
|
|
7385
7433
|
const path = getKanbanNudgeStateFile(configDir);
|
|
7386
|
-
if (!
|
|
7434
|
+
if (!existsSync16(path)) return;
|
|
7387
7435
|
let parsed;
|
|
7388
7436
|
try {
|
|
7389
|
-
parsed = JSON.parse(
|
|
7437
|
+
parsed = JSON.parse(readFileSync26(path, "utf-8"));
|
|
7390
7438
|
} catch {
|
|
7391
7439
|
return;
|
|
7392
7440
|
}
|
|
@@ -8004,9 +8052,9 @@ function closeSessionRunForCode(codeName, outcome, reason) {
|
|
|
8004
8052
|
|
|
8005
8053
|
// src/lib/manager/scheduler/kanban-route.ts
|
|
8006
8054
|
import { createHash as createHash15 } from "crypto";
|
|
8007
|
-
import { writeFileSync as writeFileSync14, renameSync as renameSync8, mkdirSync as
|
|
8055
|
+
import { writeFileSync as writeFileSync14, renameSync as renameSync8, mkdirSync as mkdirSync11, readFileSync as readFileSync27, unlinkSync as unlinkSync3 } from "fs";
|
|
8008
8056
|
import { homedir as homedir14 } from "os";
|
|
8009
|
-
import { join as
|
|
8057
|
+
import { join as join35, dirname as dirname9 } from "path";
|
|
8010
8058
|
|
|
8011
8059
|
// src/lib/manager/scheduler/notify.ts
|
|
8012
8060
|
import { createHash as createHash14 } from "crypto";
|
|
@@ -8365,7 +8413,7 @@ function resolveScheduledSlackTarget(task) {
|
|
|
8365
8413
|
}
|
|
8366
8414
|
function stampScheduledTurnMarker(codeName, taskId, target) {
|
|
8367
8415
|
try {
|
|
8368
|
-
const file =
|
|
8416
|
+
const file = join35(homedir14(), ".augmented", codeName, SCHEDULED_TURN_MARKER_FILENAME);
|
|
8369
8417
|
const marker = { ts: Date.now(), task_id: taskId, ...target ? { target } : {} };
|
|
8370
8418
|
const tmp = `${file}.tmp`;
|
|
8371
8419
|
writeFileSync14(tmp, JSON.stringify(marker), "utf8");
|
|
@@ -8375,9 +8423,9 @@ function stampScheduledTurnMarker(codeName, taskId, target) {
|
|
|
8375
8423
|
}
|
|
8376
8424
|
}
|
|
8377
8425
|
function clearScheduledTurnMarkerForTask(codeName, taskId) {
|
|
8378
|
-
const file =
|
|
8426
|
+
const file = join35(homedir14(), ".augmented", codeName, SCHEDULED_TURN_MARKER_FILENAME);
|
|
8379
8427
|
try {
|
|
8380
|
-
const raw = JSON.parse(
|
|
8428
|
+
const raw = JSON.parse(readFileSync27(file, "utf8"));
|
|
8381
8429
|
if (typeof raw?.task_id !== "string" || raw.task_id !== taskId) return;
|
|
8382
8430
|
unlinkSync3(file);
|
|
8383
8431
|
log(`[scheduled-kanban] scheduled-turn marker cleared for '${codeName}' (task ${taskId} complete)`);
|
|
@@ -8438,7 +8486,7 @@ async function routeScheduledTaskViaKanban(codeName, agentId, task, prompt, dura
|
|
|
8438
8486
|
}
|
|
8439
8487
|
try {
|
|
8440
8488
|
const doorbell = directChatDoorbellPath(agentId, homedir14());
|
|
8441
|
-
|
|
8489
|
+
mkdirSync11(dirname9(doorbell), { recursive: true });
|
|
8442
8490
|
writeFileSync14(doorbell, String(Date.now()));
|
|
8443
8491
|
} catch (err) {
|
|
8444
8492
|
log(`[scheduled-kanban] doorbell ring failed for '${codeName}': ${err.message} (notice still queued)`);
|
|
@@ -8590,11 +8638,11 @@ async function processClaudeTaskResult(codeName, agentId, templateId, rawOutput,
|
|
|
8590
8638
|
// src/lib/manager/scheduler/execution.ts
|
|
8591
8639
|
import { createHash as createHash16 } from "crypto";
|
|
8592
8640
|
import { homedir as homedir15 } from "os";
|
|
8593
|
-
import { join as
|
|
8641
|
+
import { join as join37 } from "path";
|
|
8594
8642
|
|
|
8595
8643
|
// src/lib/agent-serving-probe.ts
|
|
8596
|
-
import { readFileSync as
|
|
8597
|
-
import { join as
|
|
8644
|
+
import { readFileSync as readFileSync28, readdirSync as readdirSync8, statSync as statSync8 } from "fs";
|
|
8645
|
+
import { join as join36 } from "path";
|
|
8598
8646
|
var RATE_LIMIT_WINDOW_MS = 6 * 60 * 60 * 1e3;
|
|
8599
8647
|
function probeRateLimit(args) {
|
|
8600
8648
|
const now = args.now ?? /* @__PURE__ */ new Date();
|
|
@@ -8610,7 +8658,7 @@ function probeRateLimit(args) {
|
|
|
8610
8658
|
let newest = UNKNOWN_RATE_LIMIT;
|
|
8611
8659
|
for (const name of entries) {
|
|
8612
8660
|
if (!name.endsWith(".jsonl")) continue;
|
|
8613
|
-
const path =
|
|
8661
|
+
const path = join36(dir, name);
|
|
8614
8662
|
try {
|
|
8615
8663
|
const st = statSync8(path);
|
|
8616
8664
|
if (!st.isFile() || st.mtimeMs < startMs) continue;
|
|
@@ -8619,7 +8667,7 @@ function probeRateLimit(args) {
|
|
|
8619
8667
|
}
|
|
8620
8668
|
let content;
|
|
8621
8669
|
try {
|
|
8622
|
-
content =
|
|
8670
|
+
content = readFileSync28(path, "utf-8");
|
|
8623
8671
|
} catch {
|
|
8624
8672
|
continue;
|
|
8625
8673
|
}
|
|
@@ -8681,7 +8729,7 @@ function shouldLogUsageCapDeferral(site, codeName, limitedUntil) {
|
|
|
8681
8729
|
|
|
8682
8730
|
// src/lib/manager/scheduler/execution.ts
|
|
8683
8731
|
function claudePidFilePath() {
|
|
8684
|
-
return
|
|
8732
|
+
return join37(homedir15(), ".augmented", "manager-claude-pids.json");
|
|
8685
8733
|
}
|
|
8686
8734
|
var inFlightClaudePids = /* @__PURE__ */ new Map();
|
|
8687
8735
|
function registerClaudeSpawn(record) {
|
|
@@ -8752,7 +8800,7 @@ async function syncAndCheckClaudeScheduler(agent, tasks, boardItems, refreshData
|
|
|
8752
8800
|
|
|
8753
8801
|
// src/lib/occupancy-gate.ts
|
|
8754
8802
|
import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync9, readSync as readSync2, statSync as statSync9 } from "fs";
|
|
8755
|
-
import { join as
|
|
8803
|
+
import { join as join38 } from "path";
|
|
8756
8804
|
function rostersMeasuredZero(mode, attested, runtimeRunning) {
|
|
8757
8805
|
return mode === "enforce" && attested && runtimeRunning;
|
|
8758
8806
|
}
|
|
@@ -8843,10 +8891,10 @@ function candidateTranscriptPaths(dir) {
|
|
|
8843
8891
|
let complete = true;
|
|
8844
8892
|
for (const name of top) {
|
|
8845
8893
|
if (name.endsWith(".jsonl")) {
|
|
8846
|
-
paths.push(
|
|
8894
|
+
paths.push(join38(dir, name));
|
|
8847
8895
|
continue;
|
|
8848
8896
|
}
|
|
8849
|
-
const subDir =
|
|
8897
|
+
const subDir = join38(dir, name, "subagents");
|
|
8850
8898
|
let subs;
|
|
8851
8899
|
try {
|
|
8852
8900
|
subs = readdirSync9(subDir);
|
|
@@ -8855,7 +8903,7 @@ function candidateTranscriptPaths(dir) {
|
|
|
8855
8903
|
continue;
|
|
8856
8904
|
}
|
|
8857
8905
|
for (const sub of subs) {
|
|
8858
|
-
if (sub.endsWith(".jsonl")) paths.push(
|
|
8906
|
+
if (sub.endsWith(".jsonl")) paths.push(join38(subDir, sub));
|
|
8859
8907
|
}
|
|
8860
8908
|
}
|
|
8861
8909
|
return { paths, complete };
|
|
@@ -9081,7 +9129,7 @@ function stopPaneOccupancySampler() {
|
|
|
9081
9129
|
}
|
|
9082
9130
|
|
|
9083
9131
|
// src/lib/pid-pressure-sampler.ts
|
|
9084
|
-
import { existsSync as
|
|
9132
|
+
import { existsSync as existsSync17, readFileSync as readFileSync29 } from "fs";
|
|
9085
9133
|
var SAMPLE_INTERVAL_MS2 = 3e4;
|
|
9086
9134
|
function warnFraction() {
|
|
9087
9135
|
const raw = Number(process.env.AGT_PID_PRESSURE_WARN_FRACTION);
|
|
@@ -9094,7 +9142,7 @@ function configuredCeiling() {
|
|
|
9094
9142
|
}
|
|
9095
9143
|
function readTextReal(path) {
|
|
9096
9144
|
try {
|
|
9097
|
-
return
|
|
9145
|
+
return readFileSync29(path, "utf-8");
|
|
9098
9146
|
} catch {
|
|
9099
9147
|
return null;
|
|
9100
9148
|
}
|
|
@@ -9103,7 +9151,7 @@ var cgroupDirCache = /* @__PURE__ */ new Map();
|
|
|
9103
9151
|
var resolveRetryAfter = /* @__PURE__ */ new Map();
|
|
9104
9152
|
var RESOLVE_RETRY_BACKOFF_MS = 5 * 6e4;
|
|
9105
9153
|
function resolveCgroupDirReal(codeName, deps = {}) {
|
|
9106
|
-
const exists = deps.exists ??
|
|
9154
|
+
const exists = deps.exists ?? existsSync17;
|
|
9107
9155
|
const inspectId = deps.inspectId ?? inspectContainerId;
|
|
9108
9156
|
const now = deps.now ?? Date.now;
|
|
9109
9157
|
const cached = cgroupDirCache.get(codeName);
|
|
@@ -10400,9 +10448,9 @@ async function fireOpencodeScheduledTask(agent, task) {
|
|
|
10400
10448
|
|
|
10401
10449
|
// src/lib/opencode-telegram-ingest.ts
|
|
10402
10450
|
import { createHash as createHash19 } from "crypto";
|
|
10403
|
-
import { existsSync as
|
|
10451
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync12, readFileSync as readFileSync30, renameSync as renameSync9, unlinkSync as unlinkSync4, writeFileSync as writeFileSync15 } from "fs";
|
|
10404
10452
|
import { randomUUID } from "crypto";
|
|
10405
|
-
import { join as
|
|
10453
|
+
import { join as join39 } from "path";
|
|
10406
10454
|
|
|
10407
10455
|
// src/lib/telegram-ingest.ts
|
|
10408
10456
|
import https2 from "https";
|
|
@@ -10959,7 +11007,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
10959
11007
|
let filePath;
|
|
10960
11008
|
try {
|
|
10961
11009
|
dir = getFramework("opencode").getAgentDir(codeName);
|
|
10962
|
-
filePath =
|
|
11010
|
+
filePath = join39(dir, "telegram-getupdates-offset-opencode.json");
|
|
10963
11011
|
} catch {
|
|
10964
11012
|
dir = null;
|
|
10965
11013
|
filePath = null;
|
|
@@ -10968,7 +11016,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
10968
11016
|
load() {
|
|
10969
11017
|
if (!filePath) return 0;
|
|
10970
11018
|
try {
|
|
10971
|
-
const parsed = JSON.parse(
|
|
11019
|
+
const parsed = JSON.parse(readFileSync30(filePath, "utf-8"));
|
|
10972
11020
|
if (currentBotId != null && typeof parsed?.bot_id === "number" && parsed.bot_id !== currentBotId) {
|
|
10973
11021
|
log2(`[telegram-ingest:${codeName}] offset cursor belongs to a different bot; ignoring (bot swap)`);
|
|
10974
11022
|
return 0;
|
|
@@ -10986,7 +11034,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
10986
11034
|
if (!filePath || !dir) return;
|
|
10987
11035
|
const tmpPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
10988
11036
|
try {
|
|
10989
|
-
|
|
11037
|
+
mkdirSync12(dir, { recursive: true, mode: 448 });
|
|
10990
11038
|
writeFileSync15(
|
|
10991
11039
|
tmpPath,
|
|
10992
11040
|
JSON.stringify({
|
|
@@ -11001,7 +11049,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
11001
11049
|
} catch (err) {
|
|
11002
11050
|
log2(`[telegram-ingest:${codeName}] offset persist failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
11003
11051
|
try {
|
|
11004
|
-
if (
|
|
11052
|
+
if (existsSync18(tmpPath)) unlinkSync4(tmpPath);
|
|
11005
11053
|
} catch {
|
|
11006
11054
|
}
|
|
11007
11055
|
}
|
|
@@ -11238,24 +11286,24 @@ function partitionActionableByPoison(actionable, states, config2) {
|
|
|
11238
11286
|
}
|
|
11239
11287
|
|
|
11240
11288
|
// src/lib/restart-flags.ts
|
|
11241
|
-
import { existsSync as
|
|
11289
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync13, readdirSync as readdirSync10, readFileSync as readFileSync31, renameSync as renameSync10, rmSync as rmSync7, writeFileSync as writeFileSync16 } from "fs";
|
|
11242
11290
|
import { homedir as homedir16 } from "os";
|
|
11243
|
-
import { join as
|
|
11291
|
+
import { join as join40 } from "path";
|
|
11244
11292
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
11245
11293
|
function restartFlagsDir() {
|
|
11246
|
-
return
|
|
11294
|
+
return join40(homedir16(), ".augmented", "restart-flags");
|
|
11247
11295
|
}
|
|
11248
11296
|
function flagPath(codeName) {
|
|
11249
|
-
return
|
|
11297
|
+
return join40(restartFlagsDir(), `${codeName}.flag`);
|
|
11250
11298
|
}
|
|
11251
11299
|
function readRestartFlags() {
|
|
11252
11300
|
const dir = restartFlagsDir();
|
|
11253
|
-
if (!
|
|
11301
|
+
if (!existsSync19(dir)) return [];
|
|
11254
11302
|
const out = [];
|
|
11255
11303
|
for (const entry of readdirSync10(dir)) {
|
|
11256
11304
|
if (!entry.endsWith(".flag")) continue;
|
|
11257
11305
|
try {
|
|
11258
|
-
const raw =
|
|
11306
|
+
const raw = readFileSync31(join40(dir, entry), "utf8");
|
|
11259
11307
|
const parsed = JSON.parse(raw);
|
|
11260
11308
|
if (typeof parsed.codeName !== "string" || parsed.codeName.length === 0) {
|
|
11261
11309
|
parsed.codeName = entry.replace(/\.flag$/, "");
|
|
@@ -11273,7 +11321,7 @@ function readRestartFlags() {
|
|
|
11273
11321
|
}
|
|
11274
11322
|
function deleteRestartFlag(codeName) {
|
|
11275
11323
|
const path = flagPath(codeName);
|
|
11276
|
-
if (
|
|
11324
|
+
if (existsSync19(path)) {
|
|
11277
11325
|
rmSync7(path, { force: true });
|
|
11278
11326
|
}
|
|
11279
11327
|
}
|
|
@@ -11373,8 +11421,8 @@ async function sendError(flag, opts, text) {
|
|
|
11373
11421
|
}
|
|
11374
11422
|
|
|
11375
11423
|
// src/lib/restart-context.ts
|
|
11376
|
-
import { readdirSync as readdirSync11, readFileSync as
|
|
11377
|
-
import { dirname as
|
|
11424
|
+
import { readdirSync as readdirSync11, readFileSync as readFileSync32, writeFileSync as writeFileSync17, mkdirSync as mkdirSync14, unlinkSync as unlinkSync5 } from "fs";
|
|
11425
|
+
import { dirname as dirname10, join as join41 } from "path";
|
|
11378
11426
|
var SLACK_PENDING_INBOUND_DIRNAME = "slack-pending-inbound";
|
|
11379
11427
|
var SLACK_RESTART_CONTEXT_DIRNAME = "slack-restart-context";
|
|
11380
11428
|
var MAX_TOPIC_CHARS = 140;
|
|
@@ -11383,13 +11431,13 @@ var RECONSTRUCT_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
|
11383
11431
|
var WINDOW_PAD_MS3 = 5 * 6e4;
|
|
11384
11432
|
var DEFAULT_MAX_MARKERS_PER_AGENT = 25;
|
|
11385
11433
|
function augmentedAgentDir(codeName) {
|
|
11386
|
-
return
|
|
11434
|
+
return dirname10(getProjectDir(codeName));
|
|
11387
11435
|
}
|
|
11388
11436
|
function slackPendingInboundDir(codeName) {
|
|
11389
|
-
return
|
|
11437
|
+
return join41(augmentedAgentDir(codeName), SLACK_PENDING_INBOUND_DIRNAME);
|
|
11390
11438
|
}
|
|
11391
11439
|
function slackRestartContextDir(codeName) {
|
|
11392
|
-
return
|
|
11440
|
+
return join41(augmentedAgentDir(codeName), SLACK_RESTART_CONTEXT_DIRNAME);
|
|
11393
11441
|
}
|
|
11394
11442
|
function sanitizeTopic(raw) {
|
|
11395
11443
|
const cleaned = raw.replace(/\s+/g, " ").trim().replace(/[<>]/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -11431,7 +11479,7 @@ function safeReaddir(dir) {
|
|
|
11431
11479
|
}
|
|
11432
11480
|
function readStrandedMarker(path) {
|
|
11433
11481
|
try {
|
|
11434
|
-
const parsed = JSON.parse(
|
|
11482
|
+
const parsed = JSON.parse(readFileSync32(path, "utf-8"));
|
|
11435
11483
|
if (typeof parsed.channel === "string" && typeof parsed.thread_ts === "string") {
|
|
11436
11484
|
return { channel: parsed.channel, thread_ts: parsed.thread_ts };
|
|
11437
11485
|
}
|
|
@@ -11440,7 +11488,7 @@ function readStrandedMarker(path) {
|
|
|
11440
11488
|
return null;
|
|
11441
11489
|
}
|
|
11442
11490
|
function writeHintFile(path, dir, hint) {
|
|
11443
|
-
|
|
11491
|
+
mkdirSync14(dir, { recursive: true, mode: 448 });
|
|
11444
11492
|
writeFileSync17(path, JSON.stringify(hint), { mode: 384 });
|
|
11445
11493
|
}
|
|
11446
11494
|
function pruneHintsExcept(codeName, freshFilenames) {
|
|
@@ -11449,7 +11497,7 @@ function pruneHintsExcept(codeName, freshFilenames) {
|
|
|
11449
11497
|
if (!filename.endsWith(".json")) continue;
|
|
11450
11498
|
if (freshFilenames.has(filename)) continue;
|
|
11451
11499
|
try {
|
|
11452
|
-
unlinkSync5(
|
|
11500
|
+
unlinkSync5(join41(ctxDir, filename));
|
|
11453
11501
|
} catch {
|
|
11454
11502
|
}
|
|
11455
11503
|
}
|
|
@@ -11470,7 +11518,7 @@ function refreshSlackRestartContextHints(codeNames, opts = {}) {
|
|
|
11470
11518
|
}
|
|
11471
11519
|
const markers = [];
|
|
11472
11520
|
for (const filename of markerFilenames.slice(0, cap)) {
|
|
11473
|
-
const parsed = readStrandedMarker(
|
|
11521
|
+
const parsed = readStrandedMarker(join41(markerDir, filename));
|
|
11474
11522
|
if (parsed) markers.push({ filename, channel: parsed.channel, thread_ts: parsed.thread_ts });
|
|
11475
11523
|
}
|
|
11476
11524
|
if (markers.length === 0) {
|
|
@@ -11484,7 +11532,7 @@ function refreshSlackRestartContextHints(codeNames, opts = {}) {
|
|
|
11484
11532
|
const freshFilenames = /* @__PURE__ */ new Set();
|
|
11485
11533
|
for (const { filename, hint } of hints) {
|
|
11486
11534
|
try {
|
|
11487
|
-
writeHintFile(
|
|
11535
|
+
writeHintFile(join41(ctxDir, filename), ctxDir, hint);
|
|
11488
11536
|
freshFilenames.add(filename);
|
|
11489
11537
|
} catch (err) {
|
|
11490
11538
|
log2(`[restart-context] ${codeName}: hint write failed for ${filename}: ${err.message}`);
|
|
@@ -12954,7 +13002,7 @@ var dayRolloverInboundHold = /* @__PURE__ */ new Map();
|
|
|
12954
13002
|
var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
|
|
12955
13003
|
async function channelInboundActivityAgeSecondsFor(codeName) {
|
|
12956
13004
|
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-OBQCSEFT.js");
|
|
12957
|
-
const newest = newestPendingInboundActivityMtimeMs(
|
|
13005
|
+
const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
|
|
12958
13006
|
if (newest === null) return null;
|
|
12959
13007
|
return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
|
|
12960
13008
|
}
|
|
@@ -13203,7 +13251,7 @@ var runningChannelSecretHashes = /* @__PURE__ */ new Map();
|
|
|
13203
13251
|
var sessionLaunchManagedStructure = /* @__PURE__ */ new Map();
|
|
13204
13252
|
function projectMcpHash(_codeName, projectDir) {
|
|
13205
13253
|
try {
|
|
13206
|
-
const raw =
|
|
13254
|
+
const raw = readFileSync33(join42(projectDir, ".mcp.json"), "utf-8");
|
|
13207
13255
|
return createHash20("sha256").update(canonicalJson(JSON.parse(raw))).digest("hex");
|
|
13208
13256
|
} catch {
|
|
13209
13257
|
return null;
|
|
@@ -13211,7 +13259,7 @@ function projectMcpHash(_codeName, projectDir) {
|
|
|
13211
13259
|
}
|
|
13212
13260
|
function projectMcpKeys(_codeName, projectDir) {
|
|
13213
13261
|
try {
|
|
13214
|
-
const raw =
|
|
13262
|
+
const raw = readFileSync33(join42(projectDir, ".mcp.json"), "utf-8");
|
|
13215
13263
|
const parsed = JSON.parse(raw);
|
|
13216
13264
|
const servers = parsed.mcpServers;
|
|
13217
13265
|
if (!servers || typeof servers !== "object") return /* @__PURE__ */ new Set();
|
|
@@ -13229,7 +13277,7 @@ function seedSessionLaunchBaselines(codeName, projectDir) {
|
|
|
13229
13277
|
else runningMcpServerKeys.delete(codeName);
|
|
13230
13278
|
let launchStructure = null;
|
|
13231
13279
|
try {
|
|
13232
|
-
const raw =
|
|
13280
|
+
const raw = readFileSync33(join42(projectDir, ".mcp.json"), "utf-8");
|
|
13233
13281
|
launchStructure = managedMcpStructureHashFromFile(
|
|
13234
13282
|
JSON.parse(raw),
|
|
13235
13283
|
isManagedMcpServerKey
|
|
@@ -13364,7 +13412,7 @@ async function runAgentSessionToolBindProbes(agent, integrations, projectDir, op
|
|
|
13364
13412
|
if (result && result.rebindCandidates.length > 0 && hostFlagStore().getBoolean("session-tool-rebind")) {
|
|
13365
13413
|
let mcpJsonForRebind = null;
|
|
13366
13414
|
try {
|
|
13367
|
-
mcpJsonForRebind = JSON.parse(
|
|
13415
|
+
mcpJsonForRebind = JSON.parse(readFileSync33(join42(projectDir, ".mcp.json"), "utf-8"));
|
|
13368
13416
|
} catch {
|
|
13369
13417
|
mcpJsonForRebind = null;
|
|
13370
13418
|
}
|
|
@@ -13512,7 +13560,7 @@ function shouldInjectChannelSecrets(agentId) {
|
|
|
13512
13560
|
function projectChannelSecretHash(projectDir) {
|
|
13513
13561
|
try {
|
|
13514
13562
|
const entries = parseEnvIntegrations(
|
|
13515
|
-
|
|
13563
|
+
readFileSync33(join42(projectDir, ".env.integrations"), "utf-8")
|
|
13516
13564
|
);
|
|
13517
13565
|
return channelSecretValueHash(entries, CHANNEL_SECRET_ENV_KEYS);
|
|
13518
13566
|
} catch {
|
|
@@ -13621,7 +13669,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
13621
13669
|
var lastVersionCheckAt = 0;
|
|
13622
13670
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
13623
13671
|
var lastResponsivenessProbeAt = 0;
|
|
13624
|
-
var agtCliVersion = true ? "0.28.
|
|
13672
|
+
var agtCliVersion = true ? "0.28.835" : "dev";
|
|
13625
13673
|
function resolveBrewPath(execFileSync2) {
|
|
13626
13674
|
try {
|
|
13627
13675
|
const out = execFileSync2("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -13634,7 +13682,7 @@ function resolveBrewPath(execFileSync2) {
|
|
|
13634
13682
|
"/usr/local/bin/brew"
|
|
13635
13683
|
];
|
|
13636
13684
|
for (const path of fallbacks) {
|
|
13637
|
-
if (
|
|
13685
|
+
if (existsSync20(path)) return path;
|
|
13638
13686
|
}
|
|
13639
13687
|
return null;
|
|
13640
13688
|
}
|
|
@@ -13644,7 +13692,7 @@ function claudeBinaryInstalled(execFileSync2) {
|
|
|
13644
13692
|
"/opt/homebrew/bin/claude",
|
|
13645
13693
|
"/usr/local/bin/claude"
|
|
13646
13694
|
];
|
|
13647
|
-
if (canonical.some((path) =>
|
|
13695
|
+
if (canonical.some((path) => existsSync20(path))) return true;
|
|
13648
13696
|
try {
|
|
13649
13697
|
execFileSync2("which", ["claude"], { timeout: 5e3 });
|
|
13650
13698
|
return true;
|
|
@@ -13716,7 +13764,7 @@ async function ensureToolkitCli(toolkitSlug) {
|
|
|
13716
13764
|
toolkitCliEnsured.add(toolkitSlug);
|
|
13717
13765
|
return;
|
|
13718
13766
|
}
|
|
13719
|
-
brewBinDir =
|
|
13767
|
+
brewBinDir = dirname11(brewPath);
|
|
13720
13768
|
const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
13721
13769
|
log(`[toolkit-install] ${toolkitSlug}: installing via brew (${pkg})\u2026`);
|
|
13722
13770
|
if (isRoot) {
|
|
@@ -13954,8 +14002,8 @@ var MANAGED_SETTINGS_KEYS = ["channelsEnabled", "enableAllProjectMcpServers"];
|
|
|
13954
14002
|
function ensureClaudeManagedSettings(path = claudeManagedSettingsPath()) {
|
|
13955
14003
|
try {
|
|
13956
14004
|
let settings = {};
|
|
13957
|
-
if (
|
|
13958
|
-
const raw =
|
|
14005
|
+
if (existsSync20(path)) {
|
|
14006
|
+
const raw = readFileSync33(path, "utf-8").trim();
|
|
13959
14007
|
if (raw) {
|
|
13960
14008
|
let parsed;
|
|
13961
14009
|
try {
|
|
@@ -13972,7 +14020,7 @@ function ensureClaudeManagedSettings(path = claudeManagedSettingsPath()) {
|
|
|
13972
14020
|
const missing = MANAGED_SETTINGS_KEYS.filter((key) => settings[key] !== true);
|
|
13973
14021
|
if (missing.length === 0) return "ok";
|
|
13974
14022
|
for (const key of missing) settings[key] = true;
|
|
13975
|
-
|
|
14023
|
+
mkdirSync15(dirname11(path), { recursive: true });
|
|
13976
14024
|
writeFileSync18(path, `${JSON.stringify(settings, null, 2)}
|
|
13977
14025
|
`);
|
|
13978
14026
|
log(`[managed-settings] set ${missing.map((k) => `${k}:true`).join(", ")} in ${path} (ENG-5786 unblocks Claude Code channels; ENG-9223 pre-approves project MCP servers so a headless session never freezes on the trust prompt)`);
|
|
@@ -14011,7 +14059,7 @@ async function ensureOpencodeBinary() {
|
|
|
14011
14059
|
try {
|
|
14012
14060
|
const prefix = execFileSync2("npm", ["prefix", "-g"], { encoding: "utf-8", timeout: 1e4 }).trim();
|
|
14013
14061
|
if (prefix) {
|
|
14014
|
-
const npmBin =
|
|
14062
|
+
const npmBin = join42(prefix, "bin");
|
|
14015
14063
|
const current = (process.env.PATH ?? "").split(pathDelimiter);
|
|
14016
14064
|
if (!current.includes(npmBin)) {
|
|
14017
14065
|
process.env.PATH = [npmBin, ...current.filter(Boolean)].join(pathDelimiter);
|
|
@@ -14068,11 +14116,11 @@ async function ensureFrameworkBinary(frameworkId) {
|
|
|
14068
14116
|
log(`Claude Code install failed: ${err.message}`);
|
|
14069
14117
|
return;
|
|
14070
14118
|
}
|
|
14071
|
-
const brewBinDir =
|
|
14119
|
+
const brewBinDir = dirname11(brewPath);
|
|
14072
14120
|
if (!process.env.PATH?.split(":").includes(brewBinDir)) {
|
|
14073
14121
|
process.env.PATH = `${brewBinDir}:${process.env.PATH ?? ""}`;
|
|
14074
14122
|
}
|
|
14075
|
-
if (
|
|
14123
|
+
if (existsSync20("/home/linuxbrew/.linuxbrew/bin/claude")) {
|
|
14076
14124
|
log("Claude Code installed successfully");
|
|
14077
14125
|
} else {
|
|
14078
14126
|
log("Claude Code install completed but binary not found at expected path \u2014 check brew logs");
|
|
@@ -14151,7 +14199,7 @@ async function maybeUpgradeClaudeCode() {
|
|
|
14151
14199
|
}
|
|
14152
14200
|
var UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
14153
14201
|
function selfUpdateAppliedMarkerPath() {
|
|
14154
|
-
return
|
|
14202
|
+
return join42(homedir17(), ".augmented", ".last-self-update-applied");
|
|
14155
14203
|
}
|
|
14156
14204
|
var selfUpdateUpToDateLogged = false;
|
|
14157
14205
|
var selfUpdatePinnedLogged = false;
|
|
@@ -14202,7 +14250,7 @@ async function checkAndUpdateCli(opts) {
|
|
|
14202
14250
|
const isNpmGlobal = !isBrewFormula && resolvedPath.includes("node_modules");
|
|
14203
14251
|
if (!isBrewFormula && !isNpmGlobal) return "noop";
|
|
14204
14252
|
const { readFileSync: readF, writeFileSync: writeF } = await import("fs");
|
|
14205
|
-
const markerPath =
|
|
14253
|
+
const markerPath = join42(homedir17(), ".augmented", ".last-update-check");
|
|
14206
14254
|
if (!force) {
|
|
14207
14255
|
try {
|
|
14208
14256
|
const lastCheck = parseInt(readF(markerPath, "utf-8").trim(), 10);
|
|
@@ -14695,13 +14743,13 @@ async function checkClaudeAuth() {
|
|
|
14695
14743
|
}
|
|
14696
14744
|
var evalEmptyMcpConfigPath = null;
|
|
14697
14745
|
function ensureEvalEmptyMcpConfig() {
|
|
14698
|
-
if (evalEmptyMcpConfigPath &&
|
|
14699
|
-
const dir =
|
|
14746
|
+
if (evalEmptyMcpConfigPath && existsSync20(evalEmptyMcpConfigPath)) return evalEmptyMcpConfigPath;
|
|
14747
|
+
const dir = join42(homedir17(), ".augmented");
|
|
14700
14748
|
try {
|
|
14701
|
-
|
|
14749
|
+
mkdirSync15(dir, { recursive: true });
|
|
14702
14750
|
} catch {
|
|
14703
14751
|
}
|
|
14704
|
-
const p =
|
|
14752
|
+
const p = join42(dir, ".eval-empty-mcp.json");
|
|
14705
14753
|
writeFileSync18(p, JSON.stringify({ mcpServers: {} }));
|
|
14706
14754
|
evalEmptyMcpConfigPath = p;
|
|
14707
14755
|
return p;
|
|
@@ -14796,10 +14844,10 @@ function resolveConversationEvalBackend() {
|
|
|
14796
14844
|
return conversationEvalBackend;
|
|
14797
14845
|
}
|
|
14798
14846
|
function getStateFile() {
|
|
14799
|
-
return
|
|
14847
|
+
return join42(config?.configDir ?? join42(process.env["HOME"] ?? "/tmp", ".augmented"), "manager-state.json");
|
|
14800
14848
|
}
|
|
14801
14849
|
function channelHashCacheDir() {
|
|
14802
|
-
return config?.configDir ??
|
|
14850
|
+
return config?.configDir ?? join42(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
14803
14851
|
}
|
|
14804
14852
|
function loadChannelHashCache2() {
|
|
14805
14853
|
loadChannelHashCache(agentState.knownChannelConfigHashes, channelHashCacheDir());
|
|
@@ -15012,7 +15060,7 @@ function removeDeliveryBaselineEntries(agentId) {
|
|
|
15012
15060
|
var _channelQuarantineStore = null;
|
|
15013
15061
|
function channelQuarantineStore() {
|
|
15014
15062
|
if (!_channelQuarantineStore) {
|
|
15015
|
-
const dir = config?.configDir ??
|
|
15063
|
+
const dir = config?.configDir ?? join42(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
15016
15064
|
_channelQuarantineStore = new ChannelQuarantineStore(defaultQuarantinePath(dir));
|
|
15017
15065
|
}
|
|
15018
15066
|
return _channelQuarantineStore;
|
|
@@ -15028,12 +15076,12 @@ function claudeMdSizeFor(codeName) {
|
|
|
15028
15076
|
}
|
|
15029
15077
|
function forwardedToolsFor(codeName) {
|
|
15030
15078
|
if (!config?.configDir) return null;
|
|
15031
|
-
return readForwardedToolsReport(
|
|
15079
|
+
return readForwardedToolsReport(join42(config.configDir, codeName));
|
|
15032
15080
|
}
|
|
15033
15081
|
var _hostFlagStore = null;
|
|
15034
15082
|
function hostFlagStore() {
|
|
15035
15083
|
if (!_hostFlagStore) {
|
|
15036
|
-
const dir = config?.configDir ??
|
|
15084
|
+
const dir = config?.configDir ?? join42(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
15037
15085
|
_hostFlagStore = new HostFlagStore({ cachePath: defaultFlagsCachePath(dir), log });
|
|
15038
15086
|
}
|
|
15039
15087
|
return _hostFlagStore;
|
|
@@ -15107,12 +15155,12 @@ function parseSkillFrontmatter(content) {
|
|
|
15107
15155
|
}
|
|
15108
15156
|
async function refreshSkillsIndexInClaudeMd(configDir, codeName, log2) {
|
|
15109
15157
|
const { readdirSync: readdirSync13, readFileSync: rfs, existsSync: ex, writeFileSync: writeFileSync19 } = await import("fs");
|
|
15110
|
-
const skillsDir =
|
|
15111
|
-
const claudeMdPath =
|
|
15158
|
+
const skillsDir = join42(configDir, codeName, "project", ".claude", "skills");
|
|
15159
|
+
const claudeMdPath = join42(configDir, codeName, "project", "CLAUDE.md");
|
|
15112
15160
|
if (!ex(skillsDir) || !ex(claudeMdPath)) return;
|
|
15113
15161
|
const entries = [];
|
|
15114
15162
|
for (const dir of readdirSync13(skillsDir).sort()) {
|
|
15115
|
-
const skillFile =
|
|
15163
|
+
const skillFile = join42(skillsDir, dir, "SKILL.md");
|
|
15116
15164
|
if (!ex(skillFile)) continue;
|
|
15117
15165
|
try {
|
|
15118
15166
|
const { name, description } = parseSkillFrontmatter(rfs(skillFile, "utf-8"));
|
|
@@ -15728,13 +15776,13 @@ async function pollCycleInner() {
|
|
|
15728
15776
|
);
|
|
15729
15777
|
if (hostFlagStore().getBoolean("wedge-transient-notice")) {
|
|
15730
15778
|
try {
|
|
15731
|
-
const paneTail =
|
|
15779
|
+
const paneTail = readFileSync33(paneLogPath(codeName), "utf8").slice(-65536);
|
|
15732
15780
|
const transient = detectTransientApiErrorInLog(paneTail);
|
|
15733
15781
|
if (transient) {
|
|
15734
|
-
const wedgeHome =
|
|
15735
|
-
if (
|
|
15782
|
+
const wedgeHome = join42(homedir17(), ".augmented", codeName);
|
|
15783
|
+
if (existsSync20(wedgeHome)) {
|
|
15736
15784
|
atomicWriteFileSync(
|
|
15737
|
-
|
|
15785
|
+
join42(wedgeHome, "watchdog-give-up.json"),
|
|
15738
15786
|
JSON.stringify({
|
|
15739
15787
|
gave_up_at: wedgeNow.toISOString(),
|
|
15740
15788
|
reason: "transient_overload"
|
|
@@ -16064,7 +16112,7 @@ async function pollCycleInner() {
|
|
|
16064
16112
|
`[drain-flush] FAILED for '${prev.codeName}': ${err.message} \u2014 proceeding to teardown; this session was NOT shipped (ENG-9491)`
|
|
16065
16113
|
);
|
|
16066
16114
|
}
|
|
16067
|
-
const agentDir =
|
|
16115
|
+
const agentDir = join42(adapter.getAgentDir(prev.codeName), "provision");
|
|
16068
16116
|
await cleanupAgentFiles(prev.codeName, agentDir);
|
|
16069
16117
|
clearAgentCaches(prev.agentId, prev.codeName);
|
|
16070
16118
|
}
|
|
@@ -16151,10 +16199,10 @@ async function pollCycleInner() {
|
|
|
16151
16199
|
// pending-inbound marker. Best-effort: a write failure is logged by
|
|
16152
16200
|
// the watchdog, never fails the poll cycle.
|
|
16153
16201
|
signalGiveUp: (codeName) => {
|
|
16154
|
-
const dir =
|
|
16155
|
-
if (!
|
|
16202
|
+
const dir = join42(homedir17(), ".augmented", codeName);
|
|
16203
|
+
if (!existsSync20(dir)) return;
|
|
16156
16204
|
atomicWriteFileSync(
|
|
16157
|
-
|
|
16205
|
+
join42(dir, "watchdog-give-up.json"),
|
|
16158
16206
|
JSON.stringify({ gave_up_at: (/* @__PURE__ */ new Date()).toISOString() })
|
|
16159
16207
|
);
|
|
16160
16208
|
},
|
|
@@ -16173,9 +16221,9 @@ async function pollCycleInner() {
|
|
|
16173
16221
|
// parser elsewhere can only reconstruct an hour (ENG-8901).
|
|
16174
16222
|
signalUsageLimit: (codeName, resetsHint) => {
|
|
16175
16223
|
const dir = getFramework("claude-code").getAgentDir(codeName);
|
|
16176
|
-
if (!
|
|
16224
|
+
if (!existsSync20(dir)) return;
|
|
16177
16225
|
atomicWriteFileSync(
|
|
16178
|
-
|
|
16226
|
+
join42(dir, "watchdog-give-up.json"),
|
|
16179
16227
|
JSON.stringify({
|
|
16180
16228
|
gave_up_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16181
16229
|
reason: "usage_limit",
|
|
@@ -16443,7 +16491,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16443
16491
|
}
|
|
16444
16492
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
16445
16493
|
const adapter = resolveAgentFramework(agent.code_name);
|
|
16446
|
-
let agentDir =
|
|
16494
|
+
let agentDir = join42(adapter.getAgentDir(agent.code_name), "provision");
|
|
16447
16495
|
if (agent.status === "draft" || agent.status === "paused") {
|
|
16448
16496
|
forgetChannelSyncState(agent.agent_id);
|
|
16449
16497
|
if (previousKnownStatus !== agent.status) {
|
|
@@ -16484,7 +16532,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16484
16532
|
const residuals = {
|
|
16485
16533
|
gatewayRunning: false,
|
|
16486
16534
|
portAllocated: false,
|
|
16487
|
-
provisionDirExists:
|
|
16535
|
+
provisionDirExists: existsSync20(agentDir)
|
|
16488
16536
|
};
|
|
16489
16537
|
if (!hasRevokedResiduals(residuals)) {
|
|
16490
16538
|
agentStates.push({
|
|
@@ -16590,7 +16638,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16590
16638
|
if (refreshData.knowledge_manifest) {
|
|
16591
16639
|
const resolved = await resolveKnowledgeFromManifest({
|
|
16592
16640
|
manifest: refreshData.knowledge_manifest,
|
|
16593
|
-
cacheDir:
|
|
16641
|
+
cacheDir: join42(config.configDir, "_knowledge"),
|
|
16594
16642
|
delivery: refreshData.agent?.knowledge_delivery ?? "both",
|
|
16595
16643
|
fetchContents: async (hashes) => {
|
|
16596
16644
|
const res = await api.post(
|
|
@@ -16607,7 +16655,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16607
16655
|
const resolvedSkills = await resolveSkillsFromManifest({
|
|
16608
16656
|
globals: refreshData.global_skills_manifest ?? [],
|
|
16609
16657
|
shared: refreshData.shared_skills_manifest ?? [],
|
|
16610
|
-
cacheDir:
|
|
16658
|
+
cacheDir: join42(config.configDir, "_skills"),
|
|
16611
16659
|
fetchContents: async (hashes) => {
|
|
16612
16660
|
const res = await api.post(
|
|
16613
16661
|
"/host/skills/contents",
|
|
@@ -16625,7 +16673,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16625
16673
|
if (refreshData.integration_skills_manifest) {
|
|
16626
16674
|
const resolvedIntegrationSkills = await resolveIntegrationSkillsFromManifest({
|
|
16627
16675
|
manifest: refreshData.integration_skills_manifest,
|
|
16628
|
-
cacheDir:
|
|
16676
|
+
cacheDir: join42(config.configDir, "_skills"),
|
|
16629
16677
|
fetchContents: async (hashes) => {
|
|
16630
16678
|
const res = await api.post(
|
|
16631
16679
|
"/host/skills/contents",
|
|
@@ -16687,7 +16735,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16687
16735
|
const frameworkId = refreshData.agent.framework ?? DEFAULT_FRAMEWORK;
|
|
16688
16736
|
agentFrameworkCache.set(agent.code_name, frameworkId);
|
|
16689
16737
|
const frameworkAdapter = getFramework(frameworkId);
|
|
16690
|
-
agentDir =
|
|
16738
|
+
agentDir = join42(frameworkAdapter.getAgentDir(agent.code_name), "provision");
|
|
16691
16739
|
cacheAgentDeliveryMetadata(agent.code_name, refreshData);
|
|
16692
16740
|
agentRestartTimezoneInputs.set(agent.code_name, {
|
|
16693
16741
|
agentTimezone: typeof refreshData.agent.timezone === "string" ? refreshData.agent.timezone : null,
|
|
@@ -16744,9 +16792,9 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16744
16792
|
try {
|
|
16745
16793
|
const artifacts = generateArtifacts(agent, refreshData, frameworkAdapter, renderIntegrationsSection);
|
|
16746
16794
|
const changedFiles = [];
|
|
16747
|
-
|
|
16795
|
+
mkdirSync15(agentDir, { recursive: true });
|
|
16748
16796
|
for (const artifact of artifacts) {
|
|
16749
|
-
const filePath =
|
|
16797
|
+
const filePath = join42(agentDir, artifact.relativePath);
|
|
16750
16798
|
let existingHash;
|
|
16751
16799
|
let newHash;
|
|
16752
16800
|
let writeContent = artifact.content;
|
|
@@ -16765,8 +16813,8 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16765
16813
|
};
|
|
16766
16814
|
newHash = sha256(stripDynamicSections(artifact.content));
|
|
16767
16815
|
try {
|
|
16768
|
-
const projectClaudeMd =
|
|
16769
|
-
const existing =
|
|
16816
|
+
const projectClaudeMd = join42(config.configDir, agent.code_name, "project", "CLAUDE.md");
|
|
16817
|
+
const existing = readFileSync33(projectClaudeMd, "utf-8");
|
|
16770
16818
|
existingHash = sha256(stripDynamicSections(existing));
|
|
16771
16819
|
} catch {
|
|
16772
16820
|
existingHash = null;
|
|
@@ -16784,7 +16832,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16784
16832
|
const generatorKeys = Object.keys(generatorServers);
|
|
16785
16833
|
let existingRaw = "";
|
|
16786
16834
|
try {
|
|
16787
|
-
existingRaw =
|
|
16835
|
+
existingRaw = readFileSync33(filePath, "utf-8");
|
|
16788
16836
|
} catch {
|
|
16789
16837
|
}
|
|
16790
16838
|
const existingServers = parseMcp(existingRaw);
|
|
@@ -16800,7 +16848,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16800
16848
|
} else if (artifact.relativePath === "opencode.json") {
|
|
16801
16849
|
let existingRaw = null;
|
|
16802
16850
|
try {
|
|
16803
|
-
existingRaw =
|
|
16851
|
+
existingRaw = readFileSync33(filePath, "utf-8");
|
|
16804
16852
|
} catch {
|
|
16805
16853
|
}
|
|
16806
16854
|
const mergeResult = mergeOpencodeConfigArtifact(artifact.content, existingRaw);
|
|
@@ -16816,13 +16864,13 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16816
16864
|
}
|
|
16817
16865
|
}
|
|
16818
16866
|
if (changedFiles.length > 0) {
|
|
16819
|
-
const isFirst = !
|
|
16867
|
+
const isFirst = !existsSync20(join42(agentDir, "CHARTER.md"));
|
|
16820
16868
|
const verb = isFirst ? "Provisioning" : "Updating";
|
|
16821
16869
|
const fileNames = changedFiles.map((f) => f.relativePath).join(", ");
|
|
16822
16870
|
log(`${verb} '${agent.code_name}': ${fileNames}`);
|
|
16823
16871
|
for (const file of changedFiles) {
|
|
16824
|
-
const filePath =
|
|
16825
|
-
|
|
16872
|
+
const filePath = join42(agentDir, file.relativePath);
|
|
16873
|
+
mkdirSync15(dirname11(filePath), { recursive: true });
|
|
16826
16874
|
if (file.relativePath === ".mcp.json") {
|
|
16827
16875
|
safeWriteJsonAtomic(filePath, file.content, { mode: 384 });
|
|
16828
16876
|
} else {
|
|
@@ -16830,12 +16878,12 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16830
16878
|
}
|
|
16831
16879
|
}
|
|
16832
16880
|
try {
|
|
16833
|
-
const provSkillsDir =
|
|
16834
|
-
if (
|
|
16881
|
+
const provSkillsDir = join42(agentDir, ".claude", "skills");
|
|
16882
|
+
if (existsSync20(provSkillsDir)) {
|
|
16835
16883
|
for (const folder of readdirSync12(provSkillsDir)) {
|
|
16836
16884
|
if (folder.startsWith("knowledge-")) {
|
|
16837
16885
|
try {
|
|
16838
|
-
rmSync8(
|
|
16886
|
+
rmSync8(join42(provSkillsDir, folder), { recursive: true });
|
|
16839
16887
|
} catch {
|
|
16840
16888
|
}
|
|
16841
16889
|
}
|
|
@@ -16848,7 +16896,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16848
16896
|
const trackedFiles2 = frameworkAdapter.driftTrackedFiles();
|
|
16849
16897
|
const hashes = /* @__PURE__ */ new Map();
|
|
16850
16898
|
for (const file of trackedFiles2) {
|
|
16851
|
-
const h = hashFile(
|
|
16899
|
+
const h = hashFile(join42(agentDir, file));
|
|
16852
16900
|
if (h) hashes.set(file, h);
|
|
16853
16901
|
}
|
|
16854
16902
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -16866,14 +16914,14 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16866
16914
|
}
|
|
16867
16915
|
if (Array.isArray(refreshData.workflows)) {
|
|
16868
16916
|
try {
|
|
16869
|
-
const provWorkflowsDir =
|
|
16870
|
-
if (
|
|
16917
|
+
const provWorkflowsDir = join42(agentDir, ".claude", "workflows");
|
|
16918
|
+
if (existsSync20(provWorkflowsDir)) {
|
|
16871
16919
|
const expected = new Set(refreshData.workflows.map((w) => `${w.name}.js`));
|
|
16872
16920
|
for (const file of readdirSync12(provWorkflowsDir)) {
|
|
16873
16921
|
if (!file.endsWith(".js")) continue;
|
|
16874
16922
|
if (expected.has(file)) continue;
|
|
16875
16923
|
try {
|
|
16876
|
-
rmSync8(
|
|
16924
|
+
rmSync8(join42(provWorkflowsDir, file));
|
|
16877
16925
|
} catch {
|
|
16878
16926
|
}
|
|
16879
16927
|
}
|
|
@@ -16952,10 +17000,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16952
17000
|
}
|
|
16953
17001
|
let lastDriftCheckAt = now;
|
|
16954
17002
|
const written = agentState.writtenHashes.get(agent.agent_id);
|
|
16955
|
-
if (written &&
|
|
17003
|
+
if (written && existsSync20(agentDir)) {
|
|
16956
17004
|
const driftedFiles = [];
|
|
16957
17005
|
for (const [file, expectedHash] of written) {
|
|
16958
|
-
const localHash = hashFile(
|
|
17006
|
+
const localHash = hashFile(join42(agentDir, file));
|
|
16959
17007
|
if (localHash && localHash !== expectedHash) {
|
|
16960
17008
|
driftedFiles.push(file);
|
|
16961
17009
|
}
|
|
@@ -16966,7 +17014,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
16966
17014
|
try {
|
|
16967
17015
|
const localHashes = {};
|
|
16968
17016
|
for (const file of driftedFiles) {
|
|
16969
|
-
localHashes[file] = hashFile(
|
|
17017
|
+
localHashes[file] = hashFile(join42(agentDir, file));
|
|
16970
17018
|
}
|
|
16971
17019
|
await api.post("/host/drift", {
|
|
16972
17020
|
agent_id: agent.agent_id,
|
|
@@ -17244,15 +17292,15 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17244
17292
|
const addedChannels = [...restartDecision.added];
|
|
17245
17293
|
const writeDmNoticeMarkers = isChannelAddRestart ? () => {
|
|
17246
17294
|
try {
|
|
17247
|
-
const agentAugmentedDir =
|
|
17248
|
-
|
|
17295
|
+
const agentAugmentedDir = join42(homedir17(), ".augmented", agent.code_name);
|
|
17296
|
+
mkdirSync15(agentAugmentedDir, { recursive: true });
|
|
17249
17297
|
const markerJson = JSON.stringify({
|
|
17250
17298
|
version: 1,
|
|
17251
17299
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17252
17300
|
added: addedChannels
|
|
17253
17301
|
});
|
|
17254
17302
|
for (const file of ["slack-channel-add-restart.json", "telegram-channel-add-restart.json"]) {
|
|
17255
|
-
atomicWriteFileSync(
|
|
17303
|
+
atomicWriteFileSync(join42(agentAugmentedDir, file), markerJson);
|
|
17256
17304
|
}
|
|
17257
17305
|
} catch (err) {
|
|
17258
17306
|
log(`[hot-reload] channel-add DM-notice marker write failed for '${agent.code_name}' (non-fatal): ${err.message}`);
|
|
@@ -17551,24 +17599,24 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17551
17599
|
if (agentSessionMode === "persistent" && (agentFrameworkCache.get(agent.code_name) ?? DEFAULT_FRAMEWORK) === "claude-code") {
|
|
17552
17600
|
try {
|
|
17553
17601
|
const agentProvisionDir = agentDir;
|
|
17554
|
-
const projectDir =
|
|
17555
|
-
|
|
17556
|
-
|
|
17557
|
-
const provisionMcpPath =
|
|
17558
|
-
const projectMcpPath =
|
|
17602
|
+
const projectDir = join42(homedir17(), ".augmented", agent.code_name, "project");
|
|
17603
|
+
mkdirSync15(agentProvisionDir, { recursive: true });
|
|
17604
|
+
mkdirSync15(projectDir, { recursive: true });
|
|
17605
|
+
const provisionMcpPath = join42(agentProvisionDir, ".mcp.json");
|
|
17606
|
+
const projectMcpPath = join42(projectDir, ".mcp.json");
|
|
17559
17607
|
let mcpConfig = { mcpServers: {} };
|
|
17560
17608
|
try {
|
|
17561
|
-
mcpConfig = JSON.parse(
|
|
17609
|
+
mcpConfig = JSON.parse(readFileSync33(provisionMcpPath, "utf-8"));
|
|
17562
17610
|
if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
|
|
17563
17611
|
} catch {
|
|
17564
17612
|
}
|
|
17565
|
-
const localDirectChatChannel =
|
|
17613
|
+
const localDirectChatChannel = join42(homedir17(), ".augmented", "_mcp", "direct-chat-channel.js");
|
|
17566
17614
|
const directChatTeamSettings = refreshData.team?.settings;
|
|
17567
17615
|
const directChatTz = (() => {
|
|
17568
17616
|
const tz = directChatTeamSettings?.["timezone"];
|
|
17569
17617
|
return typeof tz === "string" && tz.trim() !== "" ? tz.trim() : void 0;
|
|
17570
17618
|
})();
|
|
17571
|
-
if (
|
|
17619
|
+
if (existsSync20(localDirectChatChannel)) {
|
|
17572
17620
|
const directChatEnv = {
|
|
17573
17621
|
AGT_HOST: requireHost(),
|
|
17574
17622
|
// ENG-5901 Track D: templated — the manager exports the real
|
|
@@ -17588,7 +17636,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17588
17636
|
// ~/.augmented/<codeName>/.current-turn-initiator.json. Note getAgentDir
|
|
17589
17637
|
// returns the agent root (NOT the /provision subdir `agentDir` points at),
|
|
17590
17638
|
// so it byte-matches the broker readers' path.
|
|
17591
|
-
AGT_TURN_INITIATOR_FILE:
|
|
17639
|
+
AGT_TURN_INITIATOR_FILE: join42(
|
|
17592
17640
|
frameworkAdapter.getAgentDir(agent.code_name),
|
|
17593
17641
|
".current-turn-initiator.json"
|
|
17594
17642
|
)
|
|
@@ -17608,8 +17656,8 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17608
17656
|
log(`Channel credentials written for '${agent.code_name}/direct-chat'`);
|
|
17609
17657
|
}
|
|
17610
17658
|
}
|
|
17611
|
-
const staleChannelsPath =
|
|
17612
|
-
if (
|
|
17659
|
+
const staleChannelsPath = join42(projectDir, ".mcp-channels.json");
|
|
17660
|
+
if (existsSync20(staleChannelsPath)) {
|
|
17613
17661
|
try {
|
|
17614
17662
|
rmSync8(staleChannelsPath, { force: true });
|
|
17615
17663
|
} catch {
|
|
@@ -17721,7 +17769,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17721
17769
|
}
|
|
17722
17770
|
if (hostFlagStore().getBoolean("connectivity-probe")) {
|
|
17723
17771
|
try {
|
|
17724
|
-
const probeProjectDir =
|
|
17772
|
+
const probeProjectDir = join42(homedir17(), ".augmented", agent.code_name, "project");
|
|
17725
17773
|
let probeSet = integrations;
|
|
17726
17774
|
const fetchQuarantined = async () => {
|
|
17727
17775
|
const quarantined = await api.post("/host/agent-integrations/quarantined", { agent_id: agent.agent_id });
|
|
@@ -17781,7 +17829,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17781
17829
|
const forceDue = attemptsLeft > 0;
|
|
17782
17830
|
let probeRan = false;
|
|
17783
17831
|
try {
|
|
17784
|
-
const probeProjectDir =
|
|
17832
|
+
const probeProjectDir = join42(homedir17(), ".augmented", agent.code_name, "project");
|
|
17785
17833
|
probeRan = await runAgentSessionToolBindProbes(agent, integrations, probeProjectDir, { forceDue });
|
|
17786
17834
|
} catch (err) {
|
|
17787
17835
|
log(`Session-tool-bind probe failed for '${agent.code_name}': ${err.message}`);
|
|
@@ -17858,11 +17906,11 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17858
17906
|
const intHash = computeIntegrationsHash(integrations);
|
|
17859
17907
|
const prevIntHash = agentState.knownIntegrationHashes.get(agent.agent_id);
|
|
17860
17908
|
if (intHash !== prevIntHash) {
|
|
17861
|
-
const projectDir =
|
|
17862
|
-
const envIntPath =
|
|
17909
|
+
const projectDir = join42(homedir17(), ".augmented", agent.code_name, "project");
|
|
17910
|
+
const envIntPath = join42(projectDir, ".env.integrations");
|
|
17863
17911
|
let preWriteEnv;
|
|
17864
17912
|
try {
|
|
17865
|
-
preWriteEnv =
|
|
17913
|
+
preWriteEnv = readFileSync33(envIntPath, "utf-8");
|
|
17866
17914
|
} catch {
|
|
17867
17915
|
preWriteEnv = void 0;
|
|
17868
17916
|
}
|
|
@@ -17881,9 +17929,9 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
17881
17929
|
}
|
|
17882
17930
|
if (fw === "claude-code" && isSessionHealthy(agent.code_name)) {
|
|
17883
17931
|
try {
|
|
17884
|
-
const projectMcpPath =
|
|
17885
|
-
const postWriteEnv =
|
|
17886
|
-
const mcpContent =
|
|
17932
|
+
const projectMcpPath = join42(projectDir, ".mcp.json");
|
|
17933
|
+
const postWriteEnv = readFileSync33(envIntPath, "utf-8");
|
|
17934
|
+
const mcpContent = readFileSync33(projectMcpPath, "utf-8");
|
|
17887
17935
|
const changedVars = diffEnvIntegrations(preWriteEnv, postWriteEnv);
|
|
17888
17936
|
const mcpJsonForReap = JSON.parse(mcpContent);
|
|
17889
17937
|
const affectedServerKeys = findMcpServersUsingVars(mcpJsonForReap, changedVars);
|
|
@@ -18196,14 +18244,14 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
18196
18244
|
const frameworkId2 = frameworkAdapter.id;
|
|
18197
18245
|
const candidateSkillDirs = [
|
|
18198
18246
|
// Claude Code — framework runtime tree
|
|
18199
|
-
|
|
18247
|
+
join42(homedir18(), ".augmented", agent.code_name, "skills"),
|
|
18200
18248
|
// Claude Code — project tree
|
|
18201
|
-
|
|
18249
|
+
join42(homedir18(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
18202
18250
|
// Defensive: legacy provision-side path, not currently an
|
|
18203
18251
|
// install target but cheap to sweep.
|
|
18204
|
-
|
|
18252
|
+
join42(agentDir, ".claude", "skills")
|
|
18205
18253
|
];
|
|
18206
|
-
const existingDirs = candidateSkillDirs.filter((d) =>
|
|
18254
|
+
const existingDirs = candidateSkillDirs.filter((d) => existsSync20(d));
|
|
18207
18255
|
const discoveredEntries = /* @__PURE__ */ new Set();
|
|
18208
18256
|
for (const dir of existingDirs) {
|
|
18209
18257
|
try {
|
|
@@ -18222,7 +18270,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
18222
18270
|
entry,
|
|
18223
18271
|
dirs: existingDirs,
|
|
18224
18272
|
removeDir: (p) => {
|
|
18225
|
-
if (
|
|
18273
|
+
if (existsSync20(p)) {
|
|
18226
18274
|
rmSync9(p, { recursive: true, force: true });
|
|
18227
18275
|
}
|
|
18228
18276
|
}
|
|
@@ -18244,7 +18292,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
18244
18292
|
const sharedSkillsPayload = refreshAny.shared_skills;
|
|
18245
18293
|
const desiredResolved = globalSkillsPayload !== void 0 || sharedSkillsPayload !== void 0;
|
|
18246
18294
|
const manifestPath = managedSkillManifestPath(
|
|
18247
|
-
|
|
18295
|
+
join42(homedir17(), ".augmented", agent.code_name)
|
|
18248
18296
|
);
|
|
18249
18297
|
const prevIds = /* @__PURE__ */ new Set([
|
|
18250
18298
|
...agentState.knownGlobalSkillIds.get(agent.agent_id) ?? /* @__PURE__ */ new Set(),
|
|
@@ -18264,15 +18312,15 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
18264
18312
|
}
|
|
18265
18313
|
if (plan.removes.length) {
|
|
18266
18314
|
const globalSkillDirs = [
|
|
18267
|
-
|
|
18268
|
-
|
|
18269
|
-
|
|
18315
|
+
join42(homedir17(), ".augmented", agent.code_name, "skills"),
|
|
18316
|
+
join42(homedir17(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
18317
|
+
join42(agentDir, ".claude", "skills")
|
|
18270
18318
|
];
|
|
18271
18319
|
for (const id of plan.removes) {
|
|
18272
18320
|
let prunedAny = false;
|
|
18273
18321
|
for (const dir of globalSkillDirs) {
|
|
18274
|
-
const p =
|
|
18275
|
-
if (
|
|
18322
|
+
const p = join42(dir, id);
|
|
18323
|
+
if (existsSync20(p) && existsSync20(join42(p, "SKILL.md"))) {
|
|
18276
18324
|
rmSync8(p, { recursive: true, force: true });
|
|
18277
18325
|
prunedAny = true;
|
|
18278
18326
|
}
|
|
@@ -18528,8 +18576,8 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
18528
18576
|
const sess = getSessionState(agent.code_name);
|
|
18529
18577
|
let mcpJsonParsed = null;
|
|
18530
18578
|
try {
|
|
18531
|
-
const mcpPath =
|
|
18532
|
-
mcpJsonParsed = JSON.parse(
|
|
18579
|
+
const mcpPath = join42(getProjectDir(agent.code_name), ".mcp.json");
|
|
18580
|
+
mcpJsonParsed = JSON.parse(readFileSync33(mcpPath, "utf-8"));
|
|
18533
18581
|
} catch {
|
|
18534
18582
|
}
|
|
18535
18583
|
reapMissingMcpSessions({
|
|
@@ -19000,10 +19048,10 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
19000
19048
|
}
|
|
19001
19049
|
}
|
|
19002
19050
|
const trackedFiles = frameworkAdapter.driftTrackedFiles();
|
|
19003
|
-
if (trackedFiles.length > 0 &&
|
|
19051
|
+
if (trackedFiles.length > 0 && existsSync20(agentDir)) {
|
|
19004
19052
|
const hashes = /* @__PURE__ */ new Map();
|
|
19005
19053
|
for (const file of trackedFiles) {
|
|
19006
|
-
const h = hashFile(
|
|
19054
|
+
const h = hashFile(join42(agentDir, file));
|
|
19007
19055
|
if (h) hashes.set(file, h);
|
|
19008
19056
|
}
|
|
19009
19057
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -19018,7 +19066,7 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
19018
19066
|
refreshData.agent.onboarding_state
|
|
19019
19067
|
);
|
|
19020
19068
|
const obStep = obState.step;
|
|
19021
|
-
const markerPath =
|
|
19069
|
+
const markerPath = join42(homedir17(), ".augmented", agent.code_name, "onboarding-drive.json");
|
|
19022
19070
|
const marker = readOnboardingDriveMarker(markerPath);
|
|
19023
19071
|
const obContactRaw = refreshData.agent.manager_last_contacted_at;
|
|
19024
19072
|
const obContact = typeof obContactRaw === "string" && obContactRaw ? obContactRaw : null;
|
|
@@ -19122,7 +19170,7 @@ async function ensureOpencodeRuntime(agent, refreshData, agentTimezone) {
|
|
|
19122
19170
|
}
|
|
19123
19171
|
stopOpencodeSlackIngest(codeName, log);
|
|
19124
19172
|
stopOpencodeTelegramIngest(codeName, log);
|
|
19125
|
-
const opencodeProjectDir =
|
|
19173
|
+
const opencodeProjectDir = join42(getFramework("opencode").getAgentDir(codeName), "provision");
|
|
19126
19174
|
const serveEnv = {
|
|
19127
19175
|
AGT_HOST: requireHost(),
|
|
19128
19176
|
AGT_API_KEY: getApiKey() ?? void 0,
|
|
@@ -19177,8 +19225,8 @@ async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
|
|
|
19177
19225
|
});
|
|
19178
19226
|
}
|
|
19179
19227
|
const projectDir = getProjectDir(codeName);
|
|
19180
|
-
const mcpConfigPath =
|
|
19181
|
-
const claudeMdPath =
|
|
19228
|
+
const mcpConfigPath = join42(projectDir, ".mcp.json");
|
|
19229
|
+
const claudeMdPath = join42(projectDir, "CLAUDE.md");
|
|
19182
19230
|
if (restartBreaker.isTripped(codeName)) {
|
|
19183
19231
|
const trip = restartBreaker.getTrip(codeName);
|
|
19184
19232
|
return {
|
|
@@ -19473,6 +19521,11 @@ async function ensurePersistentSession(agent, tasks, boardItems, refreshData) {
|
|
|
19473
19521
|
detail: trip.statusMessage
|
|
19474
19522
|
};
|
|
19475
19523
|
}
|
|
19524
|
+
try {
|
|
19525
|
+
provisionReviewPoster(codeName);
|
|
19526
|
+
} catch (err) {
|
|
19527
|
+
log(`[persistent-session] Failed to provision review poster for '${codeName}': ${err.message}`);
|
|
19528
|
+
}
|
|
19476
19529
|
if (!isSessionHealthy(codeName)) {
|
|
19477
19530
|
if (agentState.persistentSessionAgents.has(codeName)) {
|
|
19478
19531
|
const ctx = getLastFailureContext(codeName);
|
|
@@ -20393,7 +20446,7 @@ async function processDirectChatMessageOpencode(agent, msg) {
|
|
|
20393
20446
|
body
|
|
20394
20447
|
});
|
|
20395
20448
|
recordCursorAdvanceOutcome(
|
|
20396
|
-
|
|
20449
|
+
dirname11(paneLogPath(agent.codeName)),
|
|
20397
20450
|
"direct-chat-manager",
|
|
20398
20451
|
"reply",
|
|
20399
20452
|
verdict
|
|
@@ -20423,7 +20476,7 @@ async function processDirectChatMessageOpencode(agent, msg) {
|
|
|
20423
20476
|
} catch (err) {
|
|
20424
20477
|
if (!recorded) {
|
|
20425
20478
|
recordCursorAdvanceOutcome(
|
|
20426
|
-
|
|
20479
|
+
dirname11(paneLogPath(agent.codeName)),
|
|
20427
20480
|
"direct-chat-manager",
|
|
20428
20481
|
"reply",
|
|
20429
20482
|
{ outcome: "failed", error: err.message, expected: 1 }
|
|
@@ -20475,7 +20528,7 @@ async function processDirectChatMessage(agent, msg) {
|
|
|
20475
20528
|
if (useDoorbell) {
|
|
20476
20529
|
try {
|
|
20477
20530
|
const doorbell = directChatDoorbellPath(agent.agentId, homedir17());
|
|
20478
|
-
|
|
20531
|
+
mkdirSync15(dirname11(doorbell), { recursive: true });
|
|
20479
20532
|
writeFileSync18(doorbell, String(Date.now()));
|
|
20480
20533
|
log(`[direct-chat] Doorbell rung for '${agent.codeName}' (msg=${msg.id}) \u2014 in-session MCP will pull via the cursor`);
|
|
20481
20534
|
return;
|
|
@@ -20604,7 +20657,7 @@ ${formatRunMarker(run_id)}` : KANBAN_CHECK_COMMAND;
|
|
|
20604
20657
|
if (run_id) openInjectedRunByCode.set(codeName, run_id);
|
|
20605
20658
|
try {
|
|
20606
20659
|
const doorbell = directChatDoorbellPath(agentId, homedir17());
|
|
20607
|
-
|
|
20660
|
+
mkdirSync15(dirname11(doorbell), { recursive: true });
|
|
20608
20661
|
writeFileSync18(doorbell, String(Date.now()));
|
|
20609
20662
|
} catch (err) {
|
|
20610
20663
|
log(`[kanban] doorbell ring failed for '${codeName}': ${err.message} (notice still queued)`);
|
|
@@ -20940,17 +20993,17 @@ var lastLocalFileHash = /* @__PURE__ */ new Map();
|
|
|
20940
20993
|
var lastMemoriesBody = /* @__PURE__ */ new Map();
|
|
20941
20994
|
var memoryManifests = /* @__PURE__ */ new Map();
|
|
20942
20995
|
function memoryRetirementDir(configDir, codeName) {
|
|
20943
|
-
return
|
|
20996
|
+
return join42(configDir, "_memory-retirement", codeName);
|
|
20944
20997
|
}
|
|
20945
20998
|
function memoryManifestPath(configDir, codeName) {
|
|
20946
|
-
return
|
|
20999
|
+
return join42(memoryRetirementDir(configDir, codeName), "manifest.json");
|
|
20947
21000
|
}
|
|
20948
21001
|
function loadMemoryManifest(agentId, configDir, codeName) {
|
|
20949
21002
|
const cached = memoryManifests.get(agentId);
|
|
20950
21003
|
if (cached) return cached;
|
|
20951
21004
|
let manifest = {};
|
|
20952
21005
|
try {
|
|
20953
|
-
const raw =
|
|
21006
|
+
const raw = readFileSync33(memoryManifestPath(configDir, codeName), "utf-8");
|
|
20954
21007
|
const parsed = JSON.parse(raw);
|
|
20955
21008
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
20956
21009
|
for (const [name, entry] of Object.entries(parsed)) {
|
|
@@ -20970,7 +21023,7 @@ function saveMemoryManifest(agentId, configDir, codeName) {
|
|
|
20970
21023
|
if (!manifest) return;
|
|
20971
21024
|
try {
|
|
20972
21025
|
const path = memoryManifestPath(configDir, codeName);
|
|
20973
|
-
|
|
21026
|
+
mkdirSync15(memoryRetirementDir(configDir, codeName), { recursive: true });
|
|
20974
21027
|
const tmp = `${path}.tmp`;
|
|
20975
21028
|
writeFileSync18(tmp, JSON.stringify(manifest, null, 2));
|
|
20976
21029
|
renameSync11(tmp, path);
|
|
@@ -20978,7 +21031,7 @@ function saveMemoryManifest(agentId, configDir, codeName) {
|
|
|
20978
21031
|
}
|
|
20979
21032
|
}
|
|
20980
21033
|
function retiredMemoryDir(configDir, codeName) {
|
|
20981
|
-
return
|
|
21034
|
+
return join42(memoryRetirementDir(configDir, codeName), "retired");
|
|
20982
21035
|
}
|
|
20983
21036
|
var RETIRED_MEMORY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
20984
21037
|
var lastRetirementReport = /* @__PURE__ */ new Map();
|
|
@@ -21057,15 +21110,15 @@ function applyMemoryTombstones(opts) {
|
|
|
21057
21110
|
log2(`[memory-retire] ${agent.code_name}: KEPT '${tomb.name}' \u2014 no write record, not ours to remove`);
|
|
21058
21111
|
continue;
|
|
21059
21112
|
}
|
|
21060
|
-
const filePath =
|
|
21061
|
-
if (!
|
|
21113
|
+
const filePath = join42(memoryDir, entry.file);
|
|
21114
|
+
if (!existsSync20(filePath)) {
|
|
21062
21115
|
outcomes.already_gone++;
|
|
21063
21116
|
delete manifest[tomb.name];
|
|
21064
21117
|
manifestDirty = true;
|
|
21065
21118
|
continue;
|
|
21066
21119
|
}
|
|
21067
21120
|
try {
|
|
21068
|
-
const actual = createHash20("sha256").update(
|
|
21121
|
+
const actual = createHash20("sha256").update(readFileSync33(filePath)).digest("hex");
|
|
21069
21122
|
if (actual !== entry.sha) {
|
|
21070
21123
|
outcomes.kept_modified++;
|
|
21071
21124
|
outcomes.unapplied.push({ name: tomb.name, reason: "kept_modified" });
|
|
@@ -21075,11 +21128,11 @@ function applyMemoryTombstones(opts) {
|
|
|
21075
21128
|
continue;
|
|
21076
21129
|
}
|
|
21077
21130
|
const destDir = retiredMemoryDir(configDir, agent.code_name);
|
|
21078
|
-
|
|
21131
|
+
mkdirSync15(destDir, { recursive: true });
|
|
21079
21132
|
const stamp = Date.now();
|
|
21080
|
-
let dest =
|
|
21081
|
-
for (let n = 1;
|
|
21082
|
-
dest =
|
|
21133
|
+
let dest = join42(destDir, `${entry.file}.${stamp}.retired`);
|
|
21134
|
+
for (let n = 1; existsSync20(dest); n++) {
|
|
21135
|
+
dest = join42(destDir, `${entry.file}.${stamp}-${n}.retired`);
|
|
21083
21136
|
}
|
|
21084
21137
|
renameSync11(filePath, dest);
|
|
21085
21138
|
try {
|
|
@@ -21112,13 +21165,13 @@ function applyMemoryTombstones(opts) {
|
|
|
21112
21165
|
}
|
|
21113
21166
|
function reapRetiredMemories(configDir, codeName, log2) {
|
|
21114
21167
|
const dir = retiredMemoryDir(configDir, codeName);
|
|
21115
|
-
if (!
|
|
21168
|
+
if (!existsSync20(dir)) return;
|
|
21116
21169
|
const cutoff = Date.now() - RETIRED_MEMORY_TTL_MS;
|
|
21117
21170
|
let reaped = 0;
|
|
21118
21171
|
try {
|
|
21119
21172
|
for (const file of readdirSync12(dir)) {
|
|
21120
21173
|
if (!file.endsWith(".retired")) continue;
|
|
21121
|
-
const path =
|
|
21174
|
+
const path = join42(dir, file);
|
|
21122
21175
|
try {
|
|
21123
21176
|
if (statSync11(path).mtimeMs < cutoff) {
|
|
21124
21177
|
unlinkSync6(path);
|
|
@@ -21133,8 +21186,8 @@ function reapRetiredMemories(configDir, codeName, log2) {
|
|
|
21133
21186
|
if (reaped > 0) log2(`[memory-retire] ${codeName}: reaped ${reaped} retired memory file(s) past TTL`);
|
|
21134
21187
|
}
|
|
21135
21188
|
async function syncMemories(agent, configDir, log2) {
|
|
21136
|
-
const projectDir =
|
|
21137
|
-
const memoryDir =
|
|
21189
|
+
const projectDir = join42(configDir, agent.code_name, "project");
|
|
21190
|
+
const memoryDir = join42(projectDir, "memory");
|
|
21138
21191
|
const isFreshSync = pendingFreshMemorySync.has(agent.agent_id);
|
|
21139
21192
|
if (isFreshSync) {
|
|
21140
21193
|
log2(`[memory-sync] Fresh-sync requested for '${agent.code_name}' \u2014 pulling DB first`);
|
|
@@ -21158,14 +21211,14 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
21158
21211
|
}
|
|
21159
21212
|
pendingFreshMemorySync.delete(agent.agent_id);
|
|
21160
21213
|
}
|
|
21161
|
-
if (
|
|
21214
|
+
if (existsSync20(memoryDir)) {
|
|
21162
21215
|
const prevHashes = memoryFileHashes.get(agent.agent_id) ?? /* @__PURE__ */ new Map();
|
|
21163
21216
|
const currentHashes = /* @__PURE__ */ new Map();
|
|
21164
21217
|
const changedMemories = [];
|
|
21165
21218
|
for (const file of readdirSync12(memoryDir)) {
|
|
21166
21219
|
if (!file.endsWith(".md")) continue;
|
|
21167
21220
|
try {
|
|
21168
|
-
const raw =
|
|
21221
|
+
const raw = readFileSync33(join42(memoryDir, file), "utf-8");
|
|
21169
21222
|
const fileHash = createHash20("sha256").update(raw).digest("hex").slice(0, 16);
|
|
21170
21223
|
currentHashes.set(file, fileHash);
|
|
21171
21224
|
if (prevHashes.get(file) === fileHash) continue;
|
|
@@ -21190,7 +21243,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
21190
21243
|
} catch (err) {
|
|
21191
21244
|
for (const mem of changedMemories) {
|
|
21192
21245
|
for (const [file] of currentHashes) {
|
|
21193
|
-
const parsed = parseMemoryFile(
|
|
21246
|
+
const parsed = parseMemoryFile(readFileSync33(join42(memoryDir, file), "utf-8"), file.replace(/\.md$/, ""));
|
|
21194
21247
|
if (parsed?.name === mem.name) currentHashes.delete(file);
|
|
21195
21248
|
}
|
|
21196
21249
|
}
|
|
@@ -21216,7 +21269,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
21216
21269
|
}
|
|
21217
21270
|
}
|
|
21218
21271
|
async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
21219
|
-
const localFiles =
|
|
21272
|
+
const localFiles = existsSync20(memoryDir) ? readdirSync12(memoryDir).filter((f) => f.endsWith(".md")).sort() : [];
|
|
21220
21273
|
const localListHash = createHash20("sha256").update(localFiles.join(",")).digest("hex").slice(0, 16);
|
|
21221
21274
|
const prevLocalHash = lastLocalFileHash.get(agent.agent_id);
|
|
21222
21275
|
const prevDownload = lastDownloadHash.get(agent.agent_id);
|
|
@@ -21271,7 +21324,7 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
21271
21324
|
// Per-agent, not host-wide: memories are agent-private, so a shared
|
|
21272
21325
|
// store would buy almost no dedupe while exposing one agent's content
|
|
21273
21326
|
// to every other agent on the host. See memory-cache.ts's header.
|
|
21274
|
-
cacheDir:
|
|
21327
|
+
cacheDir: join42(configDir, agent.code_name, "_memory_bodies"),
|
|
21275
21328
|
fetchContents: async (hashes) => {
|
|
21276
21329
|
const res = await api.post(
|
|
21277
21330
|
"/host/memories/contents",
|
|
@@ -21300,7 +21353,7 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
21300
21353
|
lastDownloadHash.set(agent.agent_id, responseHash);
|
|
21301
21354
|
lastLocalFileHash.set(agent.agent_id, localListHash);
|
|
21302
21355
|
if (memories?.length) {
|
|
21303
|
-
|
|
21356
|
+
mkdirSync15(memoryDir, { recursive: true });
|
|
21304
21357
|
const manifest = loadMemoryManifest(agent.agent_id, configDir, agent.code_name);
|
|
21305
21358
|
let written = 0;
|
|
21306
21359
|
let overwritten = 0;
|
|
@@ -21309,7 +21362,7 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
21309
21362
|
const rawSlug = mem.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").slice(0, 60);
|
|
21310
21363
|
const slug = rawSlug || `memory-${i}`;
|
|
21311
21364
|
const fileName = `${slug}.md`;
|
|
21312
|
-
const filePath =
|
|
21365
|
+
const filePath = join42(memoryDir, fileName);
|
|
21313
21366
|
const desired = `---
|
|
21314
21367
|
name: ${JSON.stringify(mem.name)}
|
|
21315
21368
|
type: ${mem.type}
|
|
@@ -21326,10 +21379,10 @@ ${mem.content}
|
|
|
21326
21379
|
return true;
|
|
21327
21380
|
};
|
|
21328
21381
|
let manifestDirty = false;
|
|
21329
|
-
if (
|
|
21382
|
+
if (existsSync20(filePath)) {
|
|
21330
21383
|
let existing = "";
|
|
21331
21384
|
try {
|
|
21332
|
-
existing =
|
|
21385
|
+
existing = readFileSync33(filePath, "utf-8");
|
|
21333
21386
|
} catch {
|
|
21334
21387
|
}
|
|
21335
21388
|
if (existing === desired) {
|
|
@@ -21359,7 +21412,7 @@ ${mem.content}
|
|
|
21359
21412
|
}
|
|
21360
21413
|
}
|
|
21361
21414
|
async function cleanupAgentFiles(codeName, agentDir) {
|
|
21362
|
-
if (
|
|
21415
|
+
if (existsSync20(agentDir)) {
|
|
21363
21416
|
try {
|
|
21364
21417
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
21365
21418
|
log(`Removed provision directory for '${codeName}'`);
|
|
@@ -21629,8 +21682,8 @@ function startManager(opts) {
|
|
|
21629
21682
|
config = opts;
|
|
21630
21683
|
try {
|
|
21631
21684
|
const stateFile = getStateFile();
|
|
21632
|
-
if (
|
|
21633
|
-
const raw =
|
|
21685
|
+
if (existsSync20(stateFile)) {
|
|
21686
|
+
const raw = readFileSync33(stateFile, "utf-8");
|
|
21634
21687
|
const parsed = JSON.parse(raw);
|
|
21635
21688
|
if (Array.isArray(parsed.agents)) {
|
|
21636
21689
|
state8.agents = parsed.agents;
|
|
@@ -21657,7 +21710,7 @@ function startManager(opts) {
|
|
|
21657
21710
|
log(`[startup] state rehydration failed (continuing with empty state): ${err.message}`);
|
|
21658
21711
|
}
|
|
21659
21712
|
log(
|
|
21660
|
-
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${
|
|
21713
|
+
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${join42(homedir17(), ".augmented", "manager.log")}`
|
|
21661
21714
|
);
|
|
21662
21715
|
deployMcpAssets();
|
|
21663
21716
|
reapOrphanChannelMcps({ log });
|
|
@@ -21686,7 +21739,7 @@ async function reapOrphanedClaudePids() {
|
|
|
21686
21739
|
const looksLikeClaude = (pid) => {
|
|
21687
21740
|
if (process.platform !== "linux") return true;
|
|
21688
21741
|
try {
|
|
21689
|
-
const comm =
|
|
21742
|
+
const comm = readFileSync33(`/proc/${pid}/comm`, "utf-8").trim().toLowerCase();
|
|
21690
21743
|
return comm.includes("claude");
|
|
21691
21744
|
} catch {
|
|
21692
21745
|
return false;
|
|
@@ -21783,18 +21836,18 @@ function restartRunningChannelMcps(basenames) {
|
|
|
21783
21836
|
}
|
|
21784
21837
|
}
|
|
21785
21838
|
function deployMcpAssets() {
|
|
21786
|
-
const targetDir =
|
|
21787
|
-
|
|
21788
|
-
const moduleDir =
|
|
21839
|
+
const targetDir = join42(homedir17(), ".augmented", "_mcp");
|
|
21840
|
+
mkdirSync15(targetDir, { recursive: true });
|
|
21841
|
+
const moduleDir = dirname11(fileURLToPath2(import.meta.url));
|
|
21789
21842
|
let mcpSourceDir = "";
|
|
21790
21843
|
let dir = moduleDir;
|
|
21791
21844
|
for (let i = 0; i < 6; i++) {
|
|
21792
|
-
const candidate =
|
|
21793
|
-
if (
|
|
21845
|
+
const candidate = join42(dir, "dist", "mcp");
|
|
21846
|
+
if (existsSync20(join42(candidate, "index.js"))) {
|
|
21794
21847
|
mcpSourceDir = candidate;
|
|
21795
21848
|
break;
|
|
21796
21849
|
}
|
|
21797
|
-
const parent =
|
|
21850
|
+
const parent = dirname11(dir);
|
|
21798
21851
|
if (parent === dir) break;
|
|
21799
21852
|
dir = parent;
|
|
21800
21853
|
}
|
|
@@ -21807,8 +21860,8 @@ function deployMcpAssets() {
|
|
|
21807
21860
|
const failedFiles = [];
|
|
21808
21861
|
const fileHash = (p) => {
|
|
21809
21862
|
try {
|
|
21810
|
-
if (!
|
|
21811
|
-
return createHash20("sha256").update(
|
|
21863
|
+
if (!existsSync20(p)) return null;
|
|
21864
|
+
return createHash20("sha256").update(readFileSync33(p)).digest("hex");
|
|
21812
21865
|
} catch {
|
|
21813
21866
|
return null;
|
|
21814
21867
|
}
|
|
@@ -21879,9 +21932,9 @@ function deployMcpAssets() {
|
|
|
21879
21932
|
// needs restarting to pick up a token rotation.
|
|
21880
21933
|
"xero.js"
|
|
21881
21934
|
]) {
|
|
21882
|
-
const src =
|
|
21883
|
-
const dst =
|
|
21884
|
-
if (!
|
|
21935
|
+
const src = join42(mcpSourceDir, file);
|
|
21936
|
+
const dst = join42(targetDir, file);
|
|
21937
|
+
if (!existsSync20(src)) continue;
|
|
21885
21938
|
attemptedFiles.push(file);
|
|
21886
21939
|
const before = fileHash(dst);
|
|
21887
21940
|
try {
|
|
@@ -21906,16 +21959,16 @@ function deployMcpAssets() {
|
|
|
21906
21959
|
log(`[manager] Bundle(s) updated: ${changedBasenames.join(", ")} \u2014 signalling running instances to restart`);
|
|
21907
21960
|
restartRunningChannelMcps(changedBasenames);
|
|
21908
21961
|
}
|
|
21909
|
-
const localMcpPath =
|
|
21962
|
+
const localMcpPath = join42(targetDir, "index.js");
|
|
21910
21963
|
try {
|
|
21911
|
-
const agentsDir =
|
|
21912
|
-
if (
|
|
21964
|
+
const agentsDir = join42(homedir17(), ".augmented", "agents");
|
|
21965
|
+
if (existsSync20(agentsDir)) {
|
|
21913
21966
|
for (const entry of readdirSync12(agentsDir, { withFileTypes: true })) {
|
|
21914
21967
|
if (!entry.isDirectory()) continue;
|
|
21915
21968
|
for (const subdir of ["provision", "project"]) {
|
|
21916
|
-
const mcpJsonPath =
|
|
21969
|
+
const mcpJsonPath = join42(agentsDir, entry.name, subdir, ".mcp.json");
|
|
21917
21970
|
try {
|
|
21918
|
-
const raw =
|
|
21971
|
+
const raw = readFileSync33(mcpJsonPath, "utf-8");
|
|
21919
21972
|
if (!raw.includes("@integrity-labs/augmented-mcp")) continue;
|
|
21920
21973
|
const mcpConfig = JSON.parse(raw);
|
|
21921
21974
|
const augServer = mcpConfig.mcpServers?.["augmented"];
|