@stigmer/runner 3.12.8 → 3.12.9

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 (66) hide show
  1. package/dist/.build-fingerprint +1 -1
  2. package/dist/activities/execute-cursor/fetch-interceptor.js +29 -16
  3. package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -1
  4. package/dist/activities/execute-cursor/index.d.ts +14 -0
  5. package/dist/activities/execute-cursor/index.js +55 -5
  6. package/dist/activities/execute-cursor/index.js.map +1 -1
  7. package/dist/activities/execute-cursor/message-translator.d.ts +15 -9
  8. package/dist/activities/execute-cursor/message-translator.js +15 -9
  9. package/dist/activities/execute-cursor/message-translator.js.map +1 -1
  10. package/dist/activities/execute-deep-agent/index.js +9 -0
  11. package/dist/activities/execute-deep-agent/index.js.map +1 -1
  12. package/dist/activities/execute-deep-agent/setup.d.ts +10 -1
  13. package/dist/activities/execute-deep-agent/setup.js +20 -3
  14. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  15. package/dist/payload-codecs.d.ts +1 -1
  16. package/dist/payload-codecs.js +6 -4
  17. package/dist/payload-codecs.js.map +1 -1
  18. package/dist/shared/memory-retrieval.d.ts +126 -0
  19. package/dist/shared/memory-retrieval.js +293 -0
  20. package/dist/shared/memory-retrieval.js.map +1 -0
  21. package/dist/shared/runner-credential-keys.js +2 -1
  22. package/dist/shared/runner-credential-keys.js.map +1 -1
  23. package/package.json +3 -2
  24. package/src/__tests__/history-encryption-e2e.test.ts +1 -1
  25. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +40 -1
  26. package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +49 -15
  27. package/src/activities/execute-cursor/fetch-interceptor.ts +37 -16
  28. package/src/activities/execute-cursor/index.ts +58 -5
  29. package/src/activities/execute-cursor/message-translator.ts +15 -9
  30. package/src/activities/execute-deep-agent/index.ts +10 -0
  31. package/src/activities/execute-deep-agent/setup.ts +34 -6
  32. package/src/payload-codecs.ts +12 -9
  33. package/src/shared/__tests__/memory-retrieval.test.ts +310 -0
  34. package/src/shared/memory-retrieval.ts +383 -0
  35. package/src/shared/runner-credential-keys.ts +2 -1
  36. package/dist/claimcheck/compressor.d.ts +0 -2
  37. package/dist/claimcheck/compressor.js +0 -8
  38. package/dist/claimcheck/compressor.js.map +0 -1
  39. package/dist/claimcheck/config.d.ts +0 -7
  40. package/dist/claimcheck/config.js +0 -10
  41. package/dist/claimcheck/config.js.map +0 -1
  42. package/dist/claimcheck/index.d.ts +0 -3
  43. package/dist/claimcheck/index.js +0 -4
  44. package/dist/claimcheck/index.js.map +0 -1
  45. package/dist/claimcheck/payload-codec.d.ts +0 -23
  46. package/dist/claimcheck/payload-codec.js +0 -105
  47. package/dist/claimcheck/payload-codec.js.map +0 -1
  48. package/dist/encryption/config.d.ts +0 -64
  49. package/dist/encryption/config.js +0 -113
  50. package/dist/encryption/config.js.map +0 -1
  51. package/dist/encryption/index.d.ts +0 -3
  52. package/dist/encryption/index.js +0 -3
  53. package/dist/encryption/index.js.map +0 -1
  54. package/dist/encryption/payload-codec.d.ts +0 -41
  55. package/dist/encryption/payload-codec.js +0 -130
  56. package/dist/encryption/payload-codec.js.map +0 -1
  57. package/src/__tests__/claimcheck-codec.test.ts +0 -256
  58. package/src/__tests__/encryption-codec.test.ts +0 -287
  59. package/src/__tests__/fixtures/encrypted-payload-fixture.json +0 -15
  60. package/src/claimcheck/compressor.ts +0 -9
  61. package/src/claimcheck/config.ts +0 -20
  62. package/src/claimcheck/index.ts +0 -3
  63. package/src/claimcheck/payload-codec.ts +0 -139
  64. package/src/encryption/config.ts +0 -161
  65. package/src/encryption/index.ts +0 -3
  66. package/src/encryption/payload-codec.ts +0 -152
@@ -63,7 +63,8 @@ export const RUNNER_CREDENTIAL_ENV_KEYS: readonly string[] = [
63
63
  * rotation bookkeeping, not secrets.
64
64
  */
65
65
  export const RUNNER_ENCRYPTION_ENV_KEYS: readonly string[] = [
66
- // Temporal payload-encryption keys (encryption/config.ts). An agent that
66
+ // Temporal payload-encryption keys (@stigmer/temporal-codecs' encryption
67
+ // config, read through the injected getRunnerSecret). An agent that
67
68
  // reads these could decrypt the runner's Temporal history payloads.
68
69
  "STIGMER_PAYLOAD_ENCRYPTION_KEY",
69
70
  "STIGMER_PAYLOAD_ENCRYPTION_SECONDARY_KEY",
@@ -1,2 +0,0 @@
1
- export declare function compress(data: Buffer): Buffer<ArrayBuffer>;
2
- export declare function decompress(data: Buffer): Buffer<ArrayBuffer>;
@@ -1,8 +0,0 @@
1
- import { gzipSync, gunzipSync } from "node:zlib";
2
- export function compress(data) {
3
- return gzipSync(data);
4
- }
5
- export function decompress(data) {
6
- return gunzipSync(data);
7
- }
8
- //# sourceMappingURL=compressor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compressor.js","sourceRoot":"","sources":["../../src/claimcheck/compressor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,QAAQ,CAAC,IAAI,CAAwB,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,UAAU,CAAC,IAAI,CAAwB,CAAC;AACjD,CAAC"}
@@ -1,7 +0,0 @@
1
- export interface ClaimcheckConfig {
2
- readonly enabled: boolean;
3
- readonly thresholdBytes: number;
4
- readonly compressionEnabled: boolean;
5
- readonly keyPrefix: string;
6
- }
7
- export declare function loadClaimcheckConfig(): ClaimcheckConfig;
@@ -1,10 +0,0 @@
1
- const DEFAULT_THRESHOLD_BYTES = 128 * 1024; // 128KB
2
- export function loadClaimcheckConfig() {
3
- return {
4
- enabled: process.env.CLAIMCHECK_ENABLED === "true",
5
- thresholdBytes: parseInt(process.env.CLAIMCHECK_THRESHOLD_BYTES ?? String(DEFAULT_THRESHOLD_BYTES), 10),
6
- compressionEnabled: process.env.CLAIMCHECK_COMPRESSION_ENABLED !== "false",
7
- keyPrefix: process.env.CLAIMCHECK_KEY_PREFIX ?? "claimcheck/",
8
- };
9
- }
10
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/claimcheck/config.ts"],"names":[],"mappings":"AAOA,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,QAAQ;AAEpD,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM;QAClD,cAAc,EAAE,QAAQ,CACtB,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,MAAM,CAAC,uBAAuB,CAAC,EACzE,EAAE,CACH;QACD,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,8BAA8B,KAAK,OAAO;QAC1E,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,aAAa;KAC9D,CAAC;AACJ,CAAC"}
@@ -1,3 +0,0 @@
1
- export { ClaimcheckPayloadCodec } from "./payload-codec.js";
2
- export { loadClaimcheckConfig, type ClaimcheckConfig } from "./config.js";
3
- export { compress, decompress } from "./compressor.js";
@@ -1,4 +0,0 @@
1
- export { ClaimcheckPayloadCodec } from "./payload-codec.js";
2
- export { loadClaimcheckConfig } from "./config.js";
3
- export { compress, decompress } from "./compressor.js";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/claimcheck/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAyB,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Temporal PayloadCodec that transparently offloads large payloads to
3
- * external storage (ArtifactStorage). Payloads below the threshold pass
4
- * through unchanged. Payloads at or above the threshold are compressed
5
- * (optional), uploaded, and replaced with a small reference marker.
6
- *
7
- * On decode, markers are detected, the original payload is downloaded
8
- * and decompressed, and the original bytes are restored — transparent
9
- * to workflow/activity code.
10
- */
11
- import type { Payload, PayloadCodec } from "@temporalio/common";
12
- import type { ArtifactStorage } from "../shared/artifact-storage.js";
13
- import type { ClaimcheckConfig } from "./config.js";
14
- export declare class ClaimcheckPayloadCodec implements PayloadCodec {
15
- private readonly storage;
16
- private readonly config;
17
- constructor(storage: ArtifactStorage, config: ClaimcheckConfig);
18
- encode(payloads: Payload[]): Promise<Payload[]>;
19
- decode(payloads: Payload[]): Promise<Payload[]>;
20
- private encodePayload;
21
- private decodePayload;
22
- private isClaimcheckPayload;
23
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * Temporal PayloadCodec that transparently offloads large payloads to
3
- * external storage (ArtifactStorage). Payloads below the threshold pass
4
- * through unchanged. Payloads at or above the threshold are compressed
5
- * (optional), uploaded, and replaced with a small reference marker.
6
- *
7
- * On decode, markers are detected, the original payload is downloaded
8
- * and decompressed, and the original bytes are restored — transparent
9
- * to workflow/activity code.
10
- */
11
- import { randomUUID } from "node:crypto";
12
- import { compress, decompress } from "./compressor.js";
13
- const MARKER_METADATA_KEY = "encoding";
14
- const MARKER_ENCODING_VALUE = "binary/claimcheck";
15
- export class ClaimcheckPayloadCodec {
16
- storage;
17
- config;
18
- constructor(storage, config) {
19
- this.storage = storage;
20
- this.config = config;
21
- }
22
- async encode(payloads) {
23
- return Promise.all(payloads.map((p) => this.encodePayload(p)));
24
- }
25
- async decode(payloads) {
26
- return Promise.all(payloads.map((p) => this.decodePayload(p)));
27
- }
28
- async encodePayload(payload) {
29
- const data = payload.data;
30
- if (!data || data.length < this.config.thresholdBytes) {
31
- return payload;
32
- }
33
- const originalBuf = Buffer.from(data);
34
- let uploadBuf = originalBuf;
35
- let compressed = false;
36
- if (this.config.compressionEnabled) {
37
- const compressedBuf = compress(originalBuf);
38
- if (compressedBuf.length < originalBuf.length) {
39
- uploadBuf = compressedBuf;
40
- compressed = true;
41
- }
42
- }
43
- const key = `${this.config.keyPrefix}${randomUUID()}`;
44
- await this.storage.upload(key, uploadBuf, "application/octet-stream");
45
- const marker = {
46
- key,
47
- size: data.length,
48
- compressed,
49
- metadata: serializeMetadata(payload.metadata),
50
- };
51
- return {
52
- metadata: {
53
- [MARKER_METADATA_KEY]: Buffer.from(MARKER_ENCODING_VALUE),
54
- },
55
- data: Buffer.from(JSON.stringify(marker)),
56
- };
57
- }
58
- async decodePayload(payload) {
59
- if (!this.isClaimcheckPayload(payload)) {
60
- return payload;
61
- }
62
- const marker = JSON.parse(Buffer.from(payload.data).toString("utf-8"));
63
- let rawBuf;
64
- try {
65
- rawBuf = await this.storage.download(marker.key);
66
- }
67
- catch (err) {
68
- // Preserve the claimcheck-scoped error contract; the shared download error
69
- // already carries the HTTP status (proxy) or the miss (local) as the cause.
70
- const cause = err instanceof Error ? err.message : String(err);
71
- throw new Error(`Claimcheck retrieve failed for key ${marker.key}: ${cause}`);
72
- }
73
- const dataBuf = marker.compressed ? decompress(rawBuf) : rawBuf;
74
- return {
75
- metadata: marker.metadata
76
- ? deserializeMetadata(marker.metadata)
77
- : payload.metadata,
78
- data: dataBuf,
79
- };
80
- }
81
- isClaimcheckPayload(payload) {
82
- const encoding = payload.metadata?.[MARKER_METADATA_KEY];
83
- if (!encoding)
84
- return false;
85
- return Buffer.from(encoding).toString("utf-8") === MARKER_ENCODING_VALUE;
86
- }
87
- }
88
- function serializeMetadata(metadata) {
89
- if (!metadata)
90
- return undefined;
91
- const out = {};
92
- for (const [key, value] of Object.entries(metadata)) {
93
- if (value)
94
- out[key] = Buffer.from(value).toString("base64");
95
- }
96
- return out;
97
- }
98
- function deserializeMetadata(metadata) {
99
- const out = {};
100
- for (const [key, value] of Object.entries(metadata)) {
101
- out[key] = Buffer.from(value, "base64");
102
- }
103
- return out;
104
- }
105
- //# sourceMappingURL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IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,mBAAmB,CAC1B,QAAgC;IAEhC,MAAM,GAAG,GAA+B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,64 +0,0 @@
1
- /**
2
- * Payload-encryption configuration (stigmer-cloud#227, stigmer#398).
3
- *
4
- * Two key sources, strict precedence:
5
- *
6
- * 1. Environment (STIGMER_PAYLOAD_ENCRYPTION_KEY(_ID)) — the operator's
7
- * explicit choice: self-hosted deployments sharing one key with their
8
- * server, and cloud sandboxes injected with the platform key. When the
9
- * env key is set, bootstrap-delivered material is ignored entirely.
10
- * 2. Bootstrap-delivered — server-managed per-identity keys handed to
11
- * desktop-class runners by getRunnerBootstrapConfig. Held in memory
12
- * only; persistence lives server-side, which is what makes Temporal
13
- * replay work across runner restarts (every boot re-fetches the SAME
14
- * key).
15
- *
16
- * Encryption is enabled iff a key is present from either source — the same
17
- * enabled-iff-configured pattern as the claim-check codec. A malformed key
18
- * fails the boot rather than silently running plaintext: an operator who set
19
- * the key (or a server that minted one) intended history to be encrypted.
20
- *
21
- * Key rotation: payloads carry the id of the key that encrypted them.
22
- * During a rotation window the previous key stays readable via the
23
- * secondary pair while new payloads are written under the primary key.
24
- * Workers capture keys at construction, so a rotated bootstrap key lands
25
- * on the next runner boot — there is no live re-key.
26
- */
27
- export interface EncryptionKey {
28
- readonly keyId: string;
29
- /** 32-byte AES-256 key. */
30
- readonly key: Buffer;
31
- }
32
- export interface PayloadEncryptionConfig {
33
- /** Key used to encrypt outgoing payloads (and decrypt its own). */
34
- readonly primary: EncryptionKey;
35
- /** Decrypt-only key accepted during rotation windows. */
36
- readonly secondary?: EncryptionKey;
37
- }
38
- /**
39
- * Server-managed key material delivered by getRunnerBootstrapConfig.
40
- * Structurally mirrors {@link BootstrapPayloadEncryptionKeys} in
41
- * stigmer-client.ts — declared here so this leaf module stays free of
42
- * client imports.
43
- */
44
- export interface BootstrapKeyMaterial {
45
- readonly key: string;
46
- readonly keyId?: string;
47
- readonly secondaryKey?: string;
48
- readonly secondaryKeyId?: string;
49
- }
50
- /**
51
- * Returns the encryption config, or undefined when encryption is not
52
- * configured (the codec is then simply not installed).
53
- *
54
- * Source precedence: the env key wins outright; bootstrap-delivered
55
- * material applies only when no env key is set (see the module doc).
56
- *
57
- * @throws when a key is present but malformed, or a key id is missing —
58
- * key misconfiguration must stop the boot, not degrade to plaintext.
59
- * This applies equally to bootstrap material: a server that hands out
60
- * a bad key or omits its id has broken the protocol contract, and
61
- * running plaintext against a server that manages keys would silently
62
- * defeat the feature.
63
- */
64
- export declare function loadPayloadEncryptionConfig(bootstrap?: BootstrapKeyMaterial): PayloadEncryptionConfig | undefined;
@@ -1,113 +0,0 @@
1
- /**
2
- * Payload-encryption configuration (stigmer-cloud#227, stigmer#398).
3
- *
4
- * Two key sources, strict precedence:
5
- *
6
- * 1. Environment (STIGMER_PAYLOAD_ENCRYPTION_KEY(_ID)) — the operator's
7
- * explicit choice: self-hosted deployments sharing one key with their
8
- * server, and cloud sandboxes injected with the platform key. When the
9
- * env key is set, bootstrap-delivered material is ignored entirely.
10
- * 2. Bootstrap-delivered — server-managed per-identity keys handed to
11
- * desktop-class runners by getRunnerBootstrapConfig. Held in memory
12
- * only; persistence lives server-side, which is what makes Temporal
13
- * replay work across runner restarts (every boot re-fetches the SAME
14
- * key).
15
- *
16
- * Encryption is enabled iff a key is present from either source — the same
17
- * enabled-iff-configured pattern as the claim-check codec. A malformed key
18
- * fails the boot rather than silently running plaintext: an operator who set
19
- * the key (or a server that minted one) intended history to be encrypted.
20
- *
21
- * Key rotation: payloads carry the id of the key that encrypted them.
22
- * During a rotation window the previous key stays readable via the
23
- * secondary pair while new payloads are written under the primary key.
24
- * Workers capture keys at construction, so a rotated bootstrap key lands
25
- * on the next runner boot — there is no live re-key.
26
- */
27
- import { getRunnerSecret } from "../shared/runner-credential-store.js";
28
- const KEY_ENV = "STIGMER_PAYLOAD_ENCRYPTION_KEY";
29
- const KEY_ID_ENV = "STIGMER_PAYLOAD_ENCRYPTION_KEY_ID";
30
- const SECONDARY_KEY_ENV = "STIGMER_PAYLOAD_ENCRYPTION_SECONDARY_KEY";
31
- const SECONDARY_KEY_ID_ENV = "STIGMER_PAYLOAD_ENCRYPTION_SECONDARY_KEY_ID";
32
- const AES_256_KEY_BYTES = 32;
33
- /**
34
- * Returns the encryption config, or undefined when encryption is not
35
- * configured (the codec is then simply not installed).
36
- *
37
- * Source precedence: the env key wins outright; bootstrap-delivered
38
- * material applies only when no env key is set (see the module doc).
39
- *
40
- * @throws when a key is present but malformed, or a key id is missing —
41
- * key misconfiguration must stop the boot, not degrade to plaintext.
42
- * This applies equally to bootstrap material: a server that hands out
43
- * a bad key or omits its id has broken the protocol contract, and
44
- * running plaintext against a server that manages keys would silently
45
- * defeat the feature.
46
- */
47
- export function loadPayloadEncryptionConfig(bootstrap) {
48
- // Key VALUES resolve through the credential store (the #508 boot capture
49
- // moves them out of process.env — agent shells must not read them); the
50
- // *_KEY_ID companions are rotation bookkeeping, not secrets, and stay
51
- // plain env reads.
52
- const rawKey = getRunnerSecret(KEY_ENV);
53
- if (rawKey) {
54
- const primary = {
55
- keyId: requireKeyId(KEY_ID_ENV),
56
- key: parseKey(rawKey, KEY_ENV),
57
- };
58
- const rawSecondary = getRunnerSecret(SECONDARY_KEY_ENV);
59
- const secondary = rawSecondary
60
- ? {
61
- keyId: requireKeyId(SECONDARY_KEY_ID_ENV),
62
- key: parseKey(rawSecondary, SECONDARY_KEY_ENV),
63
- }
64
- : undefined;
65
- return { primary, secondary };
66
- }
67
- if (bootstrap?.key) {
68
- const primary = {
69
- keyId: requireBootstrapKeyId(bootstrap.keyId, "payload_encryption_key_id"),
70
- key: parseKey(bootstrap.key, "bootstrap payload_encryption_key"),
71
- };
72
- const secondary = bootstrap.secondaryKey
73
- ? {
74
- keyId: requireBootstrapKeyId(bootstrap.secondaryKeyId, "payload_encryption_secondary_key_id"),
75
- key: parseKey(bootstrap.secondaryKey, "bootstrap payload_encryption_secondary_key"),
76
- }
77
- : undefined;
78
- return { primary, secondary };
79
- }
80
- return undefined;
81
- }
82
- function requireKeyId(envName) {
83
- const keyId = process.env[envName];
84
- // An explicit id is required (no default): during rotation two keys
85
- // coexist, and payloads must name which one encrypted them.
86
- if (!keyId) {
87
- throw new Error(`Payload encryption misconfigured: ${envName} is required when the ` +
88
- `corresponding key is set`);
89
- }
90
- return keyId;
91
- }
92
- function requireBootstrapKeyId(keyId, fieldName) {
93
- if (!keyId) {
94
- throw new Error(`Runner bootstrap returned a payload encryption key without its ${fieldName} — ` +
95
- `refusing to encrypt under an unidentified key (server contract violation)`);
96
- }
97
- return keyId;
98
- }
99
- function parseKey(rawBase64, envName) {
100
- let key;
101
- try {
102
- key = Buffer.from(rawBase64, "base64");
103
- }
104
- catch {
105
- throw new Error(`Payload encryption misconfigured: ${envName} is not valid base64`);
106
- }
107
- if (key.length !== AES_256_KEY_BYTES) {
108
- throw new Error(`Payload encryption misconfigured: ${envName} must decode to ` +
109
- `${AES_256_KEY_BYTES} bytes (AES-256), got ${key.length}`);
110
- }
111
- return key;
112
- }
113
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/encryption/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AA4BvE,MAAM,OAAO,GAAG,gCAAgC,CAAC;AACjD,MAAM,UAAU,GAAG,mCAAmC,CAAC;AACvD,MAAM,iBAAiB,GAAG,0CA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,SAAS,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,oEAAoE;IACpE,4DAA4D;IAC5D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,qCAAqC,OAAO,wBAAwB;YAClE,0BAA0B,CAC7B,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAyB,EAAE,SAAiB;IACzE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,kEAAkE,SAAS,KAAK;YAC9E,2EAA2E,CAC9E,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,SAAiB,EAAE,OAAe;IAClD,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,sBAAsB,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,iBAAiB,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,qCAAqC,OAAO,kBAAkB;YAC5D,GAAG,iBAAiB,yBAAyB,GAAG,CAAC,MAAM,EAAE,CAC5D,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,3 +0,0 @@
1
- export { EncryptionPayloadCodec } from "./payload-codec.js";
2
- export { loadPayloadEncryptionConfig } from "./config.js";
3
- export type { PayloadEncryptionConfig, EncryptionKey } from "./config.js";
@@ -1,3 +0,0 @@
1
- export { EncryptionPayloadCodec } from "./payload-codec.js";
2
- export { loadPayloadEncryptionConfig } from "./config.js";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Temporal PayloadCodec that encrypts payloads at rest in workflow
3
- * history (stigmer-cloud#227).
4
- *
5
- * Why: the workflow engine runs inside the Temporal deterministic
6
- * sandbox, so decrypted execution-context values cross the history
7
- * boundary in many places — the hydrate activity result, the runtime
8
- * env passed as an input to every per-task activity, and expression
9
- * results recorded as local-activity markers. Encrypting at the payload
10
- * codec layer closes the entire class with one mechanism instead of
11
- * chasing each crossing.
12
- *
13
- * Envelope (cross-SDK contract — the Java decode-only codec in
14
- * stigmer-cloud's temporal-starter must match it byte-for-byte, pinned
15
- * by the conformance fixture in __tests__/fixtures/):
16
- *
17
- * metadata: encoding = "binary/encrypted"
18
- * encryption-key-id = <key id that encrypted this payload>
19
- * data: iv (12 bytes) ‖ AES-256-GCM(ciphertext ‖ tag (16 bytes))
20
- *
21
- * The plaintext is the serialized ORIGINAL Payload proto (metadata AND
22
- * data), so decode restores the payload exactly — including its
23
- * original encoding — with no side channel.
24
- *
25
- * Decode passes through payloads it did not encode. This is what keeps
26
- * plaintext signals from the Java/Go orchestrators and pre-rollout
27
- * in-flight histories working with zero migration. Everything else
28
- * fails closed: unknown key id, missing key id, and ciphertext tampering
29
- * all throw rather than surfacing bogus payloads.
30
- */
31
- import type { Payload, PayloadCodec } from "@temporalio/common";
32
- import type { PayloadEncryptionConfig } from "./config.js";
33
- export declare class EncryptionPayloadCodec implements PayloadCodec {
34
- private readonly config;
35
- private readonly decryptKeysById;
36
- constructor(config: PayloadEncryptionConfig);
37
- encode(payloads: Payload[]): Promise<Payload[]>;
38
- decode(payloads: Payload[]): Promise<Payload[]>;
39
- private encodePayload;
40
- private decodePayload;
41
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * Temporal PayloadCodec that encrypts payloads at rest in workflow
3
- * history (stigmer-cloud#227).
4
- *
5
- * Why: the workflow engine runs inside the Temporal deterministic
6
- * sandbox, so decrypted execution-context values cross the history
7
- * boundary in many places — the hydrate activity result, the runtime
8
- * env passed as an input to every per-task activity, and expression
9
- * results recorded as local-activity markers. Encrypting at the payload
10
- * codec layer closes the entire class with one mechanism instead of
11
- * chasing each crossing.
12
- *
13
- * Envelope (cross-SDK contract — the Java decode-only codec in
14
- * stigmer-cloud's temporal-starter must match it byte-for-byte, pinned
15
- * by the conformance fixture in __tests__/fixtures/):
16
- *
17
- * metadata: encoding = "binary/encrypted"
18
- * encryption-key-id = <key id that encrypted this payload>
19
- * data: iv (12 bytes) ‖ AES-256-GCM(ciphertext ‖ tag (16 bytes))
20
- *
21
- * The plaintext is the serialized ORIGINAL Payload proto (metadata AND
22
- * data), so decode restores the payload exactly — including its
23
- * original encoding — with no side channel.
24
- *
25
- * Decode passes through payloads it did not encode. This is what keeps
26
- * plaintext signals from the Java/Go orchestrators and pre-rollout
27
- * in-flight histories working with zero migration. Everything else
28
- * fails closed: unknown key id, missing key id, and ciphertext tampering
29
- * all throw rather than surfacing bogus payloads.
30
- */
31
- import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
32
- // Default-import + destructure, NOT `import { temporal } from …`:
33
- // @temporalio/proto is CommonJS and its `temporal` export defeats Node's
34
- // cjs-module-lexer named-export detection, so the named form loads under
35
- // tsx/vitest (their interop is looser) but crashes plain `node dist/main.js`
36
- // at startup with "Named export 'temporal' not found" (stigmer/stigmer#399
37
- // boot regression). Pinned by scripts/verify-dist-boot.mjs in CI.
38
- import proto from "@temporalio/proto";
39
- const { temporal } = proto;
40
- const ENCODING_METADATA_KEY = "encoding";
41
- const ENCRYPTED_ENCODING_VALUE = "binary/encrypted";
42
- const KEY_ID_METADATA_KEY = "encryption-key-id";
43
- /** AES-GCM parameters shared with the Java implementation. */
44
- const IV_BYTES = 12;
45
- const AUTH_TAG_BYTES = 16;
46
- export class EncryptionPayloadCodec {
47
- config;
48
- decryptKeysById;
49
- constructor(config) {
50
- this.config = config;
51
- this.decryptKeysById = new Map([[config.primary.keyId, config.primary.key]]);
52
- if (config.secondary) {
53
- this.decryptKeysById.set(config.secondary.keyId, config.secondary.key);
54
- }
55
- }
56
- async encode(payloads) {
57
- return payloads.map((p) => this.encodePayload(p));
58
- }
59
- async decode(payloads) {
60
- return payloads.map((p) => this.decodePayload(p));
61
- }
62
- encodePayload(payload) {
63
- // Data-less payloads (binary/null from void results) stay as-is:
64
- // there is nothing to protect, and the cross-language parents that
65
- // await our workflows as void must be able to read them without a key.
66
- if (!payload.data || payload.data.length === 0) {
67
- return payload;
68
- }
69
- const plaintext = temporal.api.common.v1.Payload.encode(payload).finish();
70
- return {
71
- metadata: {
72
- [ENCODING_METADATA_KEY]: Buffer.from(ENCRYPTED_ENCODING_VALUE),
73
- [KEY_ID_METADATA_KEY]: Buffer.from(this.config.primary.keyId),
74
- },
75
- data: encrypt(plaintext, this.config.primary),
76
- };
77
- }
78
- decodePayload(payload) {
79
- if (!isEncryptedPayload(payload)) {
80
- return payload;
81
- }
82
- const keyIdBytes = payload.metadata?.[KEY_ID_METADATA_KEY];
83
- if (!keyIdBytes) {
84
- throw new Error("Encrypted payload is missing its encryption-key-id metadata — refusing to decode");
85
- }
86
- const keyId = Buffer.from(keyIdBytes).toString("utf-8");
87
- const key = this.decryptKeysById.get(keyId);
88
- if (!key) {
89
- throw new Error(`Encrypted payload uses unknown key id '${keyId}' — configure it as the ` +
90
- `primary or secondary payload encryption key (rotation window?)`);
91
- }
92
- const plaintext = decrypt(payload.data, key, keyId);
93
- return temporal.api.common.v1.Payload.decode(plaintext);
94
- }
95
- }
96
- function isEncryptedPayload(payload) {
97
- const encoding = payload.metadata?.[ENCODING_METADATA_KEY];
98
- if (!encoding)
99
- return false;
100
- return Buffer.from(encoding).toString("utf-8") === ENCRYPTED_ENCODING_VALUE;
101
- }
102
- function encrypt(plaintext, key) {
103
- const iv = randomBytes(IV_BYTES);
104
- const cipher = createCipheriv("aes-256-gcm", key.key, iv);
105
- const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
106
- // Layout iv ‖ ciphertext ‖ tag matches Java's AES/GCM/NoPadding, whose
107
- // doFinal() output is ciphertext ‖ tag.
108
- return Buffer.concat([iv, ciphertext, cipher.getAuthTag()]);
109
- }
110
- function decrypt(data, key, keyId) {
111
- if (data.length < IV_BYTES + AUTH_TAG_BYTES) {
112
- throw new Error(`Encrypted payload under key id '${keyId}' is truncated (${data.length} bytes)`);
113
- }
114
- const buf = Buffer.from(data);
115
- const iv = buf.subarray(0, IV_BYTES);
116
- const ciphertext = buf.subarray(IV_BYTES, buf.length - AUTH_TAG_BYTES);
117
- const tag = buf.subarray(buf.length - AUTH_TAG_BYTES);
118
- const decipher = createDecipheriv("aes-256-gcm", key, iv);
119
- decipher.setAuthTag(tag);
120
- try {
121
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
122
- }
123
- catch {
124
- // GCM auth failure: tampered ciphertext or a key that does not match
125
- // its advertised id. Never surface partially decrypted bytes.
126
- throw new Error(`Failed to decrypt payload under key id '${keyId}' — ciphertext is ` +
127
- `corrupt or the configured key does not match`);
128
- }
129
- }
130
- //# sourceMappingURL=payload-codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload-codec.js","sourceRoot":"","sources":["../../src/encryption/payload-codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5E,kEAAkE;AAClE,yEAAyE;AACzE,yEAAyE;AACzE,6EAA6E;AAC7E,2EAA2E;AAC3E,kEAAkE;AAClE,OAAO,KAAK,MAAM,mBAAmB,CAAC;A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