@integrity-labs/agt-cli 0.28.474 → 0.28.475

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.
@@ -18906,7 +18906,7 @@ var require_filters = __commonJS({
18906
18906
  return r.copySafeness(str, res);
18907
18907
  }
18908
18908
  _exports.indent = indent;
18909
- function join18(arr, del, attr) {
18909
+ function join17(arr, del, attr) {
18910
18910
  del = del || "";
18911
18911
  if (attr) {
18912
18912
  arr = lib.map(arr, function(v) {
@@ -18915,7 +18915,7 @@ var require_filters = __commonJS({
18915
18915
  }
18916
18916
  return arr.join(del);
18917
18917
  }
18918
- _exports.join = join18;
18918
+ _exports.join = join17;
18919
18919
  function last(arr) {
18920
18920
  return arr[arr.length - 1];
18921
18921
  }
@@ -30132,7 +30132,7 @@ import {
30132
30132
  ftruncateSync,
30133
30133
  mkdirSync as mkdirSync9,
30134
30134
  openSync,
30135
- readFileSync as readFileSync17,
30135
+ readFileSync as readFileSync16,
30136
30136
  readdirSync as readdirSync6,
30137
30137
  realpathSync,
30138
30138
  renameSync as renameSync7,
@@ -30142,8 +30142,8 @@ import {
30142
30142
  writeFileSync as writeFileSync11,
30143
30143
  writeSync
30144
30144
  } from "fs";
30145
- import { homedir as homedir7 } from "os";
30146
- import { basename, extname, join as join17, resolve as resolve2 } from "path";
30145
+ import { homedir as homedir6 } from "os";
30146
+ import { basename, extname, join as join16, resolve as resolve2 } from "path";
30147
30147
 
30148
30148
  // ../core/dist/channels/interim-promise.js
30149
30149
  function decideMarkerEngagement(marker, kind, nowIso) {
@@ -30758,40 +30758,6 @@ function resolveGhostReplyMode(opts) {
30758
30758
  if (cached2 !== void 0) return cached2;
30759
30759
  return "off";
30760
30760
  }
30761
- var USAGE_LIMIT_REACTIVE_FLAG_KEY = "usage-limit-reactive-notice";
30762
- function parseUsageLimitReactiveMode(raw) {
30763
- if (raw === void 0) return void 0;
30764
- const v = raw.trim().toLowerCase();
30765
- if (v === "") return void 0;
30766
- if (v === "off" || v === "shadow" || v === "enforce") return v;
30767
- const b = envBoolean(raw);
30768
- if (b === true) return "enforce";
30769
- if (b === false) return "off";
30770
- return void 0;
30771
- }
30772
- function cachedUsageLimitReactiveMode(path) {
30773
- try {
30774
- if (!existsSync2(path)) return void 0;
30775
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
30776
- if (!parsed || typeof parsed !== "object") return void 0;
30777
- const flags = parsed.flags;
30778
- if (!flags || typeof flags !== "object") return void 0;
30779
- const value = flags[USAGE_LIMIT_REACTIVE_FLAG_KEY];
30780
- if (typeof value === "string") return parseUsageLimitReactiveMode(value);
30781
- if (typeof value === "boolean") return value ? "enforce" : "off";
30782
- return void 0;
30783
- } catch {
30784
- return void 0;
30785
- }
30786
- }
30787
- function resolveUsageLimitReactiveMode(opts) {
30788
- const env2 = opts?.env ?? process.env;
30789
- const modeOverride = parseUsageLimitReactiveMode(env2["AGT_USAGE_LIMIT_REACTIVE_MODE"]);
30790
- if (modeOverride !== void 0) return modeOverride;
30791
- const cached2 = cachedUsageLimitReactiveMode(opts?.cachePath ?? defaultFlagsCachePath());
30792
- if (cached2 !== void 0) return cached2;
30793
- return "off";
30794
- }
30795
30761
 
30796
30762
  // src/maintenance-mode.ts
30797
30763
  var FLAG_KEY = "platform-maintenance-mode";
@@ -30806,11 +30772,6 @@ function isMaintenanceModeActive(opts) {
30806
30772
  });
30807
30773
  }
30808
30774
 
30809
- // src/usage-limit-notice.ts
30810
- import { readFileSync as readFileSync4 } from "fs";
30811
- import { homedir as homedir3 } from "os";
30812
- import { join as join3 } from "path";
30813
-
30814
30775
  // ../core/dist/types/integration.js
30815
30776
  var HITL_TIER_ORDER = [
30816
30777
  "read",
@@ -34244,30 +34205,11 @@ function parseResetDateTime(humanDate, now) {
34244
34205
  return resolved;
34245
34206
  }
34246
34207
 
34247
- // ../core/dist/claude-code-usage/usage-limit-marker.js
34248
- var USAGE_LIMIT_MARKER_FILENAME = "claude-usage-limit.json";
34249
- var USAGE_LIMIT_MARKER_VERSION = 1;
34250
- function parseUsageLimitMarker(raw) {
34251
- let parsed;
34252
- try {
34253
- parsed = JSON.parse(raw);
34254
- } catch {
34255
- return null;
34256
- }
34257
- if (typeof parsed !== "object" || parsed === null || parsed.version !== USAGE_LIMIT_MARKER_VERSION) {
34258
- return null;
34259
- }
34260
- const until = parsed.limited_until;
34261
- if (typeof until !== "string" || !Number.isFinite(Date.parse(until)))
34262
- return null;
34263
- return { version: USAGE_LIMIT_MARKER_VERSION, limited_until: until };
34264
- }
34265
- function resolveUsageLimitUntil(marker, now) {
34266
- if (!marker)
34267
- return null;
34268
- const until = new Date(marker.limited_until);
34269
- return until.getTime() > now.getTime() ? until : null;
34270
- }
34208
+ // ../core/dist/claude-code-usage/run-marker.js
34209
+ var RUN_MARKER_RE = /<!--\s*agt-run:([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})\s*-->/;
34210
+ var RUN_MARKER_RE_GLOBAL = new RegExp(RUN_MARKER_RE.source, "g");
34211
+
34212
+ // ../core/dist/claude-code-usage/usage-limit-notice-text.js
34271
34213
  function formatUtcClock(date3) {
34272
34214
  const hours = date3.getUTCHours();
34273
34215
  const minutes = date3.getUTCMinutes();
@@ -35202,42 +35144,6 @@ var FLAG_REGISTRY = [
35202
35144
  // projectDefinition, so setting it does not roll FLAGS_SCHEMA_VERSION.
35203
35145
  since: "0.28.421"
35204
35146
  },
35205
- {
35206
- key: "usage-limit-reactive-notice",
35207
- description: "Report a Claude Code usage cap REACTIVELY instead of predicting it (ENG-8201). Today the manager guesses from the agent transcript that the next turn will be refused, writes a marker, and every channel MCP refuses to dispatch on the strength of that guess - so a wrong guess is a swallowed message, and because the notice is throttled per (channel, sender) while the DROP is not, the usual symptom is total silence rather than a wrong reply. A refused turn actually costs nothing (rejected in under a second, zero tokens) and Claude Code records it with the reset time in it, so there is no need to guess: dispatch, and report the refusal if one comes back. off = today behaviour (pre-dispatch marker gate, no watcher). shadow = still gate on the marker, but ALSO watch dispatched messages and log the refusal that would have been reported - measures the true-positive rate with no user-visible change. enforce = stop reading the marker before dispatch; every admitted human message reaches the agent and a refusal is answered in-thread with the reset time from the error itself. Read live from the heartbeat flags-cache (or the env override).",
35208
- flagType: "enum",
35209
- allowedValues: ["off", "shadow", "enforce"],
35210
- // Ships dark: off preserves today's gate byte-for-byte. shadow is a free
35211
- // local log line (the watch is a transcript read, no model spend), so it is a
35212
- // cheap soak; enforce changes what reaches the agent, so it is the audited
35213
- // per-org flip.
35214
- defaultValue: "off",
35215
- // Enum override AGT_USAGE_LIMIT_REACTIVE_MODE (off|shadow|enforce), resolved
35216
- // by resolveUsageLimitReactiveMode in the channel-server bundle.
35217
- envVar: "AGT_USAGE_LIMIT_REACTIVE_MODE",
35218
- // enforce sends a message to an agent the host currently believes is capped -
35219
- // a deliberate availability trade (the refusal is free, but it is still a
35220
- // dispatch the operator previously suppressed), so flipping toward it is an
35221
- // audited change (ADR-0022 sensitive-flag confirm).
35222
- sensitive: true,
35223
- // ENG-8149 / ENG-8229: the agt-cli that first carries
35224
- // resolveUsageLimitReactiveMode in ALL THREE channel servers - published from
35225
- // the ENG-8207 merge 0294fa1a8. Without this the flip-reach modal reports FULL
35226
- // reach, because an undefined `since` means "every host can honour it" - true
35227
- // for flags that predate the reach work, wrong for a NEW host-read flag whose
35228
- // reader older hosts simply do not have. Excluded from projectDefinition, so
35229
- // setting it does not roll FLAGS_SCHEMA_VERSION.
35230
- //
35231
- // Deliberately the LATER of the two versions this flag's reader shipped in.
35232
- // Unlike its siblings, this reader landed in two stages: direct-chat at the
35233
- // ENG-8201 Slice 2 publish, slack + telegram only at 0.28.450 (ENG-8207) - and
35234
- // `since` is one version per flag, so it cannot express "partially honoured".
35235
- // A host in between genuinely honours the flag for direct-chat and is still
35236
- // classified `stale`. That understates reach rather than overstating it, which
35237
- // is the safe direction, and it is the useful one while the flag sits at
35238
- // enforce and slack/telegram adoption is what an operator needs to track.
35239
- since: "0.28.450"
35240
- },
35241
35147
  {
35242
35148
  key: "slack-hot-thread-guard",
35243
35149
  description: "Server-side hot-thread guard on the slack.reply surface (ENG-7462). Prevents an agent posting a NEW top-level Slack message when it meant to reply inside the thread it is already working in - a prompt/memory rule proved insufficient (the agent had the rule and still slipped). When a reply would otherwise post to channel ROOT (no thread_ts / message_ts / inbound_id, no active kanban card) and the agent has a recent active thread in that channel (its last bot-posted thread, from the persisted trackedThreads cache, within a freshness window), the reply is redirected into that thread. proactive:true no longer implies channel root; posting at root becomes a deliberate action (the to_channel_root flag, or the thread_ts:null sentinel). off = guard never runs, replies with no coords root exactly as today (ships dark). shadow = compute + log the would-redirect but STILL post to root (measure the fire rate before acting). enforce = apply the redirect (a soft-block: redirect + inform, never a hard rejection). Read live from the heartbeat flags-cache (or the env override); enforce is a deliberate per-org flip after a shadow soak.",
@@ -35944,37 +35850,20 @@ function deriveBindFailureQuarantineThreshold(provisioningMax) {
35944
35850
  }
35945
35851
  var MIN_PROVISIONING_MAX_FOR_QUARANTINE_ORDERING = BIND_FAILURE_QUARANTINE_THRESHOLD + 1;
35946
35852
 
35947
- // src/usage-limit-notice.ts
35948
- function usageLimitMarkerPath(codeName) {
35949
- if (!codeName) return null;
35950
- return join3(homedir3(), ".augmented", codeName, USAGE_LIMIT_MARKER_FILENAME);
35951
- }
35952
- function readUsageLimitUntil(opts) {
35953
- const path = opts.filePath ?? usageLimitMarkerPath(opts.codeName);
35954
- if (!path) return null;
35955
- let raw;
35956
- try {
35957
- raw = readFileSync4(path, "utf-8");
35958
- } catch {
35959
- return null;
35960
- }
35961
- return resolveUsageLimitUntil(parseUsageLimitMarker(raw), opts.now ?? /* @__PURE__ */ new Date());
35962
- }
35963
-
35964
35853
  // src/account-enforcement-notice.ts
35965
- import { readFileSync as readFileSync5 } from "fs";
35966
- import { homedir as homedir4 } from "os";
35967
- import { join as join4 } from "path";
35854
+ import { readFileSync as readFileSync4 } from "fs";
35855
+ import { homedir as homedir3 } from "os";
35856
+ import { join as join3 } from "path";
35968
35857
  function accountEnforcementMarkerPath(codeName) {
35969
35858
  if (!codeName) return null;
35970
- return join4(homedir4(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
35859
+ return join3(homedir3(), ".augmented", codeName, ACCOUNT_ENFORCEMENT_MARKER_FILENAME);
35971
35860
  }
35972
35861
  function readAccountEnforcementLevel(opts) {
35973
35862
  const path = opts.filePath ?? accountEnforcementMarkerPath(opts.codeName);
35974
35863
  if (!path) return null;
35975
35864
  let raw;
35976
35865
  try {
35977
- raw = readFileSync5(path, "utf-8");
35866
+ raw = readFileSync4(path, "utf-8");
35978
35867
  } catch {
35979
35868
  return null;
35980
35869
  }
@@ -35993,13 +35882,13 @@ function shouldSendAccountWarn(opts) {
35993
35882
  }
35994
35883
 
35995
35884
  // src/turn-initiator-marker.ts
35996
- import { writeFileSync as writeFileSync4, readFileSync as readFileSync6, mkdirSync as mkdirSync4, renameSync as renameSync3 } from "fs";
35997
- import { dirname as dirname3, join as join5 } from "path";
35885
+ import { writeFileSync as writeFileSync4, readFileSync as readFileSync5, mkdirSync as mkdirSync4, renameSync as renameSync3 } from "fs";
35886
+ import { dirname as dirname3, join as join4 } from "path";
35998
35887
  var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
35999
35888
  var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
36000
35889
  var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
36001
35890
  function turnInitiatorLedgerPath(singleSlotFile) {
36002
- return join5(dirname3(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
35891
+ return join4(dirname3(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
36003
35892
  }
36004
35893
  function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
36005
35894
  const now = marker.ts;
@@ -36024,7 +35913,7 @@ function updateTurnInitiatorLedger(singleSlotFile, marker) {
36024
35913
  const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
36025
35914
  let existing = null;
36026
35915
  try {
36027
- const parsed = JSON.parse(readFileSync6(ledgerFile, "utf8"));
35916
+ const parsed = JSON.parse(readFileSync5(ledgerFile, "utf8"));
36028
35917
  if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
36029
35918
  } catch {
36030
35919
  }
@@ -36051,14 +35940,14 @@ function writeTurnInitiatorMarker(input) {
36051
35940
  }
36052
35941
 
36053
35942
  // src/scheduled-turn-marker.ts
36054
- import { readFileSync as readFileSync7, unlinkSync as unlinkSync4 } from "fs";
36055
- import { join as join6 } from "path";
35943
+ import { readFileSync as readFileSync6, unlinkSync as unlinkSync4 } from "fs";
35944
+ import { join as join5 } from "path";
36056
35945
  var SCHEDULED_TURN_MARKER_FILENAME2 = ".current-scheduled-turn.json";
36057
35946
  var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
36058
35947
  function clearScheduledTurnMarker(agentDir) {
36059
35948
  if (!agentDir) return;
36060
35949
  try {
36061
- unlinkSync4(join6(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
35950
+ unlinkSync4(join5(agentDir, SCHEDULED_TURN_MARKER_FILENAME2));
36062
35951
  } catch {
36063
35952
  }
36064
35953
  }
@@ -36710,7 +36599,7 @@ function buildCommandRegistrations() {
36710
36599
  import {
36711
36600
  existsSync as existsSync3,
36712
36601
  mkdirSync as mkdirSync5,
36713
- readFileSync as readFileSync8,
36602
+ readFileSync as readFileSync7,
36714
36603
  renameSync as renameSync4,
36715
36604
  unlinkSync as unlinkSync5,
36716
36605
  writeFileSync as writeFileSync5
@@ -36720,7 +36609,7 @@ function loadPersistedOffset(filePath) {
36720
36609
  if (!filePath) return 0;
36721
36610
  try {
36722
36611
  const parsed = JSON.parse(
36723
- readFileSync8(filePath, "utf-8")
36612
+ readFileSync7(filePath, "utf-8")
36724
36613
  );
36725
36614
  const offset = parsed?.offset;
36726
36615
  if (typeof offset === "number" && Number.isFinite(offset) && offset > 0) {
@@ -36764,8 +36653,8 @@ function conversationalLaneMeta(expectsReply = true) {
36764
36653
  }
36765
36654
 
36766
36655
  // src/inbound-lane-telemetry.ts
36767
- import { readFileSync as readFileSync9, writeFileSync as writeFileSync6 } from "fs";
36768
- import { join as join7 } from "path";
36656
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "fs";
36657
+ import { join as join6 } from "path";
36769
36658
  var LANE_CLASSIFICATION_COUNTER_SUFFIX = "-lane-classifications.json";
36770
36659
  var SUSPECTED_MISCLASSIFICATION_KEY = "suspected_misclassification";
36771
36660
  var HUMAN_CHANNEL_SOURCES = /* @__PURE__ */ new Set([
@@ -36782,10 +36671,10 @@ function isSuspectedMisclassification(lane, source) {
36782
36671
  }
36783
36672
  function recordLaneClassification(agentDir, channel, classification) {
36784
36673
  if (!agentDir) return;
36785
- const path = join7(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
36674
+ const path = join6(agentDir, `${channel}${LANE_CLASSIFICATION_COUNTER_SUFFIX}`);
36786
36675
  let counts = {};
36787
36676
  try {
36788
- const parsed = JSON.parse(readFileSync9(path, "utf-8"));
36677
+ const parsed = JSON.parse(readFileSync8(path, "utf-8"));
36789
36678
  if (parsed && typeof parsed === "object") counts = parsed;
36790
36679
  } catch {
36791
36680
  }
@@ -36801,15 +36690,15 @@ function recordLaneClassification(agentDir, channel, classification) {
36801
36690
  }
36802
36691
 
36803
36692
  // src/agent-config-state.ts
36804
- import { existsSync as existsSync4, readFileSync as readFileSync10 } from "fs";
36805
- import { join as join8 } from "path";
36693
+ import { existsSync as existsSync4, readFileSync as readFileSync9 } from "fs";
36694
+ import { join as join7 } from "path";
36806
36695
  var SESSION_STATE_FILENAME = "session-state.json";
36807
36696
  function readAgentSessionState(stateDir) {
36808
36697
  if (!stateDir) return null;
36809
- const path = join8(stateDir, SESSION_STATE_FILENAME);
36698
+ const path = join7(stateDir, SESSION_STATE_FILENAME);
36810
36699
  if (!existsSync4(path)) return null;
36811
36700
  try {
36812
- const parsed = JSON.parse(readFileSync10(path, "utf-8"));
36701
+ const parsed = JSON.parse(readFileSync9(path, "utf-8"));
36813
36702
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
36814
36703
  return parsed;
36815
36704
  } catch {
@@ -37612,15 +37501,15 @@ function emitToolCallMarkupRedactionTelemetry(channel) {
37612
37501
  }
37613
37502
 
37614
37503
  // src/rate-limit-watch.ts
37615
- import { readFileSync as readFileSync11, readdirSync, statSync } from "fs";
37616
- import { homedir as homedir5 } from "os";
37617
- import { join as join9 } from "path";
37504
+ import { readFileSync as readFileSync10, readdirSync, statSync } from "fs";
37505
+ import { homedir as homedir4 } from "os";
37506
+ import { join as join8 } from "path";
37618
37507
  var DEFAULT_WATCH_MS = 5e3;
37619
37508
  var DEFAULT_POLL_MS = 400;
37620
37509
  function agentTranscriptDir(opts) {
37621
37510
  const cwd = opts?.cwd ?? process.cwd();
37622
- const home = opts?.home ?? homedir5();
37623
- return join9(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
37511
+ const home = opts?.home ?? homedir4();
37512
+ return join8(home, ".claude", "projects", encodeClaudeProjectPath(cwd));
37624
37513
  }
37625
37514
  function classifyTranscriptSince(opts) {
37626
37515
  const dir = opts.transcriptDir ?? agentTranscriptDir({ cwd: opts.cwd, home: opts.home });
@@ -37633,7 +37522,7 @@ function classifyTranscriptSince(opts) {
37633
37522
  let newest = UNKNOWN_RATE_LIMIT;
37634
37523
  for (const name of entries) {
37635
37524
  if (!name.endsWith(".jsonl")) continue;
37636
- const path = join9(dir, name);
37525
+ const path = join8(dir, name);
37637
37526
  try {
37638
37527
  const st = statSync(path);
37639
37528
  if (!st.isFile() || st.mtimeMs < opts.sinceMs) continue;
@@ -37642,7 +37531,7 @@ function classifyTranscriptSince(opts) {
37642
37531
  }
37643
37532
  let content;
37644
37533
  try {
37645
- content = readFileSync11(path, "utf-8");
37534
+ content = readFileSync10(path, "utf-8");
37646
37535
  } catch {
37647
37536
  continue;
37648
37537
  }
@@ -37681,8 +37570,8 @@ async function watchForRateLimitRefusal(opts) {
37681
37570
  }
37682
37571
 
37683
37572
  // src/turn-failure-watch.ts
37684
- import { readFileSync as readFileSync12, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
37685
- import { join as join10 } from "path";
37573
+ import { readFileSync as readFileSync11, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
37574
+ import { join as join9 } from "path";
37686
37575
  function turnFailureNoticeEnabled(env2) {
37687
37576
  return resolveHostBooleanFlag({
37688
37577
  key: "wedge-transient-notice",
@@ -37711,7 +37600,7 @@ function classifyTurnFailureSince(opts) {
37711
37600
  const unrecognised = /* @__PURE__ */ new Set();
37712
37601
  for (const name of entries) {
37713
37602
  if (!name.endsWith(".jsonl")) continue;
37714
- const path = join10(dir, name);
37603
+ const path = join9(dir, name);
37715
37604
  let fingerprint;
37716
37605
  try {
37717
37606
  const st = statSync2(path);
@@ -37727,7 +37616,7 @@ function classifyTurnFailureSince(opts) {
37727
37616
  } else {
37728
37617
  let content;
37729
37618
  try {
37730
- content = readFileSync12(path, "utf-8");
37619
+ content = readFileSync11(path, "utf-8");
37731
37620
  } catch {
37732
37621
  continue;
37733
37622
  }
@@ -37825,19 +37714,14 @@ async function watchForTurnFailure(opts) {
37825
37714
 
37826
37715
  // src/usage-limit-reactive-decision.ts
37827
37716
  import { createHash } from "crypto";
37828
- function shouldReadPredictiveMarker(mode) {
37829
- return mode !== "enforce";
37830
- }
37831
- function armedWatchMode(opts) {
37832
- if (opts.mode === "off") return null;
37833
- if (opts.isBot || !opts.replyOwed) return null;
37834
- return opts.mode;
37717
+ function shouldArmWatch(opts) {
37718
+ return !opts.isBot && opts.replyOwed;
37835
37719
  }
37836
37720
  function decideRefusalAction(opts) {
37837
37721
  const { refusal } = opts;
37838
37722
  if (!refusal || refusal.verdict !== "capped") return "none";
37839
37723
  if (!refusal.resetsAt) return "missing-reset";
37840
- return opts.mode === "shadow" ? "shadow-log" : "notify";
37724
+ return "notify";
37841
37725
  }
37842
37726
  function describeUnparsedRefusal(text) {
37843
37727
  if (!text) return "refusal=absent";
@@ -37848,8 +37732,8 @@ function describeUnparsedRefusal(text) {
37848
37732
  // src/reply-intent-runtime.ts
37849
37733
  import { execFile as execFile2 } from "child_process";
37850
37734
  import { existsSync as existsSync5, mkdirSync as mkdirSync6, writeFileSync as writeFileSync7 } from "fs";
37851
- import { homedir as homedir6 } from "os";
37852
- import { join as join11 } from "path";
37735
+ import { homedir as homedir5 } from "os";
37736
+ import { join as join10 } from "path";
37853
37737
  var DEFAULT_CLAUDE_EVAL_MODEL = "claude-haiku-4-5-20251001";
37854
37738
  var DEFAULT_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages";
37855
37739
  var ANTHROPIC_API_VERSION = "2023-06-01";
@@ -37948,12 +37832,12 @@ async function runAnthropicMessages(prompt, opts) {
37948
37832
  var emptyMcpConfigPath = null;
37949
37833
  function ensureEmptyMcpConfig() {
37950
37834
  if (emptyMcpConfigPath && existsSync5(emptyMcpConfigPath)) return emptyMcpConfigPath;
37951
- const dir = join11(homedir6(), ".augmented");
37835
+ const dir = join10(homedir5(), ".augmented");
37952
37836
  try {
37953
37837
  mkdirSync6(dir, { recursive: true });
37954
37838
  } catch {
37955
37839
  }
37956
- const p2 = join11(dir, ".reply-intent-empty-mcp.json");
37840
+ const p2 = join10(dir, ".reply-intent-empty-mcp.json");
37957
37841
  writeFileSync7(p2, JSON.stringify({ mcpServers: {} }));
37958
37842
  emptyMcpConfigPath = p2;
37959
37843
  return p2;
@@ -37978,7 +37862,7 @@ function runClaudeP(prompt, model) {
37978
37862
  execFile2(
37979
37863
  "claude",
37980
37864
  args,
37981
- { cwd: homedir6(), timeout: CLASSIFY_TIMEOUT_MS, maxBuffer: 1 << 20 },
37865
+ { cwd: homedir5(), timeout: CLASSIFY_TIMEOUT_MS, maxBuffer: 1 << 20 },
37982
37866
  (err, stdout) => {
37983
37867
  if (err) {
37984
37868
  reject(err);
@@ -38100,11 +37984,11 @@ function emitTransientApiErrorTelemetry(channel, match, original) {
38100
37984
  }
38101
37985
 
38102
37986
  // src/telegram-pending-inbound-cleanup.ts
38103
- import { readdirSync as readdirSync3, readFileSync as readFileSync13, statSync as statSync3 } from "fs";
38104
- import { join as join12 } from "path";
37987
+ import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
37988
+ import { join as join11 } from "path";
38105
37989
  function markerArrivalMs(fullPath) {
38106
37990
  try {
38107
- const received = JSON.parse(readFileSync13(fullPath, "utf-8")).received_at;
37991
+ const received = JSON.parse(readFileSync12(fullPath, "utf-8")).received_at;
38108
37992
  const parsed = received ? Date.parse(received) : Number.NaN;
38109
37993
  if (Number.isFinite(parsed)) return parsed;
38110
37994
  } catch {
@@ -38134,7 +38018,7 @@ function applyToChatMarkers(pendingDir, chatId, op, cutoffMs) {
38134
38018
  for (const filename of filenames) {
38135
38019
  if (!filename.startsWith(prefix)) continue;
38136
38020
  if (!filename.endsWith(".json")) continue;
38137
- const fullPath = join12(pendingDir, filename);
38021
+ const fullPath = join11(pendingDir, filename);
38138
38022
  if (bounded && markerArrivalMs(fullPath) > cutoffMs) continue;
38139
38023
  op(fullPath);
38140
38024
  applied++;
@@ -38144,12 +38028,12 @@ function applyToChatMarkers(pendingDir, chatId, op, cutoffMs) {
38144
38028
 
38145
38029
  // src/recovery-ledger.ts
38146
38030
  import { existsSync as existsSync6, unlinkSync as unlinkSync6 } from "fs";
38147
- import { join as join13 } from "path";
38031
+ import { join as join12 } from "path";
38148
38032
  function recoveryLedgerEntryExists(ledgerDir, markerName, exists = (p2) => existsSync6(p2)) {
38149
38033
  if (!ledgerDir || !markerName) return false;
38150
38034
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return false;
38151
38035
  try {
38152
- return exists(join13(ledgerDir, markerName));
38036
+ return exists(join12(ledgerDir, markerName));
38153
38037
  } catch {
38154
38038
  return false;
38155
38039
  }
@@ -38160,14 +38044,14 @@ function removeRecoveryLedgerEntry(ledgerDir, markerName, unlink = (p2) => {
38160
38044
  if (!ledgerDir || !markerName) return;
38161
38045
  if (markerName.includes("/") || markerName.includes("\\") || markerName.includes("..")) return;
38162
38046
  try {
38163
- unlink(join13(ledgerDir, markerName));
38047
+ unlink(join12(ledgerDir, markerName));
38164
38048
  } catch {
38165
38049
  }
38166
38050
  }
38167
38051
 
38168
38052
  // src/inbound-delivery-ledger.ts
38169
- import { existsSync as existsSync7, mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync14, renameSync as renameSync5, writeFileSync as writeFileSync8 } from "fs";
38170
- import { join as join14 } from "path";
38053
+ import { existsSync as existsSync7, mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync13, renameSync as renameSync5, writeFileSync as writeFileSync8 } from "fs";
38054
+ import { join as join13 } from "path";
38171
38055
  function safeInboundId(inboundId) {
38172
38056
  return inboundId.replace(/[^A-Za-z0-9_-]/g, "_");
38173
38057
  }
@@ -38176,7 +38060,7 @@ var defaultDeps = {
38176
38060
  writeFile: (path, data) => writeFileSync8(path, data, "utf8"),
38177
38061
  rename: (from, to) => renameSync5(from, to),
38178
38062
  readdir: (dir) => readdirSync4(dir),
38179
- readFile: (path) => readFileSync14(path, "utf8"),
38063
+ readFile: (path) => readFileSync13(path, "utf8"),
38180
38064
  exists: (path) => existsSync7(path)
38181
38065
  };
38182
38066
  function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
@@ -38185,7 +38069,7 @@ function writeInboundDeliveryLedgerEntry(dir, record2, deps = defaultDeps) {
38185
38069
  if (!safe || safe.includes("/") || safe.includes("\\") || safe.includes("..")) return;
38186
38070
  try {
38187
38071
  deps.mkdir(dir);
38188
- const final = join14(dir, `${safe}.json`);
38072
+ const final = join13(dir, `${safe}.json`);
38189
38073
  const tmp = `${final}.tmp`;
38190
38074
  deps.writeFile(tmp, JSON.stringify(record2));
38191
38075
  deps.rename(tmp, final);
@@ -38390,14 +38274,14 @@ function createKanbanCardActiveClient(args) {
38390
38274
  import {
38391
38275
  existsSync as existsSync8,
38392
38276
  mkdirSync as mkdirSync8,
38393
- readFileSync as readFileSync15,
38277
+ readFileSync as readFileSync14,
38394
38278
  renameSync as renameSync6,
38395
38279
  statSync as statSync4,
38396
38280
  unlinkSync as unlinkSync7,
38397
38281
  utimesSync,
38398
38282
  writeFileSync as writeFileSync9
38399
38283
  } from "fs";
38400
- import { join as join15 } from "path";
38284
+ import { join as join14 } from "path";
38401
38285
  var STALE_LOCK_MS = 9e4;
38402
38286
  var HEARTBEAT_INTERVAL_MS = 3e4;
38403
38287
  function defaultIsPidAlive(pid) {
@@ -38420,7 +38304,7 @@ function acquireMcpSpawnLock(args) {
38420
38304
  const nowMs = options.nowMs ?? (() => Date.now());
38421
38305
  const lockMtimeMs = options.lockMtimeMs ?? defaultLockMtimeMs;
38422
38306
  const staleMs = options.staleMs ?? STALE_LOCK_MS;
38423
- const path = join15(agentDir, basename2);
38307
+ const path = join14(agentDir, basename2);
38424
38308
  const existing = readLockHolder(path);
38425
38309
  if (existing) {
38426
38310
  if (existing.pid === selfPid) {
@@ -38487,7 +38371,7 @@ function defaultLockMtimeMs(path) {
38487
38371
  function readLockHolder(path) {
38488
38372
  if (!existsSync8(path)) return null;
38489
38373
  try {
38490
- const raw = readFileSync15(path, "utf8");
38374
+ const raw = readFileSync14(path, "utf8");
38491
38375
  const parsed = JSON.parse(raw);
38492
38376
  const pid = typeof parsed.pid === "number" ? parsed.pid : Number(parsed.pid);
38493
38377
  if (!Number.isFinite(pid) || pid <= 0) return null;
@@ -38499,8 +38383,8 @@ function readLockHolder(path) {
38499
38383
  }
38500
38384
 
38501
38385
  // src/ack-reaction.ts
38502
- import { readdirSync as readdirSync5, readFileSync as readFileSync16, writeFileSync as writeFileSync10 } from "fs";
38503
- import { join as join16 } from "path";
38386
+ import { readdirSync as readdirSync5, readFileSync as readFileSync15, writeFileSync as writeFileSync10 } from "fs";
38387
+ import { join as join15 } from "path";
38504
38388
  var REPLY_WEDGED_THRESHOLD_MS = 5 * 60 * 1e3;
38505
38389
  var ACK_STARTUP_GRACE_MS = 6e4;
38506
38390
  var ACK_PANE_FRESH_THRESHOLD_MS = 6e4;
@@ -38573,7 +38457,7 @@ var GIVE_UP_SIGNAL_MAX_AGE_MS = 30 * 60 * 1e3;
38573
38457
  function readGiveUpSignal(path, now = Date.now()) {
38574
38458
  if (!path) return null;
38575
38459
  try {
38576
- const raw = JSON.parse(readFileSync16(path, "utf8"));
38460
+ const raw = JSON.parse(readFileSync15(path, "utf8"));
38577
38461
  if (typeof raw.gave_up_at !== "string") return null;
38578
38462
  const t = Date.parse(raw.gave_up_at);
38579
38463
  if (!Number.isFinite(t) || t > now) return null;
@@ -38614,7 +38498,7 @@ function oldestPendingMarkerAgeMs(dir, now = Date.now(), opts) {
38614
38498
  if (!name.endsWith(".json")) continue;
38615
38499
  let receivedAt;
38616
38500
  try {
38617
- const raw = JSON.parse(readFileSync16(join16(dir, name), "utf-8"));
38501
+ const raw = JSON.parse(readFileSync15(join15(dir, name), "utf-8"));
38618
38502
  if (raw.discretionary === true) continue;
38619
38503
  if (!opts?.includeSeen && typeof raw.seen_at === "string" && raw.seen_at) continue;
38620
38504
  receivedAt = raw.received_at;
@@ -38691,14 +38575,14 @@ function isMarkerGenuinelyAged(receivedAt, nowMs, thresholdMs) {
38691
38575
  }
38692
38576
  var DEFLECTION_COUNTER_SUFFIX = "-deflections.json";
38693
38577
  function deflectionCounterPath(agentDir, channel) {
38694
- return join16(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
38578
+ return join15(agentDir, `${channel}${DEFLECTION_COUNTER_SUFFIX}`);
38695
38579
  }
38696
38580
  function recordChannelDeflection(agentDir, channel, cause) {
38697
38581
  if (!agentDir) return;
38698
38582
  const path = deflectionCounterPath(agentDir, channel);
38699
38583
  let counts = {};
38700
38584
  try {
38701
- const parsed = JSON.parse(readFileSync16(path, "utf-8"));
38585
+ const parsed = JSON.parse(readFileSync15(path, "utf-8"));
38702
38586
  if (parsed && typeof parsed === "object") counts = parsed;
38703
38587
  } catch {
38704
38588
  }
@@ -38779,7 +38663,7 @@ function redactId(id) {
38779
38663
  }
38780
38664
  var BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
38781
38665
  var AGENT_CODE_NAME = process.env.AGT_AGENT_CODE_NAME ?? "unknown";
38782
- var TELEGRAM_AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join17(homedir7(), ".augmented", AGENT_CODE_NAME) : null;
38666
+ var TELEGRAM_AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join16(homedir6(), ".augmented", AGENT_CODE_NAME) : null;
38783
38667
  var AGT_HOST = process.env.AGT_HOST ?? null;
38784
38668
  var AGT_API_KEY = process.env.AGT_API_KEY ?? null;
38785
38669
  var AGT_AGENT_ID = process.env.AGT_AGENT_ID ?? null;
@@ -38882,11 +38766,11 @@ var peerRateLimiter = peerRateApiClient && parsePeerAgentModeEnv(process.env.TEL
38882
38766
  log: (line) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${line}
38883
38767
  `)
38884
38768
  }) : createPeerRateLimiter();
38885
- var PEER_PRESENCE_STATE_FILE = TELEGRAM_AGENT_DIR ? join17(TELEGRAM_AGENT_DIR, "telegram-peer-presence.json") : null;
38769
+ var PEER_PRESENCE_STATE_FILE = TELEGRAM_AGENT_DIR ? join16(TELEGRAM_AGENT_DIR, "telegram-peer-presence.json") : null;
38886
38770
  function readPeerPresenceState() {
38887
38771
  if (!PEER_PRESENCE_STATE_FILE) return null;
38888
38772
  try {
38889
- const parsed = JSON.parse(readFileSync17(PEER_PRESENCE_STATE_FILE, "utf-8"));
38773
+ const parsed = JSON.parse(readFileSync16(PEER_PRESENCE_STATE_FILE, "utf-8"));
38890
38774
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
38891
38775
  return parsed;
38892
38776
  } catch {
@@ -38921,9 +38805,9 @@ if (!BOT_TOKEN) {
38921
38805
  var stderrLogStream = null;
38922
38806
  if (AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown") {
38923
38807
  try {
38924
- const logDir = join17(homedir7(), ".augmented", AGENT_CODE_NAME);
38808
+ const logDir = join16(homedir6(), ".augmented", AGENT_CODE_NAME);
38925
38809
  mkdirSync9(logDir, { recursive: true });
38926
- stderrLogStream = createWriteStream(join17(logDir, "telegram-channel-stderr.log"), {
38810
+ stderrLogStream = createWriteStream(join16(logDir, "telegram-channel-stderr.log"), {
38927
38811
  flags: "a",
38928
38812
  mode: 384
38929
38813
  });
@@ -39112,24 +38996,17 @@ function armTelegramUsageLimitWatch(args) {
39112
38996
  void (async () => {
39113
38997
  try {
39114
38998
  const refusal = await watchForRateLimitRefusal({ sinceMs: args.sinceMs });
39115
- const action = decideRefusalAction({ mode: args.mode, refusal });
38999
+ const action = decideRefusalAction({ refusal });
39116
39000
  if (action === "none") return;
39117
39001
  if (action === "missing-reset") {
39118
39002
  process.stderr.write(
39119
- `telegram-channel(${AGENT_CODE_NAME}): [usage-limit-reactive] mode=${args.mode} refusal detected for chat=${redactId(args.chatId)} but no reset time in it (${describeUnparsedRefusal(refusal?.text)}) - no notice
39003
+ `telegram-channel(${AGENT_CODE_NAME}): [usage-limit-reactive] refusal detected for chat=${redactId(args.chatId)} but no reset time in it (${describeUnparsedRefusal(refusal?.text)}) - no notice
39120
39004
  `
39121
39005
  );
39122
39006
  return;
39123
39007
  }
39124
39008
  const resetsAt = refusal?.resetsAt;
39125
39009
  if (!resetsAt) return;
39126
- if (action === "shadow-log") {
39127
- process.stderr.write(
39128
- `telegram-channel(${AGENT_CODE_NAME}): [usage-limit-reactive] mode=shadow WOULD notify chat=${redactId(args.chatId)} resets=${resetsAt.toISOString()}
39129
- `
39130
- );
39131
- return;
39132
- }
39133
39010
  await maybeSendTelegramUsageLimitNotice({
39134
39011
  chatId: args.chatId,
39135
39012
  senderId: args.senderId,
@@ -39360,7 +39237,7 @@ function scheduleBusyAck(chatId, messageId, arrivedWhileBusy) {
39360
39237
  let paneLogFreshAgeMs = null;
39361
39238
  if (AGENT_DIR) {
39362
39239
  try {
39363
- const paneMtimeMs = statSync5(join17(AGENT_DIR, "pane.log")).mtimeMs;
39240
+ const paneMtimeMs = statSync5(join16(AGENT_DIR, "pane.log")).mtimeMs;
39364
39241
  paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
39365
39242
  } catch {
39366
39243
  }
@@ -39390,7 +39267,7 @@ function scheduleBusyAck(chatId, messageId, arrivedWhileBusy) {
39390
39267
  function __resetBusyAckNoticeThrottle() {
39391
39268
  lastBusyAckNoticeAt.clear();
39392
39269
  }
39393
- var RESTART_FLAGS_DIR = join17(homedir7(), ".augmented", "restart-flags");
39270
+ var RESTART_FLAGS_DIR = join16(homedir6(), ".augmented", "restart-flags");
39394
39271
  function actuateHostRestartTelegram() {
39395
39272
  return actuateHostRestart({
39396
39273
  agtHost: AGT_HOST,
@@ -39775,7 +39652,7 @@ async function handleRestartCommand(opts) {
39775
39652
  if (!existsSync9(RESTART_FLAGS_DIR)) {
39776
39653
  mkdirSync9(RESTART_FLAGS_DIR, { recursive: true });
39777
39654
  }
39778
- const flagPath = join17(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
39655
+ const flagPath = join16(RESTART_FLAGS_DIR, `${AGENT_CODE_NAME}.flag`);
39779
39656
  const flag = {
39780
39657
  codeName: AGENT_CODE_NAME,
39781
39658
  source: "telegram",
@@ -40181,16 +40058,16 @@ async function classifyRestartCommand(text) {
40181
40058
  if (!ours) return "verification_failed";
40182
40059
  return target === ours ? "act" : "ignore";
40183
40060
  }
40184
- var AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join17(homedir7(), ".augmented", AGENT_CODE_NAME) : null;
40185
- var PENDING_INBOUND_DIR = AGENT_DIR ? join17(AGENT_DIR, "telegram-pending-inbound") : null;
40186
- var RECOVERY_OUTBOX_DIR = AGENT_DIR ? join17(AGENT_DIR, "telegram-recovery-outbox") : null;
40187
- var RECOVERY_LEDGER_DIR = AGENT_DIR ? join17(AGENT_DIR, ".agt-telegram-recovery-ledger") : null;
40188
- var DELIVERY_LEDGER_DIR = AGENT_DIR ? join17(AGENT_DIR, ".agt-inbound-delivery-ledger") : null;
40189
- var RESTART_CONFIRM_FILE = AGENT_DIR ? join17(AGENT_DIR, "telegram-restart-confirm.json") : null;
40061
+ var AGENT_DIR = AGENT_CODE_NAME && AGENT_CODE_NAME !== "unknown" ? join16(homedir6(), ".augmented", AGENT_CODE_NAME) : null;
40062
+ var PENDING_INBOUND_DIR = AGENT_DIR ? join16(AGENT_DIR, "telegram-pending-inbound") : null;
40063
+ var RECOVERY_OUTBOX_DIR = AGENT_DIR ? join16(AGENT_DIR, "telegram-recovery-outbox") : null;
40064
+ var RECOVERY_LEDGER_DIR = AGENT_DIR ? join16(AGENT_DIR, ".agt-telegram-recovery-ledger") : null;
40065
+ var DELIVERY_LEDGER_DIR = AGENT_DIR ? join16(AGENT_DIR, ".agt-inbound-delivery-ledger") : null;
40066
+ var RESTART_CONFIRM_FILE = AGENT_DIR ? join16(AGENT_DIR, "telegram-restart-confirm.json") : null;
40190
40067
  var TELEGRAM_PROCESS_BOOT_MS = Date.now();
40191
- var TELEGRAM_RECENT_DMS_FILE = AGENT_DIR ? join17(AGENT_DIR, "telegram-recent-dms.json") : null;
40192
- var TELEGRAM_CHANNEL_ADD_RESTART_FILE = AGENT_DIR ? join17(AGENT_DIR, "telegram-channel-add-restart.json") : null;
40193
- var TELEGRAM_OFFSET_FILE = AGENT_DIR ? join17(AGENT_DIR, "telegram-getupdates-offset.json") : null;
40068
+ var TELEGRAM_RECENT_DMS_FILE = AGENT_DIR ? join16(AGENT_DIR, "telegram-recent-dms.json") : null;
40069
+ var TELEGRAM_CHANNEL_ADD_RESTART_FILE = AGENT_DIR ? join16(AGENT_DIR, "telegram-channel-add-restart.json") : null;
40070
+ var TELEGRAM_OFFSET_FILE = AGENT_DIR ? join16(AGENT_DIR, "telegram-getupdates-offset.json") : null;
40194
40071
  var recentDms = /* @__PURE__ */ new Map();
40195
40072
  var recentDmPersister = TELEGRAM_RECENT_DMS_FILE ? createRecentDmPersister({
40196
40073
  filePath: TELEGRAM_RECENT_DMS_FILE,
@@ -40245,7 +40122,7 @@ function safeMarkerName(chatId, messageId) {
40245
40122
  }
40246
40123
  function pendingInboundPath(chatId, messageId) {
40247
40124
  if (!PENDING_INBOUND_DIR) return null;
40248
- return join17(PENDING_INBOUND_DIR, safeMarkerName(chatId, messageId));
40125
+ return join16(PENDING_INBOUND_DIR, safeMarkerName(chatId, messageId));
40249
40126
  }
40250
40127
  function writePendingInboundMarker(chatId, messageId, chatType, undeliverable = false, payload) {
40251
40128
  const path = pendingInboundPath(chatId, messageId);
@@ -40293,7 +40170,7 @@ function rewriteTelegramMarkerInPlace(path, marker) {
40293
40170
  function clearTelegramMarkerFileWithHeal(fullPath) {
40294
40171
  let marker = null;
40295
40172
  try {
40296
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
40173
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40297
40174
  } catch {
40298
40175
  }
40299
40176
  if (marker && decideRecoveryHeal({
@@ -40316,7 +40193,7 @@ function markTelegramMarkerPromisedInPlace(fullPath) {
40316
40193
  function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40317
40194
  let marker;
40318
40195
  try {
40319
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
40196
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40320
40197
  } catch {
40321
40198
  return false;
40322
40199
  }
@@ -40331,7 +40208,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40331
40208
  rewriteTelegramMarkerInPlace(fullPath, marker);
40332
40209
  if (!opts.promise) return false;
40333
40210
  try {
40334
- const readBack = JSON.parse(readFileSync17(fullPath, "utf-8"));
40211
+ const readBack = JSON.parse(readFileSync16(fullPath, "utf-8"));
40335
40212
  return typeof readBack.promised_at === "string" && readBack.promised_at.length > 0;
40336
40213
  } catch {
40337
40214
  return false;
@@ -40340,7 +40217,7 @@ function markTelegramMarkerEngagedInPlace(fullPath, opts) {
40340
40217
  function markTelegramMarkerSeenWithHeal(fullPath) {
40341
40218
  let marker = null;
40342
40219
  try {
40343
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
40220
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40344
40221
  } catch {
40345
40222
  return;
40346
40223
  }
@@ -40355,7 +40232,7 @@ function markTelegramMarkerSeenWithHeal(fullPath) {
40355
40232
  function markTelegramMarkerPromisedWithHeal(fullPath) {
40356
40233
  let marker = null;
40357
40234
  try {
40358
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
40235
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40359
40236
  } catch {
40360
40237
  return;
40361
40238
  }
@@ -40373,7 +40250,7 @@ function readPendingInboundMarker(chatId, messageId) {
40373
40250
  const path = pendingInboundPath(chatId, messageId);
40374
40251
  if (!path || !existsSync9(path)) return null;
40375
40252
  try {
40376
- return JSON.parse(readFileSync17(path, "utf-8"));
40253
+ return JSON.parse(readFileSync16(path, "utf-8"));
40377
40254
  } catch {
40378
40255
  return null;
40379
40256
  }
@@ -40393,10 +40270,10 @@ function nextRetryName(filename) {
40393
40270
  async function processRecoveryOutboxFile(filename) {
40394
40271
  if (!RECOVERY_OUTBOX_DIR) return;
40395
40272
  if (filename.endsWith(".poison.json") || filename.endsWith(".tmp")) return;
40396
- const fullPath = join17(RECOVERY_OUTBOX_DIR, filename);
40273
+ const fullPath = join16(RECOVERY_OUTBOX_DIR, filename);
40397
40274
  let payload;
40398
40275
  try {
40399
- const raw = readFileSync17(fullPath, "utf-8");
40276
+ const raw = readFileSync16(fullPath, "utf-8");
40400
40277
  payload = JSON.parse(raw);
40401
40278
  } catch (err) {
40402
40279
  process.stderr.write(
@@ -40490,7 +40367,7 @@ async function processRecoveryOutboxFile(filename) {
40490
40367
  const next = nextRetryName(filename);
40491
40368
  if (next) {
40492
40369
  try {
40493
- renameSync7(fullPath, join17(RECOVERY_OUTBOX_DIR, next.next));
40370
+ renameSync7(fullPath, join16(RECOVERY_OUTBOX_DIR, next.next));
40494
40371
  if (next.attempt >= MAX_RECOVERY_ATTEMPTS) {
40495
40372
  process.stderr.write(
40496
40373
  `telegram-channel(${AGENT_CODE_NAME}): ghost-reply recovery exhausted retries \u2014 moved to ${next.next}
@@ -40531,7 +40408,7 @@ function scanRecoveryRetries() {
40531
40408
  if (!f.includes(".retry-") || f.endsWith(".poison.json")) continue;
40532
40409
  let mtimeMs;
40533
40410
  try {
40534
- mtimeMs = statSync5(join17(RECOVERY_OUTBOX_DIR, f)).mtimeMs;
40411
+ mtimeMs = statSync5(join16(RECOVERY_OUTBOX_DIR, f)).mtimeMs;
40535
40412
  } catch {
40536
40413
  continue;
40537
40414
  }
@@ -40561,7 +40438,7 @@ function startRecoveryOutboxWatcher() {
40561
40438
  const watcher = watch(RECOVERY_OUTBOX_DIR, (event, filename) => {
40562
40439
  if (event !== "rename" || !filename) return;
40563
40440
  if (!isFirstAttemptOutboxFile(filename)) return;
40564
- if (existsSync9(join17(RECOVERY_OUTBOX_DIR, filename))) {
40441
+ if (existsSync9(join16(RECOVERY_OUTBOX_DIR, filename))) {
40565
40442
  void processRecoveryOutboxFile(filename);
40566
40443
  }
40567
40444
  });
@@ -40576,7 +40453,7 @@ function startRecoveryOutboxWatcher() {
40576
40453
  retryTimer.unref?.();
40577
40454
  }
40578
40455
  startRecoveryOutboxWatcher();
40579
- var NOTICE_OUTBOX_DIR = AGENT_DIR ? join17(AGENT_DIR, "telegram-notice-outbox") : null;
40456
+ var NOTICE_OUTBOX_DIR = AGENT_DIR ? join16(AGENT_DIR, "telegram-notice-outbox") : null;
40580
40457
  var NOTICE_MAX_AGE_MS = 9e4;
40581
40458
  var NOTICE_INFLIGHT = /* @__PURE__ */ new Set();
40582
40459
  async function processNoticeOutboxFile(filename) {
@@ -40584,7 +40461,7 @@ async function processNoticeOutboxFile(filename) {
40584
40461
  if (filename.startsWith(".") || filename.endsWith(".tmp") || !filename.endsWith(".json")) return;
40585
40462
  if (NOTICE_INFLIGHT.has(filename)) return;
40586
40463
  NOTICE_INFLIGHT.add(filename);
40587
- const fullPath = join17(NOTICE_OUTBOX_DIR, filename);
40464
+ const fullPath = join16(NOTICE_OUTBOX_DIR, filename);
40588
40465
  try {
40589
40466
  let mtimeMs;
40590
40467
  try {
@@ -40601,7 +40478,7 @@ async function processNoticeOutboxFile(filename) {
40601
40478
  }
40602
40479
  let payload;
40603
40480
  try {
40604
- const parsed = JSON.parse(readFileSync17(fullPath, "utf-8"));
40481
+ const parsed = JSON.parse(readFileSync16(fullPath, "utf-8"));
40605
40482
  if (!parsed || typeof parsed !== "object") throw new Error("not an object");
40606
40483
  payload = parsed;
40607
40484
  } catch {
@@ -40678,7 +40555,7 @@ function startNoticeOutboxWatcher() {
40678
40555
  try {
40679
40556
  const watcher = watch(NOTICE_OUTBOX_DIR, (event, filename) => {
40680
40557
  if (event !== "rename" || !filename) return;
40681
- if (existsSync9(join17(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
40558
+ if (existsSync9(join16(NOTICE_OUTBOX_DIR, filename))) void processNoticeOutboxFile(filename);
40682
40559
  });
40683
40560
  watcher.unref?.();
40684
40561
  } catch (err) {
@@ -40712,10 +40589,10 @@ function sweepTelegramStaleMarkers(thresholdMs) {
40712
40589
  for (const filename of filenames) {
40713
40590
  if (!filename.endsWith(".json")) continue;
40714
40591
  if (filename.endsWith(".tmp")) continue;
40715
- const fullPath = join17(PENDING_INBOUND_DIR, filename);
40592
+ const fullPath = join16(PENDING_INBOUND_DIR, filename);
40716
40593
  let marker;
40717
40594
  try {
40718
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
40595
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
40719
40596
  } catch (err) {
40720
40597
  process.stderr.write(
40721
40598
  `telegram-channel(${AGENT_CODE_NAME}): stale-marker parse failed for ${redactId(filename)}: ${err.message}
@@ -40768,13 +40645,13 @@ var orphanSweepTimer = setInterval(() => {
40768
40645
  checkWatchdogGiveUpNotice();
40769
40646
  }, orphanSweepIntervalMs());
40770
40647
  orphanSweepTimer.unref?.();
40771
- var TELEGRAM_PROGRESS_HEARTBEAT_PATH = AGENT_DIR ? join17(AGENT_DIR, "channel-progress-heartbeat.json") : null;
40648
+ var TELEGRAM_PROGRESS_HEARTBEAT_PATH = AGENT_DIR ? join16(AGENT_DIR, "channel-progress-heartbeat.json") : null;
40772
40649
  var telegramTrackedProgress = null;
40773
40650
  var telegramProgressTickRunning = false;
40774
40651
  function readTelegramProgressHeartbeat() {
40775
40652
  if (!TELEGRAM_PROGRESS_HEARTBEAT_PATH || !existsSync9(TELEGRAM_PROGRESS_HEARTBEAT_PATH)) return null;
40776
40653
  try {
40777
- return parseProgressHeartbeat(readFileSync17(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
40654
+ return parseProgressHeartbeat(readFileSync16(TELEGRAM_PROGRESS_HEARTBEAT_PATH, "utf-8"));
40778
40655
  } catch {
40779
40656
  return null;
40780
40657
  }
@@ -40801,7 +40678,7 @@ function findTelegramProgressTarget() {
40801
40678
  if (!name.endsWith(".json")) continue;
40802
40679
  let m;
40803
40680
  try {
40804
- m = JSON.parse(readFileSync17(join17(PENDING_INBOUND_DIR, name), "utf-8"));
40681
+ m = JSON.parse(readFileSync16(join16(PENDING_INBOUND_DIR, name), "utf-8"));
40805
40682
  } catch {
40806
40683
  continue;
40807
40684
  }
@@ -40932,7 +40809,7 @@ function listPendingInboundChatIds() {
40932
40809
  if (!name.endsWith(".json")) continue;
40933
40810
  try {
40934
40811
  const marker = JSON.parse(
40935
- readFileSync17(join17(PENDING_INBOUND_DIR, name), "utf8")
40812
+ readFileSync16(join16(PENDING_INBOUND_DIR, name), "utf8")
40936
40813
  );
40937
40814
  if (typeof marker.seen_at === "string" && marker.seen_at) continue;
40938
40815
  if (typeof marker.chat_id === "string" && marker.chat_id) chats.add(marker.chat_id);
@@ -41052,7 +40929,7 @@ async function notifyWatchdogGiveUp(chatId, reason) {
41052
40929
  }
41053
40930
  function checkWatchdogGiveUpNotice() {
41054
40931
  if (!AGENT_DIR) return;
41055
- const signal = readGiveUpSignal(join17(AGENT_DIR, GIVE_UP_SIGNAL_FILENAME));
40932
+ const signal = readGiveUpSignal(join16(AGENT_DIR, GIVE_UP_SIGNAL_FILENAME));
41056
40933
  const signalAtMs = signal?.atMs ?? null;
41057
40934
  const act = decideGiveUpNotice({
41058
40935
  signalAtMs,
@@ -41348,7 +41225,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
41348
41225
  isError: true
41349
41226
  };
41350
41227
  }
41351
- const allowedRoot = resolve2(homedir7(), ".augmented", AGENT_CODE_NAME, "project") + "/";
41228
+ const allowedRoot = resolve2(homedir6(), ".augmented", AGENT_CODE_NAME, "project") + "/";
41352
41229
  const resolvedPath = resolve2(path);
41353
41230
  if (!resolvedPath.startsWith(allowedRoot)) {
41354
41231
  return {
@@ -41396,7 +41273,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
41396
41273
  }
41397
41274
  let realRoot = allowedRoot;
41398
41275
  try {
41399
- realRoot = realpathSync(resolve2(homedir7(), ".augmented", AGENT_CODE_NAME, "project")) + "/";
41276
+ realRoot = realpathSync(resolve2(homedir6(), ".augmented", AGENT_CODE_NAME, "project")) + "/";
41400
41277
  } catch {
41401
41278
  }
41402
41279
  if (!realPath.startsWith(realRoot)) {
@@ -41425,7 +41302,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
41425
41302
  isError: true
41426
41303
  };
41427
41304
  }
41428
- bytes = readFileSync17(realPath);
41305
+ bytes = readFileSync16(realPath);
41429
41306
  } catch (err) {
41430
41307
  return { content: [{ type: "text", text: `Failed to read file: ${err.message}` }], isError: true };
41431
41308
  }
@@ -41994,7 +41871,7 @@ async function replayPendingTelegramMarkers() {
41994
41871
  let paneFreshAgeMs = null;
41995
41872
  if (AGENT_DIR) {
41996
41873
  try {
41997
- paneFreshAgeMs = Math.max(0, now - statSync5(join17(AGENT_DIR, "pane.log")).mtimeMs);
41874
+ paneFreshAgeMs = Math.max(0, now - statSync5(join16(AGENT_DIR, "pane.log")).mtimeMs);
41998
41875
  } catch {
41999
41876
  }
42000
41877
  }
@@ -42002,10 +41879,10 @@ async function replayPendingTelegramMarkers() {
42002
41879
  const entries = [];
42003
41880
  for (const name of filenames) {
42004
41881
  if (!name.endsWith(".json") || name.endsWith(".tmp")) continue;
42005
- const fullPath = join17(PENDING_INBOUND_DIR, name);
41882
+ const fullPath = join16(PENDING_INBOUND_DIR, name);
42006
41883
  let marker;
42007
41884
  try {
42008
- marker = JSON.parse(readFileSync17(fullPath, "utf-8"));
41885
+ marker = JSON.parse(readFileSync16(fullPath, "utf-8"));
42009
41886
  } catch {
42010
41887
  continue;
42011
41888
  }
@@ -42491,21 +42368,6 @@ async function pollLoop() {
42491
42368
  });
42492
42369
  continue;
42493
42370
  }
42494
- const reactiveMode = resolveUsageLimitReactiveMode();
42495
- const telegramUsageLimitUntil = !isFromBot && shouldReadPredictiveMarker(reactiveMode) ? readUsageLimitUntil({ codeName: AGENT_CODE_NAME }) : null;
42496
- if (telegramUsageLimitUntil) {
42497
- process.stderr.write(
42498
- `telegram-channel(${AGENT_CODE_NAME}): usage-limit active until ${telegramUsageLimitUntil.toISOString()} \u2014 notice, no dispatch (chat=${redactId(chatId)})
42499
- `
42500
- );
42501
- await maybeSendTelegramUsageLimitNotice({
42502
- chatId,
42503
- senderId: userId,
42504
- messageThreadId: msg.message_thread_id,
42505
- limitedUntil: telegramUsageLimitUntil
42506
- });
42507
- continue;
42508
- }
42509
42371
  if (isFromBot && classification?.kind === "peer-ingress") {
42510
42372
  const limit = await peerRateLimiter.recordInboundPeer(
42511
42373
  chatId,
@@ -42556,7 +42418,7 @@ async function pollLoop() {
42556
42418
  let paneLogFreshAgeMs = null;
42557
42419
  if (AGENT_DIR) {
42558
42420
  try {
42559
- const paneMtimeMs = statSync5(join17(AGENT_DIR, "pane.log")).mtimeMs;
42421
+ const paneMtimeMs = statSync5(join16(AGENT_DIR, "pane.log")).mtimeMs;
42560
42422
  paneLogFreshAgeMs = Math.max(0, Date.now() - paneMtimeMs);
42561
42423
  } catch {
42562
42424
  }
@@ -42660,16 +42522,13 @@ async function pollLoop() {
42660
42522
  method: "notifications/claude/channel",
42661
42523
  params: channelPayload
42662
42524
  });
42663
- const watchMode = armedWatchMode({
42664
- mode: reactiveMode,
42525
+ if (shouldArmWatch({
42665
42526
  isBot: isFromBot || !!peerAgentMeta,
42666
42527
  // Every Telegram inbound that reaches here owes a reply — there is no
42667
42528
  // discretionary auto-follow variant as there is on Slack.
42668
42529
  replyOwed: true
42669
- });
42670
- if (watchMode) {
42530
+ })) {
42671
42531
  armTelegramUsageLimitWatch({
42672
- mode: watchMode,
42673
42532
  chatId,
42674
42533
  senderId: userId,
42675
42534
  ...msg.message_thread_id != null ? { messageThreadId: msg.message_thread_id } : {},