@leitwerk-dev/worker-protocol 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/docker-config.d.ts +23 -0
  2. package/dist/docker-config.d.ts.map +1 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +512 -10
  6. package/dist/index.js.map +1 -1
  7. package/dist/ipc-decode.d.ts.map +1 -1
  8. package/dist/ipc-messages.d.ts +66 -14
  9. package/dist/ipc-messages.d.ts.map +1 -1
  10. package/dist/testing.d.ts +9 -0
  11. package/dist/testing.d.ts.map +1 -1
  12. package/dist/worker-api-version.d.ts +1 -1
  13. package/dist/worker-result-image.js +28 -54
  14. package/dist/worker-result-image.js.map +1 -1
  15. package/package.json +4 -4
  16. package/src/docker-config.ts +38 -0
  17. package/src/index.ts +1 -0
  18. package/src/ipc-decode.ts +3 -0
  19. package/src/ipc-messages.ts +71 -16
  20. package/src/testing.ts +17 -0
  21. package/src/worker-api-version.ts +1 -1
  22. package/dist/ipc-codec.js +0 -48
  23. package/dist/ipc-codec.js.map +0 -1
  24. package/dist/ipc-decode.js +0 -71
  25. package/dist/ipc-decode.js.map +0 -1
  26. package/dist/ipc-messages.js +0 -14
  27. package/dist/ipc-messages.js.map +0 -1
  28. package/dist/pi-resource-bundle.js +0 -139
  29. package/dist/pi-resource-bundle.js.map +0 -1
  30. package/dist/pi-resource-manifest.js +0 -101
  31. package/dist/pi-resource-manifest.js.map +0 -1
  32. package/dist/testing.js +0 -33
  33. package/dist/testing.js.map +0 -1
  34. package/dist/worker-api-version.js +0 -9
  35. package/dist/worker-api-version.js.map +0 -1
  36. package/dist/worker-ipc-transport.js +0 -8
  37. package/dist/worker-ipc-transport.js.map +0 -1
  38. package/dist/worker-session-snapshot.js +0 -8
  39. package/dist/worker-session-snapshot.js.map +0 -1
@@ -5,13 +5,14 @@ import type {
5
5
  ProcessInputTarget,
6
6
  ProcessLifecycleStatus,
7
7
  ProcessSemanticEntryRefKey,
8
- ProcessTurnRecordPathType,
9
- ProcessTurnType,
10
8
  TurnFailedPayload,
9
+ TurnOutcomePayload,
11
10
  TurnStartRecord,
12
11
  WorkerBootstrapReceipt,
13
12
  } from "@leitwerk-dev/domain";
14
13
  import type { ConfigSnapshot } from "@leitwerk-dev/protocol/config-snapshot";
14
+ import type { InferOutput } from "valibot";
15
+ import type { dockerRegistryCredentialSchema } from "./docker-config.js";
15
16
  import { IPC_PROTOCOL_VERSION, type IpcEnvelope } from "./ipc-codec.js";
16
17
 
17
18
  export interface ProcessInstanceSnapshot {
@@ -84,9 +85,30 @@ export interface WorkerGitSshCredential {
84
85
  knownHosts: string;
85
86
  }
86
87
 
88
+ export interface WorkerGitHttpsCredential {
89
+ projectKey: string;
90
+ kind: "git_https";
91
+ credentialRef: string;
92
+ /** Exact non-secret HTTPS clone URL authorized by the server. */
93
+ repositoryUrl: string;
94
+ username: string;
95
+ /** Secret; only delivered through authenticated worker.start. */
96
+ password: string;
97
+ }
98
+
99
+ export type WorkerRepositoryCredential = WorkerGitSshCredential | WorkerGitHttpsCredential;
100
+
101
+ /** Secret material allowed only in authenticated worker.start, never snapshots or exports. */
102
+ export interface WorkerDockerRegistryCredential
103
+ extends InferOutput<typeof dockerRegistryCredentialSchema> {}
104
+
87
105
  export interface LlmWorkerStartBootstrap {
88
106
  kind: "llm";
89
- resourceBundle: { digest: string; archiveBase64: string };
107
+ resourceBundle: {
108
+ digest: string;
109
+ /** Present for a newly assembled bundle; omitted when the worker can reuse its process volume. */
110
+ archiveBase64?: string;
111
+ };
90
112
  credential: WorkerCredentialMaterial | null;
91
113
  }
92
114
 
@@ -96,6 +118,13 @@ export interface AutomaticWorkerStartBootstrap {
96
118
 
97
119
  export type WorkerRuntimeSettingsSnapshot = ConfigSnapshot["workers"];
98
120
 
121
+ export interface DevelopmentToolsStartConfig {
122
+ runner: "local" | "isolated";
123
+ miseCommand: string;
124
+ installTimeoutMs: number;
125
+ processStorageRoot: string;
126
+ }
127
+
99
128
  export interface IntegrationToolDeclaration {
100
129
  name: string;
101
130
  description: string;
@@ -114,13 +143,20 @@ interface WorkerStartPayloadBase extends WorkerRuntimeContextSnapshot {
114
143
  treePaths: {
115
144
  primaryTreeFile: string;
116
145
  workspaceRoot: string;
146
+ /** Process-scoped persistent storage for immutable Pi resource bundles. */
147
+ piResourceBundlesDir: string;
117
148
  };
118
149
  resume: boolean;
119
150
  resumeLeafEntryId?: string | null;
151
+ /** Durable non-secret preparation checkpoint reused by a replacement or Continue start. */
152
+ llmPreparation?: { sourceTurnRecordId: string; data: unknown };
120
153
  /** Fresh secret material resolved for this physical worker start only. */
121
- repositoryCredentials?: WorkerGitSshCredential[];
154
+ repositoryCredentials?: WorkerRepositoryCredential[];
155
+ dockerRegistryCredentials?: WorkerDockerRegistryCredential[];
122
156
  /** Non-secret lifecycle settings supplied to every worker bootstrap type. */
123
157
  workerRuntimeSettings?: WorkerRuntimeSettingsSnapshot;
158
+ /** Non-secret mise adapter settings. Ignored unless the process opts in. */
159
+ developmentTools?: DevelopmentToolsStartConfig;
124
160
  /** Non-secret declarations authorized for the selected LLM turn. */
125
161
  integrationTools?: IntegrationToolDeclaration[];
126
162
  }
@@ -149,6 +185,10 @@ export interface WorkerTurnStartAcceptedPayload {
149
185
  turnRecordId: string;
150
186
  }
151
187
 
188
+ export interface WorkerTurnTerminalRecordedPayload {
189
+ turnRecordId: string;
190
+ }
191
+
152
192
  export interface WorkerQuestionResponsePayload {
153
193
  turnRecordId: string;
154
194
  toolCallId: string;
@@ -198,6 +238,10 @@ export type ServerToWorkerMessage =
198
238
  type: "worker.turn_start_accepted";
199
239
  payload: WorkerTurnStartAcceptedPayload;
200
240
  })
241
+ | (Omit<IpcEnvelope, "type" | "payload"> & {
242
+ type: "worker.turn_terminal_recorded";
243
+ payload: WorkerTurnTerminalRecordedPayload;
244
+ })
201
245
  | (Omit<IpcEnvelope, "type" | "payload"> & {
202
246
  type: "worker.credential_update_accepted";
203
247
  payload: WorkerCredentialUpdateResultPayload;
@@ -231,8 +275,21 @@ export interface WorkerHelloPayload {
231
275
  capabilities: string[];
232
276
  }
233
277
 
278
+ export interface WorkerBootstrapProgressPayload {
279
+ phase: "worker_connected" | "preparing_workspace" | "loading_resources" | "preparing_turn";
280
+ }
281
+
282
+ export interface WorkerDiagnosticTracePayload {
283
+ text: string;
284
+ }
285
+
234
286
  export interface WorkerReadyPayload {
235
287
  receipt: WorkerBootstrapReceipt;
288
+ developmentTools?: {
289
+ miseVersion: string;
290
+ repositories: Array<{ repositoryKey: string; tools: Array<{ name: string; version: string }> }>;
291
+ warnings: string[];
292
+ };
236
293
  resumed: boolean;
237
294
  primaryTreeFile: string;
238
295
  workspaceRoot: string;
@@ -292,18 +349,8 @@ export interface WorkerCredentialUpdatePayload {
292
349
  values: Record<string, string>;
293
350
  }
294
351
 
295
- export interface WorkerTurnOutcomePayload {
296
- turnRecordId: string;
297
- turnId: string;
298
- turnType: ProcessTurnType;
299
- outcome: string;
300
- params: Record<string, unknown>;
301
- pathType?: ProcessTurnRecordPathType;
302
- forkPiEntryId?: string | null;
303
- resultPiEntryId?: string | null;
304
- turnResultMarkdown?: string | null;
305
- rootEntryId?: string | null;
306
- }
352
+ export interface WorkerTurnOutcomePayload
353
+ extends Omit<TurnOutcomePayload, "instanceId" | "state"> {}
307
354
 
308
355
  export interface WorkerTurnFailedPayload
309
356
  extends Omit<TurnFailedPayload, "instanceId" | "errorClass"> {
@@ -343,6 +390,14 @@ export type WorkerToServerMessage =
343
390
  type: "worker.credential_update";
344
391
  payload: WorkerCredentialUpdatePayload;
345
392
  })
393
+ | (Omit<IpcEnvelope, "type" | "payload"> & {
394
+ type: "worker.bootstrap_progress";
395
+ payload: WorkerBootstrapProgressPayload;
396
+ })
397
+ | (Omit<IpcEnvelope, "type" | "payload"> & {
398
+ type: "worker.diagnostic_trace";
399
+ payload: WorkerDiagnosticTracePayload;
400
+ })
346
401
  | (Omit<IpcEnvelope, "type" | "payload"> & {
347
402
  type: "worker.ready";
348
403
  payload: WorkerReadyPayload;
package/src/testing.ts CHANGED
@@ -1,4 +1,21 @@
1
1
  import type { ConfigSnapshot } from "@leitwerk-dev/protocol/config-snapshot";
2
+ import { IPC_PROTOCOL_VERSION } from "./ipc-codec.js";
3
+
4
+ export async function flushAsyncWork(iterations = 30): Promise<void> {
5
+ for (let i = 0; i < iterations; i++) {
6
+ await new Promise<void>((resolve) => setImmediate(resolve));
7
+ }
8
+ }
9
+
10
+ export function createTestIpcEnvelopeBase(instanceId: string, workerId: string, messageId: string) {
11
+ return {
12
+ protocol: IPC_PROTOCOL_VERSION as typeof IPC_PROTOCOL_VERSION,
13
+ messageId,
14
+ instanceId,
15
+ workerId,
16
+ sentAt: new Date().toISOString(),
17
+ };
18
+ }
2
19
 
3
20
  export function createTestConfigSnapshot(): ConfigSnapshot {
4
21
  return {
@@ -5,4 +5,4 @@
5
5
  * Workers also report it in `worker.hello` so the server can fail fast when a
6
6
  * pod image is from an incompatible leitwerk build line.
7
7
  */
8
- export const WORKER_API_VERSION = "2026-08-10";
8
+ export const WORKER_API_VERSION = "2026-09-16";
package/dist/ipc-codec.js DELETED
@@ -1,48 +0,0 @@
1
- import { parseSchema } from "@leitwerk-dev/protocol";
2
- import * as v from "valibot";
3
- export const IPC_PROTOCOL_VERSION = "leitwerk/worker-ipc/v1";
4
- export const IPC_ENVELOPE_SCHEMA = v.object({
5
- protocol: v.literal(IPC_PROTOCOL_VERSION),
6
- messageId: v.string(),
7
- correlationId: v.optional(v.string()),
8
- type: v.string(),
9
- instanceId: v.string(),
10
- workerId: v.string(),
11
- sentAt: v.string(),
12
- payload: v.unknown(),
13
- });
14
- export function validateEnvelope(msg) {
15
- if (typeof msg === "object" &&
16
- msg !== null &&
17
- "protocol" in msg &&
18
- typeof msg.protocol === "string" &&
19
- msg.protocol !== IPC_PROTOCOL_VERSION) {
20
- return {
21
- ok: false,
22
- error: `Worker IPC protocol '${msg.protocol}' is incompatible with expected protocol '${IPC_PROTOCOL_VERSION}'`,
23
- };
24
- }
25
- const envelope = parseSchema(IPC_ENVELOPE_SCHEMA, msg, "ipc envelope");
26
- return envelope.ok
27
- ? { ok: true, envelope: envelope.value }
28
- : { ok: false, error: envelope.error };
29
- }
30
- export function serializeMessage(envelope) {
31
- return JSON.stringify(envelope);
32
- }
33
- export function deserializeMessage(line) {
34
- const trimmed = line.length > 0 && line.charCodeAt(line.length - 1) === 0x0d ? line.slice(0, -1) : line;
35
- let parsed;
36
- try {
37
- parsed = JSON.parse(trimmed);
38
- }
39
- catch {
40
- return { ok: false, error: "invalid JSON" };
41
- }
42
- const validated = validateEnvelope(parsed);
43
- if (!validated.ok) {
44
- return { ok: false, error: validated.error };
45
- }
46
- return { ok: true, message: validated.envelope };
47
- }
48
- //# sourceMappingURL=ipc-codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ipc-codec.js","sourceRoot":"","sources":["../src/ipc-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAiC,CAAC;AAEtE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,aAAa,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;C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AAc,EAAE,CAAC;IAC7C,CAAC;IACD,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC;AAClD,CAAC"}
@@ -1,71 +0,0 @@
1
- import { validateEnvelope } from "./ipc-codec.js";
2
- const SERVER_TO_WORKER_TYPES = [
3
- "worker.start",
4
- "worker.turn_start_accepted",
5
- "worker.credential_update_accepted",
6
- "worker.question_response",
7
- "worker.integration_tool_result",
8
- "input.batch",
9
- "worker.stop",
10
- "worker.abort_turn",
11
- ];
12
- const WORKER_TO_SERVER_TYPES = [
13
- "worker.hello",
14
- "worker.credential_update",
15
- "worker.ready",
16
- "worker.heartbeat",
17
- "worker.state",
18
- "worker.input_consumed",
19
- "worker.event",
20
- "worker.turn_started",
21
- "worker.question_requested",
22
- "worker.integration_tool_request",
23
- "worker.integration_tool_cancel",
24
- "worker.turn_outcome",
25
- "worker.turn_failed",
26
- "worker.lifecycle_parked",
27
- "worker.cleanup_started",
28
- "worker.cleanup_completed",
29
- "worker.failed",
30
- ];
31
- function hasMessageType(allowed, value) {
32
- return allowed.includes(value);
33
- }
34
- /**
35
- * Validate the generic IPC envelope and narrow it to the correct typed message
36
- * union member for the given direction.
37
- *
38
- * This intentionally stops at the message discriminant boundary: it validates
39
- * envelope structure + known message type, but does not deeply validate the
40
- * payload shape. Payload fields are trusted to come from same-version
41
- * leitwerk components, so malformed payloads from a buggy sender can still
42
- * pass through as typed data.
43
- */
44
- function decodeKnownMessage(msg, allowed, direction) {
45
- const validated = validateEnvelope(msg);
46
- if (!validated.ok) {
47
- return { ok: false, error: validated.error };
48
- }
49
- if (!hasMessageType(allowed, validated.envelope.type)) {
50
- return {
51
- ok: false,
52
- error: `unexpected ${direction} message type: ${validated.envelope.type}`,
53
- };
54
- }
55
- return { ok: true, message: validated.envelope };
56
- }
57
- /**
58
- * Decode a parsed envelope coming from the server side of the IPC channel.
59
- * Only envelope structure + message type are runtime-validated.
60
- */
61
- export function decodeServerToWorkerMessage(msg) {
62
- return decodeKnownMessage(msg, SERVER_TO_WORKER_TYPES, "server-to-worker");
63
- }
64
- /**
65
- * Decode a parsed envelope coming from the worker side of the IPC channel.
66
- * Only envelope structure + message type are runtime-validated.
67
- */
68
- export function decodeWorkerToServerMessage(msg) {
69
- return decodeKnownMessage(msg, WORKER_TO_SERVER_TYPES, "worker-to-server");
70
- }
71
- //# sourceMappingURL=ipc-decode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ipc-decode.js","sourceRoot":"","sources":["../src/ipc-decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAOlD,MAAM,sBAAsB,GAAG;IAC9B,cAAc;IACd,4BAA4B;IAC5B,mCAAmC;IACnC,0BAA0B;IAC1B,gCAAgC;IAChC,aAAa;IACb,aAAa;IACb,mBAAmB;CACyC,CAAC;AAE9D,MAAM,sBAAsB,GAAG;IAC9B,cAAc;IACd,0BAA0B;IAC1B,cAAc;IACd,kBAAkB;IAClB,cAAc;IACd,uBAAuB;IACvB,cAAc;IACd,qBAAqB;IACrB,2BAA2B;IAC3B,iCAAiC;IACjC,gCAAgC;IAChC,qBAAqB;IACrB,oBAAoB;IACpB,yBAAyB;IACzB,wBAAwB;IACxB,0BAA0B;IAC1B,eAAe;CAC6C,CAAC;AAE9D,SAAS,cAAc,CACtB,OAAyB,EACzB,KAAa;IAEb,OAAQ,OAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CAC1B,GAAY,EACZ,OAAoC,EACpC,SAAiB;IAEjB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO;YACN,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,cAAc,SAAS,kBAAkB,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE;SACzE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,QAA+B,EAAE,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAY;IACvD,OAAO,kBAAkB,CAAC,GAAG,EAAE,sBAAsB,EAAE,kBAAkB,CAAC,CAAC;AAC5E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAY;IACvD,OAAO,kBAAkB,CAAC,GAAG,EAAE,sBAAsB,EAAE,kBAAkB,CAAC,CAAC;AAC5E,CAAC"}
@@ -1,14 +0,0 @@
1
- import { IPC_PROTOCOL_VERSION } from "./ipc-codec.js";
2
- export function createIpcMessage(args) {
3
- return {
4
- protocol: IPC_PROTOCOL_VERSION,
5
- messageId: args.messageId,
6
- correlationId: args.correlationId,
7
- type: args.type,
8
- instanceId: args.instanceId,
9
- workerId: args.workerId,
10
- sentAt: args.sentAt ?? new Date().toISOString(),
11
- payload: args.payload,
12
- };
13
- }
14
- //# sourceMappingURL=ipc-messages.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ipc-messages.js","sourceRoot":"","sources":["../src/ipc-messages.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AA+YxE,MAAM,UAAU,gBAAgB,CAC/B,IAAiE;IAEjE,OAAO;QACN,QAAQ,EAAE,oBAAoB;QAC9B,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC/C,OAAO,EAAE,IAAI,CAAC,OAAO;KACT,CAAC;AACf,CAAC"}
@@ -1,139 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import path from "node:path";
3
- const BLOCK_SIZE = 512;
4
- function fail(message) {
5
- throw new Error(`Invalid Pi resource bundle: ${message}`);
6
- }
7
- export function validateResourceRelativePath(value) {
8
- if (!value || path.posix.isAbsolute(value) || value.includes("\\")) {
9
- fail(`unsafe path '${value}'`);
10
- }
11
- const normalized = path.posix.normalize(value);
12
- if (normalized === "." || normalized === ".." || normalized.startsWith("../")) {
13
- fail(`unsafe path '${value}'`);
14
- }
15
- return normalized;
16
- }
17
- function writeString(buffer, offset, length, value) {
18
- const encoded = Buffer.from(value, "utf8");
19
- if (encoded.length > length)
20
- fail(`header value too long: ${value}`);
21
- encoded.copy(buffer, offset);
22
- }
23
- function writeOctal(buffer, offset, length, value) {
24
- const encoded = value.toString(8).padStart(length - 1, "0");
25
- if (encoded.length > length - 1)
26
- fail(`numeric header value too large: ${value}`);
27
- writeString(buffer, offset, length - 1, encoded);
28
- buffer[offset + length - 1] = 0;
29
- }
30
- function header(name, size) {
31
- if (Buffer.byteLength(name) > 100)
32
- fail(`path exceeds canonical ustar name limit: ${name}`);
33
- const result = Buffer.alloc(BLOCK_SIZE);
34
- writeString(result, 0, 100, name);
35
- writeOctal(result, 100, 8, 0o644);
36
- writeOctal(result, 108, 8, 0);
37
- writeOctal(result, 116, 8, 0);
38
- writeOctal(result, 124, 12, size);
39
- writeOctal(result, 136, 12, 0);
40
- result.fill(0x20, 148, 156);
41
- result[156] = "0".charCodeAt(0);
42
- writeString(result, 257, 6, "ustar");
43
- writeString(result, 263, 2, "00");
44
- const sum = result.reduce((total, byte) => total + byte, 0);
45
- writeString(result, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
46
- return result;
47
- }
48
- function padding(size) {
49
- const length = (BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE;
50
- return Buffer.alloc(length);
51
- }
52
- export function sha256Digest(bytes) {
53
- return createHash("sha256").update(bytes).digest("hex");
54
- }
55
- /** Creates a deterministic, uncompressed ustar archive containing regular files only. */
56
- export function createCanonicalPiResourceBundle(files) {
57
- const seen = new Set();
58
- const normalized = files.map((file) => {
59
- const resourcePath = validateResourceRelativePath(file.path);
60
- if (seen.has(resourcePath))
61
- fail(`duplicate path '${resourcePath}'`);
62
- seen.add(resourcePath);
63
- return { path: resourcePath, content: Buffer.from(file.content) };
64
- });
65
- normalized.sort((left, right) => Buffer.compare(Buffer.from(left.path), Buffer.from(right.path)));
66
- const chunks = [];
67
- for (const file of normalized) {
68
- chunks.push(header(file.path, file.content.length), file.content, padding(file.content.length));
69
- }
70
- chunks.push(Buffer.alloc(BLOCK_SIZE * 2));
71
- const bytes = Buffer.concat(chunks);
72
- return { bytes, digest: sha256Digest(bytes) };
73
- }
74
- function readNullString(block, start, length) {
75
- const end = block.subarray(start, start + length).indexOf(0);
76
- return Buffer.from(block.subarray(start, end < 0 ? start + length : start + end)).toString("utf8");
77
- }
78
- function readOctal(block, start, length) {
79
- const raw = readNullString(block, start, length).trim();
80
- if (!/^[0-7]*$/.test(raw))
81
- fail("non-octal numeric field");
82
- return raw ? Number.parseInt(raw, 8) : 0;
83
- }
84
- function verifyChecksum(block) {
85
- const expected = readOctal(block, 148, 8);
86
- let actual = 0;
87
- for (let index = 0; index < BLOCK_SIZE; index++) {
88
- actual += index >= 148 && index < 156 ? 32 : block[index];
89
- }
90
- if (actual !== expected)
91
- fail("header checksum mismatch");
92
- }
93
- function allZero(block) {
94
- return block.every((byte) => byte === 0);
95
- }
96
- /** Parses only the narrow regular-file ustar subset emitted by this module. */
97
- export function verifyCanonicalPiResourceBundle(bytes, expectedDigest) {
98
- if (expectedDigest && sha256Digest(bytes) !== expectedDigest)
99
- fail("content digest mismatch");
100
- if (bytes.length < BLOCK_SIZE * 2 || bytes.length % BLOCK_SIZE !== 0) {
101
- fail("invalid archive length");
102
- }
103
- const files = [];
104
- const paths = new Set();
105
- let offset = 0;
106
- while (offset < bytes.length) {
107
- const block = bytes.subarray(offset, offset + BLOCK_SIZE);
108
- if (allZero(block)) {
109
- if (!allZero(bytes.subarray(offset + BLOCK_SIZE, offset + BLOCK_SIZE * 2))) {
110
- fail("missing end blocks");
111
- }
112
- if (offset + BLOCK_SIZE * 2 !== bytes.length)
113
- fail("data after end blocks");
114
- return files;
115
- }
116
- verifyChecksum(block);
117
- if (readNullString(block, 257, 6) !== "ustar")
118
- fail("unsupported tar format");
119
- const type = readNullString(block, 156, 1);
120
- if (type !== "" && type !== "0")
121
- fail(`unsupported entry type '${type}'`);
122
- if (readNullString(block, 157, 100) || readNullString(block, 345, 155)) {
123
- fail("links and ustar path prefixes are unsupported");
124
- }
125
- const name = validateResourceRelativePath(readNullString(block, 0, 100));
126
- if (paths.has(name))
127
- fail(`duplicate path '${name}'`);
128
- paths.add(name);
129
- const size = readOctal(block, 124, 12);
130
- const contentStart = offset + BLOCK_SIZE;
131
- const contentEnd = contentStart + size;
132
- if (contentEnd > bytes.length)
133
- fail("truncated file content");
134
- files.push({ path: name, content: bytes.slice(contentStart, contentEnd) });
135
- offset = contentEnd + ((BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE);
136
- }
137
- fail("missing end blocks");
138
- }
139
- //# sourceMappingURL=pi-resource-bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pi-resource-bundle.js","sour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C,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACzE,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,mBAAmB,IAAI,GAAG,CAAC,CAAC;QACtD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;QACzC,MAAM,UAAU,GAAG,YAAY,GAAG,IAAI,CAAC;QACvC,IAAI,UAAU,GAAG,KAAK,CAAC,MAAM;YAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC9D,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAC3E,MAAM,GAAG,UAAU,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC5B,CAAC"}
@@ -1,101 +0,0 @@
1
- import * as v from "valibot";
2
- import { validateResourceRelativePath } from "./pi-resource-bundle.js";
3
- export const PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION = 1;
4
- const nonBlankStringSchema = v.pipe(v.string(), v.check((value) => value.trim() !== "", "Expected a non-empty string"));
5
- const jsonObjectSchema = v.record(v.string(), v.unknown());
6
- const positiveSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1));
7
- const nonNegativeSafeIntegerSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
8
- export const piResourceManifestSchema = v.strictObject({
9
- schemaVersion: v.literal(PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION),
10
- model: v.strictObject({
11
- profileId: nonBlankStringSchema,
12
- providerId: nonBlankStringSchema,
13
- modelId: nonBlankStringSchema,
14
- thinkingLevel: nonBlankStringSchema,
15
- }),
16
- providerOptions: v.record(v.string(), nonBlankStringSchema),
17
- providerWorkerConfig: v.nullable(v.strictObject({
18
- version: positiveSafeIntegerSchema,
19
- value: jsonObjectSchema,
20
- })),
21
- declaredCredentialPaths: v.array(nonBlankStringSchema),
22
- compatibility: v.strictObject({
23
- workerApiVersion: nonBlankStringSchema,
24
- piVersion: nonBlankStringSchema,
25
- protocolVersion: v.optional(nonBlankStringSchema),
26
- }),
27
- provenance: v.array(v.strictObject({
28
- kind: v.picklist(["extension", "skill", "prompt", "generated"]),
29
- ownerExtensionId: v.nullable(nonBlankStringSchema),
30
- packageName: v.nullable(nonBlankStringSchema),
31
- snapshotPath: nonBlankStringSchema,
32
- sha256: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/)),
33
- size: nonNegativeSafeIntegerSchema,
34
- })),
35
- });
36
- function invalidManifest(message, cause) {
37
- throw new Error(`Invalid managed Pi resource snapshot: ${message}`, { cause });
38
- }
39
- /** Parses and validates the complete generated.json contract. */
40
- export function parsePiResourceManifest(raw) {
41
- let manifest;
42
- try {
43
- manifest = v.parse(piResourceManifestSchema, raw);
44
- }
45
- catch (error) {
46
- invalidManifest("generated.json does not match the resource manifest schema", error);
47
- }
48
- let declaredCredentialPaths;
49
- let provenance;
50
- try {
51
- declaredCredentialPaths = manifest.declaredCredentialPaths.map(validateResourceRelativePath);
52
- provenance = manifest.provenance.map((item) => ({
53
- ...item,
54
- snapshotPath: validateResourceRelativePath(item.snapshotPath),
55
- }));
56
- }
57
- catch (error) {
58
- invalidManifest("generated.json contains an unsafe path", error);
59
- }
60
- if (new Set(declaredCredentialPaths).size !== declaredCredentialPaths.length) {
61
- invalidManifest("generated.json declares a credential path more than once");
62
- }
63
- const provenancePaths = provenance.map((item) => item.snapshotPath);
64
- if (new Set(provenancePaths).size !== provenancePaths.length) {
65
- invalidManifest("generated.json contains duplicate provenance paths");
66
- }
67
- for (const credentialPath of declaredCredentialPaths) {
68
- if (credentialPath === "generated.json" || provenancePaths.includes(credentialPath)) {
69
- invalidManifest(`credential path '${credentialPath}' overlaps immutable snapshot content`);
70
- }
71
- }
72
- return { ...manifest, declaredCredentialPaths, provenance };
73
- }
74
- export function canonicalizeJson(value, location = "value") {
75
- if (value === null || typeof value === "string" || typeof value === "boolean")
76
- return value;
77
- if (typeof value === "number") {
78
- if (!Number.isFinite(value))
79
- throw new Error(`${location} contains a non-finite number`);
80
- return Object.is(value, -0) ? 0 : value;
81
- }
82
- if (Array.isArray(value)) {
83
- return value.map((item, index) => canonicalizeJson(item, `${location}[${index}]`));
84
- }
85
- if (typeof value !== "object")
86
- throw new Error(`${location} contains a non-JSON value`);
87
- const prototype = Object.getPrototypeOf(value);
88
- if (prototype !== Object.prototype && prototype !== null) {
89
- throw new Error(`${location} contains a non-plain object`);
90
- }
91
- return Object.fromEntries(Object.keys(value)
92
- .sort((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right)))
93
- .map((key) => [key, canonicalizeJson(value[key], `${location}.${key}`)]));
94
- }
95
- export function canonicalJsonStringify(value, location = "value") {
96
- return JSON.stringify(canonicalizeJson(value, location));
97
- }
98
- export function canonicalJsonEqual(left, right) {
99
- return canonicalJsonStringify(left) === canonicalJsonStringify(right);
100
- }
101
- //# sourceMappingURL=pi-resource-manifest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pi-resource-manifest.js","sourceRoot":"","sources":["../src/pi-resource-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAClC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,E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CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAa,EAAE,KAAc;IAC/D,OAAO,sBAAsB,CAAC,IAAI,CAAC,KAAK,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC"}
package/dist/testing.js DELETED
@@ -1,33 +0,0 @@
1
- export function createTestConfigSnapshot() {
2
- return {
3
- workers: {
4
- heartbeat_interval: "5s",
5
- turn_max_duration: "30m",
6
- turn_inactivity_timeout: "5m",
7
- turn_abort_grace_period: "5s",
8
- },
9
- pi: {
10
- agent_dir: "~/.pi/leitwerk",
11
- model_profiles: [],
12
- process_title_generation: {
13
- model_profile: null,
14
- retry: {
15
- max_attempts: 6,
16
- base_delay: "5s",
17
- max_delay: "5m",
18
- },
19
- },
20
- retry: {
21
- enabled: true,
22
- max_retries: 3,
23
- base_delay: "2s",
24
- provider: {
25
- timeout: null,
26
- max_retries: null,
27
- max_retry_delay: "60s",
28
- },
29
- },
30
- },
31
- };
32
- }
33
- //# sourceMappingURL=testing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,wBAAwB;IACvC,OAAO;QACN,OAAO,EAAE;YACR,kBAAkB,EAAE,IAAI;YACxB,iBAAiB,EAAE,KAAK;YACxB,uBAAuB,EAAE,IAAI;YAC7B,uBAAuB,EAAE,IAAI;SAC7B;QACD,EAAE,EAAE;YACH,SAAS,EAAE,gBAAgB;YAC3B,cAAc,EAAE,EAAE;YAClB,wBAAwB,EAAE;gBACzB,aAAa,EAAE,IAAI;gBACnB,KAAK,EAAE;oBACN,YAAY,EAAE,CAAC;oBACf,UAAU,EAAE,IAAI;oBAChB,SAAS,EAAE,IAAI;iBACf;aACD;YACD,KAAK,EAAE;gBACN,OAAO,EAAE,IAAI;gBACb,WAAW,EAAE,CAAC;gBACd,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE;oBACT,OAAO,EAAE,IAAI;oBACb,WAAW,EAAE,IAAI;oBACjB,eAAe,EAAE,KAAK;iBACtB;aACD;SACD;KACD,CAAC;AACH,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Compatibility version for the server ↔ worker runtime API.
3
- *
4
- * Container image labels use the same value (`leitwerk.dev/worker-api-version`).
5
- * Workers also report it in `worker.hello` so the server can fail fast when a
6
- * pod image is from an incompatible leitwerk build line.
7
- */
8
- export const WORKER_API_VERSION = "2026-08-10";
9
- //# sourceMappingURL=worker-api-version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker-api-version.js","sourceRoot":"","sources":["../src/worker-api-version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC"}