@indigoai-us/hq-cli 5.345.212 → 5.345.215-beta.0

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 (161) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/bin/hq-auth-refresh.js +2 -1
  3. package/dist/command-catalog.generated.d.ts +442 -50
  4. package/dist/command-catalog.generated.js +541 -50
  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/agents.d.ts +51 -1
  9. package/dist/commands/agents.js +154 -2
  10. package/dist/commands/bot-jobs.d.ts +2 -15
  11. package/dist/commands/bot-jobs.js +2 -94
  12. package/dist/commands/bot-runtime.d.ts +46 -5
  13. package/dist/commands/bot-runtime.js +228 -18
  14. package/dist/commands/bot.d.ts +16 -9
  15. package/dist/commands/bot.js +169 -51
  16. package/dist/commands/cloud.d.ts +66 -13
  17. package/dist/commands/cloud.js +120 -39
  18. package/dist/commands/company-restore.d.ts +23 -0
  19. package/dist/commands/company-restore.js +128 -0
  20. package/dist/commands/company.js +2 -0
  21. package/dist/commands/core-handoff.js +1 -0
  22. package/dist/commands/core-hq-session-native.js +2 -2
  23. package/dist/commands/core-pin-native.js +1 -1
  24. package/dist/commands/core-policy.js +1 -1
  25. package/dist/commands/core-resolve-company-native.js +1 -1
  26. package/dist/commands/core-sentry-report-fast.d.ts +2 -0
  27. package/dist/commands/core-sentry-report-fast.js +3 -1
  28. package/dist/commands/daemon.js +11 -1
  29. package/dist/commands/integrations-connect.d.ts +17 -4
  30. package/dist/commands/integrations-connect.js +224 -26
  31. package/dist/commands/lanes-link.js +10 -5
  32. package/dist/commands/lanes.js +26 -9
  33. package/dist/commands/rescue.js +13 -0
  34. package/dist/commands/secrets.d.ts +11 -0
  35. package/dist/commands/secrets.js +41 -7
  36. package/dist/commands/sources.js +6 -0
  37. package/dist/commands/storage-offload.d.ts +12 -0
  38. package/dist/commands/storage-offload.js +41 -3
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/index.js +2 -0
  42. package/dist/lazy-commands.js +2 -0
  43. package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
  44. package/dist/lib/agent-kit/inbox-fetch.js +215 -3
  45. package/dist/lib/agent-kit/inbox-redact.js +1 -1
  46. package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
  47. package/dist/lib/agent-kit/inbox-state.js +261 -4
  48. package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
  49. package/dist/lib/agent-kit/mcp/tools.js +68 -25
  50. package/dist/lib/agent-kit/run/inbox.js +4 -2
  51. package/dist/lib/agent-kit/skills.js +4 -1
  52. package/dist/lib/agent-kit/wake.d.ts +9 -1
  53. package/dist/lib/agent-kit/wake.js +10 -3
  54. package/dist/lib/bot/config.d.ts +1 -0
  55. package/dist/lib/bot/config.js +10 -0
  56. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  57. package/dist/lib/bot/eventbridge-cron.js +104 -0
  58. package/dist/lib/bot/fleet-cron.js +193 -14
  59. package/dist/lib/bot/fleet-download.d.ts +2 -0
  60. package/dist/lib/bot/fleet-download.js +23 -0
  61. package/dist/lib/bot/fleet-local.d.ts +34 -1
  62. package/dist/lib/bot/fleet-local.js +254 -37
  63. package/dist/lib/bot/fleet-python.d.ts +3 -0
  64. package/dist/lib/bot/fleet-python.js +34 -4
  65. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  66. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  67. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  68. package/dist/lib/bot/legacy-provider-login.js +19 -2
  69. package/dist/lib/bot/prompt.js +1 -1
  70. package/dist/lib/bot/readiness.d.ts +8 -0
  71. package/dist/lib/bot/readiness.js +17 -3
  72. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  73. package/dist/lib/bot/runtime-auth.js +94 -3
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  76. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  77. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  78. package/dist/lib/capacity/collectors/grok.js +56 -5
  79. package/dist/lib/core-utils/session-id.d.ts +1 -1
  80. package/dist/lib/core-utils/session-id.js +4 -0
  81. package/dist/lib/daemon/catalog.js +11 -1
  82. package/dist/lib/daemon/run.js +9 -1
  83. package/dist/lib/daemon/updater.d.ts +34 -2
  84. package/dist/lib/daemon/updater.js +51 -2
  85. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  86. package/dist/lib/db/sqlite-binding.js +1 -1
  87. package/dist/lib/delivery/artifacts.d.ts +99 -0
  88. package/dist/lib/delivery/artifacts.js +548 -0
  89. package/dist/lib/delivery/backup.d.ts +78 -0
  90. package/dist/lib/delivery/backup.js +343 -0
  91. package/dist/lib/delivery/cache.d.ts +29 -0
  92. package/dist/lib/delivery/cache.js +33 -0
  93. package/dist/lib/delivery/contracts.d.ts +142 -0
  94. package/dist/lib/delivery/contracts.js +289 -0
  95. package/dist/lib/delivery/credentials.d.ts +54 -0
  96. package/dist/lib/delivery/credentials.js +119 -0
  97. package/dist/lib/delivery/enrollment.d.ts +142 -0
  98. package/dist/lib/delivery/enrollment.js +382 -0
  99. package/dist/lib/delivery/identity.d.ts +25 -0
  100. package/dist/lib/delivery/identity.js +82 -0
  101. package/dist/lib/delivery/inbox.d.ts +116 -0
  102. package/dist/lib/delivery/inbox.js +260 -0
  103. package/dist/lib/delivery/migrations.d.ts +139 -0
  104. package/dist/lib/delivery/migrations.js +623 -0
  105. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  106. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  107. package/dist/lib/delivery/mqtt.d.ts +61 -0
  108. package/dist/lib/delivery/mqtt.js +112 -0
  109. package/dist/lib/delivery/outbox.d.ts +95 -0
  110. package/dist/lib/delivery/outbox.js +187 -0
  111. package/dist/lib/delivery/provenance.d.ts +129 -0
  112. package/dist/lib/delivery/provenance.js +93 -0
  113. package/dist/lib/delivery/reconciler.d.ts +151 -0
  114. package/dist/lib/delivery/reconciler.js +492 -0
  115. package/dist/lib/delivery/restore.d.ts +35 -0
  116. package/dist/lib/delivery/restore.js +134 -0
  117. package/dist/lib/delivery/store.d.ts +161 -0
  118. package/dist/lib/delivery/store.js +940 -0
  119. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  120. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  121. package/dist/lib/delivery/workers/macos.d.ts +176 -0
  122. package/dist/lib/delivery/workers/macos.js +901 -0
  123. package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
  124. package/dist/lib/delivery/workers/windows-boundary.js +693 -0
  125. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  126. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  127. package/dist/lib/delivery/workers/windows.d.ts +241 -0
  128. package/dist/lib/delivery/workers/windows.js +608 -0
  129. package/dist/lib/doctor/checks/release-links.d.ts +50 -8
  130. package/dist/lib/doctor/checks/release-links.js +260 -24
  131. package/dist/lib/doctor/fix/apply.js +24 -8
  132. package/dist/lib/doctor/fix/remediation.js +15 -5
  133. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  134. package/dist/lib/install/provider-wrappers.js +68 -3
  135. package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
  136. package/dist/lib/lanes/autopilot-registry.js +59 -7
  137. package/dist/lib/lanes/links.d.ts +14 -0
  138. package/dist/lib/lanes/links.js +320 -25
  139. package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
  140. package/dist/lib/lanes/outpost-pruner-install.js +4 -3
  141. package/dist/main.js +3 -1
  142. package/dist/sentry-init.d.ts +2 -0
  143. package/dist/sentry-init.js +13 -2
  144. package/dist/sentry.d.ts +2 -0
  145. package/dist/sentry.js +5 -1
  146. package/dist/utils/cli-network-lifecycle.d.ts +9 -0
  147. package/dist/utils/cli-network-lifecycle.js +52 -0
  148. package/dist/utils/cognito-callback-port.d.ts +14 -0
  149. package/dist/utils/cognito-callback-port.js +24 -0
  150. package/dist/utils/cognito-session.js +3 -3
  151. package/dist/utils/deleted-company-notice.d.ts +59 -0
  152. package/dist/utils/deleted-company-notice.js +156 -0
  153. package/dist/utils/login-browser.d.ts +1 -1
  154. package/dist/utils/login-browser.js +7 -5
  155. package/dist/utils/resident-package-preload.js +30 -15
  156. package/dist/utils/safe-link.d.ts +63 -0
  157. package/dist/utils/safe-link.js +246 -0
  158. package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
  159. package/dist/utils/sentry-keepalive-transport.js +70 -0
  160. package/dist/utils/vault-api.js +7 -0
  161. package/package.json +7 -7
@@ -9,9 +9,24 @@ import type { CheckContext, CheckFamily, CheckResult } from "../types.js";
9
9
  export declare const RELEASE_LINKS_FAMILY_ID = "release-links";
10
10
  export declare const RELEASE_LINKS_FAMILY_TITLE = "Release links";
11
11
  export declare const RELEASE_LINKS_CHECK_ID = "release-links.resolve";
12
- export declare const RELEASE_LINK_REMEDIATION = "Run `hq doctor --fix` (or `hq rescue -y`) to restore the shipped link. A dangling link that points outside the HQ root and the temp folder is treated as your own and left alone. On Windows, a directory link is written as a junction and a file link as a copy when symlinks are not allowed.";
12
+ export declare const RELEASE_LINK_REMEDIATION = "Run `hq doctor --fix` (or `hq rescue -y`) to restore the shipped link. A dangling link that points outside the HQ root and the temp folder is treated as your own and left alone. On Windows, a directory link is written as a junction and a file link as a copy when symlinks are not allowed. A junction Windows will not list through is replaced by a copy of its target.";
13
13
  /** Message prefix for a link whose target is missing; `--fix` keys off it. */
14
14
  export declare const DANGLING_RELEASE_LINK_PROBLEM = "does not resolve.";
15
+ /**
16
+ * Message prefix for a directory link that resolves to its shipped target but
17
+ * cannot be listed through (a junction a standard Windows user created on
18
+ * some machines); `--fix` keys off it.
19
+ */
20
+ export declare const UNLISTABLE_RELEASE_LINK_PROBLEM = "is a link Windows will not list through.";
21
+ /**
22
+ * Message prefix for an HQ fallback copy whose target changed since the copy
23
+ * was made and that the user has not edited; `--fix` keys off it.
24
+ */
25
+ export declare const STALE_RELEASE_LINK_COPY_PROBLEM = "is an out-of-date copy of its target.";
26
+ /** Remediation for a fallback copy that is current or out of date. */
27
+ export declare const RELEASE_LINK_COPY_REMEDIATION = "Copies do not follow updates. `hq doctor --fix` or `hq rescue -y` refreshes the copy from its target when the target changes. Make changes in the target folder, not in the copy: a copy with changes made inside it is not refreshed, and a refresh would replace them.";
28
+ /** Every message prefix the `repair-release-link` fix acts on. */
29
+ export declare const REPAIRABLE_RELEASE_LINK_PROBLEMS: readonly string[];
15
30
  interface ReleaseLink {
16
31
  rel: string;
17
32
  linkText: string;
@@ -21,6 +36,13 @@ interface ReleaseLink {
21
36
  export declare const RELEASE_LINKS: readonly ReleaseLink[];
22
37
  export declare const releaseLinksFamily: CheckFamily;
23
38
  export declare function checkReleaseLinks(context: CheckContext): CheckResult[];
39
+ /**
40
+ * Whether listing a directory through `link` works and shows as many entries
41
+ * as listing `target` directly. False when the link listing throws (EPERM,
42
+ * EACCES, ENOENT, ...) or the counts differ. When `target` itself cannot be
43
+ * listed the link is not blamed, so this returns true.
44
+ */
45
+ export declare function linkListsLikeTarget(link: string, target: string): boolean;
24
46
  /** Where a rescue may stage its extraction folder. */
25
47
  export interface RescueStagingDeps {
26
48
  /** The system temp folder. Default `os.tmpdir()`. */
@@ -32,18 +54,25 @@ export interface RescueStagingDeps {
32
54
  export interface ReleaseLinkRepair {
33
55
  rel: string;
34
56
  /**
35
- * `repointed`: the link was rewritten (see `linkText`). `removed`: the
36
- * shipped target is missing too, so the dangling link was deleted.
37
- * `skipped`: the link points outside the HQ root and the temp folder, so it
38
- * is treated as the user's own link and left alone (see `reason`).
39
- * `failed`: the repair threw for this link only (see `reason`).
57
+ * `repointed`: the link was rewritten (see `linkText`). `copied`: on
58
+ * Windows the junction was written but could not be listed through, so it
59
+ * was removed and the target folder copied in its place (see `target`,
60
+ * `reason`). `refreshed`: an out-of-date HQ copy was replaced with a fresh
61
+ * copy of its target. `kept`: an HQ copy is out of date but files inside it
62
+ * changed, so it was left alone (see `reason`). `removed`: the shipped
63
+ * target is missing too, so the dangling link was deleted. `skipped`: the
64
+ * link points outside the HQ root and the temp folder, so it is treated as
65
+ * the user's own link and left alone (see `reason`). `failed`: the repair
66
+ * threw for this link only (see `reason`).
40
67
  */
41
- action: "repointed" | "removed" | "skipped" | "failed";
42
- /** The absolute target the link now resolves to (repointed only). */
68
+ action: "repointed" | "copied" | "refreshed" | "kept" | "removed" | "skipped" | "failed";
69
+ /** The absolute target the link now resolves to, or the copy's source. */
43
70
  target?: string;
44
71
  /** The text written into the link (repointed only). */
45
72
  linkText?: string;
46
73
  reason?: string;
74
+ /** Links inside the target that resolve outside the HQ root; left out of a copy. */
75
+ skippedOutside?: string[];
47
76
  }
48
77
  export interface RepairReleaseLinksDeps {
49
78
  platform?: NodeJS.Platform;
@@ -78,6 +107,19 @@ export interface RepairReleaseLinksDeps {
78
107
  * is created. The old entry is removed with {@link removeLinkOnly}, which never
79
108
  * follows it. A failure on one link is reported as `failed` and the remaining
80
109
  * links are still repaired.
110
+ *
111
+ * Windows junctions that cannot be listed through: on some Windows machines a
112
+ * junction a standard user creates has the right target but nobody can list
113
+ * through it (hq-core-staging PR 1883, Beaker). After writing a directory
114
+ * junction this lists through it and compares the entry count with the
115
+ * target; on a mismatch the junction is removed and the target copied in its
116
+ * place, marked with `.hq-link-copy` (`copied`). A link that already resolves
117
+ * to the shipped target but cannot be listed through is rewritten the same
118
+ * way. A link that lists correctly is never replaced.
119
+ *
120
+ * HQ copies: an unedited copy whose target changed is refreshed (`refreshed`).
121
+ * A copy whose files changed after HQ made it is left alone (`kept`), because
122
+ * a refresh would replace those changes. A current copy is not touched.
81
123
  */
82
124
  export declare function repairDanglingReleaseLinks(hqRoot: string, deps?: RepairReleaseLinksDeps): ReleaseLinkRepair[];
83
125
  export {};
@@ -8,13 +8,34 @@
8
8
  import * as fs from "node:fs";
9
9
  import * as os from "node:os";
10
10
  import * as path from "node:path";
11
- import { removeLinkOnly } from "../../../utils/safe-link.js";
11
+ import { copyFolderForLink, linkCopyContentHash, linkCopyTreeHash, readLinkCopyMarker, refreshLinkCopy, removeLinkOnly, } from "../../../utils/safe-link.js";
12
12
  export const RELEASE_LINKS_FAMILY_ID = "release-links";
13
13
  export const RELEASE_LINKS_FAMILY_TITLE = "Release links";
14
14
  export const RELEASE_LINKS_CHECK_ID = "release-links.resolve";
15
- export const RELEASE_LINK_REMEDIATION = "Run `hq doctor --fix` (or `hq rescue -y`) to restore the shipped link. A dangling link that points outside the HQ root and the temp folder is treated as your own and left alone. On Windows, a directory link is written as a junction and a file link as a copy when symlinks are not allowed.";
15
+ export const RELEASE_LINK_REMEDIATION = "Run `hq doctor --fix` (or `hq rescue -y`) to restore the shipped link. A dangling link that points outside the HQ root and the temp folder is treated as your own and left alone. On Windows, a directory link is written as a junction and a file link as a copy when symlinks are not allowed. A junction Windows will not list through is replaced by a copy of its target.";
16
16
  /** Message prefix for a link whose target is missing; `--fix` keys off it. */
17
17
  export const DANGLING_RELEASE_LINK_PROBLEM = "does not resolve.";
18
+ /**
19
+ * Message prefix for a directory link that resolves to its shipped target but
20
+ * cannot be listed through (a junction a standard Windows user created on
21
+ * some machines); `--fix` keys off it.
22
+ */
23
+ export const UNLISTABLE_RELEASE_LINK_PROBLEM = "is a link Windows will not list through.";
24
+ /**
25
+ * Message prefix for an HQ fallback copy whose target changed since the copy
26
+ * was made and that the user has not edited; `--fix` keys off it.
27
+ */
28
+ export const STALE_RELEASE_LINK_COPY_PROBLEM = "is an out-of-date copy of its target.";
29
+ /** Remediation for a fallback copy that is current or out of date. */
30
+ export const RELEASE_LINK_COPY_REMEDIATION = "Copies do not follow updates. `hq doctor --fix` or `hq rescue -y` refreshes the copy from its target when the target changes. Make changes in the target folder, not in the copy: a copy with changes made inside it is not refreshed, and a refresh would replace them.";
31
+ /** Every message prefix the `repair-release-link` fix acts on. */
32
+ export const REPAIRABLE_RELEASE_LINK_PROBLEMS = [
33
+ DANGLING_RELEASE_LINK_PROBLEM,
34
+ UNLISTABLE_RELEASE_LINK_PROBLEM,
35
+ STALE_RELEASE_LINK_COPY_PROBLEM,
36
+ ];
37
+ /** Why HQ copies a directory instead of keeping the junction. */
38
+ const UNLISTABLE_JUNCTION_REASON = "Windows created the junction but would not list its contents, so HQ copied the target instead.";
18
39
  const CYGWIN_SYMLINK_COOKIE = Buffer.from("!<symlink>", "latin1");
19
40
  /** Paths git records as symlinks in the hq-core release. */
20
41
  export const RELEASE_LINKS = [
@@ -49,21 +70,25 @@ export function checkReleaseLinks(context) {
49
70
  },
50
71
  ];
51
72
  }
52
- const failures = [];
73
+ const findings = [];
53
74
  for (const entry of present) {
54
75
  const problem = releaseLinkProblem(context.hqRoot, entry);
55
- if (!problem)
76
+ if (problem) {
77
+ findings.push({
78
+ status: "FAIL",
79
+ checkId: RELEASE_LINKS_CHECK_ID,
80
+ target: entry.rel,
81
+ message: `${entry.rel} ${problem}`,
82
+ remediation: RELEASE_LINK_REMEDIATION,
83
+ });
56
84
  continue;
57
- failures.push({
58
- status: "FAIL",
59
- checkId: RELEASE_LINKS_CHECK_ID,
60
- target: entry.rel,
61
- message: `${entry.rel} ${problem}`,
62
- remediation: RELEASE_LINK_REMEDIATION,
63
- });
85
+ }
86
+ const copy = releaseLinkCopyFinding(context.hqRoot, entry);
87
+ if (copy)
88
+ findings.push(copy);
64
89
  }
65
- if (failures.length > 0)
66
- return failures;
90
+ if (findings.length > 0)
91
+ return findings;
67
92
  return [
68
93
  {
69
94
  status: "PASS",
@@ -93,6 +118,11 @@ function releaseLinkProblem(hqRoot, entry) {
93
118
  if (!pathIsInside(hqRoot, resolved)) {
94
119
  return "points outside this HQ root, so it does not resolve to the shipped target.";
95
120
  }
121
+ if (entry.kind === "dir" &&
122
+ resolvesToShippedTarget(hqRoot, entry, resolved) &&
123
+ !linkListsLikeTarget(destination, resolved)) {
124
+ return `${UNLISTABLE_RELEASE_LINK_PROBLEM} It points at ${resolved}, but listing through it fails or shows a different number of entries than the folder itself.`;
125
+ }
96
126
  return null;
97
127
  }
98
128
  if (lst.isFile()) {
@@ -124,6 +154,104 @@ function readlinkAbsOrNull(destination) {
124
154
  return null;
125
155
  }
126
156
  }
157
+ /**
158
+ * Whether listing a directory through `link` works and shows as many entries
159
+ * as listing `target` directly. False when the link listing throws (EPERM,
160
+ * EACCES, ENOENT, ...) or the counts differ. When `target` itself cannot be
161
+ * listed the link is not blamed, so this returns true.
162
+ */
163
+ export function linkListsLikeTarget(link, target) {
164
+ let expected;
165
+ try {
166
+ expected = fs.readdirSync(target).length;
167
+ }
168
+ catch {
169
+ return true;
170
+ }
171
+ try {
172
+ return fs.readdirSync(link).length === expected;
173
+ }
174
+ catch {
175
+ return false;
176
+ }
177
+ }
178
+ function resolvesToShippedTarget(hqRoot, entry, resolved) {
179
+ const shipped = containedTarget(hqRoot, entry);
180
+ if (!shipped)
181
+ return false;
182
+ const shippedReal = resolvesOrNull(shipped);
183
+ return shippedReal !== null && shippedReal === resolved;
184
+ }
185
+ /**
186
+ * Classify the HQ fallback copy at a directory release link: `edited` when
187
+ * its files no longer match the hash HQ recorded, else `stale` when its
188
+ * target changed since, else `current`. Null when the path is not an HQ copy
189
+ * of the shipped target (a folder the user made, or a copy of something else).
190
+ */
191
+ function linkCopyState(hqRoot, entry) {
192
+ if (entry.kind !== "dir")
193
+ return null;
194
+ const destination = path.join(hqRoot, entry.rel);
195
+ const marker = readLinkCopyMarker(destination);
196
+ if (!marker)
197
+ return null;
198
+ const shipped = containedTarget(hqRoot, entry);
199
+ if (!shipped)
200
+ return null;
201
+ const rootReal = resolvesOrNull(path.resolve(hqRoot));
202
+ if (rootReal === null)
203
+ return null;
204
+ const shippedAbs = path.join(rootReal, path.relative(path.resolve(hqRoot), shipped));
205
+ if (path.resolve(marker.source) !== shippedAbs && path.resolve(marker.source) !== path.resolve(shipped)) {
206
+ return null;
207
+ }
208
+ try {
209
+ if (linkCopyContentHash(destination, rootReal) !== marker.hash) {
210
+ return { state: "edited", source: marker.source };
211
+ }
212
+ if (!statOrNull(marker.source)?.isDirectory()) {
213
+ return { state: "unreadable", source: marker.source, reason: "its target folder is missing" };
214
+ }
215
+ const fresh = linkCopyTreeHash(marker.source, rootReal) === marker.hash;
216
+ return { state: fresh ? "current" : "stale", source: marker.source };
217
+ }
218
+ catch (err) {
219
+ return { state: "unreadable", source: marker.source, reason: errorMessage(err) };
220
+ }
221
+ }
222
+ /** A WARN for an HQ fallback copy at a directory release link, or null. */
223
+ function releaseLinkCopyFinding(hqRoot, entry) {
224
+ const copy = linkCopyState(hqRoot, entry);
225
+ if (!copy)
226
+ return null;
227
+ const base = { status: "WARN", checkId: RELEASE_LINKS_CHECK_ID, target: entry.rel };
228
+ switch (copy.state) {
229
+ case "current":
230
+ return {
231
+ ...base,
232
+ message: `${entry.rel} is a copy of ${copy.source}, made because Windows would not list through a junction there. It matches its target now.`,
233
+ remediation: RELEASE_LINK_COPY_REMEDIATION,
234
+ };
235
+ case "stale":
236
+ return {
237
+ ...base,
238
+ message: `${entry.rel} ${STALE_RELEASE_LINK_COPY_PROBLEM} It was copied from ${copy.source} because Windows would not list through a junction there, and that folder has changed since.`,
239
+ remediation: RELEASE_LINK_COPY_REMEDIATION,
240
+ };
241
+ case "edited":
242
+ return {
243
+ ...base,
244
+ message: `${entry.rel} is a copy of ${copy.source}, and files inside it changed after HQ made it. HQ will not refresh it, because a refresh would replace those changes.`,
245
+ remediation: `Move the changes you want to keep into ${copy.source}, then delete ${entry.rel} and run \`hq rescue -y\` to lay it again.`,
246
+ };
247
+ case "unreadable":
248
+ return {
249
+ ...base,
250
+ message: `${entry.rel} is a copy of ${copy.source} that HQ could not compare with its target: ${copy.reason}.`,
251
+ remediation: RELEASE_LINK_COPY_REMEDIATION,
252
+ };
253
+ }
254
+ }
127
255
  /** Prefix of the folder hq-cloud's rescue creates with mkdtemp. */
128
256
  const RESCUE_STAGING_SEGMENT_PREFIX = "hq-replace-rescue-";
129
257
  /**
@@ -217,6 +345,19 @@ function readFileOrNull(target) {
217
345
  * is created. The old entry is removed with {@link removeLinkOnly}, which never
218
346
  * follows it. A failure on one link is reported as `failed` and the remaining
219
347
  * links are still repaired.
348
+ *
349
+ * Windows junctions that cannot be listed through: on some Windows machines a
350
+ * junction a standard user creates has the right target but nobody can list
351
+ * through it (hq-core-staging PR 1883, Beaker). After writing a directory
352
+ * junction this lists through it and compares the entry count with the
353
+ * target; on a mismatch the junction is removed and the target copied in its
354
+ * place, marked with `.hq-link-copy` (`copied`). A link that already resolves
355
+ * to the shipped target but cannot be listed through is rewritten the same
356
+ * way. A link that lists correctly is never replaced.
357
+ *
358
+ * HQ copies: an unedited copy whose target changed is refreshed (`refreshed`).
359
+ * A copy whose files changed after HQ made it is left alone (`kept`), because
360
+ * a refresh would replace those changes. A current copy is not touched.
220
361
  */
221
362
  export function repairDanglingReleaseLinks(hqRoot, deps = {}) {
222
363
  const platform = deps.platform ?? process.platform;
@@ -233,9 +374,7 @@ export function repairDanglingReleaseLinks(hqRoot, deps = {}) {
233
374
  continue;
234
375
  const destination = path.join(rootReal, entry.rel);
235
376
  const lst = lstatOrNull(destination);
236
- if (!lst || !lst.isSymbolicLink())
237
- continue;
238
- if (resolvesOrNull(destination) !== null)
377
+ if (!lst)
239
378
  continue;
240
379
  const parentReal = resolvesOrNull(path.dirname(destination));
241
380
  if (parentReal === null || !isUnder(rootReal, parentReal))
@@ -243,6 +382,30 @@ export function repairDanglingReleaseLinks(hqRoot, deps = {}) {
243
382
  const target = path.resolve(path.dirname(destination), entry.linkText);
244
383
  if (!isUnder(rootReal, target))
245
384
  continue;
385
+ if (!lst.isSymbolicLink()) {
386
+ const copyRepair = refreshStaleLinkCopy(rootReal, entry, destination);
387
+ if (copyRepair)
388
+ repairs.push(copyRepair);
389
+ continue;
390
+ }
391
+ const resolved = resolvesOrNull(destination);
392
+ if (resolved !== null) {
393
+ // A resolving link is replaced only when it is a directory link to the
394
+ // shipped target that cannot be listed through.
395
+ if (entry.kind !== "dir" ||
396
+ resolved !== resolvesOrNull(target) ||
397
+ linkListsLikeTarget(destination, resolved)) {
398
+ continue;
399
+ }
400
+ try {
401
+ removeLinkOnly(destination);
402
+ repairs.push(writeReleaseLink(entry, target, destination, platform, rootReal));
403
+ }
404
+ catch (err) {
405
+ repairs.push({ rel: entry.rel, action: "failed", reason: errorMessage(err) });
406
+ }
407
+ continue;
408
+ }
246
409
  let current;
247
410
  try {
248
411
  current = path.resolve(path.dirname(destination), fs.readlinkSync(destination));
@@ -269,8 +432,7 @@ export function repairDanglingReleaseLinks(hqRoot, deps = {}) {
269
432
  repairs.push({ rel: entry.rel, action: "removed" });
270
433
  continue;
271
434
  }
272
- const linkText = writeReleaseLink(entry, target, destination, platform);
273
- repairs.push({ rel: entry.rel, action: "repointed", target, linkText });
435
+ repairs.push(writeReleaseLink(entry, target, destination, platform, rootReal));
274
436
  }
275
437
  catch (err) {
276
438
  repairs.push({ rel: entry.rel, action: "failed", reason: errorMessage(err) });
@@ -278,19 +440,93 @@ export function repairDanglingReleaseLinks(hqRoot, deps = {}) {
278
440
  }
279
441
  return repairs;
280
442
  }
281
- /** Write the link and return the text it carries. */
282
- function writeReleaseLink(entry, target, destination, platform) {
443
+ /**
444
+ * Refresh the HQ copy at a directory release link when its target changed and
445
+ * its own files did not. Returns null when there is nothing to do: the path is
446
+ * not an HQ copy of the shipped target, or the copy is current.
447
+ */
448
+ function refreshStaleLinkCopy(rootReal, entry, destination) {
449
+ const copy = linkCopyState(rootReal, entry);
450
+ if (!copy || copy.state === "current")
451
+ return null;
452
+ if (copy.state === "edited") {
453
+ return {
454
+ rel: entry.rel,
455
+ action: "kept",
456
+ target: copy.source,
457
+ reason: `files inside the copy changed after HQ made it, so it was not refreshed. Move the changes you want to keep into ${copy.source}, then delete ${entry.rel} and run \`hq rescue -y\``,
458
+ };
459
+ }
460
+ if (copy.state === "unreadable") {
461
+ return { rel: entry.rel, action: "failed", target: copy.source, reason: copy.reason };
462
+ }
463
+ try {
464
+ const result = refreshLinkCopy(copy.source, destination, {
465
+ within: rootReal,
466
+ reason: UNLISTABLE_JUNCTION_REASON,
467
+ });
468
+ return {
469
+ rel: entry.rel,
470
+ action: "refreshed",
471
+ target: copy.source,
472
+ ...(result.skippedOutside.length > 0 ? { skippedOutside: result.skippedOutside } : {}),
473
+ };
474
+ }
475
+ catch (err) {
476
+ return { rel: entry.rel, action: "failed", target: copy.source, reason: errorMessage(err) };
477
+ }
478
+ }
479
+ /**
480
+ * Write the link and report what was written. On Windows a directory link is
481
+ * a junction that must list like its target; when it does not, the junction is
482
+ * removed and the target copied in its place.
483
+ */
484
+ function writeReleaseLink(entry, target, destination, platform, rootReal) {
485
+ const repointed = (linkText) => ({
486
+ rel: entry.rel,
487
+ action: "repointed",
488
+ target,
489
+ linkText,
490
+ });
283
491
  if (platform !== "win32") {
284
492
  fs.symlinkSync(entry.linkText, destination, entry.kind);
285
- return entry.linkText;
493
+ return repointed(entry.linkText);
286
494
  }
287
495
  if (entry.kind === "dir") {
288
496
  fs.symlinkSync(target, destination, "junction");
289
- return target;
497
+ if (linkListsLikeTarget(destination, target))
498
+ return repointed(target);
499
+ removeLinkOnly(destination);
500
+ let result;
501
+ try {
502
+ result = copyFolderForLink(target, destination, {
503
+ within: rootReal,
504
+ reason: UNLISTABLE_JUNCTION_REASON,
505
+ });
506
+ }
507
+ catch (err) {
508
+ // Put the junction back so the path is not left empty: an empty path is
509
+ // invisible to the check and to later repairs, while the junction keeps
510
+ // the FAIL (and its --fix) in front of the user.
511
+ try {
512
+ fs.symlinkSync(target, destination, "junction");
513
+ }
514
+ catch {
515
+ /* report the copy error */
516
+ }
517
+ throw err;
518
+ }
519
+ return {
520
+ rel: entry.rel,
521
+ action: "copied",
522
+ target,
523
+ reason: UNLISTABLE_JUNCTION_REASON,
524
+ ...(result.skippedOutside.length > 0 ? { skippedOutside: result.skippedOutside } : {}),
525
+ };
290
526
  }
291
527
  try {
292
528
  fs.symlinkSync(target, destination, "file");
293
- return target;
529
+ return repointed(target);
294
530
  }
295
531
  catch (err) {
296
532
  const code = err.code;
@@ -299,7 +535,7 @@ function writeReleaseLink(entry, target, destination, platform) {
299
535
  // Windows without the symlink privilege: the check accepts a copy whose
300
536
  // bytes equal the target.
301
537
  fs.copyFileSync(target, destination);
302
- return target;
538
+ return repointed(target);
303
539
  }
304
540
  }
305
541
  function tempRoots(tmpDir) {
@@ -44,7 +44,7 @@ import { getStateDir } from "@indigoai-us/hq-cloud";
44
44
  import { isPersonalJournalSlug } from "../checks/sync-health.js";
45
45
  import { createDefaultRegistry } from "../registry.js";
46
46
  import { flattenFamilies } from "../report.js";
47
- import { repairDanglingReleaseLinks } from "../checks/release-links.js";
47
+ import { STALE_RELEASE_LINK_COPY_PROBLEM, UNLISTABLE_RELEASE_LINK_PROBLEM, repairDanglingReleaseLinks, } from "../checks/release-links.js";
48
48
  import { parseHookGateProfiles, requiredMissingProfiles, } from "../hook-gate-profiles.js";
49
49
  import { createBackup } from "./backup.js";
50
50
  import { removeStrayGateEntries } from "../stray-gate-entries.js";
@@ -1096,10 +1096,8 @@ function planRepairReleaseLink(hqRoot, result, rem) {
1096
1096
  fixClass: "repair-release-link",
1097
1097
  target: rel,
1098
1098
  relpath: "",
1099
- preview: ` ${rel}\n` +
1100
- ` - dangling link\n` +
1101
- ` + the shipped link to its target under the HQ root (removed if that target is missing)`,
1102
- summary: `repair dangling link ${rel}`,
1099
+ preview: releaseLinkPreview(rel, result.message),
1100
+ summary: `repair release link ${rel}`,
1103
1101
  apply: () => {
1104
1102
  // Each plan repairs only its own link, and a throw is recorded as this
1105
1103
  // plan's failure so the remaining plans still run.
@@ -1109,7 +1107,7 @@ function planRepairReleaseLink(hqRoot, result, rem) {
1109
1107
  if (!entry) {
1110
1108
  failure = `${rel} was not repaired`;
1111
1109
  }
1112
- else if (entry.action === "skipped" || entry.action === "failed") {
1110
+ else if (entry.action === "skipped" || entry.action === "failed" || entry.action === "kept") {
1113
1111
  failure = `${rel} was not repaired: ${entry.reason ?? entry.action}`;
1114
1112
  }
1115
1113
  else {
@@ -1122,8 +1120,12 @@ function planRepairReleaseLink(hqRoot, result, rem) {
1122
1120
  },
1123
1121
  postStatus: (results) => {
1124
1122
  const own = results.filter((entry) => entry.checkId === result.checkId);
1125
- if (own.some((entry) => entry.target === rel))
1126
- return "FAIL";
1123
+ // A link that became a fallback copy is a WARN by design (copies do not
1124
+ // follow updates); anything else still reported for this path is its
1125
+ // own status.
1126
+ const mine = own.find((entry) => entry.target === rel);
1127
+ if (mine)
1128
+ return mine.status;
1127
1129
  // Another link's failure is that plan's status, not this one's.
1128
1130
  if (own.some((entry) => entry.status === "FAIL"))
1129
1131
  return "PASS";
@@ -1132,6 +1134,20 @@ function planRepairReleaseLink(hqRoot, result, rem) {
1132
1134
  failureReason: () => failure,
1133
1135
  };
1134
1136
  }
1137
+ function releaseLinkPreview(rel, message) {
1138
+ const problem = message.startsWith(rel + " ") ? message.slice(rel.length + 1) : message;
1139
+ if (problem.startsWith(UNLISTABLE_RELEASE_LINK_PROBLEM)) {
1140
+ return (` ${rel}\n` +
1141
+ ` - a link Windows will not list through\n` +
1142
+ ` + the shipped link, or a marked copy of its target if Windows still will not list through it`);
1143
+ }
1144
+ if (problem.startsWith(STALE_RELEASE_LINK_COPY_PROBLEM)) {
1145
+ return ` ${rel}\n` + ` - an out-of-date copy\n` + ` + a fresh copy of its target`;
1146
+ }
1147
+ return (` ${rel}\n` +
1148
+ ` - dangling link\n` +
1149
+ ` + the shipped link to its target under the HQ root (removed if that target is missing)`);
1150
+ }
1135
1151
  /** Restore the execute bit on a hook script. */
1136
1152
  function planExecutableBit(hqRoot, result, rem) {
1137
1153
  const abs = rem.fixTarget;
@@ -60,7 +60,7 @@
60
60
  * deciding which of two diverged copies is correct needs human judgement.
61
61
  */
62
62
  import * as path from "node:path";
63
- import { DANGLING_RELEASE_LINK_PROBLEM, RELEASE_LINKS, RELEASE_LINKS_CHECK_ID, } from "../checks/release-links.js";
63
+ import { REPAIRABLE_RELEASE_LINK_PROBLEMS, STALE_RELEASE_LINK_COPY_PROBLEM, UNLISTABLE_RELEASE_LINK_PROBLEM, RELEASE_LINKS, RELEASE_LINKS_CHECK_ID, } from "../checks/release-links.js";
64
64
  import { isCompanyJournalSlug, isSafeCompanySlug, isPersonalJournalSlug, journalSlugFromCheckId, } from "../checks/sync-health.js";
65
65
  /** Matches an exec-bit remediation command, quoted or not: `chmod +x <path>`. */
66
66
  const CHMOD_EXEC = /^chmod\s+\+x\s+(.+)$/;
@@ -189,16 +189,26 @@ export function deriveRemediation(result) {
189
189
  };
190
190
  }
191
191
  // repair-release-link — a shipped link whose target is missing, such as one
192
- // a rescue pointed at its deleted temp folder (feedback_2ab63e50).
192
+ // a rescue pointed at its deleted temp folder (feedback_2ab63e50); a
193
+ // Windows junction that cannot be listed through (FAIL); or an unedited HQ
194
+ // fallback copy whose target changed (WARN).
193
195
  if (checkId === RELEASE_LINKS_CHECK_ID &&
194
- result.status === "FAIL" &&
196
+ (result.status === "FAIL" || result.status === "WARN") &&
195
197
  RELEASE_LINKS.some((entry) => entry.rel === target) &&
196
- result.message.startsWith(target + " " + DANGLING_RELEASE_LINK_PROBLEM)) {
198
+ REPAIRABLE_RELEASE_LINK_PROBLEMS.some((problem) => result.message.startsWith(target + " " + problem))) {
199
+ const problem = result.message.slice(target.length + 1);
200
+ let action = `Repoint the dangling ${target} link at its target under the HQ root (or remove the link when that target is missing).`;
201
+ if (problem.startsWith(UNLISTABLE_RELEASE_LINK_PROBLEM)) {
202
+ action = `Rewrite the ${target} link; if Windows still will not list through the junction, replace it with a marked copy of its target.`;
203
+ }
204
+ else if (problem.startsWith(STALE_RELEASE_LINK_COPY_PROBLEM)) {
205
+ action = `Refresh the ${target} copy from its target. Copies whose files were changed are left alone.`;
206
+ }
197
207
  return {
198
208
  autoFixable: true,
199
209
  fixClass: "repair-release-link",
200
210
  fixTarget: target,
201
- action: `Repoint the dangling ${target} link at its target under the HQ root (or remove the link when that target is missing).`,
211
+ action,
202
212
  command: "hq doctor --fix",
203
213
  };
204
214
  }
@@ -4,6 +4,8 @@
4
4
  */
5
5
  export declare function assertProviderWrappersInstallable(binDir: string): void;
6
6
  export declare function providerWrapperInstallPaths(home: string): string[];
7
+ /** Env var the installed wrapper sets when it hands a run to another wrapper script. */
8
+ export declare function providerWrapperGuardVar(provider: 'claude' | 'codex'): string;
7
9
  export declare function installProviderWrappers(binDir: string, home?: string): string[];
8
10
  export declare function removeProviderWrappers(binDir: string): string[];
9
11
  //# sourceMappingURL=provider-wrappers.d.ts.map