@indigoai-us/hq-cli 5.345.232 → 5.345.233
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 +17 -0
- package/dist/commands/core-handoff.d.ts +1 -0
- package/dist/commands/core-handoff.js +2 -28
- 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/utils/cognito-session.d.ts +2 -56
- package/dist/utils/cognito-session.js +6 -164
- package/package.json +8 -8
|
@@ -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.233",
|
|
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.233",
|
|
130
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.233",
|
|
131
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.233",
|
|
132
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.233",
|
|
133
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.233",
|
|
134
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.233"
|
|
135
135
|
}
|
|
136
136
|
}
|