@leitwerk-dev/worker-runners 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.
Files changed (121) hide show
  1. package/dist/{chunk-6BSZBMHH.js → chunk-2P3CWUP3.js} +1 -7
  2. package/dist/chunk-2P3CWUP3.js.map +1 -0
  3. package/dist/{chunk-D56NJQ5X.js → chunk-6UZ2REWV.js} +1 -1
  4. package/dist/chunk-6UZ2REWV.js.map +1 -0
  5. package/dist/{chunk-7NF2P2VP.js → chunk-A3XSYWA5.js} +2 -2
  6. package/dist/chunk-A3XSYWA5.js.map +1 -0
  7. package/dist/{chunk-YBSX4N2K.js → chunk-BRIIMAZX.js} +13 -13
  8. package/dist/chunk-BRIIMAZX.js.map +1 -0
  9. package/dist/{chunk-OSS62AOL.js → chunk-DFPYUJIK.js} +4 -1
  10. package/dist/chunk-DFPYUJIK.js.map +1 -0
  11. package/dist/{chunk-63BBCX7B.js → chunk-H4JEE3ZT.js} +2 -1
  12. package/dist/chunk-H4JEE3ZT.js.map +1 -0
  13. package/dist/chunk-ISH4647R.js +506 -0
  14. package/dist/chunk-ISH4647R.js.map +1 -0
  15. package/dist/{chunk-ISEDLYKQ.js → chunk-V7TTFLGE.js} +30 -12
  16. package/dist/chunk-V7TTFLGE.js.map +1 -0
  17. package/dist/{chunk-YJMHXKNO.js → chunk-YDYI3BD2.js} +13 -6
  18. package/dist/chunk-YDYI3BD2.js.map +1 -0
  19. package/dist/{chunk-7X5FBNT7.js → chunk-ZGFD76I6.js} +3 -1
  20. package/dist/chunk-ZGFD76I6.js.map +1 -0
  21. package/dist/docker-client-public.d.ts +2 -0
  22. package/dist/docker-client-public.d.ts.map +1 -0
  23. package/dist/docker-client-public.js +7 -0
  24. package/dist/docker-client-public.js.map +1 -0
  25. package/dist/{docker-engine-client-CnXspTGq.d.ts → docker-engine-client-Btw6ZTXk.d.ts} +45 -18
  26. package/dist/docker-engine-client.d.ts +44 -17
  27. package/dist/docker-engine-client.d.ts.map +1 -1
  28. package/dist/docker-engine-http-client.d.ts +18 -1
  29. package/dist/docker-engine-http-client.d.ts.map +1 -1
  30. package/dist/docker-engine-http-client.js +1 -1
  31. package/dist/docker-public.d.ts +2 -0
  32. package/dist/docker-public.d.ts.map +1 -0
  33. package/dist/docker-public.js +13 -0
  34. package/dist/docker-public.js.map +1 -0
  35. package/dist/docker-worker-runner.d.ts +19 -9
  36. package/dist/docker-worker-runner.d.ts.map +1 -1
  37. package/dist/docker-worker-runner.js +6 -6
  38. package/dist/index.d.ts +2 -12
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -260
  41. package/dist/index.js.map +1 -1
  42. package/dist/{kubernetes-api-client-DD2YevYP.d.ts → kubernetes-api-client-CEe7pHC4.d.ts} +212 -88
  43. package/dist/kubernetes-api-client.d.ts +80 -0
  44. package/dist/kubernetes-api-client.d.ts.map +1 -1
  45. package/dist/kubernetes-client-public.d.ts +2 -0
  46. package/dist/kubernetes-client-public.d.ts.map +1 -0
  47. package/dist/kubernetes-client-public.js +9 -0
  48. package/dist/kubernetes-client-public.js.map +1 -0
  49. package/dist/kubernetes-http-client.d.ts +11 -0
  50. package/dist/kubernetes-http-client.d.ts.map +1 -1
  51. package/dist/kubernetes-http-client.js +5 -500
  52. package/dist/kubernetes-http-client.js.map +1 -1
  53. package/dist/kubernetes-manifests.d.ts +151 -8
  54. package/dist/kubernetes-manifests.d.ts.map +1 -1
  55. package/dist/kubernetes-public.d.ts +2 -0
  56. package/dist/kubernetes-public.d.ts.map +1 -0
  57. package/dist/kubernetes-public.js +13 -0
  58. package/dist/kubernetes-public.js.map +1 -0
  59. package/dist/kubernetes-volume-pool-api.d.ts +46 -1
  60. package/dist/kubernetes-volume-pool-api.d.ts.map +1 -1
  61. package/dist/kubernetes-volume-pool.d.ts +18 -1
  62. package/dist/kubernetes-volume-pool.d.ts.map +1 -1
  63. package/dist/kubernetes-worker-runner.d.ts +27 -11
  64. package/dist/kubernetes-worker-runner.d.ts.map +1 -1
  65. package/dist/kubernetes-worker-runner.js +6 -6
  66. package/dist/local-public.d.ts +2 -0
  67. package/dist/local-public.d.ts.map +1 -0
  68. package/dist/local-public.js +11 -0
  69. package/dist/local-public.js.map +1 -0
  70. package/dist/local-worker-runner.d.ts +15 -8
  71. package/dist/local-worker-runner.d.ts.map +1 -1
  72. package/dist/local-worker-runner.js +2 -2
  73. package/dist/process-volume-retention.d.ts +15 -0
  74. package/dist/process-volume-retention.d.ts.map +1 -1
  75. package/dist/runner-utils.d.ts +5 -0
  76. package/dist/runner-utils.d.ts.map +1 -1
  77. package/dist/session-transfer-helper-cli.js +1 -1
  78. package/dist/session-transfer-helper.d.ts +3 -0
  79. package/dist/session-transfer-helper.d.ts.map +1 -1
  80. package/dist/session-transfer-helper.js +1 -1
  81. package/dist/types-public.d.ts +3 -0
  82. package/dist/types-public.d.ts.map +1 -0
  83. package/dist/types-public.js +7 -0
  84. package/dist/types-public.js.map +1 -0
  85. package/dist/types.d.ts +87 -29
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/types.js +1 -1
  88. package/dist/worker-labels.d.ts +29 -2
  89. package/dist/worker-labels.d.ts.map +1 -1
  90. package/package.json +23 -28
  91. package/src/docker-client-public.ts +1 -0
  92. package/src/docker-engine-client.ts +59 -20
  93. package/src/docker-engine-http-client.ts +13 -0
  94. package/src/docker-public.ts +1 -0
  95. package/src/docker-worker-runner.ts +19 -9
  96. package/src/index.ts +0 -98
  97. package/src/kubernetes-api-client.ts +112 -6
  98. package/src/kubernetes-client-public.ts +1 -0
  99. package/src/kubernetes-http-client.ts +11 -0
  100. package/src/kubernetes-manifests.ts +211 -16
  101. package/src/kubernetes-public.ts +1 -0
  102. package/src/kubernetes-volume-pool-api.ts +58 -4
  103. package/src/kubernetes-volume-pool.ts +19 -1
  104. package/src/kubernetes-worker-runner.ts +54 -14
  105. package/src/local-public.ts +1 -0
  106. package/src/local-worker-runner.ts +15 -8
  107. package/src/process-volume-retention.ts +15 -0
  108. package/src/runner-utils.ts +8 -1
  109. package/src/session-transfer-helper.ts +3 -0
  110. package/src/types-public.ts +12 -0
  111. package/src/types.ts +90 -30
  112. package/src/worker-labels.ts +29 -2
  113. package/dist/chunk-63BBCX7B.js.map +0 -1
  114. package/dist/chunk-6BSZBMHH.js.map +0 -1
  115. package/dist/chunk-7NF2P2VP.js.map +0 -1
  116. package/dist/chunk-7X5FBNT7.js.map +0 -1
  117. package/dist/chunk-D56NJQ5X.js.map +0 -1
  118. package/dist/chunk-ISEDLYKQ.js.map +0 -1
  119. package/dist/chunk-OSS62AOL.js.map +0 -1
  120. package/dist/chunk-YBSX4N2K.js.map +0 -1
  121. package/dist/chunk-YJMHXKNO.js.map +0 -1
@@ -66,40 +66,64 @@ function boundedKubernetesStartDiagnostic(
66
66
  );
67
67
  }
68
68
 
69
+ /** @internal */
69
70
  export interface KubernetesWorkerRunnerOptions {
70
- preProvision?: { count: number; onError?: () => void };
71
+ /** @internal */
72
+ preProvision?: {
73
+ /** @internal */
74
+ count: number;
75
+ /** @internal */
76
+ onError?: () => void;
77
+ };
78
+ /** @internal */
71
79
  client: KubernetesApiClient;
72
- /** Prefix used to derive one Kubernetes namespace per process instance. */
80
+ /** Prefix used to derive one Kubernetes namespace per process instance. @internal */
73
81
  processNamespacePrefix: string;
82
+ /** @internal */
74
83
  volume: KubernetesProcessVolumeSpec;
75
- /** Storage and Pod wiring for process definitions that require private Docker. */
76
- docker?: KubernetesDockerPodSpecOptions & { processStorageClassName: string };
77
- /** Maximum wait after deletion before replacement is rejected. */
84
+ /** Storage and Pod wiring for process definitions that require private Docker. @internal */
85
+ docker?: KubernetesDockerPodSpecOptions & {
86
+ /** @internal */
87
+ processStorageClassName: string;
88
+ };
89
+ /** Maximum wait after deletion before replacement is rejected. @internal */
78
90
  podDisappearanceTimeoutMs?: number;
91
+ /** @internal */
79
92
  podDisappearancePollIntervalMs?: number;
80
- /** Test seam for bounded disappearance polling. */
93
+ /** Test seam for bounded disappearance polling. @internal */
81
94
  delay?: (ms: number) => Promise<void>;
82
- /** Server-local CA bundle copied into each process namespace for worker TLS trust. */
95
+ /** Server-local CA bundle copied into each process namespace for worker TLS trust. @internal */
83
96
  serverCaFile?: string;
84
- /** Namespace containing operator-managed source image-pull Secrets. */
97
+ /** Namespace containing operator-managed source image-pull Secrets. @internal */
85
98
  serverNamespace?: string;
86
- /** Docker registry Secrets copied into every process namespace. */
87
- imagePullSecretCopies?: Array<{ sourceName: string; targetName: string }>;
99
+ /** Docker registry Secrets copied into every process namespace. @internal */
100
+ imagePullSecretCopies?: Array<{
101
+ /** @internal */
102
+ sourceName: string;
103
+ /** @internal */
104
+ targetName: string;
105
+ }>;
106
+ /** @internal */
88
107
  pod?: Omit<KubernetesPodSpecOptions, "namespace">;
89
- /** Stable internal URL used by PVC export helpers. */
108
+ /** Stable internal URL used by PVC export helpers. @internal */
90
109
  serverUrl?: string;
91
- /** Trusted image containing the bundled session-transfer helper entrypoint. */
110
+ /** Trusted image containing the bundled session-transfer helper entrypoint. @internal */
92
111
  exporterImage?: string;
93
- /** Pull policy for the trusted helper image. */
112
+ /** Pull policy for the trusted helper image. @internal */
94
113
  exporterImagePullPolicy?: string;
95
- /** Server-owned relay registry used by PVC export helpers. */
114
+ /** Server-owned relay registry used by PVC export helpers. @internal */
96
115
  helperRelays?: ProcessStateExportHelperRelayProvider;
97
116
  }
98
117
 
118
+ /** @internal */
99
119
  export function createKubernetesWorkerRunner(options: KubernetesWorkerRunnerOptions): {
120
+ /** @internal */
100
121
  runner: WorkerRunner<IsolatedStartWorkerInput>;
122
+ /** @internal */
101
123
  volume: ProcessVolume;
124
+ /** @internal */
102
125
  exporter: ProcessStateExporter;
126
+ /** @internal */
103
127
  volumePool?: ReturnType<typeof createKubernetesVolumePool>;
104
128
  } {
105
129
  if (!options.serverUrl || !options.exporterImage || !options.helperRelays) {
@@ -123,7 +147,23 @@ export function createKubernetesWorkerRunner(options: KubernetesWorkerRunnerOpti
123
147
  const namespaceManifest = buildKubernetesProcessNamespaceManifest({
124
148
  instanceId,
125
149
  processNamespacePrefix: options.processNamespacePrefix,
150
+ ...(requirements?.docker && options.docker?.gvisor
151
+ ? { extraLabels: { "pod-security.kubernetes.io/enforce": "privileged" } }
152
+ : {}),
126
153
  });
154
+ if (requirements?.docker && options.docker) {
155
+ if (!client.getPersistentVolumeClaim)
156
+ throw new Error("Docker requires process storage inspection");
157
+ const existing = await client.getPersistentVolumeClaim(
158
+ kubernetesProcessPvcName(instanceId, options.volume.namePrefix),
159
+ namespaceManifest.metadata.name,
160
+ );
161
+ if (existing && existing.storageClass !== options.docker.processStorageClassName) {
162
+ throw new Error(
163
+ "Docker requires the configured block StorageClass; preserve and migrate the existing process volume before resuming",
164
+ );
165
+ }
166
+ }
127
167
  await client.ensureNamespace(namespaceManifest);
128
168
  const copySecrets = (options.imagePullSecretCopies ?? []).map(async (copy) => {
129
169
  const dockerConfigJson = await client.getDockerConfigJsonSecret(
@@ -0,0 +1 @@
1
+ export { createLocalWorkerRunner, preflightHostDocker } from "./local-worker-runner.js";
@@ -16,27 +16,30 @@ import type {
16
16
  WorkerUnitRef,
17
17
  } from "./types.js";
18
18
 
19
+ /** @internal */
19
20
  export const DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER = "@leitwerk-dev/worker/worker-entry";
20
21
 
22
+ /** @internal */
21
23
  export interface LocalWorkerRunnerOptions {
22
- /** Command used to launch the worker. Defaults to `node`. */
24
+ /** Command used to launch the worker. Defaults to `node`. @internal */
23
25
  command?: string;
24
- /** Worker entry args. The default package subpath is resolved to the installed entry file. */
26
+ /** Worker entry args. The default package subpath is resolved to the installed entry file. @internal */
25
27
  args?: readonly string[];
26
- /** Working directory for the spawned worker. Defaults to the installed server package dir. */
28
+ /** Working directory for the spawned worker. Defaults to the installed server package dir. @internal */
27
29
  cwd?: string;
28
- /** Process storage roots used by the read-only session exporter. */
30
+ /** Process storage roots used by the read-only session exporter. @internal */
29
31
  processWorkspacesDir?: string;
32
+ /** @internal */
30
33
  treeFilesDir?: string;
31
- /** Explicit acknowledgement that Docker processes inherit host Docker authority. */
34
+ /** Explicit acknowledgement that Docker processes inherit host Docker authority. @internal */
32
35
  allowHostDocker?: boolean;
33
- /** Test seam. Production uses node's spawn directly. */
36
+ /** Test seam. Production uses node's spawn directly. @internal */
34
37
  localWorkerSpawnImpl?: typeof spawn;
35
- /** Test seam for the shared host-Docker preflight. */
38
+ /** Test seam for the shared host-Docker preflight. @internal */
36
39
  dockerPreflightImpl?: (timeoutMs: number) => Promise<void>;
37
40
  }
38
41
 
39
- /** Verifies that the inherited Docker CLI context can reach its daemon. */
42
+ /** Verifies that the inherited Docker CLI context can reach its daemon. @internal */
40
43
  export async function preflightHostDocker(timeoutMs: number): Promise<void> {
41
44
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
42
45
  throw new Error("Docker preflight requires a positive startup timeout");
@@ -83,6 +86,7 @@ function resolveDefaultWorkerEntryPath(): string {
83
86
  return fileURLToPath(import.meta.resolve(DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER));
84
87
  }
85
88
 
89
+ /** @internal */
86
90
  export function resolveLocalWorkerSpawnArgs(args: readonly string[]): string[] {
87
91
  return args[0] === DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER
88
92
  ? [resolveDefaultWorkerEntryPath(), ...args.slice(1)]
@@ -101,8 +105,11 @@ function exitInfo(code: number | null, signal: NodeJS.Signals | null): WorkerExi
101
105
  * boundary, has no restart adoption, and ignores image/resource profile semantics.
102
106
  * Docker and Kubernetes remain the contract-defining production runners.
103
107
  */
108
+ /** @internal */
104
109
  export function createLocalWorkerRunner(options: LocalWorkerRunnerOptions): {
110
+ /** @internal */
105
111
  runner: WorkerRunner<LocalStartWorkerInput>;
112
+ /** @internal */
106
113
  exporter: ProcessStateExporter;
107
114
  } {
108
115
  const command = options.command ?? "node";
@@ -2,15 +2,23 @@ import type { ProcessInstance } from "@leitwerk-dev/domain";
2
2
  import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
3
3
  import type { ProcessVolume } from "./types.js";
4
4
 
5
+ /** @internal */
5
6
  export interface ProcessVolumeRetentionPolicy {
7
+ /** @internal */
6
8
  completedProcessRetention: string;
9
+ /** @internal */
7
10
  errorProcessRetention: string;
8
11
  }
9
12
 
13
+ /** @internal */
10
14
  export interface PlanProcessVolumeRetentionCleanupInput {
15
+ /** @internal */
11
16
  processes: readonly ProcessInstance[];
17
+ /** @internal */
12
18
  now: Date;
19
+ /** @internal */
13
20
  policy: ProcessVolumeRetentionPolicy;
21
+ /** @internal */
14
22
  alreadyReleased?: ReadonlySet<string>;
15
23
  }
16
24
 
@@ -26,6 +34,7 @@ function closedAtMs(process: ProcessInstance): number | null {
26
34
  return Number.isFinite(parsed) ? parsed : null;
27
35
  }
28
36
 
37
+ /** @internal */
29
38
  export function planProcessVolumeRetentionCleanup(
30
39
  input: PlanProcessVolumeRetentionCleanupInput,
31
40
  ): string[] {
@@ -55,11 +64,17 @@ export function planProcessVolumeRetentionCleanup(
55
64
  return candidates;
56
65
  }
57
66
 
67
+ /** @internal */
58
68
  export async function cleanupRetainedProcessVolumes(input: {
69
+ /** @internal */
59
70
  volume?: ProcessVolume;
71
+ /** @internal */
60
72
  processes: readonly ProcessInstance[];
73
+ /** @internal */
61
74
  now: Date;
75
+ /** @internal */
62
76
  policy: ProcessVolumeRetentionPolicy;
77
+ /** @internal */
63
78
  alreadyReleased?: ReadonlySet<string>;
64
79
  }): Promise<string[]> {
65
80
  const candidates = planProcessVolumeRetentionCleanup(input);
@@ -7,10 +7,12 @@ import type { WorkerExitInfo, WorkerUnit, WorkerUnitRef } from "./types.js";
7
7
  * `WorkerUnit.onExit` callbacks. This utility captures the identical map +
8
8
  * fire/wrap logic and leaves only the unit-keying to each runner.
9
9
  */
10
+ /** @internal */
10
11
  export class UnitExitNotifier {
11
12
  private readonly listeners = new Map<string, Array<(info: WorkerExitInfo) => void>>();
12
13
  private readonly exited = new Map<string, WorkerExitInfo>();
13
14
 
15
+ /** @internal */
14
16
  onExit(key: string, listener: (info: WorkerExitInfo) => void): void {
15
17
  const exit = this.exited.get(key);
16
18
  if (exit) {
@@ -22,6 +24,7 @@ export class UnitExitNotifier {
22
24
  this.listeners.set(key, list);
23
25
  }
24
26
 
27
+ /** @internal */
25
28
  fireExit(key: string, info: WorkerExitInfo): void {
26
29
  if (this.exited.has(key)) return;
27
30
  this.exited.set(key, info);
@@ -31,10 +34,14 @@ export class UnitExitNotifier {
31
34
  for (const listener of list.splice(0)) listener(info);
32
35
  }
33
36
 
37
+ /** @internal */
34
38
  wrapUnit<T extends WorkerUnitRef>(
35
39
  ref: T,
36
40
  key: string,
37
- options?: { replacementHandoff?: WorkerUnit["replacementHandoff"] },
41
+ options?: {
42
+ /** @internal */
43
+ replacementHandoff?: WorkerUnit["replacementHandoff"];
44
+ },
38
45
  ): WorkerUnit {
39
46
  return {
40
47
  ...ref,
@@ -5,8 +5,10 @@ import {
5
5
  prepareTransferArchive,
6
6
  } from "@leitwerk-dev/session-transfer";
7
7
 
8
+ /** @internal */
8
9
  export const SESSION_TRANSFER_HELPER_ENTRY_PATH =
9
10
  "/app/packages/worker-runners/dist/session-transfer-helper-cli.js";
11
+ /** @internal */
10
12
  export const SESSION_TRANSFER_HELPER_MOUNT_PATH = "/state";
11
13
 
12
14
  interface HelperEnvironment {
@@ -73,6 +75,7 @@ async function readHelperSpec(environment: HelperEnvironment) {
73
75
  return parseSessionTransferHelperSpec(await response.json());
74
76
  }
75
77
 
78
+ /** @internal */
76
79
  export async function runSessionTransferHelper(): Promise<void> {
77
80
  const environment = readEnvironment();
78
81
  const spec = await readHelperSpec(environment);
@@ -0,0 +1,12 @@
1
+ export type {
2
+ ProcessVolume,
3
+ ResolvedWorkerImage,
4
+ StopWorkerOptions,
5
+ WorkerExitInfo,
6
+ WorkerRunner,
7
+ WorkerStartObserver,
8
+ WorkerUnit,
9
+ WorkerUnitDescriptor,
10
+ WorkerUnitRef,
11
+ } from "./types.js";
12
+ export { WorkerStartDiagnosticError } from "./types.js";
package/src/types.ts CHANGED
@@ -24,70 +24,97 @@ import type {
24
24
  * state over the protocol (the session-snapshot exchange), never by reading the
25
25
  * volume, which keeps every run mode symmetric.
26
26
  */
27
+ /** @internal */
27
28
  export interface VolumeRef {
29
+ /** @internal */
28
30
  instanceId: string;
29
- /** Runtime-specific identifier (host path, named volume, PVC name). */
31
+ /** Runtime-specific identifier (host path, named volume, PVC name). @internal */
30
32
  id: string;
31
- /** Path inside the worker container where the volume is mounted. */
33
+ /** Path inside the worker container where the volume is mounted. @internal */
32
34
  mountPath: string;
33
- /** Runtime-specific namespace/project for the volume (Kubernetes process namespace). */
35
+ /** Runtime-specific namespace/project for the volume (Kubernetes process namespace). @internal */
34
36
  namespace?: string;
35
37
  }
36
38
 
39
+ /** @internal */
37
40
  export interface ProcessVolumeRequirements {
38
- /** New Kubernetes PVC capacity. Existing volumes are unchanged; other runners ignore it. */
41
+ /** New Kubernetes PVC capacity. Existing volumes are unchanged; other runners ignore it. @internal */
39
42
  size?: string;
40
- /** Select storage compatible with a private Docker daemon. */
43
+ /** Select storage compatible with a private Docker daemon. @internal */
41
44
  docker?: boolean;
42
45
  }
43
46
 
47
+ /** @internal */
44
48
  export type ProcessStateExportPreflight = SessionTransferPreflight;
49
+ /** @internal */
45
50
  export type ProcessStateExportHelperReport = SessionTransferPreflightReport;
46
51
 
47
- /** Server-owned, credential-scoped relay used by isolated export helpers. */
52
+ /** Server-owned, credential-scoped relay used by isolated export helpers. @internal */
48
53
  export interface ProcessStateExportHelperRelay {
54
+ /** @internal */
49
55
  readonly exportId: string;
56
+ /** @internal */
50
57
  readonly credential: string;
58
+ /** @internal */
51
59
  waitForPreflight(signal?: AbortSignal): Promise<ProcessStateExportHelperReport>;
60
+ /** @internal */
52
61
  activateStream(): Readable;
62
+ /** @internal */
53
63
  fail(error: Error): void;
54
64
  }
55
65
 
66
+ /** @internal */
56
67
  export interface PreparedProcessStateExport {
68
+ /** @internal */
57
69
  manifest: LeitwerkTransferManifestV1;
70
+ /** @internal */
58
71
  preflight: ProcessStateExportPreflight;
59
- stream(input: { signal?: AbortSignal }): Readable;
72
+ /** @internal */
73
+ stream(input: {
74
+ /** @internal */
75
+ signal?: AbortSignal;
76
+ }): Readable;
60
77
  }
61
78
 
62
- /** Purpose-specific read-only export seam. It never creates a worker lease. */
79
+ /** Purpose-specific read-only export seam. It never creates a worker lease. @internal */
63
80
  export interface ProcessStateExporter {
81
+ /** @internal */
64
82
  prepare(input: {
83
+ /** @internal */
65
84
  instanceId: string;
85
+ /** @internal */
66
86
  manifest: LeitwerkTransferManifestV1;
87
+ /** @internal */
67
88
  limits: SessionTransferLimits;
89
+ /** @internal */
68
90
  signal?: AbortSignal;
69
91
  }): Promise<PreparedProcessStateExport>;
70
- /** Removes stale runner-specific export helpers after restart. */
92
+ /** Removes stale runner-specific export helpers after restart. @internal */
71
93
  reconcile(): Promise<void>;
72
94
  }
73
95
 
96
+ /** @internal */
74
97
  export interface ProcessStateExportHelperRelayProvider {
98
+ /** @internal */
75
99
  create(input: {
100
+ /** @internal */
76
101
  instanceId: string;
102
+ /** @internal */
77
103
  manifest: LeitwerkTransferManifestV1;
78
104
  }): ProcessStateExportHelperRelay;
79
105
  }
80
106
 
107
+ /** @internal */
81
108
  export interface ProcessVolume {
82
- /** Idempotently provisions durable storage for a process instance. */
109
+ /** Idempotently provisions durable storage for a process instance. @internal */
83
110
  ensure(
84
111
  instanceId: string,
85
112
  requirements?: ProcessVolumeRequirements,
86
113
  observer?: WorkerStartObserver,
87
114
  ): Promise<VolumeRef>;
88
- /** Retention cleanup only. Stopping a worker never calls this. */
115
+ /** Retention cleanup only. Stopping a worker never calls this. @internal */
89
116
  release(instanceId: string): Promise<void>;
90
- /** Permanently deletes every runner-managed resource owned by a deleted process. */
117
+ /** Permanently deletes every runner-managed resource owned by a deleted process. @internal */
91
118
  deleteProcessResources(instanceId: string): Promise<void>;
92
119
  }
93
120
 
@@ -95,28 +122,38 @@ export interface ProcessVolume {
95
122
  * Output of runtime-profile selection. MVP resolves to a single configured
96
123
  * worker image; repository branch content must never select an image.
97
124
  */
125
+ /** @internal */
98
126
  export interface ResolvedWorkerImage {
99
- /** Fully qualified image reference, ideally digest-pinned. */
127
+ /** Fully qualified image reference, ideally digest-pinned. @internal */
100
128
  reference: string;
101
129
  }
102
130
 
131
+ /** @internal */
103
132
  export interface WorkerResourceLimits {
133
+ /** @internal */
104
134
  cpu?: string;
135
+ /** @internal */
105
136
  memory?: string;
106
137
  }
107
138
 
139
+ /** @internal */
108
140
  export interface WorkerUnitRef {
141
+ /** @internal */
109
142
  instanceId: string;
143
+ /** @internal */
110
144
  workerId: string;
111
- /** Runtime-specific handle id (container id, pod name). */
145
+ /** Runtime-specific handle id (container id, pod name). @internal */
112
146
  unitId: string;
113
- /** Runtime-specific namespace/project for the unit (Kubernetes process namespace). */
147
+ /** Runtime-specific namespace/project for the unit (Kubernetes process namespace). @internal */
114
148
  namespace?: string;
115
149
  }
116
150
 
151
+ /** @internal */
117
152
  export class WorkerStartDiagnosticError extends Error {
153
+ /** @internal */
118
154
  readonly publicDiagnostic: string;
119
155
 
156
+ /** @internal */
120
157
  constructor(publicDiagnostic: string, cause?: unknown) {
121
158
  super("Worker runtime start failed", { cause });
122
159
  this.name = "WorkerStartDiagnosticError";
@@ -124,80 +161,103 @@ export class WorkerStartDiagnosticError extends Error {
124
161
  }
125
162
  }
126
163
 
164
+ /** @internal */
127
165
  export interface WorkerExitInfo {
128
- /** Process exit code when the runtime reports one. */
166
+ /** Process exit code when the runtime reports one. @internal */
129
167
  exitCode: number | null;
130
- /** Termination signal when the runtime reports one. */
168
+ /** Termination signal when the runtime reports one. @internal */
131
169
  signal: string | null;
132
- /** True when the runtime killed the unit for exceeding memory limits. */
170
+ /** True when the runtime killed the unit for exceeding memory limits. @internal */
133
171
  oomKilled?: boolean;
134
- /** Human-readable reason surfaced by the runtime, if any. */
172
+ /** Human-readable reason surfaced by the runtime, if any. @internal */
135
173
  reason?: string;
136
174
  }
137
175
 
176
+ /** @internal */
138
177
  export interface WorkerUnit extends WorkerUnitRef {
139
- /** Require successful runtime removal before the supervisor permits replacement. */
178
+ /** Require successful runtime removal before the supervisor permits replacement. @internal */
140
179
  replacementHandoff?: "stop-before-replacement";
141
- /** Maps physical worker exit into the supervisor's existing failure paths. */
180
+ /** Maps physical worker exit into the supervisor's existing failure paths. @internal */
142
181
  onExit(listener: (info: WorkerExitInfo) => void): void;
143
182
  }
144
183
 
184
+ /** @internal */
145
185
  export interface WorkerUnitDescriptor extends WorkerUnitRef {
186
+ /** @internal */
146
187
  observedState?: "running" | "pending" | "terminal" | "unknown";
147
188
  }
148
189
 
190
+ /** @internal */
149
191
  interface StartWorkerInputBase {
192
+ /** @internal */
150
193
  instanceId: string;
194
+ /** @internal */
151
195
  workerId: string;
196
+ /** @internal */
152
197
  serverEpoch: string;
153
- /** Runtime-profile selection output; MVP = single image. */
198
+ /** Runtime-profile selection output; MVP = single image. @internal */
154
199
  image: ResolvedWorkerImage;
155
- /** Server URL, ids, connect token, `PI_CODING_AGENT_DIR`, etc. */
200
+ /** Server URL, ids, connect token, `PI_CODING_AGENT_DIR`, etc. @internal */
156
201
  env: Record<string, string>;
157
- /** Start the image's private Docker daemon before the worker. */
202
+ /** Start the image's private Docker daemon before the worker. @internal */
158
203
  docker: boolean;
204
+ /** @internal */
159
205
  resources?: WorkerResourceLimits;
206
+ /** @internal */
160
207
  resourceRequests?: WorkerResourceLimits;
161
208
  }
162
209
 
163
- /** Start input for the best-effort local runner, which uses configured host storage. */
210
+ /** Start input for the best-effort local runner, which uses configured host storage. @internal */
164
211
  export interface LocalStartWorkerInput extends StartWorkerInputBase {
212
+ /** @internal */
165
213
  runnerKind: "local";
214
+ /** @internal */
166
215
  volume?: never;
167
216
  }
168
217
 
169
- /** Start input for isolated runners, whose durable process volume is mandatory. */
218
+ /** Start input for isolated runners, whose durable process volume is mandatory. @internal */
170
219
  export interface IsolatedStartWorkerInput extends StartWorkerInputBase {
220
+ /** @internal */
171
221
  runnerKind: "isolated";
222
+ /** @internal */
172
223
  volume: VolumeRef;
173
224
  }
174
225
 
226
+ /** @internal */
175
227
  export type StartWorkerInput = LocalStartWorkerInput | IsolatedStartWorkerInput;
176
228
 
229
+ /** @internal */
177
230
  export interface StopWorkerOptions {
178
- /** Grace period before forceful termination. The volume is always kept. */
231
+ /** Grace period before forceful termination. The volume is always kept. @internal */
179
232
  graceMs: number;
180
233
  }
181
234
 
235
+ /** @internal */
182
236
  export type WorkerStartPhase = "preparing_runtime" | "allocating_runtime" | "starting_runtime";
183
237
 
238
+ /** @internal */
184
239
  export interface WorkerStartObserver {
240
+ /** @internal */
185
241
  observe?(
186
242
  observation: Omit<
187
243
  import("@leitwerk-dev/domain").StartupObservation,
188
244
  "workerLeaseId" | "turnRecordId"
189
245
  >,
190
246
  ): void;
247
+ /** @internal */
191
248
  shouldStop?(): boolean;
249
+ /** @internal */
192
250
  report(phase: WorkerStartPhase): void;
193
251
  }
194
252
 
253
+ /** @internal */
195
254
  export interface WorkerRunner<TStartInput extends StartWorkerInput = StartWorkerInput> {
255
+ /** @internal */
196
256
  start(input: TStartInput, observer?: WorkerStartObserver): Promise<WorkerUnit>;
197
- /** Stops the unit but keeps the process volume for resume. */
257
+ /** Stops the unit but keeps the process volume for resume. @internal */
198
258
  stop(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void>;
199
- /** Adoption scan: lists labelled worker units. */
259
+ /** Adoption scan: lists labelled worker units. @internal */
200
260
  list(): Promise<WorkerUnitDescriptor[]>;
201
- /** Reconnects to a live unit discovered by {@link WorkerRunner.list}. */
261
+ /** Reconnects to a live unit discovered by {@link WorkerRunner.list}. @internal */
202
262
  adopt(descriptor: WorkerUnitDescriptor, observer?: WorkerStartObserver): Promise<WorkerUnit>;
203
263
  }
@@ -8,24 +8,41 @@
8
8
  * rather than in a runtime-specific body.
9
9
  */
10
10
 
11
+ /** @internal */
11
12
  export const WORKER_LABEL_MANAGED_BY = "leitwerk.dev/managed-by";
13
+ /** @internal */
12
14
  export const WORKER_LABEL_COMPONENT = "leitwerk.dev/component";
15
+ /** @internal */
13
16
  export const WORKER_LABEL_INSTANCE_ID = "leitwerk.dev/instance-id";
17
+ /** @internal */
14
18
  export const WORKER_LABEL_WORKER_ID = "leitwerk.dev/worker-id";
19
+ /** @internal */
15
20
  export const WORKER_LABEL_SERVER_EPOCH = "leitwerk.dev/server-epoch";
16
21
 
22
+ /** @internal */
17
23
  export const WORKER_LABEL_MANAGED_BY_VALUE = "leitwerk";
24
+ /** @internal */
18
25
  export const WORKER_LABEL_COMPONENT_VALUE = "worker";
26
+ /** @internal */
19
27
  export const PROCESS_NAMESPACE_COMPONENT_VALUE = "process-namespace";
28
+ /** @internal */
20
29
  export const PROCESS_VOLUME_COMPONENT_VALUE = "process-volume";
30
+ /** @internal */
21
31
  export const PROCESS_SERVER_CA_COMPONENT_VALUE = "server-ca";
32
+ /** @internal */
22
33
  export const PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE = "image-pull-secret";
34
+ /** @internal */
23
35
  export const EXPORT_HELPER_COMPONENT_VALUE = "session-export-helper";
36
+ /** @internal */
24
37
  export const EXPORT_HELPER_LABEL_EXPORT_ID = "leitwerk.dev/export-id";
25
38
 
39
+ /** @internal */
26
40
  export interface WorkerUnitIdentity {
41
+ /** @internal */
27
42
  instanceId: string;
43
+ /** @internal */
28
44
  workerId: string;
45
+ /** @internal */
29
46
  serverEpoch: string;
30
47
  }
31
48
 
@@ -33,6 +50,7 @@ export interface WorkerUnitIdentity {
33
50
  * Builds the canonical label set for a worker unit. Extra labels are merged in
34
51
  * but can never override the managed identity keys.
35
52
  */
53
+ /** @internal */
36
54
  export function buildWorkerUnitLabels(
37
55
  identity: WorkerUnitIdentity,
38
56
  extra: Record<string, string> = {},
@@ -52,9 +70,12 @@ export function buildWorkerUnitLabels(
52
70
  * intentionally omit worker-id and server-epoch because the resources outlive a
53
71
  * specific worker lease and are not adoption targets.
54
72
  */
73
+ /** @internal */
55
74
  export function buildProcessResourceLabels(
56
75
  args: {
76
+ /** @internal */
57
77
  instanceId: string;
78
+ /** @internal */
58
79
  component:
59
80
  | typeof PROCESS_NAMESPACE_COMPONENT_VALUE
60
81
  | typeof PROCESS_VOLUME_COMPONENT_VALUE
@@ -79,12 +100,16 @@ function managedResourceLabelSelector(component: string): Record<string, string>
79
100
  };
80
101
  }
81
102
 
103
+ /** @internal */
82
104
  export function managedProcessNamespaceLabelSelector(): Record<string, string> {
83
105
  return managedResourceLabelSelector(PROCESS_NAMESPACE_COMPONENT_VALUE);
84
106
  }
85
107
 
108
+ /** @internal */
86
109
  export function buildExportHelperLabels(input: {
110
+ /** @internal */
87
111
  instanceId: string;
112
+ /** @internal */
88
113
  exportId: string;
89
114
  }): Record<string, string> {
90
115
  return {
@@ -95,11 +120,12 @@ export function buildExportHelperLabels(input: {
95
120
  };
96
121
  }
97
122
 
123
+ /** @internal */
98
124
  export function managedExportHelperLabelSelector(): Record<string, string> {
99
125
  return managedResourceLabelSelector(EXPORT_HELPER_COMPONENT_VALUE);
100
126
  }
101
127
 
102
- /** True when the labels identify an leitwerk-managed worker unit. */
128
+ /** True when the labels identify an leitwerk-managed worker unit. @internal */
103
129
  export function isManagedWorkerUnitLabels(labels: Record<string, string>): boolean {
104
130
  return (
105
131
  labels[WORKER_LABEL_MANAGED_BY] === WORKER_LABEL_MANAGED_BY_VALUE &&
@@ -111,6 +137,7 @@ export function isManagedWorkerUnitLabels(labels: Record<string, string>): boole
111
137
  * Recovers the worker identity from a unit's labels, or `null` when the labels
112
138
  * do not describe a complete leitwerk-managed worker.
113
139
  */
140
+ /** @internal */
114
141
  export function parseWorkerUnitIdentity(labels: Record<string, string>): WorkerUnitIdentity | null {
115
142
  if (!isManagedWorkerUnitLabels(labels)) {
116
143
  return null;
@@ -124,7 +151,7 @@ export function parseWorkerUnitIdentity(labels: Record<string, string>): WorkerU
124
151
  return { instanceId, workerId, serverEpoch };
125
152
  }
126
153
 
127
- /** Label selector for listing managed worker units in a runtime query. */
154
+ /** Label selector for listing managed worker units in a runtime query. @internal */
128
155
  export function managedWorkerLabelSelector(): Record<string, string> {
129
156
  return managedResourceLabelSelector(WORKER_LABEL_COMPONENT_VALUE);
130
157
  }