@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.
- package/CHANGELOG.md +20 -0
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +308 -43
- package/dist/command-catalog.generated.js +373 -43
- package/dist/commands/agent-inbox.d.ts +11 -1
- package/dist/commands/agent-inbox.js +128 -38
- package/dist/commands/agent-kit.js +2 -2
- package/dist/commands/core-handoff.js +1 -0
- package/dist/commands/core-hq-session-native.js +2 -2
- package/dist/commands/core-pin-native.js +1 -1
- package/dist/commands/core-policy.js +1 -1
- package/dist/commands/core-resolve-company-native.js +1 -1
- package/dist/commands/core-sentry-report-fast.d.ts +2 -0
- package/dist/commands/core-sentry-report-fast.js +3 -1
- package/dist/commands/daemon.js +11 -1
- package/dist/commands/integrations-connect.d.ts +7 -1
- package/dist/commands/integrations-connect.js +137 -13
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- package/dist/index.js +2 -0
- package/dist/lazy-commands.js +2 -0
- package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
- package/dist/lib/agent-kit/inbox-fetch.js +215 -3
- package/dist/lib/agent-kit/inbox-redact.js +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
- package/dist/lib/agent-kit/inbox-state.js +261 -4
- package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
- package/dist/lib/agent-kit/mcp/tools.js +68 -25
- package/dist/lib/agent-kit/run/inbox.js +4 -2
- package/dist/lib/agent-kit/skills.js +4 -1
- package/dist/lib/agent-kit/wake.d.ts +9 -1
- package/dist/lib/agent-kit/wake.js +10 -3
- package/dist/lib/bot/fleet-cron.js +193 -14
- package/dist/lib/bot/fleet-download.d.ts +2 -0
- package/dist/lib/bot/fleet-download.js +23 -0
- package/dist/lib/bot/fleet-local.d.ts +1 -0
- package/dist/lib/bot/fleet-local.js +41 -8
- package/dist/lib/core-utils/session-id.d.ts +1 -1
- package/dist/lib/core-utils/session-id.js +4 -0
- package/dist/lib/daemon/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- package/dist/lib/doctor/checks/release-links.d.ts +50 -8
- package/dist/lib/doctor/checks/release-links.js +260 -24
- package/dist/lib/doctor/fix/apply.js +24 -8
- package/dist/lib/doctor/fix/remediation.js +15 -5
- package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
- package/dist/lib/lanes/autopilot-registry.js +59 -7
- package/dist/lib/lanes/links.d.ts +14 -0
- package/dist/lib/lanes/links.js +320 -25
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/main.js +3 -1
- package/dist/sentry-init.d.ts +2 -0
- package/dist/sentry-init.js +13 -2
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +5 -1
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- 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`). `
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `
|
|
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
|
|
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
|
|
73
|
+
const findings = [];
|
|
53
74
|
for (const entry of present) {
|
|
54
75
|
const problem = releaseLinkProblem(context.hqRoot, entry);
|
|
55
|
-
if (
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 (
|
|
66
|
-
return
|
|
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
|
|
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
|
-
|
|
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
|
-
/**
|
|
282
|
-
|
|
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
|
-
|
|
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:
|
|
1100
|
-
|
|
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
|
-
|
|
1126
|
-
|
|
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 {
|
|
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 + " " +
|
|
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
|
|
211
|
+
action,
|
|
202
212
|
command: "hq doctor --fix",
|
|
203
213
|
};
|
|
204
214
|
}
|
|
@@ -3,6 +3,10 @@ declare const OUTPOST_LEAD_REGISTRY_SCHEMA = "hq-lanes-outpost-lead-registry.v1"
|
|
|
3
3
|
export declare const LEAD_REGISTRY_REL: string;
|
|
4
4
|
export declare const OUTPOST_LEAD_REGISTRY_STATE_REL: string;
|
|
5
5
|
export declare const LEAD_AUTOPILOT_FLAG = "lanes.lead-autopilot";
|
|
6
|
+
/** First wait after a failed delivery to one Outpost; doubles per failure. */
|
|
7
|
+
export declare const LEAD_REGISTRY_RETRY_BASE_MS = 30000;
|
|
8
|
+
/** The wait between delivery attempts never grows past this. */
|
|
9
|
+
export declare const LEAD_REGISTRY_RETRY_MAX_MS: number;
|
|
6
10
|
export interface LeadRegistryRow {
|
|
7
11
|
team: string;
|
|
8
12
|
lane: string;
|
|
@@ -16,6 +20,12 @@ export interface OutpostLeadRegistry {
|
|
|
16
20
|
generated_at: string;
|
|
17
21
|
juniors: LeadRegistryRow[];
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Wait before the next delivery after `failures` consecutive failures:
|
|
25
|
+
* 30 s, 60 s, 2 min, ... capped at 30 min, then scaled by a jitter factor in
|
|
26
|
+
* [0.5, 1] so many machines do not retry in step.
|
|
27
|
+
*/
|
|
28
|
+
export declare function leadRegistryRetryDelayMs(failures: number, random?: () => number): number;
|
|
19
29
|
export declare function buildOutpostLeadRegistry(input: {
|
|
20
30
|
rows: readonly LeadRegistryRow[];
|
|
21
31
|
outpostId: string;
|
|
@@ -41,6 +51,8 @@ export declare function syncOutpostLeadRegistries(input: {
|
|
|
41
51
|
stdout: string;
|
|
42
52
|
stderr: string;
|
|
43
53
|
}>;
|
|
54
|
+
/** Jitter source for the retry backoff; tests pass a fixed value. */
|
|
55
|
+
random?: () => number;
|
|
44
56
|
}): Promise<Array<{
|
|
45
57
|
outpost_id: string;
|
|
46
58
|
row_count: number;
|
|
@@ -49,6 +61,8 @@ export declare function syncOutpostLeadRegistries(input: {
|
|
|
49
61
|
reason: string;
|
|
50
62
|
}>;
|
|
51
63
|
dispatched: boolean;
|
|
64
|
+
/** Set when an earlier failure holds this Outpost's delivery until then. */
|
|
65
|
+
retry_after?: string;
|
|
52
66
|
}>>;
|
|
53
67
|
export declare function validateOutpostLeadRegistry(input: {
|
|
54
68
|
registry: unknown;
|