@indigoai-us/hq-cloud 6.15.4 → 6.15.6
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.
- package/dist/cli/push-scan-exclusions.test.d.ts +2 -0
- package/dist/cli/push-scan-exclusions.test.d.ts.map +1 -0
- package/dist/cli/push-scan-exclusions.test.js +87 -0
- package/dist/cli/push-scan-exclusions.test.js.map +1 -0
- package/dist/cli/rescue-exec-bit-preserve.test.js +8 -0
- package/dist/cli/rescue-exec-bit-preserve.test.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +21 -1
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +82 -0
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +23 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +9 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/lib/net-errors.d.ts.map +1 -1
- package/dist/lib/net-errors.js +4 -0
- package/dist/lib/net-errors.js.map +1 -1
- package/dist/machine-auth.test.js +7 -1
- package/dist/machine-auth.test.js.map +1 -1
- package/dist/object-io.d.ts +21 -0
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +229 -77
- package/dist/object-io.js.map +1 -1
- package/dist/object-io.test.js +211 -1
- package/dist/object-io.test.js.map +1 -1
- package/dist/outposts/billing.d.ts +41 -0
- package/dist/outposts/billing.d.ts.map +1 -0
- package/dist/outposts/billing.js +53 -0
- package/dist/outposts/billing.js.map +1 -0
- package/dist/outposts/cli-billing.d.ts +59 -0
- package/dist/outposts/cli-billing.d.ts.map +1 -0
- package/dist/outposts/cli-billing.js +93 -0
- package/dist/outposts/cli-billing.js.map +1 -0
- package/dist/outposts/cli.d.ts +13 -0
- package/dist/outposts/cli.d.ts.map +1 -0
- package/dist/outposts/cli.js +13 -0
- package/dist/outposts/cli.js.map +1 -0
- package/dist/outposts/client.d.ts +140 -0
- package/dist/outposts/client.d.ts.map +1 -0
- package/dist/outposts/client.js +271 -0
- package/dist/outposts/client.js.map +1 -0
- package/dist/outposts/client.test.d.ts +9 -0
- package/dist/outposts/client.test.d.ts.map +1 -0
- package/dist/outposts/client.test.js +226 -0
- package/dist/outposts/client.test.js.map +1 -0
- package/dist/outposts/command.d.ts +74 -0
- package/dist/outposts/command.d.ts.map +1 -0
- package/dist/outposts/command.js +661 -0
- package/dist/outposts/command.js.map +1 -0
- package/dist/outposts/command.test.d.ts +18 -0
- package/dist/outposts/command.test.d.ts.map +1 -0
- package/dist/outposts/command.test.js +933 -0
- package/dist/outposts/command.test.js.map +1 -0
- package/dist/outposts/errors.d.ts +32 -0
- package/dist/outposts/errors.d.ts.map +1 -0
- package/dist/outposts/errors.js +72 -0
- package/dist/outposts/errors.js.map +1 -0
- package/dist/outposts/heartbeat-command.d.ts +106 -0
- package/dist/outposts/heartbeat-command.d.ts.map +1 -0
- package/dist/outposts/heartbeat-command.js +186 -0
- package/dist/outposts/heartbeat-command.js.map +1 -0
- package/dist/outposts/host-deps.d.ts +49 -0
- package/dist/outposts/host-deps.d.ts.map +1 -0
- package/dist/outposts/host-deps.js +93 -0
- package/dist/outposts/host-deps.js.map +1 -0
- package/dist/outposts/index.d.ts +36 -0
- package/dist/outposts/index.d.ts.map +1 -0
- package/dist/outposts/index.js +32 -0
- package/dist/outposts/index.js.map +1 -0
- package/dist/outposts/node.d.ts +23 -0
- package/dist/outposts/node.d.ts.map +1 -0
- package/dist/outposts/node.js +22 -0
- package/dist/outposts/node.js.map +1 -0
- package/dist/outposts/remote-command.d.ts +30 -0
- package/dist/outposts/remote-command.d.ts.map +1 -0
- package/dist/outposts/remote-command.js +39 -0
- package/dist/outposts/remote-command.js.map +1 -0
- package/dist/outposts/replica-sync.d.ts +40 -0
- package/dist/outposts/replica-sync.d.ts.map +1 -0
- package/dist/outposts/replica-sync.js +188 -0
- package/dist/outposts/replica-sync.js.map +1 -0
- package/dist/outposts/replica-sync.test.d.ts +2 -0
- package/dist/outposts/replica-sync.test.d.ts.map +1 -0
- package/dist/outposts/replica-sync.test.js +224 -0
- package/dist/outposts/replica-sync.test.js.map +1 -0
- package/dist/outposts/self-deploy.d.ts +47 -0
- package/dist/outposts/self-deploy.d.ts.map +1 -0
- package/dist/outposts/self-deploy.js +188 -0
- package/dist/outposts/self-deploy.js.map +1 -0
- package/dist/outposts/self-deploy.test.d.ts +2 -0
- package/dist/outposts/self-deploy.test.d.ts.map +1 -0
- package/dist/outposts/self-deploy.test.js +186 -0
- package/dist/outposts/self-deploy.test.js.map +1 -0
- package/dist/outposts/session-heartbeat-bounds.test.d.ts +25 -0
- package/dist/outposts/session-heartbeat-bounds.test.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat-bounds.test.js +156 -0
- package/dist/outposts/session-heartbeat-bounds.test.js.map +1 -0
- package/dist/outposts/session-heartbeat-guard.test.d.ts +16 -0
- package/dist/outposts/session-heartbeat-guard.test.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat-guard.test.js +88 -0
- package/dist/outposts/session-heartbeat-guard.test.js.map +1 -0
- package/dist/outposts/session-heartbeat-publisher.d.ts +76 -0
- package/dist/outposts/session-heartbeat-publisher.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat-publisher.js +117 -0
- package/dist/outposts/session-heartbeat-publisher.js.map +1 -0
- package/dist/outposts/session-heartbeat-publisher.test.d.ts +10 -0
- package/dist/outposts/session-heartbeat-publisher.test.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat-publisher.test.js +153 -0
- package/dist/outposts/session-heartbeat-publisher.test.js.map +1 -0
- package/dist/outposts/session-heartbeat-retain-guard.test.d.ts +18 -0
- package/dist/outposts/session-heartbeat-retain-guard.test.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat-retain-guard.test.js +106 -0
- package/dist/outposts/session-heartbeat-retain-guard.test.js.map +1 -0
- package/dist/outposts/session-heartbeat.d.ts +210 -0
- package/dist/outposts/session-heartbeat.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat.js +657 -0
- package/dist/outposts/session-heartbeat.js.map +1 -0
- package/dist/outposts/session-heartbeat.test.d.ts +11 -0
- package/dist/outposts/session-heartbeat.test.d.ts.map +1 -0
- package/dist/outposts/session-heartbeat.test.js +370 -0
- package/dist/outposts/session-heartbeat.test.js.map +1 -0
- package/dist/outposts/ssh.d.ts +29 -0
- package/dist/outposts/ssh.d.ts.map +1 -0
- package/dist/outposts/ssh.js +66 -0
- package/dist/outposts/ssh.js.map +1 -0
- package/dist/outposts/transport.d.ts +76 -0
- package/dist/outposts/transport.d.ts.map +1 -0
- package/dist/outposts/transport.js +91 -0
- package/dist/outposts/transport.js.map +1 -0
- package/dist/outposts/transport.test.d.ts +10 -0
- package/dist/outposts/transport.test.d.ts.map +1 -0
- package/dist/outposts/transport.test.js +116 -0
- package/dist/outposts/transport.test.js.map +1 -0
- package/dist/outposts/types.d.ts +125 -0
- package/dist/outposts/types.d.ts.map +1 -0
- package/dist/outposts/types.js +13 -0
- package/dist/outposts/types.js.map +1 -0
- package/dist/personal-vault.d.ts +69 -0
- package/dist/personal-vault.d.ts.map +1 -1
- package/dist/personal-vault.js +100 -0
- package/dist/personal-vault.js.map +1 -1
- package/dist/personal-vault.test.js +140 -1
- package/dist/personal-vault.test.js.map +1 -1
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +62 -0
- package/dist/s3.js.map +1 -1
- package/dist/s3.test.js +126 -0
- package/dist/s3.test.js.map +1 -1
- package/package.json +39 -3
|
@@ -0,0 +1,117 @@
|
|
|
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, PublishCommand, } from "@aws-sdk/client-iot-data-plane";
|
|
25
|
+
import { assertNoSecretsInPayload, sessionsTopicForPerson, } from "./session-heartbeat.js";
|
|
26
|
+
/** Ceiling on a single credentials request. */
|
|
27
|
+
export const DEFAULT_CREDENTIALS_TIMEOUT_MS = 10_000;
|
|
28
|
+
/**
|
|
29
|
+
* Build the production credentials fetcher. Reads the box's current Cognito
|
|
30
|
+
* id/access token via the injected `getJwt` and POSTs it to the
|
|
31
|
+
* realtime-credentials endpoint.
|
|
32
|
+
*/
|
|
33
|
+
export function defaultRealtimeCredentialsFetcher(opts) {
|
|
34
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
35
|
+
return async () => {
|
|
36
|
+
const jwt = await opts.getJwt();
|
|
37
|
+
const res = await doFetch(`${opts.apiBaseUrl}/v1/realtime/credentials`, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
// Bounded. An endpoint that accepts the connection but never answers
|
|
40
|
+
// would otherwise park the tick forever: the loop stops beating, the
|
|
41
|
+
// liveness marker goes stale, and SIGTERM cannot finish the in-flight
|
|
42
|
+
// tick — a hang that reads exactly like a healthy quiet box.
|
|
43
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? DEFAULT_CREDENTIALS_TIMEOUT_MS),
|
|
44
|
+
headers: {
|
|
45
|
+
authorization: `Bearer ${jwt}`,
|
|
46
|
+
"content-type": "application/json",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
throw new Error(`realtime/credentials returned ${res.status} ${res.statusText}`);
|
|
51
|
+
}
|
|
52
|
+
return (await res.json());
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a `PublishPort` that vends scoped creds (refreshing before expiry) and
|
|
57
|
+
* publishes the compact payload to the box's own sessions topic over MQTT/IoT.
|
|
58
|
+
*
|
|
59
|
+
* @param fetchCredentials vends per-identity-scoped STS creds + IoT endpoint
|
|
60
|
+
* @param makeClient builds an IoT client from creds (injected for tests)
|
|
61
|
+
* @param now clock injection
|
|
62
|
+
*/
|
|
63
|
+
export function createIotPublishPort(opts) {
|
|
64
|
+
const now = opts.now ?? (() => new Date());
|
|
65
|
+
const makeClient = opts.makeClient ??
|
|
66
|
+
(({ endpoint, region, credentials }) => {
|
|
67
|
+
const url = endpoint.startsWith("http")
|
|
68
|
+
? endpoint
|
|
69
|
+
: `https://${endpoint}`;
|
|
70
|
+
return new IoTDataPlaneClient({
|
|
71
|
+
endpoint: url,
|
|
72
|
+
region,
|
|
73
|
+
credentials: {
|
|
74
|
+
accessKeyId: credentials.accessKeyId,
|
|
75
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
76
|
+
sessionToken: credentials.sessionToken,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
let cached = null;
|
|
81
|
+
// Refresh creds this many ms before they actually expire so a publish never
|
|
82
|
+
// races expiry mid-flight.
|
|
83
|
+
const REFRESH_SKEW_MS = 60_000;
|
|
84
|
+
async function clientFor() {
|
|
85
|
+
const nowMs = now().getTime();
|
|
86
|
+
if (cached && cached.expiresAtMs - REFRESH_SKEW_MS > nowMs) {
|
|
87
|
+
return { client: cached.client };
|
|
88
|
+
}
|
|
89
|
+
const vended = await opts.fetchCredentials();
|
|
90
|
+
const client = makeClient({
|
|
91
|
+
endpoint: vended.iotEndpoint,
|
|
92
|
+
region: vended.region,
|
|
93
|
+
credentials: vended.credentials,
|
|
94
|
+
});
|
|
95
|
+
cached = {
|
|
96
|
+
client,
|
|
97
|
+
endpoint: vended.iotEndpoint,
|
|
98
|
+
accessKeyId: vended.credentials.accessKeyId,
|
|
99
|
+
expiresAtMs: Date.parse(vended.credentials.expiration),
|
|
100
|
+
};
|
|
101
|
+
return { client };
|
|
102
|
+
}
|
|
103
|
+
return async (topic, payload) => {
|
|
104
|
+
// Re-guard at the transport boundary — a publisher must never ship a
|
|
105
|
+
// payload that fails the no-secrets contract, regardless of caller.
|
|
106
|
+
assertNoSecretsInPayload(payload);
|
|
107
|
+
const { client } = await clientFor();
|
|
108
|
+
await client.send(new PublishCommand({
|
|
109
|
+
topic,
|
|
110
|
+
qos: 0,
|
|
111
|
+
payload: Buffer.from(JSON.stringify(payload)),
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Re-export for the runner so it imports one module. */
|
|
116
|
+
export { sessionsTopicForPerson };
|
|
117
|
+
//# sourceMappingURL=session-heartbeat-publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-heartbeat-publisher.js","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAoBhC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC;A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M,MAAM,CAAC,IAAI,CACf,IAAI,cAAc,CAAC;YACjB,KAAK;YACL,GAAG,EAAE,CAAC;YACN,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;SAC9C,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,yDAAyD;AACzD,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=session-heartbeat-publisher.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-heartbeat-publisher.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-publisher.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
+
import { mockClient } from "aws-sdk-client-mock";
|
|
11
|
+
import { IoTDataPlaneClient, PublishCommand, } from "@aws-sdk/client-iot-data-plane";
|
|
12
|
+
import { createIotPublishPort, defaultRealtimeCredentialsFetcher, } from "./session-heartbeat-publisher";
|
|
13
|
+
const PERSON = "prs_alice";
|
|
14
|
+
const TOPIC = `hq/${PERSON}/sessions`;
|
|
15
|
+
const NOW = new Date("2026-06-15T18:55:00.000Z");
|
|
16
|
+
function credsResponse(expiresInMs) {
|
|
17
|
+
return {
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: "ASIAEXAMPLE",
|
|
20
|
+
secretAccessKey: "secret",
|
|
21
|
+
sessionToken: "token",
|
|
22
|
+
expiration: new Date(NOW.getTime() + expiresInMs).toISOString(),
|
|
23
|
+
},
|
|
24
|
+
iotEndpoint: "abc123-ats.iot.us-east-1.amazonaws.com",
|
|
25
|
+
region: "us-east-1",
|
|
26
|
+
topic: TOPIC,
|
|
27
|
+
expiresAt: new Date(NOW.getTime() + expiresInMs).toISOString(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function cleanPayload() {
|
|
31
|
+
return {
|
|
32
|
+
type: "sessions",
|
|
33
|
+
origin: "outpost",
|
|
34
|
+
emittedAt: NOW.toISOString(),
|
|
35
|
+
sessions: [
|
|
36
|
+
{
|
|
37
|
+
id: "x",
|
|
38
|
+
tool: "claude",
|
|
39
|
+
origin: "outpost",
|
|
40
|
+
cwd: "/home/ec2-user/hq",
|
|
41
|
+
project: "hq",
|
|
42
|
+
company: null,
|
|
43
|
+
model: "claude-opus-4",
|
|
44
|
+
status: "running",
|
|
45
|
+
startedAt: null,
|
|
46
|
+
lastActivityAt: NOW.toISOString(),
|
|
47
|
+
source: "/home/ec2-user/.claude/projects/p/x.jsonl",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
describe("defaultRealtimeCredentialsFetcher", () => {
|
|
53
|
+
it("POSTs the JWT to /v1/realtime/credentials and returns the parsed body", async () => {
|
|
54
|
+
const body = credsResponse(3_600_000);
|
|
55
|
+
const fetchImpl = vi.fn().mockResolvedValue({
|
|
56
|
+
ok: true,
|
|
57
|
+
status: 200,
|
|
58
|
+
statusText: "OK",
|
|
59
|
+
json: async () => body,
|
|
60
|
+
});
|
|
61
|
+
const fetcher = defaultRealtimeCredentialsFetcher({
|
|
62
|
+
apiBaseUrl: "https://hqapi.hq.computer",
|
|
63
|
+
getJwt: async () => "JWT123",
|
|
64
|
+
fetchImpl: fetchImpl,
|
|
65
|
+
});
|
|
66
|
+
const out = await fetcher();
|
|
67
|
+
expect(out).toEqual(body);
|
|
68
|
+
const [url, init] = fetchImpl.mock.calls[0];
|
|
69
|
+
expect(url).toBe("https://hqapi.hq.computer/v1/realtime/credentials");
|
|
70
|
+
expect(init.method).toBe("POST");
|
|
71
|
+
expect(init.headers.authorization).toBe("Bearer JWT123");
|
|
72
|
+
});
|
|
73
|
+
it("throws on a non-ok response", async () => {
|
|
74
|
+
const fetchImpl = vi.fn().mockResolvedValue({
|
|
75
|
+
ok: false,
|
|
76
|
+
status: 403,
|
|
77
|
+
statusText: "Forbidden",
|
|
78
|
+
json: async () => ({}),
|
|
79
|
+
});
|
|
80
|
+
const fetcher = defaultRealtimeCredentialsFetcher({
|
|
81
|
+
apiBaseUrl: "https://hqapi.hq.computer",
|
|
82
|
+
getJwt: async () => "JWT",
|
|
83
|
+
fetchImpl: fetchImpl,
|
|
84
|
+
});
|
|
85
|
+
await expect(fetcher()).rejects.toThrow(/403/);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("createIotPublishPort", () => {
|
|
89
|
+
const iotMock = mockClient(IoTDataPlaneClient);
|
|
90
|
+
beforeEach(() => iotMock.reset());
|
|
91
|
+
it("publishes the payload to the caller's topic via IoT", async () => {
|
|
92
|
+
iotMock.on(PublishCommand).resolves({});
|
|
93
|
+
const fetchCredentials = vi.fn().mockResolvedValue(credsResponse(3_600_000));
|
|
94
|
+
const publish = createIotPublishPort({
|
|
95
|
+
fetchCredentials,
|
|
96
|
+
makeClient: () => iotMock,
|
|
97
|
+
now: () => NOW,
|
|
98
|
+
});
|
|
99
|
+
const payload = cleanPayload();
|
|
100
|
+
await publish(TOPIC, payload);
|
|
101
|
+
const call = iotMock.commandCalls(PublishCommand)[0];
|
|
102
|
+
expect(call.args[0].input.topic).toBe(TOPIC);
|
|
103
|
+
const sent = JSON.parse(Buffer.from(call.args[0].input.payload).toString("utf8"));
|
|
104
|
+
expect(sent.type).toBe("sessions");
|
|
105
|
+
expect(sent.sessions[0].id).toBe("x");
|
|
106
|
+
});
|
|
107
|
+
it("caches the vended creds/client until near expiry, then re-vends", async () => {
|
|
108
|
+
iotMock.on(PublishCommand).resolves({});
|
|
109
|
+
const fetchCredentials = vi
|
|
110
|
+
.fn()
|
|
111
|
+
.mockResolvedValueOnce(credsResponse(3_600_000))
|
|
112
|
+
.mockResolvedValueOnce(credsResponse(3_600_000));
|
|
113
|
+
const publish = createIotPublishPort({
|
|
114
|
+
fetchCredentials,
|
|
115
|
+
makeClient: () => iotMock,
|
|
116
|
+
now: () => NOW,
|
|
117
|
+
});
|
|
118
|
+
await publish(TOPIC, cleanPayload());
|
|
119
|
+
await publish(TOPIC, cleanPayload());
|
|
120
|
+
// Second publish reuses the cached client — creds vended once.
|
|
121
|
+
expect(fetchCredentials).toHaveBeenCalledTimes(1);
|
|
122
|
+
});
|
|
123
|
+
it("re-vends when the cached creds are within the refresh skew of expiry", async () => {
|
|
124
|
+
iotMock.on(PublishCommand).resolves({});
|
|
125
|
+
const fetchCredentials = vi
|
|
126
|
+
.fn()
|
|
127
|
+
// expires in 30s — inside the 60s refresh skew, so every call re-vends
|
|
128
|
+
.mockResolvedValue(credsResponse(30_000));
|
|
129
|
+
const publish = createIotPublishPort({
|
|
130
|
+
fetchCredentials,
|
|
131
|
+
makeClient: () => iotMock,
|
|
132
|
+
now: () => NOW,
|
|
133
|
+
});
|
|
134
|
+
await publish(TOPIC, cleanPayload());
|
|
135
|
+
await publish(TOPIC, cleanPayload());
|
|
136
|
+
expect(fetchCredentials).toHaveBeenCalledTimes(2);
|
|
137
|
+
});
|
|
138
|
+
it("re-guards the no-secrets contract at the transport boundary", async () => {
|
|
139
|
+
iotMock.on(PublishCommand).resolves({});
|
|
140
|
+
const fetchCredentials = vi.fn().mockResolvedValue(credsResponse(3_600_000));
|
|
141
|
+
const publish = createIotPublishPort({
|
|
142
|
+
fetchCredentials,
|
|
143
|
+
makeClient: () => iotMock,
|
|
144
|
+
now: () => NOW,
|
|
145
|
+
});
|
|
146
|
+
const dirty = cleanPayload();
|
|
147
|
+
// Smuggle a secret into a whitelisted field — the publisher must refuse.
|
|
148
|
+
dirty.sessions[0].model = "sk-ant-leaked-key";
|
|
149
|
+
await expect(publish(TOPIC, dirty)).rejects.toThrow(/secret marker/);
|
|
150
|
+
expect(iotMock.commandCalls(PublishCommand)).toHaveLength(0);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=session-heartbeat-publisher.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-heartbeat-publisher.test.js","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-publisher.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,iCAAiC,GAElC,MAAM,+BAA+B,CAAC;AAGvC,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,MAAM,KAAK,GAAG,MAAM,MAAM,WAAW,CAAC;AACtC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAEjD,SAAS,aAAa,CACpB,WAAmB;IAEnB,OAAO;QACL,WAAW,EAAE;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AC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;QAC7E,MAAM,OAAO,GAAG,oBAAoB,CAAC;YACnC,gBAAgB;YAChB,UAAU,EAAE,GAAG,EAAE,CAAC,OAAwC;YAC1D,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG;SACf,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QAC7B,yEAAyE;QACzE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,mBAAmB,CAAC;QAC9C,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACrE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* company-work-corpus US-006 AC7 — no retained MQTT publishes for transcript
|
|
3
|
+
* objects.
|
|
4
|
+
*
|
|
5
|
+
* Session transcripts are pulled on demand via the presign GET path (structural
|
|
6
|
+
* owner+creator gate); they are NEVER pushed as message bodies over the realtime
|
|
7
|
+
* fabric. The on-box sessions publisher emits only a COMPACT liveness heartbeat
|
|
8
|
+
* (`SessionsHeartbeatPayload` — path-only session summaries, guarded by
|
|
9
|
+
* `assertNoSecretsInPayload`), and it must publish NON-RETAINED so a stale
|
|
10
|
+
* summary is never re-delivered from the broker to a late subscriber.
|
|
11
|
+
*
|
|
12
|
+
* This is a GUARD suite: it asserts the current (correct) behavior so a future
|
|
13
|
+
* change that (a) turns on `retain` for the sessions topic, or (b) starts
|
|
14
|
+
* shipping transcript/vault-file bytes over MQTT, fails loudly. No product code
|
|
15
|
+
* change is expected from US-006 here.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=session-heartbeat-retain-guard.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-heartbeat-retain-guard.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-retain-guard.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* company-work-corpus US-006 AC7 — no retained MQTT publishes for transcript
|
|
3
|
+
* objects.
|
|
4
|
+
*
|
|
5
|
+
* Session transcripts are pulled on demand via the presign GET path (structural
|
|
6
|
+
* owner+creator gate); they are NEVER pushed as message bodies over the realtime
|
|
7
|
+
* fabric. The on-box sessions publisher emits only a COMPACT liveness heartbeat
|
|
8
|
+
* (`SessionsHeartbeatPayload` — path-only session summaries, guarded by
|
|
9
|
+
* `assertNoSecretsInPayload`), and it must publish NON-RETAINED so a stale
|
|
10
|
+
* summary is never re-delivered from the broker to a late subscriber.
|
|
11
|
+
*
|
|
12
|
+
* This is a GUARD suite: it asserts the current (correct) behavior so a future
|
|
13
|
+
* change that (a) turns on `retain` for the sessions topic, or (b) starts
|
|
14
|
+
* shipping transcript/vault-file bytes over MQTT, fails loudly. No product code
|
|
15
|
+
* change is expected from US-006 here.
|
|
16
|
+
*/
|
|
17
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { mockClient } from "aws-sdk-client-mock";
|
|
20
|
+
import { IoTDataPlaneClient, PublishCommand, } from "@aws-sdk/client-iot-data-plane";
|
|
21
|
+
import { createIotPublishPort, } from "./session-heartbeat-publisher";
|
|
22
|
+
const PERSON = "prs_alice";
|
|
23
|
+
const TOPIC = `hq/${PERSON}/sessions`;
|
|
24
|
+
const NOW = new Date("2026-07-11T18:55:00.000Z");
|
|
25
|
+
function credsResponse() {
|
|
26
|
+
return {
|
|
27
|
+
credentials: {
|
|
28
|
+
accessKeyId: "ASIAEXAMPLE",
|
|
29
|
+
secretAccessKey: "secret",
|
|
30
|
+
sessionToken: "token",
|
|
31
|
+
expiration: new Date(NOW.getTime() + 3_600_000).toISOString(),
|
|
32
|
+
},
|
|
33
|
+
iotEndpoint: "abc123-ats.iot.us-east-1.amazonaws.com",
|
|
34
|
+
region: "us-east-1",
|
|
35
|
+
topic: TOPIC,
|
|
36
|
+
expiresAt: new Date(NOW.getTime() + 3_600_000).toISOString(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function cleanPayload() {
|
|
40
|
+
return {
|
|
41
|
+
type: "sessions",
|
|
42
|
+
origin: "outpost",
|
|
43
|
+
emittedAt: NOW.toISOString(),
|
|
44
|
+
sessions: [
|
|
45
|
+
{
|
|
46
|
+
id: "x",
|
|
47
|
+
tool: "claude",
|
|
48
|
+
origin: "outpost",
|
|
49
|
+
cwd: "/home/ec2-user/hq",
|
|
50
|
+
project: "hq",
|
|
51
|
+
company: null,
|
|
52
|
+
model: "claude-opus-4",
|
|
53
|
+
status: "running",
|
|
54
|
+
startedAt: null,
|
|
55
|
+
lastActivityAt: NOW.toISOString(),
|
|
56
|
+
source: "/home/ec2-user/.claude/projects/p/x.jsonl",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
describe("US-006 AC7 — sessions heartbeat is published NON-RETAINED", () => {
|
|
62
|
+
const iotMock = mockClient(IoTDataPlaneClient);
|
|
63
|
+
beforeEach(() => iotMock.reset());
|
|
64
|
+
it("the PublishCommand never sets retain=true", async () => {
|
|
65
|
+
iotMock.on(PublishCommand).resolves({});
|
|
66
|
+
const publish = createIotPublishPort({
|
|
67
|
+
fetchCredentials: vi.fn().mockResolvedValue(credsResponse()),
|
|
68
|
+
makeClient: () => iotMock,
|
|
69
|
+
now: () => NOW,
|
|
70
|
+
});
|
|
71
|
+
await publish(TOPIC, cleanPayload());
|
|
72
|
+
const call = iotMock.commandCalls(PublishCommand)[0];
|
|
73
|
+
// retain must be absent or explicitly false — never true (no broker
|
|
74
|
+
// re-delivery of a stale session summary; transcripts are pull-only).
|
|
75
|
+
expect(call.args[0].input.retain).not.toBe(true);
|
|
76
|
+
// The wire body is the compact summary envelope — no transcript body field.
|
|
77
|
+
const sent = JSON.parse(Buffer.from(call.args[0].input.payload).toString("utf8"));
|
|
78
|
+
expect(sent.type).toBe("sessions");
|
|
79
|
+
// The session summary carries a `source` PATH only, never file/transcript
|
|
80
|
+
// content — assert no body/content/transcript key ever rides the wire.
|
|
81
|
+
for (const s of sent.sessions) {
|
|
82
|
+
expect(s).not.toHaveProperty("body");
|
|
83
|
+
expect(s).not.toHaveProperty("content");
|
|
84
|
+
expect(s).not.toHaveProperty("transcript");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("US-006 AC7 — static guard: sessions/realtime publishers never retain", () => {
|
|
89
|
+
// The sessions publisher is the ONLY realtime path in this package that
|
|
90
|
+
// touches session data, and it may never set retain=true — a retained
|
|
91
|
+
// message would leave the last session summary sitting on the broker after
|
|
92
|
+
// the box goes away. (The server-side DM-wake publisher is guarded by the
|
|
93
|
+
// matching test in hq-pro, which is where that file lives.)
|
|
94
|
+
const guardedSources = [
|
|
95
|
+
new URL("./session-heartbeat-publisher.ts", import.meta.url),
|
|
96
|
+
new URL("./session-heartbeat.ts", import.meta.url),
|
|
97
|
+
];
|
|
98
|
+
it("no guarded publisher sets retain: true", () => {
|
|
99
|
+
for (const url of guardedSources) {
|
|
100
|
+
const src = readFileSync(url, "utf8");
|
|
101
|
+
// Tolerate any whitespace between `retain` and `true`.
|
|
102
|
+
expect(src).not.toMatch(/retain\s*:\s*true/);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=session-heartbeat-retain-guard.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-heartbeat-retain-guard.test.js","sourceRoot":"","sources":["../../src/outposts/session-heartbeat-retain-guard.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oBAAoB,GAErB,MAAM,+BAA+B,CAAC;AAGvC,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,MAAM,KAAK,GAAG,MAAM,MAAM,WAAW,CAAC;AACtC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAEjD,SAAS,aAAa;IACpB,OAAO;QACL,WAAW,EAAE;YACX,WAAW,EAAE,aAAa;YAC1B,eAAe,EAAE,QAAQ;YACzB,YAAY,EAAE,OAAO;YACrB,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,WAAW,EAAE;SAC9D;QACD,WAAW,EAAE,wCAAwC;QACrD,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,WAAW,EAAE;KAC7D,CAAC;AACJ,CAAC;AAED,SAAS,YAAY;IACnB,OAAO;QACL,IAAI,EAAE,UAAU;QACh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,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outpost on-box session heartbeat emitter — mission-control US-009.
|
|
3
|
+
*
|
|
4
|
+
* Runs ON the Outpost VM (not in a Lambda). On a fixed cadence it:
|
|
5
|
+
* 1. enumerates the box's local Claude Code (`~/.claude/projects/**\/<uuid>.jsonl`)
|
|
6
|
+
* and Codex (`~/.codex/session_index.jsonl` + `sessions/YYYY/MM/DD/rollout-*.jsonl`)
|
|
7
|
+
* sessions using cheap scandir + stat + BOUNDED tail/head reads only —
|
|
8
|
+
* it NEVER full-parses a multi-MB transcript;
|
|
9
|
+
* 2. summarizes them into a compact `AgentSession[]` payload with
|
|
10
|
+
* `origin="outpost"`, mirroring the local reader logic from US-002/US-003;
|
|
11
|
+
* 3. publishes that payload to the realtime fabric topic `hq/{personUid}/sessions`
|
|
12
|
+
* using the same on-box credential pattern the rest of the box uses
|
|
13
|
+
* (a server-minted, per-identity-scoped STS session vended by
|
|
14
|
+
* `POST /v1/realtime/credentials`, then an MQTT-over-WSS publish).
|
|
15
|
+
*
|
|
16
|
+
* Security (US-009 acceptance): the payload carries ONLY the AgentSession
|
|
17
|
+
* fields below — never a transcript body, prompt, token, API key, env var, or
|
|
18
|
+
* credential. `assertNoSecretsInPayload` is the runtime guard, and the unit
|
|
19
|
+
* tests assert the no-secrets-in-payload guarantee against adversarial
|
|
20
|
+
* fixtures.
|
|
21
|
+
*
|
|
22
|
+
* This module is intentionally dependency-light and pure-logic where it can be:
|
|
23
|
+
* the filesystem, clock, and publish transport are all injected so the
|
|
24
|
+
* enumeration → payload mapping and the no-secrets guarantee are unit-testable
|
|
25
|
+
* without a real VM, real MQTT, or real STS.
|
|
26
|
+
*/
|
|
27
|
+
/** Which agent tool produced the session. */
|
|
28
|
+
export type AgentTool = "claude" | "codex";
|
|
29
|
+
/** Where the session physically lives. The outpost emitter always emits `outpost`. */
|
|
30
|
+
export type AgentOrigin = "local" | "outpost";
|
|
31
|
+
/**
|
|
32
|
+
* Session liveness taxonomy (US-001). Derived best-effort from a last-activity
|
|
33
|
+
* mtime window. `awaiting_input` is not inferable from on-disk artifacts alone
|
|
34
|
+
* on the box, so the emitter only ever produces `running | idle | ended`; the
|
|
35
|
+
* desktop merges/cross-checks and may surface `awaiting_input` for local PIDs.
|
|
36
|
+
*/
|
|
37
|
+
export type AgentStatus = "running" | "awaiting_input" | "idle" | "ended";
|
|
38
|
+
/**
|
|
39
|
+
* Unified, compact agent session summary. This is the ONLY shape that crosses
|
|
40
|
+
* the wire — no transcript bodies, no secrets. Matches the Rust struct +
|
|
41
|
+
* TS type defined in the hq-sync repo (US-001).
|
|
42
|
+
*/
|
|
43
|
+
export interface AgentSession {
|
|
44
|
+
/** Stable session id (the `<uuid>` for Claude, the rollout/index id for Codex). */
|
|
45
|
+
id: string;
|
|
46
|
+
tool: AgentTool;
|
|
47
|
+
origin: AgentOrigin;
|
|
48
|
+
/** Working directory the session is running in, if known. */
|
|
49
|
+
cwd: string | null;
|
|
50
|
+
/** Project slug/name (last path segment of cwd, or decoded Claude project dir). */
|
|
51
|
+
project: string | null;
|
|
52
|
+
/** Owning company slug, if resolvable from HQ workspace metadata. */
|
|
53
|
+
company: string | null;
|
|
54
|
+
/** Model id last seen for the session, if observed in a bounded read. */
|
|
55
|
+
model: string | null;
|
|
56
|
+
status: AgentStatus;
|
|
57
|
+
/** ISO-8601 first-seen / creation time, if known. */
|
|
58
|
+
startedAt: string | null;
|
|
59
|
+
/** ISO-8601 last-activity time (file mtime is the liveness signal). */
|
|
60
|
+
lastActivityAt: string | null;
|
|
61
|
+
/** Provenance of this record — the on-box file we summarized. Path only, never content. */
|
|
62
|
+
source: string;
|
|
63
|
+
}
|
|
64
|
+
/** Liveness thresholds (seconds). Mirrors the desktop liveness engine (US-004). */
|
|
65
|
+
export interface LivenessThresholds {
|
|
66
|
+
/** ≤ this since last activity ⇒ `running`. */
|
|
67
|
+
runningWithinSeconds: number;
|
|
68
|
+
/** ≤ this (and > running) ⇒ `idle`; beyond ⇒ `ended`. */
|
|
69
|
+
idleWithinSeconds: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Default cadence matches the desktop polling interval (~5s). Configurable via
|
|
73
|
+
* the `OUTPOST_SESSIONS_HEARTBEAT_INTERVAL_SECONDS` env var so dev/staging can
|
|
74
|
+
* dial it without a rebuild — read by `resolveCadenceSeconds`.
|
|
75
|
+
*/
|
|
76
|
+
export declare const DEFAULT_HEARTBEAT_INTERVAL_SECONDS = 5;
|
|
77
|
+
/**
|
|
78
|
+
* Default liveness windows. `running` ⇐ activity within the last 2 cadence
|
|
79
|
+
* ticks (10s); `idle` out to 15m; older ⇒ `ended`. Kept generous so a session
|
|
80
|
+
* mid-think between writes isn't flapped to `ended`.
|
|
81
|
+
*/
|
|
82
|
+
export declare const DEFAULT_LIVENESS_THRESHOLDS: LivenessThresholds;
|
|
83
|
+
/** A directory entry as returned by the filesystem port. */
|
|
84
|
+
export interface DirEntry {
|
|
85
|
+
name: string;
|
|
86
|
+
isDirectory: boolean;
|
|
87
|
+
isFile: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Minimal stat surface used by the enumerator. */
|
|
90
|
+
export interface FileStat {
|
|
91
|
+
/** Last-modification time, ms since epoch. */
|
|
92
|
+
mtimeMs: number;
|
|
93
|
+
/** Birth/creation time, ms since epoch (may equal mtime on filesystems w/o btime). */
|
|
94
|
+
birthtimeMs: number;
|
|
95
|
+
size: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Filesystem port — abstracts node:fs so tests drive an in-memory tree and the
|
|
99
|
+
* real emitter uses `nodeFileSystem`. Every read here is bounded.
|
|
100
|
+
*/
|
|
101
|
+
export interface FileSystemPort {
|
|
102
|
+
/** Returns [] when the dir is missing — enumeration must not throw on absence. */
|
|
103
|
+
readDir(path: string): Promise<DirEntry[]>;
|
|
104
|
+
stat(path: string): Promise<FileStat>;
|
|
105
|
+
/** Whole-file read — used ONLY for the tiny Codex index, never for transcripts. */
|
|
106
|
+
readTextFile(path: string): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Bounded read: at most `maxBytes` from the END of the file (tail) or the
|
|
109
|
+
* START (head). Implementations MUST NOT load the whole file. Returns "" on
|
|
110
|
+
* any error (missing/locked) — enumeration is best-effort.
|
|
111
|
+
*/
|
|
112
|
+
readBounded(path: string, maxBytes: number, from: "head" | "tail"): Promise<string>;
|
|
113
|
+
}
|
|
114
|
+
/** Publishes the compact payload to the realtime topic. Injected for tests. */
|
|
115
|
+
export type PublishPort = (topic: string, payload: SessionsHeartbeatPayload) => Promise<void>;
|
|
116
|
+
/** The full envelope published to `hq/{personUid}/sessions`. */
|
|
117
|
+
export interface SessionsHeartbeatPayload {
|
|
118
|
+
/** Schema discriminator for the desktop subscriber. */
|
|
119
|
+
type: "sessions";
|
|
120
|
+
/** Always `outpost` from this emitter. */
|
|
121
|
+
origin: "outpost";
|
|
122
|
+
/** ISO-8601 emit time. */
|
|
123
|
+
emittedAt: string;
|
|
124
|
+
/** The compact session summaries — live only, newest first, size-bounded. */
|
|
125
|
+
sessions: AgentSession[];
|
|
126
|
+
/**
|
|
127
|
+
* How many sessions the box actually has on disk, including the `ended`
|
|
128
|
+
* archive that is deliberately not published. Present so a consumer can tell
|
|
129
|
+
* "this box has 15 sessions" from "this box has 9,340 and we sent the live
|
|
130
|
+
* 15" — a filtered list that looks complete is worse than no list.
|
|
131
|
+
*/
|
|
132
|
+
totalSessions?: number;
|
|
133
|
+
/** True when the byte budget forced sessions to be dropped. */
|
|
134
|
+
truncated?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Serialized-payload ceiling, in bytes.
|
|
138
|
+
*
|
|
139
|
+
* AWS IoT Core hard-rejects publishes over 128 KiB (131,072) — the box's first
|
|
140
|
+
* real heartbeat died on exactly that. This budget sits under it with headroom
|
|
141
|
+
* for the envelope and for any field a future schema adds.
|
|
142
|
+
*/
|
|
143
|
+
export declare const IOT_PAYLOAD_BUDGET_BYTES: number;
|
|
144
|
+
export interface HeartbeatConfig {
|
|
145
|
+
/** Caller's canonical HQ person id (`prs_*`). Topic = `hq/{personUid}/sessions`. */
|
|
146
|
+
personUid: string;
|
|
147
|
+
/** Home directory to scan (defaults to the process HOME). */
|
|
148
|
+
home?: string;
|
|
149
|
+
/** Liveness thresholds (defaults to {@link DEFAULT_LIVENESS_THRESHOLDS}). */
|
|
150
|
+
thresholds?: LivenessThresholds;
|
|
151
|
+
/** Clock injection for deterministic tests. */
|
|
152
|
+
now?: () => Date;
|
|
153
|
+
}
|
|
154
|
+
export interface HeartbeatDeps {
|
|
155
|
+
fs: FileSystemPort;
|
|
156
|
+
publish: PublishPort;
|
|
157
|
+
}
|
|
158
|
+
/** The sessions topic for a person. `hq/{personUid}/sessions`. */
|
|
159
|
+
export declare function sessionsTopicForPerson(personUid: string): string;
|
|
160
|
+
/** Resolve the heartbeat cadence (seconds) from env, clamped to a sane floor. */
|
|
161
|
+
export declare function resolveCadenceSeconds(env?: NodeJS.ProcessEnv): number;
|
|
162
|
+
/**
|
|
163
|
+
* Map an mtime to a status given the thresholds and `now`. On the box we have
|
|
164
|
+
* no per-session PID cross-check (that's the desktop's job), so we only emit
|
|
165
|
+
* `running | idle | ended` — the desktop refines from there.
|
|
166
|
+
*/
|
|
167
|
+
export declare function deriveStatus(lastActivityMs: number, nowMs: number, thresholds?: LivenessThresholds): AgentStatus;
|
|
168
|
+
/** Decode Claude's `-`-joined project dir back to a best-effort cwd. */
|
|
169
|
+
export declare function decodeClaudeProjectDir(dirName: string): string;
|
|
170
|
+
interface CodexIndexRecord {
|
|
171
|
+
id: string;
|
|
172
|
+
cwd: string | null;
|
|
173
|
+
model: string | null;
|
|
174
|
+
timestamp: string | null;
|
|
175
|
+
/** Relative path under ~/.codex, when the index records it. */
|
|
176
|
+
path: string | null;
|
|
177
|
+
}
|
|
178
|
+
/** Parse the small newline-delimited Codex index into records. */
|
|
179
|
+
export declare function parseCodexIndex(text: string): CodexIndexRecord[];
|
|
180
|
+
/**
|
|
181
|
+
* Project an arbitrary session-like object down to EXACTLY the whitelisted
|
|
182
|
+
* AgentSession fields. Any extra key (e.g. a transcript snippet, token, env
|
|
183
|
+
* var) is dropped here — this is the structural half of the no-secrets
|
|
184
|
+
* guarantee.
|
|
185
|
+
*/
|
|
186
|
+
export declare function toCompactSession(s: AgentSession): AgentSession;
|
|
187
|
+
/**
|
|
188
|
+
* Runtime guard: throw if the payload carries any non-whitelisted key OR any
|
|
189
|
+
* value that looks like a secret. The behavioral half of the no-secrets
|
|
190
|
+
* guarantee — defense in depth on top of `toCompactSession`. Called before
|
|
191
|
+
* every publish.
|
|
192
|
+
*/
|
|
193
|
+
export declare function assertNoSecretsInPayload(payload: SessionsHeartbeatPayload): void;
|
|
194
|
+
/**
|
|
195
|
+
* Enumerate the box's Claude + Codex sessions and build the compact,
|
|
196
|
+
* secret-free payload. Pure w.r.t. the injected fs/clock — does NOT publish.
|
|
197
|
+
*/
|
|
198
|
+
export declare function collectSessions(config: HeartbeatConfig, deps: Pick<HeartbeatDeps, "fs">): Promise<SessionsHeartbeatPayload>;
|
|
199
|
+
/**
|
|
200
|
+
* One heartbeat tick: collect → guard → publish to `hq/{personUid}/sessions`.
|
|
201
|
+
* Best-effort and non-fatal by contract — a publish failure must not crash the
|
|
202
|
+
* box's heartbeat loop (the desktop falls back to the S3-vault heartbeat /
|
|
203
|
+
* stale-timeout, US-011). Returns the payload that was published (or attempted)
|
|
204
|
+
* so callers/tests can assert on it; re-throws nothing.
|
|
205
|
+
*/
|
|
206
|
+
export declare function emitHeartbeatOnce(config: HeartbeatConfig, deps: HeartbeatDeps): Promise<SessionsHeartbeatPayload>;
|
|
207
|
+
/** Production FileSystemPort backed by node:fs with bounded positioned reads. */
|
|
208
|
+
export declare const nodeFileSystem: FileSystemPort;
|
|
209
|
+
export {};
|
|
210
|
+
//# sourceMappingURL=session-heartbeat.d.ts.map
|