@indigoai-us/hq-cli 5.25.0 → 5.25.1
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/.github/workflows/publish.yml +21 -1
- package/dist/commands/pkg-install.js +4 -4
- package/dist/commands/pkg-list.js +4 -4
- package/dist/commands/pkg-remove.js +4 -4
- package/dist/commands/pkg-update.js +4 -4
- package/dist/commands/team-sync.js +4 -4
- package/dist/index.js +11 -2
- package/dist/utils/cognito-session.d.ts +22 -1
- package/dist/utils/cognito-session.js +26 -3
- package/dist/utils/integrity.js +4 -4
- package/dist/utils/registry-client.js +4 -4
- package/dist/utils/version-gate.d.ts +64 -0
- package/dist/utils/version-gate.js +185 -0
- package/package.json +1 -1
- package/src/commands/pkg-install.ts +2 -2
- package/src/commands/pkg-list.ts +2 -2
- package/src/commands/pkg-remove.ts +2 -2
- package/src/commands/pkg-update.ts +2 -2
- package/src/commands/team-sync.ts +2 -2
- package/src/index.ts +12 -0
- package/src/utils/cognito-session.test.ts +56 -1
- package/src/utils/cognito-session.ts +28 -1
- package/src/utils/integrity.ts +2 -2
- package/src/utils/registry-client.ts +2 -2
- package/src/utils/version-gate.test.ts +245 -0
- package/src/utils/version-gate.ts +219 -0
- package/dist/utils/hq-root.d.ts +0 -10
- package/dist/utils/hq-root.js +0 -25
- package/src/utils/hq-root.ts +0 -27
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hard version-gate: ask hq-pro whether the current CLI is below the minimum
|
|
3
|
+
* acceptable version and, if so, run `npm install -g …@latest` synchronously
|
|
4
|
+
* before any commander parsing happens. Distinct from the existing
|
|
5
|
+
* `version-check.ts` which is a passive (cached, opt-in) stderr nag against
|
|
6
|
+
* the npm registry.
|
|
7
|
+
*
|
|
8
|
+
* Why both?
|
|
9
|
+
* - `version-check.ts` answers "is there something newer?" by polling npm
|
|
10
|
+
* directly. It's a soft hint, lives on a 24h cache, and never blocks.
|
|
11
|
+
* - `version-gate.ts` answers "is the team currently allowing your version
|
|
12
|
+
* to run?" via an authoritative hq-pro endpoint. The server can yank a
|
|
13
|
+
* known-bad release without waiting for the npm `latest` dist-tag move.
|
|
14
|
+
*
|
|
15
|
+
* The endpoint is reusable across clients (hq-sync, hq-installer, create-hq).
|
|
16
|
+
* See `apps/hq-pro/src/vault-service/handlers/client-version-check.ts` for the
|
|
17
|
+
* source-of-truth table.
|
|
18
|
+
*
|
|
19
|
+
* Trust model: anonymous. The CLI may be running pre-login (e.g. fresh
|
|
20
|
+
* install) so we never send credentials. The endpoint identifies the client
|
|
21
|
+
* by `clientId` + `currentVersion`.
|
|
22
|
+
*
|
|
23
|
+
* Failure mode: silent. Network down, hq-pro returning 5xx, malformed body —
|
|
24
|
+
* the gate must never break the CLI for a user who's otherwise fine. We log
|
|
25
|
+
* to Sentry as a breadcrumb (best-effort) and return.
|
|
26
|
+
*
|
|
27
|
+
* Opt-out: `HQ_NO_UPDATE_CHECK=1` (same env as `version-check.ts` — one knob
|
|
28
|
+
* to silence both check + gate).
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { spawnSync } from "node:child_process";
|
|
32
|
+
import chalk from "chalk";
|
|
33
|
+
import { CLI_VERSION } from "../cli-version.js";
|
|
34
|
+
import { DEFAULT_VAULT_API_URL } from "./cognito-session.js";
|
|
35
|
+
|
|
36
|
+
const CLIENT_ID = "hq-cli";
|
|
37
|
+
const ENDPOINT_PATH = "/v1/client-version/check";
|
|
38
|
+
const FETCH_TIMEOUT_MS = 3_000;
|
|
39
|
+
|
|
40
|
+
interface VersionCheckResponse {
|
|
41
|
+
clientId: string;
|
|
42
|
+
currentVersion: string;
|
|
43
|
+
minVersion: string;
|
|
44
|
+
latestVersion: string;
|
|
45
|
+
updateRequired: boolean;
|
|
46
|
+
updateRecommended: boolean;
|
|
47
|
+
updateCommand?: string;
|
|
48
|
+
downloadUrl?: string;
|
|
49
|
+
message?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isOptedOut(): boolean {
|
|
53
|
+
return process.env.HQ_NO_UPDATE_CHECK === "1";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Hit POST /v1/client-version/check. Returns the parsed body on 200, or
|
|
58
|
+
* `null` on any failure (caller treats as "no gate"). Tight 3s timeout —
|
|
59
|
+
* a hung server must not delay CLI startup.
|
|
60
|
+
*/
|
|
61
|
+
async function fetchVersionDecision(): Promise<VersionCheckResponse | null> {
|
|
62
|
+
try {
|
|
63
|
+
const url = `${DEFAULT_VAULT_API_URL}${ENDPOINT_PATH}`;
|
|
64
|
+
const res = await fetch(url, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
Accept: "application/json",
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
clientId: CLIENT_ID,
|
|
72
|
+
currentVersion: CLI_VERSION,
|
|
73
|
+
platform: `${process.platform}-${process.arch}`,
|
|
74
|
+
}),
|
|
75
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok) return null;
|
|
78
|
+
const body = (await res.json()) as Partial<VersionCheckResponse>;
|
|
79
|
+
if (
|
|
80
|
+
typeof body.minVersion !== "string" ||
|
|
81
|
+
typeof body.latestVersion !== "string" ||
|
|
82
|
+
typeof body.updateRequired !== "boolean"
|
|
83
|
+
) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return body as VersionCheckResponse;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Run the upgrade command in a blocking subprocess. Inherits stdio so the
|
|
94
|
+
* user sees the npm progress. We do NOT auto-rerun the CLI on completion —
|
|
95
|
+
* forcing a re-invocation would run twice on the same process and feel
|
|
96
|
+
* janky; instead we print a clear "rerun your command" message and exit.
|
|
97
|
+
*/
|
|
98
|
+
function performUpdate(
|
|
99
|
+
command: string,
|
|
100
|
+
): { ok: boolean; detail?: string } {
|
|
101
|
+
const parts = command.split(/\s+/).filter(Boolean);
|
|
102
|
+
if (parts.length === 0) return { ok: false, detail: "empty command" };
|
|
103
|
+
const cmd = parts[0]!;
|
|
104
|
+
const args = parts.slice(1);
|
|
105
|
+
try {
|
|
106
|
+
const result = spawnSync(cmd, args, { stdio: "inherit" });
|
|
107
|
+
if (result.status !== 0) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
detail: `exit ${result.status ?? "signal"}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return { ok: true };
|
|
114
|
+
} catch (err) {
|
|
115
|
+
return { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Soft notify when the server says we're below `latestVersion` but still ≥
|
|
121
|
+
* `minVersion`. Single chalk-yellow line on stderr; never blocks.
|
|
122
|
+
*/
|
|
123
|
+
function nudgeUpdateRecommended(decision: VersionCheckResponse): void {
|
|
124
|
+
const msg = chalk.yellow(
|
|
125
|
+
`⚠ A new version of hq-cli is available: ${decision.latestVersion} (current: ${decision.currentVersion}).`,
|
|
126
|
+
);
|
|
127
|
+
console.error(msg);
|
|
128
|
+
if (decision.updateCommand) {
|
|
129
|
+
console.error(chalk.dim(` Update: ${decision.updateCommand}`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Hard enforcement when the server says we're below `minVersion`. Print a
|
|
135
|
+
* red banner, attempt the update, then exit so the user reruns against the
|
|
136
|
+
* fresh binary. Sequence chosen so a user with a broken `npm` global prefix
|
|
137
|
+
* still gets a clear error rather than an opaque silent failure.
|
|
138
|
+
*
|
|
139
|
+
* Exit codes:
|
|
140
|
+
* 0 — update succeeded; user must rerun their command
|
|
141
|
+
* 75 — update failed (EX_TEMPFAIL; common for sudo/EACCES on system npm)
|
|
142
|
+
*/
|
|
143
|
+
function enforceUpdateRequired(decision: VersionCheckResponse): never {
|
|
144
|
+
const banner = chalk.red.bold(
|
|
145
|
+
`✗ hq-cli ${decision.currentVersion} is below the minimum required version (${decision.minVersion}).`,
|
|
146
|
+
);
|
|
147
|
+
console.error(banner);
|
|
148
|
+
if (decision.message) console.error(chalk.dim(` ${decision.message}`));
|
|
149
|
+
|
|
150
|
+
const command = decision.updateCommand;
|
|
151
|
+
if (!command) {
|
|
152
|
+
console.error(
|
|
153
|
+
chalk.red(
|
|
154
|
+
" No updateCommand provided by hq-pro — see https://hq.indigo.ai/docs/cli-update for manual steps.",
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
if (decision.downloadUrl) {
|
|
158
|
+
console.error(chalk.dim(` Download: ${decision.downloadUrl}`));
|
|
159
|
+
}
|
|
160
|
+
process.exit(75);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
console.error(chalk.dim(` Running: ${command}`));
|
|
164
|
+
const result = performUpdate(command);
|
|
165
|
+
if (!result.ok) {
|
|
166
|
+
console.error(
|
|
167
|
+
chalk.red(`✗ Update failed${result.detail ? `: ${result.detail}` : ""}.`),
|
|
168
|
+
);
|
|
169
|
+
console.error(chalk.dim(` Try manually: ${command}`));
|
|
170
|
+
process.exit(75);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
console.error(
|
|
174
|
+
chalk.green(
|
|
175
|
+
`✓ Updated to hq-cli ${decision.latestVersion}. Rerun your command.`,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
process.exit(0);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Public entry point. Call before commander parses argv. Blocks the CLI on
|
|
183
|
+
* network IO for up to FETCH_TIMEOUT_MS — acceptable because the alternative
|
|
184
|
+
* (a fire-and-forget background check) gives the user no chance to bail out
|
|
185
|
+
* of a known-bad version before it does damage.
|
|
186
|
+
*
|
|
187
|
+
* `--version` / `-v` callers MUST skip the gate (the user is debugging a
|
|
188
|
+
* broken install and shouldn't be force-upgraded mid-investigation). Caller
|
|
189
|
+
* is responsible for checking argv before invoking us — see index.ts.
|
|
190
|
+
*/
|
|
191
|
+
export async function enforceVersionGate(): Promise<void> {
|
|
192
|
+
if (isOptedOut()) return;
|
|
193
|
+
const decision = await fetchVersionDecision();
|
|
194
|
+
if (!decision) return; // best-effort: silent on any failure
|
|
195
|
+
if (decision.updateRequired) {
|
|
196
|
+
enforceUpdateRequired(decision); // exits process
|
|
197
|
+
}
|
|
198
|
+
if (decision.updateRecommended) {
|
|
199
|
+
nudgeUpdateRecommended(decision);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Cheap argv pre-check: skip the gate for `--version` / `-V` so users
|
|
205
|
+
* inspecting a broken install can still see what they have without being
|
|
206
|
+
* force-upgraded.
|
|
207
|
+
*/
|
|
208
|
+
export function shouldSkipGate(argv: readonly string[]): boolean {
|
|
209
|
+
return argv.some(
|
|
210
|
+
(a) => a === "--version" || a === "-V" || a === "-v" || a === "--help" || a === "-h",
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const __test__ = {
|
|
215
|
+
CLIENT_ID,
|
|
216
|
+
ENDPOINT_PATH,
|
|
217
|
+
FETCH_TIMEOUT_MS,
|
|
218
|
+
performUpdate,
|
|
219
|
+
};
|
package/dist/utils/hq-root.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HQ root detection — walks up from cwd looking for HQ markers (US-004)
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Find the HQ root directory by walking up from cwd.
|
|
6
|
-
* Looks for CLAUDE.md or .claude/ directory as markers.
|
|
7
|
-
* Throws if not found.
|
|
8
|
-
*/
|
|
9
|
-
export declare function findHqRoot(): string;
|
|
10
|
-
//# sourceMappingURL=hq-root.d.ts.map
|
package/dist/utils/hq-root.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HQ root detection — walks up from cwd looking for HQ markers (US-004)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="aebb967b-5f70-5107-9d81-bb495be1c405")}catch(e){}}();
|
|
6
|
-
import * as fs from 'fs';
|
|
7
|
-
import * as path from 'path';
|
|
8
|
-
/**
|
|
9
|
-
* Find the HQ root directory by walking up from cwd.
|
|
10
|
-
* Looks for CLAUDE.md or .claude/ directory as markers.
|
|
11
|
-
* Throws if not found.
|
|
12
|
-
*/
|
|
13
|
-
export function findHqRoot() {
|
|
14
|
-
let dir = process.cwd();
|
|
15
|
-
while (dir !== path.dirname(dir)) {
|
|
16
|
-
if (fs.existsSync(path.join(dir, 'CLAUDE.md')) ||
|
|
17
|
-
fs.existsSync(path.join(dir, '.claude'))) {
|
|
18
|
-
return dir;
|
|
19
|
-
}
|
|
20
|
-
dir = path.dirname(dir);
|
|
21
|
-
}
|
|
22
|
-
throw new Error('Could not find HQ root. Run this command from within your HQ directory.');
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=hq-root.js.map
|
|
25
|
-
//# debugId=aebb967b-5f70-5107-9d81-bb495be1c405
|
package/src/utils/hq-root.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HQ root detection — walks up from cwd looking for HQ markers (US-004)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Find the HQ root directory by walking up from cwd.
|
|
10
|
-
* Looks for CLAUDE.md or .claude/ directory as markers.
|
|
11
|
-
* Throws if not found.
|
|
12
|
-
*/
|
|
13
|
-
export function findHqRoot(): string {
|
|
14
|
-
let dir = process.cwd();
|
|
15
|
-
while (dir !== path.dirname(dir)) {
|
|
16
|
-
if (
|
|
17
|
-
fs.existsSync(path.join(dir, 'CLAUDE.md')) ||
|
|
18
|
-
fs.existsSync(path.join(dir, '.claude'))
|
|
19
|
-
) {
|
|
20
|
-
return dir;
|
|
21
|
-
}
|
|
22
|
-
dir = path.dirname(dir);
|
|
23
|
-
}
|
|
24
|
-
throw new Error(
|
|
25
|
-
'Could not find HQ root. Run this command from within your HQ directory.'
|
|
26
|
-
);
|
|
27
|
-
}
|