@integrity-labs/agt-cli 0.19.20 → 0.19.22

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.
@@ -22,7 +22,7 @@ import {
22
22
  resolveChannels,
23
23
  resolveDmTarget,
24
24
  wrapScheduledTaskPrompt
25
- } from "../chunk-IWFXAB4O.js";
25
+ } from "../chunk-TD4ZSQ74.js";
26
26
  import {
27
27
  findTaskByTemplate,
28
28
  getProjectDir,
@@ -1795,6 +1795,29 @@ function stopRealtimeChat() {
1795
1795
  }
1796
1796
 
1797
1797
  // src/lib/manager-worker.ts
1798
+ function applyRestartAcks(args) {
1799
+ const { agentStates, priorAgents, restartAcks } = args;
1800
+ if (agentStates.length === 0) return false;
1801
+ const priorAcks = /* @__PURE__ */ new Map();
1802
+ for (const prev of priorAgents) {
1803
+ if (prev.lastRestartProcessedAt) {
1804
+ priorAcks.set(prev.agentId, prev.lastRestartProcessedAt);
1805
+ }
1806
+ }
1807
+ let changed = false;
1808
+ for (const ack of agentStates) {
1809
+ const freshAck = restartAcks.get(ack.agentId);
1810
+ const carryForward = priorAcks.get(ack.agentId);
1811
+ if (freshAck) {
1812
+ if (ack.lastRestartProcessedAt !== freshAck) changed = true;
1813
+ ack.lastRestartProcessedAt = freshAck;
1814
+ } else if (carryForward) {
1815
+ if (ack.lastRestartProcessedAt !== carryForward) changed = true;
1816
+ ack.lastRestartProcessedAt = carryForward;
1817
+ }
1818
+ }
1819
+ return changed;
1820
+ }
1798
1821
  var GATEWAY_PORT_BASE = 18800;
1799
1822
  var GATEWAY_PORT_STEP = 10;
1800
1823
  var GATEWAY_PORT_MAX = 18899;
@@ -1852,6 +1875,52 @@ function extractCharterTelegramPeers(rawContent, gateContext) {
1852
1875
  return [];
1853
1876
  }
1854
1877
  }
1878
+ function extractCharterSlackPeers(rawContent, gateContext) {
1879
+ if (!rawContent || rawContent.length === 0) return [];
1880
+ try {
1881
+ const parsed = extractFrontmatter(rawContent);
1882
+ const frontmatter = parsed.frontmatter;
1883
+ const peers = frontmatter?.multi_agent?.slack_peers;
1884
+ if (!peers || !Array.isArray(peers)) return [];
1885
+ const teamUserIds = new Set(gateContext?.teamPeerSlackUserIds ?? []);
1886
+ const grants = gateContext?.crossTeamGrants ?? [];
1887
+ const intraOrg = gateContext?.crossTeamPeerIntraOrg ?? "unrestricted";
1888
+ const now = (gateContext?.now ?? (() => /* @__PURE__ */ new Date()))();
1889
+ const out = [];
1890
+ for (const p of peers) {
1891
+ if (!p || typeof p !== "object" || typeof p.code_name !== "string" || typeof p.bot_user_id !== "string" || p.bot_user_id.length === 0) {
1892
+ continue;
1893
+ }
1894
+ const grantId = typeof p.cross_team_grant_id === "string" && p.cross_team_grant_id.length > 0 ? p.cross_team_grant_id : null;
1895
+ let gate = null;
1896
+ if (gateContext === void 0) {
1897
+ gate = "same_team";
1898
+ } else if (teamUserIds.has(p.bot_user_id)) {
1899
+ gate = "same_team";
1900
+ } else if (grantId) {
1901
+ const grant = grants.find((g) => g.grant_id === grantId);
1902
+ if (grant && !grant.revoked_at && (!grant.expires_at || new Date(grant.expires_at) > now) && (grant.granted_agent_slack_user_id ?? null) === p.bot_user_id) {
1903
+ gate = `grant:${grantId}`;
1904
+ } else {
1905
+ gate = null;
1906
+ }
1907
+ } else if (intraOrg === "unrestricted") {
1908
+ gate = "intra_org_unrestricted";
1909
+ } else {
1910
+ gate = null;
1911
+ }
1912
+ out.push({
1913
+ code_name: p.code_name,
1914
+ bot_user_id: p.bot_user_id,
1915
+ agent_id: "",
1916
+ gate_path: gate
1917
+ });
1918
+ }
1919
+ return out;
1920
+ } catch {
1921
+ return [];
1922
+ }
1923
+ }
1855
1924
  function truncateForLog(s) {
1856
1925
  const lines = s.split("\n").filter((l) => l.length > 0);
1857
1926
  return lines.slice(-PANE_TAIL_PREVIEW_LINES).map((l) => ` | ${l}`).join("\n");
@@ -1991,7 +2060,7 @@ function clearAgentCaches(agentId, codeName) {
1991
2060
  var cachedFrameworkVersion = null;
1992
2061
  var lastVersionCheckAt = 0;
1993
2062
  var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
1994
- var agtCliVersion = true ? "0.19.20" : "dev";
2063
+ var agtCliVersion = true ? "0.19.22" : "dev";
1995
2064
  function resolveBrewPath(execFileSync3) {
1996
2065
  try {
1997
2066
  const out = execFileSync3("which", ["brew"], { timeout: 5e3 }).toString().trim();
@@ -2993,11 +3062,12 @@ async function pollCycle() {
2993
3062
  }
2994
3063
  }
2995
3064
  }
2996
- if (restartAcks.size > 0) {
2997
- for (const ack of agentStates) {
2998
- const requested = restartAcks.get(ack.agentId);
2999
- if (requested) ack.lastRestartProcessedAt = requested;
3000
- }
3065
+ const restartAckStateChanged = applyRestartAcks({
3066
+ agentStates,
3067
+ priorAgents: state.agents,
3068
+ restartAcks
3069
+ });
3070
+ if (restartAckStateChanged) {
3001
3071
  try {
3002
3072
  const ackedState = { ...state, agents: agentStates };
3003
3073
  writeFileSync3(getStateFile(), JSON.stringify(ackedState, null, 2));
@@ -3506,14 +3576,23 @@ async function processAgent(agent, agentStates) {
3506
3576
  })();
3507
3577
  const teamSettingsForHash = channelId === "telegram" || channelId === "slack" ? { peer_disabled: peerDisabledMode } : null;
3508
3578
  const crossTeamData = refreshData;
3509
- const refreshHasCrossTeamFields = Array.isArray(crossTeamData.team_peer_bot_ids);
3579
+ const refreshHasCrossTeamFields = channelId === "telegram" ? Array.isArray(crossTeamData.team_peer_bot_ids) : channelId === "slack" ? Array.isArray(crossTeamData.team_peer_slack_user_ids) : false;
3510
3580
  const gateContext = refreshHasCrossTeamFields ? {
3511
3581
  teamPeerBotIds: crossTeamData.team_peer_bot_ids ?? [],
3582
+ teamPeerSlackUserIds: crossTeamData.team_peer_slack_user_ids ?? [],
3512
3583
  crossTeamGrants: crossTeamData.cross_team_grants?.inbound ?? [],
3513
3584
  crossTeamPeerIntraOrg: crossTeamData.organization?.cross_team_peer_intra_org ?? "unrestricted"
3514
3585
  } : void 0;
3515
- const peersForHash = channelId === "telegram" ? extractCharterTelegramPeers(refreshData.charter?.raw_content ?? "", gateContext) : null;
3516
- const configHash = createHash2("sha256").update(canonicalJson({ config: entry.config, team: teamSettingsForHash, peers: peersForHash })).digest("hex");
3586
+ const peersForHash = channelId === "telegram" ? extractCharterTelegramPeers(refreshData.charter?.raw_content ?? "", gateContext) : channelId === "slack" ? extractCharterSlackPeers(refreshData.charter?.raw_content ?? "", gateContext) : null;
3587
+ const CHANNEL_WRITE_VERSION = 3;
3588
+ const configHash = createHash2("sha256").update(
3589
+ canonicalJson({
3590
+ writeVersion: CHANNEL_WRITE_VERSION,
3591
+ config: entry.config,
3592
+ team: teamSettingsForHash,
3593
+ peers: peersForHash
3594
+ })
3595
+ ).digest("hex");
3517
3596
  const cacheKey = `${agent.agent_id}:${channelId}`;
3518
3597
  let onDiskPresent = true;
3519
3598
  try {
@@ -3536,11 +3615,19 @@ async function processAgent(agent, agentStates) {
3536
3615
  const peerDisabled = channelId === "telegram" || channelId === "slack" ? peerDisabledMode : void 0;
3537
3616
  const telegramPeerDisabled = channelId === "telegram" ? peerDisabledMode === "all" : void 0;
3538
3617
  const telegramPeers = channelId === "telegram" ? extractCharterTelegramPeers(refreshData.charter?.raw_content ?? "", gateContext) : void 0;
3618
+ const slackPeers = channelId === "slack" ? extractCharterSlackPeers(refreshData.charter?.raw_content ?? "", gateContext) : void 0;
3539
3619
  frameworkAdapter.writeChannelCredentials(
3540
3620
  agent.code_name,
3541
3621
  channelId,
3542
3622
  entry.config,
3543
- { sessionMode: sessionMode2, agentId: agent.agent_id, telegramPeerDisabled, peerDisabled, telegramPeers }
3623
+ {
3624
+ sessionMode: sessionMode2,
3625
+ agentId: agent.agent_id,
3626
+ telegramPeerDisabled,
3627
+ peerDisabled,
3628
+ telegramPeers,
3629
+ slackPeers
3630
+ }
3544
3631
  );
3545
3632
  knownChannelConfigHashes.set(cacheKey, configHash);
3546
3633
  saveChannelHashCache2();
@@ -6443,6 +6530,15 @@ function generateArtifacts(agent, refreshData, adapter) {
6443
6530
  deploymentTarget: "local_docker",
6444
6531
  gatewayPort: 9e3,
6445
6532
  team: refreshData.team ?? void 0,
6533
+ // ENG-5009: org name for the identity-preamble. Only present when
6534
+ // /host/refresh ships the field — falls through cleanly for older
6535
+ // API payloads that don't carry it.
6536
+ organization: (() => {
6537
+ const org = refreshData.organization;
6538
+ if (typeof org?.name !== "string") return void 0;
6539
+ const name = org.name.trim();
6540
+ return name.length > 0 ? { name } : void 0;
6541
+ })(),
6446
6542
  timezone: agentTimezone,
6447
6543
  reportsTo,
6448
6544
  personalitySeed,
@@ -6951,6 +7047,8 @@ process.on("disconnect", () => {
6951
7047
  });
6952
7048
  export {
6953
7049
  ChildProcessError,
7050
+ applyRestartAcks,
7051
+ extractCharterSlackPeers,
6954
7052
  extractCharterTelegramPeers,
6955
7053
  markAgentForFreshMemorySync,
6956
7054
  startManager,