@indigoai-us/hq-cli 5.77.13 → 5.77.14

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 CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.77.14]
6
+
7
+ ### Fixed
8
+
9
+ - Extend `HQ_API_KEY` fail-closed: reject metadata-only `hq secrets get`
10
+ without `--reveal`, and hard-error `hq run` / `hq install` when a vault API
11
+ key is set (Cognito session required). (#273)
12
+ - Keep the Cognito-only gate on the top-level `hq install` route only — not
13
+ inside shared `installPack()` — so `hq packs update` cannot un-wire a pack
14
+ and then abort mid-flight under `HQ_API_KEY`. (#273)
15
+
5
16
  ## [5.77.13]
6
17
 
7
18
  ### Added
@@ -1613,6 +1613,15 @@ export function runScanPackages(hqRoot, opts = {}) {
1613
1613
  }
1614
1614
  }
1615
1615
  export async function installPack(source, opts = {}) {
1616
+ // NOTE: the HQ_API_KEY fail-closed gate is NOT enforced here. `installPack`
1617
+ // is a shared primitive called both by the top-level `hq install` CLI route
1618
+ // (where Cognito-only is the right gate — checked there instead) AND by
1619
+ // `hq packs update` (packs.ts:runUpdate), which un-wires an existing pack's
1620
+ // contributions BEFORE re-installing. Throwing from inside `installPack`
1621
+ // would leave an update mid-flight (unwired, not reinstalled) whenever
1622
+ // HQ_API_KEY happened to be set. Restricting the assertion to the install
1623
+ // entrypoint keeps `hq packs update` fail-closed at its own call site
1624
+ // instead (checked before it un-wires anything).
1616
1625
  const transport = classify(source);
1617
1626
  const hqRoot = findHqRoot();
1618
1627
  // `readHqVersion` (shared with `hq packs`) reads the CANONICAL
@@ -23,6 +23,7 @@ import { resolveDefaultHqRoot } from '../utils/cognito-session.js';
23
23
  import { getRegistryUrl, RegistryClient, } from '../utils/registry-client.js';
24
24
  import { verifySha256, verifyRsaSignature } from '../utils/integrity.js';
25
25
  import { addToRegistry } from '../utils/registry.js';
26
+ import { assertCognitoOnlyCommand } from '../utils/resolve-vault-credential.js';
26
27
  import { MARKETPLACE_PREFIX, installPack, sourceMatchesPackPattern, } from './pack-install.js';
27
28
  export function registerPackageInstallCommand(parent) {
28
29
  parent
@@ -35,6 +36,11 @@ export function registerPackageInstallCommand(parent) {
35
36
  .option('--branch', 'Follow a ref instead of SHA-pinning (git content-pack flow)')
36
37
  .action(async (source, opts) => {
37
38
  try {
39
+ // Gate the top-level `hq install` entrypoint only — `installPack`
40
+ // itself is also called by `hq packs update` (packs.ts), which must
41
+ // stay able to fail closed at its OWN call site (before it un-wires
42
+ // an existing pack) rather than mid-flight inside installPack.
43
+ assertCognitoOnlyCommand('hq install');
38
44
  if (sourceMatchesPackPattern(source)) {
39
45
  await installPack(source, {
40
46
  company: opts.company,
@@ -3,6 +3,7 @@ import * as path from 'node:path';
3
3
  import * as fs from 'node:fs';
4
4
  import { internal } from 'varlock';
5
5
  import { ensureCognitoToken } from '../utils/cognito-session.js';
6
+ import { peekHqApiKey } from '../utils/resolve-vault-credential.js';
6
7
  import { computeSha256 } from '../utils/integrity.js';
7
8
  import { vaultApiFetch, getCompanyUid } from '../utils/vault-api.js';
8
9
  import { discoverSchemas } from '../run/discover-schemas.js';
@@ -38,6 +39,9 @@ export function registerRunCommand(program) {
38
39
  .allowUnknownOption(true)
39
40
  .action(async (opts) => {
40
41
  try {
42
+ if (peekHqApiKey() !== undefined) {
43
+ throw new Error('HQ_API_KEY is set; `hq run` requires a Cognito session. Unset HQ_API_KEY or use `hq secrets exec`.');
44
+ }
41
45
  const dashIndex = process.argv.indexOf('--');
42
46
  const childArgs = dashIndex !== -1 ? process.argv.slice(dashIndex + 1) : [];
43
47
  if (!opts.check && childArgs.length === 0) {
@@ -732,6 +732,11 @@ export function registerSecretsCommand(program) {
732
732
  try {
733
733
  const cred = await resolveVaultCredential();
734
734
  if (cred.kind === "api-key") {
735
+ if (!opts.reveal) {
736
+ console.error(chalk.red("HQ_API_KEY is set; `hq secrets get` without --reveal is not supported for API keys. " +
737
+ "Use --reveal to fetch the value, or unset HQ_API_KEY for metadata-only reads."));
738
+ process.exit(1);
739
+ }
735
740
  const res = await vaultApiFetch({
736
741
  token: cred.token,
737
742
  path: "/v1/keys/secrets/fetch",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.77.13",
3
+ "version": "5.77.14",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -2093,6 +2093,15 @@ export async function installPack(
2093
2093
  source: string,
2094
2094
  opts: InstallPackOptions = {}
2095
2095
  ): Promise<void> {
2096
+ // NOTE: the HQ_API_KEY fail-closed gate is NOT enforced here. `installPack`
2097
+ // is a shared primitive called both by the top-level `hq install` CLI route
2098
+ // (where Cognito-only is the right gate — checked there instead) AND by
2099
+ // `hq packs update` (packs.ts:runUpdate), which un-wires an existing pack's
2100
+ // contributions BEFORE re-installing. Throwing from inside `installPack`
2101
+ // would leave an update mid-flight (unwired, not reinstalled) whenever
2102
+ // HQ_API_KEY happened to be set. Restricting the assertion to the install
2103
+ // entrypoint keeps `hq packs update` fail-closed at its own call site
2104
+ // instead (checked before it un-wires anything).
2096
2105
  const transport = classify(source);
2097
2106
  const hqRoot = findHqRoot();
2098
2107
  // `readHqVersion` (shared with `hq packs`) reads the CANONICAL
@@ -0,0 +1,105 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * Regression (Codex P1 follow-up on hq-cli#273): `hq packs update` un-wires a
4
+ * pack's existing contributions BEFORE calling `installPack()` to re-wire
5
+ * them. The Cognito-only `HQ_API_KEY` fail-closed gate added for `hq install`
6
+ * must live ONLY at that top-level CLI route (pkg-install.ts) — NOT inside
7
+ * the shared `installPack()` primitive `hq packs update` also calls. If it
8
+ * lived inside `installPack()`, a vault-key session would un-wire a pack and
9
+ * then throw before re-installing it, leaving the pack unwired with no
10
+ * symlinks and no rollback.
11
+ */
12
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
13
+ import * as os from 'os';
14
+ import { Command } from 'commander';
15
+
16
+ const { listInstalledPacks, unwirePack, installPack, resolveLatest } = vi.hoisted(() => ({
17
+ listInstalledPacks: vi.fn(),
18
+ unwirePack: vi.fn(() => ({ unlinked: [], skipped: [] })),
19
+ installPack: vi.fn(async () => {}),
20
+ resolveLatest: vi.fn(async () => ({
21
+ transport: 'git',
22
+ current: 'aaa',
23
+ latest: 'bbb',
24
+ updateAvailable: true,
25
+ })),
26
+ }));
27
+
28
+ vi.mock('./pack-install.js', () => ({
29
+ classify: vi.fn(() => 'git'),
30
+ resolveLatest,
31
+ resolveLatestMarketplace: vi.fn(),
32
+ runScanPackages: vi.fn(),
33
+ installPack,
34
+ }));
35
+
36
+ vi.mock('../utils/pack-contributions.js', () => ({
37
+ contributionLinks: vi.fn(() => []),
38
+ linkStatus: vi.fn(() => 'live'),
39
+ listInstalledPacks,
40
+ findDependentPacks: vi.fn(() => []),
41
+ readPackManifest: vi.fn(() => ({ manifest: null })),
42
+ unwirePack,
43
+ unwirePackMcp: vi.fn(),
44
+ readHqVersion: vi.fn(() => '15.0.0'),
45
+ readRecommendedPackages: vi.fn(() => []),
46
+ packagesDir: vi.fn((root: string) => `${root}/core/packages`),
47
+ }));
48
+
49
+ // resolveRoot() falls back to findHqRoot() when --hq-root isn't passed; stub
50
+ // it to a real, existing directory so packs.ts never chdir()s into one.
51
+ vi.mock('../utils/manifest.js', () => ({
52
+ findHqRoot: vi.fn(() => os.tmpdir()),
53
+ }));
54
+
55
+ import { registerPacksCommand } from './packs.js';
56
+
57
+ async function runUpdateCli(...args: string[]): Promise<void> {
58
+ const program = new Command();
59
+ program.exitOverride();
60
+ registerPacksCommand(program);
61
+ await program.parseAsync(['packs', 'update', ...args], { from: 'user' });
62
+ }
63
+
64
+ describe('hq packs update leaves no pack unwired under HQ_API_KEY', () => {
65
+ beforeEach(() => {
66
+ listInstalledPacks.mockReturnValue([
67
+ {
68
+ name: 'hq-pack-demo',
69
+ dir: '/tmp/hq/core/packages/hq-pack-demo',
70
+ manifest: {
71
+ name: 'hq-pack-demo',
72
+ version: '1.0.0',
73
+ source: 'https://example.com/demo.git#aaa',
74
+ contributes: { skills: ['demo'] },
75
+ },
76
+ },
77
+ ]);
78
+ unwirePack.mockClear();
79
+ installPack.mockClear();
80
+ });
81
+
82
+ afterEach(() => {
83
+ delete process.env.HQ_API_KEY;
84
+ });
85
+
86
+ it('still calls installPack after unwirePack when HQ_API_KEY is set', async () => {
87
+ process.env.HQ_API_KEY = 'hqk_probe';
88
+ await runUpdateCli('hq-pack-demo', '--json');
89
+
90
+ expect(unwirePack).toHaveBeenCalledTimes(1);
91
+ // The regression: installPack must run to completion right after
92
+ // unwirePack -- it must NOT throw due to a Cognito-only gate, which would
93
+ // leave the pack unwired with nothing re-installed in its place.
94
+ expect(installPack).toHaveBeenCalledTimes(1);
95
+ const unwireOrder = unwirePack.mock.invocationCallOrder[0];
96
+ const installOrder = installPack.mock.invocationCallOrder[0];
97
+ expect(unwireOrder).toBeLessThan(installOrder);
98
+ });
99
+
100
+ it('still updates without HQ_API_KEY set (baseline, unchanged behavior)', async () => {
101
+ await runUpdateCli('hq-pack-demo', '--json');
102
+ expect(unwirePack).toHaveBeenCalledTimes(1);
103
+ expect(installPack).toHaveBeenCalledTimes(1);
104
+ });
105
+ });
@@ -4,7 +4,7 @@
4
4
  * listings transport (the live install path), not the legacy Cognito-gated
5
5
  * registry flow whose backend (/packages, /entitlements) was never deployed.
6
6
  */
7
- import { describe, it, expect, vi, beforeEach } from 'vitest';
7
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
8
8
  import { Command } from 'commander';
9
9
 
10
10
  // vi.mock is hoisted above imports/consts, so build the mocks via vi.hoisted()
@@ -48,6 +48,10 @@ describe('hq install dispatch — bare slug routes to marketplace', () => {
48
48
  sourceMatchesPackPattern.mockClear();
49
49
  });
50
50
 
51
+ afterEach(() => {
52
+ delete process.env.HQ_API_KEY;
53
+ });
54
+
51
55
  it('routes a bare slug through the marketplace transport', async () => {
52
56
  await runInstall('email-assistant');
53
57
  expect(installPack).toHaveBeenCalledTimes(1);
@@ -69,3 +73,31 @@ describe('hq install dispatch — bare slug routes to marketplace', () => {
69
73
  expect(installPack.mock.calls[0][0]).toBe('@indigoai-us/hq-pack-demo');
70
74
  });
71
75
  });
76
+
77
+ describe('hq install dispatch — HQ_API_KEY fail-closed gate', () => {
78
+ beforeEach(() => {
79
+ installPack.mockClear();
80
+ sourceMatchesPackPattern.mockClear();
81
+ });
82
+
83
+ afterEach(() => {
84
+ delete process.env.HQ_API_KEY;
85
+ });
86
+
87
+ it('rejects at the CLI entrypoint before calling installPack when HQ_API_KEY is set', async () => {
88
+ process.env.HQ_API_KEY = 'hqk_probe';
89
+ const exitSpy = vi
90
+ .spyOn(process, 'exit')
91
+ .mockImplementation((code?: number | string | null) => {
92
+ throw new Error(`process.exit(${code})`);
93
+ });
94
+ try {
95
+ await expect(runInstall('@indigoai-us/hq-pack-demo')).rejects.toThrow('process.exit(1)');
96
+ // The gate must fire BEFORE installPack -- a vault-key session must
97
+ // never reach the pack-fetch/wire path via `hq install`.
98
+ expect(installPack).not.toHaveBeenCalled();
99
+ } finally {
100
+ exitSpy.mockRestore();
101
+ }
102
+ });
103
+ });
@@ -28,6 +28,7 @@ import {
28
28
  } from '../utils/registry-client.js';
29
29
  import { verifySha256, verifyRsaSignature } from '../utils/integrity.js';
30
30
  import { addToRegistry } from '../utils/registry.js';
31
+ import { assertCognitoOnlyCommand } from '../utils/resolve-vault-credential.js';
31
32
  import {
32
33
  MARKETPLACE_PREFIX,
33
34
  installPack,
@@ -51,6 +52,11 @@ export function registerPackageInstallCommand(parent: Command): void {
51
52
  opts: { company?: string; allowHooks?: boolean; allowMcp?: boolean; branch?: boolean }
52
53
  ) => {
53
54
  try {
55
+ // Gate the top-level `hq install` entrypoint only — `installPack`
56
+ // itself is also called by `hq packs update` (packs.ts), which must
57
+ // stay able to fail closed at its OWN call site (before it un-wires
58
+ // an existing pack) rather than mid-flight inside installPack.
59
+ assertCognitoOnlyCommand('hq install');
54
60
  if (sourceMatchesPackPattern(source)) {
55
61
  await installPack(source, {
56
62
  company: opts.company,
@@ -4,6 +4,7 @@ import * as path from 'node:path';
4
4
  import * as fs from 'node:fs';
5
5
  import { internal } from 'varlock';
6
6
  import { ensureCognitoToken } from '../utils/cognito-session.js';
7
+ import { peekHqApiKey } from '../utils/resolve-vault-credential.js';
7
8
  import { computeSha256 } from '../utils/integrity.js';
8
9
  import { vaultApiFetch, getCompanyUid } from '../utils/vault-api.js';
9
10
  import { discoverSchemas } from '../run/discover-schemas.js';
@@ -52,6 +53,11 @@ export function registerRunCommand(program: Command): void {
52
53
  check?: boolean;
53
54
  }) => {
54
55
  try {
56
+ if (peekHqApiKey() !== undefined) {
57
+ throw new Error(
58
+ 'HQ_API_KEY is set; `hq run` requires a Cognito session. Unset HQ_API_KEY or use `hq secrets exec`.',
59
+ );
60
+ }
55
61
  const dashIndex = process.argv.indexOf('--');
56
62
  const childArgs = dashIndex !== -1 ? process.argv.slice(dashIndex + 1) : [];
57
63
 
@@ -1945,6 +1945,19 @@ describe("HQ_API_KEY consume path", () => {
1945
1945
  expect(errText).toMatch(/must start with 'hqk_'/);
1946
1946
  });
1947
1947
 
1948
+ it("rejects secrets get without --reveal when HQ_API_KEY is set", async () => {
1949
+ process.env.HQ_API_KEY = "hqk_valid_key";
1950
+ const program = buildProgram();
1951
+ await expect(
1952
+ program.parseAsync(["node", "hq", "secrets", "get", "FOO"]),
1953
+ ).rejects.toThrow(/__EXIT__:1/);
1954
+ expect(vaultApiFetch).not.toHaveBeenCalled();
1955
+ const errText = errSpy.mock.calls
1956
+ .map((call) => call.map(String).join(" "))
1957
+ .join("\n");
1958
+ expect(errText).toMatch(/without --reveal is not supported/);
1959
+ });
1960
+
1948
1961
  it("gets a secret via /v1/keys/secrets/fetch when HQ_API_KEY is set", async () => {
1949
1962
  process.env.HQ_API_KEY = "hqk_valid_key";
1950
1963
  vi.mocked(vaultApiFetch).mockResolvedValueOnce(
@@ -1055,6 +1055,15 @@ export function registerSecretsCommand(program: Command): void {
1055
1055
  const cred = await resolveVaultCredential();
1056
1056
 
1057
1057
  if (cred.kind === "api-key") {
1058
+ if (!opts.reveal) {
1059
+ console.error(
1060
+ chalk.red(
1061
+ "HQ_API_KEY is set; `hq secrets get` without --reveal is not supported for API keys. " +
1062
+ "Use --reveal to fetch the value, or unset HQ_API_KEY for metadata-only reads.",
1063
+ ),
1064
+ );
1065
+ process.exit(1);
1066
+ }
1058
1067
  const res = await vaultApiFetch({
1059
1068
  token: cred.token,
1060
1069
  path: "/v1/keys/secrets/fetch",