@indigoai-us/hq-cli 5.345.241 → 5.345.243

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 (125) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-grant.sh +170 -8
  3. package/assets/scaffold/core/scripts/hq-delegate-publish.sh +21 -1
  4. package/assets/scaffold/core/scripts/lib/delegate-engine.sh +77 -0
  5. package/dist/command-catalog.generated.d.ts +28 -8
  6. package/dist/command-catalog.generated.js +33 -8
  7. package/dist/commands/cloud-off-gate.d.ts +7 -7
  8. package/dist/commands/cloud-off-gate.js +26 -38
  9. package/dist/commands/core-delegate-w1b.js +307 -26
  10. package/dist/commands/core-delegate.js +2 -0
  11. package/dist/commands/core-handoff.js +1 -1
  12. package/dist/commands/core-job-model-auth.d.ts +95 -0
  13. package/dist/commands/core-job-model-auth.js +247 -0
  14. package/dist/commands/core-job-run-native.js +280 -12
  15. package/dist/commands/core.js +1 -0
  16. package/dist/commands/files-browse.js +2 -0
  17. package/dist/commands/files.js +4 -0
  18. package/dist/commands/integrations-core.d.ts +11 -0
  19. package/dist/commands/integrations-core.js +15 -1
  20. package/dist/commands/lanes-link.js +2 -2
  21. package/dist/commands/lanes-loop.d.ts +2 -2
  22. package/dist/commands/lanes-loop.js +5 -5
  23. package/dist/commands/lanes-questions.js +1 -1
  24. package/dist/commands/lanes-stories.js +1 -1
  25. package/dist/commands/lanes.js +80 -14
  26. package/dist/commands/rescue.d.ts +3 -2
  27. package/dist/commands/rescue.js +48 -34
  28. package/dist/commands/search.d.ts +6 -0
  29. package/dist/commands/search.js +24 -4
  30. package/dist/commands/sources.js +6 -2
  31. package/dist/commands/sync-core.d.ts +8 -0
  32. package/dist/commands/sync-core.js +43 -0
  33. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +1737 -1450
  34. package/dist/hq-cloud-sync-runner/package.json +1 -1
  35. package/dist/lib/capacity/accounts.d.ts +1 -1
  36. package/dist/lib/capacity/accounts.js +1 -1
  37. package/dist/lib/capacity/freshness.d.ts +1 -1
  38. package/dist/lib/capacity/freshness.js +1 -1
  39. package/dist/lib/capacity/route.js +1 -1
  40. package/dist/lib/claude-md-imports.d.ts +52 -0
  41. package/dist/lib/claude-md-imports.js +226 -0
  42. package/dist/lib/daemon/catalog.d.ts +3 -0
  43. package/dist/lib/daemon/hook-requests.d.ts +1 -1
  44. package/dist/lib/daemon/hook-requests.js +4 -2
  45. package/dist/lib/daemon/run.js +16 -22
  46. package/dist/lib/doctor/checks/claude-imports.d.ts +29 -0
  47. package/dist/lib/doctor/checks/claude-imports.js +131 -0
  48. package/dist/lib/doctor/fix/apply.d.ts +7 -0
  49. package/dist/lib/doctor/fix/apply.js +77 -0
  50. package/dist/lib/doctor/fix/remediation.d.ts +11 -1
  51. package/dist/lib/doctor/fix/remediation.js +42 -0
  52. package/dist/lib/doctor/registry.js +4 -0
  53. package/dist/lib/environment/work-requirements.d.ts +1 -1
  54. package/dist/lib/environment/work-requirements.js +1 -1
  55. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  56. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  57. package/dist/lib/hook-engine/coverage.js +11 -3
  58. package/dist/lib/hook-engine/git-stop-config.json +510 -510
  59. package/dist/lib/hook-engine/native-precompact-compatibility.json +443 -443
  60. package/dist/lib/hook-engine/native-stop-compatibility.json +359 -359
  61. package/dist/lib/hot-channels/adapters/meetings.d.ts +1 -16
  62. package/dist/lib/hot-channels/adapters/meetings.js +3 -28
  63. package/dist/lib/hot-channels/adapters/slack.d.ts +3 -1
  64. package/dist/lib/hot-channels/adapters/slack.js +4 -1
  65. package/dist/lib/hot-channels/contract.d.ts +14 -0
  66. package/dist/lib/hot-channels/fleet-complete.d.ts +18 -2
  67. package/dist/lib/hot-channels/fleet-complete.js +29 -4
  68. package/dist/lib/hot-channels/meeting-source-ref.d.ts +17 -0
  69. package/dist/lib/hot-channels/meeting-source-ref.js +32 -0
  70. package/dist/lib/hot-channels/prompts/signals-pass.md +6 -1
  71. package/dist/lib/hot-channels/run.d.ts +10 -0
  72. package/dist/lib/hot-channels/run.js +34 -0
  73. package/dist/lib/hot-channels/signals-pass.d.ts +27 -0
  74. package/dist/lib/hot-channels/signals-pass.js +57 -2
  75. package/dist/lib/hot-channels/signals-runtime.js +3 -2
  76. package/dist/lib/lanes/accounts.js +2 -2
  77. package/dist/lib/lanes/claude-balance.d.ts +6 -0
  78. package/dist/lib/lanes/claude-balance.js +124 -0
  79. package/dist/lib/lanes/grants.js +15 -2
  80. package/dist/lib/lanes/hq-root.d.ts +1 -1
  81. package/dist/lib/lanes/hq-root.js +1 -1
  82. package/dist/lib/lanes/links.d.ts +1 -1
  83. package/dist/lib/lanes/liveness.d.ts +3 -0
  84. package/dist/lib/lanes/liveness.js +61 -7
  85. package/dist/lib/lanes/models.d.ts +1 -1
  86. package/dist/lib/lanes/models.js +1 -1
  87. package/dist/lib/lanes/questions.d.ts +1 -1
  88. package/dist/lib/lanes/questions.js +2 -2
  89. package/dist/lib/lanes/spawn.js +4 -6
  90. package/dist/lib/lanes/store.d.ts +13 -2
  91. package/dist/lib/lanes/store.js +13 -5
  92. package/dist/lib/lanes/types.d.ts +7 -7
  93. package/dist/lib/lanes/types.js +1 -1
  94. package/dist/lib/lanes/watcher-main.js +1 -1
  95. package/dist/lib/lanes/watcher.d.ts +1 -1
  96. package/dist/lib/lanes/watcher.js +1 -1
  97. package/dist/lib/onboarding/cli/onboard.js +5 -0
  98. package/dist/lib/signals/sanitize.d.ts +19 -0
  99. package/dist/lib/signals/sanitize.js +103 -7
  100. package/dist/lib/signals/steps/upload.d.ts +40 -1
  101. package/dist/lib/signals/steps/upload.js +122 -6
  102. package/dist/lib/sync-core/access-refresh.d.ts +29 -0
  103. package/dist/lib/sync-core/access-refresh.js +97 -0
  104. package/dist/lib/sync-core/company-adoption.d.ts +33 -0
  105. package/dist/lib/sync-core/company-adoption.js +223 -0
  106. package/dist/lib/sync-core/engine-home.d.ts +1 -0
  107. package/dist/lib/sync-core/engine-owned.d.ts +13 -0
  108. package/dist/lib/sync-core/engine-owned.js +38 -0
  109. package/dist/lib/sync-core/hand-back.d.ts +17 -0
  110. package/dist/lib/sync-core/hand-back.js +23 -0
  111. package/dist/lib/sync-core/post-apply-reindex.d.ts +33 -0
  112. package/dist/lib/sync-core/post-apply-reindex.js +149 -0
  113. package/dist/lib/sync-core/reconcile.d.ts +10 -0
  114. package/dist/lib/sync-core/reconcile.js +117 -12
  115. package/dist/lib/sync-core/rollout-state.d.ts +2 -0
  116. package/dist/lib/sync-core/rollout-state.js +6 -0
  117. package/dist/lib/vault-sync-switches.d.ts +14 -0
  118. package/dist/lib/vault-sync-switches.js +22 -0
  119. package/dist/lib/workers-registry/index.d.ts +1 -1
  120. package/dist/lib/workers-registry/index.js +1 -1
  121. package/dist/utils/github-tag-fallback.d.ts +16 -0
  122. package/dist/utils/github-tag-fallback.js +126 -0
  123. package/dist/utils/version-report.d.ts +2 -1
  124. package/dist/utils/version-report.js +40 -27
  125. package/package.json +8 -8
@@ -15,6 +15,7 @@ import { resolveCompanySlug, resolvePersonWithRosterFallback, } from "./people.j
15
15
  import { findHqRoot } from "../utils/manifest.js";
16
16
  import { maxLength } from "../utils/table-width.js";
17
17
  import { resolveCompanyFlagGate } from "../lib/flag-registry.js";
18
+ import { raiseAccessRefresh } from "../lib/sync-core/access-refresh.js";
18
19
  const PERSON_UID_PATTERN = /^(prs|agt)_[A-Za-z0-9_-]+$/;
19
20
  const AGENT_UID_PATTERN = /^agt_[A-Za-z0-9_-]+$/;
20
21
  export const FILES_SHARE_EMPTY_PREFIX_WARNING_FLAG = "files.share-empty-prefix-warning";
@@ -400,6 +401,7 @@ export function registerFilesCommand(program) {
400
401
  }
401
402
  process.exit(1);
402
403
  }
404
+ raiseAccessRefresh({ companyUid });
403
405
  const removedCount = body.removedEntries;
404
406
  const cleanupMessage = typeof removedCount === "number" && removedCount > 0
405
407
  ? `Removed ${removedCount} empty ${removedCount === 1 ? "entry" : "entries"} from '${canonicalPrefix}'. `
@@ -431,6 +433,7 @@ export function registerFilesCommand(program) {
431
433
  body: { prefix: candidate, granteeType, granteeId },
432
434
  });
433
435
  if (res.ok) {
436
+ raiseAccessRefresh({ companyUid });
434
437
  console.log(chalk.green(`Removed grant for ${principalLabel} on '${displayAclPattern(candidate)}'`));
435
438
  if (bare && candidate === canonicalPrefix) {
436
439
  console.log(chalk.dim(`This removed the exact '${candidate}' grant. A grant for ${principalLabel} on ` +
@@ -1230,6 +1233,7 @@ async function runDirectGrant(params) {
1230
1233
  }
1231
1234
  process.exit(1);
1232
1235
  }
1236
+ raiseAccessRefresh({ companyUid });
1233
1237
  const data = (await res.json());
1234
1238
  const printedPrefix = data.acl?.path ?? data.acl?.prefix ?? canonicalPrefix;
1235
1239
  await warnIfEmptySharePrefix({
@@ -327,6 +327,17 @@ export declare function isBuiltInGatewayProvider(provider: string): boolean;
327
327
  * for it. Fails closed: a row without `viewerAccess` is not listed.
328
328
  */
329
329
  export declare function fetchUsableApps(token: string, companyUid: string): Promise<UsableAppsResult>;
330
+ /**
331
+ * `fetchUsableApps` plus every connection that is not revoked, usable by the
332
+ * caller or not (`knownConnections`), from the same single summary read. The
333
+ * hot-channel sync uses the known ones only to find saved channel picks.
334
+ */
335
+ export declare function fetchIntegrationsSummary(token: string, companyUid: string): Promise<UsableAppsResult & {
336
+ knownConnections: Array<{
337
+ connectionId: string;
338
+ provider: string;
339
+ }>;
340
+ }>;
330
341
  /**
331
342
  * Resolve one connection by `--connection acct_…` or `--provider linear`
332
343
  * (matches `factory:<slug>`, bare provider ids, and an installation's human
@@ -504,6 +504,15 @@ function gatewayHasProvider(row) {
504
504
  * for it. Fails closed: a row without `viewerAccess` is not listed.
505
505
  */
506
506
  export async function fetchUsableApps(token, companyUid) {
507
+ const { knownConnections: _known, ...usable } = await fetchIntegrationsSummary(token, companyUid);
508
+ return usable;
509
+ }
510
+ /**
511
+ * `fetchUsableApps` plus every connection that is not revoked, usable by the
512
+ * caller or not (`knownConnections`), from the same single summary read. The
513
+ * hot-channel sync uses the known ones only to find saved channel picks.
514
+ */
515
+ export async function fetchIntegrationsSummary(token, companyUid) {
507
516
  const res = await vaultApiFetch({
508
517
  token,
509
518
  path: "/v1/integrations/admin",
@@ -544,7 +553,12 @@ export async function fetchUsableApps(token, companyUid) {
544
553
  })
545
554
  .sort((a, b) => compareNames(a.name, b.name))
546
555
  : [];
547
- return { companyUid: data.companyUid ?? companyUid, viewerAccessKnown, apps };
556
+ // Revoked rows count: a pick the person saved on a connection that was
557
+ // later revoked still says which channels they want.
558
+ const knownConnections = rows
559
+ .filter((row) => typeof row.id === "string" && typeof row.provider === "string")
560
+ .map((row) => ({ connectionId: row.id, provider: row.provider }));
561
+ return { companyUid: data.companyUid ?? companyUid, viewerAccessKnown, apps, knownConnections };
548
562
  }
549
563
  /**
550
564
  * Resolve one connection by `--connection acct_…` or `--provider linear`
@@ -32,7 +32,7 @@ async function readHookInput() {
32
32
  function commandError(error) {
33
33
  const code = error instanceof LaneLinkError ? error.code : "internal";
34
34
  const message = error instanceof Error ? error.message : String(error);
35
- process.stderr.write(`hq lanes link: ${message}\n`);
35
+ process.stderr.write(`hq runners link: ${message}\n`);
36
36
  writeJson({ error: code, message });
37
37
  process.exitCode = 1;
38
38
  }
@@ -82,7 +82,7 @@ export function registerLanesLinkCommand(lanes) {
82
82
  writeJson(result.output);
83
83
  }
84
84
  catch (error) {
85
- process.stderr.write(`hq lanes link _deliver: ${error instanceof Error ? error.message : String(error)}\n`);
85
+ process.stderr.write(`hq runners link _deliver: ${error instanceof Error ? error.message : String(error)}\n`);
86
86
  // Hook failures are fail-open; queued messages remain available if delivery failed.
87
87
  }
88
88
  });
@@ -10,7 +10,7 @@ import type { LaneRecord } from "../lib/lanes/types.js";
10
10
  */
11
11
  export declare function settleLoopLaneIdle(hqRoot: string, laneId: string): LaneRecord;
12
12
  /**
13
- * The next phase resumes the provider session, which `hq lanes resume` only
13
+ * The next phase resumes the provider session, which `hq runners resume` only
14
14
  * accepts from a resumable state. An idle loop lane sits in `running` with no
15
15
  * worker, so it is handed to resume as the `done` lane the phase left.
16
16
  */
@@ -44,7 +44,7 @@ export interface LoopControllerDeps {
44
44
  }
45
45
  /**
46
46
  * terminal_reason values for interrupts HQ issues itself. An operator
47
- * interrupt (`hq lanes interrupt`) records `operator_interrupt`; these keep a
47
+ * interrupt (`hq runners interrupt`) records `operator_interrupt`; these keep a
48
48
  * system recovery from looking like an operator action in the lane record.
49
49
  */
50
50
  export declare const LOOP_CONTROLLER_RECOVERY_REASON = "loop_controller_recovery";
@@ -28,7 +28,7 @@ export function settleLoopLaneIdle(hqRoot, laneId) {
28
28
  return casLoopLaneState(hqRoot, laneId, "done", "running");
29
29
  }
30
30
  /**
31
- * The next phase resumes the provider session, which `hq lanes resume` only
31
+ * The next phase resumes the provider session, which `hq runners resume` only
32
32
  * accepts from a resumable state. An idle loop lane sits in `running` with no
33
33
  * worker, so it is handed to resume as the `done` lane the phase left.
34
34
  */
@@ -94,7 +94,7 @@ function casLoopLaneState(hqRoot, laneId, from, to) {
94
94
  }
95
95
  /**
96
96
  * terminal_reason values for interrupts HQ issues itself. An operator
97
- * interrupt (`hq lanes interrupt`) records `operator_interrupt`; these keep a
97
+ * interrupt (`hq runners interrupt`) records `operator_interrupt`; these keep a
98
98
  * system recovery from looking like an operator action in the lane record.
99
99
  */
100
100
  export const LOOP_CONTROLLER_RECOVERY_REASON = "loop_controller_recovery";
@@ -166,7 +166,7 @@ export async function runLaneLoopController(ctx, laneId, deps) {
166
166
  // no longer be loaded or cancelled.
167
167
  const ignoreEnvelopeStory = envelopeStory !== undefined && !current.story_id && !!current.no_story_reason;
168
168
  if (ignoreEnvelopeStory) {
169
- process.stderr.write(`hq lanes: ignoring envelope story_id ${envelopeStory} for no-story lane ${laneId}\n`);
169
+ process.stderr.write(`hq runners: ignoring envelope story_id ${envelopeStory} for no-story lane ${laneId}\n`);
170
170
  }
171
171
  const storyId = envelopeStory !== undefined && !ignoreEnvelopeStory ? envelopeStory : current.story_id;
172
172
  if (storyId !== current.story_id) {
@@ -281,7 +281,7 @@ export async function runLaneLoopController(ctx, laneId, deps) {
281
281
  catch (error) {
282
282
  // Transient admission refusal before any engine launched (for
283
283
  // example a store lock timeout). The envelope is already active, so keep it
284
- // and park the lane as queued with a reason `hq lanes show`
284
+ // and park the lane as queued with a reason `hq runners show`
285
285
  // displays; the next admission launches this phase from
286
286
  // pending_resume and the wait below picks up its result.
287
287
  if (!(error instanceof LanesError) ||
@@ -298,7 +298,7 @@ export async function runLaneLoopController(ctx, laneId, deps) {
298
298
  let interruptPromise;
299
299
  const abortPhase = () => {
300
300
  interruptPromise = deps.interruptLane(laneId, "loop phase deadline exceeded", { preserveLoopQueue: true, terminalReason: LOOP_PHASE_DEADLINE_REASON }).catch((error) => {
301
- process.stderr.write(`hq lanes: could not interrupt stalled loop phase ${laneId}: ${error instanceof Error ? error.message : String(error)}\n`);
301
+ process.stderr.write(`hq runners: could not interrupt stalled loop phase ${laneId}: ${error instanceof Error ? error.message : String(error)}\n`);
302
302
  });
303
303
  };
304
304
  signal.addEventListener("abort", abortPhase, { once: true });
@@ -940,7 +940,7 @@ export function createLaneQuestionsHandlers(deps) {
940
940
  });
941
941
  if (isLoopStallQuestion) {
942
942
  if (!loopStallResult && !retryingSameLoopAnswer) {
943
- process.stderr.write(`hq lanes: loop phase for question ${questionId} was already re-enqueued; recording answer as superseded\n`);
943
+ process.stderr.write(`hq runners: loop phase for question ${questionId} was already re-enqueued; recording answer as superseded\n`);
944
944
  printJson({ ok: true, action: "questions.answer", lane_id: askingLane.lane_id, question: updated, loop_action: "superseded" });
945
945
  return;
946
946
  }
@@ -143,7 +143,7 @@ export function createLaneStoryHandlers(deps) {
143
143
  });
144
144
  }
145
145
  catch (rollbackErr) {
146
- process.stderr.write(`hq lanes: story transition rollback failed for ${next.lane_id}/${projectId}/${storyId}: ${rollbackErr instanceof Error ? rollbackErr.message : String(rollbackErr)}\n`);
146
+ process.stderr.write(`hq runners: story transition rollback failed for ${next.lane_id}/${projectId}/${storyId}: ${rollbackErr instanceof Error ? rollbackErr.message : String(rollbackErr)}\n`);
147
147
  }
148
148
  throw err;
149
149
  }
@@ -65,14 +65,14 @@ import { createOutpostRegistryWorkerApprovalContext, parseOutpostRegistryWorkerA
65
65
  import { OUTPOST_DIR, OUTPOST_ID_PATH, readOutpostIdentity, resolveAdmissionHost, } from "../lib/lanes/admission-host.js";
66
66
  export { OUTPOST_DIR, OUTPOST_ID_PATH, readOutpostIdentity } from "../lib/lanes/admission-host.js";
67
67
  import { buildOutpostCapacityCommand, buildOutpostIdentityBackfillCommand, buildOutpostLaneCommand, buildOutpostQuestionListCommand, buildOutpostPickupCommand, createOutpostsClient, dispatchErrorMessage, dispatchOutpostPickup, buildOutpostLaneListCommand, buildOutpostLegacyLaneUlidListCommand, REMOTE_LANE_READ_ENV, outpostRejectedEffortOption, parseOutpostPickupPayload, PICKUP_WAIT_MS, stageOutpostPayload, } from "../lib/lanes/outpost-dispatch.js";
68
- import { assertCompanyOutpostBelongsTo, companyAwareExecPort, companyOutpostAccessRequired, companyOutpostNeedsCompany, companyOutpostNotLaneReady, companyOutpostRefusal, CompanyOutpostTargets, isCompanyOutpostId, isCompanyOutpostRefusal, isNoCompanyOutposts, listCompanyOutpostCandidates, readyCompanyOutpostIds, } from "../lib/lanes/company-outposts.js";
68
+ import { assertCompanyOutpostBelongsTo, companyAwareExecPort, companyOutpostAccessRequired, companyOutpostNeedsCompany, companyOutpostNotLaneReady, companyOutpostRefusal, CompanyOutpostTargets, companyUidOfFirstOutpostId, isCompanyOutpostId, isCompanyOutpostRefusal, isNoCompanyOutposts, listCompanyOutpostCandidates, readyCompanyOutpostIds, } from "../lib/lanes/company-outposts.js";
69
69
  import { outpostHireSummaryCacheKey, OUTPOST_HIRE_SUMMARY_CACHE_TTL_MS, readOutpostHireSummaryCache, readOutpostHireSummaryCacheIncludingStale, writeOutpostHireSummaryCache, } from "../lib/lanes/outpost-hire-cache.js";
70
70
  import { buildHostCapacitySnapshot, chooseHostForLane, hostCapacitySnapshotToWire, parseHostCapacitySnapshot, } from "../lib/lanes/host-capacity.js";
71
71
  import { readHostCompute } from "../lib/lanes/host-compute.js";
72
72
  import { resolveCanonicalHost } from "../lib/lanes/canonical-host.js";
73
73
  import { parseLaneRunSize, runSizeMediansByRepo } from "../lib/lanes/run-size.js";
74
74
  import { readInstanceIdFromDisk } from "../lib/lanes/machine-identity.js";
75
- import { BALANCE_MOVABLE_STATES, selectClaudeAccount, } from "../lib/lanes/claude-balance.js";
75
+ import { BALANCE_MOVABLE_STATES, selectClaudeAccount, selectCompanyOutpostClaudeAccount, } from "../lib/lanes/claude-balance.js";
76
76
  import { parseUserYaml } from "../utils/user-yaml-error.js";
77
77
  import { backfillOutpostIdentityMarker as backfillOutpostIdentityMarkerImpl, createOutpostIdentityMarkerIfMissing, validateOutpostIdentityId, } from "../lib/lanes/outpost-identity.js";
78
78
  import { vaultApiFetch } from "../utils/vault-api.js";
@@ -1647,6 +1647,8 @@ async function readOutpostCapacityUncached(ctx, outpostId, waitMs = CAPACITY_PRO
1647
1647
  });
1648
1648
  }
1649
1649
  catch (err) {
1650
+ if (isCompanyOutpostRefusal(err))
1651
+ throw err;
1650
1652
  throw new LanesError("outpost_capacity_unavailable", `Could not read capacity from Outpost ${outpostId}: ${dispatchErrorMessage(err)}`, { outpost_id: outpostId });
1651
1653
  }
1652
1654
  if (result.done !== true || result.status !== "Success" || result.exitCode !== 0) {
@@ -2202,9 +2204,25 @@ async function resolveCommandLaneTarget(ctx, laneId, options = {}) {
2202
2204
  (hostSuffix && sanitizeHostComponent(hostSuffix) !== hostSuffix)) {
2203
2205
  throw commandLaneNotFound(laneId, options.outpostHint === true);
2204
2206
  }
2207
+ const requestedCompanyOutpost = options.outpostId !== undefined && isCompanyOutpostId(options.outpostId.trim())
2208
+ ? options.outpostId.trim()
2209
+ : undefined;
2210
+ if (requestedCompanyOutpost !== undefined) {
2211
+ const companySlug = options.company?.trim();
2212
+ const ownerUid = companyUidOfFirstOutpostId(requestedCompanyOutpost);
2213
+ if (!companySlug && ownerUid === undefined)
2214
+ throw companyOutpostNeedsCompany(requestedCompanyOutpost);
2215
+ const company = companySlug
2216
+ ? await ctx.resolveCompany(companySlug)
2217
+ : await ctx.resolveActiveCompany(ownerUid);
2218
+ if (!company) {
2219
+ throw new LanesError("company_outpost_not_a_member", `Only current members of the company that owns Outpost ${requestedCompanyOutpost} can use it.`, { outpost_id: requestedCompanyOutpost, company_uid: ownerUid });
2220
+ }
2221
+ await assertKnownLaneOutpost(ctx, requestedCompanyOutpost, company);
2222
+ }
2205
2223
  let rawOutpostRoutes;
2206
2224
  try {
2207
- rawOutpostRoutes = await ctx.listOutpostRoutes();
2225
+ rawOutpostRoutes = requestedCompanyOutpost !== undefined ? [] : await ctx.listOutpostRoutes();
2208
2226
  }
2209
2227
  catch (err) {
2210
2228
  throw new LanesError("outpost_list_unavailable", `Could not resolve registered Outposts for lane ${laneId}: ${dispatchErrorMessage(err)}`, { lane_id: laneId });
@@ -2239,7 +2257,7 @@ async function resolveCommandLaneTarget(ctx, laneId, options = {}) {
2239
2257
  if (options.outpostId !== undefined && !requestedOutpostId) {
2240
2258
  throw new LanesError("outpost_id_invalid", "--outpost must be a registered Outpost id", { lane_id: laneId });
2241
2259
  }
2242
- if (requestedOutpostId !== undefined && !outpostIds.includes(requestedOutpostId)) {
2260
+ if (requestedOutpostId !== undefined && requestedCompanyOutpost === undefined && !outpostIds.includes(requestedOutpostId)) {
2243
2261
  throw new LanesError("outpost_not_registered", `Outpost ${requestedOutpostId} is not registered`, { lane_id: laneId, outpost_id: requestedOutpostId });
2244
2262
  }
2245
2263
  const hostRoutes = hostlessUlidLookup
@@ -2360,6 +2378,34 @@ function commandLaneNotFound(laneId, outpostHint, details = {}) {
2360
2378
  : "";
2361
2379
  return new LanesError("lane_not_found", `Could not resolve lane ${laneId}: no matching local record or reachable registered Outpost owner record was found${hint}`, { lane_id: laneId, ...details });
2362
2380
  }
2381
+ async function loadCompanyOutpostBalanceHost(ctx, outpostId) {
2382
+ const host = { kind: "outpost", id: outpostId };
2383
+ let capacity;
2384
+ try {
2385
+ capacity = await readOutpostCapacity(ctx, outpostId, outpostSingleLaneWaitMs(ctx.env));
2386
+ }
2387
+ catch (err) {
2388
+ if (isCompanyOutpostRefusal(err))
2389
+ throw err;
2390
+ const reason = isLanesError(err) ? err.error : "outpost_capacity_unavailable";
2391
+ throw new LanesError("claude_account_balance_target_host_unavailable", `Cannot verify Claude accounts on target host outpost:${outpostId}: ${dispatchErrorMessage(err)}`, { requested_placement: null, target_host: host, unavailable_hosts: [{ host, reason }] });
2392
+ }
2393
+ try {
2394
+ const lanes = await readOutpostLaneRecords(ctx, outpostId, { snapshot: true });
2395
+ return {
2396
+ capacity,
2397
+ lanes: lanes.filter((lane) => lane.host.kind === "outpost" && lane.host.id === outpostId),
2398
+ laneListAvailable: true,
2399
+ };
2400
+ }
2401
+ catch (err) {
2402
+ if (isCompanyOutpostRefusal(err))
2403
+ throw err;
2404
+ if (isLanesError(err) && err.error === "outpost_lane_list_invalid")
2405
+ throw err;
2406
+ return { capacity, lanes: [], laneListAvailable: false };
2407
+ }
2408
+ }
2363
2409
  async function loadClaudeBalanceHostSnapshots(ctx, hqRoot, config, options = {}) {
2364
2410
  const localHost = laneHostFromCtx(ctx);
2365
2411
  const localLanes = loadAllLanes(hqRoot);
@@ -3925,7 +3971,17 @@ async function runCreate(ctx, opts) {
3925
3971
  let autoAccountPick;
3926
3972
  let autoChosenProvider;
3927
3973
  let autoChosenAccount;
3928
- if (opts.account !== undefined && opts.account.trim() === "auto") {
3974
+ const requestedCompanyOutpostTarget = (opts.outpost !== undefined && isCompanyOutpostId(opts.outpost.trim())) ||
3975
+ (requestedPlacement?.kind === "outpost" && isCompanyOutpostId(requestedPlacement.id));
3976
+ if (opts.account !== undefined && opts.account.trim() === "auto" && requestedCompanyOutpostTarget) {
3977
+ autoAccountPick = {
3978
+ why: "the lane runs on a company Outpost, so the account is chosen among the accounts signed in on that Outpost",
3979
+ headroom: 0,
3980
+ score: UNKNOWN_USAGE_SCORE,
3981
+ };
3982
+ opts = { ...opts, account: undefined };
3983
+ }
3984
+ else if (opts.account !== undefined && opts.account.trim() === "auto") {
3929
3985
  const ledgerOptions = capacityOptionsFromEnv(ctx.env);
3930
3986
  // feedback_9e444a9f / feedback_86552798: with no ledger yet (capacity was
3931
3987
  // never enabled), or a ledger with no reading for any lane account, there
@@ -4388,9 +4444,10 @@ async function runCreate(ctx, opts) {
4388
4444
  });
4389
4445
  pinnedAccount = resolved.id;
4390
4446
  }
4447
+ const targetsCompanyOutpost = outpostId !== undefined && isCompanyOutpostId(outpostId);
4391
4448
  // PS-006: refuse a pinned login held by another person before any model
4392
4449
  // check reads its home.
4393
- if (pinnedAccount !== undefined)
4450
+ if (pinnedAccount !== undefined && !targetsCompanyOutpost)
4394
4451
  refuseHeldPinnedAccount(provider, pinnedAccount, config);
4395
4452
  if (outpostId !== undefined &&
4396
4453
  profile !== undefined &&
@@ -4541,14 +4598,10 @@ async function runCreate(ctx, opts) {
4541
4598
  const accountCompany = resolveLaneCompany(hqRoot, { lane_id: "pending-create", company, mesh_company: meshCompany ?? undefined, project_id: project }).company;
4542
4599
  const allowedAccounts = Object.keys(config.providers[provider].accounts).filter((id) => (candidateAccounts === undefined || candidateAccounts.includes(id)) &&
4543
4600
  accountMatchesCompany(config.providers[provider].accounts[id], accountCompany, config.providers[provider].accounts));
4544
- if (pinnedAccount !== undefined)
4545
- refuseHeldPinnedAccount(provider, pinnedAccount, config);
4546
- if (pinnedAccount !== undefined && !accountMatchesCompany(config.providers[provider].accounts[pinnedAccount], accountCompany, config.providers[provider].accounts)) {
4601
+ if (pinnedAccount !== undefined && !targetsCompanyOutpost && !accountMatchesCompany(config.providers[provider].accounts[pinnedAccount], accountCompany, config.providers[provider].accounts)) {
4547
4602
  throw new LanesError("account_company_mismatch", `Account ${pinnedAccount} does not belong to the lane company`, { provider, account: pinnedAccount });
4548
4603
  }
4549
- // Local creates and Claude balancing select an account here; other Outpost
4550
- // creates pick theirs on the Outpost, so they are not refused locally.
4551
- if (pinnedAccount === undefined && (outpostId === undefined || provider === "claude")) {
4604
+ if (pinnedAccount === undefined && !targetsCompanyOutpost && (outpostId === undefined || provider === "claude")) {
4552
4605
  const mismatch = companyMismatchError({
4553
4606
  provider,
4554
4607
  providerAccounts: config.providers[provider].accounts,
@@ -4559,7 +4612,18 @@ async function runCreate(ctx, opts) {
4559
4612
  throw mismatch;
4560
4613
  }
4561
4614
  let accountSelection;
4562
- if (provider === "claude") {
4615
+ if (provider === "claude" && targetsCompanyOutpost) {
4616
+ const target = await loadCompanyOutpostBalanceHost(ctx, outpostId);
4617
+ const selected = selectCompanyOutpostClaudeAccount({
4618
+ target,
4619
+ requestedPlacement: placementToApply ?? null,
4620
+ ...(company ? { company } : {}),
4621
+ ...(explicitBalanceAccount !== undefined && autoAccountPick === undefined ? { explicitAccount: explicitBalanceAccount } : {}),
4622
+ });
4623
+ pinnedAccount = selected.account;
4624
+ accountSelection = { ...selected, selected_at: ctx.now().toISOString() };
4625
+ }
4626
+ else if (provider === "claude") {
4563
4627
  const persistedLocalHost = outpostId === undefined && placementHostOverride === undefined
4564
4628
  ? localStableHost(ctx)
4565
4629
  : undefined;
@@ -4686,7 +4750,7 @@ async function runCreate(ctx, opts) {
4686
4750
  ...(allowedAccounts !== undefined ? { allowedAccounts } : {}),
4687
4751
  }).id;
4688
4752
  }
4689
- const accountCfg = pinnedAccount !== undefined
4753
+ const accountCfg = pinnedAccount !== undefined && !targetsCompanyOutpost
4690
4754
  ? config.providers[provider].accounts[pinnedAccount]
4691
4755
  : undefined;
4692
4756
  const model = resolveLaneModel({
@@ -7661,6 +7725,7 @@ async function runGrant(ctx, laneId, opts) {
7661
7725
  const target = await resolveCommandLaneTarget(ctx, laneId, {
7662
7726
  outpostHint: true,
7663
7727
  outpostId: opts.outpost,
7728
+ ...(opts.company !== undefined ? { company: opts.company } : {}),
7664
7729
  });
7665
7730
  const initial = target.lane;
7666
7731
  const callerAuthorization = callerSeniorAuthorization(ctx, initial.senior);
@@ -11322,6 +11387,7 @@ export function registerRunnersCommand(parent, deps = {}) {
11322
11387
  .argument("<lane-id>", "Lane id")
11323
11388
  .requiredOption("--hire <n>", "Non-negative safe integer hire grant")
11324
11389
  .option("--outpost <id>", "Confirm the registered Outpost hosting a native lane")
11390
+ .option("--company <slug>", "Company that owns the --outpost company Outpost")
11325
11391
  .action(wrap(async (laneId, opts) => {
11326
11392
  await runGrant(ctx, laneId, opts);
11327
11393
  }));
@@ -22,6 +22,7 @@
22
22
  import { Command } from 'commander';
23
23
  import { retrustCodexHooksAfterRescue } from '../utils/hook-trust.js';
24
24
  import { repairDanglingReleaseLinks } from '../lib/doctor/checks/release-links.js';
25
+ import { type GitHubLookupDeps } from '../utils/github-tag-fallback.js';
25
26
  export interface RescueTarget {
26
27
  source: string;
27
28
  /** undefined → let the script apply its own default ref (`main`). */
@@ -62,8 +63,8 @@ export declare function retrustHooksAfterRescue(hqRoot: string, retrust?: typeof
62
63
  */
63
64
  export declare function repairReleaseLinksAfterRescue(hqRoot: string, repair?: typeof repairDanglingReleaseLinks): void;
64
65
  /** Latest release tag for a repo, e.g. `v12.3.0`. Throws on failure. */
65
- export declare function getLatestReleaseTag(repo: string, token?: string): Promise<string>;
66
+ export declare function getLatestReleaseTag(repo: string, token?: string, deps?: GitHubLookupDeps): Promise<string>;
66
67
  /** Resolve a tag to its commit SHA, dereferencing annotated tags. */
67
- export declare function resolveTagSha(repo: string, tag: string, token?: string): Promise<string>;
68
+ export declare function resolveTagSha(repo: string, tag: string, token?: string, deps?: GitHubLookupDeps): Promise<string>;
68
69
  export declare function registerRescueCommand(program: Command): void;
69
70
  //# sourceMappingURL=rescue.d.ts.map
@@ -8,6 +8,7 @@ import { selfUpdateAndReexec } from '../utils/self-update.js';
8
8
  import { retrustCodexHooksAfterRescue } from '../utils/hook-trust.js';
9
9
  import { repairDanglingReleaseLinks } from '../lib/doctor/checks/release-links.js';
10
10
  import { PROD_SOURCE, STAGING_SOURCE, resolveGhToken } from '../utils/shipped-codex-hooks.js';
11
+ import { GitHubApiUnavailable, onceWarning, isTransientGitHubStatus, remoteTagSha, withGitTagFallback } from '../utils/github-tag-fallback.js';
11
12
  /**
12
13
  * Resolve the source repo + ref from the user's flags. Pure + exported for
13
14
  * tests. `latestTag` is the resolved latest release tag (prod only); ignored
@@ -104,48 +105,57 @@ function ghHeaders(token) {
104
105
  }
105
106
  // Thirty seconds gives GitHub time to respond while keeping the recovery command bounded.
106
107
  const GITHUB_REQUEST_TIMEOUT_MS = 30_000;
107
- async function githubJsonRequest(url, token) {
108
+ async function githubJsonRequest(url, token, fetchImpl = fetch) {
108
109
  const signal = AbortSignal.timeout(GITHUB_REQUEST_TIMEOUT_MS);
109
110
  try {
110
- const response = await fetch(url, { headers: ghHeaders(token), signal });
111
+ const response = await fetchImpl(url, { headers: ghHeaders(token), signal });
112
+ if (isTransientGitHubStatus(response.status)) {
113
+ throw new GitHubApiUnavailable(`GitHub API for ${url}: HTTP ${response.status}`);
114
+ }
111
115
  if (!response.ok)
112
116
  return { response };
113
117
  const body = (await response.json());
114
118
  return { response, body };
115
119
  }
116
120
  catch (error) {
121
+ if (error instanceof GitHubApiUnavailable)
122
+ throw error;
117
123
  if (signal.aborted)
118
- throw new Error('GitHub request timed out', { cause: error });
119
- throw error;
124
+ throw new GitHubApiUnavailable('GitHub request timed out', { cause: error });
125
+ throw new GitHubApiUnavailable('GitHub request failed on the network', { cause: error });
120
126
  }
121
127
  }
122
128
  /** Latest release tag for a repo, e.g. `v12.3.0`. Throws on failure. */
123
- export async function getLatestReleaseTag(repo, token) {
124
- const { response, body } = await githubJsonRequest(`https://api.github.com/repos/${repo}/releases/latest`, token);
125
- if (!response.ok) {
126
- throw new Error(`GitHub releases/latest for ${repo}: HTTP ${response.status}`);
127
- }
128
- if (!body?.tag_name)
129
- throw new Error(`no tag_name in latest release for ${repo}`);
130
- return body.tag_name;
129
+ export async function getLatestReleaseTag(repo, token, deps = {}) {
130
+ return withGitTagFallback(async () => {
131
+ const { response, body } = await githubJsonRequest(`https://api.github.com/repos/${repo}/releases/latest`, token, deps.fetchImpl);
132
+ if (!response.ok) {
133
+ throw new Error(`GitHub releases/latest for ${repo}: HTTP ${response.status}`);
134
+ }
135
+ if (!body?.tag_name)
136
+ throw new Error(`no tag_name in latest release for ${repo}`);
137
+ return body.tag_name;
138
+ }, repo, undefined, tag => tag, deps);
131
139
  }
132
140
  /** Resolve a tag to its commit SHA, dereferencing annotated tags. */
133
- export async function resolveTagSha(repo, tag, token) {
134
- const { response: refRes, body: ref } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/ref/tags/${encodeURIComponent(tag)}`, token);
135
- if (!refRes.ok)
136
- throw new Error(`git/ref/tags/${tag} for ${repo}: HTTP ${refRes.status}`);
137
- const obj = ref?.object;
138
- if (!obj?.sha)
139
- throw new Error(`no object.sha for tag ${tag} in ${repo}`);
140
- if (obj.type !== 'tag')
141
- return obj.sha; // lightweight tag → already a commit
142
- // Annotated tag → dereference to the commit it points at.
143
- const { response: tagRes, body: annotated } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/tags/${obj.sha}`, token);
144
- if (!tagRes.ok)
145
- throw new Error(`git/tags/${obj.sha} for ${repo}: HTTP ${tagRes.status}`);
146
- if (!annotated?.object?.sha)
147
- throw new Error(`annotated tag ${tag} has no target sha`);
148
- return annotated.object.sha;
141
+ export async function resolveTagSha(repo, tag, token, deps = {}) {
142
+ return withGitTagFallback(async () => {
143
+ const { response: refRes, body: ref } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/ref/tags/${encodeURIComponent(tag)}`, token, deps.fetchImpl);
144
+ if (!refRes.ok)
145
+ throw new Error(`git/ref/tags/${tag} for ${repo}: HTTP ${refRes.status}`);
146
+ const obj = ref?.object;
147
+ if (!obj?.sha)
148
+ throw new Error(`no object.sha for tag ${tag} in ${repo}`);
149
+ if (obj.type !== 'tag')
150
+ return obj.sha; // lightweight tag → already a commit
151
+ // Annotated tag → dereference to the commit it points at.
152
+ const { response: tagRes, body: annotated } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/tags/${obj.sha}`, token, deps.fetchImpl);
153
+ if (!tagRes.ok)
154
+ throw new Error(`git/tags/${obj.sha} for ${repo}: HTTP ${tagRes.status}`);
155
+ if (!annotated?.object?.sha)
156
+ throw new Error(`annotated tag ${tag} has no target sha`);
157
+ return annotated.object.sha;
158
+ }, repo, tag, output => remoteTagSha(output, tag), deps);
149
159
  }
150
160
  /** Read the installed HQ core version from `{hqRoot}/core/core.yaml`. */
151
161
  function readInstalledVersion(hqRoot) {
@@ -176,6 +186,7 @@ export function registerRescueCommand(program) {
176
186
  .option('--no-backup', 'Skip the pre-op safety snapshot under ~/.hq/backups')
177
187
  .option('--no-self-update', 'Skip updating hq-cli itself to the latest version first')
178
188
  .option('--cloud-update', 'Cloud-update mode')
189
+ .option('--verbose', 'Show diagnostic details when recovery fails')
179
190
  .action(async (opts) => {
180
191
  try {
181
192
  // Bring the CLI itself to latest first: the rescue script is bundled
@@ -190,24 +201,25 @@ export function registerRescueCommand(program) {
190
201
  }
191
202
  const hqRoot = opts.hqRoot ?? findHqRoot();
192
203
  const token = resolveGhToken();
204
+ const lookupDeps = { warn: onceWarning() };
193
205
  let { source, ref } = resolveRescueTarget(opts);
194
206
  let floorSha = opts.floorSha;
195
207
  if (!opts.staging) {
196
208
  // Prod: resolve the latest release tag when no explicit ref, and
197
209
  // pin the floor to the installed version's commit when possible.
198
210
  if (!ref) {
199
- ref = await getLatestReleaseTag(source, token);
211
+ ref = await getLatestReleaseTag(source, token, lookupDeps);
200
212
  }
201
213
  if (!floorSha) {
202
214
  const installed = readInstalledVersion(hqRoot);
203
215
  if (installed) {
204
216
  try {
205
- floorSha = await resolveTagSha(source, `v${installed}`, token);
217
+ floorSha = await resolveTagSha(source, `v${installed}`, token, lookupDeps);
206
218
  }
207
219
  catch (err) {
208
- console.warn(chalk.yellow(`Warning: couldn't resolve the floor commit for v${installed} ` +
209
- `(${err instanceof Error ? err.message : 'unknown error'}); ` +
210
- `falling back to the on-disk sync stamp.`));
220
+ if (opts.verbose)
221
+ console.error(err);
222
+ console.warn(chalk.yellow('Could not check the installed version; using the saved sync history.'));
211
223
  }
212
224
  }
213
225
  }
@@ -234,7 +246,9 @@ export function registerRescueCommand(program) {
234
246
  process.exit(status);
235
247
  }
236
248
  catch (error) {
237
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
249
+ if (opts.verbose)
250
+ console.error(error);
251
+ console.error('Could not complete HQ recovery; check your connection and try again.');
238
252
  process.exit(1);
239
253
  }
240
254
  });
@@ -30,6 +30,12 @@ export type SearchOptions = {
30
30
  */
31
31
  export declare function normalizeQueryForQmd(query: string): string;
32
32
  export declare function buildSearchArgs(query: string, options?: SearchOptions): string[];
33
+ /**
34
+ * Resolve a `--mode` value to a canonical mode, or throw a usage error. Matching
35
+ * ignores case and surrounding whitespace. Aliases live in a Map so inherited
36
+ * object keys such as `constructor` or `__proto__` are never treated as modes.
37
+ */
38
+ export declare function resolveSearchMode(mode: string | undefined): SearchMode;
33
39
  export declare function buildGetArgs(document: string, options?: Pick<SearchOptions, 'collection'>): string[];
34
40
  export declare function registerSearchCommand(program: Command): void;
35
41
  export {};
@@ -51,6 +51,28 @@ export function buildSearchArgs(query, options = {}) {
51
51
  args.push('--json');
52
52
  return args;
53
53
  }
54
+ const SEARCH_MODES = ['keyword', 'semantic', 'hybrid'];
55
+ /**
56
+ * Accepted spellings that are not canonical mode names. qmd describes its BM25
57
+ * pass as "lexical" (and its query documents use a `lex:` prefix), so callers
58
+ * that learned the vocabulary from qmd ask for `--mode lexical`. That is the
59
+ * keyword (BM25) search, so it maps there instead of failing (Sentry HQ-CLI-J2).
60
+ */
61
+ const SEARCH_MODE_ALIASES = new Map([['lexical', 'keyword']]);
62
+ /**
63
+ * Resolve a `--mode` value to a canonical mode, or throw a usage error. Matching
64
+ * ignores case and surrounding whitespace. Aliases live in a Map so inherited
65
+ * object keys such as `constructor` or `__proto__` are never treated as modes.
66
+ */
67
+ export function resolveSearchMode(mode) {
68
+ const value = (mode ?? 'keyword').trim().toLowerCase();
69
+ if (SEARCH_MODES.includes(value))
70
+ return value;
71
+ const alias = SEARCH_MODE_ALIASES.get(value);
72
+ if (alias)
73
+ return alias;
74
+ throw new Error(`Unknown search mode '${mode}'. Expected keyword, semantic, or hybrid.`);
75
+ }
54
76
  export function buildGetArgs(document, options = {}) {
55
77
  const args = ['get', document];
56
78
  if (options.collection)
@@ -85,10 +107,8 @@ export function registerSearchCommand(program) {
85
107
  process.exitCode = 1;
86
108
  return;
87
109
  }
88
- if (!['keyword', 'semantic', 'hybrid'].includes(options.mode ?? 'keyword')) {
89
- throw new Error(`Unknown search mode '${options.mode}'. Expected keyword, semantic, or hybrid.`);
90
- }
91
- relay(runQmd(buildSearchArgs(query, options)));
110
+ const mode = resolveSearchMode(options.mode);
111
+ relay(runQmd(buildSearchArgs(query, { ...options, mode })));
92
112
  });
93
113
  search
94
114
  .command('get <document>')
@@ -30,7 +30,7 @@ import { SOURCE_CHANNELS, assertSourceChannel, resolveEntity, listAvailableEntit
30
30
  import { ensureCognitoToken, ensureCognitoIdToken, buildVaultConfig, DEFAULT_COGNITO, DEFAULT_HQ_ROOT, } from "../utils/cognito-session.js";
31
31
  import { getCompanyUid, vaultApiFetch } from "../utils/vault-api.js";
32
32
  import { isAuthError } from "../utils/auth-error.js";
33
- import { IntegrationsCliError, callGateway, fetchUsableApps, gatewayResultIsError, isBuiltInGatewayProvider, raiseForResponse, toolPrefixForProvider, unwrapGatewayResult, } from "./integrations-core.js";
33
+ import { IntegrationsCliError, callGateway, fetchIntegrationsSummary, gatewayResultIsError, isBuiltInGatewayProvider, raiseForResponse, toolPrefixForProvider, unwrapGatewayResult, } from "./integrations-core.js";
34
34
  import { Sentry } from "../sentry.js";
35
35
  import { resolveUploadAuthor } from "../utils/upload-author.js";
36
36
  import { createSignalsAlertChannelPoster, raiseSignalsFailureAlerts } from "../lib/hot-channels/alert.js";
@@ -342,9 +342,13 @@ async function fetchHotChannels(token, companyUid) {
342
342
  * the gateway routes each call by connection id.
343
343
  */
344
344
  export function gatewaySyncDeps(token, companyUid) {
345
+ // One summary read per sync serves both the usable apps and the known connections.
346
+ let summary;
347
+ const readSummary = () => (summary ??= fetchIntegrationsSummary(token, companyUid));
345
348
  return {
346
349
  fetchHotChannels: () => fetchHotChannels(token, companyUid),
347
- fetchUsableApps: async () => (await fetchUsableApps(token, companyUid)).apps,
350
+ fetchUsableApps: async () => (await readSummary()).apps,
351
+ fetchKnownConnections: async () => (await readSummary()).knownConnections,
348
352
  async callTool(app, tool, args) {
349
353
  const idempotencyKey = `hq-sources-sync-${randomUUID()}`;
350
354
  const params = isBuiltInGatewayProvider(app.provider)