@ship.zone/runner 0.1.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.
@@ -0,0 +1,689 @@
1
+ #!/usr/bin/env -S deno run --allow-env --allow-net --allow-read --allow-write --allow-run
2
+ export type TRunnerFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface IRunnerApiClientOptions { controlPlaneUrl: string;
4
+ allowInsecureLoopback: boolean;
5
+ requestTimeoutMs: number;
6
+ sourceTransferTimeoutMs?: number;
7
+ artifactUploadTimeoutMs?: number;
8
+ cacheTransferTimeoutMs?: number;
9
+ maximumResponseBytes: number;
10
+ runnerToken?: string;
11
+ fetch?: TRunnerFetch;
12
+ sleep?: (milliseconds: number, signal?: AbortSignal) => Promise<void>;
13
+ }
14
+ export declare class RunnerApiClient { private readonly options;
15
+ private readonly origin;
16
+ private readonly baseUrl;
17
+ private readonly fetchImplementation;
18
+ private readonly sleep;
19
+ private runnerToken?;
20
+ constructor(options: IRunnerApiClientOptions);
21
+ setRunnerToken(token: string): void;
22
+ discover(signal?: AbortSignal): Promise<IDiscoveryResponse>;
23
+ register(request: IRegisterRunnerRequest, bootstrapToken: string, signal?: AbortSignal): Promise<IRegisterRunnerResponse>;
24
+ startSession(request: IStartSessionRequest, signal?: AbortSignal): Promise<IStartSessionResponse>;
25
+ heartbeatRunner(request: IRunnerHeartbeatRequest, signal?: AbortSignal): Promise<IRunnerHeartbeatResponse>;
26
+ claimJob(request: IClaimJobRequest, signal?: AbortSignal): Promise<IClaimJobResponse>;
27
+ acceptJob(request: IAcceptJobRequest, signal?: AbortSignal): Promise<void>;
28
+ heartbeatJob(request: IJobHeartbeatRequest, signal?: AbortSignal): Promise<IJobHeartbeatResponse>;
29
+ appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
30
+ completeJob(request: ICompleteJobRequest, signal?: AbortSignal): Promise<ICompleteJobResponse>;
31
+ abandonJob(request: IAbandonJobRequest, signal?: AbortSignal): Promise<void>;
32
+ recoverAttempt(request: IRecoverAttemptRequest, signal?: AbortSignal): Promise<void>;
33
+ downloadSource(identity: IJobIdentity, source: IJobSource, signal?: AbortSignal): Promise<ITransferDownload>;
34
+ downloadCache(identity: IJobIdentity, name: string, signal?: AbortSignal): Promise<TCacheDownload>;
35
+ uploadArtifact(identity: IJobIdentity, name: string, transferRequestId: string, metadata: ITransferMetadata, openBody: TOpenTransferBody, signal?: AbortSignal): Promise<ITransferRecord>;
36
+ uploadCache(identity: IJobIdentity, name: string, transferRequestId: string, metadata: ITransferMetadata, openBody: TOpenTransferBody, signal?: AbortSignal): Promise<ITransferRecord>;
37
+ private requireRunnerToken;
38
+ private jobPath;
39
+ private requestJson;
40
+ private fetchTransfer;
41
+ private uploadTransfer;
42
+ private parseTransferDownload;
43
+ private throwResponseError;
44
+ }
45
+ export interface IArtifactApiClient { uploadArtifact(identity: IJobIdentity, name: string, transferRequestId: string, metadata: ITransferMetadata, openBody: TOpenTransferBody, signal?: AbortSignal): Promise<ITransferRecord>;
46
+ }
47
+ export declare class ArtifactManager implements IArtifactManager { private readonly config;
48
+ private readonly api;
49
+ private readonly onMessage?;
50
+ constructor(config: ITransferManagerConfig, api: IArtifactApiClient, onMessage?: ((message: string) => void) | undefined);
51
+ upload(context: IArtifactUploadContext): Promise<void>;
52
+ }
53
+ export interface ICacheApiClient { downloadCache(identity: IJobIdentity, name: string, signal?: AbortSignal): Promise<TCacheDownload>;
54
+ uploadCache(identity: IJobIdentity, name: string, transferRequestId: string, metadata: ITransferMetadata, openBody: TOpenTransferBody, signal?: AbortSignal): Promise<ITransferRecord>;
55
+ }
56
+ export declare class CacheManager implements ICacheManager { private readonly config;
57
+ private readonly api;
58
+ private readonly onMessage?;
59
+ constructor(config: ITransferManagerConfig, api: ICacheApiClient, onMessage?: ((message: string) => void) | undefined);
60
+ restore(context: ICacheRestoreContext): Promise<void>;
61
+ save(context: ICacheSaveContext): Promise<void>;
62
+ }
63
+ export declare const defaultRunnerConfig: () => IRunnerConfig;
64
+ export declare const parseRunnerConfig: (input: unknown) => IRunnerConfig;
65
+ export declare const validateRunnerConfig: (config: IRunnerConfig) => void;
66
+ export declare const loadRunnerConfig: (path: string) => Promise<IRunnerConfig>;
67
+ export declare const saveRunnerConfig: (path: string, config: IRunnerConfig) => Promise<void>;
68
+ export declare const withRunnerCredential: (config: IRunnerConfig, credential: IRunnerCredential) => IRunnerConfig;
69
+ export declare const maskRunnerConfig: (config: IRunnerConfig) => Record<string, unknown>;
70
+ export declare class RunnerError extends Error { constructor(message: string, options?: ErrorOptions);
71
+ }
72
+ export declare class ResourceCleanupError extends RunnerError { readonly errors: readonly unknown[];
73
+ constructor(message: string, errors: readonly unknown[]);
74
+ }
75
+ export declare class ConfigurationError extends RunnerError { constructor(message: string);
76
+ }
77
+ export declare class CoordinatorError extends RunnerError { readonly status?: number | undefined;
78
+ constructor(message: string, status?: number | undefined, options?: ErrorOptions);
79
+ }
80
+ export declare class AuthenticationError extends CoordinatorError { constructor(message?: string);
81
+ }
82
+ export declare class LeaseLostError extends CoordinatorError { constructor(message?: string);
83
+ }
84
+ export declare class ProtocolError extends CoordinatorError { constructor(message: string, options?: ErrorOptions);
85
+ }
86
+ export declare const runnerVersion: string;
87
+ export declare const runnerProtocolIdentifier: 'foss-ci-runner/2.0-draft.1';
88
+ export type TRunnerProtocolIdentifier = typeof runnerProtocolIdentifier;
89
+ export type TExecutionProfile = 'oci.v1';
90
+ export type TRunnerFeature = 'source.tar-gz' | 'artifacts.v1' | 'caches.v1';
91
+ export type TJobNetwork = 'none' | 'bridge';
92
+ export type TSourceFormat = 'tar.gz';
93
+ export type TOciRuntime = 'docker' | 'podman';
94
+ export type TArtifactPermission = 'none' | 'write';
95
+ export type TCachePermission = 'none' | 'read' | 'read-write';
96
+ export type TCacheAccess = 'read' | 'read-write';
97
+ export type TArtifactWhen = 'always' | 'success' | 'failure';
98
+ export type TLogStream = 'stdout' | 'stderr' | 'runner';
99
+ export type TJobCompletionStatus = 'succeeded' | 'failed' | 'canceled' | 'timed_out' | 'system_error';
100
+ export type TCancellationReason = 'user_requested' | 'superseded' | 'policy' | 'coordinator_shutdown';
101
+ export type TAbandonReason = 'runner_shutdown' | 'runner_error';
102
+ export type TJsonPrimitive = null | boolean | number | string;
103
+ export type TJsonValue = TJsonPrimitive | TJsonValue[] | { [key: string]: TJsonValue;
104
+ };
105
+ export type TJsonObject = { [key: string]: TJsonValue;
106
+ };
107
+ export interface IProtocolLimits { maximumJsonBytes: number;
108
+ maximumLogChunkBytes: number;
109
+ maximumTotalLogBytes: number;
110
+ minimumLeaseSeconds: number;
111
+ maximumLeaseSeconds: number;
112
+ }
113
+ export interface IDiscoveryResponse { protocol: TRunnerProtocolIdentifier;
114
+ basePath: '/api/runner/v2';
115
+ status: 'draft';
116
+ serverTime: string;
117
+ limits: IProtocolLimits;
118
+ }
119
+ export interface IRunnerCredential { credentialId: string;
120
+ runnerId: string;
121
+ token: string;
122
+ expiresAt: string;
123
+ previousCredentialValidUntil?: string;
124
+ }
125
+ export interface ITransferLimits { maximumSourceArchiveBytes: number;
126
+ maximumSourceExtractedBytes: number;
127
+ maximumSourceEntries: number;
128
+ maximumArtifactArchiveBytes: number;
129
+ maximumArtifactExtractedBytes: number;
130
+ maximumArtifactEntries: number;
131
+ maximumArtifacts: number;
132
+ maximumCacheArchiveBytes: number;
133
+ maximumCacheExtractedBytes: number;
134
+ maximumCacheEntries: number;
135
+ maximumCaches: number;
136
+ maximumLogChunkBytes: number;
137
+ maximumTotalLogBytes: number;
138
+ maximumWorkspaceBytes: number;
139
+ maximumWorkspaceEntries: number;
140
+ }
141
+ export interface IRunnerCapabilities { executionProfiles: TExecutionProfile[];
142
+ labels: string[];
143
+ features: TRunnerFeature[];
144
+ networks: TJobNetwork[];
145
+ sourceFormats: TSourceFormat[];
146
+ limits: ITransferLimits;
147
+ }
148
+ export interface IRegisterRunnerRequest { registrationRequestId: string;
149
+ protocol: TRunnerProtocolIdentifier;
150
+ runnerVersion: string;
151
+ name: string;
152
+ capabilities: IRunnerCapabilities;
153
+ }
154
+ export interface IRegisterRunnerResponse { protocol: TRunnerProtocolIdentifier;
155
+ serverTime: string;
156
+ registrationReplayUntil: string;
157
+ credential: IRunnerCredential;
158
+ }
159
+ export interface IStartSessionRequest { sessionRequestId: string;
160
+ runnerId: string;
161
+ protocol: TRunnerProtocolIdentifier;
162
+ runnerVersion: string;
163
+ capabilities: IRunnerCapabilities;
164
+ }
165
+ export interface IStartSessionResponse { sessionId: string;
166
+ protocol: TRunnerProtocolIdentifier;
167
+ serverTime: string;
168
+ credential?: IRunnerCredential;
169
+ }
170
+ export interface IRunnerHeartbeatRequest { runnerId: string;
171
+ sessionId: string;
172
+ }
173
+ export interface IRunnerHeartbeatResponse { serverTime: string;
174
+ drainRequested: boolean;
175
+ credential?: IRunnerCredential;
176
+ }
177
+ export interface IClaimJobRequest { claimRequestId: string;
178
+ runnerId: string;
179
+ sessionId: string;
180
+ capabilities: IRunnerCapabilities;
181
+ }
182
+ export interface IClaimJobResponse { serverTime: string;
183
+ retryAfterMs?: number;
184
+ lease: unknown | null;
185
+ }
186
+ export interface IJobLease { jobId: string;
187
+ attemptId: string;
188
+ leaseId: string;
189
+ fencingToken: string;
190
+ leaseExpiresAt: string;
191
+ job: ICompiledRunnerJob;
192
+ }
193
+ export interface IJobIdentity { runnerId: string;
194
+ sessionId: string;
195
+ jobId: string;
196
+ attemptId: string;
197
+ leaseId: string;
198
+ fencingToken: string;
199
+ }
200
+ export interface IAcceptJobRequest { acceptRequestId: string;
201
+ identity: IJobIdentity;
202
+ }
203
+ export interface IJobHeartbeatRequest { identity: IJobIdentity;
204
+ observedCancellationRequestId?: string;
205
+ }
206
+ export interface ICancellationDirective { requestId: string;
207
+ requestedAt: string;
208
+ reason: TCancellationReason;
209
+ terminateBy: string;
210
+ }
211
+ export interface IJobHeartbeatResponse { serverTime: string;
212
+ leaseExpiresAt: string;
213
+ cancellation?: ICancellationDirective;
214
+ }
215
+ export interface ILogChunk { identity: IJobIdentity;
216
+ sequence: number;
217
+ stream: TLogStream;
218
+ data: string;
219
+ timestamp: string;
220
+ }
221
+ export interface ILogAcknowledgement { serverTime: string;
222
+ nextSequence: number;
223
+ }
224
+ export interface ICompleteJobRequest { completionRequestId: string;
225
+ identity: IJobIdentity;
226
+ status: TJobCompletionStatus;
227
+ exitCode: number | null;
228
+ startedAt: string;
229
+ completedAt: string;
230
+ cancellationRequestId?: string;
231
+ error?: string;
232
+ }
233
+ export interface ICompleteJobResponse { serverTime: string;
234
+ accepted: true;
235
+ }
236
+ export interface IAbandonJobRequest { abandonRequestId: string;
237
+ identity: IJobIdentity;
238
+ reason: TAbandonReason;
239
+ }
240
+ export interface IRecoverAttemptRequest { recoveryRequestId: string;
241
+ runnerId: string;
242
+ currentSessionId: string;
243
+ previousSessionId: string;
244
+ jobId: string;
245
+ attemptId: string;
246
+ reason: 'runner_restarted';
247
+ }
248
+ export interface ITransferRecord { name: string;
249
+ format: 'tar.gz';
250
+ sha256: string;
251
+ sizeBytes: number;
252
+ extractedSizeBytes: number;
253
+ entryCount: number;
254
+ createdAt: string;
255
+ }
256
+ export interface IErrorResponse { error: { code: string;
257
+ message: string;
258
+ };
259
+ }
260
+ export interface IJobRequirements { executionProfile: TExecutionProfile;
261
+ labels: string[];
262
+ features: TRunnerFeature[];
263
+ limits: ITransferLimits;
264
+ }
265
+ export interface IJobPermissions { source: 'read';
266
+ artifacts: TArtifactPermission;
267
+ caches: TCachePermission;
268
+ packages: 'none';
269
+ }
270
+ export interface IOciExecution { profile: 'oci.v1';
271
+ image: string;
272
+ network: TJobNetwork;
273
+ workingDirectory?: string;
274
+ }
275
+ export interface ICompiledStep { name?: string;
276
+ command: string[];
277
+ environment: Record<string, string>;
278
+ }
279
+ export interface IJobSource { format: 'tar.gz';
280
+ sha256: string;
281
+ sizeBytes: number;
282
+ extractedSizeBytes: number;
283
+ entryCount: number;
284
+ }
285
+ export interface IJobResources { memoryBytes?: number;
286
+ cpus?: number;
287
+ pids?: number;
288
+ }
289
+ export interface IArtifactDeclaration { name: string;
290
+ path: string;
291
+ format: 'tar.gz';
292
+ when: TArtifactWhen;
293
+ required: boolean;
294
+ maximumBytes: number;
295
+ maximumExtractedBytes: number;
296
+ maximumEntries: number;
297
+ retentionDays?: number;
298
+ }
299
+ export interface ICacheDeclaration { name: string;
300
+ key: string;
301
+ paths: string[];
302
+ access: TCacheAccess;
303
+ maximumBytes: number;
304
+ maximumExtractedBytes: number;
305
+ maximumEntries: number;
306
+ retentionDays?: number;
307
+ }
308
+ export interface ICompiledRunnerJob { specVersion: '2.0-draft.1';
309
+ sourceObjectId: string;
310
+ workflowDigest: string;
311
+ compiledPlanDigest: string;
312
+ requirements: IJobRequirements;
313
+ permissions: IJobPermissions;
314
+ execution: IOciExecution;
315
+ steps: ICompiledStep[];
316
+ source: IJobSource;
317
+ secrets: Record<string, string>;
318
+ timeoutMs: number;
319
+ resources?: IJobResources;
320
+ artifacts: IArtifactDeclaration[];
321
+ caches: ICacheDeclaration[];
322
+ }
323
+ export interface ITransferMetadata { sha256: string;
324
+ sizeBytes: number;
325
+ extractedSizeBytes: number;
326
+ entryCount: number;
327
+ }
328
+ export interface ITransferDownload extends ITransferMetadata { body: ReadableStream<Uint8Array>;
329
+ }
330
+ export interface ICacheDownloadMiss { hit: false;
331
+ }
332
+ export interface ICacheDownloadHit extends ITransferDownload { hit: true;
333
+ }
334
+ export type TCacheDownload = ICacheDownloadMiss | ICacheDownloadHit;
335
+ export type TOpenTransferBody = () => ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>;
336
+ export interface ITransferManagerConfig { stateDirectory: string;
337
+ transferStagingReserveBytes: number;
338
+ transferStagingReserveInodes: number;
339
+ maximumSourceArchiveBytes: number;
340
+ maximumSourceExtractedBytes: number;
341
+ maximumSourceEntries: number;
342
+ maximumArtifactBytes: number;
343
+ maximumArtifactExtractedBytes: number;
344
+ maximumArtifactEntries: number;
345
+ maximumArtifacts: number;
346
+ maximumCacheArchiveBytes: number;
347
+ maximumCacheExtractedBytes: number;
348
+ maximumCacheEntries: number;
349
+ maximumCaches: number;
350
+ maximumWorkspaceEntries: number;
351
+ oci: Pick<IOciExecutorConfig, 'workspaceSizeBytes'>;
352
+ }
353
+ export type TExecutionStopReason = 'job_canceled' | 'lease_lost' | 'lease_expired' | 'runner_shutdown' | 'job_timeout' | 'log_delivery_failed' | 'resource_limit';
354
+ export type TOciArchitecture = 'amd64' | 'arm64';
355
+ export type TOciHelperTarget = 'linux_amd64' | 'linux_arm64';
356
+ export interface IOciExecutorConfig { runtime: TOciRuntime;
357
+ runtimePath: string;
358
+ workspaceHelperPath?: string;
359
+ requireRootless: boolean;
360
+ allowedNetworks: TJobNetwork[];
361
+ containerUser: string;
362
+ defaultTimeoutMs: number;
363
+ maximumTimeoutMs: number;
364
+ defaultMemoryBytes: number;
365
+ maximumMemoryBytes: number;
366
+ defaultCpus: number;
367
+ maximumCpus: number;
368
+ defaultPids: number;
369
+ maximumPids: number;
370
+ workspaceSizeBytes: number;
371
+ temporarySizeBytes: number;
372
+ stopTimeoutSeconds: number;
373
+ }
374
+ export interface IRunnerConfig extends ITransferManagerConfig { controlPlaneUrl: string;
375
+ allowInsecureLoopback: boolean;
376
+ name: string;
377
+ labels: string[];
378
+ bootstrapToken?: string;
379
+ runnerId?: string;
380
+ runnerCredentialId?: string;
381
+ runnerToken?: string;
382
+ runnerTokenExpiresAt?: string;
383
+ pollIntervalMs: number;
384
+ runnerHeartbeatIntervalMs: number;
385
+ jobHeartbeatIntervalMs: number;
386
+ leaseSafetyMarginMs: number;
387
+ requestTimeoutMs: number;
388
+ maximumResponseBytes: number;
389
+ sourceTransferTimeoutMs: number;
390
+ maximumLogBytes: number;
391
+ maximumLogChunkBytes: number;
392
+ artifactUploadTimeoutMs: number;
393
+ cacheTransferTimeoutMs: number;
394
+ maximumEnvironmentVariables: number;
395
+ maximumEnvironmentValueBytes: number;
396
+ maximumSecretBytes: number;
397
+ oci: IOciExecutorConfig;
398
+ }
399
+ export interface IExecutionContext { runnerId: string;
400
+ sessionId: string;
401
+ lease: IJobLease;
402
+ preparedLease: IPreparedOciLease;
403
+ workspacePath: string;
404
+ signal: AbortSignal;
405
+ terminationDeadline?: () => number | undefined;
406
+ onLog: (stream: 'stdout' | 'stderr', data: string) => Promise<void>;
407
+ }
408
+ export interface IOciRuntimeFacts { readonly runtime: TOciRuntime;
409
+ readonly endpoint: string;
410
+ readonly rootless: boolean;
411
+ readonly os: 'linux';
412
+ readonly architecture: TOciArchitecture;
413
+ readonly helperTarget: TOciHelperTarget;
414
+ readonly helperPath: string;
415
+ readonly helperSha256: string;
416
+ readonly workspaceBlockSize: number;
417
+ }
418
+ export interface IPrepareOciLeaseContext { runnerId: string;
419
+ sessionId: string;
420
+ lease: IJobLease;
421
+ signal: AbortSignal;
422
+ }
423
+ export interface IPreparedOciLease { readonly preparationId: string;
424
+ readonly attemptId: string;
425
+ readonly image: string;
426
+ readonly imageArchitecture: TOciArchitecture;
427
+ cleanup(): Promise<void>;
428
+ }
429
+ export interface IWorkspaceTreeMetadata { logicalBytes: number;
430
+ entryCount: number;
431
+ }
432
+ export interface IWorkspaceExportRequest { selections: string[];
433
+ maximumBytes: number;
434
+ maximumEntries: number;
435
+ signal?: AbortSignal;
436
+ }
437
+ export interface IWorkspaceExport { path: string;
438
+ metadata: IWorkspaceTreeMetadata;
439
+ cleanup(): Promise<void>;
440
+ }
441
+ export interface IRuntimeWorkspaceExporter { exportSelected(request: IWorkspaceExportRequest): Promise<IWorkspaceExport>;
442
+ cleanup(): Promise<void>;
443
+ }
444
+ export interface IExecutionResult { exitCode: number | null;
445
+ stopReason?: TExecutionStopReason;
446
+ workspace?: IRuntimeWorkspaceExporter;
447
+ }
448
+ export interface IJobExecutor { verifyRuntime(): Promise<IOciRuntimeFacts>;
449
+ prepareLease(context: IPrepareOciLeaseContext): Promise<IPreparedOciLease>;
450
+ reconcileOrphans(runnerId: string, currentSessionId: string): Promise<void>;
451
+ execute(context: IExecutionContext): Promise<IExecutionResult>;
452
+ }
453
+ export interface IPreparedWorkspace { path: string;
454
+ metadata: IWorkspaceTreeMetadata;
455
+ cleanup(): Promise<void>;
456
+ }
457
+ export interface ISourcePrepareContext { identity: IJobIdentity;
458
+ job: Pick<ICompiledRunnerJob, 'source' | 'permissions' | 'requirements'>;
459
+ signal: AbortSignal;
460
+ }
461
+ export interface IRunnerRunResult { claimed: boolean;
462
+ status?: TJobCompletionStatus;
463
+ }
464
+ export interface IArtifactUploadContext { workspace: IRuntimeWorkspaceExporter;
465
+ job: Pick<ICompiledRunnerJob, 'artifacts' | 'permissions' | 'requirements'>;
466
+ status: TJobCompletionStatus;
467
+ identity: IJobIdentity;
468
+ signal: AbortSignal;
469
+ }
470
+ export interface IArtifactManager { upload(context: IArtifactUploadContext): Promise<void>;
471
+ }
472
+ export interface ICacheRestoreContext { workspacePath: string;
473
+ job: Pick<ICompiledRunnerJob, 'caches' | 'permissions' | 'requirements' | 'source'>;
474
+ identity: IJobIdentity;
475
+ signal: AbortSignal;
476
+ }
477
+ export interface ICacheSaveContext { workspace: IRuntimeWorkspaceExporter;
478
+ job: Pick<ICompiledRunnerJob, 'caches' | 'permissions' | 'requirements'>;
479
+ status: TJobCompletionStatus;
480
+ identity: IJobIdentity;
481
+ signal: AbortSignal;
482
+ }
483
+ export interface ICacheManager { restore(context: ICacheRestoreContext): Promise<void>;
484
+ save(context: ICacheSaveContext): Promise<void>;
485
+ }
486
+ export interface ILogApi { appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
487
+ }
488
+ export declare class LogSender { private readonly api;
489
+ private readonly identity;
490
+ private readonly maximumBytes;
491
+ private readonly maximumChunkBytes;
492
+ private readonly signal?;
493
+ private readonly redactors;
494
+ private sequence;
495
+ private sentBytes;
496
+ private operationQueue;
497
+ private terminalError;
498
+ private observationSequence;
499
+ private readonly lastObservation;
500
+ constructor(api: ILogApi, identity: IJobIdentity, secrets: Iterable<string>, maximumBytes: number, maximumChunkBytes: number, signal?: AbortSignal | undefined);
501
+ write(stream: 'stdout' | 'stderr', rawData: string): Promise<void>;
502
+ writeRunnerMessage(data: string): Promise<void>;
503
+ flush(): Promise<void>;
504
+ private schedule;
505
+ private sendBatch;
506
+ }
507
+ export declare const workspaceHelperReserveBytes: number;
508
+ export declare const workspaceFixedInodes = 3;
509
+ export interface IOciRuntimeCommandRequest { executable: string;
510
+ args: string[];
511
+ environment: Record<string, string>;
512
+ timeoutMs: number;
513
+ signal?: AbortSignal;
514
+ maximumOutputBytes?: number;
515
+ onOutput?: (stream: 'stdout' | 'stderr', chunk: Uint8Array) => Promise<void>;
516
+ }
517
+ export interface IOciRuntimeCommandResult { success: boolean;
518
+ code: number;
519
+ stdout: Uint8Array;
520
+ stderr: Uint8Array;
521
+ }
522
+ export type TOciRuntimeCommandRunner = (request: IOciRuntimeCommandRequest) => Promise<IOciRuntimeCommandResult>;
523
+ export interface IOciExecutorDependencies { commandRunner?: TOciRuntimeCommandRunner;
524
+ runtimeEnvironment?: Record<string, string>;
525
+ resolveHelperPath?: (target: TOciHelperTarget) => Promise<string>;
526
+ probeTmpfs?: (helperPath: string) => Promise<number>;
527
+ randomId?: () => string;
528
+ now?: () => number;
529
+ makeTempDir?: (options: Deno.MakeTempOptions) => Promise<string>;
530
+ chmod?: (path: string, mode: number) => Promise<void>;
531
+ remove?: (path: string, options?: Deno.RemoveOptions) => Promise<void>;
532
+ }
533
+ export interface IHostTmpfsProbeScavengerDependencies { getUid?: () => number | undefined;
534
+ now?: () => number;
535
+ readDir?: (path: string) => AsyncIterable<Deno.DirEntry>;
536
+ lstat?: (path: string) => Promise<Deno.FileInfo>;
537
+ remove?: (path: string, options?: Deno.RemoveOptions) => Promise<void>;
538
+ }
539
+ export interface IWorkspaceVolumeLimits { blockSize: number;
540
+ logicalBytes: number;
541
+ maximumEntries: number;
542
+ reserveBytes: number;
543
+ sizeBytes: number;
544
+ inodeLimit: number;
545
+ }
546
+ export interface IOciRunCommand { args: string[];
547
+ environment: Record<string, string>;
548
+ }
549
+ export interface IOciStepCommandInput { runnerId: string;
550
+ sessionId: string;
551
+ lease: IJobLease;
552
+ step: ICompiledStep;
553
+ containerName: string;
554
+ volumeName: string;
555
+ }
556
+ export interface IOciHelperCommandInput { runnerId: string;
557
+ sessionId: string;
558
+ attemptId: string;
559
+ containerName: string;
560
+ image: string;
561
+ helperPath: string;
562
+ command: string[];
563
+ volumeName?: string;
564
+ sourcePath?: string;
565
+ destinationPath?: string;
566
+ }
567
+ export declare const scavengeHostTmpfsProbes: (directory?: string, dependencies?: IHostTmpfsProbeScavengerDependencies) => Promise<void>;
568
+ export declare const calculateWorkspaceVolumeLimits: (logicalBytes: number, maximumEntries: number, blockSize: number) => IWorkspaceVolumeLimits;
569
+ export declare const buildOciRunCommand: (config: IRunnerConfig, input: IOciStepCommandInput) => IOciRunCommand;
570
+ export declare const buildOciHelperCreateCommand: (config: IRunnerConfig, input: IOciHelperCommandInput) => string[];
571
+ export declare class OciExecutor implements IJobExecutor { private readonly config;
572
+ private readonly runtimeEnvironment;
573
+ private readonly commandRunner;
574
+ private readonly randomId;
575
+ private readonly now;
576
+ private readonly resolveHelperPathImplementation;
577
+ private readonly probeTmpfsImplementation;
578
+ private readonly makeTempDir;
579
+ private readonly chmod;
580
+ private readonly remove;
581
+ private runtimeFacts?;
582
+ private readonly preparedLeases;
583
+ constructor(config: IRunnerConfig, dependencies?: IOciExecutorDependencies);
584
+ verifyRuntime(): Promise<IOciRuntimeFacts>;
585
+ prepareLease(context: IPrepareOciLeaseContext): Promise<IPreparedOciLease>;
586
+ reconcileOrphans(runnerId: string, currentSessionId: string): Promise<void>;
587
+ execute(context: IExecutionContext): Promise<IExecutionResult>;
588
+ private requireRuntimeFacts;
589
+ private validateLeaseIdentity;
590
+ private resolvePackagedHelper;
591
+ private probeHostTmpfs;
592
+ private readFilesystemProbe;
593
+ private reconcileRuntimeProbeVolumes;
594
+ private probeRuntimeVolume;
595
+ private volumeCreateArgs;
596
+ private parseImageInspection;
597
+ private parseContainerState;
598
+ private parseCounts;
599
+ private runHostHelper;
600
+ private runRuntime;
601
+ private runInertContainer;
602
+ private runWorkspaceHelper;
603
+ private startVolumeHolder;
604
+ private measureWorkspace;
605
+ private readWorkspaceCapacity;
606
+ private runStepContainer;
607
+ private stopContainer;
608
+ private stopAndRemoveContainer;
609
+ private removeContainer;
610
+ private removeVolume;
611
+ private removePath;
612
+ private createResourceName;
613
+ private randomHex;
614
+ }
615
+ export declare const copyOciConfig: (config: IOciExecutorConfig) => IOciExecutorConfig;
616
+ export declare const canonicalizeJson: (value: unknown) => string;
617
+ export declare const projectCompiledPlan: (job: unknown) => TJsonObject;
618
+ export declare const computeCompiledPlanDigest: (job: unknown) => Promise<string>;
619
+ export declare const createRunnerCapabilitySnapshot: (capabilities: IRunnerCapabilities) => IRunnerCapabilities;
620
+ export declare const validateCapabilityFit: (job: ICompiledRunnerJob, capabilities: IRunnerCapabilities) => void;
621
+ export declare class RunnerProtocolValidator { private readonly capabilities;
622
+ constructor(capabilities: IRunnerCapabilities);
623
+ validateJob(jobUnknown: unknown): Promise<ICompiledRunnerJob>;
624
+ validateJobLease(leaseUnknown: unknown): Promise<IJobLease>;
625
+ }
626
+ export declare const validateJobLease: (leaseUnknown: unknown, capabilities: IRunnerCapabilities) => Promise<IJobLease>;
627
+ export declare class StreamingSecretRedactor { private readonly secrets;
628
+ private readonly maximumSecretLength;
629
+ private buffer;
630
+ constructor(secrets: Iterable<string>);
631
+ push(chunk: string): string;
632
+ flush(): string;
633
+ private consume;
634
+ }
635
+ export interface IRunnerCoordinatorClient { discover(signal?: AbortSignal): Promise<IDiscoveryResponse>;
636
+ setRunnerToken(token: string): void;
637
+ startSession(request: IStartSessionRequest, signal?: AbortSignal): Promise<IStartSessionResponse>;
638
+ heartbeatRunner(request: IRunnerHeartbeatRequest, signal?: AbortSignal): Promise<IRunnerHeartbeatResponse>;
639
+ claimJob(request: IClaimJobRequest, signal?: AbortSignal): Promise<IClaimJobResponse>;
640
+ acceptJob(request: IAcceptJobRequest, signal?: AbortSignal): Promise<void>;
641
+ heartbeatJob(request: IJobHeartbeatRequest, signal?: AbortSignal): Promise<IJobHeartbeatResponse>;
642
+ appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
643
+ completeJob(request: ICompleteJobRequest, signal?: AbortSignal): Promise<ICompleteJobResponse>;
644
+ abandonJob(request: IAbandonJobRequest, signal?: AbortSignal): Promise<void>;
645
+ recoverAttempt(request: IRecoverAttemptRequest, signal?: AbortSignal): Promise<void>;
646
+ }
647
+ export interface IRunnerWorkspaceManager { prepare(context: ISourcePrepareContext): Promise<IPreparedWorkspace>;
648
+ }
649
+ export interface IRunnerDependencies { api: IRunnerCoordinatorClient;
650
+ executor: IJobExecutor;
651
+ workspaceManager: IRunnerWorkspaceManager;
652
+ artifactManager?: IArtifactManager;
653
+ cacheManager?: ICacheManager;
654
+ onCredential?: (credential: IRunnerCredential) => Promise<void>;
655
+ onMessage?: (message: string) => void;
656
+ now?: () => number;
657
+ sleep?: (milliseconds: number, signal?: AbortSignal) => Promise<void>;
658
+ }
659
+ export declare const runnerCapabilities: (config: IRunnerConfig) => IRunnerCapabilities;
660
+ export declare const reconcileProtocolLimits: (config: IRunnerConfig, discovery: IDiscoveryResponse, capabilities: IRunnerCapabilities) => void;
661
+ export declare class ShipRunner { private readonly config;
662
+ private readonly dependencies;
663
+ private drainRequested;
664
+ private sessionInvalid;
665
+ private readonly now;
666
+ private readonly sleep;
667
+ constructor(config: IRunnerConfig, dependencies: IRunnerDependencies);
668
+ run(options?: {
669
+ once?: boolean;
670
+ signal?: AbortSignal;
671
+ }): Promise<IRunnerRunResult>;
672
+ private recoverInterruptedAttempt;
673
+ private runOnce;
674
+ private runAcceptedAttempt;
675
+ private completionStatus;
676
+ private jobHeartbeatLoop;
677
+ private observeCancellation;
678
+ private runnerHeartbeatLoop;
679
+ private abandon;
680
+ private applyCredential;
681
+ }
682
+ export interface ISourceApiClient { downloadSource(identity: IJobIdentity, source: IJobSource, signal?: AbortSignal): Promise<ITransferDownload>;
683
+ }
684
+ export declare class SourceWorkspaceManager { private readonly config;
685
+ private readonly api;
686
+ constructor(config: ITransferManagerConfig, api: ISourceApiClient);
687
+ prepare(context: ISourcePrepareContext): Promise<IPreparedWorkspace>;
688
+ }
689
+ export declare const scavengeRunnerStaging: (stateDirectory: string) => Promise<void>;