@indigoai-us/hq-cli 5.50.0 → 5.50.2

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.
Files changed (46) hide show
  1. package/dist/commands/mcp-registration.d.ts +905 -0
  2. package/dist/commands/mcp-registration.js +2001 -0
  3. package/dist/commands/mcp-status.d.ts +130 -0
  4. package/dist/commands/mcp-status.js +406 -0
  5. package/dist/commands/onboard-warning.d.ts +7 -0
  6. package/dist/commands/onboard-warning.js +14 -0
  7. package/dist/commands/onboard.js +5 -5
  8. package/dist/commands/pack-install.d.ts +74 -0
  9. package/dist/commands/pack-install.js +493 -14
  10. package/dist/commands/packs.js +42 -4
  11. package/dist/commands/pkg-install.js +5 -2
  12. package/dist/index.js +7 -2
  13. package/dist/types.d.ts +26 -1
  14. package/dist/utils/contribution-table.d.ts +103 -0
  15. package/dist/utils/contribution-table.js +65 -0
  16. package/dist/utils/pack-contributions.d.ts +93 -10
  17. package/dist/utils/pack-contributions.js +140 -48
  18. package/dist/utils/secrets-cache.d.ts +9 -0
  19. package/dist/utils/secrets-cache.js +24 -2
  20. package/dist/utils/version-gate.d.ts +40 -1
  21. package/dist/utils/version-gate.js +91 -20
  22. package/package.json +3 -2
  23. package/scripts/generate-scan-packages-table.mjs +113 -0
  24. package/src/commands/mcp-registration.test.ts +2787 -0
  25. package/src/commands/mcp-registration.ts +2612 -0
  26. package/src/commands/mcp-status.test.ts +483 -0
  27. package/src/commands/mcp-status.ts +575 -0
  28. package/src/commands/mcp-status.us011.test.ts +243 -0
  29. package/src/commands/onboard-warning.test.ts +26 -0
  30. package/src/commands/onboard-warning.ts +12 -0
  31. package/src/commands/onboard.ts +4 -7
  32. package/src/commands/pack-install.test.ts +733 -0
  33. package/src/commands/pack-install.ts +582 -13
  34. package/src/commands/packs.ts +45 -1
  35. package/src/commands/pkg-install.ts +4 -1
  36. package/src/index.ts +6 -0
  37. package/src/types.ts +28 -9
  38. package/src/utils/contribution-table.ts +83 -0
  39. package/src/utils/pack-contributions.test.ts +310 -25
  40. package/src/utils/pack-contributions.ts +194 -47
  41. package/src/utils/secrets-cache.ts +22 -0
  42. package/src/utils/version-gate.test.ts +122 -0
  43. package/src/utils/version-gate.ts +109 -13
  44. package/test/e2e/smoke-install-mcp.sh +113 -0
  45. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +1 -0
  46. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +11 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * PRD acceptance tests for US-011 — "hq mcp status + append-only audit log".
3
+ *
4
+ * These are E2E acceptance tests (from the PRD ACs), not unit tests. They
5
+ * exercise real module behaviour end-to-end without mocking the implementation.
6
+ *
7
+ * TEST SAFETY (hard requirement): EVERY test injects `env: { home }` = a fresh
8
+ * tmpdir (realpathSync'd so macOS /tmp -> /private/tmp does not break path
9
+ * equality) and cleans it in afterEach. NOTHING here reads or writes the
10
+ * developer's real ~/.claude.json, ~/.mcp.json, ~/.codex, or ~/.hq.
11
+ */
12
+ import { describe, it, expect, afterEach } from 'vitest';
13
+ import * as fs from 'fs';
14
+ import * as os from 'os';
15
+ import * as path from 'path';
16
+
17
+ import { computeMcpStatus } from './mcp-status.js';
18
+ import {
19
+ registerServer,
20
+ unregisterServer,
21
+ mcpRegistryLogPath,
22
+ type McpManifest,
23
+ type SafeWriteEnv,
24
+ type AuditLogEntry,
25
+ } from './mcp-registration.js';
26
+
27
+ // ---------------------------------------------------------------------------
28
+ // The sentinel resolved secret — it must NEVER appear in the audit log or any
29
+ // output surface. Distinctive enough to grep unambiguously.
30
+ // ---------------------------------------------------------------------------
31
+ const SENTINEL_SECRET = 'SUPER_SECRET_BEARER_VALUE_do_not_log_123';
32
+
33
+ // A manifest whose header carries a ${secret:} ref so the resolver is exercised.
34
+ const HTTP_MANIFEST_WITH_SECRET: McpManifest = {
35
+ type: 'http',
36
+ url: 'https://mcp.example.com/vyg-api',
37
+ headers: { Authorization: 'Bearer ${secret:VYG_API_KEY}' },
38
+ };
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Isolated-home sandbox (one per test — no shared state).
42
+ // ---------------------------------------------------------------------------
43
+
44
+ let home: string;
45
+ let env: SafeWriteEnv;
46
+
47
+ function mkFakeHome(): string {
48
+ // realpathSync so macOS /tmp -> /private/tmp doesn't break path equality.
49
+ return fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'hq-us011-test-')));
50
+ }
51
+
52
+ afterEach(() => {
53
+ // Clean up the tmpdir after every test. Nothing touches the real ~/.
54
+ fs.rmSync(home, { recursive: true, force: true });
55
+ });
56
+
57
+ // Helper to set up a fresh sandbox before each individual test.
58
+ function setupSandbox(): void {
59
+ home = mkFakeHome();
60
+ env = { home };
61
+ }
62
+
63
+ // ---------------------------------------------------------------------------
64
+ // Audit-log helpers (self-contained so this file reads on its own).
65
+ // ---------------------------------------------------------------------------
66
+
67
+ /** Read every JSONL line from the audit log under env.home, or [] when absent. */
68
+ function readAuditLines(): AuditLogEntry[] {
69
+ const p = mcpRegistryLogPath(env);
70
+ if (!fs.existsSync(p)) return [];
71
+ return fs
72
+ .readFileSync(p, 'utf-8')
73
+ .split('\n')
74
+ .filter((l) => l.trim().length > 0)
75
+ .map((l) => JSON.parse(l) as AuditLogEntry);
76
+ }
77
+
78
+ /** Raw audit-log file text (for sentinel grepping). */
79
+ function rawAuditText(): string {
80
+ const p = mcpRegistryLogPath(env);
81
+ return fs.existsSync(p) ? fs.readFileSync(p, 'utf-8') : '';
82
+ }
83
+
84
+ // ===========================================================================
85
+ // US-011 PRD acceptance test 1:
86
+ // "Given a pack registered in Claude but NOT Codex (PARTIAL), when
87
+ // `hq mcp status` runs, then it reports the server as PARTIAL with the
88
+ // MISSING RUNTIME NAMED."
89
+ //
90
+ // Setup: register into a sandbox home that has NO ~/.codex (Codex is not
91
+ // installed → Claude-only → PARTIAL). Then call computeMcpStatus(env) and
92
+ // assert the server's partial === true AND that the partial-reason field
93
+ // mentions "Codex" (case-insensitively), AND that Claude shows present while
94
+ // Codex shows not-installed/absent.
95
+ // ===========================================================================
96
+
97
+ describe('US-011: PRD acceptance test 1 — PARTIAL status with missing runtime named', () => {
98
+ it(
99
+ 'Given a pack registered in Claude but NOT Codex (PARTIAL), ' +
100
+ 'when hq mcp status runs, ' +
101
+ 'then it reports the server as PARTIAL with the missing runtime (Codex) named',
102
+ () => {
103
+ setupSandbox();
104
+
105
+ // ARRANGE: register into a home with NO ~/.codex (Codex not installed).
106
+ // The absence of ~/.codex is the first-class signal — never created by the substrate.
107
+ registerServer({
108
+ name: 'vyg-shopify',
109
+ manifest: HTTP_MANIFEST_WITH_SECRET,
110
+ pack: 'hq-pack-vyg-shopify',
111
+ resolveSecret: () => SENTINEL_SECRET,
112
+ env,
113
+ });
114
+
115
+ // Confirm ~/.codex was NOT fabricated by the register operation.
116
+ expect(fs.existsSync(path.join(home, '.codex'))).toBe(false);
117
+
118
+ // ACT: run the status computation (the pure, testable core of `hq mcp status`).
119
+ const report = computeMcpStatus(env);
120
+
121
+ // ASSERT: exactly one server in the report.
122
+ expect(report.servers).toHaveLength(1);
123
+ const s = report.servers[0]!;
124
+
125
+ // Server identity.
126
+ expect(s.server).toBe('vyg-shopify');
127
+ expect(s.pack).toBe('hq-pack-vyg-shopify');
128
+ expect(s.transport).toBe('http');
129
+
130
+ // Claude surface: present.
131
+ expect(s.claude.presence).toBe('present');
132
+
133
+ // Codex surface: not-installed (the runtime itself is missing, not just the server).
134
+ expect(s.codex.presence).toBe('not-installed');
135
+
136
+ // PARTIAL flag: must be true — registered in EXACTLY ONE runtime.
137
+ expect(s.partial).toBe(true);
138
+
139
+ // partialReason must name the missing runtime (Codex), case-insensitively.
140
+ expect(s.partialReason).toBeDefined();
141
+ expect(s.partialReason!.toLowerCase()).toContain('codex');
142
+
143
+ // Not drifted (only one runtime has data).
144
+ expect(s.drifted).toBe(false);
145
+
146
+ // Runtime-level flags agree.
147
+ expect(report.runtimes.claude.installed).toBe(true);
148
+ expect(report.runtimes.claude.parses).toBe(true);
149
+ expect(report.runtimes.codex.installed).toBe(false);
150
+ },
151
+ );
152
+ });
153
+
154
+ // ===========================================================================
155
+ // US-011 PRD acceptance test 2:
156
+ // "Given an install then uninstall, when the audit log is read, then BOTH
157
+ // actions appear with hashes and NO secret value."
158
+ //
159
+ // Setup: a manifest whose header carries a ${secret:} ref resolved to
160
+ // SENTINEL_SECRET. Register (install) then unregister (uninstall) the server
161
+ // into a sandbox home. Read the audit log at mcpRegistryLogPath(env).
162
+ //
163
+ // Assertions:
164
+ // - At least one line with action:'register' AND at least one with action:'unregister'.
165
+ // - Each config-mutating line carries prevHash/newHash (sha256 hex strings).
166
+ // - For the register line the prevHash !== newHash (a real write happened).
167
+ // - CRITICALLY: the raw audit-log text NEVER contains the SENTINEL secret value.
168
+ // ===========================================================================
169
+
170
+ describe('US-011: PRD acceptance test 2 — audit log shows install+uninstall with hashes, no secret', () => {
171
+ it(
172
+ 'Given an install then uninstall, ' +
173
+ 'when the audit log is read, ' +
174
+ 'then BOTH actions appear with hashes and NO secret value anywhere in the log',
175
+ () => {
176
+ setupSandbox();
177
+
178
+ const SHA256_RE = /^[0-9a-f]{64}$/;
179
+
180
+ // ARRANGE + ACT: register (install) then unregister (uninstall).
181
+ registerServer({
182
+ name: 'vyg-shopify',
183
+ manifest: HTTP_MANIFEST_WITH_SECRET,
184
+ pack: 'hq-pack-vyg-shopify',
185
+ resolveSecret: () => SENTINEL_SECRET,
186
+ env,
187
+ });
188
+
189
+ unregisterServer({
190
+ name: 'vyg-shopify',
191
+ pack: 'hq-pack-vyg-shopify',
192
+ env,
193
+ });
194
+
195
+ // Confirm the audit log is at the injected-env path (inside tmpdir, NOT in ~/.hq).
196
+ const logPath = mcpRegistryLogPath(env);
197
+ expect(logPath.startsWith(home)).toBe(true);
198
+ expect(fs.existsSync(logPath)).toBe(true);
199
+
200
+ const lines = readAuditLines();
201
+
202
+ // ASSERT: at least one 'register' line and at least one 'unregister' line.
203
+ const registerLines = lines.filter((l) => l.action === 'register');
204
+ const unregisterLines = lines.filter((l) => l.action === 'unregister');
205
+ expect(registerLines.length).toBeGreaterThanOrEqual(1);
206
+ expect(unregisterLines.length).toBeGreaterThanOrEqual(1);
207
+
208
+ // The register line that actually changed the Claude config (result:'registered').
209
+ const regLine = registerLines.find((l) => l.result === 'registered');
210
+ expect(regLine).toBeDefined();
211
+ expect(regLine!.server).toBe('vyg-shopify');
212
+ expect(regLine!.pack).toBe('hq-pack-vyg-shopify');
213
+
214
+ // prevHash and newHash must be sha256 hex strings on the config-mutating register line.
215
+ // prevHash should be '' (file absent before first write) OR a valid sha256.
216
+ // newHash must be a valid sha256 (file was written).
217
+ // Most importantly: prevHash !== newHash (the write changed the file).
218
+ expect(regLine!.newHash).toMatch(SHA256_RE);
219
+ expect(regLine!.prevHash).not.toBe(regLine!.newHash);
220
+
221
+ // The unregister line that actually changed the Claude config (result:'unregistered').
222
+ const unregLine = unregisterLines.find((l) => l.result === 'unregistered');
223
+ expect(unregLine).toBeDefined();
224
+ expect(unregLine!.server).toBe('vyg-shopify');
225
+ expect(unregLine!.pack).toBe('hq-pack-vyg-shopify');
226
+
227
+ // Unregister hashes: prevHash is the post-register sha256, newHash differs (entry removed).
228
+ expect(unregLine!.prevHash).toMatch(SHA256_RE);
229
+ expect(unregLine!.newHash).toMatch(SHA256_RE);
230
+ expect(unregLine!.prevHash).not.toBe(unregLine!.newHash);
231
+
232
+ // CRITICAL SAFETY CHECK: the raw audit-log text must NEVER contain the sentinel
233
+ // secret value ANYWHERE — grep the whole file as a string.
234
+ const rawText = rawAuditText();
235
+ expect(rawText.includes(SENTINEL_SECRET)).toBe(false);
236
+
237
+ // The URL (not a secret) may appear in the log — that's fine.
238
+ // The Bearer secret value (SENTINEL_SECRET) must NOT.
239
+ expect(rawText).toContain('https://mcp.example.com/vyg-api');
240
+ expect(rawText).not.toContain(SENTINEL_SECRET);
241
+ },
242
+ );
243
+ });
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { buildCreateCompanyWarning } from "./onboard-warning.js";
4
+
5
+ describe("buildCreateCompanyWarning", () => {
6
+ it("documents the warning shown on the create-company path", () => {
7
+ const warning = buildCreateCompanyWarning();
8
+ expect(warning).toContain("NEW company");
9
+ expect(warning).toMatch(/does NOT join an existing one/i);
10
+ });
11
+
12
+ it("advises existing-company users to ask an admin or owner for an invite", () => {
13
+ const warning = buildCreateCompanyWarning();
14
+ expect(warning).toMatch(/ask your admin or owner.*invite/i);
15
+ });
16
+
17
+ it("tells invitees to run hq sync after accepting", () => {
18
+ const warning = buildCreateCompanyWarning();
19
+ expect(warning).toContain("accept it and run `hq sync`");
20
+ });
21
+
22
+ it("warns that duplicate creation leaves the user alone in a separate company", () => {
23
+ const warning = buildCreateCompanyWarning();
24
+ expect(warning).toMatch(/separate one you'd be alone in/i);
25
+ });
26
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Builds the static create-time warning surfaced by both `create-company` and
3
+ * `dry-run`, because users may accidentally create duplicate companies instead
4
+ * of joining the existing company they were invited to.
5
+ */
6
+ export function buildCreateCompanyWarning(): string {
7
+ return (
8
+ " This creates a NEW company that you own — it does NOT join an existing one.\n" +
9
+ " If your company already uses HQ, do NOT create it again: ask your admin or owner to send you an invite, then accept it and run `hq sync` to pull the existing company.\n" +
10
+ " Creating a same-named company makes a separate one you'd be alone in.\n"
11
+ );
12
+ }
@@ -32,6 +32,7 @@ import {
32
32
  import { createDefaultVaultClient } from "./cloud-provision.js";
33
33
  import { detectOnboardingIdentityMismatch } from "./onboard-identity-guard.js";
34
34
  import { planOnboardJoin } from "./onboard-join.js";
35
+ import { buildCreateCompanyWarning } from "./onboard-warning.js";
35
36
 
36
37
  // ---------------------------------------------------------------------------
37
38
  // Command registration
@@ -70,13 +71,7 @@ export function registerOnboardCommand(program: Command): void {
70
71
  console.log(` Company: ${options.name} (${options.slug})`);
71
72
  console.log(` Person: ${options.personName} <${options.email}>`);
72
73
  console.log(` HQ root: ${options.hqRoot}\n`);
73
- console.log(
74
- chalk.gray(
75
- " This creates a NEW company you own. Joining a teammate's existing\n" +
76
- " company? Stop — accept your invite, then run `hq sync` to pull it.\n" +
77
- " Creating a same-named company leaves you alone in a separate one.\n",
78
- ),
79
- );
74
+ console.log(chalk.gray(buildCreateCompanyWarning()));
80
75
 
81
76
  const accessToken = await ensureCognitoToken();
82
77
  const result = await runOnboardCli({
@@ -248,6 +243,8 @@ export function registerOnboardCommand(program: Command): void {
248
243
  )
249
244
  .action(async (options: { hqRoot: string }) => {
250
245
  try {
246
+ console.log(chalk.gray(buildCreateCompanyWarning()));
247
+
251
248
  // No auth needed for dry-run — runOnboardCli handles this branch
252
249
  // without touching the vault-service.
253
250
  const result = await runOnboardCli({