@integrity-labs/agt-cli 0.27.167 → 0.27.168
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
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
success,
|
|
34
34
|
table,
|
|
35
35
|
warn
|
|
36
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-ZQGQVROS.js";
|
|
37
37
|
import {
|
|
38
38
|
CHANNEL_REGISTRY,
|
|
39
39
|
DEPLOYMENT_TEMPLATES,
|
|
@@ -5019,7 +5019,7 @@ import { execFileSync, execSync } from "child_process";
|
|
|
5019
5019
|
import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
|
|
5020
5020
|
import chalk18 from "chalk";
|
|
5021
5021
|
import ora16 from "ora";
|
|
5022
|
-
var cliVersion = true ? "0.27.
|
|
5022
|
+
var cliVersion = true ? "0.27.168" : "dev";
|
|
5023
5023
|
async function fetchLatestVersion() {
|
|
5024
5024
|
const host2 = getHost();
|
|
5025
5025
|
if (!host2) return null;
|
|
@@ -5942,7 +5942,7 @@ function handleError(err) {
|
|
|
5942
5942
|
}
|
|
5943
5943
|
|
|
5944
5944
|
// src/bin/agt.ts
|
|
5945
|
-
var cliVersion2 = true ? "0.27.
|
|
5945
|
+
var cliVersion2 = true ? "0.27.168" : "dev";
|
|
5946
5946
|
var program = new Command();
|
|
5947
5947
|
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");
|
|
5948
5948
|
program.hook("preAction", async (thisCommand, actionCommand) => {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
provisionStopHook,
|
|
23
23
|
requireHost,
|
|
24
24
|
safeWriteJsonAtomic
|
|
25
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-ZQGQVROS.js";
|
|
26
26
|
import {
|
|
27
27
|
getProjectDir as getProjectDir2,
|
|
28
28
|
getReadyTasks,
|
|
@@ -5041,7 +5041,7 @@ var cachedMaintenanceWindow = null;
|
|
|
5041
5041
|
var lastVersionCheckAt = 0;
|
|
5042
5042
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
5043
5043
|
var lastResponsivenessProbeAt = 0;
|
|
5044
|
-
var agtCliVersion = true ? "0.27.
|
|
5044
|
+
var agtCliVersion = true ? "0.27.168" : "dev";
|
|
5045
5045
|
function resolveBrewPath(execFileSync4) {
|
|
5046
5046
|
try {
|
|
5047
5047
|
const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -14320,16 +14320,16 @@ import {
|
|
|
14320
14320
|
createWriteStream,
|
|
14321
14321
|
existsSync as existsSync5,
|
|
14322
14322
|
mkdirSync as mkdirSync4,
|
|
14323
|
-
readFileSync as
|
|
14324
|
-
readdirSync as
|
|
14323
|
+
readFileSync as readFileSync7,
|
|
14324
|
+
readdirSync as readdirSync3,
|
|
14325
14325
|
renameSync as renameSync4,
|
|
14326
|
-
statSync,
|
|
14326
|
+
statSync as statSync2,
|
|
14327
14327
|
unlinkSync as unlinkSync4,
|
|
14328
14328
|
watch,
|
|
14329
14329
|
writeFileSync as writeFileSync4
|
|
14330
14330
|
} from "fs";
|
|
14331
14331
|
import { homedir as homedir3 } from "os";
|
|
14332
|
-
import { join as
|
|
14332
|
+
import { join as join7 } from "path";
|
|
14333
14333
|
|
|
14334
14334
|
// src/channel-attachments.ts
|
|
14335
14335
|
import { homedir } from "os";
|
|
@@ -16000,16 +16000,53 @@ var TELEGRAM_EGRESS_TOOLS = /* @__PURE__ */ new Set([
|
|
|
16000
16000
|
"channel_request_input"
|
|
16001
16001
|
]);
|
|
16002
16002
|
|
|
16003
|
+
// src/telegram-pending-inbound-cleanup.ts
|
|
16004
|
+
import { readdirSync, readFileSync as readFileSync3, statSync } from "fs";
|
|
16005
|
+
import { join as join3 } from "path";
|
|
16006
|
+
function markerArrivalMs(fullPath) {
|
|
16007
|
+
try {
|
|
16008
|
+
const received = JSON.parse(readFileSync3(fullPath, "utf-8")).received_at;
|
|
16009
|
+
const parsed = received ? Date.parse(received) : Number.NaN;
|
|
16010
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
16011
|
+
} catch {
|
|
16012
|
+
}
|
|
16013
|
+
try {
|
|
16014
|
+
return statSync(fullPath).mtimeMs;
|
|
16015
|
+
} catch {
|
|
16016
|
+
return Number.POSITIVE_INFINITY;
|
|
16017
|
+
}
|
|
16018
|
+
}
|
|
16019
|
+
function clearAllTelegramPendingMarkersForChat(pendingDir, chatId, clearMarkerFile, cutoffMs = Number.POSITIVE_INFINITY) {
|
|
16020
|
+
const prefix = `${chatId.replace(/[^A-Za-z0-9_-]/g, "_")}__`;
|
|
16021
|
+
const bounded = Number.isFinite(cutoffMs);
|
|
16022
|
+
let filenames;
|
|
16023
|
+
try {
|
|
16024
|
+
filenames = readdirSync(pendingDir);
|
|
16025
|
+
} catch {
|
|
16026
|
+
return 0;
|
|
16027
|
+
}
|
|
16028
|
+
let cleared = 0;
|
|
16029
|
+
for (const filename of filenames) {
|
|
16030
|
+
if (!filename.startsWith(prefix)) continue;
|
|
16031
|
+
if (!filename.endsWith(".json")) continue;
|
|
16032
|
+
const fullPath = join3(pendingDir, filename);
|
|
16033
|
+
if (bounded && markerArrivalMs(fullPath) > cutoffMs) continue;
|
|
16034
|
+
clearMarkerFile(fullPath);
|
|
16035
|
+
cleared++;
|
|
16036
|
+
}
|
|
16037
|
+
return cleared;
|
|
16038
|
+
}
|
|
16039
|
+
|
|
16003
16040
|
// src/mcp-spawn-lock.ts
|
|
16004
16041
|
import {
|
|
16005
16042
|
existsSync as existsSync3,
|
|
16006
16043
|
mkdirSync as mkdirSync3,
|
|
16007
|
-
readFileSync as
|
|
16044
|
+
readFileSync as readFileSync4,
|
|
16008
16045
|
renameSync as renameSync3,
|
|
16009
16046
|
unlinkSync as unlinkSync3,
|
|
16010
16047
|
writeFileSync as writeFileSync3
|
|
16011
16048
|
} from "fs";
|
|
16012
|
-
import { join as
|
|
16049
|
+
import { join as join4 } from "path";
|
|
16013
16050
|
function defaultIsPidAlive(pid) {
|
|
16014
16051
|
if (!Number.isFinite(pid) || pid <= 0) return false;
|
|
16015
16052
|
try {
|
|
@@ -16027,7 +16064,7 @@ function acquireMcpSpawnLock(args) {
|
|
|
16027
16064
|
const isPidAlive = options.isPidAlive ?? defaultIsPidAlive;
|
|
16028
16065
|
const selfPid = options.selfPid ?? process.pid;
|
|
16029
16066
|
const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
16030
|
-
const path =
|
|
16067
|
+
const path = join4(agentDir, basename);
|
|
16031
16068
|
const existing = readLockHolder(path);
|
|
16032
16069
|
if (existing) {
|
|
16033
16070
|
if (existing.pid === selfPid) {
|
|
@@ -16058,7 +16095,7 @@ function releaseMcpSpawnLock(lockPath, opts = {}) {
|
|
|
16058
16095
|
function readLockHolder(path) {
|
|
16059
16096
|
if (!existsSync3(path)) return null;
|
|
16060
16097
|
try {
|
|
16061
|
-
const raw =
|
|
16098
|
+
const raw = readFileSync4(path, "utf8");
|
|
16062
16099
|
const parsed = JSON.parse(raw);
|
|
16063
16100
|
const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
|
|
16064
16101
|
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
@@ -16070,15 +16107,15 @@ function readLockHolder(path) {
|
|
|
16070
16107
|
}
|
|
16071
16108
|
|
|
16072
16109
|
// src/ack-reaction.ts
|
|
16073
|
-
import { readdirSync, readFileSync as
|
|
16074
|
-
import { join as
|
|
16110
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync6 } from "fs";
|
|
16111
|
+
import { join as join6 } from "path";
|
|
16075
16112
|
|
|
16076
16113
|
// src/flags-cache-read.ts
|
|
16077
|
-
import { existsSync as existsSync4, readFileSync as
|
|
16114
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
16078
16115
|
import { homedir as homedir2 } from "os";
|
|
16079
|
-
import { join as
|
|
16116
|
+
import { join as join5 } from "path";
|
|
16080
16117
|
function defaultFlagsCachePath() {
|
|
16081
|
-
return
|
|
16118
|
+
return join5(homedir2(), ".augmented", "flags-cache.json");
|
|
16082
16119
|
}
|
|
16083
16120
|
function envBoolean(raw) {
|
|
16084
16121
|
if (raw === void 0) return void 0;
|
|
@@ -16091,7 +16128,7 @@ function envBoolean(raw) {
|
|
|
16091
16128
|
function cachedBoolean(key2, path) {
|
|
16092
16129
|
try {
|
|
16093
16130
|
if (!existsSync4(path)) return void 0;
|
|
16094
|
-
const parsed = JSON.parse(
|
|
16131
|
+
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
16095
16132
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
16096
16133
|
const flags = parsed.flags;
|
|
16097
16134
|
if (!flags || typeof flags !== "object") return void 0;
|
|
@@ -16171,7 +16208,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
|
16171
16208
|
function readGiveUpSignalAtMs(path, now = Date.now()) {
|
|
16172
16209
|
if (!path) return null;
|
|
16173
16210
|
try {
|
|
16174
|
-
const raw = JSON.parse(
|
|
16211
|
+
const raw = JSON.parse(readFileSync6(path, "utf8"));
|
|
16175
16212
|
if (typeof raw.gave_up_at !== "string") return null;
|
|
16176
16213
|
const t = Date.parse(raw.gave_up_at);
|
|
16177
16214
|
if (!Number.isFinite(t) || t > now) return null;
|
|
@@ -16194,7 +16231,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now()) {
|
|
|
16194
16231
|
if (!dir) return null;
|
|
16195
16232
|
let names;
|
|
16196
16233
|
try {
|
|
16197
|
-
names =
|
|
16234
|
+
names = readdirSync2(dir);
|
|
16198
16235
|
} catch {
|
|
16199
16236
|
return null;
|
|
16200
16237
|
}
|
|
@@ -16203,7 +16240,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now()) {
|
|
|
16203
16240
|
if (!name.endsWith(".json")) continue;
|
|
16204
16241
|
let receivedAt;
|
|
16205
16242
|
try {
|
|
16206
|
-
const raw = JSON.parse(
|
|
16243
|
+
const raw = JSON.parse(readFileSync6(join6(dir, name), "utf-8"));
|
|
16207
16244
|
if (raw.discretionary === true) continue;
|
|
16208
16245
|
receivedAt = raw.received_at;
|
|
16209
16246
|
} catch {
|
|
@@ -16252,7 +16289,7 @@ function redactId(id) {
|
|
|
16252
16289
|
}
|
|
16253
16290
|
var BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
|
|
16254
16291
|
var AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME ?? "unknown";
|
|
16255
|
-
var TELEGRAM_AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ?
|
|
16292
|
+
var TELEGRAM_AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join7(homedir3(), ".augmented", AGENT_CODE_NAME) : null;
|
|
16256
16293
|
var AGT_HOST = process.env.AGT_HOST ?? null;
|
|
16257
16294
|
var AGT_API_KEY = process.env.AGT_API_KEY ?? null;
|
|
16258
16295
|
var AGT_AGENT_ID = process.env.AGT_AGENT_ID ?? null;
|
|
@@ -16346,9 +16383,9 @@ if (!BOT_TOKEN) {
|
|
|
16346
16383
|
var stderrLogStream = null;
|
|
16347
16384
|
if (AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown") {
|
|
16348
16385
|
try {
|
|
16349
|
-
const logDir =
|
|
16386
|
+
const logDir = join7(homedir3(), ".augmented", AGENT_CODE_NAME);
|
|
16350
16387
|
mkdirSync4(logDir, { recursive: true });
|
|
16351
|
-
stderrLogStream = createWriteStream(
|
|
16388
|
+
stderrLogStream = createWriteStream(join7(logDir, "telegram-channel-stderr.log"), {
|
|
16352
16389
|
flags: "a",
|
|
16353
16390
|
mode: 384
|
|
16354
16391
|
});
|
|
@@ -16538,7 +16575,7 @@ function scheduleBusyAck(chatId, messageId) {
|
|
|
16538
16575
|
let paneLogFreshAgeMs = null;
|
|
16539
16576
|
if (AGENT_DIR) {
|
|
16540
16577
|
try {
|
|
16541
|
-
const paneMtimeMs =
|
|
16578
|
+
const paneMtimeMs = statSync2(join7(AGENT_DIR, "pane.log")).mtimeMs;
|
|
16542
16579
|
paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
|
|
16543
16580
|
} catch {
|
|
16544
16581
|
}
|
|
@@ -16560,7 +16597,7 @@ function scheduleBusyAck(chatId, messageId) {
|
|
|
16560
16597
|
function __resetBusyAckNoticeThrottle() {
|
|
16561
16598
|
lastBusyAckNoticeAt.clear();
|
|
16562
16599
|
}
|
|
16563
|
-
var RESTART_FLAGS_DIR =
|
|
16600
|
+
var RESTART_FLAGS_DIR = join7(homedir3(), ".augmented", "restart-flags");
|
|
16564
16601
|
function writeTelegramRestartConfirm(reply, requesterName) {
|
|
16565
16602
|
if (!RESTART_CONFIRM_FILE) return;
|
|
16566
16603
|
const marker = {
|
|
@@ -16753,7 +16790,7 @@ async function handleRestartCommand(opts) {
|
|
|
16753
16790
|
if (!existsSync5(RESTART_FLAGS_DIR)) {
|
|
16754
16791
|
mkdirSync4(RESTART_FLAGS_DIR, { recursive: true });
|
|
16755
16792
|
}
|
|
16756
|
-
const flagPath =
|
|
16793
|
+
const flagPath = join7(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
|
|
16757
16794
|
writeTelegramRestartConfirm(
|
|
16758
16795
|
{ chat_id: opts.chatId, message_id: opts.messageId },
|
|
16759
16796
|
opts.requesterName
|
|
@@ -17136,10 +17173,10 @@ async function classifyRestartCommand(text) {
|
|
|
17136
17173
|
if (!ours) return "verification_failed";
|
|
17137
17174
|
return target === ours ? "act" : "ignore";
|
|
17138
17175
|
}
|
|
17139
|
-
var AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ?
|
|
17140
|
-
var PENDING_INBOUND_DIR = AGENT_DIR ?
|
|
17141
|
-
var RECOVERY_OUTBOX_DIR = AGENT_DIR ?
|
|
17142
|
-
var RESTART_CONFIRM_FILE = AGENT_DIR ?
|
|
17176
|
+
var AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join7(homedir3(), ".augmented", AGENT_CODE_NAME) : null;
|
|
17177
|
+
var PENDING_INBOUND_DIR = AGENT_DIR ? join7(AGENT_DIR, "telegram-pending-inbound") : null;
|
|
17178
|
+
var RECOVERY_OUTBOX_DIR = AGENT_DIR ? join7(AGENT_DIR, "telegram-recovery-outbox") : null;
|
|
17179
|
+
var RESTART_CONFIRM_FILE = AGENT_DIR ? join7(AGENT_DIR, "telegram-restart-confirm.json") : null;
|
|
17143
17180
|
var TELEGRAM_PROCESS_BOOT_MS = Date.now();
|
|
17144
17181
|
function safeMarkerName(chatId, messageId) {
|
|
17145
17182
|
const safe = (s) => s.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
@@ -17147,7 +17184,7 @@ function safeMarkerName(chatId, messageId) {
|
|
|
17147
17184
|
}
|
|
17148
17185
|
function pendingInboundPath(chatId, messageId) {
|
|
17149
17186
|
if (!PENDING_INBOUND_DIR) return null;
|
|
17150
|
-
return
|
|
17187
|
+
return join7(PENDING_INBOUND_DIR, safeMarkerName(chatId, messageId));
|
|
17151
17188
|
}
|
|
17152
17189
|
function writePendingInboundMarker(chatId, messageId, chatType, undeliverable = false, payload) {
|
|
17153
17190
|
const path = pendingInboundPath(chatId, messageId);
|
|
@@ -17176,7 +17213,7 @@ function writePendingInboundMarker(chatId, messageId, chatType, undeliverable =
|
|
|
17176
17213
|
function clearTelegramMarkerFileWithHeal(fullPath) {
|
|
17177
17214
|
let marker = null;
|
|
17178
17215
|
try {
|
|
17179
|
-
marker = JSON.parse(
|
|
17216
|
+
marker = JSON.parse(readFileSync7(fullPath, "utf-8"));
|
|
17180
17217
|
} catch {
|
|
17181
17218
|
}
|
|
17182
17219
|
if (marker && decideRecoveryHeal({
|
|
@@ -17190,16 +17227,11 @@ function clearTelegramMarkerFileWithHeal(fullPath) {
|
|
|
17190
17227
|
} catch {
|
|
17191
17228
|
}
|
|
17192
17229
|
}
|
|
17193
|
-
function clearPendingInboundMarker(chatId, messageId) {
|
|
17194
|
-
const path = pendingInboundPath(chatId, messageId);
|
|
17195
|
-
if (!path) return;
|
|
17196
|
-
clearTelegramMarkerFileWithHeal(path);
|
|
17197
|
-
}
|
|
17198
17230
|
function readPendingInboundMarker(chatId, messageId) {
|
|
17199
17231
|
const path = pendingInboundPath(chatId, messageId);
|
|
17200
17232
|
if (!path || !existsSync5(path)) return null;
|
|
17201
17233
|
try {
|
|
17202
|
-
return JSON.parse(
|
|
17234
|
+
return JSON.parse(readFileSync7(path, "utf-8"));
|
|
17203
17235
|
} catch {
|
|
17204
17236
|
return null;
|
|
17205
17237
|
}
|
|
@@ -17219,10 +17251,10 @@ function nextRetryName(filename) {
|
|
|
17219
17251
|
async function processRecoveryOutboxFile(filename) {
|
|
17220
17252
|
if (!RECOVERY_OUTBOX_DIR) return;
|
|
17221
17253
|
if (filename.endsWith(".poison.json") || filename.endsWith(".tmp")) return;
|
|
17222
|
-
const fullPath =
|
|
17254
|
+
const fullPath = join7(RECOVERY_OUTBOX_DIR, filename);
|
|
17223
17255
|
let payload;
|
|
17224
17256
|
try {
|
|
17225
|
-
const raw =
|
|
17257
|
+
const raw = readFileSync7(fullPath, "utf-8");
|
|
17226
17258
|
payload = JSON.parse(raw);
|
|
17227
17259
|
} catch (err) {
|
|
17228
17260
|
process.stderr.write(
|
|
@@ -17254,6 +17286,7 @@ async function processRecoveryOutboxFile(filename) {
|
|
|
17254
17286
|
};
|
|
17255
17287
|
if (payload.message_id) body.reply_to_message_id = Number(payload.message_id);
|
|
17256
17288
|
let sendSucceeded = false;
|
|
17289
|
+
const recoveryDrainCutoffMs = Date.now();
|
|
17257
17290
|
try {
|
|
17258
17291
|
const resp = await telegramApiCall("sendMessage", body, 15e3);
|
|
17259
17292
|
if (resp.ok) {
|
|
@@ -17262,7 +17295,7 @@ async function processRecoveryOutboxFile(filename) {
|
|
|
17262
17295
|
`telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery sent (chat=${redactId(payload.chat_id)} msg=${redactId(payload.message_id ?? "")})
|
|
17263
17296
|
`
|
|
17264
17297
|
);
|
|
17265
|
-
|
|
17298
|
+
clearPendingMessage(payload.chat_id, recoveryDrainCutoffMs);
|
|
17266
17299
|
} else {
|
|
17267
17300
|
process.stderr.write(
|
|
17268
17301
|
`telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery failed (chat=${redactId(payload.chat_id)}): ${resp.description ?? "unknown"}
|
|
@@ -17285,7 +17318,7 @@ async function processRecoveryOutboxFile(filename) {
|
|
|
17285
17318
|
const next = nextRetryName(filename);
|
|
17286
17319
|
if (next) {
|
|
17287
17320
|
try {
|
|
17288
|
-
renameSync4(fullPath,
|
|
17321
|
+
renameSync4(fullPath, join7(RECOVERY_OUTBOX_DIR, next.next));
|
|
17289
17322
|
if (next.attempt >= MAX_RECOVERY_ATTEMPTS) {
|
|
17290
17323
|
process.stderr.write(
|
|
17291
17324
|
`telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
|
|
@@ -17316,7 +17349,7 @@ function scanRecoveryRetries() {
|
|
|
17316
17349
|
if (!RECOVERY_OUTBOX_DIR) return;
|
|
17317
17350
|
let entries;
|
|
17318
17351
|
try {
|
|
17319
|
-
entries =
|
|
17352
|
+
entries = readdirSync3(RECOVERY_OUTBOX_DIR);
|
|
17320
17353
|
} catch {
|
|
17321
17354
|
return;
|
|
17322
17355
|
}
|
|
@@ -17325,7 +17358,7 @@ function scanRecoveryRetries() {
|
|
|
17325
17358
|
if (!f.includes(".retry-") || f.endsWith(".poison.json")) continue;
|
|
17326
17359
|
let mtimeMs;
|
|
17327
17360
|
try {
|
|
17328
|
-
mtimeMs =
|
|
17361
|
+
mtimeMs = statSync2(join7(RECOVERY_OUTBOX_DIR, f)).mtimeMs;
|
|
17329
17362
|
} catch {
|
|
17330
17363
|
continue;
|
|
17331
17364
|
}
|
|
@@ -17346,7 +17379,7 @@ function startRecoveryOutboxWatcher() {
|
|
|
17346
17379
|
return;
|
|
17347
17380
|
}
|
|
17348
17381
|
try {
|
|
17349
|
-
for (const f of
|
|
17382
|
+
for (const f of readdirSync3(RECOVERY_OUTBOX_DIR)) {
|
|
17350
17383
|
if (isFirstAttemptOutboxFile(f)) void processRecoveryOutboxFile(f);
|
|
17351
17384
|
}
|
|
17352
17385
|
} catch {
|
|
@@ -17355,7 +17388,7 @@ function startRecoveryOutboxWatcher() {
|
|
|
17355
17388
|
const watcher = watch(RECOVERY_OUTBOX_DIR, (event, filename) => {
|
|
17356
17389
|
if (event !== "rename" || !filename) return;
|
|
17357
17390
|
if (!isFirstAttemptOutboxFile(filename)) return;
|
|
17358
|
-
if (existsSync5(
|
|
17391
|
+
if (existsSync5(join7(RECOVERY_OUTBOX_DIR, filename))) {
|
|
17359
17392
|
void processRecoveryOutboxFile(filename);
|
|
17360
17393
|
}
|
|
17361
17394
|
});
|
|
@@ -17379,7 +17412,7 @@ function sweepTelegramStaleMarkers(thresholdMs) {
|
|
|
17379
17412
|
if (!existsSync5(PENDING_INBOUND_DIR)) return;
|
|
17380
17413
|
let filenames;
|
|
17381
17414
|
try {
|
|
17382
|
-
filenames =
|
|
17415
|
+
filenames = readdirSync3(PENDING_INBOUND_DIR);
|
|
17383
17416
|
} catch (err) {
|
|
17384
17417
|
process.stderr.write(
|
|
17385
17418
|
`telegram-channel(${AGENT_CODE_NAME}): stale-marker readdir failed: ${err.message}
|
|
@@ -17392,10 +17425,10 @@ function sweepTelegramStaleMarkers(thresholdMs) {
|
|
|
17392
17425
|
for (const filename of filenames) {
|
|
17393
17426
|
if (!filename.endsWith(".json")) continue;
|
|
17394
17427
|
if (filename.endsWith(".tmp")) continue;
|
|
17395
|
-
const fullPath =
|
|
17428
|
+
const fullPath = join7(PENDING_INBOUND_DIR, filename);
|
|
17396
17429
|
let marker;
|
|
17397
17430
|
try {
|
|
17398
|
-
marker = JSON.parse(
|
|
17431
|
+
marker = JSON.parse(readFileSync7(fullPath, "utf-8"));
|
|
17399
17432
|
} catch (err) {
|
|
17400
17433
|
process.stderr.write(
|
|
17401
17434
|
`telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
|
|
@@ -17437,11 +17470,11 @@ function listPendingInboundChatIds() {
|
|
|
17437
17470
|
if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return [];
|
|
17438
17471
|
const chats = /* @__PURE__ */ new Set();
|
|
17439
17472
|
try {
|
|
17440
|
-
for (const name of
|
|
17473
|
+
for (const name of readdirSync3(PENDING_INBOUND_DIR)) {
|
|
17441
17474
|
if (!name.endsWith(".json")) continue;
|
|
17442
17475
|
try {
|
|
17443
17476
|
const marker = JSON.parse(
|
|
17444
|
-
|
|
17477
|
+
readFileSync7(join7(PENDING_INBOUND_DIR, name), "utf8")
|
|
17445
17478
|
);
|
|
17446
17479
|
if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
|
|
17447
17480
|
} catch {
|
|
@@ -17482,7 +17515,7 @@ async function notifyWatchdogGiveUp(chatId) {
|
|
|
17482
17515
|
}
|
|
17483
17516
|
function checkWatchdogGiveUpNotice() {
|
|
17484
17517
|
if (!AGENT_DIR) return;
|
|
17485
|
-
const signalAtMs = readGiveUpSignalAtMs(
|
|
17518
|
+
const signalAtMs = readGiveUpSignalAtMs(join7(AGENT_DIR, GIVE_UP_SIGNAL_FILENAME));
|
|
17486
17519
|
const act = decideGiveUpNotice({
|
|
17487
17520
|
signalAtMs,
|
|
17488
17521
|
lastHandledAtMs: lastGiveUpHandledAtMs,
|
|
@@ -17532,6 +17565,7 @@ async function deliverQueuedReply(p) {
|
|
|
17532
17565
|
}
|
|
17533
17566
|
const body = { chat_id: p.chatId, text: p.text };
|
|
17534
17567
|
if (p.replyToMessageId) body.reply_to_message_id = Number(p.replyToMessageId);
|
|
17568
|
+
const drainCutoffMs = Date.now();
|
|
17535
17569
|
const data = await telegramApiCall("sendMessage", body, 15e3);
|
|
17536
17570
|
if (!data.ok) {
|
|
17537
17571
|
process.stderr.write(
|
|
@@ -17542,7 +17576,7 @@ async function deliverQueuedReply(p) {
|
|
|
17542
17576
|
}
|
|
17543
17577
|
recordReply(p.chatId, "", Date.now(), p.throttleCfg);
|
|
17544
17578
|
if (p.isReplyTool) {
|
|
17545
|
-
clearPendingMessage(p.chatId,
|
|
17579
|
+
clearPendingMessage(p.chatId, drainCutoffMs);
|
|
17546
17580
|
}
|
|
17547
17581
|
process.stderr.write(
|
|
17548
17582
|
`telegram-channel(${AGENT_CODE_NAME}): reply_queue_delivered chat=${redactId(p.chatId)}
|
|
@@ -17555,29 +17589,18 @@ async function deliverQueuedReply(p) {
|
|
|
17555
17589
|
);
|
|
17556
17590
|
}
|
|
17557
17591
|
}
|
|
17558
|
-
function clearPendingMessage(chatId,
|
|
17559
|
-
if (messageId) {
|
|
17560
|
-
clearPendingInboundMarker(chatId, messageId);
|
|
17561
|
-
return;
|
|
17562
|
-
}
|
|
17592
|
+
function clearPendingMessage(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
|
|
17563
17593
|
if (!PENDING_INBOUND_DIR || !existsSync5(PENDING_INBOUND_DIR)) return;
|
|
17564
|
-
|
|
17565
|
-
|
|
17566
|
-
|
|
17567
|
-
|
|
17568
|
-
|
|
17569
|
-
|
|
17570
|
-
return;
|
|
17571
|
-
}
|
|
17572
|
-
for (const filename of filenames) {
|
|
17573
|
-
if (!filename.startsWith(prefix)) continue;
|
|
17574
|
-
if (!filename.endsWith(".json")) continue;
|
|
17575
|
-
clearTelegramMarkerFileWithHeal(join6(PENDING_INBOUND_DIR, filename));
|
|
17576
|
-
}
|
|
17594
|
+
clearAllTelegramPendingMarkersForChat(
|
|
17595
|
+
PENDING_INBOUND_DIR,
|
|
17596
|
+
chatId,
|
|
17597
|
+
clearTelegramMarkerFileWithHeal,
|
|
17598
|
+
cutoffMs
|
|
17599
|
+
);
|
|
17577
17600
|
}
|
|
17578
|
-
function noteThreadActivity(chatId,
|
|
17601
|
+
function noteThreadActivity(chatId, cutoffMs = Number.POSITIVE_INFINITY) {
|
|
17579
17602
|
if (!chatId) return;
|
|
17580
|
-
clearPendingMessage(chatId,
|
|
17603
|
+
clearPendingMessage(chatId, cutoffMs);
|
|
17581
17604
|
}
|
|
17582
17605
|
var mcp = new Server(
|
|
17583
17606
|
{ name: "telegram", version: "0.1.0" },
|
|
@@ -17841,6 +17864,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
17841
17864
|
try {
|
|
17842
17865
|
const body = { chat_id, text };
|
|
17843
17866
|
if (reply_to_message_id) body.reply_to_message_id = Number(reply_to_message_id);
|
|
17867
|
+
const drainCutoffMs = Date.now();
|
|
17844
17868
|
const data = await telegramApiCall("sendMessage", body, 15e3);
|
|
17845
17869
|
if (!data.ok) {
|
|
17846
17870
|
return {
|
|
@@ -17850,7 +17874,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
17850
17874
|
}
|
|
17851
17875
|
recordReply(chat_id, "", tgThrottleNow, tgThrottleCfg);
|
|
17852
17876
|
if (name === "telegram.reply") {
|
|
17853
|
-
clearPendingMessage(chat_id,
|
|
17877
|
+
clearPendingMessage(chat_id, drainCutoffMs);
|
|
17854
17878
|
}
|
|
17855
17879
|
return { content: [{ type: "text", text: "sent" }] };
|
|
17856
17880
|
} catch (err) {
|
|
@@ -17868,7 +17892,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
17868
17892
|
isError: true
|
|
17869
17893
|
};
|
|
17870
17894
|
}
|
|
17871
|
-
|
|
17895
|
+
const drainCutoffMs = Date.now();
|
|
17872
17896
|
try {
|
|
17873
17897
|
const data = await telegramApiCall(
|
|
17874
17898
|
"setMessageReaction",
|
|
@@ -17885,6 +17909,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
17885
17909
|
isError: true
|
|
17886
17910
|
};
|
|
17887
17911
|
}
|
|
17912
|
+
noteThreadActivity(chat_id, drainCutoffMs);
|
|
17888
17913
|
return { content: [{ type: "text", text: emoji2 ? "reacted" : "cleared" }] };
|
|
17889
17914
|
} catch (err) {
|
|
17890
17915
|
return {
|
|
@@ -18177,7 +18202,7 @@ async function replayPendingTelegramMarkers() {
|
|
|
18177
18202
|
if (!sessionAlive) return;
|
|
18178
18203
|
let filenames;
|
|
18179
18204
|
try {
|
|
18180
|
-
filenames =
|
|
18205
|
+
filenames = readdirSync3(PENDING_INBOUND_DIR);
|
|
18181
18206
|
} catch {
|
|
18182
18207
|
return;
|
|
18183
18208
|
}
|
|
@@ -18185,10 +18210,10 @@ async function replayPendingTelegramMarkers() {
|
|
|
18185
18210
|
const entries = [];
|
|
18186
18211
|
for (const name of filenames) {
|
|
18187
18212
|
if (!name.endsWith(".json") || name.endsWith(".tmp")) continue;
|
|
18188
|
-
const fullPath =
|
|
18213
|
+
const fullPath = join7(PENDING_INBOUND_DIR, name);
|
|
18189
18214
|
let marker;
|
|
18190
18215
|
try {
|
|
18191
|
-
marker = JSON.parse(
|
|
18216
|
+
marker = JSON.parse(readFileSync7(fullPath, "utf-8"));
|
|
18192
18217
|
} catch {
|
|
18193
18218
|
continue;
|
|
18194
18219
|
}
|
|
@@ -18596,7 +18621,7 @@ async function pollLoop() {
|
|
|
18596
18621
|
let paneLogFreshAgeMs = null;
|
|
18597
18622
|
if (AGENT_DIR) {
|
|
18598
18623
|
try {
|
|
18599
|
-
const paneMtimeMs =
|
|
18624
|
+
const paneMtimeMs = statSync2(join7(AGENT_DIR, "pane.log")).mtimeMs;
|
|
18600
18625
|
paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
|
|
18601
18626
|
} catch {
|
|
18602
18627
|
}
|
package/package.json
CHANGED
|
File without changes
|