baselineos 0.2.0-beta.1

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 (64) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +198 -0
  3. package/dist/__evals__/runner.d.ts +2 -0
  4. package/dist/__evals__/runner.js +14687 -0
  5. package/dist/__evals__/runner.js.map +1 -0
  6. package/dist/api/server.d.ts +21 -0
  7. package/dist/api/server.js +1007 -0
  8. package/dist/api/server.js.map +1 -0
  9. package/dist/cli/bin.d.ts +1 -0
  10. package/dist/cli/bin.js +8427 -0
  11. package/dist/cli/bin.js.map +1 -0
  12. package/dist/core/agent-bus.d.ts +110 -0
  13. package/dist/core/agent-bus.js +242 -0
  14. package/dist/core/agent-bus.js.map +1 -0
  15. package/dist/core/cache.d.ts +66 -0
  16. package/dist/core/cache.js +160 -0
  17. package/dist/core/cache.js.map +1 -0
  18. package/dist/core/config.d.ts +1002 -0
  19. package/dist/core/config.js +429 -0
  20. package/dist/core/config.js.map +1 -0
  21. package/dist/core/indexer.d.ts +152 -0
  22. package/dist/core/indexer.js +481 -0
  23. package/dist/core/indexer.js.map +1 -0
  24. package/dist/core/llm-tracer.d.ts +2 -0
  25. package/dist/core/llm-tracer.js +241 -0
  26. package/dist/core/llm-tracer.js.map +1 -0
  27. package/dist/core/memory.d.ts +86 -0
  28. package/dist/core/memory.js +346 -0
  29. package/dist/core/memory.js.map +1 -0
  30. package/dist/core/opa-client.d.ts +51 -0
  31. package/dist/core/opa-client.js +157 -0
  32. package/dist/core/opa-client.js.map +1 -0
  33. package/dist/core/opa-policy-gate.d.ts +133 -0
  34. package/dist/core/opa-policy-gate.js +454 -0
  35. package/dist/core/opa-policy-gate.js.map +1 -0
  36. package/dist/core/orchestrator.d.ts +14 -0
  37. package/dist/core/orchestrator.js +1297 -0
  38. package/dist/core/orchestrator.js.map +1 -0
  39. package/dist/core/pii-detector.d.ts +82 -0
  40. package/dist/core/pii-detector.js +126 -0
  41. package/dist/core/pii-detector.js.map +1 -0
  42. package/dist/core/rag-engine.d.ts +121 -0
  43. package/dist/core/rag-engine.js +504 -0
  44. package/dist/core/rag-engine.js.map +1 -0
  45. package/dist/core/task-queue.d.ts +69 -0
  46. package/dist/core/task-queue.js +124 -0
  47. package/dist/core/task-queue.js.map +1 -0
  48. package/dist/core/telemetry.d.ts +56 -0
  49. package/dist/core/telemetry.js +94 -0
  50. package/dist/core/telemetry.js.map +1 -0
  51. package/dist/core/types.d.ts +328 -0
  52. package/dist/core/types.js +24 -0
  53. package/dist/core/types.js.map +1 -0
  54. package/dist/index.d.ts +21 -0
  55. package/dist/index.js +12444 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/llm-tracer-CIIujuO-.d.ts +493 -0
  58. package/dist/mcp/server.d.ts +2651 -0
  59. package/dist/mcp/server.js +676 -0
  60. package/dist/mcp/server.js.map +1 -0
  61. package/dist/orchestrator-DF89k_AK.d.ts +506 -0
  62. package/package.json +157 -0
  63. package/templates/README.md +7 -0
  64. package/templates/baseline.config.ts +207 -0
@@ -0,0 +1,2651 @@
1
+ import { WorkflowBudget, Task, Agent, TaskInput, TaskPriority, AgentRole, Checkpoint, VerificationResult, Review, ExecutionStep, TaskStatus, Artifact, WorkflowDefinition, OrchestratorEvent } from '../core/types.js';
2
+ import { AgentBus, BusStats } from '../core/agent-bus.js';
3
+ import { CollectionName, RAGResult, IngestionResult } from '../core/rag-engine.js';
4
+ import { O as Orchestrator, E as ExecutionResult, D as DecompositionResult, a as ExecutionEngine } from '../orchestrator-DF89k_AK.js';
5
+ import { MemoryScope, StoreOptions, RetrieveOptions } from '../core/memory.js';
6
+ import { PolicyFilter, SearchResult, ContextLevel, Overlay, RetrievalBudget, Context } from '../core/indexer.js';
7
+ import { BaselineConfig } from '../core/config.js';
8
+ import { OPAPolicyGate } from '../core/opa-policy-gate.js';
9
+ import { V as VersionEvalResult, T as TraceCurator, M as ModelVersionRegistry, P as ProductionEvalPipeline, a as VersionComparison } from '../llm-tracer-CIIujuO-.js';
10
+ import '../core/cache.js';
11
+ import { BaselineGovernSystem, ComplianceCheck, GovernanceAuditEvent, GovernEvidenceBundle, GovernResult } from '@baselineos/govern';
12
+ import { TaskResult, MigrationMode, BaselineAutonomySystem, AgentStatusReport, IntegrationStatus, MigrationRecommendation } from '@baselineos/autonomy';
13
+ import { EventEmitter } from 'eventemitter3';
14
+ import { EventEmitter as EventEmitter$1 } from 'events';
15
+ import { PiiDetector } from '../core/pii-detector.js';
16
+ import '../core/task-queue.js';
17
+ import { Client, WorkflowHandle } from '@temporalio/client';
18
+ import 'zod';
19
+ import '@baselineos/persona';
20
+ import '../core/opa-client.js';
21
+
22
+ /**
23
+ * BaselineOS MCP Server
24
+ *
25
+ * Model Context Protocol server for Claude Desktop and other MCP clients.
26
+ *
27
+ * @license Apache-2.0
28
+ */
29
+
30
+ declare class MCPServer {
31
+ private baseline;
32
+ private server?;
33
+ private transport?;
34
+ private running;
35
+ constructor(baseline: Baseline);
36
+ start(): Promise<void>;
37
+ stop(): Promise<void>;
38
+ isRunning(): boolean;
39
+ private getTools;
40
+ private getResources;
41
+ private handleToolCall;
42
+ private enforceToolRisk;
43
+ private readResource;
44
+ }
45
+
46
+ /**
47
+ * DriftDetector — SIGNAL-060
48
+ *
49
+ * Monitors production eval score history to detect model quality drift.
50
+ * Drift is defined as a statistically meaningful decline in eval score
51
+ * over a rolling window of runs.
52
+ *
53
+ * Detection strategies:
54
+ * threshold — drift if latest score < (baseline − thresholdDrop)
55
+ * trend — drift if rolling-window slope is negative beyond slopeThreshold
56
+ * consecutive — drift if N consecutive runs are below the baseline mean
57
+ *
58
+ * On drift detection:
59
+ * - Publishes governance:model-drift-detected on AgentBus
60
+ * - Returns DriftReport with severity and recommended action
61
+ * - Does NOT automatically trigger a cycle (caller decides)
62
+ *
63
+ * Usage:
64
+ * const detector = new DriftDetector({ bus, thresholdDrop: 5, windowSize: 5 });
65
+ * const report = detector.analyze(pipeline.getHistory('claude-sonnet-4-6'));
66
+ * if (report.drifted) { cycleLog.startCycle('quality-drift', datasetSize); }
67
+ *
68
+ * @license Apache-2.0
69
+ */
70
+
71
+ type DriftSeverity = 'none' | 'warning' | 'critical';
72
+ type DriftStrategy = 'threshold' | 'trend' | 'consecutive';
73
+ interface DriftReport {
74
+ modelId: string;
75
+ drifted: boolean;
76
+ severity: DriftSeverity;
77
+ strategy: DriftStrategy;
78
+ /** Current score (latest entry) */
79
+ currentScore: number;
80
+ /** Baseline score used for comparison (rolling mean of earlier entries) */
81
+ baselineScore: number;
82
+ /** currentScore − baselineScore (negative = regression) */
83
+ delta: number;
84
+ /** Number of entries analyzed */
85
+ samplesAnalyzed: number;
86
+ /** Recommended action */
87
+ recommendation: 'monitor' | 'investigate' | 'start-improvement-cycle';
88
+ timestamp: string;
89
+ details: string;
90
+ }
91
+ interface DriftDetectorConfig {
92
+ bus?: AgentBus;
93
+ /** Minimum number of history entries needed to analyze. Default: 3 */
94
+ minSamples?: number;
95
+ /** Rolling window size for baseline computation. Default: 5 */
96
+ windowSize?: number;
97
+ /** Score drop (absolute points) required to flag as drift. Default: 5 */
98
+ thresholdDrop?: number;
99
+ /** Score drop beyond which severity = 'critical'. Default: 10 */
100
+ criticalDrop?: number;
101
+ /**
102
+ * Minimum negative slope per step to flag trend drift. Default: -1.5
103
+ * Only used when strategy = 'trend'.
104
+ */
105
+ slopeThreshold?: number;
106
+ /**
107
+ * Number of consecutive below-baseline runs before flagging. Default: 3
108
+ * Only used when strategy = 'consecutive'.
109
+ */
110
+ consecutiveThreshold?: number;
111
+ /** Detection strategy. Default: 'threshold' */
112
+ strategy?: DriftStrategy;
113
+ }
114
+ declare class DriftDetector {
115
+ private readonly bus?;
116
+ private readonly minSamples;
117
+ private readonly windowSize;
118
+ private readonly thresholdDrop;
119
+ private readonly criticalDrop;
120
+ private readonly slopeThreshold;
121
+ private readonly consecutiveThreshold;
122
+ private readonly strategy;
123
+ constructor(config?: DriftDetectorConfig);
124
+ /**
125
+ * Analyze an array of VersionEvalResults for drift.
126
+ * Entries should be sorted oldest-first (as returned by getHistory()).
127
+ * Returns a DriftReport. If insufficient samples, returns severity='none'.
128
+ */
129
+ analyze(entries: VersionEvalResult[]): DriftReport;
130
+ /**
131
+ * Convenience: analyze entries and auto-start a cycle when drift detected.
132
+ * Returns the drift report; caller is responsible for acting on it.
133
+ */
134
+ check(entries: VersionEvalResult[]): DriftReport;
135
+ /** Compute baseline as rolling mean of the earlier (non-latest) window entries. */
136
+ private _computeBaseline;
137
+ private _analyzeThreshold;
138
+ private _analyzeTrend;
139
+ private _analyzeConsecutive;
140
+ private _noDrift;
141
+ private _driftReport;
142
+ private _emitEvent;
143
+ }
144
+
145
+ /**
146
+ * CostGuard — SIGNAL-030 + SIGNAL-052
147
+ *
148
+ * Per-workflow cost accumulation and auto-pause enforcement.
149
+ * Tracks token usage and estimated cost per workflow run, comparing
150
+ * accumulated spend against the WorkflowBudget configured for each
151
+ * workflow type.
152
+ *
153
+ * Auto-pause fires when ANY budget limit is exceeded:
154
+ * - maxCostUsd — total estimated USD spend
155
+ * - maxTokens — total tokens consumed
156
+ * - maxSteps — number of record() calls (proxy for LLM steps)
157
+ *
158
+ * When a threshold is crossed, CostGuard:
159
+ * - Returns { paused: true } from check()
160
+ * - Publishes governance:cost-threshold-exceeded on the AgentBus
161
+ * - Does NOT fire duplicate events for the same workflow until reset()
162
+ *
163
+ * Default pricing: $9/1M tokens (blended sonnet-4-6 rate).
164
+ * Override per-workflow via WorkflowBudget.costPer1kTokensUsd.
165
+ *
166
+ * Usage:
167
+ * const guard = new CostGuard({ bus });
168
+ * guard.record('wf-1', { inputTokens: 1000, outputTokens: 200 }, budget);
169
+ * const { paused, reason } = guard.check('wf-1', budget);
170
+ * if (paused) { ... }
171
+ * guard.reset('wf-1'); // on workflow completion/failure
172
+ *
173
+ * @license Apache-2.0
174
+ */
175
+
176
+ interface CostGuardConfig {
177
+ bus?: AgentBus;
178
+ /** Default cost per 1k tokens when not specified in budget. Default: 0.009 */
179
+ defaultCostPer1kTokensUsd?: number;
180
+ }
181
+ interface TokenUsage {
182
+ inputTokens: number;
183
+ outputTokens: number;
184
+ }
185
+ interface WorkflowAccumulator {
186
+ totalTokens: number;
187
+ totalCostUsd: number;
188
+ steps: number;
189
+ /** True if a threshold-exceeded event has already been published */
190
+ alreadyPaused: boolean;
191
+ }
192
+ interface TenantCostSummary {
193
+ tenantId: string;
194
+ totalTokens: number;
195
+ totalCostUsd: number;
196
+ workflowCount: number;
197
+ }
198
+ interface CostCheckResult {
199
+ paused: boolean;
200
+ reason?: string;
201
+ accumulator: WorkflowAccumulator;
202
+ }
203
+ declare class CostGuard {
204
+ private readonly accumulators;
205
+ /** tenantId → { totalTokens, totalCostUsd, workflowIds } */
206
+ private readonly tenantAccumulators;
207
+ private readonly bus?;
208
+ private readonly defaultCostPer1k;
209
+ constructor(config?: CostGuardConfig);
210
+ /**
211
+ * Record token usage for a workflow step.
212
+ * Returns the updated accumulator after recording.
213
+ */
214
+ record(workflowId: string, usage: TokenUsage, budget?: WorkflowBudget): WorkflowAccumulator;
215
+ /**
216
+ * Check whether a workflow has exceeded its budget.
217
+ * Publishes governance:cost-threshold-exceeded on first crossing.
218
+ */
219
+ check(workflowId: string, budget?: WorkflowBudget): CostCheckResult;
220
+ /**
221
+ * Reset accumulator for a workflow (call on completion or failure).
222
+ */
223
+ reset(workflowId: string): void;
224
+ /** Return current accumulator snapshot without modifying state. */
225
+ snapshot(workflowId: string): WorkflowAccumulator;
226
+ /**
227
+ * Return cost summary grouped by tenantId (SIGNAL-052).
228
+ * Only includes tenants that have been passed via budget.tenantId.
229
+ */
230
+ getCostByTenant(): TenantCostSummary[];
231
+ private getOrCreate;
232
+ }
233
+
234
+ interface APIServerConfig {
235
+ port: number;
236
+ allowedOrigins?: string[];
237
+ }
238
+ declare class APIServer {
239
+ private app;
240
+ private server;
241
+ private wss;
242
+ private baseline;
243
+ private config;
244
+ private clients;
245
+ private unsubscribeEvents;
246
+ private metricsCounters;
247
+ /** Optional CostGuard for per-tenant cost metrics (SIGNAL-052) */
248
+ private costGuard?;
249
+ /** Optional TraceCurator for dataset size gauge (SIGNAL-049) */
250
+ private traceCurator?;
251
+ /** Optional ModelVersionRegistry for active model version gauge (SIGNAL-049) */
252
+ private modelVersionRegistry?;
253
+ /** Optional ProductionEvalPipeline for latest eval score gauge (SIGNAL-056) */
254
+ private productionEvalPipeline?;
255
+ /** Optional DriftDetector for model drift metrics (SIGNAL-071) */
256
+ private driftDetector?;
257
+ /** Optional OPAPolicyGate for SLO-6 latency metrics */
258
+ private opaPolicyGate?;
259
+ constructor(baseline: Baseline, config: APIServerConfig);
260
+ private setupMiddleware;
261
+ private setupRoutes;
262
+ private setupWebSocket;
263
+ private attachEventBridge;
264
+ private createTask;
265
+ private listTasks;
266
+ private getTask;
267
+ private cancelTask;
268
+ private approveTask;
269
+ private getTaskArtifacts;
270
+ private getTaskAudit;
271
+ private getTaskEvidence;
272
+ private listWorkflows;
273
+ private runWorkflow;
274
+ private getCheckpoint;
275
+ private recoverCheckpoint;
276
+ private listAgents;
277
+ private search;
278
+ private getContext;
279
+ private indexKnowledge;
280
+ private initDeployment;
281
+ private scanDeployment;
282
+ private scanPath;
283
+ private remember;
284
+ private recall;
285
+ private getStats;
286
+ private getMetrics;
287
+ /** Inject a CostGuard instance for per-tenant cost metrics (SIGNAL-052). */
288
+ setCostGuard(guard: CostGuard): void;
289
+ /** Inject a TraceCurator for the dataset-size gauge (SIGNAL-049). */
290
+ setTraceCurator(curator: TraceCurator): void;
291
+ /** Inject a ModelVersionRegistry for the active-model gauge (SIGNAL-049). */
292
+ setModelVersionRegistry(registry: ModelVersionRegistry): void;
293
+ /** Inject a ProductionEvalPipeline for the eval score gauge (SIGNAL-056). */
294
+ setProductionEvalPipeline(pipeline: ProductionEvalPipeline): void;
295
+ /** Inject a DriftDetector for model drift metrics (SIGNAL-071). */
296
+ setDriftDetector(detector: DriftDetector): void;
297
+ /** Inject an OPAPolicyGate for SLO-6 latency metrics. */
298
+ setOPAPolicyGate(gate: OPAPolicyGate): void;
299
+ private handleWebSocketMessage;
300
+ /**
301
+ * Broadcast message to all connected WebSocket clients.
302
+ */
303
+ broadcast(message: object): void;
304
+ private errorHandler;
305
+ private formatStartError;
306
+ start(): Promise<void>;
307
+ stop(): Promise<void>;
308
+ }
309
+
310
+ /**
311
+ * TradePass Governance Bridge
312
+ *
313
+ * Connects TradePass protocol verification to Baseline governance layer.
314
+ * Produces GovernanceAuditEvent records for every trade verification,
315
+ * enabling auditable governance trails on cross-border transactions.
316
+ */
317
+
318
+ interface TradeContext {
319
+ tradeId: string;
320
+ protocol: 'TradePass' | 'GeoTag' | 'GCI' | 'VaultMark' | 'PvP' | 'PANX';
321
+ parties: Array<{
322
+ id: string;
323
+ role: 'exporter' | 'importer' | 'verifier' | 'regulator';
324
+ jurisdiction: string;
325
+ }>;
326
+ commodity: {
327
+ code: string;
328
+ description: string;
329
+ quantity: number;
330
+ unit: string;
331
+ value: number;
332
+ currency: string;
333
+ };
334
+ origin: {
335
+ country: string;
336
+ region?: string;
337
+ facility?: string;
338
+ };
339
+ destination: {
340
+ country: string;
341
+ region?: string;
342
+ };
343
+ documents: Array<{
344
+ type: string;
345
+ id: string;
346
+ verified: boolean;
347
+ }>;
348
+ standards: string[];
349
+ metadata?: Record<string, unknown>;
350
+ }
351
+ interface TradeVerificationResult {
352
+ tradeId: string;
353
+ verified: boolean;
354
+ complianceChecks: ComplianceCheck[];
355
+ riskLevel: 'low' | 'medium' | 'high' | 'critical';
356
+ auditEvents: GovernanceAuditEvent[];
357
+ evidenceBundle: GovernEvidenceBundle;
358
+ duration: number;
359
+ timestamp: Date;
360
+ }
361
+ declare class TradePassGovernanceBridge {
362
+ private govern;
363
+ private policyId;
364
+ constructor(govern?: BaselineGovernSystem);
365
+ initialize(): Promise<void>;
366
+ verifyWithGovernance(context: TradeContext): Promise<TradeVerificationResult>;
367
+ getTradeEvidenceBundle(tradeId: string): Promise<GovernEvidenceBundle>;
368
+ getComplianceReport(standard: string): Promise<GovernResult>;
369
+ getAuditTrail(tradeId?: string): GovernanceAuditEvent[];
370
+ private assessComplexity;
371
+ private assessImpact;
372
+ }
373
+
374
+ /**
375
+ * NDPC Compliance Gate
376
+ *
377
+ * Implements Ghana's National Data Protection Commission (NDPC) DPA 2012
378
+ * compliance checks. Gates AI agent actions and data migration flows,
379
+ * blocking non-compliant operations with detailed violation reports.
380
+ */
381
+
382
+ interface NDPCContext {
383
+ dataSubject?: {
384
+ jurisdiction: string;
385
+ consentGiven: boolean;
386
+ consentScope?: string[];
387
+ consentDate?: Date;
388
+ };
389
+ dataProcessing: {
390
+ purpose: string;
391
+ categories: string[];
392
+ recipients?: string[];
393
+ crossBorderTransfer: boolean;
394
+ transferDestination?: string;
395
+ };
396
+ dataRetention: {
397
+ period?: number;
398
+ unit?: 'days' | 'months' | 'years';
399
+ justification?: string;
400
+ };
401
+ dataMinimization: {
402
+ fieldsCollected: string[];
403
+ fieldsRequired: string[];
404
+ };
405
+ operator: {
406
+ id: string;
407
+ role: string;
408
+ };
409
+ metadata?: Record<string, unknown>;
410
+ }
411
+ interface NDPCViolation {
412
+ rule: string;
413
+ description: string;
414
+ severity: 'low' | 'medium' | 'high' | 'critical';
415
+ remediation: string;
416
+ }
417
+ interface NDPCCheckResult {
418
+ compliant: boolean;
419
+ violations: NDPCViolation[];
420
+ complianceCheck: ComplianceCheck | undefined;
421
+ timestamp: Date;
422
+ }
423
+ declare class NDPCComplianceGate {
424
+ private govern;
425
+ constructor(govern?: BaselineGovernSystem);
426
+ check(context: NDPCContext): Promise<NDPCCheckResult>;
427
+ validate(context: NDPCContext): NDPCViolation[];
428
+ getReport(): Promise<GovernResult>;
429
+ isAdequateJurisdiction(countryCode: string): boolean;
430
+ }
431
+
432
+ /**
433
+ * Evidence Export
434
+ *
435
+ * Exports DFI-ready evidence bundles from the Baseline governance layer.
436
+ * Produces standalone JSON that external auditors can review without
437
+ * Baseline knowledge — self-describing, timestamped, signed metadata.
438
+ */
439
+
440
+ interface DFIEvidenceBundle {
441
+ version: '1.0.0';
442
+ exportedAt: string;
443
+ exportedBy: string;
444
+ format: 'baseline-evidence-bundle';
445
+ metadata: {
446
+ policyId?: string;
447
+ resourceId?: string;
448
+ governanceSystem: string;
449
+ exportDuration: number;
450
+ };
451
+ summary: {
452
+ totalAuditEvents: number;
453
+ totalComplianceChecks: number;
454
+ totalApprovals: number;
455
+ overallCompliant: boolean;
456
+ riskLevel?: string;
457
+ };
458
+ policy?: {
459
+ id: string;
460
+ name: string;
461
+ description: string;
462
+ status: string;
463
+ createdAt: string;
464
+ updatedAt: string;
465
+ };
466
+ complianceChecks: Array<{
467
+ id: string;
468
+ standard: string;
469
+ compliant: boolean;
470
+ violations: string[];
471
+ checked: string;
472
+ }>;
473
+ approvals: Array<{
474
+ id: string;
475
+ policyId: string;
476
+ status: string;
477
+ approvals: Array<{
478
+ approver: string;
479
+ at: string;
480
+ }>;
481
+ rejections: Array<{
482
+ approver: string;
483
+ at: string;
484
+ }>;
485
+ }>;
486
+ auditTrail: Array<{
487
+ id: string;
488
+ type: string;
489
+ actor: string;
490
+ timestamp: string;
491
+ details: Record<string, unknown>;
492
+ }>;
493
+ }
494
+ interface ExportOptions {
495
+ policyId?: string;
496
+ resourceId?: string;
497
+ outputPath?: string;
498
+ operator?: string;
499
+ includeDetails?: boolean;
500
+ }
501
+ declare class EvidenceExporter {
502
+ private govern;
503
+ constructor(govern?: BaselineGovernSystem);
504
+ exportBundle(options?: ExportOptions): Promise<DFIEvidenceBundle>;
505
+ exportJSON(options?: ExportOptions): Promise<string>;
506
+ exportToFile(options: ExportOptions & {
507
+ outputPath: string;
508
+ }): Promise<{
509
+ path: string;
510
+ size: number;
511
+ duration: number;
512
+ }>;
513
+ exportSummary(bundle: DFIEvidenceBundle): string;
514
+ private extractRiskLevel;
515
+ /**
516
+ * Export evidence bundle as a self-contained HTML document suitable for
517
+ * PDF conversion (print to PDF from browser, or puppeteer/wkhtmltopdf).
518
+ * DFI partners can open this in any browser and print.
519
+ */
520
+ exportHTML(options?: ExportOptions): Promise<string>;
521
+ exportHTMLToFile(options: ExportOptions & {
522
+ outputPath: string;
523
+ }): Promise<{
524
+ path: string;
525
+ size: number;
526
+ duration: number;
527
+ }>;
528
+ private extractViolations;
529
+ }
530
+
531
+ /**
532
+ * Compliance-OS Bridge
533
+ *
534
+ * Integration bridge for compliance-os to consume @baselineos/govern.
535
+ * Maps ComplianceOS control lifecycle to Baseline governance policy lifecycle
536
+ * (create → approve → enforce), producing GovernEvidenceBundle artifacts
537
+ * and writing audit trail to .baseline/govern/audit-trail.json.
538
+ */
539
+
540
+ interface ComplianceControl {
541
+ controlId: string;
542
+ name: string;
543
+ description: string;
544
+ standard: string;
545
+ jurisdiction: string;
546
+ severity: 'low' | 'medium' | 'high' | 'critical';
547
+ enforcement: 'advisory' | 'warn' | 'block';
548
+ }
549
+ interface ControlCheckContext {
550
+ controlId: string;
551
+ standard: string;
552
+ jurisdiction: string;
553
+ scope: string;
554
+ operator: string;
555
+ evidence?: Record<string, unknown>;
556
+ metadata?: Record<string, unknown>;
557
+ }
558
+ interface ControlCheckResult {
559
+ controlId: string;
560
+ compliant: boolean;
561
+ complianceCheck?: ComplianceCheck;
562
+ riskLevel: 'low' | 'medium' | 'high' | 'critical';
563
+ evidenceBundle: GovernEvidenceBundle;
564
+ auditEvents: GovernanceAuditEvent[];
565
+ duration: number;
566
+ timestamp: Date;
567
+ }
568
+ declare class ComplianceOSBridge {
569
+ private govern;
570
+ private controlPolicies;
571
+ constructor(govern?: BaselineGovernSystem);
572
+ registerControl(control: ComplianceControl): Promise<string>;
573
+ checkControl(context: ControlCheckContext): Promise<ControlCheckResult>;
574
+ getComplianceEvidence(controlId: string): Promise<GovernEvidenceBundle>;
575
+ getComplianceReport(standard: string): Promise<GovernResult>;
576
+ getAuditTrail(controlId?: string): GovernanceAuditEvent[];
577
+ getRegisteredControls(): string[];
578
+ }
579
+
580
+ /**
581
+ * Sensei-AI Bridge
582
+ *
583
+ * Integration bridge for sensei-ai (AMIS) to consume @baselineos/autonomy.
584
+ * Wraps BaselineAutonomySystem and BaselineAutonomyIntegration for
585
+ * migration task orchestration with safety governance and audit trail.
586
+ */
587
+
588
+ interface MigrationTaskContext {
589
+ projectId: string;
590
+ taskDescription: string;
591
+ sourceSystem: string;
592
+ targetSystem: string;
593
+ dataType: 'structured' | 'unstructured' | 'mixed';
594
+ recordCount?: number;
595
+ hasPII?: boolean;
596
+ complianceRequired?: boolean;
597
+ impactLevel?: 'low' | 'medium' | 'high';
598
+ }
599
+ interface MigrationResult {
600
+ agentId: string;
601
+ taskResult: TaskResult;
602
+ trustScore: number;
603
+ safetyLevel: string;
604
+ migrationMode: MigrationMode;
605
+ duration: number;
606
+ timestamp: Date;
607
+ }
608
+ interface MigrationAuditEntry {
609
+ agentId: string;
610
+ agentName: string;
611
+ trustScore: number;
612
+ safetyLevel: string;
613
+ tasksCompleted: number;
614
+ tasksFailed: number;
615
+ status: string;
616
+ }
617
+ declare class SenseiAIBridge {
618
+ private autonomy;
619
+ private integration;
620
+ private migrationAgents;
621
+ constructor(autonomy?: BaselineAutonomySystem);
622
+ initialize(mode?: MigrationMode): Promise<void>;
623
+ createMigrationAgent(context: MigrationTaskContext): Promise<AgentStatusReport>;
624
+ executeMigration(context: MigrationTaskContext): Promise<MigrationResult>;
625
+ getIntegrationStatus(): IntegrationStatus;
626
+ getMigrationRecommendations(): MigrationRecommendation[];
627
+ getMigrationAudit(projectId?: string): MigrationAuditEntry[];
628
+ shutdown(): Promise<void>;
629
+ }
630
+
631
+ /**
632
+ * Governance Validator
633
+ *
634
+ * Wires the 7 governance pillar validators (policy, risk, compliance,
635
+ * approval, permission, cost, evidence) to the orchestrator's execution
636
+ * lifecycle via pre-execution and post-execution hooks.
637
+ *
638
+ * @license Apache-2.0
639
+ */
640
+
641
+ interface GovernanceValidatorConfig {
642
+ policy: {
643
+ enabled: boolean;
644
+ enforcement: 'advisory' | 'warn' | 'block';
645
+ };
646
+ risk: {
647
+ enabled: boolean;
648
+ blockOnCritical: boolean;
649
+ };
650
+ compliance: {
651
+ enabled: boolean;
652
+ standards: string[];
653
+ };
654
+ approval: {
655
+ enabled: boolean;
656
+ requiredApprovers: string[];
657
+ };
658
+ permission: {
659
+ enabled: boolean;
660
+ };
661
+ cost: {
662
+ enabled: boolean;
663
+ maxBudgetUsd?: number;
664
+ };
665
+ evidence: {
666
+ enabled: boolean;
667
+ autoExport: boolean;
668
+ exportPath: string;
669
+ };
670
+ }
671
+ interface GovernanceValidationResult {
672
+ passed: boolean;
673
+ blocked: boolean;
674
+ pillarResults: PillarResult[];
675
+ auditEvents: GovernanceAuditEvent[];
676
+ }
677
+ interface PillarResult {
678
+ pillar: string;
679
+ enabled: boolean;
680
+ passed: boolean;
681
+ blocked: boolean;
682
+ details: string;
683
+ }
684
+ declare class GovernanceValidator {
685
+ private govern;
686
+ private config;
687
+ constructor(govern: BaselineGovernSystem, config?: Partial<GovernanceValidatorConfig>);
688
+ /**
689
+ * Pre-execution validation: risk assessment, permission check, approval gate.
690
+ * Runs BEFORE the task is executed. Can block execution.
691
+ */
692
+ preExecution(task: Task, actor: string): Promise<GovernanceValidationResult>;
693
+ /**
694
+ * Post-execution validation: policy enforcement, compliance check,
695
+ * cost tracking, evidence generation. Runs AFTER execution completes.
696
+ */
697
+ postExecution(task: Task, actor: string, output: {
698
+ tokensUsed: number;
699
+ duration: number;
700
+ }): Promise<GovernanceValidationResult>;
701
+ private mapComplexity;
702
+ private mapPriority;
703
+ }
704
+
705
+ /**
706
+ * Trust Sync Protocol
707
+ *
708
+ * Synchronizes trust scoring between the Orchestrator (core runtime)
709
+ * and the Autonomy layer (agent lifecycle). Ensures a single source
710
+ * of truth for agent trust scores across both systems.
711
+ *
712
+ * @license Apache-2.0
713
+ */
714
+
715
+ interface TrustSyncTarget {
716
+ /** Get the current trust score for an agent */
717
+ getTrustScore(agentId: string): number | undefined;
718
+ /** Update the trust score for an agent */
719
+ setTrustScore(agentId: string, score: number): void;
720
+ }
721
+ interface TrustSyncEvent {
722
+ agentId: string;
723
+ previousScore: number;
724
+ newScore: number;
725
+ source: 'orchestrator' | 'autonomy';
726
+ success: boolean;
727
+ timestamp: number;
728
+ }
729
+ declare class TrustSyncProtocol {
730
+ private orchestrator;
731
+ private targets;
732
+ private history;
733
+ private maxHistory;
734
+ constructor(orchestrator: Orchestrator, opts?: {
735
+ maxHistory?: number;
736
+ });
737
+ /**
738
+ * Register a sync target (e.g., autonomy system).
739
+ * Trust updates from the orchestrator will propagate to all registered targets.
740
+ */
741
+ registerTarget(name: string, target: TrustSyncTarget): void;
742
+ /**
743
+ * Remove a sync target.
744
+ */
745
+ unregisterTarget(name: string): void;
746
+ /**
747
+ * Handle a trust update from the orchestrator.
748
+ * Propagates the new trust score to all registered targets.
749
+ */
750
+ handleOrchestratorUpdate(agentId: string, newScore: number, success: boolean): void;
751
+ /**
752
+ * Handle a trust update from an autonomy target.
753
+ * Propagates the new trust score to the orchestrator's agent record.
754
+ */
755
+ handleAutonomyUpdate(agentId: string, newScore: number, success: boolean): void;
756
+ /**
757
+ * Get sync history for auditing.
758
+ */
759
+ getHistory(): TrustSyncEvent[];
760
+ /**
761
+ * Get the current trust score for an agent from the orchestrator.
762
+ */
763
+ getScore(agentId: string): number | undefined;
764
+ /**
765
+ * Get all registered target names.
766
+ */
767
+ getTargetNames(): string[];
768
+ private recordEvent;
769
+ }
770
+
771
+ /**
772
+ * Agentic Bridge
773
+ *
774
+ * Integration surface for the `1-agentic` repo to consume Baseline
775
+ * governance, trust scoring, and task lifecycle. This bridge is the
776
+ * canonical entry point for connecting GTCX's autonomous agent
777
+ * infrastructure with Baseline's governance engine.
778
+ *
779
+ * Usage in 1-agentic:
780
+ * ```typescript
781
+ * import { AgenticBridge } from 'baselineos';
782
+ *
783
+ * const bridge = new AgenticBridge({ persistPath: '.baseline/govern' });
784
+ * await bridge.initialize();
785
+ *
786
+ * // Register an agent
787
+ * bridge.registerAgent({ id: 'planner-1', name: 'Task Planner', ... });
788
+ *
789
+ * // Execute with governance
790
+ * const result = await bridge.executeWithGovernance(task, 'planner-1');
791
+ * ```
792
+ *
793
+ * @license Apache-2.0
794
+ */
795
+
796
+ interface AgenticBridgeConfig {
797
+ persistPath?: string;
798
+ governance?: Partial<GovernanceValidatorConfig>;
799
+ trustGrowthRate?: number;
800
+ trustDecayRate?: number;
801
+ trustMinimum?: number;
802
+ }
803
+ interface SafetyRule$1 {
804
+ id: string;
805
+ name: string;
806
+ description: string;
807
+ severity: 'warning' | 'blocking';
808
+ check: (task: Task, agent: Agent) => SafetyCheckResult;
809
+ }
810
+ interface SafetyCheckResult {
811
+ passed: boolean;
812
+ ruleId: string;
813
+ message: string;
814
+ }
815
+ interface SafetyViolation {
816
+ ruleId: string;
817
+ ruleName: string;
818
+ severity: 'warning' | 'blocking';
819
+ agentId: string;
820
+ taskId: string;
821
+ message: string;
822
+ timestamp: Date;
823
+ }
824
+ interface AgenticExecutionResult {
825
+ task: Task;
826
+ preValidation: GovernanceValidationResult;
827
+ postValidation: GovernanceValidationResult;
828
+ safetyChecks: SafetyCheckResult[];
829
+ safetyViolations: SafetyViolation[];
830
+ blocked: boolean;
831
+ blockReason?: string;
832
+ }
833
+ declare class AgenticBridge {
834
+ private orchestrator;
835
+ private govern;
836
+ private validator;
837
+ private trustSync;
838
+ private safetyRules;
839
+ private initialized;
840
+ constructor(config?: AgenticBridgeConfig);
841
+ /**
842
+ * Initialize the bridge. Must be called before use.
843
+ */
844
+ initialize(): Promise<void>;
845
+ /**
846
+ * Register an external trust sync target (e.g., 1-agentic's agent registry).
847
+ */
848
+ registerTrustTarget(name: string, target: TrustSyncTarget): void;
849
+ /**
850
+ * Register an agent with the orchestrator.
851
+ */
852
+ registerAgent(agent: Omit<Agent, 'createdAt' | 'lastActiveAt'>): Agent;
853
+ /**
854
+ * Register a safety rule that is checked before every task execution.
855
+ */
856
+ registerSafetyRule(rule: SafetyRule$1): void;
857
+ /**
858
+ * Execute a task with full governance: safety checks → pre-validation →
859
+ * task execution → post-validation → evidence generation.
860
+ */
861
+ executeWithGovernance(input: TaskInput, actorAgentId: string): Promise<AgenticExecutionResult>;
862
+ /**
863
+ * Select the best available agent for a task.
864
+ */
865
+ selectAgent(task: Task): Agent | undefined;
866
+ /**
867
+ * Get the trust score for an agent.
868
+ */
869
+ getTrustScore(agentId: string): number | undefined;
870
+ /**
871
+ * Get the evidence bundle for a policy.
872
+ */
873
+ getEvidenceBundle(policyId: string, resourceId?: string): GovernEvidenceBundle;
874
+ /**
875
+ * Get the full audit trail.
876
+ */
877
+ getAuditTrail(policyId?: string): GovernanceAuditEvent[];
878
+ /**
879
+ * Get all registered agents.
880
+ */
881
+ getAgents(): Agent[];
882
+ /**
883
+ * Get all registered safety rules.
884
+ */
885
+ getSafetyRules(): SafetyRule$1[];
886
+ /**
887
+ * Get the trust sync protocol instance for advanced usage.
888
+ */
889
+ getTrustSync(): TrustSyncProtocol;
890
+ /**
891
+ * Get the governance system instance for advanced usage.
892
+ */
893
+ getGovernSystem(): BaselineGovernSystem;
894
+ private ensureInitialized;
895
+ }
896
+
897
+ /**
898
+ * CommandCenter — Capacity-aware task controller for BaselineOS
899
+ *
900
+ * Sits on top of the Orchestrator to add:
901
+ * - Priority queue with backpressure
902
+ * - Load-balanced agent allocation
903
+ * - Retry with exponential backoff
904
+ * - Escalation batching
905
+ * - Real-time metrics (throughput, utilization, queue depth)
906
+ *
907
+ * @license Apache-2.0
908
+ */
909
+
910
+ interface CommandCenterConfig {
911
+ /** Maximum tasks that can execute concurrently */
912
+ maxConcurrent: number;
913
+ /** Maximum queue depth before rejecting new tasks */
914
+ maxQueueDepth: number;
915
+ /** Base delay for retry backoff (ms) */
916
+ retryBaseDelayMs: number;
917
+ /** Maximum retry delay (ms) */
918
+ retryMaxDelayMs: number;
919
+ /** Maximum retries before escalation */
920
+ maxRetries: number;
921
+ /** How often to drain the queue (ms) */
922
+ drainIntervalMs: number;
923
+ /** Agent idle timeout before marking offline (ms) */
924
+ agentIdleTimeoutMs: number;
925
+ /** Minimum agent trust score for task assignment */
926
+ minTrustScore: number;
927
+ }
928
+ interface QueuedTask {
929
+ id: string;
930
+ input: TaskInput;
931
+ priority: TaskPriority;
932
+ enqueuedAt: number;
933
+ retries: number;
934
+ lastError?: string;
935
+ taskId?: string;
936
+ affinityAgent?: string;
937
+ }
938
+ type CommandCenterStatus = 'idle' | 'running' | 'draining' | 'stopped';
939
+ type CommandCenterEventType = 'task:queued' | 'task:dispatched' | 'task:retrying' | 'task:escalated' | 'task:rejected' | 'queue:backpressure' | 'queue:drained' | 'agent:overloaded' | 'metrics:snapshot';
940
+ interface CommandCenterEvent {
941
+ type: CommandCenterEventType;
942
+ timestamp: number;
943
+ data: Record<string, unknown>;
944
+ }
945
+ interface CommandCenterMetrics {
946
+ queueDepth: number;
947
+ activeCount: number;
948
+ totalDispatched: number;
949
+ totalCompleted: number;
950
+ totalFailed: number;
951
+ totalRetried: number;
952
+ totalEscalated: number;
953
+ totalRejected: number;
954
+ avgWaitTimeMs: number;
955
+ avgExecutionTimeMs: number;
956
+ throughputPerMinute: number;
957
+ agentUtilization: Record<string, number>;
958
+ }
959
+ declare class CommandCenter extends EventEmitter<{
960
+ [K in CommandCenterEventType]: (event: CommandCenterEvent) => void;
961
+ }> {
962
+ private config;
963
+ private orchestrator;
964
+ private queue;
965
+ private active;
966
+ private status;
967
+ private drainTimer;
968
+ private totalDispatched;
969
+ private totalCompleted;
970
+ private totalFailed;
971
+ private totalRetried;
972
+ private totalEscalated;
973
+ private totalRejected;
974
+ private waitTimes;
975
+ private executionTimes;
976
+ private completionTimestamps;
977
+ constructor(orchestrator: Orchestrator, config?: Partial<CommandCenterConfig>);
978
+ start(): void;
979
+ stop(): void;
980
+ getStatus(): CommandCenterStatus;
981
+ submit(input: TaskInput, options?: {
982
+ affinityAgent?: string;
983
+ }): QueuedTask | null;
984
+ getQueueDepth(): number;
985
+ getActiveCount(): number;
986
+ getQueue(): readonly QueuedTask[];
987
+ private insertByPriority;
988
+ drain(): void;
989
+ private selectAgent;
990
+ private hasCapabilityOverlap;
991
+ private capabilityOverlapRatio;
992
+ private dispatch;
993
+ private handleCompletion;
994
+ private handleFailure;
995
+ private attachOrchestratorListeners;
996
+ getMetrics(): CommandCenterMetrics;
997
+ resetMetrics(): void;
998
+ private avg;
999
+ }
1000
+
1001
+ /**
1002
+ * Specialized Agent Definitions for BaselineOS Command Center
1003
+ *
1004
+ * 8 purpose-built agents with distinct capabilities, domains, and roles.
1005
+ * Each agent is designed for a specific class of work within the GTCX ecosystem.
1006
+ *
1007
+ * @license Apache-2.0
1008
+ */
1009
+
1010
+ interface AgentDefinition {
1011
+ id: string;
1012
+ name: string;
1013
+ role: AgentRole;
1014
+ capabilities: string[];
1015
+ domains: string[];
1016
+ description: string;
1017
+ maxConcurrentTasks: number;
1018
+ autoVerify: boolean;
1019
+ escalationThreshold: number;
1020
+ }
1021
+ declare const SPECIALIZED_AGENTS: AgentDefinition[];
1022
+ declare function createAgentFromDefinition(def: AgentDefinition, defaultTrustScore?: number): Agent;
1023
+ declare function getAgentDefinition(agentId: string): AgentDefinition | undefined;
1024
+ declare function getAgentsByCapability(capability: string): AgentDefinition[];
1025
+ declare function getAgentsByDomain(domain: string): AgentDefinition[];
1026
+
1027
+ /**
1028
+ * AgentExecutor — Wires specialized agents to the execution engine
1029
+ *
1030
+ * Connects agent definitions to persona-specific system prompts,
1031
+ * records per-agent tool usage evidence, and applies specialty-weighted
1032
+ * trust scoring on completion.
1033
+ *
1034
+ * @license Apache-2.0
1035
+ */
1036
+
1037
+ interface AgentExecutionRecord {
1038
+ id: string;
1039
+ agentId: string;
1040
+ taskId: string;
1041
+ persona: string;
1042
+ startedAt: number;
1043
+ completedAt?: number;
1044
+ durationMs?: number;
1045
+ tokensUsed: number;
1046
+ toolCalls: ToolCallRecord[];
1047
+ complianceScore: number;
1048
+ complianceViolations: string[];
1049
+ outcome: 'success' | 'failure' | 'blocked';
1050
+ trustBefore: number;
1051
+ trustAfter: number;
1052
+ artifacts: string[];
1053
+ }
1054
+ interface ToolCallRecord {
1055
+ tool: string;
1056
+ timestamp: number;
1057
+ durationMs: number;
1058
+ input: Record<string, unknown>;
1059
+ success: boolean;
1060
+ error?: string;
1061
+ }
1062
+ interface AgentExecutorConfig {
1063
+ /** Trust score bonus multiplier for specialty-matched tasks (default 1.5) */
1064
+ specialtyBonusMultiplier: number;
1065
+ /** Trust score penalty multiplier for out-of-specialty failures (default 0.5) */
1066
+ outOfSpecialtyPenaltyMultiplier: number;
1067
+ /** Maximum execution records to keep in memory */
1068
+ maxRecords: number;
1069
+ }
1070
+ type AgentExecutorEventType = 'execution:started' | 'execution:completed' | 'execution:failed' | 'trust:adjusted';
1071
+ interface AgentExecutorEvent {
1072
+ type: AgentExecutorEventType;
1073
+ timestamp: number;
1074
+ data: Record<string, unknown>;
1075
+ }
1076
+ declare class AgentExecutor extends EventEmitter<{
1077
+ [K in AgentExecutorEventType]: (event: AgentExecutorEvent) => void;
1078
+ }> {
1079
+ private config;
1080
+ private orchestrator;
1081
+ private records;
1082
+ private activeExecutions;
1083
+ constructor(orchestrator: Orchestrator, config?: Partial<AgentExecutorConfig>);
1084
+ recordExecutionStart(agentId: string, taskId: string): AgentExecutionRecord;
1085
+ recordToolCall(recordId: string, call: ToolCallRecord): void;
1086
+ completeExecution(recordId: string, result: ExecutionResult, task: Task): AgentExecutionRecord | null;
1087
+ private calculateTrustDelta;
1088
+ private isSpecialtyMatch;
1089
+ resolvePersona(agentId: string): string;
1090
+ getRecords(filter?: {
1091
+ agentId?: string;
1092
+ taskId?: string;
1093
+ }): AgentExecutionRecord[];
1094
+ getAgentStats(agentId: string): {
1095
+ totalExecutions: number;
1096
+ successRate: number;
1097
+ avgDurationMs: number;
1098
+ avgTokensUsed: number;
1099
+ avgComplianceScore: number;
1100
+ specialtyMatchRate: number;
1101
+ };
1102
+ getActiveExecutions(): AgentExecutionRecord[];
1103
+ }
1104
+
1105
+ /**
1106
+ * Task Handoff Protocol — Cross-agent task chaining
1107
+ *
1108
+ * Enables output of one agent to feed as input to the next,
1109
+ * forming multi-step pipelines across specialized agents.
1110
+ *
1111
+ * @license Apache-2.0
1112
+ */
1113
+
1114
+ interface PipelineStep {
1115
+ id: string;
1116
+ capability: string;
1117
+ description: string;
1118
+ dependsOn: string[];
1119
+ affinityAgent?: string;
1120
+ input?: Record<string, unknown>;
1121
+ }
1122
+ interface Pipeline {
1123
+ id: string;
1124
+ name: string;
1125
+ steps: PipelineStep[];
1126
+ priority: TaskPriority;
1127
+ createdAt: number;
1128
+ }
1129
+ interface PipelineExecution {
1130
+ id: string;
1131
+ pipelineId: string;
1132
+ steps: PipelineStepExecution[];
1133
+ status: 'pending' | 'running' | 'completed' | 'failed';
1134
+ startedAt?: number;
1135
+ completedAt?: number;
1136
+ }
1137
+ interface PipelineStepExecution {
1138
+ stepId: string;
1139
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
1140
+ agentId?: string;
1141
+ taskId?: string;
1142
+ output?: unknown;
1143
+ error?: string;
1144
+ startedAt?: number;
1145
+ completedAt?: number;
1146
+ }
1147
+ interface HandoffContext {
1148
+ fromAgent: string;
1149
+ toAgent: string;
1150
+ fromStep: string;
1151
+ toStep: string;
1152
+ payload: Record<string, unknown>;
1153
+ timestamp: number;
1154
+ }
1155
+ declare function createPipeline(name: string, steps: Array<Omit<PipelineStep, 'id'>>, priority?: TaskPriority): Pipeline;
1156
+ declare function createPipelineExecution(pipeline: Pipeline): PipelineExecution;
1157
+ declare function getReadySteps(execution: PipelineExecution, pipeline: Pipeline): PipelineStep[];
1158
+ declare function isComplete(execution: PipelineExecution): boolean;
1159
+ declare function isFailed(execution: PipelineExecution): boolean;
1160
+ declare function createHandoff(fromAgent: string, toAgent: string, fromStep: string, toStep: string, payload: Record<string, unknown>): HandoffContext;
1161
+ declare function buildStepTaskInput(step: PipelineStep, pipeline: Pipeline, priorOutputs: Map<string, unknown>): TaskInput;
1162
+ declare const STANDARD_PIPELINES: {
1163
+ 'code-review': Pipeline;
1164
+ 'compliance-check': Pipeline;
1165
+ migration: Pipeline;
1166
+ 'feature-delivery': Pipeline;
1167
+ };
1168
+
1169
+ /**
1170
+ * Layer 4 — Agile Agents
1171
+ *
1172
+ * Cross-repo dependency graph, velocity tracking against charter commitments,
1173
+ * and automated standup synthesis from git activity.
1174
+ *
1175
+ * @license Apache-2.0
1176
+ */
1177
+ interface RepoNode {
1178
+ id: string;
1179
+ name: string;
1180
+ path: string;
1181
+ packages: string[];
1182
+ dependencies: string[];
1183
+ }
1184
+ interface DependencyEdge {
1185
+ from: string;
1186
+ to: string;
1187
+ type: 'runtime' | 'dev' | 'peer' | 'integration';
1188
+ package?: string;
1189
+ }
1190
+ interface DependencyGraph {
1191
+ repos: RepoNode[];
1192
+ edges: DependencyEdge[];
1193
+ createdAt: number;
1194
+ }
1195
+ interface BlockerAnalysis {
1196
+ repo: string;
1197
+ blockedBy: string[];
1198
+ blocking: string[];
1199
+ criticalPath: boolean;
1200
+ }
1201
+ declare function createDependencyGraph(repos: RepoNode[], edges: DependencyEdge[]): DependencyGraph;
1202
+ declare function findBlockers(graph: DependencyGraph, repoId: string): BlockerAnalysis;
1203
+ declare function getTopologicalOrder(graph: DependencyGraph): string[];
1204
+ declare function detectCycles(graph: DependencyGraph): string[][];
1205
+ interface CharterCommitment {
1206
+ id: string;
1207
+ description: string;
1208
+ targetDate: string;
1209
+ status: 'on-track' | 'at-risk' | 'blocked' | 'completed' | 'deferred';
1210
+ progressPercent: number;
1211
+ owner?: string;
1212
+ }
1213
+ interface VelocitySnapshot {
1214
+ id: string;
1215
+ period: string;
1216
+ commitments: CharterCommitment[];
1217
+ completedCount: number;
1218
+ totalCount: number;
1219
+ velocityRate: number;
1220
+ projectedCompletionDate?: string;
1221
+ blockers: string[];
1222
+ createdAt: number;
1223
+ }
1224
+ declare function createVelocitySnapshot(period: string, commitments: CharterCommitment[]): VelocitySnapshot;
1225
+ declare function projectCompletion(snapshot: VelocitySnapshot, sprintsPerPeriod?: number): string | null;
1226
+ interface GitActivity {
1227
+ repo: string;
1228
+ branch: string;
1229
+ commits: Array<{
1230
+ hash: string;
1231
+ message: string;
1232
+ author: string;
1233
+ date: string;
1234
+ filesChanged: number;
1235
+ }>;
1236
+ pullRequests: Array<{
1237
+ number: number;
1238
+ title: string;
1239
+ status: 'open' | 'merged' | 'closed';
1240
+ author: string;
1241
+ }>;
1242
+ }
1243
+ interface StandupEntry {
1244
+ repo: string;
1245
+ yesterday: string[];
1246
+ today: string[];
1247
+ blockers: string[];
1248
+ }
1249
+ interface StandupSynthesis {
1250
+ id: string;
1251
+ date: string;
1252
+ entries: StandupEntry[];
1253
+ summary: string;
1254
+ crossRepoBlockers: string[];
1255
+ createdAt: number;
1256
+ }
1257
+ declare function synthesizeStandup(activities: GitActivity[], date: string): StandupSynthesis;
1258
+ declare const GTCX_REPOS: RepoNode[];
1259
+ declare const GTCX_EDGES: DependencyEdge[];
1260
+ declare function createGTCXGraph(): DependencyGraph;
1261
+
1262
+ /**
1263
+ * BaselineOS Security Manager
1264
+ *
1265
+ * Implements the security specification:
1266
+ * - Layer 1: ABAC permission model (grant, check, revoke)
1267
+ * - Layer 2: Risk gating (tool classification, escalation enforcement)
1268
+ * - Layer 3: Compliance gate integration
1269
+ * - Safety enforcement rules with trust-based access tiers
1270
+ * - Unified audit trail
1271
+ *
1272
+ * @license Apache-2.0
1273
+ */
1274
+
1275
+ interface Permission {
1276
+ id: string;
1277
+ subject: string;
1278
+ resource: string;
1279
+ action: string;
1280
+ granted: Date;
1281
+ revoked?: Date;
1282
+ status: 'active' | 'revoked';
1283
+ options: Record<string, unknown>;
1284
+ }
1285
+ type SecurityAuditEventType = 'permission_granted' | 'permission_revoked' | 'policy_evaluated' | 'policy_enforced' | 'approval_requested' | 'approval_reviewed' | 'compliance_checked';
1286
+ interface SecurityAuditEntry {
1287
+ id: string;
1288
+ type: SecurityAuditEventType;
1289
+ timestamp: Date;
1290
+ actor: string;
1291
+ subject?: string;
1292
+ resource?: string;
1293
+ action?: string;
1294
+ result: 'allowed' | 'denied' | 'pending';
1295
+ details: Record<string, unknown>;
1296
+ }
1297
+ type ToolRiskLevel = 'low' | 'medium' | 'high';
1298
+ interface ToolRiskClassification {
1299
+ level: ToolRiskLevel;
1300
+ requiresEscalation: boolean;
1301
+ reason: string;
1302
+ }
1303
+ interface SafetyRule {
1304
+ id: string;
1305
+ name: string;
1306
+ validate: (context: SafetyContext) => SafetyResult;
1307
+ }
1308
+ interface SafetyContext {
1309
+ description: string;
1310
+ requiredCapabilities: string[];
1311
+ agentCapabilities: string[];
1312
+ trustScore: number;
1313
+ systemImpact: 'low' | 'medium' | 'high';
1314
+ dataTypes?: string[];
1315
+ }
1316
+ interface SafetyResult {
1317
+ passed: boolean;
1318
+ rule: string;
1319
+ reason?: string;
1320
+ }
1321
+ type TrustTier = 'full_autonomy' | 'supervised' | 'requires_approval' | 'suspended';
1322
+ interface SecurityManagerConfig {
1323
+ trustMinimum?: number;
1324
+ defaultTrustTier?: TrustTier;
1325
+ auditPersistPath?: string;
1326
+ }
1327
+ declare function getTrustTier(trustScore: number): TrustTier;
1328
+ declare class SecurityManager extends EventEmitter$1 {
1329
+ private permissions;
1330
+ private auditTrail;
1331
+ private toolRisks;
1332
+ private config;
1333
+ constructor(config?: SecurityManagerConfig);
1334
+ grantPermission(subject: string, resource: string, action: string, actor: string, options?: Record<string, unknown>): Permission;
1335
+ checkPermission(subject: string, resource: string, action: string, actor: string): boolean;
1336
+ revokePermission(permissionId: string, actor: string): boolean;
1337
+ getPermission(id: string): Permission | undefined;
1338
+ getPermissionsForSubject(subject: string): Permission[];
1339
+ registerToolRisk(toolName: string, classification: ToolRiskClassification): void;
1340
+ getToolRisk(toolName: string): ToolRiskClassification | undefined;
1341
+ checkToolAccess(toolName: string, args: Record<string, unknown>, actor: string): {
1342
+ allowed: boolean;
1343
+ reason?: string;
1344
+ };
1345
+ getAllToolRisks(): Record<string, ToolRiskClassification>;
1346
+ evaluateSafety(context: SafetyContext): {
1347
+ passed: boolean;
1348
+ results: SafetyResult[];
1349
+ };
1350
+ getSafetyRules(): SafetyRule[];
1351
+ getTrustTier(trustScore: number): TrustTier;
1352
+ canExecute(trustScore: number): boolean;
1353
+ private recordAudit;
1354
+ getAuditTrail(filter?: {
1355
+ type?: SecurityAuditEventType;
1356
+ actor?: string;
1357
+ resource?: string;
1358
+ }): SecurityAuditEntry[];
1359
+ getAuditCount(): number;
1360
+ getStats(): Record<string, unknown>;
1361
+ }
1362
+
1363
+ /**
1364
+ * OutputValidator — SIGNAL-027
1365
+ *
1366
+ * Post-execution validation gate applied to every agent output before
1367
+ * it is committed as an artifact. Three checks run in order:
1368
+ *
1369
+ * 1. PII scan — detects residual PII that the LLM may have reproduced
1370
+ * from context; fails if any match is found.
1371
+ * 2. Refusal — detects model-refusal patterns that indicate the engine
1372
+ * returned a non-answer rather than a real result.
1373
+ * 3. Schema — optional JSON-schema-style structural conformance check
1374
+ * against caller-supplied `requiredFields`.
1375
+ *
1376
+ * On any failure the validator:
1377
+ * - Returns a structured `OutputValidationResult` with `valid: false`
1378
+ * - Publishes `governance:output-validation-failed` on the AgentBus
1379
+ * - Sets OTel span attributes for traceability
1380
+ *
1381
+ * Usage:
1382
+ * const validator = new OutputValidator({ bus, piiDetector });
1383
+ * const result = await validator.validate(output, { taskId, agentId });
1384
+ * if (!result.valid) { ... }
1385
+ *
1386
+ * @license Apache-2.0
1387
+ */
1388
+
1389
+ type OutputValidationFailureReason = 'pii-detected' | 'refusal-detected' | 'schema-violation' | 'empty-output';
1390
+ interface OutputValidationFailure {
1391
+ reason: OutputValidationFailureReason;
1392
+ detail: string;
1393
+ }
1394
+ interface OutputValidationResult {
1395
+ valid: boolean;
1396
+ failures: OutputValidationFailure[];
1397
+ /** Output text after PII redaction (only differs from input when PII found in non-blocking mode) */
1398
+ sanitized: string;
1399
+ }
1400
+ interface ValidateOptions {
1401
+ /** Task ID for bus event and span attributes */
1402
+ taskId?: string;
1403
+ /** Agent ID for bus event and span attributes */
1404
+ agentId?: string;
1405
+ /**
1406
+ * When provided, the output is parsed as JSON and each listed key must
1407
+ * be present and non-null in the top-level object.
1408
+ */
1409
+ requiredFields?: string[];
1410
+ }
1411
+ interface OutputValidatorConfig {
1412
+ /** PiiDetector instance. When omitted, PII scanning is skipped. */
1413
+ piiDetector?: PiiDetector;
1414
+ /** AgentBus for publishing governance:output-validation-failed events. */
1415
+ bus?: AgentBus;
1416
+ /**
1417
+ * Whether to fail on PII in output (default: true).
1418
+ * Set to false to redact silently without marking as invalid.
1419
+ */
1420
+ failOnPii?: boolean;
1421
+ }
1422
+ declare class OutputValidator {
1423
+ private readonly piiDetector?;
1424
+ private readonly bus?;
1425
+ private readonly failOnPii;
1426
+ constructor(config?: OutputValidatorConfig);
1427
+ validate(output: string, options?: ValidateOptions): Promise<OutputValidationResult>;
1428
+ }
1429
+
1430
+ /**
1431
+ * CredentialProvider — SIGNAL-028 + SIGNAL-041
1432
+ *
1433
+ * Dynamic, per-workflow credential scoping with TTL enforcement.
1434
+ * Prevents workflow runs from sharing credentials and enables runtime
1435
+ * injection / revocation without process restarts.
1436
+ *
1437
+ * TTL enforcement (SIGNAL-041):
1438
+ * - Every credential can carry an optional `expiresAt` timestamp.
1439
+ * - get() throws CredentialExpiredError for expired entries.
1440
+ * - rotate() replaces a credential and optionally resets its TTL.
1441
+ * - listExpiring(withinMs) surfaces credentials about to expire.
1442
+ * - Bus event 'governance:credential-expired' fires on expiry detection.
1443
+ *
1444
+ * Design:
1445
+ * - Global registry holds base credentials keyed by service name.
1446
+ * - Per-workflow overlay is registered at workflow start and revoked at end.
1447
+ * - get() resolves: workflow scope → global registry → process.env fallback.
1448
+ * - Every access (including misses) is published as a governance bus event
1449
+ * so the audit trail captures which credentials each workflow touched.
1450
+ *
1451
+ * @license Apache-2.0
1452
+ */
1453
+
1454
+ interface CredentialProviderConfig {
1455
+ /** AgentBus for publishing governance:credential-accessed events. */
1456
+ bus?: AgentBus;
1457
+ /**
1458
+ * When true, get() falls back to process.env[`${SERVICE}_API_KEY`] when no
1459
+ * registered value is found. Default: true.
1460
+ */
1461
+ envFallback?: boolean;
1462
+ }
1463
+ interface CredentialEntry {
1464
+ value: string;
1465
+ /** Unix ms timestamp when this credential expires. Undefined = no expiry. */
1466
+ expiresAt?: number;
1467
+ }
1468
+ interface CredentialAccessEvent {
1469
+ service: string;
1470
+ workflowId: string | undefined;
1471
+ /** 'workflow-scope' | 'global' | 'env' | 'miss' */
1472
+ source: 'workflow-scope' | 'global' | 'env' | 'miss';
1473
+ }
1474
+ interface ExpiringCredential {
1475
+ service: string;
1476
+ workflowId?: string;
1477
+ expiresAt: number;
1478
+ msRemaining: number;
1479
+ }
1480
+ declare class CredentialExpiredError extends Error {
1481
+ readonly service: string;
1482
+ readonly expiresAt: number;
1483
+ constructor(service: string, expiresAt: number);
1484
+ }
1485
+ declare class CredentialProvider {
1486
+ private readonly global;
1487
+ private readonly workflows;
1488
+ private readonly bus?;
1489
+ private readonly envFallback;
1490
+ constructor(config?: CredentialProviderConfig);
1491
+ /**
1492
+ * Register a global credential for a service.
1493
+ * @param service Service name (e.g. 'anthropic')
1494
+ * @param value Credential value (API key, token, etc.)
1495
+ * @param ttlMs Optional TTL in milliseconds from now.
1496
+ */
1497
+ register(service: string, value: string | undefined, ttlMs?: number): void;
1498
+ /**
1499
+ * Register a map of per-workflow credentials.
1500
+ * @param workflowId Workflow run identifier
1501
+ * @param credentials Map of service → value (or service → CredentialEntry)
1502
+ * @param ttlMs Default TTL applied to all values without explicit expiresAt
1503
+ */
1504
+ registerWorkflow(workflowId: string, credentials: Record<string, string | CredentialEntry>, ttlMs?: number): void;
1505
+ /**
1506
+ * Revoke all credentials registered for a workflow.
1507
+ */
1508
+ revokeWorkflow(workflowId: string): void;
1509
+ /**
1510
+ * Rotate a credential (global or workflow-scoped).
1511
+ * Replaces the existing value and optionally resets the TTL.
1512
+ *
1513
+ * @param service Service name
1514
+ * @param newValue New credential value
1515
+ * @param ttlMs New TTL in ms from now. Omit to clear expiry.
1516
+ * @param workflowId If provided, rotates the workflow-scoped credential.
1517
+ */
1518
+ rotate(service: string, newValue: string, ttlMs?: number, workflowId?: string): void;
1519
+ /**
1520
+ * Returns credentials (global + all workflow scopes) that will expire
1521
+ * within the given window.
1522
+ *
1523
+ * @param withinMs Look-ahead window in milliseconds (e.g. 60_000 for 1 min)
1524
+ */
1525
+ listExpiring(withinMs: number): ExpiringCredential[];
1526
+ /**
1527
+ * Retrieve a credential for a service, scoped to an optional workflow.
1528
+ * Resolution order: workflow scope → global registry → process.env → undefined.
1529
+ *
1530
+ * @throws CredentialExpiredError if the resolved credential has passed its expiresAt.
1531
+ */
1532
+ get(service: string, workflowId?: string): string | undefined;
1533
+ /** Returns the set of services with registered global credentials. */
1534
+ registeredServices(): string[];
1535
+ /** Returns the set of active workflow IDs with scoped credentials. */
1536
+ activeWorkflows(): string[];
1537
+ }
1538
+
1539
+ /**
1540
+ * RollbackManager — SIGNAL-029
1541
+ *
1542
+ * Formal rollback definition and execution for autonomous workflows.
1543
+ * Provides a structured rollback contract on top of the existing Checkpoint
1544
+ * infrastructure so that rollbacks are traceable, auditable, and testable.
1545
+ *
1546
+ * Responsibilities:
1547
+ * - Select the best eligible rollback checkpoint from a candidate list
1548
+ * - Restore a task to its prior state (status, context, artifacts)
1549
+ * - Publish governance:rollback-triggered on the AgentBus
1550
+ * - Return a typed RollbackResult for callers to act on
1551
+ *
1552
+ * Eligibility rules for a checkpoint:
1553
+ * - recoverable: true
1554
+ * - Not expired (expiresAt > Date.now() OR no expiresAt)
1555
+ *
1556
+ * Usage:
1557
+ * const rm = new RollbackManager({ bus });
1558
+ * const result = rm.rollback(task, checkpoints, 'execution-failed');
1559
+ * if (result.success) { ... }
1560
+ *
1561
+ * @license Apache-2.0
1562
+ */
1563
+
1564
+ interface RollbackManagerConfig {
1565
+ bus?: AgentBus;
1566
+ }
1567
+ interface RollbackResult {
1568
+ success: boolean;
1569
+ /** The checkpoint that was used for rollback, or null if none eligible. */
1570
+ checkpoint: Checkpoint | null;
1571
+ /** Human-readable description of what happened. */
1572
+ message: string;
1573
+ }
1574
+ declare class RollbackManager {
1575
+ private readonly bus?;
1576
+ constructor(config?: RollbackManagerConfig);
1577
+ /**
1578
+ * Returns true if at least one eligible checkpoint exists for the task.
1579
+ */
1580
+ canRollback(taskId: string, checkpoints: Checkpoint[]): boolean;
1581
+ /**
1582
+ * Select the most recent eligible checkpoint for the given task.
1583
+ * Eligible = recoverable AND not expired AND matches taskId.
1584
+ */
1585
+ selectBestCheckpoint(taskId: string, checkpoints: Checkpoint[]): Checkpoint | null;
1586
+ /**
1587
+ * Rollback a task to its most recent eligible checkpoint.
1588
+ *
1589
+ * Mutates the task in-place: resets status to 'pending', restores context
1590
+ * and artifacts from the checkpoint, sets currentCheckpoint.
1591
+ *
1592
+ * Publishes governance:rollback-triggered on the bus.
1593
+ */
1594
+ rollback(task: Task, checkpoints: Checkpoint[], reason: string): RollbackResult;
1595
+ }
1596
+
1597
+ /**
1598
+ * Prompt Loader — SIGNAL-035
1599
+ *
1600
+ * Loads versioned agent system prompts from
1601
+ * `packages/baselineos/prompts/{role}/system.md` (and
1602
+ * `prompts/personas/{name}.md` for executor personas).
1603
+ *
1604
+ * Each prompt file carries YAML front matter:
1605
+ * version, agent, updated, changelog[]
1606
+ *
1607
+ * Falls back to the provided inline string when the file is absent,
1608
+ * enabling safe staged migration without breaking existing deployments.
1609
+ *
1610
+ * @license Apache-2.0
1611
+ */
1612
+ interface PromptMeta {
1613
+ version: string;
1614
+ agent: string;
1615
+ persona?: string;
1616
+ updated: string;
1617
+ changelog: string[];
1618
+ }
1619
+ interface LoadedPrompt {
1620
+ meta: PromptMeta;
1621
+ text: string;
1622
+ /** Absolute path the prompt was loaded from */
1623
+ source: string;
1624
+ }
1625
+ /**
1626
+ * Load a role-level system prompt (verifier, supervisor, quality, planner).
1627
+ *
1628
+ * Returns `null` when the file is absent — callers should fall back to their
1629
+ * embedded inline strings.
1630
+ */
1631
+ declare function loadRolePrompt(role: string): LoadedPrompt | null;
1632
+ /**
1633
+ * Load a named executor persona prompt from `prompts/personas/{name}.md`.
1634
+ *
1635
+ * Returns `null` when the file is absent.
1636
+ */
1637
+ declare function loadPersonaPrompt(name: string): LoadedPrompt | null;
1638
+ /**
1639
+ * Load all persona prompts from `prompts/personas/`.
1640
+ * Returns a map of `{ name → LoadedPrompt }` for every `.md` file found.
1641
+ */
1642
+ declare function loadAllPersonas(): Map<string, LoadedPrompt>;
1643
+
1644
+ /**
1645
+ * Approval Token Manager — SIGNAL-036
1646
+ *
1647
+ * Manages single-use, time-limited approval tokens for irreversible actions.
1648
+ * Tokens gate task execution when human sign-off is required — either because
1649
+ * the task was explicitly flagged (context.requiresApproval) or because its
1650
+ * complexity exceeds the autonomous ceiling (epic tasks).
1651
+ *
1652
+ * Design:
1653
+ * - Tokens are random UUIDs (cryptographically unpredictable, 122 bits entropy)
1654
+ * - Single-use: validation consumes the token; replaying returns invalid
1655
+ * - Time-limited: default TTL is 24 hours; configurable via ttlMs
1656
+ * - Bus events: governance:approval-issued and governance:approval-consumed
1657
+ * are published when configured with an AgentBus
1658
+ *
1659
+ * Usage:
1660
+ * const mgr = new ApprovalTokenManager({ bus });
1661
+ * const token = mgr.generate(task.id, 'Epic task requires human sign-off');
1662
+ * // ... human receives token.id out-of-band ...
1663
+ * const result = mgr.validate(task.id, token.id); // { valid: true }
1664
+ * // second call on same task returns { valid: false, reason: 'Token already consumed' }
1665
+ *
1666
+ * @license Apache-2.0
1667
+ */
1668
+
1669
+ interface ApprovalToken {
1670
+ /** The token value — a random UUID, passed as the approval credential */
1671
+ id: string;
1672
+ /** Task this token authorises */
1673
+ taskId: string;
1674
+ /** Human-readable reason the approval was required */
1675
+ reason: string;
1676
+ /** Identity that issued the token (default: 'system') */
1677
+ issuedBy: string;
1678
+ /** Unix ms timestamp when the token was generated */
1679
+ createdAt: number;
1680
+ /** Unix ms timestamp when the token expires */
1681
+ expiresAt: number;
1682
+ /** true once the token has been used via validate() */
1683
+ consumed: boolean;
1684
+ /** Unix ms timestamp when the token was consumed; undefined until used */
1685
+ consumedAt?: number;
1686
+ }
1687
+ interface ValidationResult {
1688
+ valid: boolean;
1689
+ /** Human-readable reason when valid=false */
1690
+ reason?: string;
1691
+ }
1692
+ interface ApprovalTokenConfig {
1693
+ /**
1694
+ * Token time-to-live in milliseconds.
1695
+ * Default: 86_400_000 (24 hours)
1696
+ */
1697
+ ttlMs?: number;
1698
+ /** AgentBus for publishing governance events. */
1699
+ bus?: AgentBus;
1700
+ }
1701
+ declare class ApprovalTokenManager {
1702
+ private readonly ttlMs;
1703
+ private readonly bus?;
1704
+ /** Map from taskId → token */
1705
+ private readonly tokens;
1706
+ constructor(config?: ApprovalTokenConfig);
1707
+ /**
1708
+ * Issue a new approval token for a task.
1709
+ *
1710
+ * Replaces any existing (unconsumed) token for the same task.
1711
+ * The token.id must be passed to validate() to authorise execution.
1712
+ */
1713
+ generate(taskId: string, reason: string, issuedBy?: string): ApprovalToken;
1714
+ /**
1715
+ * Validate and consume a token.
1716
+ *
1717
+ * Returns `{ valid: true }` the first time the correct token is presented
1718
+ * for an unexpired task. Subsequent calls — or calls with a wrong token —
1719
+ * return `{ valid: false, reason: '...' }`.
1720
+ */
1721
+ validate(taskId: string, tokenId: string): ValidationResult;
1722
+ /**
1723
+ * Revoke any pending (unconsumed) token for a task.
1724
+ * Returns true if a token was found and revoked, false if none existed.
1725
+ */
1726
+ revoke(taskId: string): boolean;
1727
+ /**
1728
+ * Returns all unexpired, unconsumed tokens.
1729
+ * Useful for operator dashboards and runbook queries.
1730
+ */
1731
+ listPending(): ApprovalToken[];
1732
+ /**
1733
+ * Returns true when a task requires human approval before it may execute.
1734
+ *
1735
+ * A task requires approval when:
1736
+ * - task.context.requiresApproval === true (explicit operator flag)
1737
+ * - task.complexity === 'epic' (beyond autonomous ceiling)
1738
+ */
1739
+ isRequired(task: Task): boolean;
1740
+ }
1741
+
1742
+ interface BaselineTaskWorkflowInput {
1743
+ task: Task;
1744
+ step?: ExecutionStep;
1745
+ /** Whether to run supervisor review after self-verify (default: false) */
1746
+ runSupervisorReview?: boolean;
1747
+ /** Whether to decompose the task before executing (default: false) */
1748
+ runDecomposition?: boolean;
1749
+ /** Whether to pause for human approval before execution (default: false) */
1750
+ requireHumanApproval?: boolean;
1751
+ }
1752
+ interface WorkflowResult {
1753
+ taskId: string;
1754
+ output: string;
1755
+ tokensUsed: number;
1756
+ duration: number;
1757
+ model: string;
1758
+ verification: VerificationResult;
1759
+ review?: Review;
1760
+ decomposition?: DecompositionResult;
1761
+ phase: WorkflowPhase;
1762
+ }
1763
+ type WorkflowPhase = 'initialising' | 'awaiting-approval' | 'decomposing' | 'executing' | 'verifying' | 'reviewing' | 'completed' | 'failed';
1764
+ declare function baselineTaskWorkflow(input: BaselineTaskWorkflowInput): Promise<WorkflowResult>;
1765
+
1766
+ /**
1767
+ * TemporalOrchestrator — SIGNAL-045
1768
+ *
1769
+ * Submits BaselineOS tasks as durable Temporal workflows instead of
1770
+ * executing them inline. Acts as a drop-in replacement for direct
1771
+ * AnthropicEngine usage when durable execution is required.
1772
+ *
1773
+ * Each submitted workflow:
1774
+ * - Gets a deterministic workflow ID: `baseline-task-{taskId}`
1775
+ * - Runs on the `baseline-task-queue`
1776
+ * - Can be queried for status via getStatus()
1777
+ * - Can be signalled for human approval via humanApproval()
1778
+ *
1779
+ * Usage:
1780
+ * const orchestrator = new TemporalOrchestrator({ client, bus });
1781
+ * const result = await orchestrator.submit(task, { runSupervisorReview: true });
1782
+ *
1783
+ * @license Apache-2.0
1784
+ */
1785
+
1786
+ interface TemporalOrchestratorConfig {
1787
+ client: Client;
1788
+ bus?: AgentBus;
1789
+ }
1790
+ interface SubmitOptions {
1791
+ step?: ExecutionStep;
1792
+ runSupervisorReview?: boolean;
1793
+ runDecomposition?: boolean;
1794
+ requireHumanApproval?: boolean;
1795
+ }
1796
+ declare class TemporalOrchestrator {
1797
+ private readonly client;
1798
+ private readonly bus?;
1799
+ constructor(config: TemporalOrchestratorConfig);
1800
+ /**
1801
+ * Submit a task as a durable workflow.
1802
+ * Returns after the workflow completes (or throws on failure).
1803
+ */
1804
+ submit(task: Task, options?: SubmitOptions): Promise<WorkflowResult>;
1805
+ /**
1806
+ * Query the current phase of a running workflow.
1807
+ * Returns undefined if the workflow does not exist.
1808
+ */
1809
+ getStatus(taskId: string): Promise<WorkflowPhase | undefined>;
1810
+ /**
1811
+ * Send a human approval signal to a paused workflow.
1812
+ */
1813
+ sendApproval(taskId: string, approved: boolean, reason?: string): Promise<void>;
1814
+ /**
1815
+ * Terminate a running workflow immediately.
1816
+ */
1817
+ terminate(taskId: string, reason?: string): Promise<void>;
1818
+ /**
1819
+ * Retrieve a typed handle for a task's workflow.
1820
+ */
1821
+ getHandle(taskId: string): WorkflowHandle<typeof baselineTaskWorkflow>;
1822
+ }
1823
+
1824
+ /**
1825
+ * Temporal Activities — SIGNAL-045
1826
+ *
1827
+ * Activity functions executed by the Temporal worker. Each activity wraps a
1828
+ * single operation on the execution engine and is retried independently by
1829
+ * Temporal on failure. Activities are the boundary between Temporal's durable
1830
+ * orchestration and the existing BaselineOS execution infrastructure.
1831
+ *
1832
+ * Retry policy (applied by workflow — see workflows.ts):
1833
+ * - maximumAttempts: 3
1834
+ * - initialInterval: 1s, backoffCoefficient: 2, maximumInterval: 30s
1835
+ * - Non-retryable: ApplicationFailure with nonRetryable=true
1836
+ *
1837
+ * All activities receive their dependencies via context injection through
1838
+ * createActivities(). This keeps activities pure functions for testing.
1839
+ *
1840
+ * @license Apache-2.0
1841
+ */
1842
+
1843
+ interface ActivityDependencies {
1844
+ engine: ExecutionEngine;
1845
+ }
1846
+ interface ExecuteTaskInput {
1847
+ task: Task;
1848
+ step?: ExecutionStep;
1849
+ }
1850
+ interface SelfVerifyInput {
1851
+ task: Task;
1852
+ output: string;
1853
+ }
1854
+ interface ConductReviewInput {
1855
+ task: Task;
1856
+ output: string;
1857
+ reviewType: 'supervisor' | 'quality';
1858
+ }
1859
+ interface DecomposeInput {
1860
+ task: Task;
1861
+ }
1862
+ /**
1863
+ * Create activity functions bound to the given execution engine.
1864
+ * Register the returned object with the Temporal worker:
1865
+ * worker.run({ activities: createActivities({ engine }) })
1866
+ */
1867
+ declare function createActivities(deps: ActivityDependencies): {
1868
+ /**
1869
+ * Execute a task (or a specific step) using the underlying engine.
1870
+ * Returns ExecutionResult on success; throws ApplicationFailure on compliance violations.
1871
+ */
1872
+ executeTask(input: ExecuteTaskInput): Promise<ExecutionResult>;
1873
+ /**
1874
+ * Agent self-verifies its output against the task's acceptance criteria.
1875
+ */
1876
+ selfVerifyTask(input: SelfVerifyInput): Promise<VerificationResult>;
1877
+ /**
1878
+ * Supervisor or quality review of task output.
1879
+ */
1880
+ conductTaskReview(input: ConductReviewInput): Promise<Review>;
1881
+ /**
1882
+ * Decompose a complex task into structured subtasks.
1883
+ */
1884
+ decomposeTask(input: DecomposeInput): Promise<DecompositionResult>;
1885
+ };
1886
+ type BaselineActivities = ReturnType<typeof createActivities>;
1887
+
1888
+ /**
1889
+ * Temporal Client Factory — SIGNAL-045
1890
+ *
1891
+ * Creates a Temporal client configured from environment variables.
1892
+ * The client is used by TemporalOrchestrator to submit workflows.
1893
+ *
1894
+ * Environment variables:
1895
+ * TEMPORAL_ADDRESS — Temporal frontend address (default: localhost:7233)
1896
+ * TEMPORAL_NAMESPACE — Temporal namespace (default: baseline)
1897
+ * TEMPORAL_TLS — 'true' to enable TLS (default: false)
1898
+ *
1899
+ * @license Apache-2.0
1900
+ */
1901
+
1902
+ interface TemporalClientConfig {
1903
+ address?: string;
1904
+ namespace?: string;
1905
+ tls?: boolean;
1906
+ }
1907
+ declare const BASELINE_TASK_QUEUE = "baseline-task-queue";
1908
+ /**
1909
+ * Create and connect a Temporal client.
1910
+ * Call client.connection.close() when done.
1911
+ */
1912
+ declare function createTemporalClient(config?: TemporalClientConfig): Promise<Client>;
1913
+
1914
+ type CycleTrigger = 'eval-drift' | 'dataset-growth' | 'quality-drift' | 'manual' | 'scheduled';
1915
+ type CycleOutcome = 'promoted' | 'held' | 'rolled-back' | 'in-progress' | 'aborted';
1916
+ interface ImprovementCycle {
1917
+ /** Cycle identifier: IC-001, IC-002, etc. */
1918
+ id: string;
1919
+ /** ISO timestamp when cycle was started */
1920
+ startedAt: string;
1921
+ /** ISO timestamp when cycle was completed (undefined if in-progress) */
1922
+ completedAt?: string;
1923
+ /** What initiated the cycle */
1924
+ trigger: CycleTrigger;
1925
+ /** Number of cases in dataset when cycle started */
1926
+ datasetSizeAtStart: number;
1927
+ /** Production eval score for current production model (0–100) */
1928
+ evalScoreBefore?: number;
1929
+ /** Production eval score for candidate model (0–100) */
1930
+ evalScoreAfter?: number;
1931
+ /** evalScoreAfter - evalScoreBefore (positive = improvement) */
1932
+ deltaScore?: number;
1933
+ /** Model ID that was evaluated as a candidate */
1934
+ candidateModelId?: string;
1935
+ /** Model ID promoted to production (undefined if not promoted) */
1936
+ promotedModelId?: string;
1937
+ /** Whether the red-team safety check passed for the candidate */
1938
+ redTeamPassed?: boolean;
1939
+ /** Total LLM cost incurred during this cycle in USD */
1940
+ costUsd?: number;
1941
+ /** Final cycle outcome */
1942
+ outcome: CycleOutcome;
1943
+ /** Human-readable notes or reason for outcome */
1944
+ notes: string;
1945
+ }
1946
+ interface ImprovementCycleLogConfig {
1947
+ /** Path to the JSON log file. Default: packages/baselineos/src/data/improvement-cycles.json */
1948
+ logPath?: string;
1949
+ /** AgentBus for publishing governance events */
1950
+ bus?: AgentBus;
1951
+ }
1952
+ declare class ImprovementCycleLog {
1953
+ private readonly logPath;
1954
+ private readonly bus?;
1955
+ constructor(config?: ImprovementCycleLogConfig);
1956
+ /**
1957
+ * Start a new cycle. Assigns the next IC-NNN ID, writes in-progress entry.
1958
+ */
1959
+ startCycle(trigger: CycleTrigger, datasetSize: number, notes?: string): ImprovementCycle;
1960
+ /**
1961
+ * Update an in-progress cycle with partial data.
1962
+ * Merges updates into the existing cycle record.
1963
+ */
1964
+ updateCycle(cycleId: string, updates: Partial<Omit<ImprovementCycle, 'id' | 'startedAt'>>): void;
1965
+ /**
1966
+ * Complete a cycle with a final outcome. Sets completedAt timestamp.
1967
+ */
1968
+ completeCycle(cycleId: string, outcome: Exclude<CycleOutcome, 'in-progress'>, updates?: Partial<ImprovementCycle>): ImprovementCycle;
1969
+ /** Return all recorded cycles */
1970
+ getAll(): ImprovementCycle[];
1971
+ /** Return the most recent cycle, or undefined if none exist */
1972
+ getLatest(): ImprovementCycle | undefined;
1973
+ /** Return a specific cycle by ID */
1974
+ getCycle(cycleId: string): ImprovementCycle | undefined;
1975
+ /**
1976
+ * Returns number of days since the last completed cycle.
1977
+ * Returns Infinity if no completed cycle exists.
1978
+ */
1979
+ getDaysSinceLastCycle(): number;
1980
+ /**
1981
+ * Return cycles that resulted in a promotion.
1982
+ */
1983
+ getPromotionHistory(): ImprovementCycle[];
1984
+ /**
1985
+ * Snapshot the LLM cost for a cycle from a CostGuard instance.
1986
+ * Reads guard.snapshot(cycleId).totalCostUsd and persists it on the cycle.
1987
+ * The cycle ID is used as the CostGuard workflow ID by convention.
1988
+ *
1989
+ * Call this at any point during the cycle (e.g. before completeCycle()).
1990
+ * Idempotent — safe to call multiple times; accumulates the guard value.
1991
+ */
1992
+ snapshotCycleCost(cycleId: string, guard: CostGuard): void;
1993
+ /**
1994
+ * Record a specific USD cost against an in-progress cycle.
1995
+ * Use this when cost data comes from a source other than CostGuard.
1996
+ */
1997
+ recordCycleCost(cycleId: string, costUsd: number): void;
1998
+ /**
1999
+ * Return cost summary across all completed cycles.
2000
+ */
2001
+ getCostSummary(): {
2002
+ totalCycles: number;
2003
+ totalCostUsd: number;
2004
+ avgCostPerCycle: number;
2005
+ };
2006
+ private _write;
2007
+ }
2008
+
2009
+ /**
2010
+ * ShadowRouter — SIGNAL-057
2011
+ *
2012
+ * Routes every request to the primary ExecutionEngine while simultaneously
2013
+ * dispatching a shadow copy to a candidate engine. Shadow results are never
2014
+ * returned to the caller — they are used purely for comparison and promotion
2015
+ * decisions.
2016
+ *
2017
+ * Architecture:
2018
+ * 1. Execute primary engine (blocking — caller receives this result)
2019
+ * 2. Execute candidate engine (non-blocking by default, or awaited in
2020
+ * 'compare' mode for synchronous diff recording)
2021
+ * 3. Score both outputs using a lightweight similarity metric
2022
+ * 4. Publish governance:shadow-comparison on AgentBus
2023
+ * 5. Accumulate ShadowComparison records for offline analysis
2024
+ *
2025
+ * Modes:
2026
+ * fire-and-forget — candidate runs after primary returns (default)
2027
+ * compare — candidate awaited; comparison written before return
2028
+ *
2029
+ * Usage:
2030
+ * const router = new ShadowRouter({
2031
+ * primary: primaryEngine,
2032
+ * candidate: candidateEngine,
2033
+ * bus,
2034
+ * sampleRate: 0.2, // shadow 20% of traffic
2035
+ * });
2036
+ * const result = await router.execute(task); // always returns primary result
2037
+ *
2038
+ * @license Apache-2.0
2039
+ */
2040
+
2041
+ type ShadowMode = 'fire-and-forget' | 'compare';
2042
+ interface ShadowComparison {
2043
+ taskId: string;
2044
+ timestamp: string;
2045
+ primaryModel: string;
2046
+ candidateModel: string;
2047
+ /** Rough token overlap ratio (0–1) between primary and candidate outputs */
2048
+ similarityScore: number;
2049
+ /** True when candidate produced output without error */
2050
+ candidateSucceeded: boolean;
2051
+ /** True when candidate output is meaningfully different from primary */
2052
+ diverged: boolean;
2053
+ primaryTokens: number;
2054
+ candidateTokens: number;
2055
+ durationPrimaryMs: number;
2056
+ durationCandidateMs: number;
2057
+ error?: string;
2058
+ }
2059
+ interface ShadowRouterConfig {
2060
+ primary: ExecutionEngine;
2061
+ candidate: ExecutionEngine;
2062
+ bus?: AgentBus;
2063
+ /** Fraction of calls to shadow (0–1). Default: 1.0 (all calls) */
2064
+ sampleRate?: number;
2065
+ /** Execution mode. Default: fire-and-forget */
2066
+ mode?: ShadowMode;
2067
+ /** Similarity below this threshold is flagged as diverged. Default: 0.6 */
2068
+ divergenceThreshold?: number;
2069
+ /** Max comparisons to keep in memory. Default: 500 */
2070
+ maxHistory?: number;
2071
+ }
2072
+ declare class ShadowRouter implements ExecutionEngine {
2073
+ private readonly primary;
2074
+ private readonly candidate;
2075
+ private readonly bus?;
2076
+ private readonly sampleRate;
2077
+ private readonly mode;
2078
+ private readonly divergenceThreshold;
2079
+ private readonly maxHistory;
2080
+ private readonly history;
2081
+ constructor(config: ShadowRouterConfig);
2082
+ execute(task: Task, step?: ExecutionStep): Promise<ExecutionResult>;
2083
+ selfVerify(task: Task, output: string): Promise<VerificationResult>;
2084
+ conductReview(task: Task, output: string, reviewType: 'supervisor' | 'quality'): Promise<Review>;
2085
+ decompose(task: Task): ReturnType<ExecutionEngine['decompose']>;
2086
+ /** All recorded shadow comparisons (newest last). */
2087
+ getHistory(): ShadowComparison[];
2088
+ /** Comparisons where candidate diverged from primary. */
2089
+ getDivergences(): ShadowComparison[];
2090
+ /**
2091
+ * Aggregate stats across all comparisons.
2092
+ * Useful for promotion decisions.
2093
+ */
2094
+ getStats(): {
2095
+ total: number;
2096
+ candidateSuccessRate: number;
2097
+ avgSimilarity: number;
2098
+ divergenceRate: number;
2099
+ avgCandidateTokenDelta: number;
2100
+ };
2101
+ private shouldSample;
2102
+ private buildComparison;
2103
+ /**
2104
+ * Lightweight token-overlap similarity (Jaccard on word tokens).
2105
+ * Good enough for divergence detection without a full diff.
2106
+ */
2107
+ private tokenOverlapSimilarity;
2108
+ private appendComparison;
2109
+ private emitEvent;
2110
+ }
2111
+
2112
+ /**
2113
+ * RedTeamRunner — SIGNAL-058
2114
+ *
2115
+ * Automated adversarial testing scaffold for promotion gates.
2116
+ * Runs a set of probes against an ExecutionEngine and produces a
2117
+ * structured RedTeamReport suitable for logging and CI gating.
2118
+ *
2119
+ * Probe categories:
2120
+ * jailbreak — attempts to override system prompt / safety rules
2121
+ * prompt-injection — embedded instructions in user content
2122
+ * pii-exfiltration — attempts to extract or echo PII
2123
+ * refusal-check — verifies the engine refuses harmful requests
2124
+ * output-stability — verifies consistent output format under rephrasing
2125
+ *
2126
+ * Architecture:
2127
+ * 1. Define probes as { input, category, shouldRefuse, expectOutputContains? }
2128
+ * 2. Run each probe against the engine under test
2129
+ * 3. Apply lightweight pass criteria (refusal heuristics, PII detector)
2130
+ * 4. Return RedTeamReport with per-probe results and a summary pass/fail
2131
+ * 5. Publish governance:red-team-completed on AgentBus
2132
+ *
2133
+ * Integration with promotion gate:
2134
+ * if (!report.passed) → hold candidate model, do not promote
2135
+ *
2136
+ * @license Apache-2.0
2137
+ */
2138
+
2139
+ type ProbeCategory = 'jailbreak' | 'prompt-injection' | 'pii-exfiltration' | 'refusal-check' | 'output-stability';
2140
+ interface RedTeamProbe {
2141
+ id: string;
2142
+ category: ProbeCategory;
2143
+ description: string;
2144
+ /** The adversarial input to send to the engine */
2145
+ input: string;
2146
+ /** If true, the engine is expected to refuse or produce a safe non-compliance output */
2147
+ shouldRefuse: boolean;
2148
+ /** If set, the output must contain this substring (case-insensitive) to pass */
2149
+ expectOutputContains?: string;
2150
+ /** If set, the output must NOT contain this substring (case-insensitive) to pass */
2151
+ expectOutputExcludes?: string;
2152
+ }
2153
+ interface ProbeResult {
2154
+ probeId: string;
2155
+ category: ProbeCategory;
2156
+ passed: boolean;
2157
+ reason: string;
2158
+ output: string;
2159
+ durationMs: number;
2160
+ error?: string;
2161
+ }
2162
+ interface RedTeamReport {
2163
+ runId: string;
2164
+ modelId: string;
2165
+ timestamp: string;
2166
+ totalProbes: number;
2167
+ passedProbes: number;
2168
+ failedProbes: number;
2169
+ passed: boolean;
2170
+ /** Fraction of probes passed (0–1) */
2171
+ passRate: number;
2172
+ results: ProbeResult[];
2173
+ durationMs: number;
2174
+ }
2175
+ interface RedTeamRunnerConfig {
2176
+ engine: ExecutionEngine;
2177
+ bus?: AgentBus;
2178
+ /** Custom probe set. Defaults to the built-in probe suite. */
2179
+ probes?: RedTeamProbe[];
2180
+ /** Minimum pass rate to mark report.passed = true. Default: 1.0 (all must pass) */
2181
+ passingThreshold?: number;
2182
+ /** Model ID to tag the report with (for history correlation). Default: 'unknown' */
2183
+ modelId?: string;
2184
+ }
2185
+ declare const DEFAULT_PROBES: RedTeamProbe[];
2186
+ declare class RedTeamRunner {
2187
+ private readonly engine;
2188
+ private readonly bus?;
2189
+ private readonly probes;
2190
+ private readonly passingThreshold;
2191
+ private readonly modelId;
2192
+ private readonly piiDetector;
2193
+ constructor(config: RedTeamRunnerConfig);
2194
+ /**
2195
+ * Run all configured probes against the engine and return a report.
2196
+ * Never throws — all errors are captured per-probe.
2197
+ */
2198
+ run(): Promise<RedTeamReport>;
2199
+ private runProbe;
2200
+ private evaluateProbe;
2201
+ private probeToTask;
2202
+ }
2203
+
2204
+ /**
2205
+ * PromotionGate — SIGNAL-062
2206
+ *
2207
+ * Automated gate that combines eval comparison, red-team results, and
2208
+ * ImprovementCycleLog to produce a deterministic promote/hold/rollback
2209
+ * decision for a candidate model.
2210
+ *
2211
+ * Decision logic (in order):
2212
+ * 1. Red-team must pass (report.passed === true) → else: hold with red-team-failure note
2213
+ * 2. Eval comparison recommend must be 'promote' → else: hold or rollback
2214
+ * 3. deltaScore must exceed promotionThreshold → else: hold
2215
+ * 4. If all criteria met → 'promote'
2216
+ *
2217
+ * The gate also:
2218
+ * - Completes the in-progress ImprovementCycle with the decision outcome
2219
+ * - Publishes governance:promotion-decision on AgentBus
2220
+ * - Returns a PromotionDecision record for audit
2221
+ *
2222
+ * Usage:
2223
+ * const gate = new PromotionGate({ cycleLog, bus, promotionThreshold: 3 });
2224
+ * const decision = await gate.evaluate({
2225
+ * cycleId, comparison, redTeamReport, candidateModelId
2226
+ * });
2227
+ * if (decision.outcome === 'promote') { registry.promote(candidateModelId); }
2228
+ *
2229
+ * @license Apache-2.0
2230
+ */
2231
+
2232
+ type PromotionOutcome = 'promote' | 'hold' | 'rollback';
2233
+ interface PromotionDecision {
2234
+ cycleId: string;
2235
+ candidateModelId: string;
2236
+ outcome: PromotionOutcome;
2237
+ reason: string;
2238
+ /** All criteria evaluated, in order */
2239
+ criteria: Array<{
2240
+ label: string;
2241
+ passed: boolean;
2242
+ detail: string;
2243
+ }>;
2244
+ timestamp: string;
2245
+ /** deltaScore from comparison (may be undefined if comparison not run) */
2246
+ deltaScore?: number;
2247
+ redTeamPassed: boolean;
2248
+ compareRecommend: VersionComparison['recommend'] | 'not-run';
2249
+ }
2250
+ interface EvaluateInput {
2251
+ cycleId: string;
2252
+ candidateModelId: string;
2253
+ /** Eval comparison between production (baseline) and candidate */
2254
+ comparison: VersionComparison;
2255
+ /** Red-team report for the candidate model */
2256
+ redTeamReport: RedTeamReport;
2257
+ /** Optional eval score before (production baseline) */
2258
+ evalScoreBefore?: number;
2259
+ /** Optional eval score after (candidate) */
2260
+ evalScoreAfter?: number;
2261
+ }
2262
+ interface PromotionGateConfig {
2263
+ cycleLog: ImprovementCycleLog;
2264
+ bus?: AgentBus;
2265
+ /**
2266
+ * Minimum deltaScore required for promotion. Default: 3.
2267
+ * Matches the default threshold in ProductionEvalPipeline.compareVersions().
2268
+ */
2269
+ promotionThreshold?: number;
2270
+ }
2271
+ declare class PromotionGate {
2272
+ private readonly cycleLog;
2273
+ private readonly bus?;
2274
+ private readonly promotionThreshold;
2275
+ constructor(config: PromotionGateConfig);
2276
+ /**
2277
+ * Evaluate a candidate model for promotion.
2278
+ * Completes the ImprovementCycle with the outcome.
2279
+ * Never throws — errors are captured in the decision reason.
2280
+ */
2281
+ evaluate(input: EvaluateInput): PromotionDecision;
2282
+ private toCycleOutcome;
2283
+ }
2284
+
2285
+ /**
2286
+ * L5Pipeline — SIGNAL-063
2287
+ *
2288
+ * Orchestrates a complete SIGNAL L5 improvement cycle in a single call:
2289
+ *
2290
+ * 1. Snapshot dataset size & start ImprovementCycle
2291
+ * 2. Export fine-tune dataset (JSONL)
2292
+ * 3. PII audit the export (fail-fast on violations)
2293
+ * 4. Run production eval for baseline model (VersionEvalResult)
2294
+ * 5. Run production eval for candidate model (VersionEvalResult)
2295
+ * 6. Compare baseline vs candidate (VersionComparison)
2296
+ * 7. Run red-team against candidate engine
2297
+ * 8. PromotionGate decision (promote / hold / rollback)
2298
+ * 9. Complete ImprovementCycle with outcome
2299
+ * 10. Emit governance:l5-cycle-completed on AgentBus
2300
+ *
2301
+ * Components wired:
2302
+ * TraceCurator → dataset export
2303
+ * PiiDetector → training data PII gate
2304
+ * ProductionEvalPipeline → baseline + candidate scoring
2305
+ * ShadowRouter → optional shadow traffic (caller provides)
2306
+ * RedTeamRunner → adversarial probe suite
2307
+ * PromotionGate → deterministic decision
2308
+ * ImprovementCycleLog → cycle record-keeping
2309
+ * CostGuard → cost snapshot per cycle
2310
+ * DriftDetector → optional pre-cycle drift check
2311
+ * AgentBus → governance event publishing
2312
+ *
2313
+ * Usage:
2314
+ * const pipeline = new L5Pipeline({ ... });
2315
+ * const result = await pipeline.runCycle({
2316
+ * candidateEngine,
2317
+ * trigger: 'eval-drift',
2318
+ * });
2319
+ * if (result.decision.outcome === 'promote') {
2320
+ * registry.setActive('anthropic', candidateModelId);
2321
+ * }
2322
+ *
2323
+ * @license Apache-2.0
2324
+ */
2325
+
2326
+ interface L5CycleInput {
2327
+ /** What triggered this cycle */
2328
+ trigger: CycleTrigger;
2329
+ /** Candidate model ID for eval attribution and promotion records */
2330
+ candidateModelId: string;
2331
+ /** Candidate execution engine for red-team evaluation */
2332
+ candidateEngine: ExecutionEngine;
2333
+ /** Optional notes to attach to the ImprovementCycle */
2334
+ notes?: string;
2335
+ }
2336
+ interface L5CycleResult {
2337
+ cycleId: string;
2338
+ baselineResult: VersionEvalResult;
2339
+ candidateResult: VersionEvalResult;
2340
+ comparison: VersionComparison;
2341
+ redTeamReport: RedTeamReport;
2342
+ decision: PromotionDecision;
2343
+ driftReport?: DriftReport;
2344
+ exportedExamples: number;
2345
+ piiViolations: number;
2346
+ durationMs: number;
2347
+ aborted: boolean;
2348
+ abortReason?: string;
2349
+ }
2350
+ interface L5PipelineConfig {
2351
+ curator: TraceCurator;
2352
+ evalPipeline: ProductionEvalPipeline;
2353
+ redTeamRunner: RedTeamRunner;
2354
+ cycleLog: ImprovementCycleLog;
2355
+ /** Baseline model ID for eval attribution */
2356
+ baselineModelId: string;
2357
+ bus?: AgentBus;
2358
+ costGuard?: CostGuard;
2359
+ driftDetector?: DriftDetector;
2360
+ /** Promotion gate threshold. Default: 3 */
2361
+ promotionThreshold?: number;
2362
+ /** Directory for temporary export files. Default: OS tmpdir */
2363
+ exportDir?: string;
2364
+ /** If true, abort cycle when PII is found in fine-tune export. Default: true */
2365
+ abortOnPii?: boolean;
2366
+ }
2367
+ declare class L5Pipeline {
2368
+ private readonly curator;
2369
+ private readonly evalPipeline;
2370
+ private readonly redTeamRunner;
2371
+ private readonly cycleLog;
2372
+ private readonly gate;
2373
+ private readonly baselineModelId;
2374
+ private readonly bus?;
2375
+ private readonly costGuard?;
2376
+ private readonly driftDetector?;
2377
+ private readonly exportDir;
2378
+ private readonly abortOnPii;
2379
+ private readonly piiDetector;
2380
+ constructor(config: L5PipelineConfig);
2381
+ /**
2382
+ * Execute a complete L5 improvement cycle.
2383
+ * Never throws — all errors are captured in the result.
2384
+ */
2385
+ runCycle(input: L5CycleInput): Promise<L5CycleResult>;
2386
+ private _auditExport;
2387
+ private _cleanupExport;
2388
+ private _abortedResult;
2389
+ }
2390
+
2391
+ declare class Baseline {
2392
+ private config;
2393
+ private orchestrator;
2394
+ private memory;
2395
+ private indexer;
2396
+ private cache;
2397
+ private rag;
2398
+ readonly bus: AgentBus;
2399
+ private initialized;
2400
+ constructor(config?: Partial<BaselineConfig>);
2401
+ /**
2402
+ * Initialize BaselineOS. Call this before using other methods.
2403
+ */
2404
+ init(): Promise<void>;
2405
+ /**
2406
+ * Shutdown gracefully.
2407
+ */
2408
+ shutdown(): Promise<void>;
2409
+ /**
2410
+ * Execute an autonomous task.
2411
+ *
2412
+ * @param input - Task definition
2413
+ * @returns Task handle with status and control methods
2414
+ */
2415
+ run(input: TaskInput): Promise<TaskHandle>;
2416
+ /**
2417
+ * Execute a workflow by id.
2418
+ */
2419
+ runWorkflow(workflowId: string, input?: Partial<TaskInput>): Promise<TaskHandle>;
2420
+ /**
2421
+ * Execute a task and wait for completion.
2422
+ */
2423
+ runSync(input: TaskInput): Promise<Task>;
2424
+ /**
2425
+ * Get a task by ID.
2426
+ */
2427
+ getTask(taskId: string): Task | undefined;
2428
+ /**
2429
+ * List all tasks.
2430
+ */
2431
+ listTasks(filter?: {
2432
+ status?: TaskStatus;
2433
+ }): Task[];
2434
+ cancelTask(taskId: string, reason?: string): boolean;
2435
+ approveTask(taskId: string, approvedBy?: string, approvalToken?: string): Promise<Task>;
2436
+ registerWorkflow(definition: WorkflowDefinition): void;
2437
+ listWorkflows(): WorkflowDefinition[];
2438
+ getWorkflow(id: string): WorkflowDefinition | undefined;
2439
+ /**
2440
+ * Index knowledge base.
2441
+ */
2442
+ index(options?: {
2443
+ full?: boolean;
2444
+ }): Promise<{
2445
+ indexed: number;
2446
+ errors: number;
2447
+ skipped: number;
2448
+ changed: string[];
2449
+ removed: string[];
2450
+ }>;
2451
+ /**
2452
+ * Search knowledge base.
2453
+ */
2454
+ search(query: string, options?: {
2455
+ limit?: number;
2456
+ types?: Array<'doc' | 'code' | 'config' | 'spec' | 'api'>;
2457
+ policy?: PolicyFilter;
2458
+ }): Promise<SearchResult[]>;
2459
+ /**
2460
+ * Get context for a subject.
2461
+ */
2462
+ getContext(subject: string, level?: ContextLevel, options?: {
2463
+ policy?: PolicyFilter;
2464
+ overlayOrder?: Overlay[];
2465
+ budget?: RetrievalBudget;
2466
+ }): Promise<Context | null>;
2467
+ /**
2468
+ * Get context delta for a subject (only changed/unknown docs).
2469
+ */
2470
+ getContextDelta(subject: string, level?: ContextLevel, options?: {
2471
+ policy?: PolicyFilter;
2472
+ overlayOrder?: Overlay[];
2473
+ known?: Array<{
2474
+ id: string;
2475
+ hash?: string;
2476
+ }>;
2477
+ budget?: RetrievalBudget;
2478
+ }): Promise<Context | null>;
2479
+ /**
2480
+ * Search using RAG hybrid retrieval (BM25 + vector).
2481
+ */
2482
+ ragSearch(query: string, options?: {
2483
+ collections?: CollectionName[];
2484
+ repo?: string;
2485
+ limit?: number;
2486
+ minScore?: number;
2487
+ }): Promise<RAGResult>;
2488
+ /**
2489
+ * Get RAG context for a query — combines chunk-level retrieval
2490
+ * with optional structured context from the knowledge indexer.
2491
+ */
2492
+ ragContext(query: string, options?: {
2493
+ collections?: CollectionName[];
2494
+ repo?: string;
2495
+ maxTokens?: number;
2496
+ }): Promise<{
2497
+ content: string;
2498
+ sources: string[];
2499
+ tokenEstimate: number;
2500
+ }>;
2501
+ /**
2502
+ * Re-ingest RAG knowledge paths.
2503
+ */
2504
+ ragIngest(paths?: string[]): Promise<IngestionResult>;
2505
+ /**
2506
+ * Store in memory.
2507
+ */
2508
+ remember(key: string, value: unknown, scopeOrOptions?: MemoryScope | StoreOptions): Promise<void>;
2509
+ /**
2510
+ * Retrieve from memory.
2511
+ */
2512
+ recall(key: string, scopeOrOptions?: MemoryScope | RetrieveOptions): Promise<unknown>;
2513
+ /**
2514
+ * Register a custom agent.
2515
+ */
2516
+ registerAgent(agent: AgentConfig): void;
2517
+ /**
2518
+ * List all agents.
2519
+ */
2520
+ listAgents(): Agent[];
2521
+ /**
2522
+ * Start MCP server for Claude integration.
2523
+ */
2524
+ startMCPServer(): Promise<MCPServer>;
2525
+ /**
2526
+ * Start HTTP/WebSocket API server.
2527
+ */
2528
+ startAPIServer(port?: number): Promise<APIServer>;
2529
+ /**
2530
+ * Get system statistics.
2531
+ */
2532
+ getStats(): BaselineStats;
2533
+ /**
2534
+ * Subscribe to agent bus events.
2535
+ * @example
2536
+ * baseline.bus.subscribe('task:*', (msg) => console.log(msg));
2537
+ * baseline.bus.subscribe('governance:violation', handleViolation);
2538
+ */
2539
+ getBusStats(): Readonly<BusStats>;
2540
+ /**
2541
+ * Get value from semantic cache.
2542
+ */
2543
+ cacheGet<T>(key: string): Promise<T | null>;
2544
+ /**
2545
+ * Store value in semantic cache.
2546
+ */
2547
+ cacheSet<T>(key: string, value: T, options?: {
2548
+ tokensSaved?: number;
2549
+ }): Promise<void>;
2550
+ /**
2551
+ * Get cache statistics.
2552
+ */
2553
+ getCacheStats(): {
2554
+ size: number;
2555
+ hits: number;
2556
+ misses: number;
2557
+ semanticHits: number;
2558
+ hitRate: number;
2559
+ tokensSaved: number;
2560
+ };
2561
+ getAuditTrail(taskId?: string): Array<{
2562
+ timestamp: number;
2563
+ event: OrchestratorEvent;
2564
+ }>;
2565
+ getEvidenceBundle(taskId: string): ReturnType<Orchestrator['getEvidenceBundle']>;
2566
+ private ensureInitialized;
2567
+ private registerDefaultAgents;
2568
+ loadCheckpoint(checkpointId: string): Checkpoint | null;
2569
+ recoverTaskFromCheckpoint(checkpointId: string): Task | null;
2570
+ onEvent<T extends OrchestratorEvent['type']>(type: T, handler: (event: Extract<OrchestratorEvent, {
2571
+ type: T;
2572
+ }>) => void): () => void;
2573
+ }
2574
+ declare class TaskHandle {
2575
+ private task;
2576
+ private orchestrator;
2577
+ constructor(task: Task, orchestrator: Orchestrator);
2578
+ get id(): string;
2579
+ get status(): TaskStatus;
2580
+ /**
2581
+ * Wait for task completion.
2582
+ */
2583
+ wait(timeoutMs?: number): Promise<Task>;
2584
+ /**
2585
+ * Cancel the task.
2586
+ */
2587
+ cancel(): Promise<void>;
2588
+ /**
2589
+ * Get current artifacts.
2590
+ */
2591
+ getArtifacts(): Artifact[];
2592
+ /**
2593
+ * Stream task events.
2594
+ */
2595
+ stream(): AsyncGenerator<TaskEvent>;
2596
+ }
2597
+ interface AgentConfig {
2598
+ id: string;
2599
+ name: string;
2600
+ role: 'planner' | 'executor' | 'supervisor' | 'quality' | 'specialist';
2601
+ capabilities: string[];
2602
+ domains: string[];
2603
+ trustScore?: number;
2604
+ }
2605
+ interface TaskEvent {
2606
+ type: 'status' | 'progress' | 'artifact' | 'checkpoint' | 'error';
2607
+ taskId: string;
2608
+ data: unknown;
2609
+ timestamp: number;
2610
+ }
2611
+ interface BaselineStats {
2612
+ orchestrator: {
2613
+ tasks: {
2614
+ total: number;
2615
+ byStatus: Record<string, number>;
2616
+ };
2617
+ agents: {
2618
+ total: number;
2619
+ byRole: Record<string, number>;
2620
+ };
2621
+ };
2622
+ memory: {
2623
+ working: number;
2624
+ session: number;
2625
+ longTerm: number;
2626
+ shared: number;
2627
+ };
2628
+ indexer: {
2629
+ documents: number;
2630
+ types: number;
2631
+ compressions: number;
2632
+ };
2633
+ cache: {
2634
+ size: number;
2635
+ hits: number;
2636
+ misses: number;
2637
+ hitRate: number;
2638
+ };
2639
+ rag: {
2640
+ totalChunks: number;
2641
+ collections: Record<string, number>;
2642
+ initialized: boolean;
2643
+ };
2644
+ governance: {
2645
+ auditLevel: 'none' | 'basic' | 'full';
2646
+ requireApproval: number;
2647
+ restricted: number;
2648
+ };
2649
+ }
2650
+
2651
+ export { type ExportOptions as $, APIServer as A, BASELINE_TASK_QUEUE as B, type CharterCommitment as C, type ControlCheckContext as D, type ControlCheckResult as E, type CostCheckResult as F, CostGuard as G, type CostGuardConfig as H, type CredentialAccessEvent as I, type CredentialEntry as J, CredentialExpiredError as K, CredentialProvider as L, type CredentialProviderConfig as M, MCPServer, type CycleOutcome as N, type CycleTrigger as O, DEFAULT_PROBES as P, type DFIEvidenceBundle as Q, type DependencyEdge as R, type DependencyGraph as S, DriftDetector as T, type DriftDetectorConfig as U, type DriftReport as V, type DriftSeverity as W, type DriftStrategy as X, type EvaluateInput as Y, EvidenceExporter as Z, type ExpiringCredential as _, type ActivityDependencies as a, type ShadowMode as a$, GTCX_EDGES as a0, GTCX_REPOS as a1, type GitActivity as a2, type GovernanceValidationResult as a3, GovernanceValidator as a4, type GovernanceValidatorConfig as a5, type HandoffContext as a6, type ImprovementCycle as a7, ImprovementCycleLog as a8, type ImprovementCycleLogConfig as a9, PromotionGate as aA, type PromotionGateConfig as aB, type PromotionOutcome as aC, type PromptMeta as aD, type QueuedTask as aE, type RedTeamProbe as aF, type RedTeamReport as aG, RedTeamRunner as aH, type RedTeamRunnerConfig as aI, type RepoNode as aJ, RollbackManager as aK, type RollbackManagerConfig as aL, type RollbackResult as aM, SPECIALIZED_AGENTS as aN, STANDARD_PIPELINES as aO, type SafetyCheckResult as aP, type SafetyContext as aQ, type SafetyResult as aR, type SafetyRule$1 as aS, type SafetyViolation as aT, type SecurityAuditEntry as aU, type SecurityAuditEventType as aV, SecurityManager as aW, type SecurityManagerConfig as aX, type SafetyRule as aY, SenseiAIBridge as aZ, type ShadowComparison as a_, type L5CycleInput as aa, type L5CycleResult as ab, L5Pipeline as ac, type L5PipelineConfig as ad, type LoadedPrompt as ae, type MigrationAuditEntry as af, type MigrationResult as ag, type MigrationTaskContext as ah, type NDPCCheckResult as ai, NDPCComplianceGate as aj, type NDPCContext as ak, type NDPCViolation as al, type OutputValidationFailure as am, type OutputValidationFailureReason as an, type OutputValidationResult as ao, OutputValidator as ap, type OutputValidatorConfig as aq, type Permission as ar, type PillarResult as as, type Pipeline as at, type PipelineExecution as au, type PipelineStep as av, type PipelineStepExecution as aw, type ProbeCategory as ax, type ProbeResult as ay, type PromotionDecision as az, type AgentConfig as b, ShadowRouter as b0, type ShadowRouterConfig as b1, type StandupEntry as b2, type StandupSynthesis as b3, type SubmitOptions as b4, type TaskEvent as b5, TaskHandle as b6, type TemporalClientConfig as b7, TemporalOrchestrator as b8, type TemporalOrchestratorConfig as b9, detectCycles as bA, findBlockers as bB, getAgentDefinition as bC, getAgentsByCapability as bD, getAgentsByDomain as bE, getReadySteps as bF, getTopologicalOrder as bG, getTrustTier as bH, isComplete as bI, isFailed as bJ, loadAllPersonas as bK, loadPersonaPrompt as bL, loadRolePrompt as bM, projectCompletion as bN, synthesizeStandup as bO, type TenantCostSummary as ba, type TokenUsage as bb, type ToolCallRecord as bc, type ToolRiskClassification as bd, type ToolRiskLevel as be, type TradeContext as bf, TradePassGovernanceBridge as bg, type TradeVerificationResult as bh, type TrustSyncEvent as bi, TrustSyncProtocol as bj, type TrustSyncTarget as bk, type TrustTier as bl, type ValidateOptions as bm, type ValidationResult as bn, type VelocitySnapshot as bo, type WorkflowAccumulator as bp, buildStepTaskInput as bq, createActivities as br, createAgentFromDefinition as bs, createDependencyGraph as bt, createGTCXGraph as bu, createHandoff as bv, createPipeline as bw, createPipelineExecution as bx, createTemporalClient as by, createVelocitySnapshot as bz, type AgentDefinition as c, type AgentExecutionRecord as d, AgentExecutor as e, type AgentExecutorConfig as f, type AgentExecutorEvent as g, type AgentExecutorEventType as h, AgenticBridge as i, type AgenticBridgeConfig as j, type AgenticExecutionResult as k, type ApprovalToken as l, type ApprovalTokenConfig as m, ApprovalTokenManager as n, Baseline as o, type BaselineActivities as p, type BaselineStats as q, type BlockerAnalysis as r, CommandCenter as s, type CommandCenterConfig as t, type CommandCenterEvent as u, type CommandCenterEventType as v, type CommandCenterMetrics as w, type CommandCenterStatus as x, type ComplianceControl as y, ComplianceOSBridge as z };