@kb-labs/core-platform 1.0.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 (56) hide show
  1. package/README.md +108 -0
  2. package/dist/adapters/index.cjs +26 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +125 -0
  5. package/dist/adapters/index.d.ts +125 -0
  6. package/dist/adapters/index.js +21 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/artifacts-BUghvkUU.d.cts +273 -0
  9. package/dist/artifacts-Bd-1UVTw.d.ts +273 -0
  10. package/dist/artifacts-DrVnkLzu.d.cts +1374 -0
  11. package/dist/artifacts-DrVnkLzu.d.ts +1374 -0
  12. package/dist/core/index.cjs +4 -0
  13. package/dist/core/index.cjs.map +1 -0
  14. package/dist/core/index.d.cts +2 -0
  15. package/dist/core/index.d.ts +2 -0
  16. package/dist/core/index.js +3 -0
  17. package/dist/core/index.js.map +1 -0
  18. package/dist/database-DGV6a1nj.d.cts +427 -0
  19. package/dist/database-DGV6a1nj.d.ts +427 -0
  20. package/dist/index.cjs +1405 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +579 -0
  23. package/dist/index.d.ts +579 -0
  24. package/dist/index.js +1381 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/log-reader-BVohbSMB.d.cts +314 -0
  27. package/dist/log-reader-uOHBLBax.d.ts +314 -0
  28. package/dist/noop/adapters/index.cjs +656 -0
  29. package/dist/noop/adapters/index.cjs.map +1 -0
  30. package/dist/noop/adapters/index.d.cts +71 -0
  31. package/dist/noop/adapters/index.d.ts +71 -0
  32. package/dist/noop/adapters/index.js +637 -0
  33. package/dist/noop/adapters/index.js.map +1 -0
  34. package/dist/noop/core/index.cjs +217 -0
  35. package/dist/noop/core/index.cjs.map +1 -0
  36. package/dist/noop/core/index.d.cts +94 -0
  37. package/dist/noop/core/index.d.ts +94 -0
  38. package/dist/noop/core/index.js +212 -0
  39. package/dist/noop/core/index.js.map +1 -0
  40. package/dist/noop/index.cjs +806 -0
  41. package/dist/noop/index.cjs.map +1 -0
  42. package/dist/noop/index.d.cts +36 -0
  43. package/dist/noop/index.d.ts +36 -0
  44. package/dist/noop/index.js +787 -0
  45. package/dist/noop/index.js.map +1 -0
  46. package/dist/resources-DaufJFad.d.cts +419 -0
  47. package/dist/resources-DaufJFad.d.ts +419 -0
  48. package/dist/serializable/index.cjs +162 -0
  49. package/dist/serializable/index.cjs.map +1 -0
  50. package/dist/serializable/index.d.cts +352 -0
  51. package/dist/serializable/index.d.ts +352 -0
  52. package/dist/serializable/index.js +152 -0
  53. package/dist/serializable/index.js.map +1 -0
  54. package/dist/snapshot-provider--COac4P-.d.ts +923 -0
  55. package/dist/snapshot-provider-nE9wuc1C.d.cts +923 -0
  56. package/package.json +92 -0
@@ -0,0 +1,923 @@
1
+ import { L as LogRecord, a as LogQuery } from './artifacts-DrVnkLzu.js';
2
+ import { I as ISQLDatabase } from './database-DGV6a1nj.js';
3
+
4
+ /**
5
+ * @module @kb-labs/core-platform/adapters/adapter-manifest
6
+ * Adapter manifest schema for dependency management and extension points.
7
+ */
8
+ /**
9
+ * Adapter type classification.
10
+ *
11
+ * - core: Primary adapter implementing a platform interface (e.g., logger, db)
12
+ * - extension: Adapter that extends another adapter via hooks (e.g., log persistence)
13
+ * - proxy: Adapter that wraps/delegates to another adapter (e.g., IPC proxy)
14
+ */
15
+ type AdapterType = "core" | "extension" | "proxy";
16
+ /**
17
+ * Adapter dependency specification.
18
+ *
19
+ * Short form: runtime adapter token (config key in `platform.adapters`)
20
+ * Long form: { id, alias } where alias is used in factory deps parameter
21
+ */
22
+ type AdapterDependency = string | {
23
+ id: string;
24
+ alias?: string;
25
+ };
26
+ /**
27
+ * Extension point configuration.
28
+ *
29
+ * Describes how this adapter extends another adapter:
30
+ * - adapter: Target adapter ID (e.g., "logger")
31
+ * - hook: Method name on target adapter (e.g., "onLog")
32
+ * - method: Method name on this adapter to call (e.g., "write")
33
+ * - priority: Call order (higher = called first, default: 0)
34
+ */
35
+ interface AdapterExtension {
36
+ /** Target adapter ID to extend */
37
+ adapter: string;
38
+ /** Hook method on target adapter (e.g., "onLog") */
39
+ hook: string;
40
+ /** Method on this adapter to call when hook fires (e.g., "write") */
41
+ method: string;
42
+ /**
43
+ * Priority for extension ordering.
44
+ * Higher values are called first.
45
+ * Default: 0
46
+ * Ties resolved by registration order.
47
+ */
48
+ priority?: number;
49
+ }
50
+ /**
51
+ * Adapter capabilities declaration.
52
+ *
53
+ * Describes what features this adapter supports.
54
+ * Used for adapter selection and runtime feature detection.
55
+ */
56
+ interface AdapterCapabilities {
57
+ /** Supports streaming/realtime data */
58
+ streaming?: boolean;
59
+ /** Supports batch operations */
60
+ batch?: boolean;
61
+ /** Supports search/query operations */
62
+ search?: boolean;
63
+ /** Supports transactions */
64
+ transactions?: boolean;
65
+ /** Custom capabilities (adapter-specific) */
66
+ custom?: Record<string, unknown>;
67
+ }
68
+ /**
69
+ * Adapter manifest.
70
+ *
71
+ * Every adapter exports a manifest describing its:
72
+ * - Identity (id, name, version)
73
+ * - Type (core/extension/proxy)
74
+ * - Interface implementation (implements: "ILogger")
75
+ * - Dependencies (requires, optional)
76
+ * - Extension points (extends: { adapter, hook, method })
77
+ * - Capabilities (streaming, batch, search, etc.)
78
+ *
79
+ * @example Core adapter (Pino logger)
80
+ * ```typescript
81
+ * export const manifest: AdapterManifest = {
82
+ * manifestVersion: '1.0.0',
83
+ * id: 'pino-logger',
84
+ * name: 'Pino Logger',
85
+ * version: '1.0.0',
86
+ * type: 'core',
87
+ * implements: 'ILogger',
88
+ * optional: { adapters: ['analytics'] },
89
+ * capabilities: { streaming: true }
90
+ * };
91
+ * ```
92
+ *
93
+ * @example Extension adapter (Ring buffer)
94
+ * ```typescript
95
+ * export const manifest: AdapterManifest = {
96
+ * manifestVersion: '1.0.0',
97
+ * id: 'log-ringbuffer',
98
+ * name: 'Log Ring Buffer',
99
+ * version: '1.0.0',
100
+ * type: 'extension',
101
+ * implements: 'ILogRingBuffer',
102
+ * extends: {
103
+ * adapter: 'logger',
104
+ * hook: 'onLog',
105
+ * method: 'append',
106
+ * priority: 10
107
+ * },
108
+ * capabilities: { streaming: true }
109
+ * };
110
+ * ```
111
+ *
112
+ * @example Extension with dependency (SQLite persistence)
113
+ * ```typescript
114
+ * export const manifest: AdapterManifest = {
115
+ * manifestVersion: '1.0.0',
116
+ * id: 'log-persistence',
117
+ * name: 'SQLite Log Persistence',
118
+ * version: '1.0.0',
119
+ * type: 'extension',
120
+ * implements: 'ILogPersistence',
121
+ * requires: {
122
+ * adapters: [{ id: 'db', alias: 'database' }],
123
+ * platform: '>= 1.0.0'
124
+ * },
125
+ * extends: {
126
+ * adapter: 'logger',
127
+ * hook: 'onLog',
128
+ * method: 'write',
129
+ * priority: 5
130
+ * },
131
+ * capabilities: { batch: true, search: true, transactions: true }
132
+ * };
133
+ * ```
134
+ */
135
+ interface AdapterManifest {
136
+ /**
137
+ * Manifest schema version.
138
+ * Used for compatibility checking and evolution.
139
+ * Format: semver (e.g., "1.0.0")
140
+ */
141
+ manifestVersion: string;
142
+ /**
143
+ * Unique adapter identifier.
144
+ * Used in dependency resolution and configuration.
145
+ * Convention: kebab-case (e.g., "pino-logger", "log-ringbuffer")
146
+ */
147
+ id: string;
148
+ /**
149
+ * Human-readable adapter name.
150
+ * Shown in logs, UI, documentation.
151
+ */
152
+ name: string;
153
+ /**
154
+ * Adapter version.
155
+ * Format: semver (e.g., "1.0.0")
156
+ */
157
+ version: string;
158
+ /**
159
+ * Adapter description (optional).
160
+ * Brief explanation of what this adapter does.
161
+ */
162
+ description?: string;
163
+ /**
164
+ * Author information (optional).
165
+ */
166
+ author?: string;
167
+ /**
168
+ * License (optional).
169
+ * SPDX identifier (e.g., "MIT", "Apache-2.0")
170
+ */
171
+ license?: string;
172
+ /**
173
+ * Homepage URL (optional).
174
+ * Link to documentation or repository.
175
+ */
176
+ homepage?: string;
177
+ /**
178
+ * Adapter type.
179
+ * - core: Primary adapter implementing a platform interface
180
+ * - extension: Extends another adapter via hooks
181
+ * - proxy: Wraps/delegates to another adapter
182
+ */
183
+ type: AdapterType;
184
+ /**
185
+ * Interface this adapter implements.
186
+ * Convention: PascalCase interface name (e.g., "ILogger", "ILogRingBuffer")
187
+ *
188
+ * This is informational - TypeScript provides compile-time type safety.
189
+ * No runtime type checking is performed.
190
+ */
191
+ implements: string;
192
+ /**
193
+ * Required dependencies.
194
+ *
195
+ * If any required dependency is missing, adapter load fails immediately.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * requires: {
200
+ * adapters: ['db'], // Runtime token from config
201
+ * adapters: [{ id: 'db', alias: 'database' }], // Runtime token + factory alias
202
+ * platform: '>= 1.0.0' // Semver range
203
+ * }
204
+ * ```
205
+ */
206
+ requires?: {
207
+ /**
208
+ * Required adapters by runtime token (config key), NOT by `manifest.id`.
209
+ *
210
+ * Example:
211
+ * - `platform.adapters.cache = "@kb-labs/adapters-redis"`
212
+ * - runtime token is `cache`
213
+ * - provider manifest id can be `redis-cache`
214
+ * - dependency must reference `cache`, not `redis-cache`
215
+ *
216
+ * Each will be passed to factory function in `deps` parameter.
217
+ */
218
+ adapters?: AdapterDependency[];
219
+ /**
220
+ * Required platform version (semver range).
221
+ * Example: ">= 1.0.0", "^1.2.0", "~1.2.3"
222
+ */
223
+ platform?: string;
224
+ };
225
+ /**
226
+ * Optional dependencies.
227
+ *
228
+ * If optional dependency is missing, adapter still loads (no error).
229
+ * Factory function receives `undefined` for missing optional deps.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * optional: {
234
+ * adapters: ['analytics', 'metrics']
235
+ * }
236
+ * ```
237
+ */
238
+ optional?: {
239
+ /** Optional adapters (by ID) */
240
+ adapters?: string[];
241
+ };
242
+ /**
243
+ * Requested runtime contexts.
244
+ *
245
+ * Specifies which runtime contexts this adapter needs.
246
+ * Requested contexts are injected into the adapter's config by the loader.
247
+ *
248
+ * Available contexts:
249
+ * - 'workspace': { cwd: string } - Workspace directory path
250
+ * - 'analytics': AnalyticsContext - Analytics enrichment context (source, actor, runId)
251
+ * - 'tenant': TenantContext - Multi-tenancy context (future)
252
+ * - 'request': RequestContext - HTTP request context (future)
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * contexts: ['workspace', 'analytics']
257
+ * ```
258
+ */
259
+ contexts?: string[];
260
+ /**
261
+ * Extension point configuration.
262
+ *
263
+ * If present, this adapter extends another adapter via a hook.
264
+ * The platform automatically connects the extension after all adapters load.
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * extends: {
269
+ * adapter: 'logger', // Target adapter
270
+ * hook: 'onLog', // Hook method on target
271
+ * method: 'write', // Method on this adapter
272
+ * priority: 5 // Call order (optional)
273
+ * }
274
+ * ```
275
+ */
276
+ extends?: AdapterExtension;
277
+ /**
278
+ * Adapter capabilities.
279
+ *
280
+ * Describes what features this adapter supports.
281
+ * Used for adapter selection and runtime feature detection.
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * capabilities: {
286
+ * streaming: true,
287
+ * batch: true,
288
+ * search: true,
289
+ * transactions: true,
290
+ * custom: { maxBatchSize: 1000 }
291
+ * }
292
+ * ```
293
+ */
294
+ capabilities?: AdapterCapabilities;
295
+ /**
296
+ * Configuration options schema (optional).
297
+ *
298
+ * Declares what configuration options this adapter accepts.
299
+ * Useful for:
300
+ * - Auto-generating documentation
301
+ * - IDE auto-completion
302
+ * - Configuration validation tools
303
+ * - UI configuration builders
304
+ *
305
+ * This is informational only - TypeScript provides compile-time validation.
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * configSchema: {
310
+ * level: {
311
+ * type: 'string',
312
+ * enum: ['trace', 'debug', 'info', 'warn', 'error'],
313
+ * default: 'info',
314
+ * description: 'Minimum log level'
315
+ * },
316
+ * pretty: {
317
+ * type: 'boolean',
318
+ * default: false,
319
+ * description: 'Enable pretty printing'
320
+ * },
321
+ * batchSize: {
322
+ * type: 'number',
323
+ * default: 100,
324
+ * description: 'Number of logs per batch'
325
+ * }
326
+ * }
327
+ * ```
328
+ */
329
+ configSchema?: Record<string, {
330
+ type: "string" | "number" | "boolean" | "object" | "array";
331
+ description?: string;
332
+ default?: unknown;
333
+ required?: boolean;
334
+ enum?: unknown[];
335
+ properties?: Record<string, unknown>;
336
+ }>;
337
+ }
338
+ /**
339
+ * Adapter factory function signature.
340
+ *
341
+ * Every adapter exports a createAdapter function that:
342
+ * - Accepts adapter-specific config
343
+ * - Receives dependencies via deps parameter
344
+ * - Returns adapter instance implementing the declared interface
345
+ *
346
+ * @template TConfig - Adapter configuration type
347
+ * @template TDeps - Dependencies object type (from manifest.requires)
348
+ * @template TAdapter - Adapter interface type (from manifest.implements)
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * export function createAdapter(
353
+ * config: PinoConfig,
354
+ * deps: { analytics?: IAnalytics }
355
+ * ): ILogger {
356
+ * return new PinoAdapter(config, deps);
357
+ * }
358
+ * ```
359
+ */
360
+ type AdapterFactory<TConfig = unknown, TDeps = Record<string, unknown>, TAdapter = unknown> = (config: TConfig, deps: TDeps) => TAdapter | Promise<TAdapter>;
361
+
362
+ /**
363
+ * @module @kb-labs/core-platform/adapters/log-persistence
364
+ * Persistent log storage adapter interface.
365
+ *
366
+ * Purpose:
367
+ * - Long-term log storage (database, files, etc.)
368
+ * - Cross-process log aggregation
369
+ * - Advanced querying (search, filters, pagination)
370
+ *
371
+ * Not for:
372
+ * - Real-time streaming (use ILogRingBuffer)
373
+ * - Low-latency access to recent logs
374
+ */
375
+
376
+ /**
377
+ * Persistent log storage for historical queries.
378
+ *
379
+ * Design:
380
+ * - Writes logs to database (SQLite, PostgreSQL, etc.)
381
+ * - Supports batch writes with auto-flush
382
+ * - Full-text search support
383
+ * - Retention policy support (delete old logs)
384
+ * - Pagination for large result sets
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * const persistence = await createPersistenceAdapter({
389
+ * database: platform.db,
390
+ * batchSize: 100,
391
+ * flushInterval: 5000,
392
+ * });
393
+ *
394
+ * // Write logs
395
+ * await persistence.write({ timestamp: Date.now(), level: 'info', message: 'Hello' });
396
+ *
397
+ * // Query logs
398
+ * const result = await persistence.query(
399
+ * { level: 'error', startTime: Date.now() - 3600000 },
400
+ * { limit: 50, offset: 0 }
401
+ * );
402
+ *
403
+ * // Search logs
404
+ * const searchResults = await persistence.search('authentication failed');
405
+ * ```
406
+ */
407
+ interface ILogPersistence {
408
+ /**
409
+ * Write log record to persistent storage.
410
+ * Logs are buffered and flushed in batches.
411
+ *
412
+ * @param record - Log record to persist
413
+ * @returns Promise that resolves when write is queued (not necessarily flushed)
414
+ */
415
+ write(record: LogRecord): Promise<void>;
416
+ /**
417
+ * Write multiple log records in batch.
418
+ * More efficient than multiple write() calls.
419
+ *
420
+ * @param records - Array of log records
421
+ * @returns Promise that resolves when all writes are queued
422
+ */
423
+ writeBatch(records: LogRecord[]): Promise<void>;
424
+ /**
425
+ * Query logs from persistent storage.
426
+ *
427
+ * @param query - Query parameters (time range, level, source)
428
+ * @param options - Pagination and sorting options
429
+ * @returns Promise with logs and pagination info
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * // Get last 50 error logs
434
+ * const result = await persistence.query(
435
+ * { level: 'error' },
436
+ * { limit: 50, sortBy: 'timestamp', sortOrder: 'desc' }
437
+ * );
438
+ *
439
+ * console.log(result.logs); // Array of 50 logs
440
+ * console.log(result.total); // Total matching logs
441
+ * console.log(result.hasMore); // true if more pages exist
442
+ * ```
443
+ */
444
+ query(query: LogQuery, options?: {
445
+ /** Maximum number of logs to return (default: 100) */
446
+ limit?: number;
447
+ /** Number of logs to skip (default: 0) */
448
+ offset?: number;
449
+ /** Sort by field (default: 'timestamp') */
450
+ sortBy?: "timestamp" | "level";
451
+ /** Sort order (default: 'desc') */
452
+ sortOrder?: "asc" | "desc";
453
+ }): Promise<{
454
+ /** Logs matching query */
455
+ logs: LogRecord[];
456
+ /** Total number of logs matching query (ignoring limit/offset) */
457
+ total: number;
458
+ /** True if more results are available (offset + logs.length < total) */
459
+ hasMore: boolean;
460
+ }>;
461
+ /**
462
+ * Get single log record by ID.
463
+ *
464
+ * @param id - Log record ID
465
+ * @returns Promise with log record or null if not found
466
+ */
467
+ getById(id: string): Promise<LogRecord | null>;
468
+ /**
469
+ * Search logs by text query (full-text search).
470
+ * Searches message field using database FTS capabilities.
471
+ *
472
+ * @param searchText - Search query (supports database-specific syntax)
473
+ * @param options - Pagination options
474
+ * @returns Promise with matching logs
475
+ *
476
+ * @example
477
+ * ```typescript
478
+ * // Simple search
479
+ * const results = await persistence.search('authentication failed');
480
+ *
481
+ * // Advanced search (SQLite FTS5 syntax)
482
+ * const results = await persistence.search('auth* AND (error OR warn)');
483
+ * ```
484
+ */
485
+ search(searchText: string, options?: {
486
+ /** Maximum number of logs to return (default: 100) */
487
+ limit?: number;
488
+ /** Number of logs to skip (default: 0) */
489
+ offset?: number;
490
+ }): Promise<{
491
+ /** Logs matching search query */
492
+ logs: LogRecord[];
493
+ /** Total number of logs matching search */
494
+ total: number;
495
+ /** True if more results are available */
496
+ hasMore: boolean;
497
+ }>;
498
+ /**
499
+ * Delete logs older than specified timestamp.
500
+ * Used for implementing retention policies.
501
+ *
502
+ * @param beforeTimestamp - Delete logs before this timestamp (milliseconds)
503
+ * @returns Promise with number of deleted logs
504
+ *
505
+ * @example
506
+ * ```typescript
507
+ * // Delete logs older than 30 days
508
+ * const thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
509
+ * const deleted = await persistence.deleteOlderThan(thirtyDaysAgo);
510
+ * console.log(`Deleted ${deleted} old logs`);
511
+ * ```
512
+ */
513
+ deleteOlderThan(beforeTimestamp: number): Promise<number>;
514
+ /**
515
+ * Get statistics about stored logs.
516
+ *
517
+ * @returns Promise with log storage statistics
518
+ */
519
+ getStats(): Promise<{
520
+ /** Total number of logs in storage */
521
+ totalLogs: number;
522
+ /** Timestamp of oldest log (0 if empty) */
523
+ oldestTimestamp: number;
524
+ /** Timestamp of newest log (0 if empty) */
525
+ newestTimestamp: number;
526
+ /** Storage size in bytes */
527
+ sizeBytes: number;
528
+ }>;
529
+ /**
530
+ * Close persistence adapter and flush pending writes.
531
+ * Should be called during application shutdown.
532
+ *
533
+ * @returns Promise that resolves when all pending writes are flushed
534
+ */
535
+ close?(): Promise<void>;
536
+ }
537
+ /**
538
+ * Configuration for log persistence adapter.
539
+ */
540
+ interface LogPersistenceConfig {
541
+ /**
542
+ * Database adapter for storage.
543
+ * Must be ISQLDatabase (SQLite, PostgreSQL, etc.)
544
+ */
545
+ database: ISQLDatabase;
546
+ /**
547
+ * Table name for logs.
548
+ * @default 'logs'
549
+ */
550
+ tableName?: string;
551
+ /**
552
+ * Batch size for bulk writes.
553
+ * Logs are buffered and written in batches for performance.
554
+ * @default 100
555
+ */
556
+ batchSize?: number;
557
+ /**
558
+ * Flush interval in milliseconds.
559
+ * Pending logs are flushed at this interval even if batch is not full.
560
+ * @default 5000 (5 seconds)
561
+ */
562
+ flushInterval?: number;
563
+ }
564
+
565
+ /**
566
+ * @module @kb-labs/core-platform/adapters/execution
567
+ * Execution backend interface (plugin execution layer).
568
+ */
569
+ /**
570
+ * Execution backend interface.
571
+ * Handles plugin execution (in-process, worker-pool, or remote).
572
+ *
573
+ * Implementations:
574
+ * - InProcessBackend: Same process, no isolation (dev mode)
575
+ * - WorkerPoolBackend: Worker pool with fault isolation (production)
576
+ * - RemoteExecutionBackend: Remote executor service (Phase 3)
577
+ */
578
+ interface IExecutionBackend {
579
+ /**
580
+ * Execute a plugin handler.
581
+ *
582
+ * @param request - Execution request with descriptor, pluginRoot, handlerRef
583
+ * @param options - Optional execution options (signal, etc.)
584
+ * @returns Execution result with data/error
585
+ */
586
+ execute(request: ExecutionRequest, options?: ExecuteOptions): Promise<ExecutionResult>;
587
+ /**
588
+ * Shutdown execution backend gracefully.
589
+ * Closes worker pool, cleanup resources.
590
+ */
591
+ shutdown(): Promise<void>;
592
+ }
593
+ /**
594
+ * Execution options (optional).
595
+ */
596
+ interface ExecuteOptions {
597
+ /** Abort signal for cancellation */
598
+ signal?: AbortSignal;
599
+ /** Additional options */
600
+ [key: string]: unknown;
601
+ }
602
+ /**
603
+ * Execution request - minimal interface for core-platform.
604
+ * Full implementation in @kb-labs/plugin-execution.
605
+ */
606
+ interface ExecutionRequest {
607
+ /** Unique execution ID */
608
+ executionId: string;
609
+ /**
610
+ * Runtime descriptor containing execution context.
611
+ *
612
+ * Type is `any` to allow implementations to use their concrete descriptor types
613
+ * (e.g., PluginContextDescriptor from @kb-labs/plugin-contracts).
614
+ *
615
+ * This is intentional for interface contracts - concrete type determined by implementation.
616
+ */
617
+ descriptor: any;
618
+ /** Plugin root directory (absolute path) */
619
+ pluginRoot: string;
620
+ /** Handler reference (relative path) */
621
+ handlerRef: string;
622
+ /** Input data passed to handler */
623
+ input: unknown;
624
+ /** Execution timeout in milliseconds */
625
+ timeoutMs?: number;
626
+ /** Optional execution target affinity */
627
+ target?: {
628
+ environmentId?: string;
629
+ workspaceId?: string;
630
+ namespace?: string;
631
+ workdir?: string;
632
+ };
633
+ /** Additional configuration */
634
+ [key: string]: unknown;
635
+ }
636
+ /**
637
+ * Execution result - minimal interface for core-platform.
638
+ * Full implementation in @kb-labs/plugin-execution.
639
+ */
640
+ interface ExecutionResult {
641
+ /** Success flag */
642
+ ok: boolean;
643
+ /** Result data (if ok) */
644
+ data?: unknown;
645
+ /**
646
+ * Error details (if !ok).
647
+ * Type is `any` to allow implementations to use their own error types.
648
+ * Expected to have at least { message: string } structure.
649
+ */
650
+ error?: any;
651
+ /** Execution time in milliseconds */
652
+ executionTimeMs: number;
653
+ /**
654
+ * Execution metadata (optional).
655
+ * Contains backend-specific info, timing, plugin info.
656
+ * Type is `any` to allow implementations to extend with their own metadata types.
657
+ */
658
+ metadata?: any;
659
+ /** Additional fields allowed for extensibility */
660
+ [key: string]: unknown;
661
+ }
662
+
663
+ /**
664
+ * @module @kb-labs/core-platform/environment/environment-provider
665
+ * Environment lifecycle abstraction.
666
+ *
667
+ * This port manages long-lived execution environments (container/pod/vm/sandbox).
668
+ * It intentionally does NOT execute plugin jobs directly.
669
+ */
670
+ /**
671
+ * Environment status in lifecycle.
672
+ */
673
+ type EnvironmentStatus = "pending" | "provisioning" | "ready" | "degraded" | "terminating" | "terminated" | "failed";
674
+ /**
675
+ * Environment resource limits.
676
+ */
677
+ interface EnvironmentResources {
678
+ cpu?: string;
679
+ memory?: string;
680
+ disk?: string;
681
+ gpu?: string;
682
+ }
683
+ /**
684
+ * Environment lease metadata.
685
+ */
686
+ interface EnvironmentLease {
687
+ leaseId: string;
688
+ acquiredAt: string;
689
+ expiresAt: string;
690
+ owner?: string;
691
+ }
692
+ /**
693
+ * Environment network endpoint descriptor.
694
+ */
695
+ interface EnvironmentEndpoint {
696
+ name: string;
697
+ protocol?: "http" | "https" | "tcp" | "udp" | "unix";
698
+ host?: string;
699
+ port?: number;
700
+ path?: string;
701
+ }
702
+ /**
703
+ * Environment creation request.
704
+ */
705
+ interface CreateEnvironmentRequest {
706
+ tenantId?: string;
707
+ namespace?: string;
708
+ runId?: string;
709
+ templateId?: string;
710
+ image?: string;
711
+ workspacePath?: string;
712
+ command?: string[];
713
+ env?: Record<string, string>;
714
+ resources?: EnvironmentResources;
715
+ ttlMs?: number;
716
+ metadata?: Record<string, unknown>;
717
+ }
718
+ /**
719
+ * Created environment descriptor.
720
+ */
721
+ interface EnvironmentDescriptor {
722
+ environmentId: string;
723
+ provider: string;
724
+ status: EnvironmentStatus;
725
+ createdAt: string;
726
+ updatedAt: string;
727
+ lease?: EnvironmentLease;
728
+ endpoints?: EnvironmentEndpoint[];
729
+ metadata?: Record<string, unknown>;
730
+ }
731
+ /**
732
+ * Environment status result.
733
+ */
734
+ interface EnvironmentStatusResult {
735
+ environmentId: string;
736
+ status: EnvironmentStatus;
737
+ reason?: string;
738
+ updatedAt: string;
739
+ lease?: EnvironmentLease;
740
+ }
741
+ /**
742
+ * Environment provider capabilities.
743
+ */
744
+ interface EnvironmentProviderCapabilities {
745
+ supportsLeaseRenewal?: boolean;
746
+ supportsSnapshots?: boolean;
747
+ supportsExecProbe?: boolean;
748
+ supportsLogs?: boolean;
749
+ custom?: Record<string, unknown>;
750
+ }
751
+ /**
752
+ * Long-lived environment provider abstraction.
753
+ *
754
+ * Responsibilities:
755
+ * - Provision, inspect, and destroy environments
756
+ * - Manage lease lifecycle
757
+ *
758
+ * Non-responsibilities:
759
+ * - Plugin/job dispatch and horizontal runner scaling (ExecutionBackend)
760
+ */
761
+ interface IEnvironmentProvider {
762
+ /**
763
+ * Create a new environment instance.
764
+ */
765
+ create(request: CreateEnvironmentRequest): Promise<EnvironmentDescriptor>;
766
+ /**
767
+ * Get current status for an environment.
768
+ */
769
+ getStatus(environmentId: string): Promise<EnvironmentStatusResult>;
770
+ /**
771
+ * Destroy environment and release resources.
772
+ * Must be idempotent.
773
+ */
774
+ destroy(environmentId: string, reason?: string): Promise<void>;
775
+ /**
776
+ * Renew environment lease (if provider supports it).
777
+ */
778
+ renewLease?(environmentId: string, ttlMs: number): Promise<EnvironmentLease>;
779
+ /**
780
+ * Provider capability declaration.
781
+ */
782
+ getCapabilities?(): EnvironmentProviderCapabilities;
783
+ }
784
+
785
+ /**
786
+ * @module @kb-labs/core-platform/workspace/workspace-provider
787
+ * Workspace lifecycle abstraction.
788
+ *
789
+ * This port manages workspace materialization and attach/release lifecycle.
790
+ */
791
+ type WorkspaceStatus = "pending" | "materializing" | "ready" | "attaching" | "attached" | "releasing" | "released" | "failed";
792
+ interface WorkspaceMount {
793
+ hostPath?: string;
794
+ mountPath?: string;
795
+ readOnly?: boolean;
796
+ }
797
+ interface MaterializeWorkspaceRequest {
798
+ workspaceId?: string;
799
+ tenantId?: string;
800
+ namespace?: string;
801
+ sourceRef?: string;
802
+ basePath?: string;
803
+ metadata?: Record<string, unknown>;
804
+ }
805
+ interface WorkspaceDescriptor {
806
+ workspaceId: string;
807
+ provider: string;
808
+ status: WorkspaceStatus;
809
+ rootPath?: string;
810
+ mount?: WorkspaceMount;
811
+ createdAt: string;
812
+ updatedAt: string;
813
+ metadata?: Record<string, unknown>;
814
+ }
815
+ interface AttachWorkspaceRequest {
816
+ workspaceId: string;
817
+ environmentId: string;
818
+ mountPath?: string;
819
+ readOnly?: boolean;
820
+ }
821
+ interface WorkspaceAttachment {
822
+ workspaceId: string;
823
+ environmentId: string;
824
+ mountPath?: string;
825
+ attachedAt: string;
826
+ metadata?: Record<string, unknown>;
827
+ }
828
+ interface WorkspaceStatusResult {
829
+ workspaceId: string;
830
+ status: WorkspaceStatus;
831
+ reason?: string;
832
+ updatedAt: string;
833
+ }
834
+ interface WorkspaceProviderCapabilities {
835
+ supportsAttach?: boolean;
836
+ supportsRelease?: boolean;
837
+ supportsReadOnlyMounts?: boolean;
838
+ custom?: Record<string, unknown>;
839
+ }
840
+ interface IWorkspaceProvider {
841
+ materialize(request: MaterializeWorkspaceRequest): Promise<WorkspaceDescriptor>;
842
+ attach(request: AttachWorkspaceRequest): Promise<WorkspaceAttachment>;
843
+ release(workspaceId: string, environmentId?: string): Promise<void>;
844
+ getStatus(workspaceId: string): Promise<WorkspaceStatusResult>;
845
+ getCapabilities?(): WorkspaceProviderCapabilities;
846
+ }
847
+
848
+ /**
849
+ * @module @kb-labs/core-platform/snapshot/snapshot-provider
850
+ * Snapshot lifecycle abstraction.
851
+ *
852
+ * This port captures/restores point-in-time workspace or environment state.
853
+ */
854
+ type SnapshotStatus = "pending" | "capturing" | "ready" | "restoring" | "deleted" | "failed";
855
+ interface CaptureSnapshotRequest {
856
+ snapshotId?: string;
857
+ workspaceId?: string;
858
+ environmentId?: string;
859
+ sourcePath?: string;
860
+ namespace?: string;
861
+ metadata?: Record<string, unknown>;
862
+ }
863
+ interface SnapshotDescriptor {
864
+ snapshotId: string;
865
+ provider: string;
866
+ status: SnapshotStatus;
867
+ createdAt: string;
868
+ updatedAt: string;
869
+ workspaceId?: string;
870
+ environmentId?: string;
871
+ sizeBytes?: number;
872
+ metadata?: Record<string, unknown>;
873
+ }
874
+ interface RestoreSnapshotRequest {
875
+ snapshotId: string;
876
+ workspaceId?: string;
877
+ environmentId?: string;
878
+ targetPath?: string;
879
+ overwrite?: boolean;
880
+ metadata?: Record<string, unknown>;
881
+ }
882
+ interface RestoreSnapshotResult {
883
+ snapshotId: string;
884
+ restoredAt: string;
885
+ workspaceId?: string;
886
+ environmentId?: string;
887
+ targetPath?: string;
888
+ metadata?: Record<string, unknown>;
889
+ }
890
+ interface SnapshotStatusResult {
891
+ snapshotId: string;
892
+ status: SnapshotStatus;
893
+ reason?: string;
894
+ updatedAt: string;
895
+ }
896
+ interface SnapshotGarbageCollectRequest {
897
+ namespace?: string;
898
+ before?: string;
899
+ limit?: number;
900
+ dryRun?: boolean;
901
+ }
902
+ interface SnapshotGarbageCollectResult {
903
+ scanned: number;
904
+ deleted: number;
905
+ dryRun: boolean;
906
+ }
907
+ interface SnapshotProviderCapabilities {
908
+ supportsWorkspaceSnapshots?: boolean;
909
+ supportsEnvironmentSnapshots?: boolean;
910
+ supportsGarbageCollection?: boolean;
911
+ supportsIncrementalSnapshots?: boolean;
912
+ custom?: Record<string, unknown>;
913
+ }
914
+ interface ISnapshotProvider {
915
+ capture(request: CaptureSnapshotRequest): Promise<SnapshotDescriptor>;
916
+ restore(request: RestoreSnapshotRequest): Promise<RestoreSnapshotResult>;
917
+ getStatus(snapshotId: string): Promise<SnapshotStatusResult>;
918
+ delete(snapshotId: string): Promise<void>;
919
+ garbageCollect?(request: SnapshotGarbageCollectRequest): Promise<SnapshotGarbageCollectResult>;
920
+ getCapabilities?(): SnapshotProviderCapabilities;
921
+ }
922
+
923
+ export type { AdapterManifest as A, RestoreSnapshotResult as B, CreateEnvironmentRequest as C, SnapshotStatusResult as D, ExecutionRequest as E, SnapshotGarbageCollectRequest as F, SnapshotGarbageCollectResult as G, SnapshotProviderCapabilities as H, ILogPersistence as I, LogPersistenceConfig as L, MaterializeWorkspaceRequest as M, RestoreSnapshotRequest as R, SnapshotStatus as S, WorkspaceStatus as W, AdapterType as a, AdapterDependency as b, AdapterExtension as c, AdapterCapabilities as d, AdapterFactory as e, IExecutionBackend as f, ExecutionResult as g, ExecuteOptions as h, IEnvironmentProvider as i, EnvironmentStatus as j, EnvironmentResources as k, EnvironmentLease as l, EnvironmentEndpoint as m, EnvironmentDescriptor as n, EnvironmentStatusResult as o, EnvironmentProviderCapabilities as p, IWorkspaceProvider as q, WorkspaceMount as r, WorkspaceDescriptor as s, AttachWorkspaceRequest as t, WorkspaceAttachment as u, WorkspaceStatusResult as v, WorkspaceProviderCapabilities as w, ISnapshotProvider as x, CaptureSnapshotRequest as y, SnapshotDescriptor as z };