@indigoai-us/hq-cli 5.345.212 → 5.345.214

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 (66) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bin/hq-auth-refresh.js +2 -1
  3. package/dist/command-catalog.generated.d.ts +308 -43
  4. package/dist/command-catalog.generated.js +373 -43
  5. package/dist/commands/agent-inbox.d.ts +11 -1
  6. package/dist/commands/agent-inbox.js +128 -38
  7. package/dist/commands/agent-kit.js +2 -2
  8. package/dist/commands/core-handoff.js +1 -0
  9. package/dist/commands/core-hq-session-native.js +2 -2
  10. package/dist/commands/core-pin-native.js +1 -1
  11. package/dist/commands/core-policy.js +1 -1
  12. package/dist/commands/core-resolve-company-native.js +1 -1
  13. package/dist/commands/core-sentry-report-fast.d.ts +2 -0
  14. package/dist/commands/core-sentry-report-fast.js +3 -1
  15. package/dist/commands/daemon.js +11 -1
  16. package/dist/commands/integrations-connect.d.ts +7 -1
  17. package/dist/commands/integrations-connect.js +137 -13
  18. package/dist/commands/lanes-link.js +10 -5
  19. package/dist/commands/rescue.js +13 -0
  20. package/dist/commands/secrets.d.ts +11 -0
  21. package/dist/commands/secrets.js +41 -7
  22. package/dist/index.js +2 -0
  23. package/dist/lazy-commands.js +2 -0
  24. package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
  25. package/dist/lib/agent-kit/inbox-fetch.js +215 -3
  26. package/dist/lib/agent-kit/inbox-redact.js +1 -1
  27. package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
  28. package/dist/lib/agent-kit/inbox-state.js +261 -4
  29. package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
  30. package/dist/lib/agent-kit/mcp/tools.js +68 -25
  31. package/dist/lib/agent-kit/run/inbox.js +4 -2
  32. package/dist/lib/agent-kit/skills.js +4 -1
  33. package/dist/lib/agent-kit/wake.d.ts +9 -1
  34. package/dist/lib/agent-kit/wake.js +10 -3
  35. package/dist/lib/bot/fleet-cron.js +193 -14
  36. package/dist/lib/bot/fleet-download.d.ts +2 -0
  37. package/dist/lib/bot/fleet-download.js +23 -0
  38. package/dist/lib/bot/fleet-local.d.ts +1 -0
  39. package/dist/lib/bot/fleet-local.js +41 -8
  40. package/dist/lib/core-utils/session-id.d.ts +1 -1
  41. package/dist/lib/core-utils/session-id.js +4 -0
  42. package/dist/lib/daemon/run.js +9 -1
  43. package/dist/lib/daemon/updater.d.ts +34 -2
  44. package/dist/lib/daemon/updater.js +51 -2
  45. package/dist/lib/doctor/checks/release-links.d.ts +50 -8
  46. package/dist/lib/doctor/checks/release-links.js +260 -24
  47. package/dist/lib/doctor/fix/apply.js +24 -8
  48. package/dist/lib/doctor/fix/remediation.js +15 -5
  49. package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
  50. package/dist/lib/lanes/autopilot-registry.js +59 -7
  51. package/dist/lib/lanes/links.d.ts +14 -0
  52. package/dist/lib/lanes/links.js +320 -25
  53. package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
  54. package/dist/lib/lanes/outpost-pruner-install.js +4 -3
  55. package/dist/main.js +3 -1
  56. package/dist/sentry-init.d.ts +2 -0
  57. package/dist/sentry-init.js +13 -2
  58. package/dist/sentry.d.ts +2 -0
  59. package/dist/sentry.js +5 -1
  60. package/dist/utils/cli-network-lifecycle.d.ts +9 -0
  61. package/dist/utils/cli-network-lifecycle.js +52 -0
  62. package/dist/utils/safe-link.d.ts +63 -0
  63. package/dist/utils/safe-link.js +246 -0
  64. package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
  65. package/dist/utils/sentry-keepalive-transport.js +70 -0
  66. package/package.json +7 -7
@@ -2,7 +2,8 @@ import { createRequire } from "node:module";
2
2
  import { BUNDLED_DSN } from "./sentry-dsn.generated.js";
3
3
  import { CLI_VERSION } from "./cli-version.js";
4
4
  import { beforeBreadcrumb } from "./utils/breadcrumb-buffer.js";
5
- import { residentProcessSkipsSentry } from "./utils/cli-network-lifecycle.js";
5
+ import { isScheduledShortRunCommand, residentProcessSkipsSentry } from "./utils/cli-network-lifecycle.js";
6
+ import { closeSentryTransportAgents, sentryHttpModule } from "./utils/sentry-keepalive-transport.js";
6
7
  import { getCachedSentryUser } from "./utils/sentry-identity.js";
7
8
  const requireRuntime = createRequire(import.meta.url);
8
9
  let sentryModule;
@@ -135,6 +136,8 @@ export function initSentryRuntime(beforeSend, overrides = {}, pendingBreadcrumbs
135
136
  beforeSend: createFlaggedBeforeSend(beforeSend),
136
137
  beforeBreadcrumb,
137
138
  integrations: (defaults) => defaults.filter((integration) => integration.name !== "ProcessSession"),
139
+ // One keep-alive connection, capped, instead of a new socket per envelope.
140
+ transportOptions: { httpModule: sentryHttpModule },
138
141
  ...overrides,
139
142
  });
140
143
  const user = getCachedSentryUser();
@@ -142,12 +145,20 @@ export function initSentryRuntime(beforeSend, overrides = {}, pendingBreadcrumbs
142
145
  sdk.setUser(user);
143
146
  for (const breadcrumb of pendingBreadcrumbs)
144
147
  sdk.addBreadcrumb(breadcrumb);
145
- sdk.startSession();
148
+ // A scheduled run (a daemon unit or timer, every 15 s to 6 h) sends only
149
+ // what it captures. Its release-health session was an envelope, and so a
150
+ // new ingest socket, on every clean run.
151
+ if (!isScheduledShortRunCommand(process.argv))
152
+ sdk.startSession();
146
153
  return sdk;
147
154
  }
148
155
  export function finishSentryRuntimeSession() {
149
156
  sentryModule?.endSession();
150
157
  }
158
+ /** Close the transport's sockets once the final flush is done. */
159
+ export function closeSentryRuntimeTransport() {
160
+ closeSentryTransportAgents();
161
+ }
151
162
  export function addSentryRuntimeBreadcrumb(breadcrumb) {
152
163
  sentryModule?.addBreadcrumb(breadcrumb);
153
164
  }
package/dist/sentry.d.ts CHANGED
@@ -26,5 +26,7 @@ export declare function epipeAwareBeforeSend(event: ErrorEvent, hint: EventHint)
26
26
  export declare function initSentry(overrides?: Partial<Pick<NodeOptions, "transport">>): void;
27
27
  /** Finish HQ's one per-invocation release-health session. */
28
28
  export declare function finishSentrySession(): void;
29
+ /** Close the Sentry transport's sockets after the run's final flush. */
30
+ export declare function closeSentryTransport(): void;
29
31
  export {};
30
32
  //# sourceMappingURL=sentry.d.ts.map
package/dist/sentry.js CHANGED
@@ -5,7 +5,7 @@ import { companySkillWrapperSentryTagsFor } from "./lib/company-skill-wrapper.js
5
5
  import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
6
6
  import { incompleteInstallCaptureContext, incompleteInstallMessage, } from "./utils/incomplete-install-error.js";
7
7
  import { installTreeTornSentryTagsFor, sentryFingerprintFor, sentryMcpCollisionContextFor, } from "./utils/sentry-fingerprint.js";
8
- import { finishSentryRuntimeSession, initSentryRuntime } from "./sentry-init.js";
8
+ import { closeSentryRuntimeTransport, finishSentryRuntimeSession, initSentryRuntime, } from "./sentry-init.js";
9
9
  const inertSentryScope = {
10
10
  setTag: () => inertSentryScope,
11
11
  setUser: () => inertSentryScope,
@@ -232,4 +232,8 @@ export function initSentry(overrides = {}) {
232
232
  export function finishSentrySession() {
233
233
  finishSentryRuntimeSession();
234
234
  }
235
+ /** Close the Sentry transport's sockets after the run's final flush. */
236
+ export function closeSentryTransport() {
237
+ closeSentryRuntimeTransport();
238
+ }
235
239
  //# sourceMappingURL=sentry.js.map
@@ -6,6 +6,15 @@ export declare function isHqDaemonRunCommand(argv: readonly string[]): boolean;
6
6
  */
7
7
  export declare function isLongLivedDaemonCommand(argv: readonly string[]): boolean;
8
8
  export declare function isLongLivedHelperCommand(argv: readonly string[]): boolean;
9
+ /**
10
+ * True for a scheduled short run. Such a run still reports errors, but it does
11
+ * not start a release-health session, so a run with nothing to report opens no
12
+ * connection to Sentry. One session per run was one new ingest socket per run:
13
+ * a 15 s reconcile timer alone left thousands of sockets in TIME_WAIT a day.
14
+ */
15
+ export declare function isScheduledShortRunCommand(argv: readonly string[], options?: {
16
+ interactive?: boolean;
17
+ }): boolean;
9
18
  /**
10
19
  * True when this process must not open the Sentry transport. `HQ_DAEMON_RESIDENT`
11
20
  * marks the long-running process the daemon started, including one whose
@@ -37,6 +37,58 @@ export function isLongLivedHelperCommand(argv) {
37
37
  const command = commandArgv(argv);
38
38
  return LONG_LIVED_HELPER_COMMANDS.some((prefix) => prefix.length <= command.length && prefix.every((part, index) => command[index] === part));
39
39
  }
40
+ /**
41
+ * Short commands that a scheduler runs again and again: the daemon's scheduled
42
+ * units (src/lib/daemon/catalog.ts) and the outpost systemd timers. Each run is
43
+ * a fresh process. Matched on argv, not on an environment mark, so a run that
44
+ * a daemon started before this release still matches once the new CLI is on
45
+ * disk. Leading `--hq-root <path>` after `core` is skipped.
46
+ */
47
+ const SCHEDULED_SHORT_RUN_COMMANDS = [
48
+ ["daemon", "service", "self-update"],
49
+ ["daemon", "service", "fleet-bots-update"],
50
+ ["daemon", "service", "sync-core-reconcile"],
51
+ ["daemon", "service", "sync-core-selfcheck"],
52
+ ["daemon", "service", "sync-core-manifest"],
53
+ ["runners", "reconcile"],
54
+ ["lanes", "reconcile"],
55
+ ["lanes", "outpost-pruner", "run"],
56
+ ["index", "sync"],
57
+ ["core", "jobs", "reconcile"],
58
+ ];
59
+ function withoutCoreHqRoot(command) {
60
+ if (command[0] !== "core")
61
+ return command;
62
+ const rest = command.slice(1);
63
+ while (rest[0] === "--hq-root" && rest.length >= 2)
64
+ rest.splice(0, 2);
65
+ return ["core", ...rest];
66
+ }
67
+ /**
68
+ * True for a scheduled short run. Such a run still reports errors, but it does
69
+ * not start a release-health session, so a run with nothing to report opens no
70
+ * connection to Sentry. One session per run was one new ingest socket per run:
71
+ * a 15 s reconcile timer alone left thousands of sockets in TIME_WAIT a day.
72
+ */
73
+ export function isScheduledShortRunCommand(argv, options = {}) {
74
+ // A person running one of these by hand keeps the normal session. Units and
75
+ // timers run with no terminal on stdin or stdout.
76
+ if (options.interactive ?? isInteractiveTerminal())
77
+ return false;
78
+ const command = withoutCoreHqRoot(commandArgv(argv));
79
+ if (command.includes("--dry-run"))
80
+ return false;
81
+ return SCHEDULED_SHORT_RUN_COMMANDS.some((prefix) => {
82
+ if (prefix.length > command.length || !prefix.every((part, index) => command[index] === part))
83
+ return false;
84
+ // Exact subcommand: `lanes reconcile install` is a setup command, not the timer run.
85
+ const next = command[prefix.length];
86
+ return next === undefined || next.startsWith("-");
87
+ });
88
+ }
89
+ function isInteractiveTerminal() {
90
+ return process.stdin.isTTY === true || process.stdout.isTTY === true;
91
+ }
40
92
  /**
41
93
  * True when this process must not open the Sentry transport. `HQ_DAEMON_RESIDENT`
42
94
  * marks the long-running process the daemon started, including one whose
@@ -47,4 +47,67 @@ export declare function removeEntryNoFollow(p: string, opts?: {
47
47
  * Returns false when nothing exists at `linkPath`.
48
48
  */
49
49
  export declare function removeLinkOnly(linkPath: string): boolean;
50
+ /** Marker file written into a folder HQ copied in place of a release link. */
51
+ export declare const LINK_COPY_MARKER = ".hq-link-copy";
52
+ /** What a link copy's marker records. */
53
+ export interface LinkCopyMarker {
54
+ /** The absolute folder the copy was made from (the link's target). */
55
+ source: string;
56
+ /** The entry name HQ gave the copy. */
57
+ name: string;
58
+ /** {@link linkCopyTreeHash} of the copy when HQ wrote it. */
59
+ hash: string;
60
+ /** Why HQ copied instead of linking. */
61
+ reason?: string;
62
+ }
63
+ export interface LinkCopyResult {
64
+ /** Hash recorded in the marker. */
65
+ hash: string;
66
+ /** Paths (relative to the source) of links that resolve outside `within`; not copied. */
67
+ skippedOutside: string[];
68
+ }
69
+ export interface LinkCopyOptions {
70
+ /** Real path of the HQ root. A link inside the source is followed only when it resolves under it. */
71
+ within: string;
72
+ /** Why HQ copied instead of linking; stored in the marker. */
73
+ reason?: string;
74
+ }
75
+ /**
76
+ * A sha256 over the names and contents of what a link copy of `dir` holds,
77
+ * read with the same rules as the copy (see {@link walkLinkCopyTree}). Hashing
78
+ * the copy and hashing its source give the same value while they match.
79
+ */
80
+ export declare function linkCopyTreeHash(dir: string, within: string): string;
81
+ /**
82
+ * The hash of an HQ link copy as it sits on disk. HQ copies never contain
83
+ * links (links in the source are copied as real files and folders, or left
84
+ * out), so any link inside the copy is something the user added: it is hashed
85
+ * by its text and never followed. For a copy without links this equals
86
+ * {@link linkCopyTreeHash} of the copy.
87
+ */
88
+ export declare function linkCopyContentHash(dir: string, within: string): string;
89
+ /**
90
+ * The marker of a folder HQ copied in place of a release link, or null when
91
+ * `p` is not a real folder carrying a valid marker.
92
+ */
93
+ export declare function readLinkCopyMarker(p: string): LinkCopyMarker | null;
94
+ /**
95
+ * Copy the folder `source` to the new path `dest` and mark it as a link copy.
96
+ * `source` must resolve under `opts.within` (the HQ root). A link inside the
97
+ * source is followed only when it resolves under `opts.within`; one that
98
+ * resolves outside is left out and listed in `skippedOutside`. A partial copy
99
+ * is removed when the copy fails.
100
+ */
101
+ export declare function copyFolderForLink(source: string, dest: string, opts: LinkCopyOptions): LinkCopyResult;
102
+ /**
103
+ * Replace the marked link copy at `dest` with a fresh copy of `source`. The
104
+ * new copy is made beside it first, so a failed copy leaves the old copy in
105
+ * place. The old copy is then renamed aside, the new one renamed into place,
106
+ * and only then is the old one deleted; if the second rename fails the old
107
+ * copy is renamed back. A failure at any step leaves a complete, marked copy
108
+ * at `dest`. Refuses a folder without a link-copy marker. The caller decides
109
+ * whether the old copy holds user changes (compare
110
+ * {@link linkCopyContentHash} with the marker's hash) before calling this.
111
+ */
112
+ export declare function refreshLinkCopy(source: string, dest: string, opts: LinkCopyOptions): LinkCopyResult;
50
113
  //# sourceMappingURL=safe-link.d.ts.map
@@ -306,4 +306,250 @@ function assertStillLink(linkPath) {
306
306
  throw new Error(`Refusing to remove ${linkPath}: it is no longer a link.`);
307
307
  }
308
308
  }
309
+ // ---------------------------------------------------------------------------
310
+ // Copies made in place of a release-shipped directory link
311
+ //
312
+ // On some Windows machines a junction a standard user creates is written with
313
+ // the right target but cannot be listed through by anyone (Beaker, Windows 11
314
+ // build 26300, hq-core-staging PR 1883). HQ then removes the junction and
315
+ // copies the target folder in its place. The copy carries a `.hq-link-copy`
316
+ // marker with the same fields as a skill copy's marker (source, entry name,
317
+ // hash of the copied files), so `hq doctor` can tell an HQ copy from a folder
318
+ // the user made, tell whether the user changed it, and tell whether its source
319
+ // moved on since the copy was made.
320
+ // ---------------------------------------------------------------------------
321
+ /** Marker file written into a folder HQ copied in place of a release link. */
322
+ export const LINK_COPY_MARKER = '.hq-link-copy';
323
+ function isUnderReal(rootReal, candidate) {
324
+ const base = rootReal.endsWith(path.sep) ? rootReal.slice(0, -1) : rootReal;
325
+ return candidate === base || candidate.startsWith(base + path.sep);
326
+ }
327
+ /**
328
+ * Walk `root` in sorted order the way a link copy reads it: links are followed
329
+ * only when their real path is under `within`, a link back to a folder on the
330
+ * current path (a loop) is skipped, and the top-level marker is ignored.
331
+ * Entries that are neither files nor folders are skipped.
332
+ */
333
+ function walkLinkCopyTree(root, within, visit, linksAsEntries = false) {
334
+ const ancestors = new Set([fs.realpathSync.native(root)]);
335
+ const walk = (rel) => {
336
+ const abs = rel === '' ? root : path.join(root, rel);
337
+ for (const name of fs.readdirSync(abs).sort()) {
338
+ if (rel === '' && name === LINK_COPY_MARKER)
339
+ continue;
340
+ const childRel = rel === '' ? name : `${rel}/${name}`;
341
+ const child = path.join(abs, name);
342
+ const lst = fs.lstatSync(child);
343
+ let st = lst;
344
+ if (lst.isSymbolicLink() && linksAsEntries) {
345
+ visit({ kind: 'link', rel: childRel, abs: child });
346
+ continue;
347
+ }
348
+ if (lst.isSymbolicLink()) {
349
+ let real;
350
+ try {
351
+ real = fs.realpathSync.native(child);
352
+ }
353
+ catch {
354
+ continue; // A dangling link has nothing to copy.
355
+ }
356
+ if (!isUnderReal(within, real)) {
357
+ visit({ kind: 'outside', rel: childRel, abs: child });
358
+ continue;
359
+ }
360
+ st = fs.statSync(child);
361
+ }
362
+ if (st.isDirectory()) {
363
+ const real = fs.realpathSync.native(child);
364
+ if (ancestors.has(real))
365
+ continue;
366
+ visit({ kind: 'dir', rel: childRel, abs: child });
367
+ ancestors.add(real);
368
+ try {
369
+ walk(childRel);
370
+ }
371
+ finally {
372
+ ancestors.delete(real);
373
+ }
374
+ }
375
+ else if (st.isFile()) {
376
+ visit({ kind: 'file', rel: childRel, abs: child });
377
+ }
378
+ }
379
+ };
380
+ walk('');
381
+ }
382
+ /**
383
+ * A sha256 over the names and contents of what a link copy of `dir` holds,
384
+ * read with the same rules as the copy (see {@link walkLinkCopyTree}). Hashing
385
+ * the copy and hashing its source give the same value while they match.
386
+ */
387
+ export function linkCopyTreeHash(dir, within) {
388
+ const hash = crypto.createHash('sha256');
389
+ walkLinkCopyTree(dir, within, (entry) => {
390
+ if (entry.kind === 'dir')
391
+ hash.update(`d:${entry.rel}\0`);
392
+ else if (entry.kind === 'file') {
393
+ const content = crypto.createHash('sha256').update(fs.readFileSync(entry.abs)).digest('hex');
394
+ hash.update(`f:${entry.rel}\0${content}\0`);
395
+ }
396
+ });
397
+ return hash.digest('hex');
398
+ }
399
+ /**
400
+ * The hash of an HQ link copy as it sits on disk. HQ copies never contain
401
+ * links (links in the source are copied as real files and folders, or left
402
+ * out), so any link inside the copy is something the user added: it is hashed
403
+ * by its text and never followed. For a copy without links this equals
404
+ * {@link linkCopyTreeHash} of the copy.
405
+ */
406
+ export function linkCopyContentHash(dir, within) {
407
+ const hash = crypto.createHash('sha256');
408
+ walkLinkCopyTree(dir, within, (entry) => {
409
+ if (entry.kind === 'dir')
410
+ hash.update(`d:${entry.rel}\0`);
411
+ else if (entry.kind === 'file') {
412
+ const content = crypto.createHash('sha256').update(fs.readFileSync(entry.abs)).digest('hex');
413
+ hash.update(`f:${entry.rel}\0${content}\0`);
414
+ }
415
+ else if (entry.kind === 'link') {
416
+ hash.update(`l:${entry.rel}\0${fs.readlinkSync(entry.abs)}\0`);
417
+ }
418
+ }, true);
419
+ return hash.digest('hex');
420
+ }
421
+ /**
422
+ * The marker of a folder HQ copied in place of a release link, or null when
423
+ * `p` is not a real folder carrying a valid marker.
424
+ */
425
+ export function readLinkCopyMarker(p) {
426
+ try {
427
+ if (!fs.lstatSync(p).isDirectory())
428
+ return null;
429
+ const parsed = JSON.parse(fs.readFileSync(path.join(p, LINK_COPY_MARKER), 'utf-8'));
430
+ if (typeof parsed.source !== 'string' || parsed.source.length === 0)
431
+ return null;
432
+ if (typeof parsed.name !== 'string' || typeof parsed.hash !== 'string')
433
+ return null;
434
+ return {
435
+ source: parsed.source,
436
+ name: parsed.name,
437
+ hash: parsed.hash,
438
+ reason: typeof parsed.reason === 'string' ? parsed.reason : undefined,
439
+ };
440
+ }
441
+ catch {
442
+ return null;
443
+ }
444
+ }
445
+ function copyIntoNewFolder(source, dest, opts, name) {
446
+ const sourceReal = fs.realpathSync.native(source);
447
+ if (!isUnderReal(opts.within, sourceReal)) {
448
+ throw new Error(`Refusing to copy ${source}: it resolves outside ${opts.within}.`);
449
+ }
450
+ const skippedOutside = [];
451
+ let created = false;
452
+ try {
453
+ fs.mkdirSync(dest);
454
+ created = true;
455
+ walkLinkCopyTree(source, opts.within, (entry) => {
456
+ const to = path.join(dest, ...entry.rel.split('/'));
457
+ if (entry.kind === 'outside')
458
+ skippedOutside.push(entry.rel);
459
+ else if (entry.kind === 'dir')
460
+ fs.mkdirSync(to);
461
+ else if (entry.kind === 'file')
462
+ fs.copyFileSync(entry.abs, to, fs.constants.COPYFILE_EXCL);
463
+ });
464
+ const hash = linkCopyContentHash(dest, opts.within);
465
+ const marker = { source, name, hash, ...(opts.reason ? { reason: opts.reason } : {}) };
466
+ fs.writeFileSync(path.join(dest, LINK_COPY_MARKER), `${JSON.stringify(marker)}\n`);
467
+ return { hash, skippedOutside };
468
+ }
469
+ catch (err) {
470
+ // Remove the partial copy, but only when this call created the folder.
471
+ if (created) {
472
+ try {
473
+ removeTreeNoFollow(dest);
474
+ }
475
+ catch { /* report the copy error */ }
476
+ }
477
+ throw err;
478
+ }
479
+ }
480
+ /**
481
+ * Copy the folder `source` to the new path `dest` and mark it as a link copy.
482
+ * `source` must resolve under `opts.within` (the HQ root). A link inside the
483
+ * source is followed only when it resolves under `opts.within`; one that
484
+ * resolves outside is left out and listed in `skippedOutside`. A partial copy
485
+ * is removed when the copy fails.
486
+ */
487
+ export function copyFolderForLink(source, dest, opts) {
488
+ return copyIntoNewFolder(source, dest, opts, path.basename(dest));
489
+ }
490
+ /**
491
+ * Replace the marked link copy at `dest` with a fresh copy of `source`. The
492
+ * new copy is made beside it first, so a failed copy leaves the old copy in
493
+ * place. The old copy is then renamed aside, the new one renamed into place,
494
+ * and only then is the old one deleted; if the second rename fails the old
495
+ * copy is renamed back. A failure at any step leaves a complete, marked copy
496
+ * at `dest`. Refuses a folder without a link-copy marker. The caller decides
497
+ * whether the old copy holds user changes (compare
498
+ * {@link linkCopyContentHash} with the marker's hash) before calling this.
499
+ */
500
+ export function refreshLinkCopy(source, dest, opts) {
501
+ if (readLinkCopyMarker(dest) === null) {
502
+ throw new Error(`Refusing to refresh ${dest}: it is not a copy made by HQ.`);
503
+ }
504
+ // Fixed names reserved for HQ, so a leftover from an interrupted run is
505
+ // found and cleared by the next one.
506
+ const staging = `${dest}.hq-link-refresh`;
507
+ const old = `${dest}.hq-link-old`;
508
+ for (const leftover of [staging, old]) {
509
+ if (fs.existsSync(leftover) || isLinkPath(leftover))
510
+ removeEntryNoFollow(leftover);
511
+ }
512
+ const result = copyIntoNewFolder(source, staging, opts, path.basename(dest));
513
+ try {
514
+ fs.renameSync(dest, old);
515
+ }
516
+ catch (err) {
517
+ try {
518
+ removeTreeNoFollow(staging);
519
+ }
520
+ catch { /* report the swap error */ }
521
+ throw err;
522
+ }
523
+ try {
524
+ fs.renameSync(staging, dest);
525
+ }
526
+ catch (err) {
527
+ try {
528
+ fs.renameSync(old, dest);
529
+ }
530
+ catch {
531
+ /* the old copy stays at `old`; report the swap error */
532
+ }
533
+ try {
534
+ removeTreeNoFollow(staging);
535
+ }
536
+ catch { /* report the swap error */ }
537
+ throw err;
538
+ }
539
+ try {
540
+ removeTreeNoFollow(old);
541
+ }
542
+ catch {
543
+ // The fresh copy is in place; the next refresh clears the leftover.
544
+ }
545
+ return result;
546
+ }
547
+ function isLinkPath(p) {
548
+ try {
549
+ return fs.lstatSync(p).isSymbolicLink();
550
+ }
551
+ catch {
552
+ return false;
553
+ }
554
+ }
309
555
  //# sourceMappingURL=safe-link.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * One shared keep-alive agent for the Sentry transport.
3
+ *
4
+ * `@sentry/node-core`'s default transport builds an agent with
5
+ * `keepAlive: false` and `maxSockets: 30`, so every envelope is a new TCP
6
+ * connection that this process closes, leaving a TIME_WAIT behind. This
7
+ * module reuses one connection per process and caps it at a few sockets.
8
+ *
9
+ * No static network import: fast native entries reach the Sentry setup, and
10
+ * their closure guard (node-network-compat-closure.test.ts) rejects one. The
11
+ * built-in modules are loaded on the first request.
12
+ */
13
+ import type { Agent, ClientRequest, IncomingMessage, RequestOptions } from "node:http";
14
+ type Protocol = "http:" | "https:";
15
+ /** At most this many sockets to Sentry ingest at once, per process. */
16
+ export declare const SENTRY_MAX_SOCKETS = 2;
17
+ /** An idle or stalled Sentry socket is closed after this long. */
18
+ export declare const SENTRY_SOCKET_TIMEOUT_MS = 2000;
19
+ /** The shared agent for one protocol, created on first use. */
20
+ export declare function sentryTransportAgent(protocol?: Protocol): Agent;
21
+ /** `transportOptions.httpModule` for the Sentry Node transport. */
22
+ export declare const sentryHttpModule: {
23
+ request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
24
+ };
25
+ /** Close the shared sockets at the end of a run. A later send opens a new agent. */
26
+ export declare function closeSentryTransportAgents(): void;
27
+ export {};
28
+ //# sourceMappingURL=sentry-keepalive-transport.d.ts.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * One shared keep-alive agent for the Sentry transport.
3
+ *
4
+ * `@sentry/node-core`'s default transport builds an agent with
5
+ * `keepAlive: false` and `maxSockets: 30`, so every envelope is a new TCP
6
+ * connection that this process closes, leaving a TIME_WAIT behind. This
7
+ * module reuses one connection per process and caps it at a few sockets.
8
+ *
9
+ * No static network import: fast native entries reach the Sentry setup, and
10
+ * their closure guard (node-network-compat-closure.test.ts) rejects one. The
11
+ * built-in modules are loaded on the first request.
12
+ */
13
+ import { createRequire } from "node:module";
14
+ const requireBuiltin = createRequire(import.meta.url);
15
+ /** At most this many sockets to Sentry ingest at once, per process. */
16
+ export const SENTRY_MAX_SOCKETS = 2;
17
+ /** An idle or stalled Sentry socket is closed after this long. */
18
+ export const SENTRY_SOCKET_TIMEOUT_MS = 2_000;
19
+ const agents = new Map();
20
+ function builtin(protocol) {
21
+ return requireBuiltin(protocol === "http:" ? "node:http" : "node:https");
22
+ }
23
+ /** The shared agent for one protocol, created on first use. */
24
+ export function sentryTransportAgent(protocol = "https:") {
25
+ let agent = agents.get(protocol);
26
+ if (!agent) {
27
+ agent = new (builtin(protocol).Agent)({
28
+ keepAlive: true,
29
+ keepAliveMsecs: 1_000,
30
+ maxSockets: SENTRY_MAX_SOCKETS,
31
+ maxFreeSockets: 1,
32
+ timeout: SENTRY_SOCKET_TIMEOUT_MS,
33
+ });
34
+ agents.set(protocol, agent);
35
+ }
36
+ return agent;
37
+ }
38
+ /**
39
+ * The SDK passes its own plain agent with every request. A proxy agent is a
40
+ * subclass; keep it so proxied installs still reach Sentry.
41
+ */
42
+ function isSdkPlainAgent(agent) {
43
+ if (agent === undefined || agent === null)
44
+ return true;
45
+ if (typeof agent !== "object")
46
+ return false;
47
+ const ctor = agent.constructor;
48
+ return ctor === builtin("http:").Agent || ctor === builtin("https:").Agent;
49
+ }
50
+ /** `transportOptions.httpModule` for the Sentry Node transport. */
51
+ export const sentryHttpModule = {
52
+ request(options, callback) {
53
+ if (typeof options === "string" || options instanceof URL) {
54
+ const protocol = new URL(String(options)).protocol === "http:" ? "http:" : "https:";
55
+ return builtin(protocol).request(options, { agent: sentryTransportAgent(protocol) }, callback);
56
+ }
57
+ const protocol = options.protocol === "http:" ? "http:" : "https:";
58
+ const request = isSdkPlainAgent(options.agent)
59
+ ? { ...options, agent: sentryTransportAgent(protocol) }
60
+ : options;
61
+ return builtin(protocol).request(request, callback);
62
+ },
63
+ };
64
+ /** Close the shared sockets at the end of a run. A later send opens a new agent. */
65
+ export function closeSentryTransportAgents() {
66
+ for (const agent of agents.values())
67
+ agent.destroy();
68
+ agents.clear();
69
+ }
70
+ //# sourceMappingURL=sentry-keepalive-transport.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.212",
3
+ "version": "5.345.214",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -117,11 +117,11 @@
117
117
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
118
118
  },
119
119
  "optionalDependencies": {
120
- "@indigoai-us/hq-hook-win32-x64": "5.345.212",
121
- "@indigoai-us/hq-hook-win32-arm64": "5.345.212",
122
- "@indigoai-us/hq-hook-darwin-x64": "5.345.212",
123
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.212",
124
- "@indigoai-us/hq-hook-linux-x64": "5.345.212",
125
- "@indigoai-us/hq-hook-linux-arm64": "5.345.212"
120
+ "@indigoai-us/hq-hook-win32-x64": "5.345.214",
121
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.214",
122
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.214",
123
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.214",
124
+ "@indigoai-us/hq-hook-linux-x64": "5.345.214",
125
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.214"
126
126
  }
127
127
  }