@indigoai-us/hq-cli 5.345.232 → 5.345.234
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 +24 -0
- package/dist/command-catalog.generated.d.ts +4 -0
- package/dist/command-catalog.generated.js +5 -0
- package/dist/commands/core-handoff.d.ts +1 -0
- package/dist/commands/core-handoff.js +2 -28
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +24 -0
- package/dist/commands/install-global.js +10 -0
- package/dist/commands/mcp-serve-gate.d.ts +22 -0
- package/dist/commands/mcp-serve-gate.js +37 -0
- package/dist/commands/mcp-serve.js +2 -8
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +257 -214
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/daemon/flag.d.ts +2 -0
- package/dist/lib/daemon/flag.js +6 -4
- package/dist/lib/daemon/shared-flag-reads.d.ts +70 -0
- package/dist/lib/daemon/shared-flag-reads.js +173 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/coverage.js +50 -0
- package/dist/lib/windows/jq.d.ts +17 -0
- package/dist/lib/windows/jq.js +72 -0
- package/dist/utils/cognito-session.d.ts +2 -56
- package/dist/utils/cognito-session.js +6 -164
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +8 -15
|
@@ -1682,8 +1682,58 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
|
|
|
1682
1682
|
if (hold)
|
|
1683
1683
|
missing.push(`(native PreCompact compatibility: ${hold})`);
|
|
1684
1684
|
}
|
|
1685
|
+
if (host === 'grok' && GROK_STOP_OBSERVE.has(event) && covered.includes(`master-hook:${event}`)) {
|
|
1686
|
+
for (const hook of grokStopObserveUncovered(root, event, covers))
|
|
1687
|
+
if (!missing.includes(hook))
|
|
1688
|
+
missing.push(hook);
|
|
1689
|
+
}
|
|
1685
1690
|
return missing;
|
|
1686
1691
|
}
|
|
1692
|
+
/** Grok events the adapter dispatched as its settings.json `Stop` entries (lifecycle_master.rs `dispatched`). */
|
|
1693
|
+
const GROK_STOP_OBSERVE = new Set(['StopCancelled', 'StopFailure']);
|
|
1694
|
+
/**
|
|
1695
|
+
* The Stop hooks the old path ran on a Grok StopCancelled or StopFailure that
|
|
1696
|
+
* the claim does not cover, as lifecycle_master.rs `stop_observe_uncovered`
|
|
1697
|
+
* lists them for its guard: with master-hook among the settings.json Stop
|
|
1698
|
+
* entries, every Stop hook (registry rows, folders, other settings commands);
|
|
1699
|
+
* without it, only the other settings.json Stop commands. Covered are the
|
|
1700
|
+
* event's own claims, master-hook:Stop and grok-adapter:Stop, and the Stop
|
|
1701
|
+
* host-set claims for grok. Without this, reindex switches the event and the
|
|
1702
|
+
* native guard refuses every one (US-050 c7, O2 R1).
|
|
1703
|
+
*/
|
|
1704
|
+
function grokStopObserveUncovered(root, event, covers) {
|
|
1705
|
+
const stop = shellHooks(root, 'grok', 'Stop');
|
|
1706
|
+
if (!stop)
|
|
1707
|
+
return [UNREADABLE];
|
|
1708
|
+
let master = 0;
|
|
1709
|
+
try {
|
|
1710
|
+
const settings = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'settings.json'), 'utf8'));
|
|
1711
|
+
const groups = settings?.hooks?.Stop;
|
|
1712
|
+
for (const group of Array.isArray(groups) ? groups : []) {
|
|
1713
|
+
for (const entry of Array.isArray(group?.hooks) ? group.hooks : []) {
|
|
1714
|
+
const command = entry?.command;
|
|
1715
|
+
if (typeof command !== 'string' || !command.includes('master-hook.sh'))
|
|
1716
|
+
continue;
|
|
1717
|
+
master += 1;
|
|
1718
|
+
if (entry.args != null)
|
|
1719
|
+
master += 1;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
catch {
|
|
1724
|
+
return [UNREADABLE];
|
|
1725
|
+
}
|
|
1726
|
+
// Two master-hook entries, or the exec form: the native guard refuses.
|
|
1727
|
+
if (master > 1)
|
|
1728
|
+
return [`(native Grok ${event}: master-hook Stop entry not modelled)`];
|
|
1729
|
+
const listed = master === 1 ? stop : stop.filter((hook) => hook.startsWith('settings:'));
|
|
1730
|
+
const onHost = {};
|
|
1731
|
+
for (const [key, ids] of Object.entries(covers ?? {}))
|
|
1732
|
+
if (key.includes('@'))
|
|
1733
|
+
onHost[key] = ids;
|
|
1734
|
+
const covered = [...coveredOn(covers, event, 'grok'), 'master-hook:Stop', 'grok-adapter:Stop', ...coveredOn(onHost, 'Stop', 'grok')];
|
|
1735
|
+
return listed.filter((hook) => !covered.some((claim) => claimCovers(claim, hook)));
|
|
1736
|
+
}
|
|
1687
1737
|
/**
|
|
1688
1738
|
* `target` narrowed to the events it covers in full on `host` in this HQ
|
|
1689
1739
|
* root; null when none is covered (every event stays on the old dispatcher),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const WINDOWS_JQ_REPAIR = "hq doctor --fix-jq";
|
|
2
|
+
interface JqAsset {
|
|
3
|
+
name: string;
|
|
4
|
+
sha256: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function windowsJqPath(home?: string): string;
|
|
7
|
+
interface InstallOptions {
|
|
8
|
+
platform?: NodeJS.Platform;
|
|
9
|
+
arch?: NodeJS.Architecture;
|
|
10
|
+
home?: string;
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
asset?: JqAsset;
|
|
13
|
+
}
|
|
14
|
+
/** The npm lifecycle, global hook setup and doctor use the same Windows installer. */
|
|
15
|
+
export declare function installWindowsJq({ platform, arch, home, fetch: download, asset, }?: InstallOptions): Promise<string | undefined>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=jq.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { mkdir, mkdtemp, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
const version = "1.8.2";
|
|
7
|
+
const release = `https://github.com/jqlang/jq/releases/download/jq-${version}`;
|
|
8
|
+
export const WINDOWS_JQ_REPAIR = "hq doctor --fix-jq";
|
|
9
|
+
// https://github.com/jqlang/jq/releases/tag/jq-1.8.2
|
|
10
|
+
const assets = {
|
|
11
|
+
x64: {
|
|
12
|
+
name: "jq-windows-amd64.exe",
|
|
13
|
+
sha256: "a6fc67fedaf9128a3309a1e2ebb8b986aeccf70122ee46d2cb4849e423f0c627",
|
|
14
|
+
},
|
|
15
|
+
arm64: {
|
|
16
|
+
name: "jq-windows-arm64.exe",
|
|
17
|
+
sha256: "083b5377392bc57cf27052b6d20a2d927770683bca844632901ff38b4b7b0ac7",
|
|
18
|
+
},
|
|
19
|
+
ia32: {
|
|
20
|
+
name: "jq-windows-i386.exe",
|
|
21
|
+
sha256: "a99cb668f95bdd788d9ee20529613b115e5d2a0d7f9127ee6976607e878558ba",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export function windowsJqPath(home = homedir()) {
|
|
25
|
+
// hq-core-staging #2047 adds this directory to hook PATH when it holds jq.exe.
|
|
26
|
+
return join(home, ".local", "bin", "jq.exe");
|
|
27
|
+
}
|
|
28
|
+
function digest(bytes) {
|
|
29
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
30
|
+
}
|
|
31
|
+
function matchesAsset(file, asset) {
|
|
32
|
+
try {
|
|
33
|
+
return digest(readFileSync(file)) === asset.sha256;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === "ENOENT")
|
|
37
|
+
return false;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** The npm lifecycle, global hook setup and doctor use the same Windows installer. */
|
|
42
|
+
export async function installWindowsJq({ platform = process.platform, arch = process.arch, home, fetch: download = fetch, asset = assets[arch], } = {}) {
|
|
43
|
+
if (platform !== "win32")
|
|
44
|
+
return undefined;
|
|
45
|
+
if (!asset)
|
|
46
|
+
throw new Error(`jq has no official Windows build for ${arch}.`);
|
|
47
|
+
const target = windowsJqPath(home);
|
|
48
|
+
if (matchesAsset(target, asset))
|
|
49
|
+
return target;
|
|
50
|
+
const response = await download(`${release}/${asset.name}`, {
|
|
51
|
+
signal: AbortSignal.timeout(20_000),
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok)
|
|
54
|
+
throw new Error(`jq download failed (HTTP ${response.status}).`);
|
|
55
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
56
|
+
if (digest(bytes) !== asset.sha256) {
|
|
57
|
+
throw new Error(`The SHA-256 of ${asset.name} did not match the pinned release checksum.`);
|
|
58
|
+
}
|
|
59
|
+
const dir = dirname(target);
|
|
60
|
+
await mkdir(dir, { recursive: true });
|
|
61
|
+
const staged = await mkdtemp(join(dir, ".hq-jq-"));
|
|
62
|
+
try {
|
|
63
|
+
const file = join(staged, "jq.exe");
|
|
64
|
+
await writeFile(file, bytes, { flag: "wx", mode: 0o755 });
|
|
65
|
+
await rename(file, target);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await rm(staged, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=jq.js.map
|
|
@@ -22,6 +22,7 @@ import { isExpiring, isMachineIdentity, type CognitoAuthConfig, type CognitoToke
|
|
|
22
22
|
import { hasPersonCachedSession, isMachineCredsFileEnvSet, wantsMachineCognitoTokens, type CognitoTokenSource } from "./machine-principal-state.js";
|
|
23
23
|
import { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir } from "./machine-token-cache.js";
|
|
24
24
|
export { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir };
|
|
25
|
+
import { resolveDefaultHqRoot } from "./hq-root-resolver.js";
|
|
25
26
|
import { HQ_NO_BROWSER_LOGIN_ENV, type InteractiveCallerInput } from "./interactive-caller.js";
|
|
26
27
|
import { loadCachedTokens, personTokenCacheFile, readPersonTokenFile } from "./person-token-cache.js";
|
|
27
28
|
export { loadCachedTokens, personTokenCacheFile, readPersonTokenFile };
|
|
@@ -37,62 +38,7 @@ export type CognitoActorKind = "human" | "agent" | "unknown";
|
|
|
37
38
|
*/
|
|
38
39
|
export declare const DEFAULT_COGNITO: CognitoAuthConfig;
|
|
39
40
|
export declare const DEFAULT_VAULT_API_URL: string;
|
|
40
|
-
|
|
41
|
-
* Resolve the HQ tree root for cloud-aware subcommands (`hq sync`, `hq onboard`,
|
|
42
|
-
* `hq cloud …`, etc.).
|
|
43
|
-
*
|
|
44
|
-
* Resolution order — mirrors the menubar/installer resolver
|
|
45
|
-
* (`hq-sync` `util/paths.rs::resolve_hq_folder`) so the CLI targets the SAME
|
|
46
|
-
* root the AppBar syncs, regardless of cwd:
|
|
47
|
-
* 1. `$HQ_ROOT` env var — explicit assertion by the caller; short-circuits all.
|
|
48
|
-
* 2. Walk up from `process.cwd()` to the nearest HQ root (working-tree wins:
|
|
49
|
-
* if you're inside an HQ tree, operate on THAT tree). See {@link isHqRoot}.
|
|
50
|
-
* 3. `~/.hq/menubar.json` → `hqPath` — the canonical record written by the
|
|
51
|
-
* installer (≥0.1.28) and the menubar's Settings re-tether. Same field HQ
|
|
52
|
-
* Sync reads first.
|
|
53
|
-
* 4. `~/.hq/config.json` → `hqFolderPath` — legacy installer record.
|
|
54
|
-
* 5. Discovery: scan well-known locations (`~/HQ`, `~/hq`, `~/Documents/HQ`,
|
|
55
|
-
* …) for a folder carrying a valid `core.yaml` signature. Safety net for
|
|
56
|
-
* installs that never wrote the path back to menubar.json.
|
|
57
|
-
* 6. Fall back to `~/hq` (`C:\hq` on Windows) — or throw, per
|
|
58
|
-
* `opts.onMissing`.
|
|
59
|
-
*
|
|
60
|
-
* Why tiers 3–5 exist:
|
|
61
|
-
* Before this, the CLI only knew `$HQ_ROOT` and the cwd walk-up. Run from any
|
|
62
|
-
* cwd OUTSIDE the HQ tree with `$HQ_ROOT` unset, it fell straight to `~/hq` —
|
|
63
|
-
* so a user whose HQ lives anywhere else (e.g. `~/Desktop/HQ`, as the AppBar
|
|
64
|
-
* syncs it) silently got a brand-new `~/hq` stub and a full re-sync into it
|
|
65
|
-
* (split-brain). Reading the installer/menubar records the way HQ Sync does
|
|
66
|
-
* closes that gap (feedback_3967e294).
|
|
67
|
-
*
|
|
68
|
-
* Why both markers in the walk-up (tier 2)?
|
|
69
|
-
* An HQ root has a `core.yaml` (canonical `core/core.yaml` since hq-core v14,
|
|
70
|
-
* legacy `<root>/core.yaml` before) AND a sibling `companies/` directory. The
|
|
71
|
-
* synced `core/` subtree ALSO contains a `core.yaml` (the template version
|
|
72
|
-
* source-of-truth) but NO `companies/`. Requiring `companies/` as well stops
|
|
73
|
-
* the walk from latching onto `<hqRoot>/core/` (Codex P2 on hq#146).
|
|
74
|
-
*
|
|
75
|
-
* `opts.onMissing` controls the final arm:
|
|
76
|
-
* - `'fallback'` (default) — return `~/hq` (`C:\hq` on Windows) if nothing resolves. Preserves the
|
|
77
|
-
* module-load contract of `DEFAULT_HQ_ROOT`, pinned by commander.js
|
|
78
|
-
* `.option()` callers at registration time.
|
|
79
|
-
* - `'throw'` — throw a user-actionable error. Used by module-management
|
|
80
|
-
* commands (pkg-*, team-sync) where a silent default-path miss would
|
|
81
|
-
* target the wrong directory.
|
|
82
|
-
*
|
|
83
|
-
* Evaluated once at module load for `DEFAULT_HQ_ROOT`; the installer/menubar
|
|
84
|
-
* records and cwd are both fixed at process start, so a one-shot read is sound.
|
|
85
|
-
* Re-importable as a function for command-time resolution and tests.
|
|
86
|
-
*/
|
|
87
|
-
export declare function resolveDefaultHqRoot(opts?: {
|
|
88
|
-
onMissing?: "throw" | "fallback";
|
|
89
|
-
/** Defaults to process.env, process.cwd() and os.homedir(). */
|
|
90
|
-
env?: NodeJS.ProcessEnv;
|
|
91
|
-
cwd?: string;
|
|
92
|
-
home?: string;
|
|
93
|
-
/** Defaults to process.platform; injectable so tests can exercise win32. */
|
|
94
|
-
platform?: NodeJS.Platform;
|
|
95
|
-
}): string;
|
|
41
|
+
export { resolveDefaultHqRoot };
|
|
96
42
|
export declare const DEFAULT_HQ_ROOT: string;
|
|
97
43
|
/** Default machine-creds path hq-cloud also checks when the env is unset. */
|
|
98
44
|
export declare function defaultMachineCredsFile(home?: string): string;
|
|
@@ -23,14 +23,13 @@ import { randomBytes } from "node:crypto";
|
|
|
23
23
|
import * as fs from "fs";
|
|
24
24
|
import * as os from "os";
|
|
25
25
|
import * as path from "path";
|
|
26
|
-
import * as yaml from "js-yaml";
|
|
27
26
|
import chalk from "chalk";
|
|
28
27
|
import { isExpiring, refreshTokens, saveCachedTokens, browserLogin, detectHqCoreVersion, isMachineIdentity, getValidMachineTokens, CognitoRefreshError, accessTokenFingerprint, invalidateCachedTokensByFingerprint, } from "@indigoai-us/hq-cloud";
|
|
29
28
|
import { hasPersonCachedSession, isMachineCredsFileEnvSet, probeMachineIdentity, wantsMachineCognitoTokens, } from "./machine-principal-state.js";
|
|
30
29
|
import { CLI_NAME, CLI_VERSION } from "../cli-version.js";
|
|
31
30
|
import { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir, } from "./machine-token-cache.js";
|
|
32
31
|
export { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir };
|
|
33
|
-
import {
|
|
32
|
+
import { resolveDefaultHqRoot } from "./hq-root-resolver.js";
|
|
34
33
|
import { acquireLockFileExclusively } from "./exclusive-lock.js";
|
|
35
34
|
import { interactiveLoginConfig, resolveCognitoCallbackPort } from "./cognito-callback-port.js";
|
|
36
35
|
import { HQ_NO_BROWSER_LOGIN_ENV, NON_INTERACTIVE_LOGIN_MESSAGE, isInteractiveCaller, } from "./interactive-caller.js";
|
|
@@ -66,168 +65,11 @@ export const DEFAULT_COGNITO = {
|
|
|
66
65
|
: "Google",
|
|
67
66
|
};
|
|
68
67
|
export const DEFAULT_VAULT_API_URL = process.env.HQ_VAULT_API_URL ?? "https://hqapi.hq.computer";
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* (`hq-sync` `util/paths.rs::resolve_hq_folder`) so the CLI targets the SAME
|
|
75
|
-
* root the AppBar syncs, regardless of cwd:
|
|
76
|
-
* 1. `$HQ_ROOT` env var — explicit assertion by the caller; short-circuits all.
|
|
77
|
-
* 2. Walk up from `process.cwd()` to the nearest HQ root (working-tree wins:
|
|
78
|
-
* if you're inside an HQ tree, operate on THAT tree). See {@link isHqRoot}.
|
|
79
|
-
* 3. `~/.hq/menubar.json` → `hqPath` — the canonical record written by the
|
|
80
|
-
* installer (≥0.1.28) and the menubar's Settings re-tether. Same field HQ
|
|
81
|
-
* Sync reads first.
|
|
82
|
-
* 4. `~/.hq/config.json` → `hqFolderPath` — legacy installer record.
|
|
83
|
-
* 5. Discovery: scan well-known locations (`~/HQ`, `~/hq`, `~/Documents/HQ`,
|
|
84
|
-
* …) for a folder carrying a valid `core.yaml` signature. Safety net for
|
|
85
|
-
* installs that never wrote the path back to menubar.json.
|
|
86
|
-
* 6. Fall back to `~/hq` (`C:\hq` on Windows) — or throw, per
|
|
87
|
-
* `opts.onMissing`.
|
|
88
|
-
*
|
|
89
|
-
* Why tiers 3–5 exist:
|
|
90
|
-
* Before this, the CLI only knew `$HQ_ROOT` and the cwd walk-up. Run from any
|
|
91
|
-
* cwd OUTSIDE the HQ tree with `$HQ_ROOT` unset, it fell straight to `~/hq` —
|
|
92
|
-
* so a user whose HQ lives anywhere else (e.g. `~/Desktop/HQ`, as the AppBar
|
|
93
|
-
* syncs it) silently got a brand-new `~/hq` stub and a full re-sync into it
|
|
94
|
-
* (split-brain). Reading the installer/menubar records the way HQ Sync does
|
|
95
|
-
* closes that gap (feedback_3967e294).
|
|
96
|
-
*
|
|
97
|
-
* Why both markers in the walk-up (tier 2)?
|
|
98
|
-
* An HQ root has a `core.yaml` (canonical `core/core.yaml` since hq-core v14,
|
|
99
|
-
* legacy `<root>/core.yaml` before) AND a sibling `companies/` directory. The
|
|
100
|
-
* synced `core/` subtree ALSO contains a `core.yaml` (the template version
|
|
101
|
-
* source-of-truth) but NO `companies/`. Requiring `companies/` as well stops
|
|
102
|
-
* the walk from latching onto `<hqRoot>/core/` (Codex P2 on hq#146).
|
|
103
|
-
*
|
|
104
|
-
* `opts.onMissing` controls the final arm:
|
|
105
|
-
* - `'fallback'` (default) — return `~/hq` (`C:\hq` on Windows) if nothing resolves. Preserves the
|
|
106
|
-
* module-load contract of `DEFAULT_HQ_ROOT`, pinned by commander.js
|
|
107
|
-
* `.option()` callers at registration time.
|
|
108
|
-
* - `'throw'` — throw a user-actionable error. Used by module-management
|
|
109
|
-
* commands (pkg-*, team-sync) where a silent default-path miss would
|
|
110
|
-
* target the wrong directory.
|
|
111
|
-
*
|
|
112
|
-
* Evaluated once at module load for `DEFAULT_HQ_ROOT`; the installer/menubar
|
|
113
|
-
* records and cwd are both fixed at process start, so a one-shot read is sound.
|
|
114
|
-
* Re-importable as a function for command-time resolution and tests.
|
|
115
|
-
*/
|
|
116
|
-
export function resolveDefaultHqRoot(opts = {}) {
|
|
117
|
-
const env = opts.env ?? process.env;
|
|
118
|
-
const home = opts.home ?? os.homedir();
|
|
119
|
-
const platform = opts.platform ?? process.platform;
|
|
120
|
-
const p = pathForPlatform(platform);
|
|
121
|
-
// Tier 1: explicit override.
|
|
122
|
-
if (env.HQ_ROOT)
|
|
123
|
-
return p.resolve(env.HQ_ROOT);
|
|
124
|
-
// Tier 2: working-tree walk-up — operate on the HQ tree you're inside.
|
|
125
|
-
let cur = p.resolve(opts.cwd ?? process.cwd());
|
|
126
|
-
while (cur !== p.dirname(cur)) {
|
|
127
|
-
if (isHqRoot(cur, p))
|
|
128
|
-
return cur;
|
|
129
|
-
cur = p.dirname(cur);
|
|
130
|
-
}
|
|
131
|
-
// Tiers 3–4: the installer/menubar's canonical "where is HQ" records.
|
|
132
|
-
const fromConfig = readHqRootFromHqConfig(p.join(home, ".hq"), p);
|
|
133
|
-
if (fromConfig)
|
|
134
|
-
return p.resolve(fromConfig);
|
|
135
|
-
// Tier 5: discover a valid HQ root in the well-known locations (on Windows
|
|
136
|
-
// the home-relative ones first, then %SystemDrive%\hq and %LOCALAPPDATA%\hq).
|
|
137
|
-
const discovered = hqDiscoveryCandidates({ platform, env, home }).find((dir) => isValidHqRootSignature(dir, p));
|
|
138
|
-
if (discovered)
|
|
139
|
-
return discovered;
|
|
140
|
-
// Tier 6: nothing resolved. Fallback is ~/hq, or %SystemDrive%\hq on Windows.
|
|
141
|
-
if (opts.onMissing === "throw") {
|
|
142
|
-
throw new Error("Could not find HQ root. Run this command from within your HQ directory " +
|
|
143
|
-
"(must contain core.yaml AND a companies/ subdirectory), set $HQ_ROOT, " +
|
|
144
|
-
"or install HQ via the installer/menubar so ~/.hq/menubar.json records " +
|
|
145
|
-
"its location.");
|
|
146
|
-
}
|
|
147
|
-
return defaultHqRootFallback({ platform, env, home });
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Read the configured HQ root from the installer/menubar records under
|
|
151
|
-
* `hqConfigDir` (`~/.hq`). Mirrors HQ Sync's precedence:
|
|
152
|
-
* 1. `menubar.json` → `hqPath` (canonical; written by installer ≥0.1.28 and
|
|
153
|
-
* the menubar Settings re-tether)
|
|
154
|
-
* 2. `config.json` → `hqFolderPath` (legacy installer flows)
|
|
155
|
-
* Returns the first non-empty string, or undefined. Best-effort: a missing or
|
|
156
|
-
* malformed file is treated as "not configured" (never throws).
|
|
157
|
-
*/
|
|
158
|
-
function readHqRootFromHqConfig(hqConfigDir, p = path) {
|
|
159
|
-
const fromMenubar = readJsonStringField(p.join(hqConfigDir, "menubar.json"), "hqPath");
|
|
160
|
-
if (fromMenubar)
|
|
161
|
-
return fromMenubar;
|
|
162
|
-
return readJsonStringField(p.join(hqConfigDir, "config.json"), "hqFolderPath");
|
|
163
|
-
}
|
|
164
|
-
/** Read a top-level string field from a JSON file, or undefined on any miss. */
|
|
165
|
-
function readJsonStringField(file, field) {
|
|
166
|
-
try {
|
|
167
|
-
const parsed = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
168
|
-
const value = parsed[field];
|
|
169
|
-
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
return undefined;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* True iff `dir` carries a valid hq-core `core.yaml` — canonical
|
|
177
|
-
* (`<dir>/core/core.yaml`, hq-core ≥v14) or legacy (`<dir>/core.yaml`) — that
|
|
178
|
-
* parses as YAML and has BOTH the `version` and `hqVersion` fields. The dual
|
|
179
|
-
* field check (matching hq-sync's `is_valid_hq_root`) stops a stray `core.yaml`
|
|
180
|
-
* from another tool from false-matching.
|
|
181
|
-
*/
|
|
182
|
-
function isValidHqRootSignature(dir, p = path) {
|
|
183
|
-
const canonical = p.join(dir, "core", "core.yaml");
|
|
184
|
-
const legacy = p.join(dir, "core.yaml");
|
|
185
|
-
let file;
|
|
186
|
-
if (fileExists(canonical))
|
|
187
|
-
file = canonical;
|
|
188
|
-
else if (fileExists(legacy))
|
|
189
|
-
file = legacy;
|
|
190
|
-
else
|
|
191
|
-
return false;
|
|
192
|
-
try {
|
|
193
|
-
const parsed = yaml.load(fs.readFileSync(file, "utf-8"));
|
|
194
|
-
return (!!parsed &&
|
|
195
|
-
typeof parsed === "object" &&
|
|
196
|
-
"version" in parsed &&
|
|
197
|
-
"hqVersion" in parsed);
|
|
198
|
-
}
|
|
199
|
-
catch {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/** True iff `p` exists and is a regular file. */
|
|
204
|
-
function fileExists(p) {
|
|
205
|
-
try {
|
|
206
|
-
return fs.statSync(p).isFile();
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* True iff `dir` is an HQ root for the cwd walk-up: it has a `core.yaml`
|
|
214
|
-
* (canonical `core/core.yaml` since hq-core v14, or legacy `<dir>/core.yaml`)
|
|
215
|
-
* AND a sibling `companies/` directory. The `companies/` discriminator keeps
|
|
216
|
-
* the walk from latching onto the inner `core/` subtree, which carries its own
|
|
217
|
-
* `core.yaml` but no `companies/`.
|
|
218
|
-
*/
|
|
219
|
-
function isHqRoot(dir, p = path) {
|
|
220
|
-
const hasCoreYaml = fileExists(p.join(dir, "core", "core.yaml")) ||
|
|
221
|
-
fileExists(p.join(dir, "core.yaml"));
|
|
222
|
-
if (!hasCoreYaml)
|
|
223
|
-
return false;
|
|
224
|
-
try {
|
|
225
|
-
return fs.statSync(p.join(dir, "companies")).isDirectory();
|
|
226
|
-
}
|
|
227
|
-
catch {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
68
|
+
// HQ-root resolution (HQ_ROOT, cwd walk with the core.yaml + companies/
|
|
69
|
+
// check, installer records, known locations, then ~/hq or a throw) has one
|
|
70
|
+
// implementation, in hq-root-resolver.ts (US-030 c2). Re-exported here for
|
|
71
|
+
// the callers that import it from this module.
|
|
72
|
+
export { resolveDefaultHqRoot };
|
|
231
73
|
export const DEFAULT_HQ_ROOT = resolveDefaultHqRoot();
|
|
232
74
|
/** Default machine-creds path hq-cloud also checks when the env is unset. */
|
|
233
75
|
export function defaultMachineCredsFile(home = os.homedir()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.234",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@aws-sdk/client-iot-data-plane": "^3.1096.0",
|
|
64
64
|
"@aws-sdk/client-s3": "^3.1049.0",
|
|
65
65
|
"@aws-sdk/dsql-signer": "^3.1146.0",
|
|
66
|
-
"@indigoai-us/hq-cloud": "6.18.
|
|
66
|
+
"@indigoai-us/hq-cloud": "6.18.114",
|
|
67
67
|
"@indigoai-us/hq-flags-client": "^0.2.0",
|
|
68
68
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
69
69
|
"@sentry/node": "^10.49.0",
|
|
@@ -126,11 +126,11 @@
|
|
|
126
126
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
127
127
|
},
|
|
128
128
|
"optionalDependencies": {
|
|
129
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
129
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.234",
|
|
130
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.234",
|
|
131
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.234",
|
|
132
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.234",
|
|
133
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.234",
|
|
134
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.234"
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -24,20 +24,13 @@ try {
|
|
|
24
24
|
} catch (error) {
|
|
25
25
|
console.warn(`HQ PowerShell launcher cleanup skipped: ${error instanceof Error ? error.message : String(error)}. If PowerShell blocks hq, run hq.cmd doctor --fix.`);
|
|
26
26
|
}
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const dirs = (process.env.PATH ?? '').split(';').map(dir => dir.trim().replace(/^"(.*)"$/, '$1')).filter(Boolean);
|
|
36
|
-
// Git Bash runs the hooks: it can run jq.exe but not a jq.cmd or jq.bat.
|
|
37
|
-
if (!dirs.some(dir => existsSync(join(dir, 'jq.exe')))) {
|
|
38
|
-
console.warn('jq not found on PATH. Install jq (Windows: winget install jqlang.jq) and open a new terminal; HQ hooks block tool calls until jq is on PATH.');
|
|
39
|
-
}
|
|
27
|
+
// The CLI stays available for repair if the download fails. The hook's
|
|
28
|
+
// existing refusal still applies whenever it cannot find jq.
|
|
29
|
+
if (process.platform === 'win32') {
|
|
30
|
+
try {
|
|
31
|
+
const { installWindowsJq } = await import('../dist/lib/windows/jq.js');
|
|
32
|
+
await installWindowsJq();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.warn(`HQ could not install jq: ${error instanceof Error ? error.message : String(error)}. Repair: hq doctor --fix-jq.`);
|
|
40
35
|
}
|
|
41
|
-
} catch {
|
|
42
|
-
// A PATH scan failure must not fail the install.
|
|
43
36
|
}
|