@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,67 +0,0 @@
1
- /**
2
- * Runtime Node.js version guard for the hq CLI.
3
- *
4
- * HQ tooling requires Node.js 20 or newer. On older runtimes (notably Node 18)
5
- * the CLI dies with cryptic failures long before reaching any of its own code:
6
- * a native-module ABI mismatch from a prebuilt dependency, and a missing
7
- * `util.styleText` (added in Node 20). Those errors give the user no hint that
8
- * the real problem is just an old Node.
9
- *
10
- * This module exists to fail fast with an actionable message instead. It is
11
- * imported FIRST by every CLI entry point (`index.ts`, `bin/hq-auth-refresh.ts`)
12
- * so the check runs before commander, Sentry, or any dependency that needs a
13
- * Node 20+ API or a newer native ABI is evaluated. ES modules evaluate their
14
- * imports in source order, so as long as this is the first import in the entry
15
- * module, the guard short-circuits an unsupported runtime cleanly.
16
- *
17
- * Keep this file dependency-free — it must not import anything that could itself
18
- * fail to load on the very runtime it is trying to detect.
19
- */
20
-
21
- export const MIN_NODE_MAJOR = 20;
22
-
23
- export interface NodeVersionCheck {
24
- ok: boolean;
25
- major: number;
26
- message?: string;
27
- }
28
-
29
- /**
30
- * Pure check: is the given Node version string (e.g. "18.19.0") supported?
31
- * Defaults to the running runtime's version. An unparseable version is treated
32
- * as supported so we never block a user on a version string we can't read.
33
- */
34
- export function checkNodeVersion(
35
- versionString: string = process.versions.node,
36
- ): NodeVersionCheck {
37
- const major = Number.parseInt(String(versionString).split(".")[0] ?? "", 10);
38
-
39
- if (!Number.isFinite(major) || major >= MIN_NODE_MAJOR) {
40
- return { ok: true, major };
41
- }
42
-
43
- const message =
44
- `hq requires Node.js ${MIN_NODE_MAJOR} or newer — you are running Node ${versionString}.\n` +
45
- `Older versions fail with native-module ABI mismatches and missing APIs.\n` +
46
- `Please upgrade to Node ${MIN_NODE_MAJOR}+ (https://nodejs.org/) and run hq again.`;
47
-
48
- return { ok: false, major, message };
49
- }
50
-
51
- /**
52
- * Side-effecting guard run on import: prints the upgrade message to stderr and
53
- * exits 1 on an unsupported runtime. A no-op on Node 20+. Set
54
- * `HQ_SKIP_NODE_PREFLIGHT=1` to bypass (used by the test runner, which already
55
- * runs on a supported Node).
56
- */
57
- export function enforceNodeVersion(): void {
58
- if (process.env.HQ_SKIP_NODE_PREFLIGHT) return;
59
-
60
- const result = checkNodeVersion();
61
- if (!result.ok && result.message) {
62
- process.stderr.write(`${result.message}\n`);
63
- process.exit(1);
64
- }
65
- }
66
-
67
- enforceNodeVersion();
@@ -1,195 +0,0 @@
1
- /**
2
- * Payload bounding for the Outpost session heartbeat.
3
- *
4
- * ## Why this exists
5
- *
6
- * The heartbeat enumerates every Claude transcript and Codex rollout on the
7
- * box. On a long-lived Outpost that is an archive, not a status: the box this
8
- * was first run against had **8,258 Claude transcripts and 1,082 Codex
9
- * rollouts — 9,340 sessions — of which 15 had any activity in the last 15
10
- * minutes.** Publishing all of them produced a payload of roughly 1.9 MB.
11
- *
12
- * AWS IoT Core rejects anything over 128 KB, so the very first real publish
13
- * failed with `payload larger than 131072 bytes`. Every subsequent one would
14
- * have too. The heartbeat is a liveness signal; it must carry what is live.
15
- *
16
- * Two rules, both tested here:
17
- * 1. `ended` sessions are not published — they are history, and re-sending
18
- * thousands of them every five seconds is the bug.
19
- * 2. Whatever survives that filter is still bounded by BYTES, because a busy
20
- * box could exceed the limit on live sessions alone. When the bound bites
21
- * it is reported, never silent — a truncated payload that looks complete
22
- * is how you get a wrong dashboard instead of a missing one.
23
- */
24
-
25
- import { describe, expect, it } from "vitest";
26
- import {
27
- DEFAULT_LIVENESS_THRESHOLDS,
28
- IOT_PAYLOAD_BUDGET_BYTES,
29
- collectSessions,
30
- type DirEntry,
31
- type FileStat,
32
- type FileSystemPort,
33
- } from "./session-heartbeat.js";
34
-
35
- const NOW = new Date("2026-07-29T12:00:00.000Z");
36
- const NOW_MS = NOW.getTime();
37
-
38
- /**
39
- * A fake Claude tree with `count` transcripts, each aged `ageSecondsFor(i)`.
40
- * Codex enumeration sees an empty tree.
41
- */
42
- function claudeTreeFs(
43
- count: number,
44
- ageSecondsFor: (i: number) => number,
45
- ): FileSystemPort {
46
- const names = Array.from(
47
- { length: count },
48
- (_, i) =>
49
- `${i.toString(16).padStart(8, "0")}-aaaa-bbbb-cccc-dddddddddddd.jsonl`,
50
- );
51
- const ageOf = new Map<string, number>();
52
- names.forEach((n, i) => ageOf.set(n, ageSecondsFor(i)));
53
-
54
- return {
55
- async readDir(path: string): Promise<DirEntry[]> {
56
- if (path.endsWith("/.claude/projects")) {
57
- return [{ name: "-home-ec2-user-hq", isDirectory: true, isFile: false }];
58
- }
59
- if (path.endsWith("/.claude/projects/-home-ec2-user-hq")) {
60
- return names.map((name) => ({
61
- name,
62
- isDirectory: false,
63
- isFile: true,
64
- }));
65
- }
66
- return [];
67
- },
68
- async stat(path: string): Promise<FileStat> {
69
- const name = path.split("/").pop() ?? "";
70
- const age = ageOf.get(name) ?? 0;
71
- const mtimeMs = NOW_MS - age * 1000;
72
- return { mtimeMs, birthtimeMs: mtimeMs, size: 1024 };
73
- },
74
- async readTextFile() {
75
- return "";
76
- },
77
- async readBounded() {
78
- // A realistic cwd/model sniff, so each record is a realistic size.
79
- return JSON.stringify({
80
- cwd: "/home/ec2-user/hq/repos/private/some-longish-repo-name",
81
- model: "claude-opus-4-8",
82
- });
83
- },
84
- };
85
- }
86
-
87
- const config = { personUid: "prs_01TEST", home: "/home/ec2-user", now: () => NOW };
88
-
89
- describe("payload bounding", () => {
90
- it("publishes live sessions and drops the ended archive", async () => {
91
- // 500 sessions: the first 5 active, the rest ancient — the real shape of
92
- // a box that has been running for weeks.
93
- const fs = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
94
-
95
- const payload = await collectSessions(config, { fs });
96
-
97
- expect(payload.sessions).toHaveLength(5);
98
- expect(payload.sessions.every((s) => s.status !== "ended")).toBe(true);
99
- });
100
-
101
- it("reports how many sessions exist, not just how many it sent", async () => {
102
- const fs = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
103
-
104
- const payload = await collectSessions(config, { fs });
105
-
106
- // Silent filtering reads as "this box has 5 sessions". It has 500.
107
- expect(payload.totalSessions).toBe(500);
108
- expect(payload.sessions.length).toBeLessThan(payload.totalSessions);
109
- });
110
-
111
- it("keeps idle sessions — only `ended` is archive", async () => {
112
- // 2s → running, 5min → idle, 30d → ended.
113
- const fs = claudeTreeFs(3, (i) => [2, 300, 60 * 60 * 24 * 30][i]!);
114
-
115
- const payload = await collectSessions(config, { fs });
116
-
117
- const statuses = payload.sessions.map((s) => s.status).sort();
118
- expect(statuses).toEqual(["idle", "running"]);
119
- });
120
-
121
- it("stays under the IoT limit even when every session is live", async () => {
122
- // 5,000 sessions all active — the size bound, not the status filter, is
123
- // what has to hold here.
124
- const fs = claudeTreeFs(5000, () => 2);
125
-
126
- const payload = await collectSessions(config, { fs });
127
- const bytes = Buffer.byteLength(JSON.stringify(payload), "utf8");
128
-
129
- expect(bytes).toBeLessThanOrEqual(IOT_PAYLOAD_BUDGET_BYTES);
130
- // The real AWS IoT Core ceiling. The budget must leave headroom under it.
131
- expect(bytes).toBeLessThan(131072);
132
- });
133
-
134
- it("flags truncation rather than quietly shortening the list", async () => {
135
- const fs = claudeTreeFs(5000, () => 2);
136
-
137
- const payload = await collectSessions(config, { fs });
138
-
139
- expect(payload.truncated).toBe(true);
140
- expect(payload.totalSessions).toBe(5000);
141
- expect(payload.sessions.length).toBeLessThan(5000);
142
- });
143
-
144
- it("does not flag truncation when everything fits", async () => {
145
- const fs = claudeTreeFs(3, () => 2);
146
-
147
- const payload = await collectSessions(config, { fs });
148
-
149
- expect(payload.truncated).toBe(false);
150
- expect(payload.sessions).toHaveLength(3);
151
- expect(payload.totalSessions).toBe(3);
152
- });
153
-
154
- it("reads transcript bodies ONLY for sessions it will publish", async () => {
155
- // The enumerator statted every file AND did a 16 KiB bounded read on each,
156
- // before anything was filtered. On the first real box that was 9,340 reads
157
- // per tick, every 5 seconds — ~150 MB of disk for 15 useful records, on
158
- // the exact resource that had already taken the machine down once.
159
- const reads: string[] = [];
160
- const base = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
161
- const fs: FileSystemPort = {
162
- ...base,
163
- async readBounded(path, maxBytes, from) {
164
- reads.push(path);
165
- return base.readBounded(path, maxBytes, from);
166
- },
167
- };
168
-
169
- const payload = await collectSessions(config, { fs });
170
-
171
- expect(payload.sessions).toHaveLength(5);
172
- // Five live sessions ⇒ five reads, not five hundred.
173
- expect(reads).toHaveLength(5);
174
- });
175
-
176
- it("keeps the MOST RECENTLY ACTIVE sessions when it has to choose", async () => {
177
- // Index 0 is freshest, index N oldest — all still within `idle`.
178
- const fs = claudeTreeFs(5000, (i) => 1 + i * (1 / 10));
179
-
180
- const payload = await collectSessions(config, { fs });
181
-
182
- expect(payload.truncated).toBe(true);
183
- // Dropping the newest and keeping stale ones would make the live view
184
- // wrong in the one way that matters.
185
- const kept = payload.sessions
186
- .map((s) => Date.parse(s.lastActivityAt!))
187
- .sort((a, b) => a - b);
188
- const oldestKept = kept[0]!;
189
- const cutoff =
190
- NOW_MS - DEFAULT_LIVENESS_THRESHOLDS.idleWithinSeconds * 1000;
191
- expect(oldestKept).toBeGreaterThan(cutoff);
192
- // The single freshest session must always survive.
193
- expect(Math.max(...kept)).toBe(NOW_MS - 1000);
194
- });
195
- });
@@ -1,105 +0,0 @@
1
- /**
2
- * The no-secrets guard must catch credentials WITHOUT catching ordinary paths.
3
- *
4
- * Both halves matter equally, and the second is easy to get wrong. The guard
5
- * throws, and a throw fails the whole tick — so a pattern that matches a
6
- * legitimate directory name silently disables reporting for the entire box
7
- * until that session ages out.
8
- *
9
- * The original marker list held `sk-` and `asia` as bare substrings. `sk-`
10
- * matches `task-runner`, `flask-app`, `disk-usage`, `risk-model`. Anyone who
11
- * created a repo with one of those names would have taken the heartbeat down
12
- * across the box, with the service still reporting active — the exact failure
13
- * shape this whole change exists to remove.
14
- */
15
-
16
- import { describe, expect, it } from "vitest";
17
- import {
18
- assertNoSecretsInPayload,
19
- type AgentSession,
20
- type SessionsHeartbeatPayload,
21
- } from "./session-heartbeat.js";
22
-
23
- function payloadWith(over: Partial<AgentSession>): SessionsHeartbeatPayload {
24
- const session: AgentSession = {
25
- id: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
26
- tool: "claude",
27
- origin: "outpost",
28
- cwd: "/home/ec2-user/hq",
29
- project: "hq",
30
- company: null,
31
- model: "claude-opus-4-8",
32
- status: "running",
33
- startedAt: "2026-07-29T12:00:00.000Z",
34
- lastActivityAt: "2026-07-29T12:00:00.000Z",
35
- source: "/home/ec2-user/.claude/projects/-home-ec2-user-hq/x.jsonl",
36
- ...over,
37
- };
38
- return {
39
- type: "sessions",
40
- origin: "outpost",
41
- emittedAt: "2026-07-29T12:00:00.000Z",
42
- sessions: [session],
43
- };
44
- }
45
-
46
- describe("ordinary paths must never trip the guard", () => {
47
- // Every one of these contains `sk-` or `asia` and would have thrown before.
48
- const innocentPaths = [
49
- "/home/ec2-user/hq/repos/private/task-runner",
50
- "/home/ec2-user/hq/repos/public/flask-app",
51
- "/home/ec2-user/hq/tools/disk-usage",
52
- "/home/ec2-user/hq/models/risk-model",
53
- "/home/ec2-user/hq/regions/asia-pacific",
54
- "/home/ec2-user/hq/repos/private/password-manager",
55
- "/home/ec2-user/hq/kiosk-display",
56
- ];
57
-
58
- for (const cwd of innocentPaths) {
59
- it(`allows ${cwd.split("/").pop()}`, () => {
60
- const project = cwd.split("/").pop()!;
61
- expect(() =>
62
- assertNoSecretsInPayload(payloadWith({ cwd, project, source: `${cwd}/s.jsonl` })),
63
- ).not.toThrow();
64
- });
65
- }
66
-
67
- it("allows a model id that merely starts with the letters sk", () => {
68
- expect(() =>
69
- assertNoSecretsInPayload(payloadWith({ model: "sk-lite-preview" })),
70
- ).not.toThrow();
71
- });
72
- });
73
-
74
- describe("real credentials must still be caught", () => {
75
- const leaks: [string, Partial<AgentSession>][] = [
76
- ["an Anthropic key", { model: "sk-ant-api03-AbCdEfGhIjKlMnOpQrStUv" }],
77
- ["an OpenAI-style key", { model: "sk-AbCdEfGhIjKlMnOpQrStUvWxYz012345" }],
78
- ["a long-lived AWS key id", { project: "AKIAIOSFODNN7EXAMPLE" }],
79
- ["an STS temp key id", { project: "ASIAIOSFODNN7EXAMPLE" }],
80
- ["a PEM private key", { cwd: "-----BEGIN RSA PRIVATE KEY-----" }],
81
- ["an authorization header", { model: "authorization: xyz" }],
82
- ["a bearer token", { model: "Bearer abcdefghijklmnop0123" }],
83
- ["an instance token header", { project: "x-outpost-instance-token" }],
84
- ["a refresh token field", { model: 'refresh_token="abc"' }],
85
- ["a password field", { model: "password=hunter2" }],
86
- ["a secret access key", { project: "secretaccesskey" }],
87
- ["a session token", { project: "sessiontoken" }],
88
- ];
89
-
90
- for (const [what, over] of leaks) {
91
- it(`rejects ${what}`, () => {
92
- expect(() => assertNoSecretsInPayload(payloadWith(over))).toThrow(
93
- /refusing to publish/,
94
- );
95
- });
96
- }
97
- });
98
-
99
- describe("non-whitelisted fields are still rejected", () => {
100
- it("refuses a payload carrying an extra field", () => {
101
- const p = payloadWith({});
102
- (p.sessions[0] as unknown as Record<string, unknown>).transcript = "secret";
103
- expect(() => assertNoSecretsInPayload(p)).toThrow(/non-whitelisted/);
104
- });
105
- });
@@ -1,178 +0,0 @@
1
- /**
2
- * Tests for the on-box realtime publisher (mission-control US-009):
3
- * - defaultRealtimeCredentialsFetcher POSTs the box's JWT to
4
- * /v1/realtime/credentials and parses the response
5
- * - createIotPublishPort vends scoped creds, builds an IoT client, publishes
6
- * to the caller's topic, caches the client until near-expiry, and re-guards
7
- * the no-secrets contract at the transport boundary
8
- */
9
-
10
- import { beforeEach, describe, expect, it, vi } from "vitest";
11
- import { mockClient } from "aws-sdk-client-mock";
12
- import {
13
- IoTDataPlaneClient,
14
- PublishCommand,
15
- } from "@aws-sdk/client-iot-data-plane";
16
- import {
17
- createIotPublishPort,
18
- defaultRealtimeCredentialsFetcher,
19
- type RealtimeCredentialsResponse,
20
- } from "./session-heartbeat-publisher";
21
- import type { SessionsHeartbeatPayload } from "./session-heartbeat";
22
-
23
- const PERSON = "prs_alice";
24
- const TOPIC = `hq/${PERSON}/sessions`;
25
- const NOW = new Date("2026-06-15T18:55:00.000Z");
26
-
27
- function credsResponse(
28
- expiresInMs: number,
29
- ): RealtimeCredentialsResponse {
30
- return {
31
- credentials: {
32
- accessKeyId: "ASIAEXAMPLE",
33
- secretAccessKey: "secret",
34
- sessionToken: "token",
35
- expiration: new Date(NOW.getTime() + expiresInMs).toISOString(),
36
- },
37
- iotEndpoint: "abc123-ats.iot.us-east-1.amazonaws.com",
38
- region: "us-east-1",
39
- topic: TOPIC,
40
- expiresAt: new Date(NOW.getTime() + expiresInMs).toISOString(),
41
- };
42
- }
43
-
44
- function cleanPayload(): SessionsHeartbeatPayload {
45
- return {
46
- type: "sessions",
47
- origin: "outpost",
48
- emittedAt: NOW.toISOString(),
49
- sessions: [
50
- {
51
- id: "x",
52
- tool: "claude",
53
- origin: "outpost",
54
- cwd: "/home/ec2-user/hq",
55
- project: "hq",
56
- company: null,
57
- model: "claude-opus-4",
58
- status: "running",
59
- startedAt: null,
60
- lastActivityAt: NOW.toISOString(),
61
- source: "/home/ec2-user/.claude/projects/p/x.jsonl",
62
- },
63
- ],
64
- };
65
- }
66
-
67
- describe("defaultRealtimeCredentialsFetcher", () => {
68
- it("POSTs the JWT to /v1/realtime/credentials and returns the parsed body", async () => {
69
- const body = credsResponse(3_600_000);
70
- const fetchImpl = vi.fn().mockResolvedValue({
71
- ok: true,
72
- status: 200,
73
- statusText: "OK",
74
- json: async () => body,
75
- } as Response);
76
- const fetcher = defaultRealtimeCredentialsFetcher({
77
- apiBaseUrl: "https://hqapi.hq.computer",
78
- getJwt: async () => "JWT123",
79
- fetchImpl: fetchImpl as unknown as typeof fetch,
80
- });
81
- const out = await fetcher();
82
- expect(out).toEqual(body);
83
- const [url, init] = fetchImpl.mock.calls[0];
84
- expect(url).toBe("https://hqapi.hq.computer/v1/realtime/credentials");
85
- expect(init.method).toBe("POST");
86
- expect(init.headers.authorization).toBe("Bearer JWT123");
87
- });
88
-
89
- it("throws on a non-ok response", async () => {
90
- const fetchImpl = vi.fn().mockResolvedValue({
91
- ok: false,
92
- status: 403,
93
- statusText: "Forbidden",
94
- json: async () => ({}),
95
- } as Response);
96
- const fetcher = defaultRealtimeCredentialsFetcher({
97
- apiBaseUrl: "https://hqapi.hq.computer",
98
- getJwt: async () => "JWT",
99
- fetchImpl: fetchImpl as unknown as typeof fetch,
100
- });
101
- await expect(fetcher()).rejects.toThrow(/403/);
102
- });
103
- });
104
-
105
- describe("createIotPublishPort", () => {
106
- const iotMock = mockClient(IoTDataPlaneClient);
107
- beforeEach(() => iotMock.reset());
108
-
109
- it("publishes the payload to the caller's topic via IoT", async () => {
110
- iotMock.on(PublishCommand).resolves({});
111
- const fetchCredentials = vi.fn().mockResolvedValue(credsResponse(3_600_000));
112
- const publish = createIotPublishPort({
113
- fetchCredentials,
114
- makeClient: () => iotMock as unknown as IoTDataPlaneClient,
115
- now: () => NOW,
116
- });
117
-
118
- const payload = cleanPayload();
119
- await publish(TOPIC, payload);
120
-
121
- const call = iotMock.commandCalls(PublishCommand)[0];
122
- expect(call.args[0].input.topic).toBe(TOPIC);
123
- const sent = JSON.parse(
124
- Buffer.from(call.args[0].input.payload as Uint8Array).toString("utf8"),
125
- );
126
- expect(sent.type).toBe("sessions");
127
- expect(sent.sessions[0].id).toBe("x");
128
- });
129
-
130
- it("caches the vended creds/client until near expiry, then re-vends", async () => {
131
- iotMock.on(PublishCommand).resolves({});
132
- const fetchCredentials = vi
133
- .fn()
134
- .mockResolvedValueOnce(credsResponse(3_600_000))
135
- .mockResolvedValueOnce(credsResponse(3_600_000));
136
- const publish = createIotPublishPort({
137
- fetchCredentials,
138
- makeClient: () => iotMock as unknown as IoTDataPlaneClient,
139
- now: () => NOW,
140
- });
141
-
142
- await publish(TOPIC, cleanPayload());
143
- await publish(TOPIC, cleanPayload());
144
- // Second publish reuses the cached client — creds vended once.
145
- expect(fetchCredentials).toHaveBeenCalledTimes(1);
146
- });
147
-
148
- it("re-vends when the cached creds are within the refresh skew of expiry", async () => {
149
- iotMock.on(PublishCommand).resolves({});
150
- const fetchCredentials = vi
151
- .fn()
152
- // expires in 30s — inside the 60s refresh skew, so every call re-vends
153
- .mockResolvedValue(credsResponse(30_000));
154
- const publish = createIotPublishPort({
155
- fetchCredentials,
156
- makeClient: () => iotMock as unknown as IoTDataPlaneClient,
157
- now: () => NOW,
158
- });
159
- await publish(TOPIC, cleanPayload());
160
- await publish(TOPIC, cleanPayload());
161
- expect(fetchCredentials).toHaveBeenCalledTimes(2);
162
- });
163
-
164
- it("re-guards the no-secrets contract at the transport boundary", async () => {
165
- iotMock.on(PublishCommand).resolves({});
166
- const fetchCredentials = vi.fn().mockResolvedValue(credsResponse(3_600_000));
167
- const publish = createIotPublishPort({
168
- fetchCredentials,
169
- makeClient: () => iotMock as unknown as IoTDataPlaneClient,
170
- now: () => NOW,
171
- });
172
- const dirty = cleanPayload();
173
- // Smuggle a secret into a whitelisted field — the publisher must refuse.
174
- dirty.sessions[0].model = "sk-ant-leaked-key";
175
- await expect(publish(TOPIC, dirty)).rejects.toThrow(/secret marker/);
176
- expect(iotMock.commandCalls(PublishCommand)).toHaveLength(0);
177
- });
178
- });