@baselineos/studio 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,846 @@
1
+ // src/config/studio-system-config.json
2
+ var studio_system_config_default = {
3
+ system: {
4
+ name: "Baseline Studio System",
5
+ version: "1.0.0",
6
+ description: "Execution and output generation layer for Baseline Protocol",
7
+ type: "studio-layer",
8
+ architecture: "execution-orchestration"
9
+ },
10
+ execution: {
11
+ maxConcurrent: 10,
12
+ timeout: 6e4,
13
+ retryAttempts: 5,
14
+ retryDelay: 2e3,
15
+ backoffMultiplier: 1.5,
16
+ maxRetryDelay: 3e4,
17
+ enableCircuitBreaker: true,
18
+ circuitBreakerThreshold: 5,
19
+ circuitBreakerTimeout: 6e4,
20
+ enableLoadBalancing: true,
21
+ loadBalancingStrategy: "round-robin",
22
+ enableHealthChecks: true,
23
+ healthCheckInterval: 3e4,
24
+ enableMetrics: true,
25
+ metricsCollection: ["execution_time", "success_rate", "error_rate", "throughput"]
26
+ },
27
+ output: {
28
+ formats: ["json", "yaml", "text", "table", "csv", "xml", "html"],
29
+ defaultFormat: "text",
30
+ prettyPrint: true,
31
+ includeMetadata: true,
32
+ includeTimestamps: true,
33
+ includePerformance: true,
34
+ compression: {
35
+ enabled: false,
36
+ algorithm: "gzip",
37
+ level: 6
38
+ },
39
+ encryption: {
40
+ enabled: false,
41
+ algorithm: "aes-256",
42
+ keyRotation: false
43
+ },
44
+ validation: {
45
+ enabled: true,
46
+ schema: "auto",
47
+ strict: false
48
+ },
49
+ customization: {
50
+ enableCustomFormatters: true,
51
+ enableTemplateEngine: true,
52
+ enableDynamicFormatting: true
53
+ }
54
+ },
55
+ workflows: {
56
+ maxSteps: 200,
57
+ maxDepth: 20,
58
+ enableRollback: true,
59
+ enableCheckpoints: true,
60
+ checkpointInterval: 10,
61
+ rollbackStrategy: "automatic",
62
+ enableParallelExecution: true,
63
+ maxParallelSteps: 5,
64
+ enableConditionalExecution: true,
65
+ enableLooping: true,
66
+ maxLoopIterations: 100,
67
+ enableErrorHandling: true,
68
+ errorHandlingStrategy: "continue-on-error",
69
+ enableMonitoring: true,
70
+ monitoringInterval: 1e3,
71
+ enableLogging: true,
72
+ logLevel: "info",
73
+ enableAuditing: true,
74
+ auditTrail: true
75
+ },
76
+ performance: {
77
+ enableCaching: true,
78
+ cacheSize: 5e3,
79
+ cacheTTL: 6e5,
80
+ cacheStrategy: "lru",
81
+ enableProfiling: false,
82
+ profilingLevel: "basic",
83
+ enableOptimization: true,
84
+ optimizationStrategies: ["query_optimization", "memory_optimization", "cpu_optimization"],
85
+ enableLoadBalancing: true,
86
+ loadBalancingAlgorithm: "least_connections",
87
+ enableAutoScaling: false,
88
+ autoScalingThreshold: 80,
89
+ enableResourceMonitoring: true,
90
+ resourceThresholds: {
91
+ cpu: 80,
92
+ memory: 80,
93
+ disk: 85,
94
+ network: 70
95
+ },
96
+ enablePerformanceAlerts: true,
97
+ alertThresholds: {
98
+ response_time: 1e3,
99
+ throughput: 100,
100
+ error_rate: 5
101
+ }
102
+ },
103
+ integration: {
104
+ langSystem: {
105
+ enabled: true,
106
+ interface: "command_processing",
107
+ dataFlow: "bidirectional",
108
+ synchronization: "real-time"
109
+ },
110
+ frameSystem: {
111
+ enabled: true,
112
+ interface: "context_management",
113
+ dataFlow: "bidirectional",
114
+ synchronization: "real-time"
115
+ },
116
+ governSystem: {
117
+ enabled: false,
118
+ interface: "policy_enforcement",
119
+ dataFlow: "unidirectional",
120
+ synchronization: "on-demand"
121
+ },
122
+ experienceSystem: {
123
+ enabled: false,
124
+ interface: "user_interaction",
125
+ dataFlow: "bidirectional",
126
+ synchronization: "real-time"
127
+ }
128
+ },
129
+ security: {
130
+ authentication: {
131
+ required: true,
132
+ methods: ["token", "oauth", "sso", "certificate"],
133
+ timeout: 3600,
134
+ refreshEnabled: true
135
+ },
136
+ authorization: {
137
+ required: true,
138
+ method: "role-based",
139
+ audit: true,
140
+ granular: true
141
+ },
142
+ encryption: {
143
+ data_at_rest: true,
144
+ data_in_transit: true,
145
+ algorithm: "AES-256",
146
+ key_management: "automated"
147
+ },
148
+ logging: {
149
+ enabled: true,
150
+ level: "info",
151
+ retention: "90d",
152
+ encryption: true
153
+ },
154
+ monitoring: {
155
+ enabled: true,
156
+ real_time: true,
157
+ alerts: true,
158
+ compliance: true
159
+ }
160
+ },
161
+ monitoring: {
162
+ metrics: {
163
+ enabled: true,
164
+ collection: ["performance", "business", "infrastructure"],
165
+ interval: 5e3,
166
+ retention: "30d"
167
+ },
168
+ alerting: {
169
+ enabled: true,
170
+ channels: ["email", "slack", "webhook"],
171
+ escalation: true,
172
+ auto_resolution: false
173
+ },
174
+ dashboard: {
175
+ enabled: true,
176
+ real_time: true,
177
+ customizable: true,
178
+ export: true
179
+ },
180
+ reporting: {
181
+ enabled: true,
182
+ scheduled: true,
183
+ formats: ["pdf", "html", "csv"],
184
+ automation: true
185
+ }
186
+ },
187
+ deployment: {
188
+ environments: {
189
+ development: {
190
+ config: "dev",
191
+ features: ["debug", "profiling", "detailed_logging"]
192
+ },
193
+ testing: {
194
+ config: "test",
195
+ features: ["validation", "testing", "mock_data"]
196
+ },
197
+ staging: {
198
+ config: "staging",
199
+ features: ["monitoring", "performance", "security"]
200
+ },
201
+ production: {
202
+ config: "prod",
203
+ features: ["optimization", "security", "monitoring"]
204
+ }
205
+ },
206
+ scaling: {
207
+ horizontal: true,
208
+ vertical: true,
209
+ auto: false,
210
+ manual: true
211
+ },
212
+ backup: {
213
+ enabled: true,
214
+ frequency: "daily",
215
+ retention: "30d",
216
+ encryption: true
217
+ },
218
+ recovery: {
219
+ enabled: true,
220
+ rto: "4h",
221
+ rpo: "1h",
222
+ automated: true
223
+ }
224
+ }
225
+ };
226
+
227
+ // src/system.ts
228
+ import { createHash } from "crypto";
229
+ var ExecutionEngine = class {
230
+ activeCommands = /* @__PURE__ */ new Map();
231
+ config = { maxConcurrent: 5, timeout: 3e4, retryAttempts: 3, retryDelay: 1e3 };
232
+ stats = {
233
+ totalExecuted: 0,
234
+ successful: 0,
235
+ failed: 0,
236
+ averageExecutionTime: 0
237
+ };
238
+ initialize(config) {
239
+ this.config = config;
240
+ }
241
+ async execute(command, options, context) {
242
+ const commandId = `cmd-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
243
+ this.activeCommands.set(commandId, { command, startTime: Date.now(), status: "executing" });
244
+ try {
245
+ const result = await this.simulateExecution(command, options, context);
246
+ const entry = this.activeCommands.get(commandId);
247
+ if (entry) entry.status = "completed";
248
+ this.stats.totalExecuted++;
249
+ this.stats.successful++;
250
+ return {
251
+ success: true,
252
+ commandId,
253
+ result,
254
+ performance: this.calculatePerformance(commandId),
255
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
256
+ };
257
+ } catch (error) {
258
+ const entry = this.activeCommands.get(commandId);
259
+ if (entry) entry.status = "failed";
260
+ this.stats.totalExecuted++;
261
+ this.stats.failed++;
262
+ throw error;
263
+ } finally {
264
+ this.activeCommands.delete(commandId);
265
+ }
266
+ }
267
+ async simulateExecution(command, options, context) {
268
+ return {
269
+ command,
270
+ result: `Executed: ${command}`,
271
+ options,
272
+ context,
273
+ executionTime: 0,
274
+ success: true,
275
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
276
+ };
277
+ }
278
+ calculatePerformance(commandId) {
279
+ const cmd = this.activeCommands.get(commandId);
280
+ if (!cmd) return null;
281
+ return {
282
+ executionTime: Date.now() - cmd.startTime
283
+ };
284
+ }
285
+ getStatus() {
286
+ return {
287
+ status: "operational",
288
+ activeCommands: this.activeCommands.size,
289
+ maxConcurrent: this.config.maxConcurrent,
290
+ timeout: this.config.timeout,
291
+ retryAttempts: this.config.retryAttempts,
292
+ stats: this.stats
293
+ };
294
+ }
295
+ };
296
+ var OutputGenerator = class {
297
+ formatters = /* @__PURE__ */ new Map();
298
+ config = {
299
+ formats: ["json", "yaml", "text", "table", "csv"],
300
+ defaultFormat: "text",
301
+ prettyPrint: true,
302
+ includeMetadata: true
303
+ };
304
+ initialize(config) {
305
+ this.config = config;
306
+ this.setupFormatters();
307
+ }
308
+ setupFormatters() {
309
+ this.formatters.set("json", this.formatJSON.bind(this));
310
+ this.formatters.set("yaml", this.formatYAML.bind(this));
311
+ this.formatters.set("text", this.formatText.bind(this));
312
+ this.formatters.set("table", this.formatTable.bind(this));
313
+ this.formatters.set("csv", this.formatCSV.bind(this));
314
+ this.formatters.set("html", this.formatHTML.bind(this));
315
+ }
316
+ generate(result, format) {
317
+ const outputFormat = format || this.config.defaultFormat;
318
+ const formatter = this.formatters.get(outputFormat);
319
+ if (!formatter) {
320
+ throw new Error(`Unsupported output format: ${outputFormat}`);
321
+ }
322
+ return formatter(result);
323
+ }
324
+ formatJSON(result) {
325
+ const output = {
326
+ success: result.success,
327
+ command: result.command,
328
+ result: result.result,
329
+ timestamp: result.timestamp
330
+ };
331
+ if (this.config.includeMetadata) {
332
+ output.metadata = {
333
+ format: "json",
334
+ generated: (/* @__PURE__ */ new Date()).toISOString(),
335
+ version: "1.0.0"
336
+ };
337
+ }
338
+ return this.config.prettyPrint ? JSON.stringify(output, null, 2) : JSON.stringify(output);
339
+ }
340
+ formatYAML(result) {
341
+ let output = `success: ${result.success}
342
+ `;
343
+ output += `command: ${result.command}
344
+ `;
345
+ output += `result: ${result.result}
346
+ `;
347
+ output += `timestamp: ${result.timestamp}
348
+ `;
349
+ if (this.config.includeMetadata) {
350
+ output += `metadata:
351
+ `;
352
+ output += ` format: yaml
353
+ `;
354
+ output += ` generated: ${(/* @__PURE__ */ new Date()).toISOString()}
355
+ `;
356
+ output += ` version: 1.0.0
357
+ `;
358
+ }
359
+ return output;
360
+ }
361
+ formatText(result) {
362
+ let output = `Command: ${result.command}
363
+ `;
364
+ output += `Status: ${result.success ? "SUCCESS" : "FAILED"}
365
+ `;
366
+ output += `Result: ${result.result}
367
+ `;
368
+ output += `Timestamp: ${result.timestamp}
369
+ `;
370
+ return output;
371
+ }
372
+ formatTable(result) {
373
+ const command = String(result.command || "").padEnd(45);
374
+ const status = (result.success ? "SUCCESS" : "FAILED").padEnd(45);
375
+ let output = "+---------------------------------------------------------+\n";
376
+ output += "| COMMAND EXECUTION RESULT |\n";
377
+ output += "+---------------------------------------------------------+\n";
378
+ output += `| Command | ${command} |
379
+ `;
380
+ output += `| Status | ${status} |
381
+ `;
382
+ output += "+---------------------------------------------------------+\n";
383
+ return output;
384
+ }
385
+ formatCSV(result) {
386
+ let output = "Command,Status,Result,Timestamp\n";
387
+ output += `"${result.command}","${result.success ? "SUCCESS" : "FAILED"}","${result.result}","${result.timestamp}"
388
+ `;
389
+ return output;
390
+ }
391
+ formatHTML(result) {
392
+ const escaped = JSON.stringify(result, null, this.config.prettyPrint ? 2 : 0).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
393
+ return `<!doctype html>
394
+ <html>
395
+ <head>
396
+ <meta charset="utf-8" />
397
+ <title>Baseline Studio Output</title>
398
+ <style>
399
+ body { font-family: system-ui, sans-serif; margin: 24px; }
400
+ pre { background: #f6f8fa; padding: 16px; border-radius: 8px; }
401
+ </style>
402
+ </head>
403
+ <body>
404
+ <h1>Baseline Studio Output</h1>
405
+ <pre>${escaped}</pre>
406
+ </body>
407
+ </html>`;
408
+ }
409
+ getStatus() {
410
+ return {
411
+ status: "operational",
412
+ supportedFormats: this.config.formats,
413
+ defaultFormat: this.config.defaultFormat,
414
+ prettyPrint: this.config.prettyPrint,
415
+ includeMetadata: this.config.includeMetadata
416
+ };
417
+ }
418
+ };
419
+ var WorkflowManager = class {
420
+ activeWorkflows = /* @__PURE__ */ new Map();
421
+ config = { maxSteps: 100, maxDepth: 10, enableRollback: true, enableCheckpoints: true };
422
+ initialize(config) {
423
+ this.config = config;
424
+ }
425
+ async execute(workflow, _options) {
426
+ const workflowId = `wf-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
427
+ this.activeWorkflows.set(workflowId, {
428
+ workflow,
429
+ startTime: Date.now(),
430
+ status: "executing",
431
+ currentStep: 0
432
+ });
433
+ try {
434
+ const result = await this.executeWorkflowSteps(workflow, workflowId);
435
+ const entry = this.activeWorkflows.get(workflowId);
436
+ if (entry) entry.status = "completed";
437
+ return {
438
+ success: true,
439
+ workflowId,
440
+ steps: result.steps,
441
+ performance: result.performance,
442
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
443
+ };
444
+ } catch (error) {
445
+ const entry = this.activeWorkflows.get(workflowId);
446
+ if (entry) entry.status = "failed";
447
+ throw error;
448
+ } finally {
449
+ this.activeWorkflows.delete(workflowId);
450
+ }
451
+ }
452
+ async executeWorkflowSteps(workflow, workflowId) {
453
+ const steps = workflow.steps || [];
454
+ const results = [];
455
+ const startTime = Date.now();
456
+ for (let i = 0; i < steps.length && i < this.config.maxSteps; i++) {
457
+ const step = steps[i];
458
+ const stepResult = {
459
+ stepIndex: i,
460
+ step,
461
+ status: "completed",
462
+ result: `Step ${i + 1} executed: ${step}`
463
+ };
464
+ results.push(stepResult);
465
+ const entry = this.activeWorkflows.get(workflowId);
466
+ if (entry) entry.currentStep = i + 1;
467
+ }
468
+ return {
469
+ steps: results,
470
+ performance: {
471
+ totalTime: Date.now() - startTime,
472
+ stepsExecuted: results.length
473
+ }
474
+ };
475
+ }
476
+ getStatus() {
477
+ return {
478
+ status: "operational",
479
+ activeWorkflows: this.activeWorkflows.size,
480
+ maxSteps: this.config.maxSteps,
481
+ maxDepth: this.config.maxDepth,
482
+ enableRollback: this.config.enableRollback,
483
+ enableCheckpoints: this.config.enableCheckpoints
484
+ };
485
+ }
486
+ };
487
+ var TemplateRegistry = class {
488
+ templates = /* @__PURE__ */ new Map();
489
+ register(template) {
490
+ this.templates.set(template.id, template);
491
+ }
492
+ get(id) {
493
+ return this.templates.get(id);
494
+ }
495
+ list() {
496
+ return Array.from(this.templates.values());
497
+ }
498
+ render(id, data) {
499
+ const template = this.templates.get(id);
500
+ if (!template) {
501
+ throw new Error(`Template not found: ${id}`);
502
+ }
503
+ return this.renderTemplate(template.template, data);
504
+ }
505
+ renderTemplate(template, data) {
506
+ return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, key) => {
507
+ let value = data;
508
+ for (const part of key.split(".")) {
509
+ if (value && typeof value === "object") {
510
+ value = value[part];
511
+ continue;
512
+ }
513
+ value = void 0;
514
+ break;
515
+ }
516
+ return value === void 0 || value === null ? "" : String(value);
517
+ });
518
+ }
519
+ };
520
+ var ArtifactManifestBuilder = class {
521
+ build(artifacts) {
522
+ const hash = sha256(stableStringify(artifacts));
523
+ return {
524
+ id: `manifest-${Date.now()}`,
525
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
526
+ artifacts,
527
+ hash
528
+ };
529
+ }
530
+ };
531
+ var ResultProcessor = class {
532
+ initialize() {
533
+ }
534
+ process(result) {
535
+ let processed = this.validateResult(result);
536
+ processed = this.transformResult(processed);
537
+ processed = this.enrichResult(processed);
538
+ return processed;
539
+ }
540
+ validateResult(result) {
541
+ let commandResult = result;
542
+ if (result.result && typeof result.result === "object" && result.result.command) {
543
+ commandResult = result.result;
544
+ }
545
+ return commandResult;
546
+ }
547
+ transformResult(result) {
548
+ return {
549
+ ...result,
550
+ processed: true,
551
+ processedAt: (/* @__PURE__ */ new Date()).toISOString()
552
+ };
553
+ }
554
+ enrichResult(result) {
555
+ return {
556
+ ...result,
557
+ metadata: {
558
+ ...result.metadata || {},
559
+ processor: "Baseline Studio System",
560
+ version: "1.0.0"
561
+ }
562
+ };
563
+ }
564
+ };
565
+ var PerformanceOptimizer = class {
566
+ cache = /* @__PURE__ */ new Map();
567
+ config = { enableCaching: true, cacheSize: 1e3, cacheTTL: 3e5, enableProfiling: false };
568
+ stats = { cacheHits: 0, cacheMisses: 0, optimizationsApplied: 0 };
569
+ initialize(config) {
570
+ this.config = config;
571
+ }
572
+ optimize(result) {
573
+ if (this.config.enableCaching) {
574
+ this.cacheResult(result);
575
+ }
576
+ this.stats.optimizationsApplied++;
577
+ return result;
578
+ }
579
+ cacheResult(result) {
580
+ const key = this.generateCacheKey(result);
581
+ if (this.cache.size >= this.config.cacheSize) {
582
+ const firstKey = this.cache.keys().next().value;
583
+ if (firstKey) this.cache.delete(firstKey);
584
+ }
585
+ this.cache.set(key, { result, timestamp: Date.now(), ttl: this.config.cacheTTL });
586
+ }
587
+ generateCacheKey(result) {
588
+ return `${result.command}-${JSON.stringify(result.options)}`;
589
+ }
590
+ getCachedResult(command, options) {
591
+ const key = this.generateCacheKey({ command, options });
592
+ const cached = this.cache.get(key);
593
+ if (cached && Date.now() - cached.timestamp < cached.ttl) {
594
+ this.stats.cacheHits++;
595
+ return cached.result;
596
+ }
597
+ this.stats.cacheMisses++;
598
+ return null;
599
+ }
600
+ getStatus() {
601
+ return {
602
+ status: "operational",
603
+ enableCaching: this.config.enableCaching,
604
+ cacheSize: this.cache.size,
605
+ cacheTTL: this.config.cacheTTL,
606
+ enableProfiling: this.config.enableProfiling,
607
+ stats: this.stats
608
+ };
609
+ }
610
+ };
611
+ var BaselineStudioSystem = class {
612
+ config;
613
+ executionEngine;
614
+ outputGenerator;
615
+ workflowManager;
616
+ resultProcessor;
617
+ performanceOptimizer;
618
+ templateRegistry;
619
+ manifestBuilder;
620
+ constructor() {
621
+ this.config = this.loadConfiguration();
622
+ this.executionEngine = new ExecutionEngine();
623
+ this.outputGenerator = new OutputGenerator();
624
+ this.workflowManager = new WorkflowManager();
625
+ this.resultProcessor = new ResultProcessor();
626
+ this.performanceOptimizer = new PerformanceOptimizer();
627
+ this.templateRegistry = new TemplateRegistry();
628
+ this.manifestBuilder = new ArtifactManifestBuilder();
629
+ this.initializeSystem();
630
+ }
631
+ loadConfiguration() {
632
+ const cfg = studio_system_config_default;
633
+ const exec = cfg.execution ?? {};
634
+ const out = cfg.output ?? {};
635
+ const wf = cfg.workflows ?? {};
636
+ const perf = cfg.performance ?? {};
637
+ return {
638
+ system: {
639
+ name: cfg.system?.name ?? "Baseline Studio System",
640
+ version: cfg.system?.version ?? "1.0.0",
641
+ description: cfg.system?.description ?? "Execution and output generation layer for Baseline Protocol"
642
+ },
643
+ execution: {
644
+ maxConcurrent: exec.maxConcurrent ?? 5,
645
+ timeout: exec.timeout ?? 3e4,
646
+ retryAttempts: exec.retryAttempts ?? 3,
647
+ retryDelay: exec.retryDelay ?? 1e3
648
+ },
649
+ output: {
650
+ formats: out.formats ?? ["json", "yaml", "text", "table", "csv"],
651
+ defaultFormat: out.defaultFormat ?? "text",
652
+ prettyPrint: out.prettyPrint ?? true,
653
+ includeMetadata: out.includeMetadata ?? true
654
+ },
655
+ workflows: {
656
+ maxSteps: wf.maxSteps ?? 100,
657
+ maxDepth: wf.maxDepth ?? 10,
658
+ enableRollback: wf.enableRollback ?? true,
659
+ enableCheckpoints: wf.enableCheckpoints ?? true
660
+ },
661
+ performance: {
662
+ enableCaching: perf.enableCaching ?? true,
663
+ cacheSize: perf.cacheSize ?? 1e3,
664
+ cacheTTL: perf.cacheTTL ?? 3e5,
665
+ enableProfiling: perf.enableProfiling ?? false
666
+ }
667
+ };
668
+ }
669
+ initializeSystem() {
670
+ this.executionEngine.initialize(this.config.execution);
671
+ this.outputGenerator.initialize(this.config.output);
672
+ this.workflowManager.initialize(this.config.workflows);
673
+ this.resultProcessor.initialize();
674
+ this.performanceOptimizer.initialize(this.config.performance);
675
+ }
676
+ async executeCommand(command, options = {}, context = {}) {
677
+ try {
678
+ const validation = this.validateInput(command, options, context);
679
+ if (!validation.valid) {
680
+ return { success: false, error: "Input validation failed", details: validation.errors };
681
+ }
682
+ const executionResult = await this.executionEngine.execute(command, options, context);
683
+ const processedResult = this.resultProcessor.process(executionResult.result);
684
+ const output = this.outputGenerator.generate(processedResult, options.format || null);
685
+ this.performanceOptimizer.optimize(executionResult.result);
686
+ const artifacts = this.buildArtifacts({
687
+ command,
688
+ output,
689
+ format: options.format || this.config.output.defaultFormat,
690
+ context
691
+ });
692
+ const manifest = this.manifestBuilder.build(artifacts);
693
+ return {
694
+ success: true,
695
+ command,
696
+ result: processedResult,
697
+ output,
698
+ artifacts,
699
+ manifest,
700
+ performance: executionResult.performance,
701
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
702
+ };
703
+ } catch (error) {
704
+ const msg = error instanceof Error ? error.message : String(error);
705
+ return {
706
+ success: false,
707
+ error: "Command execution failed",
708
+ details: msg,
709
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
710
+ };
711
+ }
712
+ }
713
+ async executeWorkflow(workflow, options = {}) {
714
+ try {
715
+ const workflowResult = await this.workflowManager.execute(workflow, options);
716
+ const artifacts = this.buildArtifacts({
717
+ workflow: workflow.name,
718
+ output: JSON.stringify(workflowResult),
719
+ format: "json",
720
+ context: options
721
+ });
722
+ const manifest = this.manifestBuilder.build(artifacts);
723
+ return {
724
+ success: true,
725
+ workflow: workflow.name,
726
+ result: workflowResult,
727
+ steps: workflowResult.steps,
728
+ artifacts,
729
+ manifest,
730
+ performance: workflowResult.performance,
731
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
732
+ };
733
+ } catch (error) {
734
+ const msg = error instanceof Error ? error.message : String(error);
735
+ return {
736
+ success: false,
737
+ error: "Workflow execution failed",
738
+ details: msg,
739
+ workflow: workflow.name
740
+ };
741
+ }
742
+ }
743
+ validateInput(command, options, context) {
744
+ const errors = [];
745
+ if (!command || typeof command !== "string") {
746
+ errors.push("Command must be a non-empty string");
747
+ }
748
+ if (options.format && !this.config.output.formats.includes(options.format)) {
749
+ errors.push(
750
+ `Invalid output format: ${options.format}. Valid formats: ${this.config.output.formats.join(", ")}`
751
+ );
752
+ }
753
+ if (context.mode && !["development", "production", "testing", "maintenance"].includes(context.mode)) {
754
+ errors.push(`Invalid context mode: ${context.mode}`);
755
+ }
756
+ return { valid: errors.length === 0, errors };
757
+ }
758
+ getStatus() {
759
+ return {
760
+ system: this.config.system.name,
761
+ version: this.config.system.version,
762
+ execution: this.executionEngine.getStatus(),
763
+ output: this.outputGenerator.getStatus(),
764
+ workflows: this.workflowManager.getStatus(),
765
+ performance: this.performanceOptimizer.getStatus()
766
+ };
767
+ }
768
+ registerTemplate(template) {
769
+ this.templateRegistry.register(template);
770
+ }
771
+ renderTemplate(templateId, data) {
772
+ return this.templateRegistry.render(templateId, data);
773
+ }
774
+ preview(templateId, data, format = "text") {
775
+ const rendered = this.renderTemplate(templateId, data);
776
+ if (format === "json") {
777
+ return JSON.stringify({ rendered, templateId }, null, 2);
778
+ }
779
+ if (format === "html") {
780
+ return `<!doctype html><html><body><pre>${rendered}</pre></body></html>`;
781
+ }
782
+ return rendered;
783
+ }
784
+ getExecutionEngine() {
785
+ return this.executionEngine;
786
+ }
787
+ getOutputGenerator() {
788
+ return this.outputGenerator;
789
+ }
790
+ getWorkflowManager() {
791
+ return this.workflowManager;
792
+ }
793
+ getPerformanceOptimizer() {
794
+ return this.performanceOptimizer;
795
+ }
796
+ getTemplateRegistry() {
797
+ return this.templateRegistry;
798
+ }
799
+ buildArtifacts(input) {
800
+ const provenance = {
801
+ command: input.command,
802
+ workflow: input.workflow,
803
+ context: input.context,
804
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString()
805
+ };
806
+ const artifact = {
807
+ id: `artifact-${Date.now()}`,
808
+ type: "output",
809
+ format: input.format,
810
+ content: input.output,
811
+ hash: sha256(stableStringify({ command: input.command, workflow: input.workflow, format: input.format, context: input.context })),
812
+ provenance
813
+ };
814
+ return [artifact];
815
+ }
816
+ };
817
+ function sha256(input) {
818
+ return createHash("sha256").update(input).digest("hex");
819
+ }
820
+ function stableStringify(value) {
821
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
822
+ if (Array.isArray(value)) {
823
+ return `[${value.map(stableStringify).join(",")}]`;
824
+ }
825
+ const obj = value;
826
+ const keys = Object.keys(obj).sort();
827
+ const entries = keys.map((key) => `"${key}":${stableStringify(obj[key])}`);
828
+ return `{${entries.join(",")}}`;
829
+ }
830
+ export {
831
+ BaselineStudioSystem,
832
+ ExecutionEngine,
833
+ OutputGenerator,
834
+ PerformanceOptimizer,
835
+ ResultProcessor,
836
+ WorkflowManager
837
+ };
838
+ /**
839
+ * Baseline Studio System
840
+ *
841
+ * The execution and output generation layer of the Baseline Protocol that
842
+ * orchestrates command execution, manages workflows, and generates
843
+ * structured output in multiple formats.
844
+ *
845
+ * @license Apache-2.0
846
+ */