@indigoai-us/hq-cloud 6.15.3 → 6.15.5

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 (150) hide show
  1. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  2. package/dist/bin/sync-runner-company.js +15 -0
  3. package/dist/bin/sync-runner-company.js.map +1 -1
  4. package/dist/bin/sync-runner-company.test.js +71 -0
  5. package/dist/bin/sync-runner-company.test.js.map +1 -1
  6. package/dist/bin/sync-runner-events.test.js +21 -0
  7. package/dist/bin/sync-runner-events.test.js.map +1 -1
  8. package/dist/bin/sync-runner.d.ts +5 -0
  9. package/dist/bin/sync-runner.d.ts.map +1 -1
  10. package/dist/bin/sync-runner.js.map +1 -1
  11. package/dist/cli/push-scan-exclusions.test.d.ts +2 -0
  12. package/dist/cli/push-scan-exclusions.test.d.ts.map +1 -0
  13. package/dist/cli/push-scan-exclusions.test.js +87 -0
  14. package/dist/cli/push-scan-exclusions.test.js.map +1 -0
  15. package/dist/cli/share.d.ts.map +1 -1
  16. package/dist/cli/share.js +44 -7
  17. package/dist/cli/share.js.map +1 -1
  18. package/dist/cli/share.test.js +136 -1
  19. package/dist/cli/share.test.js.map +1 -1
  20. package/dist/cli/sync.d.ts +47 -0
  21. package/dist/cli/sync.d.ts.map +1 -1
  22. package/dist/cli/sync.js +46 -1
  23. package/dist/cli/sync.js.map +1 -1
  24. package/dist/cli/sync.test.js +153 -0
  25. package/dist/cli/sync.test.js.map +1 -1
  26. package/dist/outposts/billing.d.ts +41 -0
  27. package/dist/outposts/billing.d.ts.map +1 -0
  28. package/dist/outposts/billing.js +53 -0
  29. package/dist/outposts/billing.js.map +1 -0
  30. package/dist/outposts/cli-billing.d.ts +59 -0
  31. package/dist/outposts/cli-billing.d.ts.map +1 -0
  32. package/dist/outposts/cli-billing.js +93 -0
  33. package/dist/outposts/cli-billing.js.map +1 -0
  34. package/dist/outposts/cli.d.ts +13 -0
  35. package/dist/outposts/cli.d.ts.map +1 -0
  36. package/dist/outposts/cli.js +13 -0
  37. package/dist/outposts/cli.js.map +1 -0
  38. package/dist/outposts/client.d.ts +140 -0
  39. package/dist/outposts/client.d.ts.map +1 -0
  40. package/dist/outposts/client.js +271 -0
  41. package/dist/outposts/client.js.map +1 -0
  42. package/dist/outposts/client.test.d.ts +9 -0
  43. package/dist/outposts/client.test.d.ts.map +1 -0
  44. package/dist/outposts/client.test.js +226 -0
  45. package/dist/outposts/client.test.js.map +1 -0
  46. package/dist/outposts/command.d.ts +74 -0
  47. package/dist/outposts/command.d.ts.map +1 -0
  48. package/dist/outposts/command.js +661 -0
  49. package/dist/outposts/command.js.map +1 -0
  50. package/dist/outposts/command.test.d.ts +18 -0
  51. package/dist/outposts/command.test.d.ts.map +1 -0
  52. package/dist/outposts/command.test.js +933 -0
  53. package/dist/outposts/command.test.js.map +1 -0
  54. package/dist/outposts/errors.d.ts +32 -0
  55. package/dist/outposts/errors.d.ts.map +1 -0
  56. package/dist/outposts/errors.js +72 -0
  57. package/dist/outposts/errors.js.map +1 -0
  58. package/dist/outposts/heartbeat-command.d.ts +106 -0
  59. package/dist/outposts/heartbeat-command.d.ts.map +1 -0
  60. package/dist/outposts/heartbeat-command.js +186 -0
  61. package/dist/outposts/heartbeat-command.js.map +1 -0
  62. package/dist/outposts/host-deps.d.ts +49 -0
  63. package/dist/outposts/host-deps.d.ts.map +1 -0
  64. package/dist/outposts/host-deps.js +93 -0
  65. package/dist/outposts/host-deps.js.map +1 -0
  66. package/dist/outposts/index.d.ts +36 -0
  67. package/dist/outposts/index.d.ts.map +1 -0
  68. package/dist/outposts/index.js +32 -0
  69. package/dist/outposts/index.js.map +1 -0
  70. package/dist/outposts/node.d.ts +23 -0
  71. package/dist/outposts/node.d.ts.map +1 -0
  72. package/dist/outposts/node.js +22 -0
  73. package/dist/outposts/node.js.map +1 -0
  74. package/dist/outposts/remote-command.d.ts +30 -0
  75. package/dist/outposts/remote-command.d.ts.map +1 -0
  76. package/dist/outposts/remote-command.js +39 -0
  77. package/dist/outposts/remote-command.js.map +1 -0
  78. package/dist/outposts/replica-sync.d.ts +40 -0
  79. package/dist/outposts/replica-sync.d.ts.map +1 -0
  80. package/dist/outposts/replica-sync.js +188 -0
  81. package/dist/outposts/replica-sync.js.map +1 -0
  82. package/dist/outposts/replica-sync.test.d.ts +2 -0
  83. package/dist/outposts/replica-sync.test.d.ts.map +1 -0
  84. package/dist/outposts/replica-sync.test.js +224 -0
  85. package/dist/outposts/replica-sync.test.js.map +1 -0
  86. package/dist/outposts/self-deploy.d.ts +47 -0
  87. package/dist/outposts/self-deploy.d.ts.map +1 -0
  88. package/dist/outposts/self-deploy.js +188 -0
  89. package/dist/outposts/self-deploy.js.map +1 -0
  90. package/dist/outposts/self-deploy.test.d.ts +2 -0
  91. package/dist/outposts/self-deploy.test.d.ts.map +1 -0
  92. package/dist/outposts/self-deploy.test.js +186 -0
  93. package/dist/outposts/self-deploy.test.js.map +1 -0
  94. package/dist/outposts/session-heartbeat-bounds.test.d.ts +25 -0
  95. package/dist/outposts/session-heartbeat-bounds.test.d.ts.map +1 -0
  96. package/dist/outposts/session-heartbeat-bounds.test.js +156 -0
  97. package/dist/outposts/session-heartbeat-bounds.test.js.map +1 -0
  98. package/dist/outposts/session-heartbeat-guard.test.d.ts +16 -0
  99. package/dist/outposts/session-heartbeat-guard.test.d.ts.map +1 -0
  100. package/dist/outposts/session-heartbeat-guard.test.js +88 -0
  101. package/dist/outposts/session-heartbeat-guard.test.js.map +1 -0
  102. package/dist/outposts/session-heartbeat-publisher.d.ts +76 -0
  103. package/dist/outposts/session-heartbeat-publisher.d.ts.map +1 -0
  104. package/dist/outposts/session-heartbeat-publisher.js +117 -0
  105. package/dist/outposts/session-heartbeat-publisher.js.map +1 -0
  106. package/dist/outposts/session-heartbeat-publisher.test.d.ts +10 -0
  107. package/dist/outposts/session-heartbeat-publisher.test.d.ts.map +1 -0
  108. package/dist/outposts/session-heartbeat-publisher.test.js +153 -0
  109. package/dist/outposts/session-heartbeat-publisher.test.js.map +1 -0
  110. package/dist/outposts/session-heartbeat-retain-guard.test.d.ts +18 -0
  111. package/dist/outposts/session-heartbeat-retain-guard.test.d.ts.map +1 -0
  112. package/dist/outposts/session-heartbeat-retain-guard.test.js +106 -0
  113. package/dist/outposts/session-heartbeat-retain-guard.test.js.map +1 -0
  114. package/dist/outposts/session-heartbeat.d.ts +210 -0
  115. package/dist/outposts/session-heartbeat.d.ts.map +1 -0
  116. package/dist/outposts/session-heartbeat.js +657 -0
  117. package/dist/outposts/session-heartbeat.js.map +1 -0
  118. package/dist/outposts/session-heartbeat.test.d.ts +11 -0
  119. package/dist/outposts/session-heartbeat.test.d.ts.map +1 -0
  120. package/dist/outposts/session-heartbeat.test.js +370 -0
  121. package/dist/outposts/session-heartbeat.test.js.map +1 -0
  122. package/dist/outposts/ssh.d.ts +29 -0
  123. package/dist/outposts/ssh.d.ts.map +1 -0
  124. package/dist/outposts/ssh.js +66 -0
  125. package/dist/outposts/ssh.js.map +1 -0
  126. package/dist/outposts/transport.d.ts +76 -0
  127. package/dist/outposts/transport.d.ts.map +1 -0
  128. package/dist/outposts/transport.js +91 -0
  129. package/dist/outposts/transport.js.map +1 -0
  130. package/dist/outposts/transport.test.d.ts +10 -0
  131. package/dist/outposts/transport.test.d.ts.map +1 -0
  132. package/dist/outposts/transport.test.js +116 -0
  133. package/dist/outposts/transport.test.js.map +1 -0
  134. package/dist/outposts/types.d.ts +125 -0
  135. package/dist/outposts/types.d.ts.map +1 -0
  136. package/dist/outposts/types.js +13 -0
  137. package/dist/outposts/types.js.map +1 -0
  138. package/dist/personal-vault.d.ts +69 -0
  139. package/dist/personal-vault.d.ts.map +1 -1
  140. package/dist/personal-vault.js +100 -0
  141. package/dist/personal-vault.js.map +1 -1
  142. package/dist/personal-vault.test.js +140 -1
  143. package/dist/personal-vault.test.js.map +1 -1
  144. package/dist/s3.d.ts +36 -0
  145. package/dist/s3.d.ts.map +1 -1
  146. package/dist/s3.js +61 -1
  147. package/dist/s3.js.map +1 -1
  148. package/dist/s3.symlink-materialize.test.js +161 -1
  149. package/dist/s3.symlink-materialize.test.js.map +1 -1
  150. package/package.json +39 -3
@@ -0,0 +1,186 @@
1
+ import { Command } from "commander";
2
+ import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
3
+ import { registerOutpostsCommand } from "./command.js";
4
+ // The box-side commands were the only thing these suites drove, but the command
5
+ // tree now needs full host deps. Everything except the injected host-environment
6
+ // surface is inert here (no control-plane call is made), so stub the transport
7
+ // and token minimally and route the test's `Partial<SelfDeployDependencies>`
8
+ // through `.host`.
9
+ function outpostsDepsWithHost(host) {
10
+ return {
11
+ transport: async () => new Response("{}", { status: 200 }),
12
+ getToken: async () => "test-token",
13
+ loadCachedTokens: () => ({ refreshToken: "rt_test" }),
14
+ resolveCallerPersonUid: async () => "prs_test",
15
+ defaultApiBaseUrl: "https://hqapi.test.invalid",
16
+ host,
17
+ };
18
+ }
19
+ const AL2023 = 'ID="amzn"\nVERSION_ID="2023"\n';
20
+ const SECRET = "refresh-token-that-must-never-be-printed";
21
+ function successfulSpawn(stdout = "") {
22
+ return {
23
+ status: 0,
24
+ stdout,
25
+ stderr: "",
26
+ error: undefined,
27
+ };
28
+ }
29
+ function selfDeployDependencies(input = {}) {
30
+ const calls = [];
31
+ const deps = {
32
+ readTextFile: () => input.osRelease ?? AL2023,
33
+ loadCachedTokens: () => input.session ?? { refreshToken: SECRET },
34
+ getUid: () => input.uid ?? 1000,
35
+ isStdinTty: () => input.stdinTty ?? true,
36
+ confirm: async () => true,
37
+ defaultHqRoot: () => "/home/ec2-user/hq",
38
+ invokingUser: () => "ec2-user",
39
+ spawnSync: ((command, args, options) => {
40
+ calls.push({ command, args, options });
41
+ if (command === "uname")
42
+ return successfulSpawn(input.uname ?? "x86_64\n");
43
+ if (command === "systemctl" && args[0] === "--version") {
44
+ return input.systemd === false
45
+ ? { ...successfulSpawn(), status: 1 }
46
+ : successfulSpawn("systemd 252\n");
47
+ }
48
+ if (command === "sudo" && args[0] === "-n") {
49
+ return input.sudo === false ? { ...successfulSpawn(), status: 1 } : successfulSpawn();
50
+ }
51
+ return successfulSpawn();
52
+ }),
53
+ };
54
+ return { deps, calls };
55
+ }
56
+ function buildProgram(deps) {
57
+ const program = new Command();
58
+ program.name("hq").exitOverride();
59
+ registerOutpostsCommand(program, outpostsDepsWithHost(deps));
60
+ return program;
61
+ }
62
+ async function run(deps, args) {
63
+ await buildProgram(deps).parseAsync(["node", "hq", ...args]);
64
+ }
65
+ let exitSpy;
66
+ let logSpy;
67
+ let errorSpy;
68
+ let fetchSpy;
69
+ beforeEach(() => {
70
+ exitSpy = vi
71
+ .spyOn(process, "exit")
72
+ .mockImplementation((code) => {
73
+ throw new Error(`process.exit(${code})`);
74
+ });
75
+ logSpy = vi.spyOn(console, "log").mockImplementation(() => { });
76
+ errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
77
+ fetchSpy = vi.spyOn(globalThis, "fetch");
78
+ });
79
+ afterEach(() => {
80
+ vi.restoreAllMocks();
81
+ });
82
+ function printed() {
83
+ return [
84
+ ...logSpy.mock.calls.map((call) => call.map(String).join(" ")),
85
+ ...errorSpy.mock.calls.map((call) => call.map(String).join(" ")),
86
+ ].join("\n");
87
+ }
88
+ function installedCommands(calls) {
89
+ return calls.filter((call) => call.command === "hq" ||
90
+ (call.command === "sudo" &&
91
+ ["tee", "chmod", "systemctl"].includes(call.args[0] ?? "")));
92
+ }
93
+ describe("hq outposts self-deploy", () => {
94
+ it("is hidden from outposts help but remains invokable", async () => {
95
+ const { deps, calls } = selfDeployDependencies();
96
+ const program = buildProgram(deps);
97
+ const outposts = program.commands.find((command) => command.name() === "outposts");
98
+ expect(outposts?.helpInformation()).not.toContain("self-deploy");
99
+ await run(deps, ["outposts", "self-deploy", "--yes"]);
100
+ expect(calls).toContainEqual(expect.objectContaining({
101
+ command: "hq",
102
+ args: ["rescue", "--hq-root", "/home/ec2-user/hq", "--yes"],
103
+ }));
104
+ });
105
+ it("rejects non-Amazon Linux 2023 before installing anything", async () => {
106
+ const { deps, calls } = selfDeployDependencies({
107
+ osRelease: 'ID="ubuntu"\nVERSION_ID="24.04"\n',
108
+ });
109
+ await expect(run(deps, ["outposts", "self-deploy", "--yes"])).rejects.toThrow("process.exit(1)");
110
+ expect(printed()).toContain("Amazon Linux 2023 x86_64");
111
+ expect(installedCommands(calls)).toEqual([]);
112
+ });
113
+ it("rejects a host without systemd before installing anything", async () => {
114
+ const { deps, calls } = selfDeployDependencies({ systemd: false });
115
+ await expect(run(deps, ["outposts", "self-deploy", "--yes"])).rejects.toThrow("process.exit(1)");
116
+ expect(printed()).toContain("systemd is required");
117
+ expect(installedCommands(calls)).toEqual([]);
118
+ });
119
+ it("requires an existing hq login before installing anything", async () => {
120
+ const { deps, calls } = selfDeployDependencies({ session: undefined });
121
+ deps.loadCachedTokens = () => undefined;
122
+ await expect(run(deps, ["outposts", "self-deploy", "--yes"])).rejects.toThrow("process.exit(1)");
123
+ expect(printed()).toContain("hq login");
124
+ expect(installedCommands(calls)).toEqual([]);
125
+ });
126
+ it("aborts without a TTY or --yes before running install commands", async () => {
127
+ const idToken = `header.${Buffer.from(JSON.stringify({ email: "person@example.com" })).toString("base64url")}.signature`;
128
+ const { deps, calls } = selfDeployDependencies({
129
+ stdinTty: false,
130
+ session: { refreshToken: SECRET, idToken },
131
+ });
132
+ await expect(run(deps, ["outposts", "self-deploy"])).rejects.toThrow("process.exit(1)");
133
+ expect(printed()).toContain("HQ identity: person@example.com");
134
+ expect(printed()).toContain("SELF-HOSTED HQ outpost");
135
+ expect(printed()).toMatch(/pass --yes/i);
136
+ expect(installedCommands(calls)).toEqual([]);
137
+ });
138
+ it("installs the pinned legacy launcher without a local realtime enrollment override", async () => {
139
+ const { deps, calls } = selfDeployDependencies();
140
+ await run(deps, ["outposts", "self-deploy", "--yes"]);
141
+ expect(calls).toContainEqual(expect.objectContaining({
142
+ command: "hq",
143
+ args: ["rescue", "--hq-root", "/home/ec2-user/hq", "--yes"],
144
+ }));
145
+ const serviceWrite = calls.find((call) => call.command === "sudo" &&
146
+ call.args[0] === "tee" &&
147
+ call.args[1] === "/etc/systemd/system/outpost-sync.service");
148
+ const serviceContents = String(serviceWrite?.options?.input);
149
+ expect(serviceContents).toContain("User=ec2-user");
150
+ expect(serviceContents).toContain("WorkingDirectory=\"/home/ec2-user/hq\"");
151
+ expect(serviceContents).toContain("ExecStart=/usr/local/bin/outpost-sync.sh");
152
+ expect(serviceContents).toContain("Restart=always");
153
+ const scriptWrite = calls.find((call) => call.command === "sudo" &&
154
+ call.args[0] === "tee" &&
155
+ call.args[1] === "/usr/local/bin/outpost-sync.sh");
156
+ const scriptContents = String(scriptWrite?.options?.input);
157
+ expect(scriptContents).toContain("hq auth refresh");
158
+ expect(scriptContents).toContain(`npx -y --package=@indigoai-us/hq-cloud@6.15.1 hq-sync-runner \\
159
+ --companies \\
160
+ --direction both \\
161
+ --on-conflict keep \\
162
+ --hq-root "$HQ_ROOT" \\
163
+ --watch \\
164
+ --event-push \\
165
+ --poll-remote-ms 60000`);
166
+ expect(scriptContents).not.toContain("@latest");
167
+ // An Outpost cannot opt itself into V2. Eligibility is fail-closed at the
168
+ // server; this launcher must not introduce a local realtime bypass.
169
+ expect(scriptContents).not.toMatch(/--(?:enable-)?realtime(?:-sync)?\b/);
170
+ expect(calls).toContainEqual(expect.objectContaining({
171
+ command: "sudo",
172
+ args: ["systemctl", "enable", "--now", "outpost-sync.service"],
173
+ }));
174
+ });
175
+ it("never exposes session secrets or makes hq-pro requests", async () => {
176
+ const { deps, calls } = selfDeployDependencies({
177
+ session: { refreshToken: SECRET },
178
+ });
179
+ await run(deps, ["outposts", "self-deploy", "--yes"]);
180
+ expect(JSON.stringify(calls)).not.toContain(SECRET);
181
+ expect(printed()).not.toContain(SECRET);
182
+ expect(fetchSpy).not.toHaveBeenCalled();
183
+ expect(exitSpy).not.toHaveBeenCalled();
184
+ });
185
+ });
186
+ //# sourceMappingURL=self-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CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACxC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,25 @@
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
+ export {};
25
+ //# sourceMappingURL=session-heartbeat-bounds.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-heartbeat-bounds.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-bounds.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG"}
@@ -0,0 +1,156 @@
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
+ import { describe, expect, it } from "vitest";
25
+ import { DEFAULT_LIVENESS_THRESHOLDS, IOT_PAYLOAD_BUDGET_BYTES, collectSessions, } from "./session-heartbeat.js";
26
+ const NOW = new Date("2026-07-29T12:00:00.000Z");
27
+ const NOW_MS = NOW.getTime();
28
+ /**
29
+ * A fake Claude tree with `count` transcripts, each aged `ageSecondsFor(i)`.
30
+ * Codex enumeration sees an empty tree.
31
+ */
32
+ function claudeTreeFs(count, ageSecondsFor) {
33
+ const names = Array.from({ length: count }, (_, i) => `${i.toString(16).padStart(8, "0")}-aaaa-bbbb-cccc-dddddddddddd.jsonl`);
34
+ const ageOf = new Map();
35
+ names.forEach((n, i) => ageOf.set(n, ageSecondsFor(i)));
36
+ return {
37
+ async readDir(path) {
38
+ if (path.endsWith("/.claude/projects")) {
39
+ return [{ name: "-home-ec2-user-hq", isDirectory: true, isFile: false }];
40
+ }
41
+ if (path.endsWith("/.claude/projects/-home-ec2-user-hq")) {
42
+ return names.map((name) => ({
43
+ name,
44
+ isDirectory: false,
45
+ isFile: true,
46
+ }));
47
+ }
48
+ return [];
49
+ },
50
+ async stat(path) {
51
+ const name = path.split("/").pop() ?? "";
52
+ const age = ageOf.get(name) ?? 0;
53
+ const mtimeMs = NOW_MS - age * 1000;
54
+ return { mtimeMs, birthtimeMs: mtimeMs, size: 1024 };
55
+ },
56
+ async readTextFile() {
57
+ return "";
58
+ },
59
+ async readBounded() {
60
+ // A realistic cwd/model sniff, so each record is a realistic size.
61
+ return JSON.stringify({
62
+ cwd: "/home/ec2-user/hq/repos/private/some-longish-repo-name",
63
+ model: "claude-opus-4-8",
64
+ });
65
+ },
66
+ };
67
+ }
68
+ const config = { personUid: "prs_01TEST", home: "/home/ec2-user", now: () => NOW };
69
+ describe("payload bounding", () => {
70
+ it("publishes live sessions and drops the ended archive", async () => {
71
+ // 500 sessions: the first 5 active, the rest ancient — the real shape of
72
+ // a box that has been running for weeks.
73
+ const fs = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
74
+ const payload = await collectSessions(config, { fs });
75
+ expect(payload.sessions).toHaveLength(5);
76
+ expect(payload.sessions.every((s) => s.status !== "ended")).toBe(true);
77
+ });
78
+ it("reports how many sessions exist, not just how many it sent", async () => {
79
+ const fs = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
80
+ const payload = await collectSessions(config, { fs });
81
+ // Silent filtering reads as "this box has 5 sessions". It has 500.
82
+ expect(payload.totalSessions).toBe(500);
83
+ // `totalSessions` is optional on the payload, so coalesce rather than assert
84
+ // non-null: a missing count then fails this comparison instead of throwing a
85
+ // confusing error, which is the right outcome — an absent total IS the bug
86
+ // this test exists to catch.
87
+ expect(payload.sessions.length).toBeLessThan(payload.totalSessions ?? 0);
88
+ });
89
+ it("keeps idle sessions — only `ended` is archive", async () => {
90
+ // 2s → running, 5min → idle, 30d → ended.
91
+ const fs = claudeTreeFs(3, (i) => [2, 300, 60 * 60 * 24 * 30][i]);
92
+ const payload = await collectSessions(config, { fs });
93
+ const statuses = payload.sessions.map((s) => s.status).sort();
94
+ expect(statuses).toEqual(["idle", "running"]);
95
+ });
96
+ it("stays under the IoT limit even when every session is live", async () => {
97
+ // 5,000 sessions all active — the size bound, not the status filter, is
98
+ // what has to hold here.
99
+ const fs = claudeTreeFs(5000, () => 2);
100
+ const payload = await collectSessions(config, { fs });
101
+ const bytes = Buffer.byteLength(JSON.stringify(payload), "utf8");
102
+ expect(bytes).toBeLessThanOrEqual(IOT_PAYLOAD_BUDGET_BYTES);
103
+ // The real AWS IoT Core ceiling. The budget must leave headroom under it.
104
+ expect(bytes).toBeLessThan(131072);
105
+ });
106
+ it("flags truncation rather than quietly shortening the list", async () => {
107
+ const fs = claudeTreeFs(5000, () => 2);
108
+ const payload = await collectSessions(config, { fs });
109
+ expect(payload.truncated).toBe(true);
110
+ expect(payload.totalSessions).toBe(5000);
111
+ expect(payload.sessions.length).toBeLessThan(5000);
112
+ });
113
+ it("does not flag truncation when everything fits", async () => {
114
+ const fs = claudeTreeFs(3, () => 2);
115
+ const payload = await collectSessions(config, { fs });
116
+ expect(payload.truncated).toBe(false);
117
+ expect(payload.sessions).toHaveLength(3);
118
+ expect(payload.totalSessions).toBe(3);
119
+ });
120
+ it("reads transcript bodies ONLY for sessions it will publish", async () => {
121
+ // The enumerator statted every file AND did a 16 KiB bounded read on each,
122
+ // before anything was filtered. On the first real box that was 9,340 reads
123
+ // per tick, every 5 seconds — ~150 MB of disk for 15 useful records, on
124
+ // the exact resource that had already taken the machine down once.
125
+ const reads = [];
126
+ const base = claudeTreeFs(500, (i) => (i < 5 ? 2 : 60 * 60 * 24 * 30));
127
+ const fs = {
128
+ ...base,
129
+ async readBounded(path, maxBytes, from) {
130
+ reads.push(path);
131
+ return base.readBounded(path, maxBytes, from);
132
+ },
133
+ };
134
+ const payload = await collectSessions(config, { fs });
135
+ expect(payload.sessions).toHaveLength(5);
136
+ // Five live sessions ⇒ five reads, not five hundred.
137
+ expect(reads).toHaveLength(5);
138
+ });
139
+ it("keeps the MOST RECENTLY ACTIVE sessions when it has to choose", async () => {
140
+ // Index 0 is freshest, index N oldest — all still within `idle`.
141
+ const fs = claudeTreeFs(5000, (i) => 1 + i * (1 / 10));
142
+ const payload = await collectSessions(config, { fs });
143
+ expect(payload.truncated).toBe(true);
144
+ // Dropping the newest and keeping stale ones would make the live view
145
+ // wrong in the one way that matters.
146
+ const kept = payload.sessions
147
+ .map((s) => Date.parse(s.lastActivityAt))
148
+ .sort((a, b) => a - b);
149
+ const oldestKept = kept[0];
150
+ const cutoff = NOW_MS - DEFAULT_LIVENESS_THRESHOLDS.idleWithinSeconds * 1000;
151
+ expect(oldestKept).toBeGreaterThan(cutoff);
152
+ // The single freshest session must always survive.
153
+ expect(Math.max(...kept)).toBe(NOW_MS - 1000);
154
+ });
155
+ });
156
+ //# sourceMappingURL=session-heartbeat-bounds.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-heartbeat-bounds.test.js","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-bounds.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,eAAe,GAIhB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC;AACjD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;AAE7B;;;GAGG;AACH,SAAS,YAAY,CACnB,KAAa,EACb,aAAoC;IAEpC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CACtB,EAAE,MAAM,EAAE,KAAK,EAAE,EACjB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACP,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,oCAAoC,CACzE,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,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CAAC,CAAC,CAAC,cAAe,CAAC,CAAC;aACzC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QAC5B,MAAM,MAAM,GACV,MAAM,GAAG,2BAA2B,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChE,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,mDAAmD;QACnD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
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
+ export {};
16
+ //# sourceMappingURL=session-heartbeat-guard.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-heartbeat-guard.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-guard.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -0,0 +1,88 @@
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
+ import { describe, expect, it } from "vitest";
16
+ import { assertNoSecretsInPayload, } from "./session-heartbeat.js";
17
+ function payloadWith(over) {
18
+ const session = {
19
+ id: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
20
+ tool: "claude",
21
+ origin: "outpost",
22
+ cwd: "/home/ec2-user/hq",
23
+ project: "hq",
24
+ company: null,
25
+ model: "claude-opus-4-8",
26
+ status: "running",
27
+ startedAt: "2026-07-29T12:00:00.000Z",
28
+ lastActivityAt: "2026-07-29T12:00:00.000Z",
29
+ source: "/home/ec2-user/.claude/projects/-home-ec2-user-hq/x.jsonl",
30
+ ...over,
31
+ };
32
+ return {
33
+ type: "sessions",
34
+ origin: "outpost",
35
+ emittedAt: "2026-07-29T12:00:00.000Z",
36
+ sessions: [session],
37
+ };
38
+ }
39
+ describe("ordinary paths must never trip the guard", () => {
40
+ // Every one of these contains `sk-` or `asia` and would have thrown before.
41
+ const innocentPaths = [
42
+ "/home/ec2-user/hq/repos/private/task-runner",
43
+ "/home/ec2-user/hq/repos/public/flask-app",
44
+ "/home/ec2-user/hq/tools/disk-usage",
45
+ "/home/ec2-user/hq/models/risk-model",
46
+ "/home/ec2-user/hq/regions/asia-pacific",
47
+ "/home/ec2-user/hq/repos/private/password-manager",
48
+ "/home/ec2-user/hq/kiosk-display",
49
+ ];
50
+ for (const cwd of innocentPaths) {
51
+ it(`allows ${cwd.split("/").pop()}`, () => {
52
+ const project = cwd.split("/").pop();
53
+ expect(() => assertNoSecretsInPayload(payloadWith({ cwd, project, source: `${cwd}/s.jsonl` }))).not.toThrow();
54
+ });
55
+ }
56
+ it("allows a model id that merely starts with the letters sk", () => {
57
+ expect(() => assertNoSecretsInPayload(payloadWith({ model: "sk-lite-preview" }))).not.toThrow();
58
+ });
59
+ });
60
+ describe("real credentials must still be caught", () => {
61
+ const leaks = [
62
+ ["an Anthropic key", { model: "sk-ant-api03-AbCdEfGhIjKlMnOpQrStUv" }],
63
+ ["an OpenAI-style key", { model: "sk-AbCdEfGhIjKlMnOpQrStUvWxYz012345" }],
64
+ ["a long-lived AWS key id", { project: "AKIAIOSFODNN7EXAMPLE" }],
65
+ ["an STS temp key id", { project: "ASIAIOSFODNN7EXAMPLE" }],
66
+ ["a PEM private key", { cwd: "-----BEGIN RSA PRIVATE KEY-----" }],
67
+ ["an authorization header", { model: "authorization: xyz" }],
68
+ ["a bearer token", { model: "Bearer abcdefghijklmnop0123" }],
69
+ ["an instance token header", { project: "x-outpost-instance-token" }],
70
+ ["a refresh token field", { model: 'refresh_token="abc"' }],
71
+ ["a password field", { model: "password=hunter2" }],
72
+ ["a secret access key", { project: "secretaccesskey" }],
73
+ ["a session token", { project: "sessiontoken" }],
74
+ ];
75
+ for (const [what, over] of leaks) {
76
+ it(`rejects ${what}`, () => {
77
+ expect(() => assertNoSecretsInPayload(payloadWith(over))).toThrow(/refusing to publish/);
78
+ });
79
+ }
80
+ });
81
+ describe("non-whitelisted fields are still rejected", () => {
82
+ it("refuses a payload carrying an extra field", () => {
83
+ const p = payloadWith({});
84
+ p.sessions[0].transcript = "secret";
85
+ expect(() => assertNoSecretsInPayload(p)).toThrow(/non-whitelisted/);
86
+ });
87
+ });
88
+ //# sourceMappingURL=session-heartbeat-guard.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-heartbeat-guard.test.js","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-guard.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,w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C,wBAAwB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAC/D,qBAAqB,CACtB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACzD,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;QACzB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAwC,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC5E,MAAM,CAAC,GAAG,EAAE,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Outpost on-box realtime publisher — mission-control US-009.
3
+ *
4
+ * The box already holds a Cognito session (seeded from the caller's refresh
5
+ * token in user-data, kept fresh by the box's auth timers — see provision.ts).
6
+ * This module turns that session into a `PublishPort` for the session-heartbeat
7
+ * emitter using the EXACT on-box credential pattern the rest of the realtime
8
+ * fabric uses (docs/realtime-fabric.md):
9
+ *
10
+ * 1. POST {HQAPI}/v1/realtime/credentials with the box's Cognito JWT.
11
+ * The Lambda resolves the caller's `personUid` from the verified JWT
12
+ * (never request input) and vends short-lived STS creds whose session
13
+ * policy scopes `iot:Connect/Publish/...` to `hq/{personUid}/*` only.
14
+ * 2. SigV4-sign an IoT Data-plane publish with those creds to
15
+ * `hq/{personUid}/sessions`.
16
+ *
17
+ * No new auth surface, no embedded long-lived key, no per-device cert — the
18
+ * per-identity STS session policy is the isolation boundary (US-010).
19
+ *
20
+ * The HTTP fetch + IoT client are injected so this is unit-testable without a
21
+ * live endpoint; `defaultRealtimeCredentialsFetcher` and the IoT publish are
22
+ * the production wiring.
23
+ */
24
+ import { IoTDataPlaneClient } from "@aws-sdk/client-iot-data-plane";
25
+ import type { PublishPort } from "./session-heartbeat.js";
26
+ import { sessionsTopicForPerson } from "./session-heartbeat.js";
27
+ /** Shape returned by `POST /v1/realtime/credentials` (mirrors the handler). */
28
+ export interface RealtimeCredentialsResponse {
29
+ credentials: {
30
+ accessKeyId: string;
31
+ secretAccessKey: string;
32
+ sessionToken: string;
33
+ expiration: string;
34
+ };
35
+ iotEndpoint: string;
36
+ region: string;
37
+ /** The caller's own topic — `hq/{personUid}/...`. */
38
+ topic: string;
39
+ expiresAt: string;
40
+ }
41
+ /** Fetches scoped realtime credentials for the box. Injected for tests. */
42
+ export type RealtimeCredentialsFetcher = () => Promise<RealtimeCredentialsResponse>;
43
+ /** Ceiling on a single credentials request. */
44
+ export declare const DEFAULT_CREDENTIALS_TIMEOUT_MS = 10000;
45
+ /**
46
+ * Build the production credentials fetcher. Reads the box's current Cognito
47
+ * id/access token via the injected `getJwt` and POSTs it to the
48
+ * realtime-credentials endpoint.
49
+ */
50
+ export declare function defaultRealtimeCredentialsFetcher(opts: {
51
+ apiBaseUrl: string;
52
+ getJwt: () => Promise<string>;
53
+ fetchImpl?: typeof fetch;
54
+ /** Bound the request. Defaults to {@link DEFAULT_CREDENTIALS_TIMEOUT_MS}. */
55
+ timeoutMs?: number;
56
+ }): RealtimeCredentialsFetcher;
57
+ /**
58
+ * Create a `PublishPort` that vends scoped creds (refreshing before expiry) and
59
+ * publishes the compact payload to the box's own sessions topic over MQTT/IoT.
60
+ *
61
+ * @param fetchCredentials vends per-identity-scoped STS creds + IoT endpoint
62
+ * @param makeClient builds an IoT client from creds (injected for tests)
63
+ * @param now clock injection
64
+ */
65
+ export declare function createIotPublishPort(opts: {
66
+ fetchCredentials: RealtimeCredentialsFetcher;
67
+ makeClient?: (args: {
68
+ endpoint: string;
69
+ region: string;
70
+ credentials: RealtimeCredentialsResponse["credentials"];
71
+ }) => IoTDataPlaneClient;
72
+ now?: () => Date;
73
+ }): PublishPort;
74
+ /** Re-export for the runner so it imports one module. */
75
+ export { sessionsTopicForPerson };
76
+ //# sourceMappingURL=session-heartbeat-publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-heartbeat-publisher.d.ts","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,kBAAkB,EAEnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAEhC,+EAA+E;AAC/E,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,MAAM,MAAM,0BAA0B,GAAG,MAAM,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAEpF,+CAA+C;AAC/C,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,0BAA0B,CAyB7B;AAUD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,gBAAgB,EAAE,0BAA0B,CAAC;IAC7C,UAAU,CAAC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