@integrity-labs/agt-cli 0.28.1060 → 0.28.1061
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/bin/agt.js +5 -5
- package/dist/{chunk-ROZAO2DB.js → chunk-PDQI3LRM.js} +2 -2
- package/dist/{chunk-GOTLGDZJ.js → chunk-YNEXVKL5.js} +4 -4
- package/dist/{chunk-JFLRDMGU.js → chunk-ZRI5CERC.js} +1 -1
- package/dist/chunk-ZRI5CERC.js.map +1 -0
- package/dist/{claude-pair-runtime-VUKAG635.js → claude-pair-runtime-FXKMOD2H.js} +2 -2
- package/dist/lib/manager-worker.js +14 -14
- package/dist/mcp/direct-chat-channel.js +280 -141
- package/dist/{persistent-session-VBDEAOEO.js → persistent-session-GDBT6G2O.js} +3 -3
- package/dist/{responsiveness-probe-BN4VTJPH.js → responsiveness-probe-2Q2R7NYJ.js} +3 -3
- package/dist/{session-auth-dead-ONJMUXYK.js → session-auth-dead-KMAJCLTW.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-JFLRDMGU.js.map +0 -1
- /package/dist/{chunk-ROZAO2DB.js.map → chunk-PDQI3LRM.js.map} +0 -0
- /package/dist/{chunk-GOTLGDZJ.js.map → chunk-YNEXVKL5.js.map} +0 -0
- /package/dist/{claude-pair-runtime-VUKAG635.js.map → claude-pair-runtime-FXKMOD2H.js.map} +0 -0
- /package/dist/{persistent-session-VBDEAOEO.js.map → persistent-session-GDBT6G2O.js.map} +0 -0
- /package/dist/{responsiveness-probe-BN4VTJPH.js.map → responsiveness-probe-2Q2R7NYJ.js.map} +0 -0
- /package/dist/{session-auth-dead-ONJMUXYK.js.map → session-auth-dead-KMAJCLTW.js.map} +0 -0
|
@@ -18867,7 +18867,7 @@ var require_filters = __commonJS({
|
|
|
18867
18867
|
return r.copySafeness(str, res);
|
|
18868
18868
|
}
|
|
18869
18869
|
_exports.indent = indent;
|
|
18870
|
-
function
|
|
18870
|
+
function join17(arr, del, attr) {
|
|
18871
18871
|
del = del || "";
|
|
18872
18872
|
if (attr) {
|
|
18873
18873
|
arr = lib.map(arr, function(v) {
|
|
@@ -18876,7 +18876,7 @@ var require_filters = __commonJS({
|
|
|
18876
18876
|
}
|
|
18877
18877
|
return arr.join(del);
|
|
18878
18878
|
}
|
|
18879
|
-
_exports.join =
|
|
18879
|
+
_exports.join = join17;
|
|
18880
18880
|
function last(arr) {
|
|
18881
18881
|
return arr[arr.length - 1];
|
|
18882
18882
|
}
|
|
@@ -20042,9 +20042,9 @@ var require_handler = __commonJS({
|
|
|
20042
20042
|
if (this.fsw.closed) {
|
|
20043
20043
|
return;
|
|
20044
20044
|
}
|
|
20045
|
-
const
|
|
20045
|
+
const dirname3 = sysPath.dirname(file);
|
|
20046
20046
|
const basename = sysPath.basename(file);
|
|
20047
|
-
const parent = this.fsw._getWatchedDir(
|
|
20047
|
+
const parent = this.fsw._getWatchedDir(dirname3);
|
|
20048
20048
|
let prevStats = stats;
|
|
20049
20049
|
if (parent.has(basename))
|
|
20050
20050
|
return;
|
|
@@ -20071,7 +20071,7 @@ var require_handler = __commonJS({
|
|
|
20071
20071
|
prevStats = newStats2;
|
|
20072
20072
|
}
|
|
20073
20073
|
} catch (error2) {
|
|
20074
|
-
this.fsw._remove(
|
|
20074
|
+
this.fsw._remove(dirname3, basename);
|
|
20075
20075
|
}
|
|
20076
20076
|
} else if (parent.has(basename)) {
|
|
20077
20077
|
const at = newStats.atimeMs;
|
|
@@ -29824,14 +29824,22 @@ function emitTransientApiErrorTelemetry(channel, match, original) {
|
|
|
29824
29824
|
// src/direct-chat-claim-tracker.ts
|
|
29825
29825
|
var DirectChatClaimTracker = class {
|
|
29826
29826
|
bySession = /* @__PURE__ */ new Map();
|
|
29827
|
+
onChange;
|
|
29828
|
+
now;
|
|
29829
|
+
constructor(opts = {}) {
|
|
29830
|
+
this.onChange = opts.onChange;
|
|
29831
|
+
this.now = opts.now ?? Date.now;
|
|
29832
|
+
}
|
|
29827
29833
|
/** Record that `messageId` was claimed for `sessionId` (idempotent). */
|
|
29828
29834
|
track(sessionId, messageId) {
|
|
29829
|
-
let
|
|
29830
|
-
if (!
|
|
29831
|
-
|
|
29832
|
-
this.bySession.set(sessionId,
|
|
29835
|
+
let ids = this.bySession.get(sessionId);
|
|
29836
|
+
if (!ids) {
|
|
29837
|
+
ids = /* @__PURE__ */ new Map();
|
|
29838
|
+
this.bySession.set(sessionId, ids);
|
|
29833
29839
|
}
|
|
29834
|
-
|
|
29840
|
+
if (ids.has(messageId)) return;
|
|
29841
|
+
ids.set(messageId, this.now());
|
|
29842
|
+
this.onChange?.(this);
|
|
29835
29843
|
}
|
|
29836
29844
|
/**
|
|
29837
29845
|
* The claimed-but-unconsumed message ids for a session, WITHOUT clearing them.
|
|
@@ -29839,7 +29847,7 @@ var DirectChatClaimTracker = class {
|
|
|
29839
29847
|
* reply/consume POST doesn't lose the ids — they stay tracked for the retry.
|
|
29840
29848
|
*/
|
|
29841
29849
|
peek(sessionId) {
|
|
29842
|
-
return [...this.bySession.get(sessionId) ?? []];
|
|
29850
|
+
return [...this.bySession.get(sessionId)?.keys() ?? []];
|
|
29843
29851
|
}
|
|
29844
29852
|
/**
|
|
29845
29853
|
* Clear exactly the given ids for a session (call after a successful
|
|
@@ -29847,18 +29855,123 @@ var DirectChatClaimTracker = class {
|
|
|
29847
29855
|
* claimed between peek and clear stays tracked for the next turn.
|
|
29848
29856
|
*/
|
|
29849
29857
|
clear(sessionId, ids) {
|
|
29850
|
-
const
|
|
29851
|
-
if (!
|
|
29852
|
-
|
|
29853
|
-
|
|
29858
|
+
const tracked = this.bySession.get(sessionId);
|
|
29859
|
+
if (!tracked) return;
|
|
29860
|
+
let changed = false;
|
|
29861
|
+
for (const id of ids) changed = tracked.delete(id) || changed;
|
|
29862
|
+
if (tracked.size === 0) this.bySession.delete(sessionId);
|
|
29863
|
+
if (changed) this.onChange?.(this);
|
|
29854
29864
|
}
|
|
29855
29865
|
/** Total tracked message ids across all sessions (for bounding / diagnostics). */
|
|
29856
29866
|
get size() {
|
|
29857
29867
|
let n = 0;
|
|
29858
|
-
for (const
|
|
29868
|
+
for (const ids of this.bySession.values()) n += ids.size;
|
|
29859
29869
|
return n;
|
|
29860
29870
|
}
|
|
29871
|
+
/** Every tracked claim, for persistence. */
|
|
29872
|
+
snapshot() {
|
|
29873
|
+
const out = [];
|
|
29874
|
+
for (const [session_id, ids] of this.bySession) {
|
|
29875
|
+
for (const [message_id, claimed_at_ms] of ids) out.push({ session_id, message_id, claimed_at_ms });
|
|
29876
|
+
}
|
|
29877
|
+
return out;
|
|
29878
|
+
}
|
|
29879
|
+
/**
|
|
29880
|
+
* Re-seed claims recovered from disk after a restart. Merges (never drops a
|
|
29881
|
+
* claim already tracked in this process) and does NOT fire `onChange` — the
|
|
29882
|
+
* entries came from the store, so writing them straight back is pointless.
|
|
29883
|
+
*/
|
|
29884
|
+
restore(entries) {
|
|
29885
|
+
for (const e of entries) {
|
|
29886
|
+
let ids = this.bySession.get(e.session_id);
|
|
29887
|
+
if (!ids) {
|
|
29888
|
+
ids = /* @__PURE__ */ new Map();
|
|
29889
|
+
this.bySession.set(e.session_id, ids);
|
|
29890
|
+
}
|
|
29891
|
+
if (!ids.has(e.message_id)) ids.set(e.message_id, e.claimed_at_ms);
|
|
29892
|
+
}
|
|
29893
|
+
}
|
|
29894
|
+
};
|
|
29895
|
+
|
|
29896
|
+
// src/direct-chat-claim-store.ts
|
|
29897
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
29898
|
+
import { dirname, join } from "path";
|
|
29899
|
+
var DIRECT_CHAT_CLAIMS_FILE = "direct-chat-claims.json";
|
|
29900
|
+
var DEFAULT_CLAIM_MAX_AGE_MS = 6 * 60 * 60 * 1e3;
|
|
29901
|
+
var DEFAULT_CLAIM_MAX_ENTRIES = 1e3;
|
|
29902
|
+
var realFs = {
|
|
29903
|
+
readFile: (p2) => readFileSync(p2, "utf8"),
|
|
29904
|
+
writeFile: (p2, d) => writeFileSync(p2, d, "utf8"),
|
|
29905
|
+
rename: (a, b) => renameSync(a, b),
|
|
29906
|
+
mkdir: (d) => {
|
|
29907
|
+
mkdirSync(d, { recursive: true });
|
|
29908
|
+
}
|
|
29861
29909
|
};
|
|
29910
|
+
function directChatClaimsPath(dir) {
|
|
29911
|
+
return dir ? join(dir, DIRECT_CHAT_CLAIMS_FILE) : null;
|
|
29912
|
+
}
|
|
29913
|
+
function isEntry(v) {
|
|
29914
|
+
if (!v || typeof v !== "object") return false;
|
|
29915
|
+
const o = v;
|
|
29916
|
+
return typeof o.session_id === "string" && o.session_id.length > 0 && typeof o.message_id === "string" && o.message_id.length > 0 && typeof o.claimed_at_ms === "number" && Number.isFinite(o.claimed_at_ms);
|
|
29917
|
+
}
|
|
29918
|
+
function boundClaims(entries, nowMs, bounds = {}) {
|
|
29919
|
+
const maxAgeMs = bounds.maxAgeMs ?? DEFAULT_CLAIM_MAX_AGE_MS;
|
|
29920
|
+
const maxEntries = bounds.maxEntries ?? DEFAULT_CLAIM_MAX_ENTRIES;
|
|
29921
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29922
|
+
const kept = [];
|
|
29923
|
+
for (const e of entries) {
|
|
29924
|
+
if (!isEntry(e)) continue;
|
|
29925
|
+
if (nowMs - e.claimed_at_ms > maxAgeMs) continue;
|
|
29926
|
+
const key = `${e.session_id.length}|${e.session_id}|${e.message_id}`;
|
|
29927
|
+
if (seen.has(key)) continue;
|
|
29928
|
+
seen.add(key);
|
|
29929
|
+
kept.push({ session_id: e.session_id, message_id: e.message_id, claimed_at_ms: e.claimed_at_ms });
|
|
29930
|
+
}
|
|
29931
|
+
kept.sort((a, b) => b.claimed_at_ms - a.claimed_at_ms);
|
|
29932
|
+
return kept.slice(0, Math.max(0, maxEntries));
|
|
29933
|
+
}
|
|
29934
|
+
function planClaimRecovery(state) {
|
|
29935
|
+
if (!state.markerRead || !state.sessionId) return { restore: false, bindTo: null };
|
|
29936
|
+
return { restore: true, bindTo: state.sessionId };
|
|
29937
|
+
}
|
|
29938
|
+
function loadDirectChatClaims(path, transcriptId, nowMs, bounds = {}, fs = realFs) {
|
|
29939
|
+
if (!path || !transcriptId) return [];
|
|
29940
|
+
try {
|
|
29941
|
+
const parsed = JSON.parse(fs.readFile(path));
|
|
29942
|
+
if (!parsed || typeof parsed !== "object") return [];
|
|
29943
|
+
const o = parsed;
|
|
29944
|
+
if (o.transcript_session_id !== transcriptId) return [];
|
|
29945
|
+
const claims = o.claims;
|
|
29946
|
+
if (!Array.isArray(claims)) return [];
|
|
29947
|
+
return boundClaims(claims, nowMs, bounds);
|
|
29948
|
+
} catch {
|
|
29949
|
+
return [];
|
|
29950
|
+
}
|
|
29951
|
+
}
|
|
29952
|
+
function writeAtomic(path, body, fs) {
|
|
29953
|
+
try {
|
|
29954
|
+
fs.mkdir(dirname(path));
|
|
29955
|
+
const tmp = `${path}.tmp`;
|
|
29956
|
+
fs.writeFile(tmp, JSON.stringify(body));
|
|
29957
|
+
fs.rename(tmp, path);
|
|
29958
|
+
return true;
|
|
29959
|
+
} catch {
|
|
29960
|
+
return false;
|
|
29961
|
+
}
|
|
29962
|
+
}
|
|
29963
|
+
function saveDirectChatClaims(path, transcriptId, entries, nowMs, bounds = {}, fs = realFs) {
|
|
29964
|
+
if (!path || !transcriptId) return false;
|
|
29965
|
+
return writeAtomic(
|
|
29966
|
+
path,
|
|
29967
|
+
{ version: 2, transcript_session_id: transcriptId, claims: boundClaims(entries, nowMs, bounds) },
|
|
29968
|
+
fs
|
|
29969
|
+
);
|
|
29970
|
+
}
|
|
29971
|
+
function resetDirectChatClaims(path, fs = realFs) {
|
|
29972
|
+
if (!path) return false;
|
|
29973
|
+
return writeAtomic(path, { version: 2, transcript_session_id: null, claims: [] }, fs);
|
|
29974
|
+
}
|
|
29862
29975
|
|
|
29863
29976
|
// ../core/dist/types/agent.js
|
|
29864
29977
|
var FRAMEWORK_MODEL_SLOTS = {
|
|
@@ -38976,20 +39089,22 @@ function renderHistoryResult(result, requestedNotices) {
|
|
|
38976
39089
|
}
|
|
38977
39090
|
|
|
38978
39091
|
// src/direct-chat-session-state.ts
|
|
38979
|
-
import { existsSync, readFileSync } from "fs";
|
|
38980
|
-
import { join } from "path";
|
|
39092
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
39093
|
+
import { join as join2 } from "path";
|
|
38981
39094
|
function readDirectChatSessionState(agentDir, nowMs) {
|
|
38982
|
-
const path =
|
|
39095
|
+
const path = join2(agentDir, "direct-chat-session.json");
|
|
39096
|
+
const fallback = { fresh: false, startedAtMs: nowMs, markerRead: false, sessionId: null };
|
|
38983
39097
|
try {
|
|
38984
|
-
if (!existsSync(path)) return
|
|
38985
|
-
const parsed = JSON.parse(
|
|
38986
|
-
if (!parsed || typeof parsed !== "object") return
|
|
39098
|
+
if (!existsSync(path)) return fallback;
|
|
39099
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
39100
|
+
if (!parsed || typeof parsed !== "object") return fallback;
|
|
38987
39101
|
const o = parsed;
|
|
38988
39102
|
const fresh = o.fresh === true;
|
|
38989
39103
|
const startedAtMs = typeof o.startedAtMs === "number" && Number.isFinite(o.startedAtMs) ? o.startedAtMs : nowMs;
|
|
38990
|
-
|
|
39104
|
+
const sessionId = typeof o.sessionId === "string" && o.sessionId.length > 0 ? o.sessionId : null;
|
|
39105
|
+
return { fresh, startedAtMs, markerRead: true, sessionId };
|
|
38991
39106
|
} catch {
|
|
38992
|
-
return
|
|
39107
|
+
return fallback;
|
|
38993
39108
|
}
|
|
38994
39109
|
}
|
|
38995
39110
|
|
|
@@ -39026,13 +39141,13 @@ function buildDirectChatChannelMeta(input) {
|
|
|
39026
39141
|
}
|
|
39027
39142
|
|
|
39028
39143
|
// src/turn-initiator-marker.ts
|
|
39029
|
-
import { writeFileSync, readFileSync as
|
|
39030
|
-
import { dirname, join as
|
|
39144
|
+
import { writeFileSync as writeFileSync2, readFileSync as readFileSync3, mkdirSync as mkdirSync2, renameSync as renameSync2 } from "fs";
|
|
39145
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
39031
39146
|
var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
39032
39147
|
var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
|
|
39033
39148
|
var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
|
|
39034
39149
|
function turnInitiatorLedgerPath(singleSlotFile) {
|
|
39035
|
-
return
|
|
39150
|
+
return join3(dirname2(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
|
|
39036
39151
|
}
|
|
39037
39152
|
function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
|
|
39038
39153
|
const now = marker.ts;
|
|
@@ -39057,24 +39172,24 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
|
|
|
39057
39172
|
const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
|
|
39058
39173
|
let existing = null;
|
|
39059
39174
|
try {
|
|
39060
|
-
const parsed = JSON.parse(
|
|
39175
|
+
const parsed = JSON.parse(readFileSync3(ledgerFile, "utf8"));
|
|
39061
39176
|
if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
|
|
39062
39177
|
} catch {
|
|
39063
39178
|
}
|
|
39064
39179
|
const next = foldTurnInitiatorLedger(existing, marker);
|
|
39065
39180
|
const tmp = `${ledgerFile}.tmp`;
|
|
39066
|
-
|
|
39067
|
-
|
|
39181
|
+
writeFileSync2(tmp, JSON.stringify(next), "utf8");
|
|
39182
|
+
renameSync2(tmp, ledgerFile);
|
|
39068
39183
|
}
|
|
39069
39184
|
function writeTurnInitiatorMarker(input) {
|
|
39070
39185
|
const file = process.env["AGT_TURN_INITIATOR_FILE"];
|
|
39071
39186
|
if (!file || !input.sender_id) return;
|
|
39072
39187
|
try {
|
|
39073
|
-
|
|
39188
|
+
mkdirSync2(dirname2(file), { recursive: true });
|
|
39074
39189
|
const marker = { ...input, ts: Date.now() };
|
|
39075
39190
|
const tmp = `${file}.tmp`;
|
|
39076
|
-
|
|
39077
|
-
|
|
39191
|
+
writeFileSync2(tmp, JSON.stringify(marker), "utf8");
|
|
39192
|
+
renameSync2(tmp, file);
|
|
39078
39193
|
try {
|
|
39079
39194
|
updateTurnInitiatorLedger(file, marker);
|
|
39080
39195
|
} catch {
|
|
@@ -39084,14 +39199,14 @@ function writeTurnInitiatorMarker(input) {
|
|
|
39084
39199
|
}
|
|
39085
39200
|
|
|
39086
39201
|
// src/scheduled-turn-marker.ts
|
|
39087
|
-
import { readFileSync as
|
|
39088
|
-
import { join as
|
|
39202
|
+
import { readFileSync as readFileSync4, unlinkSync } from "fs";
|
|
39203
|
+
import { join as join4 } from "path";
|
|
39089
39204
|
var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
|
|
39090
39205
|
var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
|
|
39091
39206
|
function clearScheduledTurnMarker(agentDir) {
|
|
39092
39207
|
if (!agentDir) return;
|
|
39093
39208
|
try {
|
|
39094
|
-
unlinkSync(
|
|
39209
|
+
unlinkSync(join4(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
|
|
39095
39210
|
} catch {
|
|
39096
39211
|
}
|
|
39097
39212
|
}
|
|
@@ -39099,14 +39214,14 @@ function clearScheduledTurnMarker(agentDir) {
|
|
|
39099
39214
|
// src/direct-chat-pending-inbound.ts
|
|
39100
39215
|
import {
|
|
39101
39216
|
existsSync as existsSync2,
|
|
39102
|
-
mkdirSync as
|
|
39217
|
+
mkdirSync as mkdirSync3,
|
|
39103
39218
|
readdirSync,
|
|
39104
|
-
readFileSync as
|
|
39105
|
-
renameSync as
|
|
39219
|
+
readFileSync as readFileSync5,
|
|
39220
|
+
renameSync as renameSync3,
|
|
39106
39221
|
unlinkSync as unlinkSync2,
|
|
39107
|
-
writeFileSync as
|
|
39222
|
+
writeFileSync as writeFileSync3
|
|
39108
39223
|
} from "fs";
|
|
39109
|
-
import { join as
|
|
39224
|
+
import { join as join5 } from "path";
|
|
39110
39225
|
function hexEncodeSegment(value) {
|
|
39111
39226
|
return Buffer.from(value, "utf8").toString("hex");
|
|
39112
39227
|
}
|
|
@@ -39125,7 +39240,7 @@ function directChatInboundId(sessionId, messageId) {
|
|
|
39125
39240
|
function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
|
|
39126
39241
|
if (!dir || !sessionId || !messageId) return;
|
|
39127
39242
|
try {
|
|
39128
|
-
|
|
39243
|
+
mkdirSync3(dir, { recursive: true });
|
|
39129
39244
|
const marker = {
|
|
39130
39245
|
channel: "direct-chat",
|
|
39131
39246
|
session_id: sessionId,
|
|
@@ -39133,10 +39248,10 @@ function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
|
|
|
39133
39248
|
received_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
39134
39249
|
inbound_id: directChatInboundId(sessionId, messageId)
|
|
39135
39250
|
};
|
|
39136
|
-
const final =
|
|
39251
|
+
const final = join5(dir, directChatMarkerName(sessionId, messageId));
|
|
39137
39252
|
const tmp = `${final}.tmp`;
|
|
39138
|
-
|
|
39139
|
-
|
|
39253
|
+
writeFileSync3(tmp, JSON.stringify(marker), "utf8");
|
|
39254
|
+
renameSync3(tmp, final);
|
|
39140
39255
|
} catch {
|
|
39141
39256
|
}
|
|
39142
39257
|
}
|
|
@@ -39152,15 +39267,15 @@ function clearDirectChatPendingMarkersForSession(dir, sessionId, op = defaultCle
|
|
|
39152
39267
|
}
|
|
39153
39268
|
for (const name of names) {
|
|
39154
39269
|
if (!name.startsWith(prefix) || !name.endsWith(".json")) continue;
|
|
39155
|
-
op(
|
|
39270
|
+
op(join5(dir, name));
|
|
39156
39271
|
cleared += 1;
|
|
39157
39272
|
}
|
|
39158
39273
|
return cleared;
|
|
39159
39274
|
}
|
|
39160
|
-
function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) =>
|
|
39275
|
+
function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) => readFileSync5(path, "utf8")) {
|
|
39161
39276
|
if (!dir || !sessionId || !messageId) return null;
|
|
39162
39277
|
try {
|
|
39163
|
-
const raw = readFileImpl(
|
|
39278
|
+
const raw = readFileImpl(join5(dir, directChatMarkerName(sessionId, messageId)));
|
|
39164
39279
|
return JSON.parse(raw);
|
|
39165
39280
|
} catch {
|
|
39166
39281
|
return null;
|
|
@@ -39183,7 +39298,7 @@ function sweepAgedDirectChatMarkers(dir, deps) {
|
|
|
39183
39298
|
}
|
|
39184
39299
|
for (const name of names) {
|
|
39185
39300
|
if (!name.endsWith(".json") || name.startsWith(".")) continue;
|
|
39186
|
-
const full =
|
|
39301
|
+
const full = join5(dir, name);
|
|
39187
39302
|
let marker;
|
|
39188
39303
|
try {
|
|
39189
39304
|
marker = JSON.parse(deps.readFile(full));
|
|
@@ -39282,17 +39397,17 @@ async function consumeDirectChatRecoveryFile(fullPath, filename, deps) {
|
|
|
39282
39397
|
}
|
|
39283
39398
|
|
|
39284
39399
|
// src/inbound-delivery-ledger.ts
|
|
39285
|
-
import { existsSync as existsSync3, mkdirSync as
|
|
39286
|
-
import { join as
|
|
39400
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync6, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
39401
|
+
import { join as join6 } from "path";
|
|
39287
39402
|
function safeInboundId(inboundId) {
|
|
39288
39403
|
return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
39289
39404
|
}
|
|
39290
39405
|
var defaultDeps = {
|
|
39291
|
-
mkdir: (dir) =>
|
|
39292
|
-
writeFile: (path, data) =>
|
|
39293
|
-
rename: (from, to) =>
|
|
39406
|
+
mkdir: (dir) => mkdirSync4(dir, { recursive: true }),
|
|
39407
|
+
writeFile: (path, data) => writeFileSync4(path, data, "utf8"),
|
|
39408
|
+
rename: (from, to) => renameSync4(from, to),
|
|
39294
39409
|
readdir: (dir) => readdirSync2(dir),
|
|
39295
|
-
readFile: (path) =>
|
|
39410
|
+
readFile: (path) => readFileSync6(path, "utf8"),
|
|
39296
39411
|
exists: (path) => existsSync3(path)
|
|
39297
39412
|
};
|
|
39298
39413
|
function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
|
|
@@ -39301,7 +39416,7 @@ function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
|
|
|
39301
39416
|
if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return;
|
|
39302
39417
|
try {
|
|
39303
39418
|
deps.mkdir(dir);
|
|
39304
|
-
const final =
|
|
39419
|
+
const final = join6(dir, `${safe}.json`);
|
|
39305
39420
|
const tmp = `${final}.tmp`;
|
|
39306
39421
|
deps.writeFile(tmp, JSON.stringify(record2));
|
|
39307
39422
|
deps.rename(tmp, final);
|
|
@@ -39313,22 +39428,22 @@ function inboundDeliveryLedgerHas(dir, inboundId, deps = defaultDeps) {
|
|
|
39313
39428
|
const safe = safeInboundId(inboundId);
|
|
39314
39429
|
if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return false;
|
|
39315
39430
|
try {
|
|
39316
|
-
return deps.exists(
|
|
39431
|
+
return deps.exists(join6(dir, `${safe}.json`));
|
|
39317
39432
|
} catch {
|
|
39318
39433
|
return false;
|
|
39319
39434
|
}
|
|
39320
39435
|
}
|
|
39321
39436
|
|
|
39322
39437
|
// src/ack-reaction.ts
|
|
39323
|
-
import { readdirSync as readdirSync3, readFileSync as
|
|
39324
|
-
import { join as
|
|
39438
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "fs";
|
|
39439
|
+
import { join as join8 } from "path";
|
|
39325
39440
|
|
|
39326
39441
|
// src/flags-cache-read.ts
|
|
39327
|
-
import { existsSync as existsSync4, readFileSync as
|
|
39442
|
+
import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
39328
39443
|
import { homedir } from "os";
|
|
39329
|
-
import { join as
|
|
39444
|
+
import { join as join7 } from "path";
|
|
39330
39445
|
function defaultFlagsCachePath() {
|
|
39331
|
-
return
|
|
39446
|
+
return join7(homedir(), ".augmented", "flags-cache.json");
|
|
39332
39447
|
}
|
|
39333
39448
|
function envBoolean(raw) {
|
|
39334
39449
|
if (raw === void 0) return void 0;
|
|
@@ -39341,7 +39456,7 @@ function envBoolean(raw) {
|
|
|
39341
39456
|
function cachedBoolean(key, path) {
|
|
39342
39457
|
try {
|
|
39343
39458
|
if (!existsSync4(path)) return void 0;
|
|
39344
|
-
const parsed = JSON.parse(
|
|
39459
|
+
const parsed = JSON.parse(readFileSync7(path, "utf8"));
|
|
39345
39460
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
39346
39461
|
const flags = parsed.flags;
|
|
39347
39462
|
if (!flags || typeof flags !== "object") return void 0;
|
|
@@ -39422,7 +39537,7 @@ function undeliverableNoticeTextForRepeat(i) {
|
|
|
39422
39537
|
}
|
|
39423
39538
|
return null;
|
|
39424
39539
|
}
|
|
39425
|
-
function channelInboundGateOpen(readFile = (p2) =>
|
|
39540
|
+
function channelInboundGateOpen(readFile = (p2) => readFileSync8(p2, "utf-8")) {
|
|
39426
39541
|
const path = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : "/etc/claude-code/managed-settings.json";
|
|
39427
39542
|
let raw;
|
|
39428
39543
|
try {
|
|
@@ -39487,7 +39602,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
|
39487
39602
|
function readGiveUpSignal(path, now = Date.now()) {
|
|
39488
39603
|
if (!path) return null;
|
|
39489
39604
|
try {
|
|
39490
|
-
const raw = JSON.parse(
|
|
39605
|
+
const raw = JSON.parse(readFileSync8(path, "utf8"));
|
|
39491
39606
|
if (typeof raw.gave_up_at !== "string") return null;
|
|
39492
39607
|
const t = Date.parse(raw.gave_up_at);
|
|
39493
39608
|
if (!Number.isFinite(t) || t > now) return null;
|
|
@@ -39501,12 +39616,12 @@ function readGiveUpSignal(path, now = Date.now()) {
|
|
|
39501
39616
|
var USAGE_LIMIT_LIVE_WINDOW_MS = 3 * 6e4;
|
|
39502
39617
|
function readUsageLimitForBusyAck(agentDir, now = Date.now()) {
|
|
39503
39618
|
if (!agentDir) return null;
|
|
39504
|
-
const path =
|
|
39619
|
+
const path = join8(agentDir, GIVE_UP_SIGNAL_FILENAME);
|
|
39505
39620
|
const sig = readGiveUpSignal(path, now);
|
|
39506
39621
|
if (sig?.reason !== "usage_limit") return null;
|
|
39507
39622
|
let lastSeenMs = null;
|
|
39508
39623
|
try {
|
|
39509
|
-
const raw = JSON.parse(
|
|
39624
|
+
const raw = JSON.parse(readFileSync8(path, "utf8"));
|
|
39510
39625
|
if (typeof raw.usage_limit_last_seen_at === "string") {
|
|
39511
39626
|
const t = Date.parse(raw.usage_limit_last_seen_at);
|
|
39512
39627
|
if (Number.isFinite(t) && t <= now) lastSeenMs = t;
|
|
@@ -39525,7 +39640,7 @@ function readBlockedPromptForBusyAck(agentDir, now = Date.now()) {
|
|
|
39525
39640
|
if (!agentDir) return null;
|
|
39526
39641
|
let raw;
|
|
39527
39642
|
try {
|
|
39528
|
-
raw = JSON.parse(
|
|
39643
|
+
raw = JSON.parse(readFileSync8(join8(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
|
|
39529
39644
|
} catch {
|
|
39530
39645
|
return null;
|
|
39531
39646
|
}
|
|
@@ -39578,7 +39693,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
|
|
|
39578
39693
|
if (!name.endsWith(".json")) continue;
|
|
39579
39694
|
let receivedAt;
|
|
39580
39695
|
try {
|
|
39581
|
-
const raw = JSON.parse(
|
|
39696
|
+
const raw = JSON.parse(readFileSync8(join8(dir, name), "utf-8"));
|
|
39582
39697
|
if (raw.discretionary === true) continue;
|
|
39583
39698
|
if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
|
|
39584
39699
|
receivedAt = raw.received_at;
|
|
@@ -39632,32 +39747,32 @@ function isMarkerGenuinelyAged(receivedAt, nowMs, thresholdMs) {
|
|
|
39632
39747
|
}
|
|
39633
39748
|
var DEFLECTION_COUNTER_SUFFIX = "-deflections.json";
|
|
39634
39749
|
function deflectionCounterPath(agentDir, channel) {
|
|
39635
|
-
return
|
|
39750
|
+
return join8(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
|
|
39636
39751
|
}
|
|
39637
39752
|
function recordChannelDeflection(agentDir, channel, cause) {
|
|
39638
39753
|
if (!agentDir) return;
|
|
39639
39754
|
const path = deflectionCounterPath(agentDir, channel);
|
|
39640
39755
|
let counts = {};
|
|
39641
39756
|
try {
|
|
39642
|
-
const parsed = JSON.parse(
|
|
39757
|
+
const parsed = JSON.parse(readFileSync8(path, "utf-8"));
|
|
39643
39758
|
if (parsed && typeof parsed === "object") counts = parsed;
|
|
39644
39759
|
} catch {
|
|
39645
39760
|
}
|
|
39646
39761
|
counts[cause] = (counts[cause] ?? 0) + 1;
|
|
39647
39762
|
try {
|
|
39648
|
-
|
|
39763
|
+
writeFileSync5(path, JSON.stringify(counts), { mode: 384 });
|
|
39649
39764
|
} catch {
|
|
39650
39765
|
}
|
|
39651
39766
|
}
|
|
39652
39767
|
|
|
39653
39768
|
// src/turn-failure-watch.ts
|
|
39654
39769
|
import { readdirSync as readdirSync5, statSync as statSync2 } from "fs";
|
|
39655
|
-
import { join as
|
|
39770
|
+
import { join as join10 } from "path";
|
|
39656
39771
|
|
|
39657
39772
|
// src/rate-limit-watch.ts
|
|
39658
39773
|
import { closeSync, fstatSync, openSync, readSync, readdirSync as readdirSync4, statSync } from "fs";
|
|
39659
39774
|
import { homedir as homedir2 } from "os";
|
|
39660
|
-
import { join as
|
|
39775
|
+
import { join as join9 } from "path";
|
|
39661
39776
|
var DEFAULT_WATCH_MS = 5e3;
|
|
39662
39777
|
var DEFAULT_POLL_MS = 400;
|
|
39663
39778
|
var INITIAL_TAIL_BYTES = 256 * 1024;
|
|
@@ -39729,7 +39844,7 @@ function oldestTimestampMs(text) {
|
|
|
39729
39844
|
function agentTranscriptDir(opts) {
|
|
39730
39845
|
const cwd = opts?.cwd ?? process.cwd();
|
|
39731
39846
|
const home = opts?.home ?? homedir2();
|
|
39732
|
-
return
|
|
39847
|
+
return join9(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
|
|
39733
39848
|
}
|
|
39734
39849
|
function classifyTranscriptSince(opts) {
|
|
39735
39850
|
const dir = opts.transcriptDir ?? agentTranscriptDir({ cwd: opts.cwd, home: opts.home });
|
|
@@ -39742,7 +39857,7 @@ function classifyTranscriptSince(opts) {
|
|
|
39742
39857
|
let newest = UNKNOWN_RATE_LIMIT;
|
|
39743
39858
|
for (const name of entries) {
|
|
39744
39859
|
if (!name.endsWith(".jsonl")) continue;
|
|
39745
|
-
const path =
|
|
39860
|
+
const path = join9(dir, name);
|
|
39746
39861
|
try {
|
|
39747
39862
|
const st = statSync(path);
|
|
39748
39863
|
if (!st.isFile() || st.mtimeMs < opts.sinceMs) continue;
|
|
@@ -39817,7 +39932,7 @@ function classifyTurnFailureSince(opts) {
|
|
|
39817
39932
|
const unrecognised = /* @__PURE__ */ new Set();
|
|
39818
39933
|
for (const name of entries) {
|
|
39819
39934
|
if (!name.endsWith(".jsonl")) continue;
|
|
39820
|
-
const path =
|
|
39935
|
+
const path = join10(dir, name);
|
|
39821
39936
|
let fingerprint;
|
|
39822
39937
|
try {
|
|
39823
39938
|
const st = statSync2(path);
|
|
@@ -40004,15 +40119,15 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
|
|
|
40004
40119
|
// src/mcp-spawn-lock.ts
|
|
40005
40120
|
import {
|
|
40006
40121
|
existsSync as existsSync5,
|
|
40007
|
-
mkdirSync as
|
|
40008
|
-
readFileSync as
|
|
40009
|
-
renameSync as
|
|
40122
|
+
mkdirSync as mkdirSync5,
|
|
40123
|
+
readFileSync as readFileSync9,
|
|
40124
|
+
renameSync as renameSync5,
|
|
40010
40125
|
statSync as statSync3,
|
|
40011
40126
|
unlinkSync as unlinkSync3,
|
|
40012
40127
|
utimesSync,
|
|
40013
|
-
writeFileSync as
|
|
40128
|
+
writeFileSync as writeFileSync6
|
|
40014
40129
|
} from "fs";
|
|
40015
|
-
import { join as
|
|
40130
|
+
import { join as join11 } from "path";
|
|
40016
40131
|
var STALE_LOCK_MS = 9e4;
|
|
40017
40132
|
var HEARTBEAT_INTERVAL_MS = 3e4;
|
|
40018
40133
|
function defaultIsPidAlive(pid) {
|
|
@@ -40035,7 +40150,7 @@ function acquireMcpSpawnLock(args) {
|
|
|
40035
40150
|
const nowMs = options.nowMs ?? (() => Date.now());
|
|
40036
40151
|
const lockMtimeMs = options.lockMtimeMs ?? defaultLockMtimeMs;
|
|
40037
40152
|
const staleMs = options.staleMs ?? STALE_LOCK_MS;
|
|
40038
|
-
const path =
|
|
40153
|
+
const path = join11(agentDir, basename);
|
|
40039
40154
|
const existing = readLockHolder(path);
|
|
40040
40155
|
if (existing) {
|
|
40041
40156
|
if (existing.pid === selfPid) {
|
|
@@ -40049,11 +40164,11 @@ function acquireMcpSpawnLock(args) {
|
|
|
40049
40164
|
}
|
|
40050
40165
|
}
|
|
40051
40166
|
}
|
|
40052
|
-
|
|
40167
|
+
mkdirSync5(agentDir, { recursive: true, mode: 448 });
|
|
40053
40168
|
const tmpPath = `${path}.${selfPid}.tmp`;
|
|
40054
40169
|
const payload = { pid: selfPid, started_at: now() };
|
|
40055
|
-
|
|
40056
|
-
|
|
40170
|
+
writeFileSync6(tmpPath, JSON.stringify(payload), { mode: 384 });
|
|
40171
|
+
renameSync5(tmpPath, path);
|
|
40057
40172
|
return { kind: "acquired", path };
|
|
40058
40173
|
}
|
|
40059
40174
|
function releaseMcpSpawnLock(lockPath, opts = {}) {
|
|
@@ -40102,7 +40217,7 @@ function defaultLockMtimeMs(path) {
|
|
|
40102
40217
|
function readLockHolder(path) {
|
|
40103
40218
|
if (!existsSync5(path)) return null;
|
|
40104
40219
|
try {
|
|
40105
|
-
const raw =
|
|
40220
|
+
const raw = readFileSync9(path, "utf8");
|
|
40106
40221
|
const parsed = JSON.parse(raw);
|
|
40107
40222
|
const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
|
|
40108
40223
|
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
@@ -40115,26 +40230,26 @@ function readLockHolder(path) {
|
|
|
40115
40230
|
|
|
40116
40231
|
// src/direct-chat-channel.ts
|
|
40117
40232
|
import { homedir as homedir4 } from "os";
|
|
40118
|
-
import { join as
|
|
40233
|
+
import { join as join16 } from "path";
|
|
40119
40234
|
import { randomUUID } from "crypto";
|
|
40120
40235
|
import {
|
|
40121
40236
|
watch,
|
|
40122
|
-
mkdirSync as
|
|
40123
|
-
writeFileSync as
|
|
40124
|
-
readFileSync as
|
|
40237
|
+
mkdirSync as mkdirSync6,
|
|
40238
|
+
writeFileSync as writeFileSync8,
|
|
40239
|
+
readFileSync as readFileSync12,
|
|
40125
40240
|
readdirSync as readdirSync6,
|
|
40126
40241
|
existsSync as existsSync6,
|
|
40127
|
-
renameSync as
|
|
40242
|
+
renameSync as renameSync6,
|
|
40128
40243
|
unlinkSync as unlinkSync4,
|
|
40129
40244
|
statSync as statSync4,
|
|
40130
40245
|
createWriteStream
|
|
40131
40246
|
} from "fs";
|
|
40132
40247
|
|
|
40133
40248
|
// src/direct-chat-inbound-attachments.ts
|
|
40134
|
-
import { join as
|
|
40249
|
+
import { join as join13 } from "path";
|
|
40135
40250
|
|
|
40136
40251
|
// ../core/dist/provisioning/frameworks/claudecode/agent-dir-alias.js
|
|
40137
|
-
import { isAbsolute, join as
|
|
40252
|
+
import { isAbsolute, join as join12, relative, sep } from "path";
|
|
40138
40253
|
var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
40139
40254
|
var VALID_AGENT_ID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
40140
40255
|
var INITIATOR_BASENAME = ".current-turn-initiator.json";
|
|
@@ -40142,7 +40257,7 @@ function isSafeAgentSegment(segment) {
|
|
|
40142
40257
|
return VALID_CODE_NAME.test(segment) || VALID_AGENT_ID.test(segment);
|
|
40143
40258
|
}
|
|
40144
40259
|
function initiatorDirSegment(initiatorFile, homeDir) {
|
|
40145
|
-
const rel = relative(
|
|
40260
|
+
const rel = relative(join12(homeDir, ".augmented"), initiatorFile);
|
|
40146
40261
|
if (!rel || isAbsolute(rel))
|
|
40147
40262
|
return null;
|
|
40148
40263
|
const parts = rel.split(sep);
|
|
@@ -40157,17 +40272,17 @@ function resolveAgentDirAlias(input) {
|
|
|
40157
40272
|
const { codeName, turnInitiatorFile, agentId, homeDir } = input;
|
|
40158
40273
|
const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
|
|
40159
40274
|
if (codeNameTrimmed && VALID_CODE_NAME.test(codeNameTrimmed)) {
|
|
40160
|
-
return
|
|
40275
|
+
return join12(homeDir, ".augmented", codeNameTrimmed);
|
|
40161
40276
|
}
|
|
40162
40277
|
const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
|
|
40163
40278
|
if (initiator) {
|
|
40164
40279
|
const segment = initiatorDirSegment(initiator, homeDir);
|
|
40165
40280
|
if (segment)
|
|
40166
|
-
return
|
|
40281
|
+
return join12(homeDir, ".augmented", segment);
|
|
40167
40282
|
}
|
|
40168
40283
|
const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
|
|
40169
40284
|
if (agentIdTrimmed && VALID_AGENT_ID.test(agentIdTrimmed)) {
|
|
40170
|
-
return
|
|
40285
|
+
return join12(homeDir, ".augmented", agentIdTrimmed);
|
|
40171
40286
|
}
|
|
40172
40287
|
return null;
|
|
40173
40288
|
}
|
|
@@ -40177,7 +40292,7 @@ var MAX_INBOUND_ATTACHMENT_BYTES = 10 * 1024 * 1024;
|
|
|
40177
40292
|
var INBOUND_ATTACHMENTS_SUBDIR = "direct-chat-inbound";
|
|
40178
40293
|
function resolveInboundAttachmentsDir(input) {
|
|
40179
40294
|
const alias = resolveAgentDirAlias(input);
|
|
40180
|
-
return alias === null ? null :
|
|
40295
|
+
return alias === null ? null : join13(alias, INBOUND_ATTACHMENTS_SUBDIR);
|
|
40181
40296
|
}
|
|
40182
40297
|
function isImageContentType(contentType) {
|
|
40183
40298
|
return typeof contentType === "string" && contentType.toLowerCase().startsWith("image/");
|
|
@@ -40660,19 +40775,19 @@ function isMaintenanceModeActive(opts) {
|
|
|
40660
40775
|
}
|
|
40661
40776
|
|
|
40662
40777
|
// src/account-enforcement-notice.ts
|
|
40663
|
-
import { readFileSync as
|
|
40778
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
40664
40779
|
import { homedir as homedir3 } from "os";
|
|
40665
|
-
import { join as
|
|
40780
|
+
import { join as join14 } from "path";
|
|
40666
40781
|
function accountEnforcementMarkerPath(codeName) {
|
|
40667
40782
|
if (!codeName) return null;
|
|
40668
|
-
return
|
|
40783
|
+
return join14(homedir3(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
40669
40784
|
}
|
|
40670
40785
|
function readAccountEnforcementMarker(opts) {
|
|
40671
40786
|
const path = opts.filePath ?? accountEnforcementMarkerPath(opts.codeName);
|
|
40672
40787
|
if (!path) return null;
|
|
40673
40788
|
let raw;
|
|
40674
40789
|
try {
|
|
40675
|
-
raw =
|
|
40790
|
+
raw = readFileSync10(path, "utf-8");
|
|
40676
40791
|
} catch {
|
|
40677
40792
|
return null;
|
|
40678
40793
|
}
|
|
@@ -40698,8 +40813,8 @@ function shouldSendAccountWarn(opts) {
|
|
|
40698
40813
|
}
|
|
40699
40814
|
|
|
40700
40815
|
// ../core/dist/direct-chat/cursor-advance-telemetry.js
|
|
40701
|
-
import { readFileSync as
|
|
40702
|
-
import { join as
|
|
40816
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "fs";
|
|
40817
|
+
import { join as join15 } from "path";
|
|
40703
40818
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
40704
40819
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
40705
40820
|
if (!agentDir)
|
|
@@ -40707,10 +40822,10 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
40707
40822
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
40708
40823
|
if (key === null)
|
|
40709
40824
|
return;
|
|
40710
|
-
const path =
|
|
40825
|
+
const path = join15(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
40711
40826
|
const counts = {};
|
|
40712
40827
|
try {
|
|
40713
|
-
const parsed = JSON.parse(
|
|
40828
|
+
const parsed = JSON.parse(readFileSync11(path, "utf-8"));
|
|
40714
40829
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
40715
40830
|
for (const [k, v] of Object.entries(parsed)) {
|
|
40716
40831
|
if (typeof v === "number" && Number.isInteger(v) && v >= 0)
|
|
@@ -40721,7 +40836,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
40721
40836
|
}
|
|
40722
40837
|
counts[key] = (counts[key] ?? 0) + 1;
|
|
40723
40838
|
try {
|
|
40724
|
-
|
|
40839
|
+
writeFileSync7(path, JSON.stringify(counts), { mode: 384 });
|
|
40725
40840
|
} catch {
|
|
40726
40841
|
}
|
|
40727
40842
|
}
|
|
@@ -40843,7 +40958,7 @@ var DIRECT_CHAT_ACCOUNT_WARN_COOLDOWN_MS = (() => {
|
|
|
40843
40958
|
var AGT_HOST = process.env.AGT_HOST;
|
|
40844
40959
|
var AGT_API_KEY = process.env.AGT_API_KEY;
|
|
40845
40960
|
var AGT_AGENT_ID = process.env.AGT_AGENT_ID;
|
|
40846
|
-
var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ?
|
|
40961
|
+
var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join16(homedir4(), ".augmented", AGT_AGENT_ID) : null;
|
|
40847
40962
|
var INBOUND_ATTACHMENTS_DIR = resolveInboundAttachmentsDir({
|
|
40848
40963
|
codeName: process.env.AGT_AGENT_CODE_NAME,
|
|
40849
40964
|
turnInitiatorFile: process.env.AGT_TURN_INITIATOR_FILE,
|
|
@@ -40854,10 +40969,10 @@ var AGT_AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME;
|
|
|
40854
40969
|
var directChatStderrLogStream = null;
|
|
40855
40970
|
if (AGT_AGENT_CODE_NAME) {
|
|
40856
40971
|
try {
|
|
40857
|
-
const logDir =
|
|
40858
|
-
|
|
40972
|
+
const logDir = join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME);
|
|
40973
|
+
mkdirSync6(logDir, { recursive: true });
|
|
40859
40974
|
directChatStderrLogStream = createWriteStream(
|
|
40860
|
-
|
|
40975
|
+
join16(logDir, "direct-chat-channel-stderr.log"),
|
|
40861
40976
|
{ flags: "a", mode: 384 }
|
|
40862
40977
|
);
|
|
40863
40978
|
directChatStderrLogStream.on("error", () => {
|
|
@@ -40876,10 +40991,10 @@ if (AGT_AGENT_CODE_NAME) {
|
|
|
40876
40991
|
} catch {
|
|
40877
40992
|
}
|
|
40878
40993
|
}
|
|
40879
|
-
var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ?
|
|
40880
|
-
var DIRECT_CHAT_PENDING_INBOUND_DIR = AGT_AGENT_CODE_NAME ?
|
|
40881
|
-
var DIRECT_CHAT_DELIVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ?
|
|
40882
|
-
var DIRECT_CHAT_CODE_NAME_AGENT_DIR = AGT_AGENT_CODE_NAME ?
|
|
40994
|
+
var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
|
|
40995
|
+
var DIRECT_CHAT_PENDING_INBOUND_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-pending-inbound") : null;
|
|
40996
|
+
var DIRECT_CHAT_DELIVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-inbound-delivery-ledger") : null;
|
|
40997
|
+
var DIRECT_CHAT_CODE_NAME_AGENT_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME) : null;
|
|
40883
40998
|
var DIRECT_CHAT_STALE_MARKER_MS = 24 * 60 * 60 * 1e3;
|
|
40884
40999
|
function judgeCursorAdvance(input, ctx) {
|
|
40885
41000
|
const verdict = classifyCursorAdvance(input);
|
|
@@ -40899,8 +41014,8 @@ function recordDirectChatDelivery(sessionId, messageIds) {
|
|
|
40899
41014
|
delivered_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40900
41015
|
});
|
|
40901
41016
|
}
|
|
40902
|
-
var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ?
|
|
40903
|
-
var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ?
|
|
41017
|
+
var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-recovery-outbox") : null;
|
|
41018
|
+
var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-direct-chat-recovery-ledger") : null;
|
|
40904
41019
|
var progressReceivedAt = /* @__PURE__ */ new Map();
|
|
40905
41020
|
var directChatProgressState = { tracked: null };
|
|
40906
41021
|
var directChatProgressTickRunning = false;
|
|
@@ -40919,7 +41034,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
|
|
|
40919
41034
|
function readProgressHeartbeat() {
|
|
40920
41035
|
if (!PROGRESS_HEARTBEAT_PATH || !existsSync6(PROGRESS_HEARTBEAT_PATH)) return null;
|
|
40921
41036
|
try {
|
|
40922
|
-
return parseProgressHeartbeat(
|
|
41037
|
+
return parseProgressHeartbeat(readFileSync12(PROGRESS_HEARTBEAT_PATH, "utf-8"));
|
|
40923
41038
|
} catch {
|
|
40924
41039
|
return null;
|
|
40925
41040
|
}
|
|
@@ -40928,9 +41043,9 @@ function seedProgressHeartbeat() {
|
|
|
40928
41043
|
if (!PROGRESS_HEARTBEAT_PATH) return;
|
|
40929
41044
|
const tmp = `${PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
|
|
40930
41045
|
try {
|
|
40931
|
-
|
|
40932
|
-
|
|
40933
|
-
|
|
41046
|
+
mkdirSync6(join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
|
|
41047
|
+
writeFileSync8(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
|
|
41048
|
+
renameSync6(tmp, PROGRESS_HEARTBEAT_PATH);
|
|
40934
41049
|
} catch {
|
|
40935
41050
|
try {
|
|
40936
41051
|
unlinkSync4(tmp);
|
|
@@ -41123,9 +41238,9 @@ var inboundAttachmentDeps = {
|
|
|
41123
41238
|
bytes: async () => new Uint8Array(await res.arrayBuffer())
|
|
41124
41239
|
};
|
|
41125
41240
|
},
|
|
41126
|
-
ensureDir: (dir) =>
|
|
41127
|
-
writeFile: (path, bytes) =>
|
|
41128
|
-
joinPath: (...parts) =>
|
|
41241
|
+
ensureDir: (dir) => mkdirSync6(dir, { recursive: true }),
|
|
41242
|
+
writeFile: (path, bytes) => writeFileSync8(path, bytes, { mode: 384 }),
|
|
41243
|
+
joinPath: (...parts) => join16(...parts),
|
|
41129
41244
|
warn: (msg) => process.stderr.write(`${msg}
|
|
41130
41245
|
`)
|
|
41131
41246
|
};
|
|
@@ -41159,7 +41274,13 @@ var mcp = new Server(
|
|
|
41159
41274
|
instructions: buildDirectChatMcpInstructions()
|
|
41160
41275
|
}
|
|
41161
41276
|
);
|
|
41162
|
-
var
|
|
41277
|
+
var DIRECT_CHAT_CLAIMS_PATH = directChatClaimsPath(DIRECT_CHAT_AGENT_DIR);
|
|
41278
|
+
var claimsTranscriptId = null;
|
|
41279
|
+
var claimTracker = new DirectChatClaimTracker({
|
|
41280
|
+
onChange: (t) => {
|
|
41281
|
+
saveDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH, claimsTranscriptId, t.snapshot(), Date.now());
|
|
41282
|
+
}
|
|
41283
|
+
});
|
|
41163
41284
|
mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
41164
41285
|
tools: [
|
|
41165
41286
|
{
|
|
@@ -41553,7 +41674,7 @@ function directChatSessionReplayFacts(sessionId) {
|
|
|
41553
41674
|
sessionId,
|
|
41554
41675
|
(fullPath) => {
|
|
41555
41676
|
try {
|
|
41556
|
-
const marker = JSON.parse(
|
|
41677
|
+
const marker = JSON.parse(readFileSync12(fullPath, "utf-8"));
|
|
41557
41678
|
found.push({ hasPayload: Boolean(marker.payload), discretionary: marker.discretionary });
|
|
41558
41679
|
} catch {
|
|
41559
41680
|
found.push({ hasPayload: false });
|
|
@@ -41612,7 +41733,7 @@ function scheduleDirectChatBusyAck(sessionId, messageId, arrivedWhileBusy) {
|
|
|
41612
41733
|
let paneLogFreshAgeMs = null;
|
|
41613
41734
|
if (DIRECT_CHAT_CODE_NAME_AGENT_DIR) {
|
|
41614
41735
|
try {
|
|
41615
|
-
const paneMtimeMs = statSync4(
|
|
41736
|
+
const paneMtimeMs = statSync4(join16(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "pane.log")).mtimeMs;
|
|
41616
41737
|
paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
|
|
41617
41738
|
} catch {
|
|
41618
41739
|
}
|
|
@@ -41767,6 +41888,7 @@ function armUsageLimitWatch(args) {
|
|
|
41767
41888
|
})();
|
|
41768
41889
|
}
|
|
41769
41890
|
async function pollForMessages(sinceMs) {
|
|
41891
|
+
let pushPendingId = null;
|
|
41770
41892
|
try {
|
|
41771
41893
|
const res = await apiPost("/host/direct-chat/poll", {
|
|
41772
41894
|
agent_id: AGT_AGENT_ID,
|
|
@@ -41794,11 +41916,7 @@ async function pollForMessages(sinceMs) {
|
|
|
41794
41916
|
const accountMuted = !isNotice && !maintenanceActive ? readAccountEnforcementLevel({ codeName: AGT_AGENT_CODE_NAME ?? null }) === "mute" : false;
|
|
41795
41917
|
if (!isNotice && !maintenanceActive && !accountMuted) {
|
|
41796
41918
|
markProcessed(msg.id);
|
|
41797
|
-
|
|
41798
|
-
if (!progressReceivedAt.has(msg.session_id)) {
|
|
41799
|
-
progressReceivedAt.set(msg.session_id, Date.now());
|
|
41800
|
-
}
|
|
41801
|
-
seedProgressHeartbeat();
|
|
41919
|
+
pushPendingId = msg.id;
|
|
41802
41920
|
}
|
|
41803
41921
|
if (maintenanceActive) {
|
|
41804
41922
|
const throttleKey = `${msg.session_id}|maintenance`;
|
|
@@ -41947,6 +42065,12 @@ async function pollForMessages(sinceMs) {
|
|
|
41947
42065
|
}
|
|
41948
42066
|
});
|
|
41949
42067
|
if (!isNotice) {
|
|
42068
|
+
pushPendingId = null;
|
|
42069
|
+
claimTracker.track(msg.session_id, msg.id);
|
|
42070
|
+
if (!progressReceivedAt.has(msg.session_id)) {
|
|
42071
|
+
progressReceivedAt.set(msg.session_id, Date.now());
|
|
42072
|
+
}
|
|
42073
|
+
seedProgressHeartbeat();
|
|
41950
42074
|
const arrivedWhileBusy = hasInFlightInbound(DIRECT_CHAT_PENDING_INBOUND_DIR);
|
|
41951
42075
|
writeDirectChatPendingInboundMarker(
|
|
41952
42076
|
DIRECT_CHAT_PENDING_INBOUND_DIR,
|
|
@@ -42020,6 +42144,7 @@ async function pollForMessages(sinceMs) {
|
|
|
42020
42144
|
}
|
|
42021
42145
|
return true;
|
|
42022
42146
|
} catch (err) {
|
|
42147
|
+
if (pushPendingId) processedIds.delete(pushPendingId);
|
|
42023
42148
|
process.stderr.write(
|
|
42024
42149
|
`direct-chat-channel: Poll error: ${err.message}
|
|
42025
42150
|
`
|
|
@@ -42077,11 +42202,25 @@ var doorbellWatcher = null;
|
|
|
42077
42202
|
var safetyNetTimer = null;
|
|
42078
42203
|
if (DOORBELL_ENABLED && DIRECT_CHAT_AGENT_DIR) {
|
|
42079
42204
|
try {
|
|
42080
|
-
|
|
42205
|
+
mkdirSync6(DIRECT_CHAT_AGENT_DIR, { recursive: true });
|
|
42081
42206
|
} catch {
|
|
42082
42207
|
}
|
|
42083
42208
|
const sessionState = readDirectChatSessionState(DIRECT_CHAT_AGENT_DIR, Date.now());
|
|
42084
42209
|
const sinceMs = sessionState.startedAtMs;
|
|
42210
|
+
const claimPlan = planClaimRecovery(sessionState);
|
|
42211
|
+
claimsTranscriptId = claimPlan.bindTo;
|
|
42212
|
+
if (claimPlan.restore) {
|
|
42213
|
+
const recovered = loadDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH, claimPlan.bindTo, Date.now());
|
|
42214
|
+
claimTracker.restore(recovered);
|
|
42215
|
+
if (recovered.length > 0) {
|
|
42216
|
+
process.stderr.write(
|
|
42217
|
+
`direct-chat-channel: restored ${recovered.length} pre-restart claim(s) for resumed session
|
|
42218
|
+
`
|
|
42219
|
+
);
|
|
42220
|
+
}
|
|
42221
|
+
} else {
|
|
42222
|
+
resetDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH);
|
|
42223
|
+
}
|
|
42085
42224
|
let debounce = null;
|
|
42086
42225
|
try {
|
|
42087
42226
|
doorbellWatcher = watch(DIRECT_CHAT_AGENT_DIR, (_event, filename) => {
|
|
@@ -42134,7 +42273,7 @@ function sweepAgedDirectChatMarkersNow(thresholdMs) {
|
|
|
42134
42273
|
const now = Date.now();
|
|
42135
42274
|
const res = sweepAgedDirectChatMarkers(DIRECT_CHAT_PENDING_INBOUND_DIR, {
|
|
42136
42275
|
readdir: (dir) => readdirSync6(dir),
|
|
42137
|
-
readFile: (p2) =>
|
|
42276
|
+
readFile: (p2) => readFileSync12(p2, "utf8"),
|
|
42138
42277
|
unlink: (p2) => {
|
|
42139
42278
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42140
42279
|
},
|
|
@@ -42183,8 +42322,8 @@ function sanitizeRecoveryText(text) {
|
|
|
42183
42322
|
}
|
|
42184
42323
|
function directChatRecoveryDeps() {
|
|
42185
42324
|
return {
|
|
42186
|
-
readFile: (p2) =>
|
|
42187
|
-
renameFile: (from, to) =>
|
|
42325
|
+
readFile: (p2) => readFileSync12(p2, "utf-8"),
|
|
42326
|
+
renameFile: (from, to) => renameSync6(from, to),
|
|
42188
42327
|
unlinkFile: (p2) => {
|
|
42189
42328
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42190
42329
|
},
|
|
@@ -42196,7 +42335,7 @@ function directChatRecoveryDeps() {
|
|
|
42196
42335
|
if (!DIRECT_CHAT_RECOVERY_LEDGER_DIR) return;
|
|
42197
42336
|
if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
|
|
42198
42337
|
try {
|
|
42199
|
-
const p2 =
|
|
42338
|
+
const p2 = join16(DIRECT_CHAT_RECOVERY_LEDGER_DIR, markerName);
|
|
42200
42339
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42201
42340
|
} catch {
|
|
42202
42341
|
}
|
|
@@ -42247,7 +42386,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
|
|
|
42247
42386
|
if (!enabled) return;
|
|
42248
42387
|
directChatRecoveryInFlight.add(filename);
|
|
42249
42388
|
try {
|
|
42250
|
-
const fullPath =
|
|
42389
|
+
const fullPath = join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, filename);
|
|
42251
42390
|
await consumeDirectChatRecoveryFile(fullPath, filename, directChatRecoveryDeps());
|
|
42252
42391
|
} catch (err) {
|
|
42253
42392
|
process.stderr.write(
|
|
@@ -42261,7 +42400,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
|
|
|
42261
42400
|
var directChatRecoveryWatcher = null;
|
|
42262
42401
|
if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
|
|
42263
42402
|
try {
|
|
42264
|
-
|
|
42403
|
+
mkdirSync6(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
|
|
42265
42404
|
} catch {
|
|
42266
42405
|
}
|
|
42267
42406
|
try {
|
|
@@ -42275,7 +42414,7 @@ if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
|
|
|
42275
42414
|
if (!filename) return;
|
|
42276
42415
|
const name = filename.toString();
|
|
42277
42416
|
if (!name.endsWith(".json")) return;
|
|
42278
|
-
if (existsSync6(
|
|
42417
|
+
if (existsSync6(join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, name))) {
|
|
42279
42418
|
void processDirectChatRecoveryOutboxFile(name);
|
|
42280
42419
|
}
|
|
42281
42420
|
});
|