@integrity-labs/agt-cli 0.28.1060 → 0.28.1062
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-HDPG36NY.js} +2 -2
- package/dist/{chunk-GOTLGDZJ.js → chunk-IE4Q3IZH.js} +4 -4
- package/dist/{chunk-JFLRDMGU.js → chunk-PN7B4DLS.js} +9 -3
- package/dist/chunk-PN7B4DLS.js.map +1 -0
- package/dist/{claude-pair-runtime-VUKAG635.js → claude-pair-runtime-6F6UDQKQ.js} +2 -2
- package/dist/lib/manager-worker.js +14 -14
- package/dist/mcp/direct-chat-channel.js +288 -143
- package/dist/mcp/index.js +8 -2
- package/dist/mcp/origami.js +19 -4
- package/dist/mcp/slack-channel.js +8 -2
- package/dist/mcp/telegram-channel.js +8 -2
- package/dist/{persistent-session-VBDEAOEO.js → persistent-session-Y36GGHCA.js} +3 -3
- package/dist/{responsiveness-probe-BN4VTJPH.js → responsiveness-probe-JDFWZC6W.js} +3 -3
- package/dist/{session-auth-dead-ONJMUXYK.js → session-auth-dead-BRMWKA3Y.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-JFLRDMGU.js.map +0 -1
- /package/dist/{chunk-ROZAO2DB.js.map → chunk-HDPG36NY.js.map} +0 -0
- /package/dist/{chunk-GOTLGDZJ.js.map → chunk-IE4Q3IZH.js.map} +0 -0
- /package/dist/{claude-pair-runtime-VUKAG635.js.map → claude-pair-runtime-6F6UDQKQ.js.map} +0 -0
- /package/dist/{persistent-session-VBDEAOEO.js.map → persistent-session-Y36GGHCA.js.map} +0 -0
- /package/dist/{responsiveness-probe-BN4VTJPH.js.map → responsiveness-probe-JDFWZC6W.js.map} +0 -0
- /package/dist/{session-auth-dead-ONJMUXYK.js.map → session-auth-dead-BRMWKA3Y.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,19 +29855,124 @@ 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
|
+
}
|
|
29861
29894
|
};
|
|
29862
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
|
+
}
|
|
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
|
+
}
|
|
29975
|
+
|
|
29863
29976
|
// ../core/dist/types/agent.js
|
|
29864
29977
|
var FRAMEWORK_MODEL_SLOTS = {
|
|
29865
29978
|
"claude-code": ["primary", "small_fast", "advisor"],
|
|
@@ -30604,8 +30717,8 @@ var integration_metadata_v1_default = {
|
|
|
30604
30717
|
},
|
|
30605
30718
|
auth_encoding: {
|
|
30606
30719
|
type: "string",
|
|
30607
|
-
enum: ["basic_username"],
|
|
30608
|
-
description: "How the credential is encoded into Authorization (ENG-10524). `basic_username` sends it as the HTTP Basic username with an empty password (`Authorization: Basic base64(<credential>:)`), Sportsyear's API-key form. Omit for `<auth_scheme> <credential>`. Must not be combined with `auth_scheme`."
|
|
30720
|
+
enum: ["basic_username", "raw"],
|
|
30721
|
+
description: "How the credential is encoded into Authorization (ENG-10524). `basic_username` sends it as the HTTP Basic username with an empty password (`Authorization: Basic base64(<credential>:)`), Sportsyear's API-key form. `raw` sends the credential itself as the header value with no scheme word (`Authorization: <credential>`), AppsFlyer OneLink's form (CS-1918). Omit for `<auth_scheme> <credential>`. Must not be combined with `auth_scheme`."
|
|
30609
30722
|
},
|
|
30610
30723
|
runtime_scopes: {
|
|
30611
30724
|
type: "object",
|
|
@@ -30641,6 +30754,12 @@ var integration_metadata_v1_default = {
|
|
|
30641
30754
|
host_suffix: { type: "string", pattern: "^[a-z0-9.-]+\\.[a-z]{2,}$" }
|
|
30642
30755
|
}
|
|
30643
30756
|
},
|
|
30757
|
+
config_arg_defaults: {
|
|
30758
|
+
type: "object",
|
|
30759
|
+
description: "Tool arguments that default from the install's config (CS-1918), as { <tool arg>: <config key> }. An argument the caller passes wins; an absent one is filled from config[<config key>] (non-empty string, trimmed, case preserved) and the result is re-validated against the tool's input_schema. For per-account values such as AppsFlyer's OneLink template ID, entered once on the install form instead of carried by the agent. Applied at build time by fillArgsFromConfig in both broker lanes.",
|
|
30760
|
+
propertyNames: { pattern: "^[a-zA-Z_][a-zA-Z0-9_]*$" },
|
|
30761
|
+
additionalProperties: { type: "string", pattern: "^[a-zA-Z_][a-zA-Z0-9_]*$" }
|
|
30762
|
+
},
|
|
30644
30763
|
redirect_means_auth_failure: {
|
|
30645
30764
|
type: "boolean",
|
|
30646
30765
|
description: "The vendor answers a rejected credential with a REDIRECT (Storrito: a 302 to its login page) rather than a 401. A redirected non-GET call is never followed (vendor-fetch.ts) and always fails; with this set, it is also treated like a 401 and the install is flagged for re-auth."
|
|
@@ -38976,20 +39095,22 @@ function renderHistoryResult(result, requestedNotices) {
|
|
|
38976
39095
|
}
|
|
38977
39096
|
|
|
38978
39097
|
// src/direct-chat-session-state.ts
|
|
38979
|
-
import { existsSync, readFileSync } from "fs";
|
|
38980
|
-
import { join } from "path";
|
|
39098
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
39099
|
+
import { join as join2 } from "path";
|
|
38981
39100
|
function readDirectChatSessionState(agentDir, nowMs) {
|
|
38982
|
-
const path =
|
|
39101
|
+
const path = join2(agentDir, "direct-chat-session.json");
|
|
39102
|
+
const fallback = { fresh: false, startedAtMs: nowMs, markerRead: false, sessionId: null };
|
|
38983
39103
|
try {
|
|
38984
|
-
if (!existsSync(path)) return
|
|
38985
|
-
const parsed = JSON.parse(
|
|
38986
|
-
if (!parsed || typeof parsed !== "object") return
|
|
39104
|
+
if (!existsSync(path)) return fallback;
|
|
39105
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
39106
|
+
if (!parsed || typeof parsed !== "object") return fallback;
|
|
38987
39107
|
const o = parsed;
|
|
38988
39108
|
const fresh = o.fresh === true;
|
|
38989
39109
|
const startedAtMs = typeof o.startedAtMs === "number" && Number.isFinite(o.startedAtMs) ? o.startedAtMs : nowMs;
|
|
38990
|
-
|
|
39110
|
+
const sessionId = typeof o.sessionId === "string" && o.sessionId.length > 0 ? o.sessionId : null;
|
|
39111
|
+
return { fresh, startedAtMs, markerRead: true, sessionId };
|
|
38991
39112
|
} catch {
|
|
38992
|
-
return
|
|
39113
|
+
return fallback;
|
|
38993
39114
|
}
|
|
38994
39115
|
}
|
|
38995
39116
|
|
|
@@ -39026,13 +39147,13 @@ function buildDirectChatChannelMeta(input) {
|
|
|
39026
39147
|
}
|
|
39027
39148
|
|
|
39028
39149
|
// src/turn-initiator-marker.ts
|
|
39029
|
-
import { writeFileSync, readFileSync as
|
|
39030
|
-
import { dirname, join as
|
|
39150
|
+
import { writeFileSync as writeFileSync2, readFileSync as readFileSync3, mkdirSync as mkdirSync2, renameSync as renameSync2 } from "fs";
|
|
39151
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
39031
39152
|
var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
39032
39153
|
var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
|
|
39033
39154
|
var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
|
|
39034
39155
|
function turnInitiatorLedgerPath(singleSlotFile) {
|
|
39035
|
-
return
|
|
39156
|
+
return join3(dirname2(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
|
|
39036
39157
|
}
|
|
39037
39158
|
function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
|
|
39038
39159
|
const now = marker.ts;
|
|
@@ -39057,24 +39178,24 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
|
|
|
39057
39178
|
const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
|
|
39058
39179
|
let existing = null;
|
|
39059
39180
|
try {
|
|
39060
|
-
const parsed = JSON.parse(
|
|
39181
|
+
const parsed = JSON.parse(readFileSync3(ledgerFile, "utf8"));
|
|
39061
39182
|
if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
|
|
39062
39183
|
} catch {
|
|
39063
39184
|
}
|
|
39064
39185
|
const next = foldTurnInitiatorLedger(existing, marker);
|
|
39065
39186
|
const tmp = `${ledgerFile}.tmp`;
|
|
39066
|
-
|
|
39067
|
-
|
|
39187
|
+
writeFileSync2(tmp, JSON.stringify(next), "utf8");
|
|
39188
|
+
renameSync2(tmp, ledgerFile);
|
|
39068
39189
|
}
|
|
39069
39190
|
function writeTurnInitiatorMarker(input) {
|
|
39070
39191
|
const file = process.env["AGT_TURN_INITIATOR_FILE"];
|
|
39071
39192
|
if (!file || !input.sender_id) return;
|
|
39072
39193
|
try {
|
|
39073
|
-
|
|
39194
|
+
mkdirSync2(dirname2(file), { recursive: true });
|
|
39074
39195
|
const marker = { ...input, ts: Date.now() };
|
|
39075
39196
|
const tmp = `${file}.tmp`;
|
|
39076
|
-
|
|
39077
|
-
|
|
39197
|
+
writeFileSync2(tmp, JSON.stringify(marker), "utf8");
|
|
39198
|
+
renameSync2(tmp, file);
|
|
39078
39199
|
try {
|
|
39079
39200
|
updateTurnInitiatorLedger(file, marker);
|
|
39080
39201
|
} catch {
|
|
@@ -39084,14 +39205,14 @@ function writeTurnInitiatorMarker(input) {
|
|
|
39084
39205
|
}
|
|
39085
39206
|
|
|
39086
39207
|
// src/scheduled-turn-marker.ts
|
|
39087
|
-
import { readFileSync as
|
|
39088
|
-
import { join as
|
|
39208
|
+
import { readFileSync as readFileSync4, unlinkSync } from "fs";
|
|
39209
|
+
import { join as join4 } from "path";
|
|
39089
39210
|
var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
|
|
39090
39211
|
var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
|
|
39091
39212
|
function clearScheduledTurnMarker(agentDir) {
|
|
39092
39213
|
if (!agentDir) return;
|
|
39093
39214
|
try {
|
|
39094
|
-
unlinkSync(
|
|
39215
|
+
unlinkSync(join4(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
|
|
39095
39216
|
} catch {
|
|
39096
39217
|
}
|
|
39097
39218
|
}
|
|
@@ -39099,14 +39220,14 @@ function clearScheduledTurnMarker(agentDir) {
|
|
|
39099
39220
|
// src/direct-chat-pending-inbound.ts
|
|
39100
39221
|
import {
|
|
39101
39222
|
existsSync as existsSync2,
|
|
39102
|
-
mkdirSync as
|
|
39223
|
+
mkdirSync as mkdirSync3,
|
|
39103
39224
|
readdirSync,
|
|
39104
|
-
readFileSync as
|
|
39105
|
-
renameSync as
|
|
39225
|
+
readFileSync as readFileSync5,
|
|
39226
|
+
renameSync as renameSync3,
|
|
39106
39227
|
unlinkSync as unlinkSync2,
|
|
39107
|
-
writeFileSync as
|
|
39228
|
+
writeFileSync as writeFileSync3
|
|
39108
39229
|
} from "fs";
|
|
39109
|
-
import { join as
|
|
39230
|
+
import { join as join5 } from "path";
|
|
39110
39231
|
function hexEncodeSegment(value) {
|
|
39111
39232
|
return Buffer.from(value, "utf8").toString("hex");
|
|
39112
39233
|
}
|
|
@@ -39125,7 +39246,7 @@ function directChatInboundId(sessionId, messageId) {
|
|
|
39125
39246
|
function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
|
|
39126
39247
|
if (!dir || !sessionId || !messageId) return;
|
|
39127
39248
|
try {
|
|
39128
|
-
|
|
39249
|
+
mkdirSync3(dir, { recursive: true });
|
|
39129
39250
|
const marker = {
|
|
39130
39251
|
channel: "direct-chat",
|
|
39131
39252
|
session_id: sessionId,
|
|
@@ -39133,10 +39254,10 @@ function writeDirectChatPendingInboundMarker(dir, sessionId, messageId) {
|
|
|
39133
39254
|
received_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
39134
39255
|
inbound_id: directChatInboundId(sessionId, messageId)
|
|
39135
39256
|
};
|
|
39136
|
-
const final =
|
|
39257
|
+
const final = join5(dir, directChatMarkerName(sessionId, messageId));
|
|
39137
39258
|
const tmp = `${final}.tmp`;
|
|
39138
|
-
|
|
39139
|
-
|
|
39259
|
+
writeFileSync3(tmp, JSON.stringify(marker), "utf8");
|
|
39260
|
+
renameSync3(tmp, final);
|
|
39140
39261
|
} catch {
|
|
39141
39262
|
}
|
|
39142
39263
|
}
|
|
@@ -39152,15 +39273,15 @@ function clearDirectChatPendingMarkersForSession(dir, sessionId, op = defaultCle
|
|
|
39152
39273
|
}
|
|
39153
39274
|
for (const name of names) {
|
|
39154
39275
|
if (!name.startsWith(prefix) || !name.endsWith(".json")) continue;
|
|
39155
|
-
op(
|
|
39276
|
+
op(join5(dir, name));
|
|
39156
39277
|
cleared += 1;
|
|
39157
39278
|
}
|
|
39158
39279
|
return cleared;
|
|
39159
39280
|
}
|
|
39160
|
-
function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) =>
|
|
39281
|
+
function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) => readFileSync5(path, "utf8")) {
|
|
39161
39282
|
if (!dir || !sessionId || !messageId) return null;
|
|
39162
39283
|
try {
|
|
39163
|
-
const raw = readFileImpl(
|
|
39284
|
+
const raw = readFileImpl(join5(dir, directChatMarkerName(sessionId, messageId)));
|
|
39164
39285
|
return JSON.parse(raw);
|
|
39165
39286
|
} catch {
|
|
39166
39287
|
return null;
|
|
@@ -39183,7 +39304,7 @@ function sweepAgedDirectChatMarkers(dir, deps) {
|
|
|
39183
39304
|
}
|
|
39184
39305
|
for (const name of names) {
|
|
39185
39306
|
if (!name.endsWith(".json") || name.startsWith(".")) continue;
|
|
39186
|
-
const full =
|
|
39307
|
+
const full = join5(dir, name);
|
|
39187
39308
|
let marker;
|
|
39188
39309
|
try {
|
|
39189
39310
|
marker = JSON.parse(deps.readFile(full));
|
|
@@ -39282,17 +39403,17 @@ async function consumeDirectChatRecoveryFile(fullPath, filename, deps) {
|
|
|
39282
39403
|
}
|
|
39283
39404
|
|
|
39284
39405
|
// src/inbound-delivery-ledger.ts
|
|
39285
|
-
import { existsSync as existsSync3, mkdirSync as
|
|
39286
|
-
import { join as
|
|
39406
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync6, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
39407
|
+
import { join as join6 } from "path";
|
|
39287
39408
|
function safeInboundId(inboundId) {
|
|
39288
39409
|
return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
39289
39410
|
}
|
|
39290
39411
|
var defaultDeps = {
|
|
39291
|
-
mkdir: (dir) =>
|
|
39292
|
-
writeFile: (path, data) =>
|
|
39293
|
-
rename: (from, to) =>
|
|
39412
|
+
mkdir: (dir) => mkdirSync4(dir, { recursive: true }),
|
|
39413
|
+
writeFile: (path, data) => writeFileSync4(path, data, "utf8"),
|
|
39414
|
+
rename: (from, to) => renameSync4(from, to),
|
|
39294
39415
|
readdir: (dir) => readdirSync2(dir),
|
|
39295
|
-
readFile: (path) =>
|
|
39416
|
+
readFile: (path) => readFileSync6(path, "utf8"),
|
|
39296
39417
|
exists: (path) => existsSync3(path)
|
|
39297
39418
|
};
|
|
39298
39419
|
function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
|
|
@@ -39301,7 +39422,7 @@ function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
|
|
|
39301
39422
|
if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return;
|
|
39302
39423
|
try {
|
|
39303
39424
|
deps.mkdir(dir);
|
|
39304
|
-
const final =
|
|
39425
|
+
const final = join6(dir, `${safe}.json`);
|
|
39305
39426
|
const tmp = `${final}.tmp`;
|
|
39306
39427
|
deps.writeFile(tmp, JSON.stringify(record2));
|
|
39307
39428
|
deps.rename(tmp, final);
|
|
@@ -39313,22 +39434,22 @@ function inboundDeliveryLedgerHas(dir, inboundId, deps = defaultDeps) {
|
|
|
39313
39434
|
const safe = safeInboundId(inboundId);
|
|
39314
39435
|
if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return false;
|
|
39315
39436
|
try {
|
|
39316
|
-
return deps.exists(
|
|
39437
|
+
return deps.exists(join6(dir, `${safe}.json`));
|
|
39317
39438
|
} catch {
|
|
39318
39439
|
return false;
|
|
39319
39440
|
}
|
|
39320
39441
|
}
|
|
39321
39442
|
|
|
39322
39443
|
// src/ack-reaction.ts
|
|
39323
|
-
import { readdirSync as readdirSync3, readFileSync as
|
|
39324
|
-
import { join as
|
|
39444
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "fs";
|
|
39445
|
+
import { join as join8 } from "path";
|
|
39325
39446
|
|
|
39326
39447
|
// src/flags-cache-read.ts
|
|
39327
|
-
import { existsSync as existsSync4, readFileSync as
|
|
39448
|
+
import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
39328
39449
|
import { homedir } from "os";
|
|
39329
|
-
import { join as
|
|
39450
|
+
import { join as join7 } from "path";
|
|
39330
39451
|
function defaultFlagsCachePath() {
|
|
39331
|
-
return
|
|
39452
|
+
return join7(homedir(), ".augmented", "flags-cache.json");
|
|
39332
39453
|
}
|
|
39333
39454
|
function envBoolean(raw) {
|
|
39334
39455
|
if (raw === void 0) return void 0;
|
|
@@ -39341,7 +39462,7 @@ function envBoolean(raw) {
|
|
|
39341
39462
|
function cachedBoolean(key, path) {
|
|
39342
39463
|
try {
|
|
39343
39464
|
if (!existsSync4(path)) return void 0;
|
|
39344
|
-
const parsed = JSON.parse(
|
|
39465
|
+
const parsed = JSON.parse(readFileSync7(path, "utf8"));
|
|
39345
39466
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
39346
39467
|
const flags = parsed.flags;
|
|
39347
39468
|
if (!flags || typeof flags !== "object") return void 0;
|
|
@@ -39422,7 +39543,7 @@ function undeliverableNoticeTextForRepeat(i) {
|
|
|
39422
39543
|
}
|
|
39423
39544
|
return null;
|
|
39424
39545
|
}
|
|
39425
|
-
function channelInboundGateOpen(readFile = (p2) =>
|
|
39546
|
+
function channelInboundGateOpen(readFile = (p2) => readFileSync8(p2, "utf-8")) {
|
|
39426
39547
|
const path = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : "/etc/claude-code/managed-settings.json";
|
|
39427
39548
|
let raw;
|
|
39428
39549
|
try {
|
|
@@ -39487,7 +39608,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
|
39487
39608
|
function readGiveUpSignal(path, now = Date.now()) {
|
|
39488
39609
|
if (!path) return null;
|
|
39489
39610
|
try {
|
|
39490
|
-
const raw = JSON.parse(
|
|
39611
|
+
const raw = JSON.parse(readFileSync8(path, "utf8"));
|
|
39491
39612
|
if (typeof raw.gave_up_at !== "string") return null;
|
|
39492
39613
|
const t = Date.parse(raw.gave_up_at);
|
|
39493
39614
|
if (!Number.isFinite(t) || t > now) return null;
|
|
@@ -39501,12 +39622,12 @@ function readGiveUpSignal(path, now = Date.now()) {
|
|
|
39501
39622
|
var USAGE_LIMIT_LIVE_WINDOW_MS = 3 * 6e4;
|
|
39502
39623
|
function readUsageLimitForBusyAck(agentDir, now = Date.now()) {
|
|
39503
39624
|
if (!agentDir) return null;
|
|
39504
|
-
const path =
|
|
39625
|
+
const path = join8(agentDir, GIVE_UP_SIGNAL_FILENAME);
|
|
39505
39626
|
const sig = readGiveUpSignal(path, now);
|
|
39506
39627
|
if (sig?.reason !== "usage_limit") return null;
|
|
39507
39628
|
let lastSeenMs = null;
|
|
39508
39629
|
try {
|
|
39509
|
-
const raw = JSON.parse(
|
|
39630
|
+
const raw = JSON.parse(readFileSync8(path, "utf8"));
|
|
39510
39631
|
if (typeof raw.usage_limit_last_seen_at === "string") {
|
|
39511
39632
|
const t = Date.parse(raw.usage_limit_last_seen_at);
|
|
39512
39633
|
if (Number.isFinite(t) && t <= now) lastSeenMs = t;
|
|
@@ -39525,7 +39646,7 @@ function readBlockedPromptForBusyAck(agentDir, now = Date.now()) {
|
|
|
39525
39646
|
if (!agentDir) return null;
|
|
39526
39647
|
let raw;
|
|
39527
39648
|
try {
|
|
39528
|
-
raw = JSON.parse(
|
|
39649
|
+
raw = JSON.parse(readFileSync8(join8(agentDir, BLOCKED_PROMPT_SIGNAL_FILENAME), "utf8"));
|
|
39529
39650
|
} catch {
|
|
39530
39651
|
return null;
|
|
39531
39652
|
}
|
|
@@ -39578,7 +39699,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
|
|
|
39578
39699
|
if (!name.endsWith(".json")) continue;
|
|
39579
39700
|
let receivedAt;
|
|
39580
39701
|
try {
|
|
39581
|
-
const raw = JSON.parse(
|
|
39702
|
+
const raw = JSON.parse(readFileSync8(join8(dir, name), "utf-8"));
|
|
39582
39703
|
if (raw.discretionary === true) continue;
|
|
39583
39704
|
if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
|
|
39584
39705
|
receivedAt = raw.received_at;
|
|
@@ -39632,32 +39753,32 @@ function isMarkerGenuinelyAged(receivedAt, nowMs, thresholdMs) {
|
|
|
39632
39753
|
}
|
|
39633
39754
|
var DEFLECTION_COUNTER_SUFFIX = "-deflections.json";
|
|
39634
39755
|
function deflectionCounterPath(agentDir, channel) {
|
|
39635
|
-
return
|
|
39756
|
+
return join8(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
|
|
39636
39757
|
}
|
|
39637
39758
|
function recordChannelDeflection(agentDir, channel, cause) {
|
|
39638
39759
|
if (!agentDir) return;
|
|
39639
39760
|
const path = deflectionCounterPath(agentDir, channel);
|
|
39640
39761
|
let counts = {};
|
|
39641
39762
|
try {
|
|
39642
|
-
const parsed = JSON.parse(
|
|
39763
|
+
const parsed = JSON.parse(readFileSync8(path, "utf-8"));
|
|
39643
39764
|
if (parsed && typeof parsed === "object") counts = parsed;
|
|
39644
39765
|
} catch {
|
|
39645
39766
|
}
|
|
39646
39767
|
counts[cause] = (counts[cause] ?? 0) + 1;
|
|
39647
39768
|
try {
|
|
39648
|
-
|
|
39769
|
+
writeFileSync5(path, JSON.stringify(counts), { mode: 384 });
|
|
39649
39770
|
} catch {
|
|
39650
39771
|
}
|
|
39651
39772
|
}
|
|
39652
39773
|
|
|
39653
39774
|
// src/turn-failure-watch.ts
|
|
39654
39775
|
import { readdirSync as readdirSync5, statSync as statSync2 } from "fs";
|
|
39655
|
-
import { join as
|
|
39776
|
+
import { join as join10 } from "path";
|
|
39656
39777
|
|
|
39657
39778
|
// src/rate-limit-watch.ts
|
|
39658
39779
|
import { closeSync, fstatSync, openSync, readSync, readdirSync as readdirSync4, statSync } from "fs";
|
|
39659
39780
|
import { homedir as homedir2 } from "os";
|
|
39660
|
-
import { join as
|
|
39781
|
+
import { join as join9 } from "path";
|
|
39661
39782
|
var DEFAULT_WATCH_MS = 5e3;
|
|
39662
39783
|
var DEFAULT_POLL_MS = 400;
|
|
39663
39784
|
var INITIAL_TAIL_BYTES = 256 * 1024;
|
|
@@ -39729,7 +39850,7 @@ function oldestTimestampMs(text) {
|
|
|
39729
39850
|
function agentTranscriptDir(opts) {
|
|
39730
39851
|
const cwd = opts?.cwd ?? process.cwd();
|
|
39731
39852
|
const home = opts?.home ?? homedir2();
|
|
39732
|
-
return
|
|
39853
|
+
return join9(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
|
|
39733
39854
|
}
|
|
39734
39855
|
function classifyTranscriptSince(opts) {
|
|
39735
39856
|
const dir = opts.transcriptDir ?? agentTranscriptDir({ cwd: opts.cwd, home: opts.home });
|
|
@@ -39742,7 +39863,7 @@ function classifyTranscriptSince(opts) {
|
|
|
39742
39863
|
let newest = UNKNOWN_RATE_LIMIT;
|
|
39743
39864
|
for (const name of entries) {
|
|
39744
39865
|
if (!name.endsWith(".jsonl")) continue;
|
|
39745
|
-
const path =
|
|
39866
|
+
const path = join9(dir, name);
|
|
39746
39867
|
try {
|
|
39747
39868
|
const st = statSync(path);
|
|
39748
39869
|
if (!st.isFile() || st.mtimeMs < opts.sinceMs) continue;
|
|
@@ -39817,7 +39938,7 @@ function classifyTurnFailureSince(opts) {
|
|
|
39817
39938
|
const unrecognised = /* @__PURE__ */ new Set();
|
|
39818
39939
|
for (const name of entries) {
|
|
39819
39940
|
if (!name.endsWith(".jsonl")) continue;
|
|
39820
|
-
const path =
|
|
39941
|
+
const path = join10(dir, name);
|
|
39821
39942
|
let fingerprint;
|
|
39822
39943
|
try {
|
|
39823
39944
|
const st = statSync2(path);
|
|
@@ -40004,15 +40125,15 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
|
|
|
40004
40125
|
// src/mcp-spawn-lock.ts
|
|
40005
40126
|
import {
|
|
40006
40127
|
existsSync as existsSync5,
|
|
40007
|
-
mkdirSync as
|
|
40008
|
-
readFileSync as
|
|
40009
|
-
renameSync as
|
|
40128
|
+
mkdirSync as mkdirSync5,
|
|
40129
|
+
readFileSync as readFileSync9,
|
|
40130
|
+
renameSync as renameSync5,
|
|
40010
40131
|
statSync as statSync3,
|
|
40011
40132
|
unlinkSync as unlinkSync3,
|
|
40012
40133
|
utimesSync,
|
|
40013
|
-
writeFileSync as
|
|
40134
|
+
writeFileSync as writeFileSync6
|
|
40014
40135
|
} from "fs";
|
|
40015
|
-
import { join as
|
|
40136
|
+
import { join as join11 } from "path";
|
|
40016
40137
|
var STALE_LOCK_MS = 9e4;
|
|
40017
40138
|
var HEARTBEAT_INTERVAL_MS = 3e4;
|
|
40018
40139
|
function defaultIsPidAlive(pid) {
|
|
@@ -40035,7 +40156,7 @@ function acquireMcpSpawnLock(args) {
|
|
|
40035
40156
|
const nowMs = options.nowMs ?? (() => Date.now());
|
|
40036
40157
|
const lockMtimeMs = options.lockMtimeMs ?? defaultLockMtimeMs;
|
|
40037
40158
|
const staleMs = options.staleMs ?? STALE_LOCK_MS;
|
|
40038
|
-
const path =
|
|
40159
|
+
const path = join11(agentDir, basename);
|
|
40039
40160
|
const existing = readLockHolder(path);
|
|
40040
40161
|
if (existing) {
|
|
40041
40162
|
if (existing.pid === selfPid) {
|
|
@@ -40049,11 +40170,11 @@ function acquireMcpSpawnLock(args) {
|
|
|
40049
40170
|
}
|
|
40050
40171
|
}
|
|
40051
40172
|
}
|
|
40052
|
-
|
|
40173
|
+
mkdirSync5(agentDir, { recursive: true, mode: 448 });
|
|
40053
40174
|
const tmpPath = `${path}.${selfPid}.tmp`;
|
|
40054
40175
|
const payload = { pid: selfPid, started_at: now() };
|
|
40055
|
-
|
|
40056
|
-
|
|
40176
|
+
writeFileSync6(tmpPath, JSON.stringify(payload), { mode: 384 });
|
|
40177
|
+
renameSync5(tmpPath, path);
|
|
40057
40178
|
return { kind: "acquired", path };
|
|
40058
40179
|
}
|
|
40059
40180
|
function releaseMcpSpawnLock(lockPath, opts = {}) {
|
|
@@ -40102,7 +40223,7 @@ function defaultLockMtimeMs(path) {
|
|
|
40102
40223
|
function readLockHolder(path) {
|
|
40103
40224
|
if (!existsSync5(path)) return null;
|
|
40104
40225
|
try {
|
|
40105
|
-
const raw =
|
|
40226
|
+
const raw = readFileSync9(path, "utf8");
|
|
40106
40227
|
const parsed = JSON.parse(raw);
|
|
40107
40228
|
const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
|
|
40108
40229
|
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
@@ -40115,26 +40236,26 @@ function readLockHolder(path) {
|
|
|
40115
40236
|
|
|
40116
40237
|
// src/direct-chat-channel.ts
|
|
40117
40238
|
import { homedir as homedir4 } from "os";
|
|
40118
|
-
import { join as
|
|
40239
|
+
import { join as join16 } from "path";
|
|
40119
40240
|
import { randomUUID } from "crypto";
|
|
40120
40241
|
import {
|
|
40121
40242
|
watch,
|
|
40122
|
-
mkdirSync as
|
|
40123
|
-
writeFileSync as
|
|
40124
|
-
readFileSync as
|
|
40243
|
+
mkdirSync as mkdirSync6,
|
|
40244
|
+
writeFileSync as writeFileSync8,
|
|
40245
|
+
readFileSync as readFileSync12,
|
|
40125
40246
|
readdirSync as readdirSync6,
|
|
40126
40247
|
existsSync as existsSync6,
|
|
40127
|
-
renameSync as
|
|
40248
|
+
renameSync as renameSync6,
|
|
40128
40249
|
unlinkSync as unlinkSync4,
|
|
40129
40250
|
statSync as statSync4,
|
|
40130
40251
|
createWriteStream
|
|
40131
40252
|
} from "fs";
|
|
40132
40253
|
|
|
40133
40254
|
// src/direct-chat-inbound-attachments.ts
|
|
40134
|
-
import { join as
|
|
40255
|
+
import { join as join13 } from "path";
|
|
40135
40256
|
|
|
40136
40257
|
// ../core/dist/provisioning/frameworks/claudecode/agent-dir-alias.js
|
|
40137
|
-
import { isAbsolute, join as
|
|
40258
|
+
import { isAbsolute, join as join12, relative, sep } from "path";
|
|
40138
40259
|
var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
40139
40260
|
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
40261
|
var INITIATOR_BASENAME = ".current-turn-initiator.json";
|
|
@@ -40142,7 +40263,7 @@ function isSafeAgentSegment(segment) {
|
|
|
40142
40263
|
return VALID_CODE_NAME.test(segment) || VALID_AGENT_ID.test(segment);
|
|
40143
40264
|
}
|
|
40144
40265
|
function initiatorDirSegment(initiatorFile, homeDir) {
|
|
40145
|
-
const rel = relative(
|
|
40266
|
+
const rel = relative(join12(homeDir, ".augmented"), initiatorFile);
|
|
40146
40267
|
if (!rel || isAbsolute(rel))
|
|
40147
40268
|
return null;
|
|
40148
40269
|
const parts = rel.split(sep);
|
|
@@ -40157,17 +40278,17 @@ function resolveAgentDirAlias(input) {
|
|
|
40157
40278
|
const { codeName, turnInitiatorFile, agentId, homeDir } = input;
|
|
40158
40279
|
const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
|
|
40159
40280
|
if (codeNameTrimmed && VALID_CODE_NAME.test(codeNameTrimmed)) {
|
|
40160
|
-
return
|
|
40281
|
+
return join12(homeDir, ".augmented", codeNameTrimmed);
|
|
40161
40282
|
}
|
|
40162
40283
|
const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
|
|
40163
40284
|
if (initiator) {
|
|
40164
40285
|
const segment = initiatorDirSegment(initiator, homeDir);
|
|
40165
40286
|
if (segment)
|
|
40166
|
-
return
|
|
40287
|
+
return join12(homeDir, ".augmented", segment);
|
|
40167
40288
|
}
|
|
40168
40289
|
const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
|
|
40169
40290
|
if (agentIdTrimmed && VALID_AGENT_ID.test(agentIdTrimmed)) {
|
|
40170
|
-
return
|
|
40291
|
+
return join12(homeDir, ".augmented", agentIdTrimmed);
|
|
40171
40292
|
}
|
|
40172
40293
|
return null;
|
|
40173
40294
|
}
|
|
@@ -40177,7 +40298,7 @@ var MAX_INBOUND_ATTACHMENT_BYTES = 10 * 1024 * 1024;
|
|
|
40177
40298
|
var INBOUND_ATTACHMENTS_SUBDIR = "direct-chat-inbound";
|
|
40178
40299
|
function resolveInboundAttachmentsDir(input) {
|
|
40179
40300
|
const alias = resolveAgentDirAlias(input);
|
|
40180
|
-
return alias === null ? null :
|
|
40301
|
+
return alias === null ? null : join13(alias, INBOUND_ATTACHMENTS_SUBDIR);
|
|
40181
40302
|
}
|
|
40182
40303
|
function isImageContentType(contentType) {
|
|
40183
40304
|
return typeof contentType === "string" && contentType.toLowerCase().startsWith("image/");
|
|
@@ -40660,19 +40781,19 @@ function isMaintenanceModeActive(opts) {
|
|
|
40660
40781
|
}
|
|
40661
40782
|
|
|
40662
40783
|
// src/account-enforcement-notice.ts
|
|
40663
|
-
import { readFileSync as
|
|
40784
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
40664
40785
|
import { homedir as homedir3 } from "os";
|
|
40665
|
-
import { join as
|
|
40786
|
+
import { join as join14 } from "path";
|
|
40666
40787
|
function accountEnforcementMarkerPath(codeName) {
|
|
40667
40788
|
if (!codeName) return null;
|
|
40668
|
-
return
|
|
40789
|
+
return join14(homedir3(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
|
|
40669
40790
|
}
|
|
40670
40791
|
function readAccountEnforcementMarker(opts) {
|
|
40671
40792
|
const path = opts.filePath ?? accountEnforcementMarkerPath(opts.codeName);
|
|
40672
40793
|
if (!path) return null;
|
|
40673
40794
|
let raw;
|
|
40674
40795
|
try {
|
|
40675
|
-
raw =
|
|
40796
|
+
raw = readFileSync10(path, "utf-8");
|
|
40676
40797
|
} catch {
|
|
40677
40798
|
return null;
|
|
40678
40799
|
}
|
|
@@ -40698,8 +40819,8 @@ function shouldSendAccountWarn(opts) {
|
|
|
40698
40819
|
}
|
|
40699
40820
|
|
|
40700
40821
|
// ../core/dist/direct-chat/cursor-advance-telemetry.js
|
|
40701
|
-
import { readFileSync as
|
|
40702
|
-
import { join as
|
|
40822
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "fs";
|
|
40823
|
+
import { join as join15 } from "path";
|
|
40703
40824
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
40704
40825
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
40705
40826
|
if (!agentDir)
|
|
@@ -40707,10 +40828,10 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
40707
40828
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
40708
40829
|
if (key === null)
|
|
40709
40830
|
return;
|
|
40710
|
-
const path =
|
|
40831
|
+
const path = join15(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
40711
40832
|
const counts = {};
|
|
40712
40833
|
try {
|
|
40713
|
-
const parsed = JSON.parse(
|
|
40834
|
+
const parsed = JSON.parse(readFileSync11(path, "utf-8"));
|
|
40714
40835
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
40715
40836
|
for (const [k, v] of Object.entries(parsed)) {
|
|
40716
40837
|
if (typeof v === "number" && Number.isInteger(v) && v >= 0)
|
|
@@ -40721,7 +40842,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
40721
40842
|
}
|
|
40722
40843
|
counts[key] = (counts[key] ?? 0) + 1;
|
|
40723
40844
|
try {
|
|
40724
|
-
|
|
40845
|
+
writeFileSync7(path, JSON.stringify(counts), { mode: 384 });
|
|
40725
40846
|
} catch {
|
|
40726
40847
|
}
|
|
40727
40848
|
}
|
|
@@ -40843,7 +40964,7 @@ var DIRECT_CHAT_ACCOUNT_WARN_COOLDOWN_MS = (() => {
|
|
|
40843
40964
|
var AGT_HOST = process.env.AGT_HOST;
|
|
40844
40965
|
var AGT_API_KEY = process.env.AGT_API_KEY;
|
|
40845
40966
|
var AGT_AGENT_ID = process.env.AGT_AGENT_ID;
|
|
40846
|
-
var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ?
|
|
40967
|
+
var DIRECT_CHAT_AGENT_DIR = AGT_AGENT_ID ? join16(homedir4(), ".augmented", AGT_AGENT_ID) : null;
|
|
40847
40968
|
var INBOUND_ATTACHMENTS_DIR = resolveInboundAttachmentsDir({
|
|
40848
40969
|
codeName: process.env.AGT_AGENT_CODE_NAME,
|
|
40849
40970
|
turnInitiatorFile: process.env.AGT_TURN_INITIATOR_FILE,
|
|
@@ -40854,10 +40975,10 @@ var AGT_AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME;
|
|
|
40854
40975
|
var directChatStderrLogStream = null;
|
|
40855
40976
|
if (AGT_AGENT_CODE_NAME) {
|
|
40856
40977
|
try {
|
|
40857
|
-
const logDir =
|
|
40858
|
-
|
|
40978
|
+
const logDir = join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME);
|
|
40979
|
+
mkdirSync6(logDir, { recursive: true });
|
|
40859
40980
|
directChatStderrLogStream = createWriteStream(
|
|
40860
|
-
|
|
40981
|
+
join16(logDir, "direct-chat-channel-stderr.log"),
|
|
40861
40982
|
{ flags: "a", mode: 384 }
|
|
40862
40983
|
);
|
|
40863
40984
|
directChatStderrLogStream.on("error", () => {
|
|
@@ -40876,10 +40997,10 @@ if (AGT_AGENT_CODE_NAME) {
|
|
|
40876
40997
|
} catch {
|
|
40877
40998
|
}
|
|
40878
40999
|
}
|
|
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 ?
|
|
41000
|
+
var PROGRESS_HEARTBEAT_PATH = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "channel-progress-heartbeat.json") : null;
|
|
41001
|
+
var DIRECT_CHAT_PENDING_INBOUND_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-pending-inbound") : null;
|
|
41002
|
+
var DIRECT_CHAT_DELIVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-inbound-delivery-ledger") : null;
|
|
41003
|
+
var DIRECT_CHAT_CODE_NAME_AGENT_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME) : null;
|
|
40883
41004
|
var DIRECT_CHAT_STALE_MARKER_MS = 24 * 60 * 60 * 1e3;
|
|
40884
41005
|
function judgeCursorAdvance(input, ctx) {
|
|
40885
41006
|
const verdict = classifyCursorAdvance(input);
|
|
@@ -40899,8 +41020,8 @@ function recordDirectChatDelivery(sessionId, messageIds) {
|
|
|
40899
41020
|
delivered_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40900
41021
|
});
|
|
40901
41022
|
}
|
|
40902
|
-
var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ?
|
|
40903
|
-
var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ?
|
|
41023
|
+
var DIRECT_CHAT_RECOVERY_OUTBOX_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, "direct-chat-recovery-outbox") : null;
|
|
41024
|
+
var DIRECT_CHAT_RECOVERY_LEDGER_DIR = AGT_AGENT_CODE_NAME ? join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME, ".agt-direct-chat-recovery-ledger") : null;
|
|
40904
41025
|
var progressReceivedAt = /* @__PURE__ */ new Map();
|
|
40905
41026
|
var directChatProgressState = { tracked: null };
|
|
40906
41027
|
var directChatProgressTickRunning = false;
|
|
@@ -40919,7 +41040,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
|
|
|
40919
41040
|
function readProgressHeartbeat() {
|
|
40920
41041
|
if (!PROGRESS_HEARTBEAT_PATH || !existsSync6(PROGRESS_HEARTBEAT_PATH)) return null;
|
|
40921
41042
|
try {
|
|
40922
|
-
return parseProgressHeartbeat(
|
|
41043
|
+
return parseProgressHeartbeat(readFileSync12(PROGRESS_HEARTBEAT_PATH, "utf-8"));
|
|
40923
41044
|
} catch {
|
|
40924
41045
|
return null;
|
|
40925
41046
|
}
|
|
@@ -40928,9 +41049,9 @@ function seedProgressHeartbeat() {
|
|
|
40928
41049
|
if (!PROGRESS_HEARTBEAT_PATH) return;
|
|
40929
41050
|
const tmp = `${PROGRESS_HEARTBEAT_PATH}.${process.pid}.tmp`;
|
|
40930
41051
|
try {
|
|
40931
|
-
|
|
40932
|
-
|
|
40933
|
-
|
|
41052
|
+
mkdirSync6(join16(homedir4(), ".augmented", AGT_AGENT_CODE_NAME), { recursive: true });
|
|
41053
|
+
writeFileSync8(tmp, serializeProgressHeartbeat(SEED_PROGRESS_STEP, Date.now()), { mode: 384 });
|
|
41054
|
+
renameSync6(tmp, PROGRESS_HEARTBEAT_PATH);
|
|
40934
41055
|
} catch {
|
|
40935
41056
|
try {
|
|
40936
41057
|
unlinkSync4(tmp);
|
|
@@ -41123,9 +41244,9 @@ var inboundAttachmentDeps = {
|
|
|
41123
41244
|
bytes: async () => new Uint8Array(await res.arrayBuffer())
|
|
41124
41245
|
};
|
|
41125
41246
|
},
|
|
41126
|
-
ensureDir: (dir) =>
|
|
41127
|
-
writeFile: (path, bytes) =>
|
|
41128
|
-
joinPath: (...parts) =>
|
|
41247
|
+
ensureDir: (dir) => mkdirSync6(dir, { recursive: true }),
|
|
41248
|
+
writeFile: (path, bytes) => writeFileSync8(path, bytes, { mode: 384 }),
|
|
41249
|
+
joinPath: (...parts) => join16(...parts),
|
|
41129
41250
|
warn: (msg) => process.stderr.write(`${msg}
|
|
41130
41251
|
`)
|
|
41131
41252
|
};
|
|
@@ -41159,7 +41280,13 @@ var mcp = new Server(
|
|
|
41159
41280
|
instructions: buildDirectChatMcpInstructions()
|
|
41160
41281
|
}
|
|
41161
41282
|
);
|
|
41162
|
-
var
|
|
41283
|
+
var DIRECT_CHAT_CLAIMS_PATH = directChatClaimsPath(DIRECT_CHAT_AGENT_DIR);
|
|
41284
|
+
var claimsTranscriptId = null;
|
|
41285
|
+
var claimTracker = new DirectChatClaimTracker({
|
|
41286
|
+
onChange: (t) => {
|
|
41287
|
+
saveDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH, claimsTranscriptId, t.snapshot(), Date.now());
|
|
41288
|
+
}
|
|
41289
|
+
});
|
|
41163
41290
|
mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
41164
41291
|
tools: [
|
|
41165
41292
|
{
|
|
@@ -41553,7 +41680,7 @@ function directChatSessionReplayFacts(sessionId) {
|
|
|
41553
41680
|
sessionId,
|
|
41554
41681
|
(fullPath) => {
|
|
41555
41682
|
try {
|
|
41556
|
-
const marker = JSON.parse(
|
|
41683
|
+
const marker = JSON.parse(readFileSync12(fullPath, "utf-8"));
|
|
41557
41684
|
found.push({ hasPayload: Boolean(marker.payload), discretionary: marker.discretionary });
|
|
41558
41685
|
} catch {
|
|
41559
41686
|
found.push({ hasPayload: false });
|
|
@@ -41612,7 +41739,7 @@ function scheduleDirectChatBusyAck(sessionId, messageId, arrivedWhileBusy) {
|
|
|
41612
41739
|
let paneLogFreshAgeMs = null;
|
|
41613
41740
|
if (DIRECT_CHAT_CODE_NAME_AGENT_DIR) {
|
|
41614
41741
|
try {
|
|
41615
|
-
const paneMtimeMs = statSync4(
|
|
41742
|
+
const paneMtimeMs = statSync4(join16(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "pane.log")).mtimeMs;
|
|
41616
41743
|
paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
|
|
41617
41744
|
} catch {
|
|
41618
41745
|
}
|
|
@@ -41767,6 +41894,7 @@ function armUsageLimitWatch(args) {
|
|
|
41767
41894
|
})();
|
|
41768
41895
|
}
|
|
41769
41896
|
async function pollForMessages(sinceMs) {
|
|
41897
|
+
let pushPendingId = null;
|
|
41770
41898
|
try {
|
|
41771
41899
|
const res = await apiPost("/host/direct-chat/poll", {
|
|
41772
41900
|
agent_id: AGT_AGENT_ID,
|
|
@@ -41794,11 +41922,7 @@ async function pollForMessages(sinceMs) {
|
|
|
41794
41922
|
const accountMuted = !isNotice && !maintenanceActive ? readAccountEnforcementLevel({ codeName: AGT_AGENT_CODE_NAME ?? null }) === "mute" : false;
|
|
41795
41923
|
if (!isNotice && !maintenanceActive && !accountMuted) {
|
|
41796
41924
|
markProcessed(msg.id);
|
|
41797
|
-
|
|
41798
|
-
if (!progressReceivedAt.has(msg.session_id)) {
|
|
41799
|
-
progressReceivedAt.set(msg.session_id, Date.now());
|
|
41800
|
-
}
|
|
41801
|
-
seedProgressHeartbeat();
|
|
41925
|
+
pushPendingId = msg.id;
|
|
41802
41926
|
}
|
|
41803
41927
|
if (maintenanceActive) {
|
|
41804
41928
|
const throttleKey = `${msg.session_id}|maintenance`;
|
|
@@ -41947,6 +42071,12 @@ async function pollForMessages(sinceMs) {
|
|
|
41947
42071
|
}
|
|
41948
42072
|
});
|
|
41949
42073
|
if (!isNotice) {
|
|
42074
|
+
pushPendingId = null;
|
|
42075
|
+
claimTracker.track(msg.session_id, msg.id);
|
|
42076
|
+
if (!progressReceivedAt.has(msg.session_id)) {
|
|
42077
|
+
progressReceivedAt.set(msg.session_id, Date.now());
|
|
42078
|
+
}
|
|
42079
|
+
seedProgressHeartbeat();
|
|
41950
42080
|
const arrivedWhileBusy = hasInFlightInbound(DIRECT_CHAT_PENDING_INBOUND_DIR);
|
|
41951
42081
|
writeDirectChatPendingInboundMarker(
|
|
41952
42082
|
DIRECT_CHAT_PENDING_INBOUND_DIR,
|
|
@@ -42020,6 +42150,7 @@ async function pollForMessages(sinceMs) {
|
|
|
42020
42150
|
}
|
|
42021
42151
|
return true;
|
|
42022
42152
|
} catch (err) {
|
|
42153
|
+
if (pushPendingId) processedIds.delete(pushPendingId);
|
|
42023
42154
|
process.stderr.write(
|
|
42024
42155
|
`direct-chat-channel: Poll error: ${err.message}
|
|
42025
42156
|
`
|
|
@@ -42077,11 +42208,25 @@ var doorbellWatcher = null;
|
|
|
42077
42208
|
var safetyNetTimer = null;
|
|
42078
42209
|
if (DOORBELL_ENABLED && DIRECT_CHAT_AGENT_DIR) {
|
|
42079
42210
|
try {
|
|
42080
|
-
|
|
42211
|
+
mkdirSync6(DIRECT_CHAT_AGENT_DIR, { recursive: true });
|
|
42081
42212
|
} catch {
|
|
42082
42213
|
}
|
|
42083
42214
|
const sessionState = readDirectChatSessionState(DIRECT_CHAT_AGENT_DIR, Date.now());
|
|
42084
42215
|
const sinceMs = sessionState.startedAtMs;
|
|
42216
|
+
const claimPlan = planClaimRecovery(sessionState);
|
|
42217
|
+
claimsTranscriptId = claimPlan.bindTo;
|
|
42218
|
+
if (claimPlan.restore) {
|
|
42219
|
+
const recovered = loadDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH, claimPlan.bindTo, Date.now());
|
|
42220
|
+
claimTracker.restore(recovered);
|
|
42221
|
+
if (recovered.length > 0) {
|
|
42222
|
+
process.stderr.write(
|
|
42223
|
+
`direct-chat-channel: restored ${recovered.length} pre-restart claim(s) for resumed session
|
|
42224
|
+
`
|
|
42225
|
+
);
|
|
42226
|
+
}
|
|
42227
|
+
} else {
|
|
42228
|
+
resetDirectChatClaims(DIRECT_CHAT_CLAIMS_PATH);
|
|
42229
|
+
}
|
|
42085
42230
|
let debounce = null;
|
|
42086
42231
|
try {
|
|
42087
42232
|
doorbellWatcher = watch(DIRECT_CHAT_AGENT_DIR, (_event, filename) => {
|
|
@@ -42134,7 +42279,7 @@ function sweepAgedDirectChatMarkersNow(thresholdMs) {
|
|
|
42134
42279
|
const now = Date.now();
|
|
42135
42280
|
const res = sweepAgedDirectChatMarkers(DIRECT_CHAT_PENDING_INBOUND_DIR, {
|
|
42136
42281
|
readdir: (dir) => readdirSync6(dir),
|
|
42137
|
-
readFile: (p2) =>
|
|
42282
|
+
readFile: (p2) => readFileSync12(p2, "utf8"),
|
|
42138
42283
|
unlink: (p2) => {
|
|
42139
42284
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42140
42285
|
},
|
|
@@ -42183,8 +42328,8 @@ function sanitizeRecoveryText(text) {
|
|
|
42183
42328
|
}
|
|
42184
42329
|
function directChatRecoveryDeps() {
|
|
42185
42330
|
return {
|
|
42186
|
-
readFile: (p2) =>
|
|
42187
|
-
renameFile: (from, to) =>
|
|
42331
|
+
readFile: (p2) => readFileSync12(p2, "utf-8"),
|
|
42332
|
+
renameFile: (from, to) => renameSync6(from, to),
|
|
42188
42333
|
unlinkFile: (p2) => {
|
|
42189
42334
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42190
42335
|
},
|
|
@@ -42196,7 +42341,7 @@ function directChatRecoveryDeps() {
|
|
|
42196
42341
|
if (!DIRECT_CHAT_RECOVERY_LEDGER_DIR) return;
|
|
42197
42342
|
if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
|
|
42198
42343
|
try {
|
|
42199
|
-
const p2 =
|
|
42344
|
+
const p2 = join16(DIRECT_CHAT_RECOVERY_LEDGER_DIR, markerName);
|
|
42200
42345
|
if (existsSync6(p2)) unlinkSync4(p2);
|
|
42201
42346
|
} catch {
|
|
42202
42347
|
}
|
|
@@ -42247,7 +42392,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
|
|
|
42247
42392
|
if (!enabled) return;
|
|
42248
42393
|
directChatRecoveryInFlight.add(filename);
|
|
42249
42394
|
try {
|
|
42250
|
-
const fullPath =
|
|
42395
|
+
const fullPath = join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, filename);
|
|
42251
42396
|
await consumeDirectChatRecoveryFile(fullPath, filename, directChatRecoveryDeps());
|
|
42252
42397
|
} catch (err) {
|
|
42253
42398
|
process.stderr.write(
|
|
@@ -42261,7 +42406,7 @@ async function processDirectChatRecoveryOutboxFile(filename) {
|
|
|
42261
42406
|
var directChatRecoveryWatcher = null;
|
|
42262
42407
|
if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
|
|
42263
42408
|
try {
|
|
42264
|
-
|
|
42409
|
+
mkdirSync6(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, { recursive: true, mode: 448 });
|
|
42265
42410
|
} catch {
|
|
42266
42411
|
}
|
|
42267
42412
|
try {
|
|
@@ -42275,7 +42420,7 @@ if (DIRECT_CHAT_RECOVERY_OUTBOX_DIR) {
|
|
|
42275
42420
|
if (!filename) return;
|
|
42276
42421
|
const name = filename.toString();
|
|
42277
42422
|
if (!name.endsWith(".json")) return;
|
|
42278
|
-
if (existsSync6(
|
|
42423
|
+
if (existsSync6(join16(DIRECT_CHAT_RECOVERY_OUTBOX_DIR, name))) {
|
|
42279
42424
|
void processDirectChatRecoveryOutboxFile(name);
|
|
42280
42425
|
}
|
|
42281
42426
|
});
|