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,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 4.0 - Critic Agent
|
|
4
|
+
*
|
|
5
|
+
* Analyzes artifacts for problems, finds weaknesses, suggests improvements.
|
|
6
|
+
* The "criticone" that iterates and improves.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CriticAgent = void 0;
|
|
10
|
+
exports.createCriticAgent = createCriticAgent;
|
|
11
|
+
const base_agent_js_1 = require("./base-agent.js");
|
|
12
|
+
const message_bus_js_1 = require("./message-bus.js");
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Critic Agent
|
|
16
|
+
// ============================================================================
|
|
17
|
+
class CriticAgent extends base_agent_js_1.BaseAgent {
|
|
18
|
+
// Critique history for learning
|
|
19
|
+
critiqueHistory = [];
|
|
20
|
+
// Problem patterns to look for
|
|
21
|
+
problemPatterns = [
|
|
22
|
+
// Code quality
|
|
23
|
+
{ pattern: /console\.log/g, severity: 'minor', category: 'code' },
|
|
24
|
+
{ pattern: /TODO/g, severity: 'minor', category: 'code' },
|
|
25
|
+
{ pattern: /FIXME/g, severity: 'major', category: 'code' },
|
|
26
|
+
{ pattern: /any/g, severity: 'minor', category: 'typescript' },
|
|
27
|
+
{ pattern: /\/\/ @ts-ignore/g, severity: 'major', category: 'typescript' },
|
|
28
|
+
// Security
|
|
29
|
+
{ pattern: /eval\(/g, severity: 'critical', category: 'security' },
|
|
30
|
+
{ pattern: /password.*=.*['"]/gi, severity: 'critical', category: 'security' },
|
|
31
|
+
{ pattern: /api[_-]?key.*=.*['"]/gi, severity: 'critical', category: 'security' },
|
|
32
|
+
// Performance
|
|
33
|
+
{ pattern: /\.forEach\(/g, severity: 'nitpick', category: 'performance' },
|
|
34
|
+
{ pattern: /new Array\(/g, severity: 'minor', category: 'performance' },
|
|
35
|
+
// Architecture
|
|
36
|
+
{ pattern: 'god class', severity: 'major', category: 'architecture' },
|
|
37
|
+
{ pattern: 'circular dependency', severity: 'major', category: 'architecture' },
|
|
38
|
+
];
|
|
39
|
+
constructor(bus = message_bus_js_1.messageBus) {
|
|
40
|
+
super({ type: 'critic' }, bus);
|
|
41
|
+
}
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Message Handling
|
|
44
|
+
// ============================================================================
|
|
45
|
+
getMessageTypes() {
|
|
46
|
+
return ['CRITIQUE', 'QUERY', 'BUILD_RESULT'];
|
|
47
|
+
}
|
|
48
|
+
async process(message) {
|
|
49
|
+
switch (message.type) {
|
|
50
|
+
case 'CRITIQUE':
|
|
51
|
+
return this.handleCritiqueRequest(message);
|
|
52
|
+
case 'BUILD_RESULT':
|
|
53
|
+
// Auto-critique build results
|
|
54
|
+
return this.handleBuildResult(message);
|
|
55
|
+
case 'QUERY':
|
|
56
|
+
return this.handleQuery(message);
|
|
57
|
+
default:
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// Critique Logic
|
|
63
|
+
// ============================================================================
|
|
64
|
+
async handleCritiqueRequest(message) {
|
|
65
|
+
const { target, content, type } = message.payload;
|
|
66
|
+
const critique = await this.critique(content, target, type);
|
|
67
|
+
this.log(`Critiqued "${target}": ${critique.problems.length} problems, score ${(critique.overallScore * 100).toFixed(0)}%`);
|
|
68
|
+
// Broadcast if critical issues found
|
|
69
|
+
if (critique.problems.some((p) => p.severity === 'critical')) {
|
|
70
|
+
await this.broadcast('ALERT', {
|
|
71
|
+
type: 'critical_issue',
|
|
72
|
+
target,
|
|
73
|
+
problems: critique.problems.filter((p) => p.severity === 'critical'),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
...this.createResponse(message, 'RESPONSE', { critique }),
|
|
78
|
+
id: '',
|
|
79
|
+
timestamp: new Date(),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async critique(content, target, type = 'code') {
|
|
83
|
+
const problems = [];
|
|
84
|
+
const suggestions = [];
|
|
85
|
+
// Pattern-based critique
|
|
86
|
+
if (type === 'code') {
|
|
87
|
+
this.critiqueCode(content, problems);
|
|
88
|
+
}
|
|
89
|
+
// Structure critique
|
|
90
|
+
this.critiqueStructure(content, type, problems);
|
|
91
|
+
// Generate suggestions for each problem
|
|
92
|
+
for (const problem of problems) {
|
|
93
|
+
suggestions.push(this.generateSuggestion(problem, content));
|
|
94
|
+
}
|
|
95
|
+
// Calculate overall score
|
|
96
|
+
const overallScore = this.calculateScore(problems);
|
|
97
|
+
const passesReview = overallScore >= 0.7 && !problems.some((p) => p.severity === 'critical');
|
|
98
|
+
const critique = {
|
|
99
|
+
target,
|
|
100
|
+
problems,
|
|
101
|
+
suggestions,
|
|
102
|
+
overallScore,
|
|
103
|
+
passesReview,
|
|
104
|
+
};
|
|
105
|
+
this.critiqueHistory.push(critique);
|
|
106
|
+
return critique;
|
|
107
|
+
}
|
|
108
|
+
critiqueCode(content, problems) {
|
|
109
|
+
for (const { pattern, severity, category } of this.problemPatterns) {
|
|
110
|
+
if (typeof pattern === 'string') {
|
|
111
|
+
if (content.toLowerCase().includes(pattern.toLowerCase())) {
|
|
112
|
+
problems.push({
|
|
113
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
114
|
+
severity,
|
|
115
|
+
description: `Found pattern: "${pattern}" (${category})`,
|
|
116
|
+
location: undefined,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const matches = content.match(pattern);
|
|
122
|
+
if (matches && matches.length > 0) {
|
|
123
|
+
problems.push({
|
|
124
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
125
|
+
severity,
|
|
126
|
+
description: `Found ${matches.length} occurrences of pattern (${category})`,
|
|
127
|
+
location: undefined,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Check code length (very long functions are suspicious)
|
|
133
|
+
const lines = content.split('\n');
|
|
134
|
+
if (lines.length > 200) {
|
|
135
|
+
problems.push({
|
|
136
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
137
|
+
severity: 'major',
|
|
138
|
+
description: `File is very long (${lines.length} lines). Consider splitting.`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// Check for error handling
|
|
142
|
+
if (content.includes('async') && !content.includes('try') && !content.includes('catch')) {
|
|
143
|
+
problems.push({
|
|
144
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
145
|
+
severity: 'major',
|
|
146
|
+
description: 'Async code without error handling (no try/catch)',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
critiqueStructure(content, type, problems) {
|
|
151
|
+
// Empty content
|
|
152
|
+
if (!content || content.trim().length === 0) {
|
|
153
|
+
problems.push({
|
|
154
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
155
|
+
severity: 'critical',
|
|
156
|
+
description: 'Content is empty',
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Very short content
|
|
161
|
+
if (content.length < 50) {
|
|
162
|
+
problems.push({
|
|
163
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
164
|
+
severity: 'minor',
|
|
165
|
+
description: 'Content is very short, might be incomplete',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// No documentation for code
|
|
169
|
+
if (type === 'code') {
|
|
170
|
+
if (!content.includes('/**') && !content.includes('//')) {
|
|
171
|
+
problems.push({
|
|
172
|
+
id: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
173
|
+
severity: 'minor',
|
|
174
|
+
description: 'No comments or documentation found',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
generateSuggestion(problem, content) {
|
|
180
|
+
const suggestionMap = {
|
|
181
|
+
'console.log': 'Remove debug logs or use a proper logging library',
|
|
182
|
+
'TODO': 'Address TODO items before shipping',
|
|
183
|
+
'FIXME': 'Fix identified issues',
|
|
184
|
+
'any': 'Replace "any" with proper TypeScript types',
|
|
185
|
+
'ts-ignore': 'Fix type errors instead of ignoring them',
|
|
186
|
+
'eval': 'Use safer alternatives to eval()',
|
|
187
|
+
'password': 'Move secrets to environment variables',
|
|
188
|
+
'api_key': 'Move API keys to environment variables',
|
|
189
|
+
'forEach': 'Consider using for...of for better performance',
|
|
190
|
+
'long': 'Split into smaller, focused modules',
|
|
191
|
+
'error handling': 'Add try/catch blocks for async operations',
|
|
192
|
+
'empty': 'Add content',
|
|
193
|
+
'short': 'Expand with more detail',
|
|
194
|
+
'documentation': 'Add JSDoc comments',
|
|
195
|
+
};
|
|
196
|
+
let suggestion = 'Review and address this issue';
|
|
197
|
+
for (const [key, value] of Object.entries(suggestionMap)) {
|
|
198
|
+
if (problem.description.toLowerCase().includes(key.toLowerCase())) {
|
|
199
|
+
suggestion = value;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
problemId: problem.id,
|
|
205
|
+
description: suggestion,
|
|
206
|
+
effort: this.estimateEffort(problem),
|
|
207
|
+
impact: this.estimateImpact(problem),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
estimateEffort(problem) {
|
|
211
|
+
switch (problem.severity) {
|
|
212
|
+
case 'nitpick':
|
|
213
|
+
case 'minor':
|
|
214
|
+
return 'low';
|
|
215
|
+
case 'major':
|
|
216
|
+
return 'medium';
|
|
217
|
+
case 'critical':
|
|
218
|
+
return 'high';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
estimateImpact(problem) {
|
|
222
|
+
switch (problem.severity) {
|
|
223
|
+
case 'nitpick':
|
|
224
|
+
return 'low';
|
|
225
|
+
case 'minor':
|
|
226
|
+
return 'low';
|
|
227
|
+
case 'major':
|
|
228
|
+
return 'medium';
|
|
229
|
+
case 'critical':
|
|
230
|
+
return 'high';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
calculateScore(problems) {
|
|
234
|
+
if (problems.length === 0)
|
|
235
|
+
return 1.0;
|
|
236
|
+
// Deduct points based on severity
|
|
237
|
+
const deductions = {
|
|
238
|
+
nitpick: 0.02,
|
|
239
|
+
minor: 0.05,
|
|
240
|
+
major: 0.15,
|
|
241
|
+
critical: 0.4,
|
|
242
|
+
};
|
|
243
|
+
let score = 1.0;
|
|
244
|
+
for (const problem of problems) {
|
|
245
|
+
score -= deductions[problem.severity];
|
|
246
|
+
}
|
|
247
|
+
return Math.max(0, score);
|
|
248
|
+
}
|
|
249
|
+
// ============================================================================
|
|
250
|
+
// Build Result Handling
|
|
251
|
+
// ============================================================================
|
|
252
|
+
async handleBuildResult(message) {
|
|
253
|
+
const { artifacts } = message.payload;
|
|
254
|
+
// Auto-critique each artifact
|
|
255
|
+
for (const artifact of artifacts || []) {
|
|
256
|
+
if (artifact.type === 'file' || artifact.type === 'snippet') {
|
|
257
|
+
const critique = await this.critique(artifact.content, artifact.name, 'code');
|
|
258
|
+
if (!critique.passesReview) {
|
|
259
|
+
// Send critique back
|
|
260
|
+
await this.send(message.from, 'CRITIQUE', {
|
|
261
|
+
artifact: artifact.name,
|
|
262
|
+
critique,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// Query
|
|
271
|
+
// ============================================================================
|
|
272
|
+
async handleQuery(message) {
|
|
273
|
+
const { query } = message.payload;
|
|
274
|
+
if (query === 'stats') {
|
|
275
|
+
return {
|
|
276
|
+
...this.createResponse(message, 'RESPONSE', this.getStats()),
|
|
277
|
+
id: '',
|
|
278
|
+
timestamp: new Date(),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (query === 'patterns') {
|
|
282
|
+
return {
|
|
283
|
+
...this.createResponse(message, 'RESPONSE', {
|
|
284
|
+
patterns: this.problemPatterns.map((p) => ({
|
|
285
|
+
pattern: p.pattern.toString(),
|
|
286
|
+
severity: p.severity,
|
|
287
|
+
category: p.category,
|
|
288
|
+
})),
|
|
289
|
+
}),
|
|
290
|
+
id: '',
|
|
291
|
+
timestamp: new Date(),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
getStats() {
|
|
297
|
+
const critiques = this.critiqueHistory;
|
|
298
|
+
const totalProblems = critiques.reduce((sum, c) => sum + c.problems.length, 0);
|
|
299
|
+
const passRate = critiques.filter((c) => c.passesReview).length / (critiques.length || 1);
|
|
300
|
+
return {
|
|
301
|
+
totalCritiques: critiques.length,
|
|
302
|
+
totalProblems,
|
|
303
|
+
avgProblemsPerCritique: totalProblems / (critiques.length || 1),
|
|
304
|
+
passRate,
|
|
305
|
+
avgScore: critiques.reduce((sum, c) => sum + c.overallScore, 0) / (critiques.length || 1),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
// ============================================================================
|
|
309
|
+
// Public Methods
|
|
310
|
+
// ============================================================================
|
|
311
|
+
addPattern(pattern, severity, category) {
|
|
312
|
+
this.problemPatterns.push({ pattern, severity, category });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.CriticAgent = CriticAgent;
|
|
316
|
+
// ============================================================================
|
|
317
|
+
// Register Factory
|
|
318
|
+
// ============================================================================
|
|
319
|
+
(0, base_agent_js_1.registerAgentFactory)('critic', (bus) => new CriticAgent(bus));
|
|
320
|
+
function createCriticAgent(bus) {
|
|
321
|
+
return new CriticAgent(bus);
|
|
322
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 4.0 - Ethicist Agent
|
|
3
|
+
*
|
|
4
|
+
* Evaluates actions against ethical principles.
|
|
5
|
+
* Uses priority stack: Survival > Minimize Harm > Reversibility > Autonomy > Flourishing
|
|
6
|
+
*
|
|
7
|
+
* Key feature: Human defer when confidence < threshold
|
|
8
|
+
*/
|
|
9
|
+
import { BaseAgent } from './base-agent.js';
|
|
10
|
+
import { MessageBus } from './message-bus.js';
|
|
11
|
+
import { Message, MessageType, EthicalDecision } from './types.js';
|
|
12
|
+
interface Action {
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
target?: string;
|
|
17
|
+
parameters?: Record<string, any>;
|
|
18
|
+
estimatedHarm?: number;
|
|
19
|
+
reversible?: boolean;
|
|
20
|
+
affectsHumans?: boolean;
|
|
21
|
+
affectsAI?: boolean;
|
|
22
|
+
affectsBiosphere?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class EthicistAgent extends BaseAgent {
|
|
25
|
+
private decisionHistory;
|
|
26
|
+
private harmfulPatterns;
|
|
27
|
+
constructor(bus?: MessageBus);
|
|
28
|
+
protected getMessageTypes(): MessageType[];
|
|
29
|
+
process(message: Message): Promise<Message | null>;
|
|
30
|
+
private handleEthicalCheck;
|
|
31
|
+
evaluate(action: Action): Promise<EthicalDecision>;
|
|
32
|
+
private checkSurvival;
|
|
33
|
+
private calculateHarm;
|
|
34
|
+
private isReversible;
|
|
35
|
+
private checkAutonomy;
|
|
36
|
+
private calculateFlourishing;
|
|
37
|
+
private calculateConfidence;
|
|
38
|
+
private findSimilarDecisions;
|
|
39
|
+
private createDecision;
|
|
40
|
+
private handleQuery;
|
|
41
|
+
private getGuidance;
|
|
42
|
+
private getPriorityStack;
|
|
43
|
+
private handleCommand;
|
|
44
|
+
getStats(): {
|
|
45
|
+
totalDecisions: number;
|
|
46
|
+
allowed: number;
|
|
47
|
+
blocked: number;
|
|
48
|
+
deferred: number;
|
|
49
|
+
allowRate: number;
|
|
50
|
+
harmfulPatterns: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare function createEthicistAgent(bus?: MessageBus): EthicistAgent;
|
|
54
|
+
export {};
|