@leitwerk-dev/worker-protocol 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DVN32ANP.js → chunk-VR7BWTD7.js} +5 -1
- package/dist/chunk-VR7BWTD7.js.map +1 -0
- package/dist/docker-config.d.ts +16 -0
- package/dist/docker-config.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -24
- package/dist/index.js.map +1 -1
- package/dist/ipc-codec.d.ts +22 -0
- package/dist/ipc-codec.d.ts.map +1 -1
- package/dist/ipc-decode.d.ts +7 -0
- package/dist/ipc-decode.d.ts.map +1 -1
- package/dist/ipc-messages.d.ts +286 -18
- package/dist/ipc-messages.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +13 -2
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/pi-resource-manifest.d.ts +35 -1
- package/dist/pi-resource-manifest.d.ts.map +1 -1
- package/dist/testing.d.ts +2 -8
- package/dist/testing.d.ts.map +1 -1
- package/dist/worker-api-version.d.ts +1 -0
- package/dist/worker-api-version.d.ts.map +1 -1
- package/dist/worker-ipc-transport.d.ts +7 -0
- package/dist/worker-ipc-transport.d.ts.map +1 -1
- package/dist/worker-result-image-public.d.ts +2 -0
- package/dist/worker-result-image-public.d.ts.map +1 -0
- package/dist/worker-result-image-public.js +7 -0
- package/dist/worker-result-image-public.js.map +1 -0
- package/dist/worker-result-image.d.ts +22 -0
- package/dist/worker-result-image.d.ts.map +1 -1
- package/dist/worker-result-image.js +1 -1
- package/dist/worker-session-snapshot.d.ts +5 -0
- package/dist/worker-session-snapshot.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/docker-config.ts +12 -0
- package/src/index.ts +62 -5
- package/src/ipc-codec.ts +40 -6
- package/src/ipc-decode.ts +15 -2
- package/src/ipc-messages.ts +314 -25
- package/src/pi-resource-bundle.ts +13 -2
- package/src/pi-resource-manifest.ts +35 -1
- package/src/testing.ts +2 -11
- package/src/worker-api-version.ts +1 -0
- package/src/worker-ipc-transport.ts +7 -0
- package/src/worker-result-image-public.ts +1 -0
- package/src/worker-result-image.ts +25 -1
- package/src/worker-session-snapshot.ts +5 -0
- package/dist/chunk-DVN32ANP.js.map +0 -1
|
@@ -16,9 +16,13 @@ function assertResultImageStorageSegment(value) {
|
|
|
16
16
|
if (!isResultImageStorageSegment(value)) throw new Error("Invalid result image storage id");
|
|
17
17
|
}
|
|
18
18
|
var workerResultImageUploadResponseSchema = v.object({
|
|
19
|
+
/** @internal */
|
|
19
20
|
imageId: v.string(),
|
|
21
|
+
/** @internal */
|
|
20
22
|
url: v.string(),
|
|
23
|
+
/** @internal */
|
|
21
24
|
mimeType: v.picklist(RESULT_IMAGE_MIME_TYPES),
|
|
25
|
+
/** @internal */
|
|
22
26
|
byteSize: v.number()
|
|
23
27
|
});
|
|
24
28
|
function buildWorkerResultImageUploadPath(instanceId, turnRecordId) {
|
|
@@ -59,4 +63,4 @@ export {
|
|
|
59
63
|
parseManagedResultImagePath,
|
|
60
64
|
parseWorkerResultImageUploadResponse
|
|
61
65
|
};
|
|
62
|
-
//# sourceMappingURL=chunk-
|
|
66
|
+
//# sourceMappingURL=chunk-VR7BWTD7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/worker-result-image.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/** @internal */\nexport const WORKER_RESULT_IMAGE_WORKER_ID_HEADER = \"x-leitwerk-worker-id\";\n/** @internal */\nexport const RESULT_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\"] as const;\n/** @internal */\nexport const RESULT_IMAGE_MAX_SIZE_BYTES = 10 * 1024 * 1024;\n/** @internal */\nexport const RESULT_IMAGE_STORAGE_SEGMENT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n/** @internal */\nexport const RESULT_IMAGE_ID_PATTERN = /^img_[A-Za-z0-9]+\\.(png|jpg|webp)$/;\n/** @internal */\nexport type ResultImageMimeType = (typeof RESULT_IMAGE_MIME_TYPES)[number];\n\n/** @internal */\nexport function isResultImageStorageSegment(value: string): boolean {\n\treturn RESULT_IMAGE_STORAGE_SEGMENT_PATTERN.test(value);\n}\n\n/** @internal */\nexport function parseResultImageId(value: string): {\n\t/** @internal */\n\textension: \"png\" | \"jpg\" | \"webp\";\n} | null {\n\tconst extension = RESULT_IMAGE_ID_PATTERN.exec(value)?.[1];\n\treturn extension === \"png\" || extension === \"jpg\" || extension === \"webp\" ? { extension } : null;\n}\n\nfunction assertResultImageStorageSegment(value: string): void {\n\tif (!isResultImageStorageSegment(value)) throw new Error(\"Invalid result image storage id\");\n}\n\n/** @internal */\nexport const workerResultImageUploadResponseSchema = v.object({\n\t/** @internal */\n\timageId: v.string(),\n\t/** @internal */\n\turl: v.string(),\n\t/** @internal */\n\tmimeType: v.picklist(RESULT_IMAGE_MIME_TYPES),\n\t/** @internal */\n\tbyteSize: v.number(),\n});\n\n/** @internal */\nexport type WorkerResultImageUploadResponse = v.InferOutput<\n\ttypeof workerResultImageUploadResponseSchema\n>;\n\n/** @internal */\nexport function buildWorkerResultImageUploadPath(instanceId: string, turnRecordId: string): string {\n\tassertResultImageStorageSegment(instanceId);\n\tassertResultImageStorageSegment(turnRecordId);\n\treturn `/internal/workers/${instanceId}/turn-records/${turnRecordId}/result-images`;\n}\n\n/** @internal */\nexport function buildManagedResultImagePath(\n\tinstanceId: string,\n\tturnRecordId: string,\n\timageId: string,\n): string {\n\tassertResultImageStorageSegment(instanceId);\n\tassertResultImageStorageSegment(turnRecordId);\n\tif (!parseResultImageId(imageId)) throw new Error(\"Invalid result image id\");\n\treturn `/api/processes/${instanceId}/turn-records/${turnRecordId}/result-images/${imageId}`;\n}\n\nconst MANAGED_RESULT_IMAGE_PATH =\n\t/^\\/api\\/processes\\/([^/]+)\\/turn-records\\/([^/]+)\\/result-images\\/([^/]+)$/;\n\n/** @internal */\nexport function parseManagedResultImagePath(value: string): {\n\t/** @internal */\n\tinstanceId: string;\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\timageId: string;\n} | null {\n\tconst match = MANAGED_RESULT_IMAGE_PATH.exec(value);\n\tconst instanceId = match?.[1];\n\tconst turnRecordId = match?.[2];\n\tconst imageId = match?.[3];\n\treturn instanceId &&\n\t\tturnRecordId &&\n\t\timageId &&\n\t\tisResultImageStorageSegment(instanceId) &&\n\t\tisResultImageStorageSegment(turnRecordId) &&\n\t\tparseResultImageId(imageId)\n\t\t? { instanceId, turnRecordId, imageId }\n\t\t: null;\n}\n\n/** @internal */\nexport function parseWorkerResultImageUploadResponse(\n\tvalue: unknown,\n): WorkerResultImageUploadResponse | null {\n\tconst parsed = v.safeParse(workerResultImageUploadResponseSchema, value);\n\treturn parsed.success ? parsed.output : null;\n}\n"],"mappings":";AAAA,YAAY,OAAO;AAGZ,IAAM,uCAAuC;AAE7C,IAAM,0BAA0B,CAAC,aAAa,cAAc,YAAY;AAExE,IAAM,8BAA8B,KAAK,OAAO;AAEhD,IAAM,uCAAuC;AAE7C,IAAM,0BAA0B;AAKhC,SAAS,4BAA4B,OAAwB;AACnE,SAAO,qCAAqC,KAAK,KAAK;AACvD;AAGO,SAAS,mBAAmB,OAG1B;AACR,QAAM,YAAY,wBAAwB,KAAK,KAAK,IAAI,CAAC;AACzD,SAAO,cAAc,SAAS,cAAc,SAAS,cAAc,SAAS,EAAE,UAAU,IAAI;AAC7F;AAEA,SAAS,gCAAgC,OAAqB;AAC7D,MAAI,CAAC,4BAA4B,KAAK,EAAG,OAAM,IAAI,MAAM,iCAAiC;AAC3F;AAGO,IAAM,wCAA0C,SAAO;AAAA;AAAA,EAE7D,SAAW,SAAO;AAAA;AAAA,EAElB,KAAO,SAAO;AAAA;AAAA,EAEd,UAAY,WAAS,uBAAuB;AAAA;AAAA,EAE5C,UAAY,SAAO;AACpB,CAAC;AAQM,SAAS,iCAAiC,YAAoB,cAA8B;AAClG,kCAAgC,UAAU;AAC1C,kCAAgC,YAAY;AAC5C,SAAO,qBAAqB,UAAU,iBAAiB,YAAY;AACpE;AAGO,SAAS,4BACf,YACA,cACA,SACS;AACT,kCAAgC,UAAU;AAC1C,kCAAgC,YAAY;AAC5C,MAAI,CAAC,mBAAmB,OAAO,EAAG,OAAM,IAAI,MAAM,yBAAyB;AAC3E,SAAO,kBAAkB,UAAU,iBAAiB,YAAY,kBAAkB,OAAO;AAC1F;AAEA,IAAM,4BACL;AAGM,SAAS,4BAA4B,OAOnC;AACR,QAAM,QAAQ,0BAA0B,KAAK,KAAK;AAClD,QAAM,aAAa,QAAQ,CAAC;AAC5B,QAAM,eAAe,QAAQ,CAAC;AAC9B,QAAM,UAAU,QAAQ,CAAC;AACzB,SAAO,cACN,gBACA,WACA,4BAA4B,UAAU,KACtC,4BAA4B,YAAY,KACxC,mBAAmB,OAAO,IACxB,EAAE,YAAY,cAAc,QAAQ,IACpC;AACJ;AAGO,SAAS,qCACf,OACyC;AACzC,QAAM,SAAW,YAAU,uCAAuC,KAAK;AACvE,SAAO,OAAO,UAAU,OAAO,SAAS;AACzC;","names":[]}
|
package/dist/docker-config.d.ts
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
+
/** @internal */
|
|
2
3
|
export declare const dockerRegistryCredentialSchema: v.ObjectSchema<{
|
|
4
|
+
/** @internal */
|
|
3
5
|
readonly registry: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
6
|
+
/** @internal */
|
|
4
7
|
readonly username: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.RegexAction<string, undefined>]>;
|
|
8
|
+
/** @internal */
|
|
5
9
|
readonly password: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
6
10
|
}, undefined>;
|
|
11
|
+
/** @internal */
|
|
7
12
|
export declare const ipAddressSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.CheckAction<string, "Expected an IPv4 or IPv6 address">]>;
|
|
13
|
+
/** @internal */
|
|
8
14
|
export type DockerNetworkConfig = v.InferOutput<typeof dockerNetworkSchema>;
|
|
15
|
+
/** @internal */
|
|
9
16
|
export declare const dockerNetworkSchema: v.StrictObjectSchema<{
|
|
17
|
+
/** @internal */
|
|
10
18
|
readonly bridge_cidr: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, undefined>]>;
|
|
19
|
+
/** @internal */
|
|
11
20
|
readonly address_pools: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
21
|
+
/** @internal */
|
|
12
22
|
readonly base: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, undefined>]>;
|
|
23
|
+
/** @internal */
|
|
13
24
|
readonly size: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MaxValueAction<number, 30, undefined>]>;
|
|
14
25
|
}, undefined>, v.CheckAction<{
|
|
26
|
+
/** @internal */
|
|
15
27
|
base: string;
|
|
28
|
+
/** @internal */
|
|
16
29
|
size: number;
|
|
17
30
|
}, undefined>]>, undefined>, v.NonEmptyAction<{
|
|
31
|
+
/** @internal */
|
|
18
32
|
base: string;
|
|
33
|
+
/** @internal */
|
|
19
34
|
size: number;
|
|
20
35
|
}[], undefined>]>;
|
|
36
|
+
/** @internal */
|
|
21
37
|
readonly dns: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.CheckAction<string, "Expected an IPv4 or IPv6 address">]>, undefined>, v.NonEmptyAction<string[], undefined>]>;
|
|
22
38
|
}, undefined>;
|
|
23
39
|
//# sourceMappingURL=docker-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docker-config.d.ts","sourceRoot":"","sources":["../src/docker-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,eAAO,MAAM,8BAA8B
|
|
1
|
+
{"version":3,"file":"docker-config.d.ts","sourceRoot":"","sources":["../src/docker-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,gBAAgB;AAChB,eAAO,MAAM,8BAA8B;IAC1C,gBAAgB;;IAEhB,gBAAgB;;IAEhB,gBAAgB;;aAEf,CAAC;AAEH,gBAAgB;AAChB,eAAO,MAAM,eAAe,wJAI3B,CAAC;AAOF,gBAAgB;AAChB,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE5E,gBAAgB;AAChB,eAAO,MAAM,mBAAmB;IAC/B,gBAAgB;;IAEhB,gBAAgB;;QAKZ,gBAAgB;;QAEhB,gBAAgB;;;;;;;;;;;;;IAQpB,gBAAgB;;aAEf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export * from "./docker-config.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export { deserializeMessage, IPC_PROTOCOL_VERSION, type IpcEnvelope, serializeMessage, } from "./ipc-codec.js";
|
|
3
|
+
export { decodeServerToWorkerMessage, decodeWorkerToServerMessage } from "./ipc-decode.js";
|
|
4
|
+
export type { DevelopmentToolsStartConfig, InputDelivery, IntegrationToolDeclaration, ProcessInstanceSnapshot, ProcessProjectSnapshot, ServerToWorkerMessage, WorkerCredentialMaterial, WorkerCredentialUpdateResultPayload, WorkerDockerRegistryCredential, WorkerEventPayload, WorkerFailedPayload, WorkerHelloPayload, WorkerInputConsumedPayload, WorkerIntegrationToolCancelPayload, WorkerIntegrationToolRequestPayload, WorkerIntegrationToolResultPayload, WorkerLifecycleParkedPayload, WorkerQuestionRequestedPayload, WorkerQuestionResponsePayload, WorkerReadyPayload, WorkerRepositoryCredential, WorkerRuntimeSettingsSnapshot, WorkerStartPayload, WorkerToServerMessage, WorkerTurnFailedPayload, WorkerTurnOutcomePayload, WorkerTurnStartAcceptedPayload, WorkerTurnTerminalRecordedPayload, } from "./ipc-messages.js";
|
|
5
|
+
export { createIpcMessage } from "./ipc-messages.js";
|
|
5
6
|
export * from "./pi-resource-bundle.js";
|
|
6
|
-
export
|
|
7
|
+
export { canonicalizeJson, canonicalJsonEqual, canonicalJsonStringify, PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION, type PiResourceFileProvenance, type PiResourceManifest, type PiResourceProvenanceKind, type PiResourceSnapshotCompatibility, type PiResourceSnapshotModel, type PiResourceSnapshotWorkerConfig, parsePiResourceManifest, } from "./pi-resource-manifest.js";
|
|
7
8
|
export * from "./testing.js";
|
|
8
9
|
export * from "./worker-api-version.js";
|
|
9
10
|
export * from "./worker-ipc-transport.js";
|
|
10
|
-
export
|
|
11
|
+
export { buildManagedResultImagePath, buildWorkerResultImageUploadPath, isResultImageStorageSegment, parseManagedResultImagePath, parseResultImageId, parseWorkerResultImageUploadResponse, RESULT_IMAGE_MAX_SIZE_BYTES, type ResultImageMimeType, WORKER_RESULT_IMAGE_WORKER_ID_HEADER, } from "./worker-result-image.js";
|
|
11
12
|
export * from "./worker-session-snapshot.js";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,OAAO,EACN,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,WAAW,EAChB,gBAAgB,GAChB,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ATTERN,
|
|
3
2
|
RESULT_IMAGE_MAX_SIZE_BYTES,
|
|
4
|
-
RESULT_IMAGE_MIME_TYPES,
|
|
5
|
-
RESULT_IMAGE_STORAGE_SEGMENT_PATTERN,
|
|
6
3
|
WORKER_RESULT_IMAGE_WORKER_ID_HEADER,
|
|
7
4
|
buildManagedResultImagePath,
|
|
8
5
|
buildWorkerResultImageUploadPath,
|
|
9
6
|
isResultImageStorageSegment,
|
|
10
7
|
parseManagedResultImagePath,
|
|
11
8
|
parseResultImageId,
|
|
12
|
-
parseWorkerResultImageUploadResponse
|
|
13
|
-
|
|
14
|
-
} from "./chunk-DVN32ANP.js";
|
|
9
|
+
parseWorkerResultImageUploadResponse
|
|
10
|
+
} from "./chunk-VR7BWTD7.js";
|
|
15
11
|
|
|
16
12
|
// src/docker-config.ts
|
|
17
13
|
import { isIP } from "net";
|
|
18
14
|
import * as v from "valibot";
|
|
19
15
|
var dockerRegistryCredentialSchema = v.object({
|
|
16
|
+
/** @internal */
|
|
20
17
|
registry: v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?::[0-9]{1,5})?$/)),
|
|
18
|
+
/** @internal */
|
|
21
19
|
username: v.pipe(v.string(), v.nonEmpty(), v.regex(/^[^:\r\n\0]+$/)),
|
|
20
|
+
/** @internal */
|
|
22
21
|
password: v.pipe(v.string(), v.nonEmpty())
|
|
23
22
|
});
|
|
24
23
|
var ipAddressSchema = v.pipe(
|
|
@@ -33,12 +32,16 @@ var ipv4CidrSchema = v.pipe(
|
|
|
33
32
|
)
|
|
34
33
|
);
|
|
35
34
|
var dockerNetworkSchema = v.strictObject({
|
|
35
|
+
/** @internal */
|
|
36
36
|
bridge_cidr: ipv4CidrSchema,
|
|
37
|
+
/** @internal */
|
|
37
38
|
address_pools: v.pipe(
|
|
38
39
|
v.array(
|
|
39
40
|
v.pipe(
|
|
40
41
|
v.strictObject({
|
|
42
|
+
/** @internal */
|
|
41
43
|
base: ipv4CidrSchema,
|
|
44
|
+
/** @internal */
|
|
42
45
|
size: v.pipe(v.number(), v.integer(), v.maxValue(30))
|
|
43
46
|
}),
|
|
44
47
|
v.check((pool) => pool.size >= Number(pool.base.split("/")[1]))
|
|
@@ -46,6 +49,7 @@ var dockerNetworkSchema = v.strictObject({
|
|
|
46
49
|
),
|
|
47
50
|
v.nonEmpty()
|
|
48
51
|
),
|
|
52
|
+
/** @internal */
|
|
49
53
|
dns: v.pipe(v.array(ipAddressSchema), v.nonEmpty())
|
|
50
54
|
});
|
|
51
55
|
|
|
@@ -54,13 +58,21 @@ import { parseSchema } from "@leitwerk-dev/protocol";
|
|
|
54
58
|
import * as v2 from "valibot";
|
|
55
59
|
var IPC_PROTOCOL_VERSION = "leitwerk/worker-ipc/v1";
|
|
56
60
|
var IPC_ENVELOPE_SCHEMA = v2.object({
|
|
61
|
+
/** @internal */
|
|
57
62
|
protocol: v2.literal(IPC_PROTOCOL_VERSION),
|
|
63
|
+
/** @internal */
|
|
58
64
|
messageId: v2.string(),
|
|
65
|
+
/** @internal */
|
|
59
66
|
correlationId: v2.optional(v2.string()),
|
|
67
|
+
/** @internal */
|
|
60
68
|
type: v2.string(),
|
|
69
|
+
/** @internal */
|
|
61
70
|
instanceId: v2.string(),
|
|
71
|
+
/** @internal */
|
|
62
72
|
workerId: v2.string(),
|
|
73
|
+
/** @internal */
|
|
63
74
|
sentAt: v2.string(),
|
|
75
|
+
/** @internal */
|
|
64
76
|
payload: v2.unknown()
|
|
65
77
|
});
|
|
66
78
|
function validateEnvelope(msg) {
|
|
@@ -300,33 +312,55 @@ var jsonObjectSchema = v3.record(v3.string(), v3.unknown());
|
|
|
300
312
|
var positiveSafeIntegerSchema = v3.pipe(v3.number(), v3.safeInteger(), v3.minValue(1));
|
|
301
313
|
var nonNegativeSafeIntegerSchema = v3.pipe(v3.number(), v3.safeInteger(), v3.minValue(0));
|
|
302
314
|
var piResourceManifestSchema = v3.strictObject({
|
|
315
|
+
/** @internal */
|
|
303
316
|
schemaVersion: v3.literal(PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION),
|
|
317
|
+
/** @internal */
|
|
304
318
|
model: v3.strictObject({
|
|
319
|
+
/** @internal */
|
|
305
320
|
profileId: nonBlankStringSchema,
|
|
321
|
+
/** @internal */
|
|
306
322
|
providerId: nonBlankStringSchema,
|
|
323
|
+
/** @internal */
|
|
307
324
|
modelId: nonBlankStringSchema,
|
|
325
|
+
/** @internal */
|
|
308
326
|
thinkingLevel: nonBlankStringSchema
|
|
309
327
|
}),
|
|
328
|
+
/** @internal */
|
|
310
329
|
providerOptions: v3.record(v3.string(), nonBlankStringSchema),
|
|
330
|
+
/** @internal */
|
|
311
331
|
providerWorkerConfig: v3.nullable(
|
|
312
332
|
v3.strictObject({
|
|
333
|
+
/** @internal */
|
|
313
334
|
version: positiveSafeIntegerSchema,
|
|
335
|
+
/** @internal */
|
|
314
336
|
value: jsonObjectSchema
|
|
315
337
|
})
|
|
316
338
|
),
|
|
339
|
+
/** @internal */
|
|
317
340
|
declaredCredentialPaths: v3.array(nonBlankStringSchema),
|
|
341
|
+
/** @internal */
|
|
318
342
|
compatibility: v3.strictObject({
|
|
343
|
+
/** @internal */
|
|
319
344
|
workerApiVersion: nonBlankStringSchema,
|
|
345
|
+
/** @internal */
|
|
320
346
|
piVersion: nonBlankStringSchema,
|
|
347
|
+
/** @internal */
|
|
321
348
|
protocolVersion: v3.optional(nonBlankStringSchema)
|
|
322
349
|
}),
|
|
350
|
+
/** @internal */
|
|
323
351
|
provenance: v3.array(
|
|
324
352
|
v3.strictObject({
|
|
353
|
+
/** @internal */
|
|
325
354
|
kind: v3.picklist(["extension", "skill", "prompt", "generated"]),
|
|
355
|
+
/** @internal */
|
|
326
356
|
ownerExtensionId: v3.nullable(nonBlankStringSchema),
|
|
357
|
+
/** @internal */
|
|
327
358
|
packageName: v3.nullable(nonBlankStringSchema),
|
|
359
|
+
/** @internal */
|
|
328
360
|
snapshotPath: nonBlankStringSchema,
|
|
361
|
+
/** @internal */
|
|
329
362
|
sha256: v3.pipe(v3.string(), v3.regex(/^[a-f0-9]{64}$/)),
|
|
363
|
+
/** @internal */
|
|
330
364
|
size: nonNegativeSafeIntegerSchema
|
|
331
365
|
})
|
|
332
366
|
)
|
|
@@ -397,15 +431,6 @@ async function flushAsyncWork(iterations = 30) {
|
|
|
397
431
|
await new Promise((resolve) => setImmediate(resolve));
|
|
398
432
|
}
|
|
399
433
|
}
|
|
400
|
-
function createTestIpcEnvelopeBase(instanceId, workerId, messageId) {
|
|
401
|
-
return {
|
|
402
|
-
protocol: IPC_PROTOCOL_VERSION,
|
|
403
|
-
messageId,
|
|
404
|
-
instanceId,
|
|
405
|
-
workerId,
|
|
406
|
-
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
434
|
function createTestConfigSnapshot() {
|
|
410
435
|
return {
|
|
411
436
|
workers: {
|
|
@@ -460,13 +485,9 @@ function buildWorkerSessionSnapshotPath(instanceId) {
|
|
|
460
485
|
return `/internal/workers/${encodeURIComponent(instanceId)}/session-snapshot`;
|
|
461
486
|
}
|
|
462
487
|
export {
|
|
463
|
-
IPC_ENVELOPE_SCHEMA,
|
|
464
488
|
IPC_PROTOCOL_VERSION,
|
|
465
489
|
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
466
|
-
RESULT_IMAGE_ID_PATTERN,
|
|
467
490
|
RESULT_IMAGE_MAX_SIZE_BYTES,
|
|
468
|
-
RESULT_IMAGE_MIME_TYPES,
|
|
469
|
-
RESULT_IMAGE_STORAGE_SEGMENT_PATTERN,
|
|
470
491
|
WORKER_API_VERSION,
|
|
471
492
|
WORKER_ID_ENV,
|
|
472
493
|
WORKER_INSTANCE_ID_ENV,
|
|
@@ -489,7 +510,6 @@ export {
|
|
|
489
510
|
createCanonicalPiResourceBundle,
|
|
490
511
|
createIpcMessage,
|
|
491
512
|
createTestConfigSnapshot,
|
|
492
|
-
createTestIpcEnvelopeBase,
|
|
493
513
|
decodeServerToWorkerMessage,
|
|
494
514
|
decodeWorkerToServerMessage,
|
|
495
515
|
deserializeMessage,
|
|
@@ -502,12 +522,9 @@ export {
|
|
|
502
522
|
parsePiResourceManifest,
|
|
503
523
|
parseResultImageId,
|
|
504
524
|
parseWorkerResultImageUploadResponse,
|
|
505
|
-
piResourceManifestSchema,
|
|
506
525
|
serializeMessage,
|
|
507
526
|
sha256Digest,
|
|
508
|
-
validateEnvelope,
|
|
509
527
|
validateResourceRelativePath,
|
|
510
|
-
verifyCanonicalPiResourceBundle
|
|
511
|
-
workerResultImageUploadResponseSchema
|
|
528
|
+
verifyCanonicalPiResourceBundle
|
|
512
529
|
};
|
|
513
530
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/docker-config.ts","../src/ipc-codec.ts","../src/ipc-decode.ts","../src/ipc-messages.ts","../src/pi-resource-bundle.ts","../src/pi-resource-manifest.ts","../src/testing.ts","../src/worker-api-version.ts","../src/worker-ipc-transport.ts","../src/worker-session-snapshot.ts"],"sourcesContent":["import { isIP } from \"node:net\";\nimport * as v from \"valibot\";\n\nexport const dockerRegistryCredentialSchema = v.object({\n\tregistry: v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?::[0-9]{1,5})?$/)),\n\tusername: v.pipe(v.string(), v.nonEmpty(), v.regex(/^[^:\\r\\n\\0]+$/)),\n\tpassword: v.pipe(v.string(), v.nonEmpty()),\n});\n\nexport const ipAddressSchema = v.pipe(\n\tv.string(),\n\tv.nonEmpty(),\n\tv.check((value) => isIP(value) !== 0, \"Expected an IPv4 or IPv6 address\"),\n);\nconst ipv4CidrSchema = v.pipe(\n\tv.string(),\n\tv.check(\n\t\t(value) => /^.+\\/(?:[1-9]|[12][0-9]|30)$/.test(value) && isIP(value.split(\"/\")[0] ?? \"\") === 4,\n\t),\n);\nexport type DockerNetworkConfig = v.InferOutput<typeof dockerNetworkSchema>;\n\nexport const dockerNetworkSchema = v.strictObject({\n\tbridge_cidr: ipv4CidrSchema,\n\taddress_pools: v.pipe(\n\t\tv.array(\n\t\t\tv.pipe(\n\t\t\t\tv.strictObject({\n\t\t\t\t\tbase: ipv4CidrSchema,\n\t\t\t\t\tsize: v.pipe(v.number(), v.integer(), v.maxValue(30)),\n\t\t\t\t}),\n\t\t\t\tv.check((pool) => pool.size >= Number(pool.base.split(\"/\")[1])),\n\t\t\t),\n\t\t),\n\t\tv.nonEmpty(),\n\t),\n\tdns: v.pipe(v.array(ipAddressSchema), v.nonEmpty()),\n});\n","import { parseSchema } from \"@leitwerk-dev/protocol\";\nimport * as v from \"valibot\";\n\nexport const IPC_PROTOCOL_VERSION = \"leitwerk/worker-ipc/v1\" as const;\n\nexport const IPC_ENVELOPE_SCHEMA = v.object({\n\tprotocol: v.literal(IPC_PROTOCOL_VERSION),\n\tmessageId: v.string(),\n\tcorrelationId: v.optional(v.string()),\n\ttype: v.string(),\n\tinstanceId: v.string(),\n\tworkerId: v.string(),\n\tsentAt: v.string(),\n\tpayload: v.unknown(),\n});\n\nexport type IpcEnvelope = v.InferOutput<typeof IPC_ENVELOPE_SCHEMA>;\n\nexport function validateEnvelope(\n\tmsg: unknown,\n): { ok: true; envelope: IpcEnvelope } | { ok: false; error: string } {\n\tif (\n\t\ttypeof msg === \"object\" &&\n\t\tmsg !== null &&\n\t\t\"protocol\" in msg &&\n\t\ttypeof msg.protocol === \"string\" &&\n\t\tmsg.protocol !== IPC_PROTOCOL_VERSION\n\t) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `Worker IPC protocol '${msg.protocol}' is incompatible with expected protocol '${IPC_PROTOCOL_VERSION}'`,\n\t\t};\n\t}\n\tconst envelope = parseSchema(IPC_ENVELOPE_SCHEMA, msg, \"ipc envelope\");\n\treturn envelope.ok\n\t\t? { ok: true, envelope: envelope.value }\n\t\t: { ok: false, error: envelope.error };\n}\n\nexport function serializeMessage<TEnvelope extends IpcEnvelope>(envelope: TEnvelope): string {\n\treturn JSON.stringify(envelope);\n}\n\nexport function deserializeMessage(\n\tline: string,\n): { ok: true; message: IpcEnvelope } | { ok: false; error: string } {\n\tconst trimmed =\n\t\tline.length > 0 && line.charCodeAt(line.length - 1) === 0x0d ? line.slice(0, -1) : line;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(trimmed) as unknown;\n\t} catch {\n\t\treturn { ok: false, error: \"invalid JSON\" };\n\t}\n\tconst validated = validateEnvelope(parsed);\n\tif (!validated.ok) {\n\t\treturn { ok: false, error: validated.error };\n\t}\n\treturn { ok: true, message: validated.envelope };\n}\n","import { validateEnvelope } from \"./ipc-codec.js\";\nimport type { ServerToWorkerMessage, WorkerToServerMessage } from \"./ipc-messages.js\";\n\nexport type IpcDecodeResult<TMessage> =\n\t| { ok: true; message: TMessage }\n\t| { ok: false; error: string };\n\nconst SERVER_TO_WORKER_TYPES = [\n\t\"worker.start\",\n\t\"worker.turn_start_accepted\",\n\t\"worker.turn_terminal_recorded\",\n\t\"worker.credential_update_accepted\",\n\t\"worker.question_response\",\n\t\"worker.integration_tool_result\",\n\t\"input.batch\",\n\t\"worker.stop\",\n\t\"worker.abort_turn\",\n] as const satisfies readonly ServerToWorkerMessage[\"type\"][];\n\nconst WORKER_TO_SERVER_TYPES = [\n\t\"worker.hello\",\n\t\"worker.credential_update\",\n\t\"worker.bootstrap_progress\",\n\t\"worker.diagnostic_trace\",\n\t\"worker.ready\",\n\t\"worker.heartbeat\",\n\t\"worker.state\",\n\t\"worker.input_consumed\",\n\t\"worker.event\",\n\t\"worker.turn_started\",\n\t\"worker.question_requested\",\n\t\"worker.integration_tool_request\",\n\t\"worker.integration_tool_cancel\",\n\t\"worker.turn_outcome\",\n\t\"worker.turn_failed\",\n\t\"worker.lifecycle_parked\",\n\t\"worker.cleanup_started\",\n\t\"worker.cleanup_completed\",\n\t\"worker.failed\",\n] as const satisfies readonly WorkerToServerMessage[\"type\"][];\n\nfunction hasMessageType<TType extends string>(\n\tallowed: readonly TType[],\n\tvalue: string,\n): value is TType {\n\treturn (allowed as readonly string[]).includes(value);\n}\n\n/**\n * Validate the generic IPC envelope and narrow it to the correct typed message\n * union member for the given direction.\n *\n * This intentionally stops at the message discriminant boundary: it validates\n * envelope structure + known message type, but does not deeply validate the\n * payload shape. Payload fields are trusted to come from same-version\n * leitwerk components, so malformed payloads from a buggy sender can still\n * pass through as typed data.\n */\nfunction decodeKnownMessage<TMessage extends { type: string }>(\n\tmsg: unknown,\n\tallowed: readonly TMessage[\"type\"][],\n\tdirection: string,\n): IpcDecodeResult<TMessage> {\n\tconst validated = validateEnvelope(msg);\n\tif (!validated.ok) {\n\t\treturn { ok: false, error: validated.error };\n\t}\n\tif (!hasMessageType(allowed, validated.envelope.type)) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `unexpected ${direction} message type: ${validated.envelope.type}`,\n\t\t};\n\t}\n\treturn { ok: true, message: validated.envelope as unknown as TMessage };\n}\n\n/**\n * Decode a parsed envelope coming from the server side of the IPC channel.\n * Only envelope structure + message type are runtime-validated.\n */\nexport function decodeServerToWorkerMessage(msg: unknown): IpcDecodeResult<ServerToWorkerMessage> {\n\treturn decodeKnownMessage(msg, SERVER_TO_WORKER_TYPES, \"server-to-worker\");\n}\n\n/**\n * Decode a parsed envelope coming from the worker side of the IPC channel.\n * Only envelope structure + message type are runtime-validated.\n */\nexport function decodeWorkerToServerMessage(msg: unknown): IpcDecodeResult<WorkerToServerMessage> {\n\treturn decodeKnownMessage(msg, WORKER_TO_SERVER_TYPES, \"worker-to-server\");\n}\n","import type {\n\tCurrentExecutionRef,\n\tNormalizedQuestion,\n\tPreparedTurnStart,\n\tProcessInputTarget,\n\tProcessLifecycleStatus,\n\tProcessSemanticEntryRefKey,\n\tTurnFailedPayload,\n\tTurnOutcomePayload,\n\tTurnStartRecord,\n\tWorkerBootstrapReceipt,\n} from \"@leitwerk-dev/domain\";\nimport type { ConfigSnapshot } from \"@leitwerk-dev/protocol/config-snapshot\";\nimport type { InferOutput } from \"valibot\";\nimport type { dockerRegistryCredentialSchema } from \"./docker-config.js\";\nimport { IPC_PROTOCOL_VERSION, type IpcEnvelope } from \"./ipc-codec.js\";\n\nexport interface ProcessInstanceSnapshot {\n\tid?: string;\n\tprocessId?: string;\n\tselectedTurnId?: string | null;\n\tlifecycleStatus?: ProcessLifecycleStatus;\n\tcurrentExecution?: CurrentExecutionRef;\n\tplanRevision?: number;\n\ttitle?: string | null;\n\texternalId?: string | null;\n\texternalUrl?: string | null;\n\tmetadata?: Record<string, unknown> | null;\n\tdefaultModelProfileId?: string | null;\n\tturnConfigsJson?: string | null;\n\tselectedTurnModelProfileId?: string | null;\n\tparamsJson?: string | null;\n\tstateJson?: string | null;\n\tcreatedAt?: string;\n\tupdatedAt?: string;\n}\n\nexport interface ProcessProjectSnapshot {\n\tid?: string;\n\tinstanceId?: string;\n\tkey: string;\n\trepoLocator: string;\n\trepoLocatorKind?: \"remote_url\" | \"local_path\";\n\tbaseBranch: string;\n\tworkBranch?: string | null;\n\texternalId?: string | null;\n\texternalUrl?: string | null;\n\tmetadata?: Record<string, unknown> | null;\n\tpipelineStatus?: string | null;\n\tcreatedAt?: string;\n\tupdatedAt?: string;\n}\n\nexport interface InputDelivery {\n\tinputId: string;\n\tsequence: number;\n\tsource: string;\n\tkind: string;\n\ttarget: ProcessInputTarget | null;\n\treceivedAt: string;\n\tbodyMarkdown: string;\n}\n\nexport interface WorkerRuntimeContextSnapshot {\n\tprocessSnapshot: ProcessInstanceSnapshot;\n\tprojectSnapshots: ProcessProjectSnapshot[];\n\tturnResultMarkdownBySemanticRef?: Partial<Record<ProcessSemanticEntryRefKey, string>>;\n\tturnResultMarkdownByProduct?: Record<string, string>;\n}\n\nexport interface WorkerCredentialMaterial {\n\tproviderId: string;\n\t/** Null for generated credentials that are materialized but never synchronized. */\n\trevision: number | null;\n\t/** Secret payload. This type is valid only in worker.start and credential-update frames. */\n\tvalues: Record<string, string>;\n}\n\nexport interface WorkerGitSshCredential {\n\tprojectKey: string;\n\tkind: \"git_ssh\";\n\tcredentialRef: string;\n\t/** Secret values; valid only while preparing worker.start. */\n\tprivateKey: string;\n\tknownHosts: string;\n}\n\nexport interface WorkerGitHttpsCredential {\n\tprojectKey: string;\n\tkind: \"git_https\";\n\tcredentialRef: string;\n\t/** Exact non-secret HTTPS clone URL authorized by the server. */\n\trepositoryUrl: string;\n\tusername: string;\n\t/** Secret; only delivered through authenticated worker.start. */\n\tpassword: string;\n}\n\nexport type WorkerRepositoryCredential = WorkerGitSshCredential | WorkerGitHttpsCredential;\n\n/** Secret material allowed only in authenticated worker.start, never snapshots or exports. */\nexport interface WorkerDockerRegistryCredential\n\textends InferOutput<typeof dockerRegistryCredentialSchema> {}\n\nexport interface LlmWorkerStartBootstrap {\n\tkind: \"llm\";\n\tresourceBundle: {\n\t\tdigest: string;\n\t\t/** Present for a newly assembled bundle; omitted when the worker can reuse its process volume. */\n\t\tarchiveBase64?: string;\n\t};\n\tcredential: WorkerCredentialMaterial | null;\n}\n\nexport interface AutomaticWorkerStartBootstrap {\n\tkind: \"automatic\";\n}\n\nexport type WorkerRuntimeSettingsSnapshot = ConfigSnapshot[\"workers\"];\n\nexport interface DevelopmentToolsStartConfig {\n\trunner: \"local\" | \"isolated\";\n\tmiseCommand: string;\n\tinstallTimeoutMs: number;\n\tprocessStorageRoot: string;\n}\n\nexport interface IntegrationToolDeclaration {\n\tname: string;\n\tdescription: string;\n\tparameters: Record<string, unknown>;\n}\n\ninterface WorkerStartPayloadBase extends WorkerRuntimeContextSnapshot {\n\tworkerLeaseId: string;\n\tturnStart: TurnStartRecord;\n\t/**\n\t * The immutable pre-acceptance tree plan from the lease that first accepted\n\t * this start. It is supplied only when a replacement resumes a running turn.\n\t */\n\tacceptedPreparedStart?: PreparedTurnStart | null;\n\tpendingInputs: InputDelivery[];\n\ttreePaths: {\n\t\tprimaryTreeFile: string;\n\t\tworkspaceRoot: string;\n\t\t/** Process-scoped persistent storage for immutable Pi resource bundles. */\n\t\tpiResourceBundlesDir: string;\n\t};\n\tresume: boolean;\n\tresumeLeafEntryId?: string | null;\n\t/** Durable non-secret preparation checkpoint reused by a replacement or Continue start. */\n\tllmPreparation?: { sourceTurnRecordId: string; data: unknown };\n\t/** Fresh secret material resolved for this physical worker start only. */\n\trepositoryCredentials?: WorkerRepositoryCredential[];\n\tdockerRegistryCredentials?: WorkerDockerRegistryCredential[];\n\t/** Non-secret lifecycle settings supplied to every worker bootstrap type. */\n\tworkerRuntimeSettings?: WorkerRuntimeSettingsSnapshot;\n\t/** Non-secret mise adapter settings. Ignored unless the process opts in. */\n\tdevelopmentTools?: DevelopmentToolsStartConfig;\n\t/** Non-secret declarations authorized for the selected LLM turn. */\n\tintegrationTools?: IntegrationToolDeclaration[];\n}\n\nexport type WorkerStartPayload =\n\t| (WorkerStartPayloadBase & {\n\t\t\tbootstrap: LlmWorkerStartBootstrap;\n\t\t\tconfigSnapshot: ConfigSnapshot;\n\t })\n\t| (WorkerStartPayloadBase & { bootstrap: AutomaticWorkerStartBootstrap });\n\nexport interface InputBatchPayload {\n\tinputs: InputDelivery[];\n}\n\nexport interface WorkerStopPayload {\n\treason: string;\n}\n\nexport interface WorkerAbortTurnPayload {\n\treason: string;\n}\n\nexport interface WorkerTurnStartAcceptedPayload {\n\tstartRecordId: string;\n\tturnRecordId: string;\n}\n\nexport interface WorkerTurnTerminalRecordedPayload {\n\tturnRecordId: string;\n}\n\nexport interface WorkerQuestionResponsePayload {\n\tturnRecordId: string;\n\ttoolCallId: string;\n\tanswers: string[];\n}\n\nexport interface WorkerQuestionRequestedPayload {\n\tturnRecordId: string;\n\ttoolCallId: string;\n\tquestions: NormalizedQuestion[];\n}\n\nexport interface WorkerIntegrationToolRequestPayload {\n\tturnRecordId: string;\n\ttoolCallId: string;\n\ttoolName: string;\n\targs: Record<string, unknown>;\n}\n\nexport interface WorkerIntegrationToolCancelPayload {\n\tturnRecordId: string;\n\ttoolCallId: string;\n\ttoolName: string;\n}\n\nexport interface WorkerIntegrationToolResultPayload {\n\tturnRecordId: string;\n\ttoolCallId: string;\n\tok: boolean;\n\tresult?: unknown;\n\terror?: string;\n}\n\nexport interface WorkerCredentialUpdateResultPayload {\n\tproviderId: string;\n\taccepted: boolean;\n\tcurrentRevision: number | null;\n\tsafeReason?: string;\n}\n\nexport type ServerToWorkerMessage =\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.start\";\n\t\t\tpayload: WorkerStartPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.turn_start_accepted\";\n\t\t\tpayload: WorkerTurnStartAcceptedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.turn_terminal_recorded\";\n\t\t\tpayload: WorkerTurnTerminalRecordedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.credential_update_accepted\";\n\t\t\tpayload: WorkerCredentialUpdateResultPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.question_response\";\n\t\t\tpayload: WorkerQuestionResponsePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.integration_tool_result\";\n\t\t\tpayload: WorkerIntegrationToolResultPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"input.batch\";\n\t\t\tpayload: InputBatchPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.stop\";\n\t\t\tpayload: WorkerStopPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.abort_turn\";\n\t\t\tpayload: WorkerAbortTurnPayload;\n\t });\n\nexport interface WorkerHelloPayload {\n\t/** Package/runtime version for diagnostics. */\n\tversion: string;\n\t/** Server-worker API compatibility version. Missing only on legacy/test workers. */\n\tapiVersion?: string;\n\tcapabilities: string[];\n}\n\nexport interface WorkerBootstrapProgressPayload {\n\tphase: \"worker_connected\" | \"preparing_workspace\" | \"loading_resources\" | \"preparing_turn\";\n}\n\nexport interface WorkerDiagnosticTracePayload {\n\ttext: string;\n}\n\nexport interface WorkerReadyPayload {\n\treceipt: WorkerBootstrapReceipt;\n\tdevelopmentTools?: {\n\t\tmiseVersion: string;\n\t\trepositories: Array<{ repositoryKey: string; tools: Array<{ name: string; version: string }> }>;\n\t\twarnings: string[];\n\t};\n\tresumed: boolean;\n\tprimaryTreeFile: string;\n\tworkspaceRoot: string;\n\taggregatedAgentsSources: string[];\n\tloadedSkills: string[];\n\tloadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;\n\tloadedSkillFiles: Array<{ name: string; path: string }>;\n\trootEntryId?: string | null;\n}\n\nexport interface WorkerHeartbeatPayload {\n\t/** Diagnostic worker-local runtime state; not the authoritative lease transition channel. */\n\tstate: string;\n\tlastSequenceConsumed: number;\n\tcurrentTurnId?: string;\n\tcurrentSelectedTurnId?: string | null;\n}\n\nexport interface WorkerStatePayload {\n\t/** Explicit server-visible runtime transition, e.g. idle -> busy or busy -> idle. */\n\tfrom: string;\n\tto: string;\n\treason: string;\n}\n\nexport interface WorkerInputConsumedPayload {\n\tinputId: string;\n\tsequence: number;\n\tdeliveryMode: string;\n\tcurrentPrimaryPathLeafId?: string | null;\n\trootEntryId?: string | null;\n\ttargetSemanticRef?: ProcessSemanticEntryRefKey | null;\n\ttargetProductName?: string | null;\n\ttargetEntryId?: string | null;\n}\n\nexport interface WorkerEventPayload {\n\teventType: string;\n\tselectedTurnId?: string | null;\n\t/**\n\t * Object-shaped event data emitted by trusted worker senders. Decode helpers\n\t * do not deeply validate this field at runtime; they only narrow it at the\n\t * protocol boundary after envelope + message-type validation.\n\t */\n\tdata: Record<string, unknown>;\n}\n\nexport interface WorkerTurnStartedPayload {\n\tstartRecordId: string;\n\tproposedTurnRecordId: string;\n}\n\nexport interface WorkerCredentialUpdatePayload {\n\tproviderId: string;\n\texpectedRevision: number;\n\t/** Secret payload. It must not be copied into receipts, events, or turn state. */\n\tvalues: Record<string, string>;\n}\n\nexport interface WorkerTurnOutcomePayload\n\textends Omit<TurnOutcomePayload, \"instanceId\" | \"state\"> {}\n\nexport interface WorkerTurnFailedPayload\n\textends Omit<TurnFailedPayload, \"instanceId\" | \"errorClass\"> {\n\terrorClass?: string;\n}\n\nexport interface WorkerLifecycleParkedPayload {\n\tselectedTurnId: string | null;\n\treason?: string;\n\terrorClass?: string;\n}\n\nexport interface WorkerCleanupStartedPayload {\n\treason: string;\n}\n\nexport interface WorkerCleanupCompletedPayload {\n\treleasedLocks: string[];\n\tremovedTransientPaths: string[];\n}\n\nexport interface WorkerFailedPayload {\n\tstate: string;\n\terrorCode: string;\n\tmessage: string;\n\terrorClass: string;\n\tselectedTurnId?: string | null;\n\tretryAttempt?: number;\n}\n\nexport type WorkerToServerMessage =\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.hello\";\n\t\t\tpayload: WorkerHelloPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.credential_update\";\n\t\t\tpayload: WorkerCredentialUpdatePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.bootstrap_progress\";\n\t\t\tpayload: WorkerBootstrapProgressPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.diagnostic_trace\";\n\t\t\tpayload: WorkerDiagnosticTracePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.ready\";\n\t\t\tpayload: WorkerReadyPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.heartbeat\";\n\t\t\tpayload: WorkerHeartbeatPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.state\";\n\t\t\tpayload: WorkerStatePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.input_consumed\";\n\t\t\tpayload: WorkerInputConsumedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.event\";\n\t\t\tpayload: WorkerEventPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.turn_started\";\n\t\t\tpayload: WorkerTurnStartedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.question_requested\";\n\t\t\tpayload: WorkerQuestionRequestedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.integration_tool_request\";\n\t\t\tpayload: WorkerIntegrationToolRequestPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.integration_tool_cancel\";\n\t\t\tpayload: WorkerIntegrationToolCancelPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.turn_outcome\";\n\t\t\tpayload: WorkerTurnOutcomePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.turn_failed\";\n\t\t\tpayload: WorkerTurnFailedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.lifecycle_parked\";\n\t\t\tpayload: WorkerLifecycleParkedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.cleanup_started\";\n\t\t\tpayload: WorkerCleanupStartedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.cleanup_completed\";\n\t\t\tpayload: WorkerCleanupCompletedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\ttype: \"worker.failed\";\n\t\t\tpayload: WorkerFailedPayload;\n\t });\n\nexport type AnyIpcMessage = ServerToWorkerMessage | WorkerToServerMessage;\nexport type IpcMessageType = AnyIpcMessage[\"type\"];\nexport type IpcMessageOfType<TType extends IpcMessageType> = Extract<\n\tAnyIpcMessage,\n\t{ type: TType }\n>;\n\nexport function createIpcMessage<TMessage extends AnyIpcMessage>(\n\targs: Omit<TMessage, \"protocol\" | \"sentAt\"> & { sentAt?: string },\n): TMessage {\n\treturn {\n\t\tprotocol: IPC_PROTOCOL_VERSION,\n\t\tmessageId: args.messageId,\n\t\tcorrelationId: args.correlationId,\n\t\ttype: args.type,\n\t\tinstanceId: args.instanceId,\n\t\tworkerId: args.workerId,\n\t\tsentAt: args.sentAt ?? new Date().toISOString(),\n\t\tpayload: args.payload,\n\t} as TMessage;\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\n\nconst BLOCK_SIZE = 512;\n\nexport interface PiResourceFile {\n\tpath: string;\n\tcontent: Uint8Array;\n}\n\nexport interface PiResourceBundle {\n\tdigest: string;\n\tbytes: Uint8Array;\n}\n\nexport interface ExtractedPiResourceFile {\n\tpath: string;\n\tcontent: Uint8Array;\n}\n\nfunction fail(message: string): never {\n\tthrow new Error(`Invalid Pi resource bundle: ${message}`);\n}\n\nexport function validateResourceRelativePath(value: string): string {\n\tif (!value || path.posix.isAbsolute(value) || value.includes(\"\\\\\")) {\n\t\tfail(`unsafe path '${value}'`);\n\t}\n\tconst normalized = path.posix.normalize(value);\n\tif (normalized === \".\" || normalized === \"..\" || normalized.startsWith(\"../\")) {\n\t\tfail(`unsafe path '${value}'`);\n\t}\n\treturn normalized;\n}\n\nfunction writeString(buffer: Buffer, offset: number, length: number, value: string): void {\n\tconst encoded = Buffer.from(value, \"utf8\");\n\tif (encoded.length > length) fail(`header value too long: ${value}`);\n\tencoded.copy(buffer, offset);\n}\n\nfunction writeOctal(buffer: Buffer, offset: number, length: number, value: number): void {\n\tconst encoded = value.toString(8).padStart(length - 1, \"0\");\n\tif (encoded.length > length - 1) fail(`numeric header value too large: ${value}`);\n\twriteString(buffer, offset, length - 1, encoded);\n\tbuffer[offset + length - 1] = 0;\n}\n\nfunction header(name: string, size: number): Buffer {\n\tif (Buffer.byteLength(name) > 100) fail(`path exceeds canonical ustar name limit: ${name}`);\n\tconst result = Buffer.alloc(BLOCK_SIZE);\n\twriteString(result, 0, 100, name);\n\twriteOctal(result, 100, 8, 0o644);\n\twriteOctal(result, 108, 8, 0);\n\twriteOctal(result, 116, 8, 0);\n\twriteOctal(result, 124, 12, size);\n\twriteOctal(result, 136, 12, 0);\n\tresult.fill(0x20, 148, 156);\n\tresult[156] = \"0\".charCodeAt(0);\n\twriteString(result, 257, 6, \"ustar\");\n\twriteString(result, 263, 2, \"00\");\n\tconst sum = result.reduce((total, byte) => total + byte, 0);\n\twriteString(result, 148, 8, `${sum.toString(8).padStart(6, \"0\")}\\0 `);\n\treturn result;\n}\n\nfunction padding(size: number): Buffer {\n\tconst length = (BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE;\n\treturn Buffer.alloc(length);\n}\n\nexport function sha256Digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\n/** Creates a deterministic, uncompressed ustar archive containing regular files only. */\nexport function createCanonicalPiResourceBundle(\n\tfiles: readonly PiResourceFile[],\n): PiResourceBundle {\n\tconst seen = new Set<string>();\n\tconst normalized = files.map((file) => {\n\t\tconst resourcePath = validateResourceRelativePath(file.path);\n\t\tif (seen.has(resourcePath)) fail(`duplicate path '${resourcePath}'`);\n\t\tseen.add(resourcePath);\n\t\treturn { path: resourcePath, content: Buffer.from(file.content) };\n\t});\n\tnormalized.sort((left, right) => Buffer.compare(Buffer.from(left.path), Buffer.from(right.path)));\n\tconst chunks: Buffer[] = [];\n\tfor (const file of normalized) {\n\t\tchunks.push(header(file.path, file.content.length), file.content, padding(file.content.length));\n\t}\n\tchunks.push(Buffer.alloc(BLOCK_SIZE * 2));\n\tconst bytes = Buffer.concat(chunks);\n\treturn { bytes, digest: sha256Digest(bytes) };\n}\n\nfunction readNullString(block: Uint8Array, start: number, length: number): string {\n\tconst end = block.subarray(start, start + length).indexOf(0);\n\treturn Buffer.from(block.subarray(start, end < 0 ? start + length : start + end)).toString(\n\t\t\"utf8\",\n\t);\n}\n\nfunction readOctal(block: Uint8Array, start: number, length: number): number {\n\tconst raw = readNullString(block, start, length).trim();\n\tif (!/^[0-7]*$/.test(raw)) fail(\"non-octal numeric field\");\n\treturn raw ? Number.parseInt(raw, 8) : 0;\n}\n\nfunction verifyChecksum(block: Uint8Array): void {\n\tconst expected = readOctal(block, 148, 8);\n\tlet actual = 0;\n\tfor (let index = 0; index < BLOCK_SIZE; index++) {\n\t\tactual += index >= 148 && index < 156 ? 32 : block[index];\n\t}\n\tif (actual !== expected) fail(\"header checksum mismatch\");\n}\n\nfunction allZero(block: Uint8Array): boolean {\n\treturn block.every((byte) => byte === 0);\n}\n\n/** Parses only the narrow regular-file ustar subset emitted by this module. */\nexport function verifyCanonicalPiResourceBundle(\n\tbytes: Uint8Array,\n\texpectedDigest?: string,\n): ExtractedPiResourceFile[] {\n\tif (expectedDigest && sha256Digest(bytes) !== expectedDigest) fail(\"content digest mismatch\");\n\tif (bytes.length < BLOCK_SIZE * 2 || bytes.length % BLOCK_SIZE !== 0) {\n\t\tfail(\"invalid archive length\");\n\t}\n\tconst files: ExtractedPiResourceFile[] = [];\n\tconst paths = new Set<string>();\n\tlet offset = 0;\n\twhile (offset < bytes.length) {\n\t\tconst block = bytes.subarray(offset, offset + BLOCK_SIZE);\n\t\tif (allZero(block)) {\n\t\t\tif (!allZero(bytes.subarray(offset + BLOCK_SIZE, offset + BLOCK_SIZE * 2))) {\n\t\t\t\tfail(\"missing end blocks\");\n\t\t\t}\n\t\t\tif (offset + BLOCK_SIZE * 2 !== bytes.length) fail(\"data after end blocks\");\n\t\t\treturn files;\n\t\t}\n\t\tverifyChecksum(block);\n\t\tif (readNullString(block, 257, 6) !== \"ustar\") fail(\"unsupported tar format\");\n\t\tconst type = readNullString(block, 156, 1);\n\t\tif (type !== \"\" && type !== \"0\") fail(`unsupported entry type '${type}'`);\n\t\tif (readNullString(block, 157, 100) || readNullString(block, 345, 155)) {\n\t\t\tfail(\"links and ustar path prefixes are unsupported\");\n\t\t}\n\t\tconst name = validateResourceRelativePath(readNullString(block, 0, 100));\n\t\tif (paths.has(name)) fail(`duplicate path '${name}'`);\n\t\tpaths.add(name);\n\t\tconst size = readOctal(block, 124, 12);\n\t\tconst contentStart = offset + BLOCK_SIZE;\n\t\tconst contentEnd = contentStart + size;\n\t\tif (contentEnd > bytes.length) fail(\"truncated file content\");\n\t\tfiles.push({ path: name, content: bytes.slice(contentStart, contentEnd) });\n\t\toffset = contentEnd + ((BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE);\n\t}\n\tfail(\"missing end blocks\");\n}\n","import * as v from \"valibot\";\nimport { validateResourceRelativePath } from \"./pi-resource-bundle.js\";\n\nexport const PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION = 1;\n\nconst nonBlankStringSchema = v.pipe(\n\tv.string(),\n\tv.check((value) => value.trim() !== \"\", \"Expected a non-empty string\"),\n);\nconst jsonObjectSchema = v.record(v.string(), v.unknown());\nconst positiveSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1));\nconst nonNegativeSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(0));\n\nexport const piResourceManifestSchema = v.strictObject({\n\tschemaVersion: v.literal(PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION),\n\tmodel: v.strictObject({\n\t\tprofileId: nonBlankStringSchema,\n\t\tproviderId: nonBlankStringSchema,\n\t\tmodelId: nonBlankStringSchema,\n\t\tthinkingLevel: nonBlankStringSchema,\n\t}),\n\tproviderOptions: v.record(v.string(), nonBlankStringSchema),\n\tproviderWorkerConfig: v.nullable(\n\t\tv.strictObject({\n\t\t\tversion: positiveSafeIntegerSchema,\n\t\t\tvalue: jsonObjectSchema,\n\t\t}),\n\t),\n\tdeclaredCredentialPaths: v.array(nonBlankStringSchema),\n\tcompatibility: v.strictObject({\n\t\tworkerApiVersion: nonBlankStringSchema,\n\t\tpiVersion: nonBlankStringSchema,\n\t\tprotocolVersion: v.optional(nonBlankStringSchema),\n\t}),\n\tprovenance: v.array(\n\t\tv.strictObject({\n\t\t\tkind: v.picklist([\"extension\", \"skill\", \"prompt\", \"generated\"]),\n\t\t\townerExtensionId: v.nullable(nonBlankStringSchema),\n\t\t\tpackageName: v.nullable(nonBlankStringSchema),\n\t\t\tsnapshotPath: nonBlankStringSchema,\n\t\t\tsha256: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/)),\n\t\t\tsize: nonNegativeSafeIntegerSchema,\n\t\t}),\n\t),\n});\n\ntype DeepReadonly<T> = T extends readonly unknown[]\n\t? { readonly [Index in keyof T]: DeepReadonly<T[Index]> }\n\t: T extends object\n\t\t? { readonly [Key in keyof T]: DeepReadonly<T[Key]> }\n\t\t: T;\n\nexport type PiResourceManifest = DeepReadonly<v.InferOutput<typeof piResourceManifestSchema>>;\nexport type PiResourceSnapshotModel = PiResourceManifest[\"model\"];\nexport type PiResourceSnapshotWorkerConfig = NonNullable<\n\tPiResourceManifest[\"providerWorkerConfig\"]\n>;\nexport type PiResourceSnapshotCompatibility = PiResourceManifest[\"compatibility\"];\nexport type PiResourceFileProvenance = PiResourceManifest[\"provenance\"][number];\nexport type PiResourceProvenanceKind = PiResourceFileProvenance[\"kind\"];\n\nfunction invalidManifest(message: string, cause?: unknown): never {\n\tthrow new Error(`Invalid managed Pi resource snapshot: ${message}`, { cause });\n}\n\n/** Parses and validates the complete generated.json contract. */\nexport function parsePiResourceManifest(raw: unknown): PiResourceManifest {\n\tlet manifest: PiResourceManifest;\n\ttry {\n\t\tmanifest = v.parse(piResourceManifestSchema, raw);\n\t} catch (error) {\n\t\tinvalidManifest(\"generated.json does not match the resource manifest schema\", error);\n\t}\n\n\tlet declaredCredentialPaths: string[];\n\tlet provenance: PiResourceFileProvenance[];\n\ttry {\n\t\tdeclaredCredentialPaths = manifest.declaredCredentialPaths.map(validateResourceRelativePath);\n\t\tprovenance = manifest.provenance.map((item) => ({\n\t\t\t...item,\n\t\t\tsnapshotPath: validateResourceRelativePath(item.snapshotPath),\n\t\t}));\n\t} catch (error) {\n\t\tinvalidManifest(\"generated.json contains an unsafe path\", error);\n\t}\n\tif (new Set(declaredCredentialPaths).size !== declaredCredentialPaths.length) {\n\t\tinvalidManifest(\"generated.json declares a credential path more than once\");\n\t}\n\tconst provenancePaths = provenance.map((item) => item.snapshotPath);\n\tif (new Set(provenancePaths).size !== provenancePaths.length) {\n\t\tinvalidManifest(\"generated.json contains duplicate provenance paths\");\n\t}\n\tfor (const credentialPath of declaredCredentialPaths) {\n\t\tif (credentialPath === \"generated.json\" || provenancePaths.includes(credentialPath)) {\n\t\t\tinvalidManifest(`credential path '${credentialPath}' overlaps immutable snapshot content`);\n\t\t}\n\t}\n\treturn { ...manifest, declaredCredentialPaths, provenance };\n}\n\ntype JsonRecord = Record<string, unknown>;\n\nexport function canonicalizeJson(value: unknown, location = \"value\"): unknown {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new Error(`${location} contains a non-finite number`);\n\t\treturn Object.is(value, -0) ? 0 : value;\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item, index) => canonicalizeJson(item, `${location}[${index}]`));\n\t}\n\tif (typeof value !== \"object\") throw new Error(`${location} contains a non-JSON value`);\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new Error(`${location} contains a non-plain object`);\n\t}\n\treturn Object.fromEntries(\n\t\tObject.keys(value as JsonRecord)\n\t\t\t.sort((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right)))\n\t\t\t.map((key) => [key, canonicalizeJson((value as JsonRecord)[key], `${location}.${key}`)]),\n\t);\n}\n\nexport function canonicalJsonStringify(value: unknown, location = \"value\"): string {\n\treturn JSON.stringify(canonicalizeJson(value, location));\n}\n\nexport function canonicalJsonEqual(left: unknown, right: unknown): boolean {\n\treturn canonicalJsonStringify(left) === canonicalJsonStringify(right);\n}\n","import type { ConfigSnapshot } from \"@leitwerk-dev/protocol/config-snapshot\";\nimport { IPC_PROTOCOL_VERSION } from \"./ipc-codec.js\";\n\nexport async function flushAsyncWork(iterations = 30): Promise<void> {\n\tfor (let i = 0; i < iterations; i++) {\n\t\tawait new Promise<void>((resolve) => setImmediate(resolve));\n\t}\n}\n\nexport function createTestIpcEnvelopeBase(instanceId: string, workerId: string, messageId: string) {\n\treturn {\n\t\tprotocol: IPC_PROTOCOL_VERSION as typeof IPC_PROTOCOL_VERSION,\n\t\tmessageId,\n\t\tinstanceId,\n\t\tworkerId,\n\t\tsentAt: new Date().toISOString(),\n\t};\n}\n\nexport function createTestConfigSnapshot(): ConfigSnapshot {\n\treturn {\n\t\tworkers: {\n\t\t\theartbeat_interval: \"5s\",\n\t\t\tturn_max_duration: \"30m\",\n\t\t\tturn_inactivity_timeout: \"5m\",\n\t\t\tturn_abort_grace_period: \"5s\",\n\t\t},\n\t\tpi: {\n\t\t\tagent_dir: \"~/.pi/leitwerk\",\n\t\t\tmodel_profiles: [],\n\t\t\tprocess_title_generation: {\n\t\t\t\tmodel_profile: null,\n\t\t\t\tretry: {\n\t\t\t\t\tmax_attempts: 6,\n\t\t\t\t\tbase_delay: \"5s\",\n\t\t\t\t\tmax_delay: \"5m\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tretry: {\n\t\t\t\tenabled: true,\n\t\t\t\tmax_retries: 3,\n\t\t\t\tbase_delay: \"2s\",\n\t\t\t\tprovider: {\n\t\t\t\t\ttimeout: null,\n\t\t\t\t\tmax_retries: null,\n\t\t\t\t\tmax_retry_delay: \"60s\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n","/**\n * Compatibility version for the server ↔ worker runtime API.\n *\n * Container image labels use the same value (`leitwerk.dev/worker-api-version`).\n * Workers also report it in `worker.hello` so the server can fail fast when a\n * pod image is from an incompatible leitwerk build line.\n */\nexport const WORKER_API_VERSION = \"2026-09-16\";\n","export const WORKER_INSTANCE_ID_ENV = \"LEITWERK_INSTANCE_ID\";\nexport const WORKER_ID_ENV = \"LEITWERK_WORKER_ID\";\nexport const WORKER_IPC_SERVER_URL_ENV = \"LEITWERK_SERVER_URL\";\nexport const WORKER_IPC_CONNECT_TOKEN_ENV = \"LEITWERK_WORKER_CONNECT_TOKEN\";\nexport const WORKER_IPC_RECONNECT_ENV = \"LEITWERK_WORKER_RECONNECT\";\nexport const WORKER_SNAPSHOT_TOKEN_ENV = \"LEITWERK_WORKER_SNAPSHOT_TOKEN\";\nexport const WORKER_SERVER_EPOCH_ENV = \"LEITWERK_SERVER_EPOCH\";\n","export const WORKER_SESSION_SNAPSHOT_CONTENT_TYPE = \"application/x-ndjson\";\nexport const WORKER_SESSION_SNAPSHOT_WORKER_ID_HEADER = \"x-leitwerk-worker-id\";\nexport const WORKER_SESSION_SNAPSHOT_REASON_HEADER = \"x-leitwerk-session-snapshot-reason\";\nexport const WORKER_SESSION_SNAPSHOT_TURN_RECORD_ID_HEADER = \"x-leitwerk-turn-record-id\";\nexport function buildWorkerSessionSnapshotPath(instanceId: string): string {\n\treturn `/internal/workers/${encodeURIComponent(instanceId)}/session-snapshot`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,YAAY,OAAO;AAEZ,IAAM,iCAAmC,SAAO;AAAA,EACtD,UAAY,OAAO,SAAO,GAAK,QAAM,+CA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IAAI,YAAY,KAAK;AACpC,UAAM,IAAI,QAAc,CAAC,YAAY,aAAa,OAAO,CAAC;AAAA,EAC3D;AACD;AAEO,SAAS,0BAA0B,YAAoB,UAAkB,WAAmB;AAClG,SAAO;AAAA,IACN,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAQ,oBAAI,KAAK,GAAE,YAAY;AAAA,EAChC;AACD;AAEO,SAAS,2BAA2C;AAC1D,SAAO;AAAA,IACN,SAAS;AAAA,MACR,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,MACnB,yBAAyB;AAAA,MACzB,yBAAyB;AAAA,IAC1B;AAAA,IACA,IAAI;AAAA,MACH,WAAW;AAAA,MACX,gBAAgB,CAAC;AAAA,MACjB,0BAA0B;AAAA,QACzB,eAAe;AAAA,QACf,OAAO;AAAA,UACN,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,QACb,YAAY;AAAA,QACZ,UAAU;AAAA,UACT,SAAS;AAAA,UACT,aAAa;AAAA,UACb,iBAAiB;AAAA,QAClB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;;;AC3CO,IAAM,qBAAqB;;;ACP3B,IAAM,yBAAyB;AAC/B,IAAM,gBAAgB;AACtB,IAAM,4BAA4B;AAClC,IAAM,+BAA+B;AACrC,IAAM,2BAA2B;AACjC,IAAM,4BAA4B;AAClC,IAAM,0BAA0B;;;ACNhC,IAAM,uCAAuC;AAC7C,IAAM,2CAA2C;AACjD,IAAM,wCAAwC;AAC9C,IAAM,gDAAgD;AACtD,SAAS,+BAA+B,YAA4B;AAC1E,SAAO,qBAAqB,mBAAmB,UAAU,CAAC;AAC3D;","names":["v","v"]}
|
|
1
|
+
{"version":3,"sources":["../src/docker-config.ts","../src/ipc-codec.ts","../src/ipc-decode.ts","../src/ipc-messages.ts","../src/pi-resource-bundle.ts","../src/pi-resource-manifest.ts","../src/testing.ts","../src/worker-api-version.ts","../src/worker-ipc-transport.ts","../src/worker-session-snapshot.ts"],"sourcesContent":["import { isIP } from \"node:net\";\nimport * as v from \"valibot\";\n\n/** @internal */\nexport const dockerRegistryCredentialSchema = v.object({\n\t/** @internal */\n\tregistry: v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?::[0-9]{1,5})?$/)),\n\t/** @internal */\n\tusername: v.pipe(v.string(), v.nonEmpty(), v.regex(/^[^:\\r\\n\\0]+$/)),\n\t/** @internal */\n\tpassword: v.pipe(v.string(), v.nonEmpty()),\n});\n\n/** @internal */\nexport const ipAddressSchema = v.pipe(\n\tv.string(),\n\tv.nonEmpty(),\n\tv.check((value) => isIP(value) !== 0, \"Expected an IPv4 or IPv6 address\"),\n);\nconst ipv4CidrSchema = v.pipe(\n\tv.string(),\n\tv.check(\n\t\t(value) => /^.+\\/(?:[1-9]|[12][0-9]|30)$/.test(value) && isIP(value.split(\"/\")[0] ?? \"\") === 4,\n\t),\n);\n/** @internal */\nexport type DockerNetworkConfig = v.InferOutput<typeof dockerNetworkSchema>;\n\n/** @internal */\nexport const dockerNetworkSchema = v.strictObject({\n\t/** @internal */\n\tbridge_cidr: ipv4CidrSchema,\n\t/** @internal */\n\taddress_pools: v.pipe(\n\t\tv.array(\n\t\t\tv.pipe(\n\t\t\t\tv.strictObject({\n\t\t\t\t\t/** @internal */\n\t\t\t\t\tbase: ipv4CidrSchema,\n\t\t\t\t\t/** @internal */\n\t\t\t\t\tsize: v.pipe(v.number(), v.integer(), v.maxValue(30)),\n\t\t\t\t}),\n\t\t\t\tv.check((pool) => pool.size >= Number(pool.base.split(\"/\")[1])),\n\t\t\t),\n\t\t),\n\t\tv.nonEmpty(),\n\t),\n\t/** @internal */\n\tdns: v.pipe(v.array(ipAddressSchema), v.nonEmpty()),\n});\n","import { parseSchema } from \"@leitwerk-dev/protocol\";\nimport * as v from \"valibot\";\n\n/** @internal */\nexport const IPC_PROTOCOL_VERSION = \"leitwerk/worker-ipc/v1\" as const;\n\n/** @internal */\nexport const IPC_ENVELOPE_SCHEMA = v.object({\n\t/** @internal */\n\tprotocol: v.literal(IPC_PROTOCOL_VERSION),\n\t/** @internal */\n\tmessageId: v.string(),\n\t/** @internal */\n\tcorrelationId: v.optional(v.string()),\n\t/** @internal */\n\ttype: v.string(),\n\t/** @internal */\n\tinstanceId: v.string(),\n\t/** @internal */\n\tworkerId: v.string(),\n\t/** @internal */\n\tsentAt: v.string(),\n\t/** @internal */\n\tpayload: v.unknown(),\n});\n\n/** @internal */\nexport type IpcEnvelope = v.InferOutput<typeof IPC_ENVELOPE_SCHEMA>;\n\n/** @internal */\nexport function validateEnvelope(msg: unknown):\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: true;\n\t\t\t/** @internal */\n\t\t\tenvelope: IpcEnvelope;\n\t }\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: false;\n\t\t\t/** @internal */\n\t\t\terror: string;\n\t } {\n\tif (\n\t\ttypeof msg === \"object\" &&\n\t\tmsg !== null &&\n\t\t\"protocol\" in msg &&\n\t\ttypeof msg.protocol === \"string\" &&\n\t\tmsg.protocol !== IPC_PROTOCOL_VERSION\n\t) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `Worker IPC protocol '${msg.protocol}' is incompatible with expected protocol '${IPC_PROTOCOL_VERSION}'`,\n\t\t};\n\t}\n\tconst envelope = parseSchema(IPC_ENVELOPE_SCHEMA, msg, \"ipc envelope\");\n\treturn envelope.ok\n\t\t? { ok: true, envelope: envelope.value }\n\t\t: { ok: false, error: envelope.error };\n}\n\n/** @internal */\nexport function serializeMessage<TEnvelope extends IpcEnvelope>(envelope: TEnvelope): string {\n\treturn JSON.stringify(envelope);\n}\n\n/** @internal */\nexport function deserializeMessage(line: string):\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: true;\n\t\t\t/** @internal */\n\t\t\tmessage: IpcEnvelope;\n\t }\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: false;\n\t\t\t/** @internal */\n\t\t\terror: string;\n\t } {\n\tconst trimmed =\n\t\tline.length > 0 && line.charCodeAt(line.length - 1) === 0x0d ? line.slice(0, -1) : line;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(trimmed) as unknown;\n\t} catch {\n\t\treturn { ok: false, error: \"invalid JSON\" };\n\t}\n\tconst validated = validateEnvelope(parsed);\n\tif (!validated.ok) {\n\t\treturn { ok: false, error: validated.error };\n\t}\n\treturn { ok: true, message: validated.envelope };\n}\n","import { validateEnvelope } from \"./ipc-codec.js\";\nimport type { ServerToWorkerMessage, WorkerToServerMessage } from \"./ipc-messages.js\";\n\n/** @internal */\nexport type IpcDecodeResult<TMessage> =\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: true;\n\t\t\t/** @internal */\n\t\t\tmessage: TMessage;\n\t }\n\t| {\n\t\t\t/** @internal */\n\t\t\tok: false;\n\t\t\t/** @internal */\n\t\t\terror: string;\n\t };\n\nconst SERVER_TO_WORKER_TYPES = [\n\t\"worker.start\",\n\t\"worker.turn_start_accepted\",\n\t\"worker.turn_terminal_recorded\",\n\t\"worker.credential_update_accepted\",\n\t\"worker.question_response\",\n\t\"worker.integration_tool_result\",\n\t\"input.batch\",\n\t\"worker.stop\",\n\t\"worker.abort_turn\",\n] as const satisfies readonly ServerToWorkerMessage[\"type\"][];\n\nconst WORKER_TO_SERVER_TYPES = [\n\t\"worker.hello\",\n\t\"worker.credential_update\",\n\t\"worker.bootstrap_progress\",\n\t\"worker.diagnostic_trace\",\n\t\"worker.ready\",\n\t\"worker.heartbeat\",\n\t\"worker.state\",\n\t\"worker.input_consumed\",\n\t\"worker.event\",\n\t\"worker.turn_started\",\n\t\"worker.question_requested\",\n\t\"worker.integration_tool_request\",\n\t\"worker.integration_tool_cancel\",\n\t\"worker.turn_outcome\",\n\t\"worker.turn_failed\",\n\t\"worker.lifecycle_parked\",\n\t\"worker.cleanup_started\",\n\t\"worker.cleanup_completed\",\n\t\"worker.failed\",\n] as const satisfies readonly WorkerToServerMessage[\"type\"][];\n\nfunction hasMessageType<TType extends string>(\n\tallowed: readonly TType[],\n\tvalue: string,\n): value is TType {\n\treturn (allowed as readonly string[]).includes(value);\n}\n\n/**\n * Validate the generic IPC envelope and narrow it to the correct typed message\n * union member for the given direction.\n *\n * This intentionally stops at the message discriminant boundary: it validates\n * envelope structure + known message type, but does not deeply validate the\n * payload shape. Payload fields are trusted to come from same-version\n * leitwerk components, so malformed payloads from a buggy sender can still\n * pass through as typed data.\n */\nfunction decodeKnownMessage<TMessage extends { type: string }>(\n\tmsg: unknown,\n\tallowed: readonly TMessage[\"type\"][],\n\tdirection: string,\n): IpcDecodeResult<TMessage> {\n\tconst validated = validateEnvelope(msg);\n\tif (!validated.ok) {\n\t\treturn { ok: false, error: validated.error };\n\t}\n\tif (!hasMessageType(allowed, validated.envelope.type)) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `unexpected ${direction} message type: ${validated.envelope.type}`,\n\t\t};\n\t}\n\treturn { ok: true, message: validated.envelope as unknown as TMessage };\n}\n\n/**\n * Decode a parsed envelope coming from the server side of the IPC channel.\n * Only envelope structure + message type are runtime-validated.\n */\n/** @internal */\nexport function decodeServerToWorkerMessage(msg: unknown): IpcDecodeResult<ServerToWorkerMessage> {\n\treturn decodeKnownMessage(msg, SERVER_TO_WORKER_TYPES, \"server-to-worker\");\n}\n\n/**\n * Decode a parsed envelope coming from the worker side of the IPC channel.\n * Only envelope structure + message type are runtime-validated.\n */\n/** @internal */\nexport function decodeWorkerToServerMessage(msg: unknown): IpcDecodeResult<WorkerToServerMessage> {\n\treturn decodeKnownMessage(msg, WORKER_TO_SERVER_TYPES, \"worker-to-server\");\n}\n","import type {\n\tCurrentExecutionRef,\n\tNormalizedQuestion,\n\tPreparedTurnStart,\n\tProcessInputTarget,\n\tProcessLifecycleStatus,\n\tProcessSemanticEntryRefKey,\n\tTurnFailedPayload,\n\tTurnOutcomePayload,\n\tTurnStartRecord,\n\tWorkerBootstrapReceipt,\n} from \"@leitwerk-dev/domain\";\nimport type { ConfigSnapshot } from \"@leitwerk-dev/protocol/config-snapshot\";\nimport type { InferOutput } from \"valibot\";\nimport type { dockerRegistryCredentialSchema } from \"./docker-config.js\";\nimport { IPC_PROTOCOL_VERSION, type IpcEnvelope } from \"./ipc-codec.js\";\n\n/** @internal */\nexport interface ProcessInstanceSnapshot {\n\t/** @internal */\n\tid?: string;\n\t/** @internal */\n\tprocessId?: string;\n\t/** @internal */\n\tselectedTurnId?: string | null;\n\t/** @internal */\n\tlifecycleStatus?: ProcessLifecycleStatus;\n\t/** @internal */\n\tcurrentExecution?: CurrentExecutionRef;\n\t/** @internal */\n\tplanRevision?: number;\n\t/** @internal */\n\ttitle?: string | null;\n\t/** @internal */\n\texternalId?: string | null;\n\t/** @internal */\n\texternalUrl?: string | null;\n\t/** @internal */\n\tmetadata?: Record<string, unknown> | null;\n\t/** @internal */\n\tdefaultModelProfileId?: string | null;\n\t/** @internal */\n\tturnConfigsJson?: string | null;\n\t/** @internal */\n\tselectedTurnModelProfileId?: string | null;\n\t/** @internal */\n\tparamsJson?: string | null;\n\t/** @internal */\n\tstateJson?: string | null;\n\t/** @internal */\n\tcreatedAt?: string;\n\t/** @internal */\n\tupdatedAt?: string;\n}\n\n/** @internal */\nexport interface ProcessProjectSnapshot {\n\t/** @internal */\n\tid?: string;\n\t/** @internal */\n\tinstanceId?: string;\n\t/** @internal */\n\tkey: string;\n\t/** @internal */\n\trepoLocator: string;\n\t/** @internal */\n\trepoLocatorKind?: \"remote_url\" | \"local_path\";\n\t/** @internal */\n\tbaseBranch: string;\n\t/** @internal */\n\tworkBranch?: string | null;\n\t/** @internal */\n\texternalId?: string | null;\n\t/** @internal */\n\texternalUrl?: string | null;\n\t/** @internal */\n\tmetadata?: Record<string, unknown> | null;\n\t/** @internal */\n\tpipelineStatus?: string | null;\n\t/** @internal */\n\tcreatedAt?: string;\n\t/** @internal */\n\tupdatedAt?: string;\n}\n\n/** @internal */\nexport interface InputDelivery {\n\t/** @internal */\n\tinputId: string;\n\t/** @internal */\n\tsequence: number;\n\t/** @internal */\n\tsource: string;\n\t/** @internal */\n\tkind: string;\n\t/** @internal */\n\ttarget: ProcessInputTarget | null;\n\t/** @internal */\n\treceivedAt: string;\n\t/** @internal */\n\tbodyMarkdown: string;\n}\n\n/** @internal */\nexport interface WorkerRuntimeContextSnapshot {\n\t/** @internal */\n\tprocessSnapshot: ProcessInstanceSnapshot;\n\t/** @internal */\n\tprojectSnapshots: ProcessProjectSnapshot[];\n\t/** @internal */\n\tturnResultMarkdownBySemanticRef?: Partial<Record<ProcessSemanticEntryRefKey, string>>;\n\t/** @internal */\n\tturnResultMarkdownByProduct?: Record<string, string>;\n}\n\n/** @internal */\nexport interface WorkerCredentialMaterial {\n\t/** @internal */\n\tproviderId: string;\n\t/** Null for generated credentials that are materialized but never synchronized. @internal */\n\trevision: number | null;\n\t/** Secret payload. This type is valid only in worker.start and credential-update frames. @internal */\n\tvalues: Record<string, string>;\n}\n\n/** @internal */\nexport interface WorkerGitSshCredential {\n\t/** @internal */\n\tprojectKey: string;\n\t/** @internal */\n\tkind: \"git_ssh\";\n\t/** @internal */\n\tcredentialRef: string;\n\t/** Secret values; valid only while preparing worker.start. @internal */\n\tprivateKey: string;\n\t/** @internal */\n\tknownHosts: string;\n}\n\n/** @internal */\nexport interface WorkerGitHttpsCredential {\n\t/** @internal */\n\tprojectKey: string;\n\t/** @internal */\n\tkind: \"git_https\";\n\t/** @internal */\n\tcredentialRef: string;\n\t/** Exact non-secret HTTPS clone URL authorized by the server. @internal */\n\trepositoryUrl: string;\n\t/** @internal */\n\tusername: string;\n\t/** Secret; only delivered through authenticated worker.start. @internal */\n\tpassword: string;\n}\n\n/** @internal */\nexport type WorkerRepositoryCredential = WorkerGitSshCredential | WorkerGitHttpsCredential;\n\n/** Secret material allowed only in authenticated worker.start, never snapshots or exports. @internal */\nexport interface WorkerDockerRegistryCredential\n\textends InferOutput<typeof dockerRegistryCredentialSchema> {}\n\n/** @internal */\nexport interface LlmWorkerStartBootstrap {\n\t/** @internal */\n\tkind: \"llm\";\n\t/** @internal */\n\tresourceBundle: {\n\t\t/** @internal */\n\t\tdigest: string;\n\t\t/** Present for a newly assembled bundle; omitted when the worker can reuse its process volume. @internal */\n\t\tarchiveBase64?: string;\n\t};\n\t/** @internal */\n\tcredential: WorkerCredentialMaterial | null;\n}\n\n/** @internal */\nexport interface AutomaticWorkerStartBootstrap {\n\t/** @internal */\n\tkind: \"automatic\";\n}\n\n/** @internal */\nexport type WorkerRuntimeSettingsSnapshot = ConfigSnapshot[\"workers\"];\n\n/** @internal */\nexport interface DevelopmentToolsStartConfig {\n\t/** @internal */\n\trunner: \"local\" | \"isolated\";\n\t/** @internal */\n\tmiseCommand: string;\n\t/** @internal */\n\tinstallTimeoutMs: number;\n\t/** @internal */\n\tprocessStorageRoot: string;\n}\n\n/** @internal */\nexport interface IntegrationToolDeclaration {\n\t/** @internal */\n\tname: string;\n\t/** @internal */\n\tdescription: string;\n\t/** @internal */\n\tparameters: Record<string, unknown>;\n}\n\n/** @internal */\ninterface WorkerStartPayloadBase extends WorkerRuntimeContextSnapshot {\n\t/** @internal */\n\tworkerLeaseId: string;\n\t/** @internal */\n\tturnStart: TurnStartRecord;\n\t/**\n\t * The immutable pre-acceptance tree plan from the lease that first accepted\n\t * this start. It is supplied only when a replacement resumes a running turn.\n\t */\n\t/** @internal */\n\tacceptedPreparedStart?: PreparedTurnStart | null;\n\t/** @internal */\n\tpendingInputs: InputDelivery[];\n\t/** @internal */\n\ttreePaths: {\n\t\t/** @internal */\n\t\tprimaryTreeFile: string;\n\t\t/** @internal */\n\t\tworkspaceRoot: string;\n\t\t/** Process-scoped persistent storage for immutable Pi resource bundles. @internal */\n\t\tpiResourceBundlesDir: string;\n\t};\n\t/** @internal */\n\tresume: boolean;\n\t/** @internal */\n\tresumeLeafEntryId?: string | null;\n\t/** Durable non-secret preparation checkpoint reused by a replacement or Continue start. @internal */\n\tllmPreparation?: {\n\t\t/** @internal */\n\t\tsourceTurnRecordId: string;\n\t\t/** @internal */\n\t\tdata: unknown;\n\t};\n\t/** Fresh secret material resolved for this physical worker start only. @internal */\n\trepositoryCredentials?: WorkerRepositoryCredential[];\n\t/** @internal */\n\tdockerRegistryCredentials?: WorkerDockerRegistryCredential[];\n\t/** Non-secret lifecycle settings supplied to every worker bootstrap type. @internal */\n\tworkerRuntimeSettings?: WorkerRuntimeSettingsSnapshot;\n\t/** Non-secret mise adapter settings. Ignored unless the process opts in. @internal */\n\tdevelopmentTools?: DevelopmentToolsStartConfig;\n\t/** Non-secret declarations authorized for the selected LLM turn. @internal */\n\tintegrationTools?: IntegrationToolDeclaration[];\n}\n\n/** @internal */\nexport type WorkerStartPayload =\n\t| (WorkerStartPayloadBase & {\n\t\t\t/** @internal */\n\t\t\tbootstrap: LlmWorkerStartBootstrap;\n\t\t\t/** @internal */\n\t\t\tconfigSnapshot: ConfigSnapshot;\n\t })\n\t| (WorkerStartPayloadBase & {\n\t\t\t/** @internal */\n\t\t\tbootstrap: AutomaticWorkerStartBootstrap;\n\t });\n\n/** @internal */\nexport interface InputBatchPayload {\n\t/** @internal */\n\tinputs: InputDelivery[];\n}\n\n/** @internal */\nexport interface WorkerStopPayload {\n\t/** @internal */\n\treason: string;\n}\n\n/** @internal */\nexport interface WorkerAbortTurnPayload {\n\t/** @internal */\n\treason: string;\n}\n\n/** @internal */\nexport interface WorkerTurnStartAcceptedPayload {\n\t/** @internal */\n\tstartRecordId: string;\n\t/** @internal */\n\tturnRecordId: string;\n}\n\n/** @internal */\nexport interface WorkerTurnTerminalRecordedPayload {\n\t/** @internal */\n\tturnRecordId: string;\n}\n\n/** @internal */\nexport interface WorkerQuestionResponsePayload {\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\ttoolCallId: string;\n\t/** @internal */\n\tanswers: string[];\n}\n\n/** @internal */\nexport interface WorkerQuestionRequestedPayload {\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\ttoolCallId: string;\n\t/** @internal */\n\tquestions: NormalizedQuestion[];\n}\n\n/** @internal */\nexport interface WorkerIntegrationToolRequestPayload {\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\ttoolCallId: string;\n\t/** @internal */\n\ttoolName: string;\n\t/** @internal */\n\targs: Record<string, unknown>;\n}\n\n/** @internal */\nexport interface WorkerIntegrationToolCancelPayload {\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\ttoolCallId: string;\n\t/** @internal */\n\ttoolName: string;\n}\n\n/** @internal */\nexport interface WorkerIntegrationToolResultPayload {\n\t/** @internal */\n\tturnRecordId: string;\n\t/** @internal */\n\ttoolCallId: string;\n\t/** @internal */\n\tok: boolean;\n\t/** @internal */\n\tresult?: unknown;\n\t/** @internal */\n\terror?: string;\n}\n\n/** @internal */\nexport interface WorkerCredentialUpdateResultPayload {\n\t/** @internal */\n\tproviderId: string;\n\t/** @internal */\n\taccepted: boolean;\n\t/** @internal */\n\tcurrentRevision: number | null;\n\t/** @internal */\n\tsafeReason?: string;\n}\n\n/** @internal */\nexport type ServerToWorkerMessage =\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.start\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerStartPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.turn_start_accepted\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerTurnStartAcceptedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.turn_terminal_recorded\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerTurnTerminalRecordedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.credential_update_accepted\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerCredentialUpdateResultPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.question_response\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerQuestionResponsePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.integration_tool_result\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerIntegrationToolResultPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"input.batch\";\n\t\t\t/** @internal */\n\t\t\tpayload: InputBatchPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.stop\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerStopPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.abort_turn\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerAbortTurnPayload;\n\t });\n\n/** @internal */\nexport interface WorkerHelloPayload {\n\t/** Package/runtime version for diagnostics. @internal */\n\tversion: string;\n\t/** Server-worker API compatibility version. Missing only on legacy/test workers. @internal */\n\tapiVersion?: string;\n\t/** @internal */\n\tcapabilities: string[];\n}\n\n/** @internal */\nexport interface WorkerBootstrapProgressPayload {\n\t/** @internal */\n\tphase: \"worker_connected\" | \"preparing_workspace\" | \"loading_resources\" | \"preparing_turn\";\n}\n\n/** @internal */\nexport interface WorkerDiagnosticTracePayload {\n\t/** @internal */\n\ttext: string;\n}\n\n/** @internal */\nexport interface WorkerReadyPayload {\n\t/** @internal */\n\treceipt: WorkerBootstrapReceipt;\n\t/** @internal */\n\tdevelopmentTools?: {\n\t\t/** @internal */\n\t\tmiseVersion: string;\n\t\t/** @internal */\n\t\trepositories: Array<{\n\t\t\t/** @internal */\n\t\t\trepositoryKey: string;\n\t\t\t/** @internal */\n\t\t\ttools: Array<{\n\t\t\t\t/** @internal */\n\t\t\t\tname: string;\n\t\t\t\t/** @internal */\n\t\t\t\tversion: string;\n\t\t\t}>;\n\t\t}>;\n\t\t/** @internal */\n\t\twarnings: string[];\n\t};\n\t/** @internal */\n\tresumed: boolean;\n\t/** @internal */\n\tprimaryTreeFile: string;\n\t/** @internal */\n\tworkspaceRoot: string;\n\t/** @internal */\n\taggregatedAgentsSources: string[];\n\t/** @internal */\n\tloadedSkills: string[];\n\t/** @internal */\n\tloadedAgentsFiles: Array<{\n\t\t/** @internal */\n\t\tpath: string;\n\t\t/** @internal */\n\t\tsizeBytes: number;\n\t}>;\n\t/** @internal */\n\tloadedSkillFiles: Array<{\n\t\t/** @internal */\n\t\tname: string;\n\t\t/** @internal */\n\t\tpath: string;\n\t}>;\n\t/** @internal */\n\trootEntryId?: string | null;\n}\n\n/** @internal */\nexport interface WorkerHeartbeatPayload {\n\t/** Diagnostic worker-local runtime state; not the authoritative lease transition channel. @internal */\n\tstate: string;\n\t/** @internal */\n\tlastSequenceConsumed: number;\n\t/** @internal */\n\tcurrentTurnId?: string;\n\t/** @internal */\n\tcurrentSelectedTurnId?: string | null;\n}\n\n/** @internal */\nexport interface WorkerStatePayload {\n\t/** Explicit server-visible runtime transition, e.g. idle -> busy or busy -> idle. @internal */\n\tfrom: string;\n\t/** @internal */\n\tto: string;\n\t/** @internal */\n\treason: string;\n}\n\n/** @internal */\nexport interface WorkerInputConsumedPayload {\n\t/** @internal */\n\tinputId: string;\n\t/** @internal */\n\tsequence: number;\n\t/** @internal */\n\tdeliveryMode: string;\n\t/** @internal */\n\tcurrentPrimaryPathLeafId?: string | null;\n\t/** @internal */\n\trootEntryId?: string | null;\n\t/** @internal */\n\ttargetSemanticRef?: ProcessSemanticEntryRefKey | null;\n\t/** @internal */\n\ttargetProductName?: string | null;\n\t/** @internal */\n\ttargetEntryId?: string | null;\n}\n\n/** @internal */\nexport interface WorkerEventPayload {\n\t/** @internal */\n\teventType: string;\n\t/** @internal */\n\tselectedTurnId?: string | null;\n\t/**\n\t * Object-shaped event data emitted by trusted worker senders. Decode helpers\n\t * do not deeply validate this field at runtime; they only narrow it at the\n\t * protocol boundary after envelope + message-type validation.\n\t */\n\t/** @internal */\n\tdata: Record<string, unknown>;\n}\n\n/** @internal */\nexport interface WorkerTurnStartedPayload {\n\t/** @internal */\n\tstartRecordId: string;\n\t/** @internal */\n\tproposedTurnRecordId: string;\n}\n\n/** @internal */\nexport interface WorkerCredentialUpdatePayload {\n\t/** @internal */\n\tproviderId: string;\n\t/** @internal */\n\texpectedRevision: number;\n\t/** Secret payload. It must not be copied into receipts, events, or turn state. @internal */\n\tvalues: Record<string, string>;\n}\n\n/** @internal */\nexport interface WorkerTurnOutcomePayload\n\textends Omit<TurnOutcomePayload, \"instanceId\" | \"state\"> {}\n\n/** @internal */\nexport interface WorkerTurnFailedPayload\n\textends Omit<TurnFailedPayload, \"instanceId\" | \"errorClass\"> {\n\t/** @internal */\n\terrorClass?: string;\n}\n\n/** @internal */\nexport interface WorkerLifecycleParkedPayload {\n\t/** @internal */\n\tselectedTurnId: string | null;\n\t/** @internal */\n\treason?: string;\n\t/** @internal */\n\terrorClass?: string;\n}\n\n/** @internal */\nexport interface WorkerCleanupStartedPayload {\n\t/** @internal */\n\treason: string;\n}\n\n/** @internal */\nexport interface WorkerCleanupCompletedPayload {\n\t/** @internal */\n\treleasedLocks: string[];\n\t/** @internal */\n\tremovedTransientPaths: string[];\n}\n\n/** @internal */\nexport interface WorkerFailedPayload {\n\t/** @internal */\n\tstate: string;\n\t/** @internal */\n\terrorCode: string;\n\t/** @internal */\n\tmessage: string;\n\t/** @internal */\n\terrorClass: string;\n\t/** @internal */\n\tselectedTurnId?: string | null;\n\t/** @internal */\n\tretryAttempt?: number;\n}\n\n/** @internal */\nexport type WorkerToServerMessage =\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.hello\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerHelloPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.credential_update\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerCredentialUpdatePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.bootstrap_progress\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerBootstrapProgressPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.diagnostic_trace\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerDiagnosticTracePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.ready\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerReadyPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.heartbeat\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerHeartbeatPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.state\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerStatePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.input_consumed\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerInputConsumedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.event\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerEventPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.turn_started\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerTurnStartedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.question_requested\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerQuestionRequestedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.integration_tool_request\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerIntegrationToolRequestPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.integration_tool_cancel\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerIntegrationToolCancelPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.turn_outcome\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerTurnOutcomePayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.turn_failed\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerTurnFailedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.lifecycle_parked\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerLifecycleParkedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.cleanup_started\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerCleanupStartedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.cleanup_completed\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerCleanupCompletedPayload;\n\t })\n\t| (Omit<IpcEnvelope, \"type\" | \"payload\"> & {\n\t\t\t/** @internal */\n\t\t\ttype: \"worker.failed\";\n\t\t\t/** @internal */\n\t\t\tpayload: WorkerFailedPayload;\n\t });\n\n/** @internal */\nexport type AnyIpcMessage = ServerToWorkerMessage | WorkerToServerMessage;\n/** @internal */\nexport type IpcMessageType = AnyIpcMessage[\"type\"];\n/** @internal */\nexport type IpcMessageOfType<TType extends IpcMessageType> = Extract<\n\tAnyIpcMessage,\n\t{\n\t\t/** @internal */\n\t\ttype: TType;\n\t}\n>;\n\n/** @internal */\nexport function createIpcMessage<TMessage extends AnyIpcMessage>(\n\targs: Omit<TMessage, \"protocol\" | \"sentAt\"> & {\n\t\t/** @internal */\n\t\tsentAt?: string;\n\t},\n): TMessage {\n\treturn {\n\t\tprotocol: IPC_PROTOCOL_VERSION,\n\t\tmessageId: args.messageId,\n\t\tcorrelationId: args.correlationId,\n\t\ttype: args.type,\n\t\tinstanceId: args.instanceId,\n\t\tworkerId: args.workerId,\n\t\tsentAt: args.sentAt ?? new Date().toISOString(),\n\t\tpayload: args.payload,\n\t} as TMessage;\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\n\nconst BLOCK_SIZE = 512;\n\n/** @internal */\nexport interface PiResourceFile {\n\t/** @internal */\n\tpath: string;\n\t/** @internal */\n\tcontent: Uint8Array;\n}\n\n/** @internal */\nexport interface PiResourceBundle {\n\t/** @internal */\n\tdigest: string;\n\t/** @internal */\n\tbytes: Uint8Array;\n}\n\n/** @internal */\nexport interface ExtractedPiResourceFile {\n\t/** @internal */\n\tpath: string;\n\t/** @internal */\n\tcontent: Uint8Array;\n}\n\nfunction fail(message: string): never {\n\tthrow new Error(`Invalid Pi resource bundle: ${message}`);\n}\n\n/** @internal */\nexport function validateResourceRelativePath(value: string): string {\n\tif (!value || path.posix.isAbsolute(value) || value.includes(\"\\\\\")) {\n\t\tfail(`unsafe path '${value}'`);\n\t}\n\tconst normalized = path.posix.normalize(value);\n\tif (normalized === \".\" || normalized === \"..\" || normalized.startsWith(\"../\")) {\n\t\tfail(`unsafe path '${value}'`);\n\t}\n\treturn normalized;\n}\n\nfunction writeString(buffer: Buffer, offset: number, length: number, value: string): void {\n\tconst encoded = Buffer.from(value, \"utf8\");\n\tif (encoded.length > length) fail(`header value too long: ${value}`);\n\tencoded.copy(buffer, offset);\n}\n\nfunction writeOctal(buffer: Buffer, offset: number, length: number, value: number): void {\n\tconst encoded = value.toString(8).padStart(length - 1, \"0\");\n\tif (encoded.length > length - 1) fail(`numeric header value too large: ${value}`);\n\twriteString(buffer, offset, length - 1, encoded);\n\tbuffer[offset + length - 1] = 0;\n}\n\nfunction header(name: string, size: number): Buffer {\n\tif (Buffer.byteLength(name) > 100) fail(`path exceeds canonical ustar name limit: ${name}`);\n\tconst result = Buffer.alloc(BLOCK_SIZE);\n\twriteString(result, 0, 100, name);\n\twriteOctal(result, 100, 8, 0o644);\n\twriteOctal(result, 108, 8, 0);\n\twriteOctal(result, 116, 8, 0);\n\twriteOctal(result, 124, 12, size);\n\twriteOctal(result, 136, 12, 0);\n\tresult.fill(0x20, 148, 156);\n\tresult[156] = \"0\".charCodeAt(0);\n\twriteString(result, 257, 6, \"ustar\");\n\twriteString(result, 263, 2, \"00\");\n\tconst sum = result.reduce((total, byte) => total + byte, 0);\n\twriteString(result, 148, 8, `${sum.toString(8).padStart(6, \"0\")}\\0 `);\n\treturn result;\n}\n\nfunction padding(size: number): Buffer {\n\tconst length = (BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE;\n\treturn Buffer.alloc(length);\n}\n\n/** @internal */\nexport function sha256Digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\n/** Creates a deterministic, uncompressed ustar archive containing regular files only. @internal */\nexport function createCanonicalPiResourceBundle(\n\tfiles: readonly PiResourceFile[],\n): PiResourceBundle {\n\tconst seen = new Set<string>();\n\tconst normalized = files.map((file) => {\n\t\tconst resourcePath = validateResourceRelativePath(file.path);\n\t\tif (seen.has(resourcePath)) fail(`duplicate path '${resourcePath}'`);\n\t\tseen.add(resourcePath);\n\t\treturn { path: resourcePath, content: Buffer.from(file.content) };\n\t});\n\tnormalized.sort((left, right) => Buffer.compare(Buffer.from(left.path), Buffer.from(right.path)));\n\tconst chunks: Buffer[] = [];\n\tfor (const file of normalized) {\n\t\tchunks.push(header(file.path, file.content.length), file.content, padding(file.content.length));\n\t}\n\tchunks.push(Buffer.alloc(BLOCK_SIZE * 2));\n\tconst bytes = Buffer.concat(chunks);\n\treturn { bytes, digest: sha256Digest(bytes) };\n}\n\nfunction readNullString(block: Uint8Array, start: number, length: number): string {\n\tconst end = block.subarray(start, start + length).indexOf(0);\n\treturn Buffer.from(block.subarray(start, end < 0 ? start + length : start + end)).toString(\n\t\t\"utf8\",\n\t);\n}\n\nfunction readOctal(block: Uint8Array, start: number, length: number): number {\n\tconst raw = readNullString(block, start, length).trim();\n\tif (!/^[0-7]*$/.test(raw)) fail(\"non-octal numeric field\");\n\treturn raw ? Number.parseInt(raw, 8) : 0;\n}\n\nfunction verifyChecksum(block: Uint8Array): void {\n\tconst expected = readOctal(block, 148, 8);\n\tlet actual = 0;\n\tfor (let index = 0; index < BLOCK_SIZE; index++) {\n\t\tactual += index >= 148 && index < 156 ? 32 : block[index];\n\t}\n\tif (actual !== expected) fail(\"header checksum mismatch\");\n}\n\nfunction allZero(block: Uint8Array): boolean {\n\treturn block.every((byte) => byte === 0);\n}\n\n/** Parses only the narrow regular-file ustar subset emitted by this module. @internal */\nexport function verifyCanonicalPiResourceBundle(\n\tbytes: Uint8Array,\n\texpectedDigest?: string,\n): ExtractedPiResourceFile[] {\n\tif (expectedDigest && sha256Digest(bytes) !== expectedDigest) fail(\"content digest mismatch\");\n\tif (bytes.length < BLOCK_SIZE * 2 || bytes.length % BLOCK_SIZE !== 0) {\n\t\tfail(\"invalid archive length\");\n\t}\n\tconst files: ExtractedPiResourceFile[] = [];\n\tconst paths = new Set<string>();\n\tlet offset = 0;\n\twhile (offset < bytes.length) {\n\t\tconst block = bytes.subarray(offset, offset + BLOCK_SIZE);\n\t\tif (allZero(block)) {\n\t\t\tif (!allZero(bytes.subarray(offset + BLOCK_SIZE, offset + BLOCK_SIZE * 2))) {\n\t\t\t\tfail(\"missing end blocks\");\n\t\t\t}\n\t\t\tif (offset + BLOCK_SIZE * 2 !== bytes.length) fail(\"data after end blocks\");\n\t\t\treturn files;\n\t\t}\n\t\tverifyChecksum(block);\n\t\tif (readNullString(block, 257, 6) !== \"ustar\") fail(\"unsupported tar format\");\n\t\tconst type = readNullString(block, 156, 1);\n\t\tif (type !== \"\" && type !== \"0\") fail(`unsupported entry type '${type}'`);\n\t\tif (readNullString(block, 157, 100) || readNullString(block, 345, 155)) {\n\t\t\tfail(\"links and ustar path prefixes are unsupported\");\n\t\t}\n\t\tconst name = validateResourceRelativePath(readNullString(block, 0, 100));\n\t\tif (paths.has(name)) fail(`duplicate path '${name}'`);\n\t\tpaths.add(name);\n\t\tconst size = readOctal(block, 124, 12);\n\t\tconst contentStart = offset + BLOCK_SIZE;\n\t\tconst contentEnd = contentStart + size;\n\t\tif (contentEnd > bytes.length) fail(\"truncated file content\");\n\t\tfiles.push({ path: name, content: bytes.slice(contentStart, contentEnd) });\n\t\toffset = contentEnd + ((BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE);\n\t}\n\tfail(\"missing end blocks\");\n}\n","import * as v from \"valibot\";\nimport { validateResourceRelativePath } from \"./pi-resource-bundle.js\";\n\n/** @internal */\nexport const PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION = 1;\n\nconst nonBlankStringSchema = v.pipe(\n\tv.string(),\n\tv.check((value) => value.trim() !== \"\", \"Expected a non-empty string\"),\n);\nconst jsonObjectSchema = v.record(v.string(), v.unknown());\nconst positiveSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1));\nconst nonNegativeSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(0));\n\n/** @internal */\nexport const piResourceManifestSchema = v.strictObject({\n\t/** @internal */\n\tschemaVersion: v.literal(PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION),\n\t/** @internal */\n\tmodel: v.strictObject({\n\t\t/** @internal */\n\t\tprofileId: nonBlankStringSchema,\n\t\t/** @internal */\n\t\tproviderId: nonBlankStringSchema,\n\t\t/** @internal */\n\t\tmodelId: nonBlankStringSchema,\n\t\t/** @internal */\n\t\tthinkingLevel: nonBlankStringSchema,\n\t}),\n\t/** @internal */\n\tproviderOptions: v.record(v.string(), nonBlankStringSchema),\n\t/** @internal */\n\tproviderWorkerConfig: v.nullable(\n\t\tv.strictObject({\n\t\t\t/** @internal */\n\t\t\tversion: positiveSafeIntegerSchema,\n\t\t\t/** @internal */\n\t\t\tvalue: jsonObjectSchema,\n\t\t}),\n\t),\n\t/** @internal */\n\tdeclaredCredentialPaths: v.array(nonBlankStringSchema),\n\t/** @internal */\n\tcompatibility: v.strictObject({\n\t\t/** @internal */\n\t\tworkerApiVersion: nonBlankStringSchema,\n\t\t/** @internal */\n\t\tpiVersion: nonBlankStringSchema,\n\t\t/** @internal */\n\t\tprotocolVersion: v.optional(nonBlankStringSchema),\n\t}),\n\t/** @internal */\n\tprovenance: v.array(\n\t\tv.strictObject({\n\t\t\t/** @internal */\n\t\t\tkind: v.picklist([\"extension\", \"skill\", \"prompt\", \"generated\"]),\n\t\t\t/** @internal */\n\t\t\townerExtensionId: v.nullable(nonBlankStringSchema),\n\t\t\t/** @internal */\n\t\t\tpackageName: v.nullable(nonBlankStringSchema),\n\t\t\t/** @internal */\n\t\t\tsnapshotPath: nonBlankStringSchema,\n\t\t\t/** @internal */\n\t\t\tsha256: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/)),\n\t\t\t/** @internal */\n\t\t\tsize: nonNegativeSafeIntegerSchema,\n\t\t}),\n\t),\n});\n\n/** @internal */\ntype DeepReadonly<T> = T extends readonly unknown[]\n\t? { readonly [Index in keyof T]: DeepReadonly<T[Index]> }\n\t: T extends object\n\t\t? { readonly [Key in keyof T]: DeepReadonly<T[Key]> }\n\t\t: T;\n\n/** @internal */\nexport type PiResourceManifest = DeepReadonly<v.InferOutput<typeof piResourceManifestSchema>>;\n/** @internal */\nexport type PiResourceSnapshotModel = PiResourceManifest[\"model\"];\n/** @internal */\nexport type PiResourceSnapshotWorkerConfig = NonNullable<\n\tPiResourceManifest[\"providerWorkerConfig\"]\n>;\n/** @internal */\nexport type PiResourceSnapshotCompatibility = PiResourceManifest[\"compatibility\"];\n/** @internal */\nexport type PiResourceFileProvenance = PiResourceManifest[\"provenance\"][number];\n/** @internal */\nexport type PiResourceProvenanceKind = PiResourceFileProvenance[\"kind\"];\n\nfunction invalidManifest(message: string, cause?: unknown): never {\n\tthrow new Error(`Invalid managed Pi resource snapshot: ${message}`, { cause });\n}\n\n/** Parses and validates the complete generated.json contract. @internal */\nexport function parsePiResourceManifest(raw: unknown): PiResourceManifest {\n\tlet manifest: PiResourceManifest;\n\ttry {\n\t\tmanifest = v.parse(piResourceManifestSchema, raw);\n\t} catch (error) {\n\t\tinvalidManifest(\"generated.json does not match the resource manifest schema\", error);\n\t}\n\n\tlet declaredCredentialPaths: string[];\n\tlet provenance: PiResourceFileProvenance[];\n\ttry {\n\t\tdeclaredCredentialPaths = manifest.declaredCredentialPaths.map(validateResourceRelativePath);\n\t\tprovenance = manifest.provenance.map((item) => ({\n\t\t\t...item,\n\t\t\tsnapshotPath: validateResourceRelativePath(item.snapshotPath),\n\t\t}));\n\t} catch (error) {\n\t\tinvalidManifest(\"generated.json contains an unsafe path\", error);\n\t}\n\tif (new Set(declaredCredentialPaths).size !== declaredCredentialPaths.length) {\n\t\tinvalidManifest(\"generated.json declares a credential path more than once\");\n\t}\n\tconst provenancePaths = provenance.map((item) => item.snapshotPath);\n\tif (new Set(provenancePaths).size !== provenancePaths.length) {\n\t\tinvalidManifest(\"generated.json contains duplicate provenance paths\");\n\t}\n\tfor (const credentialPath of declaredCredentialPaths) {\n\t\tif (credentialPath === \"generated.json\" || provenancePaths.includes(credentialPath)) {\n\t\t\tinvalidManifest(`credential path '${credentialPath}' overlaps immutable snapshot content`);\n\t\t}\n\t}\n\treturn { ...manifest, declaredCredentialPaths, provenance };\n}\n\ntype JsonRecord = Record<string, unknown>;\n\n/** @internal */\nexport function canonicalizeJson(value: unknown, location = \"value\"): unknown {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new Error(`${location} contains a non-finite number`);\n\t\treturn Object.is(value, -0) ? 0 : value;\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item, index) => canonicalizeJson(item, `${location}[${index}]`));\n\t}\n\tif (typeof value !== \"object\") throw new Error(`${location} contains a non-JSON value`);\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new Error(`${location} contains a non-plain object`);\n\t}\n\treturn Object.fromEntries(\n\t\tObject.keys(value as JsonRecord)\n\t\t\t.sort((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right)))\n\t\t\t.map((key) => [key, canonicalizeJson((value as JsonRecord)[key], `${location}.${key}`)]),\n\t);\n}\n\n/** @internal */\nexport function canonicalJsonStringify(value: unknown, location = \"value\"): string {\n\treturn JSON.stringify(canonicalizeJson(value, location));\n}\n\n/** @internal */\nexport function canonicalJsonEqual(left: unknown, right: unknown): boolean {\n\treturn canonicalJsonStringify(left) === canonicalJsonStringify(right);\n}\n","import type { ConfigSnapshot } from \"@leitwerk-dev/protocol/config-snapshot\";\n\n/** @internal */\nexport async function flushAsyncWork(iterations = 30): Promise<void> {\n\tfor (let i = 0; i < iterations; i++) {\n\t\tawait new Promise<void>((resolve) => setImmediate(resolve));\n\t}\n}\n\n/** @internal */\nexport function createTestConfigSnapshot(): ConfigSnapshot {\n\treturn {\n\t\tworkers: {\n\t\t\theartbeat_interval: \"5s\",\n\t\t\tturn_max_duration: \"30m\",\n\t\t\tturn_inactivity_timeout: \"5m\",\n\t\t\tturn_abort_grace_period: \"5s\",\n\t\t},\n\t\tpi: {\n\t\t\tagent_dir: \"~/.pi/leitwerk\",\n\t\t\tmodel_profiles: [],\n\t\t\tprocess_title_generation: {\n\t\t\t\tmodel_profile: null,\n\t\t\t\tretry: {\n\t\t\t\t\tmax_attempts: 6,\n\t\t\t\t\tbase_delay: \"5s\",\n\t\t\t\t\tmax_delay: \"5m\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tretry: {\n\t\t\t\tenabled: true,\n\t\t\t\tmax_retries: 3,\n\t\t\t\tbase_delay: \"2s\",\n\t\t\t\tprovider: {\n\t\t\t\t\ttimeout: null,\n\t\t\t\t\tmax_retries: null,\n\t\t\t\t\tmax_retry_delay: \"60s\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n","/**\n * Compatibility version for the server ↔ worker runtime API.\n *\n * Container image labels use the same value (`leitwerk.dev/worker-api-version`).\n * Workers also report it in `worker.hello` so the server can fail fast when a\n * pod image is from an incompatible leitwerk build line.\n */\n/** @public */\nexport const WORKER_API_VERSION = \"2026-09-16\";\n","/** @internal */\nexport const WORKER_INSTANCE_ID_ENV = \"LEITWERK_INSTANCE_ID\";\n/** @internal */\nexport const WORKER_ID_ENV = \"LEITWERK_WORKER_ID\";\n/** @internal */\nexport const WORKER_IPC_SERVER_URL_ENV = \"LEITWERK_SERVER_URL\";\n/** @internal */\nexport const WORKER_IPC_CONNECT_TOKEN_ENV = \"LEITWERK_WORKER_CONNECT_TOKEN\";\n/** @internal */\nexport const WORKER_IPC_RECONNECT_ENV = \"LEITWERK_WORKER_RECONNECT\";\n/** @internal */\nexport const WORKER_SNAPSHOT_TOKEN_ENV = \"LEITWERK_WORKER_SNAPSHOT_TOKEN\";\n/** @internal */\nexport const WORKER_SERVER_EPOCH_ENV = \"LEITWERK_SERVER_EPOCH\";\n","/** @internal */\nexport const WORKER_SESSION_SNAPSHOT_CONTENT_TYPE = \"application/x-ndjson\";\n/** @internal */\nexport const WORKER_SESSION_SNAPSHOT_WORKER_ID_HEADER = \"x-leitwerk-worker-id\";\n/** @internal */\nexport const WORKER_SESSION_SNAPSHOT_REASON_HEADER = \"x-leitwerk-session-snapshot-reason\";\n/** @internal */\nexport const WORKER_SESSION_SNAPSHOT_TURN_RECORD_ID_HEADER = \"x-leitwerk-turn-record-id\";\n/** @internal */\nexport function buildWorkerSessionSnapshotPath(instanceId: string): string {\n\treturn `/internal/workers/${encodeURIComponent(instanceId)}/session-snapshot`;\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,YAAY,OAAO;AAGZ,IAAM,iCAAmC,SAAO;AAAA;AAAA,EAEtD,UAAY,OAAO,SAAO,GAAK,QAAM,+CAA+C,CAAC;AAAA;AAAA,EAErF,UAAY,OAAO,SAAO,GAAK,WAAS,GAAK,QAAM,eAAe,CAAC;AAAA;AAAA,EAEnE,UAAY,OAAO,SAAO,GAAK,WAAS,CAAC;AAC1C,CAAC;AAGM,IAAM,kBAAoB;AAAA,EAC9B,SAAO;AAAA,EACP,WAAS;AAAA,EACT,QAAM,CAAC,UAAU,KAAK,KAAK,MAAM,GAAG,kCAAkC;AACzE;AACA,IAAM,iBAAmB;AAAA,EACtB,SAAO;AAAA,EACP;AAAA,IACD,CAAC,UAAU,+BAA+B,KAAK,KAAK,KAAK,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM;AAAA,EAC9F;AACD;AAKO,IAAM,sBAAwB,eAAa;AAAA;AAAA,EAEjD,aAAa;AAAA;AAAA,EAEb,eAAiB;AAAA,IACd;AAAA,MACC;AAAA,QACC,eAAa;AAAA;AAAA,UAEd,MAAM;AAAA;AAAA,UAEN,MAAQ,OAAO,SAAO,GAAK,UAAQ,GAAK,WAAS,EAAE,CAAC;AAAA,QACrD,CAAC;A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;AAAA,MACA,OAAO;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,QACb,YAAY;AAAA,QACZ,UAAU;AAAA,UACT,SAAS;AAAA,UACT,aAAa;AAAA,UACb,iBAAiB;AAAA,QAClB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;;;ACjCO,IAAM,qBAAqB;;;ACP3B,IAAM,yBAAyB;AAE/B,IAAM,gBAAgB;AAEtB,IAAM,4BAA4B;AAElC,IAAM,+BAA+B;AAErC,IAAM,2BAA2B;AAEjC,IAAM,4BAA4B;AAElC,IAAM,0BAA0B;;;ACZhC,IAAM,uCAAuC;AAE7C,IAAM,2CAA2C;AAEjD,IAAM,wCAAwC;AAE9C,IAAM,gDAAgD;AAEtD,SAAS,+BAA+B,YAA4B;AAC1E,SAAO,qBAAqB,mBAAmB,UAAU,CAAC;AAC3D;","names":["v","v"]}
|
package/dist/ipc-codec.d.ts
CHANGED
|
@@ -1,29 +1,51 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
+
/** @internal */
|
|
2
3
|
export declare const IPC_PROTOCOL_VERSION: "leitwerk/worker-ipc/v1";
|
|
4
|
+
/** @internal */
|
|
3
5
|
export declare const IPC_ENVELOPE_SCHEMA: v.ObjectSchema<{
|
|
6
|
+
/** @internal */
|
|
4
7
|
readonly protocol: v.LiteralSchema<"leitwerk/worker-ipc/v1", undefined>;
|
|
8
|
+
/** @internal */
|
|
5
9
|
readonly messageId: v.StringSchema<undefined>;
|
|
10
|
+
/** @internal */
|
|
6
11
|
readonly correlationId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
12
|
+
/** @internal */
|
|
7
13
|
readonly type: v.StringSchema<undefined>;
|
|
14
|
+
/** @internal */
|
|
8
15
|
readonly instanceId: v.StringSchema<undefined>;
|
|
16
|
+
/** @internal */
|
|
9
17
|
readonly workerId: v.StringSchema<undefined>;
|
|
18
|
+
/** @internal */
|
|
10
19
|
readonly sentAt: v.StringSchema<undefined>;
|
|
20
|
+
/** @internal */
|
|
11
21
|
readonly payload: v.UnknownSchema;
|
|
12
22
|
}, undefined>;
|
|
23
|
+
/** @internal */
|
|
13
24
|
export type IpcEnvelope = v.InferOutput<typeof IPC_ENVELOPE_SCHEMA>;
|
|
25
|
+
/** @internal */
|
|
14
26
|
export declare function validateEnvelope(msg: unknown): {
|
|
27
|
+
/** @internal */
|
|
15
28
|
ok: true;
|
|
29
|
+
/** @internal */
|
|
16
30
|
envelope: IpcEnvelope;
|
|
17
31
|
} | {
|
|
32
|
+
/** @internal */
|
|
18
33
|
ok: false;
|
|
34
|
+
/** @internal */
|
|
19
35
|
error: string;
|
|
20
36
|
};
|
|
37
|
+
/** @internal */
|
|
21
38
|
export declare function serializeMessage<TEnvelope extends IpcEnvelope>(envelope: TEnvelope): string;
|
|
39
|
+
/** @internal */
|
|
22
40
|
export declare function deserializeMessage(line: string): {
|
|
41
|
+
/** @internal */
|
|
23
42
|
ok: true;
|
|
43
|
+
/** @internal */
|
|
24
44
|
message: IpcEnvelope;
|
|
25
45
|
} | {
|
|
46
|
+
/** @internal */
|
|
26
47
|
ok: false;
|
|
48
|
+
/** @internal */
|
|
27
49
|
error: string;
|
|
28
50
|
};
|
|
29
51
|
//# sourceMappingURL=ipc-codec.d.ts.map
|
package/dist/ipc-codec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipc-codec.d.ts","sourceRoot":"","sources":["../src/ipc-codec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,eAAO,MAAM,oBAAoB,EAAG,wBAAiC,CAAC;AAEtE,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"ipc-codec.d.ts","sourceRoot":"","sources":["../src/ipc-codec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,gBAAgB;AAChB,eAAO,MAAM,oBAAoB,EAAG,wBAAiC,CAAC;AAEtE,g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