@integrity-labs/agt-cli 0.28.1284 → 0.28.1286

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.
Files changed (30) hide show
  1. package/dist/{api-client-R6RJRYGB.js → api-client-XQRYQJKJ.js} +3 -3
  2. package/dist/bin/agt.js +7 -7
  3. package/dist/{chunk-VVLJQMAS.js → chunk-3R7OXS5I.js} +3 -3
  4. package/dist/{chunk-MOEUK4YM.js → chunk-DITI25ZO.js} +4 -4
  5. package/dist/chunk-DITI25ZO.js.map +1 -0
  6. package/dist/{chunk-ENQZZU7H.js → chunk-FRNONFQA.js} +2 -2
  7. package/dist/{chunk-UTJFYUFS.js → chunk-HJGZG3P6.js} +3 -3
  8. package/dist/{chunk-ORVKG3JD.js → chunk-TTEBS4AE.js} +5 -5
  9. package/dist/{chunk-NTSHQA62.js → chunk-X7ZRYILH.js} +2 -2
  10. package/dist/{claude-code-updater-CHQOLPJQ.js → claude-code-updater-6NRYKDKS.js} +3 -3
  11. package/dist/{claude-pair-runtime-DULPA33Z.js → claude-pair-runtime-7UQEV7XI.js} +3 -3
  12. package/dist/lib/manager-worker.js +21 -21
  13. package/dist/mcp/slack-channel.js +270 -3
  14. package/dist/mcp/xero.js +19 -8
  15. package/dist/{persistent-session-IAMIVRZ3.js → persistent-session-VBJAAJC7.js} +4 -4
  16. package/dist/{responsiveness-probe-CLRUQOE2.js → responsiveness-probe-QKMGCTFR.js} +4 -4
  17. package/dist/{session-auth-dead-SH6ZJTOS.js → session-auth-dead-IBUKQXBO.js} +3 -3
  18. package/package.json +1 -1
  19. package/dist/chunk-MOEUK4YM.js.map +0 -1
  20. /package/dist/{api-client-R6RJRYGB.js.map → api-client-XQRYQJKJ.js.map} +0 -0
  21. /package/dist/{chunk-VVLJQMAS.js.map → chunk-3R7OXS5I.js.map} +0 -0
  22. /package/dist/{chunk-ENQZZU7H.js.map → chunk-FRNONFQA.js.map} +0 -0
  23. /package/dist/{chunk-UTJFYUFS.js.map → chunk-HJGZG3P6.js.map} +0 -0
  24. /package/dist/{chunk-ORVKG3JD.js.map → chunk-TTEBS4AE.js.map} +0 -0
  25. /package/dist/{chunk-NTSHQA62.js.map → chunk-X7ZRYILH.js.map} +0 -0
  26. /package/dist/{claude-code-updater-CHQOLPJQ.js.map → claude-code-updater-6NRYKDKS.js.map} +0 -0
  27. /package/dist/{claude-pair-runtime-DULPA33Z.js.map → claude-pair-runtime-7UQEV7XI.js.map} +0 -0
  28. /package/dist/{persistent-session-IAMIVRZ3.js.map → persistent-session-VBJAAJC7.js.map} +0 -0
  29. /package/dist/{responsiveness-probe-CLRUQOE2.js.map → responsiveness-probe-QKMGCTFR.js.map} +0 -0
  30. /package/dist/{session-auth-dead-SH6ZJTOS.js.map → session-auth-dead-IBUKQXBO.js.map} +0 -0
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-XWVM4KPK.js";
5
5
  import {
6
6
  FORCED_UPDATE_HARD_DEADLINE_MS
7
- } from "./chunk-MOEUK4YM.js";
7
+ } from "./chunk-DITI25ZO.js";
8
8
  import {
9
9
  effectiveClaudeJsonPath
10
10
  } from "./chunk-AIUIMEUS.js";
@@ -722,4 +722,4 @@ export {
722
722
  probeClaudeInstalls,
723
723
  maybeUpdateClaudeCode
724
724
  };
725
- //# sourceMappingURL=chunk-ENQZZU7H.js.map
725
+ //# sourceMappingURL=chunk-FRNONFQA.js.map
@@ -4,7 +4,7 @@ import {
4
4
  rotateDailySession,
5
5
  sessionFileExists,
6
6
  todayLocalIso
7
- } from "./chunk-NTSHQA62.js";
7
+ } from "./chunk-X7ZRYILH.js";
8
8
  import {
9
9
  classifyUnanswerablePane,
10
10
  customApiKeyDialogKeys,
@@ -54,7 +54,7 @@ import {
54
54
  remoteMcpConnectionEnvInfix,
55
55
  remoteMcpConnectionLabel,
56
56
  remoteMcpConnectionScopedEnvVar
57
- } from "./chunk-MOEUK4YM.js";
57
+ } from "./chunk-DITI25ZO.js";
58
58
  import {
59
59
  CLAUDE_CONFIG_DIR_ENV,
60
60
  approveApiKeyInClaudeConfig,
@@ -6566,4 +6566,4 @@ export {
6566
6566
  stopAllSessionsAndWait,
6567
6567
  getProjectDir
6568
6568
  };
6569
- //# sourceMappingURL=chunk-UTJFYUFS.js.map
6569
+ //# sourceMappingURL=chunk-HJGZG3P6.js.map
@@ -2,7 +2,7 @@ import {
2
2
  exchangeApiKey,
3
3
  getApiKey,
4
4
  getHost
5
- } from "./chunk-VVLJQMAS.js";
5
+ } from "./chunk-3R7OXS5I.js";
6
6
  import {
7
7
  LATE_BOUND_VARS,
8
8
  PLATFORM_DENY_PERMISSIONS,
@@ -26,11 +26,11 @@ import {
26
26
  warnIgnoredIsolationAllowlist,
27
27
  withheldRemoteMcpMessage,
28
28
  withheldRemoteMcpReasonFor
29
- } from "./chunk-UTJFYUFS.js";
29
+ } from "./chunk-HJGZG3P6.js";
30
30
  import {
31
31
  readDailySessionPin,
32
32
  sessionTranscriptDir
33
- } from "./chunk-NTSHQA62.js";
33
+ } from "./chunk-X7ZRYILH.js";
34
34
  import {
35
35
  classifyUnanswerablePane,
36
36
  isConsumerTermsDialogVisible,
@@ -102,7 +102,7 @@ import {
102
102
  scanConfigForLiteralSecrets,
103
103
  worseConnectivityOutcome,
104
104
  wrapScheduledTaskPrompt
105
- } from "./chunk-MOEUK4YM.js";
105
+ } from "./chunk-DITI25ZO.js";
106
106
  import {
107
107
  claudeJsonPathFor,
108
108
  effectiveClaudeJsonPath,
@@ -13853,4 +13853,4 @@ export {
13853
13853
  managerInstallSystemUnitCommand,
13854
13854
  managerUninstallSystemUnitCommand
13855
13855
  };
13856
- //# sourceMappingURL=chunk-ORVKG3JD.js.map
13856
+ //# sourceMappingURL=chunk-TTEBS4AE.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  encodeClaudeProjectPath
3
- } from "./chunk-MOEUK4YM.js";
3
+ } from "./chunk-DITI25ZO.js";
4
4
 
5
5
  // src/lib/daily-session.ts
6
6
  import { randomUUID } from "crypto";
@@ -244,4 +244,4 @@ export {
244
244
  peekPreviousSession,
245
245
  readDailySessionPin
246
246
  };
247
- //# sourceMappingURL=chunk-NTSHQA62.js.map
247
+ //# sourceMappingURL=chunk-X7ZRYILH.js.map
@@ -13,9 +13,9 @@ import {
13
13
  probeClaudeInstalls,
14
14
  readsAsNativeInstall,
15
15
  shouldRunClaudeCodeUpdater
16
- } from "./chunk-ENQZZU7H.js";
16
+ } from "./chunk-FRNONFQA.js";
17
17
  import "./chunk-XWVM4KPK.js";
18
- import "./chunk-MOEUK4YM.js";
18
+ import "./chunk-DITI25ZO.js";
19
19
  import "./chunk-AIUIMEUS.js";
20
20
  import "./chunk-DGUM43GV.js";
21
21
  export {
@@ -34,4 +34,4 @@ export {
34
34
  readsAsNativeInstall,
35
35
  shouldRunClaudeCodeUpdater
36
36
  };
37
- //# sourceMappingURL=claude-code-updater-CHQOLPJQ.js.map
37
+ //# sourceMappingURL=claude-code-updater-6NRYKDKS.js.map
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  redactPaneFrame,
12
12
  sanitizeTerminalFrame
13
- } from "./chunk-MOEUK4YM.js";
13
+ } from "./chunk-DITI25ZO.js";
14
14
  import {
15
15
  CLAUDE_CONFIG_DIR_ENV,
16
16
  claudeConfigDirFor,
@@ -323,7 +323,7 @@ async function spawnPairSession(session) {
323
323
  return { ok: true };
324
324
  } catch {
325
325
  }
326
- const { resolveClaudeBinary } = await import("./persistent-session-IAMIVRZ3.js");
326
+ const { resolveClaudeBinary } = await import("./persistent-session-VBJAAJC7.js");
327
327
  const claudeBin = resolveClaudeBinary();
328
328
  const pairEnv = {
329
329
  ...process.env,
@@ -838,4 +838,4 @@ export {
838
838
  startClaudePair,
839
839
  submitClaudePairCode
840
840
  };
841
- //# sourceMappingURL=claude-pair-runtime-DULPA33Z.js.map
841
+ //# sourceMappingURL=claude-pair-runtime-7UQEV7XI.js.map
@@ -70,7 +70,7 @@ import {
70
70
  tripClass,
71
71
  writeEtcEnvironment,
72
72
  writeProfileDScript
73
- } from "../chunk-ORVKG3JD.js";
73
+ } from "../chunk-TTEBS4AE.js";
74
74
  import {
75
75
  ApiError,
76
76
  adoptHostKeyInProcess,
@@ -88,7 +88,7 @@ import {
88
88
  probeHostKey,
89
89
  requireHost,
90
90
  setConfigHash
91
- } from "../chunk-VVLJQMAS.js";
91
+ } from "../chunk-3R7OXS5I.js";
92
92
  import {
93
93
  BLOCKED_ON_PROMPT_DECISION,
94
94
  CHANNEL_SECRET_ENV_KEYS,
@@ -180,7 +180,7 @@ import {
180
180
  webFetchBaselineValue,
181
181
  webFetchRestartNeeded,
182
182
  writeEgressAllowlist
183
- } from "../chunk-UTJFYUFS.js";
183
+ } from "../chunk-HJGZG3P6.js";
184
184
  import {
185
185
  isAgentIdle,
186
186
  isStaleForToday,
@@ -191,7 +191,7 @@ import {
191
191
  subagentActivityAgeSeconds,
192
192
  subagentTranscriptDir,
193
193
  transcriptActivityAgeSeconds
194
- } from "../chunk-NTSHQA62.js";
194
+ } from "../chunk-X7ZRYILH.js";
195
195
  import {
196
196
  classifyUnanswerablePane,
197
197
  focusedConfirmDialogBlock,
@@ -217,7 +217,7 @@ import {
217
217
  runSafeCleanup,
218
218
  tightestDiskStat,
219
219
  withPackageCacheLock
220
- } from "../chunk-ENQZZU7H.js";
220
+ } from "../chunk-FRNONFQA.js";
221
221
  import {
222
222
  parsePsRows,
223
223
  reapOrphanChannelMcps
@@ -346,7 +346,7 @@ import {
346
346
  stabiliseResetInstant,
347
347
  sumTranscriptUsageInWindow,
348
348
  summarizeTranscriptActivity
349
- } from "../chunk-MOEUK4YM.js";
349
+ } from "../chunk-DITI25ZO.js";
350
350
  import {
351
351
  CLAUDE_CONFIG_DIR_ENV,
352
352
  claudeConfigDirFor,
@@ -15444,7 +15444,7 @@ function createFileMigrationReportIO(codeName, log2) {
15444
15444
  };
15445
15445
  }
15446
15446
  var managerHostPost = async (path, body) => {
15447
- const { api: api2, ApiError: ApiError3 } = await import("../api-client-R6RJRYGB.js");
15447
+ const { api: api2, ApiError: ApiError3 } = await import("../api-client-XQRYQJKJ.js");
15448
15448
  try {
15449
15449
  const json = await api2.post(path, body);
15450
15450
  return { status: 200, json };
@@ -17499,7 +17499,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
17499
17499
  var dayRolloverInboundHold = /* @__PURE__ */ new Map();
17500
17500
  var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
17501
17501
  async function channelInboundActivityAgeSecondsFor(codeName) {
17502
- const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-CLRUQOE2.js");
17502
+ const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-QKMGCTFR.js");
17503
17503
  const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
17504
17504
  if (newest === null) return null;
17505
17505
  return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
@@ -18380,7 +18380,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
18380
18380
  var lastVersionCheckAt = 0;
18381
18381
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
18382
18382
  var lastResponsivenessProbeAt = 0;
18383
- var agtCliVersion = true ? "0.28.1284" : "dev";
18383
+ var agtCliVersion = true ? "0.28.1286" : "dev";
18384
18384
  function resolveBrewPath(execFileSync5) {
18385
18385
  try {
18386
18386
  const out = execFileSync5("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -20491,7 +20491,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
20491
20491
  if (codeNames.length === 0) return;
20492
20492
  void (async () => {
20493
20493
  try {
20494
- const { collectDiagnostics } = await import("../persistent-session-IAMIVRZ3.js");
20494
+ const { collectDiagnostics } = await import("../persistent-session-VBJAAJC7.js");
20495
20495
  await api.post("/host/heartbeat", {
20496
20496
  host_id: hostId,
20497
20497
  agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -20634,7 +20634,7 @@ async function pollCycleInner() {
20634
20634
  }
20635
20635
  try {
20636
20636
  const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
20637
- const { collectDiagnostics } = await import("../persistent-session-IAMIVRZ3.js");
20637
+ const { collectDiagnostics } = await import("../persistent-session-VBJAAJC7.js");
20638
20638
  const diagCodeNames = [...agentState.persistentSessionAgents];
20639
20639
  const agentDiagnostics = diagCodeNames.length > 0 ? collectDiagnostics(diagCodeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor) : void 0;
20640
20640
  let tailscaleHostname;
@@ -20933,7 +20933,7 @@ async function pollCycleInner() {
20933
20933
  }
20934
20934
  try {
20935
20935
  const desiredClaudeCodeVersion = hbResp?.desired_claude_code_version?.trim();
20936
- const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-CHQOLPJQ.js");
20936
+ const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-6NRYKDKS.js");
20937
20937
  const securityFloor = currentSecurityFloor();
20938
20938
  claudeUpdaterInFlight = true;
20939
20939
  if (desiredClaudeCodeVersion && (claudePairLoop.busy || claudePairingInProgress())) {
@@ -20968,7 +20968,7 @@ async function pollCycleInner() {
20968
20968
  collectPanelessActivityProbes,
20969
20969
  getResponsivenessIntervalMs,
20970
20970
  occupancyQualificationClassifications
20971
- } = await import("../responsiveness-probe-CLRUQOE2.js");
20971
+ } = await import("../responsiveness-probe-QKMGCTFR.js");
20972
20972
  const probeIntervalMs = getResponsivenessIntervalMs();
20973
20973
  if (now - lastResponsivenessProbeAt > probeIntervalMs) {
20974
20974
  const probeCodeNames = [...agentState.persistentSessionAgents];
@@ -21085,7 +21085,7 @@ async function pollCycleInner() {
21085
21085
  collectResponsivenessProbes,
21086
21086
  livePendingInboundOldestAgeSeconds,
21087
21087
  parkPendingInbound
21088
- } = await import("../responsiveness-probe-CLRUQOE2.js");
21088
+ } = await import("../responsiveness-probe-QKMGCTFR.js");
21089
21089
  const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
21090
21090
  const wedgeNow = /* @__PURE__ */ new Date();
21091
21091
  const liveAgents = agentState.persistentSessionAgents;
@@ -21371,7 +21371,7 @@ async function pollCycleInner() {
21371
21371
  }
21372
21372
  }
21373
21373
  );
21374
- const { parkPendingInbound } = await import("../responsiveness-probe-CLRUQOE2.js");
21374
+ const { parkPendingInbound } = await import("../responsiveness-probe-QKMGCTFR.js");
21375
21375
  const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
21376
21376
  paneFatalStreak.delete(codeName);
21377
21377
  paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
@@ -21402,7 +21402,7 @@ async function pollCycleInner() {
21402
21402
  TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
21403
21403
  bindSourceEscalations
21404
21404
  } = await import("../transcript-mount-health-OHE6IVJV.js");
21405
- const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-IAMIVRZ3.js");
21405
+ const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-VBJAAJC7.js");
21406
21406
  const mountConfig = resolveTranscriptMountConfig();
21407
21407
  const liveAgents = agentState.persistentSessionAgents;
21408
21408
  for (const tracked of [
@@ -21567,7 +21567,7 @@ async function pollCycleInner() {
21567
21567
  }
21568
21568
  try {
21569
21569
  const { scrapeMcpFailedBannerCount } = await import("../pane-mcp-banner-scraper-VR5QGP3J.js");
21570
- const { probeSessionAuth } = await import("../session-auth-dead-SH6ZJTOS.js");
21570
+ const { probeSessionAuth } = await import("../session-auth-dead-IBUKQXBO.js");
21571
21571
  const observations = [];
21572
21572
  const pendingCacheCommits = [];
21573
21573
  const modelApiErrorReportingOn = hostFlagStore().getBoolean("model-api-error-reporting");
@@ -26678,7 +26678,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
26678
26678
  if (!refreshData) return;
26679
26679
  const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
26680
26680
  const hostId = await getHostId();
26681
- const parkForRestart = await import("../responsiveness-probe-CLRUQOE2.js").then(
26681
+ const parkForRestart = await import("../responsiveness-probe-QKMGCTFR.js").then(
26682
26682
  (m) => m.parkPendingInbound,
26683
26683
  (err) => err
26684
26684
  );
@@ -26755,7 +26755,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
26755
26755
  void api.post("/host/restart-ack", { host_id: hostId, agent_id: agentId, restart_requested_at: requestedAt }).catch((err) => log(`[restart-lane] ack failed for '${codeName}': ${err.message}`));
26756
26756
  void (async () => {
26757
26757
  try {
26758
- const { collectDiagnostics } = await import("../persistent-session-IAMIVRZ3.js");
26758
+ const { collectDiagnostics } = await import("../persistent-session-VBJAAJC7.js");
26759
26759
  await api.post("/host/heartbeat", {
26760
26760
  host_id: hostId,
26761
26761
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -26808,7 +26808,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
26808
26808
  }
26809
26809
  try {
26810
26810
  const hostId = await getHostId();
26811
- const { collectDiagnostics } = await import("../persistent-session-IAMIVRZ3.js");
26811
+ const { collectDiagnostics } = await import("../persistent-session-VBJAAJC7.js");
26812
26812
  await api.post("/host/heartbeat", {
26813
26813
  host_id: hostId,
26814
26814
  agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
@@ -27547,7 +27547,7 @@ async function processClaudePairSessions(agents) {
27547
27547
  snapshotPairConfig,
27548
27548
  // ENG-11659: result -> report body + the manager.log line that records it.
27549
27549
  planPairStartReport
27550
- } = await import("../claude-pair-runtime-DULPA33Z.js");
27550
+ } = await import("../claude-pair-runtime-7UQEV7XI.js");
27551
27551
  const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
27552
27552
  for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
27553
27553
  log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);
@@ -46905,15 +46905,262 @@ function buildChannelInfoResult(args) {
46905
46905
  function buildDmUserInfo(usersInfoRes) {
46906
46906
  if (!usersInfoRes || usersInfoRes.ok === false || !usersInfoRes.user) return {};
46907
46907
  const u = usersInfoRes.user;
46908
- const nonEmpty = (s) => typeof s === "string" && s.trim().length > 0 ? s : void 0;
46909
- const user_name = nonEmpty(u.profile?.display_name) ?? nonEmpty(u.profile?.real_name) ?? nonEmpty(u.real_name);
46910
- const user_handle = nonEmpty(u.name);
46908
+ const nonEmpty2 = (s) => typeof s === "string" && s.trim().length > 0 ? s : void 0;
46909
+ const user_name = nonEmpty2(u.profile?.display_name) ?? nonEmpty2(u.profile?.real_name) ?? nonEmpty2(u.real_name);
46910
+ const user_handle = nonEmpty2(u.name);
46911
46911
  const out = {};
46912
46912
  if (user_handle) out.user_handle = user_handle;
46913
46913
  if (user_name) out.user_name = user_name;
46914
46914
  return out;
46915
46915
  }
46916
46916
 
46917
+ // src/slack-lookup-user.ts
46918
+ var NAME_CACHE_TTL_MS = 15 * 60 * 1e3;
46919
+ var NAME_MIN_REFRESH_INTERVAL_MS = 60 * 1e3;
46920
+ var NAME_MAX_RESULTS = 10;
46921
+ var USERS_LIST_PAGE_SIZE = 200;
46922
+ var USERS_LIST_MAX_PAGES = 50;
46923
+ var REINSTALL_MESSAGE = (scope) => `The Slack app is not allowed to look users up (it is missing the ${scope} permission). Reinstall the Slack app to grant user lookup. Tell a human operator; do not retry, and do not treat this as "person not found".`;
46924
+ var TERMINAL_REASONS = /* @__PURE__ */ new Set(["missing_scope", "auth_failed"]);
46925
+ var AUTH_ERRORS = /* @__PURE__ */ new Set(["invalid_auth", "not_authed", "token_expired", "token_revoked", "account_inactive"]);
46926
+ function grantedScopes(headers) {
46927
+ const raw = headers.get("x-oauth-scopes");
46928
+ if (raw === null) return null;
46929
+ return raw.split(",").map((s) => s.trim()).filter(Boolean);
46930
+ }
46931
+ function nonEmpty(s) {
46932
+ return typeof s === "string" && s.trim().length > 0 ? s.trim() : void 0;
46933
+ }
46934
+ function toLookupUser(u) {
46935
+ if (!u.id) return null;
46936
+ const display_name = nonEmpty(u.profile?.display_name) ?? nonEmpty(u.profile?.real_name) ?? nonEmpty(u.real_name) ?? nonEmpty(u.name) ?? u.id;
46937
+ return { user_id: u.id, display_name, is_bot: u.is_bot === true };
46938
+ }
46939
+ function inBotWorkspace(u, botTeamId) {
46940
+ if (u.deleted === true) return false;
46941
+ if (u.is_stranger === true) return false;
46942
+ if (u.id === "USLACKBOT") return false;
46943
+ if (!botTeamId) return false;
46944
+ if (u.team_id === botTeamId) return true;
46945
+ return Array.isArray(u.enterprise_user?.teams) && u.enterprise_user.teams.includes(botTeamId);
46946
+ }
46947
+ var EMAIL_SHAPE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
46948
+ function normaliseName(s) {
46949
+ return s.trim().replace(/^@+/, "").replace(/\s+/g, " ").toLowerCase();
46950
+ }
46951
+ function cacheRow(u) {
46952
+ const user = toLookupUser(u);
46953
+ if (!user) return null;
46954
+ const keys = [u.profile?.display_name, u.profile?.real_name, u.real_name, u.name].map((k) => nonEmpty(k)).filter((k) => k !== void 0).map(normaliseName);
46955
+ return { user, keys: [...new Set(keys)] };
46956
+ }
46957
+ function matchByName(rows, query) {
46958
+ const q = normaliseName(query);
46959
+ if (!q) return [];
46960
+ const exact = rows.filter((r) => r.keys.includes(q));
46961
+ if (exact.length > 0) return exact.map((r) => r.user);
46962
+ return rows.filter((r) => r.keys.some((k) => k.startsWith(q) || k.split(" ").some((w) => w.startsWith(q)))).map((r) => r.user);
46963
+ }
46964
+ function createSlackUserLookup(deps) {
46965
+ const now = deps.now ?? (() => Date.now());
46966
+ const ttl = deps.cacheTtlMs ?? NAME_CACHE_TTL_MS;
46967
+ const minGap = deps.minRefreshIntervalMs ?? NAME_MIN_REFRESH_INTERVAL_MS;
46968
+ const maxResults = deps.maxResults ?? NAME_MAX_RESULTS;
46969
+ let botTeamId;
46970
+ let teamResolved = false;
46971
+ let cache = null;
46972
+ let lastRefreshAttemptAt = -Infinity;
46973
+ let refreshNotBefore = -Infinity;
46974
+ let terminalFailure = null;
46975
+ let lastFailure = null;
46976
+ let partial2 = null;
46977
+ let inflight = null;
46978
+ function headers() {
46979
+ return { Authorization: `Bearer ${deps.token() ?? ""}` };
46980
+ }
46981
+ const workspaceUnknown = (raw) => ({
46982
+ ok: false,
46983
+ users: [],
46984
+ reason: "unknown",
46985
+ raw_error: raw,
46986
+ message: "Could not confirm which Slack workspace the bot belongs to, so no user can be resolved safely. Retry once; if it persists, escalate to an operator."
46987
+ });
46988
+ async function resolveTeam() {
46989
+ if (teamResolved && botTeamId) return { team: botTeamId };
46990
+ try {
46991
+ const res = await deps.fetch("https://slack.com/api/auth.test", { method: "POST", headers: headers() });
46992
+ const data = await res.json();
46993
+ if (data.ok && nonEmpty(data.team_id)) {
46994
+ botTeamId = data.team_id.trim();
46995
+ teamResolved = true;
46996
+ return { team: botTeamId };
46997
+ }
46998
+ if (!data.ok && data.error) {
46999
+ const mapped = failure(res.status, data, res.headers.get("retry-after"), "users:read");
47000
+ if (mapped.reason !== "unknown") return { failure: mapped };
47001
+ }
47002
+ return { failure: workspaceUnknown(data.error ?? "auth_test_no_team_id") };
47003
+ } catch (err) {
47004
+ return { failure: workspaceUnknown(`auth_test_failed: ${err.message}`) };
47005
+ }
47006
+ }
47007
+ function failure(status, data, retryAfter, neededScope) {
47008
+ const err = data.error ?? (status === 429 ? "ratelimited" : "unknown");
47009
+ if (err === "missing_scope") {
47010
+ return { ok: false, users: [], reason: "missing_scope", missing_scope: data.needed ?? neededScope, message: REINSTALL_MESSAGE(data.needed ?? neededScope) };
47011
+ }
47012
+ if (err === "ratelimited" || status === 429) {
47013
+ const secs = Number(retryAfter);
47014
+ return {
47015
+ ok: false,
47016
+ users: [],
47017
+ reason: "rate_limited",
47018
+ retry_after_seconds: Number.isFinite(secs) && secs > 0 ? secs : 30,
47019
+ message: "Slack rate-limited the lookup. Wait, then retry once."
47020
+ };
47021
+ }
47022
+ if (AUTH_ERRORS.has(err)) {
47023
+ return { ok: false, users: [], reason: "auth_failed", raw_error: err, message: "The Slack bot token is not valid. Escalate to an operator; do not ask the end user." };
47024
+ }
47025
+ return { ok: false, users: [], reason: "unknown", raw_error: err, message: `Slack error: ${err}` };
47026
+ }
47027
+ async function lookupByEmail(email2) {
47028
+ const res = await deps.fetch(`https://slack.com/api/users.lookupByEmail?email=${encodeURIComponent(email2)}`, {
47029
+ headers: headers()
47030
+ });
47031
+ const data = await res.json();
47032
+ const scopes = grantedScopes(res.headers);
47033
+ if (scopes !== null && !scopes.includes("users:read.email")) {
47034
+ return { ok: false, matched_by: "email", users: [], reason: "missing_scope", missing_scope: "users:read.email", message: REINSTALL_MESSAGE("users:read.email") };
47035
+ }
47036
+ if (!data.ok) {
47037
+ if (data.error === "users_not_found") {
47038
+ return { ok: false, matched_by: "email", users: [], reason: "not_found", message: "No member of this Slack workspace has that email." };
47039
+ }
47040
+ return { matched_by: "email", ...failure(res.status, data, res.headers.get("retry-after"), "users:read.email") };
47041
+ }
47042
+ const resolved = await resolveTeam();
47043
+ if ("failure" in resolved) return { matched_by: "email", ...resolved.failure };
47044
+ const user = data.user && inBotWorkspace(data.user, resolved.team) ? toLookupUser(data.user) : null;
47045
+ if (!user) {
47046
+ return { ok: false, matched_by: "email", users: [], reason: "not_found", message: "No member of this Slack workspace has that email." };
47047
+ }
47048
+ return { ok: true, matched_by: "email", users: [user] };
47049
+ }
47050
+ async function refreshDirectory() {
47051
+ lastRefreshAttemptAt = now();
47052
+ const result = await fetchDirectory();
47053
+ if (result === null) {
47054
+ terminalFailure = null;
47055
+ lastFailure = null;
47056
+ return null;
47057
+ }
47058
+ lastFailure = result;
47059
+ if (result.reason && TERMINAL_REASONS.has(result.reason)) terminalFailure = result;
47060
+ if (result.reason === "rate_limited" && result.retry_after_seconds) {
47061
+ refreshNotBefore = Math.max(refreshNotBefore, now() + result.retry_after_seconds * 1e3);
47062
+ }
47063
+ return result;
47064
+ }
47065
+ async function fetchDirectory() {
47066
+ const resolved = await resolveTeam();
47067
+ if ("failure" in resolved) return resolved.failure;
47068
+ const team = resolved.team;
47069
+ const resume = partial2 && partial2.team === team && now() - partial2.startedAt < ttl ? partial2 : null;
47070
+ partial2 = null;
47071
+ const rows = resume ? resume.rows : [];
47072
+ let cursor = resume?.cursor;
47073
+ const startedAt = resume?.startedAt ?? now();
47074
+ for (let page = resume?.pages ?? 0; page < USERS_LIST_MAX_PAGES; page++) {
47075
+ const params = new URLSearchParams({ limit: String(USERS_LIST_PAGE_SIZE) });
47076
+ if (cursor) params.set("cursor", cursor);
47077
+ const res = await deps.fetch(`https://slack.com/api/users.list?${params}`, { headers: headers() });
47078
+ const data = await res.json();
47079
+ if (!data.ok) {
47080
+ const failed = failure(res.status, data, res.headers.get("retry-after"), "users:read");
47081
+ if (failed.reason === "rate_limited" && cursor) partial2 = { rows, cursor, pages: page, team, startedAt };
47082
+ return failed;
47083
+ }
47084
+ for (const m of data.members ?? []) {
47085
+ if (!inBotWorkspace(m, team)) continue;
47086
+ const row = cacheRow(m);
47087
+ if (row) rows.push(row);
47088
+ }
47089
+ cursor = nonEmpty(data.response_metadata?.next_cursor);
47090
+ if (!cursor) break;
47091
+ }
47092
+ if (cursor) {
47093
+ return {
47094
+ ok: false,
47095
+ users: [],
47096
+ reason: "unknown",
47097
+ raw_error: "directory_incomplete",
47098
+ message: `Reading the Slack directory stopped at its ${USERS_LIST_MAX_PAGES}-page limit with more pages left, so a name lookup cannot be answered reliably. Look the person up by email instead.`
47099
+ };
47100
+ }
47101
+ cache = { rows, fetchedAt: now() };
47102
+ return null;
47103
+ }
47104
+ async function lookupByName(name) {
47105
+ const fresh = cache !== null && now() - cache.fetchedAt < ttl;
47106
+ if (!fresh) {
47107
+ const refreshAllowedAt = Math.max(lastRefreshAttemptAt + minGap, refreshNotBefore);
47108
+ const mayRefresh = inflight !== null || now() >= refreshAllowedAt;
47109
+ if (!mayRefresh && terminalFailure) {
47110
+ return { matched_by: "name", ...terminalFailure };
47111
+ }
47112
+ if (mayRefresh || cache === null) {
47113
+ if (!mayRefresh && cache === null) {
47114
+ if (lastFailure && lastFailure.reason !== "rate_limited") return { matched_by: "name", ...lastFailure };
47115
+ return {
47116
+ ok: false,
47117
+ matched_by: "name",
47118
+ users: [],
47119
+ reason: "rate_limited",
47120
+ retry_after_seconds: Math.max(1, Math.ceil((refreshAllowedAt - now()) / 1e3)),
47121
+ message: "The Slack directory was refreshed moments ago and is not available yet. Wait, then retry once."
47122
+ };
47123
+ }
47124
+ inflight ??= refreshDirectory().finally(() => {
47125
+ inflight = null;
47126
+ });
47127
+ const failed = await inflight;
47128
+ if (failed && cache === null) return { matched_by: "name", ...failed };
47129
+ if (failed && failed.reason && TERMINAL_REASONS.has(failed.reason)) return { matched_by: "name", ...failed };
47130
+ }
47131
+ }
47132
+ const matches = matchByName(cache.rows, name);
47133
+ if (matches.length === 0) {
47134
+ return { ok: false, matched_by: "name", users: [], reason: "not_found", message: "No member of this Slack workspace has that name." };
47135
+ }
47136
+ const truncated = matches.length > maxResults;
47137
+ return { ok: true, matched_by: "name", users: matches.slice(0, maxResults), ...truncated ? { truncated } : {} };
47138
+ }
47139
+ async function lookup(args) {
47140
+ const email2 = nonEmpty(args["email"]);
47141
+ const name = nonEmpty(args["name"]);
47142
+ if (!email2 && !name) {
47143
+ return { ok: false, users: [], reason: "invalid_input", message: "Pass email or name." };
47144
+ }
47145
+ if (!deps.token()) {
47146
+ return { ok: false, users: [], reason: "auth_failed", raw_error: "no_bot_token", message: "No Slack bot token is configured. Escalate to an operator." };
47147
+ }
47148
+ try {
47149
+ if (email2) {
47150
+ if (!EMAIL_SHAPE.test(email2)) {
47151
+ return { ok: false, users: [], reason: "invalid_input", message: "That is not an email address." };
47152
+ }
47153
+ const byEmail = await lookupByEmail(email2);
47154
+ if (byEmail.reason !== "not_found" || !name) return byEmail;
47155
+ }
47156
+ return await lookupByName(name);
47157
+ } catch (err) {
47158
+ return { ok: false, users: [], reason: "unknown", raw_error: err.message, message: "Slack lookup failed; retry once." };
47159
+ }
47160
+ }
47161
+ return { lookup };
47162
+ }
47163
+
46917
47164
  // ../core/dist/channels/governance/slack-peer-classifier.js
46918
47165
  var CODE_NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
46919
47166
  function findThirdPartyGrant(msg, cfg) {
@@ -51239,6 +51486,18 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
51239
51486
  }
51240
51487
  }
51241
51488
  }
51489
+ },
51490
+ {
51491
+ // CS-2644: resolve a person to the Slack user id needed to @-mention them.
51492
+ name: "slack.lookup_user",
51493
+ description: 'Find a person\'s Slack user id so you can @-mention them. Pass `email` (exact, preferred) or `name` (display name, real name or handle; case-insensitive, exact match first, then prefix). Only members of this bot\'s own Slack workspace are returned. Returns `{ ok, matched_by, users: [{ user_id, display_name, is_bot }], truncated? }`; mention a user by writing `<@USER_ID>` in your slack_reply text. A name can match several people: if `users` has more than one entry, do not guess, confirm which person (or use their email). Emails are never returned. When `ok=false`, branch on `reason`: "not_found" means no member of this workspace matches, so write the name as plain text; "missing_scope" means the Slack app must be reinstalled to allow user lookup, so tell an operator and do NOT treat it as not found; "rate_limited" means wait `retry_after_seconds` and retry once; "auth_failed" means escalate to an operator.',
51494
+ inputSchema: {
51495
+ type: "object",
51496
+ properties: {
51497
+ email: { type: "string", description: "The person's email address. Preferred: it identifies one person exactly." },
51498
+ name: { type: "string", description: "The person's name or Slack handle. Used when no email is given, or when the email matches nobody." }
51499
+ }
51500
+ }
51242
51501
  }
51243
51502
  ]
51244
51503
  }));
@@ -51992,8 +52251,16 @@ ${result.formatted}` : "No messages in range, or the bot is not a member of this
51992
52251
  if (name === "slack.channel_info") {
51993
52252
  return await handleChannelInfo(args);
51994
52253
  }
52254
+ if (name === "slack.lookup_user") {
52255
+ const result = await slackUserLookup.lookup(args);
52256
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], ...result.ok || result.reason === "not_found" ? {} : { isError: true } };
52257
+ }
51995
52258
  throw new Error(`Unknown tool: ${name}`);
51996
52259
  });
52260
+ var slackUserLookup = createSlackUserLookup({
52261
+ fetch: (url, init) => fetch(url, init),
52262
+ token: () => BOT_TOKEN
52263
+ });
51997
52264
  var LIST_CHANNELS_DEFAULT_LIMIT = 50;
51998
52265
  var LIST_CHANNELS_MAX_LIMIT = 200;
51999
52266
  var LIST_CHANNELS_PAGE_SIZE = 200;