@baselineos/frame 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,800 @@
1
+ // src/config/frame-system-config.json
2
+ var frame_system_config_default = {
3
+ system: {
4
+ name: "Baseline Frame System",
5
+ version: "1.0.0",
6
+ description: "Context and control layer for Baseline Protocol",
7
+ type: "frame-layer",
8
+ architecture: "context-control"
9
+ },
10
+ modes: {
11
+ development: {
12
+ description: "Development mode with full access and debugging capabilities",
13
+ permissions: ["read", "write", "execute", "debug", "test"],
14
+ environment: "dev",
15
+ features: ["hot-reload", "debugging", "testing", "profiling", "logging"],
16
+ security: "relaxed",
17
+ performance: "development"
18
+ },
19
+ production: {
20
+ description: "Production mode with restricted access and security focus",
21
+ permissions: ["read", "execute", "monitor"],
22
+ environment: "prod",
23
+ features: ["monitoring", "logging", "security", "performance", "scalability"],
24
+ security: "strict",
25
+ performance: "optimized"
26
+ },
27
+ testing: {
28
+ description: "Testing mode for validation and quality assurance",
29
+ permissions: ["read", "write", "execute", "test"],
30
+ environment: "test",
31
+ features: ["validation", "testing", "reporting", "coverage", "mocking"],
32
+ security: "moderate",
33
+ performance: "testing"
34
+ },
35
+ maintenance: {
36
+ description: "Maintenance mode for system operations and administration",
37
+ permissions: ["read", "write", "execute", "admin", "system"],
38
+ environment: "maintenance",
39
+ features: ["backup", "restore", "upgrade", "repair", "diagnostics"],
40
+ security: "elevated",
41
+ performance: "maintenance"
42
+ },
43
+ staging: {
44
+ description: "Staging mode for pre-production testing and validation",
45
+ permissions: ["read", "write", "execute", "test", "monitor"],
46
+ environment: "staging",
47
+ features: ["validation", "testing", "monitoring", "performance", "security"],
48
+ security: "moderate",
49
+ performance: "production-like"
50
+ }
51
+ },
52
+ contexts: {
53
+ default: {
54
+ description: "Default application context for general operations",
55
+ mode: "development",
56
+ environment: "dev",
57
+ permissions: ["read", "write", "execute"],
58
+ authority: "user",
59
+ scope: "application"
60
+ },
61
+ user: {
62
+ description: "User-specific context with personalized settings",
63
+ mode: "development",
64
+ environment: "dev",
65
+ permissions: ["read", "write", "execute"],
66
+ authority: "user",
67
+ scope: "user"
68
+ },
69
+ system: {
70
+ description: "System-level context for core operations",
71
+ mode: "production",
72
+ environment: "prod",
73
+ permissions: ["read", "execute", "monitor"],
74
+ authority: "system",
75
+ scope: "system"
76
+ },
77
+ admin: {
78
+ description: "Administrative context for system management",
79
+ mode: "maintenance",
80
+ environment: "maintenance",
81
+ permissions: ["read", "write", "execute", "admin"],
82
+ authority: "admin",
83
+ scope: "system"
84
+ },
85
+ developer: {
86
+ description: "Developer context for development and testing",
87
+ mode: "development",
88
+ environment: "dev",
89
+ permissions: ["read", "write", "execute", "debug", "test"],
90
+ authority: "developer",
91
+ scope: "development"
92
+ },
93
+ tester: {
94
+ description: "Testing context for quality assurance",
95
+ mode: "testing",
96
+ environment: "test",
97
+ permissions: ["read", "write", "execute", "test"],
98
+ authority: "developer",
99
+ scope: "testing"
100
+ },
101
+ deployment: {
102
+ description: "Deployment context for release management",
103
+ mode: "staging",
104
+ environment: "staging",
105
+ permissions: ["read", "write", "execute", "deploy"],
106
+ authority: "admin",
107
+ scope: "deployment"
108
+ }
109
+ },
110
+ authorities: {
111
+ user: {
112
+ level: 1,
113
+ permissions: ["read", "write"],
114
+ description: "Standard user permissions for basic operations",
115
+ scope: "user",
116
+ restrictions: ["system", "admin"]
117
+ },
118
+ developer: {
119
+ level: 2,
120
+ permissions: ["read", "write", "execute", "debug", "test"],
121
+ description: "Developer permissions for development and testing",
122
+ scope: "development",
123
+ restrictions: ["system", "admin"]
124
+ },
125
+ admin: {
126
+ level: 3,
127
+ permissions: ["read", "write", "execute", "admin", "deploy"],
128
+ description: "Administrative permissions for system management",
129
+ scope: "system",
130
+ restrictions: ["system"]
131
+ },
132
+ system: {
133
+ level: 4,
134
+ permissions: ["read", "write", "execute", "admin", "system", "core"],
135
+ description: "System-level permissions for core operations",
136
+ scope: "core",
137
+ restrictions: []
138
+ },
139
+ superuser: {
140
+ level: 5,
141
+ permissions: ["read", "write", "execute", "admin", "system", "core", "override"],
142
+ description: "Superuser permissions with override capabilities",
143
+ scope: "all",
144
+ restrictions: []
145
+ }
146
+ },
147
+ environments: {
148
+ dev: {
149
+ name: "dev",
150
+ type: "development",
151
+ description: "Development environment for active development",
152
+ variables: {
153
+ NODE_ENV: "development",
154
+ DEBUG: "true",
155
+ LOG_LEVEL: "debug",
156
+ API_URL: "http://localhost:3000",
157
+ DATABASE_URL: "mongodb://localhost:27017/dev",
158
+ CACHE_TTL: "300"
159
+ },
160
+ features: ["hot-reload", "debugging", "profiling"]
161
+ },
162
+ test: {
163
+ name: "test",
164
+ type: "testing",
165
+ description: "Testing environment for quality assurance",
166
+ variables: {
167
+ NODE_ENV: "test",
168
+ DEBUG: "true",
169
+ LOG_LEVEL: "debug",
170
+ API_URL: "http://localhost:3001",
171
+ DATABASE_URL: "mongodb://localhost:27017/test",
172
+ CACHE_TTL: "60"
173
+ },
174
+ features: ["testing", "mocking", "coverage"]
175
+ },
176
+ staging: {
177
+ name: "staging",
178
+ type: "staging",
179
+ description: "Staging environment for pre-production validation",
180
+ variables: {
181
+ NODE_ENV: "staging",
182
+ DEBUG: "false",
183
+ LOG_LEVEL: "info",
184
+ API_URL: "https://staging-api.example.com",
185
+ DATABASE_URL: "mongodb://staging-db:27017/staging",
186
+ CACHE_TTL: "1800"
187
+ },
188
+ features: ["monitoring", "validation", "performance"]
189
+ },
190
+ prod: {
191
+ name: "prod",
192
+ type: "production",
193
+ description: "Production environment for live operations",
194
+ variables: {
195
+ NODE_ENV: "production",
196
+ DEBUG: "false",
197
+ LOG_LEVEL: "warn",
198
+ API_URL: "https://api.example.com",
199
+ DATABASE_URL: "mongodb://prod-db:27017/production",
200
+ CACHE_TTL: "3600"
201
+ },
202
+ features: ["monitoring", "security", "scalability"]
203
+ },
204
+ maintenance: {
205
+ name: "maintenance",
206
+ type: "maintenance",
207
+ description: "Maintenance environment for system operations",
208
+ variables: {
209
+ NODE_ENV: "maintenance",
210
+ DEBUG: "true",
211
+ LOG_LEVEL: "info",
212
+ API_URL: "http://localhost:3002",
213
+ DATABASE_URL: "mongodb://localhost:27017/maintenance",
214
+ CACHE_TTL: "0"
215
+ },
216
+ features: ["backup", "restore", "diagnostics"]
217
+ }
218
+ },
219
+ permissions: {
220
+ read: {
221
+ description: "Read access to resources and data",
222
+ scope: "data",
223
+ level: 1
224
+ },
225
+ write: {
226
+ description: "Write access to resources and data",
227
+ scope: "data",
228
+ level: 2
229
+ },
230
+ execute: {
231
+ description: "Execute commands and operations",
232
+ scope: "operations",
233
+ level: 2
234
+ },
235
+ debug: {
236
+ description: "Debug and development capabilities",
237
+ scope: "development",
238
+ level: 2
239
+ },
240
+ test: {
241
+ description: "Testing and validation capabilities",
242
+ scope: "testing",
243
+ level: 2
244
+ },
245
+ monitor: {
246
+ description: "Monitoring and observation capabilities",
247
+ scope: "monitoring",
248
+ level: 1
249
+ },
250
+ admin: {
251
+ description: "Administrative and management capabilities",
252
+ scope: "system",
253
+ level: 3
254
+ },
255
+ deploy: {
256
+ description: "Deployment and release capabilities",
257
+ scope: "deployment",
258
+ level: 3
259
+ },
260
+ system: {
261
+ description: "System-level capabilities",
262
+ scope: "core",
263
+ level: 4
264
+ },
265
+ core: {
266
+ description: "Core system capabilities",
267
+ scope: "core",
268
+ level: 4
269
+ },
270
+ override: {
271
+ description: "Override and emergency capabilities",
272
+ scope: "all",
273
+ level: 5
274
+ }
275
+ },
276
+ security: {
277
+ authentication: {
278
+ required: true,
279
+ methods: ["token", "oauth", "sso"],
280
+ timeout: 3600
281
+ },
282
+ authorization: {
283
+ required: true,
284
+ method: "role-based",
285
+ audit: true
286
+ },
287
+ encryption: {
288
+ data_at_rest: true,
289
+ data_in_transit: true,
290
+ algorithm: "AES-256"
291
+ },
292
+ logging: {
293
+ enabled: true,
294
+ level: "info",
295
+ retention: "90d"
296
+ }
297
+ },
298
+ performance: {
299
+ caching: {
300
+ enabled: true,
301
+ strategy: "lru",
302
+ max_size: "100MB"
303
+ },
304
+ monitoring: {
305
+ enabled: true,
306
+ metrics: ["cpu", "memory", "response_time"],
307
+ alerts: true
308
+ },
309
+ optimization: {
310
+ enabled: true,
311
+ strategies: ["compression", "minification", "bundling"]
312
+ }
313
+ }
314
+ };
315
+
316
+ // src/system.ts
317
+ function extractRequiredPermissions(options) {
318
+ const candidate = options.requiredPermissions;
319
+ if (!Array.isArray(candidate)) {
320
+ return null;
321
+ }
322
+ if (candidate.every((permission) => typeof permission === "string")) {
323
+ return candidate;
324
+ }
325
+ return null;
326
+ }
327
+ var ContextManager = class {
328
+ contexts = /* @__PURE__ */ new Map();
329
+ currentContext = null;
330
+ history = [];
331
+ initialize(contextConfig) {
332
+ for (const [name, config] of Object.entries(contextConfig)) {
333
+ this.contexts.set(name, {
334
+ name,
335
+ description: config.description,
336
+ mode: config.mode,
337
+ environment: config.environment,
338
+ permissions: config.permissions,
339
+ authority: config.authority || "user",
340
+ status: "inactive",
341
+ createdAt: Date.now(),
342
+ updatedAt: Date.now()
343
+ });
344
+ }
345
+ }
346
+ createContext(name, config) {
347
+ if (this.contexts.has(name)) return false;
348
+ this.contexts.set(name, {
349
+ name,
350
+ description: config.description,
351
+ mode: config.mode,
352
+ environment: config.environment,
353
+ permissions: config.permissions,
354
+ authority: config.authority || "user",
355
+ status: "inactive",
356
+ createdAt: Date.now(),
357
+ updatedAt: Date.now()
358
+ });
359
+ this.history.push({ name, action: "create", timestamp: Date.now() });
360
+ return true;
361
+ }
362
+ setContext(contextName) {
363
+ return this.activateContext(contextName);
364
+ }
365
+ activateContext(contextName) {
366
+ const ctx = this.contexts.get(contextName);
367
+ if (!ctx || ctx.status === "archived") return false;
368
+ if (this.currentContext) {
369
+ this.currentContext.status = "inactive";
370
+ this.currentContext.updatedAt = Date.now();
371
+ }
372
+ ctx.status = "active";
373
+ ctx.updatedAt = Date.now();
374
+ ctx.lastActivatedAt = Date.now();
375
+ this.currentContext = ctx;
376
+ this.history.push({ name: contextName, action: "activate", timestamp: Date.now() });
377
+ return true;
378
+ }
379
+ archiveContext(contextName) {
380
+ const ctx = this.contexts.get(contextName);
381
+ if (!ctx) return false;
382
+ ctx.status = "archived";
383
+ ctx.archivedAt = Date.now();
384
+ ctx.updatedAt = Date.now();
385
+ if (this.currentContext?.name === contextName) {
386
+ this.currentContext = null;
387
+ }
388
+ this.history.push({ name: contextName, action: "archive", timestamp: Date.now() });
389
+ return true;
390
+ }
391
+ getCurrentContext() {
392
+ return this.currentContext;
393
+ }
394
+ getContext(contextName) {
395
+ return this.contexts.get(contextName);
396
+ }
397
+ listContexts() {
398
+ return Array.from(this.contexts.keys());
399
+ }
400
+ getContextHistory() {
401
+ return this.history.map((item) => item.name);
402
+ }
403
+ getActiveContexts() {
404
+ return this.currentContext ? [this.currentContext] : [];
405
+ }
406
+ getContextTimeline() {
407
+ return [...this.history];
408
+ }
409
+ };
410
+ var ModeManager = class {
411
+ modes = /* @__PURE__ */ new Map();
412
+ currentMode = null;
413
+ initialize(modeConfig) {
414
+ for (const [name, config] of Object.entries(modeConfig)) {
415
+ this.modes.set(name, {
416
+ name,
417
+ description: config.description,
418
+ permissions: config.permissions,
419
+ environment: config.environment,
420
+ features: config.features
421
+ });
422
+ }
423
+ }
424
+ setMode(modeName) {
425
+ if (this.modes.has(modeName)) {
426
+ this.currentMode = this.modes.get(modeName);
427
+ return true;
428
+ }
429
+ return false;
430
+ }
431
+ getCurrentMode() {
432
+ return this.currentMode;
433
+ }
434
+ getMode(modeName) {
435
+ return this.modes.get(modeName);
436
+ }
437
+ processInMode(modeName, command, options, args) {
438
+ const mode = this.modes.get(modeName);
439
+ if (!mode) {
440
+ throw new Error(`Mode "${modeName}" not found`);
441
+ }
442
+ return {
443
+ mode: modeName,
444
+ command,
445
+ options,
446
+ arguments: args,
447
+ permissions: mode.permissions,
448
+ environment: mode.environment,
449
+ result: `Command executed in ${modeName} mode`
450
+ };
451
+ }
452
+ };
453
+ var AuthorityManager = class {
454
+ authorities = /* @__PURE__ */ new Map();
455
+ currentAuthority = null;
456
+ initialize(authorityConfig) {
457
+ for (const [name, config] of Object.entries(authorityConfig)) {
458
+ this.authorities.set(name, {
459
+ name,
460
+ level: config.level,
461
+ permissions: config.permissions,
462
+ description: config.description
463
+ });
464
+ }
465
+ this.currentAuthority = this.authorities.get("user") || null;
466
+ }
467
+ getCurrentAuthority() {
468
+ return this.currentAuthority;
469
+ }
470
+ setAuthority(authorityName) {
471
+ if (this.authorities.has(authorityName)) {
472
+ this.currentAuthority = this.authorities.get(authorityName);
473
+ return true;
474
+ }
475
+ return false;
476
+ }
477
+ checkPermission(authorityName, command, options) {
478
+ const authority = this.authorities.get(authorityName);
479
+ if (!authority) return false;
480
+ const required = this.getRequiredPermissions(command, options);
481
+ return required.every((perm) => authority.permissions.includes(perm));
482
+ }
483
+ getRequiredPermissions(command, options) {
484
+ if (options) {
485
+ const fromOptions = extractRequiredPermissions(options);
486
+ if (fromOptions) {
487
+ return fromOptions;
488
+ }
489
+ }
490
+ const cmd = command.toLowerCase();
491
+ if (cmd.includes("admin") || cmd.includes("system") || cmd.includes("override")) {
492
+ return ["admin"];
493
+ }
494
+ if (cmd.includes("deploy")) {
495
+ return ["deploy"];
496
+ }
497
+ if (cmd.includes("write") || cmd.includes("create") || cmd.includes("set") || cmd.includes("update") || cmd.includes("archive")) {
498
+ return ["write"];
499
+ }
500
+ if (cmd.includes("run") || cmd.includes("execute") || cmd.includes("start")) {
501
+ return ["execute"];
502
+ }
503
+ return ["read"];
504
+ }
505
+ };
506
+ var EnvironmentManager = class {
507
+ environments = /* @__PURE__ */ new Map();
508
+ currentEnvironment = null;
509
+ initialize(envConfig) {
510
+ if (envConfig && Object.keys(envConfig).length > 0) {
511
+ for (const [name, env] of Object.entries(envConfig)) {
512
+ this.environments.set(name, env);
513
+ }
514
+ this.currentEnvironment = this.environments.values().next().value ?? null;
515
+ return;
516
+ }
517
+ this.environments.set("dev", {
518
+ name: "dev",
519
+ type: "development",
520
+ description: "Development environment",
521
+ variables: { NODE_ENV: "development", DEBUG: "true", LOG_LEVEL: "debug" }
522
+ });
523
+ this.environments.set("prod", {
524
+ name: "prod",
525
+ type: "production",
526
+ description: "Production environment",
527
+ variables: { NODE_ENV: "production", DEBUG: "false", LOG_LEVEL: "info" }
528
+ });
529
+ this.environments.set("test", {
530
+ name: "test",
531
+ type: "testing",
532
+ description: "Testing environment",
533
+ variables: { NODE_ENV: "test", DEBUG: "true", LOG_LEVEL: "debug" }
534
+ });
535
+ this.currentEnvironment = this.environments.get("dev") || null;
536
+ }
537
+ getCurrentEnvironment() {
538
+ return this.currentEnvironment;
539
+ }
540
+ setEnvironment(envName) {
541
+ if (this.environments.has(envName)) {
542
+ this.currentEnvironment = this.environments.get(envName);
543
+ return true;
544
+ }
545
+ return false;
546
+ }
547
+ getEnvironmentVariable(name) {
548
+ return this.currentEnvironment?.variables[name];
549
+ }
550
+ };
551
+ var BaselineFrameSystem = class {
552
+ config;
553
+ context;
554
+ modeManager;
555
+ authorityManager;
556
+ environmentManager;
557
+ initialized = false;
558
+ constructor() {
559
+ this.config = this.loadConfiguration();
560
+ this.context = new ContextManager();
561
+ this.modeManager = new ModeManager();
562
+ this.authorityManager = new AuthorityManager();
563
+ this.environmentManager = new EnvironmentManager();
564
+ this.initializeSystem();
565
+ }
566
+ loadConfiguration() {
567
+ const cfg = frame_system_config_default;
568
+ const modes = {};
569
+ for (const [name, mode] of Object.entries(cfg.modes ?? {})) {
570
+ modes[name] = {
571
+ description: mode.description ?? "",
572
+ permissions: mode.permissions ?? [],
573
+ environment: mode.environment ?? "dev",
574
+ features: mode.features ?? []
575
+ };
576
+ }
577
+ const contexts = {};
578
+ for (const [name, ctx] of Object.entries(cfg.contexts ?? {})) {
579
+ contexts[name] = {
580
+ description: ctx.description ?? "",
581
+ mode: ctx.mode ?? "development",
582
+ environment: ctx.environment ?? "dev",
583
+ permissions: ctx.permissions ?? []
584
+ };
585
+ }
586
+ const authorities = {};
587
+ for (const [name, auth] of Object.entries(cfg.authorities ?? {})) {
588
+ authorities[name] = {
589
+ level: auth.level ?? 1,
590
+ permissions: auth.permissions ?? [],
591
+ description: auth.description ?? ""
592
+ };
593
+ }
594
+ return {
595
+ system: {
596
+ name: cfg.system?.name ?? "Baseline Frame System",
597
+ version: cfg.system?.version ?? "1.0.0",
598
+ description: cfg.system?.description ?? "Context and control layer for Baseline Protocol"
599
+ },
600
+ modes,
601
+ contexts,
602
+ authorities,
603
+ environments: cfg.environments ?? {}
604
+ };
605
+ }
606
+ initializeSystem() {
607
+ this.context.initialize(this.config.contexts);
608
+ this.modeManager.initialize(this.config.modes);
609
+ this.authorityManager.initialize(this.config.authorities);
610
+ this.environmentManager.initialize(this.config.environments);
611
+ this.context.setContext("default");
612
+ const defaultContext = this.context.getCurrentContext();
613
+ if (defaultContext?.mode) {
614
+ this.modeManager.setMode(defaultContext.mode);
615
+ } else {
616
+ this.modeManager.setMode("development");
617
+ }
618
+ if (defaultContext?.authority) {
619
+ this.authorityManager.setAuthority(defaultContext.authority);
620
+ }
621
+ if (defaultContext?.environment) {
622
+ this.environmentManager.setEnvironment(defaultContext.environment);
623
+ }
624
+ this.initialized = true;
625
+ }
626
+ processCommand(command, options = {}, args = []) {
627
+ try {
628
+ const currentContext = this.context.getCurrentContext();
629
+ if (!currentContext) {
630
+ return { success: false, error: "No context set" };
631
+ }
632
+ const hasPermission = this.authorityManager.checkPermission(
633
+ currentContext.authority,
634
+ command,
635
+ options
636
+ );
637
+ if (!hasPermission) {
638
+ return {
639
+ success: false,
640
+ error: "Insufficient permissions for this command",
641
+ context: currentContext.name,
642
+ required: this.authorityManager.getRequiredPermissions(command),
643
+ current: currentContext.authority
644
+ };
645
+ }
646
+ const requiredPermissions = this.authorityManager.getRequiredPermissions(command, options);
647
+ const currentMode = this.modeManager.getCurrentMode();
648
+ const modePermissions = currentMode?.permissions ?? [];
649
+ const contextPermissions = currentContext.permissions ?? [];
650
+ const missingFromContext = requiredPermissions.filter((p) => !contextPermissions.includes(p));
651
+ const missingFromMode = requiredPermissions.filter((p) => !modePermissions.includes(p));
652
+ if (missingFromContext.length > 0 || missingFromMode.length > 0) {
653
+ return {
654
+ success: false,
655
+ error: "Permission denied by context/mode",
656
+ context: currentContext.name,
657
+ required: requiredPermissions,
658
+ current: currentContext.authority,
659
+ permissions: {
660
+ context: contextPermissions,
661
+ mode: modePermissions
662
+ }
663
+ };
664
+ }
665
+ const result = this.modeManager.processInMode(
666
+ currentContext.mode,
667
+ command,
668
+ options,
669
+ args
670
+ );
671
+ return {
672
+ success: true,
673
+ command,
674
+ context: currentContext.name,
675
+ mode: currentContext.mode,
676
+ result,
677
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
678
+ };
679
+ } catch (error) {
680
+ const msg = error instanceof Error ? error.message : String(error);
681
+ return {
682
+ success: false,
683
+ error: "Command processing failed",
684
+ details: msg,
685
+ context: this.context.getCurrentContext()?.name || "unknown"
686
+ };
687
+ }
688
+ }
689
+ switchContext(contextName) {
690
+ const target = this.context.getContext(contextName);
691
+ if (!target || target.status === "archived") {
692
+ return {
693
+ success: false,
694
+ error: `Context "${contextName}" not found`,
695
+ available: Object.keys(this.config.contexts)
696
+ };
697
+ }
698
+ const mode = this.modeManager.getMode(target.mode);
699
+ if (!mode) {
700
+ return {
701
+ success: false,
702
+ error: `Mode "${target.mode}" not found`,
703
+ available: Object.keys(this.config.modes)
704
+ };
705
+ }
706
+ if (mode.environment !== target.environment) {
707
+ return {
708
+ success: false,
709
+ error: `Context environment "${target.environment}" does not match mode environment "${mode.environment}"`
710
+ };
711
+ }
712
+ const success = this.context.activateContext(contextName);
713
+ if (!success) {
714
+ return {
715
+ success: false,
716
+ error: `Context "${contextName}" not found`,
717
+ available: Object.keys(this.config.contexts)
718
+ };
719
+ }
720
+ const newContext = this.context.getCurrentContext();
721
+ this.authorityManager.setAuthority(newContext.authority);
722
+ this.modeManager.setMode(newContext.mode);
723
+ this.environmentManager.setEnvironment(newContext.environment);
724
+ return {
725
+ success: true,
726
+ context: newContext.name,
727
+ mode: newContext.mode,
728
+ authority: newContext.authority,
729
+ environment: newContext.environment
730
+ };
731
+ }
732
+ switchMode(modeName) {
733
+ const currentMode = this.modeManager.getCurrentMode();
734
+ const success = this.modeManager.setMode(modeName);
735
+ if (!success) {
736
+ return {
737
+ success: false,
738
+ error: `Mode "${modeName}" not found`,
739
+ available: Object.keys(this.config.modes)
740
+ };
741
+ }
742
+ const newMode = this.modeManager.getCurrentMode();
743
+ const currentContext = this.context.getCurrentContext();
744
+ if (currentContext && currentContext.environment !== newMode.environment) {
745
+ if (currentMode) this.modeManager.setMode(currentMode.name);
746
+ return {
747
+ success: false,
748
+ error: `Mode environment "${newMode.environment}" does not match context environment "${currentContext.environment}"`
749
+ };
750
+ }
751
+ this.environmentManager.setEnvironment(newMode.environment);
752
+ return {
753
+ success: true,
754
+ mode: newMode,
755
+ description: newMode.description,
756
+ permissions: newMode.permissions,
757
+ environment: newMode.environment
758
+ };
759
+ }
760
+ getStatus() {
761
+ return {
762
+ initialized: this.initialized,
763
+ contextHistory: this.context.getContextHistory().length,
764
+ currentMode: this.modeManager.getCurrentMode(),
765
+ currentEnvironment: this.environmentManager.getCurrentEnvironment()?.name,
766
+ activeContexts: this.context.getActiveContexts().length,
767
+ systemName: this.config.system.name,
768
+ version: this.config.system.version,
769
+ currentAuthority: this.authorityManager.getCurrentAuthority()?.name ?? null
770
+ };
771
+ }
772
+ getContextManager() {
773
+ return this.context;
774
+ }
775
+ getModeManager() {
776
+ return this.modeManager;
777
+ }
778
+ getAuthorityManager() {
779
+ return this.authorityManager;
780
+ }
781
+ getEnvironmentManager() {
782
+ return this.environmentManager;
783
+ }
784
+ };
785
+ export {
786
+ AuthorityManager,
787
+ BaselineFrameSystem,
788
+ ContextManager,
789
+ EnvironmentManager,
790
+ ModeManager
791
+ };
792
+ /**
793
+ * Baseline Frame System
794
+ *
795
+ * The context and control layer of the Baseline Protocol that manages
796
+ * intent recognition, mode switching, environment context, and authority
797
+ * management.
798
+ *
799
+ * @license Apache-2.0
800
+ */