@indigoai-us/hq-cli 5.50.2 → 5.52.0
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 +23 -0
- package/dist/bin/hq-auth-refresh.d.ts +1 -1
- package/dist/bin/hq-auth-refresh.js +5 -2
- package/dist/commands/files.js +33 -3
- package/dist/commands/members.d.ts +27 -0
- package/dist/commands/members.js +95 -37
- package/dist/commands/people.d.ts +26 -1
- package/dist/commands/people.js +70 -7
- package/dist/commands/secrets-scope.d.ts +20 -0
- package/dist/commands/secrets-scope.js +19 -0
- package/dist/commands/secrets.js +21 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -14
- package/dist/node-preflight.d.ts +39 -0
- package/dist/node-preflight.js +55 -0
- package/dist/sentry.d.ts +12 -0
- package/dist/sentry.js +19 -3
- package/dist/utils/epipe.d.ts +8 -0
- package/dist/utils/epipe.js +30 -0
- package/dist/utils/intercepted-process-exit.d.ts +7 -0
- package/dist/utils/intercepted-process-exit.js +38 -0
- package/e2e/cli.test.ts +35 -0
- package/package.json +1 -1
- package/src/bin/hq-auth-refresh.ts +3 -0
- package/src/commands/files.test.ts +130 -0
- package/src/commands/files.ts +55 -3
- package/src/commands/members.test.ts +292 -0
- package/src/commands/members.ts +153 -43
- package/src/commands/people.test.ts +212 -5
- package/src/commands/people.ts +141 -5
- package/src/commands/secrets-scope.test.ts +56 -0
- package/src/commands/secrets-scope.ts +32 -0
- package/src/commands/secrets.ts +24 -10
- package/src/index.ts +40 -12
- package/src/node-preflight.test.ts +60 -0
- package/src/node-preflight.ts +67 -0
- package/src/sentry-epipe.test.ts +37 -0
- package/src/sentry-release.test.ts +54 -0
- package/src/sentry.ts +21 -1
- package/src/utils/epipe.test.ts +28 -0
- package/src/utils/epipe.ts +29 -0
- package/src/utils/intercepted-process-exit.test.ts +37 -0
- package/src/utils/intercepted-process-exit.ts +36 -0
|
@@ -19,7 +19,11 @@ import {
|
|
|
19
19
|
resolveNameToEmail,
|
|
20
20
|
type PersonRecord,
|
|
21
21
|
} from "../utils/people.js";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
registerPeopleCommand,
|
|
24
|
+
resolveCompanySlug,
|
|
25
|
+
type RefreshPeopleRoster,
|
|
26
|
+
} from "./people.js";
|
|
23
27
|
|
|
24
28
|
// ---------------------------------------------------------------------------
|
|
25
29
|
// Filesystem fixture helpers
|
|
@@ -335,15 +339,20 @@ describe("companyPeopleDir", () => {
|
|
|
335
339
|
// Wired CLI surface (list / search / resolve)
|
|
336
340
|
// ---------------------------------------------------------------------------
|
|
337
341
|
|
|
338
|
-
function buildProgram(): Command {
|
|
342
|
+
function buildProgram(deps?: { refreshRoster?: RefreshPeopleRoster }): Command {
|
|
339
343
|
const program = new Command();
|
|
340
344
|
program.exitOverride(); // throw instead of process.exit on commander errors
|
|
341
|
-
registerPeopleCommand(program);
|
|
345
|
+
registerPeopleCommand(program, deps);
|
|
342
346
|
return program;
|
|
343
347
|
}
|
|
344
348
|
|
|
345
|
-
async function run(
|
|
346
|
-
|
|
349
|
+
async function run(
|
|
350
|
+
args: string[],
|
|
351
|
+
deps: { refreshRoster?: RefreshPeopleRoster } = {
|
|
352
|
+
refreshRoster: async () => {},
|
|
353
|
+
},
|
|
354
|
+
): Promise<void> {
|
|
355
|
+
await buildProgram(deps).parseAsync(["node", "hq", ...args]);
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
describe("hq people (wired)", () => {
|
|
@@ -396,6 +405,104 @@ describe("hq people (wired)", () => {
|
|
|
396
405
|
expect(out[0].email).toBe("jane@acme.com");
|
|
397
406
|
});
|
|
398
407
|
|
|
408
|
+
it("search local hit does not refresh the roster", async () => {
|
|
409
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>();
|
|
410
|
+
await run(
|
|
411
|
+
[
|
|
412
|
+
"people",
|
|
413
|
+
"search",
|
|
414
|
+
"jane",
|
|
415
|
+
"--company",
|
|
416
|
+
"acme",
|
|
417
|
+
"--hq-root",
|
|
418
|
+
tmpRoot,
|
|
419
|
+
"--json",
|
|
420
|
+
],
|
|
421
|
+
{ refreshRoster },
|
|
422
|
+
);
|
|
423
|
+
expect(refreshRoster).not.toHaveBeenCalled();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("search local miss refreshes once and retries from the refreshed roster", async () => {
|
|
427
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>(async () => {
|
|
428
|
+
makePerson("acme", "ada-lovelace", {
|
|
429
|
+
name: "Ada Lovelace",
|
|
430
|
+
email: "ada@acme.com",
|
|
431
|
+
type: "internal",
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
await run(
|
|
436
|
+
[
|
|
437
|
+
"people",
|
|
438
|
+
"search",
|
|
439
|
+
"ada",
|
|
440
|
+
"--company",
|
|
441
|
+
"acme",
|
|
442
|
+
"--hq-root",
|
|
443
|
+
tmpRoot,
|
|
444
|
+
"--json",
|
|
445
|
+
],
|
|
446
|
+
{ refreshRoster },
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
expect(refreshRoster).toHaveBeenCalledTimes(1);
|
|
450
|
+
expect(refreshRoster).toHaveBeenCalledWith(tmpRoot, "acme");
|
|
451
|
+
const out = JSON.parse(logSpy.mock.calls[0][0] as string);
|
|
452
|
+
expect(out).toHaveLength(1);
|
|
453
|
+
expect(out[0]).toMatchObject({
|
|
454
|
+
name: "Ada Lovelace",
|
|
455
|
+
email: "ada@acme.com",
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("search local miss with refresh failure reports the original empty JSON and logs a note", async () => {
|
|
460
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>(async () => {
|
|
461
|
+
throw new Error("offline");
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
await run(
|
|
465
|
+
[
|
|
466
|
+
"people",
|
|
467
|
+
"search",
|
|
468
|
+
"ada",
|
|
469
|
+
"--company",
|
|
470
|
+
"acme",
|
|
471
|
+
"--hq-root",
|
|
472
|
+
tmpRoot,
|
|
473
|
+
"--json",
|
|
474
|
+
],
|
|
475
|
+
{ refreshRoster },
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
expect(refreshRoster).toHaveBeenCalledTimes(1);
|
|
479
|
+
expect(JSON.parse(logSpy.mock.calls[0][0] as string)).toEqual([]);
|
|
480
|
+
expect(errSpy).toHaveBeenCalledWith(
|
|
481
|
+
expect.stringContaining("Could not refresh people roster"),
|
|
482
|
+
);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it("search --local-only skips refresh on a miss", async () => {
|
|
486
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>();
|
|
487
|
+
await run(
|
|
488
|
+
[
|
|
489
|
+
"people",
|
|
490
|
+
"search",
|
|
491
|
+
"ada",
|
|
492
|
+
"--company",
|
|
493
|
+
"acme",
|
|
494
|
+
"--hq-root",
|
|
495
|
+
tmpRoot,
|
|
496
|
+
"--json",
|
|
497
|
+
"--local-only",
|
|
498
|
+
],
|
|
499
|
+
{ refreshRoster },
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
expect(refreshRoster).not.toHaveBeenCalled();
|
|
503
|
+
expect(JSON.parse(logSpy.mock.calls[0][0] as string)).toEqual([]);
|
|
504
|
+
});
|
|
505
|
+
|
|
399
506
|
it("resolve prints the bare email on stdout", async () => {
|
|
400
507
|
await run([
|
|
401
508
|
"people",
|
|
@@ -409,6 +516,106 @@ describe("hq people (wired)", () => {
|
|
|
409
516
|
expect(logSpy).toHaveBeenCalledWith("jane@acme.com");
|
|
410
517
|
});
|
|
411
518
|
|
|
519
|
+
it("resolve local hit does not refresh the roster", async () => {
|
|
520
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>();
|
|
521
|
+
await run(
|
|
522
|
+
[
|
|
523
|
+
"people",
|
|
524
|
+
"resolve",
|
|
525
|
+
"Jane Smith",
|
|
526
|
+
"--company",
|
|
527
|
+
"acme",
|
|
528
|
+
"--hq-root",
|
|
529
|
+
tmpRoot,
|
|
530
|
+
],
|
|
531
|
+
{ refreshRoster },
|
|
532
|
+
);
|
|
533
|
+
expect(refreshRoster).not.toHaveBeenCalled();
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it("resolve local miss refreshes once and retries from the refreshed roster", async () => {
|
|
537
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>(async () => {
|
|
538
|
+
makePerson("acme", "ada-lovelace", {
|
|
539
|
+
name: "Ada Lovelace",
|
|
540
|
+
email: "ada@acme.com",
|
|
541
|
+
type: "internal",
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
await run(
|
|
546
|
+
[
|
|
547
|
+
"people",
|
|
548
|
+
"resolve",
|
|
549
|
+
"Ada Lovelace",
|
|
550
|
+
"--company",
|
|
551
|
+
"acme",
|
|
552
|
+
"--hq-root",
|
|
553
|
+
tmpRoot,
|
|
554
|
+
],
|
|
555
|
+
{ refreshRoster },
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
expect(refreshRoster).toHaveBeenCalledTimes(1);
|
|
559
|
+
expect(refreshRoster).toHaveBeenCalledWith(tmpRoot, "acme");
|
|
560
|
+
expect(logSpy).toHaveBeenCalledWith("ada@acme.com");
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it("resolve local miss with refresh failure reports unchanged not_found JSON and logs a note", async () => {
|
|
564
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>(async () => {
|
|
565
|
+
throw new Error("not signed in");
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
await expect(
|
|
569
|
+
run(
|
|
570
|
+
[
|
|
571
|
+
"people",
|
|
572
|
+
"resolve",
|
|
573
|
+
"Ada Lovelace",
|
|
574
|
+
"--company",
|
|
575
|
+
"acme",
|
|
576
|
+
"--hq-root",
|
|
577
|
+
tmpRoot,
|
|
578
|
+
"--json",
|
|
579
|
+
],
|
|
580
|
+
{ refreshRoster },
|
|
581
|
+
),
|
|
582
|
+
).rejects.toThrow("__exit__");
|
|
583
|
+
|
|
584
|
+
expect(refreshRoster).toHaveBeenCalledTimes(1);
|
|
585
|
+
expect(JSON.parse(logSpy.mock.calls[0][0] as string)).toEqual({
|
|
586
|
+
status: "not_found",
|
|
587
|
+
});
|
|
588
|
+
expect(errSpy).toHaveBeenCalledWith(
|
|
589
|
+
expect.stringContaining("Could not refresh people roster"),
|
|
590
|
+
);
|
|
591
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it("resolve --local-only skips refresh on a miss", async () => {
|
|
595
|
+
const refreshRoster = vi.fn<RefreshPeopleRoster>();
|
|
596
|
+
await expect(
|
|
597
|
+
run(
|
|
598
|
+
[
|
|
599
|
+
"people",
|
|
600
|
+
"resolve",
|
|
601
|
+
"Ada Lovelace",
|
|
602
|
+
"--company",
|
|
603
|
+
"acme",
|
|
604
|
+
"--hq-root",
|
|
605
|
+
tmpRoot,
|
|
606
|
+
"--json",
|
|
607
|
+
"--local-only",
|
|
608
|
+
],
|
|
609
|
+
{ refreshRoster },
|
|
610
|
+
),
|
|
611
|
+
).rejects.toThrow("__exit__");
|
|
612
|
+
|
|
613
|
+
expect(refreshRoster).not.toHaveBeenCalled();
|
|
614
|
+
expect(JSON.parse(logSpy.mock.calls[0][0] as string)).toEqual({
|
|
615
|
+
status: "not_found",
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
412
619
|
it("resolve exits non-zero when not found", async () => {
|
|
413
620
|
await expect(
|
|
414
621
|
run([
|
package/src/commands/people.ts
CHANGED
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
import * as fs from "fs";
|
|
15
15
|
import { Command, Option } from "commander";
|
|
16
16
|
import chalk from "chalk";
|
|
17
|
+
import { VaultClient } from "@indigoai-us/hq-cloud";
|
|
17
18
|
import * as yaml from "js-yaml";
|
|
18
19
|
import { findHqRoot } from "../utils/manifest.js";
|
|
19
20
|
import { manifestPath, type ManifestDoc } from "./cloud-provision.js";
|
|
21
|
+
import {
|
|
22
|
+
DEFAULT_COGNITO,
|
|
23
|
+
buildVaultConfig,
|
|
24
|
+
ensureCognitoToken,
|
|
25
|
+
} from "../utils/cognito-session.js";
|
|
26
|
+
import { getCompanyUid } from "../utils/vault-api.js";
|
|
27
|
+
import { createCompanyPresignClient, runGet } from "./files-browse.js";
|
|
20
28
|
import {
|
|
21
29
|
assertSafeCompanySlug,
|
|
22
30
|
listCompanyPeople,
|
|
@@ -31,6 +39,39 @@ interface PeopleScopeOpts {
|
|
|
31
39
|
hqRoot?: string;
|
|
32
40
|
}
|
|
33
41
|
|
|
42
|
+
export type RefreshPeopleRoster = (
|
|
43
|
+
hqRoot: string,
|
|
44
|
+
companySlug: string,
|
|
45
|
+
) => Promise<void>;
|
|
46
|
+
|
|
47
|
+
interface PeopleCommandDeps {
|
|
48
|
+
refreshRoster?: RefreshPeopleRoster;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface PeopleLookupOpts {
|
|
52
|
+
localOnly?: boolean;
|
|
53
|
+
json?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function refreshPeopleRosterFromCloud(
|
|
57
|
+
hqRoot: string,
|
|
58
|
+
companySlug: string,
|
|
59
|
+
): Promise<void> {
|
|
60
|
+
const accessToken = await ensureCognitoToken();
|
|
61
|
+
const client = new VaultClient(buildVaultConfig(accessToken));
|
|
62
|
+
await getCompanyUid(accessToken, companySlug);
|
|
63
|
+
|
|
64
|
+
await runGet({
|
|
65
|
+
path: `companies/${companySlug}/people/`,
|
|
66
|
+
hqRoot,
|
|
67
|
+
companySlug,
|
|
68
|
+
vaultClient: client,
|
|
69
|
+
companyClient: ({ companyUid }) =>
|
|
70
|
+
createCompanyPresignClient({ token: accessToken, companyUid }),
|
|
71
|
+
region: DEFAULT_COGNITO.region,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
34
75
|
/** Companies that still exist (anything not explicitly `status: archived`). */
|
|
35
76
|
function activeCompanySlugs(manifest: ManifestDoc): string[] {
|
|
36
77
|
const companies = manifest.companies ?? {};
|
|
@@ -118,7 +159,82 @@ function fail(message: string): never {
|
|
|
118
159
|
process.exit(1);
|
|
119
160
|
}
|
|
120
161
|
|
|
121
|
-
|
|
162
|
+
function logRefreshFailure(companySlug: string, err: unknown): void {
|
|
163
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
164
|
+
console.error(
|
|
165
|
+
chalk.dim(
|
|
166
|
+
` Could not refresh people roster for '${companySlug}': ${message}`,
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function tryRefreshRoster(
|
|
172
|
+
refreshRoster: RefreshPeopleRoster,
|
|
173
|
+
hqRoot: string,
|
|
174
|
+
slug: string,
|
|
175
|
+
): Promise<boolean> {
|
|
176
|
+
try {
|
|
177
|
+
await refreshRoster(hqRoot, slug);
|
|
178
|
+
return true;
|
|
179
|
+
} catch (err) {
|
|
180
|
+
logRefreshFailure(slug, err);
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function resolvePersonWithRosterFallback(
|
|
186
|
+
input: {
|
|
187
|
+
hqRoot: string;
|
|
188
|
+
slug: string;
|
|
189
|
+
name: string;
|
|
190
|
+
opts?: PeopleLookupOpts;
|
|
191
|
+
refreshRoster?: RefreshPeopleRoster;
|
|
192
|
+
},
|
|
193
|
+
): Promise<ReturnType<typeof resolveNameToEmail>> {
|
|
194
|
+
const local = resolveNameToEmail(
|
|
195
|
+
listCompanyPeople(input.hqRoot, input.slug),
|
|
196
|
+
input.name,
|
|
197
|
+
);
|
|
198
|
+
if (local.status !== "not_found" || input.opts?.localOnly) return local;
|
|
199
|
+
|
|
200
|
+
const refreshed = await tryRefreshRoster(
|
|
201
|
+
input.refreshRoster ?? refreshPeopleRosterFromCloud,
|
|
202
|
+
input.hqRoot,
|
|
203
|
+
input.slug,
|
|
204
|
+
);
|
|
205
|
+
if (!refreshed) return local;
|
|
206
|
+
return resolveNameToEmail(
|
|
207
|
+
listCompanyPeople(input.hqRoot, input.slug),
|
|
208
|
+
input.name,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export async function searchPeopleWithRosterFallback(input: {
|
|
213
|
+
hqRoot: string;
|
|
214
|
+
slug: string;
|
|
215
|
+
keyword: string;
|
|
216
|
+
opts?: PeopleLookupOpts;
|
|
217
|
+
refreshRoster?: RefreshPeopleRoster;
|
|
218
|
+
}): Promise<PersonRecord[]> {
|
|
219
|
+
const local = searchPeople(
|
|
220
|
+
listCompanyPeople(input.hqRoot, input.slug),
|
|
221
|
+
input.keyword,
|
|
222
|
+
);
|
|
223
|
+
if (local.length > 0 || input.opts?.localOnly) return local;
|
|
224
|
+
|
|
225
|
+
const refreshed = await tryRefreshRoster(
|
|
226
|
+
input.refreshRoster ?? refreshPeopleRosterFromCloud,
|
|
227
|
+
input.hqRoot,
|
|
228
|
+
input.slug,
|
|
229
|
+
);
|
|
230
|
+
if (!refreshed) return local;
|
|
231
|
+
return searchPeople(listCompanyPeople(input.hqRoot, input.slug), input.keyword);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function registerPeopleCommand(
|
|
235
|
+
program: Command,
|
|
236
|
+
deps: PeopleCommandDeps = {},
|
|
237
|
+
): void {
|
|
122
238
|
const people = program
|
|
123
239
|
.command("people")
|
|
124
240
|
.description(
|
|
@@ -170,12 +286,22 @@ export function registerPeopleCommand(program: Command): void {
|
|
|
170
286
|
.command("search <keyword>")
|
|
171
287
|
.description("Keyword search over people names and emails")
|
|
172
288
|
.option("--json", "Output JSON instead of a table")
|
|
173
|
-
.
|
|
289
|
+
.option(
|
|
290
|
+
"--local-only",
|
|
291
|
+
"Skip cloud fallback; search only the local people roster",
|
|
292
|
+
)
|
|
293
|
+
.action(async (keyword: string, opts: PeopleLookupOpts) => {
|
|
174
294
|
try {
|
|
175
295
|
const scope = people.opts() as PeopleScopeOpts;
|
|
176
296
|
const hqRoot = resolveHqRoot(scope);
|
|
177
297
|
const slug = resolveCompanySlug(hqRoot, scope.company);
|
|
178
|
-
const matches =
|
|
298
|
+
const matches = await searchPeopleWithRosterFallback({
|
|
299
|
+
hqRoot,
|
|
300
|
+
slug,
|
|
301
|
+
keyword,
|
|
302
|
+
opts,
|
|
303
|
+
refreshRoster: deps.refreshRoster,
|
|
304
|
+
});
|
|
179
305
|
|
|
180
306
|
if (opts.json) {
|
|
181
307
|
console.log(JSON.stringify(matches, null, 2));
|
|
@@ -195,12 +321,22 @@ export function registerPeopleCommand(program: Command): void {
|
|
|
195
321
|
.command("resolve <name>")
|
|
196
322
|
.description("Resolve a person name to their email address")
|
|
197
323
|
.option("--json", "Output JSON instead of plain text")
|
|
198
|
-
.
|
|
324
|
+
.option(
|
|
325
|
+
"--local-only",
|
|
326
|
+
"Skip cloud fallback; resolve only from the local people roster",
|
|
327
|
+
)
|
|
328
|
+
.action(async (name: string, opts: PeopleLookupOpts) => {
|
|
199
329
|
try {
|
|
200
330
|
const scope = people.opts() as PeopleScopeOpts;
|
|
201
331
|
const hqRoot = resolveHqRoot(scope);
|
|
202
332
|
const slug = resolveCompanySlug(hqRoot, scope.company);
|
|
203
|
-
const result =
|
|
333
|
+
const result = await resolvePersonWithRosterFallback({
|
|
334
|
+
hqRoot,
|
|
335
|
+
slug,
|
|
336
|
+
name,
|
|
337
|
+
opts,
|
|
338
|
+
refreshRoster: deps.refreshRoster,
|
|
339
|
+
});
|
|
204
340
|
|
|
205
341
|
if (opts.json) {
|
|
206
342
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describeSecretsScope,
|
|
5
|
+
formatSecretSaved,
|
|
6
|
+
formatSecretsListEmpty,
|
|
7
|
+
formatSecretsListHeader,
|
|
8
|
+
} from "./secrets-scope.js";
|
|
9
|
+
|
|
10
|
+
describe("describeSecretsScope", () => {
|
|
11
|
+
it("describes the personal vault", () => {
|
|
12
|
+
expect(
|
|
13
|
+
describeSecretsScope({ personal: true, companyUid: "prs_alice" }),
|
|
14
|
+
).toBe("your personal vault");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("describes a company by slug when present", () => {
|
|
18
|
+
expect(
|
|
19
|
+
describeSecretsScope({
|
|
20
|
+
personal: false,
|
|
21
|
+
companySlug: "acme",
|
|
22
|
+
companyUid: "cmp_01ABC",
|
|
23
|
+
}),
|
|
24
|
+
).toBe("company acme");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("describes a company by uid when no slug is present", () => {
|
|
28
|
+
expect(
|
|
29
|
+
describeSecretsScope({ personal: false, companyUid: "cmp_01ABC" }),
|
|
30
|
+
).toBe("company cmp_01ABC");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("formatSecretSaved", () => {
|
|
35
|
+
it("formats the set echo", () => {
|
|
36
|
+
expect(formatSecretSaved("MY_KEY", "your personal vault")).toBe(
|
|
37
|
+
"Secret 'MY_KEY' saved to your personal vault.",
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("formatSecretsListHeader", () => {
|
|
43
|
+
it("formats the list header", () => {
|
|
44
|
+
expect(formatSecretsListHeader("company acme")).toBe(
|
|
45
|
+
"Secrets for company acme:",
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("formatSecretsListEmpty", () => {
|
|
51
|
+
it("formats the empty list message", () => {
|
|
52
|
+
expect(formatSecretsListEmpty("your personal vault")).toBe(
|
|
53
|
+
"No secrets found for your personal vault.",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers describing WHICH secrets scope a command acted on, so `set` and
|
|
3
|
+
* `list` can echo it. Users were setting a secret in one scope (personal vs a
|
|
4
|
+
* company, or company A vs B) and listing another, then seeing "no secrets" with
|
|
5
|
+
* no indication the scopes differed (feedback_70e059da).
|
|
6
|
+
*/
|
|
7
|
+
export interface SecretsScopeRef {
|
|
8
|
+
/** True when --personal was used (caller's personal vault). */
|
|
9
|
+
personal: boolean;
|
|
10
|
+
/** The slug the user passed via --company, if any. */
|
|
11
|
+
companySlug?: string;
|
|
12
|
+
/** Resolved entity uid: prs_* for personal, cmp_* for a company. */
|
|
13
|
+
companyUid: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Human label for a secrets scope: "your personal vault" or "company <slug-or-uid>". */
|
|
17
|
+
export function describeSecretsScope(ref: SecretsScopeRef): string {
|
|
18
|
+
if (ref.personal) return "your personal vault";
|
|
19
|
+
return `company ${ref.companySlug ?? ref.companyUid}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function formatSecretSaved(name: string, scope: string): string {
|
|
23
|
+
return `Secret '${name}' saved to ${scope}.`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function formatSecretsListHeader(scope: string): string {
|
|
27
|
+
return `Secrets for ${scope}:`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function formatSecretsListEmpty(scope: string): string {
|
|
31
|
+
return `No secrets found for ${scope}.`;
|
|
32
|
+
}
|
package/src/commands/secrets.ts
CHANGED
|
@@ -13,6 +13,12 @@ import {
|
|
|
13
13
|
} from "../utils/secrets-cache.js";
|
|
14
14
|
import { computeSha256 } from "../utils/integrity.js";
|
|
15
15
|
import { SECRET_NAME_PATTERN, GROUP_ID_PATTERN } from "./_patterns.js";
|
|
16
|
+
import {
|
|
17
|
+
describeSecretsScope,
|
|
18
|
+
formatSecretSaved,
|
|
19
|
+
formatSecretsListEmpty,
|
|
20
|
+
formatSecretsListHeader,
|
|
21
|
+
} from "./secrets-scope.js";
|
|
16
22
|
import {
|
|
17
23
|
vaultApiFetch,
|
|
18
24
|
getCompanyUid,
|
|
@@ -506,10 +512,13 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
506
512
|
}
|
|
507
513
|
|
|
508
514
|
const token = await ensureCognitoToken();
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
515
|
+
const scope = scopeOpts(secrets.opts());
|
|
516
|
+
const companyUid = await getEntityUid(token, scope);
|
|
517
|
+
const scopeLabel = describeSecretsScope({
|
|
518
|
+
personal: scope.personal,
|
|
519
|
+
companySlug: scope.companySlug,
|
|
520
|
+
companyUid,
|
|
521
|
+
});
|
|
513
522
|
|
|
514
523
|
const res = await vaultApiFetch({
|
|
515
524
|
token,
|
|
@@ -527,7 +536,7 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
527
536
|
}
|
|
528
537
|
|
|
529
538
|
removeCacheEntry(companyUid, name);
|
|
530
|
-
console.log(chalk.green(
|
|
539
|
+
console.log(chalk.green(formatSecretSaved(name, scopeLabel)));
|
|
531
540
|
} catch (err) {
|
|
532
541
|
console.error(
|
|
533
542
|
chalk.red("Error:"),
|
|
@@ -703,10 +712,13 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
703
712
|
}
|
|
704
713
|
|
|
705
714
|
const token = await ensureCognitoToken();
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
715
|
+
const scope = scopeOpts(secrets.opts());
|
|
716
|
+
const companyUid = await getEntityUid(token, scope);
|
|
717
|
+
const scopeLabel = describeSecretsScope({
|
|
718
|
+
personal: scope.personal,
|
|
719
|
+
companySlug: scope.companySlug,
|
|
720
|
+
companyUid,
|
|
721
|
+
});
|
|
710
722
|
|
|
711
723
|
const query: Record<string, string> = {};
|
|
712
724
|
if (normalizedPrefix) {
|
|
@@ -739,7 +751,7 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
739
751
|
};
|
|
740
752
|
|
|
741
753
|
if (data.secrets.length === 0) {
|
|
742
|
-
console.log(chalk.dim(
|
|
754
|
+
console.log(chalk.dim(formatSecretsListEmpty(scopeLabel)));
|
|
743
755
|
return;
|
|
744
756
|
}
|
|
745
757
|
|
|
@@ -756,6 +768,7 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
756
768
|
if (hasPermission) {
|
|
757
769
|
const accessWidth = Math.max(6, ...data.secrets.map((s) => (s.permission ?? "-").length));
|
|
758
770
|
const header = `${"NAME".padEnd(nameWidth)} ${"ACCESS".padEnd(accessWidth)} ${"TIER".padEnd(tierWidth)} ${"SCRIPT LOCK".padEnd(scriptLockWidth)} LAST MODIFIED`;
|
|
771
|
+
console.log(chalk.dim(formatSecretsListHeader(scopeLabel)));
|
|
759
772
|
console.log(chalk.bold(header));
|
|
760
773
|
for (const s of data.secrets) {
|
|
761
774
|
const access = s.permission ?? "-";
|
|
@@ -766,6 +779,7 @@ export function registerSecretsCommand(program: Command): void {
|
|
|
766
779
|
}
|
|
767
780
|
} else {
|
|
768
781
|
const header = `${"NAME".padEnd(nameWidth)} ${"TIER".padEnd(tierWidth)} ${"SCRIPT LOCK".padEnd(scriptLockWidth)} LAST MODIFIED`;
|
|
782
|
+
console.log(chalk.dim(formatSecretsListHeader(scopeLabel)));
|
|
769
783
|
console.log(chalk.bold(header));
|
|
770
784
|
for (const s of data.secrets) {
|
|
771
785
|
const tier = normalizeSecretTier(s.tier);
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* HQ CLI - Module management, package management, and cloud sync for HQ
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
// MUST be first: guard the Node version before any dependency that needs a
|
|
8
|
+
// Node 20+ API (e.g. util.styleText) or a newer native ABI is evaluated.
|
|
9
|
+
import "./node-preflight.js";
|
|
7
10
|
import { Command } from "commander";
|
|
8
11
|
import { initSentry, Sentry } from "./sentry.js";
|
|
9
12
|
import { registerAddCommand } from "./commands/add.js";
|
|
@@ -47,6 +50,8 @@ import { registerRescueCommand } from "./commands/rescue.js";
|
|
|
47
50
|
import { registerMcpCommand } from "./commands/mcp-status.js";
|
|
48
51
|
import { sanitizeArgv } from "./utils/feedback-diagnostics.js";
|
|
49
52
|
import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
|
|
53
|
+
import { isEpipe } from "./utils/epipe.js";
|
|
54
|
+
import { isInterceptedProcessExit } from "./utils/intercepted-process-exit.js";
|
|
50
55
|
import {
|
|
51
56
|
maybeWarnNewVersion,
|
|
52
57
|
refreshVersionCache,
|
|
@@ -57,9 +62,13 @@ import {
|
|
|
57
62
|
} from "./utils/version-gate.js";
|
|
58
63
|
import { CLI_VERSION } from "./cli-version.js";
|
|
59
64
|
|
|
60
|
-
// Swallow EPIPE when a downstream reader (e.g. `source <(…)`, `| head`) closes
|
|
65
|
+
// Swallow EPIPE when a downstream reader (e.g. `source <(…)`, `| head`) closes
|
|
66
|
+
// the pipe early. This covers the ASYNC path — an 'error' event emitted on the
|
|
67
|
+
// stream. The SYNCHRONOUS path (a `write EPIPE` thrown straight out of
|
|
68
|
+
// console.log inside a command) is handled in the top-level catch below; both
|
|
69
|
+
// share `isEpipe` (HQ-6B).
|
|
61
70
|
const onPipeError = (err: NodeJS.ErrnoException): void => {
|
|
62
|
-
if (err
|
|
71
|
+
if (isEpipe(err)) {
|
|
63
72
|
process.exit(0);
|
|
64
73
|
}
|
|
65
74
|
throw err;
|
|
@@ -222,18 +231,37 @@ registerMcpCommand(program);
|
|
|
222
231
|
}
|
|
223
232
|
await program.parseAsync();
|
|
224
233
|
} catch (err) {
|
|
225
|
-
// A
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
if (
|
|
232
|
-
process.
|
|
234
|
+
// A broken pipe (EPIPE) means the reader of `hq`'s output closed it early
|
|
235
|
+
// (`hq … | head`, `source <(hq …)`, a parent that exited). That is normal
|
|
236
|
+
// Unix behavior with no user-facing degradation — exit cleanly (0) and
|
|
237
|
+
// skip Sentry capture instead of shipping a fatal (HQ-6B). A synchronous
|
|
238
|
+
// `write EPIPE` thrown out of console.log lands here rather than on the
|
|
239
|
+
// stream 'error' listener above.
|
|
240
|
+
if (isEpipe(err)) {
|
|
241
|
+
process.exitCode = 0;
|
|
242
|
+
} else if (isInterceptedProcessExit(err)) {
|
|
243
|
+
// A security/audit FUZZ harness replaced `process.exit` with a throw so it
|
|
244
|
+
// can keep exercising the binary. Commander calling `process.exit` for
|
|
245
|
+
// normal CLI control flow (e.g. an unknown command → exit 1) then surfaces
|
|
246
|
+
// here as that synthetic marker. It is a test-harness artifact, NOT an
|
|
247
|
+
// hq-cli defect — a real user's `process.exit` just exits, so nothing is
|
|
248
|
+
// thrown or captured. Skip Sentry capture (no signal, no user-facing
|
|
249
|
+
// degradation) and preserve the intended non-zero exit (HQ-CLI-3).
|
|
250
|
+
process.exitCode = 1;
|
|
233
251
|
} else {
|
|
234
|
-
|
|
252
|
+
// A full disk / exhausted quota / read-only filesystem is the user's
|
|
253
|
+
// machine, not an HQ code defect. Surface a clear, actionable message and
|
|
254
|
+
// skip Sentry capture so one full disk doesn't flood the tracker with
|
|
255
|
+
// identical, unfixable crash reports (HQ-CLI-2). Genuine errors still go
|
|
256
|
+
// to Sentry and still exit 1.
|
|
257
|
+
const envMsg = environmentalFsErrorMessage(err);
|
|
258
|
+
if (envMsg) {
|
|
259
|
+
process.stderr.write(`hq: ${envMsg}\n`);
|
|
260
|
+
} else {
|
|
261
|
+
Sentry.captureException(err);
|
|
262
|
+
}
|
|
263
|
+
process.exitCode = 1;
|
|
235
264
|
}
|
|
236
|
-
process.exitCode = 1;
|
|
237
265
|
} finally {
|
|
238
266
|
// Release health: finalize the per-run session before the flush.
|
|
239
267
|
Sentry.endSession();
|