@integrity-labs/agt-cli 0.28.367 → 0.28.368
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
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
success,
|
|
41
41
|
table,
|
|
42
42
|
warn
|
|
43
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-3QBV4ZA3.js";
|
|
44
44
|
import {
|
|
45
45
|
AnchorSessionClient,
|
|
46
46
|
CHANNEL_REGISTRY,
|
|
@@ -4829,7 +4829,7 @@ import { execFileSync, execSync } from "child_process";
|
|
|
4829
4829
|
import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
|
|
4830
4830
|
import chalk18 from "chalk";
|
|
4831
4831
|
import ora16 from "ora";
|
|
4832
|
-
var cliVersion = true ? "0.28.
|
|
4832
|
+
var cliVersion = true ? "0.28.368" : "dev";
|
|
4833
4833
|
async function fetchLatestVersion() {
|
|
4834
4834
|
const host2 = getHost();
|
|
4835
4835
|
if (!host2) return null;
|
|
@@ -6001,7 +6001,7 @@ function handleError(err) {
|
|
|
6001
6001
|
}
|
|
6002
6002
|
|
|
6003
6003
|
// src/bin/agt.ts
|
|
6004
|
-
var cliVersion2 = true ? "0.28.
|
|
6004
|
+
var cliVersion2 = true ? "0.28.368" : "dev";
|
|
6005
6005
|
var program = new Command();
|
|
6006
6006
|
program.name("agt").description("Augmented CLI \u2014 agent provisioning and management").version(cliVersion2).option("--json", "Emit machine-readable JSON output (suppress spinners and colors)").option("--skip-update-check", "Skip the automatic update check on startup");
|
|
6007
6007
|
program.hook("preAction", async (thisCommand, actionCommand) => {
|
|
@@ -6348,7 +6348,7 @@ function requireHost() {
|
|
|
6348
6348
|
}
|
|
6349
6349
|
|
|
6350
6350
|
// src/lib/api-client.ts
|
|
6351
|
-
var agtCliVersion = true ? "0.28.
|
|
6351
|
+
var agtCliVersion = true ? "0.28.368" : "dev";
|
|
6352
6352
|
var lastConfigHash = null;
|
|
6353
6353
|
function setConfigHash(hash) {
|
|
6354
6354
|
lastConfigHash = hash && hash.length > 0 ? hash : null;
|
|
@@ -8794,4 +8794,4 @@ export {
|
|
|
8794
8794
|
managerInstallSystemUnitCommand,
|
|
8795
8795
|
managerUninstallSystemUnitCommand
|
|
8796
8796
|
};
|
|
8797
|
-
//# sourceMappingURL=chunk-
|
|
8797
|
+
//# sourceMappingURL=chunk-3QBV4ZA3.js.map
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
resolveEffectivePinRaw,
|
|
44
44
|
safeWriteJsonAtomic,
|
|
45
45
|
setConfigHash
|
|
46
|
-
} from "../chunk-
|
|
46
|
+
} from "../chunk-3QBV4ZA3.js";
|
|
47
47
|
import {
|
|
48
48
|
getProjectDir as getProjectDir2,
|
|
49
49
|
getReadyTasks,
|
|
@@ -9072,7 +9072,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
9072
9072
|
var lastVersionCheckAt = 0;
|
|
9073
9073
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
9074
9074
|
var lastResponsivenessProbeAt = 0;
|
|
9075
|
-
var agtCliVersion = true ? "0.28.
|
|
9075
|
+
var agtCliVersion = true ? "0.28.368" : "dev";
|
|
9076
9076
|
function resolveBrewPath(execFileSync2) {
|
|
9077
9077
|
try {
|
|
9078
9078
|
const out = execFileSync2("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -29827,6 +29827,7 @@ import {
|
|
|
29827
29827
|
existsSync as existsSync2,
|
|
29828
29828
|
mkdirSync as mkdirSync2,
|
|
29829
29829
|
readdirSync,
|
|
29830
|
+
readFileSync as readFileSync3,
|
|
29830
29831
|
renameSync as renameSync2,
|
|
29831
29832
|
unlinkSync,
|
|
29832
29833
|
writeFileSync as writeFileSync2
|
|
@@ -29882,6 +29883,15 @@ function clearDirectChatPendingMarkersForSession(dir, sessionId, op = defaultCle
|
|
|
29882
29883
|
}
|
|
29883
29884
|
return cleared;
|
|
29884
29885
|
}
|
|
29886
|
+
function readDirectChatPendingInboundMarker(dir, sessionId, messageId, readFileImpl = (path) => readFileSync3(path, "utf8")) {
|
|
29887
|
+
if (!dir || !sessionId || !messageId) return null;
|
|
29888
|
+
try {
|
|
29889
|
+
const raw = readFileImpl(join3(dir, directChatMarkerName(sessionId, messageId)));
|
|
29890
|
+
return JSON.parse(raw);
|
|
29891
|
+
} catch {
|
|
29892
|
+
return null;
|
|
29893
|
+
}
|
|
29894
|
+
}
|
|
29885
29895
|
function sweepAgedDirectChatMarkers(dir, deps) {
|
|
29886
29896
|
const result = { cleared: 0, orphaned: 0 };
|
|
29887
29897
|
if (!dir) return result;
|
|
@@ -29982,7 +29992,7 @@ async function consumeDirectChatRecoveryFile(fullPath, filename, deps) {
|
|
|
29982
29992
|
}
|
|
29983
29993
|
|
|
29984
29994
|
// src/inbound-delivery-ledger.ts
|
|
29985
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as
|
|
29995
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
29986
29996
|
import { join as join4 } from "path";
|
|
29987
29997
|
function safeInboundId(inboundId) {
|
|
29988
29998
|
return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
@@ -29992,7 +30002,7 @@ var defaultDeps = {
|
|
|
29992
30002
|
writeFile: (path, data) => writeFileSync3(path, data, "utf8"),
|
|
29993
30003
|
rename: (from, to) => renameSync3(from, to),
|
|
29994
30004
|
readdir: (dir) => readdirSync2(dir),
|
|
29995
|
-
readFile: (path) =>
|
|
30005
|
+
readFile: (path) => readFileSync4(path, "utf8"),
|
|
29996
30006
|
exists: (path) => existsSync3(path)
|
|
29997
30007
|
};
|
|
29998
30008
|
function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
|
|
@@ -30020,11 +30030,11 @@ function inboundDeliveryLedgerHas(dir, inboundId, deps = defaultDeps) {
|
|
|
30020
30030
|
}
|
|
30021
30031
|
|
|
30022
30032
|
// src/ack-reaction.ts
|
|
30023
|
-
import { readdirSync as readdirSync3, readFileSync as
|
|
30033
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
30024
30034
|
import { join as join6 } from "path";
|
|
30025
30035
|
|
|
30026
30036
|
// src/flags-cache-read.ts
|
|
30027
|
-
import { existsSync as existsSync4, readFileSync as
|
|
30037
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
30028
30038
|
import { homedir } from "os";
|
|
30029
30039
|
import { join as join5 } from "path";
|
|
30030
30040
|
function defaultFlagsCachePath() {
|
|
@@ -30041,7 +30051,7 @@ function envBoolean(raw) {
|
|
|
30041
30051
|
function cachedBoolean(key, path) {
|
|
30042
30052
|
try {
|
|
30043
30053
|
if (!existsSync4(path)) return void 0;
|
|
30044
|
-
const parsed = JSON.parse(
|
|
30054
|
+
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
30045
30055
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
30046
30056
|
const flags = parsed.flags;
|
|
30047
30057
|
if (!flags || typeof flags !== "object") return void 0;
|
|
@@ -30062,9 +30072,90 @@ function resolveHostBooleanFlag(opts) {
|
|
|
30062
30072
|
|
|
30063
30073
|
// src/ack-reaction.ts
|
|
30064
30074
|
var REPLY_WEDGED_THRESHOLD_MS = 5 * 60 * 1e3;
|
|
30075
|
+
var ACK_PANE_FRESH_THRESHOLD_MS = 6e4;
|
|
30076
|
+
function classifyUndeliverableCause(i) {
|
|
30077
|
+
if (!i.hasTarget) return null;
|
|
30078
|
+
if (!i.integrationReady) return "integration_down";
|
|
30079
|
+
if (i.tmux === "dead") return "session_dead";
|
|
30080
|
+
if (!i.withinStartupGrace && i.claude === "dead") return "session_dead";
|
|
30081
|
+
const threshold = i.pendingStaleThresholdMs ?? REPLY_WEDGED_THRESHOLD_MS;
|
|
30082
|
+
if (i.oldestPendingAgeMs != null && i.oldestPendingAgeMs > threshold) {
|
|
30083
|
+
const paneFreshThreshold = i.paneFreshThresholdMs ?? ACK_PANE_FRESH_THRESHOLD_MS;
|
|
30084
|
+
const paneIsFresh = i.paneLogFreshAgeMs != null && i.paneLogFreshAgeMs <= paneFreshThreshold;
|
|
30085
|
+
if (paneIsFresh && i.tmux === "alive" && i.claude === "alive") {
|
|
30086
|
+
return null;
|
|
30087
|
+
}
|
|
30088
|
+
return "wedged";
|
|
30089
|
+
}
|
|
30090
|
+
return null;
|
|
30091
|
+
}
|
|
30065
30092
|
var UNDELIVERABLE_NOTICE_THROTTLE_MS = 5 * 60 * 1e3;
|
|
30093
|
+
function shouldPostUndeliverableNotice(lastNoticeAtMs, nowMs, throttleMs = UNDELIVERABLE_NOTICE_THROTTLE_MS) {
|
|
30094
|
+
return lastNoticeAtMs == null || nowMs - lastNoticeAtMs >= throttleMs;
|
|
30095
|
+
}
|
|
30096
|
+
function undeliverableNoticeText(replayEnabled = channelReplayEnabled()) {
|
|
30097
|
+
return replayEnabled ? "\u23F3 I can't get to this right now \u2014 no need to resend; I'll pick it up automatically as soon as I'm free." : "\u23F3 I can't get to this right now. Please resend in a few minutes \u2014 I may not see this one.";
|
|
30098
|
+
}
|
|
30099
|
+
var BUSY_ACK_THRESHOLD_MS = 12e4;
|
|
30066
30100
|
var BUSY_ACK_NOTICE_THROTTLE_MS = 20 * 60 * 1e3;
|
|
30101
|
+
function channelBusyAckEnabled() {
|
|
30102
|
+
return resolveHostBooleanFlag({
|
|
30103
|
+
key: "channel-busy-ack",
|
|
30104
|
+
envVar: "AGT_CHANNEL_BUSY_ACK_ENABLED",
|
|
30105
|
+
defaultValue: false
|
|
30106
|
+
});
|
|
30107
|
+
}
|
|
30108
|
+
function channelBusyAckThresholdMs() {
|
|
30109
|
+
const raw = parseInt(process.env.AGT_CHANNEL_BUSY_ACK_THRESHOLD_MS ?? "", 10);
|
|
30110
|
+
return Number.isFinite(raw) && raw > 0 ? raw : BUSY_ACK_THRESHOLD_MS;
|
|
30111
|
+
}
|
|
30112
|
+
function decideBusyAck(i) {
|
|
30113
|
+
if (!i.hasTarget) return false;
|
|
30114
|
+
if (!i.arrivedWhileBusy) return false;
|
|
30115
|
+
if (!i.stillPending) return false;
|
|
30116
|
+
if (!Number.isFinite(i.pendingAgeMs)) return false;
|
|
30117
|
+
const threshold = i.thresholdMs ?? channelBusyAckThresholdMs();
|
|
30118
|
+
if (i.pendingAgeMs < threshold) return false;
|
|
30119
|
+
if (!i.sessionAlive) return false;
|
|
30120
|
+
const paneFreshThreshold = i.paneFreshThresholdMs ?? ACK_PANE_FRESH_THRESHOLD_MS;
|
|
30121
|
+
return i.paneLogFreshAgeMs != null && i.paneLogFreshAgeMs <= paneFreshThreshold;
|
|
30122
|
+
}
|
|
30123
|
+
function busyAckNoticeText() {
|
|
30124
|
+
return "\u{1F6E0}\uFE0F I'm in the middle of something right now \u2014 I'll follow up on this as soon as I'm free.";
|
|
30125
|
+
}
|
|
30067
30126
|
var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
30127
|
+
function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
|
|
30128
|
+
if (!dir) return null;
|
|
30129
|
+
let names;
|
|
30130
|
+
try {
|
|
30131
|
+
names = readdirSync3(dir);
|
|
30132
|
+
} catch {
|
|
30133
|
+
return null;
|
|
30134
|
+
}
|
|
30135
|
+
let oldest = null;
|
|
30136
|
+
for (const name of names) {
|
|
30137
|
+
if (!name.endsWith(".json")) continue;
|
|
30138
|
+
let receivedAt;
|
|
30139
|
+
try {
|
|
30140
|
+
const raw = JSON.parse(readFileSync6(join6(dir, name), "utf-8"));
|
|
30141
|
+
if (raw.discretionary === true) continue;
|
|
30142
|
+
if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
|
|
30143
|
+
receivedAt = raw.received_at;
|
|
30144
|
+
} catch {
|
|
30145
|
+
continue;
|
|
30146
|
+
}
|
|
30147
|
+
if (!receivedAt) continue;
|
|
30148
|
+
const t = Date.parse(receivedAt);
|
|
30149
|
+
if (Number.isNaN(t)) continue;
|
|
30150
|
+
const age = now - t;
|
|
30151
|
+
if (age < 0) continue;
|
|
30152
|
+
if (oldest == null || age > oldest) oldest = age;
|
|
30153
|
+
}
|
|
30154
|
+
return oldest;
|
|
30155
|
+
}
|
|
30156
|
+
function hasInFlightInbound(dir, now = Date.now()) {
|
|
30157
|
+
return oldestPendingMarkerAgeMs(dir, now, { includeSeen: true }) != null;
|
|
30158
|
+
}
|
|
30068
30159
|
function channelOrphanMarkerMs() {
|
|
30069
30160
|
const raw = parseInt(process.env.AGT_CHANNEL_ORPHAN_MARKER_MS ?? "", 10);
|
|
30070
30161
|
return Number.isFinite(raw) && raw > 0 ? Math.max(raw, 12e4) : 30 * 6e4;
|
|
@@ -30074,6 +30165,13 @@ function orphanSweepIntervalMs() {
|
|
|
30074
30165
|
return Math.max(6e4, Math.min(ORPHAN_SWEEP_INTERVAL_MS, channelOrphanMarkerMs()));
|
|
30075
30166
|
}
|
|
30076
30167
|
var PANE_FRESH_DEFER_MAX_MS = 10 * 60 * 1e3;
|
|
30168
|
+
function channelReplayEnabled() {
|
|
30169
|
+
return resolveHostBooleanFlag({
|
|
30170
|
+
key: "channel-replay",
|
|
30171
|
+
envVar: "AGT_CHANNEL_REPLAY_ENABLED",
|
|
30172
|
+
defaultValue: true
|
|
30173
|
+
});
|
|
30174
|
+
}
|
|
30077
30175
|
function isMarkerGenuinelyAged(receivedAt, nowMs, thresholdMs) {
|
|
30078
30176
|
const t = Date.parse(receivedAt ?? "");
|
|
30079
30177
|
return Number.isFinite(t) && t <= nowMs && nowMs - t >= thresholdMs;
|
|
@@ -30087,7 +30185,7 @@ function recordChannelDeflection(agentDir, channel, cause) {
|
|
|
30087
30185
|
const path = deflectionCounterPath(agentDir, channel);
|
|
30088
30186
|
let counts = {};
|
|
30089
30187
|
try {
|
|
30090
|
-
const parsed = JSON.parse(
|
|
30188
|
+
const parsed = JSON.parse(readFileSync6(path, "utf-8"));
|
|
30091
30189
|
if (parsed && typeof parsed === "object") counts = parsed;
|
|
30092
30190
|
} catch {
|
|
30093
30191
|
}
|
|
@@ -30174,7 +30272,7 @@ async function fetchWithTimeout(input, init, timeoutMs, fetchImpl = fetch) {
|
|
|
30174
30272
|
import {
|
|
30175
30273
|
existsSync as existsSync5,
|
|
30176
30274
|
mkdirSync as mkdirSync4,
|
|
30177
|
-
readFileSync as
|
|
30275
|
+
readFileSync as readFileSync7,
|
|
30178
30276
|
renameSync as renameSync4,
|
|
30179
30277
|
unlinkSync as unlinkSync2,
|
|
30180
30278
|
writeFileSync as writeFileSync5
|
|
@@ -30228,7 +30326,7 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
|
|
|
30228
30326
|
function readLockHolder(path) {
|
|
30229
30327
|
if (!existsSync5(path)) return null;
|
|
30230
30328
|
try {
|
|
30231
|
-
const raw =
|
|
30329
|
+
const raw = readFileSync7(path, "utf8");
|
|
30232
30330
|
const parsed = JSON.parse(raw);
|
|
30233
30331
|
const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
|
|
30234
30332
|
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
@@ -30247,11 +30345,12 @@ import {
|
|
|
30247
30345
|
watch,
|
|
30248
30346
|
mkdirSync as mkdirSync5,
|
|
30249
30347
|
writeFileSync as writeFileSync6,
|
|
30250
|
-
readFileSync as
|
|
30348
|
+
readFileSync as readFileSync9,
|
|
30251
30349
|
readdirSync as readdirSync4,
|
|
30252
30350
|
existsSync as existsSync6,
|
|
30253
30351
|
renameSync as renameSync5,
|
|
30254
30352
|
unlinkSync as unlinkSync3,
|
|
30353
|
+
statSync,
|
|
30255
30354
|
createWriteStream
|
|
30256
30355
|
} from "fs";
|
|
30257
30356
|
|
|
@@ -30678,7 +30777,7 @@ function isMaintenanceModeActive(opts) {
|
|
|
30678
30777
|
}
|
|
30679
30778
|
|
|
30680
30779
|
// src/usage-limit-notice.ts
|
|
30681
|
-
import { readFileSync as
|
|
30780
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
30682
30781
|
import { homedir as homedir2 } from "os";
|
|
30683
30782
|
import { join as join9 } from "path";
|
|
30684
30783
|
|
|
@@ -35075,7 +35174,7 @@ function readUsageLimitUntil(opts) {
|
|
|
35075
35174
|
if (!path) return null;
|
|
35076
35175
|
let raw;
|
|
35077
35176
|
try {
|
|
35078
|
-
raw =
|
|
35177
|
+
raw = readFileSync8(path, "utf-8");
|
|
35079
35178
|
} catch {
|
|
35080
35179
|
return null;
|
|
35081
35180
|
}
|
|
@@ -35173,7 +35272,7 @@ var directChatKanbanCardClient = createKanbanCardActiveClient({
|
|
|
35173
35272
|
function readProgressHeartbeat() {
|
|
35174
35273
|
if (!PROGRESS_HEARTBEAT_PATH || !existsSync6(PROGRESS_HEARTBEAT_PATH)) return null;
|
|
35175
35274
|
try {
|
|
35176
|
-
return parseProgressHeartbeat(
|
|
35275
|
+
return parseProgressHeartbeat(readFileSync9(PROGRESS_HEARTBEAT_PATH, "utf-8"));
|
|
35177
35276
|
} catch {
|
|
35178
35277
|
return null;
|
|
35179
35278
|
}
|
|
@@ -35600,6 +35699,119 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
35600
35699
|
});
|
|
35601
35700
|
await mcp.connect(new StdioServerTransport());
|
|
35602
35701
|
var processedIds = /* @__PURE__ */ new Set();
|
|
35702
|
+
var lastBusyAckNoticeAt = /* @__PURE__ */ new Map();
|
|
35703
|
+
var lastUndeliverableNoticeAt = /* @__PURE__ */ new Map();
|
|
35704
|
+
async function postDirectChatNoticeMessage(sessionId, content) {
|
|
35705
|
+
try {
|
|
35706
|
+
const res = await apiPost("/host/direct-chat/reply", {
|
|
35707
|
+
agent_id: AGT_AGENT_ID,
|
|
35708
|
+
session_id: sessionId,
|
|
35709
|
+
content,
|
|
35710
|
+
liveness_stamp: false
|
|
35711
|
+
});
|
|
35712
|
+
if (!res.ok) return false;
|
|
35713
|
+
const data = await res.json().catch(() => ({}));
|
|
35714
|
+
return data.error == null;
|
|
35715
|
+
} catch {
|
|
35716
|
+
return false;
|
|
35717
|
+
}
|
|
35718
|
+
}
|
|
35719
|
+
function postDirectChatBusyAckNotice(sessionId) {
|
|
35720
|
+
const now = Date.now();
|
|
35721
|
+
if (!shouldPostUndeliverableNotice(lastBusyAckNoticeAt.get(sessionId), now, BUSY_ACK_NOTICE_THROTTLE_MS)) {
|
|
35722
|
+
return;
|
|
35723
|
+
}
|
|
35724
|
+
lastBusyAckNoticeAt.set(sessionId, now);
|
|
35725
|
+
void (async () => {
|
|
35726
|
+
const ok = await postDirectChatNoticeMessage(sessionId, busyAckNoticeText());
|
|
35727
|
+
if (!ok) {
|
|
35728
|
+
lastBusyAckNoticeAt.delete(sessionId);
|
|
35729
|
+
process.stderr.write(
|
|
35730
|
+
`direct-chat-channel(${AGT_AGENT_CODE_NAME}): busy-ack notice failed (session=${sessionId})
|
|
35731
|
+
`
|
|
35732
|
+
);
|
|
35733
|
+
}
|
|
35734
|
+
})();
|
|
35735
|
+
}
|
|
35736
|
+
function postDirectChatUndeliverableNotice(sessionId) {
|
|
35737
|
+
const now = Date.now();
|
|
35738
|
+
if (!shouldPostUndeliverableNotice(lastUndeliverableNoticeAt.get(sessionId), now)) {
|
|
35739
|
+
return;
|
|
35740
|
+
}
|
|
35741
|
+
lastUndeliverableNoticeAt.set(sessionId, now);
|
|
35742
|
+
void (async () => {
|
|
35743
|
+
const ok = await postDirectChatNoticeMessage(sessionId, undeliverableNoticeText());
|
|
35744
|
+
if (!ok) {
|
|
35745
|
+
lastUndeliverableNoticeAt.delete(sessionId);
|
|
35746
|
+
process.stderr.write(
|
|
35747
|
+
`direct-chat-channel(${AGT_AGENT_CODE_NAME}): undeliverable notice failed (session=${sessionId})
|
|
35748
|
+
`
|
|
35749
|
+
);
|
|
35750
|
+
}
|
|
35751
|
+
})();
|
|
35752
|
+
}
|
|
35753
|
+
function __resetDirectChatBusyAckThrottles() {
|
|
35754
|
+
lastBusyAckNoticeAt.clear();
|
|
35755
|
+
lastUndeliverableNoticeAt.clear();
|
|
35756
|
+
}
|
|
35757
|
+
function scheduleDirectChatBusyAck(sessionId, messageId, arrivedWhileBusy) {
|
|
35758
|
+
if (!channelBusyAckEnabled()) return;
|
|
35759
|
+
if (!arrivedWhileBusy) return;
|
|
35760
|
+
if (!DIRECT_CHAT_PENDING_INBOUND_DIR) return;
|
|
35761
|
+
const thresholdMs = channelBusyAckThresholdMs();
|
|
35762
|
+
const timer = setTimeout(() => {
|
|
35763
|
+
const probe = process.env.TMUX && AGT_AGENT_CODE_NAME ? probeAgentSessionCached(AGT_AGENT_CODE_NAME) : { tmux: "unknown", claude: "unknown" };
|
|
35764
|
+
let paneLogFreshAgeMs = null;
|
|
35765
|
+
if (DIRECT_CHAT_CODE_NAME_AGENT_DIR) {
|
|
35766
|
+
try {
|
|
35767
|
+
const paneMtimeMs = statSync(join10(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "pane.log")).mtimeMs;
|
|
35768
|
+
paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
|
|
35769
|
+
} catch {
|
|
35770
|
+
}
|
|
35771
|
+
}
|
|
35772
|
+
const marker = readDirectChatPendingInboundMarker(DIRECT_CHAT_PENDING_INBOUND_DIR, sessionId, messageId);
|
|
35773
|
+
if (!marker) return;
|
|
35774
|
+
const sessionAlive = probe.tmux === "alive" && probe.claude === "alive";
|
|
35775
|
+
const pendingAgeMs = Math.max(0, Date.now() - Date.parse(marker.received_at));
|
|
35776
|
+
if (decideBusyAck({
|
|
35777
|
+
hasTarget: Boolean(sessionId && messageId),
|
|
35778
|
+
arrivedWhileBusy,
|
|
35779
|
+
stillPending: true,
|
|
35780
|
+
pendingAgeMs,
|
|
35781
|
+
sessionAlive,
|
|
35782
|
+
paneLogFreshAgeMs,
|
|
35783
|
+
thresholdMs
|
|
35784
|
+
})) {
|
|
35785
|
+
recordChannelDeflection(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "direct-chat", "busy");
|
|
35786
|
+
process.stderr.write(
|
|
35787
|
+
`direct-chat-channel(${AGT_AGENT_CODE_NAME}): [channel-deflection] cause=busy channel=direct-chat session=${sessionId}
|
|
35788
|
+
`
|
|
35789
|
+
);
|
|
35790
|
+
postDirectChatBusyAckNotice(sessionId);
|
|
35791
|
+
return;
|
|
35792
|
+
}
|
|
35793
|
+
const cause = classifyUndeliverableCause({
|
|
35794
|
+
hasTarget: true,
|
|
35795
|
+
integrationReady: true,
|
|
35796
|
+
// direct-chat egress is the API - always reachable
|
|
35797
|
+
tmux: probe.tmux,
|
|
35798
|
+
claude: probe.claude,
|
|
35799
|
+
withinStartupGrace: false,
|
|
35800
|
+
// 2min past an in-flight inbound ⇒ well clear of boot grace
|
|
35801
|
+
oldestPendingAgeMs: pendingAgeMs,
|
|
35802
|
+
paneLogFreshAgeMs
|
|
35803
|
+
});
|
|
35804
|
+
if (cause) {
|
|
35805
|
+
recordChannelDeflection(DIRECT_CHAT_CODE_NAME_AGENT_DIR, "direct-chat", cause);
|
|
35806
|
+
process.stderr.write(
|
|
35807
|
+
`direct-chat-channel(${AGT_AGENT_CODE_NAME}): [channel-deflection] cause=${cause} channel=direct-chat session=${sessionId}
|
|
35808
|
+
`
|
|
35809
|
+
);
|
|
35810
|
+
postDirectChatUndeliverableNotice(sessionId);
|
|
35811
|
+
}
|
|
35812
|
+
}, thresholdMs);
|
|
35813
|
+
timer.unref();
|
|
35814
|
+
}
|
|
35603
35815
|
async function pollForMessages(sinceMs) {
|
|
35604
35816
|
try {
|
|
35605
35817
|
const res = await apiPost("/host/direct-chat/poll", {
|
|
@@ -35720,11 +35932,13 @@ async function pollForMessages(sinceMs) {
|
|
|
35720
35932
|
}
|
|
35721
35933
|
});
|
|
35722
35934
|
if (!isNotice) {
|
|
35935
|
+
const arrivedWhileBusy = hasInFlightInbound(DIRECT_CHAT_PENDING_INBOUND_DIR);
|
|
35723
35936
|
writeDirectChatPendingInboundMarker(
|
|
35724
35937
|
DIRECT_CHAT_PENDING_INBOUND_DIR,
|
|
35725
35938
|
msg.session_id,
|
|
35726
35939
|
msg.id
|
|
35727
35940
|
);
|
|
35941
|
+
scheduleDirectChatBusyAck(msg.session_id, msg.id, arrivedWhileBusy);
|
|
35728
35942
|
}
|
|
35729
35943
|
if (!isNotice && msg.sender_id) {
|
|
35730
35944
|
writeTurnInitiatorMarker({
|
|
@@ -35864,7 +36078,7 @@ function sweepAgedDirectChatMarkersNow(thresholdMs) {
|
|
|
35864
36078
|
const now = Date.now();
|
|
35865
36079
|
const res = sweepAgedDirectChatMarkers(DIRECT_CHAT_PENDING_INBOUND_DIR, {
|
|
35866
36080
|
readdir: (dir) => readdirSync4(dir),
|
|
35867
|
-
readFile: (p2) =>
|
|
36081
|
+
readFile: (p2) => readFileSync9(p2, "utf8"),
|
|
35868
36082
|
unlink: (p2) => {
|
|
35869
36083
|
if (existsSync6(p2)) unlinkSync3(p2);
|
|
35870
36084
|
},
|
|
@@ -35900,7 +36114,7 @@ function sanitizeRecoveryText(text) {
|
|
|
35900
36114
|
}
|
|
35901
36115
|
function directChatRecoveryDeps() {
|
|
35902
36116
|
return {
|
|
35903
|
-
readFile: (p2) =>
|
|
36117
|
+
readFile: (p2) => readFileSync9(p2, "utf-8"),
|
|
35904
36118
|
renameFile: (from, to) => renameSync5(from, to),
|
|
35905
36119
|
unlinkFile: (p2) => {
|
|
35906
36120
|
if (existsSync6(p2)) unlinkSync3(p2);
|
|
@@ -36012,6 +36226,9 @@ process.stdin.on("end", () => shutdown("stdin ended"));
|
|
|
36012
36226
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
36013
36227
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
36014
36228
|
process.on("SIGHUP", () => shutdown("SIGHUP"));
|
|
36229
|
+
export {
|
|
36230
|
+
__resetDirectChatBusyAckThrottles
|
|
36231
|
+
};
|
|
36015
36232
|
/*! Bundled license information:
|
|
36016
36233
|
|
|
36017
36234
|
chokidar/index.js:
|
package/package.json
CHANGED
|
File without changes
|