@indigoai-us/hq-cli 5.16.0 → 5.17.0-sources-rc.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.
Files changed (37) hide show
  1. package/.github/workflows/ci.yml +8 -4
  2. package/.github/workflows/publish.yml +8 -3
  3. package/dist/cli-version.d.ts +1 -0
  4. package/dist/cli-version.js +3 -2
  5. package/dist/commands/groups.js +6 -6
  6. package/dist/commands/meetings.js +8 -8
  7. package/dist/commands/members.d.ts +4 -2
  8. package/dist/commands/members.js +30 -14
  9. package/dist/commands/signals.d.ts +24 -0
  10. package/dist/commands/signals.js +240 -0
  11. package/dist/commands/sources.d.ts +22 -0
  12. package/dist/commands/sources.js +250 -0
  13. package/dist/index.js +8 -2
  14. package/dist/utils/cognito-session.d.ts +10 -1
  15. package/dist/utils/cognito-session.js +18 -3
  16. package/package.json +5 -4
  17. package/scripts/smoke-sources-signals.sh +103 -0
  18. package/src/cli-version.ts +5 -1
  19. package/src/commands/groups.ts +4 -4
  20. package/src/commands/meetings.ts +6 -6
  21. package/src/commands/members.test.ts +56 -0
  22. package/src/commands/members.ts +44 -13
  23. package/src/commands/signals.ts +345 -0
  24. package/src/commands/sources.ts +356 -0
  25. package/src/index.ts +8 -0
  26. package/src/utils/cognito-session.test.ts +24 -1
  27. package/src/utils/cognito-session.ts +18 -0
  28. package/test/commands/signals.test.ts +200 -0
  29. package/test/commands/sources.test.ts +225 -0
  30. package/test/fixtures/signals/action_item/sample.md +16 -0
  31. package/test/fixtures/signals/summary/sample.md +12 -0
  32. package/test/fixtures/sources/meetings/sample.md +25 -0
  33. package/test/helpers/cli-runner.ts +150 -0
  34. package/test/helpers/s3-list-mock.ts +79 -0
  35. package/test/helpers/vault-service-mock.ts +160 -0
  36. package/test/sources-signals/smoke.test.ts +226 -0
  37. package/vitest.config.ts +11 -0
@@ -10,12 +10,16 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v4
13
+ - uses: pnpm/action-setup@v4
14
+ with:
15
+ version: 10
13
16
  - uses: actions/setup-node@v4
14
17
  with:
15
18
  node-version: 22
16
- - run: npm ci
19
+ cache: pnpm
20
+ - run: pnpm install --frozen-lockfile --config.minimumReleaseAge=1440
17
21
  # generate-dsn.mjs only fatals when GITHUB_JOB=publish, so CI builds with
18
22
  # an empty BUNDLED_DSN. That's intentional — the DSN is publish-only.
19
- - run: npm run build --if-present
20
- - run: npm run typecheck --if-present
21
- - run: npm test --if-present
23
+ - run: pnpm run build
24
+ - run: pnpm run typecheck
25
+ - run: pnpm test
@@ -11,6 +11,9 @@ jobs:
11
11
  id-token: write
12
12
  steps:
13
13
  - uses: actions/checkout@v4
14
+ - uses: pnpm/action-setup@v4
15
+ with:
16
+ version: 10
14
17
  - uses: actions/setup-node@v4
15
18
  with:
16
19
  # Node 24 ships npm 11.x, required for npm's trusted-publisher OIDC
@@ -18,12 +21,14 @@ jobs:
18
21
  # rationale (npm 10.x produces masked-404 failures on publish PUT).
19
22
  node-version: 24
20
23
  registry-url: https://registry.npmjs.org
24
+ cache: pnpm
21
25
 
22
- - run: node --version && npm --version
23
- - run: npm ci
26
+ - run: node --version && npm --version && pnpm --version
27
+ # Install with pnpm (supply-chain policy); npm publish keeps OIDC.
28
+ - run: pnpm install --frozen-lockfile --config.minimumReleaseAge=1440
24
29
 
25
30
  - name: Build
26
- run: npm run build --if-present
31
+ run: pnpm run build
27
32
  env:
28
33
  # generate-dsn.mjs fatals when GITHUB_JOB=publish and this var is
29
34
  # missing. Set this as a repo secret to bundle a Sentry DSN into the
@@ -1,2 +1,3 @@
1
+ export declare const CLI_NAME: string;
1
2
  export declare const CLI_VERSION: string;
2
3
  //# sourceMappingURL=cli-version.d.ts.map
@@ -1,11 +1,12 @@
1
1
 
2
- !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]="9d613278-0268-5da9-a6d0-f1b4f15d405a")}catch(e){}}();
2
+ !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]="3e4e6f0a-40ac-5bee-b3c0-547fffb71ea5")}catch(e){}}();
3
3
  import { readFileSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import path from "node:path";
6
6
  const here = path.dirname(fileURLToPath(import.meta.url));
7
7
  const pkgPath = path.resolve(here, "..", "package.json");
8
8
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
9
+ export const CLI_NAME = pkg.name;
9
10
  export const CLI_VERSION = pkg.version;
10
11
  //# sourceMappingURL=cli-version.js.map
11
- //# debugId=9d613278-0268-5da9-a6d0-f1b4f15d405a
12
+ //# debugId=3e4e6f0a-40ac-5bee-b3c0-547fffb71ea5
@@ -1,5 +1,5 @@
1
1
 
2
- !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]="37e6bf57-eabb-58da-874c-57cc39e78d89")}catch(e){}}();
2
+ !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]="35b60d26-d8e7-5c10-9ad4-db53285eaaf0")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
5
  import { vaultApiFetch, getCompanyUid } from "./secrets.js";
@@ -58,7 +58,7 @@ export function registerGroupsCommand(program) {
58
58
  console.error(chalk.red("Not authenticated — please run `hq login`"));
59
59
  }
60
60
  else if (res.status === 403) {
61
- console.error(chalk.red("Not authorized — owner or admin role required"));
61
+ console.error(chalk.red("Not authorized — owner role required"));
62
62
  }
63
63
  else if (res.status === 409) {
64
64
  console.error(chalk.red(`Group already exists: ${groupId}`));
@@ -102,7 +102,7 @@ export function registerGroupsCommand(program) {
102
102
  console.error(chalk.red("Not authenticated — please run `hq login`"));
103
103
  }
104
104
  else if (res.status === 403) {
105
- console.error(chalk.red("Not authorized — owner or admin role required"));
105
+ console.error(chalk.red("Not authorized — owner role required"));
106
106
  }
107
107
  else if (res.status === 404) {
108
108
  console.error(chalk.red(`Group not found: ${groupId}`));
@@ -151,7 +151,7 @@ export function registerGroupsCommand(program) {
151
151
  console.error(chalk.red("Not authenticated — please run `hq login`"));
152
152
  }
153
153
  else if (res.status === 403) {
154
- console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
154
+ console.error(chalk.red("Not authorized — owner role or group creator required"));
155
155
  }
156
156
  else if (res.status === 404) {
157
157
  // Server provides a helpful message (email not found vs group not found)
@@ -205,7 +205,7 @@ export function registerGroupsCommand(program) {
205
205
  console.error(chalk.red("Not authenticated — please run `hq login`"));
206
206
  }
207
207
  else if (res.status === 403) {
208
- console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
208
+ console.error(chalk.red("Not authorized — owner role or group creator required"));
209
209
  }
210
210
  else if (res.status === 404) {
211
211
  console.error(chalk.red(err.error ?? `Not found`));
@@ -345,4 +345,4 @@ export function registerGroupsCommand(program) {
345
345
  });
346
346
  }
347
347
  //# sourceMappingURL=groups.js.map
348
- //# debugId=37e6bf57-eabb-58da-874c-57cc39e78d89
348
+ //# debugId=35b60d26-d8e7-5c10-9ad4-db53285eaaf0
@@ -1,8 +1,8 @@
1
1
 
2
- !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]="8237a835-5842-52be-bb27-c4ffb7944d89")}catch(e){}}();
2
+ !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]="e1c09963-744f-5033-9981-1ab6d37956e9")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
- import { vaultApiFetch } from "../utils/vault-api.js";
5
+ import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
6
6
  function formatDuration(seconds) {
7
7
  const h = Math.floor(seconds / 3600);
8
8
  const m = Math.floor((seconds % 3600) / 60);
@@ -132,7 +132,7 @@ export function registerMeetingsCommand(program) {
132
132
  if (opts.next)
133
133
  query.nextToken = opts.next;
134
134
  if (companySlug)
135
- query.companyId = companySlug;
135
+ query.companyId = await getCompanyUid(token, companySlug);
136
136
  const res = await vaultApiFetch({ token, path: "/v1/meetings", query });
137
137
  if (!res.ok)
138
138
  await handleApiError(res);
@@ -163,7 +163,7 @@ export function registerMeetingsCommand(program) {
163
163
  const query = {};
164
164
  const companySlug = meetings.opts().company;
165
165
  if (companySlug)
166
- query.companyId = companySlug;
166
+ query.companyId = await getCompanyUid(token, companySlug);
167
167
  const meetingId = await resolveShortId(token, rawId, query);
168
168
  const res = await vaultApiFetch({
169
169
  token,
@@ -217,7 +217,7 @@ export function registerMeetingsCommand(program) {
217
217
  const params = { q: query };
218
218
  const companySlug = meetings.opts().company;
219
219
  if (companySlug)
220
- params.companyId = companySlug;
220
+ params.companyId = await getCompanyUid(token, companySlug);
221
221
  const res = await vaultApiFetch({
222
222
  token,
223
223
  path: "/v1/meetings/search",
@@ -249,7 +249,7 @@ export function registerMeetingsCommand(program) {
249
249
  const query = {};
250
250
  const companySlug = meetings.opts().company;
251
251
  if (companySlug)
252
- query.companyId = companySlug;
252
+ query.companyId = await getCompanyUid(token, companySlug);
253
253
  const meetingId = await resolveShortId(token, rawId, query);
254
254
  const res = await vaultApiFetch({
255
255
  token,
@@ -299,7 +299,7 @@ export function registerMeetingsCommand(program) {
299
299
  const query = {};
300
300
  const companySlug = meetings.opts().company;
301
301
  if (companySlug)
302
- query.companyId = companySlug;
302
+ query.companyId = await getCompanyUid(token, companySlug);
303
303
  const meetingId = await resolveShortId(token, rawId, query);
304
304
  const res = await vaultApiFetch({
305
305
  token,
@@ -371,4 +371,4 @@ export function registerMeetingsCommand(program) {
371
371
  });
372
372
  }
373
373
  //# sourceMappingURL=meetings.js.map
374
- //# debugId=8237a835-5842-52be-bb27-c4ffb7944d89
374
+ //# debugId=e1c09963-744f-5033-9981-1ab6d37956e9
@@ -26,6 +26,7 @@ export interface InviteResult {
26
26
  membership: {
27
27
  role: string;
28
28
  status: string;
29
+ inviteToken?: string;
29
30
  };
30
31
  }
31
32
  export interface DetectedTarget {
@@ -44,9 +45,10 @@ export declare function getCallerPersonUid(token: string): Promise<string>;
44
45
  export declare function inviteMember(options: InviteOptions): Promise<InviteResult>;
45
46
  export declare class InviteHttpError extends Error {
46
47
  status: number;
47
- constructor(status: number, message: string);
48
+ code?: string | undefined;
49
+ constructor(status: number, message: string, code?: string | undefined);
48
50
  }
49
- export declare function formatInviteHttpError(status: number, fallback: string): string;
51
+ export declare function formatInviteHttpError(status: number, fallback: string, code?: string): string;
50
52
  export declare function listPendingInvites(token: string, companyUid: string): Promise<PendingInvite[]>;
51
53
  export declare function revokeInvite(token: string, tokenOrKey: string, companyUid: string): Promise<void>;
52
54
  export declare function registerMembersCommand(program: Command): void;
@@ -1,5 +1,5 @@
1
1
 
2
- !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]="1b3646e3-32c8-5601-9dba-1d7c0f6cf972")}catch(e){}}();
2
+ !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]="5f8b5b62-a00e-5ca3-b293-23906579a464")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
5
  import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
@@ -69,27 +69,41 @@ export async function inviteMember(options) {
69
69
  });
70
70
  if (!res.ok) {
71
71
  const err = (await res.json().catch(() => ({})));
72
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
72
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
73
73
  }
74
74
  const data = (await res.json());
75
+ // The token may arrive at the response root OR nested on the membership row,
76
+ // depending on vault-service version. Resolve from either; never emit
77
+ // `hq://accept/undefined` (a broken link that looks like success).
78
+ const inviteToken = data.inviteToken ?? data.membership?.inviteToken;
79
+ if (!inviteToken) {
80
+ const keys = Object.keys(data ?? {}).join(", ") || "<empty>";
81
+ throw new Error(`Invite was created but the server response did not include an invite token (response keys: ${keys}). ` +
82
+ "Run `hq members list` to retrieve the pending invite, or upgrade hq.");
83
+ }
75
84
  return {
76
- inviteToken: data.inviteToken,
77
- magicLink: `hq://accept/${data.inviteToken}`,
78
- membership: data.membership,
85
+ inviteToken,
86
+ magicLink: `hq://accept/${inviteToken}`,
87
+ membership: data.membership ?? { role: options.role, status: "pending" },
79
88
  };
80
89
  }
81
90
  export class InviteHttpError extends Error {
82
91
  status;
83
- constructor(status, message) {
92
+ code;
93
+ constructor(status, message, code) {
84
94
  super(message);
85
95
  this.status = status;
96
+ this.code = code;
86
97
  this.name = "InviteHttpError";
87
98
  }
88
99
  }
89
- export function formatInviteHttpError(status, fallback) {
100
+ export function formatInviteHttpError(status, fallback, code) {
90
101
  if (status === 401)
91
102
  return "Not authenticated — please run `hq login`";
92
103
  if (status === 403) {
104
+ if (code === "ADMIN_ROLE_TARGET_RESTRICTED") {
105
+ return "Admin can only invite at role=member; ask an owner to invite at this role";
106
+ }
93
107
  return "Not authorized — only admins and owners can invite members";
94
108
  }
95
109
  if (status === 409) {
@@ -106,10 +120,10 @@ export async function listPendingInvites(token, companyUid) {
106
120
  });
107
121
  if (!res.ok) {
108
122
  const err = (await res.json().catch(() => ({})));
109
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
123
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
110
124
  }
111
125
  const data = (await res.json());
112
- return data.invites;
126
+ return data?.invites ?? [];
113
127
  }
114
128
  export async function revokeInvite(token, tokenOrKey, companyUid) {
115
129
  const res = await vaultApiFetch({
@@ -120,7 +134,7 @@ export async function revokeInvite(token, tokenOrKey, companyUid) {
120
134
  });
121
135
  if (!res.ok) {
122
136
  const err = (await res.json().catch(() => ({})));
123
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
137
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
124
138
  }
125
139
  }
126
140
  export function registerMembersCommand(program) {
@@ -156,7 +170,7 @@ export function registerMembersCommand(program) {
156
170
  }
157
171
  catch (err) {
158
172
  if (err instanceof InviteHttpError) {
159
- console.error(chalk.red(formatInviteHttpError(err.status, err.message)));
173
+ console.error(chalk.red(formatInviteHttpError(err.status, err.message, err.code)));
160
174
  process.exit(1);
161
175
  }
162
176
  console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
@@ -224,10 +238,12 @@ export function registerMembersCommand(program) {
224
238
  catch (err) {
225
239
  if (err instanceof InviteHttpError) {
226
240
  const msg = err.status === 403
227
- ? "Not authorized — only admins and owners can revoke invites"
241
+ ? err.code === "ADMIN_ROLE_TARGET_RESTRICTED"
242
+ ? "Admin can only revoke role=member; ask an owner to revoke this membership"
243
+ : "Not authorized — only admins and owners can revoke invites"
228
244
  : err.status === 404
229
245
  ? "Invite not found — it may have already been accepted or revoked"
230
- : formatInviteHttpError(err.status, err.message);
246
+ : formatInviteHttpError(err.status, err.message, err.code);
231
247
  console.error(chalk.red(msg));
232
248
  process.exit(1);
233
249
  }
@@ -237,4 +253,4 @@ export function registerMembersCommand(program) {
237
253
  });
238
254
  }
239
255
  //# sourceMappingURL=members.js.map
240
- //# debugId=1b3646e3-32c8-5601-9dba-1d7c0f6cf972
256
+ //# debugId=5f8b5b62-a00e-5ca3-b293-23906579a464
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `hq signals` subcommand group (US-007).
3
+ *
4
+ * Read-side surface over the signals written by sources-pipeline (and any
5
+ * future signal producer). Each invocation resolves a Cognito access
6
+ * token (or honors HQ_ACCESS_TOKEN), vends STS-scoped credentials via
7
+ * vault-service for the requested entity, and delegates to hq-cloud's
8
+ * listSignals/getSignal primitives.
9
+ *
10
+ * Subcommands:
11
+ * hq signals list List signals of a given type for an entity.
12
+ * hq signals get Fetch one signal by id.
13
+ * hq signals types Print the canonical SIGNAL_TYPES enum.
14
+ * hq signals entities List entities the caller has access to.
15
+ *
16
+ * Mirrors `hq sources` exactly — same flags, same TTY-aware defaults,
17
+ * same error/Sentry plumbing. Defense-in-depth signal-type validation
18
+ * (assertSignalType) runs at the CLI layer as well as in hq-cloud, so
19
+ * agents can't fabricate a signal type even if they bypass the CLI's
20
+ * --type flag parsing.
21
+ */
22
+ import { Command } from "commander";
23
+ export declare function registerSignalsCommand(program: Command): void;
24
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1,240 @@
1
+ /**
2
+ * `hq signals` subcommand group (US-007).
3
+ *
4
+ * Read-side surface over the signals written by sources-pipeline (and any
5
+ * future signal producer). Each invocation resolves a Cognito access
6
+ * token (or honors HQ_ACCESS_TOKEN), vends STS-scoped credentials via
7
+ * vault-service for the requested entity, and delegates to hq-cloud's
8
+ * listSignals/getSignal primitives.
9
+ *
10
+ * Subcommands:
11
+ * hq signals list List signals of a given type for an entity.
12
+ * hq signals get Fetch one signal by id.
13
+ * hq signals types Print the canonical SIGNAL_TYPES enum.
14
+ * hq signals entities List entities the caller has access to.
15
+ *
16
+ * Mirrors `hq sources` exactly — same flags, same TTY-aware defaults,
17
+ * same error/Sentry plumbing. Defense-in-depth signal-type validation
18
+ * (assertSignalType) runs at the CLI layer as well as in hq-cloud, so
19
+ * agents can't fabricate a signal type even if they bypass the CLI's
20
+ * --type flag parsing.
21
+ */
22
+
23
+ !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]="2088e3af-a005-57eb-b642-90aca198460b")}catch(e){}}();
24
+ import * as fs from "node:fs";
25
+ import * as path from "node:path";
26
+ import chalk from "chalk";
27
+ import { SIGNAL_TYPES, assertSignalType, resolveEntity, listAvailableEntities, listSignals, getSignal, } from "@indigoai-us/hq-cloud";
28
+ import { ensureCognitoToken, buildVaultConfig, DEFAULT_HQ_ROOT, } from "../utils/cognito-session.js";
29
+ import { Sentry } from "../sentry.js";
30
+ // ---------------------------------------------------------------------------
31
+ // Access token resolution — honors HQ_ACCESS_TOKEN for tests + CI smoke
32
+ // ---------------------------------------------------------------------------
33
+ async function resolveAccessToken() {
34
+ if (process.env.HQ_ACCESS_TOKEN)
35
+ return process.env.HQ_ACCESS_TOKEN;
36
+ return ensureCognitoToken();
37
+ }
38
+ // ---------------------------------------------------------------------------
39
+ // Entity resolution — flag → .hq/config.json activeCompany fallback
40
+ // ---------------------------------------------------------------------------
41
+ function readActiveCompanySlug(hqRoot) {
42
+ const configPath = path.join(hqRoot, ".hq", "config.json");
43
+ if (!fs.existsSync(configPath))
44
+ return undefined;
45
+ try {
46
+ const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
47
+ const slug = cfg.activeCompany;
48
+ return typeof slug === "string" && slug.length > 0 ? slug : undefined;
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ }
54
+ function requireEntitySlug(flag, hqRoot) {
55
+ const slug = flag ?? readActiveCompanySlug(hqRoot);
56
+ if (!slug) {
57
+ throw new Error("No entity specified. Pass --entity <slug> or run `hq signals entities` to see your options.");
58
+ }
59
+ return slug;
60
+ }
61
+ function defaultListFormat() {
62
+ return process.stdout.isTTY ? "table" : "json";
63
+ }
64
+ function defaultGetFormat() {
65
+ return process.stdout.isTTY ? "markdown" : "json";
66
+ }
67
+ // ---------------------------------------------------------------------------
68
+ // Rendering helpers
69
+ // ---------------------------------------------------------------------------
70
+ function renderListTable(entries, includeFrontmatter) {
71
+ if (entries.length === 0)
72
+ return "(no signals)";
73
+ // sourceRef column is only meaningful when --include-frontmatter was passed;
74
+ // omit it otherwise so the table doesn't lie with empty cells.
75
+ const rows = entries.map((e) => ({
76
+ signalId: e.signalId,
77
+ ...(includeFrontmatter ? { sourceRef: e.sourceRef ?? "" } : {}),
78
+ lastModified: e.lastModified.toISOString(),
79
+ size: String(e.size),
80
+ }));
81
+ const headers = Object.keys(rows[0]);
82
+ const widths = headers.map((h) => Math.max(h.length, ...rows.map((r) => String(r[h]).length)));
83
+ const pad = (s, w) => s + " ".repeat(Math.max(0, w - s.length));
84
+ const headerLine = headers.map((h, i) => pad(h, widths[i])).join(" ");
85
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
86
+ const body = rows
87
+ .map((r) => headers.map((h, i) => pad(String(r[h]), widths[i])).join(" "))
88
+ .join("\n");
89
+ return [headerLine, sep, body].join("\n");
90
+ }
91
+ async function runList(options) {
92
+ if (!options.type) {
93
+ throw new Error(`--type <signalType> is required. Valid types: ${SIGNAL_TYPES.join(", ")}`);
94
+ }
95
+ // Throws InvalidSignalTypeError with the list of valid types if not in enum.
96
+ assertSignalType(options.type);
97
+ const signalType = options.type;
98
+ const slug = requireEntitySlug(options.entity, options.hqRoot);
99
+ const limit = options.limit ? Number.parseInt(options.limit, 10) : 50;
100
+ if (!Number.isFinite(limit) || limit <= 0) {
101
+ throw new Error(`--limit must be a positive integer (got '${options.limit}')`);
102
+ }
103
+ const format = options.format ?? defaultListFormat();
104
+ const accessToken = await resolveAccessToken();
105
+ const vaultConfig = buildVaultConfig(accessToken);
106
+ const entity = await resolveEntity({ slug, vaultConfig });
107
+ const result = await listSignals({
108
+ entity,
109
+ signalType,
110
+ limit,
111
+ continuationToken: options.pageToken,
112
+ includeFrontmatter: options.includeFrontmatter,
113
+ });
114
+ if (format === "json") {
115
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
116
+ return;
117
+ }
118
+ process.stdout.write(renderListTable(result.entries, !!options.includeFrontmatter) + "\n");
119
+ if (result.nextToken) {
120
+ process.stdout.write(`\nNext page token: ${result.nextToken}\n`);
121
+ }
122
+ }
123
+ async function runGet(options) {
124
+ if (!options.type) {
125
+ throw new Error(`--type <signalType> is required. Valid types: ${SIGNAL_TYPES.join(", ")}`);
126
+ }
127
+ if (!options.id) {
128
+ throw new Error("--id <signalId> is required.");
129
+ }
130
+ assertSignalType(options.type);
131
+ const signalType = options.type;
132
+ const slug = requireEntitySlug(options.entity, options.hqRoot);
133
+ const format = options.format ?? defaultGetFormat();
134
+ const accessToken = await resolveAccessToken();
135
+ const vaultConfig = buildVaultConfig(accessToken);
136
+ const entity = await resolveEntity({ slug, vaultConfig });
137
+ const doc = await getSignal({
138
+ entity,
139
+ signalType,
140
+ signalId: options.id,
141
+ });
142
+ if (format === "json") {
143
+ process.stdout.write(JSON.stringify(doc, null, 2) + "\n");
144
+ return;
145
+ }
146
+ // markdown: reconstruct frontmatter block + body so the output round-trips.
147
+ if (doc.frontmatter) {
148
+ const yamlLines = Object.entries(doc.frontmatter).map(([k, v]) => `${k}: ${typeof v === "string" ? v : JSON.stringify(v)}`);
149
+ process.stdout.write(`---\n${yamlLines.join("\n")}\n---\n\n${doc.body}\n`);
150
+ }
151
+ else {
152
+ process.stdout.write(doc.body + "\n");
153
+ }
154
+ }
155
+ // ---------------------------------------------------------------------------
156
+ // Subcommand: types
157
+ // ---------------------------------------------------------------------------
158
+ function runTypes() {
159
+ const sorted = [...SIGNAL_TYPES].sort();
160
+ process.stdout.write(sorted.join("\n") + "\n");
161
+ }
162
+ // ---------------------------------------------------------------------------
163
+ // Subcommand: entities (alias — identical to `hq sources entities`)
164
+ // ---------------------------------------------------------------------------
165
+ async function runEntities(options) {
166
+ const format = options.format ?? defaultListFormat();
167
+ const accessToken = await resolveAccessToken();
168
+ const vaultConfig = buildVaultConfig(accessToken);
169
+ const entities = await listAvailableEntities({ vaultConfig });
170
+ if (format === "json") {
171
+ process.stdout.write(JSON.stringify(entities, null, 2) + "\n");
172
+ return;
173
+ }
174
+ if (entities.length === 0) {
175
+ process.stdout.write("(no entities — your account has no active memberships)\n");
176
+ return;
177
+ }
178
+ const headers = ["slug", "role", "uid"];
179
+ const widths = headers.map((h, i) => Math.max(h.length, ...entities.map((e) => String([e.slug, e.role, e.uid][i]).length)));
180
+ const pad = (s, w) => s + " ".repeat(Math.max(0, w - s.length));
181
+ const headerLine = headers.map((h, i) => pad(h, widths[i])).join(" ");
182
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
183
+ const body = entities
184
+ .map((e) => [e.slug, e.role, e.uid].map((cell, i) => pad(cell, widths[i])).join(" "))
185
+ .join("\n");
186
+ process.stdout.write([headerLine, sep, body].join("\n") + "\n");
187
+ }
188
+ // ---------------------------------------------------------------------------
189
+ // Registration
190
+ // ---------------------------------------------------------------------------
191
+ /** Wrap an action so caught errors print red + capture to Sentry + exit 1. */
192
+ function withErrorHandling(fn) {
193
+ return async (...args) => {
194
+ try {
195
+ await fn(...args);
196
+ }
197
+ catch (err) {
198
+ const message = err instanceof Error ? err.message : String(err);
199
+ process.stderr.write(chalk.red(`✗ ${message}\n`));
200
+ Sentry.captureException(err);
201
+ process.exit(1);
202
+ }
203
+ };
204
+ }
205
+ export function registerSignalsCommand(program) {
206
+ const signals = program
207
+ .command("signals")
208
+ .description("Read signals (action_items, decisions, etc.) from a vault entity");
209
+ signals
210
+ .command("list")
211
+ .description("List signals of a given type for an entity")
212
+ .option("--entity <slug>", "Entity slug (defaults to .hq/config.json activeCompany)")
213
+ .option("--type <signalType>", `Signal type: ${SIGNAL_TYPES.join(" | ")}`)
214
+ .option("--limit <n>", "Max entries per page (default 50)")
215
+ .option("--page-token <token>", "Continuation token from a prior page")
216
+ .option("--format <fmt>", "Output format: table | json (default: table for TTY, json piped)")
217
+ .option("--include-frontmatter", "Fetch + parse each entry's frontmatter (extra GETs)")
218
+ .option("--hq-root <path>", `Local HQ tree root (for .hq/config.json lookup; default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
219
+ .action(withErrorHandling(async (options) => runList(options)));
220
+ signals
221
+ .command("get")
222
+ .description("Fetch a single signal by id")
223
+ .option("--entity <slug>", "Entity slug (defaults to .hq/config.json activeCompany)")
224
+ .option("--type <signalType>", `Signal type: ${SIGNAL_TYPES.join(" | ")}`)
225
+ .option("--id <signalId>", "Signal id (filename minus .md)")
226
+ .option("--format <fmt>", "Output format: markdown | json (default: markdown for TTY, json piped)")
227
+ .option("--hq-root <path>", `Local HQ tree root (for .hq/config.json lookup; default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
228
+ .action(withErrorHandling(async (options) => runGet(options)));
229
+ signals
230
+ .command("types")
231
+ .description("Print the canonical signal types (one per line)")
232
+ .action(withErrorHandling(() => runTypes()));
233
+ signals
234
+ .command("entities")
235
+ .description("List entities (companies/personal) your account has access to")
236
+ .option("--format <fmt>", "Output format: table | json (default: table for TTY, json piped)")
237
+ .action(withErrorHandling(async (options) => runEntities(options)));
238
+ }
239
+ //# sourceMappingURL=signals.js.map
240
+ //# debugId=2088e3af-a005-57eb-b642-90aca198460b
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `hq sources` subcommand group (US-006).
3
+ *
4
+ * Read-side surface over the sources written by sources-pipeline. Each
5
+ * invocation resolves a Cognito access token (or honors HQ_ACCESS_TOKEN),
6
+ * vends STS-scoped credentials via vault-service for the requested entity,
7
+ * and delegates to hq-cloud's listSources/getSource primitives.
8
+ *
9
+ * Subcommands:
10
+ * hq sources list List sources of a given channel for an entity.
11
+ * hq sources get Fetch one source by id.
12
+ * hq sources channels Print the canonical SOURCE_CHANNELS enum.
13
+ * hq sources entities List entities the caller has access to.
14
+ *
15
+ * Defaults:
16
+ * --entity falls back to .hq/config.json activeCompany (per sync.ts).
17
+ * --format 'table' when stdout is a TTY, 'json' when piped.
18
+ * --limit 50.
19
+ */
20
+ import { Command } from "commander";
21
+ export declare function registerSourcesCommand(program: Command): void;
22
+ //# sourceMappingURL=sources.d.ts.map