@vishal_20/basetree 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +10 -0
- package/README.md +369 -0
- package/dist/agents/alignmentAgent.js +68 -0
- package/dist/agents/governanceOrchestrator.js +152 -0
- package/dist/agents/planet/climateAgent.js +39 -0
- package/dist/agents/planet/diplomacyAgent.js +52 -0
- package/dist/agents/planet/discoveryAgent.js +41 -0
- package/dist/agents/planet/economicAgent.js +64 -0
- package/dist/agents/planet/educationAgent.js +41 -0
- package/dist/agents/planet/governanceCouncilAgent.js +76 -0
- package/dist/agents/planet/healthcareAgent.js +42 -0
- package/dist/agents/planet/infrastructureAgent.js +49 -0
- package/dist/agents/planet/planetAgent.js +5 -0
- package/dist/agents/planet/riskStabilityAgent.js +84 -0
- package/dist/agents/planet/urbanSystemsAgent.js +42 -0
- package/dist/agents/policyAgent.js +31 -0
- package/dist/agents/promptGenomeAgent.js +120 -0
- package/dist/agents/reasoningOptimizerAgent.js +72 -0
- package/dist/agents/regressionAgent.js +162 -0
- package/dist/agents/reinforcementLearnerAgent.js +108 -0
- package/dist/agents/riskEvaluationAgent.js +131 -0
- package/dist/agents/rollbackAgent.js +53 -0
- package/dist/agents/stabilityAgent.js +90 -0
- package/dist/agents/strategyMutationAgent.js +74 -0
- package/dist/agents/systemIntrospectionAgent.js +274 -0
- package/dist/agents/upgradeExecutorAgent.js +146 -0
- package/dist/agents/upgradePlannerAgent.js +80 -0
- package/dist/agents/venture/businessModelAgent.js +81 -0
- package/dist/agents/venture/growthAgent.js +82 -0
- package/dist/agents/venture/ideationAgent.js +89 -0
- package/dist/agents/venture/investorAgent.js +90 -0
- package/dist/agents/venture/legalAgent.js +112 -0
- package/dist/agents/venture/marketResearchAgent.js +80 -0
- package/dist/agents/venture/productAgent.js +96 -0
- package/dist/agents/venture/revenueAgent.js +63 -0
- package/dist/agents/venture/validationAgent.js +189 -0
- package/dist/bootstrap.js +200 -0
- package/dist/cli.js +453 -0
- package/dist/cognitiveGraph/cognitiveGraphEngine.js +180 -0
- package/dist/cognitiveGraph/graphStore.js +81 -0
- package/dist/cognitiveGraph/reasoningStreamBus.js +190 -0
- package/dist/config/config.js +76 -0
- package/dist/core/agent/AdaptivePlanner.js +49 -0
- package/dist/core/agent/AutoFixEngine.js +37 -0
- package/dist/core/agent/ExecutorAgent.js +79 -0
- package/dist/core/agent/LearningMemoryAgent.js +67 -0
- package/dist/core/agent/MemoryAgent.js +35 -0
- package/dist/core/agent/MetaCognitionAgent.js +38 -0
- package/dist/core/agent/PlannerAgent.js +59 -0
- package/dist/core/agent/ReflectionLoop.js +34 -0
- package/dist/core/agent/ReviewerAgent.js +34 -0
- package/dist/core/agent/VerificationAgent.js +20 -0
- package/dist/core/agent/specialists/SpecializedAgents.js +43 -0
- package/dist/core/ai/GeminiProvider.js +113 -0
- package/dist/core/ai/listModels.js +73 -0
- package/dist/core/monitor/PerformanceMonitor.js +18 -0
- package/dist/core/swarm/AgentSwarm.js +56 -0
- package/dist/core/swarm/ReasoningBus.js +26 -0
- package/dist/core/swarm/SwarmOrchestrator.js +36 -0
- package/dist/discovery/experimentOrchestrator.js +75 -0
- package/dist/discovery/hypothesisEngine.js +79 -0
- package/dist/discovery/knowledgeSynthesizer.js +83 -0
- package/dist/discovery/simulationPipeline.js +57 -0
- package/dist/experiments/experimentationEngine.js +174 -0
- package/dist/index.js +67 -0
- package/dist/kernel/eventBus.js +89 -0
- package/dist/kernel/kernel.js +146 -0
- package/dist/llm/tokenEfficiencyOptimizer.js +91 -0
- package/dist/memory/civilizationMemory.js +147 -0
- package/dist/memory/globalVectorMemory.js +87 -0
- package/dist/mesh/crossOrgProtocol.js +110 -0
- package/dist/mesh/globalReasoningBus.js +99 -0
- package/dist/observability/businessDashboard.js +103 -0
- package/dist/observability/businessMetrics.js +105 -0
- package/dist/observability/cognitiveMetrics.js +119 -0
- package/dist/observability/failureSurfaceMapper.js +135 -0
- package/dist/observability/metricsCollector.js +94 -0
- package/dist/observability/planetaryDashboard.js +97 -0
- package/dist/observability/planetaryMetrics.js +127 -0
- package/dist/observability/reportRenderer.js +100 -0
- package/dist/performance/memoryProfiler.js +107 -0
- package/dist/performance/profiler.js +130 -0
- package/dist/pipelines/evolvePipeline.js +150 -0
- package/dist/pipelines/governanceReviewPipeline.js +68 -0
- package/dist/pipelines/introspectPipeline.js +73 -0
- package/dist/pipelines/venture/growPipeline.js +51 -0
- package/dist/pipelines/venture/launchPipeline.js +55 -0
- package/dist/pipelines/venture/monetizePipeline.js +46 -0
- package/dist/pipelines/venture/shutdownPipeline.js +40 -0
- package/dist/pipelines/venture/startupPipeline.js +145 -0
- package/dist/pipelines/venture/validatePipeline.js +40 -0
- package/dist/planet/controlPlane.js +131 -0
- package/dist/planet/executionEngine.js +142 -0
- package/dist/planet/globalTypes.js +5 -0
- package/dist/planet/regionManager.js +114 -0
- package/dist/quality/codeQualityAuditor.js +161 -0
- package/dist/safety/containmentProtocols.js +87 -0
- package/dist/safety/integrityChecker.js +110 -0
- package/dist/safety/kernelGuard.js +57 -0
- package/dist/safety/killSwitch.js +100 -0
- package/dist/safety/planetaryKernel.js +92 -0
- package/dist/safety/policyEngine.js +129 -0
- package/dist/safety/rollbackManager.js +141 -0
- package/dist/safety/sandbox.js +143 -0
- package/dist/server/mindmapServer.js +102 -0
- package/dist/state/distributedState.js +241 -0
- package/dist/state/fileStateStore.js +264 -0
- package/dist/state/snapshotter.js +96 -0
- package/dist/state/stateStore.js +5 -0
- package/dist/tools/FileTools.js +25 -0
- package/dist/tools/GitTools.js +16 -0
- package/dist/tools/ShellTools.js +24 -0
- package/dist/types/architecture.js +5 -0
- package/dist/types/core.js +35 -0
- package/dist/types/governance.js +5 -0
- package/dist/types/venture.js +5 -0
- package/dist/ui/App.js +32 -0
- package/dist/ui/animation/AnimationEngine.js +117 -0
- package/dist/ui/animation/Easing.js +61 -0
- package/dist/ui/cli.js +50 -0
- package/dist/ui/command/ActionPreview.js +47 -0
- package/dist/ui/command/CommandPalette.js +55 -0
- package/dist/ui/command/NaturalLanguageBar.js +77 -0
- package/dist/ui/emotion/AnimationSequences.js +59 -0
- package/dist/ui/emotion/EmotionalUXEngine.js +86 -0
- package/dist/ui/integration/BackendAdapter.js +50 -0
- package/dist/ui/integration/WebSocketAdapter.js +90 -0
- package/dist/ui/intelligence/AdaptiveUIEngine.js +75 -0
- package/dist/ui/intelligence/UserBehaviorTracker.js +88 -0
- package/dist/ui/layout/LayoutEngine.js +115 -0
- package/dist/ui/mindmap/CognitiveMindmapRenderer.js +53 -0
- package/dist/ui/mindmap/EdgeRenderer.js +35 -0
- package/dist/ui/mindmap/GraphLayout.js +137 -0
- package/dist/ui/mindmap/MindmapControls.js +53 -0
- package/dist/ui/mindmap/NodeRenderer.js +53 -0
- package/dist/ui/modes/CognitiveMode.js +31 -0
- package/dist/ui/modes/CommandMode.js +6 -0
- package/dist/ui/modes/GovernanceMode.js +6 -0
- package/dist/ui/modes/MissionControlMode.js +6 -0
- package/dist/ui/modes/ModeManager.js +67 -0
- package/dist/ui/modes/ObservatoryMode.js +10 -0
- package/dist/ui/modes/TimelineMode.js +27 -0
- package/dist/ui/terminalOS.js +180 -0
- package/dist/ui/theme/ThemeEngine.js +164 -0
- package/dist/ui/visual/ColorGradient.js +91 -0
- package/dist/ui/visual/Typography.js +128 -0
- package/dist/ui/visual/UnicodeRenderer.js +86 -0
- package/dist/venture/ventureMemory.js +62 -0
- package/package.json +70 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Synthesizer for BASETREE V7
|
|
3
|
+
* Synthesizes results into coherent knowledge summaries and drafts papers
|
|
4
|
+
*/
|
|
5
|
+
import { GeminiProvider } from '../core/ai/GeminiProvider.js';
|
|
6
|
+
export class KnowledgeSynthesizer {
|
|
7
|
+
civilizationMemory;
|
|
8
|
+
ai;
|
|
9
|
+
constructor(civilizationMemory) {
|
|
10
|
+
this.civilizationMemory = civilizationMemory;
|
|
11
|
+
this.ai = new GeminiProvider();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Synthesize knowledge from multiple sources
|
|
15
|
+
*/
|
|
16
|
+
async synthesize(title, query, relatedMemoryIds) {
|
|
17
|
+
// Retrieve relevant memories
|
|
18
|
+
const memories = relatedMemoryIds
|
|
19
|
+
? await Promise.all(relatedMemoryIds.map(async (id) => {
|
|
20
|
+
const results = await this.civilizationMemory.search(id, undefined, 1);
|
|
21
|
+
return results[0];
|
|
22
|
+
}))
|
|
23
|
+
: await this.civilizationMemory.search(query, undefined, 10);
|
|
24
|
+
const context = memories
|
|
25
|
+
.map((m) => `## ${m.title}\n${m.content}`)
|
|
26
|
+
.join('\n\n');
|
|
27
|
+
// Use AI to synthesize
|
|
28
|
+
const prompt = `Synthesize the following knowledge into a coherent summary:
|
|
29
|
+
|
|
30
|
+
${context}
|
|
31
|
+
|
|
32
|
+
Provide:
|
|
33
|
+
1. A comprehensive summary
|
|
34
|
+
2. Key findings (bullet points)
|
|
35
|
+
3. Conclusions
|
|
36
|
+
4. A draft scientific paper abstract
|
|
37
|
+
|
|
38
|
+
Format as JSON with fields: summary, findings (array), conclusions (array), paperDraft.`;
|
|
39
|
+
try {
|
|
40
|
+
const response = await this.ai.generateResponse(prompt);
|
|
41
|
+
const text = typeof response === 'string' ? response : JSON.stringify(response);
|
|
42
|
+
const synthesis = this.parseSynthesis(text, title);
|
|
43
|
+
// Record synthesis in civilization memory
|
|
44
|
+
await this.civilizationMemory.recordScientificDiscovery(synthesis.title, synthesis.summary);
|
|
45
|
+
return synthesis;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.warn('Failed to synthesize with AI, using fallback:', error);
|
|
49
|
+
return this.createFallbackSynthesis(title, query);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
parseSynthesis(text, title) {
|
|
53
|
+
try {
|
|
54
|
+
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
55
|
+
if (jsonMatch) {
|
|
56
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
57
|
+
return {
|
|
58
|
+
id: `synth_${Date.now()}`,
|
|
59
|
+
title,
|
|
60
|
+
summary: parsed.summary || '',
|
|
61
|
+
findings: parsed.findings || [],
|
|
62
|
+
conclusions: parsed.conclusions || [],
|
|
63
|
+
paperDraft: parsed.paperDraft,
|
|
64
|
+
createdAt: new Date(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// Fall through
|
|
70
|
+
}
|
|
71
|
+
return this.createFallbackSynthesis(title, '');
|
|
72
|
+
}
|
|
73
|
+
createFallbackSynthesis(title, query) {
|
|
74
|
+
return {
|
|
75
|
+
id: `synth_${Date.now()}`,
|
|
76
|
+
title,
|
|
77
|
+
summary: `Synthesis of knowledge related to: ${query}`,
|
|
78
|
+
findings: ['Finding 1', 'Finding 2'],
|
|
79
|
+
conclusions: ['Conclusion 1'],
|
|
80
|
+
createdAt: new Date(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simulation Pipeline for BASETREE V7
|
|
3
|
+
* Manages simulation tasks across regions
|
|
4
|
+
*/
|
|
5
|
+
import { randomUUID } from 'crypto';
|
|
6
|
+
export class SimulationPipeline {
|
|
7
|
+
executionEngine;
|
|
8
|
+
constructor(executionEngine) {
|
|
9
|
+
this.executionEngine = executionEngine;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create and schedule a simulation task
|
|
13
|
+
*/
|
|
14
|
+
async createSimulation(config) {
|
|
15
|
+
const taskId = `sim_${randomUUID()}`;
|
|
16
|
+
const goal = {
|
|
17
|
+
id: `goal_${taskId}`,
|
|
18
|
+
title: `${config.type} Simulation`,
|
|
19
|
+
description: `Run ${config.type} simulation with specified parameters`,
|
|
20
|
+
priority: 'medium',
|
|
21
|
+
constraints: {
|
|
22
|
+
requiredRegions: config.regionId ? [config.regionId] : undefined,
|
|
23
|
+
},
|
|
24
|
+
metadata: {
|
|
25
|
+
simulationType: config.type,
|
|
26
|
+
parameters: config.parameters,
|
|
27
|
+
duration: config.duration,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const task = {
|
|
31
|
+
id: taskId,
|
|
32
|
+
goalId: goal.id,
|
|
33
|
+
runId: `run_${randomUUID()}`,
|
|
34
|
+
type: 'simulation',
|
|
35
|
+
payload: {
|
|
36
|
+
config,
|
|
37
|
+
},
|
|
38
|
+
dependencies: [],
|
|
39
|
+
constraints: {
|
|
40
|
+
preferredRegion: config.regionId,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
await this.executionEngine.scheduleTask(task);
|
|
44
|
+
return taskId;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Run multiple simulations in parallel
|
|
48
|
+
*/
|
|
49
|
+
async runSimulationBatch(configs) {
|
|
50
|
+
const taskIds = [];
|
|
51
|
+
for (const config of configs) {
|
|
52
|
+
const taskId = await this.createSimulation(config);
|
|
53
|
+
taskIds.push(taskId);
|
|
54
|
+
}
|
|
55
|
+
return taskIds;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experimentation Engine for BASETREE V6
|
|
3
|
+
* Landing page generation, A/B testing, pricing experiments, feature gates
|
|
4
|
+
*/
|
|
5
|
+
import { getKernel } from '../kernel/kernel.js';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
export class ExperimentationEngine {
|
|
8
|
+
kernel = getKernel();
|
|
9
|
+
async createLandingPageExperiment(venture, variants) {
|
|
10
|
+
const experimentId = `exp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
11
|
+
const venturePath = join('ventures', venture.slug, 'landing');
|
|
12
|
+
const experimentVariants = variants.map((variant, index) => ({
|
|
13
|
+
id: `variant_${index}`,
|
|
14
|
+
name: variant,
|
|
15
|
+
description: `Landing page variant: ${variant}`,
|
|
16
|
+
trafficShare: 1 / variants.length,
|
|
17
|
+
metrics: {
|
|
18
|
+
visitors: 0,
|
|
19
|
+
signups: 0,
|
|
20
|
+
conversions: 0,
|
|
21
|
+
revenue: 0,
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
24
|
+
const experiment = {
|
|
25
|
+
id: experimentId,
|
|
26
|
+
ventureId: venture.id,
|
|
27
|
+
type: 'landing_page',
|
|
28
|
+
hypothesis: `Testing ${variants.length} landing page variants to optimize conversion`,
|
|
29
|
+
variants: experimentVariants,
|
|
30
|
+
createdAt: new Date(),
|
|
31
|
+
status: 'pending',
|
|
32
|
+
};
|
|
33
|
+
await this.kernel.getStateStore().saveExperiment(experiment);
|
|
34
|
+
return experiment;
|
|
35
|
+
}
|
|
36
|
+
async runABTest(experimentId) {
|
|
37
|
+
const experiment = await this.kernel.getStateStore().getExperiment(experimentId);
|
|
38
|
+
if (!experiment || experiment.status !== 'completed') {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
// Find variant with best conversion rate
|
|
42
|
+
let bestVariant = experiment.variants[0];
|
|
43
|
+
let bestScore = 0;
|
|
44
|
+
for (const variant of experiment.variants) {
|
|
45
|
+
const conversionRate = variant.metrics.visitors > 0
|
|
46
|
+
? variant.metrics.conversions / variant.metrics.visitors
|
|
47
|
+
: 0;
|
|
48
|
+
const revenuePerVisitor = variant.metrics.visitors > 0
|
|
49
|
+
? variant.metrics.revenue / variant.metrics.visitors
|
|
50
|
+
: 0;
|
|
51
|
+
// Combined score: conversion rate * 0.6 + revenue per visitor normalized * 0.4
|
|
52
|
+
const score = conversionRate * 0.6 + Math.min(revenuePerVisitor / 100, 1) * 0.4;
|
|
53
|
+
if (score > bestScore) {
|
|
54
|
+
bestScore = score;
|
|
55
|
+
bestVariant = variant;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return bestVariant;
|
|
59
|
+
}
|
|
60
|
+
async createPricingExperiment(venture, prices) {
|
|
61
|
+
const experimentId = `exp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
62
|
+
const variants = prices.map((price, index) => ({
|
|
63
|
+
id: `price_${index}`,
|
|
64
|
+
name: `$${price}/month`,
|
|
65
|
+
description: `Pricing tier at $${price} per month`,
|
|
66
|
+
trafficShare: 1 / prices.length,
|
|
67
|
+
metrics: {
|
|
68
|
+
visitors: 0,
|
|
69
|
+
signups: 0,
|
|
70
|
+
conversions: 0,
|
|
71
|
+
revenue: 0,
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
const experiment = {
|
|
75
|
+
id: experimentId,
|
|
76
|
+
ventureId: venture.id,
|
|
77
|
+
type: 'pricing',
|
|
78
|
+
hypothesis: `Testing price points $${prices.join(', $')} to determine optimal pricing`,
|
|
79
|
+
variants,
|
|
80
|
+
createdAt: new Date(),
|
|
81
|
+
status: 'pending',
|
|
82
|
+
};
|
|
83
|
+
await this.kernel.getStateStore().saveExperiment(experiment);
|
|
84
|
+
return experiment;
|
|
85
|
+
}
|
|
86
|
+
async trackExperimentMetrics(experimentId, variantId, event, value) {
|
|
87
|
+
const experiment = await this.kernel.getStateStore().getExperiment(experimentId);
|
|
88
|
+
if (!experiment) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const variant = experiment.variants.find((v) => v.id === variantId);
|
|
92
|
+
if (!variant) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Update metrics based on event
|
|
96
|
+
switch (event) {
|
|
97
|
+
case 'page_view':
|
|
98
|
+
variant.metrics.visitors++;
|
|
99
|
+
break;
|
|
100
|
+
case 'signup':
|
|
101
|
+
variant.metrics.signups++;
|
|
102
|
+
break;
|
|
103
|
+
case 'conversion':
|
|
104
|
+
variant.metrics.conversions++;
|
|
105
|
+
break;
|
|
106
|
+
case 'revenue':
|
|
107
|
+
variant.metrics.revenue += value || 0;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
// Update experiment status if needed
|
|
111
|
+
if (experiment.status === 'pending' && variant.metrics.visitors > 0) {
|
|
112
|
+
experiment.status = 'running';
|
|
113
|
+
}
|
|
114
|
+
await this.kernel.getStateStore().updateExperiment(experimentId, {
|
|
115
|
+
variants: experiment.variants,
|
|
116
|
+
status: experiment.status,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async completeExperiment(experimentId) {
|
|
120
|
+
const experiment = await this.kernel.getStateStore().getExperiment(experimentId);
|
|
121
|
+
if (!experiment) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const winner = await this.runABTest(experimentId);
|
|
125
|
+
const resultSummary = winner
|
|
126
|
+
? `Winner: ${winner.name} with ${((winner.metrics.conversions / Math.max(winner.metrics.visitors, 1)) * 100).toFixed(2)}% conversion rate`
|
|
127
|
+
: 'No clear winner';
|
|
128
|
+
await this.kernel.getStateStore().updateExperiment(experimentId, {
|
|
129
|
+
status: 'completed',
|
|
130
|
+
completedAt: new Date(),
|
|
131
|
+
resultSummary,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async createFeatureGateExperiment(venture, feature, userSegments) {
|
|
135
|
+
const experimentId = `exp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
136
|
+
const variants = [
|
|
137
|
+
{
|
|
138
|
+
id: 'enabled',
|
|
139
|
+
name: 'Feature Enabled',
|
|
140
|
+
description: `${feature} enabled for all users`,
|
|
141
|
+
trafficShare: 0.5,
|
|
142
|
+
metrics: {
|
|
143
|
+
visitors: 0,
|
|
144
|
+
signups: 0,
|
|
145
|
+
conversions: 0,
|
|
146
|
+
revenue: 0,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: 'disabled',
|
|
151
|
+
name: 'Feature Disabled',
|
|
152
|
+
description: `${feature} disabled (control)`,
|
|
153
|
+
trafficShare: 0.5,
|
|
154
|
+
metrics: {
|
|
155
|
+
visitors: 0,
|
|
156
|
+
signups: 0,
|
|
157
|
+
conversions: 0,
|
|
158
|
+
revenue: 0,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
const experiment = {
|
|
163
|
+
id: experimentId,
|
|
164
|
+
ventureId: venture.id,
|
|
165
|
+
type: 'feature_gate',
|
|
166
|
+
hypothesis: `Testing impact of ${feature} on user engagement and conversion`,
|
|
167
|
+
variants,
|
|
168
|
+
createdAt: new Date(),
|
|
169
|
+
status: 'pending',
|
|
170
|
+
};
|
|
171
|
+
await this.kernel.getStateStore().saveExperiment(experiment);
|
|
172
|
+
return experiment;
|
|
173
|
+
}
|
|
174
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import gradient from "gradient-string";
|
|
6
|
+
import { GeminiProvider } from "./core/ai/GeminiProvider.js";
|
|
7
|
+
import { LearningMemoryAgent } from "./core/agent/LearningMemoryAgent.js";
|
|
8
|
+
import { AdaptivePlanner } from "./core/agent/AdaptivePlanner.js";
|
|
9
|
+
import { MetaCognitionAgent } from "./core/agent/MetaCognitionAgent.js";
|
|
10
|
+
import { PerformanceMonitor } from "./core/monitor/PerformanceMonitor.js";
|
|
11
|
+
import { SwarmOrchestrator } from "./core/swarm/SwarmOrchestrator.js";
|
|
12
|
+
import { ReasoningBus } from "./core/swarm/ReasoningBus.js";
|
|
13
|
+
import dotenv from "dotenv";
|
|
14
|
+
import { setupCLI as setupV5CLI } from "./cli.js";
|
|
15
|
+
dotenv.config();
|
|
16
|
+
const performance = new PerformanceMonitor();
|
|
17
|
+
const bus = ReasoningBus.getInstance();
|
|
18
|
+
// Subscribe to global reasoning bus for swarm telemetry
|
|
19
|
+
bus.subscribe((event) => {
|
|
20
|
+
const icon = event.type === "error" ? "❌" : event.type === "result" ? "✅" : "💡";
|
|
21
|
+
console.log(chalk.dim(` ${icon} [${event.role}] ${event.content}`));
|
|
22
|
+
});
|
|
23
|
+
const BASETREE_ASCII = `
|
|
24
|
+
██████╗ █████╗ ███████╗███████╗████████╗██████╗ ███████╗███████╗
|
|
25
|
+
██╔══██╗██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔════╝██╔════╝
|
|
26
|
+
██████╔╝███████║███████╗█████╗ ██║ ██████╔╝█████╗ █████╗
|
|
27
|
+
██╔══██╗██╔══██║╚════██║██╔══╝ ██║ ██╔══██╗██╔══╝ ██╔══╝
|
|
28
|
+
██████╔╝██║ ██║███████║███████╗ ██║ ██║ ██║███████╗███████╗
|
|
29
|
+
╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝
|
|
30
|
+
`;
|
|
31
|
+
// V5/V6/V7 CLI (core commands)
|
|
32
|
+
const program = setupV5CLI();
|
|
33
|
+
// V4 chat command
|
|
34
|
+
program
|
|
35
|
+
.command("chat")
|
|
36
|
+
.description("Start interactive session (V4)")
|
|
37
|
+
.action(async () => {
|
|
38
|
+
console.clear();
|
|
39
|
+
console.log(gradient.pastel.multiline(BASETREE_ASCII));
|
|
40
|
+
const ai = new GeminiProvider();
|
|
41
|
+
const memory = new LearningMemoryAgent(ai);
|
|
42
|
+
const planner = new AdaptivePlanner(ai, memory);
|
|
43
|
+
const orchestrator = new SwarmOrchestrator(ai, memory);
|
|
44
|
+
const meta = new MetaCognitionAgent(ai, memory);
|
|
45
|
+
while (true) {
|
|
46
|
+
const response = await prompts({
|
|
47
|
+
type: 'text',
|
|
48
|
+
name: 'value',
|
|
49
|
+
message: gradient.passion('➜ '),
|
|
50
|
+
});
|
|
51
|
+
if (!response.value)
|
|
52
|
+
break;
|
|
53
|
+
await runAutonomousEngine(response.value, ai, memory, planner, orchestrator, meta);
|
|
54
|
+
}
|
|
55
|
+
console.log(chalk.gray(performance.getSummary()));
|
|
56
|
+
});
|
|
57
|
+
async function runAutonomousEngine(input, ai, memory, planner, orchestrator, meta) {
|
|
58
|
+
const spinner = ora(chalk.blue("Swarm Strategy Planning...")).start();
|
|
59
|
+
const paths = await planner.createAdaptivePlan(input);
|
|
60
|
+
const bestPath = planner.selectBestPath(paths);
|
|
61
|
+
spinner.succeed(chalk.green(`Swarm Route Selected: ${bestPath.id} (Risk: ${bestPath.riskScore})`));
|
|
62
|
+
// Execute plan via swarm orchestrator
|
|
63
|
+
await orchestrator.executePlanParallel(bestPath.steps);
|
|
64
|
+
// Meta-cognition loop
|
|
65
|
+
await meta.critique(input, "Success", []);
|
|
66
|
+
}
|
|
67
|
+
program.parse();
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Bus for BASETREE V5
|
|
3
|
+
* Typed event bus for system events
|
|
4
|
+
*/
|
|
5
|
+
class EventBus {
|
|
6
|
+
handlers = new Map();
|
|
7
|
+
eventHistory = [];
|
|
8
|
+
maxHistorySize = 1000;
|
|
9
|
+
subscribe(eventType, handler) {
|
|
10
|
+
if (!this.handlers.has(eventType)) {
|
|
11
|
+
this.handlers.set(eventType, new Set());
|
|
12
|
+
}
|
|
13
|
+
this.handlers.get(eventType).add(handler);
|
|
14
|
+
// Return unsubscribe function
|
|
15
|
+
return () => {
|
|
16
|
+
const handlers = this.handlers.get(eventType);
|
|
17
|
+
if (handlers) {
|
|
18
|
+
handlers.delete(handler);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
subscribeAll(handler) {
|
|
23
|
+
const unsubscribers = [];
|
|
24
|
+
const eventTypes = [
|
|
25
|
+
'IntrospectionCompleted',
|
|
26
|
+
'ProposalCreated',
|
|
27
|
+
'ProposalUpdated',
|
|
28
|
+
'GovernanceDecision',
|
|
29
|
+
'UpgradeStarted',
|
|
30
|
+
'UpgradeApplied',
|
|
31
|
+
'UpgradeFailed',
|
|
32
|
+
'RegressionStarted',
|
|
33
|
+
'RegressionCompleted',
|
|
34
|
+
'RegressionFailed',
|
|
35
|
+
'RollbackTriggered',
|
|
36
|
+
'RollbackCompleted',
|
|
37
|
+
'MetricRecorded',
|
|
38
|
+
'SnapshotCreated',
|
|
39
|
+
'AgentRegistered',
|
|
40
|
+
'AgentUnregistered',
|
|
41
|
+
];
|
|
42
|
+
for (const eventType of eventTypes) {
|
|
43
|
+
const unsubscribe = this.subscribe(eventType, handler);
|
|
44
|
+
unsubscribers.push(unsubscribe);
|
|
45
|
+
}
|
|
46
|
+
return () => {
|
|
47
|
+
unsubscribers.forEach((unsub) => unsub());
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async emit(event) {
|
|
51
|
+
// Add to history
|
|
52
|
+
this.eventHistory.push(event);
|
|
53
|
+
if (this.eventHistory.length > this.maxHistorySize) {
|
|
54
|
+
this.eventHistory.shift();
|
|
55
|
+
}
|
|
56
|
+
// Notify handlers
|
|
57
|
+
const handlers = this.handlers.get(event.type);
|
|
58
|
+
if (handlers) {
|
|
59
|
+
const promises = Array.from(handlers).map((handler) => {
|
|
60
|
+
try {
|
|
61
|
+
return Promise.resolve(handler(event));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(`Error in event handler for ${event.type}:`, error);
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
await Promise.all(promises);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getHistory(eventType) {
|
|
72
|
+
if (eventType) {
|
|
73
|
+
return this.eventHistory.filter((e) => e.type === eventType);
|
|
74
|
+
}
|
|
75
|
+
return [...this.eventHistory];
|
|
76
|
+
}
|
|
77
|
+
clearHistory() {
|
|
78
|
+
this.eventHistory = [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Singleton instance
|
|
82
|
+
let eventBusInstance = null;
|
|
83
|
+
export function getEventBus() {
|
|
84
|
+
if (!eventBusInstance) {
|
|
85
|
+
eventBusInstance = new EventBus();
|
|
86
|
+
}
|
|
87
|
+
return eventBusInstance;
|
|
88
|
+
}
|
|
89
|
+
export { EventBus };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Kernel for BASETREE V5
|
|
3
|
+
* Immutable core kernel exposing stable API for agents, pipelines, events, and state
|
|
4
|
+
*/
|
|
5
|
+
import { getEventBus } from './eventBus.js';
|
|
6
|
+
import { FileStateStore } from '../state/fileStateStore.js';
|
|
7
|
+
import { getConfig } from '../config/config.js';
|
|
8
|
+
export class Kernel {
|
|
9
|
+
agents = new Map();
|
|
10
|
+
pipelines = new Map();
|
|
11
|
+
stateStore;
|
|
12
|
+
eventBus = getEventBus();
|
|
13
|
+
config = getConfig();
|
|
14
|
+
initialized = false;
|
|
15
|
+
upgradeTransaction = { active: false };
|
|
16
|
+
constructor(stateStore) {
|
|
17
|
+
this.stateStore = stateStore || new FileStateStore();
|
|
18
|
+
}
|
|
19
|
+
async initialize() {
|
|
20
|
+
if (this.initialized) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Initialize state store if needed
|
|
24
|
+
// Register core event handlers
|
|
25
|
+
this.eventBus.subscribe('AgentRegistered', (event) => {
|
|
26
|
+
console.log(`[Kernel] Agent registered: ${event.agentId}`);
|
|
27
|
+
});
|
|
28
|
+
this.initialized = true;
|
|
29
|
+
}
|
|
30
|
+
async shutdown() {
|
|
31
|
+
// Shutdown all agents
|
|
32
|
+
for (const agent of this.agents.values()) {
|
|
33
|
+
if (agent.shutdown) {
|
|
34
|
+
try {
|
|
35
|
+
await agent.shutdown();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Error shutting down agent ${agent.id}:`, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.agents.clear();
|
|
43
|
+
this.pipelines.clear();
|
|
44
|
+
this.initialized = false;
|
|
45
|
+
}
|
|
46
|
+
// Agent registration
|
|
47
|
+
registerAgent(agent) {
|
|
48
|
+
if (this.agents.has(agent.id)) {
|
|
49
|
+
throw new Error(`Agent ${agent.id} is already registered`);
|
|
50
|
+
}
|
|
51
|
+
this.agents.set(agent.id, agent);
|
|
52
|
+
this.eventBus.emit({
|
|
53
|
+
type: 'AgentRegistered',
|
|
54
|
+
timestamp: new Date(),
|
|
55
|
+
agentId: agent.id,
|
|
56
|
+
});
|
|
57
|
+
// Initialize agent if kernel is already initialized
|
|
58
|
+
if (this.initialized && agent.initialize) {
|
|
59
|
+
agent.initialize().catch((error) => {
|
|
60
|
+
console.error(`Failed to initialize agent ${agent.id}:`, error);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
unregisterAgent(agentId) {
|
|
65
|
+
const agent = this.agents.get(agentId);
|
|
66
|
+
if (agent) {
|
|
67
|
+
if (agent.shutdown) {
|
|
68
|
+
agent.shutdown().catch((error) => {
|
|
69
|
+
console.error(`Error shutting down agent ${agentId}:`, error);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
this.agents.delete(agentId);
|
|
73
|
+
this.eventBus.emit({
|
|
74
|
+
type: 'AgentUnregistered',
|
|
75
|
+
timestamp: new Date(),
|
|
76
|
+
agentId,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
getAgent(agentId) {
|
|
81
|
+
return this.agents.get(agentId);
|
|
82
|
+
}
|
|
83
|
+
listAgents() {
|
|
84
|
+
return Array.from(this.agents.values());
|
|
85
|
+
}
|
|
86
|
+
// Pipeline registration
|
|
87
|
+
registerPipeline(pipeline) {
|
|
88
|
+
if (this.pipelines.has(pipeline.id)) {
|
|
89
|
+
throw new Error(`Pipeline ${pipeline.id} is already registered`);
|
|
90
|
+
}
|
|
91
|
+
this.pipelines.set(pipeline.id, pipeline);
|
|
92
|
+
}
|
|
93
|
+
getPipeline(id) {
|
|
94
|
+
return this.pipelines.get(id);
|
|
95
|
+
}
|
|
96
|
+
listPipelines() {
|
|
97
|
+
return Array.from(this.pipelines.values());
|
|
98
|
+
}
|
|
99
|
+
// State store access
|
|
100
|
+
getStateStore() {
|
|
101
|
+
return this.stateStore;
|
|
102
|
+
}
|
|
103
|
+
// Event bus access
|
|
104
|
+
getEventBus() {
|
|
105
|
+
return this.eventBus;
|
|
106
|
+
}
|
|
107
|
+
// Config access
|
|
108
|
+
getConfig() {
|
|
109
|
+
return this.config;
|
|
110
|
+
}
|
|
111
|
+
// Upgrade transaction management
|
|
112
|
+
beginUpgradeTransaction(proposalId, snapshotId) {
|
|
113
|
+
if (this.upgradeTransaction.active) {
|
|
114
|
+
throw new Error('Upgrade transaction already active');
|
|
115
|
+
}
|
|
116
|
+
this.upgradeTransaction = {
|
|
117
|
+
active: true,
|
|
118
|
+
proposalId,
|
|
119
|
+
snapshotId,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
endUpgradeTransaction() {
|
|
123
|
+
this.upgradeTransaction = { active: false };
|
|
124
|
+
}
|
|
125
|
+
getUpgradeTransaction() {
|
|
126
|
+
return { ...this.upgradeTransaction };
|
|
127
|
+
}
|
|
128
|
+
// Protected kernel check - used by kernel guard
|
|
129
|
+
isKernelProtectedPath(filePath) {
|
|
130
|
+
const relativePath = filePath.replace(this.config.workspaceRoot, '').replace(/^[/\\]/, '');
|
|
131
|
+
return this.config.safety.protectedPaths.some((protectedPath) => {
|
|
132
|
+
return relativePath.startsWith(protectedPath);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Singleton instance
|
|
137
|
+
let kernelInstance = null;
|
|
138
|
+
export function getKernel() {
|
|
139
|
+
if (!kernelInstance) {
|
|
140
|
+
kernelInstance = new Kernel();
|
|
141
|
+
}
|
|
142
|
+
return kernelInstance;
|
|
143
|
+
}
|
|
144
|
+
export function resetKernel() {
|
|
145
|
+
kernelInstance = null;
|
|
146
|
+
}
|