@indigoai-us/hq-cli 5.345.263 → 5.345.267

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 (83) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-grant.sh +4 -48
  3. package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +16 -10
  4. package/assets/scaffold/core/scripts/hq-delegate-send.sh +17 -1
  5. package/contracts/host-canary-release.json +7 -7
  6. package/dist/command-catalog.generated.d.ts +67 -1
  7. package/dist/command-catalog.generated.js +83 -1
  8. package/dist/command-registration-plan.d.ts +6 -0
  9. package/dist/command-registration-plan.js +1 -0
  10. package/dist/commands/bot.d.ts +2 -0
  11. package/dist/commands/bot.js +4 -3
  12. package/dist/commands/core-delegate-w1b.js +21 -40
  13. package/dist/commands/core-delegate.js +11 -8
  14. package/dist/commands/files-browse.d.ts +83 -4
  15. package/dist/commands/files-browse.js +404 -54
  16. package/dist/commands/groups.js +2 -2
  17. package/dist/commands/skill.js +15 -0
  18. package/dist/commands/sync-held.d.ts +11 -0
  19. package/dist/commands/sync-held.js +65 -1
  20. package/dist/commands/sync-telemetry-report.d.ts +5 -0
  21. package/dist/commands/sync-telemetry-report.js +239 -0
  22. package/dist/commands/sync-telemetry.d.ts +47 -0
  23. package/dist/commands/sync-telemetry.js +309 -0
  24. package/dist/index.js +107 -43
  25. package/dist/lib/agent-kit/mcp/tools.js +2 -2
  26. package/dist/lib/agent-kit/skills.js +12 -6
  27. package/dist/lib/bot/runnable.d.ts +17 -7
  28. package/dist/lib/bot/runnable.js +17 -10
  29. package/dist/lib/capacity/available.js +6 -2
  30. package/dist/lib/capacity/collectors/claude-oauth.d.ts +10 -256
  31. package/dist/lib/capacity/collectors/claude-oauth.js +19 -1078
  32. package/dist/lib/capacity/ledger.d.ts +12 -1
  33. package/dist/lib/capacity/ledger.js +15 -5
  34. package/dist/lib/capacity/route.d.ts +2 -0
  35. package/dist/lib/capacity/route.js +21 -4
  36. package/dist/lib/capacity/scheduler.js +2 -3
  37. package/dist/lib/capacity/sign-in.js +4 -4
  38. package/dist/lib/daemon/merge-sections.d.ts +44 -9
  39. package/dist/lib/daemon/merge-sections.js +234 -37
  40. package/dist/lib/daemon/ops/skill-command.d.ts +2 -0
  41. package/dist/lib/daemon/ops/skill-command.js +7 -1
  42. package/dist/lib/daemon/run.js +1 -0
  43. package/dist/lib/doctor/checks/antigravity-wiring.d.ts +2 -1
  44. package/dist/lib/doctor/checks/antigravity-wiring.js +75 -3
  45. package/dist/lib/doctor/checks/hook-engine.d.ts +2 -0
  46. package/dist/lib/doctor/checks/hook-engine.js +100 -1
  47. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  48. package/dist/lib/doctor/checks/host-core.js +19 -7
  49. package/dist/lib/doctor/fix/process-identity.d.ts +2 -0
  50. package/dist/lib/doctor/fix/process-identity.js +5 -2
  51. package/dist/lib/hook-engine/coverage.d.ts +19 -10
  52. package/dist/lib/hook-engine/coverage.js +116 -25
  53. package/dist/lib/hook-engine/native-precompact-compatibility.json +8 -1
  54. package/dist/lib/hook-engine/native-stop-compatibility.json +8 -4
  55. package/dist/lib/hook-engine/reconcile.js +60 -2
  56. package/dist/lib/install/antigravity-targets.d.ts +22 -0
  57. package/dist/lib/install/antigravity-targets.js +82 -0
  58. package/dist/lib/signals/reply.js +25 -5
  59. package/dist/lib/signals/steps/extract.d.ts +28 -4
  60. package/dist/lib/signals/steps/extract.js +124 -10
  61. package/dist/lib/sync-core/release.d.ts +1 -1
  62. package/dist/lib/sync-core/release.js +2 -2
  63. package/dist/main.js +8 -3
  64. package/dist/sentry-init.d.ts +7 -1
  65. package/dist/sentry-init.js +6 -2
  66. package/dist/sentry.d.ts +7 -0
  67. package/dist/sentry.js +16 -1
  68. package/dist/started-version.d.ts +13 -0
  69. package/dist/started-version.js +34 -0
  70. package/dist/startup-registration.d.ts +9 -9
  71. package/dist/startup-registration.js +42 -18
  72. package/dist/utils/client-health.d.ts +1 -0
  73. package/dist/utils/client-health.js +54 -11
  74. package/dist/utils/core-next-kill.d.ts +9 -0
  75. package/dist/utils/core-next-kill.js +22 -0
  76. package/dist/utils/host-registration.d.ts +4 -2
  77. package/dist/utils/host-registration.js +55 -7
  78. package/dist/utils/install-tree-recovery-markers.d.ts +45 -0
  79. package/dist/utils/install-tree-recovery-markers.js +70 -0
  80. package/dist/utils/install-tree-torn.d.ts +102 -5
  81. package/dist/utils/install-tree-torn.js +199 -2
  82. package/dist/utils/sentry-fingerprint.js +3 -0
  83. package/package.json +7 -7
@@ -389,8 +389,19 @@ export interface LedgerOptions {
389
389
  }
390
390
  export declare function capacityOptionsFromEnv(env?: NodeJS.ProcessEnv): LedgerOptions;
391
391
  export declare function capacityRoot(env?: NodeJS.ProcessEnv, home?: string): string;
392
- /** Shown for a credential that exists and is past expiry. Never a login. */
392
+ /**
393
+ * Shown for a credential that exists and is past expiry, for providers whose
394
+ * collector renews the token itself (Grok). Never a login.
395
+ */
393
396
  export declare const EXPIRED_REASON = "expired: hq capacity renews it on the next collect";
397
+ /**
398
+ * Shown for an expired Claude credential. hq capacity never refreshes Claude
399
+ * tokens: they are single use, and a refresh here raced Claude Code's own
400
+ * refresh and signed accounts out. Claude Code renews the token on its next run.
401
+ */
402
+ export declare const CLAUDE_EXPIRED_REASON = "expired: refreshes the next time Claude Code is used with this account";
403
+ /** The expired text for one provider. */
404
+ export declare function expiredReasonFor(provider: string): string;
394
405
  /** The token endpoint rejected the stored refresh token. The human must sign in again. */
395
406
  export declare const SIGN_IN_REVOKED_REASON = "signed out: sign-in revoked";
396
407
  export declare function isExpiredReason(reason: string | null | undefined): boolean;
@@ -199,17 +199,27 @@ const SIGNED_OUT_PREFIX = "signed out:";
199
199
  const EXPIRED_PREFIX = "expired:";
200
200
  /** Ledger text written before expired and signed-out were different states. */
201
201
  const LEGACY_EXPIRED_REASON = "signed out: token expired";
202
- /** Ledger text written before hq capacity refreshed Claude tokens itself. */
203
- const LEGACY_EXPIRED_REASON_V2 = "expired: refreshes the next time Claude Code is used with this account";
204
- /** Shown for a credential that exists and is past expiry. Never a login. */
202
+ /**
203
+ * Shown for a credential that exists and is past expiry, for providers whose
204
+ * collector renews the token itself (Grok). Never a login.
205
+ */
205
206
  export const EXPIRED_REASON = "expired: hq capacity renews it on the next collect";
207
+ /**
208
+ * Shown for an expired Claude credential. hq capacity never refreshes Claude
209
+ * tokens: they are single use, and a refresh here raced Claude Code's own
210
+ * refresh and signed accounts out. Claude Code renews the token on its next run.
211
+ */
212
+ export const CLAUDE_EXPIRED_REASON = "expired: refreshes the next time Claude Code is used with this account";
213
+ /** The expired text for one provider. */
214
+ export function expiredReasonFor(provider) {
215
+ return provider === "claude" ? CLAUDE_EXPIRED_REASON : EXPIRED_REASON;
216
+ }
206
217
  /** The token endpoint rejected the stored refresh token. The human must sign in again. */
207
218
  export const SIGN_IN_REVOKED_REASON = "signed out: sign-in revoked";
208
219
  export function isExpiredReason(reason) {
209
220
  if (!reason)
210
221
  return false;
211
222
  return reason === LEGACY_EXPIRED_REASON
212
- || reason === LEGACY_EXPIRED_REASON_V2
213
223
  || reason === "unavailable: token_expired"
214
224
  || reason.startsWith(EXPIRED_PREFIX);
215
225
  }
@@ -1256,7 +1266,7 @@ function clusterAccounts(provider, events, nowMs) {
1256
1266
  signedOut: isSignedOut,
1257
1267
  authState,
1258
1268
  observedAt: Number.isFinite(latestAt) ? new Date(latestAt).toISOString() : null,
1259
- reason: expired ? EXPIRED_REASON : isSignedOut ? problem?.reason ?? null : null,
1269
+ reason: expired ? expiredReasonFor(provider.provider) : isSignedOut ? problem?.reason ?? null : null,
1260
1270
  fixCommand: expired
1261
1271
  ? (provider.provider === "claude" ? claudeOpenCommand(home) : null)
1262
1272
  : isSignedOut
@@ -28,6 +28,8 @@ export declare const OLD_READING_PENALTY = 10;
28
28
  * view stale). Sits below any account with fresh known headroom.
29
29
  */
30
30
  export declare const UNKNOWN_USAGE_SCORE = -100;
31
+ /** Why line for an expired Claude account ranked as usage-unknown until Claude Code renews it. */
32
+ export declare const CLAUDE_AWAITING_RENEWAL_WHY = "usage unknown until Claude Code renews the expired sign-in";
31
33
  /**
32
34
  * Score for an account whose plan limit is used up but which still runs on
33
35
  * paid extra usage. Ranked only with --allow-extra-usage, below every account
@@ -50,6 +50,8 @@ export const OLD_READING_PENALTY = 10;
50
50
  * view stale). Sits below any account with fresh known headroom.
51
51
  */
52
52
  export const UNKNOWN_USAGE_SCORE = -100;
53
+ /** Why line for an expired Claude account ranked as usage-unknown until Claude Code renews it. */
54
+ export const CLAUDE_AWAITING_RENEWAL_WHY = "usage unknown until Claude Code renews the expired sign-in";
53
55
  /**
54
56
  * Score for an account whose plan limit is used up but which still runs on
55
57
  * paid extra usage. Ranked only with --allow-extra-usage, below every account
@@ -317,9 +319,9 @@ export function pickAccount(input) {
317
319
  const readingsUnreliable = input.collectorEnabled === false
318
320
  || input.collectorEnabled === null
319
321
  || input.capacityStale === true;
320
- const rankUnknown = (base, accountId, tokenExpired) => {
322
+ const rankUnknown = (base, accountId, tokenExpired, unknownWhy = "usage unknown, capacity readings are stale or the collector is off") => {
321
323
  const live = liveLaneCount(lanes, base.provider, accountId);
322
- const whyParts = ["usage unknown, capacity readings are stale or the collector is off"];
324
+ const whyParts = [unknownWhy];
323
325
  if (live)
324
326
  whyParts.push(`${live} live lane${live === 1 ? "" : "s"} already on it`);
325
327
  if (tokenExpired)
@@ -440,10 +442,16 @@ export function pickAccount(input) {
440
442
  });
441
443
  continue;
442
444
  }
445
+ // hq capacity never renews a Claude sign-in; only a Claude Code run on
446
+ // the account does. An expired Claude account that is skipped for lack
447
+ // of a fresh reading would never run, never renew, and never be picked,
448
+ // so it is ranked as usage-unknown instead (below every account with
449
+ // known room) unless its last reading shows a limit used up.
450
+ const awaitsClaudeRenewal = providerId === "claude" && tokenExpired;
443
451
  // The ledger sets usageStale when the sign-in expired and no reading has
444
452
  // landed since the expiry. The limits on file describe the old token, so
445
453
  // the account cannot be ranked on them.
446
- if (account.usageStale === true) {
454
+ if (account.usageStale === true && !awaitsClaudeRenewal) {
447
455
  skipped.push({
448
456
  ...base,
449
457
  reason: "no fresh reading (sign-in expired)",
@@ -477,8 +485,17 @@ export function pickAccount(input) {
477
485
  .filter((ms) => Number.isFinite(ms));
478
486
  const newestReadingMs = readingTimes.length > 0 ? Math.max(...readingTimes) : -Infinity;
479
487
  const accountObservedMs = account.observedAt ? Date.parse(account.observedAt) : NaN;
480
- const noFreshReading = !Number.isFinite(newestReadingMs)
488
+ const noFreshReading = account.usageStale === true
489
+ || !Number.isFinite(newestReadingMs)
481
490
  || (Number.isFinite(accountObservedMs) && newestReadingMs < accountObservedMs);
491
+ if (noFreshReading && awaitsClaudeRenewal) {
492
+ const usedUpAtLastReading = viewRows.some((row) => !row.resetPassed
493
+ && (row.limit.state === "exhausted" || (typeof row.used === "number" && row.used >= 100)));
494
+ if (!usedUpAtLastReading) {
495
+ rankUnknown(base, laneMatch.id, true, CLAUDE_AWAITING_RENEWAL_WHY);
496
+ continue;
497
+ }
498
+ }
482
499
  if (noFreshReading) {
483
500
  skipped.push({
484
501
  ...base,
@@ -26,9 +26,8 @@ export const RUN_TIMEOUT_MS = {
26
26
  "codex-tail": 15_000,
27
27
  "codex-app-server": 30_000,
28
28
  "claude-statusline": 10_000,
29
- // Must stay well above CLAUDE_OAUTH_REFRESH_TIMEOUT_MS plus Keychain reads. A run
30
- // marked timed out keeps going, so a short budget lets a second run POST the same
31
- // single-use refresh token and get the account marked revoked.
29
+ // Covers a Keychain read and a usage GET per Claude home. The collector no
30
+ // longer refreshes tokens, so a slow run cannot spend a refresh token twice.
32
31
  "claude-oauth": 180_000,
33
32
  grok: 30_000,
34
33
  rebuild: 10_000,
@@ -9,7 +9,7 @@
9
9
  import * as fs from "node:fs";
10
10
  import * as path from "node:path";
11
11
  import { defaultProviderHome } from "./accounts.js";
12
- import { EXPIRED_REASON, capacityLoginCommand, claudeOpenCommand, defaultHomeLoginCommand, isExpiredReason, } from "./ledger.js";
12
+ import { expiredReasonFor, capacityLoginCommand, claudeOpenCommand, defaultHomeLoginCommand, isExpiredReason, } from "./ledger.js";
13
13
  import { effectiveAccountHome } from "../lanes/account-home.js";
14
14
  import { canonicalizeHome, loadLanesConfig, writeLanesConfig } from "../lanes/config.js";
15
15
  import { LANE_PROVIDERS, parseLaneProvider } from "../lanes/types.js";
@@ -94,7 +94,7 @@ export function presentAccount(account, provider, userHome) {
94
94
  const home = account.homes?.[0] ?? null;
95
95
  return {
96
96
  state: "expired",
97
- reason: EXPIRED_REASON,
97
+ reason: expiredReasonFor(provider),
98
98
  command: provider === "claude"
99
99
  ? claudeOpenCommand(home ?? (label === "default" ? null : home), userHome)
100
100
  : account.fixCommand ?? null,
@@ -250,7 +250,7 @@ function formatRepairPlan(plan) {
250
250
  lines.push("", "Expired (open the account; login is not repeated):");
251
251
  for (const row of plan.expired) {
252
252
  lines.push(`${row.provider} ${row.label}`);
253
- lines.push(row.reason ?? EXPIRED_REASON);
253
+ lines.push(row.reason ?? expiredReasonFor(row.provider));
254
254
  if (row.command)
255
255
  lines.push(formatRefreshLine(row.provider, row.command));
256
256
  }
@@ -392,7 +392,7 @@ async function runRepair(request, deps) {
392
392
  skipped.push({
393
393
  provider: row.provider,
394
394
  label: row.label,
395
- reason: row.reason ?? EXPIRED_REASON,
395
+ reason: row.reason ?? expiredReasonFor(row.provider),
396
396
  fix: row.command ? formatRefreshLine(row.provider, row.command) : null,
397
397
  });
398
398
  }
@@ -4,16 +4,27 @@
4
4
  * - merge_holds: every repository merge hold record under
5
5
  * <hqRoot>/workspace/lanes/holds, grouped by the company that owns it, with
6
6
  * that company's `lanes.repo-merge-hold` flag;
7
- * - merge_approvals: per session id, the conduct-link decision queue that
8
- * gates the session's merges, the session's company, and whether the
9
- * `lanes.review-before-merge` gate applies to it, with the lane review
10
- * records.
7
+ * - merge_approvals: per session id, the conduct link whose decision queue
8
+ * gates the session's merges and whether that queue could be read (closed
9
+ * links and stale conductor pointers omitted), the session's company, and
10
+ * whether the `lanes.review-before-merge` gate applies to it, with the lane
11
+ * review records.
12
+ *
13
+ * `decisions` is always written as an empty array. The native owner-approval
14
+ * gate (crates/hq-hook/src/rules/conduct_files.rs) reads the conduct link and
15
+ * its decision queue from disk when the merge is called, so unanswered,
16
+ * withdrawn and superseded decisions are decided there; no reader decides from
17
+ * this section's copy. Copying the queue once per session made the section
18
+ * grow with sessions x queue length (4.5 MB on one machine). The key stays,
19
+ * as an empty array, because released hook binaries require it when
20
+ * queue_status is "present".
11
21
  *
12
22
  * The native merge check in crates/hq-hook reads only these two sections and
13
23
  * starts no process. It refuses every merge while a section is missing, has a
14
- * missing or wrongly typed field, or its `refreshed_at` is older than
15
- * min(max_age_seconds, 60) seconds, so whenever a decision cannot be made here
16
- * the section (or the session) is written so the check refuses:
24
+ * missing or wrongly typed field, exceeds MAX_SECTION_BYTES (256 KiB), or its
25
+ * `refreshed_at` is older than min(max_age_seconds, 60) seconds, so whenever a
26
+ * decision cannot be made here the section (or the session) is written so the
27
+ * check refuses:
17
28
  *
18
29
  * - a hold file `hq runners hold` would refuse, an unreadable holds folder, or
19
30
  * an unreadable `lanes.repo-merge-hold` flag omits merge_holds;
@@ -22,7 +33,12 @@
22
33
  * whose company cannot be resolved is written with queue_status
23
34
  * "unreadable";
24
35
  * - an unreadable `lanes.review-before-merge` flag writes review_required
25
- * true with no reviews.
36
+ * true with no reviews;
37
+ * - if merge_approvals would still exceed MERGE_APPROVALS_MAX_SECTION_BYTES
38
+ * (a backstop: with no decisions copied it is not expected), the largest
39
+ * sessions lose their review records while keeping review_required, so
40
+ * only those sessions refuse, rather than letting the whole section exceed
41
+ * the reader's cap and refuse every session.
26
42
  *
27
43
  * Files are read through src/lib/safe-store.ts (a regular single-link file of
28
44
  * this user in a folder no other user can write), except lane records and
@@ -33,6 +49,12 @@ import { type RepoMergeHold } from "../lanes/repo-merge-hold.js";
33
49
  import { type LaneCompanyRef } from "../lanes/types.js";
34
50
  export declare const MERGE_HOLDS_SCHEMA = "merge-holds.v1";
35
51
  export declare const MERGE_APPROVALS_SCHEMA = "merge-approvals.v1";
52
+ export declare const MERGE_APPROVALS_SECTION_NAME = "merge_approvals";
53
+ /**
54
+ * Per-section cap enforced by `crates/hq-hook/src/state.rs` (`MAX_SECTION_BYTES`):
55
+ * the section name (`"merge_approvals"`) plus compact UTF-8 JSON bytes.
56
+ */
57
+ export declare const MERGE_APPROVALS_MAX_SECTION_BYTES: number;
36
58
  /** Written as each section's max_age_seconds; the native check caps it at 60 anyway. */
37
59
  export declare const MERGE_SECTION_MAX_AGE_SECONDS = 60;
38
60
  /**
@@ -79,7 +101,8 @@ export interface MergeApprovalSession {
79
101
  company_slug: string;
80
102
  link_id: string;
81
103
  queue_status: MergeQueueStatus;
82
- decisions: MergeDecision[];
104
+ /** Always empty: the owner-approval gate reads the queue file itself. */
105
+ decisions: [];
83
106
  review_required: boolean;
84
107
  reviews: MergeReview[];
85
108
  }
@@ -109,11 +132,16 @@ export interface MergeSections {
109
132
  }
110
133
  /** A lanes flag for one company: its value, or null when it could not be read. */
111
134
  export type MergeFlagReader = (flag: string, company: LaneCompanyRef) => Promise<boolean | null>;
135
+ export type MergeSectionLog = (level: "info" | "warn" | "error", message: string) => void;
112
136
  export interface MergeSectionInput {
113
137
  hqRoot: string;
114
138
  /** Written as refreshed_at; take it before any file is read. */
115
139
  now: Date;
116
140
  readFlag: MergeFlagReader;
141
+ /** Optional log sink for size-guard warnings. */
142
+ log?: MergeSectionLog;
143
+ /** Test seam: override MERGE_APPROVALS_MAX_SECTION_BYTES. */
144
+ maxApprovalsSectionBytes?: number;
117
145
  }
118
146
  /**
119
147
  * Every hold record, or null when any of them is one `hq runners hold list`
@@ -134,6 +162,11 @@ export interface FoldedQueue {
134
162
  * lines (a torn last line among them) and rows without an id are skipped.
135
163
  */
136
164
  export declare function foldDecisionQueue(text: string): FoldedQueue;
165
+ /**
166
+ * Exact byte size `crates/hq-hook/src/state.rs` measures against
167
+ * `MAX_SECTION_BYTES`: section name plus compact UTF-8 JSON bytes.
168
+ */
169
+ export declare function mergeApprovalsSectionBytes(section: MergeApprovalsSection): number;
137
170
  /** The merge_approvals section, or null to leave it out of the state file. */
138
171
  export declare function buildMergeApprovalsSection(input: MergeSectionInput): Promise<MergeApprovalsSection | null>;
139
172
  /** Both sections, read at `input.now`. A builder that throws leaves its section out. */
@@ -174,6 +207,8 @@ export interface MergeSectionRefresherOptions {
174
207
  readFlag: MergeFlagReader;
175
208
  /** Called after each refresh, to rewrite the state file. */
176
209
  onRefresh?: () => void;
210
+ /** Optional log sink for size-guard warnings (deduplicated across identical ticks). */
211
+ log?: MergeSectionLog;
177
212
  intervalMs?: number;
178
213
  wallClock?: () => Date;
179
214
  /** Start the timer (default true). */