@indigoai-us/hq-cli 5.77.14 → 5.79.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 (309) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
  3. package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
  4. package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
  5. package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
  6. package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
  7. package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
  8. package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
  9. package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
  10. package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
  11. package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
  12. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
  13. package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
  14. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
  15. package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
  16. package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
  17. package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
  18. package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
  19. package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
  20. package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
  21. package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
  22. package/assets/scaffold/core/scripts/worktree.sh +136 -0
  23. package/dist/commands/agents.js +28 -12
  24. package/dist/commands/api-keys.js +100 -20
  25. package/dist/commands/core.d.ts +90 -0
  26. package/dist/commands/core.js +279 -0
  27. package/dist/commands/files-browse.d.ts +21 -0
  28. package/dist/commands/files-browse.js +145 -24
  29. package/dist/commands/files.js +33 -7
  30. package/dist/commands/meetings.js +16 -9
  31. package/dist/commands/members.js +16 -5
  32. package/dist/commands/pack-install.d.ts +14 -0
  33. package/dist/commands/pack-install.js +42 -2
  34. package/dist/commands/pkg-install.js +39 -2
  35. package/dist/commands/run.js +6 -2
  36. package/dist/commands/secrets.js +120 -65
  37. package/dist/main.js +6 -0
  38. package/dist/utils/api-key-command-gate.d.ts +45 -0
  39. package/dist/utils/api-key-command-gate.js +51 -0
  40. package/dist/utils/hq-roots.d.ts +91 -0
  41. package/dist/utils/hq-roots.js +212 -0
  42. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  43. package/dist/utils/resolve-vault-credential.js +152 -6
  44. package/dist/utils/run-bundled-script.d.ts +66 -0
  45. package/dist/utils/run-bundled-script.js +80 -0
  46. package/dist/utils/vault-api.d.ts +21 -0
  47. package/dist/utils/vault-api.js +74 -3
  48. package/package.json +7 -1
  49. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  50. package/.github/workflows/ci.yml +0 -46
  51. package/.github/workflows/publish.yml +0 -36
  52. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  53. package/e2e/cli.test.ts +0 -128
  54. package/eslint.config.js +0 -37
  55. package/pnpm-workspace.yaml +0 -4
  56. package/scripts/chmod-bins.mjs +0 -49
  57. package/scripts/generate-dsn.mjs +0 -26
  58. package/scripts/generate-scan-packages-table.mjs +0 -113
  59. package/scripts/smoke-sources-signals.sh +0 -103
  60. package/src/bin/hq-auth-refresh.ts +0 -43
  61. package/src/cli-version.ts +0 -13
  62. package/src/commands/__fixtures__/make-tar.ts +0 -126
  63. package/src/commands/_patterns.ts +0 -10
  64. package/src/commands/add.ts +0 -75
  65. package/src/commands/agents.test.ts +0 -527
  66. package/src/commands/agents.ts +0 -923
  67. package/src/commands/api-keys.test.ts +0 -291
  68. package/src/commands/api-keys.ts +0 -382
  69. package/src/commands/artifact-verify.test.ts +0 -177
  70. package/src/commands/auth.test.ts +0 -82
  71. package/src/commands/auth.ts +0 -213
  72. package/src/commands/billing.test.ts +0 -158
  73. package/src/commands/billing.ts +0 -146
  74. package/src/commands/channels.test.ts +0 -74
  75. package/src/commands/channels.ts +0 -91
  76. package/src/commands/cloud-demote.test.ts +0 -401
  77. package/src/commands/cloud-demote.ts +0 -278
  78. package/src/commands/cloud-provision.test.ts +0 -1117
  79. package/src/commands/cloud-provision.ts +0 -942
  80. package/src/commands/cloud.pull-all.test.ts +0 -711
  81. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  82. package/src/commands/cloud.push-all.test.ts +0 -485
  83. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  84. package/src/commands/cloud.selectors.test.ts +0 -208
  85. package/src/commands/cloud.status.test.ts +0 -160
  86. package/src/commands/cloud.test.ts +0 -41
  87. package/src/commands/cloud.ts +0 -2130
  88. package/src/commands/company.test.ts +0 -202
  89. package/src/commands/company.ts +0 -148
  90. package/src/commands/creators.test.ts +0 -60
  91. package/src/commands/creators.ts +0 -117
  92. package/src/commands/crm.test.ts +0 -179
  93. package/src/commands/crm.ts +0 -236
  94. package/src/commands/db-migrate.ts +0 -55
  95. package/src/commands/db-provision.ts +0 -114
  96. package/src/commands/db-sql.ts +0 -124
  97. package/src/commands/db-status.ts +0 -108
  98. package/src/commands/db.ts +0 -26
  99. package/src/commands/dm.test.ts +0 -748
  100. package/src/commands/dm.ts +0 -1226
  101. package/src/commands/feedback.test.ts +0 -413
  102. package/src/commands/feedback.ts +0 -169
  103. package/src/commands/files-browse.test.ts +0 -1249
  104. package/src/commands/files-browse.ts +0 -1506
  105. package/src/commands/files-delete.test.ts +0 -484
  106. package/src/commands/files-recovery.test.ts +0 -370
  107. package/src/commands/files.test.ts +0 -722
  108. package/src/commands/files.ts +0 -1446
  109. package/src/commands/group-grants.test.ts +0 -330
  110. package/src/commands/group-grants.ts +0 -455
  111. package/src/commands/groups.test.ts +0 -44
  112. package/src/commands/groups.ts +0 -368
  113. package/src/commands/integrations.test.ts +0 -633
  114. package/src/commands/integrations.ts +0 -507
  115. package/src/commands/list.ts +0 -85
  116. package/src/commands/login.ts +0 -52
  117. package/src/commands/logout.ts +0 -30
  118. package/src/commands/marketplace-install.test.ts +0 -543
  119. package/src/commands/marketplace-security.test.ts +0 -646
  120. package/src/commands/mcp-registration.test.ts +0 -2787
  121. package/src/commands/mcp-registration.ts +0 -2612
  122. package/src/commands/mcp-status.test.ts +0 -483
  123. package/src/commands/mcp-status.ts +0 -575
  124. package/src/commands/mcp-status.us011.test.ts +0 -243
  125. package/src/commands/meetings.test.ts +0 -522
  126. package/src/commands/meetings.ts +0 -789
  127. package/src/commands/members.test.ts +0 -1474
  128. package/src/commands/members.ts +0 -1181
  129. package/src/commands/onboard-identity-guard.test.ts +0 -99
  130. package/src/commands/onboard-identity-guard.ts +0 -103
  131. package/src/commands/onboard-join.test.ts +0 -96
  132. package/src/commands/onboard-join.ts +0 -101
  133. package/src/commands/onboard-warning.test.ts +0 -26
  134. package/src/commands/onboard-warning.ts +0 -12
  135. package/src/commands/onboard.ts +0 -267
  136. package/src/commands/outposts-heartbeat.test.ts +0 -299
  137. package/src/commands/outposts-heartbeat.ts +0 -310
  138. package/src/commands/outposts-replica-sync.test.ts +0 -272
  139. package/src/commands/outposts-self-deploy.test.ts +0 -243
  140. package/src/commands/outposts.test.ts +0 -1039
  141. package/src/commands/outposts.ts +0 -1935
  142. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  143. package/src/commands/pack-install.test.ts +0 -1469
  144. package/src/commands/pack-install.ts +0 -2256
  145. package/src/commands/pack-update-cache.test.ts +0 -149
  146. package/src/commands/packs-update-api-key.test.ts +0 -105
  147. package/src/commands/packs.test.ts +0 -88
  148. package/src/commands/packs.ts +0 -622
  149. package/src/commands/people.test.ts +0 -807
  150. package/src/commands/people.ts +0 -422
  151. package/src/commands/pkg-install.dispatch.test.ts +0 -103
  152. package/src/commands/pkg-install.ts +0 -221
  153. package/src/commands/pkg-list.test.ts +0 -79
  154. package/src/commands/pkg-list.ts +0 -13
  155. package/src/commands/pkg-remove.ts +0 -71
  156. package/src/commands/pkg-update.ts +0 -189
  157. package/src/commands/publish.test.ts +0 -650
  158. package/src/commands/publish.ts +0 -580
  159. package/src/commands/reindex.test.ts +0 -259
  160. package/src/commands/reindex.ts +0 -274
  161. package/src/commands/rescue.test.ts +0 -39
  162. package/src/commands/rescue.ts +0 -210
  163. package/src/commands/run.env-local.test.ts +0 -88
  164. package/src/commands/run.test.ts +0 -45
  165. package/src/commands/run.ts +0 -190
  166. package/src/commands/safe-extract.test.ts +0 -459
  167. package/src/commands/safe-extract.ts +0 -444
  168. package/src/commands/secrets-scope.test.ts +0 -56
  169. package/src/commands/secrets-scope.ts +0 -32
  170. package/src/commands/secrets.parse-destination.test.ts +0 -38
  171. package/src/commands/secrets.test.ts +0 -2050
  172. package/src/commands/secrets.ts +0 -2249
  173. package/src/commands/signals.ts +0 -351
  174. package/src/commands/skill.test.ts +0 -770
  175. package/src/commands/skill.ts +0 -796
  176. package/src/commands/sources.ts +0 -362
  177. package/src/commands/sync-mode.test.ts +0 -366
  178. package/src/commands/sync-mode.ts +0 -387
  179. package/src/commands/sync-narrow.test.ts +0 -633
  180. package/src/commands/sync-narrow.ts +0 -555
  181. package/src/commands/sync.ts +0 -165
  182. package/src/commands/team-sync.ts +0 -628
  183. package/src/commands/update.ts +0 -71
  184. package/src/commands/whoami.ts +0 -83
  185. package/src/commands/workers.test.ts +0 -158
  186. package/src/commands/workers.ts +0 -301
  187. package/src/index.test.ts +0 -32
  188. package/src/index.ts +0 -20
  189. package/src/lib/db/control-plane.test.ts +0 -59
  190. package/src/lib/db/control-plane.ts +0 -113
  191. package/src/lib/db/local.test.ts +0 -81
  192. package/src/lib/db/local.ts +0 -148
  193. package/src/lib/db/migrate.test.ts +0 -133
  194. package/src/lib/db/migrate.ts +0 -137
  195. package/src/lib/db/paths.test.ts +0 -112
  196. package/src/lib/db/paths.ts +0 -128
  197. package/src/lib/db/remote-engine.test.ts +0 -44
  198. package/src/lib/db/remote-engine.ts +0 -148
  199. package/src/lib/db/remote-sql.test.ts +0 -32
  200. package/src/lib/db/remote-sql.ts +0 -62
  201. package/src/lib/db/sql.test.ts +0 -106
  202. package/src/lib/db/sql.ts +0 -192
  203. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  204. package/src/lib/local-tree-diff.test.ts +0 -301
  205. package/src/lib/local-tree-diff.ts +0 -362
  206. package/src/lib/narrow-hint-banner.test.ts +0 -235
  207. package/src/lib/narrow-hint-banner.ts +0 -212
  208. package/src/lib/plan-limit-nag.test.ts +0 -317
  209. package/src/lib/plan-limit-nag.ts +0 -264
  210. package/src/main.ts +0 -371
  211. package/src/node-preflight.test.ts +0 -60
  212. package/src/node-preflight.ts +0 -67
  213. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  214. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  215. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  216. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  217. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  218. package/src/outpost/session-heartbeat.test.ts +0 -459
  219. package/src/outpost/session-heartbeat.ts +0 -877
  220. package/src/packaging.test.ts +0 -109
  221. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  222. package/src/run/discover-schemas.test.ts +0 -153
  223. package/src/run/discover-schemas.ts +0 -79
  224. package/src/run/hq-plugin.test.ts +0 -371
  225. package/src/run/hq-plugin.ts +0 -277
  226. package/src/run/varlock-shape.test.ts +0 -57
  227. package/src/schemas/hq-package.schema.json +0 -155
  228. package/src/sentry-before-send.test.ts +0 -359
  229. package/src/sentry-before-send.ts +0 -221
  230. package/src/sentry-epipe.test.ts +0 -37
  231. package/src/sentry-release.test.ts +0 -54
  232. package/src/sentry.test.ts +0 -24
  233. package/src/sentry.ts +0 -54
  234. package/src/strategies/link.ts +0 -62
  235. package/src/strategies/merge.ts +0 -142
  236. package/src/types.ts +0 -146
  237. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  238. package/src/utils/auth-error.test.ts +0 -40
  239. package/src/utils/auth-error.ts +0 -42
  240. package/src/utils/billing-gate.test.ts +0 -95
  241. package/src/utils/billing-gate.ts +0 -228
  242. package/src/utils/breadcrumb-buffer.ts +0 -18
  243. package/src/utils/cli-telemetry.test.ts +0 -153
  244. package/src/utils/cli-telemetry.ts +0 -61
  245. package/src/utils/cognito-session.machine.test.ts +0 -109
  246. package/src/utils/cognito-session.refresh.test.ts +0 -84
  247. package/src/utils/cognito-session.test.ts +0 -328
  248. package/src/utils/cognito-session.ts +0 -448
  249. package/src/utils/company-selection-error.test.ts +0 -42
  250. package/src/utils/company-selection-error.ts +0 -45
  251. package/src/utils/contribution-table.ts +0 -83
  252. package/src/utils/environmental-error.test.ts +0 -45
  253. package/src/utils/environmental-error.ts +0 -39
  254. package/src/utils/epipe.test.ts +0 -28
  255. package/src/utils/epipe.ts +0 -29
  256. package/src/utils/expected-cli-error.test.ts +0 -28
  257. package/src/utils/expected-cli-error.ts +0 -39
  258. package/src/utils/feedback-diagnostics.test.ts +0 -183
  259. package/src/utils/feedback-diagnostics.ts +0 -123
  260. package/src/utils/feedback-screenshots.test.ts +0 -134
  261. package/src/utils/feedback-screenshots.ts +0 -124
  262. package/src/utils/feedback-versions.test.ts +0 -98
  263. package/src/utils/feedback-versions.ts +0 -68
  264. package/src/utils/git.ts +0 -74
  265. package/src/utils/integrity.ts +0 -59
  266. package/src/utils/intercepted-process-exit.test.ts +0 -37
  267. package/src/utils/intercepted-process-exit.ts +0 -36
  268. package/src/utils/login-provider.test.ts +0 -42
  269. package/src/utils/login-provider.ts +0 -30
  270. package/src/utils/manifest.test.ts +0 -167
  271. package/src/utils/manifest.ts +0 -131
  272. package/src/utils/pack-contributions.test.ts +0 -603
  273. package/src/utils/pack-contributions.ts +0 -450
  274. package/src/utils/people.ts +0 -215
  275. package/src/utils/registry-client.ts +0 -204
  276. package/src/utils/registry.ts +0 -90
  277. package/src/utils/resolve-vault-credential.test.ts +0 -69
  278. package/src/utils/resolve-vault-credential.ts +0 -60
  279. package/src/utils/sandbox-runner-client.test.ts +0 -279
  280. package/src/utils/sandbox-runner-client.ts +0 -260
  281. package/src/utils/secrets-cache.ts +0 -183
  282. package/src/utils/sentry-identity.ts +0 -45
  283. package/src/utils/settle-with-timeout.test.ts +0 -21
  284. package/src/utils/settle-with-timeout.ts +0 -22
  285. package/src/utils/user-yaml-error.test.ts +0 -24
  286. package/src/utils/user-yaml-error.ts +0 -30
  287. package/src/utils/vault-api.test.ts +0 -536
  288. package/src/utils/vault-api.ts +0 -382
  289. package/src/utils/version-check.test.ts +0 -176
  290. package/src/utils/version-check.ts +0 -155
  291. package/src/utils/version-gate.test.ts +0 -1024
  292. package/src/utils/version-gate.ts +0 -702
  293. package/test/commands/db-tenant-isolation.test.ts +0 -94
  294. package/test/commands/db.test.ts +0 -85
  295. package/test/commands/signals.test.ts +0 -207
  296. package/test/commands/sources.test.ts +0 -231
  297. package/test/e2e/smoke-install-mcp.sh +0 -113
  298. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  299. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  300. package/test/fixtures/signals/action_item/sample.md +0 -16
  301. package/test/fixtures/signals/summary/sample.md +0 -12
  302. package/test/fixtures/sources/meetings/sample.md +0 -25
  303. package/test/helpers/cli-runner.ts +0 -150
  304. package/test/helpers/s3-list-mock.ts +0 -79
  305. package/test/helpers/vault-service-mock.ts +0 -295
  306. package/test/sources-signals/smoke.test.ts +0 -228
  307. package/tsconfig.json +0 -20
  308. package/vitest.config.ts +0 -11
  309. package/vitest.e2e.config.ts +0 -7
@@ -1,83 +0,0 @@
1
- /**
2
- * hq whoami — displays current user or 'not logged in'
3
- */
4
-
5
- import { Command } from 'commander';
6
- import chalk from 'chalk';
7
- import {
8
- loadCachedTokens,
9
- isExpiring,
10
- isMachineIdentity,
11
- loadMachineCreds,
12
- } from '@indigoai-us/hq-cloud';
13
-
14
- function peekIdToken(idToken: string): {
15
- email?: string;
16
- sub?: string;
17
- entityType?: string;
18
- entityUid?: string;
19
- } {
20
- try {
21
- const payload = idToken.split('.')[1];
22
- if (!payload) return {};
23
- const pad = payload.length % 4 === 0 ? '' : '='.repeat(4 - (payload.length % 4));
24
- const normalized = payload.replace(/-/g, '+').replace(/_/g, '/') + pad;
25
- const decoded = JSON.parse(Buffer.from(normalized, 'base64').toString('utf-8'));
26
- return {
27
- email: decoded.email,
28
- sub: decoded.sub,
29
- entityType: decoded['custom:entityType'],
30
- entityUid: decoded['custom:entityUid'],
31
- };
32
- } catch {
33
- return {};
34
- }
35
- }
36
-
37
- export function registerWhoamiCommand(program: Command): void {
38
- program
39
- .command('whoami')
40
- .description('Show the currently authenticated user')
41
- .action(async () => {
42
- try {
43
- const machine = isMachineIdentity();
44
- const cached = loadCachedTokens();
45
-
46
- if (machine) {
47
- // Machine identities (company agents) mint sessions on demand from
48
- // long-lived creds — report the machine identity honestly even when
49
- // no session is cached yet.
50
- const username = loadMachineCreds()?.username ?? 'unknown';
51
- const entityUid = cached
52
- ? peekIdToken(cached.idToken).entityUid
53
- : undefined;
54
- console.log(
55
- `Machine identity ${username}${entityUid ? ` (agent ${entityUid})` : ''} — sessions mint automatically`
56
- );
57
- return;
58
- }
59
-
60
- if (!cached) {
61
- console.log("Not logged in. Run 'hq login' to authenticate.");
62
- return;
63
- }
64
-
65
- if (isExpiring(cached, 0)) {
66
- const who = peekIdToken(cached.idToken).email ?? 'unknown';
67
- console.log(
68
- chalk.yellow(`Session expired for ${who}. Run 'hq login' to re-authenticate.`)
69
- );
70
- return;
71
- }
72
-
73
- const { email, sub } = peekIdToken(cached.idToken);
74
- console.log(`Logged in as ${email ?? 'unknown'}${sub ? ` (${sub})` : ''}`);
75
- } catch (error) {
76
- console.error(
77
- chalk.red('Error:'),
78
- error instanceof Error ? error.message : 'Unknown error'
79
- );
80
- process.exit(1);
81
- }
82
- });
83
- }
@@ -1,158 +0,0 @@
1
- /**
2
- * Unit tests for `hq workers` (workers.ts).
3
- *
4
- * Coverage:
5
- * - readWorkerRegistry — parses registry.yaml, empty when missing
6
- * - filterAccessibleWorkers — public always; company only for active company
7
- * - workerVaultPrefix — companies/{co}/workers/{id}/ -> workers/{id}/; null for public
8
- * - classifyPrincipal — @all | email | grp_ | invalid
9
- * - resolveActiveCompany — reads .current -> meta.yaml company_slug
10
- * - writeGrantSidecar — creates + unions .grants.yaml idempotently
11
- */
12
-
13
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
- import * as fs from "fs";
15
- import * as os from "os";
16
- import * as path from "path";
17
- import * as yaml from "js-yaml";
18
- import {
19
- readWorkerRegistry,
20
- filterAccessibleWorkers,
21
- workerVaultPrefix,
22
- classifyPrincipal,
23
- resolveActiveCompany,
24
- writeGrantSidecar,
25
- type RegistryWorker,
26
- } from "./workers.js";
27
-
28
- let hqRoot: string;
29
-
30
- function writeRegistry(workers: RegistryWorker[]): void {
31
- const p = path.join(hqRoot, "core/workers/registry.yaml");
32
- fs.mkdirSync(path.dirname(p), { recursive: true });
33
- fs.writeFileSync(p, yaml.dump({ version: "5.1", workers }), "utf8");
34
- }
35
-
36
- const pub: RegistryWorker = {
37
- id: "architect",
38
- path: "core/workers/public/dev-team/architect/",
39
- type: "CodeWorker",
40
- visibility: "public",
41
- description: "System design",
42
- };
43
- const indigo: RegistryWorker = {
44
- id: "deal-brain",
45
- path: "companies/indigo/workers/deal-brain/",
46
- type: "OpsWorker",
47
- visibility: "private",
48
- company: "indigo",
49
- description: "GTM teammate",
50
- };
51
- const amass: RegistryWorker = {
52
- id: "gtm-refresh",
53
- path: "companies/amass/workers/gtm-refresh/",
54
- type: "OpsWorker",
55
- visibility: "private",
56
- company: "amass",
57
- description: "Depletions",
58
- };
59
-
60
- beforeEach(() => {
61
- hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-workers-"));
62
- });
63
- afterEach(() => {
64
- fs.rmSync(hqRoot, { recursive: true, force: true });
65
- });
66
-
67
- describe("readWorkerRegistry", () => {
68
- it("returns [] when the registry does not exist", () => {
69
- expect(readWorkerRegistry(hqRoot)).toEqual([]);
70
- });
71
- it("parses the workers list", () => {
72
- writeRegistry([pub, indigo]);
73
- const got = readWorkerRegistry(hqRoot);
74
- expect(got.map((w) => w.id)).toEqual(["architect", "deal-brain"]);
75
- });
76
- });
77
-
78
- describe("filterAccessibleWorkers", () => {
79
- it("always includes public workers", () => {
80
- expect(filterAccessibleWorkers([pub], undefined).map((w) => w.id)).toEqual(["architect"]);
81
- });
82
- it("includes company workers only for the active company", () => {
83
- const got = filterAccessibleWorkers([pub, indigo, amass], "indigo").map((w) => w.id);
84
- expect(got).toEqual(["architect", "deal-brain"]);
85
- expect(got).not.toContain("gtm-refresh");
86
- });
87
- it("excludes all company workers when no active company", () => {
88
- expect(filterAccessibleWorkers([pub, indigo, amass], undefined).map((w) => w.id)).toEqual([
89
- "architect",
90
- ]);
91
- });
92
- });
93
-
94
- describe("workerVaultPrefix", () => {
95
- it("maps a company worker path to a company-relative glob prefix (covers everything under the worker dir)", () => {
96
- expect(workerVaultPrefix(indigo)).toBe("workers/deal-brain/*");
97
- });
98
- it("returns null for a public worker", () => {
99
- expect(workerVaultPrefix(pub)).toBeNull();
100
- });
101
- });
102
-
103
- describe("classifyPrincipal", () => {
104
- it("classifies @all as company-wide with empty granteeId", () => {
105
- expect(classifyPrincipal("@all")).toEqual({
106
- granteeType: "company-wide",
107
- granteeId: "",
108
- label: "everyone in the company",
109
- });
110
- });
111
- it("lowercases emails", () => {
112
- expect(classifyPrincipal("Me@Co.com")).toEqual({
113
- granteeType: "email",
114
- granteeId: "me@co.com",
115
- label: "me@co.com",
116
- });
117
- });
118
- it("accepts group ids", () => {
119
- expect(classifyPrincipal("grp_finance")).toEqual({
120
- granteeType: "group",
121
- granteeId: "grp_finance",
122
- label: "grp_finance",
123
- });
124
- });
125
- it("rejects invalid principals", () => {
126
- expect(classifyPrincipal("not-a-principal")).toBeNull();
127
- expect(classifyPrincipal("grp_")).toBeNull();
128
- });
129
- });
130
-
131
- describe("resolveActiveCompany", () => {
132
- it("undefined when no session pointer", () => {
133
- expect(resolveActiveCompany(hqRoot)).toBeUndefined();
134
- });
135
- it("reads company_slug from the current session meta", () => {
136
- const sess = "sess-123";
137
- fs.mkdirSync(path.join(hqRoot, "workspace/sessions", sess), { recursive: true });
138
- fs.writeFileSync(path.join(hqRoot, "workspace/sessions/.current"), sess);
139
- fs.writeFileSync(
140
- path.join(hqRoot, "workspace/sessions", sess, "meta.yaml"),
141
- "company_slug: indigo\n",
142
- );
143
- expect(resolveActiveCompany(hqRoot)).toBe("indigo");
144
- });
145
- });
146
-
147
- describe("writeGrantSidecar", () => {
148
- it("creates .grants.yaml with the principal, then unions idempotently", () => {
149
- fs.mkdirSync(path.join(hqRoot, indigo.path), { recursive: true });
150
- writeGrantSidecar(hqRoot, indigo.path, "grp_finance");
151
- writeGrantSidecar(hqRoot, indigo.path, "grp_finance"); // idempotent
152
- writeGrantSidecar(hqRoot, indigo.path, "me@co.com");
153
- const doc = yaml.load(
154
- fs.readFileSync(path.join(hqRoot, indigo.path, ".grants.yaml"), "utf8"),
155
- ) as { grants: string[] };
156
- expect(doc.grants).toEqual(["grp_finance", "me@co.com"]);
157
- });
158
- });
@@ -1,301 +0,0 @@
1
- import { Command } from "commander";
2
- import chalk from "chalk";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import * as yaml from "js-yaml";
6
- import { parseUserYaml } from "../utils/user-yaml-error.js";
7
- import { ensureCognitoToken } from "../utils/cognito-session.js";
8
- import { vaultApiFetch, getCompanyUid } from "./secrets.js";
9
- import { GROUP_ID_PATTERN, EMAIL_PATTERN, normalizeFilePrefix } from "./_patterns.js";
10
- import { findHqRoot } from "../utils/manifest.js";
11
-
12
- // A worker entry as it appears in the auto-generated core/workers/registry.yaml.
13
- export interface RegistryWorker {
14
- id: string;
15
- path: string;
16
- type: string;
17
- visibility: string;
18
- company?: string;
19
- team?: string;
20
- status?: string;
21
- description?: string;
22
- triggers?: string;
23
- grants?: string;
24
- }
25
-
26
- /** Read + parse the worker registry. Empty array if it does not exist. */
27
- export function readWorkerRegistry(hqRoot: string): RegistryWorker[] {
28
- const p = path.join(hqRoot, "core/workers/registry.yaml");
29
- if (!fs.existsSync(p)) return [];
30
- const doc = parseUserYaml<{ workers?: RegistryWorker[] } | null>(
31
- fs.readFileSync(p, "utf8"),
32
- p,
33
- );
34
- return doc?.workers ?? [];
35
- }
36
-
37
- /**
38
- * Best-effort active company: workspace/sessions/.current -> meta.yaml
39
- * company_slug. Undefined when no session context is set. Pure/read-only.
40
- */
41
- export function resolveActiveCompany(hqRoot: string): string | undefined {
42
- try {
43
- const currentFile = path.join(hqRoot, "workspace/sessions/.current");
44
- const current = fs.readFileSync(currentFile, "utf8").trim();
45
- if (!current) return undefined;
46
- const metaPath = path.join(hqRoot, "workspace/sessions", current, "meta.yaml");
47
- if (!fs.existsSync(metaPath)) return undefined;
48
- const meta = yaml.load(fs.readFileSync(metaPath, "utf8")) as
49
- | Record<string, unknown>
50
- | null;
51
- const co = meta?.company_slug;
52
- return typeof co === "string" && co ? co : undefined;
53
- } catch {
54
- return undefined;
55
- }
56
- }
57
-
58
- /**
59
- * Membership-aware access filter for worker discovery: public workers always;
60
- * company workers only for the active company. Mirrors the /run skill and the
61
- * inject-worker-suggestion hook so all three surfaces agree.
62
- */
63
- export function filterAccessibleWorkers(
64
- workers: RegistryWorker[],
65
- activeCompany: string | undefined,
66
- ): RegistryWorker[] {
67
- return workers.filter((w) => {
68
- if (w.visibility === "public") return true;
69
- if (!w.company) return false;
70
- return activeCompany !== undefined && w.company === activeCompany;
71
- });
72
- }
73
-
74
- /**
75
- * The company-relative vault prefix for a worker, e.g.
76
- * companies/indigo/workers/deal-brain/ -> workers/deal-brain/. Returns null for
77
- * a worker with no company (public/shared — not shareable via ACL).
78
- */
79
- export function workerVaultPrefix(w: RegistryWorker): string | null {
80
- if (!w.company) return null;
81
- const companyRoot = `companies/${w.company}/`;
82
- const rel = w.path.startsWith(companyRoot)
83
- ? w.path.slice(companyRoot.length)
84
- : w.path;
85
- return normalizeFilePrefix(rel);
86
- }
87
-
88
- export type GranteeType = "company-wide" | "email" | "group";
89
-
90
- export interface ClassifiedPrincipal {
91
- granteeType: GranteeType;
92
- granteeId: string;
93
- label: string;
94
- }
95
-
96
- /** Classify a share principal (@all | email | grp_*) — null when invalid. */
97
- export function classifyPrincipal(principal: string): ClassifiedPrincipal | null {
98
- if (principal === "@all") {
99
- return { granteeType: "company-wide", granteeId: "", label: "everyone in the company" };
100
- }
101
- if (EMAIL_PATTERN.test(principal)) {
102
- const id = principal.trim().toLowerCase();
103
- return { granteeType: "email", granteeId: id, label: id };
104
- }
105
- if (GROUP_ID_PATTERN.test(principal)) {
106
- return { granteeType: "group", granteeId: principal, label: principal };
107
- }
108
- return null;
109
- }
110
-
111
- /**
112
- * Record a grant locally in the worker's tool-owned .grants.yaml sidecar. Kept
113
- * out of worker.yaml so we never rewrite a hand-authored file; the registry
114
- * generator unions this sidecar into the registry `grants:` field. Idempotent.
115
- */
116
- export function writeGrantSidecar(
117
- hqRoot: string,
118
- workerPath: string,
119
- principalLabel: string,
120
- ): void {
121
- const dir = path.join(hqRoot, workerPath);
122
- const sidecar = path.join(dir, ".grants.yaml");
123
- let grants: string[] = [];
124
- if (fs.existsSync(sidecar)) {
125
- const doc = parseUserYaml<{ grants?: string[] } | null>(
126
- fs.readFileSync(sidecar, "utf8"),
127
- sidecar,
128
- );
129
- if (Array.isArray(doc?.grants)) grants = doc!.grants.filter((g) => typeof g === "string");
130
- }
131
- if (!grants.includes(principalLabel)) grants.push(principalLabel);
132
- const header =
133
- "# Worker access grants — tool-owned, written by `hq workers share`.\n" +
134
- "# Unioned into core/workers/registry.yaml `grants:` by the registry generator.\n";
135
- fs.writeFileSync(sidecar, header + yaml.dump({ grants }), "utf8");
136
- }
137
-
138
- async function runWorkersShare(
139
- workerId: string,
140
- opts: { with: string; permission?: string; company?: string },
141
- ): Promise<void> {
142
- const hqRoot = findHqRoot();
143
- const worker = readWorkerRegistry(hqRoot).find((w) => w.id === workerId);
144
- if (!worker) {
145
- console.error(
146
- chalk.red(`Worker '${workerId}' not found in registry.`),
147
- "\nRun 'hq workers list' to see accessible workers.",
148
- );
149
- process.exit(1);
150
- }
151
-
152
- const prefix = workerVaultPrefix(worker!);
153
- if (!prefix) {
154
- console.error(
155
- chalk.red(`'${workerId}' is a shared/public worker (visibility ${worker!.visibility}).`),
156
- "\nPublic workers already ship to every HQ install — only company-scoped workers are shared with `hq workers share`.",
157
- );
158
- process.exit(1);
159
- }
160
-
161
- const permission = opts.permission ?? "read";
162
- if (!["read", "write"].includes(permission)) {
163
- console.error(chalk.red(`Invalid permission '${permission}': must be read or write`));
164
- process.exit(1);
165
- }
166
-
167
- const classified = classifyPrincipal(opts.with);
168
- if (!classified) {
169
- console.error(
170
- chalk.red(
171
- `Invalid principal '${opts.with}': must be '@all', an email address, or a group id matching grp_<alphanumeric>`,
172
- ),
173
- );
174
- process.exit(1);
175
- }
176
-
177
- const companySlug = opts.company ?? worker!.company;
178
- const token = await ensureCognitoToken();
179
- const companyUid = await getCompanyUid(token, companySlug);
180
-
181
- const body = {
182
- prefix,
183
- granteeType: classified!.granteeType,
184
- granteeId: classified!.granteeId,
185
- permission,
186
- };
187
- let res = await vaultApiFetch({
188
- token,
189
- path: `/files/${encodeURIComponent(companyUid)}/acl/grant`,
190
- method: "POST",
191
- body,
192
- });
193
- // No ACL row for this prefix yet — auto-create one with this grant.
194
- if (res.status === 404) {
195
- res = await vaultApiFetch({
196
- token,
197
- path: `/files/${encodeURIComponent(companyUid)}/acl`,
198
- method: "POST",
199
- body: {
200
- prefix,
201
- entries: [
202
- {
203
- granteeType: classified!.granteeType,
204
- granteeId: classified!.granteeId,
205
- permission,
206
- },
207
- ],
208
- },
209
- });
210
- }
211
- if (!res.ok) {
212
- const text = await res.text().catch(() => "");
213
- console.error(chalk.red(`Failed to share worker (HTTP ${res.status}). ${text}`));
214
- process.exit(1);
215
- }
216
-
217
- writeGrantSidecar(hqRoot, worker!.path, classified!.label);
218
-
219
- console.log(
220
- chalk.green("✓"),
221
- `Shared worker '${workerId}' with ${classified!.label} (${permission}).`,
222
- );
223
- console.log(
224
- chalk.dim(
225
- ` Vault prefix ${prefix} granted in company '${companySlug}'. It will sync to granted members and appear in their /run list.`,
226
- ),
227
- );
228
- }
229
-
230
- function runWorkersList(opts: { company?: string; mine?: boolean; shared?: boolean }): void {
231
- const hqRoot = findHqRoot();
232
- const activeCompany = opts.company ?? resolveActiveCompany(hqRoot);
233
- let workers = filterAccessibleWorkers(readWorkerRegistry(hqRoot), activeCompany);
234
-
235
- if (opts.shared) workers = workers.filter((w) => Boolean(w.grants && w.grants.trim()));
236
- if (opts.mine) workers = workers.filter((w) => Boolean(w.company) && w.company === activeCompany);
237
-
238
- if (workers.length === 0) {
239
- console.log("No accessible workers.");
240
- return;
241
- }
242
-
243
- const publicWorkers = workers.filter((w) => w.visibility === "public");
244
- const companyWorkers = workers.filter((w) => w.visibility !== "public");
245
-
246
- console.log(chalk.bold("Available Workers:"));
247
- const printGroup = (title: string, list: RegistryWorker[]) => {
248
- if (list.length === 0) return;
249
- console.log(`\n ${chalk.cyan(title)}:`);
250
- for (const w of list.sort((a, b) => a.id.localeCompare(b.id))) {
251
- const desc = (w.description ?? "").slice(0, 72);
252
- const shared = w.grants && w.grants.trim() ? chalk.dim(` [shared: ${w.grants}]`) : "";
253
- console.log(` ${w.id.padEnd(24)} ${desc}${shared}`);
254
- }
255
- };
256
- printGroup("Public", publicWorkers);
257
- if (activeCompany) printGroup(activeCompany, companyWorkers);
258
-
259
- console.log(chalk.dim("\nUsage: hq run {worker-id} [skill] [args]"));
260
- console.log(
261
- chalk.dim(
262
- "Share a company worker: hq workers share {worker-id} --with {grp_<name>|@all} --permission read",
263
- ),
264
- );
265
- }
266
-
267
- export function registerWorkersCommand(program: Command): void {
268
- const workers = program
269
- .command("workers")
270
- .description("Discover and share HQ workers")
271
- .option("--company <slug>", "Company slug (resolves to companyUid)");
272
-
273
- workers
274
- .command("list")
275
- .description("List workers you can access (public + your active company's)")
276
- .option("--mine", "Only this company's workers")
277
- .option("--shared", "Only workers that have been shared with someone")
278
- .action((opts: { mine?: boolean; shared?: boolean }) => {
279
- runWorkersList({ ...opts, company: workers.opts().company as string | undefined });
280
- });
281
-
282
- workers
283
- .command("share <workerId>")
284
- .description("Grant a teammate, group, or @all access to a company worker")
285
- .requiredOption(
286
- "--with <principal>",
287
- "Email address, group id (grp_<name>), or '@all' to share with every active company member",
288
- )
289
- .option("--permission <level>", "Permission level: read | write (default: read)")
290
- .action(async (workerId: string, opts: { with: string; permission?: string }) => {
291
- try {
292
- await runWorkersShare(workerId, {
293
- ...opts,
294
- company: workers.opts().company as string | undefined,
295
- });
296
- } catch (err) {
297
- console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
298
- process.exit(1);
299
- }
300
- });
301
- }
package/src/index.test.ts DELETED
@@ -1,32 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
-
3
- vi.mock("./cli-version.js", () => ({
4
- CLI_VERSION: "5.60.0",
5
- CLI_NAME: "@indigoai-us/hq-cli",
6
- }));
7
-
8
- vi.mock("./node-preflight.js", () => ({}));
9
-
10
- afterEach(() => {
11
- vi.restoreAllMocks();
12
- vi.resetModules();
13
- });
14
-
15
- describe("bin bootstrap", () => {
16
- it("answers --version without importing the command graph", async () => {
17
- const originalArgv = process.argv;
18
- const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
19
- const runCli = vi.fn();
20
- vi.doMock("./main.js", () => ({ runCli }));
21
- process.argv = ["node", "hq", "--version"];
22
-
23
- try {
24
- await import("./index.js");
25
- } finally {
26
- process.argv = originalArgv;
27
- }
28
-
29
- expect(write).toHaveBeenCalledWith("5.60.0\n");
30
- expect(runCli).not.toHaveBeenCalled();
31
- });
32
- });
package/src/index.ts DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // MUST be first: guard the Node version before any dependency that needs a
4
- // Node 20+ API (e.g. util.styleText) or a newer native ABI is evaluated.
5
- import "./node-preflight.js";
6
- import { CLI_VERSION } from "./cli-version.js";
7
-
8
- function isVersionRequest(argv: readonly string[]): boolean {
9
- const args = argv.slice(2);
10
- return args.length === 1 && (args[0] === "--version" || args[0] === "-V" || args[0] === "-v");
11
- }
12
-
13
- if (isVersionRequest(process.argv)) {
14
- process.stdout.write(`${CLI_VERSION}\n`);
15
- } else {
16
- const { runCli } = await import("./main.js");
17
- await runCli();
18
- }
19
-
20
- export const __test__ = { isVersionRequest };
@@ -1,59 +0,0 @@
1
- /**
2
- * Control-plane client tests (US-009).
3
- */
4
-
5
- import { describe, expect, it, vi } from "vitest";
6
-
7
- import { ControlPlaneDbClient } from "./control-plane.js";
8
-
9
- describe("ControlPlaneDbClient", () => {
10
- it("provision success returns remote status without connection string", async () => {
11
- const fetchImpl = vi.fn(async () => {
12
- return new Response(
13
- JSON.stringify({
14
- ok: true,
15
- companyUid: "cmp_x",
16
- companySlug: "x",
17
- engineId: "aurora-dsql",
18
- resourceArn: "arn:aws:dsql:us-east-1:1:cluster/x",
19
- region: "us-east-1",
20
- status: "ready",
21
- secretRef: "ssm:/hq/cmp_x/secrets/DB/REMOTE/X",
22
- idempotent: false,
23
- }),
24
- { status: 200 },
25
- );
26
- }) as unknown as typeof fetch;
27
-
28
- const client = new ControlPlaneDbClient({
29
- baseUrl: "https://api.example",
30
- getAccessToken: async () => "tok",
31
- fetchImpl,
32
- });
33
-
34
- const result = await client.provision({
35
- companyUid: "cmp_x",
36
- companySlug: "x",
37
- });
38
- expect(result.status).toBe("ready");
39
- expect(JSON.stringify(result)).not.toMatch(/postgres:\/\//i);
40
- });
41
-
42
- it("403 surfaces actionable error without secret", async () => {
43
- const fetchImpl = vi.fn(async () => {
44
- return new Response(JSON.stringify({ error: "Forbidden" }), {
45
- status: 403,
46
- });
47
- }) as unknown as typeof fetch;
48
-
49
- const client = new ControlPlaneDbClient({
50
- baseUrl: "https://api.example",
51
- getAccessToken: async () => "tok",
52
- fetchImpl,
53
- });
54
-
55
- await expect(
56
- client.provision({ companyUid: "cmp_x", companySlug: "x" }),
57
- ).rejects.toThrow(/Forbidden|403/);
58
- });
59
- });