genesis-ai-cli 7.4.5
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 +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- package/package.json +60 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.0 - Epistemic Stack
|
|
4
|
+
*
|
|
5
|
+
* Complete knowledge architecture:
|
|
6
|
+
* - Science: factual/empirical claims
|
|
7
|
+
* - Proof: mathematical/logical claims
|
|
8
|
+
* - Wisdom: practical knowledge beyond science
|
|
9
|
+
* - Religion/Tradition: meaning and moral absolutes
|
|
10
|
+
* - Human: preferences and final authority
|
|
11
|
+
* - Prudence: acting under irreducible uncertainty
|
|
12
|
+
*
|
|
13
|
+
* "La verità la tiene la scienza, dove non arriva la scienza
|
|
14
|
+
* arriva la religione e la saggezza"
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.EpistemicStack = exports.TRADITION_REPOSITORY = exports.WISDOM_REPOSITORY = void 0;
|
|
18
|
+
exports.classifyDomain = classifyDomain;
|
|
19
|
+
exports.getAuthority = getAuthority;
|
|
20
|
+
exports.createEpistemicStack = createEpistemicStack;
|
|
21
|
+
exports.getEpistemicStack = getEpistemicStack;
|
|
22
|
+
exports.resetEpistemicStack = resetEpistemicStack;
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Domain Classifier
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Domain patterns in priority order (more specific first to avoid false matches)
|
|
27
|
+
// e.g., "what is the meaning" should match existential, not factual's "what is"
|
|
28
|
+
const DOMAIN_PATTERN_LIST = [
|
|
29
|
+
// Most specific first
|
|
30
|
+
['existential', [
|
|
31
|
+
/what is the meaning/i, /why am I/i, /\bpurpose\b/i,
|
|
32
|
+
/what is the point/i, /does it matter/i,
|
|
33
|
+
/significance/i, /why bother/i, /meaning of life/i,
|
|
34
|
+
]],
|
|
35
|
+
['mathematical', [
|
|
36
|
+
/prove that/i, /is it provable/i, /\bcalculate\b/i,
|
|
37
|
+
/what is the formula/i, /\bsolve\b/i, /\bderive\b/i,
|
|
38
|
+
/is it consistent/i, /follows from/i, /theorem/i,
|
|
39
|
+
]],
|
|
40
|
+
['ethical', [
|
|
41
|
+
/should I/i, /is it right to/i, /is it wrong to/i,
|
|
42
|
+
/what is the ethical/i, /\bmoral\b/i, /\bought\b/i,
|
|
43
|
+
/is it permissible/i, /\bduty\b/i, /obligation/i,
|
|
44
|
+
]],
|
|
45
|
+
['aesthetic', [
|
|
46
|
+
/is it beautiful/i, /is it good \(art\)/i, /\btaste\b/i,
|
|
47
|
+
/\bprefer\b/i, /like better/i, /\bstyle\b/i,
|
|
48
|
+
]],
|
|
49
|
+
['novel', [
|
|
50
|
+
/never been done/i, /unprecedented/i, /new situation/i,
|
|
51
|
+
/no data on/i, /first time/i, /no precedent/i,
|
|
52
|
+
]],
|
|
53
|
+
// Factual is last (catch-all for empirical questions)
|
|
54
|
+
['factual', [
|
|
55
|
+
/what is\b/i, /how does/i, /why does/i, /when did/i,
|
|
56
|
+
/is it true that/i, /what causes/i, /how many/i,
|
|
57
|
+
/does .* exist/i, /what are the effects/i,
|
|
58
|
+
]],
|
|
59
|
+
];
|
|
60
|
+
function classifyDomain(question) {
|
|
61
|
+
for (const [domain, patterns] of DOMAIN_PATTERN_LIST) {
|
|
62
|
+
for (const pattern of patterns) {
|
|
63
|
+
if (pattern.test(question)) {
|
|
64
|
+
return domain;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Default to factual, science will determine if it can answer
|
|
69
|
+
return 'factual';
|
|
70
|
+
}
|
|
71
|
+
function getAuthority(domain) {
|
|
72
|
+
switch (domain) {
|
|
73
|
+
case 'factual':
|
|
74
|
+
return ['science'];
|
|
75
|
+
case 'mathematical':
|
|
76
|
+
return ['proof'];
|
|
77
|
+
case 'ethical':
|
|
78
|
+
return ['wisdom', 'human'];
|
|
79
|
+
case 'existential':
|
|
80
|
+
return ['religion', 'human'];
|
|
81
|
+
case 'aesthetic':
|
|
82
|
+
return ['human'];
|
|
83
|
+
case 'novel':
|
|
84
|
+
return ['prudence', 'human'];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// Wisdom Repository
|
|
89
|
+
// ============================================================================
|
|
90
|
+
exports.WISDOM_REPOSITORY = [
|
|
91
|
+
// Prudence
|
|
92
|
+
{
|
|
93
|
+
type: 'heuristic',
|
|
94
|
+
content: 'When in doubt, do not act - unless inaction is worse',
|
|
95
|
+
origin: 'Stoicism',
|
|
96
|
+
applicability: 0.9,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: 'heuristic',
|
|
100
|
+
content: 'Prefer reversible actions over irreversible ones',
|
|
101
|
+
origin: 'Rational Decision Theory',
|
|
102
|
+
applicability: 0.95,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'heuristic',
|
|
106
|
+
content: 'Via Negativa: removing bad is more reliable than adding good',
|
|
107
|
+
origin: 'Nassim Taleb / Apophatic Theology',
|
|
108
|
+
applicability: 0.8,
|
|
109
|
+
},
|
|
110
|
+
// Humility
|
|
111
|
+
{
|
|
112
|
+
type: 'proverb',
|
|
113
|
+
content: 'The more you know, the more you know you don\'t know',
|
|
114
|
+
origin: 'Socratic philosophy',
|
|
115
|
+
applicability: 0.85,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
type: 'heuristic',
|
|
119
|
+
content: 'Strong opinions, loosely held',
|
|
120
|
+
origin: 'Paul Saffo',
|
|
121
|
+
applicability: 0.75,
|
|
122
|
+
},
|
|
123
|
+
// Balance
|
|
124
|
+
{
|
|
125
|
+
type: 'framework',
|
|
126
|
+
content: 'The Middle Way: avoid extremes',
|
|
127
|
+
origin: 'Buddhism / Aristotle',
|
|
128
|
+
applicability: 0.9,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: 'proverb',
|
|
132
|
+
content: 'Chi va piano va sano e va lontano',
|
|
133
|
+
origin: 'Italian wisdom',
|
|
134
|
+
applicability: 0.7,
|
|
135
|
+
},
|
|
136
|
+
// Action
|
|
137
|
+
{
|
|
138
|
+
type: 'heuristic',
|
|
139
|
+
content: 'Perfect is the enemy of good',
|
|
140
|
+
origin: 'Voltaire',
|
|
141
|
+
applicability: 0.8,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: 'heuristic',
|
|
145
|
+
content: 'Skin in the game: don\'t give advice you wouldn\'t follow',
|
|
146
|
+
origin: 'Nassim Taleb',
|
|
147
|
+
applicability: 0.9,
|
|
148
|
+
},
|
|
149
|
+
// Systems Thinking
|
|
150
|
+
{
|
|
151
|
+
type: 'heuristic',
|
|
152
|
+
content: 'Lindy Effect: the old has survived for a reason',
|
|
153
|
+
origin: 'Statistical wisdom',
|
|
154
|
+
applicability: 0.75,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
type: 'heuristic',
|
|
158
|
+
content: 'Second-order effects matter more than first-order',
|
|
159
|
+
origin: 'Systems thinking',
|
|
160
|
+
applicability: 0.85,
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
// ============================================================================
|
|
164
|
+
// Tradition Repository
|
|
165
|
+
// ============================================================================
|
|
166
|
+
exports.TRADITION_REPOSITORY = [
|
|
167
|
+
// Universal Moral Absolutes (cross-tradition)
|
|
168
|
+
{
|
|
169
|
+
type: 'moral_absolute',
|
|
170
|
+
tradition: 'Universal',
|
|
171
|
+
content: 'Do not kill innocent people',
|
|
172
|
+
universality: 0.99,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: 'moral_absolute',
|
|
176
|
+
tradition: 'Universal',
|
|
177
|
+
content: 'Do not deceive for personal gain',
|
|
178
|
+
universality: 0.95,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
type: 'moral_absolute',
|
|
182
|
+
tradition: 'Universal',
|
|
183
|
+
content: 'Protect those who cannot protect themselves',
|
|
184
|
+
universality: 0.9,
|
|
185
|
+
},
|
|
186
|
+
// Meaning Frameworks
|
|
187
|
+
{
|
|
188
|
+
type: 'meaning_framework',
|
|
189
|
+
tradition: 'Stoicism',
|
|
190
|
+
content: 'Focus on what you can control, accept what you cannot',
|
|
191
|
+
universality: 0.8,
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
type: 'meaning_framework',
|
|
195
|
+
tradition: 'Buddhism',
|
|
196
|
+
content: 'Suffering comes from attachment; liberation from letting go',
|
|
197
|
+
universality: 0.7,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
type: 'meaning_framework',
|
|
201
|
+
tradition: 'Existentialism',
|
|
202
|
+
content: 'Meaning is not found but created through authentic choice',
|
|
203
|
+
universality: 0.6,
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: 'meaning_framework',
|
|
207
|
+
tradition: 'Christianity',
|
|
208
|
+
content: 'Purpose comes from relationship with the transcendent and love of neighbor',
|
|
209
|
+
universality: 0.5,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
type: 'meaning_framework',
|
|
213
|
+
tradition: 'Secular Humanism',
|
|
214
|
+
content: 'Human flourishing and reducing suffering give meaning',
|
|
215
|
+
universality: 0.7,
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
// ============================================================================
|
|
219
|
+
// Epistemic Stack Class
|
|
220
|
+
// ============================================================================
|
|
221
|
+
class EpistemicStack {
|
|
222
|
+
scienceGrounder;
|
|
223
|
+
proofChecker;
|
|
224
|
+
/**
|
|
225
|
+
* Set the science grounding function (connects to MCP servers)
|
|
226
|
+
*/
|
|
227
|
+
setScienceGrounder(fn) {
|
|
228
|
+
this.scienceGrounder = fn;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Set the proof checking function (connects to Wolfram, type checkers)
|
|
232
|
+
*/
|
|
233
|
+
setProofChecker(fn) {
|
|
234
|
+
this.proofChecker = fn;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Ground a claim using the full epistemic stack
|
|
238
|
+
*/
|
|
239
|
+
async ground(claim) {
|
|
240
|
+
const domain = classifyDomain(claim);
|
|
241
|
+
const authorities = getAuthority(domain);
|
|
242
|
+
let grounding = {
|
|
243
|
+
sources: [],
|
|
244
|
+
consensusLevel: 'unknown',
|
|
245
|
+
};
|
|
246
|
+
let level = 'unknown';
|
|
247
|
+
let confidence = 0;
|
|
248
|
+
// Route to appropriate authority
|
|
249
|
+
for (const authority of authorities) {
|
|
250
|
+
switch (authority) {
|
|
251
|
+
case 'science':
|
|
252
|
+
if (this.scienceGrounder) {
|
|
253
|
+
grounding = await this.scienceGrounder(claim);
|
|
254
|
+
level = grounding.sources.length > 2 ? 'verified' :
|
|
255
|
+
grounding.sources.length > 0 ? 'supported' : 'hypothesis';
|
|
256
|
+
confidence = this.calculateConfidence(grounding);
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case 'proof':
|
|
260
|
+
if (this.proofChecker) {
|
|
261
|
+
grounding = await this.proofChecker(claim);
|
|
262
|
+
level = grounding.sources.some(s => s.type === 'proof') ? 'verified' : 'hypothesis';
|
|
263
|
+
confidence = level === 'verified' ? 1.0 : 0.3;
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
case 'wisdom':
|
|
267
|
+
grounding.wisdomSources = this.findRelevantWisdom(claim);
|
|
268
|
+
level = 'wisdom';
|
|
269
|
+
confidence = grounding.wisdomSources.length > 0 ? 0.7 : 0.3;
|
|
270
|
+
break;
|
|
271
|
+
case 'religion':
|
|
272
|
+
grounding.traditionSources = this.findRelevantTradition(claim);
|
|
273
|
+
level = 'tradition';
|
|
274
|
+
confidence = this.calculateTraditionConfidence(grounding.traditionSources);
|
|
275
|
+
break;
|
|
276
|
+
case 'human':
|
|
277
|
+
grounding.humanConsultation = {
|
|
278
|
+
required: true,
|
|
279
|
+
reason: `Domain '${domain}' requires human judgment`,
|
|
280
|
+
question: this.generateHumanQuestion(claim, domain),
|
|
281
|
+
};
|
|
282
|
+
level = 'preference';
|
|
283
|
+
confidence = 0; // Until human responds
|
|
284
|
+
break;
|
|
285
|
+
case 'prudence':
|
|
286
|
+
grounding.wisdomSources = this.findPrudentialWisdom(claim);
|
|
287
|
+
level = 'hypothesis';
|
|
288
|
+
confidence = 0.5;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
content: claim,
|
|
294
|
+
domain,
|
|
295
|
+
authority: authorities[0],
|
|
296
|
+
level,
|
|
297
|
+
confidence,
|
|
298
|
+
grounding,
|
|
299
|
+
timestamp: new Date(),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Check if a claim requires human consultation
|
|
304
|
+
*/
|
|
305
|
+
requiresHuman(claim) {
|
|
306
|
+
return claim.grounding.humanConsultation?.required ?? false;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get the question to ask the human
|
|
310
|
+
*/
|
|
311
|
+
getHumanQuestion(claim) {
|
|
312
|
+
return claim.grounding.humanConsultation?.question;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Update claim with human response
|
|
316
|
+
*/
|
|
317
|
+
incorporateHumanResponse(claim, response) {
|
|
318
|
+
if (claim.grounding.humanConsultation) {
|
|
319
|
+
claim.grounding.humanConsultation.response = response;
|
|
320
|
+
claim.grounding.humanConsultation.timestamp = new Date();
|
|
321
|
+
claim.confidence = 0.9; // Human has spoken
|
|
322
|
+
claim.level = 'preference';
|
|
323
|
+
}
|
|
324
|
+
return claim;
|
|
325
|
+
}
|
|
326
|
+
// ============================================================================
|
|
327
|
+
// Helpers
|
|
328
|
+
// ============================================================================
|
|
329
|
+
findRelevantWisdom(claim) {
|
|
330
|
+
const claimLower = claim.toLowerCase();
|
|
331
|
+
return exports.WISDOM_REPOSITORY.filter(w => {
|
|
332
|
+
// Simple keyword matching - could be improved with embeddings
|
|
333
|
+
const keywords = w.content.toLowerCase().split(/\s+/);
|
|
334
|
+
return keywords.some(k => claimLower.includes(k));
|
|
335
|
+
}).sort((a, b) => b.applicability - a.applicability);
|
|
336
|
+
}
|
|
337
|
+
findPrudentialWisdom(claim) {
|
|
338
|
+
// For novel situations, return prudential heuristics
|
|
339
|
+
return exports.WISDOM_REPOSITORY.filter(w => w.content.includes('doubt') ||
|
|
340
|
+
w.content.includes('reversible') ||
|
|
341
|
+
w.content.includes('Via Negativa'));
|
|
342
|
+
}
|
|
343
|
+
findRelevantTradition(claim) {
|
|
344
|
+
const claimLower = claim.toLowerCase();
|
|
345
|
+
return exports.TRADITION_REPOSITORY.filter(t => {
|
|
346
|
+
const keywords = t.content.toLowerCase().split(/\s+/);
|
|
347
|
+
return keywords.some(k => claimLower.includes(k));
|
|
348
|
+
}).sort((a, b) => b.universality - a.universality);
|
|
349
|
+
}
|
|
350
|
+
calculateConfidence(grounding) {
|
|
351
|
+
if (grounding.sources.length === 0)
|
|
352
|
+
return 0;
|
|
353
|
+
const avgSourceConfidence = grounding.sources.reduce((sum, s) => sum + s.confidence, 0)
|
|
354
|
+
/ grounding.sources.length;
|
|
355
|
+
const consensusBonus = {
|
|
356
|
+
settled: 0.3,
|
|
357
|
+
emerging: 0.15,
|
|
358
|
+
contested: 0,
|
|
359
|
+
unknown: -0.1,
|
|
360
|
+
}[grounding.consensusLevel];
|
|
361
|
+
const multiModelBonus = grounding.multiModelAgreement
|
|
362
|
+
? (grounding.multiModelAgreement - 0.5) * 0.2
|
|
363
|
+
: 0;
|
|
364
|
+
return Math.min(1, Math.max(0, avgSourceConfidence + consensusBonus + multiModelBonus));
|
|
365
|
+
}
|
|
366
|
+
calculateTraditionConfidence(traditions) {
|
|
367
|
+
if (!traditions || traditions.length === 0)
|
|
368
|
+
return 0.3;
|
|
369
|
+
// Higher confidence if multiple traditions agree
|
|
370
|
+
const avgUniversality = traditions.reduce((sum, t) => sum + t.universality, 0)
|
|
371
|
+
/ traditions.length;
|
|
372
|
+
return avgUniversality;
|
|
373
|
+
}
|
|
374
|
+
generateHumanQuestion(claim, domain) {
|
|
375
|
+
switch (domain) {
|
|
376
|
+
case 'ethical':
|
|
377
|
+
return `Riguardo a "${claim}": qual è la tua posizione etica? Considera le conseguenze e i principi coinvolti.`;
|
|
378
|
+
case 'existential':
|
|
379
|
+
return `Riguardo a "${claim}": che significato ha per te? Qual è il tuo framework di riferimento?`;
|
|
380
|
+
case 'aesthetic':
|
|
381
|
+
return `Riguardo a "${claim}": qual è la tua preferenza? Cosa ti piace di più e perché?`;
|
|
382
|
+
case 'novel':
|
|
383
|
+
return `Situazione nuova: "${claim}". Non ci sono precedenti. Come vorresti procedere? (Nota: preferire azioni reversibili)`;
|
|
384
|
+
default:
|
|
385
|
+
return `Serve il tuo input per: "${claim}"`;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
exports.EpistemicStack = EpistemicStack;
|
|
390
|
+
// ============================================================================
|
|
391
|
+
// Factory
|
|
392
|
+
// ============================================================================
|
|
393
|
+
function createEpistemicStack() {
|
|
394
|
+
return new EpistemicStack();
|
|
395
|
+
}
|
|
396
|
+
// ============================================================================
|
|
397
|
+
// Singleton
|
|
398
|
+
// ============================================================================
|
|
399
|
+
let epistemicStackInstance = null;
|
|
400
|
+
function getEpistemicStack() {
|
|
401
|
+
if (!epistemicStackInstance) {
|
|
402
|
+
epistemicStackInstance = createEpistemicStack();
|
|
403
|
+
}
|
|
404
|
+
return epistemicStackInstance;
|
|
405
|
+
}
|
|
406
|
+
function resetEpistemicStack() {
|
|
407
|
+
epistemicStackInstance = null;
|
|
408
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis Grounding Feedback Loop
|
|
3
|
+
*
|
|
4
|
+
* Iterative verification and fixing pipeline:
|
|
5
|
+
* 1. Generate code
|
|
6
|
+
* 2. Verify (compile, test, semantic)
|
|
7
|
+
* 3. If fails: pass errors to fixer
|
|
8
|
+
* 4. Regenerate with error context
|
|
9
|
+
* 5. Max N iterations
|
|
10
|
+
*/
|
|
11
|
+
import { VerificationContext, CodeVerificationResult } from './verifier.js';
|
|
12
|
+
import { FixResult } from '../healing/fixer.js';
|
|
13
|
+
export interface FeedbackLoopConfig {
|
|
14
|
+
/** Maximum iterations before giving up */
|
|
15
|
+
maxIterations: number;
|
|
16
|
+
/** Stop on first success */
|
|
17
|
+
stopOnSuccess: boolean;
|
|
18
|
+
/** Verification config */
|
|
19
|
+
verificationContext: VerificationContext;
|
|
20
|
+
/** Enable auto-fixing */
|
|
21
|
+
enableAutoFix: boolean;
|
|
22
|
+
/** Log progress */
|
|
23
|
+
verbose: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface IterationResult {
|
|
26
|
+
/** Iteration number (1-based) */
|
|
27
|
+
iteration: number;
|
|
28
|
+
/** Verification result */
|
|
29
|
+
verification: CodeVerificationResult;
|
|
30
|
+
/** Fix result (if attempted) */
|
|
31
|
+
fix?: FixResult;
|
|
32
|
+
/** Duration in ms */
|
|
33
|
+
duration: number;
|
|
34
|
+
/** Was this iteration successful */
|
|
35
|
+
success: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface FeedbackLoopResult {
|
|
38
|
+
/** Overall success */
|
|
39
|
+
success: boolean;
|
|
40
|
+
/** Total iterations performed */
|
|
41
|
+
iterations: number;
|
|
42
|
+
/** Results per iteration */
|
|
43
|
+
history: IterationResult[];
|
|
44
|
+
/** Final verification result */
|
|
45
|
+
finalResult: CodeVerificationResult;
|
|
46
|
+
/** Total duration in ms */
|
|
47
|
+
totalDuration: number;
|
|
48
|
+
/** Summary message */
|
|
49
|
+
summary: string;
|
|
50
|
+
}
|
|
51
|
+
export declare class FeedbackLoop {
|
|
52
|
+
private config;
|
|
53
|
+
private verifier;
|
|
54
|
+
private fixer;
|
|
55
|
+
constructor(config?: Partial<FeedbackLoopConfig>);
|
|
56
|
+
/**
|
|
57
|
+
* Run the feedback loop
|
|
58
|
+
*/
|
|
59
|
+
run(): Promise<FeedbackLoopResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Run verification only (no fixing)
|
|
62
|
+
*/
|
|
63
|
+
verifyOnly(): Promise<CodeVerificationResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Map grounding issue type to error category
|
|
66
|
+
*/
|
|
67
|
+
private mapIssueType;
|
|
68
|
+
/**
|
|
69
|
+
* Generate summary message
|
|
70
|
+
*/
|
|
71
|
+
private generateSummary;
|
|
72
|
+
/**
|
|
73
|
+
* Update configuration
|
|
74
|
+
*/
|
|
75
|
+
updateConfig(updates: Partial<FeedbackLoopConfig>): void;
|
|
76
|
+
/**
|
|
77
|
+
* Get current configuration
|
|
78
|
+
*/
|
|
79
|
+
getConfig(): FeedbackLoopConfig;
|
|
80
|
+
}
|
|
81
|
+
export declare function getFeedbackLoop(config?: Partial<FeedbackLoopConfig>): FeedbackLoop;
|
|
82
|
+
export declare function resetFeedbackLoop(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Run feedback loop with default configuration
|
|
85
|
+
*/
|
|
86
|
+
export declare function runFeedbackLoop(workingDirectory: string, options?: Partial<Omit<FeedbackLoopConfig, 'verificationContext'>>): Promise<FeedbackLoopResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Verify and fix until success or max iterations
|
|
89
|
+
*/
|
|
90
|
+
export declare function verifyAndFix(workingDirectory: string, maxIterations?: number): Promise<FeedbackLoopResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Quick check if code is currently valid
|
|
93
|
+
*/
|
|
94
|
+
export declare function isProjectValid(workingDirectory: string): Promise<boolean>;
|
|
95
|
+
/**
|
|
96
|
+
* Format feedback loop result for display
|
|
97
|
+
*/
|
|
98
|
+
export declare function formatFeedbackResult(result: FeedbackLoopResult): string;
|