@indigoai-us/hq-cli 5.345.262 → 5.345.264

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 (64) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/contracts/host-canary-release.json +7 -7
  3. package/dist/command-catalog.generated.d.ts +37 -0
  4. package/dist/command-catalog.generated.js +46 -0
  5. package/dist/command-registration-plan.d.ts +6 -0
  6. package/dist/command-registration-plan.js +1 -0
  7. package/dist/commands/bot.d.ts +2 -0
  8. package/dist/commands/bot.js +4 -3
  9. package/dist/commands/core-handoff.js +273 -115
  10. package/dist/commands/sync-held.d.ts +11 -0
  11. package/dist/commands/sync-held.js +65 -1
  12. package/dist/commands/sync-telemetry-report.d.ts +5 -0
  13. package/dist/commands/sync-telemetry-report.js +239 -0
  14. package/dist/commands/sync-telemetry.d.ts +47 -0
  15. package/dist/commands/sync-telemetry.js +309 -0
  16. package/dist/index.js +107 -43
  17. package/dist/lib/bot/runnable.d.ts +17 -7
  18. package/dist/lib/bot/runnable.js +17 -10
  19. package/dist/lib/capacity/available.js +6 -2
  20. package/dist/lib/capacity/collectors/claude-oauth.d.ts +10 -256
  21. package/dist/lib/capacity/collectors/claude-oauth.js +19 -1078
  22. package/dist/lib/capacity/ledger.d.ts +12 -1
  23. package/dist/lib/capacity/ledger.js +15 -5
  24. package/dist/lib/capacity/route.d.ts +2 -0
  25. package/dist/lib/capacity/route.js +21 -4
  26. package/dist/lib/capacity/scheduler.js +2 -3
  27. package/dist/lib/capacity/sign-in.js +4 -4
  28. package/dist/lib/daemon/ops/skill-command.d.ts +2 -0
  29. package/dist/lib/daemon/ops/skill-command.js +7 -1
  30. package/dist/lib/doctor/checks/antigravity-wiring.d.ts +2 -1
  31. package/dist/lib/doctor/checks/antigravity-wiring.js +59 -3
  32. package/dist/lib/doctor/checks/hook-engine.d.ts +2 -0
  33. package/dist/lib/doctor/checks/hook-engine.js +100 -1
  34. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  35. package/dist/lib/doctor/checks/host-core.js +11 -4
  36. package/dist/lib/hook-engine/coverage.d.ts +19 -10
  37. package/dist/lib/hook-engine/coverage.js +103 -24
  38. package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -1
  39. package/dist/lib/hook-engine/native-stop-compatibility.json +8 -4
  40. package/dist/lib/hook-engine/reconcile.js +49 -1
  41. package/dist/lib/install/antigravity-targets.d.ts +22 -0
  42. package/dist/lib/install/antigravity-targets.js +82 -0
  43. package/dist/main.js +8 -3
  44. package/dist/sentry-init.d.ts +7 -1
  45. package/dist/sentry-init.js +6 -2
  46. package/dist/sentry.d.ts +7 -0
  47. package/dist/sentry.js +16 -1
  48. package/dist/started-version.d.ts +13 -0
  49. package/dist/started-version.js +34 -0
  50. package/dist/startup-registration.d.ts +9 -9
  51. package/dist/startup-registration.js +42 -18
  52. package/dist/utils/client-health.d.ts +1 -0
  53. package/dist/utils/client-health.js +54 -11
  54. package/dist/utils/core-next-kill.d.ts +9 -0
  55. package/dist/utils/core-next-kill.js +22 -0
  56. package/dist/utils/delegate-lock.js +19 -1
  57. package/dist/utils/host-registration.d.ts +4 -2
  58. package/dist/utils/host-registration.js +55 -7
  59. package/dist/utils/install-tree-recovery-markers.d.ts +45 -0
  60. package/dist/utils/install-tree-recovery-markers.js +70 -0
  61. package/dist/utils/install-tree-torn.d.ts +102 -5
  62. package/dist/utils/install-tree-torn.js +199 -2
  63. package/dist/utils/sentry-fingerprint.js +3 -0
  64. package/package.json +7 -7
@@ -8,22 +8,9 @@
8
8
  * header. This module does not invoke the claude CLI except
9
9
  * `claude --version` when the caller does not pass cliVersion.
10
10
  *
11
- * US-014 wires in a token-refresh gate. The gate uses two seams,
12
- * `defaultListLiveLanes` and `defaultListProcesses`, to decide whether a
13
- * refresh is safe (no running Claude Code holds the home). Both seams
14
- * FAIL CLOSED: an error, a timeout, or an unexpected JSON shape returns an
15
- * error-signalling throw and the caller records `skipped-live` /
16
- * `skipped-process` and does NOT rotate the refresh token.
17
- *
18
- * Residual blind spot on darwin: `ps -axo pid=,command=` cannot read a
19
- * child process's environment, so on darwin a running `claude` process is
20
- * conservatively treated as holding the DEFAULT home AND blocking any
21
- * non-default home refresh. A sibling that sets `CLAUDE_CONFIG_DIR` to a
22
- * different home still blocks the gate; this is the safe side of the
23
- * precision/safety tradeoff. On linux `/proc/<pid>/environ` lets the gate
24
- * read the per-process `CLAUDE_CONFIG_DIR`, so it only blocks the matching
25
- * home. Windows and other platforms get no process gate; the lane gate is
26
- * authoritative there.
11
+ * It never refreshes a token. Claude refresh tokens are single use, so a
12
+ * refresh from here raced Claude Code's own refresh and signed accounts out.
13
+ * An expired access token is reported as expired until Claude Code renews it.
27
14
  *
28
15
  * The legacy shape (seven_day_opus populated, no limits[]) is drift.
29
16
  * observedAt is the response time. One collect appends every account's
@@ -52,20 +39,13 @@ export declare const CLAUDE_OAUTH_FETCH_TIMEOUT_MS = 10000;
52
39
  export declare const CLAUDE_OAUTH_SECURITY_TIMEOUT_MS = 5000;
53
40
  export declare const CLAUDE_OAUTH_POLL_FILE = "claude-oauth-last-call.json";
54
41
  export declare const CLAUDE_KEYCHAIN_SERVICE = "Claude Code-credentials";
55
- /** Claude Code's refresh endpoint. The URL and the client_id are the ones Claude Code itself posts. */
56
- export declare const CLAUDE_OAUTH_REFRESH_URL = "https://console.anthropic.com/v1/oauth/token";
57
- export declare const CLAUDE_OAUTH_REFRESH_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
58
- /** Minimum gap between refresh attempts for one home when the previous attempt did not revoke. */
59
- export declare const CLAUDE_OAUTH_REFRESH_BACKOFF_MS: number;
60
- /** Minimum gap between refresh attempts for one home after an invalid_grant. */
61
- export declare const CLAUDE_OAUTH_REFRESH_REVOKED_BACKOFF_MS: number;
62
- /** Try a refresh when the token is this close to expiry, so one tick does not land on a stale token. */
63
- export declare const CLAUDE_OAUTH_REFRESH_PREFLIGHT_MS: number;
64
42
  /**
65
- * Claude refresh tokens are single use. A refresh the server completed but whose
66
- * response we abandoned leaves the stored token dead, so this limit is generous.
43
+ * A token this close to expiry is treated as expired and not sent. A usage
44
+ * 401 marks the account revoked; a token sent in its last seconds (or under
45
+ * clock skew) could be refused while its refresh token still works, and the
46
+ * collector would sign out a healthy account.
67
47
  */
68
- export declare const CLAUDE_OAUTH_REFRESH_TIMEOUT_MS = 30000;
48
+ export declare const CLAUDE_OAUTH_EXPIRY_SKEW_MS: number;
69
49
  export declare const CLAUDE_OAUTH_REFRESH_LAST_FILE = "claude-oauth-refresh-last.json";
70
50
  export interface ClaudeOAuthFetchInit {
71
51
  method: "GET";
@@ -80,21 +60,6 @@ export type ClaudeOAuthFetch = (url: string, init: ClaudeOAuthFetchInit) => Prom
80
60
  get(name: string): string | null;
81
61
  };
82
62
  }>;
83
- export interface ClaudeOAuthRefreshFetchInit {
84
- method: "POST";
85
- headers: Record<string, string>;
86
- body: string;
87
- redirect: "manual";
88
- signal?: AbortSignal;
89
- }
90
- /** Separate seam from the usage fetch: POST + body, same response shape. */
91
- export type ClaudeOAuthRefreshFetch = (url: string, init: ClaudeOAuthRefreshFetchInit) => Promise<{
92
- status: number;
93
- text: () => Promise<string>;
94
- headers?: {
95
- get(name: string): string | null;
96
- };
97
- }>;
98
63
  export interface SecurityExecResult {
99
64
  status: number | null;
100
65
  stdout: string;
@@ -110,9 +75,9 @@ export interface ClaudeCredentialAccount {
110
75
  expiresAt?: number | null;
111
76
  scopes?: readonly string[] | null;
112
77
  planType?: string | null;
113
- /** Opaque refresh token. Never logged, never surfaced. Passed to writeCredentials verbatim. */
78
+ /** Opaque refresh token. Never logged, never surfaced. Only fingerprinted for the revoked marker. */
114
79
  refreshToken?: string | null;
115
- /** Full parsed credential JSON. Preserved so writeCredentials can round-trip mcpOAuth and siblings. */
80
+ /** Full parsed credential JSON. Read only. */
116
81
  credentialDocument?: Record<string, unknown> | null;
117
82
  /** The config dir this credential belongs to; needed to resolve the Keychain service or file path. */
118
83
  home?: string | null;
@@ -122,82 +87,6 @@ export interface ReadClaudeCredentialsResult {
122
87
  accounts: ClaudeCredentialAccount[];
123
88
  }
124
89
  export type ReadClaudeCredentials = () => ReadClaudeCredentialsResult;
125
- export interface WriteClaudeCredentialsRequest {
126
- home: string;
127
- /** macOS Keychain service name; empty on non-darwin. */
128
- service: string;
129
- platform: NodeJS.Platform;
130
- /** The full new credential JSON object. The caller preserved sibling keys. */
131
- document: Record<string, unknown>;
132
- /** The refreshToken we read before POSTing to the token endpoint. Used to detect rotation races. */
133
- previousRefreshToken: string | null;
134
- }
135
- export interface WriteClaudeCredentialsResult {
136
- ok: boolean;
137
- /** True when the on-disk refresh token no longer matches `previousRefreshToken`. */
138
- raceDetected?: boolean;
139
- invalidGrant?: boolean;
140
- /** Human-readable, already scrubbed of tokens. */
141
- error?: string;
142
- }
143
- export type WriteClaudeCredentials = (request: WriteClaudeCredentialsRequest) => Promise<WriteClaudeCredentialsResult>;
144
- /**
145
- * Reads the refresh token currently stored for a home. `null` = stored item has no
146
- * refresh token; `undefined` = the item could not be read. Never logged.
147
- */
148
- export type ReadStoredClaudeRefreshToken = (request: {
149
- home: string;
150
- service: string;
151
- platform: NodeJS.Platform;
152
- }) => string | null | undefined;
153
- /**
154
- * One row per lane the gate must consider.
155
- * - `isLive` is true for state ∈ {queued, running, awaiting_input}: a running
156
- * Claude Code may hold the home; a refresh would race and get invalid_grant.
157
- * - `isAuthFailed` is true when the lane terminated with reason
158
- * `provider_auth_failed` (src/lib/lanes/watcher.ts classifies 401/403 that
159
- * way). The refresh gate no longer treats this as proof of revocation: the
160
- * lane may have failed on an older token. Only invalid_grant from the token
161
- * endpoint marks a refresh token revoked.
162
- * - `home` is the resolved per-host provider home for the account; the gate
163
- * compares it to the home being refreshed with `canonicalHomePath` (realpath,
164
- * lower case on darwin) so symlinks and case differences do not slip through;
165
- * a home that cannot be resolved blocks. `null` is accepted only when the row
166
- * is not live.
167
- */
168
- export interface LiveLane {
169
- home: string | null;
170
- account: string | null;
171
- provider: string;
172
- state: string;
173
- reason: string | null;
174
- isLive: boolean;
175
- isAuthFailed: boolean;
176
- }
177
- /** Fail-closed: throw on error/timeout/unexpected shape; the caller skips refresh. */
178
- export type ListLiveLanes = () => Promise<readonly LiveLane[]>;
179
- /**
180
- * One row per Claude Code process the gate must consider.
181
- * - `probe === "env"` means the probe read `/proc/<pid>/environ` and the
182
- * `env.CLAUDE_CONFIG_DIR` field is authoritative (undefined means default).
183
- * - `probe === "command-only"` means we only saw the command line (darwin
184
- * `ps -axo pid=,command=`), with no visibility into the process env. The
185
- * gate treats such a row as a conservative blocker for every home.
186
- */
187
- export interface ClaudeProcess {
188
- pid: number;
189
- /**
190
- * `HOME` is set when the probe read it. Claude Code resolves its default config dir as
191
- * HOME/.claude, so a process with HOME set and no CLAUDE_CONFIG_DIR holds that dir.
192
- */
193
- env: {
194
- CLAUDE_CONFIG_DIR?: string;
195
- HOME?: string;
196
- };
197
- probe: "env" | "command-only";
198
- }
199
- /** Fail-closed: throw on error/timeout; the caller skips refresh. */
200
- export type ListProcesses = () => Promise<readonly ClaudeProcess[]>;
201
90
  export interface ClaudeOAuthCollectResult {
202
91
  readings: ReadingInput[];
203
92
  failures: ParserFailureEvent[];
@@ -233,25 +122,6 @@ export interface CollectClaudeOAuthOptions {
233
122
  }[];
234
123
  /** One-shot collect reads while the resident collector stays disabled. */
235
124
  allowDisabled?: boolean;
236
- /**
237
- * Writes a refreshed credential back to disk / Keychain. Default implementation uses
238
- * `security add-generic-password -U` on darwin and tmp+rename at mode 0600 on linux,
239
- * preserving all sibling fields (including `mcpOAuth`).
240
- */
241
- writeCredentials?: WriteClaudeCredentials;
242
- /**
243
- * Re-reads the stored refresh token before an invalid_grant is recorded as revoked,
244
- * so a token another process rotated in the meantime is not marked dead.
245
- */
246
- readStoredRefreshToken?: ReadStoredClaudeRefreshToken;
247
- /** Returns homes that live lanes are using. Default implementation reads `hq runners list --json`. */
248
- listLiveLanes?: ListLiveLanes;
249
- /** Returns processes whose `CLAUDE_CONFIG_DIR` identifies a home. Default reads `ps -ewwo pid,command`. */
250
- listProcesses?: ListProcesses;
251
- /** Overrides the Claude Code refresh endpoint. Tests set this to a 127.0.0.1 stub. */
252
- tokenEndpoint?: string;
253
- /** Overrides the POST transport for the refresh. Default wraps `fetch` with a 10s abort. */
254
- refreshFetch?: ClaudeOAuthRefreshFetch;
255
125
  }
256
126
  interface MapOptions {
257
127
  observedAt: string;
@@ -362,121 +232,5 @@ export declare function isRefreshTokenRevoked(root: string, refreshToken: string
362
232
  * revoked the usage fetch will set a fingerprinted marker on the next 401.
363
233
  */
364
234
  export declare function revokedMarkerForCurrentCredential(root: string, accountId: string, refreshToken: string | null | undefined): "match" | "stale" | "none";
365
- /**
366
- * Shape of a single lane row emitted by `hq runners list --json`.
367
- * See src/commands/lanes.ts (withoutProviderHome strips `provider_home_at_spawn`
368
- * from CLI output; we must consult the accounts registry to map
369
- * account id -> effective_home).
370
- *
371
- * Note: the lane watcher writes a provider-auth-failed signal to the
372
- * `terminal_reason` field (watcher.ts:~729). The `terminal_details` record
373
- * carries the structured `account` and `provider` of the rejection
374
- * (provider-rejection.ts:providerRejectionDetails). Lane records never
375
- * surface a top-level `reason` for the auth-failed state, so this is the
376
- * only shape we read.
377
- */
378
- interface RawLaneRow {
379
- state?: unknown;
380
- account?: unknown;
381
- provider?: unknown;
382
- terminal_reason?: unknown;
383
- terminal_details?: unknown;
384
- }
385
- interface RawAccountRow {
386
- id?: unknown;
387
- home?: unknown;
388
- effective_home?: unknown;
389
- auth_state?: unknown;
390
- provider?: unknown;
391
- }
392
- /**
393
- * How to re-invoke the running hq CLI without a PATH lookup. When argv[1] is
394
- * the entry of an installed hq-cli package, run it with the same node binary;
395
- * the collector runs under launchd and lane workers where PATH may be empty.
396
- * Falls back to `hq` on PATH when this process is not the hq CLI (tests,
397
- * embedders). Exported for tests.
398
- */
399
- export declare function resolveHqInvocation(argv?: readonly string[], execPath?: string, execArgv?: readonly string[]): {
400
- command: string;
401
- args: string[];
402
- };
403
- /**
404
- * Run `hq ... --json` and parse stdout. Async on purpose: the collector runs inside the mesh
405
- * daemon, and a synchronous read that takes 15-30 s on a loaded machine froze the daemon's
406
- * event loop (MQTT keepalive, owner heartbeat) for the whole read.
407
- * Exported for tests; `invocation` defaults to {@link resolveHqInvocation}.
408
- */
409
- export declare function execHqJson(args: readonly string[], invocation?: {
410
- command: string;
411
- args: string[];
412
- }, env?: NodeJS.ProcessEnv): Promise<unknown>;
413
- /**
414
- * Parse `hq runners list --json` payload into typed rows.
415
- * Exported for tests; fail-closed semantics live in defaultListLiveLanes.
416
- */
417
- export declare function parseLanesListPayload(payload: unknown): readonly RawLaneRow[];
418
- /**
419
- * Parse `hq runners accounts list --json` payload into typed rows.
420
- * Exported for tests; fail-closed semantics live in defaultListLiveLanes.
421
- */
422
- export declare function parseAccountsListPayload(payload: unknown): readonly RawAccountRow[];
423
- /**
424
- * Join lanes rows against accounts rows to produce LiveLane records.
425
- * Exported for tests.
426
- */
427
- export declare function buildLiveLanesFromPayloads(lanes: readonly RawLaneRow[], accounts: readonly RawAccountRow[]): readonly LiveLane[];
428
- /**
429
- * Share one lane read across every home in a collect. Without this each expired home ran its
430
- * own pair of `hq runners ... --json` reads, so one slow machine turned into N timeouts per
431
- * collect. A failure is shared too: the next home fails closed without waiting again.
432
- * Exported for tests.
433
- */
434
- export declare function memoizeListLiveLanes(list: ListLiveLanes): ListLiveLanes;
435
- /**
436
- * Parse `ps -axo pid=,command=` into rows that mention the `claude` executable.
437
- * Exported for tests. Returned rows carry `probe: "command-only"` so the gate
438
- * knows it cannot read per-process CLAUDE_CONFIG_DIR on darwin.
439
- */
440
- export declare function parsePsClaudeOutput(stdout: string): readonly ClaudeProcess[];
441
- /** Pid to full command line, from `ps -ww -o pid=,command= -p <pids>`. Exported for tests. */
442
- export declare function parsePsCommandLines(stdout: string): ReadonlyMap<number, string>;
443
- export interface PsEnvProbeOptions {
444
- isDirectory?: (dir: string) => boolean;
445
- /** False only when the pid is known to be gone (ESRCH). Unknown counts as alive. */
446
- isAlive?: (pid: number) => boolean;
447
- }
448
- /**
449
- * Upgrade darwin command-only rows with each process's environment. `ps -wwE` prints a
450
- * same-user process's command line followed by its environment, unquoted and space separated.
451
- * Only the text after the exact command line (read separately with `ps -ww`) is treated as the
452
- * environment, so a prompt argument that mentions CLAUDE_CONFIG_DIR= or HOME= is never read as
453
- * env. A row becomes `probe: "env"` only when:
454
- * - the `-E` line starts with the command line plus a space, and the rest starts with NAME=;
455
- * - CLAUDE_CONFIG_DIR= appears at most once in that rest, and its value is absolute and
456
- * names an existing directory (the value runs to the next ` NAME=` or the end of line).
457
- * Anything else stays command-only, which blocks every home. A pid missing from the output
458
- * is dropped only when it is known to have exited; otherwise it stays command-only.
459
- * Exported for tests.
460
- */
461
- export declare function parsePsEnvOutput(envStdout: string, commandLines: ReadonlyMap<number, string>, rows: readonly ClaudeProcess[], options?: PsEnvProbeOptions): readonly ClaudeProcess[];
462
- /** Default config dir of an env-probed process with CLAUDE_CONFIG_DIR unset. Exported for tests. */
463
- export declare function processDefaultConfigDir(proc: ClaudeProcess): string;
464
- /**
465
- * Canonical form of a home directory for comparison: symlinks resolved by the OS, and lower
466
- * case on darwin, where APFS is case-insensitive by default. Null when the path cannot be
467
- * resolved. Exported for tests.
468
- */
469
- export declare function canonicalHomePath(dir: string, platform?: NodeJS.Platform): string | null;
470
- export interface ClaudeTokenRefreshResult {
471
- outcome: "refreshed" | "revoked" | "error" | "skipped-race" | "skipped-live" | "skipped-live-check-failed" | "skipped-process" | "skipped-process-check-failed" | "skipped-backoff" | "skipped-revoked";
472
- newAccessToken?: string;
473
- newExpiresAt?: number;
474
- newRefreshToken?: string;
475
- newScopes?: readonly string[] | null;
476
- errorMessage?: string;
477
- errorClass?: ClaudeRefreshErrorClass;
478
- httpStatus?: number | null;
479
- }
480
- export type ClaudeRefreshErrorClass = "invalid_grant" | "revoked" | "server_error" | "timeout" | "network" | "shape";
481
235
  export {};
482
236
  //# sourceMappingURL=claude-oauth.d.ts.map