@integrity-labs/agt-cli 0.28.1266 → 0.28.1268
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{api-client-5CNPCJKS.js → api-client-MH7MLGTA.js} +2 -2
- package/dist/bin/agt.js +5 -5
- package/dist/{chunk-SGYCPC5K.js → chunk-EHZQAT3Q.js} +2 -2
- package/dist/{chunk-WJUGK4R5.js → chunk-ERO3R3Z7.js} +85 -2
- package/dist/chunk-ERO3R3Z7.js.map +1 -0
- package/dist/{chunk-7Z3N4G2Y.js → chunk-TMZDRXAK.js} +3 -3
- package/dist/{claude-pair-runtime-2XKML4U6.js → claude-pair-runtime-3PHBCCUP.js} +2 -2
- package/dist/lib/manager-worker.js +1009 -451
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/mcp/direct-chat-channel.js +6 -1
- package/dist/mcp/slack-channel.js +6 -1
- package/dist/mcp/telegram-channel.js +6 -1
- package/dist/{persistent-session-YBCMFF7T.js → persistent-session-BLZPYHBE.js} +16 -2
- package/dist/{responsiveness-probe-ZOCD6UYO.js → responsiveness-probe-T6O4V2XZ.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-WJUGK4R5.js.map +0 -1
- /package/dist/{api-client-5CNPCJKS.js.map → api-client-MH7MLGTA.js.map} +0 -0
- /package/dist/{chunk-SGYCPC5K.js.map → chunk-EHZQAT3Q.js.map} +0 -0
- /package/dist/{chunk-7Z3N4G2Y.js.map → chunk-TMZDRXAK.js.map} +0 -0
- /package/dist/{claude-pair-runtime-2XKML4U6.js.map → claude-pair-runtime-3PHBCCUP.js.map} +0 -0
- /package/dist/{persistent-session-YBCMFF7T.js.map → persistent-session-BLZPYHBE.js.map} +0 -0
- /package/dist/{responsiveness-probe-ZOCD6UYO.js.map → responsiveness-probe-T6O4V2XZ.js.map} +0 -0
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
tripClass,
|
|
71
71
|
writeEtcEnvironment,
|
|
72
72
|
writeProfileDScript
|
|
73
|
-
} from "../chunk-
|
|
73
|
+
} from "../chunk-TMZDRXAK.js";
|
|
74
74
|
import {
|
|
75
75
|
ApiError,
|
|
76
76
|
adoptHostKeyInProcess,
|
|
@@ -88,7 +88,7 @@ import {
|
|
|
88
88
|
probeHostKey,
|
|
89
89
|
requireHost,
|
|
90
90
|
setConfigHash
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-EHZQAT3Q.js";
|
|
92
92
|
import {
|
|
93
93
|
BLOCKED_ON_PROMPT_DECISION,
|
|
94
94
|
CHANNEL_SECRET_ENV_KEYS,
|
|
@@ -125,6 +125,7 @@ import {
|
|
|
125
125
|
isOpencodeSessionHealthy,
|
|
126
126
|
isSessionHealthy,
|
|
127
127
|
isolationMode,
|
|
128
|
+
killStragglerProcess,
|
|
128
129
|
log,
|
|
129
130
|
mergeOpencodeConfigArtifact,
|
|
130
131
|
modelPolicyAuthComponent,
|
|
@@ -138,6 +139,8 @@ import {
|
|
|
138
139
|
policyResolvedModel,
|
|
139
140
|
prepareForRespawn,
|
|
140
141
|
probeClaudeProcessInTmux,
|
|
142
|
+
probeSessionProcess,
|
|
143
|
+
probeSessionProcessOlderThan,
|
|
141
144
|
probeTmuxSession,
|
|
142
145
|
readChannelServerEnv,
|
|
143
146
|
readDirectChatSessionState,
|
|
@@ -154,6 +157,7 @@ import {
|
|
|
154
157
|
restartEgressSidecar,
|
|
155
158
|
rotatePaneLogForDayRollover,
|
|
156
159
|
rotateSessionForWedge,
|
|
160
|
+
sanitizeMcpJson,
|
|
157
161
|
seedContainerMemory,
|
|
158
162
|
sessionBlockedOnPrompt,
|
|
159
163
|
sessionHealthyAndUnblocked,
|
|
@@ -174,7 +178,7 @@ import {
|
|
|
174
178
|
webFetchBaselineValue,
|
|
175
179
|
webFetchRestartNeeded,
|
|
176
180
|
writeEgressAllowlist
|
|
177
|
-
} from "../chunk-
|
|
181
|
+
} from "../chunk-ERO3R3Z7.js";
|
|
178
182
|
import {
|
|
179
183
|
isAgentIdle,
|
|
180
184
|
isStaleForToday,
|
|
@@ -453,15 +457,31 @@ function configReloadConfirmed(input) {
|
|
|
453
457
|
var ConfigReloadLedger = class {
|
|
454
458
|
pending = /* @__PURE__ */ new Map();
|
|
455
459
|
confirmed = /* @__PURE__ */ new Set();
|
|
460
|
+
/**
|
|
461
|
+
* ENG-12052: when the FIRST fresh render for the pending reload landed. A
|
|
462
|
+
* session started at or after it was started from fresh config, so the
|
|
463
|
+
* reload retry must never stop it (stopping it is the kill/respawn loop
|
|
464
|
+
* b4cfce82 hit). Cleared whenever the reload is re-torn-down or acked.
|
|
465
|
+
*/
|
|
466
|
+
freshRenderAt = /* @__PURE__ */ new Map();
|
|
456
467
|
/** What the poll does with this agent's integration-change request. Records a teardown. */
|
|
457
468
|
service(agentId, requested) {
|
|
458
469
|
const action = configReloadAction({ requested, pendingRequested: this.pending.get(agentId) });
|
|
459
470
|
if (action === "teardown") {
|
|
460
471
|
this.pending.set(agentId, requested);
|
|
461
472
|
this.confirmed.delete(agentId);
|
|
473
|
+
this.freshRenderAt.delete(agentId);
|
|
462
474
|
}
|
|
463
475
|
return action;
|
|
464
476
|
}
|
|
477
|
+
/** ENG-12052: a fresh render landed for the pending reload; keeps the earliest. */
|
|
478
|
+
noteFreshRender(agentId, atMs) {
|
|
479
|
+
if (this.pending.has(agentId) && !this.freshRenderAt.has(agentId)) this.freshRenderAt.set(agentId, atMs);
|
|
480
|
+
}
|
|
481
|
+
/** ENG-12052: when the pending reload's first fresh render landed, or null. */
|
|
482
|
+
freshRenderedAt(agentId) {
|
|
483
|
+
return this.freshRenderAt.get(agentId) ?? null;
|
|
484
|
+
}
|
|
465
485
|
isPending(agentId) {
|
|
466
486
|
return this.pending.has(agentId);
|
|
467
487
|
}
|
|
@@ -477,6 +497,7 @@ var ConfigReloadLedger = class {
|
|
|
477
497
|
const requestedAt = this.pending.get(agentId);
|
|
478
498
|
this.confirmed.delete(agentId);
|
|
479
499
|
this.pending.delete(agentId);
|
|
500
|
+
this.freshRenderAt.delete(agentId);
|
|
480
501
|
if (requestedAt) out.push({ agentId, requestedAt });
|
|
481
502
|
}
|
|
482
503
|
return out;
|
|
@@ -485,6 +506,7 @@ var ConfigReloadLedger = class {
|
|
|
485
506
|
forget(agentId) {
|
|
486
507
|
this.pending.delete(agentId);
|
|
487
508
|
this.confirmed.delete(agentId);
|
|
509
|
+
this.freshRenderAt.delete(agentId);
|
|
488
510
|
}
|
|
489
511
|
};
|
|
490
512
|
function stampIsOlder(a, b) {
|
|
@@ -533,38 +555,168 @@ function staleSessionStopConfirmed(sessionState) {
|
|
|
533
555
|
}
|
|
534
556
|
|
|
535
557
|
// src/lib/config-reload-confirm.ts
|
|
558
|
+
var UNKNOWN_ALERT_AFTER_MS = 10 * 6e4;
|
|
536
559
|
function staleReloadTmuxSession(framework, codeName) {
|
|
537
560
|
return framework === "opencode" ? opencodeTmuxSession(codeName) : `agt-${codeName}`;
|
|
538
561
|
}
|
|
562
|
+
var UnknownStreak = class {
|
|
563
|
+
since = /* @__PURE__ */ new Map();
|
|
564
|
+
alertedAt = /* @__PURE__ */ new Map();
|
|
565
|
+
count = /* @__PURE__ */ new Map();
|
|
566
|
+
/** `count` is how many times in a row this key was noted (1 on the first). */
|
|
567
|
+
note(agentId, nowMs) {
|
|
568
|
+
const start = this.since.get(agentId) ?? nowMs;
|
|
569
|
+
this.since.set(agentId, start);
|
|
570
|
+
const count = (this.count.get(agentId) ?? 0) + 1;
|
|
571
|
+
this.count.set(agentId, count);
|
|
572
|
+
const forMs = nowMs - start;
|
|
573
|
+
const last = this.alertedAt.get(agentId);
|
|
574
|
+
const due = forMs >= UNKNOWN_ALERT_AFTER_MS && (last === void 0 || nowMs - last >= UNKNOWN_ALERT_AFTER_MS);
|
|
575
|
+
if (due) this.alertedAt.set(agentId, nowMs);
|
|
576
|
+
return { alert: due, forMs, count };
|
|
577
|
+
}
|
|
578
|
+
clear(agentId) {
|
|
579
|
+
this.since.delete(agentId);
|
|
580
|
+
this.alertedAt.delete(agentId);
|
|
581
|
+
this.count.delete(agentId);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
539
584
|
function confirmConfigReload(input, deps) {
|
|
585
|
+
let held = false;
|
|
586
|
+
const out = confirmConfigReloadOnce(input, deps, () => {
|
|
587
|
+
held = true;
|
|
588
|
+
});
|
|
589
|
+
if (!held && !(out.action === "not_ready" && input.pending)) deps.unknownStreak?.clear(input.agentId);
|
|
590
|
+
return out;
|
|
591
|
+
}
|
|
592
|
+
function confirmConfigReloadOnce(input, deps, onHold) {
|
|
540
593
|
if (!configReloadConfirmed({ pending: input.pending, freshFetch: input.freshFetch, rendered: input.rendered })) {
|
|
541
594
|
return { action: "not_ready" };
|
|
542
595
|
}
|
|
596
|
+
const now = deps.now ?? Date.now;
|
|
597
|
+
const claudeCode = input.framework !== "opencode";
|
|
543
598
|
const session = staleReloadTmuxSession(input.framework, input.codeName);
|
|
599
|
+
const holdUnknown = (what) => {
|
|
600
|
+
onHold();
|
|
601
|
+
const streak = deps.unknownStreak?.note(input.agentId, now());
|
|
602
|
+
if (streak?.alert) {
|
|
603
|
+
deps.alert?.(
|
|
604
|
+
input.agentId,
|
|
605
|
+
`config-change reload for '${input.codeName}' has been unconfirmable for ${Math.round(streak.forMs / 6e4)} min (${what}); it stays pending, and the agent may still be running pre-reload config (ENG-12052)`
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
544
609
|
let stopped = false;
|
|
545
610
|
if (deps.probe(session) === "alive") {
|
|
611
|
+
const spawnedAt = claudeCode && deps.sessionSpawnedAt ? deps.sessionSpawnedAt(input.codeName) : void 0;
|
|
612
|
+
const freshAt = input.freshRenderedAt ?? null;
|
|
613
|
+
if (spawnedAt !== void 0 && spawnedAt !== null && freshAt !== null && spawnedAt >= freshAt) {
|
|
614
|
+
const blind = claudeCode && deps.spawnedBlind?.(input.codeName);
|
|
615
|
+
const olderState = blind && deps.probeProcessOlderThan ? deps.probeProcessOlderThan(input.codeName, (now() - spawnedAt) / 1e3 + BLIND_SPAWN_AGE_MARGIN_S) : "unknown";
|
|
616
|
+
if (blind && olderState === "dead") {
|
|
617
|
+
deps.clearBlind?.(input.codeName);
|
|
618
|
+
deps.log(
|
|
619
|
+
`[restart] RELOAD_FRESH_SESSION_VERIFIED agent='${input.codeName}': no session process predates the blind spawn, so no pre-reload straggler survived it (ENG-12052)`
|
|
620
|
+
);
|
|
621
|
+
} else if (blind) {
|
|
622
|
+
deps.log(
|
|
623
|
+
`[restart] RELOAD_FRESH_SESSION_UNVERIFIED agent='${input.codeName}': the running session was started from the fresh render, but while it could not be told whether a pre-reload process was still running, so the reload stays pending (ENG-12052)`
|
|
624
|
+
);
|
|
625
|
+
holdUnknown(
|
|
626
|
+
olderState === "alive" ? "a session process older than the current session is still running beside it (a pre-reload straggler)" : "the session was started while the previous session process could not be probed"
|
|
627
|
+
);
|
|
628
|
+
return { action: "process_unconfirmed", processState: olderState === "alive" ? "alive" : "unknown", stopped: false };
|
|
629
|
+
}
|
|
630
|
+
deps.unknownStreak?.clear(input.agentId);
|
|
631
|
+
deps.confirm(input.agentId);
|
|
632
|
+
deps.log(
|
|
633
|
+
`[restart] config-change reload for '${input.codeName}': the running session was started from the fresh render - acking without a restart (ENG-12052)`
|
|
634
|
+
);
|
|
635
|
+
return { action: "acked", stopped: false, fresh: true };
|
|
636
|
+
}
|
|
637
|
+
if (spawnedAt !== void 0 && (spawnedAt === null || freshAt === null)) {
|
|
638
|
+
deps.log(
|
|
639
|
+
`[restart] RELOAD_GENERATION_UNKNOWN agent='${input.codeName}' spawned_at=${spawnedAt ?? "unknown"} fresh_render_at=${freshAt ?? "unknown"}: cannot tell whether the running session predates the fresh render, so it is not stopped and the reload stays pending (ENG-12052)`
|
|
640
|
+
);
|
|
641
|
+
holdUnknown("the running session's start time or the fresh render time is unknown");
|
|
642
|
+
return { action: "generation_unknown" };
|
|
643
|
+
}
|
|
546
644
|
deps.log(
|
|
547
645
|
`[restart] '${input.codeName}' is running config from before the reload's fresh render - restarting it (ENG-11912)`
|
|
548
646
|
);
|
|
549
|
-
if (
|
|
550
|
-
else deps.
|
|
647
|
+
if (claudeCode) deps.stopClaudeCode(input.codeName);
|
|
648
|
+
else deps.stopOpencode(input.codeName);
|
|
551
649
|
stopped = true;
|
|
552
650
|
}
|
|
553
651
|
const sessionState = deps.probe(session);
|
|
554
|
-
if (staleSessionStopConfirmed(sessionState)) {
|
|
555
|
-
deps.
|
|
556
|
-
|
|
557
|
-
|
|
652
|
+
if (!staleSessionStopConfirmed(sessionState)) {
|
|
653
|
+
deps.log(
|
|
654
|
+
`[restart] STALE_SESSION_STOP_FAILED agent='${input.codeName}' session_state=${sessionState}: the session spawned from pre-reload config is still running or could not be probed, so the config-change reload stays pending and the stop is retried next poll (ENG-11912)`
|
|
655
|
+
);
|
|
656
|
+
if (sessionState === "unknown") holdUnknown("the tmux probe cannot answer");
|
|
657
|
+
return { action: "stop_unconfirmed", sessionState, stopped };
|
|
658
|
+
}
|
|
659
|
+
if (claudeCode && deps.probeProcess) {
|
|
660
|
+
const processState = deps.probeProcess(input.codeName);
|
|
661
|
+
if (processState !== "dead") {
|
|
662
|
+
deps.log(
|
|
663
|
+
`[restart] STALE_SESSION_PROCESS_ALIVE agent='${input.codeName}' process_state=${processState}: tmux is gone but a session process ${processState === "alive" ? "is still running" : "could not be probed"} with pre-reload config, so the reload stays pending; the spawn gate stops a live straggler before any respawn (ENG-12052)`
|
|
664
|
+
);
|
|
665
|
+
if (processState === "unknown") holdUnknown("the session process probe cannot answer");
|
|
666
|
+
return { action: "process_unconfirmed", processState, stopped };
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
deps.unknownStreak?.clear(input.agentId);
|
|
670
|
+
deps.confirm(input.agentId);
|
|
671
|
+
deps.log(`[restart] config-change reload for '${input.codeName}' rendered from fresh integrations - acking (ENG-11912)`);
|
|
672
|
+
return { action: "acked", stopped };
|
|
673
|
+
}
|
|
674
|
+
var BLIND_SPAWN_AGE_MARGIN_S = 5;
|
|
675
|
+
var STRAGGLER_TERM_ATTEMPTS = 2;
|
|
676
|
+
function stragglerSpawnGate(codeName, deps) {
|
|
677
|
+
const tmux = deps.probeTmux?.(codeName) ?? "dead";
|
|
678
|
+
if (tmux !== "dead") {
|
|
679
|
+
deps.deferStreak?.clear(codeName);
|
|
680
|
+
deps.log(
|
|
681
|
+
`[persistent-session] '${codeName}': STRAGGLER_GATE_TMUX_${tmux.toUpperCase()} - tmux does not confirm the session is gone, so a claude process for it may be the current session; nothing signalled (ENG-12052)`
|
|
682
|
+
);
|
|
683
|
+
return "spawn-unknown";
|
|
684
|
+
}
|
|
685
|
+
const state10 = deps.probeProcess(codeName);
|
|
686
|
+
if (state10 !== "alive") deps.deferStreak?.clear(codeName);
|
|
687
|
+
if (state10 === "dead") return "spawn";
|
|
688
|
+
if (state10 === "unknown") {
|
|
689
|
+
deps.log(
|
|
690
|
+
`[persistent-session] '${codeName}': STRAGGLER_PROBE_UNKNOWN - cannot tell whether a previous session process is still running; spawning anyway so the agent is not held offline (ENG-12052)`
|
|
691
|
+
);
|
|
692
|
+
return "spawn-unknown";
|
|
693
|
+
}
|
|
694
|
+
if (deps.isDocker(codeName)) {
|
|
695
|
+
deps.deferStreak?.clear(codeName);
|
|
696
|
+
deps.log(
|
|
697
|
+
`[persistent-session] '${codeName}': a previous session's container is still running; the spawn's docker rm -f removes it before the new one starts (ENG-12052)`
|
|
698
|
+
);
|
|
699
|
+
return "spawn-docker-replaces";
|
|
558
700
|
}
|
|
701
|
+
const streak = deps.deferStreak?.note(codeName, (deps.now ?? Date.now)());
|
|
702
|
+
const attempt = streak?.count ?? 1;
|
|
703
|
+
const signal = attempt > STRAGGLER_TERM_ATTEMPTS ? "KILL" : "TERM";
|
|
704
|
+
const signalled = deps.killStraggler(codeName, signal);
|
|
559
705
|
deps.log(
|
|
560
|
-
`[
|
|
706
|
+
`[persistent-session] '${codeName}': deferring spawn - STRAGGLER_ALIVE (attempt ${attempt}): a previous claude process outlived its tmux session and still runs pre-reload config; ${signalled ? `sent it SIG${signal}` : `SIG${signal} matched nothing or failed`}. Not counted as a restart; the next poll re-probes before spawning (ENG-12052)`
|
|
561
707
|
);
|
|
562
|
-
|
|
708
|
+
if (streak?.alert) {
|
|
709
|
+
deps.alert?.(
|
|
710
|
+
codeName,
|
|
711
|
+
`agent '${codeName}' has been held offline for ${Math.round(streak.forMs / 6e4)} min by a previous claude process that survives ${signal === "KILL" ? "SIGTERM and SIGKILL" : "SIGTERM (SIGKILL follows from the next attempt)"} (${attempt} attempts); it is not respawned beside it because it runs pre-reload config. Kill it by hand if it persists (ENG-12052)`
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
return "defer";
|
|
563
715
|
}
|
|
564
716
|
|
|
565
717
|
// src/lib/manager-worker.ts
|
|
566
|
-
import { createHash as
|
|
567
|
-
import { readFileSync as
|
|
718
|
+
import { createHash as createHash21 } from "crypto";
|
|
719
|
+
import { readFileSync as readFileSync37, writeFileSync as writeFileSync19, mkdirSync as mkdirSync18, existsSync as existsSync20, rmSync as rmSync9, readdirSync as readdirSync14, statSync as statSync15, unlinkSync as unlinkSync6, renameSync as renameSync11, utimesSync as utimesSync4, readlinkSync as readlinkSync2 } from "fs";
|
|
568
720
|
|
|
569
721
|
// src/lib/atomic-file-replace.ts
|
|
570
722
|
import { copyFileSync, renameSync, unlinkSync } from "fs";
|
|
@@ -981,7 +1133,7 @@ function clearEpisode(codeName) {
|
|
|
981
1133
|
}
|
|
982
1134
|
|
|
983
1135
|
// src/lib/manager-worker.ts
|
|
984
|
-
import { join as
|
|
1136
|
+
import { join as join46, dirname as dirname11, delimiter as pathDelimiter } from "path";
|
|
985
1137
|
import { homedir as homedir17, hostname, platform as platform3 } from "os";
|
|
986
1138
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
987
1139
|
|
|
@@ -2857,17 +3009,272 @@ function isRemoteMcpEntry(value) {
|
|
|
2857
3009
|
function expectedRemoteMcpKeys(integrations) {
|
|
2858
3010
|
return new Set(integrations.map((i) => remoteMcpServerKey(i.definition_id, i.connection_key ?? null)));
|
|
2859
3011
|
}
|
|
3012
|
+
function isSanitizedRemoteBridge(entry) {
|
|
3013
|
+
if (!entry || typeof entry !== "object") return false;
|
|
3014
|
+
const e = entry;
|
|
3015
|
+
if (e.command !== "npx" || !Array.isArray(e.args)) return false;
|
|
3016
|
+
const a = e.args;
|
|
3017
|
+
return a.length === 4 && a[0] === "-y" && a[1] === "mcp-remote" && typeof a[2] === "string" && /^https?:\/\//.test(a[2]) && a[3] === "--allow-http";
|
|
3018
|
+
}
|
|
2860
3019
|
function orphanedRemoteMcpKeys(mcpServers, expectedIntegrationKeys) {
|
|
2861
3020
|
const orphans = [];
|
|
2862
3021
|
for (const [key, entry] of Object.entries(mcpServers)) {
|
|
2863
3022
|
if (expectedIntegrationKeys.has(key)) continue;
|
|
2864
3023
|
if (isManagedMcpServerKey(key)) continue;
|
|
2865
|
-
if (!isRemoteMcpEntry(entry) && classifyMcpServer(entry) !== "oauth-proxy") continue;
|
|
3024
|
+
if (!isRemoteMcpEntry(entry) && classifyMcpServer(entry) !== "oauth-proxy" && !isSanitizedRemoteBridge(entry)) continue;
|
|
2866
3025
|
orphans.push(key);
|
|
2867
3026
|
}
|
|
2868
3027
|
return orphans;
|
|
2869
3028
|
}
|
|
2870
3029
|
|
|
3030
|
+
// src/lib/spawn-mcp-filter.ts
|
|
3031
|
+
import {
|
|
3032
|
+
closeSync,
|
|
3033
|
+
constants as fsConstants,
|
|
3034
|
+
fchmodSync,
|
|
3035
|
+
fstatSync,
|
|
3036
|
+
ftruncateSync,
|
|
3037
|
+
lstatSync as lstatSync2,
|
|
3038
|
+
mkdirSync as mkdirSync3,
|
|
3039
|
+
openSync,
|
|
3040
|
+
readFileSync as readFileSync7,
|
|
3041
|
+
writeSync
|
|
3042
|
+
} from "fs";
|
|
3043
|
+
import { join as join7 } from "path";
|
|
3044
|
+
import { createHash as createHash4 } from "crypto";
|
|
3045
|
+
var SPAWN_MCP_CONFIG_RELATIVE = join7(".claude", "spawn-mcp.json");
|
|
3046
|
+
var SPAWN_MCP_FILE_MODE = 384;
|
|
3047
|
+
function writeSpawnConfigNoFollow(projectDir, relativePath, content) {
|
|
3048
|
+
const claudeDir = join7(projectDir, ".claude");
|
|
3049
|
+
mkdirSync3(projectDir, { recursive: true });
|
|
3050
|
+
try {
|
|
3051
|
+
mkdirSync3(claudeDir);
|
|
3052
|
+
} catch (err) {
|
|
3053
|
+
if (err.code !== "EEXIST") throw err;
|
|
3054
|
+
}
|
|
3055
|
+
const dirStat = lstatSync2(claudeDir);
|
|
3056
|
+
if (dirStat.isSymbolicLink() || !dirStat.isDirectory()) {
|
|
3057
|
+
throw new Error(`${claudeDir} is not a real directory (refusing to follow it)`);
|
|
3058
|
+
}
|
|
3059
|
+
const path = join7(projectDir, relativePath);
|
|
3060
|
+
const fd = openSync(
|
|
3061
|
+
path,
|
|
3062
|
+
fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK,
|
|
3063
|
+
SPAWN_MCP_FILE_MODE
|
|
3064
|
+
);
|
|
3065
|
+
try {
|
|
3066
|
+
const st = fstatSync(fd);
|
|
3067
|
+
if (!st.isFile()) throw new Error(`${path} is not a regular file (refusing to write it)`);
|
|
3068
|
+
if (st.nlink !== 1) throw new Error(`${path} has ${st.nlink} links (refusing to write through a hard link)`);
|
|
3069
|
+
fchmodSync(fd, SPAWN_MCP_FILE_MODE);
|
|
3070
|
+
ftruncateSync(fd, 0);
|
|
3071
|
+
const bytes = Buffer.from(content, "utf-8");
|
|
3072
|
+
let off = 0;
|
|
3073
|
+
while (off < bytes.length) {
|
|
3074
|
+
const n = writeSync(fd, bytes, off, bytes.length - off);
|
|
3075
|
+
if (n <= 0) throw new Error(`${path}: short write (${off}/${bytes.length} bytes)`);
|
|
3076
|
+
off += n;
|
|
3077
|
+
}
|
|
3078
|
+
} finally {
|
|
3079
|
+
closeSync(fd);
|
|
3080
|
+
}
|
|
3081
|
+
return path;
|
|
3082
|
+
}
|
|
3083
|
+
function filterOrphanRemoteMcpForSpawn(servers, expectedKeys) {
|
|
3084
|
+
const dropped = orphanedRemoteMcpKeys(servers, expectedKeys);
|
|
3085
|
+
if (dropped.length === 0) return { kept: servers, dropped };
|
|
3086
|
+
const kept = {};
|
|
3087
|
+
for (const [key, entry] of Object.entries(servers)) {
|
|
3088
|
+
if (!dropped.includes(key)) kept[key] = entry;
|
|
3089
|
+
}
|
|
3090
|
+
return { kept, dropped };
|
|
3091
|
+
}
|
|
3092
|
+
function spawnViewOfMcpConfig(parsed, integrations) {
|
|
3093
|
+
if (integrations === void 0) return parsed;
|
|
3094
|
+
const servers = parsed["mcpServers"];
|
|
3095
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return parsed;
|
|
3096
|
+
const { kept, dropped } = filterOrphanRemoteMcpForSpawn(servers, expectedRemoteMcpKeys(integrations));
|
|
3097
|
+
return dropped.length === 0 ? parsed : { ...parsed, mcpServers: kept };
|
|
3098
|
+
}
|
|
3099
|
+
function spawnDroppedServerKeys(mcpConfigPath, integrations) {
|
|
3100
|
+
if (integrations === void 0) return /* @__PURE__ */ new Set();
|
|
3101
|
+
try {
|
|
3102
|
+
const parsed = JSON.parse(readFileSync7(mcpConfigPath, "utf-8"));
|
|
3103
|
+
const servers = parsed?.mcpServers;
|
|
3104
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return /* @__PURE__ */ new Set();
|
|
3105
|
+
return new Set(filterOrphanRemoteMcpForSpawn(servers, expectedRemoteMcpKeys(integrations)).dropped);
|
|
3106
|
+
} catch {
|
|
3107
|
+
return /* @__PURE__ */ new Set();
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
function prepareSpawnMcpConfig(input) {
|
|
3111
|
+
const { codeName, projectDir, mcpConfigPath, integrations, apiHost, log: log2, onCopyFailed, onNothingToDrop } = input;
|
|
3112
|
+
if (integrations === void 0) {
|
|
3113
|
+
log2(
|
|
3114
|
+
`[spawn-mcp-filter] ORPHAN_FILTER_SET_UNKNOWN agent='${codeName}': no integration set known in this manager process yet, so the spawn uses .mcp.json unfiltered (filtering against nothing would drop every remote server) (ENG-12048)`
|
|
3115
|
+
);
|
|
3116
|
+
return mcpConfigPath;
|
|
3117
|
+
}
|
|
3118
|
+
let config2;
|
|
3119
|
+
try {
|
|
3120
|
+
config2 = JSON.parse(readFileSync7(mcpConfigPath, "utf-8"));
|
|
3121
|
+
} catch {
|
|
3122
|
+
return mcpConfigPath;
|
|
3123
|
+
}
|
|
3124
|
+
if (!config2 || typeof config2 !== "object" || Array.isArray(config2)) return mcpConfigPath;
|
|
3125
|
+
const rawServers = config2["mcpServers"];
|
|
3126
|
+
if (rawServers !== void 0 && (!rawServers || typeof rawServers !== "object" || Array.isArray(rawServers))) {
|
|
3127
|
+
return mcpConfigPath;
|
|
3128
|
+
}
|
|
3129
|
+
const servers = rawServers ?? {};
|
|
3130
|
+
const { dropped } = filterOrphanRemoteMcpForSpawn(servers, expectedRemoteMcpKeys(integrations));
|
|
3131
|
+
if (dropped.length === 0) {
|
|
3132
|
+
onNothingToDrop?.();
|
|
3133
|
+
return mcpConfigPath;
|
|
3134
|
+
}
|
|
3135
|
+
try {
|
|
3136
|
+
sanitizeMcpJson(mcpConfigPath, apiHost);
|
|
3137
|
+
const reread = JSON.parse(readFileSync7(mcpConfigPath, "utf-8"));
|
|
3138
|
+
if (reread && typeof reread === "object" && !Array.isArray(reread)) config2 = reread;
|
|
3139
|
+
} catch {
|
|
3140
|
+
}
|
|
3141
|
+
const afterSanitise = config2["mcpServers"] ?? {};
|
|
3142
|
+
const droppedAfterSanitise = filterOrphanRemoteMcpForSpawn(afterSanitise, expectedRemoteMcpKeys(integrations)).dropped;
|
|
3143
|
+
const neverLoad = /* @__PURE__ */ new Set([...dropped, ...droppedAfterSanitise]);
|
|
3144
|
+
const keptAfterSanitise = Object.fromEntries(Object.entries(afterSanitise).filter(([key]) => !neverLoad.has(key)));
|
|
3145
|
+
let spawnPath;
|
|
3146
|
+
try {
|
|
3147
|
+
spawnPath = writeSpawnConfigNoFollow(
|
|
3148
|
+
projectDir,
|
|
3149
|
+
SPAWN_MCP_CONFIG_RELATIVE,
|
|
3150
|
+
`${JSON.stringify({ ...config2, mcpServers: keptAfterSanitise }, null, 2)}
|
|
3151
|
+
`
|
|
3152
|
+
);
|
|
3153
|
+
} catch (err) {
|
|
3154
|
+
log2(
|
|
3155
|
+
`[spawn-mcp-filter] ORPHAN_SPAWN_UNFILTERED agent='${codeName}' servers=${dropped.map((k) => `'${k}'`).join(", ")} reason=could not write the filtered spawn config (${err.message}). The session starts WITH these removed integrations' servers (ENG-12048)`
|
|
3156
|
+
);
|
|
3157
|
+
onCopyFailed?.({ dropped: [...neverLoad], error: err.message });
|
|
3158
|
+
return mcpConfigPath;
|
|
3159
|
+
}
|
|
3160
|
+
log2(
|
|
3161
|
+
`[spawn-mcp-filter] '${codeName}': session starts WITHOUT orphaned remote MCP server(s) ${dropped.map((k) => `'${k}'`).join(", ")} (integration removed; .mcp.json still declares them) (ENG-12048)`
|
|
3162
|
+
);
|
|
3163
|
+
return spawnPath;
|
|
3164
|
+
}
|
|
3165
|
+
function hashMcpConfig(config2) {
|
|
3166
|
+
return createHash4("sha256").update(canonicalJson(config2)).digest("hex");
|
|
3167
|
+
}
|
|
3168
|
+
var SPAWN_COPY_RETRY_INTERVAL_MS = 5 * 6e4;
|
|
3169
|
+
var SpawnCopyFailureTracker = class {
|
|
3170
|
+
constructor(retryIntervalMs = SPAWN_COPY_RETRY_INTERVAL_MS) {
|
|
3171
|
+
this.retryIntervalMs = retryIntervalMs;
|
|
3172
|
+
}
|
|
3173
|
+
failures = /* @__PURE__ */ new Map();
|
|
3174
|
+
/** When the copy write was last attempted for a held agent (spawn or retry). */
|
|
3175
|
+
lastAttemptMs = /* @__PURE__ */ new Map();
|
|
3176
|
+
/** Record a fail-open spawn. Returns true when this ENTERS (or changes) the state. */
|
|
3177
|
+
noteFailure(codeName, failure, nowMs = Date.now()) {
|
|
3178
|
+
const prev = this.failures.get(codeName);
|
|
3179
|
+
this.failures.set(codeName, failure);
|
|
3180
|
+
this.lastAttemptMs.set(codeName, nowMs);
|
|
3181
|
+
return !prev || prev.rawHash !== failure.rawHash;
|
|
3182
|
+
}
|
|
3183
|
+
/** A spawn wrote its copy (or had nothing to drop). Returns true when this cleared a failure. */
|
|
3184
|
+
noteSuccess(codeName) {
|
|
3185
|
+
this.lastAttemptMs.delete(codeName);
|
|
3186
|
+
return this.failures.delete(codeName);
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* Obi Wan c7b7dea6ccc0: the hold is keyed on the raw file, but the spawn view
|
|
3190
|
+
* also changes when the integration set does (a SECOND removal whose prune is
|
|
3191
|
+
* also refused). Record the servers the view drops NOW, so the per-poll log
|
|
3192
|
+
* and alert name the new one. Returns true when the set changed. Never starts
|
|
3193
|
+
* or ends a hold.
|
|
3194
|
+
*/
|
|
3195
|
+
noteDropped(codeName, dropped) {
|
|
3196
|
+
const f = this.failures.get(codeName);
|
|
3197
|
+
if (!f || dropped.length === 0) return false;
|
|
3198
|
+
const next = [...new Set(dropped)].sort();
|
|
3199
|
+
if (next.join("\0") === [...f.dropped].sort().join("\0")) return false;
|
|
3200
|
+
this.failures.set(codeName, { ...f, dropped: next });
|
|
3201
|
+
return true;
|
|
3202
|
+
}
|
|
3203
|
+
/** The failure currently held for an agent, or null. */
|
|
3204
|
+
held(codeName) {
|
|
3205
|
+
return this.failures.get(codeName) ?? null;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* CodeRabbit on c464bd3a: while held, is a retry of the copy write due? True
|
|
3209
|
+
* at most once per interval per agent (the call stamps the attempt), and
|
|
3210
|
+
* never when nothing is held. A failed retry goes back through noteFailure.
|
|
3211
|
+
*/
|
|
3212
|
+
retryDue(codeName, nowMs = Date.now()) {
|
|
3213
|
+
if (!this.failures.has(codeName)) return false;
|
|
3214
|
+
const last = this.lastAttemptMs.get(codeName);
|
|
3215
|
+
if (last !== void 0 && nowMs - last < this.retryIntervalMs) return false;
|
|
3216
|
+
this.lastAttemptMs.set(codeName, nowMs);
|
|
3217
|
+
return true;
|
|
3218
|
+
}
|
|
3219
|
+
/**
|
|
3220
|
+
* Should a drift restart be held? While the recorded raw hash is unchanged,
|
|
3221
|
+
* or unknown (an unreadable read is not a change). A changed raw file clears
|
|
3222
|
+
* the state and returns null.
|
|
3223
|
+
*/
|
|
3224
|
+
holdsDriftRestart(codeName, currentRawHash) {
|
|
3225
|
+
const f = this.failures.get(codeName);
|
|
3226
|
+
if (!f) return null;
|
|
3227
|
+
if (currentRawHash !== null && currentRawHash !== f.rawHash) {
|
|
3228
|
+
this.failures.delete(codeName);
|
|
3229
|
+
this.lastAttemptMs.delete(codeName);
|
|
3230
|
+
return null;
|
|
3231
|
+
}
|
|
3232
|
+
return f;
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
function retryHeldSpawnCopy(input) {
|
|
3236
|
+
const { tracker, codeName, projectDir, held, integrations, resolveApiHost, log: log2, nowMs = Date.now() } = input;
|
|
3237
|
+
if (integrations === void 0) return held;
|
|
3238
|
+
const mcpConfigPath = join7(projectDir, ".mcp.json");
|
|
3239
|
+
const outcome = {
|
|
3240
|
+
failed: null,
|
|
3241
|
+
nothingToDrop: false
|
|
3242
|
+
};
|
|
3243
|
+
let written;
|
|
3244
|
+
try {
|
|
3245
|
+
written = prepareSpawnMcpConfig({
|
|
3246
|
+
codeName,
|
|
3247
|
+
projectDir,
|
|
3248
|
+
mcpConfigPath,
|
|
3249
|
+
integrations,
|
|
3250
|
+
apiHost: resolveApiHost?.(),
|
|
3251
|
+
log: log2,
|
|
3252
|
+
onCopyFailed: (info) => {
|
|
3253
|
+
outcome.failed = info;
|
|
3254
|
+
},
|
|
3255
|
+
onNothingToDrop: () => {
|
|
3256
|
+
outcome.nothingToDrop = true;
|
|
3257
|
+
}
|
|
3258
|
+
});
|
|
3259
|
+
} catch (err) {
|
|
3260
|
+
outcome.failed = { dropped: held.dropped, error: err instanceof Error ? err.message : String(err) };
|
|
3261
|
+
written = mcpConfigPath;
|
|
3262
|
+
}
|
|
3263
|
+
if (!outcome.failed && outcome.nothingToDrop) {
|
|
3264
|
+
tracker.noteSuccess(codeName);
|
|
3265
|
+
log2(`[spawn-mcp-filter] ORPHAN_SPAWN_COPY_NOT_NEEDED agent='${codeName}': the config no longer drops any server, so the copy-failure hold ends; drift is judged normally again (ENG-12048)`);
|
|
3266
|
+
return null;
|
|
3267
|
+
}
|
|
3268
|
+
if (outcome.failed || written === mcpConfigPath) {
|
|
3269
|
+
const still = { ...held, ...outcome.failed ?? {} };
|
|
3270
|
+
tracker.noteFailure(codeName, still, nowMs);
|
|
3271
|
+
return still;
|
|
3272
|
+
}
|
|
3273
|
+
tracker.noteSuccess(codeName);
|
|
3274
|
+
log2(`[spawn-mcp-filter] ORPHAN_SPAWN_COPY_RECOVERED agent='${codeName}': the filtered spawn config was written on retry; drift is judged normally again (ENG-12048)`);
|
|
3275
|
+
return null;
|
|
3276
|
+
}
|
|
3277
|
+
|
|
2871
3278
|
// src/lib/auto-resume.ts
|
|
2872
3279
|
var DEFAULT_QUIET_MS = 18e5;
|
|
2873
3280
|
var DEFAULT_BACKOFF_RESET_MS = 864e5;
|
|
@@ -3089,12 +3496,12 @@ function stopAgentRuntime(codeName, reason, log2, deps) {
|
|
|
3089
3496
|
}
|
|
3090
3497
|
|
|
3091
3498
|
// src/lib/opencode-credential-fingerprint.ts
|
|
3092
|
-
import { createHash as
|
|
3499
|
+
import { createHash as createHash5 } from "crypto";
|
|
3093
3500
|
var FINGERPRINT_LENGTH = 16;
|
|
3094
3501
|
var ABSENT = "none";
|
|
3095
3502
|
function fingerprintOf(secret) {
|
|
3096
3503
|
if (!secret) return ABSENT;
|
|
3097
|
-
return
|
|
3504
|
+
return createHash5("sha256").update(secret, "utf8").digest("hex").slice(0, FINGERPRINT_LENGTH);
|
|
3098
3505
|
}
|
|
3099
3506
|
function opencodeCredentialFingerprint(inputs) {
|
|
3100
3507
|
const openRouter = inputs.openRouterToken ? inputs.openRouterFingerprint || fingerprintOf(inputs.openRouterToken) : ABSENT;
|
|
@@ -3286,9 +3693,9 @@ var DependencyRecoveryLedger = class {
|
|
|
3286
3693
|
// src/lib/mcp-assets-ready.ts
|
|
3287
3694
|
import { existsSync as nodeExistsSync, readFileSync as nodeReadFileSync } from "fs";
|
|
3288
3695
|
import { homedir as homedir2 } from "os";
|
|
3289
|
-
import { join as
|
|
3696
|
+
import { join as join8, resolve, sep } from "path";
|
|
3290
3697
|
function getSharedMcpDir(homeDir = homedir2()) {
|
|
3291
|
-
return
|
|
3698
|
+
return join8(homeDir, ".augmented", "_mcp");
|
|
3292
3699
|
}
|
|
3293
3700
|
function isPathInsideDir(candidate, dir) {
|
|
3294
3701
|
const resolvedDir = resolve(dir);
|
|
@@ -3298,11 +3705,11 @@ function isPathInsideDir(candidate, dir) {
|
|
|
3298
3705
|
}
|
|
3299
3706
|
function findMissingMcpBundles(mcpConfigPath, deps = {}) {
|
|
3300
3707
|
const existsSync21 = deps.existsSync ?? nodeExistsSync;
|
|
3301
|
-
const
|
|
3708
|
+
const readFileSync38 = deps.readFileSync ?? nodeReadFileSync;
|
|
3302
3709
|
const mcpDir = deps.mcpDir ?? getSharedMcpDir();
|
|
3303
3710
|
let parsed;
|
|
3304
3711
|
try {
|
|
3305
|
-
parsed = JSON.parse(
|
|
3712
|
+
parsed = JSON.parse(readFileSync38(mcpConfigPath, "utf-8"));
|
|
3306
3713
|
} catch {
|
|
3307
3714
|
return [];
|
|
3308
3715
|
}
|
|
@@ -3311,6 +3718,7 @@ function findMissingMcpBundles(mcpConfigPath, deps = {}) {
|
|
|
3311
3718
|
const missing = [];
|
|
3312
3719
|
const seenPaths = /* @__PURE__ */ new Set();
|
|
3313
3720
|
for (const [key, rawEntry] of Object.entries(servers)) {
|
|
3721
|
+
if (deps.skipKeys?.has(key)) continue;
|
|
3314
3722
|
if (!rawEntry || typeof rawEntry !== "object" || Array.isArray(rawEntry)) continue;
|
|
3315
3723
|
const entry = rawEntry;
|
|
3316
3724
|
if (entry.command !== "node") continue;
|
|
@@ -3340,7 +3748,7 @@ function formatMissingMcpBundles(missing) {
|
|
|
3340
3748
|
}
|
|
3341
3749
|
|
|
3342
3750
|
// src/lib/self-update-coalesce.ts
|
|
3343
|
-
import { readFileSync as
|
|
3751
|
+
import { readFileSync as readFileSync8, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "fs";
|
|
3344
3752
|
import { dirname as dirname4 } from "path";
|
|
3345
3753
|
var DEFAULT_SELF_UPDATE_COALESCE_MS = 30 * 60 * 1e3;
|
|
3346
3754
|
function resolveCoalesceWindowMs(env = process.env) {
|
|
@@ -3350,7 +3758,7 @@ function resolveCoalesceWindowMs(env = process.env) {
|
|
|
3350
3758
|
if (!Number.isFinite(parsed) || parsed < 0) return DEFAULT_SELF_UPDATE_COALESCE_MS;
|
|
3351
3759
|
return Math.trunc(parsed);
|
|
3352
3760
|
}
|
|
3353
|
-
function readLastSelfUpdateAppliedMs(markerPath, now = Date.now(), read = (p) =>
|
|
3761
|
+
function readLastSelfUpdateAppliedMs(markerPath, now = Date.now(), read = (p) => readFileSync8(p, "utf-8")) {
|
|
3354
3762
|
let raw;
|
|
3355
3763
|
try {
|
|
3356
3764
|
raw = read(markerPath);
|
|
@@ -3363,7 +3771,7 @@ function readLastSelfUpdateAppliedMs(markerPath, now = Date.now(), read = (p) =>
|
|
|
3363
3771
|
return v;
|
|
3364
3772
|
}
|
|
3365
3773
|
function stampLastSelfUpdateApplied(markerPath, now = Date.now(), write = (p, v) => {
|
|
3366
|
-
|
|
3774
|
+
mkdirSync4(dirname4(p), { recursive: true });
|
|
3367
3775
|
writeFileSync4(p, v);
|
|
3368
3776
|
}) {
|
|
3369
3777
|
try {
|
|
@@ -3655,11 +4063,11 @@ async function reportModelApiError(opts) {
|
|
|
3655
4063
|
}
|
|
3656
4064
|
|
|
3657
4065
|
// src/lib/claude-pid-tracker.ts
|
|
3658
|
-
import { existsSync, readFileSync as
|
|
4066
|
+
import { existsSync, readFileSync as readFileSync9 } from "fs";
|
|
3659
4067
|
function readPidFile(path) {
|
|
3660
4068
|
if (!existsSync(path)) return { version: 1, spawns: [] };
|
|
3661
4069
|
try {
|
|
3662
|
-
const raw = JSON.parse(
|
|
4070
|
+
const raw = JSON.parse(readFileSync9(path, "utf-8"));
|
|
3663
4071
|
if (raw.version !== 1 || !Array.isArray(raw.spawns)) return { version: 1, spawns: [] };
|
|
3664
4072
|
const spawns = raw.spawns.filter(
|
|
3665
4073
|
(s) => !!s && typeof s.pid === "number" && Number.isFinite(s.pid) && s.pid > 0
|
|
@@ -3759,14 +4167,14 @@ async function killSessionsConcurrently(sessions, killOne) {
|
|
|
3759
4167
|
}
|
|
3760
4168
|
|
|
3761
4169
|
// src/lib/direct-chat-delivery.ts
|
|
3762
|
-
import { join as
|
|
4170
|
+
import { join as join9 } from "path";
|
|
3763
4171
|
var DEFAULT_DIRECT_CHAT_MAX_AGE_MS = 30 * 6e4;
|
|
3764
4172
|
function directChatMaxAgeMs() {
|
|
3765
4173
|
const raw = parseInt(process.env["AGT_DIRECT_CHAT_MAX_AGE_MS"] ?? "", 10);
|
|
3766
4174
|
return Number.isFinite(raw) && raw >= 0 ? raw : DEFAULT_DIRECT_CHAT_MAX_AGE_MS;
|
|
3767
4175
|
}
|
|
3768
4176
|
function directChatDoorbellPath(agentId, home) {
|
|
3769
|
-
return
|
|
4177
|
+
return join9(home, ".augmented", agentId, "direct-chat-doorbell");
|
|
3770
4178
|
}
|
|
3771
4179
|
function isDirectChatMessageExpired(createdAt, nowMs, maxAgeMs) {
|
|
3772
4180
|
if (!maxAgeMs || maxAgeMs <= 0) return false;
|
|
@@ -3777,8 +4185,8 @@ function isDirectChatMessageExpired(createdAt, nowMs, maxAgeMs) {
|
|
|
3777
4185
|
}
|
|
3778
4186
|
|
|
3779
4187
|
// src/lib/review-poster-asset.ts
|
|
3780
|
-
import { copyFileSync as copyFileSync2, chmodSync, existsSync as existsSync2, mkdirSync as
|
|
3781
|
-
import { dirname as dirname5, join as
|
|
4188
|
+
import { copyFileSync as copyFileSync2, chmodSync, existsSync as existsSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10 } from "fs";
|
|
4189
|
+
import { dirname as dirname5, join as join10 } from "path";
|
|
3782
4190
|
import { fileURLToPath } from "url";
|
|
3783
4191
|
var POSTER_FILENAME = "post-review-findings.mjs";
|
|
3784
4192
|
var AUTH_FILENAME = "obiwan-auth.mjs";
|
|
@@ -3791,14 +4199,14 @@ function resolveBundledReviewAssetDir() {
|
|
|
3791
4199
|
const moduleDir = dirname5(fileURLToPath(import.meta.url));
|
|
3792
4200
|
const candidates = [
|
|
3793
4201
|
// Built output: dist/<chunk>.js → dist/assets/review
|
|
3794
|
-
|
|
4202
|
+
join10(moduleDir, "assets", REVIEW_ASSET_DIRNAME),
|
|
3795
4203
|
// Built output sibling case: dist/<sub>/<chunk>.js → dist/assets/review
|
|
3796
|
-
|
|
4204
|
+
join10(moduleDir, "..", "assets", REVIEW_ASSET_DIRNAME),
|
|
3797
4205
|
// Dev source: src/lib/review-poster-asset.ts → ../../assets/review
|
|
3798
|
-
|
|
4206
|
+
join10(moduleDir, "..", "..", "assets", REVIEW_ASSET_DIRNAME)
|
|
3799
4207
|
];
|
|
3800
4208
|
for (const candidate of candidates) {
|
|
3801
|
-
if (existsSync2(
|
|
4209
|
+
if (existsSync2(join10(candidate, POSTER_FILENAME))) return candidate;
|
|
3802
4210
|
}
|
|
3803
4211
|
throw new Error(
|
|
3804
4212
|
`[review-poster] could not locate bundled assets; tried:
|
|
@@ -3806,18 +4214,18 @@ function resolveBundledReviewAssetDir() {
|
|
|
3806
4214
|
);
|
|
3807
4215
|
}
|
|
3808
4216
|
function reviewPosterDir(codeName) {
|
|
3809
|
-
return
|
|
4217
|
+
return join10(getFramework("claude-code").getAgentDir(codeName), REVIEW_ASSET_DIRNAME);
|
|
3810
4218
|
}
|
|
3811
4219
|
function provisionReviewPoster(codeName, sourceDir = resolveBundledReviewAssetDir()) {
|
|
3812
4220
|
const destDir = reviewPosterDir(codeName);
|
|
3813
|
-
|
|
4221
|
+
mkdirSync5(destDir, { recursive: true });
|
|
3814
4222
|
for (const [name, mode] of ASSET_FILES) {
|
|
3815
|
-
const src =
|
|
3816
|
-
const dest =
|
|
4223
|
+
const src = join10(sourceDir, name);
|
|
4224
|
+
const dest = join10(destDir, name);
|
|
3817
4225
|
if (!existsSync2(src)) {
|
|
3818
4226
|
throw new Error(`[review-poster] bundled asset missing: ${src}`);
|
|
3819
4227
|
}
|
|
3820
|
-
if (!existsSync2(dest) || !
|
|
4228
|
+
if (!existsSync2(dest) || !readFileSync10(src).equals(readFileSync10(dest))) {
|
|
3821
4229
|
copyFileSync2(src, dest);
|
|
3822
4230
|
}
|
|
3823
4231
|
chmodSync(dest, mode);
|
|
@@ -3825,8 +4233,8 @@ function provisionReviewPoster(codeName, sourceDir = resolveBundledReviewAssetDi
|
|
|
3825
4233
|
}
|
|
3826
4234
|
|
|
3827
4235
|
// src/lib/scratch-sweep-policy.ts
|
|
3828
|
-
import { existsSync as existsSync3, mkdirSync as
|
|
3829
|
-
import { join as
|
|
4236
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync6, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
|
|
4237
|
+
import { join as join11 } from "path";
|
|
3830
4238
|
var SCRATCH_POLICY_LOG_INTERVAL_MS = 60 * 60 * 1e3;
|
|
3831
4239
|
var SCRATCH_HOLD_LIFT_DELAY_MS = 10 * 60 * 1e3;
|
|
3832
4240
|
var SCRATCH_HOLD_MAX_OBSERVATION_GAP_MS = 5 * 60 * 1e3;
|
|
@@ -3857,9 +4265,9 @@ function resolveScratchSweepPolicy(input) {
|
|
|
3857
4265
|
note(input, "kept=all reason=invalid-agent-id");
|
|
3858
4266
|
return HELD;
|
|
3859
4267
|
}
|
|
3860
|
-
const marker =
|
|
4268
|
+
const marker = join11(input.holdsDir, input.agentId);
|
|
3861
4269
|
if (unrecordedHolds.has(input.agentId) || input.flag("scratch-sweep-held", input.agentId)) {
|
|
3862
|
-
|
|
4270
|
+
mkdirSync6(input.holdsDir, { recursive: true });
|
|
3863
4271
|
writeFileSync5(marker, HELD_MARKER);
|
|
3864
4272
|
unrecordedHolds.delete(input.agentId);
|
|
3865
4273
|
return HELD;
|
|
@@ -3872,7 +4280,7 @@ function resolveScratchSweepPolicy(input) {
|
|
|
3872
4280
|
return HELD;
|
|
3873
4281
|
}
|
|
3874
4282
|
const now = (input.now ?? Date.now)();
|
|
3875
|
-
const off = OFF_SINCE.exec(
|
|
4283
|
+
const off = OFF_SINCE.exec(readFileSync11(marker, "utf8"));
|
|
3876
4284
|
if (!off) {
|
|
3877
4285
|
writeFileSync5(marker, offSince(now, now));
|
|
3878
4286
|
return HELD;
|
|
@@ -3895,7 +4303,7 @@ function resolveScratchSweepPolicy(input) {
|
|
|
3895
4303
|
rmSync2(marker, { force: true });
|
|
3896
4304
|
}
|
|
3897
4305
|
if (state10 === "not-evaluated") {
|
|
3898
|
-
|
|
4306
|
+
mkdirSync6(input.holdsDir, { recursive: true });
|
|
3899
4307
|
writeFileSync5(marker, HELD_MARKER);
|
|
3900
4308
|
note(input, "kept=all reason=agent-not-evaluated");
|
|
3901
4309
|
return HELD;
|
|
@@ -3925,15 +4333,15 @@ function recordScratchHoldsFromHeartbeat(input) {
|
|
|
3925
4333
|
let held = false;
|
|
3926
4334
|
try {
|
|
3927
4335
|
held = input.flag("scratch-sweep-held", id);
|
|
3928
|
-
const marker =
|
|
4336
|
+
const marker = join11(input.holdsDir, id);
|
|
3929
4337
|
if (held) {
|
|
3930
|
-
|
|
4338
|
+
mkdirSync6(input.holdsDir, { recursive: true });
|
|
3931
4339
|
writeFileSync5(marker, HELD_MARKER);
|
|
3932
4340
|
unrecordedHolds.delete(id);
|
|
3933
4341
|
continue;
|
|
3934
4342
|
}
|
|
3935
4343
|
if (!existsSync3(marker)) continue;
|
|
3936
|
-
const off = OFF_SINCE.exec(
|
|
4344
|
+
const off = OFF_SINCE.exec(readFileSync11(marker, "utf8"));
|
|
3937
4345
|
if (!off) continue;
|
|
3938
4346
|
const since = Number(off[1]);
|
|
3939
4347
|
const seen = Number(off[2] ?? off[1]);
|
|
@@ -3949,8 +4357,8 @@ function recordScratchHoldsFromHeartbeat(input) {
|
|
|
3949
4357
|
for (const id of input.hostAgentIds ?? []) {
|
|
3950
4358
|
if (!safe(id) || evaluated.has(id)) continue;
|
|
3951
4359
|
try {
|
|
3952
|
-
|
|
3953
|
-
writeFileSync5(
|
|
4360
|
+
mkdirSync6(input.holdsDir, { recursive: true });
|
|
4361
|
+
writeFileSync5(join11(input.holdsDir, id), HELD_MARKER);
|
|
3954
4362
|
} catch (err) {
|
|
3955
4363
|
unrecordedHolds.add(id);
|
|
3956
4364
|
const code = err?.code ?? "unknown";
|
|
@@ -3961,8 +4369,8 @@ function recordScratchHoldsFromHeartbeat(input) {
|
|
|
3961
4369
|
}
|
|
3962
4370
|
|
|
3963
4371
|
// src/lib/id-keyed-migration.ts
|
|
3964
|
-
import { existsSync as existsSync4, lstatSync as
|
|
3965
|
-
import { join as
|
|
4372
|
+
import { existsSync as existsSync4, lstatSync as lstatSync3, readlinkSync, renameSync as renameSync2 } from "fs";
|
|
4373
|
+
import { join as join12 } from "path";
|
|
3966
4374
|
import { homedir as homedir3 } from "os";
|
|
3967
4375
|
var ID_KEYED_MIGRATION_FLAG = "id-keyed-layout-migration";
|
|
3968
4376
|
function agentHasActiveWhatsapp(channelConfigs, codeNameDir) {
|
|
@@ -3970,7 +4378,7 @@ function agentHasActiveWhatsapp(channelConfigs, codeNameDir) {
|
|
|
3970
4378
|
return true;
|
|
3971
4379
|
}
|
|
3972
4380
|
try {
|
|
3973
|
-
if (existsSync4(
|
|
4381
|
+
if (existsSync4(join12(codeNameDir, "whatsapp-pending-inbound"))) return true;
|
|
3974
4382
|
} catch {
|
|
3975
4383
|
}
|
|
3976
4384
|
return false;
|
|
@@ -4002,13 +4410,13 @@ function finishTranscriptMove(oldCwd, newCwd, codeName, log2) {
|
|
|
4002
4410
|
function maybeMigrateAgentToIdKeyedLayout(agent, deps) {
|
|
4003
4411
|
const home = deps.home ?? homedir3();
|
|
4004
4412
|
const { code_name: codeName, agent_id: agentId } = agent;
|
|
4005
|
-
const codeNamePath =
|
|
4006
|
-
const idPath =
|
|
4007
|
-
const oldCwd =
|
|
4008
|
-
const newCwd =
|
|
4413
|
+
const codeNamePath = join12(home, ".augmented", codeName);
|
|
4414
|
+
const idPath = join12(home, ".augmented", agentId);
|
|
4415
|
+
const oldCwd = join12(home, ".augmented", codeName, "project");
|
|
4416
|
+
const newCwd = join12(idPath, "project");
|
|
4009
4417
|
let codeNameKind;
|
|
4010
4418
|
try {
|
|
4011
|
-
codeNameKind =
|
|
4419
|
+
codeNameKind = lstatSync3(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
4012
4420
|
} catch {
|
|
4013
4421
|
codeNameKind = "absent";
|
|
4014
4422
|
}
|
|
@@ -4266,7 +4674,7 @@ function decideAuthResolveFailureAction(args) {
|
|
|
4266
4674
|
}
|
|
4267
4675
|
|
|
4268
4676
|
// ../../packages/core/dist/host-config/capture.js
|
|
4269
|
-
import { createHash as
|
|
4677
|
+
import { createHash as createHash6 } from "crypto";
|
|
4270
4678
|
var NON_SECRET_ENV_GATES = [
|
|
4271
4679
|
"AGT_MEMORY_EXTRACTION_ENABLED",
|
|
4272
4680
|
"AGT_CHANNEL_REPLAY_ENABLED",
|
|
@@ -4304,8 +4712,8 @@ function collectEnvGates(env) {
|
|
|
4304
4712
|
}
|
|
4305
4713
|
|
|
4306
4714
|
// ../../packages/core/dist/direct-chat/cursor-advance-telemetry.js
|
|
4307
|
-
import { readFileSync as
|
|
4308
|
-
import { join as
|
|
4715
|
+
import { readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "fs";
|
|
4716
|
+
import { join as join13 } from "path";
|
|
4309
4717
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
4310
4718
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
4311
4719
|
if (!agentDir)
|
|
@@ -4313,10 +4721,10 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
4313
4721
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
4314
4722
|
if (key === null)
|
|
4315
4723
|
return;
|
|
4316
|
-
const path =
|
|
4724
|
+
const path = join13(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
4317
4725
|
const counts = {};
|
|
4318
4726
|
try {
|
|
4319
|
-
const parsed = JSON.parse(
|
|
4727
|
+
const parsed = JSON.parse(readFileSync12(path, "utf-8"));
|
|
4320
4728
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
4321
4729
|
for (const [k, v] of Object.entries(parsed)) {
|
|
4322
4730
|
if (typeof v === "number" && Number.isInteger(v) && v >= 0)
|
|
@@ -4333,7 +4741,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
4333
4741
|
}
|
|
4334
4742
|
|
|
4335
4743
|
// src/lib/artifact-stream.ts
|
|
4336
|
-
import { join as
|
|
4744
|
+
import { join as join14 } from "path";
|
|
4337
4745
|
import { homedir as homedir4 } from "os";
|
|
4338
4746
|
import { readdir, stat, readFile } from "fs/promises";
|
|
4339
4747
|
var ARTEFACT_ENTRY_FILE = "index.html";
|
|
@@ -4419,7 +4827,7 @@ var ArtifactStreamScanner = class {
|
|
|
4419
4827
|
return;
|
|
4420
4828
|
}
|
|
4421
4829
|
for (const name of names) {
|
|
4422
|
-
const file =
|
|
4830
|
+
const file = join14(this.artifactsDir, name, ARTEFACT_ENTRY_FILE);
|
|
4423
4831
|
const mtime = await this.fsDeps.mtimeMs(file).catch(() => null);
|
|
4424
4832
|
if (mtime === null) continue;
|
|
4425
4833
|
if (this.seenMtime.get(name) === mtime) continue;
|
|
@@ -4450,7 +4858,7 @@ var ArtifactStreamScanner = class {
|
|
|
4450
4858
|
}
|
|
4451
4859
|
};
|
|
4452
4860
|
function artifactsDirFor(codeName) {
|
|
4453
|
-
return
|
|
4861
|
+
return join14(homedir4(), ".augmented", codeName, "artifacts");
|
|
4454
4862
|
}
|
|
4455
4863
|
var nodeArtifactFs = {
|
|
4456
4864
|
async listArtefactNames(artifactsDir) {
|
|
@@ -4723,15 +5131,15 @@ async function maybePollHostUsage(deps) {
|
|
|
4723
5131
|
}
|
|
4724
5132
|
|
|
4725
5133
|
// src/lib/claude-account-fingerprint.ts
|
|
4726
|
-
import { createHash as
|
|
5134
|
+
import { createHash as createHash7 } from "crypto";
|
|
4727
5135
|
import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
|
|
4728
5136
|
import { homedir as homedir6, platform as platform2 } from "os";
|
|
4729
|
-
import { dirname as dirname6, join as
|
|
5137
|
+
import { dirname as dirname6, join as join16 } from "path";
|
|
4730
5138
|
|
|
4731
5139
|
// src/lib/claude-auth-detect.ts
|
|
4732
5140
|
import { readFile as readFile2, readdir as readdir2 } from "fs/promises";
|
|
4733
5141
|
import { homedir as homedir5, platform } from "os";
|
|
4734
|
-
import { join as
|
|
5142
|
+
import { join as join15 } from "path";
|
|
4735
5143
|
import { execFile } from "child_process";
|
|
4736
5144
|
import { promisify } from "util";
|
|
4737
5145
|
var execFileAsync = promisify(execFile);
|
|
@@ -4746,16 +5154,16 @@ async function detectClaudeAuth() {
|
|
|
4746
5154
|
}
|
|
4747
5155
|
async function findClaudeCredentialsPaths() {
|
|
4748
5156
|
const candidates = [
|
|
4749
|
-
|
|
4750
|
-
|
|
5157
|
+
join15(homedir5(), ".claude", ".credentials.json"),
|
|
5158
|
+
join15(homedir5(), ".claude", "credentials.json")
|
|
4751
5159
|
];
|
|
4752
5160
|
const isLinuxRoot = platform() === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
4753
5161
|
if (isLinuxRoot) {
|
|
4754
5162
|
try {
|
|
4755
5163
|
const entries = await readdir2("/home", { withFileTypes: true });
|
|
4756
5164
|
for (const entry of entries.filter((entry2) => entry2.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
4757
|
-
candidates.push(
|
|
4758
|
-
candidates.push(
|
|
5165
|
+
candidates.push(join15("/home", entry.name, ".claude", ".credentials.json"));
|
|
5166
|
+
candidates.push(join15("/home", entry.name, ".claude", "credentials.json"));
|
|
4759
5167
|
}
|
|
4760
5168
|
} catch {
|
|
4761
5169
|
}
|
|
@@ -4839,7 +5247,7 @@ async function candidateHomes() {
|
|
|
4839
5247
|
try {
|
|
4840
5248
|
const entries = await readdir3("/home", { withFileTypes: true });
|
|
4841
5249
|
for (const entry of entries.filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
4842
|
-
homes.push(
|
|
5250
|
+
homes.push(join16("/home", entry.name));
|
|
4843
5251
|
}
|
|
4844
5252
|
} catch {
|
|
4845
5253
|
}
|
|
@@ -4859,17 +5267,17 @@ async function homeOfActiveCredentials() {
|
|
|
4859
5267
|
async function claudeConfigCandidatePaths() {
|
|
4860
5268
|
const paths = [];
|
|
4861
5269
|
const configDir = process.env["CLAUDE_CONFIG_DIR"]?.trim();
|
|
4862
|
-
if (configDir) paths.push(
|
|
5270
|
+
if (configDir) paths.push(join16(configDir, ".claude.json"));
|
|
4863
5271
|
const activeHome = await homeOfActiveCredentials();
|
|
4864
|
-
if (activeHome) paths.push(
|
|
5272
|
+
if (activeHome) paths.push(join16(activeHome, ".claude.json"));
|
|
4865
5273
|
for (const home of await candidateHomes()) {
|
|
4866
|
-
const path =
|
|
5274
|
+
const path = join16(home, ".claude.json");
|
|
4867
5275
|
if (!paths.includes(path)) paths.push(path);
|
|
4868
5276
|
}
|
|
4869
5277
|
return paths;
|
|
4870
5278
|
}
|
|
4871
5279
|
function hashAccount(accountUuid, organizationUuid) {
|
|
4872
|
-
return
|
|
5280
|
+
return createHash7("sha256").update(`claude-account:${accountUuid}:${organizationUuid ?? ""}`).digest("hex").slice(0, 12);
|
|
4873
5281
|
}
|
|
4874
5282
|
var ABSENT_CODES = /* @__PURE__ */ new Set(["ENOENT", "ENOTDIR"]);
|
|
4875
5283
|
function errnoCode(err) {
|
|
@@ -5027,11 +5435,11 @@ function diffAuthTuples(recorded, current) {
|
|
|
5027
5435
|
}
|
|
5028
5436
|
|
|
5029
5437
|
// src/lib/account-enforcement-marker.ts
|
|
5030
|
-
import { mkdirSync as
|
|
5438
|
+
import { mkdirSync as mkdirSync7, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "fs";
|
|
5031
5439
|
import { homedir as homedir7 } from "os";
|
|
5032
|
-
import { join as
|
|
5440
|
+
import { join as join17 } from "path";
|
|
5033
5441
|
function accountEnforcementMarkerPath(codeName) {
|
|
5034
|
-
return
|
|
5442
|
+
return join17(homedir7(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
5035
5443
|
}
|
|
5036
5444
|
function syncAccountEnforcementMarker(codeName, level, log2 = (m) => process.stderr.write(`${m}
|
|
5037
5445
|
`), text) {
|
|
@@ -5039,11 +5447,11 @@ function syncAccountEnforcementMarker(codeName, level, log2 = (m) => process.std
|
|
|
5039
5447
|
clearAccountEnforcementMarker(codeName, log2);
|
|
5040
5448
|
return;
|
|
5041
5449
|
}
|
|
5042
|
-
const dir =
|
|
5043
|
-
const path =
|
|
5450
|
+
const dir = join17(homedir7(), ".augmented", codeName);
|
|
5451
|
+
const path = join17(dir, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
5044
5452
|
const tempPath = `${path}.${process.pid}.tmp`;
|
|
5045
5453
|
try {
|
|
5046
|
-
|
|
5454
|
+
mkdirSync7(dir, { recursive: true });
|
|
5047
5455
|
writeFileSync7(tempPath, serializeAccountEnforcementMarker(level, text), "utf-8");
|
|
5048
5456
|
renameSync3(tempPath, path);
|
|
5049
5457
|
} catch (err) {
|
|
@@ -5065,8 +5473,8 @@ function clearAccountEnforcementMarker(codeName, log2 = (m) => process.stderr.wr
|
|
|
5065
5473
|
}
|
|
5066
5474
|
|
|
5067
5475
|
// src/lib/token-usage-monitor.ts
|
|
5068
|
-
import { readdirSync, readFileSync as
|
|
5069
|
-
import { join as
|
|
5476
|
+
import { readdirSync, readFileSync as readFileSync13, statSync } from "fs";
|
|
5477
|
+
import { join as join18 } from "path";
|
|
5070
5478
|
var MIN_CHECK_INTERVAL_MS2 = 6e4;
|
|
5071
5479
|
var TRANSCRIPT_MTIME_WINDOW_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
5072
5480
|
var MAX_ENTRIES_PER_POST = 200;
|
|
@@ -5095,7 +5503,7 @@ async function maybeReportTokenUsage(args) {
|
|
|
5095
5503
|
if (!name.endsWith(".jsonl")) continue;
|
|
5096
5504
|
const sessionId = name.slice(0, -".jsonl".length);
|
|
5097
5505
|
if (!sessionId) continue;
|
|
5098
|
-
const path =
|
|
5506
|
+
const path = join18(dir, name);
|
|
5099
5507
|
let st;
|
|
5100
5508
|
try {
|
|
5101
5509
|
st = statSync(path);
|
|
@@ -5111,7 +5519,7 @@ async function maybeReportTokenUsage(args) {
|
|
|
5111
5519
|
}
|
|
5112
5520
|
let content;
|
|
5113
5521
|
try {
|
|
5114
|
-
content =
|
|
5522
|
+
content = readFileSync13(path, "utf-8");
|
|
5115
5523
|
} catch (err) {
|
|
5116
5524
|
log2(`[token-usage] read failed for '${codeName}/${name}': ${err.message}`);
|
|
5117
5525
|
continue;
|
|
@@ -5192,8 +5600,8 @@ async function maybeReportTokenUsage(args) {
|
|
|
5192
5600
|
}
|
|
5193
5601
|
|
|
5194
5602
|
// src/lib/failing-turn-monitor.ts
|
|
5195
|
-
import { closeSync, openSync, readdirSync as readdirSync2, readSync, statSync as statSync2 } from "fs";
|
|
5196
|
-
import { join as
|
|
5603
|
+
import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync2, readSync, statSync as statSync2 } from "fs";
|
|
5604
|
+
import { join as join19 } from "path";
|
|
5197
5605
|
var MIN_CHECK_INTERVAL_MS3 = 3e4;
|
|
5198
5606
|
var FAILING_TURN_TAIL_BYTES = 512 * 1024;
|
|
5199
5607
|
var ACTIVE_TRANSCRIPT_WINDOW_MS = 60 * 60 * 1e3;
|
|
@@ -5225,7 +5633,7 @@ function newestActiveTranscript(dir, nowMs) {
|
|
|
5225
5633
|
let best = null;
|
|
5226
5634
|
for (const name of names) {
|
|
5227
5635
|
if (!name.endsWith(".jsonl")) continue;
|
|
5228
|
-
const path =
|
|
5636
|
+
const path = join19(dir, name);
|
|
5229
5637
|
try {
|
|
5230
5638
|
const st = statSync2(path);
|
|
5231
5639
|
if (!st.isFile() || nowMs - st.mtimeMs > ACTIVE_TRANSCRIPT_WINDOW_MS) continue;
|
|
@@ -5239,11 +5647,11 @@ function newestActiveTranscript(dir, nowMs) {
|
|
|
5239
5647
|
function readTail(path, size, bytes = FAILING_TURN_TAIL_BYTES) {
|
|
5240
5648
|
const length = Math.min(size, bytes);
|
|
5241
5649
|
const buf = Buffer.alloc(length);
|
|
5242
|
-
const fd =
|
|
5650
|
+
const fd = openSync2(path, "r");
|
|
5243
5651
|
try {
|
|
5244
5652
|
readSync(fd, buf, 0, length, size - length);
|
|
5245
5653
|
} finally {
|
|
5246
|
-
|
|
5654
|
+
closeSync2(fd);
|
|
5247
5655
|
}
|
|
5248
5656
|
return buf.toString("utf-8");
|
|
5249
5657
|
}
|
|
@@ -5297,8 +5705,8 @@ function failingTurnLoops(now = Date.now(), threshold = failingTurnThreshold(),
|
|
|
5297
5705
|
}
|
|
5298
5706
|
|
|
5299
5707
|
// src/lib/session-activity.ts
|
|
5300
|
-
import { closeSync as
|
|
5301
|
-
import { join as
|
|
5708
|
+
import { closeSync as closeSync3, openSync as openSync3, readFileSync as readFileSync14, readSync as readSync2, readdirSync as readdirSync3, statSync as statSync3 } from "fs";
|
|
5709
|
+
import { join as join20 } from "path";
|
|
5302
5710
|
var RULE = /^[─━]{10,}/;
|
|
5303
5711
|
var CARET_LINE = /^\s*❯(\s|$)/;
|
|
5304
5712
|
var NON_BLOCKING_PICKER = { title: "We recommend compacting earlier", footer: "esc not now", kind: "compaction-suggestion" };
|
|
@@ -5358,7 +5766,7 @@ function newestTranscript(dir) {
|
|
|
5358
5766
|
let best = null;
|
|
5359
5767
|
for (const name of names) {
|
|
5360
5768
|
if (!name.endsWith(".jsonl")) continue;
|
|
5361
|
-
const path =
|
|
5769
|
+
const path = join20(dir, name);
|
|
5362
5770
|
try {
|
|
5363
5771
|
const st = statSync3(path);
|
|
5364
5772
|
if (st.isFile() && (best === null || st.mtimeMs > best.mtimeMs)) {
|
|
@@ -5372,7 +5780,7 @@ function newestTranscript(dir) {
|
|
|
5372
5780
|
}
|
|
5373
5781
|
function sessionTranscript(dir, sessionId) {
|
|
5374
5782
|
if (!sessionId) return newestTranscript(dir);
|
|
5375
|
-
const path =
|
|
5783
|
+
const path = join20(dir, `${sessionId}.jsonl`);
|
|
5376
5784
|
try {
|
|
5377
5785
|
const st = statSync3(path);
|
|
5378
5786
|
return st.isFile() ? { path, mtimeMs: st.mtimeMs, size: st.size } : null;
|
|
@@ -5413,12 +5821,12 @@ function scanNewLines(path, size, scan, budget, log2) {
|
|
|
5413
5821
|
const length = Math.min(size - offset, budget);
|
|
5414
5822
|
if (length <= 0) return 0;
|
|
5415
5823
|
const buffer = Buffer.alloc(length);
|
|
5416
|
-
const fd =
|
|
5824
|
+
const fd = openSync3(path, "r");
|
|
5417
5825
|
let read;
|
|
5418
5826
|
try {
|
|
5419
5827
|
read = readSync2(fd, buffer, 0, length, offset);
|
|
5420
5828
|
} finally {
|
|
5421
|
-
|
|
5829
|
+
closeSync3(fd);
|
|
5422
5830
|
}
|
|
5423
5831
|
let window = buffer.subarray(0, read);
|
|
5424
5832
|
let base = offset;
|
|
@@ -5460,7 +5868,7 @@ function subagentFiles(dir) {
|
|
|
5460
5868
|
}
|
|
5461
5869
|
return names.flatMap((name) => {
|
|
5462
5870
|
if (!name.endsWith(".jsonl")) return [];
|
|
5463
|
-
const path =
|
|
5871
|
+
const path = join20(dir, name);
|
|
5464
5872
|
try {
|
|
5465
5873
|
const st = statSync3(path);
|
|
5466
5874
|
return st.isFile() ? [{ path, mtimeMs: st.mtimeMs, size: st.size }] : [];
|
|
@@ -5474,7 +5882,7 @@ function knownProcessStartMs(session) {
|
|
|
5474
5882
|
return session.startedAt === session.estimatedStartedAt ? null : session.startedAt;
|
|
5475
5883
|
}
|
|
5476
5884
|
function drainScan(scan, dir, log2) {
|
|
5477
|
-
const main =
|
|
5885
|
+
const main = join20(dir, `${scan.sessionId}.jsonl`);
|
|
5478
5886
|
let budget = BACKGROUND_SCAN_BYTES_PER_POLL;
|
|
5479
5887
|
try {
|
|
5480
5888
|
budget -= scanNewLines(main, statSync3(main).size, scan, budget, log2);
|
|
@@ -5491,7 +5899,7 @@ function readBackgroundActivity(codeName, dir, sessionId, spawnedAtMs, isSpawnSe
|
|
|
5491
5899
|
const sameRun = prev?.sessionId === sessionId && prev.spawnedAtMs === spawnedAtMs;
|
|
5492
5900
|
if (prev && sameRun && minCheckMs > 0 && nowMs - prev.checkedAt < minCheckMs) return prev;
|
|
5493
5901
|
try {
|
|
5494
|
-
const main =
|
|
5902
|
+
const main = join20(dir, `${sessionId}.jsonl`);
|
|
5495
5903
|
let size;
|
|
5496
5904
|
try {
|
|
5497
5905
|
size = statSync3(main).size;
|
|
@@ -5539,7 +5947,7 @@ function readBackgroundActivity(codeName, dir, sessionId, spawnedAtMs, isSpawnSe
|
|
|
5539
5947
|
}
|
|
5540
5948
|
function readRecordedSession(agentDir) {
|
|
5541
5949
|
try {
|
|
5542
|
-
const parsed = JSON.parse(
|
|
5950
|
+
const parsed = JSON.parse(readFileSync14(join20(agentDir, "session-state.json"), "utf-8"));
|
|
5543
5951
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
5544
5952
|
const { session_id: sessionId, recorded_at: recordedAtMs } = parsed;
|
|
5545
5953
|
if (typeof sessionId !== "string" || typeof recordedAtMs !== "number" || !Number.isFinite(recordedAtMs)) return null;
|
|
@@ -5631,8 +6039,8 @@ function buildSessionActivityReport(args) {
|
|
|
5631
6039
|
}
|
|
5632
6040
|
|
|
5633
6041
|
// src/lib/workflow-run-reconciler.ts
|
|
5634
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
5635
|
-
import { join as
|
|
6042
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync4 } from "fs";
|
|
6043
|
+
import { join as join21 } from "path";
|
|
5636
6044
|
var MIN_CHECK_INTERVAL_MS4 = 5 * 6e4;
|
|
5637
6045
|
var SETTLE_MS = 3e4;
|
|
5638
6046
|
var TRANSCRIPT_MTIME_WINDOW_MS2 = 2 * 24 * 60 * 60 * 1e3;
|
|
@@ -5671,7 +6079,7 @@ function collectJsonlRecursive(dir, minMtimeMs, out, depth) {
|
|
|
5671
6079
|
return;
|
|
5672
6080
|
}
|
|
5673
6081
|
for (const name of entries) {
|
|
5674
|
-
const p =
|
|
6082
|
+
const p = join21(dir, name);
|
|
5675
6083
|
let st;
|
|
5676
6084
|
try {
|
|
5677
6085
|
st = statSync4(p);
|
|
@@ -5694,7 +6102,7 @@ function enumerateTranscriptFiles(transcriptDir, nowMs, minMtimeMs = nowMs - TRA
|
|
|
5694
6102
|
return out;
|
|
5695
6103
|
}
|
|
5696
6104
|
for (const name of entries) {
|
|
5697
|
-
const path =
|
|
6105
|
+
const path = join21(transcriptDir, name);
|
|
5698
6106
|
let st;
|
|
5699
6107
|
try {
|
|
5700
6108
|
st = statSync4(path);
|
|
@@ -5706,7 +6114,7 @@ function enumerateTranscriptFiles(transcriptDir, nowMs, minMtimeMs = nowMs - TRA
|
|
|
5706
6114
|
continue;
|
|
5707
6115
|
}
|
|
5708
6116
|
if (st.isDirectory()) {
|
|
5709
|
-
collectJsonlRecursive(
|
|
6117
|
+
collectJsonlRecursive(join21(path, "subagents"), minMtimeMs, out, 0);
|
|
5710
6118
|
}
|
|
5711
6119
|
}
|
|
5712
6120
|
return out;
|
|
@@ -5750,7 +6158,7 @@ async function maybeReconcileWorkflowRunTokens(args) {
|
|
|
5750
6158
|
const contents = [];
|
|
5751
6159
|
for (const path of files) {
|
|
5752
6160
|
try {
|
|
5753
|
-
contents.push(
|
|
6161
|
+
contents.push(readFileSync15(path, "utf-8"));
|
|
5754
6162
|
} catch {
|
|
5755
6163
|
}
|
|
5756
6164
|
}
|
|
@@ -5795,8 +6203,8 @@ async function maybeReconcileWorkflowRunTokens(args) {
|
|
|
5795
6203
|
}
|
|
5796
6204
|
|
|
5797
6205
|
// src/lib/conversation-evaluator.ts
|
|
5798
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
5799
|
-
import { join as
|
|
6206
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync16, statSync as statSync5 } from "fs";
|
|
6207
|
+
import { join as join22 } from "path";
|
|
5800
6208
|
|
|
5801
6209
|
// src/lib/detect-meta-egress.ts
|
|
5802
6210
|
var REPOST_PREAMBLE_WINDOW = 200;
|
|
@@ -6281,7 +6689,7 @@ function readRecentTurns(dir, nowMs) {
|
|
|
6281
6689
|
return;
|
|
6282
6690
|
}
|
|
6283
6691
|
for (const ent of entries) {
|
|
6284
|
-
const full =
|
|
6692
|
+
const full = join22(d, ent.name);
|
|
6285
6693
|
if (ent.isDirectory()) {
|
|
6286
6694
|
visit(full);
|
|
6287
6695
|
continue;
|
|
@@ -6296,7 +6704,7 @@ function readRecentTurns(dir, nowMs) {
|
|
|
6296
6704
|
if (nowMs - mtimeMs > TRANSCRIPT_MTIME_WINDOW_MS3) continue;
|
|
6297
6705
|
let content;
|
|
6298
6706
|
try {
|
|
6299
|
-
content =
|
|
6707
|
+
content = readFileSync16(full, "utf8");
|
|
6300
6708
|
} catch {
|
|
6301
6709
|
continue;
|
|
6302
6710
|
}
|
|
@@ -6669,22 +7077,22 @@ async function reportSkip2(api2, agentId, conversationId, log2, codeName) {
|
|
|
6669
7077
|
|
|
6670
7078
|
// src/lib/tool-call-audit.ts
|
|
6671
7079
|
import { homedir as homedir11 } from "os";
|
|
6672
|
-
import { join as
|
|
7080
|
+
import { join as join27 } from "path";
|
|
6673
7081
|
|
|
6674
7082
|
// src/lib/agent-logging-mode.ts
|
|
6675
|
-
import { readFileSync as
|
|
7083
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
6676
7084
|
import { homedir as homedir8 } from "os";
|
|
6677
|
-
import { join as
|
|
7085
|
+
import { join as join23 } from "path";
|
|
6678
7086
|
var LOGGING_MODES = ["hash-only", "redacted", "full-local"];
|
|
6679
7087
|
function charterPath(codeName, homeDir) {
|
|
6680
7088
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir8());
|
|
6681
7089
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
6682
|
-
return
|
|
7090
|
+
return join23(home, ".augmented", key, "provision", "CHARTER.md");
|
|
6683
7091
|
}
|
|
6684
7092
|
function readAgentLoggingMode(codeName, homeDir) {
|
|
6685
7093
|
let raw;
|
|
6686
7094
|
try {
|
|
6687
|
-
raw =
|
|
7095
|
+
raw = readFileSync17(charterPath(codeName, homeDir), "utf-8");
|
|
6688
7096
|
} catch {
|
|
6689
7097
|
return { mode: null, reason: "no-charter" };
|
|
6690
7098
|
}
|
|
@@ -6708,15 +7116,15 @@ function loggingModeWithholdsTargets(reading) {
|
|
|
6708
7116
|
|
|
6709
7117
|
// src/lib/tool-call-path-salt.ts
|
|
6710
7118
|
import { randomBytes } from "crypto";
|
|
6711
|
-
import { existsSync as existsSync5, mkdirSync as
|
|
7119
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync8, readFileSync as readFileSync18, renameSync as renameSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync8 } from "fs";
|
|
6712
7120
|
import { homedir as homedir9 } from "os";
|
|
6713
|
-
import { dirname as dirname7, join as
|
|
7121
|
+
import { dirname as dirname7, join as join24 } from "path";
|
|
6714
7122
|
var SALT_BYTES = 32;
|
|
6715
7123
|
var SALT_RE = /^[0-9a-f]{64}$/;
|
|
6716
7124
|
function pathSaltPath(codeName, homeDir) {
|
|
6717
7125
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir9());
|
|
6718
7126
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
6719
|
-
return
|
|
7127
|
+
return join24(home, ".augmented", key, "tool-call-path-salt");
|
|
6720
7128
|
}
|
|
6721
7129
|
function readToolCallPathSalt(codeName, homeDir) {
|
|
6722
7130
|
let file;
|
|
@@ -6727,7 +7135,7 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
6727
7135
|
}
|
|
6728
7136
|
try {
|
|
6729
7137
|
if (existsSync5(file)) {
|
|
6730
|
-
const existing =
|
|
7138
|
+
const existing = readFileSync18(file, "utf-8").trim();
|
|
6731
7139
|
if (SALT_RE.test(existing)) return existing;
|
|
6732
7140
|
}
|
|
6733
7141
|
} catch {
|
|
@@ -6735,7 +7143,7 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
6735
7143
|
const salt = randomBytes(SALT_BYTES).toString("hex");
|
|
6736
7144
|
const tmp = `${file}.tmp.${process.pid}`;
|
|
6737
7145
|
try {
|
|
6738
|
-
|
|
7146
|
+
mkdirSync8(dirname7(file), { recursive: true, mode: 448 });
|
|
6739
7147
|
writeFileSync8(tmp, `${salt}
|
|
6740
7148
|
`, { encoding: "utf-8", mode: 384 });
|
|
6741
7149
|
renameSync4(tmp, file);
|
|
@@ -6753,20 +7161,20 @@ function readToolCallPathSalt(codeName, homeDir) {
|
|
|
6753
7161
|
import { statSync as statSync6 } from "fs";
|
|
6754
7162
|
|
|
6755
7163
|
// src/lib/tool-call-extractor.ts
|
|
6756
|
-
import { closeSync as
|
|
6757
|
-
import { basename as basename2, join as
|
|
7164
|
+
import { closeSync as closeSync4, fstatSync as fstatSync2, openSync as openSync4, readFileSync as readFileSync19, readSync as readSync3, readdirSync as readdirSync6 } from "fs";
|
|
7165
|
+
import { basename as basename2, join as join25, relative } from "path";
|
|
6758
7166
|
import { StringDecoder } from "string_decoder";
|
|
6759
7167
|
|
|
6760
7168
|
// src/lib/tool-call-redaction.ts
|
|
6761
7169
|
import { createHmac } from "crypto";
|
|
6762
7170
|
|
|
6763
7171
|
// ../../packages/core/dist/tool-calls/input-hash.js
|
|
6764
|
-
import { createHash as
|
|
7172
|
+
import { createHash as createHash8 } from "crypto";
|
|
6765
7173
|
function hashToolInput(input) {
|
|
6766
7174
|
if (input === void 0)
|
|
6767
7175
|
return null;
|
|
6768
7176
|
try {
|
|
6769
|
-
return
|
|
7177
|
+
return createHash8("sha256").update(canonicalJson2(input)).digest("hex");
|
|
6770
7178
|
} catch {
|
|
6771
7179
|
return null;
|
|
6772
7180
|
}
|
|
@@ -6883,7 +7291,7 @@ function redactToolTargetInner(toolName, input, ctx) {
|
|
|
6883
7291
|
var EXTRACTOR_VERSION = "e1";
|
|
6884
7292
|
function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
6885
7293
|
const files = [];
|
|
6886
|
-
const mainAbs =
|
|
7294
|
+
const mainAbs = join25(transcriptDir, `${sessionId}.jsonl`);
|
|
6887
7295
|
files.push({
|
|
6888
7296
|
absPath: mainAbs,
|
|
6889
7297
|
relPath: relative(projectsRoot, mainAbs),
|
|
@@ -6891,7 +7299,7 @@ function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
|
6891
7299
|
isSubagent: false,
|
|
6892
7300
|
subagentId: null
|
|
6893
7301
|
});
|
|
6894
|
-
const subDir =
|
|
7302
|
+
const subDir = join25(transcriptDir, sessionId, "subagents");
|
|
6895
7303
|
let entries;
|
|
6896
7304
|
try {
|
|
6897
7305
|
entries = readdirSync6(subDir);
|
|
@@ -6900,7 +7308,7 @@ function enumerateSessionTranscripts(transcriptDir, sessionId, projectsRoot) {
|
|
|
6900
7308
|
}
|
|
6901
7309
|
for (const name of entries) {
|
|
6902
7310
|
if (!name.endsWith(".jsonl")) continue;
|
|
6903
|
-
const abs =
|
|
7311
|
+
const abs = join25(subDir, name);
|
|
6904
7312
|
const stem = basename2(name, ".jsonl");
|
|
6905
7313
|
files.push({
|
|
6906
7314
|
absPath: abs,
|
|
@@ -7003,7 +7411,7 @@ var WINDOW_BUDGET_BYTES = 4 * 1024 * 1024;
|
|
|
7003
7411
|
function extractTranscriptWindow(file, opts, from) {
|
|
7004
7412
|
let fd;
|
|
7005
7413
|
try {
|
|
7006
|
-
fd =
|
|
7414
|
+
fd = openSync4(file.absPath, "r");
|
|
7007
7415
|
} catch {
|
|
7008
7416
|
return {
|
|
7009
7417
|
records: [],
|
|
@@ -7024,7 +7432,7 @@ function extractTranscriptWindow(file, opts, from) {
|
|
|
7024
7432
|
let rewound = false;
|
|
7025
7433
|
let fileSize = null;
|
|
7026
7434
|
try {
|
|
7027
|
-
const { size } =
|
|
7435
|
+
const { size } = fstatSync2(fd);
|
|
7028
7436
|
fileSize = size;
|
|
7029
7437
|
if (startByte > size) {
|
|
7030
7438
|
startByte = 0;
|
|
@@ -7072,7 +7480,7 @@ function extractTranscriptWindow(file, opts, from) {
|
|
|
7072
7480
|
} catch {
|
|
7073
7481
|
} finally {
|
|
7074
7482
|
try {
|
|
7075
|
-
|
|
7483
|
+
closeSync4(fd);
|
|
7076
7484
|
} catch {
|
|
7077
7485
|
}
|
|
7078
7486
|
}
|
|
@@ -7098,9 +7506,9 @@ function extractTranscriptWindow(file, opts, from) {
|
|
|
7098
7506
|
}
|
|
7099
7507
|
|
|
7100
7508
|
// src/lib/tool-call-cursor.ts
|
|
7101
|
-
import { existsSync as existsSync6, readFileSync as
|
|
7509
|
+
import { existsSync as existsSync6, readFileSync as readFileSync20 } from "fs";
|
|
7102
7510
|
import { homedir as homedir10 } from "os";
|
|
7103
|
-
import { join as
|
|
7511
|
+
import { join as join26 } from "path";
|
|
7104
7512
|
var COVERAGE_DISPOSITIONS = [
|
|
7105
7513
|
"ok",
|
|
7106
7514
|
"not_entitled",
|
|
@@ -7155,13 +7563,13 @@ function parseCursorKey(key) {
|
|
|
7155
7563
|
function cursorStatePath(codeName, homeDir) {
|
|
7156
7564
|
const home = homeDir ?? (process.env["HOME"]?.trim() || homedir10());
|
|
7157
7565
|
const key = agentRuntimeKey(codeName, homeDir);
|
|
7158
|
-
return
|
|
7566
|
+
return join26(home, ".augmented", key, "tool-call-cursors.json");
|
|
7159
7567
|
}
|
|
7160
7568
|
function loadCursors(path) {
|
|
7161
7569
|
const out = /* @__PURE__ */ new Map();
|
|
7162
7570
|
if (!existsSync6(path)) return out;
|
|
7163
7571
|
try {
|
|
7164
|
-
const parsed = JSON.parse(
|
|
7572
|
+
const parsed = JSON.parse(readFileSync20(path, "utf-8"));
|
|
7165
7573
|
if (!parsed || parsed.version !== 1 || typeof parsed.files !== "object") return out;
|
|
7166
7574
|
for (const [k, v] of Object.entries(parsed.files)) {
|
|
7167
7575
|
if (!v || typeof v !== "object") continue;
|
|
@@ -7568,7 +7976,7 @@ async function maybeScanToolCalls(args) {
|
|
|
7568
7976
|
log2(`[tool-call-audit] ${codeName}: no path-hash salt available \u2014 file targets withheld`);
|
|
7569
7977
|
}
|
|
7570
7978
|
const home = args.homeDir ?? (process.env["HOME"]?.trim() || homedir11());
|
|
7571
|
-
const projectsRoot = args.projectsRoot ??
|
|
7979
|
+
const projectsRoot = args.projectsRoot ?? join27(home, ".claude", "projects");
|
|
7572
7980
|
const transcriptDir = args.transcriptDir ?? sessionTranscriptDir(getProjectDir(codeName));
|
|
7573
7981
|
const current = peekCurrentSession(codeName);
|
|
7574
7982
|
const sessionIds = current ? [current.sessionId] : [];
|
|
@@ -7597,11 +8005,11 @@ async function maybeScanToolCalls(args) {
|
|
|
7597
8005
|
}
|
|
7598
8006
|
|
|
7599
8007
|
// src/lib/activity-cache-monitor.ts
|
|
7600
|
-
import { existsSync as existsSync7, readFileSync as
|
|
8008
|
+
import { existsSync as existsSync7, readFileSync as readFileSync21 } from "fs";
|
|
7601
8009
|
import { homedir as homedir12 } from "os";
|
|
7602
|
-
import { join as
|
|
8010
|
+
import { join as join28 } from "path";
|
|
7603
8011
|
var MIN_CHECK_INTERVAL_MS8 = 6e4;
|
|
7604
|
-
var STATS_CACHE_PATH =
|
|
8012
|
+
var STATS_CACHE_PATH = join28(homedir12(), ".claude", "stats-cache.json");
|
|
7605
8013
|
var ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
7606
8014
|
var state8 = { lastObservedDate: null, lastCheckedAt: 0 };
|
|
7607
8015
|
function selectNewDailyRows(raw, lastObservedDate) {
|
|
@@ -7649,7 +8057,7 @@ async function maybeReportActivityCache(args) {
|
|
|
7649
8057
|
}
|
|
7650
8058
|
let raw;
|
|
7651
8059
|
try {
|
|
7652
|
-
raw =
|
|
8060
|
+
raw = readFileSync21(STATS_CACHE_PATH, "utf-8");
|
|
7653
8061
|
} catch (err) {
|
|
7654
8062
|
log2(`[activity-cache] readFileSync failed: ${err.message}`);
|
|
7655
8063
|
return;
|
|
@@ -7922,7 +8330,7 @@ function deviceStateHoldApplies(inputs) {
|
|
|
7922
8330
|
}
|
|
7923
8331
|
|
|
7924
8332
|
// src/lib/channel-config-hash.ts
|
|
7925
|
-
import { createHash as
|
|
8333
|
+
import { createHash as createHash9 } from "crypto";
|
|
7926
8334
|
var DERIVED_PRINCIPAL_ID_LIST_KEYS = [
|
|
7927
8335
|
"allowed_users",
|
|
7928
8336
|
"diagnostic_chat_ids",
|
|
@@ -7943,7 +8351,7 @@ function normalizeChannelConfigForHash(config2) {
|
|
|
7943
8351
|
}
|
|
7944
8352
|
var CHANNEL_WRITE_VERSION = 9;
|
|
7945
8353
|
function computeChannelConfigHash(input) {
|
|
7946
|
-
return
|
|
8354
|
+
return createHash9("sha256").update(
|
|
7947
8355
|
canonicalJson({
|
|
7948
8356
|
writeVersion: CHANNEL_WRITE_VERSION,
|
|
7949
8357
|
cliVersion: input.cliVersion,
|
|
@@ -7967,11 +8375,11 @@ function computeChannelConfigHash(input) {
|
|
|
7967
8375
|
}
|
|
7968
8376
|
|
|
7969
8377
|
// src/lib/knowledge-cache.ts
|
|
7970
|
-
import { createHash as
|
|
8378
|
+
import { createHash as createHash10 } from "crypto";
|
|
7971
8379
|
import {
|
|
7972
8380
|
existsSync as existsSync8,
|
|
7973
|
-
mkdirSync as
|
|
7974
|
-
readFileSync as
|
|
8381
|
+
mkdirSync as mkdirSync9,
|
|
8382
|
+
readFileSync as readFileSync22,
|
|
7975
8383
|
readdirSync as readdirSync7,
|
|
7976
8384
|
renameSync as renameSync5,
|
|
7977
8385
|
rmSync as rmSync4,
|
|
@@ -7979,21 +8387,21 @@ import {
|
|
|
7979
8387
|
utimesSync,
|
|
7980
8388
|
writeFileSync as writeFileSync9
|
|
7981
8389
|
} from "fs";
|
|
7982
|
-
import { join as
|
|
8390
|
+
import { join as join29 } from "path";
|
|
7983
8391
|
var KNOWLEDGE_FETCH_CHUNK = 100;
|
|
7984
8392
|
var CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7985
8393
|
var SWEEP_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
7986
8394
|
var lastSweepAt = 0;
|
|
7987
8395
|
function knowledgeHash(content) {
|
|
7988
|
-
return
|
|
8396
|
+
return createHash10("sha256").update(content, "utf8").digest("hex");
|
|
7989
8397
|
}
|
|
7990
8398
|
function cachePath(cacheDir, hash) {
|
|
7991
|
-
return
|
|
8399
|
+
return join29(cacheDir, hash);
|
|
7992
8400
|
}
|
|
7993
8401
|
function readCachedKnowledge(cacheDir, hash) {
|
|
7994
8402
|
const path = cachePath(cacheDir, hash);
|
|
7995
8403
|
try {
|
|
7996
|
-
const content =
|
|
8404
|
+
const content = readFileSync22(path, "utf-8");
|
|
7997
8405
|
try {
|
|
7998
8406
|
const now = /* @__PURE__ */ new Date();
|
|
7999
8407
|
utimesSync(path, now, now);
|
|
@@ -8007,7 +8415,7 @@ function readCachedKnowledge(cacheDir, hash) {
|
|
|
8007
8415
|
function writeCachedKnowledge(cacheDir, hash, content) {
|
|
8008
8416
|
if (knowledgeHash(content) !== hash) return false;
|
|
8009
8417
|
try {
|
|
8010
|
-
|
|
8418
|
+
mkdirSync9(cacheDir, { recursive: true });
|
|
8011
8419
|
const tmp = `${cachePath(cacheDir, hash)}.tmp-${process.pid}`;
|
|
8012
8420
|
writeFileSync9(tmp, content, "utf-8");
|
|
8013
8421
|
renameSync5(tmp, cachePath(cacheDir, hash));
|
|
@@ -8022,7 +8430,7 @@ function sweepKnowledgeCache(cacheDir, now = Date.now()) {
|
|
|
8022
8430
|
try {
|
|
8023
8431
|
if (!existsSync8(cacheDir)) return;
|
|
8024
8432
|
for (const name of readdirSync7(cacheDir)) {
|
|
8025
|
-
const path =
|
|
8433
|
+
const path = join29(cacheDir, name);
|
|
8026
8434
|
try {
|
|
8027
8435
|
if (now - statSync8(path).mtimeMs > CACHE_TTL_MS) rmSync4(path, { force: true });
|
|
8028
8436
|
} catch {
|
|
@@ -8070,11 +8478,11 @@ async function resolveKnowledgeFromManifest(args) {
|
|
|
8070
8478
|
}
|
|
8071
8479
|
|
|
8072
8480
|
// src/lib/memory-cache.ts
|
|
8073
|
-
import { createHash as
|
|
8481
|
+
import { createHash as createHash11 } from "crypto";
|
|
8074
8482
|
import {
|
|
8075
8483
|
existsSync as existsSync9,
|
|
8076
|
-
mkdirSync as
|
|
8077
|
-
readFileSync as
|
|
8484
|
+
mkdirSync as mkdirSync10,
|
|
8485
|
+
readFileSync as readFileSync23,
|
|
8078
8486
|
readdirSync as readdirSync8,
|
|
8079
8487
|
renameSync as renameSync6,
|
|
8080
8488
|
rmSync as rmSync5,
|
|
@@ -8082,21 +8490,21 @@ import {
|
|
|
8082
8490
|
utimesSync as utimesSync2,
|
|
8083
8491
|
writeFileSync as writeFileSync10
|
|
8084
8492
|
} from "fs";
|
|
8085
|
-
import { join as
|
|
8493
|
+
import { join as join30 } from "path";
|
|
8086
8494
|
var MEMORY_FETCH_CHUNK = 100;
|
|
8087
8495
|
var CACHE_TTL_MS2 = 30 * 24 * 60 * 60 * 1e3;
|
|
8088
8496
|
var SWEEP_INTERVAL_MS2 = 24 * 60 * 60 * 1e3;
|
|
8089
8497
|
var lastSweepAt2 = /* @__PURE__ */ new Map();
|
|
8090
8498
|
function memoryHash(content) {
|
|
8091
|
-
return
|
|
8499
|
+
return createHash11("sha256").update(content, "utf8").digest("hex");
|
|
8092
8500
|
}
|
|
8093
8501
|
function cachePath2(cacheDir, hash) {
|
|
8094
|
-
return
|
|
8502
|
+
return join30(cacheDir, hash);
|
|
8095
8503
|
}
|
|
8096
8504
|
function readCachedMemory(cacheDir, hash) {
|
|
8097
8505
|
const path = cachePath2(cacheDir, hash);
|
|
8098
8506
|
try {
|
|
8099
|
-
const content =
|
|
8507
|
+
const content = readFileSync23(path, "utf-8");
|
|
8100
8508
|
try {
|
|
8101
8509
|
const now = /* @__PURE__ */ new Date();
|
|
8102
8510
|
utimesSync2(path, now, now);
|
|
@@ -8110,7 +8518,7 @@ function readCachedMemory(cacheDir, hash) {
|
|
|
8110
8518
|
function writeCachedMemory(cacheDir, hash, content) {
|
|
8111
8519
|
if (memoryHash(content) !== hash) return false;
|
|
8112
8520
|
try {
|
|
8113
|
-
|
|
8521
|
+
mkdirSync10(cacheDir, { recursive: true });
|
|
8114
8522
|
const tmp = `${cachePath2(cacheDir, hash)}.tmp-${process.pid}`;
|
|
8115
8523
|
writeFileSync10(tmp, content, "utf-8");
|
|
8116
8524
|
renameSync6(tmp, cachePath2(cacheDir, hash));
|
|
@@ -8125,7 +8533,7 @@ function sweepMemoryCache(cacheDir, now = Date.now()) {
|
|
|
8125
8533
|
try {
|
|
8126
8534
|
if (!existsSync9(cacheDir)) return;
|
|
8127
8535
|
for (const name of readdirSync8(cacheDir)) {
|
|
8128
|
-
const path =
|
|
8536
|
+
const path = join30(cacheDir, name);
|
|
8129
8537
|
try {
|
|
8130
8538
|
if (now - statSync9(path).mtimeMs > CACHE_TTL_MS2) rmSync5(path, { force: true });
|
|
8131
8539
|
} catch {
|
|
@@ -8179,11 +8587,11 @@ async function resolveMemoriesFromManifest(args) {
|
|
|
8179
8587
|
}
|
|
8180
8588
|
|
|
8181
8589
|
// src/lib/skill-cache.ts
|
|
8182
|
-
import { createHash as
|
|
8590
|
+
import { createHash as createHash12 } from "crypto";
|
|
8183
8591
|
import {
|
|
8184
8592
|
existsSync as existsSync10,
|
|
8185
|
-
mkdirSync as
|
|
8186
|
-
readFileSync as
|
|
8593
|
+
mkdirSync as mkdirSync11,
|
|
8594
|
+
readFileSync as readFileSync24,
|
|
8187
8595
|
readdirSync as readdirSync9,
|
|
8188
8596
|
renameSync as renameSync7,
|
|
8189
8597
|
rmSync as rmSync6,
|
|
@@ -8191,21 +8599,21 @@ import {
|
|
|
8191
8599
|
utimesSync as utimesSync3,
|
|
8192
8600
|
writeFileSync as writeFileSync11
|
|
8193
8601
|
} from "fs";
|
|
8194
|
-
import { join as
|
|
8602
|
+
import { join as join31 } from "path";
|
|
8195
8603
|
var SKILL_FETCH_CHUNK = 100;
|
|
8196
8604
|
var CACHE_TTL_MS3 = 30 * 24 * 60 * 60 * 1e3;
|
|
8197
8605
|
var SWEEP_INTERVAL_MS3 = 24 * 60 * 60 * 1e3;
|
|
8198
8606
|
var lastSweepAt3 = 0;
|
|
8199
8607
|
function skillHash(content) {
|
|
8200
|
-
return
|
|
8608
|
+
return createHash12("sha256").update(content, "utf8").digest("hex");
|
|
8201
8609
|
}
|
|
8202
8610
|
function cachePath3(cacheDir, hash) {
|
|
8203
|
-
return
|
|
8611
|
+
return join31(cacheDir, hash);
|
|
8204
8612
|
}
|
|
8205
8613
|
function readCachedSkill(cacheDir, hash) {
|
|
8206
8614
|
const path = cachePath3(cacheDir, hash);
|
|
8207
8615
|
try {
|
|
8208
|
-
const content =
|
|
8616
|
+
const content = readFileSync24(path, "utf-8");
|
|
8209
8617
|
try {
|
|
8210
8618
|
const now = /* @__PURE__ */ new Date();
|
|
8211
8619
|
utimesSync3(path, now, now);
|
|
@@ -8219,7 +8627,7 @@ function readCachedSkill(cacheDir, hash) {
|
|
|
8219
8627
|
function writeCachedSkill(cacheDir, hash, content) {
|
|
8220
8628
|
if (skillHash(content) !== hash) return "mismatch";
|
|
8221
8629
|
try {
|
|
8222
|
-
|
|
8630
|
+
mkdirSync11(cacheDir, { recursive: true });
|
|
8223
8631
|
const tmp = `${cachePath3(cacheDir, hash)}.tmp-${process.pid}`;
|
|
8224
8632
|
writeFileSync11(tmp, content, "utf-8");
|
|
8225
8633
|
renameSync7(tmp, cachePath3(cacheDir, hash));
|
|
@@ -8234,7 +8642,7 @@ function sweepSkillCache(cacheDir, now = Date.now()) {
|
|
|
8234
8642
|
try {
|
|
8235
8643
|
if (!existsSync10(cacheDir)) return;
|
|
8236
8644
|
for (const name of readdirSync9(cacheDir)) {
|
|
8237
|
-
const path =
|
|
8645
|
+
const path = join31(cacheDir, name);
|
|
8238
8646
|
try {
|
|
8239
8647
|
if (now - statSync10(path).mtimeMs > CACHE_TTL_MS3) rmSync6(path, { force: true });
|
|
8240
8648
|
} catch {
|
|
@@ -8563,18 +8971,18 @@ function resolveConditionalResponse(wire, hasCachedBody) {
|
|
|
8563
8971
|
}
|
|
8564
8972
|
|
|
8565
8973
|
// src/lib/channel-hash-cache.ts
|
|
8566
|
-
import { existsSync as existsSync11, readFileSync as
|
|
8567
|
-
import { join as
|
|
8974
|
+
import { existsSync as existsSync11, readFileSync as readFileSync25, writeFileSync as writeFileSync12 } from "fs";
|
|
8975
|
+
import { join as join32 } from "path";
|
|
8568
8976
|
var CACHE_FILENAME = "channel-hash-cache.json";
|
|
8569
8977
|
function getChannelHashCacheFile(configDir) {
|
|
8570
|
-
return
|
|
8978
|
+
return join32(configDir, CACHE_FILENAME);
|
|
8571
8979
|
}
|
|
8572
8980
|
function loadChannelHashCache(target, configDir) {
|
|
8573
8981
|
const path = getChannelHashCacheFile(configDir);
|
|
8574
8982
|
if (!existsSync11(path)) return;
|
|
8575
8983
|
let parsed;
|
|
8576
8984
|
try {
|
|
8577
|
-
parsed = JSON.parse(
|
|
8985
|
+
parsed = JSON.parse(readFileSync25(path, "utf-8"));
|
|
8578
8986
|
} catch {
|
|
8579
8987
|
return;
|
|
8580
8988
|
}
|
|
@@ -8594,8 +9002,8 @@ function saveChannelHashCache(source, configDir) {
|
|
|
8594
9002
|
}
|
|
8595
9003
|
|
|
8596
9004
|
// src/lib/sender-policy-baseline.ts
|
|
8597
|
-
import { existsSync as existsSync12, readFileSync as
|
|
8598
|
-
import { join as
|
|
9005
|
+
import { existsSync as existsSync12, readFileSync as readFileSync26 } from "fs";
|
|
9006
|
+
import { join as join33 } from "path";
|
|
8599
9007
|
var BASELINE_FILENAME = "sender-policy-baseline.json";
|
|
8600
9008
|
var SENDER_POLICY_BASELINE_VERSION = 1;
|
|
8601
9009
|
var BASELINE_CONCERNS = [
|
|
@@ -8651,14 +9059,14 @@ function createDeliveryBaselineMaps() {
|
|
|
8651
9059
|
};
|
|
8652
9060
|
}
|
|
8653
9061
|
function getSenderPolicyBaselineFile(configDir) {
|
|
8654
|
-
return
|
|
9062
|
+
return join33(configDir, BASELINE_FILENAME);
|
|
8655
9063
|
}
|
|
8656
9064
|
function loadSenderPolicyBaseline(target, configDir, log2) {
|
|
8657
9065
|
const path = getSenderPolicyBaselineFile(configDir);
|
|
8658
9066
|
if (!existsSync12(path)) return;
|
|
8659
9067
|
let parsed;
|
|
8660
9068
|
try {
|
|
8661
|
-
parsed = JSON.parse(
|
|
9069
|
+
parsed = JSON.parse(readFileSync26(path, "utf-8"));
|
|
8662
9070
|
} catch (err) {
|
|
8663
9071
|
log2?.(
|
|
8664
9072
|
`[sender-policy] discarding corrupt ${BASELINE_FILENAME} (${err.message}) - restrictive-policy agents will take one fail-closed restart`
|
|
@@ -8737,8 +9145,8 @@ function resolveIntegrationEgressDomains(fetched, persisted) {
|
|
|
8737
9145
|
}
|
|
8738
9146
|
|
|
8739
9147
|
// src/lib/stuck-streak-store.ts
|
|
8740
|
-
import { existsSync as existsSync13, readFileSync as
|
|
8741
|
-
import { join as
|
|
9148
|
+
import { existsSync as existsSync13, readFileSync as readFileSync27 } from "fs";
|
|
9149
|
+
import { join as join34 } from "path";
|
|
8742
9150
|
var STORE_FILENAME = "stuck-streaks.json";
|
|
8743
9151
|
var STUCK_STREAK_STORE_VERSION = 1;
|
|
8744
9152
|
var STUCK_STREAK_CONCERNS = ["channelSync", "realtimeRebind"];
|
|
@@ -8746,7 +9154,7 @@ function createStuckStreakMaps() {
|
|
|
8746
9154
|
return { channelSync: /* @__PURE__ */ new Map(), realtimeRebind: /* @__PURE__ */ new Map() };
|
|
8747
9155
|
}
|
|
8748
9156
|
function getStuckStreakStoreFile(configDir) {
|
|
8749
|
-
return
|
|
9157
|
+
return join34(configDir, STORE_FILENAME);
|
|
8750
9158
|
}
|
|
8751
9159
|
function isValidPersistedStreak(value) {
|
|
8752
9160
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -8788,7 +9196,7 @@ function loadStuckStreaks(target, configDir, log2) {
|
|
|
8788
9196
|
if (!existsSync13(path)) return;
|
|
8789
9197
|
let parsed;
|
|
8790
9198
|
try {
|
|
8791
|
-
parsed = JSON.parse(
|
|
9199
|
+
parsed = JSON.parse(readFileSync27(path, "utf-8"));
|
|
8792
9200
|
} catch (err) {
|
|
8793
9201
|
log2?.(
|
|
8794
9202
|
`[stuck-streaks] discarding corrupt ${STORE_FILENAME} (${err.message}) \u2014 stuck-streak ages restart from zero and one spurious "recovered" close may follow`
|
|
@@ -8831,7 +9239,7 @@ function pruneStuckStreaksToAgents(maps, activeAgentIds) {
|
|
|
8831
9239
|
}
|
|
8832
9240
|
|
|
8833
9241
|
// src/lib/claude-device-state.ts
|
|
8834
|
-
import { readFileSync as
|
|
9242
|
+
import { readFileSync as readFileSync28, statSync as statSync11 } from "fs";
|
|
8835
9243
|
function claudeDeviceStatePath(env = process.env) {
|
|
8836
9244
|
return effectiveClaudeJsonPath(void 0, env);
|
|
8837
9245
|
}
|
|
@@ -8856,7 +9264,7 @@ function checkClaudeDeviceState(path = claudeDeviceStatePath()) {
|
|
|
8856
9264
|
}
|
|
8857
9265
|
let raw;
|
|
8858
9266
|
try {
|
|
8859
|
-
raw =
|
|
9267
|
+
raw = readFileSync28(path, "utf-8");
|
|
8860
9268
|
} catch {
|
|
8861
9269
|
return { usable: false, reason: "unreadable" };
|
|
8862
9270
|
}
|
|
@@ -9548,7 +9956,7 @@ function planGlobalSkillSync(globalSkills, prevIds, hashOf, knownHash, options)
|
|
|
9548
9956
|
}
|
|
9549
9957
|
|
|
9550
9958
|
// src/lib/manager/integration-skill-cache.ts
|
|
9551
|
-
import { join as
|
|
9959
|
+
import { join as join35 } from "path";
|
|
9552
9960
|
function integrationSkillHashKey(agentId, skillId) {
|
|
9553
9961
|
return `plugin-skill:${agentId}:${skillId}`;
|
|
9554
9962
|
}
|
|
@@ -9564,21 +9972,21 @@ function forgetIntegrationSkill(cache3, agentId, skillId) {
|
|
|
9564
9972
|
function removeIntegrationSkillFolder(opts) {
|
|
9565
9973
|
forgetIntegrationSkill(opts.cache, opts.agentId, opts.entry);
|
|
9566
9974
|
for (const dir of opts.dirs) {
|
|
9567
|
-
opts.removeDir(
|
|
9975
|
+
opts.removeDir(join35(dir, opts.entry));
|
|
9568
9976
|
}
|
|
9569
9977
|
}
|
|
9570
9978
|
|
|
9571
9979
|
// src/lib/manager/managed-skill-manifest.ts
|
|
9572
|
-
import { existsSync as existsSync14, mkdirSync as
|
|
9573
|
-
import { dirname as dirname8, join as
|
|
9980
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync12, readFileSync as readFileSync29, writeFileSync as writeFileSync13 } from "fs";
|
|
9981
|
+
import { dirname as dirname8, join as join36 } from "path";
|
|
9574
9982
|
var MANIFEST_VERSION = 1;
|
|
9575
9983
|
function managedSkillManifestPath(agentRootDir) {
|
|
9576
|
-
return
|
|
9984
|
+
return join36(agentRootDir, "managed-skills.json");
|
|
9577
9985
|
}
|
|
9578
9986
|
function readManagedSkillManifest(path) {
|
|
9579
9987
|
try {
|
|
9580
9988
|
if (!existsSync14(path)) return /* @__PURE__ */ new Set();
|
|
9581
|
-
const parsed = JSON.parse(
|
|
9989
|
+
const parsed = JSON.parse(readFileSync29(path, "utf-8"));
|
|
9582
9990
|
const ids = Array.isArray(parsed?.globalSkillIds) ? parsed.globalSkillIds : [];
|
|
9583
9991
|
return new Set(ids.filter((id) => typeof id === "string" && id.length > 0));
|
|
9584
9992
|
} catch {
|
|
@@ -9587,7 +9995,7 @@ function readManagedSkillManifest(path) {
|
|
|
9587
9995
|
}
|
|
9588
9996
|
function writeManagedSkillManifest(path, ids) {
|
|
9589
9997
|
try {
|
|
9590
|
-
|
|
9998
|
+
mkdirSync12(dirname8(path), { recursive: true });
|
|
9591
9999
|
const body = {
|
|
9592
10000
|
version: MANIFEST_VERSION,
|
|
9593
10001
|
globalSkillIds: [...ids].sort()
|
|
@@ -9727,8 +10135,8 @@ function resolveModelChain(refreshData) {
|
|
|
9727
10135
|
}
|
|
9728
10136
|
|
|
9729
10137
|
// src/lib/manager/claude-auth.ts
|
|
9730
|
-
import { chmodSync as chmodSync2, existsSync as existsSync15, lstatSync as
|
|
9731
|
-
import { join as
|
|
10138
|
+
import { chmodSync as chmodSync2, existsSync as existsSync15, lstatSync as lstatSync4, mkdirSync as mkdirSync13, rmSync as rmSync7 } from "fs";
|
|
10139
|
+
import { join as join37 } from "path";
|
|
9732
10140
|
import { homedir as homedir13 } from "os";
|
|
9733
10141
|
async function applyClaudeAuthToEnv(childEnv, label, options = {}) {
|
|
9734
10142
|
const apiKey = getApiKey();
|
|
@@ -9747,7 +10155,7 @@ async function applyClaudeAuthToEnv(childEnv, label, options = {}) {
|
|
|
9747
10155
|
}
|
|
9748
10156
|
const claudeDir = claudeConfigDirForChild(childEnv);
|
|
9749
10157
|
for (const filename of [".credentials.json", "credentials.json"]) {
|
|
9750
|
-
const p =
|
|
10158
|
+
const p = join37(claudeDir, filename);
|
|
9751
10159
|
if (existsSync15(p)) {
|
|
9752
10160
|
try {
|
|
9753
10161
|
rmSync7(p, { force: true });
|
|
@@ -9762,23 +10170,23 @@ async function applyClaudeAuthToEnv(childEnv, label, options = {}) {
|
|
|
9762
10170
|
return { isolated: false };
|
|
9763
10171
|
}
|
|
9764
10172
|
function claudeConfigDirForChild(childEnv) {
|
|
9765
|
-
return childEnv.CLAUDE_CONFIG_DIR?.trim() ||
|
|
10173
|
+
return childEnv.CLAUDE_CONFIG_DIR?.trim() || join37(homedir13(), ".claude");
|
|
9766
10174
|
}
|
|
9767
10175
|
function ensurePrivateConfigDir(dir, platform4 = process.platform, chmod = chmodSync2) {
|
|
9768
|
-
|
|
9769
|
-
const st =
|
|
10176
|
+
mkdirSync13(dir, { recursive: true, mode: 448 });
|
|
10177
|
+
const st = lstatSync4(dir);
|
|
9770
10178
|
if (!st.isDirectory()) {
|
|
9771
10179
|
throw new Error(`isolated Claude config dir ${dir} is not a real directory (symlink or file); refusing`);
|
|
9772
10180
|
}
|
|
9773
10181
|
if (platform4 === "win32") return;
|
|
9774
10182
|
if ((st.mode & 511) !== 448) chmod(dir, 448);
|
|
9775
|
-
const mode =
|
|
10183
|
+
const mode = lstatSync4(dir).mode & 511;
|
|
9776
10184
|
if (mode !== 448) {
|
|
9777
10185
|
throw new Error(`isolated Claude config dir ${dir} could not be made private (mode ${mode.toString(8)}); refusing`);
|
|
9778
10186
|
}
|
|
9779
10187
|
}
|
|
9780
10188
|
function oneShotIsolatedConfigDir() {
|
|
9781
|
-
return
|
|
10189
|
+
return join37(homedir13(), ".augmented", "claude-oneshot");
|
|
9782
10190
|
}
|
|
9783
10191
|
|
|
9784
10192
|
// src/lib/claude-runtime-auth-probe.ts
|
|
@@ -10123,19 +10531,19 @@ function formatBoardForPrompt(items, template) {
|
|
|
10123
10531
|
}
|
|
10124
10532
|
|
|
10125
10533
|
// src/lib/manager/kanban/nudge-state-cache.ts
|
|
10126
|
-
import { existsSync as existsSync16, readFileSync as
|
|
10127
|
-
import { join as
|
|
10534
|
+
import { existsSync as existsSync16, readFileSync as readFileSync30, writeFileSync as writeFileSync14 } from "fs";
|
|
10535
|
+
import { join as join38 } from "path";
|
|
10128
10536
|
var CACHE_FILENAME2 = "kanban-nudge-state.json";
|
|
10129
10537
|
var KANBAN_NUDGE_STATE_VERSION = 1;
|
|
10130
10538
|
function getKanbanNudgeStateFile(configDir) {
|
|
10131
|
-
return
|
|
10539
|
+
return join38(configDir, CACHE_FILENAME2);
|
|
10132
10540
|
}
|
|
10133
10541
|
function loadKanbanNudgeState(target, configDir) {
|
|
10134
10542
|
const path = getKanbanNudgeStateFile(configDir);
|
|
10135
10543
|
if (!existsSync16(path)) return;
|
|
10136
10544
|
let parsed;
|
|
10137
10545
|
try {
|
|
10138
|
-
parsed = JSON.parse(
|
|
10546
|
+
parsed = JSON.parse(readFileSync30(path, "utf-8"));
|
|
10139
10547
|
} catch {
|
|
10140
10548
|
return;
|
|
10141
10549
|
}
|
|
@@ -10173,7 +10581,7 @@ function saveKanbanNudgeState(source, configDir) {
|
|
|
10173
10581
|
}
|
|
10174
10582
|
|
|
10175
10583
|
// src/lib/manager/kanban/notify.ts
|
|
10176
|
-
import { createHash as
|
|
10584
|
+
import { createHash as createHash13 } from "crypto";
|
|
10177
10585
|
async function enqueueKanbanNotice(opts) {
|
|
10178
10586
|
try {
|
|
10179
10587
|
const res = await api.post(
|
|
@@ -10188,7 +10596,7 @@ async function enqueueKanbanNotice(opts) {
|
|
|
10188
10596
|
return res.ok === true;
|
|
10189
10597
|
} catch (err) {
|
|
10190
10598
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10191
|
-
const errId =
|
|
10599
|
+
const errId = createHash13("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10192
10600
|
log(`[kanban] notice enqueue failed for agent_id=${opts.agentId} error_id=${errId}`);
|
|
10193
10601
|
return false;
|
|
10194
10602
|
}
|
|
@@ -10203,7 +10611,7 @@ async function cancelKanbanNotice(agentId) {
|
|
|
10203
10611
|
return typeof res.cancelled === "number" ? res.cancelled : 0;
|
|
10204
10612
|
} catch (err) {
|
|
10205
10613
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10206
|
-
const errId =
|
|
10614
|
+
const errId = createHash13("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10207
10615
|
log(`[kanban] notice cancel failed for agent_id=${agentId} error_id=${errId}`);
|
|
10208
10616
|
return null;
|
|
10209
10617
|
}
|
|
@@ -10700,7 +11108,7 @@ function deriveScheduledTaskNotify(task) {
|
|
|
10700
11108
|
}
|
|
10701
11109
|
|
|
10702
11110
|
// src/lib/manager/scheduler/runs.ts
|
|
10703
|
-
import { createHash as
|
|
11111
|
+
import { createHash as createHash14 } from "crypto";
|
|
10704
11112
|
async function startRun(opts) {
|
|
10705
11113
|
try {
|
|
10706
11114
|
const res = await api.post(
|
|
@@ -10715,7 +11123,7 @@ async function startRun(opts) {
|
|
|
10715
11123
|
};
|
|
10716
11124
|
} catch (err) {
|
|
10717
11125
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10718
|
-
const errId =
|
|
11126
|
+
const errId = createHash14("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10719
11127
|
log(`[runs] start failed for agent_id=${opts.agent_id} source_type=${opts.source_type} error_id=${errId}`);
|
|
10720
11128
|
return { run_id: null, kanban_item_id: null };
|
|
10721
11129
|
}
|
|
@@ -10754,7 +11162,7 @@ async function finishRun(runId, outcome, options = {}) {
|
|
|
10754
11162
|
return;
|
|
10755
11163
|
} catch (err) {
|
|
10756
11164
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10757
|
-
const errId =
|
|
11165
|
+
const errId = createHash14("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10758
11166
|
const status = err instanceof ApiError ? err.status : 0;
|
|
10759
11167
|
if (isRetryableFinishError(err) && attempt < maxRetries) {
|
|
10760
11168
|
log(
|
|
@@ -10783,7 +11191,7 @@ async function fetchPriorScheduledRuns(agentId, taskId) {
|
|
|
10783
11191
|
return rows.filter((r) => typeof r.output_text === "string" && r.output_text.length > 0).map((r) => ({ startedAt: r.started_at, output: r.output_text }));
|
|
10784
11192
|
} catch (err) {
|
|
10785
11193
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10786
|
-
const errId =
|
|
11194
|
+
const errId = createHash14("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10787
11195
|
log(`[runs] prior-runs lookup failed for task_id=${taskId} error_id=${errId}`);
|
|
10788
11196
|
return [];
|
|
10789
11197
|
}
|
|
@@ -10844,13 +11252,13 @@ function closeSessionRunForCode(codeName, outcome, reason) {
|
|
|
10844
11252
|
}
|
|
10845
11253
|
|
|
10846
11254
|
// src/lib/manager/scheduler/kanban-route.ts
|
|
10847
|
-
import { createHash as
|
|
10848
|
-
import { writeFileSync as writeFileSync15, renameSync as renameSync8, mkdirSync as
|
|
11255
|
+
import { createHash as createHash16 } from "crypto";
|
|
11256
|
+
import { writeFileSync as writeFileSync15, renameSync as renameSync8, mkdirSync as mkdirSync14, readFileSync as readFileSync31, unlinkSync as unlinkSync3 } from "fs";
|
|
10849
11257
|
import { homedir as homedir14 } from "os";
|
|
10850
|
-
import { join as
|
|
11258
|
+
import { join as join39, dirname as dirname9 } from "path";
|
|
10851
11259
|
|
|
10852
11260
|
// src/lib/manager/scheduler/notify.ts
|
|
10853
|
-
import { createHash as
|
|
11261
|
+
import { createHash as createHash15 } from "crypto";
|
|
10854
11262
|
async function enqueueScheduledTaskNotice(opts) {
|
|
10855
11263
|
try {
|
|
10856
11264
|
const res = await api.post(
|
|
@@ -10867,7 +11275,7 @@ async function enqueueScheduledTaskNotice(opts) {
|
|
|
10867
11275
|
return res.ok === true;
|
|
10868
11276
|
} catch (err) {
|
|
10869
11277
|
const errText = err instanceof Error ? err.message : String(err);
|
|
10870
|
-
const errId =
|
|
11278
|
+
const errId = createHash15("sha256").update(errText).digest("hex").slice(0, 12);
|
|
10871
11279
|
log(
|
|
10872
11280
|
`[scheduled-kanban] notice enqueue failed for agent_id=${opts.agentId} task_id=${opts.taskId} error_id=${errId}`
|
|
10873
11281
|
);
|
|
@@ -11210,7 +11618,7 @@ function resolveScheduledSlackTarget(task) {
|
|
|
11210
11618
|
}
|
|
11211
11619
|
function stampScheduledTurnMarker(codeName, taskId, target) {
|
|
11212
11620
|
try {
|
|
11213
|
-
const file =
|
|
11621
|
+
const file = join39(homedir14(), ".augmented", codeName, SCHEDULED_TURN_MARKER_FILENAME);
|
|
11214
11622
|
const marker = { ts: Date.now(), task_id: taskId, ...target ? { target } : {} };
|
|
11215
11623
|
const tmp = `${file}.tmp`;
|
|
11216
11624
|
writeFileSync15(tmp, JSON.stringify(marker), "utf8");
|
|
@@ -11220,9 +11628,9 @@ function stampScheduledTurnMarker(codeName, taskId, target) {
|
|
|
11220
11628
|
}
|
|
11221
11629
|
}
|
|
11222
11630
|
function clearScheduledTurnMarkerForTask(codeName, taskId) {
|
|
11223
|
-
const file =
|
|
11631
|
+
const file = join39(homedir14(), ".augmented", codeName, SCHEDULED_TURN_MARKER_FILENAME);
|
|
11224
11632
|
try {
|
|
11225
|
-
const raw = JSON.parse(
|
|
11633
|
+
const raw = JSON.parse(readFileSync31(file, "utf8"));
|
|
11226
11634
|
if (typeof raw?.task_id !== "string" || raw.task_id !== taskId) return;
|
|
11227
11635
|
unlinkSync3(file);
|
|
11228
11636
|
log(`[scheduled-kanban] scheduled-turn marker cleared for '${codeName}' (task ${taskId} complete)`);
|
|
@@ -11289,7 +11697,7 @@ async function routeScheduledTaskViaKanban(codeName, agentId, task, prompt, dura
|
|
|
11289
11697
|
if (!enqueued) return false;
|
|
11290
11698
|
try {
|
|
11291
11699
|
const doorbell = directChatDoorbellPath(agentId, homedir14());
|
|
11292
|
-
|
|
11700
|
+
mkdirSync14(dirname9(doorbell), { recursive: true });
|
|
11293
11701
|
writeFileSync15(doorbell, String(Date.now()));
|
|
11294
11702
|
} catch (err) {
|
|
11295
11703
|
log(`[scheduled-kanban] doorbell ring failed for '${codeName}': ${err.message} (notice still queued)`);
|
|
@@ -11380,24 +11788,24 @@ async function processClaudeTaskResult(codeName, agentId, templateId, rawOutput,
|
|
|
11380
11788
|
const assertion = parseDeliverAssertion(rawOutput);
|
|
11381
11789
|
if (!assertion.deliver) {
|
|
11382
11790
|
const trimmed = (rawOutput ?? "").trim();
|
|
11383
|
-
const outputHash = trimmed.length === 0 ? "empty" :
|
|
11791
|
+
const outputHash = trimmed.length === 0 ? "empty" : createHash16("sha256").update(trimmed).digest("hex").slice(0, 12);
|
|
11384
11792
|
log(`[claude-scheduler] Suppressed by delivery_policy=conditional for '${codeName}' (template=${templateId}, task=${delivery?.taskId ?? "n/a"}) \u2014 ${assertion.vacuous ? "deliver marker had a vacuous reason" : "no deliver marker"}; output_len=${trimmed.length} output_hash=${outputHash}`);
|
|
11385
11793
|
if (delivery?.mode === "announce" && delivery.to) {
|
|
11386
11794
|
await reportDeliveryStatus(agentId, delivery.taskId, { status: "skipped", error_code: "SUPPRESSED_BY_POLICY" });
|
|
11387
11795
|
}
|
|
11388
11796
|
return { ok: true };
|
|
11389
11797
|
}
|
|
11390
|
-
const reasonHash =
|
|
11798
|
+
const reasonHash = createHash16("sha256").update(assertion.reason ?? "").digest("hex").slice(0, 12);
|
|
11391
11799
|
log(`[claude-scheduler] Delivering conditional run for '${codeName}' (template=${templateId}, task=${delivery?.taskId ?? "n/a"}) \u2014 agent asserted a concrete trigger (reason_len=${(assertion.reason ?? "").length} reason_hash=${reasonHash})`);
|
|
11392
11800
|
rawOutput = assertion.deliverable;
|
|
11393
11801
|
}
|
|
11394
11802
|
const classification = classifyOutput(rawOutput);
|
|
11395
11803
|
if (classification.action === "suppress") {
|
|
11396
11804
|
const trimmed = (rawOutput ?? "").trim();
|
|
11397
|
-
const outputHash = trimmed.length === 0 ? "empty" :
|
|
11805
|
+
const outputHash = trimmed.length === 0 ? "empty" : createHash16("sha256").update(trimmed).digest("hex").slice(0, 12);
|
|
11398
11806
|
log(`[claude-scheduler] Suppressing delivery for '${codeName}' (template=${templateId}, task=${delivery?.taskId ?? "n/a"}) \u2014 output_len=${trimmed.length} output_hash=${outputHash}`);
|
|
11399
11807
|
if (classification.suppressedNotes) {
|
|
11400
|
-
const notesHash =
|
|
11808
|
+
const notesHash = createHash16("sha256").update(classification.suppressedNotes).digest("hex").slice(0, 12);
|
|
11401
11809
|
log(`[claude-scheduler] Suppressed notes for '${codeName}' (task=${delivery?.taskId ?? "n/a"}) \u2014 notes_len=${classification.suppressedNotes.length} notes_hash=${notesHash}`);
|
|
11402
11810
|
}
|
|
11403
11811
|
if (delivery?.mode === "announce" && delivery.to) {
|
|
@@ -11469,13 +11877,13 @@ async function processClaudeTaskResult(codeName, agentId, templateId, rawOutput,
|
|
|
11469
11877
|
}
|
|
11470
11878
|
|
|
11471
11879
|
// src/lib/manager/scheduler/execution.ts
|
|
11472
|
-
import { createHash as
|
|
11880
|
+
import { createHash as createHash17 } from "crypto";
|
|
11473
11881
|
import { homedir as homedir15 } from "os";
|
|
11474
|
-
import { join as
|
|
11882
|
+
import { join as join41 } from "path";
|
|
11475
11883
|
|
|
11476
11884
|
// src/lib/agent-serving-probe.ts
|
|
11477
|
-
import { readFileSync as
|
|
11478
|
-
import { join as
|
|
11885
|
+
import { readFileSync as readFileSync32, readdirSync as readdirSync10, statSync as statSync12 } from "fs";
|
|
11886
|
+
import { join as join40 } from "path";
|
|
11479
11887
|
var RATE_LIMIT_WINDOW_MS = 6 * 60 * 60 * 1e3;
|
|
11480
11888
|
function probeRateLimit(args) {
|
|
11481
11889
|
const now = args.now ?? /* @__PURE__ */ new Date();
|
|
@@ -11491,7 +11899,7 @@ function probeRateLimit(args) {
|
|
|
11491
11899
|
let newest = UNKNOWN_RATE_LIMIT;
|
|
11492
11900
|
for (const name of entries) {
|
|
11493
11901
|
if (!name.endsWith(".jsonl")) continue;
|
|
11494
|
-
const path =
|
|
11902
|
+
const path = join40(dir, name);
|
|
11495
11903
|
try {
|
|
11496
11904
|
const st = statSync12(path);
|
|
11497
11905
|
if (!st.isFile() || st.mtimeMs < startMs) continue;
|
|
@@ -11500,7 +11908,7 @@ function probeRateLimit(args) {
|
|
|
11500
11908
|
}
|
|
11501
11909
|
let content;
|
|
11502
11910
|
try {
|
|
11503
|
-
content =
|
|
11911
|
+
content = readFileSync32(path, "utf-8");
|
|
11504
11912
|
} catch {
|
|
11505
11913
|
continue;
|
|
11506
11914
|
}
|
|
@@ -11562,7 +11970,7 @@ function shouldLogUsageCapDeferral(site, codeName, limitedUntil) {
|
|
|
11562
11970
|
|
|
11563
11971
|
// src/lib/manager/scheduler/execution.ts
|
|
11564
11972
|
function claudePidFilePath() {
|
|
11565
|
-
return
|
|
11973
|
+
return join41(homedir15(), ".augmented", "manager-claude-pids.json");
|
|
11566
11974
|
}
|
|
11567
11975
|
var inFlightClaudePids = /* @__PURE__ */ new Map();
|
|
11568
11976
|
function registerClaudeSpawn(record) {
|
|
@@ -11582,10 +11990,10 @@ function unregisterClaudeSpawn(pid) {
|
|
|
11582
11990
|
}
|
|
11583
11991
|
async function syncAndCheckClaudeScheduler(agent, tasks, boardItems, refreshData, durableScheduledNudge = false) {
|
|
11584
11992
|
const codeName = agent.code_name;
|
|
11585
|
-
const stableTasksHash =
|
|
11586
|
-
const boardHash = boardItems.length > 0 ?
|
|
11993
|
+
const stableTasksHash = createHash17("sha256").update(JSON.stringify(tasks)).digest("hex").slice(0, 16);
|
|
11994
|
+
const boardHash = boardItems.length > 0 ? createHash17("sha256").update(JSON.stringify(boardItems.map((b) => ({ id: b.id, title: b.title, status: b.status, priority: b.priority, deliverable: b.deliverable })))).digest("hex").slice(0, 16) : "empty";
|
|
11587
11995
|
const resolvedModels = resolveModelChain(refreshData);
|
|
11588
|
-
const modelsHash =
|
|
11996
|
+
const modelsHash = createHash17("sha256").update(JSON.stringify(resolvedModels)).digest("hex").slice(0, 16);
|
|
11589
11997
|
const combinedHash = `${stableTasksHash}:${boardHash}:${modelsHash}`;
|
|
11590
11998
|
const prevHash = agentState.knownTasksHashes.get(agent.agent_id);
|
|
11591
11999
|
if (combinedHash !== prevHash) {
|
|
@@ -11854,8 +12262,8 @@ function respawnedByAnotherCaller(decision, healthyAfter, sessionStartedAt, lane
|
|
|
11854
12262
|
}
|
|
11855
12263
|
|
|
11856
12264
|
// src/lib/occupancy-gate.ts
|
|
11857
|
-
import { closeSync as
|
|
11858
|
-
import { join as
|
|
12265
|
+
import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync11, readSync as readSync4, statSync as statSync13 } from "fs";
|
|
12266
|
+
import { join as join42 } from "path";
|
|
11859
12267
|
function rostersMeasuredZero(mode, attested, runtimeRunning) {
|
|
11860
12268
|
return mode === "enforce" && attested && runtimeRunning;
|
|
11861
12269
|
}
|
|
@@ -11871,7 +12279,7 @@ function readAlignedTail(path, tailBytes, maxAlignBytes) {
|
|
|
11871
12279
|
try {
|
|
11872
12280
|
const size = statSync13(path).size;
|
|
11873
12281
|
if (size <= 0) return { content: "", complete: true, truncated: false };
|
|
11874
|
-
fd =
|
|
12282
|
+
fd = openSync5(path, "r");
|
|
11875
12283
|
let readStart = Math.max(0, size - tailBytes);
|
|
11876
12284
|
if (readStart > 0) {
|
|
11877
12285
|
const scanFloor = Math.max(0, readStart - maxAlignBytes);
|
|
@@ -11907,7 +12315,7 @@ function readAlignedTail(path, tailBytes, maxAlignBytes) {
|
|
|
11907
12315
|
} finally {
|
|
11908
12316
|
if (fd != null) {
|
|
11909
12317
|
try {
|
|
11910
|
-
|
|
12318
|
+
closeSync5(fd);
|
|
11911
12319
|
} catch {
|
|
11912
12320
|
}
|
|
11913
12321
|
}
|
|
@@ -11946,10 +12354,10 @@ function candidateTranscriptPaths(dir) {
|
|
|
11946
12354
|
let complete = true;
|
|
11947
12355
|
for (const name of top) {
|
|
11948
12356
|
if (name.endsWith(".jsonl")) {
|
|
11949
|
-
paths.push(
|
|
12357
|
+
paths.push(join42(dir, name));
|
|
11950
12358
|
continue;
|
|
11951
12359
|
}
|
|
11952
|
-
const subDir =
|
|
12360
|
+
const subDir = join42(dir, name, "subagents");
|
|
11953
12361
|
let subs;
|
|
11954
12362
|
try {
|
|
11955
12363
|
subs = readdirSync11(subDir);
|
|
@@ -11958,7 +12366,7 @@ function candidateTranscriptPaths(dir) {
|
|
|
11958
12366
|
continue;
|
|
11959
12367
|
}
|
|
11960
12368
|
for (const sub of subs) {
|
|
11961
|
-
if (sub.endsWith(".jsonl")) paths.push(
|
|
12369
|
+
if (sub.endsWith(".jsonl")) paths.push(join42(subDir, sub));
|
|
11962
12370
|
}
|
|
11963
12371
|
}
|
|
11964
12372
|
return { paths, complete };
|
|
@@ -12184,7 +12592,7 @@ function stopPaneOccupancySampler() {
|
|
|
12184
12592
|
}
|
|
12185
12593
|
|
|
12186
12594
|
// src/lib/pid-pressure-sampler.ts
|
|
12187
|
-
import { existsSync as existsSync17, readFileSync as
|
|
12595
|
+
import { existsSync as existsSync17, readFileSync as readFileSync33 } from "fs";
|
|
12188
12596
|
var SAMPLE_INTERVAL_MS2 = 3e4;
|
|
12189
12597
|
function warnFraction() {
|
|
12190
12598
|
const raw = Number(process.env.AGT_PID_PRESSURE_WARN_FRACTION);
|
|
@@ -12212,7 +12620,7 @@ function parseMemoryEvents(text) {
|
|
|
12212
12620
|
}
|
|
12213
12621
|
function readTextReal(path) {
|
|
12214
12622
|
try {
|
|
12215
|
-
return
|
|
12623
|
+
return readFileSync33(path, "utf-8");
|
|
12216
12624
|
} catch {
|
|
12217
12625
|
return null;
|
|
12218
12626
|
}
|
|
@@ -12452,7 +12860,7 @@ function stopRuntimeVersionSampler() {
|
|
|
12452
12860
|
}
|
|
12453
12861
|
|
|
12454
12862
|
// src/lib/opencode-slack-ingest.ts
|
|
12455
|
-
import { createHash as
|
|
12863
|
+
import { createHash as createHash18 } from "crypto";
|
|
12456
12864
|
|
|
12457
12865
|
// ../../packages/core/dist/channels/slack-rich-text.js
|
|
12458
12866
|
var MAX_DEPTH = 12;
|
|
@@ -13420,7 +13828,7 @@ function startSlackIngest(config2) {
|
|
|
13420
13828
|
// src/lib/opencode-slack-ingest.ts
|
|
13421
13829
|
var ingests = /* @__PURE__ */ new Map();
|
|
13422
13830
|
function fingerprint(params) {
|
|
13423
|
-
return
|
|
13831
|
+
return createHash18("sha256").update(
|
|
13424
13832
|
JSON.stringify({
|
|
13425
13833
|
appToken: params.appToken,
|
|
13426
13834
|
botToken: params.botToken,
|
|
@@ -13501,7 +13909,7 @@ function stopAllOpencodeSlackIngests(log2) {
|
|
|
13501
13909
|
}
|
|
13502
13910
|
|
|
13503
13911
|
// src/lib/manager/opencode-scheduler.ts
|
|
13504
|
-
import { createHash as
|
|
13912
|
+
import { createHash as createHash19 } from "crypto";
|
|
13505
13913
|
var MAX_OPENCODE_SCHED_CONCURRENCY = 2;
|
|
13506
13914
|
var opencodeSchedulerStates = /* @__PURE__ */ new Map();
|
|
13507
13915
|
var inFlightOpencodeTasks = /* @__PURE__ */ new Set();
|
|
@@ -13515,7 +13923,7 @@ function shouldDeliver(task, reply) {
|
|
|
13515
13923
|
}
|
|
13516
13924
|
async function syncAndCheckOpencodeScheduler(agent, tasks, refreshData) {
|
|
13517
13925
|
const codeName = agent.code_name;
|
|
13518
|
-
const tasksHash =
|
|
13926
|
+
const tasksHash = createHash19("sha256").update(JSON.stringify(tasks)).digest("hex").slice(0, 16);
|
|
13519
13927
|
if (knownOpencodeTaskHashes.get(agent.agent_id) !== tasksHash) {
|
|
13520
13928
|
const taskInputs = tasks.map((t) => buildSchedulerTaskInput(t));
|
|
13521
13929
|
const state11 = syncTasksToScheduler(codeName, agent.agent_id, taskInputs);
|
|
@@ -13593,10 +14001,10 @@ async function fireOpencodeScheduledTask(agent, task) {
|
|
|
13593
14001
|
}
|
|
13594
14002
|
|
|
13595
14003
|
// src/lib/opencode-telegram-ingest.ts
|
|
13596
|
-
import { createHash as
|
|
13597
|
-
import { existsSync as existsSync18, mkdirSync as
|
|
14004
|
+
import { createHash as createHash20 } from "crypto";
|
|
14005
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync15, readFileSync as readFileSync34, renameSync as renameSync9, unlinkSync as unlinkSync4, writeFileSync as writeFileSync16 } from "fs";
|
|
13598
14006
|
import { randomUUID } from "crypto";
|
|
13599
|
-
import { join as
|
|
14007
|
+
import { join as join43 } from "path";
|
|
13600
14008
|
|
|
13601
14009
|
// src/lib/telegram-ingest.ts
|
|
13602
14010
|
import https2 from "https";
|
|
@@ -14277,7 +14685,7 @@ function anySignal(signals) {
|
|
|
14277
14685
|
var ingests2 = /* @__PURE__ */ new Map();
|
|
14278
14686
|
var migrationQueues = /* @__PURE__ */ new Map();
|
|
14279
14687
|
function fingerprint2(params) {
|
|
14280
|
-
return
|
|
14688
|
+
return createHash20("sha256").update(
|
|
14281
14689
|
JSON.stringify({
|
|
14282
14690
|
botToken: params.botToken,
|
|
14283
14691
|
allowedChats: [...params.allowedChats].sort(),
|
|
@@ -14299,7 +14707,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
14299
14707
|
let filePath;
|
|
14300
14708
|
try {
|
|
14301
14709
|
dir = getFramework("opencode").getAgentDir(codeName);
|
|
14302
|
-
filePath =
|
|
14710
|
+
filePath = join43(dir, "telegram-getupdates-offset-opencode.json");
|
|
14303
14711
|
} catch {
|
|
14304
14712
|
dir = null;
|
|
14305
14713
|
filePath = null;
|
|
@@ -14308,7 +14716,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
14308
14716
|
load() {
|
|
14309
14717
|
if (!filePath) return 0;
|
|
14310
14718
|
try {
|
|
14311
|
-
const parsed = JSON.parse(
|
|
14719
|
+
const parsed = JSON.parse(readFileSync34(filePath, "utf-8"));
|
|
14312
14720
|
if (currentBotId != null && typeof parsed?.bot_id === "number" && parsed.bot_id !== currentBotId) {
|
|
14313
14721
|
log2(`[telegram-ingest:${codeName}] offset cursor belongs to a different bot; ignoring (bot swap)`);
|
|
14314
14722
|
return 0;
|
|
@@ -14326,7 +14734,7 @@ function createFileOffsetStore(codeName, log2, currentBotId) {
|
|
|
14326
14734
|
if (!filePath || !dir) return;
|
|
14327
14735
|
const tmpPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
14328
14736
|
try {
|
|
14329
|
-
|
|
14737
|
+
mkdirSync15(dir, { recursive: true, mode: 448 });
|
|
14330
14738
|
writeFileSync16(
|
|
14331
14739
|
tmpPath,
|
|
14332
14740
|
JSON.stringify({
|
|
@@ -14353,7 +14761,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
14353
14761
|
let filePath;
|
|
14354
14762
|
try {
|
|
14355
14763
|
dir = getFramework("opencode").getAgentDir(codeName);
|
|
14356
|
-
filePath =
|
|
14764
|
+
filePath = join43(dir, "telegram-migration-reports-opencode.json");
|
|
14357
14765
|
} catch {
|
|
14358
14766
|
dir = null;
|
|
14359
14767
|
filePath = null;
|
|
@@ -14362,7 +14770,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
14362
14770
|
load() {
|
|
14363
14771
|
if (!filePath) return null;
|
|
14364
14772
|
try {
|
|
14365
|
-
return
|
|
14773
|
+
return readFileSync34(filePath, "utf-8");
|
|
14366
14774
|
} catch {
|
|
14367
14775
|
return null;
|
|
14368
14776
|
}
|
|
@@ -14370,7 +14778,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
14370
14778
|
save(data) {
|
|
14371
14779
|
if (!filePath || !dir) return;
|
|
14372
14780
|
try {
|
|
14373
|
-
|
|
14781
|
+
mkdirSync15(dir, { recursive: true, mode: 448 });
|
|
14374
14782
|
atomicWriteFileSync(filePath, data, { mode: 384 });
|
|
14375
14783
|
} catch (err) {
|
|
14376
14784
|
log2(`[telegram-ingest:${codeName}] migration-report persist failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -14379,7 +14787,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
14379
14787
|
};
|
|
14380
14788
|
}
|
|
14381
14789
|
var managerHostPost = async (path, body) => {
|
|
14382
|
-
const { api: api2, ApiError: ApiError3 } = await import("../api-client-
|
|
14790
|
+
const { api: api2, ApiError: ApiError3 } = await import("../api-client-MH7MLGTA.js");
|
|
14383
14791
|
try {
|
|
14384
14792
|
const json = await api2.post(path, body);
|
|
14385
14793
|
return { status: 200, json };
|
|
@@ -14645,15 +15053,15 @@ function partitionActionableByPoison(actionable, states, config2) {
|
|
|
14645
15053
|
}
|
|
14646
15054
|
|
|
14647
15055
|
// src/lib/restart-flags.ts
|
|
14648
|
-
import { existsSync as existsSync19, mkdirSync as
|
|
15056
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync16, readdirSync as readdirSync12, readFileSync as readFileSync35, renameSync as renameSync10, rmSync as rmSync8, writeFileSync as writeFileSync17 } from "fs";
|
|
14649
15057
|
import { homedir as homedir16 } from "os";
|
|
14650
|
-
import { join as
|
|
15058
|
+
import { join as join44 } from "path";
|
|
14651
15059
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
14652
15060
|
function restartFlagsDir() {
|
|
14653
|
-
return
|
|
15061
|
+
return join44(homedir16(), ".augmented", "restart-flags");
|
|
14654
15062
|
}
|
|
14655
15063
|
function flagPath(codeName) {
|
|
14656
|
-
return
|
|
15064
|
+
return join44(restartFlagsDir(), `${codeName}.flag`);
|
|
14657
15065
|
}
|
|
14658
15066
|
function readRestartFlags() {
|
|
14659
15067
|
const dir = restartFlagsDir();
|
|
@@ -14662,7 +15070,7 @@ function readRestartFlags() {
|
|
|
14662
15070
|
for (const entry of readdirSync12(dir)) {
|
|
14663
15071
|
if (!entry.endsWith(".flag")) continue;
|
|
14664
15072
|
try {
|
|
14665
|
-
const raw =
|
|
15073
|
+
const raw = readFileSync35(join44(dir, entry), "utf8");
|
|
14666
15074
|
const parsed = JSON.parse(raw);
|
|
14667
15075
|
if (typeof parsed.codeName !== "string" || parsed.codeName.length === 0) {
|
|
14668
15076
|
parsed.codeName = entry.replace(/\.flag$/, "");
|
|
@@ -14780,8 +15188,8 @@ async function sendError(flag, opts, text) {
|
|
|
14780
15188
|
}
|
|
14781
15189
|
|
|
14782
15190
|
// src/lib/restart-context.ts
|
|
14783
|
-
import { readdirSync as readdirSync13, readFileSync as
|
|
14784
|
-
import { dirname as dirname10, join as
|
|
15191
|
+
import { readdirSync as readdirSync13, readFileSync as readFileSync36, writeFileSync as writeFileSync18, mkdirSync as mkdirSync17, unlinkSync as unlinkSync5 } from "fs";
|
|
15192
|
+
import { dirname as dirname10, join as join45 } from "path";
|
|
14785
15193
|
var SLACK_PENDING_INBOUND_DIRNAME = "slack-pending-inbound";
|
|
14786
15194
|
var SLACK_RESTART_CONTEXT_DIRNAME = "slack-restart-context";
|
|
14787
15195
|
var MAX_TOPIC_CHARS = 140;
|
|
@@ -14793,10 +15201,10 @@ function augmentedAgentDir(codeName) {
|
|
|
14793
15201
|
return dirname10(getProjectDir(codeName));
|
|
14794
15202
|
}
|
|
14795
15203
|
function slackPendingInboundDir(codeName) {
|
|
14796
|
-
return
|
|
15204
|
+
return join45(augmentedAgentDir(codeName), SLACK_PENDING_INBOUND_DIRNAME);
|
|
14797
15205
|
}
|
|
14798
15206
|
function slackRestartContextDir(codeName) {
|
|
14799
|
-
return
|
|
15207
|
+
return join45(augmentedAgentDir(codeName), SLACK_RESTART_CONTEXT_DIRNAME);
|
|
14800
15208
|
}
|
|
14801
15209
|
function sanitizeTopic(raw) {
|
|
14802
15210
|
const cleaned = raw.replace(/\s+/g, " ").trim().replace(/[<>]/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -14838,7 +15246,7 @@ function safeReaddir(dir) {
|
|
|
14838
15246
|
}
|
|
14839
15247
|
function readStrandedMarker(path) {
|
|
14840
15248
|
try {
|
|
14841
|
-
const parsed = JSON.parse(
|
|
15249
|
+
const parsed = JSON.parse(readFileSync36(path, "utf-8"));
|
|
14842
15250
|
if (typeof parsed.channel === "string" && typeof parsed.thread_ts === "string") {
|
|
14843
15251
|
return { channel: parsed.channel, thread_ts: parsed.thread_ts };
|
|
14844
15252
|
}
|
|
@@ -14847,7 +15255,7 @@ function readStrandedMarker(path) {
|
|
|
14847
15255
|
return null;
|
|
14848
15256
|
}
|
|
14849
15257
|
function writeHintFile(path, dir, hint) {
|
|
14850
|
-
|
|
15258
|
+
mkdirSync17(dir, { recursive: true, mode: 448 });
|
|
14851
15259
|
writeFileSync18(path, JSON.stringify(hint), { mode: 384 });
|
|
14852
15260
|
}
|
|
14853
15261
|
function pruneHintsExcept(codeName, freshFilenames) {
|
|
@@ -14856,7 +15264,7 @@ function pruneHintsExcept(codeName, freshFilenames) {
|
|
|
14856
15264
|
if (!filename.endsWith(".json")) continue;
|
|
14857
15265
|
if (freshFilenames.has(filename)) continue;
|
|
14858
15266
|
try {
|
|
14859
|
-
unlinkSync5(
|
|
15267
|
+
unlinkSync5(join45(ctxDir, filename));
|
|
14860
15268
|
} catch {
|
|
14861
15269
|
}
|
|
14862
15270
|
}
|
|
@@ -14877,7 +15285,7 @@ function refreshSlackRestartContextHints(codeNames, opts = {}) {
|
|
|
14877
15285
|
}
|
|
14878
15286
|
const markers = [];
|
|
14879
15287
|
for (const filename of markerFilenames.slice(0, cap)) {
|
|
14880
|
-
const parsed = readStrandedMarker(
|
|
15288
|
+
const parsed = readStrandedMarker(join45(markerDir, filename));
|
|
14881
15289
|
if (parsed) markers.push({ filename, channel: parsed.channel, thread_ts: parsed.thread_ts });
|
|
14882
15290
|
}
|
|
14883
15291
|
if (markers.length === 0) {
|
|
@@ -14891,7 +15299,7 @@ function refreshSlackRestartContextHints(codeNames, opts = {}) {
|
|
|
14891
15299
|
const freshFilenames = /* @__PURE__ */ new Set();
|
|
14892
15300
|
for (const { filename, hint } of hints) {
|
|
14893
15301
|
try {
|
|
14894
|
-
writeHintFile(
|
|
15302
|
+
writeHintFile(join45(ctxDir, filename), ctxDir, hint);
|
|
14895
15303
|
freshFilenames.add(filename);
|
|
14896
15304
|
} catch (err) {
|
|
14897
15305
|
log2(`[restart-context] ${codeName}: hint write failed for ${filename}: ${err.message}`);
|
|
@@ -15665,6 +16073,15 @@ function recordConfigChurnEvent(agentId, codeName, channel, signature) {
|
|
|
15665
16073
|
);
|
|
15666
16074
|
});
|
|
15667
16075
|
}
|
|
16076
|
+
var reloadUnknownStreak = new UnknownStreak();
|
|
16077
|
+
var reloadBlindSpawns = /* @__PURE__ */ new Set();
|
|
16078
|
+
var stragglerDeferStreak = new UnknownStreak();
|
|
16079
|
+
function reloadSessionSpawnedAt(codeName) {
|
|
16080
|
+
const s = getSessionState(codeName);
|
|
16081
|
+
if (!s || s.startedAt === null) return null;
|
|
16082
|
+
if (s.estimatedStartedAt != null && s.estimatedStartedAt === s.startedAt) return null;
|
|
16083
|
+
return s.startedAt;
|
|
16084
|
+
}
|
|
15668
16085
|
async function reportReaperEvent(agentId, reaper, action, reason) {
|
|
15669
16086
|
try {
|
|
15670
16087
|
await api.post("/host/reaper-event", {
|
|
@@ -15697,7 +16114,7 @@ async function runDangerousRmBackstop(agentId, codeName, pane) {
|
|
|
15697
16114
|
return;
|
|
15698
16115
|
}
|
|
15699
16116
|
const policy = readRmPolicyText(
|
|
15700
|
-
() =>
|
|
16117
|
+
() => readFileSync37(join46(getFramework("claude-code").getAgentDir(codeName), RM_POLICY_RELATIVE_PATH), "utf-8")
|
|
15701
16118
|
);
|
|
15702
16119
|
const decision = decideDangerousRm(action.prompt, policy, {
|
|
15703
16120
|
isolated: isolationMode(codeName) === "docker"
|
|
@@ -16418,7 +16835,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
|
|
|
16418
16835
|
var dayRolloverInboundHold = /* @__PURE__ */ new Map();
|
|
16419
16836
|
var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
|
|
16420
16837
|
async function channelInboundActivityAgeSecondsFor(codeName) {
|
|
16421
|
-
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-
|
|
16838
|
+
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-T6O4V2XZ.js");
|
|
16422
16839
|
const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
|
|
16423
16840
|
if (newest === null) return null;
|
|
16424
16841
|
return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
|
|
@@ -16785,18 +17202,66 @@ var anchorSessionLifecycle = new AnchorSessionLifecycle();
|
|
|
16785
17202
|
var runningMcpServerKeys = /* @__PURE__ */ new Map();
|
|
16786
17203
|
var runningChannelSecretHashes = /* @__PURE__ */ new Map();
|
|
16787
17204
|
var sessionLaunchManagedStructure = /* @__PURE__ */ new Map();
|
|
16788
|
-
function
|
|
17205
|
+
function readSpawnViewMcpConfig(codeName, projectDir) {
|
|
17206
|
+
const parsed = JSON.parse(readFileSync37(join46(projectDir, ".mcp.json"), "utf-8"));
|
|
17207
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return parsed;
|
|
17208
|
+
const agentId = agentState.codeNameToAgentId.get(codeName);
|
|
17209
|
+
const integrations = agentId ? lastIntegrationsPayload.get(agentId) : void 0;
|
|
17210
|
+
return spawnViewOfMcpConfig(parsed, integrations);
|
|
17211
|
+
}
|
|
17212
|
+
var sessionsSpawnedByThisProcess = /* @__PURE__ */ new Set();
|
|
17213
|
+
var spawnCopyFailures = new SpawnCopyFailureTracker();
|
|
17214
|
+
function reportSpawnCopyFailure(codeName, f) {
|
|
17215
|
+
const agentId = agentState.codeNameToAgentId.get(codeName);
|
|
17216
|
+
if (!agentId) return;
|
|
17217
|
+
void reportReaperEvent(
|
|
17218
|
+
agentId,
|
|
17219
|
+
"spawn-mcp-filter",
|
|
17220
|
+
"alert",
|
|
17221
|
+
`Agent '${codeName}' is running with removed integration server(s) ${f.dropped.map((k) => `'${k}'`).join(", ")} still declared: the filtered spawn config could not be written (${f.error}). Their tools are reachable until the copy is written or the integration's entry is pruned from .mcp.json. Drift restarts are held so this does not loop (ENG-12048).`
|
|
17222
|
+
);
|
|
17223
|
+
}
|
|
17224
|
+
function refreshHeldDropped(codeName, projectDir, held) {
|
|
17225
|
+
const agentId = agentState.codeNameToAgentId.get(codeName);
|
|
17226
|
+
const integrations = agentId ? lastIntegrationsPayload.get(agentId) : void 0;
|
|
17227
|
+
const now = [...spawnDroppedServerKeys(join46(projectDir, ".mcp.json"), integrations)];
|
|
17228
|
+
if (spawnCopyFailures.noteDropped(codeName, now)) {
|
|
17229
|
+
log(
|
|
17230
|
+
`[spawn-mcp-filter] ORPHAN_SPAWN_UNFILTERED_CHANGED agent='${codeName}' servers=${now.map((k) => `'${k}'`).join(", ")}: the set of removed servers still loaded changed while the copy failure is held (ENG-12048)`
|
|
17231
|
+
);
|
|
17232
|
+
}
|
|
17233
|
+
return spawnCopyFailures.held(codeName) ?? held;
|
|
17234
|
+
}
|
|
17235
|
+
function retryHeldSpawnCopy2(codeName, projectDir, held) {
|
|
17236
|
+
const agentId = agentState.codeNameToAgentId.get(codeName);
|
|
17237
|
+
const integrations = agentId ? lastIntegrationsPayload.get(agentId) : void 0;
|
|
17238
|
+
if (integrations === void 0) return held;
|
|
17239
|
+
return retryHeldSpawnCopy({ tracker: spawnCopyFailures, codeName, projectDir, held, integrations, resolveApiHost: requireHost, log });
|
|
17240
|
+
}
|
|
17241
|
+
function readSpawnedMcpConfig(path) {
|
|
16789
17242
|
try {
|
|
16790
|
-
const
|
|
16791
|
-
return
|
|
17243
|
+
const parsed = JSON.parse(readFileSync37(path, "utf-8"));
|
|
17244
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
16792
17245
|
} catch {
|
|
16793
17246
|
return null;
|
|
16794
17247
|
}
|
|
16795
17248
|
}
|
|
16796
|
-
function
|
|
17249
|
+
function readRawMcpConfig(projectDir) {
|
|
17250
|
+
return JSON.parse(readFileSync37(join46(projectDir, ".mcp.json"), "utf-8"));
|
|
17251
|
+
}
|
|
17252
|
+
function readMcpConfigFor(codeName, projectDir, source) {
|
|
17253
|
+
return source === "raw" ? readRawMcpConfig(projectDir) : readSpawnViewMcpConfig(codeName, projectDir);
|
|
17254
|
+
}
|
|
17255
|
+
function projectMcpHash(codeName, projectDir, source = "spawn-view") {
|
|
16797
17256
|
try {
|
|
16798
|
-
|
|
16799
|
-
|
|
17257
|
+
return hashMcpConfig(readMcpConfigFor(codeName, projectDir, source));
|
|
17258
|
+
} catch {
|
|
17259
|
+
return null;
|
|
17260
|
+
}
|
|
17261
|
+
}
|
|
17262
|
+
function projectMcpKeys(codeName, projectDir, source = "spawn-view") {
|
|
17263
|
+
try {
|
|
17264
|
+
const parsed = readMcpConfigFor(codeName, projectDir, source);
|
|
16800
17265
|
const servers = parsed.mcpServers;
|
|
16801
17266
|
if (!servers || typeof servers !== "object") return /* @__PURE__ */ new Set();
|
|
16802
17267
|
return new Set(Object.keys(servers));
|
|
@@ -16804,16 +17269,18 @@ function projectMcpKeys(_codeName, projectDir) {
|
|
|
16804
17269
|
return null;
|
|
16805
17270
|
}
|
|
16806
17271
|
}
|
|
16807
|
-
function seedSessionLaunchBaselines(codeName, projectDir) {
|
|
16808
|
-
|
|
16809
|
-
const
|
|
17272
|
+
function seedSessionLaunchBaselines(codeName, projectDir, spawnMcpConfigPath) {
|
|
17273
|
+
sessionsSpawnedByThisProcess.add(codeName);
|
|
17274
|
+
const given = spawnMcpConfigPath ? readSpawnedMcpConfig(spawnMcpConfigPath) : void 0;
|
|
17275
|
+
const hash = given === void 0 ? projectMcpHash(codeName, projectDir) : given === null ? null : hashMcpConfig(given);
|
|
17276
|
+
const keys = given === void 0 ? projectMcpKeys(codeName, projectDir) : given === null ? null : new Set(Object.keys(given.mcpServers ?? {}));
|
|
16810
17277
|
if (hash) runningMcpHashes.set(codeName, hash);
|
|
16811
17278
|
else runningMcpHashes.delete(codeName);
|
|
16812
17279
|
if (keys) runningMcpServerKeys.set(codeName, keys);
|
|
16813
17280
|
else runningMcpServerKeys.delete(codeName);
|
|
16814
17281
|
let launchStructure = null;
|
|
16815
17282
|
try {
|
|
16816
|
-
const raw =
|
|
17283
|
+
const raw = readFileSync37(join46(projectDir, ".mcp.json"), "utf-8");
|
|
16817
17284
|
launchStructure = managedMcpStructureHashFromFile(
|
|
16818
17285
|
JSON.parse(raw),
|
|
16819
17286
|
isManagedMcpServerKey
|
|
@@ -16965,7 +17432,7 @@ async function runAgentSessionToolBindProbes(agent, integrations, projectDir, op
|
|
|
16965
17432
|
if (result && result.rebindCandidates.length > 0 && hostFlagStore().getBoolean("session-tool-rebind")) {
|
|
16966
17433
|
let mcpJsonForRebind = null;
|
|
16967
17434
|
try {
|
|
16968
|
-
mcpJsonForRebind = JSON.parse(
|
|
17435
|
+
mcpJsonForRebind = JSON.parse(readFileSync37(join46(projectDir, ".mcp.json"), "utf-8"));
|
|
16969
17436
|
} catch {
|
|
16970
17437
|
mcpJsonForRebind = null;
|
|
16971
17438
|
}
|
|
@@ -17047,8 +17514,11 @@ function checkMcpConfigDriftAndScheduleRestart(codeName, projectDir) {
|
|
|
17047
17514
|
case "no-drift":
|
|
17048
17515
|
return;
|
|
17049
17516
|
case "baseline": {
|
|
17050
|
-
|
|
17051
|
-
const
|
|
17517
|
+
const baselineSource = sessionsSpawnedByThisProcess.has(codeName) ? "spawn-view" : "raw";
|
|
17518
|
+
const rawHash = projectMcpHash(codeName, projectDir, baselineSource);
|
|
17519
|
+
if (rawHash === null) return;
|
|
17520
|
+
runningMcpHashes.set(codeName, rawHash);
|
|
17521
|
+
const baselineKeys = projectMcpKeys(codeName, projectDir, baselineSource);
|
|
17052
17522
|
if (baselineKeys) {
|
|
17053
17523
|
runningMcpServerKeys.set(codeName, baselineKeys);
|
|
17054
17524
|
} else {
|
|
@@ -17057,6 +17527,18 @@ function checkMcpConfigDriftAndScheduleRestart(codeName, projectDir) {
|
|
|
17057
17527
|
return;
|
|
17058
17528
|
}
|
|
17059
17529
|
case "drift": {
|
|
17530
|
+
let heldFailure = spawnCopyFailures.holdsDriftRestart(codeName, projectMcpHash(codeName, projectDir, "raw"));
|
|
17531
|
+
if (heldFailure && spawnCopyFailures.retryDue(codeName)) {
|
|
17532
|
+
heldFailure = retryHeldSpawnCopy2(codeName, projectDir, heldFailure);
|
|
17533
|
+
}
|
|
17534
|
+
if (heldFailure) heldFailure = refreshHeldDropped(codeName, projectDir, heldFailure);
|
|
17535
|
+
if (heldFailure) {
|
|
17536
|
+
log(
|
|
17537
|
+
`[spawn-mcp-filter] ORPHAN_SPAWN_UNFILTERED agent='${codeName}' servers=${heldFailure.dropped.map((k) => `'${k}'`).join(", ")} reason=${heldFailure.error}; drift restart held (the respawn would fail the same way) (ENG-12048)`
|
|
17538
|
+
);
|
|
17539
|
+
reportSpawnCopyFailure(codeName, heldFailure);
|
|
17540
|
+
return;
|
|
17541
|
+
}
|
|
17060
17542
|
log(
|
|
17061
17543
|
`[hot-reload] .mcp.json content changed for '${codeName}' (${action.previous.slice(0, 12)} \u2192 ${action.current.slice(0, 12)}) (ENG-4897)`
|
|
17062
17544
|
);
|
|
@@ -17114,7 +17596,7 @@ function shouldInjectChannelSecrets(agentId) {
|
|
|
17114
17596
|
function projectChannelSecretHash(projectDir) {
|
|
17115
17597
|
try {
|
|
17116
17598
|
const entries = parseEnvIntegrations(
|
|
17117
|
-
|
|
17599
|
+
readFileSync37(join46(projectDir, ".env.integrations"), "utf-8")
|
|
17118
17600
|
);
|
|
17119
17601
|
return channelSecretValueHash(entries, CHANNEL_SECRET_ENV_KEYS);
|
|
17120
17602
|
} catch {
|
|
@@ -17234,7 +17716,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
17234
17716
|
var lastVersionCheckAt = 0;
|
|
17235
17717
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
17236
17718
|
var lastResponsivenessProbeAt = 0;
|
|
17237
|
-
var agtCliVersion = true ? "0.28.
|
|
17719
|
+
var agtCliVersion = true ? "0.28.1268" : "dev";
|
|
17238
17720
|
function resolveBrewPath(execFileSync4) {
|
|
17239
17721
|
try {
|
|
17240
17722
|
const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -17794,7 +18276,7 @@ function runAsync(cmd, args, opts) {
|
|
|
17794
18276
|
});
|
|
17795
18277
|
}
|
|
17796
18278
|
function claudeManagedSettingsPath() {
|
|
17797
|
-
return
|
|
18279
|
+
return join46(CLAUDE_MANAGED_SETTINGS_DIR, "managed-settings.json");
|
|
17798
18280
|
}
|
|
17799
18281
|
var MANAGED_SETTINGS_KEYS = ["channelsEnabled", "enableAllProjectMcpServers"];
|
|
17800
18282
|
var MANAGED_SETTINGS_ENV = { DISABLE_AUTOUPDATER: "1" };
|
|
@@ -17817,7 +18299,7 @@ function deniedTools(settings) {
|
|
|
17817
18299
|
}
|
|
17818
18300
|
function readCrossSessionBlockStatus(path = claudeManagedSettingsPath()) {
|
|
17819
18301
|
try {
|
|
17820
|
-
const parsed = JSON.parse(
|
|
18302
|
+
const parsed = JSON.parse(readFileSync37(path, "utf-8"));
|
|
17821
18303
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return "missing";
|
|
17822
18304
|
const settings = parsed;
|
|
17823
18305
|
const deny = deniedTools(settings);
|
|
@@ -17857,7 +18339,7 @@ function ensureClaudeManagedSettings(path = claudeManagedSettingsPath(), write =
|
|
|
17857
18339
|
try {
|
|
17858
18340
|
let settings = {};
|
|
17859
18341
|
if (existsSync20(path)) {
|
|
17860
|
-
const raw =
|
|
18342
|
+
const raw = readFileSync37(path, "utf-8").trim();
|
|
17861
18343
|
if (raw) {
|
|
17862
18344
|
let parsed;
|
|
17863
18345
|
try {
|
|
@@ -17898,7 +18380,7 @@ function ensureClaudeManagedSettings(path = claudeManagedSettingsPath(), write =
|
|
|
17898
18380
|
const body = `${JSON.stringify(settings, null, 2)}
|
|
17899
18381
|
`;
|
|
17900
18382
|
try {
|
|
17901
|
-
|
|
18383
|
+
mkdirSync18(dirname11(path), { recursive: true });
|
|
17902
18384
|
write(path, body);
|
|
17903
18385
|
} catch (err) {
|
|
17904
18386
|
if (channelKeysNeeded) throw err;
|
|
@@ -17950,7 +18432,7 @@ async function ensureOpencodeBinary() {
|
|
|
17950
18432
|
try {
|
|
17951
18433
|
const prefix = execFileSync4("npm", ["prefix", "-g"], { encoding: "utf-8", timeout: 1e4 }).trim();
|
|
17952
18434
|
if (prefix) {
|
|
17953
|
-
const npmBin =
|
|
18435
|
+
const npmBin = join46(prefix, "bin");
|
|
17954
18436
|
const current = (process.env.PATH ?? "").split(pathDelimiter);
|
|
17955
18437
|
if (!current.includes(npmBin)) {
|
|
17956
18438
|
process.env.PATH = [npmBin, ...current.filter(Boolean)].join(pathDelimiter);
|
|
@@ -18021,7 +18503,7 @@ async function ensureFrameworkBinary(frameworkId) {
|
|
|
18021
18503
|
agentRuntimeAuthenticated = await checkClaudeAuth();
|
|
18022
18504
|
}
|
|
18023
18505
|
var claudeCodeUpgradeInFlight = false;
|
|
18024
|
-
var SCRATCH_HOLDS_DIR = () =>
|
|
18506
|
+
var SCRATCH_HOLDS_DIR = () => join46(homedir17(), ".augmented", ".manager-scratch-holds");
|
|
18025
18507
|
setScratchSweepPolicyResolver(
|
|
18026
18508
|
(codeName) => resolveScratchSweepPolicy({
|
|
18027
18509
|
agentId: agentState.codeNameToAgentId.get(codeName),
|
|
@@ -18100,7 +18582,7 @@ async function maybeUpgradeClaudeCode() {
|
|
|
18100
18582
|
}
|
|
18101
18583
|
var UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
18102
18584
|
function selfUpdateAppliedMarkerPath() {
|
|
18103
|
-
return
|
|
18585
|
+
return join46(homedir17(), ".augmented", ".last-self-update-applied");
|
|
18104
18586
|
}
|
|
18105
18587
|
var selfUpdateUpToDateLogged = false;
|
|
18106
18588
|
var selfUpdatePinnedLogged = false;
|
|
@@ -18151,7 +18633,7 @@ async function checkAndUpdateCli(opts) {
|
|
|
18151
18633
|
const isNpmGlobal = !isBrewFormula && resolvedPath.includes("node_modules");
|
|
18152
18634
|
if (!isBrewFormula && !isNpmGlobal) return "noop";
|
|
18153
18635
|
const { readFileSync: readF, writeFileSync: writeF } = await import("fs");
|
|
18154
|
-
const markerPath =
|
|
18636
|
+
const markerPath = join46(homedir17(), ".augmented", ".last-update-check");
|
|
18155
18637
|
if (!force) {
|
|
18156
18638
|
try {
|
|
18157
18639
|
const lastCheck = parseInt(readF(markerPath, "utf-8").trim(), 10);
|
|
@@ -18655,12 +19137,12 @@ async function checkClaudeAuth() {
|
|
|
18655
19137
|
var evalEmptyMcpConfigPath = null;
|
|
18656
19138
|
function ensureEvalEmptyMcpConfig() {
|
|
18657
19139
|
if (evalEmptyMcpConfigPath && existsSync20(evalEmptyMcpConfigPath)) return evalEmptyMcpConfigPath;
|
|
18658
|
-
const dir =
|
|
19140
|
+
const dir = join46(homedir17(), ".augmented");
|
|
18659
19141
|
try {
|
|
18660
|
-
|
|
19142
|
+
mkdirSync18(dir, { recursive: true });
|
|
18661
19143
|
} catch {
|
|
18662
19144
|
}
|
|
18663
|
-
const p =
|
|
19145
|
+
const p = join46(dir, ".eval-empty-mcp.json");
|
|
18664
19146
|
writeFileSync19(p, JSON.stringify({ mcpServers: {} }));
|
|
18665
19147
|
evalEmptyMcpConfigPath = p;
|
|
18666
19148
|
return p;
|
|
@@ -18751,10 +19233,10 @@ function resolveConversationEvalBackend() {
|
|
|
18751
19233
|
return conversationEvalBackend;
|
|
18752
19234
|
}
|
|
18753
19235
|
function getStateFile() {
|
|
18754
|
-
return
|
|
19236
|
+
return join46(config?.configDir ?? join46(process.env["HOME"] ?? "/tmp", ".augmented"), "manager-state.json");
|
|
18755
19237
|
}
|
|
18756
19238
|
function channelHashCacheDir() {
|
|
18757
|
-
return config?.configDir ??
|
|
19239
|
+
return config?.configDir ?? join46(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
18758
19240
|
}
|
|
18759
19241
|
function loadChannelHashCache2() {
|
|
18760
19242
|
loadChannelHashCache(agentState.knownChannelConfigHashes, channelHashCacheDir());
|
|
@@ -18967,7 +19449,7 @@ function removeDeliveryBaselineEntries(agentId) {
|
|
|
18967
19449
|
var _channelQuarantineStore = null;
|
|
18968
19450
|
function channelQuarantineStore() {
|
|
18969
19451
|
if (!_channelQuarantineStore) {
|
|
18970
|
-
const dir = config?.configDir ??
|
|
19452
|
+
const dir = config?.configDir ?? join46(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
18971
19453
|
_channelQuarantineStore = new ChannelQuarantineStore(defaultQuarantinePath(dir));
|
|
18972
19454
|
}
|
|
18973
19455
|
return _channelQuarantineStore;
|
|
@@ -18975,7 +19457,7 @@ function channelQuarantineStore() {
|
|
|
18975
19457
|
var _channelResumeHistoryStore = null;
|
|
18976
19458
|
function channelResumeHistoryStore() {
|
|
18977
19459
|
if (!_channelResumeHistoryStore) {
|
|
18978
|
-
const dir = config?.configDir ??
|
|
19460
|
+
const dir = config?.configDir ?? join46(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
18979
19461
|
_channelResumeHistoryStore = new ChannelResumeHistoryStore(defaultResumeHistoryPath(dir));
|
|
18980
19462
|
}
|
|
18981
19463
|
return _channelResumeHistoryStore;
|
|
@@ -19020,12 +19502,12 @@ function sessionActivityFor(codeName, pane, opts = {}) {
|
|
|
19020
19502
|
}
|
|
19021
19503
|
function forwardedToolsFor(codeName) {
|
|
19022
19504
|
if (!config?.configDir) return null;
|
|
19023
|
-
return readForwardedToolsReport(
|
|
19505
|
+
return readForwardedToolsReport(join46(config.configDir, codeName));
|
|
19024
19506
|
}
|
|
19025
19507
|
var _hostFlagStore = null;
|
|
19026
19508
|
function hostFlagStore() {
|
|
19027
19509
|
if (!_hostFlagStore) {
|
|
19028
|
-
const dir = config?.configDir ??
|
|
19510
|
+
const dir = config?.configDir ?? join46(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
19029
19511
|
_hostFlagStore = new HostFlagStore({ cachePath: defaultFlagsCachePath(dir), log });
|
|
19030
19512
|
}
|
|
19031
19513
|
return _hostFlagStore;
|
|
@@ -19099,12 +19581,12 @@ function parseSkillFrontmatter(content) {
|
|
|
19099
19581
|
}
|
|
19100
19582
|
async function refreshSkillsIndexInClaudeMd(configDir, codeName, log2) {
|
|
19101
19583
|
const { readdirSync: readdirSync15, readFileSync: rfs, existsSync: ex, writeFileSync: writeFileSync20 } = await import("fs");
|
|
19102
|
-
const skillsDir =
|
|
19103
|
-
const claudeMdPath =
|
|
19584
|
+
const skillsDir = join46(configDir, codeName, "project", ".claude", "skills");
|
|
19585
|
+
const claudeMdPath = join46(configDir, codeName, "project", "CLAUDE.md");
|
|
19104
19586
|
if (!ex(skillsDir) || !ex(claudeMdPath)) return;
|
|
19105
19587
|
const entries = [];
|
|
19106
19588
|
for (const dir of readdirSync15(skillsDir).sort()) {
|
|
19107
|
-
const skillFile =
|
|
19589
|
+
const skillFile = join46(skillsDir, dir, "SKILL.md");
|
|
19108
19590
|
if (!ex(skillFile)) continue;
|
|
19109
19591
|
try {
|
|
19110
19592
|
const { name, description } = parseSkillFrontmatter(rfs(skillFile, "utf-8"));
|
|
@@ -19243,7 +19725,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
|
|
|
19243
19725
|
if (codeNames.length === 0) return;
|
|
19244
19726
|
void (async () => {
|
|
19245
19727
|
try {
|
|
19246
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
19728
|
+
const { collectDiagnostics } = await import("../persistent-session-BLZPYHBE.js");
|
|
19247
19729
|
await api.post("/host/heartbeat", {
|
|
19248
19730
|
host_id: hostId,
|
|
19249
19731
|
agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -19386,7 +19868,7 @@ async function pollCycleInner() {
|
|
|
19386
19868
|
}
|
|
19387
19869
|
try {
|
|
19388
19870
|
const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
|
|
19389
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
19871
|
+
const { collectDiagnostics } = await import("../persistent-session-BLZPYHBE.js");
|
|
19390
19872
|
const diagCodeNames = [...agentState.persistentSessionAgents];
|
|
19391
19873
|
const agentDiagnostics = diagCodeNames.length > 0 ? collectDiagnostics(diagCodeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor) : void 0;
|
|
19392
19874
|
let tailscaleHostname;
|
|
@@ -19416,7 +19898,7 @@ async function pollCycleInner() {
|
|
|
19416
19898
|
claudeAuth = await detectClaudeAuth();
|
|
19417
19899
|
} catch (err) {
|
|
19418
19900
|
const errText = err instanceof Error ? err.message : String(err);
|
|
19419
|
-
const errId =
|
|
19901
|
+
const errId = createHash21("sha256").update(errText).digest("hex").slice(0, 12);
|
|
19420
19902
|
log(`Claude auth detection failed (error_id=${errId})`);
|
|
19421
19903
|
}
|
|
19422
19904
|
let claudeAccountEmail = null;
|
|
@@ -19692,7 +20174,7 @@ async function pollCycleInner() {
|
|
|
19692
20174
|
collectPanelessActivityProbes,
|
|
19693
20175
|
getResponsivenessIntervalMs,
|
|
19694
20176
|
occupancyQualificationClassifications
|
|
19695
|
-
} = await import("../responsiveness-probe-
|
|
20177
|
+
} = await import("../responsiveness-probe-T6O4V2XZ.js");
|
|
19696
20178
|
const probeIntervalMs = getResponsivenessIntervalMs();
|
|
19697
20179
|
if (now - lastResponsivenessProbeAt > probeIntervalMs) {
|
|
19698
20180
|
const probeCodeNames = [...agentState.persistentSessionAgents];
|
|
@@ -19809,7 +20291,7 @@ async function pollCycleInner() {
|
|
|
19809
20291
|
collectResponsivenessProbes,
|
|
19810
20292
|
livePendingInboundOldestAgeSeconds,
|
|
19811
20293
|
parkPendingInbound
|
|
19812
|
-
} = await import("../responsiveness-probe-
|
|
20294
|
+
} = await import("../responsiveness-probe-T6O4V2XZ.js");
|
|
19813
20295
|
const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
|
|
19814
20296
|
const wedgeNow = /* @__PURE__ */ new Date();
|
|
19815
20297
|
const liveAgents = agentState.persistentSessionAgents;
|
|
@@ -19898,13 +20380,13 @@ async function pollCycleInner() {
|
|
|
19898
20380
|
);
|
|
19899
20381
|
if (hostFlagStore().getBoolean("wedge-transient-notice")) {
|
|
19900
20382
|
try {
|
|
19901
|
-
const paneTail =
|
|
20383
|
+
const paneTail = readFileSync37(paneLogPath(codeName), "utf8").slice(-65536);
|
|
19902
20384
|
const transient = detectTransientApiErrorInLog(paneTail);
|
|
19903
20385
|
if (transient) {
|
|
19904
|
-
const wedgeHome =
|
|
20386
|
+
const wedgeHome = join46(homedir17(), ".augmented", codeName);
|
|
19905
20387
|
if (existsSync20(wedgeHome)) {
|
|
19906
20388
|
atomicWriteFileSync(
|
|
19907
|
-
|
|
20389
|
+
join46(wedgeHome, "watchdog-give-up.json"),
|
|
19908
20390
|
JSON.stringify({
|
|
19909
20391
|
gave_up_at: wedgeNow.toISOString(),
|
|
19910
20392
|
reason: "transient_overload"
|
|
@@ -20095,7 +20577,7 @@ async function pollCycleInner() {
|
|
|
20095
20577
|
}
|
|
20096
20578
|
}
|
|
20097
20579
|
);
|
|
20098
|
-
const { parkPendingInbound } = await import("../responsiveness-probe-
|
|
20580
|
+
const { parkPendingInbound } = await import("../responsiveness-probe-T6O4V2XZ.js");
|
|
20099
20581
|
const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
|
|
20100
20582
|
paneFatalStreak.delete(codeName);
|
|
20101
20583
|
paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
|
|
@@ -20126,7 +20608,7 @@ async function pollCycleInner() {
|
|
|
20126
20608
|
TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
|
|
20127
20609
|
bindSourceEscalations
|
|
20128
20610
|
} = await import("../transcript-mount-health-OHE6IVJV.js");
|
|
20129
|
-
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-
|
|
20611
|
+
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-BLZPYHBE.js");
|
|
20130
20612
|
const mountConfig = resolveTranscriptMountConfig();
|
|
20131
20613
|
const liveAgents = agentState.persistentSessionAgents;
|
|
20132
20614
|
for (const tracked of [
|
|
@@ -20845,7 +21327,7 @@ async function pollCycleInner() {
|
|
|
20845
21327
|
`[drain-flush] FAILED for '${prev.codeName}': ${err.message} \u2014 proceeding to teardown; this session was NOT shipped (ENG-9491)`
|
|
20846
21328
|
);
|
|
20847
21329
|
}
|
|
20848
|
-
const agentDir =
|
|
21330
|
+
const agentDir = join46(adapter.getAgentDir(prev.codeName), "provision");
|
|
20849
21331
|
await cleanupAgentFiles(prev.codeName, agentDir);
|
|
20850
21332
|
clearAgentCaches(prev.agentId, prev.codeName);
|
|
20851
21333
|
}
|
|
@@ -20924,10 +21406,10 @@ async function pollCycleInner() {
|
|
|
20924
21406
|
// pending-inbound marker. Best-effort: a write failure is logged by
|
|
20925
21407
|
// the watchdog, never fails the poll cycle.
|
|
20926
21408
|
signalGiveUp: (codeName) => {
|
|
20927
|
-
const dir =
|
|
21409
|
+
const dir = join46(homedir17(), ".augmented", codeName);
|
|
20928
21410
|
if (!existsSync20(dir)) return;
|
|
20929
21411
|
atomicWriteFileSync(
|
|
20930
|
-
|
|
21412
|
+
join46(dir, "watchdog-give-up.json"),
|
|
20931
21413
|
JSON.stringify({ gave_up_at: (/* @__PURE__ */ new Date()).toISOString() })
|
|
20932
21414
|
);
|
|
20933
21415
|
},
|
|
@@ -20955,20 +21437,20 @@ async function pollCycleInner() {
|
|
|
20955
21437
|
const dir = getFramework("claude-code").getAgentDir(codeName);
|
|
20956
21438
|
if (!existsSync20(dir)) return;
|
|
20957
21439
|
atomicWriteFileSync(
|
|
20958
|
-
|
|
21440
|
+
join46(dir, "blocked-prompt.json"),
|
|
20959
21441
|
JSON.stringify({ kind, last_seen_at: (/* @__PURE__ */ new Date()).toISOString() })
|
|
20960
21442
|
);
|
|
20961
21443
|
},
|
|
20962
21444
|
clearBlockedPromptLiveness: (codeName) => {
|
|
20963
|
-
const file =
|
|
21445
|
+
const file = join46(getFramework("claude-code").getAgentDir(codeName), "blocked-prompt.json");
|
|
20964
21446
|
if (existsSync20(file)) rmSync9(file, { force: true });
|
|
20965
21447
|
},
|
|
20966
21448
|
refreshUsageLimitLiveness: (codeName) => {
|
|
20967
21449
|
const dir = getFramework("claude-code").getAgentDir(codeName);
|
|
20968
|
-
const file =
|
|
21450
|
+
const file = join46(dir, "watchdog-give-up.json");
|
|
20969
21451
|
if (!existsSync20(file)) return;
|
|
20970
21452
|
try {
|
|
20971
|
-
const raw = JSON.parse(
|
|
21453
|
+
const raw = JSON.parse(readFileSync37(file, "utf8"));
|
|
20972
21454
|
if (raw["reason"] !== "usage_limit") return;
|
|
20973
21455
|
raw["usage_limit_last_seen_at"] = (/* @__PURE__ */ new Date()).toISOString();
|
|
20974
21456
|
atomicWriteFileSync(file, JSON.stringify(raw));
|
|
@@ -20979,7 +21461,7 @@ async function pollCycleInner() {
|
|
|
20979
21461
|
const dir = getFramework("claude-code").getAgentDir(codeName);
|
|
20980
21462
|
if (!existsSync20(dir)) return;
|
|
20981
21463
|
atomicWriteFileSync(
|
|
20982
|
-
|
|
21464
|
+
join46(dir, "watchdog-give-up.json"),
|
|
20983
21465
|
JSON.stringify({
|
|
20984
21466
|
gave_up_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20985
21467
|
reason: "usage_limit",
|
|
@@ -21256,7 +21738,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21256
21738
|
}
|
|
21257
21739
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
21258
21740
|
const adapter = resolveAgentFramework(agent.code_name);
|
|
21259
|
-
let agentDir =
|
|
21741
|
+
let agentDir = join46(adapter.getAgentDir(agent.code_name), "provision");
|
|
21260
21742
|
if (agent.status === "draft" || agent.status === "paused") {
|
|
21261
21743
|
forgetChannelSyncState(agent.agent_id);
|
|
21262
21744
|
reapLegacyTokenFileEdgeWarned(agent.code_name, log);
|
|
@@ -21404,7 +21886,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21404
21886
|
if (refreshData.knowledge_manifest) {
|
|
21405
21887
|
const resolved = await resolveKnowledgeFromManifest({
|
|
21406
21888
|
manifest: refreshData.knowledge_manifest,
|
|
21407
|
-
cacheDir:
|
|
21889
|
+
cacheDir: join46(config.configDir, "_knowledge"),
|
|
21408
21890
|
delivery: refreshData.agent?.knowledge_delivery ?? "both",
|
|
21409
21891
|
fetchContents: async (hashes) => {
|
|
21410
21892
|
const res = await api.post(
|
|
@@ -21421,7 +21903,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21421
21903
|
const resolvedSkills = await resolveSkillsFromManifest({
|
|
21422
21904
|
globals: refreshData.global_skills_manifest ?? [],
|
|
21423
21905
|
shared: refreshData.shared_skills_manifest ?? [],
|
|
21424
|
-
cacheDir:
|
|
21906
|
+
cacheDir: join46(config.configDir, "_skills"),
|
|
21425
21907
|
fetchContents: async (hashes) => {
|
|
21426
21908
|
const res = await api.post(
|
|
21427
21909
|
"/host/skills/contents",
|
|
@@ -21439,7 +21921,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21439
21921
|
if (refreshData.integration_skills_manifest) {
|
|
21440
21922
|
const resolvedIntegrationSkills = await resolveIntegrationSkillsFromManifest({
|
|
21441
21923
|
manifest: refreshData.integration_skills_manifest,
|
|
21442
|
-
cacheDir:
|
|
21924
|
+
cacheDir: join46(config.configDir, "_skills"),
|
|
21443
21925
|
fetchContents: async (hashes) => {
|
|
21444
21926
|
const res = await api.post(
|
|
21445
21927
|
"/host/skills/contents",
|
|
@@ -21501,7 +21983,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21501
21983
|
const frameworkId = refreshData.agent.framework ?? DEFAULT_FRAMEWORK;
|
|
21502
21984
|
agentFrameworkCache.set(agent.code_name, frameworkId);
|
|
21503
21985
|
const frameworkAdapter = getFramework(frameworkId);
|
|
21504
|
-
agentDir =
|
|
21986
|
+
agentDir = join46(frameworkAdapter.getAgentDir(agent.code_name), "provision");
|
|
21505
21987
|
cacheAgentDeliveryMetadata(agent.code_name, refreshData);
|
|
21506
21988
|
agentRestartTimezoneInputs.set(agent.code_name, {
|
|
21507
21989
|
agentTimezone: typeof refreshData.agent.timezone === "string" ? refreshData.agent.timezone : null,
|
|
@@ -21577,9 +22059,9 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21577
22059
|
}
|
|
21578
22060
|
const artifacts = generateArtifacts(agent, provisionRefreshData, frameworkAdapter, renderIntegrationsSection);
|
|
21579
22061
|
const changedFiles = [];
|
|
21580
|
-
|
|
22062
|
+
mkdirSync18(agentDir, { recursive: true });
|
|
21581
22063
|
for (const artifact of artifacts) {
|
|
21582
|
-
const filePath =
|
|
22064
|
+
const filePath = join46(agentDir, artifact.relativePath);
|
|
21583
22065
|
let existingHash;
|
|
21584
22066
|
let newHash;
|
|
21585
22067
|
let writeContent = artifact.content;
|
|
@@ -21598,8 +22080,8 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21598
22080
|
};
|
|
21599
22081
|
newHash = sha256(stripDynamicSections(artifact.content));
|
|
21600
22082
|
try {
|
|
21601
|
-
const projectClaudeMd =
|
|
21602
|
-
const existing =
|
|
22083
|
+
const projectClaudeMd = join46(config.configDir, agent.code_name, "project", "CLAUDE.md");
|
|
22084
|
+
const existing = readFileSync37(projectClaudeMd, "utf-8");
|
|
21603
22085
|
existingHash = sha256(stripDynamicSections(existing));
|
|
21604
22086
|
} catch {
|
|
21605
22087
|
existingHash = null;
|
|
@@ -21617,7 +22099,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21617
22099
|
const generatorKeys = Object.keys(generatorServers);
|
|
21618
22100
|
let existingRaw = "";
|
|
21619
22101
|
try {
|
|
21620
|
-
existingRaw =
|
|
22102
|
+
existingRaw = readFileSync37(filePath, "utf-8");
|
|
21621
22103
|
} catch {
|
|
21622
22104
|
}
|
|
21623
22105
|
const existingServers = parseMcp(existingRaw);
|
|
@@ -21633,7 +22115,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21633
22115
|
} else if (artifact.relativePath === "opencode.json") {
|
|
21634
22116
|
let existingRaw = null;
|
|
21635
22117
|
try {
|
|
21636
|
-
existingRaw =
|
|
22118
|
+
existingRaw = readFileSync37(filePath, "utf-8");
|
|
21637
22119
|
} catch {
|
|
21638
22120
|
}
|
|
21639
22121
|
const mergeResult = mergeOpencodeConfigArtifact(artifact.content, existingRaw);
|
|
@@ -21649,13 +22131,13 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21649
22131
|
}
|
|
21650
22132
|
}
|
|
21651
22133
|
if (changedFiles.length > 0) {
|
|
21652
|
-
const isFirst = !existsSync20(
|
|
22134
|
+
const isFirst = !existsSync20(join46(agentDir, "CHARTER.md"));
|
|
21653
22135
|
const verb = isFirst ? "Provisioning" : "Updating";
|
|
21654
22136
|
const fileNames = changedFiles.map((f) => f.relativePath).join(", ");
|
|
21655
22137
|
log(`${verb} '${agent.code_name}': ${fileNames}`);
|
|
21656
22138
|
for (const file of changedFiles) {
|
|
21657
|
-
const filePath =
|
|
21658
|
-
|
|
22139
|
+
const filePath = join46(agentDir, file.relativePath);
|
|
22140
|
+
mkdirSync18(dirname11(filePath), { recursive: true });
|
|
21659
22141
|
if (file.relativePath === ".mcp.json") {
|
|
21660
22142
|
safeWriteJsonAtomic(filePath, file.content, { mode: 384 });
|
|
21661
22143
|
} else {
|
|
@@ -21663,12 +22145,12 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21663
22145
|
}
|
|
21664
22146
|
}
|
|
21665
22147
|
try {
|
|
21666
|
-
const provSkillsDir =
|
|
22148
|
+
const provSkillsDir = join46(agentDir, ".claude", "skills");
|
|
21667
22149
|
if (existsSync20(provSkillsDir)) {
|
|
21668
22150
|
for (const folder of readdirSync14(provSkillsDir)) {
|
|
21669
22151
|
if (folder.startsWith("knowledge-")) {
|
|
21670
22152
|
try {
|
|
21671
|
-
rmSync9(
|
|
22153
|
+
rmSync9(join46(provSkillsDir, folder), { recursive: true });
|
|
21672
22154
|
} catch {
|
|
21673
22155
|
}
|
|
21674
22156
|
}
|
|
@@ -21681,7 +22163,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21681
22163
|
const trackedFiles2 = frameworkAdapter.driftTrackedFiles();
|
|
21682
22164
|
const hashes = /* @__PURE__ */ new Map();
|
|
21683
22165
|
for (const file of trackedFiles2) {
|
|
21684
|
-
const h = hashFile(
|
|
22166
|
+
const h = hashFile(join46(agentDir, file));
|
|
21685
22167
|
if (h) hashes.set(file, h);
|
|
21686
22168
|
}
|
|
21687
22169
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -21699,14 +22181,14 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21699
22181
|
}
|
|
21700
22182
|
if (Array.isArray(refreshData.workflows)) {
|
|
21701
22183
|
try {
|
|
21702
|
-
const provWorkflowsDir =
|
|
22184
|
+
const provWorkflowsDir = join46(agentDir, ".claude", "workflows");
|
|
21703
22185
|
if (existsSync20(provWorkflowsDir)) {
|
|
21704
22186
|
const expected = new Set(refreshData.workflows.map((w) => `${w.name}.js`));
|
|
21705
22187
|
for (const file of readdirSync14(provWorkflowsDir)) {
|
|
21706
22188
|
if (!file.endsWith(".js")) continue;
|
|
21707
22189
|
if (expected.has(file)) continue;
|
|
21708
22190
|
try {
|
|
21709
|
-
rmSync9(
|
|
22191
|
+
rmSync9(join46(provWorkflowsDir, file));
|
|
21710
22192
|
} catch {
|
|
21711
22193
|
}
|
|
21712
22194
|
}
|
|
@@ -21801,7 +22283,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21801
22283
|
if (written && existsSync20(agentDir)) {
|
|
21802
22284
|
const driftedFiles = [];
|
|
21803
22285
|
for (const [file, expectedHash] of written) {
|
|
21804
|
-
const localHash = hashFile(
|
|
22286
|
+
const localHash = hashFile(join46(agentDir, file));
|
|
21805
22287
|
if (localHash && localHash !== expectedHash) {
|
|
21806
22288
|
driftedFiles.push(file);
|
|
21807
22289
|
}
|
|
@@ -21812,7 +22294,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
21812
22294
|
try {
|
|
21813
22295
|
const localHashes = {};
|
|
21814
22296
|
for (const file of driftedFiles) {
|
|
21815
|
-
localHashes[file] = hashFile(
|
|
22297
|
+
localHashes[file] = hashFile(join46(agentDir, file));
|
|
21816
22298
|
}
|
|
21817
22299
|
await api.post("/host/drift", {
|
|
21818
22300
|
agent_id: agent.agent_id,
|
|
@@ -22097,15 +22579,15 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22097
22579
|
const addedChannels = [...restartDecision.added];
|
|
22098
22580
|
const writeDmNoticeMarkers = isChannelAddRestart ? () => {
|
|
22099
22581
|
try {
|
|
22100
|
-
const agentAugmentedDir =
|
|
22101
|
-
|
|
22582
|
+
const agentAugmentedDir = join46(homedir17(), ".augmented", agent.code_name);
|
|
22583
|
+
mkdirSync18(agentAugmentedDir, { recursive: true });
|
|
22102
22584
|
const markerJson = JSON.stringify({
|
|
22103
22585
|
version: 1,
|
|
22104
22586
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22105
22587
|
added: addedChannels
|
|
22106
22588
|
});
|
|
22107
22589
|
for (const file of ["slack-channel-add-restart.json", "telegram-channel-add-restart.json"]) {
|
|
22108
|
-
atomicWriteFileSync(
|
|
22590
|
+
atomicWriteFileSync(join46(agentAugmentedDir, file), markerJson);
|
|
22109
22591
|
}
|
|
22110
22592
|
} catch (err) {
|
|
22111
22593
|
log(`[hot-reload] channel-add DM-notice marker write failed for '${agent.code_name}' (non-fatal): ${err.message}`);
|
|
@@ -22185,7 +22667,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22185
22667
|
const behaviourSubset = extractMsTeamsBehaviourSubset(
|
|
22186
22668
|
msteamsEntry?.config
|
|
22187
22669
|
);
|
|
22188
|
-
const behaviourHash =
|
|
22670
|
+
const behaviourHash = createHash21("sha256").update(canonicalJson(behaviourSubset)).digest("hex");
|
|
22189
22671
|
const prevBehaviourHash = agentState.knownMsTeamsBehaviourHashes.get(agent.agent_id);
|
|
22190
22672
|
const msteamsBehaviourRestrictive = isMsTeamsBehaviourRestrictive(behaviourSubset);
|
|
22191
22673
|
const behaviourDecision = decideSenderPolicyRestart({
|
|
@@ -22241,7 +22723,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22241
22723
|
const slackBehaviourSubset = extractSlackBehaviourSubset(
|
|
22242
22724
|
slackEntry?.config
|
|
22243
22725
|
);
|
|
22244
|
-
const slackBehaviourHash =
|
|
22726
|
+
const slackBehaviourHash = createHash21("sha256").update(canonicalJson(slackBehaviourSubset)).digest("hex");
|
|
22245
22727
|
const prevSlackBehaviourHash = agentState.knownSlackBehaviourHashes.get(agent.agent_id);
|
|
22246
22728
|
const slackBehaviourRestrictive = isSlackBehaviourRestrictive(slackBehaviourSubset);
|
|
22247
22729
|
const slackBehaviourDecision = decideSenderPolicyRestart({
|
|
@@ -22296,7 +22778,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22296
22778
|
}
|
|
22297
22779
|
if (currentChannelIds.has("telegram")) {
|
|
22298
22780
|
const telegramPolicyEnv = telegramPolicyEnvForRestart ?? {};
|
|
22299
|
-
const telegramPolicyHash =
|
|
22781
|
+
const telegramPolicyHash = createHash21("sha256").update(telegramPolicyEnvBasis(telegramPolicyEnv)).digest("hex");
|
|
22300
22782
|
const prevTelegramPolicyHash = agentState.knownTelegramPolicyHashes.get(agent.agent_id);
|
|
22301
22783
|
const telegramPolicyRestrictive = isTelegramPolicyRestrictive(telegramPolicyEnv);
|
|
22302
22784
|
const telegramPolicyDecision = decideSenderPolicyRestart({
|
|
@@ -22355,7 +22837,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22355
22837
|
} else {
|
|
22356
22838
|
const agentRules = refreshData.agent_rules ?? [];
|
|
22357
22839
|
const inheritedRules = inheritedResolution.rules;
|
|
22358
|
-
const agentRulesHash =
|
|
22840
|
+
const agentRulesHash = createHash21("sha256").update(agentRulesRestartBasis(agentRules, inheritedRules)).digest("hex");
|
|
22359
22841
|
const prevAgentRulesHash = agentState.knownAgentRulesHashes.get(agent.agent_id);
|
|
22360
22842
|
const rulesPresent = agentHasRules(agentRules, inheritedRules);
|
|
22361
22843
|
const agentRulesDecision = decideSenderPolicyRestart({
|
|
@@ -22409,18 +22891,18 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22409
22891
|
if (agentSessionMode === "persistent" && (agentFrameworkCache.get(agent.code_name) ?? DEFAULT_FRAMEWORK) === "claude-code") {
|
|
22410
22892
|
try {
|
|
22411
22893
|
const agentProvisionDir = agentDir;
|
|
22412
|
-
const projectDir =
|
|
22413
|
-
|
|
22414
|
-
|
|
22415
|
-
const provisionMcpPath =
|
|
22416
|
-
const projectMcpPath =
|
|
22894
|
+
const projectDir = join46(homedir17(), ".augmented", agent.code_name, "project");
|
|
22895
|
+
mkdirSync18(agentProvisionDir, { recursive: true });
|
|
22896
|
+
mkdirSync18(projectDir, { recursive: true });
|
|
22897
|
+
const provisionMcpPath = join46(agentProvisionDir, ".mcp.json");
|
|
22898
|
+
const projectMcpPath = join46(projectDir, ".mcp.json");
|
|
22417
22899
|
let mcpConfig = { mcpServers: {} };
|
|
22418
22900
|
try {
|
|
22419
|
-
mcpConfig = JSON.parse(
|
|
22901
|
+
mcpConfig = JSON.parse(readFileSync37(provisionMcpPath, "utf-8"));
|
|
22420
22902
|
if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
|
|
22421
22903
|
} catch {
|
|
22422
22904
|
}
|
|
22423
|
-
const localDirectChatChannel =
|
|
22905
|
+
const localDirectChatChannel = join46(homedir17(), ".augmented", "_mcp", "direct-chat-channel.js");
|
|
22424
22906
|
const directChatTeamSettings = refreshData.team?.settings;
|
|
22425
22907
|
const directChatTz = (() => {
|
|
22426
22908
|
const tz = directChatTeamSettings?.["timezone"];
|
|
@@ -22446,7 +22928,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22446
22928
|
// ~/.augmented/<codeName>/.current-turn-initiator.json. Note getAgentDir
|
|
22447
22929
|
// returns the agent root (NOT the /provision subdir `agentDir` points at),
|
|
22448
22930
|
// so it byte-matches the broker readers' path.
|
|
22449
|
-
AGT_TURN_INITIATOR_FILE:
|
|
22931
|
+
AGT_TURN_INITIATOR_FILE: join46(
|
|
22450
22932
|
frameworkAdapter.getAgentDir(agent.code_name),
|
|
22451
22933
|
".current-turn-initiator.json"
|
|
22452
22934
|
)
|
|
@@ -22466,7 +22948,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22466
22948
|
log(`Channel credentials written for '${agent.code_name}/direct-chat'`);
|
|
22467
22949
|
}
|
|
22468
22950
|
}
|
|
22469
|
-
const staleChannelsPath =
|
|
22951
|
+
const staleChannelsPath = join46(projectDir, ".mcp-channels.json");
|
|
22470
22952
|
if (existsSync20(staleChannelsPath)) {
|
|
22471
22953
|
try {
|
|
22472
22954
|
rmSync9(staleChannelsPath, { force: true });
|
|
@@ -22594,7 +23076,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22594
23076
|
}
|
|
22595
23077
|
if (hostFlagStore().getBoolean("connectivity-probe")) {
|
|
22596
23078
|
try {
|
|
22597
|
-
const probeProjectDir =
|
|
23079
|
+
const probeProjectDir = join46(homedir17(), ".augmented", agent.code_name, "project");
|
|
22598
23080
|
let probeSet = integrations;
|
|
22599
23081
|
const fetchQuarantined = async () => {
|
|
22600
23082
|
const quarantined = await api.post("/host/agent-integrations/quarantined", { agent_id: agent.agent_id });
|
|
@@ -22654,7 +23136,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22654
23136
|
const forceDue = attemptsLeft > 0;
|
|
22655
23137
|
let probeRan = false;
|
|
22656
23138
|
try {
|
|
22657
|
-
const probeProjectDir =
|
|
23139
|
+
const probeProjectDir = join46(homedir17(), ".augmented", agent.code_name, "project");
|
|
22658
23140
|
const renderPending = integrationRenderPending(
|
|
22659
23141
|
integrations,
|
|
22660
23142
|
agentState.knownIntegrationHashes.get(agent.agent_id)
|
|
@@ -22783,11 +23265,11 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22783
23265
|
const intHash = computeIntegrationsHash(integrations);
|
|
22784
23266
|
const prevIntHash = agentState.knownIntegrationHashes.get(agent.agent_id);
|
|
22785
23267
|
if (intHash !== prevIntHash) {
|
|
22786
|
-
const projectDir =
|
|
22787
|
-
const envIntPath =
|
|
23268
|
+
const projectDir = join46(homedir17(), ".augmented", agent.code_name, "project");
|
|
23269
|
+
const envIntPath = join46(projectDir, ".env.integrations");
|
|
22788
23270
|
let preWriteEnv;
|
|
22789
23271
|
try {
|
|
22790
|
-
preWriteEnv =
|
|
23272
|
+
preWriteEnv = readFileSync37(envIntPath, "utf-8");
|
|
22791
23273
|
} catch {
|
|
22792
23274
|
preWriteEnv = void 0;
|
|
22793
23275
|
}
|
|
@@ -22815,9 +23297,9 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22815
23297
|
}
|
|
22816
23298
|
if (fw === "claude-code" && isSessionHealthy(agent.code_name)) {
|
|
22817
23299
|
try {
|
|
22818
|
-
const projectMcpPath =
|
|
22819
|
-
const postWriteEnv =
|
|
22820
|
-
const mcpContent =
|
|
23300
|
+
const projectMcpPath = join46(projectDir, ".mcp.json");
|
|
23301
|
+
const postWriteEnv = readFileSync37(envIntPath, "utf-8");
|
|
23302
|
+
const mcpContent = readFileSync37(projectMcpPath, "utf-8");
|
|
22821
23303
|
const changedVars = diffEnvIntegrations(preWriteEnv, postWriteEnv);
|
|
22822
23304
|
const mcpJsonForReap = JSON.parse(mcpContent);
|
|
22823
23305
|
const affectedServerKeys = findMcpServersUsingVars(mcpJsonForReap, changedVars);
|
|
@@ -22886,6 +23368,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22886
23368
|
if (markMcpRepairPending(agentState.knownIntegrationHashes, agent.agent_id, orphanPruneFailed || mcpWriteFailed || !rotationHandled)) {
|
|
22887
23369
|
log(`[hot-reload] '${agent.code_name}': MCP config writes did not all land this poll; the next poll re-renders to repair them (ENG-11912)`);
|
|
22888
23370
|
}
|
|
23371
|
+
const reloadRendered = rotationHandled && !orphanPruneFailed && !mcpWriteFailed;
|
|
23372
|
+
if (configReloads.isPending(agent.agent_id) && integrationsFresh && reloadRendered) {
|
|
23373
|
+
configReloads.noteFreshRender(agent.agent_id, Date.now());
|
|
23374
|
+
}
|
|
22889
23375
|
confirmConfigReload(
|
|
22890
23376
|
{
|
|
22891
23377
|
agentId: agent.agent_id,
|
|
@@ -22893,7 +23379,8 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22893
23379
|
framework: agentFrameworkCache.get(agent.code_name) ?? DEFAULT_FRAMEWORK,
|
|
22894
23380
|
pending: configReloads.isPending(agent.agent_id),
|
|
22895
23381
|
freshFetch: integrationsFresh,
|
|
22896
|
-
rendered:
|
|
23382
|
+
rendered: reloadRendered,
|
|
23383
|
+
freshRenderedAt: configReloads.freshRenderedAt(agent.agent_id)
|
|
22897
23384
|
},
|
|
22898
23385
|
{
|
|
22899
23386
|
// CodeRabbit on ba9356f4: the tri-state probe, not the boolean health
|
|
@@ -22909,7 +23396,15 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22909
23396
|
stopPersistentSessionAndForgetMcpBaseline(code, "integration-change");
|
|
22910
23397
|
},
|
|
22911
23398
|
confirm: (agentId) => configReloads.confirm(agentId),
|
|
22912
|
-
log
|
|
23399
|
+
log,
|
|
23400
|
+
// ENG-12052: the session process, not just its tmux session.
|
|
23401
|
+
probeProcess: probeSessionProcess,
|
|
23402
|
+
sessionSpawnedAt: reloadSessionSpawnedAt,
|
|
23403
|
+
spawnedBlind: (code) => reloadBlindSpawns.has(code),
|
|
23404
|
+
probeProcessOlderThan: probeSessionProcessOlderThan,
|
|
23405
|
+
clearBlind: (code) => void reloadBlindSpawns.delete(code),
|
|
23406
|
+
unknownStreak: reloadUnknownStreak,
|
|
23407
|
+
alert: (agentId, reason) => void reportReaperEvent(agentId, "reload-confirm", "alert", reason)
|
|
22913
23408
|
}
|
|
22914
23409
|
);
|
|
22915
23410
|
if (capSurfaceHash !== prevCapSurfaceHash && rotationHandled) {
|
|
@@ -22944,10 +23439,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22944
23439
|
desiredEntries.push({ serverId, url, headers: mcpHeaders, name: tk.toolkit_name });
|
|
22945
23440
|
}
|
|
22946
23441
|
const hashBasis = desiredEntries.slice().sort((a, b) => a.serverId.localeCompare(b.serverId)).map((e) => {
|
|
22947
|
-
const headersHash =
|
|
23442
|
+
const headersHash = createHash21("sha256").update(canonicalJson(e.headers ?? {})).digest("hex").slice(0, 16);
|
|
22948
23443
|
return `${e.serverId}|${e.url}|${headersHash}`;
|
|
22949
23444
|
}).join("\n");
|
|
22950
|
-
const mcpHash =
|
|
23445
|
+
const mcpHash = createHash21("sha256").update(hashBasis).digest("hex").slice(0, 16);
|
|
22951
23446
|
const prevMcpHash = agentState.knownManagedMcpHashes.get(agent.agent_id);
|
|
22952
23447
|
const structureHash = managedMcpStructureHash(desiredEntries);
|
|
22953
23448
|
const prevStructureHash = agentState.knownManagedMcpStructure.get(agent.agent_id);
|
|
@@ -22990,7 +23485,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
22990
23485
|
if (mcpHash !== prevMcpHash) {
|
|
22991
23486
|
for (const e of desiredEntries) {
|
|
22992
23487
|
frameworkAdapter.writeMcpServer(agent.code_name, e.serverId, { url: e.url, headers: e.headers });
|
|
22993
|
-
const urlHash =
|
|
23488
|
+
const urlHash = createHash21("sha256").update(e.url).digest("hex").slice(0, 12);
|
|
22994
23489
|
log(`[managed-toolkit] ${agent.code_name}: wrote '${e.name}' (serverId=${e.serverId}, url_hash=${urlHash})`);
|
|
22995
23490
|
}
|
|
22996
23491
|
if (deferredPruneKeys.length === 0) {
|
|
@@ -23092,7 +23587,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23092
23587
|
if (frameworkAdapter.installSkillFiles) {
|
|
23093
23588
|
const currentIntegrationSkillIds = /* @__PURE__ */ new Set();
|
|
23094
23589
|
const installedIntegrationSkills = [];
|
|
23095
|
-
const { createHash:
|
|
23590
|
+
const { createHash: createHash22 } = await import("crypto");
|
|
23096
23591
|
const refreshAny = refreshData;
|
|
23097
23592
|
const contexts = refreshAny.integration_contexts ?? refreshAny.plugin_contexts ?? [];
|
|
23098
23593
|
const contextBySlug = /* @__PURE__ */ new Map();
|
|
@@ -23129,7 +23624,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23129
23624
|
)
|
|
23130
23625
|
}));
|
|
23131
23626
|
const bundle = buildIntegrationBundle(renderedScopes);
|
|
23132
|
-
const contentHash =
|
|
23627
|
+
const contentHash = createHash22("sha256").update(bundleFingerprint(bundle.files)).digest("hex").slice(0, 12);
|
|
23133
23628
|
if (!shouldWriteIntegrationSkill(
|
|
23134
23629
|
agentState.knownSkillHashes,
|
|
23135
23630
|
agent.agent_id,
|
|
@@ -23157,12 +23652,12 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23157
23652
|
const frameworkId2 = frameworkAdapter.id;
|
|
23158
23653
|
const candidateSkillDirs = [
|
|
23159
23654
|
// Claude Code — framework runtime tree
|
|
23160
|
-
|
|
23655
|
+
join46(homedir18(), ".augmented", agent.code_name, "skills"),
|
|
23161
23656
|
// Claude Code — project tree
|
|
23162
|
-
|
|
23657
|
+
join46(homedir18(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
23163
23658
|
// Defensive: legacy provision-side path, not currently an
|
|
23164
23659
|
// install target but cheap to sweep.
|
|
23165
|
-
|
|
23660
|
+
join46(agentDir, ".claude", "skills")
|
|
23166
23661
|
];
|
|
23167
23662
|
const existingDirs = candidateSkillDirs.filter((d) => existsSync20(d));
|
|
23168
23663
|
const discoveredEntries = /* @__PURE__ */ new Set();
|
|
@@ -23205,7 +23700,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23205
23700
|
const sharedSkillsPayload = refreshAny.shared_skills;
|
|
23206
23701
|
const desiredResolved = globalSkillsPayload !== void 0 || sharedSkillsPayload !== void 0;
|
|
23207
23702
|
const manifestPath = managedSkillManifestPath(
|
|
23208
|
-
|
|
23703
|
+
join46(homedir17(), ".augmented", agent.code_name)
|
|
23209
23704
|
);
|
|
23210
23705
|
const prevIds = /* @__PURE__ */ new Set([
|
|
23211
23706
|
...agentState.knownGlobalSkillIds.get(agent.agent_id) ?? /* @__PURE__ */ new Set(),
|
|
@@ -23214,7 +23709,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23214
23709
|
const plan = planGlobalSkillSync(
|
|
23215
23710
|
[...globalSkillsPayload ?? [], ...sharedSkillsPayload ?? []],
|
|
23216
23711
|
prevIds,
|
|
23217
|
-
(content) =>
|
|
23712
|
+
(content) => createHash22("sha256").update(content).digest("hex").slice(0, 12),
|
|
23218
23713
|
(skillId) => agentState.knownSkillHashes.get(`global-skill:${agent.agent_id}:${skillId}`),
|
|
23219
23714
|
{ desiredResolved }
|
|
23220
23715
|
);
|
|
@@ -23225,15 +23720,15 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23225
23720
|
}
|
|
23226
23721
|
if (plan.removes.length) {
|
|
23227
23722
|
const globalSkillDirs = [
|
|
23228
|
-
|
|
23229
|
-
|
|
23230
|
-
|
|
23723
|
+
join46(homedir17(), ".augmented", agent.code_name, "skills"),
|
|
23724
|
+
join46(homedir17(), ".augmented", agent.code_name, "project", ".claude", "skills"),
|
|
23725
|
+
join46(agentDir, ".claude", "skills")
|
|
23231
23726
|
];
|
|
23232
23727
|
for (const id of plan.removes) {
|
|
23233
23728
|
let prunedAny = false;
|
|
23234
23729
|
for (const dir of globalSkillDirs) {
|
|
23235
|
-
const p =
|
|
23236
|
-
if (existsSync20(p) && existsSync20(
|
|
23730
|
+
const p = join46(dir, id);
|
|
23731
|
+
if (existsSync20(p) && existsSync20(join46(p, "SKILL.md"))) {
|
|
23237
23732
|
rmSync9(p, { recursive: true, force: true });
|
|
23238
23733
|
prunedAny = true;
|
|
23239
23734
|
}
|
|
@@ -23265,7 +23760,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23265
23760
|
const slug = hook.integration_slug ?? hook.plugin_slug;
|
|
23266
23761
|
if (!slug) continue;
|
|
23267
23762
|
try {
|
|
23268
|
-
const scriptHash =
|
|
23763
|
+
const scriptHash = createHash22("sha256").update(hook.script).digest("hex").slice(0, 12);
|
|
23269
23764
|
const hookKey = `${agent.agent_id}:${frameworkAdapter.id}:plugin-hook:${slug}:on_install`;
|
|
23270
23765
|
if (agentState.knownSkillHashes.get(hookKey) === scriptHash) continue;
|
|
23271
23766
|
const result = await frameworkAdapter.executePluginHook({
|
|
@@ -23280,9 +23775,9 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23280
23775
|
} else if (result.timedOut) {
|
|
23281
23776
|
log(`Integration hook on_install '${slug}' TIMED OUT for '${agent.code_name}' after ${result.durationMs}ms`);
|
|
23282
23777
|
} else {
|
|
23283
|
-
const stderrHash =
|
|
23778
|
+
const stderrHash = createHash22("sha256").update(result.stderr).digest("hex").slice(0, 12);
|
|
23284
23779
|
const missingCmd = result.exitCode === 127 ? extractCommandNotFound(result.stderr) : null;
|
|
23285
|
-
const missingCmdHash = missingCmd ?
|
|
23780
|
+
const missingCmdHash = missingCmd ? createHash22("sha256").update(missingCmd).digest("hex").slice(0, 8) : null;
|
|
23286
23781
|
log(
|
|
23287
23782
|
`Integration hook on_install '${slug}' exited ${result.exitCode} for '${agent.code_name}' ` + (missingCmdHash ? `[missing_command_hash=${missingCmdHash}] ` : "") + `[stderr_hash=${stderrHash} stderr_len=${result.stderr.length}]`
|
|
23288
23783
|
);
|
|
@@ -23503,8 +23998,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23503
23998
|
const sess = getSessionState(agent.code_name);
|
|
23504
23999
|
let mcpJsonParsed = null;
|
|
23505
24000
|
try {
|
|
23506
|
-
|
|
23507
|
-
|
|
24001
|
+
mcpJsonParsed = readSpawnViewMcpConfig(
|
|
24002
|
+
agent.code_name,
|
|
24003
|
+
getProjectDir(agent.code_name)
|
|
24004
|
+
);
|
|
23508
24005
|
} catch {
|
|
23509
24006
|
}
|
|
23510
24007
|
const computerUseIsolated = isolationMode(agent.code_name) === "docker";
|
|
@@ -23966,7 +24463,7 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
23966
24463
|
freshDoneIds.add(item.id);
|
|
23967
24464
|
}
|
|
23968
24465
|
} catch (err) {
|
|
23969
|
-
const errId =
|
|
24466
|
+
const errId = createHash21("sha256").update(err instanceof Error ? err.message : String(err)).digest("hex").slice(0, 12);
|
|
23970
24467
|
log(`Reap API error for item_id=${item.id} error_id=${errId}`);
|
|
23971
24468
|
}
|
|
23972
24469
|
if (reapAction === "dead_letter") {
|
|
@@ -24017,7 +24514,7 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
24017
24514
|
if (trackedFiles.length > 0 && existsSync20(agentDir)) {
|
|
24018
24515
|
const hashes = /* @__PURE__ */ new Map();
|
|
24019
24516
|
for (const file of trackedFiles) {
|
|
24020
|
-
const h = hashFile(
|
|
24517
|
+
const h = hashFile(join46(agentDir, file));
|
|
24021
24518
|
if (h) hashes.set(file, h);
|
|
24022
24519
|
}
|
|
24023
24520
|
agentState.writtenHashes.set(agent.agent_id, hashes);
|
|
@@ -24032,7 +24529,7 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
24032
24529
|
refreshData.agent.onboarding_state
|
|
24033
24530
|
);
|
|
24034
24531
|
const obStep = obState.step;
|
|
24035
|
-
const markerPath =
|
|
24532
|
+
const markerPath = join46(homedir17(), ".augmented", agent.code_name, "onboarding-drive.json");
|
|
24036
24533
|
const marker = readOnboardingDriveMarker(markerPath);
|
|
24037
24534
|
const obContactRaw = refreshData.agent.manager_last_contacted_at;
|
|
24038
24535
|
const obContact = typeof obContactRaw === "string" && obContactRaw ? obContactRaw : null;
|
|
@@ -24165,7 +24662,7 @@ async function ensureOpencodeRuntime(agent, refreshData, agentTimezone) {
|
|
|
24165
24662
|
}
|
|
24166
24663
|
stopOpencodeSlackIngest(codeName, log);
|
|
24167
24664
|
stopOpencodeTelegramIngest(codeName, log);
|
|
24168
|
-
const opencodeProjectDir =
|
|
24665
|
+
const opencodeProjectDir = join46(getFramework("opencode").getAgentDir(codeName), "provision");
|
|
24169
24666
|
const serveEnv = {
|
|
24170
24667
|
AGT_HOST: requireHost(),
|
|
24171
24668
|
AGT_API_KEY: getApiKey() ?? void 0,
|
|
@@ -24236,8 +24733,8 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
24236
24733
|
});
|
|
24237
24734
|
}
|
|
24238
24735
|
const projectDir = getProjectDir(codeName);
|
|
24239
|
-
const mcpConfigPath =
|
|
24240
|
-
const claudeMdPath =
|
|
24736
|
+
const mcpConfigPath = join46(projectDir, ".mcp.json");
|
|
24737
|
+
const claudeMdPath = join46(projectDir, "CLAUDE.md");
|
|
24241
24738
|
if (restartBreaker.isTripped(codeName)) {
|
|
24242
24739
|
const trip = restartBreaker.getTrip(codeName);
|
|
24243
24740
|
return {
|
|
@@ -24248,7 +24745,11 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
24248
24745
|
};
|
|
24249
24746
|
}
|
|
24250
24747
|
if ((agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK) === "claude-code" && !isSessionHealthy(codeName)) {
|
|
24251
|
-
const
|
|
24748
|
+
const spawnDropped = spawnDroppedServerKeys(
|
|
24749
|
+
mcpConfigPath,
|
|
24750
|
+
lastIntegrationsPayload.get(agent.agent_id)
|
|
24751
|
+
);
|
|
24752
|
+
const missingMcpBundles = findMissingMcpBundles(mcpConfigPath, { skipKeys: spawnDropped });
|
|
24252
24753
|
if (missingMcpBundles.length > 0) {
|
|
24253
24754
|
const detail = formatMissingMcpBundles(missingMcpBundles);
|
|
24254
24755
|
log(
|
|
@@ -24262,6 +24763,37 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
24262
24763
|
};
|
|
24263
24764
|
}
|
|
24264
24765
|
}
|
|
24766
|
+
let stragglerGateRan = false;
|
|
24767
|
+
const runStragglerGate = () => {
|
|
24768
|
+
stragglerGateRan = true;
|
|
24769
|
+
const gate = stragglerSpawnGate(codeName, {
|
|
24770
|
+
probeProcess: probeSessionProcess,
|
|
24771
|
+
probeTmux: (c) => probeTmuxSession(`agt-${c}`),
|
|
24772
|
+
isDocker: (c) => effectiveIsolationMode(c) === "docker",
|
|
24773
|
+
killStraggler: killStragglerProcess,
|
|
24774
|
+
log,
|
|
24775
|
+
deferStreak: stragglerDeferStreak,
|
|
24776
|
+
// Obi Wan 417cd9e6ce9a: under 'reload-confirm', which /host/reaper-event
|
|
24777
|
+
// accepts (REAPER_EVENT_ALLOWLIST); an unlisted reaper name is a 400 and
|
|
24778
|
+
// the alert would never open.
|
|
24779
|
+
alert: (_code, reason) => void reportReaperEvent(agent.agent_id, "reload-confirm", "alert", reason)
|
|
24780
|
+
});
|
|
24781
|
+
if (gate === "spawn-unknown" && effectiveIsolationMode(codeName) !== "docker") reloadBlindSpawns.add(codeName);
|
|
24782
|
+
else if (gate !== "defer") reloadBlindSpawns.delete(codeName);
|
|
24783
|
+
if (gate === "defer") {
|
|
24784
|
+
return {
|
|
24785
|
+
decision: "skipped-straggler-alive",
|
|
24786
|
+
spawnAttempted: false,
|
|
24787
|
+
sessionHealthyAfter: false,
|
|
24788
|
+
detail: "a previous claude process for this agent is still running (sent SIGTERM)"
|
|
24789
|
+
};
|
|
24790
|
+
}
|
|
24791
|
+
return null;
|
|
24792
|
+
};
|
|
24793
|
+
if ((agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK) === "claude-code" && !isSessionHealthy(codeName)) {
|
|
24794
|
+
const deferred = runStragglerGate();
|
|
24795
|
+
if (deferred) return deferred;
|
|
24796
|
+
}
|
|
24265
24797
|
const teamSettingsForTz = refreshData.team?.settings;
|
|
24266
24798
|
const agentTimezone = (() => {
|
|
24267
24799
|
const ownTzRaw = refreshData.agent?.timezone;
|
|
@@ -24621,7 +25153,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
24621
25153
|
const ctx = getLastFailureContext(codeName);
|
|
24622
25154
|
const recovery = prepareForRespawn(codeName);
|
|
24623
25155
|
const tailSummary = !ctx.tail ? "" : KNOWN_SAFE_TAIL_SIGNATURES.has(ctx.signature) ? `; last pane output (${PANE_TAIL_PREVIEW_LINES} of ~20 lines):
|
|
24624
|
-
${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${
|
|
25156
|
+
${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256").update(ctx.tail).digest("hex").slice(0, 12)} (raw at ~/.augmented/${codeName}/pane.log)`;
|
|
24625
25157
|
const sigSummary = ctx.signature !== "unknown" ? `; signature=${ctx.signature}` : "";
|
|
24626
25158
|
const recoverySummary = recovery ? `; recovery=${recovery}` : "";
|
|
24627
25159
|
log(
|
|
@@ -24635,7 +25167,7 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash20("sha256")
|
|
|
24635
25167
|
);
|
|
24636
25168
|
getHostId().then((hostId) => {
|
|
24637
25169
|
if (!hostId) return;
|
|
24638
|
-
const paneTailHash = zombie.paneTail ? `sha256:${
|
|
25170
|
+
const paneTailHash = zombie.paneTail ? `sha256:${createHash21("sha256").update(zombie.paneTail).digest("hex").slice(0, 12)}` : null;
|
|
24639
25171
|
return api.post("/host/events", {
|
|
24640
25172
|
host_id: hostId,
|
|
24641
25173
|
agent_code_name: codeName,
|
|
@@ -24746,11 +25278,37 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash20("sha256")
|
|
|
24746
25278
|
`[persistent-session] '${codeName}' (host_kind=${hostKind ?? "dedicated"}): injecting per-agent org-scoped key (ADR-0042 pt3b)`
|
|
24747
25279
|
);
|
|
24748
25280
|
}
|
|
25281
|
+
if (!stragglerGateRan && (agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK) === "claude-code" && !isSessionHealthy(codeName)) {
|
|
25282
|
+
const deferred = runStragglerGate();
|
|
25283
|
+
if (deferred) {
|
|
25284
|
+
closeSessionRunForCode(codeName, "failed", "a previous claude process is still running");
|
|
25285
|
+
return deferred;
|
|
25286
|
+
}
|
|
25287
|
+
}
|
|
25288
|
+
let spawnCopyFailedNow = false;
|
|
25289
|
+
const spawnMcpConfigPath = prepareSpawnMcpConfig({
|
|
25290
|
+
codeName,
|
|
25291
|
+
projectDir,
|
|
25292
|
+
mcpConfigPath,
|
|
25293
|
+
integrations: lastIntegrationsPayload.get(agent.agent_id),
|
|
25294
|
+
apiHost: requireHost(),
|
|
25295
|
+
log,
|
|
25296
|
+
// Sherlock's ruling on #7569: hold the drift restart while the copy keeps
|
|
25297
|
+
// failing on the same raw file, and keep a human-facing alert open.
|
|
25298
|
+
onCopyFailed: (info) => {
|
|
25299
|
+
spawnCopyFailedNow = true;
|
|
25300
|
+
const rawHash = projectMcpHash(codeName, projectDir, "raw");
|
|
25301
|
+
if (rawHash !== null && spawnCopyFailures.noteFailure(codeName, { rawHash, ...info })) {
|
|
25302
|
+
reportSpawnCopyFailure(codeName, info);
|
|
25303
|
+
}
|
|
25304
|
+
}
|
|
25305
|
+
});
|
|
25306
|
+
if (!spawnCopyFailedNow) spawnCopyFailures.noteSuccess(codeName);
|
|
24749
25307
|
startPersistentSession({
|
|
24750
25308
|
codeName,
|
|
24751
25309
|
agentId: agent.agent_id,
|
|
24752
25310
|
projectDir,
|
|
24753
|
-
mcpConfigPath,
|
|
25311
|
+
mcpConfigPath: spawnMcpConfigPath,
|
|
24754
25312
|
claudeMdPath,
|
|
24755
25313
|
channels,
|
|
24756
25314
|
devChannels,
|
|
@@ -24834,7 +25392,7 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash20("sha256")
|
|
|
24834
25392
|
recordSessionPolicyBaseline(codeName, currentPolicyModel, currentPolicyId);
|
|
24835
25393
|
denyWebFetchBySession.set(codeName, spawnDenyWebFetch);
|
|
24836
25394
|
persistDeliveryBaselineEntry("webFetch", agent.agent_id, webFetchBaselineValue(spawnDenyWebFetch));
|
|
24837
|
-
seedSessionLaunchBaselines(codeName, projectDir);
|
|
25395
|
+
seedSessionLaunchBaselines(codeName, projectDir, spawnMcpConfigPath);
|
|
24838
25396
|
if (effectiveIsolationMode(codeName) === "docker") {
|
|
24839
25397
|
seedContainerMemory(codeName, resolveContainerMemory(spawnAgentClass));
|
|
24840
25398
|
}
|
|
@@ -24900,7 +25458,7 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash20("sha256")
|
|
|
24900
25458
|
claudeAuthTupleBySession.set(codeName, currentAuthTuple);
|
|
24901
25459
|
recordSessionPolicyBaseline(codeName, currentPolicyModel, currentPolicyId);
|
|
24902
25460
|
}
|
|
24903
|
-
const stableTasksHash =
|
|
25461
|
+
const stableTasksHash = createHash21("sha256").update(JSON.stringify(tasks)).digest("hex").slice(0, 16);
|
|
24904
25462
|
const prevHash = agentState.knownTasksHashes.get(agent.agent_id);
|
|
24905
25463
|
if (stableTasksHash !== prevHash) {
|
|
24906
25464
|
const taskInputs = tasks.map((t) => buildSchedulerTaskInput(t));
|
|
@@ -25255,7 +25813,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
25255
25813
|
if (!refreshData) return;
|
|
25256
25814
|
const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
25257
25815
|
const hostId = await getHostId();
|
|
25258
|
-
const parkForRestart = await import("../responsiveness-probe-
|
|
25816
|
+
const parkForRestart = await import("../responsiveness-probe-T6O4V2XZ.js").then(
|
|
25259
25817
|
(m) => m.parkPendingInbound,
|
|
25260
25818
|
(err) => err
|
|
25261
25819
|
);
|
|
@@ -25332,7 +25890,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
25332
25890
|
void api.post("/host/restart-ack", { host_id: hostId, agent_id: agentId, restart_requested_at: requestedAt }).catch((err) => log(`[restart-lane] ack failed for '${codeName}': ${err.message}`));
|
|
25333
25891
|
void (async () => {
|
|
25334
25892
|
try {
|
|
25335
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
25893
|
+
const { collectDiagnostics } = await import("../persistent-session-BLZPYHBE.js");
|
|
25336
25894
|
await api.post("/host/heartbeat", {
|
|
25337
25895
|
host_id: hostId,
|
|
25338
25896
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -25385,7 +25943,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
|
|
|
25385
25943
|
}
|
|
25386
25944
|
try {
|
|
25387
25945
|
const hostId = await getHostId();
|
|
25388
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
25946
|
+
const { collectDiagnostics } = await import("../persistent-session-BLZPYHBE.js");
|
|
25389
25947
|
await api.post("/host/heartbeat", {
|
|
25390
25948
|
host_id: hostId,
|
|
25391
25949
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -25480,7 +26038,7 @@ function ensureRealtimeKanbanStarted(agentStates) {
|
|
|
25480
26038
|
);
|
|
25481
26039
|
}
|
|
25482
26040
|
}).catch((err) => {
|
|
25483
|
-
const errId =
|
|
26041
|
+
const errId = createHash21("sha256").update(err instanceof Error ? err.message : String(err)).digest("hex").slice(0, 12);
|
|
25484
26042
|
log(
|
|
25485
26043
|
`[realtime] Work trigger enqueue threw for '${agent.codeName}' item_id=${item.id} error_id=${errId} \u2014 hybrid nudge will retry`
|
|
25486
26044
|
);
|
|
@@ -25797,7 +26355,7 @@ async function processDirectChatMessage(agent, msg) {
|
|
|
25797
26355
|
if (useDoorbell) {
|
|
25798
26356
|
try {
|
|
25799
26357
|
const doorbell = directChatDoorbellPath(agent.agentId, homedir17());
|
|
25800
|
-
|
|
26358
|
+
mkdirSync18(dirname11(doorbell), { recursive: true });
|
|
25801
26359
|
writeFileSync19(doorbell, String(Date.now()));
|
|
25802
26360
|
log(`[direct-chat] Doorbell rung for '${agent.codeName}' (msg=${msg.id}) \u2014 in-session MCP will pull via the cursor`);
|
|
25803
26361
|
return;
|
|
@@ -25926,7 +26484,7 @@ ${formatRunMarker(run_id)}` : KANBAN_CHECK_COMMAND;
|
|
|
25926
26484
|
if (run_id) openInjectedRunByCode.set(codeName, run_id);
|
|
25927
26485
|
try {
|
|
25928
26486
|
const doorbell = directChatDoorbellPath(agentId, homedir17());
|
|
25929
|
-
|
|
26487
|
+
mkdirSync18(dirname11(doorbell), { recursive: true });
|
|
25930
26488
|
writeFileSync19(doorbell, String(Date.now()));
|
|
25931
26489
|
} catch (err) {
|
|
25932
26490
|
log(`[kanban] doorbell ring failed for '${codeName}': ${err.message} (notice still queued)`);
|
|
@@ -26087,7 +26645,7 @@ async function processClaudePairSessions(agents) {
|
|
|
26087
26645
|
snapshotPairConfig,
|
|
26088
26646
|
// ENG-11659: result -> report body + the manager.log line that records it.
|
|
26089
26647
|
planPairStartReport
|
|
26090
|
-
} = await import("../claude-pair-runtime-
|
|
26648
|
+
} = await import("../claude-pair-runtime-3PHBCCUP.js");
|
|
26091
26649
|
const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
|
|
26092
26650
|
for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
|
|
26093
26651
|
log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);
|
|
@@ -26386,17 +26944,17 @@ var lastLocalFileHash = /* @__PURE__ */ new Map();
|
|
|
26386
26944
|
var lastMemoriesBody = /* @__PURE__ */ new Map();
|
|
26387
26945
|
var memoryManifests = /* @__PURE__ */ new Map();
|
|
26388
26946
|
function memoryRetirementDir(configDir, codeName) {
|
|
26389
|
-
return
|
|
26947
|
+
return join46(configDir, "_memory-retirement", codeName);
|
|
26390
26948
|
}
|
|
26391
26949
|
function memoryManifestPath(configDir, codeName) {
|
|
26392
|
-
return
|
|
26950
|
+
return join46(memoryRetirementDir(configDir, codeName), "manifest.json");
|
|
26393
26951
|
}
|
|
26394
26952
|
function loadMemoryManifest(agentId, configDir, codeName) {
|
|
26395
26953
|
const cached = memoryManifests.get(agentId);
|
|
26396
26954
|
if (cached) return cached;
|
|
26397
26955
|
let manifest = {};
|
|
26398
26956
|
try {
|
|
26399
|
-
const raw =
|
|
26957
|
+
const raw = readFileSync37(memoryManifestPath(configDir, codeName), "utf-8");
|
|
26400
26958
|
const parsed = JSON.parse(raw);
|
|
26401
26959
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
26402
26960
|
for (const [name, entry] of Object.entries(parsed)) {
|
|
@@ -26416,7 +26974,7 @@ function saveMemoryManifest(agentId, configDir, codeName) {
|
|
|
26416
26974
|
if (!manifest) return;
|
|
26417
26975
|
try {
|
|
26418
26976
|
const path = memoryManifestPath(configDir, codeName);
|
|
26419
|
-
|
|
26977
|
+
mkdirSync18(memoryRetirementDir(configDir, codeName), { recursive: true });
|
|
26420
26978
|
const tmp = `${path}.tmp`;
|
|
26421
26979
|
writeFileSync19(tmp, JSON.stringify(manifest, null, 2));
|
|
26422
26980
|
renameSync11(tmp, path);
|
|
@@ -26424,7 +26982,7 @@ function saveMemoryManifest(agentId, configDir, codeName) {
|
|
|
26424
26982
|
}
|
|
26425
26983
|
}
|
|
26426
26984
|
function retiredMemoryDir(configDir, codeName) {
|
|
26427
|
-
return
|
|
26985
|
+
return join46(memoryRetirementDir(configDir, codeName), "retired");
|
|
26428
26986
|
}
|
|
26429
26987
|
var RETIRED_MEMORY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
26430
26988
|
var lastRetirementReport = /* @__PURE__ */ new Map();
|
|
@@ -26503,7 +27061,7 @@ function applyMemoryTombstones(opts) {
|
|
|
26503
27061
|
log2(`[memory-retire] ${agent.code_name}: KEPT '${tomb.name}' \u2014 no write record, not ours to remove`);
|
|
26504
27062
|
continue;
|
|
26505
27063
|
}
|
|
26506
|
-
const filePath =
|
|
27064
|
+
const filePath = join46(memoryDir, entry.file);
|
|
26507
27065
|
if (!existsSync20(filePath)) {
|
|
26508
27066
|
outcomes.already_gone++;
|
|
26509
27067
|
delete manifest[tomb.name];
|
|
@@ -26511,7 +27069,7 @@ function applyMemoryTombstones(opts) {
|
|
|
26511
27069
|
continue;
|
|
26512
27070
|
}
|
|
26513
27071
|
try {
|
|
26514
|
-
const actual =
|
|
27072
|
+
const actual = createHash21("sha256").update(readFileSync37(filePath)).digest("hex");
|
|
26515
27073
|
if (actual !== entry.sha) {
|
|
26516
27074
|
outcomes.kept_modified++;
|
|
26517
27075
|
outcomes.unapplied.push({ name: tomb.name, reason: "kept_modified" });
|
|
@@ -26521,11 +27079,11 @@ function applyMemoryTombstones(opts) {
|
|
|
26521
27079
|
continue;
|
|
26522
27080
|
}
|
|
26523
27081
|
const destDir = retiredMemoryDir(configDir, agent.code_name);
|
|
26524
|
-
|
|
27082
|
+
mkdirSync18(destDir, { recursive: true });
|
|
26525
27083
|
const stamp = Date.now();
|
|
26526
|
-
let dest =
|
|
27084
|
+
let dest = join46(destDir, `${entry.file}.${stamp}.retired`);
|
|
26527
27085
|
for (let n = 1; existsSync20(dest); n++) {
|
|
26528
|
-
dest =
|
|
27086
|
+
dest = join46(destDir, `${entry.file}.${stamp}-${n}.retired`);
|
|
26529
27087
|
}
|
|
26530
27088
|
renameSync11(filePath, dest);
|
|
26531
27089
|
try {
|
|
@@ -26564,7 +27122,7 @@ function reapRetiredMemories(configDir, codeName, log2) {
|
|
|
26564
27122
|
try {
|
|
26565
27123
|
for (const file of readdirSync14(dir)) {
|
|
26566
27124
|
if (!file.endsWith(".retired")) continue;
|
|
26567
|
-
const path =
|
|
27125
|
+
const path = join46(dir, file);
|
|
26568
27126
|
try {
|
|
26569
27127
|
if (statSync15(path).mtimeMs < cutoff) {
|
|
26570
27128
|
unlinkSync6(path);
|
|
@@ -26579,8 +27137,8 @@ function reapRetiredMemories(configDir, codeName, log2) {
|
|
|
26579
27137
|
if (reaped > 0) log2(`[memory-retire] ${codeName}: reaped ${reaped} retired memory file(s) past TTL`);
|
|
26580
27138
|
}
|
|
26581
27139
|
async function syncMemories(agent, configDir, log2) {
|
|
26582
|
-
const projectDir =
|
|
26583
|
-
const memoryDir =
|
|
27140
|
+
const projectDir = join46(configDir, agent.code_name, "project");
|
|
27141
|
+
const memoryDir = join46(projectDir, "memory");
|
|
26584
27142
|
const isFreshSync = pendingFreshMemorySync.has(agent.agent_id);
|
|
26585
27143
|
if (isFreshSync) {
|
|
26586
27144
|
log2(`[memory-sync] Fresh-sync requested for '${agent.code_name}' \u2014 pulling DB first`);
|
|
@@ -26611,8 +27169,8 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
26611
27169
|
for (const file of readdirSync14(memoryDir)) {
|
|
26612
27170
|
if (!file.endsWith(".md")) continue;
|
|
26613
27171
|
try {
|
|
26614
|
-
const raw =
|
|
26615
|
-
const fileHash =
|
|
27172
|
+
const raw = readFileSync37(join46(memoryDir, file), "utf-8");
|
|
27173
|
+
const fileHash = createHash21("sha256").update(raw).digest("hex").slice(0, 16);
|
|
26616
27174
|
currentHashes.set(file, fileHash);
|
|
26617
27175
|
if (prevHashes.get(file) === fileHash) continue;
|
|
26618
27176
|
const parsed = parseMemoryFile(raw, file.replace(/\.md$/, ""));
|
|
@@ -26636,7 +27194,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
26636
27194
|
} catch (err) {
|
|
26637
27195
|
for (const mem of changedMemories) {
|
|
26638
27196
|
for (const [file] of currentHashes) {
|
|
26639
|
-
const parsed = parseMemoryFile(
|
|
27197
|
+
const parsed = parseMemoryFile(readFileSync37(join46(memoryDir, file), "utf-8"), file.replace(/\.md$/, ""));
|
|
26640
27198
|
if (parsed?.name === mem.name) currentHashes.delete(file);
|
|
26641
27199
|
}
|
|
26642
27200
|
}
|
|
@@ -26663,7 +27221,7 @@ async function syncMemories(agent, configDir, log2) {
|
|
|
26663
27221
|
}
|
|
26664
27222
|
async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
26665
27223
|
const localFiles = existsSync20(memoryDir) ? readdirSync14(memoryDir).filter((f) => f.endsWith(".md")).sort() : [];
|
|
26666
|
-
const localListHash =
|
|
27224
|
+
const localListHash = createHash21("sha256").update(localFiles.join(",")).digest("hex").slice(0, 16);
|
|
26667
27225
|
const prevLocalHash = lastLocalFileHash.get(agent.agent_id);
|
|
26668
27226
|
const prevDownload = lastDownloadHash.get(agent.agent_id);
|
|
26669
27227
|
const memoriesToken = memoriesFetchGate.beginFetch(agent.agent_id);
|
|
@@ -26717,7 +27275,7 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
26717
27275
|
// Per-agent, not host-wide: memories are agent-private, so a shared
|
|
26718
27276
|
// store would buy almost no dedupe while exposing one agent's content
|
|
26719
27277
|
// to every other agent on the host. See memory-cache.ts's header.
|
|
26720
|
-
cacheDir:
|
|
27278
|
+
cacheDir: join46(configDir, agent.code_name, "_memory_bodies"),
|
|
26721
27279
|
fetchContents: async (hashes) => {
|
|
26722
27280
|
const res = await api.post(
|
|
26723
27281
|
"/host/memories/contents",
|
|
@@ -26739,14 +27297,14 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
26739
27297
|
);
|
|
26740
27298
|
}
|
|
26741
27299
|
}
|
|
26742
|
-
const responseHash =
|
|
27300
|
+
const responseHash = createHash21("sha256").update(JSON.stringify({ m: memories ?? [], t: tombstones })).digest("hex").slice(0, 16);
|
|
26743
27301
|
if (!force && prevDownload && prevLocalHash === localListHash && lastDownloadHash.get(agent.agent_id) === responseHash) {
|
|
26744
27302
|
return { status: "skipped", tombstones, truncated: dbMemories.tombstones_truncated === true };
|
|
26745
27303
|
}
|
|
26746
27304
|
lastDownloadHash.set(agent.agent_id, responseHash);
|
|
26747
27305
|
lastLocalFileHash.set(agent.agent_id, localListHash);
|
|
26748
27306
|
if (memories?.length) {
|
|
26749
|
-
|
|
27307
|
+
mkdirSync18(memoryDir, { recursive: true });
|
|
26750
27308
|
const manifest = loadMemoryManifest(agent.agent_id, configDir, agent.code_name);
|
|
26751
27309
|
let written = 0;
|
|
26752
27310
|
let overwritten = 0;
|
|
@@ -26755,7 +27313,7 @@ async function downloadMemories(agent, memoryDir, log2, { force, configDir }) {
|
|
|
26755
27313
|
const rawSlug = mem.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").slice(0, 60);
|
|
26756
27314
|
const slug = rawSlug || `memory-${i}`;
|
|
26757
27315
|
const fileName = `${slug}.md`;
|
|
26758
|
-
const filePath =
|
|
27316
|
+
const filePath = join46(memoryDir, fileName);
|
|
26759
27317
|
const desired = `---
|
|
26760
27318
|
name: ${JSON.stringify(mem.name)}
|
|
26761
27319
|
type: ${mem.type}
|
|
@@ -26765,7 +27323,7 @@ description: ${JSON.stringify(mem.content.slice(0, 200))}
|
|
|
26765
27323
|
${mem.content}
|
|
26766
27324
|
`;
|
|
26767
27325
|
const record = () => {
|
|
26768
|
-
const sha =
|
|
27326
|
+
const sha = createHash21("sha256").update(desired).digest("hex");
|
|
26769
27327
|
const prev = manifest[mem.name];
|
|
26770
27328
|
if (prev?.file === fileName && prev.sha === sha) return false;
|
|
26771
27329
|
manifest[mem.name] = { file: fileName, sha };
|
|
@@ -26775,7 +27333,7 @@ ${mem.content}
|
|
|
26775
27333
|
if (existsSync20(filePath)) {
|
|
26776
27334
|
let existing = "";
|
|
26777
27335
|
try {
|
|
26778
|
-
existing =
|
|
27336
|
+
existing = readFileSync37(filePath, "utf-8");
|
|
26779
27337
|
} catch {
|
|
26780
27338
|
}
|
|
26781
27339
|
if (existing === desired) {
|
|
@@ -26794,7 +27352,7 @@ ${mem.content}
|
|
|
26794
27352
|
}
|
|
26795
27353
|
if (written > 0 || overwritten > 0) {
|
|
26796
27354
|
const updatedFiles = readdirSync14(memoryDir).filter((f) => f.endsWith(".md")).sort();
|
|
26797
|
-
lastLocalFileHash.set(agent.agent_id,
|
|
27355
|
+
lastLocalFileHash.set(agent.agent_id, createHash21("sha256").update(updatedFiles.join(",")).digest("hex").slice(0, 16));
|
|
26798
27356
|
log2(`Memory download for '${agent.code_name}': wrote ${written} new, overwrote ${overwritten} stale`);
|
|
26799
27357
|
}
|
|
26800
27358
|
}
|
|
@@ -27176,7 +27734,7 @@ function startManager(opts) {
|
|
|
27176
27734
|
try {
|
|
27177
27735
|
const stateFile = getStateFile();
|
|
27178
27736
|
if (existsSync20(stateFile)) {
|
|
27179
|
-
const raw =
|
|
27737
|
+
const raw = readFileSync37(stateFile, "utf-8");
|
|
27180
27738
|
const parsed = JSON.parse(raw);
|
|
27181
27739
|
if (Array.isArray(parsed.agents)) {
|
|
27182
27740
|
state9.agents = parsed.agents;
|
|
@@ -27210,7 +27768,7 @@ function startManager(opts) {
|
|
|
27210
27768
|
log(`[startup] state rehydration failed (continuing with empty state): ${err.message}`);
|
|
27211
27769
|
}
|
|
27212
27770
|
log(
|
|
27213
|
-
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${
|
|
27771
|
+
`[startup] worker pid=${process.pid} ppid=${process.ppid} node=${process.version} log=${join46(homedir17(), ".augmented", "manager.log")}`
|
|
27214
27772
|
);
|
|
27215
27773
|
deployMcpAssets();
|
|
27216
27774
|
reapOrphanChannelMcps({ log });
|
|
@@ -27239,7 +27797,7 @@ async function reapOrphanedClaudePids() {
|
|
|
27239
27797
|
const looksLikeClaude = (pid) => {
|
|
27240
27798
|
if (process.platform !== "linux") return true;
|
|
27241
27799
|
try {
|
|
27242
|
-
const comm =
|
|
27800
|
+
const comm = readFileSync37(`/proc/${pid}/comm`, "utf-8").trim().toLowerCase();
|
|
27243
27801
|
return comm.includes("claude");
|
|
27244
27802
|
} catch {
|
|
27245
27803
|
return false;
|
|
@@ -27336,14 +27894,14 @@ function restartRunningChannelMcps(basenames) {
|
|
|
27336
27894
|
}
|
|
27337
27895
|
}
|
|
27338
27896
|
function deployMcpAssets() {
|
|
27339
|
-
const targetDir =
|
|
27340
|
-
|
|
27897
|
+
const targetDir = join46(homedir17(), ".augmented", "_mcp");
|
|
27898
|
+
mkdirSync18(targetDir, { recursive: true });
|
|
27341
27899
|
const moduleDir = dirname11(fileURLToPath2(import.meta.url));
|
|
27342
27900
|
let mcpSourceDir = "";
|
|
27343
27901
|
let dir = moduleDir;
|
|
27344
27902
|
for (let i = 0; i < 6; i++) {
|
|
27345
|
-
const candidate =
|
|
27346
|
-
if (existsSync20(
|
|
27903
|
+
const candidate = join46(dir, "dist", "mcp");
|
|
27904
|
+
if (existsSync20(join46(candidate, "index.js"))) {
|
|
27347
27905
|
mcpSourceDir = candidate;
|
|
27348
27906
|
break;
|
|
27349
27907
|
}
|
|
@@ -27361,7 +27919,7 @@ function deployMcpAssets() {
|
|
|
27361
27919
|
const fileHash = (p) => {
|
|
27362
27920
|
try {
|
|
27363
27921
|
if (!existsSync20(p)) return null;
|
|
27364
|
-
return
|
|
27922
|
+
return createHash21("sha256").update(readFileSync37(p)).digest("hex");
|
|
27365
27923
|
} catch {
|
|
27366
27924
|
return null;
|
|
27367
27925
|
}
|
|
@@ -27443,8 +28001,8 @@ function deployMcpAssets() {
|
|
|
27443
28001
|
// natural session restart.
|
|
27444
28002
|
"computer-use-proxy.js"
|
|
27445
28003
|
]) {
|
|
27446
|
-
const src =
|
|
27447
|
-
const dst =
|
|
28004
|
+
const src = join46(mcpSourceDir, file);
|
|
28005
|
+
const dst = join46(targetDir, file);
|
|
27448
28006
|
if (!existsSync20(src)) continue;
|
|
27449
28007
|
attemptedFiles.push(file);
|
|
27450
28008
|
const before = fileHash(dst);
|
|
@@ -27470,16 +28028,16 @@ function deployMcpAssets() {
|
|
|
27470
28028
|
log(`[manager] Bundle(s) updated: ${changedBasenames.join(", ")} \u2014 signalling running instances to restart`);
|
|
27471
28029
|
restartRunningChannelMcps(changedBasenames);
|
|
27472
28030
|
}
|
|
27473
|
-
const localMcpPath =
|
|
28031
|
+
const localMcpPath = join46(targetDir, "index.js");
|
|
27474
28032
|
try {
|
|
27475
|
-
const agentsDir =
|
|
28033
|
+
const agentsDir = join46(homedir17(), ".augmented", "agents");
|
|
27476
28034
|
if (existsSync20(agentsDir)) {
|
|
27477
28035
|
for (const entry of readdirSync14(agentsDir, { withFileTypes: true })) {
|
|
27478
28036
|
if (!entry.isDirectory()) continue;
|
|
27479
28037
|
for (const subdir of ["provision", "project"]) {
|
|
27480
|
-
const mcpJsonPath =
|
|
28038
|
+
const mcpJsonPath = join46(agentsDir, entry.name, subdir, ".mcp.json");
|
|
27481
28039
|
try {
|
|
27482
|
-
const raw =
|
|
28040
|
+
const raw = readFileSync37(mcpJsonPath, "utf-8");
|
|
27483
28041
|
if (!raw.includes("@integrity-labs/augmented-mcp")) continue;
|
|
27484
28042
|
const mcpConfig = JSON.parse(raw);
|
|
27485
28043
|
const augServer = mcpConfig.mcpServers?.["augmented"];
|