@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,527 +0,0 @@
1
- /**
2
- * Unit tests for `hq agents` (agents.ts).
3
- *
4
- * Mirrors company.test.ts / members.test.ts: mock ensureCognitoToken +
5
- * getCompanyUid, spy on global fetch, drive through a Commander program, and
6
- * assert the /v1/agents request shape (method + path + body) plus the guard /
7
- * validation / exit behavior. `vaultApiFetch` itself is NOT mocked — the spied
8
- * global fetch verifies the real URL + init the helper produces.
9
- */
10
-
11
- import { Command } from "commander";
12
- import {
13
- afterEach,
14
- beforeEach,
15
- describe,
16
- expect,
17
- it,
18
- vi,
19
- type MockInstance,
20
- } from "vitest";
21
-
22
- vi.mock("../utils/cognito-session.js", async (importOriginal) => {
23
- const original =
24
- await importOriginal<typeof import("../utils/cognito-session.js")>();
25
- return {
26
- ...original,
27
- ensureCognitoToken: vi.fn(async () => "test-token"),
28
- };
29
- });
30
-
31
- vi.mock("../utils/vault-api.js", async (importOriginal) => {
32
- const original = await importOriginal<typeof import("../utils/vault-api.js")>();
33
- return {
34
- ...original,
35
- getCompanyUid: vi.fn(async () => "cmp_acme"),
36
- };
37
- });
38
-
39
- import { ensureCognitoToken } from "../utils/cognito-session.js";
40
- import { getCompanyUid } from "../utils/vault-api.js";
41
- import { registerAgentsCommand } from "./agents.js";
42
-
43
- function jsonResponse(status: number, body: unknown): Response {
44
- return new Response(JSON.stringify(body), {
45
- status,
46
- headers: { "Content-Type": "application/json" },
47
- });
48
- }
49
-
50
- let fetchSpy: MockInstance<typeof fetch>;
51
- let exitSpy: MockInstance<typeof process.exit>;
52
- let logSpy: MockInstance<typeof console.log>;
53
- const mockEnsureCognitoToken = vi.mocked(ensureCognitoToken);
54
- const mockGetCompanyUid = vi.mocked(getCompanyUid);
55
-
56
- beforeEach(() => {
57
- vi.clearAllMocks();
58
- fetchSpy = vi.spyOn(globalThis, "fetch");
59
- mockEnsureCognitoToken.mockResolvedValue("test-token");
60
- mockGetCompanyUid.mockResolvedValue("cmp_acme");
61
- exitSpy = vi.spyOn(process, "exit").mockImplementation((code?: number) => {
62
- throw new Error(`process.exit(${code})`);
63
- }) as unknown as MockInstance<typeof process.exit>;
64
- logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
65
- vi.spyOn(console, "error").mockImplementation(() => {});
66
- });
67
-
68
- afterEach(() => {
69
- vi.restoreAllMocks();
70
- });
71
-
72
- function buildProgram(): Command {
73
- const program = new Command();
74
- program.name("hq").exitOverride();
75
- registerAgentsCommand(program);
76
- return program;
77
- }
78
-
79
- async function run(args: string[]): Promise<void> {
80
- await buildProgram().parseAsync(["node", "hq", ...args]);
81
- }
82
-
83
- describe("hq agents list", () => {
84
- it("GETs /v1/agents with the resolved companyUid", async () => {
85
- fetchSpy.mockResolvedValueOnce(
86
- jsonResponse(200, {
87
- agents: [
88
- { uid: "agt_1", name: "Ops", slug: "ops", agentStatus: "running" },
89
- ],
90
- }),
91
- );
92
-
93
- await run(["agents", "--company", "acme", "list"]);
94
-
95
- expect(fetchSpy).toHaveBeenCalledTimes(1);
96
- const [url, init] = fetchSpy.mock.calls[0];
97
- expect(String(url)).toContain("/v1/agents");
98
- expect(String(url)).toContain("companyUid=cmp_acme");
99
- expect(init?.method ?? "GET").toBe("GET");
100
- });
101
-
102
- it("accepts --company on the subcommand too", async () => {
103
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { agents: [] }));
104
- await run(["agents", "list", "--company", "acme"]);
105
- expect(mockGetCompanyUid).toHaveBeenCalledWith("test-token", "acme");
106
- });
107
-
108
- it("emits raw JSON with --json", async () => {
109
- const stdoutSpy = vi
110
- .spyOn(process.stdout, "write")
111
- .mockImplementation(() => true);
112
- fetchSpy.mockResolvedValueOnce(
113
- jsonResponse(200, { agents: [{ uid: "agt_1", name: "Ops", slug: "ops" }] }),
114
- );
115
- await run(["agents", "--company", "acme", "list", "--json"]);
116
- const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("\n");
117
- expect(printed).toContain('"uid": "agt_1"');
118
- });
119
-
120
- it("prints a friendly message when agents are not enabled (404)", async () => {
121
- fetchSpy.mockResolvedValueOnce(jsonResponse(404, { error: "not found" }));
122
- await run(["agents", "--company", "acme", "list"]);
123
- const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
124
- expect(printed).toMatch(/agents feature isn't enabled/i);
125
- expect(exitSpy).not.toHaveBeenCalled();
126
- });
127
- });
128
-
129
- describe("hq agents rename", () => {
130
- it("PATCHes the profile with displayName", async () => {
131
- fetchSpy.mockResolvedValueOnce(
132
- jsonResponse(200, {
133
- uid: "agt_1",
134
- profile: { displayName: "New" },
135
- slackUpdated: false,
136
- }),
137
- );
138
-
139
- await run(["agents", "--company", "acme", "rename", "agt_1", "New"]);
140
-
141
- const [url, init] = fetchSpy.mock.calls[0];
142
- expect(String(url)).toContain("/v1/agents/agt_1/profile");
143
- expect(init?.method).toBe("PATCH");
144
- expect(JSON.parse(init?.body as string)).toEqual({ displayName: "New" });
145
- });
146
- });
147
-
148
- describe("hq agents set", () => {
149
- it("PATCHes only the supplied profile fields", async () => {
150
- fetchSpy.mockResolvedValueOnce(
151
- jsonResponse(200, { uid: "agt_1", profile: {}, slackUpdated: true }),
152
- );
153
-
154
- await run([
155
- "agents",
156
- "--company",
157
- "acme",
158
- "set",
159
- "agt_1",
160
- "--title",
161
- "Chief of Staff",
162
- ]);
163
-
164
- const [url, init] = fetchSpy.mock.calls[0];
165
- expect(String(url)).toContain("/v1/agents/agt_1/profile");
166
- expect(init?.method).toBe("PATCH");
167
- const sent = JSON.parse(init?.body as string);
168
- expect(sent).toEqual({ title: "Chief of Staff" });
169
- });
170
-
171
- it("requires at least one field", async () => {
172
- await expect(
173
- run(["agents", "--company", "acme", "set", "agt_1"]),
174
- ).rejects.toThrow("process.exit(1)");
175
- expect(fetchSpy).not.toHaveBeenCalled();
176
- });
177
- });
178
-
179
- describe("hq agents config", () => {
180
- it("PATCHes runtime-config with model/effort/tier", async () => {
181
- fetchSpy.mockResolvedValueOnce(
182
- jsonResponse(200, { uid: "agt_1", codexModel: "gpt-5.5", applied: true }),
183
- );
184
-
185
- await run([
186
- "agents",
187
- "--company",
188
- "acme",
189
- "config",
190
- "agt_1",
191
- "--model",
192
- "gpt-5.5",
193
- "--effort",
194
- "high",
195
- "--tier",
196
- "priority",
197
- ]);
198
-
199
- const [url, init] = fetchSpy.mock.calls[0];
200
- expect(String(url)).toContain("/v1/agents/agt_1/runtime-config");
201
- expect(init?.method).toBe("PATCH");
202
- expect(JSON.parse(init?.body as string)).toEqual({
203
- codexModel: "gpt-5.5",
204
- codexReasoningEffort: "high",
205
- codexServiceTier: "priority",
206
- });
207
- });
208
-
209
- it("rejects an invalid --effort", async () => {
210
- await expect(
211
- run([
212
- "agents",
213
- "--company",
214
- "acme",
215
- "config",
216
- "agt_1",
217
- "--effort",
218
- "turbo",
219
- ]),
220
- ).rejects.toThrow("process.exit(1)");
221
- expect(fetchSpy).not.toHaveBeenCalled();
222
- });
223
-
224
- it("rejects an invalid --tier", async () => {
225
- await expect(
226
- run([
227
- "agents",
228
- "--company",
229
- "acme",
230
- "config",
231
- "agt_1",
232
- "--tier",
233
- "turbo",
234
- ]),
235
- ).rejects.toThrow("process.exit(1)");
236
- expect(fetchSpy).not.toHaveBeenCalled();
237
- });
238
-
239
- it("requires at least one field", async () => {
240
- await expect(
241
- run(["agents", "--company", "acme", "config", "agt_1"]),
242
- ).rejects.toThrow("process.exit(1)");
243
- expect(fetchSpy).not.toHaveBeenCalled();
244
- });
245
- });
246
-
247
- describe("hq agents start/stop/retry", () => {
248
- it("POSTs /start", async () => {
249
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { uid: "agt_1" }));
250
- await run(["agents", "--company", "acme", "start", "agt_1"]);
251
- const [url, init] = fetchSpy.mock.calls[0];
252
- expect(String(url)).toContain("/v1/agents/agt_1/start");
253
- expect(init?.method).toBe("POST");
254
- });
255
-
256
- it("POSTs /stop", async () => {
257
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { uid: "agt_1" }));
258
- await run(["agents", "--company", "acme", "stop", "agt_1"]);
259
- expect(String(fetchSpy.mock.calls[0][0])).toContain("/v1/agents/agt_1/stop");
260
- });
261
-
262
- it("POSTs /retry", async () => {
263
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { uid: "agt_1" }));
264
- await run(["agents", "--company", "acme", "retry", "agt_1"]);
265
- expect(String(fetchSpy.mock.calls[0][0])).toContain("/v1/agents/agt_1/retry");
266
- });
267
- });
268
-
269
- describe("hq agents rm", () => {
270
- it("refuses without --yes and does not call the API", async () => {
271
- await expect(
272
- run(["agents", "--company", "acme", "rm", "agt_1"]),
273
- ).rejects.toThrow("process.exit(1)");
274
- expect(fetchSpy).not.toHaveBeenCalled();
275
- });
276
-
277
- it("DELETEs the agent with --yes", async () => {
278
- fetchSpy.mockResolvedValueOnce(
279
- jsonResponse(200, { uid: "agt_1", terminal: true }),
280
- );
281
- await run(["agents", "--company", "acme", "rm", "agt_1", "--yes"]);
282
- const [url, init] = fetchSpy.mock.calls[0];
283
- expect(String(url)).toContain("/v1/agents/agt_1");
284
- expect(init?.method).toBe("DELETE");
285
- });
286
- });
287
-
288
- describe("hq agents status", () => {
289
- it("exits 1 on a non-2xx and surfaces the error", async () => {
290
- fetchSpy.mockResolvedValueOnce(
291
- jsonResponse(403, { error: "forbidden" }),
292
- );
293
- await expect(
294
- run(["agents", "--company", "acme", "status", "agt_1"]),
295
- ).rejects.toThrow("process.exit(1)");
296
- });
297
- });
298
-
299
- describe("hq agents provision (billing gate)", () => {
300
- it("refuses without --yes, prints the cost, and makes NO API call", async () => {
301
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
302
- await expect(
303
- run(["agents", "--company", "acme", "provision", "Ops Bot"]),
304
- ).rejects.toThrow("process.exit(1)");
305
- expect(fetchSpy).not.toHaveBeenCalled();
306
- const printed = errSpy.mock.calls
307
- .map((c) => c.map(String).join(" "))
308
- .join("\n");
309
- expect(printed).toMatch(/\$100\.00\/month/);
310
- });
311
-
312
- it("POSTs /v1/agents with slugified name + idempotency key when --yes", async () => {
313
- fetchSpy.mockResolvedValueOnce(
314
- jsonResponse(200, { uid: "agt_new", slug: "ops-bot" }),
315
- );
316
- await run(["agents", "--company", "acme", "provision", "Ops Bot", "--yes"]);
317
- const [url, init] = fetchSpy.mock.calls[0];
318
- expect(String(url)).toContain("/v1/agents");
319
- expect(init?.method).toBe("POST");
320
- const sent = JSON.parse(init?.body as string);
321
- expect(sent.companyUid).toBe("cmp_acme");
322
- expect(sent.name).toBe("Ops Bot");
323
- expect(sent.slug).toBe("ops-bot");
324
- expect(sent.codexAuthMode).toBe("subscription");
325
- expect(typeof sent.idempotencyKey).toBe("string");
326
- expect(sent.idempotencyKey.length).toBeGreaterThan(0);
327
- });
328
-
329
- it("mints a card-capture link on 402 billing_required and exits 1", async () => {
330
- fetchSpy
331
- .mockResolvedValueOnce(
332
- jsonResponse(402, {
333
- error: "payment required",
334
- code: "BILLING_REQUIRED",
335
- billing: {
336
- status: "billing_required",
337
- setup: {
338
- payerType: "company",
339
- path: "/v1/billing/checkout/org",
340
- method: "POST",
341
- body: { companyUid: "cmp_acme" },
342
- },
343
- },
344
- }),
345
- )
346
- .mockResolvedValueOnce(
347
- jsonResponse(200, { url: "https://checkout.stripe.com/card" }),
348
- );
349
-
350
- const logSpyLocal = vi.spyOn(console, "log").mockImplementation(() => {});
351
- await expect(
352
- run(["agents", "--company", "acme", "provision", "Ops Bot", "--yes"]),
353
- ).rejects.toThrow("process.exit(1)");
354
-
355
- // Second call mints the checkout link the 402 pointed at.
356
- expect(String(fetchSpy.mock.calls[1][0])).toContain(
357
- "/v1/billing/checkout/org",
358
- );
359
- expect(JSON.parse(fetchSpy.mock.calls[1][1]?.body as string)).toEqual({
360
- companyUid: "cmp_acme",
361
- });
362
- const printed = logSpyLocal.mock.calls.map((c) => String(c[0])).join("\n");
363
- expect(printed).toContain("https://checkout.stripe.com/card");
364
- });
365
-
366
- it("surfaces the DECLINE reason on 402 payment_failed (message-first decoding)", async () => {
367
- // The payment_failed envelope carries BOTH the generic error AND the
368
- // friendly decline message — the decode must prefer `message` or the
369
- // decline copy is lost and the operator sees "add a card" for a card
370
- // that exists and was declined.
371
- fetchSpy
372
- .mockResolvedValueOnce(
373
- jsonResponse(402, {
374
- error: "payment required",
375
- message:
376
- "Your card was declined. Try a different card or contact your bank.",
377
- code: "PAYMENT_FAILED",
378
- billing: {
379
- status: "payment_failed",
380
- setup: {
381
- payerType: "company",
382
- path: "/v1/billing/checkout/org",
383
- method: "POST",
384
- body: { companyUid: "cmp_acme" },
385
- },
386
- },
387
- }),
388
- )
389
- .mockResolvedValueOnce(
390
- jsonResponse(200, { url: "https://checkout.stripe.com/update" }),
391
- );
392
-
393
- const logSpyLocal = vi.spyOn(console, "log").mockImplementation(() => {});
394
- const errSpyLocal = vi.spyOn(console, "error").mockImplementation(() => {});
395
- await expect(
396
- run(["agents", "--company", "acme", "provision", "Ops Bot", "--yes"]),
397
- ).rejects.toThrow("process.exit(1)");
398
-
399
- const printed = [...errSpyLocal.mock.calls, ...logSpyLocal.mock.calls]
400
- .map((c) => c.map(String).join(" "))
401
- .join("\n");
402
- expect(printed).toContain("declined");
403
- expect(printed).not.toContain("No card on file");
404
- expect(printed).toContain("https://checkout.stripe.com/update");
405
- });
406
-
407
- it("requires --api-key-env for --auth-mode apiKey (before any charge)", async () => {
408
- await expect(
409
- run([
410
- "agents",
411
- "--company",
412
- "acme",
413
- "provision",
414
- "Ops Bot",
415
- "--auth-mode",
416
- "apiKey",
417
- "--yes",
418
- ]),
419
- ).rejects.toThrow("process.exit(1)");
420
- expect(fetchSpy).not.toHaveBeenCalled();
421
- });
422
- });
423
-
424
- describe("hq agents talk (message / thread)", () => {
425
- function agentRow(uid: string, slug: string, name: string) {
426
- return { uid, slug, name, companyUid: "cmp_acme" };
427
- }
428
-
429
- it("resolves an agent by slug and reads the thread", async () => {
430
- // 1) roster lookup for slug→uid, 2) thread read
431
- fetchSpy
432
- .mockResolvedValueOnce(
433
- jsonResponse(200, { agents: [agentRow("agt_deacon", "deacon", "Deacon")] }),
434
- )
435
- .mockResolvedValueOnce(
436
- jsonResponse(200, {
437
- messages: [
438
- {
439
- eventId: "e1",
440
- fromPersonUid: "prs_me",
441
- body: "hi",
442
- createdAt: "2026-07-13T10:00",
443
- direction: "out",
444
- },
445
- {
446
- eventId: "e2",
447
- fromPersonUid: "agt_deacon",
448
- fromDisplayName: "Deacon",
449
- body: "hello back",
450
- createdAt: "2026-07-13T10:01",
451
- direction: "in",
452
- },
453
- ],
454
- }),
455
- );
456
-
457
- const logs: string[] = [];
458
- vi.spyOn(console, "log").mockImplementation((...a) => {
459
- logs.push(a.map(String).join(" "));
460
- });
461
- await run(["agents", "--company", "acme", "thread", "deacon"]);
462
-
463
- // roster call then thread call
464
- expect(String(fetchSpy.mock.calls[0][0])).toContain("/v1/agents");
465
- const threadUrl = String(fetchSpy.mock.calls[1][0]);
466
- expect(threadUrl).toContain("/v1/notify/thread");
467
- expect(threadUrl).toContain("withPersonUid=agt_deacon");
468
- const out = logs.join("\n");
469
- expect(out).toContain("hello back");
470
- expect(out).toContain("hi");
471
- });
472
-
473
- it("passes an agt_ uid straight through (no roster lookup)", async () => {
474
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { messages: [] }));
475
- await run(["agents", "thread", "agt_xyz"]);
476
- // Only the thread call — no /v1/agents roster fetch.
477
- expect(fetchSpy).toHaveBeenCalledTimes(1);
478
- expect(String(fetchSpy.mock.calls[0][0])).toContain("withPersonUid=agt_xyz");
479
- expect(mockGetCompanyUid).not.toHaveBeenCalled();
480
- });
481
-
482
- it("message --no-wait POSTs the DM and does not poll", async () => {
483
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true })); // POST /v1/notify/dm
484
- await run(["agents", "message", "agt_xyz", "--no-wait", "hello", "there"]);
485
- expect(fetchSpy).toHaveBeenCalledTimes(1);
486
- const [url, init] = fetchSpy.mock.calls[0];
487
- expect(String(url)).toContain("/v1/notify/dm");
488
- expect(init?.method).toBe("POST");
489
- expect(JSON.parse(init?.body as string)).toEqual({
490
- toPersonUid: "agt_xyz",
491
- body: "hello there",
492
- });
493
- });
494
-
495
- it("message waits for and prints the agent's reply", async () => {
496
- fetchSpy
497
- .mockResolvedValueOnce(jsonResponse(200, { messages: [] })) // baseline read
498
- .mockResolvedValueOnce(jsonResponse(200, { ok: true })) // POST dm
499
- .mockResolvedValueOnce(
500
- jsonResponse(200, {
501
- messages: [
502
- {
503
- eventId: "r1",
504
- fromPersonUid: "agt_xyz",
505
- fromDisplayName: "Xyz",
506
- body: "on it",
507
- createdAt: "2026-07-13T11:00",
508
- direction: "in",
509
- },
510
- ],
511
- }),
512
- ); // first poll returns the reply
513
-
514
- const logs: string[] = [];
515
- vi.spyOn(console, "log").mockImplementation((...a) => {
516
- logs.push(a.map(String).join(" "));
517
- });
518
- await run(["agents", "message", "agt_xyz", "--timeout", "10", "ping"]);
519
- expect(logs.join("\n")).toContain("on it");
520
- }, 10000);
521
-
522
- it("requires a non-empty message", async () => {
523
- await expect(
524
- run(["agents", "message", "agt_xyz", " "]),
525
- ).rejects.toThrow("process.exit(1)");
526
- });
527
- });