erosolar-cli 2.1.287 → 2.1.289
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/README.md +7 -0
- package/dist/bin/agi-cli.d.ts +15 -0
- package/dist/bin/agi-cli.d.ts.map +1 -0
- package/dist/bin/agi-cli.js +175 -0
- package/dist/bin/agi-cli.js.map +1 -0
- package/dist/capabilities/metaCapability.d.ts +22 -0
- package/dist/capabilities/metaCapability.d.ts.map +1 -0
- package/dist/capabilities/metaCapability.js +33 -0
- package/dist/capabilities/metaCapability.js.map +1 -0
- package/dist/capabilities/orchestrationCapability.d.ts.map +1 -1
- package/dist/capabilities/orchestrationCapability.js +6 -2
- package/dist/capabilities/orchestrationCapability.js.map +1 -1
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +0 -3
- package/dist/core/agent.js.map +1 -1
- package/dist/core/agiCore.d.ts +149 -0
- package/dist/core/agiCore.d.ts.map +1 -0
- package/dist/core/agiCore.js +1085 -0
- package/dist/core/agiCore.js.map +1 -0
- package/dist/core/defensiveSecurityToolkit.d.ts.map +1 -1
- package/dist/core/defensiveSecurityToolkit.js +1 -0
- package/dist/core/defensiveSecurityToolkit.js.map +1 -1
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/hooks.js +101 -8
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/iMessageVerification.d.ts.map +1 -1
- package/dist/core/iMessageVerification.js +1 -0
- package/dist/core/iMessageVerification.js.map +1 -1
- package/dist/core/integrityVerification.d.ts.map +1 -1
- package/dist/core/integrityVerification.js +1 -0
- package/dist/core/integrityVerification.js.map +1 -1
- package/dist/core/intelligentTargetResearcher.d.ts.map +1 -1
- package/dist/core/intelligentTargetResearcher.js +1 -0
- package/dist/core/intelligentTargetResearcher.js.map +1 -1
- package/dist/core/persistentObjectiveStore.d.ts.map +1 -1
- package/dist/core/persistentObjectiveStore.js +1 -0
- package/dist/core/persistentObjectiveStore.js.map +1 -1
- package/dist/core/productTestHarness.d.ts +3 -3
- package/dist/core/productTestHarness.d.ts.map +1 -1
- package/dist/core/productTestHarness.js +4 -3
- package/dist/core/productTestHarness.js.map +1 -1
- package/dist/core/realAGI.d.ts +113 -0
- package/dist/core/realAGI.d.ts.map +1 -0
- package/dist/core/realAGI.js +899 -0
- package/dist/core/realAGI.js.map +1 -0
- package/dist/core/securityDeliverableGenerator.d.ts.map +1 -1
- package/dist/core/securityDeliverableGenerator.js +1 -0
- package/dist/core/securityDeliverableGenerator.js.map +1 -1
- package/dist/core/sourceCodeManager.d.ts +1 -1
- package/dist/core/sourceCodeManager.d.ts.map +1 -1
- package/dist/core/techFraudInvestigator.d.ts.map +1 -1
- package/dist/core/techFraudInvestigator.js +1 -0
- package/dist/core/techFraudInvestigator.js.map +1 -1
- package/dist/core/toolEmbeddings.d.ts +64 -0
- package/dist/core/toolEmbeddings.d.ts.map +1 -0
- package/dist/core/toolEmbeddings.js +471 -0
- package/dist/core/toolEmbeddings.js.map +1 -0
- package/dist/core/toolRuntime.d.ts +1 -1
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +1 -1
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/unifiedAGI.d.ts +158 -0
- package/dist/core/unifiedAGI.d.ts.map +1 -0
- package/dist/core/unifiedAGI.js +685 -0
- package/dist/core/unifiedAGI.js.map +1 -0
- package/dist/plugins/tools/agi/agiPlugin.d.ts +24 -0
- package/dist/plugins/tools/agi/agiPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/agi/agiPlugin.js +511 -0
- package/dist/plugins/tools/agi/agiPlugin.js.map +1 -0
- package/dist/plugins/tools/meta/metaPlugin.d.ts +12 -0
- package/dist/plugins/tools/meta/metaPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/meta/metaPlugin.js +19 -0
- package/dist/plugins/tools/meta/metaPlugin.js.map +1 -0
- package/dist/plugins/tools/nodeDefaults.d.ts +2 -0
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +6 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/plugins/tools/unified/unifiedAGIPlugin.d.ts +25 -0
- package/dist/plugins/tools/unified/unifiedAGIPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/unified/unifiedAGIPlugin.js +479 -0
- package/dist/plugins/tools/unified/unifiedAGIPlugin.js.map +1 -0
- package/dist/providers/openaiChatCompletionsProvider.js +3 -2
- package/dist/providers/openaiChatCompletionsProvider.js.map +1 -1
- package/dist/providers/openaiResponsesProvider.js +3 -2
- package/dist/providers/openaiResponsesProvider.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +4 -6
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/skills/skillRepository.d.ts.map +1 -1
- package/dist/skills/skillRepository.js +15 -6
- package/dist/skills/skillRepository.js.map +1 -1
- package/dist/tools/appleExposureTools.d.ts.map +1 -1
- package/dist/tools/appleExposureTools.js +1 -0
- package/dist/tools/appleExposureTools.js.map +1 -1
- package/dist/tools/bidirectionalAuditTools.d.ts.map +1 -1
- package/dist/tools/bidirectionalAuditTools.js +1 -0
- package/dist/tools/bidirectionalAuditTools.js.map +1 -1
- package/dist/tools/defensiveSecurityTools.d.ts.map +1 -1
- package/dist/tools/defensiveSecurityTools.js +1 -0
- package/dist/tools/defensiveSecurityTools.js.map +1 -1
- package/dist/tools/forwardAttackChainTracer.d.ts.map +1 -1
- package/dist/tools/forwardAttackChainTracer.js +1 -0
- package/dist/tools/forwardAttackChainTracer.js.map +1 -1
- package/dist/tools/iMessageVerificationTools.d.ts.map +1 -1
- package/dist/tools/iMessageVerificationTools.js +1 -0
- package/dist/tools/iMessageVerificationTools.js.map +1 -1
- package/dist/tools/integrityTools.d.ts.map +1 -1
- package/dist/tools/integrityTools.js +1 -0
- package/dist/tools/integrityTools.js.map +1 -1
- package/dist/tools/metaTools.d.ts +62 -0
- package/dist/tools/metaTools.d.ts.map +1 -0
- package/dist/tools/metaTools.js +3201 -0
- package/dist/tools/metaTools.js.map +1 -0
- package/dist/tools/offensiveTransparencyTools.d.ts.map +1 -1
- package/dist/tools/offensiveTransparencyTools.js +1 -0
- package/dist/tools/offensiveTransparencyTools.js.map +1 -1
- package/dist/tools/searchTools.js +1 -1
- package/dist/tools/searchTools.js.map +1 -1
- package/dist/tools/taoTools.js +1 -1
- package/dist/tools/threatIntelligenceTools.d.ts.map +1 -1
- package/dist/tools/threatIntelligenceTools.js +1 -0
- package/dist/tools/threatIntelligenceTools.js.map +1 -1
- package/dist/ui/UnifiedUIRenderer.js +1 -1
- package/dist/ui/UnifiedUIRenderer.js.map +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified AGI Core - Real Autonomous General Intelligence
|
|
3
|
+
*
|
|
4
|
+
* This is the single, unified AGI system that:
|
|
5
|
+
* 1. Understands ANY prompt (software, research, legal, finance, automation, defense, etc.)
|
|
6
|
+
* 2. Decomposes into real, executable tasks
|
|
7
|
+
* 3. Generates real tool calls
|
|
8
|
+
* 4. Provides Claude Code style output
|
|
9
|
+
*
|
|
10
|
+
* NO SIMULATIONS - Everything is real and executable
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import { EventEmitter } from 'events';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// UNIFIED AGI CLASS
|
|
17
|
+
// ============================================================================
|
|
18
|
+
export class UnifiedAGI extends EventEmitter {
|
|
19
|
+
context;
|
|
20
|
+
memoryPath;
|
|
21
|
+
constructor(workingDir) {
|
|
22
|
+
super();
|
|
23
|
+
const dir = workingDir || process.cwd();
|
|
24
|
+
this.memoryPath = path.join(dir, '.erosolar', 'unified-agi-memory.json');
|
|
25
|
+
this.context = {
|
|
26
|
+
workingDir: dir,
|
|
27
|
+
sessionId: `uagi-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
28
|
+
startTime: Date.now(),
|
|
29
|
+
memory: this.loadMemory(),
|
|
30
|
+
domain: this.initializeDomainContext(),
|
|
31
|
+
};
|
|
32
|
+
this.analyzeProject();
|
|
33
|
+
}
|
|
34
|
+
// ==========================================================================
|
|
35
|
+
// MEMORY MANAGEMENT
|
|
36
|
+
// ==========================================================================
|
|
37
|
+
loadMemory() {
|
|
38
|
+
try {
|
|
39
|
+
if (fs.existsSync(this.memoryPath)) {
|
|
40
|
+
return JSON.parse(fs.readFileSync(this.memoryPath, 'utf-8'));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Start fresh
|
|
45
|
+
}
|
|
46
|
+
return this.createEmptyMemory();
|
|
47
|
+
}
|
|
48
|
+
createEmptyMemory() {
|
|
49
|
+
return {
|
|
50
|
+
patterns: [],
|
|
51
|
+
recentOps: [],
|
|
52
|
+
projectKnowledge: {
|
|
53
|
+
type: 'unknown',
|
|
54
|
+
buildSystem: null,
|
|
55
|
+
testCommand: null,
|
|
56
|
+
lintCommand: null,
|
|
57
|
+
entryPoints: [],
|
|
58
|
+
dependencies: {},
|
|
59
|
+
lastAnalyzed: 0,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
saveMemory() {
|
|
64
|
+
try {
|
|
65
|
+
const dir = path.dirname(this.memoryPath);
|
|
66
|
+
if (!fs.existsSync(dir)) {
|
|
67
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
fs.writeFileSync(this.memoryPath, JSON.stringify(this.context.memory, null, 2));
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
this.emit('warning', `Failed to save memory: ${error}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
initializeDomainContext() {
|
|
76
|
+
return {
|
|
77
|
+
currentDomain: 'general',
|
|
78
|
+
domainCapabilities: [
|
|
79
|
+
{ domain: 'software', tools: ['Read', 'Edit', 'Write', 'Bash', 'Grep', 'Glob'], description: 'Software engineering' },
|
|
80
|
+
{ domain: 'research', tools: ['Read', 'WebSearch', 'WebFetch', 'Bash', 'Write'], description: 'Research and analysis' },
|
|
81
|
+
{ domain: 'data_science', tools: ['Bash', 'Read', 'Write', 'Edit'], description: 'Data science and ML' },
|
|
82
|
+
{ domain: 'legal', tools: ['Read', 'Write', 'Edit', 'Grep', 'WebSearch'], description: 'Legal document automation' },
|
|
83
|
+
{ domain: 'finance', tools: ['Read', 'Write', 'Edit', 'Bash'], description: 'Financial analysis and automation' },
|
|
84
|
+
{ domain: 'automation', tools: ['Bash', 'Read', 'Write', 'Edit', 'Glob'], description: 'Workflow automation' },
|
|
85
|
+
{ domain: 'devops', tools: ['Bash', 'Read', 'Write', 'Edit', 'Glob'], description: 'DevOps and infrastructure' },
|
|
86
|
+
{ domain: 'security', tools: ['Bash', 'Grep', 'Read', 'Edit', 'Glob'], description: 'Security analysis' },
|
|
87
|
+
{ domain: 'defense', tools: ['Bash', 'Read', 'Write', 'Edit', 'Grep', 'Glob', 'WebSearch'], description: 'Defense systems' },
|
|
88
|
+
{ domain: 'general', tools: ['Read', 'Edit', 'Write', 'Bash', 'Grep', 'Glob'], description: 'General tasks' },
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// ==========================================================================
|
|
93
|
+
// PROJECT ANALYSIS
|
|
94
|
+
// ==========================================================================
|
|
95
|
+
analyzeProject() {
|
|
96
|
+
const knowledge = this.context.memory.projectKnowledge;
|
|
97
|
+
const dir = this.context.workingDir;
|
|
98
|
+
// Node.js
|
|
99
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
100
|
+
if (fs.existsSync(pkgPath)) {
|
|
101
|
+
try {
|
|
102
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
103
|
+
knowledge.type = 'node';
|
|
104
|
+
knowledge.dependencies = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
105
|
+
if (pkg.scripts) {
|
|
106
|
+
knowledge.testCommand = pkg.scripts.test ? 'npm test' : null;
|
|
107
|
+
knowledge.lintCommand = pkg.scripts.lint ? 'npm run lint' : null;
|
|
108
|
+
knowledge.buildSystem = pkg.scripts.build ? 'npm run build' : null;
|
|
109
|
+
}
|
|
110
|
+
if (pkg.main)
|
|
111
|
+
knowledge.entryPoints.push(pkg.main);
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
}
|
|
115
|
+
// Python
|
|
116
|
+
if (fs.existsSync(path.join(dir, 'pyproject.toml')) || fs.existsSync(path.join(dir, 'setup.py'))) {
|
|
117
|
+
knowledge.type = 'python';
|
|
118
|
+
knowledge.testCommand = 'pytest';
|
|
119
|
+
knowledge.lintCommand = 'ruff check .';
|
|
120
|
+
}
|
|
121
|
+
// Rust
|
|
122
|
+
if (fs.existsSync(path.join(dir, 'Cargo.toml'))) {
|
|
123
|
+
knowledge.type = 'rust';
|
|
124
|
+
knowledge.testCommand = 'cargo test';
|
|
125
|
+
knowledge.lintCommand = 'cargo clippy';
|
|
126
|
+
knowledge.buildSystem = 'cargo build';
|
|
127
|
+
}
|
|
128
|
+
// Go
|
|
129
|
+
if (fs.existsSync(path.join(dir, 'go.mod'))) {
|
|
130
|
+
knowledge.type = 'go';
|
|
131
|
+
knowledge.testCommand = 'go test ./...';
|
|
132
|
+
knowledge.lintCommand = 'golangci-lint run';
|
|
133
|
+
knowledge.buildSystem = 'go build';
|
|
134
|
+
}
|
|
135
|
+
knowledge.lastAnalyzed = Date.now();
|
|
136
|
+
this.saveMemory();
|
|
137
|
+
}
|
|
138
|
+
// ==========================================================================
|
|
139
|
+
// UNIFIED PROMPT ANALYSIS - The core of AGI
|
|
140
|
+
// ==========================================================================
|
|
141
|
+
/**
|
|
142
|
+
* Analyze ANY prompt and produce a complete execution plan
|
|
143
|
+
*/
|
|
144
|
+
analyze(prompt) {
|
|
145
|
+
const lower = prompt.toLowerCase().trim();
|
|
146
|
+
// Check learned patterns first
|
|
147
|
+
const learned = this.getLearnedApproach(prompt);
|
|
148
|
+
if (learned && learned.successCount >= 2) {
|
|
149
|
+
return this.createFromLearnedPattern(prompt, learned);
|
|
150
|
+
}
|
|
151
|
+
// Determine domain
|
|
152
|
+
const domain = this.determineDomain(lower);
|
|
153
|
+
this.context.domain.currentDomain = domain;
|
|
154
|
+
// Generate interpretation and tasks
|
|
155
|
+
const interpretation = this.generateInterpretation(prompt, domain);
|
|
156
|
+
const tasks = this.generateTasks(prompt, domain);
|
|
157
|
+
const toolCalls = this.generateToolCalls(tasks, domain);
|
|
158
|
+
const clarificationNeeded = this.checkAmbiguity(prompt, domain);
|
|
159
|
+
return {
|
|
160
|
+
originalPrompt: prompt,
|
|
161
|
+
interpretation,
|
|
162
|
+
domain,
|
|
163
|
+
confidence: clarificationNeeded.length === 0 ? 0.9 : 0.6,
|
|
164
|
+
tasks,
|
|
165
|
+
toolCalls,
|
|
166
|
+
clarificationNeeded,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Determine the domain of a prompt
|
|
171
|
+
*/
|
|
172
|
+
determineDomain(lower) {
|
|
173
|
+
// Defense/Military systems (check first - high priority)
|
|
174
|
+
if (/fighter\s*(?:drone|jet|aircraft)|missile|ballistic|reentry|carrier|military|warfare|combat|weapon/i.test(lower)) {
|
|
175
|
+
return 'defense';
|
|
176
|
+
}
|
|
177
|
+
if (/6th\s*gen|drone\s*coordination|maneuverable\s*reentry|mrv|mirv|hypersonic/i.test(lower)) {
|
|
178
|
+
return 'defense';
|
|
179
|
+
}
|
|
180
|
+
// Security (check before software - explicit security terms)
|
|
181
|
+
if (/pentest|vulnerab|exploit|hack|cyber\s*(?:attack|security|symmetric)|security\s+(?:audit|assessment|test)|offensive\s+cyber/i.test(lower)) {
|
|
182
|
+
return 'security';
|
|
183
|
+
}
|
|
184
|
+
// Legal (expanded patterns)
|
|
185
|
+
if (/\bsue\b|lawsuit|litigation|legal|court|attorney|lawyer|complaint|motion|brief|deposition|\bcontract\b/i.test(lower)) {
|
|
186
|
+
return 'legal';
|
|
187
|
+
}
|
|
188
|
+
// Finance
|
|
189
|
+
if (/accounting|bookkeeping|financ|tax\b|ledger|balance\s*sheet|invoice|payroll|budget/i.test(lower)) {
|
|
190
|
+
return 'finance';
|
|
191
|
+
}
|
|
192
|
+
// Research/Science (expanded)
|
|
193
|
+
if (/\bcure\b|research|experiment|hypothesis|scientific|laboratory|clinical|biomedical|genome|genomic/i.test(lower)) {
|
|
194
|
+
return 'research';
|
|
195
|
+
}
|
|
196
|
+
// Data Science (before general)
|
|
197
|
+
if (/data\s+(?:analysis|science|engineer|pipeline)|statistic|machine\s+learning|\bml\b|\bai\b|neural|dataset/i.test(lower)) {
|
|
198
|
+
return 'data_science';
|
|
199
|
+
}
|
|
200
|
+
// Scientific Computing
|
|
201
|
+
if (/simulat|physics|chemistry|cad\b|finite\s+element|signal\s+process|engineering|science\s+shit/i.test(lower)) {
|
|
202
|
+
return 'scientific_computing';
|
|
203
|
+
}
|
|
204
|
+
// Business
|
|
205
|
+
if (/business|strateg|\bmarket\b|competitor|swot|business\s+plan/i.test(lower)) {
|
|
206
|
+
return 'business';
|
|
207
|
+
}
|
|
208
|
+
// DevOps (more specific - avoid catching "deploy" when used in software context)
|
|
209
|
+
if (/devops|ci\/cd|docker|kubernetes|terraform|ansible|jenkins/i.test(lower)) {
|
|
210
|
+
return 'devops';
|
|
211
|
+
}
|
|
212
|
+
// Deploy to production without explicit software context -> devops
|
|
213
|
+
if (/deploy\s+to\s+(?:prod|production|staging|cloud)/i.test(lower)) {
|
|
214
|
+
return 'devops';
|
|
215
|
+
}
|
|
216
|
+
// Pipeline without data context -> devops
|
|
217
|
+
if (/pipeline/i.test(lower) && !/data/i.test(lower)) {
|
|
218
|
+
return 'devops';
|
|
219
|
+
}
|
|
220
|
+
// Automation
|
|
221
|
+
if (/\bautomat|\bworkflow|\bschedule|\bcron\b|batch\s+process/i.test(lower)) {
|
|
222
|
+
return 'automation';
|
|
223
|
+
}
|
|
224
|
+
// Monitoring
|
|
225
|
+
if (/\bmonitor|alert|dashboard|metric|observab|logging/i.test(lower)) {
|
|
226
|
+
return 'monitoring';
|
|
227
|
+
}
|
|
228
|
+
// Infrastructure (check before software)
|
|
229
|
+
if (/infrastructure/i.test(lower)) {
|
|
230
|
+
return 'devops';
|
|
231
|
+
}
|
|
232
|
+
// Software Engineering (default for code-related)
|
|
233
|
+
if (/fix|bug|error|add|create|implement|build|refactor|test|document|deploy|optimize/i.test(lower)) {
|
|
234
|
+
return 'software';
|
|
235
|
+
}
|
|
236
|
+
return 'general';
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Generate human-readable interpretation
|
|
240
|
+
*/
|
|
241
|
+
generateInterpretation(prompt, domain) {
|
|
242
|
+
const interpretations = {
|
|
243
|
+
software: (p) => `Software engineering task: ${p}`,
|
|
244
|
+
research: (p) => `Research/analysis pipeline for: ${p}`,
|
|
245
|
+
data_science: (p) => `Data science/ML pipeline for: ${p}`,
|
|
246
|
+
scientific_computing: (p) => `Scientific computing task: ${p}`,
|
|
247
|
+
legal: (p) => `Legal automation and document generation for: ${p}`,
|
|
248
|
+
business: (p) => `Business analysis tools for: ${p}`,
|
|
249
|
+
finance: (p) => `Financial analysis and automation for: ${p}`,
|
|
250
|
+
automation: (p) => `Workflow automation for: ${p}`,
|
|
251
|
+
devops: (p) => `DevOps/infrastructure task: ${p}`,
|
|
252
|
+
monitoring: (p) => `Monitoring/observability setup for: ${p}`,
|
|
253
|
+
security: (p) => `Security analysis and testing for: ${p}`,
|
|
254
|
+
defense: (p) => `Defense systems engineering for: ${p}`,
|
|
255
|
+
general: (p) => `Task execution: ${p}`,
|
|
256
|
+
};
|
|
257
|
+
return interpretations[domain](prompt);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Generate tasks based on prompt and domain
|
|
261
|
+
*/
|
|
262
|
+
generateTasks(prompt, domain) {
|
|
263
|
+
const lower = prompt.toLowerCase();
|
|
264
|
+
const tasks = [];
|
|
265
|
+
const knowledge = this.context.memory.projectKnowledge;
|
|
266
|
+
// Domain-specific task generation
|
|
267
|
+
switch (domain) {
|
|
268
|
+
case 'software':
|
|
269
|
+
return this.generateSoftwareTasks(lower, knowledge);
|
|
270
|
+
case 'research':
|
|
271
|
+
return this.generateResearchTasks(prompt);
|
|
272
|
+
case 'data_science':
|
|
273
|
+
return this.generateDataScienceTasks(prompt);
|
|
274
|
+
case 'legal':
|
|
275
|
+
return this.generateLegalTasks(prompt);
|
|
276
|
+
case 'finance':
|
|
277
|
+
return this.generateFinanceTasks(prompt);
|
|
278
|
+
case 'automation':
|
|
279
|
+
return this.generateAutomationTasks(prompt);
|
|
280
|
+
case 'devops':
|
|
281
|
+
return this.generateDevOpsTasks(prompt);
|
|
282
|
+
case 'security':
|
|
283
|
+
return this.generateSecurityTasks(prompt);
|
|
284
|
+
case 'defense':
|
|
285
|
+
return this.generateDefenseTasks(prompt);
|
|
286
|
+
default:
|
|
287
|
+
return this.generateGeneralTasks(prompt);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// ==========================================================================
|
|
291
|
+
// DOMAIN-SPECIFIC TASK GENERATORS
|
|
292
|
+
// ==========================================================================
|
|
293
|
+
generateSoftwareTasks(lower, knowledge) {
|
|
294
|
+
const tasks = [];
|
|
295
|
+
// Bug fixing
|
|
296
|
+
if (/fix|bug|error|issue|broken|crash|fail/i.test(lower)) {
|
|
297
|
+
tasks.push({ id: 'analyze-errors', description: 'Run type checker and linter to identify issues', domain: 'software', category: 'execution', tools: ['Bash'], dependencies: [], status: 'pending' }, { id: 'search-issues', description: 'Search for TODO/FIXME comments', domain: 'software', category: 'search', tools: ['Grep'], dependencies: [], status: 'pending' }, { id: 'analyze-findings', description: 'Analyze findings and prioritize fixes', domain: 'software', category: 'analysis', tools: ['Read'], dependencies: ['analyze-errors', 'search-issues'], status: 'pending' }, { id: 'fix-issues', description: 'Apply fixes to identified issues', domain: 'software', category: 'modification', tools: ['Edit'], dependencies: ['analyze-findings'], status: 'pending' }, { id: 'verify-fixes', description: 'Verify fixes by re-running checks', domain: 'software', category: 'verification', tools: ['Bash'], dependencies: ['fix-issues'], status: 'pending' });
|
|
298
|
+
if (knowledge.testCommand) {
|
|
299
|
+
tasks.splice(1, 0, { id: 'run-tests', description: 'Run test suite to find failing tests', domain: 'software', category: 'execution', tools: ['Bash'], dependencies: [], status: 'pending' });
|
|
300
|
+
}
|
|
301
|
+
return tasks;
|
|
302
|
+
}
|
|
303
|
+
// Feature addition
|
|
304
|
+
if (/add|create|implement|build|new|feature/i.test(lower)) {
|
|
305
|
+
return [
|
|
306
|
+
{ id: 'understand-codebase', description: 'Analyze existing code structure', domain: 'software', category: 'analysis', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
307
|
+
{ id: 'plan-implementation', description: 'Plan the implementation approach', domain: 'software', category: 'analysis', tools: ['Read'], dependencies: ['understand-codebase'], status: 'pending' },
|
|
308
|
+
{ id: 'implement-feature', description: 'Write the feature code', domain: 'software', category: 'modification', tools: ['Edit', 'Write'], dependencies: ['plan-implementation'], status: 'pending' },
|
|
309
|
+
{ id: 'add-tests', description: 'Add tests for the new feature', domain: 'software', category: 'modification', tools: ['Edit', 'Write'], dependencies: ['implement-feature'], status: 'pending' },
|
|
310
|
+
{ id: 'verify-feature', description: 'Run tests and verify feature works', domain: 'software', category: 'verification', tools: ['Bash'], dependencies: ['add-tests'], status: 'pending' }
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
// Security audit
|
|
314
|
+
if (/security|vulnerab|pentest|audit/i.test(lower)) {
|
|
315
|
+
return [
|
|
316
|
+
{ id: 'dependency-audit', description: 'Audit dependencies for vulnerabilities', domain: 'software', category: 'execution', tools: ['Bash'], dependencies: [], status: 'pending' },
|
|
317
|
+
{ id: 'code-patterns', description: 'Search for insecure code patterns', domain: 'software', category: 'search', tools: ['Grep'], dependencies: [], status: 'pending' },
|
|
318
|
+
{ id: 'analyze-security', description: 'Analyze security findings', domain: 'software', category: 'analysis', tools: ['Read'], dependencies: ['dependency-audit', 'code-patterns'], status: 'pending' },
|
|
319
|
+
{ id: 'report-findings', description: 'Report findings with recommendations', domain: 'software', category: 'communication', tools: [], dependencies: ['analyze-security'], status: 'pending' }
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
// Default software task
|
|
323
|
+
return [
|
|
324
|
+
{ id: 'analyze', description: 'Analyze the request and codebase', domain: 'software', category: 'analysis', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
325
|
+
{ id: 'execute', description: 'Execute the requested changes', domain: 'software', category: 'execution', tools: ['Edit', 'Bash'], dependencies: ['analyze'], status: 'pending' },
|
|
326
|
+
{ id: 'verify', description: 'Verify the changes', domain: 'software', category: 'verification', tools: ['Bash'], dependencies: ['execute'], status: 'pending' }
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
generateResearchTasks(prompt) {
|
|
330
|
+
return [
|
|
331
|
+
{ id: 'define-scope', description: 'Define research scope and objectives', domain: 'research', category: 'analysis', tools: ['Read'], dependencies: [], status: 'pending' },
|
|
332
|
+
{ id: 'gather-data', description: 'Gather relevant data and research materials', domain: 'research', category: 'research', tools: ['WebSearch', 'Read'], dependencies: ['define-scope'], status: 'pending' },
|
|
333
|
+
{ id: 'build-pipeline', description: 'Build data processing and analysis pipeline', domain: 'research', category: 'generation', tools: ['Write', 'Bash'], dependencies: ['gather-data'], status: 'pending' },
|
|
334
|
+
{ id: 'implement-analysis', description: 'Implement analysis algorithms and models', domain: 'research', category: 'generation', tools: ['Edit', 'Write'], dependencies: ['build-pipeline'], status: 'pending' },
|
|
335
|
+
{ id: 'generate-report', description: 'Generate analysis report with findings', domain: 'research', category: 'communication', tools: ['Write'], dependencies: ['implement-analysis'], status: 'pending' }
|
|
336
|
+
];
|
|
337
|
+
}
|
|
338
|
+
generateDataScienceTasks(prompt) {
|
|
339
|
+
return [
|
|
340
|
+
{ id: 'explore-data', description: 'Explore and understand the data', domain: 'data_science', category: 'analysis', tools: ['Read', 'Bash'], dependencies: [], status: 'pending' },
|
|
341
|
+
{ id: 'clean-data', description: 'Clean and preprocess data', domain: 'data_science', category: 'execution', tools: ['Bash', 'Edit'], dependencies: ['explore-data'], status: 'pending' },
|
|
342
|
+
{ id: 'analyze-patterns', description: 'Analyze patterns and statistics', domain: 'data_science', category: 'computation', tools: ['Bash'], dependencies: ['clean-data'], status: 'pending' },
|
|
343
|
+
{ id: 'build-model', description: 'Build and train ML model', domain: 'data_science', category: 'computation', tools: ['Bash', 'Write'], dependencies: ['analyze-patterns'], status: 'pending' },
|
|
344
|
+
{ id: 'evaluate-model', description: 'Evaluate model performance', domain: 'data_science', category: 'verification', tools: ['Bash'], dependencies: ['build-model'], status: 'pending' },
|
|
345
|
+
{ id: 'create-visualizations', description: 'Create visualizations and charts', domain: 'data_science', category: 'generation', tools: ['Bash', 'Write'], dependencies: ['evaluate-model'], status: 'pending' }
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
generateLegalTasks(prompt) {
|
|
349
|
+
const lower = prompt.toLowerCase();
|
|
350
|
+
const defendantMatch = lower.match(/sue\s+(\w+)/i) || lower.match(/against\s+(\w+)/i);
|
|
351
|
+
const defendant = defendantMatch ? defendantMatch[1] : 'defendant';
|
|
352
|
+
return [
|
|
353
|
+
{ id: 'identify-claims', description: 'Identify legal claims and causes of action', domain: 'legal', category: 'research', tools: ['Read', 'WebSearch'], dependencies: [], status: 'pending' },
|
|
354
|
+
{ id: 'research-law', description: 'Research applicable laws and precedents', domain: 'legal', category: 'research', tools: ['WebSearch', 'Read'], dependencies: ['identify-claims'], status: 'pending' },
|
|
355
|
+
{ id: 'gather-evidence', description: 'Gather and organize evidence', domain: 'legal', category: 'search', tools: ['Glob', 'Grep', 'Read'], dependencies: [], status: 'pending' },
|
|
356
|
+
{ id: 'draft-complaint', description: `Draft complaint against ${defendant}`, domain: 'legal', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['research-law', 'gather-evidence'], status: 'pending' },
|
|
357
|
+
{ id: 'prepare-filing', description: 'Prepare filing package', domain: 'legal', category: 'generation', tools: ['Write'], dependencies: ['draft-complaint'], status: 'pending' },
|
|
358
|
+
{ id: 'discovery-plan', description: 'Create discovery plan', domain: 'legal', category: 'generation', tools: ['Write'], dependencies: ['draft-complaint'], status: 'pending' }
|
|
359
|
+
];
|
|
360
|
+
}
|
|
361
|
+
generateFinanceTasks(prompt) {
|
|
362
|
+
return [
|
|
363
|
+
{ id: 'gather-financial-data', description: 'Gather financial data and records', domain: 'finance', category: 'search', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
364
|
+
{ id: 'organize-transactions', description: 'Organize and categorize transactions', domain: 'finance', category: 'analysis', tools: ['Read', 'Edit'], dependencies: ['gather-financial-data'], status: 'pending' },
|
|
365
|
+
{ id: 'calculate-financials', description: 'Calculate financial metrics', domain: 'finance', category: 'computation', tools: ['Bash'], dependencies: ['organize-transactions'], status: 'pending' },
|
|
366
|
+
{ id: 'generate-statements', description: 'Generate financial statements', domain: 'finance', category: 'generation', tools: ['Write'], dependencies: ['calculate-financials'], status: 'pending' },
|
|
367
|
+
{ id: 'prepare-reports', description: 'Prepare financial reports and visualizations', domain: 'finance', category: 'generation', tools: ['Write', 'Bash'], dependencies: ['generate-statements'], status: 'pending' }
|
|
368
|
+
];
|
|
369
|
+
}
|
|
370
|
+
generateAutomationTasks(prompt) {
|
|
371
|
+
return [
|
|
372
|
+
{ id: 'analyze-workflow', description: 'Analyze current workflow and processes', domain: 'automation', category: 'analysis', tools: ['Read', 'Glob'], dependencies: [], status: 'pending' },
|
|
373
|
+
{ id: 'design-automation', description: 'Design automation solution', domain: 'automation', category: 'analysis', tools: ['Read'], dependencies: ['analyze-workflow'], status: 'pending' },
|
|
374
|
+
{ id: 'implement-automation', description: 'Implement automation scripts', domain: 'automation', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['design-automation'], status: 'pending' },
|
|
375
|
+
{ id: 'test-automation', description: 'Test automation workflow', domain: 'automation', category: 'verification', tools: ['Bash'], dependencies: ['implement-automation'], status: 'pending' }
|
|
376
|
+
];
|
|
377
|
+
}
|
|
378
|
+
generateDevOpsTasks(prompt) {
|
|
379
|
+
return [
|
|
380
|
+
{ id: 'audit-existing', description: 'Audit existing CI/CD and infrastructure', domain: 'devops', category: 'search', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
381
|
+
{ id: 'check-configs', description: 'Check Docker/Kubernetes configurations', domain: 'devops', category: 'search', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
382
|
+
{ id: 'identify-gaps', description: 'Identify missing DevOps components', domain: 'devops', category: 'analysis', tools: ['Read'], dependencies: ['audit-existing', 'check-configs'], status: 'pending' },
|
|
383
|
+
{ id: 'implement-configs', description: 'Implement DevOps configurations', domain: 'devops', category: 'modification', tools: ['Write', 'Edit'], dependencies: ['identify-gaps'], status: 'pending' },
|
|
384
|
+
{ id: 'verify-setup', description: 'Verify DevOps setup', domain: 'devops', category: 'verification', tools: ['Bash'], dependencies: ['implement-configs'], status: 'pending' }
|
|
385
|
+
];
|
|
386
|
+
}
|
|
387
|
+
generateSecurityTasks(prompt) {
|
|
388
|
+
return [
|
|
389
|
+
{ id: 'recon', description: 'Reconnaissance and information gathering', domain: 'security', category: 'search', tools: ['Bash', 'Grep', 'Glob'], dependencies: [], status: 'pending' },
|
|
390
|
+
{ id: 'scan', description: 'Vulnerability scanning and assessment', domain: 'security', category: 'execution', tools: ['Bash'], dependencies: ['recon'], status: 'pending' },
|
|
391
|
+
{ id: 'analyze-vulns', description: 'Analyze vulnerabilities and prioritize', domain: 'security', category: 'analysis', tools: ['Read'], dependencies: ['scan'], status: 'pending' },
|
|
392
|
+
{ id: 'document-findings', description: 'Document security findings', domain: 'security', category: 'generation', tools: ['Write'], dependencies: ['analyze-vulns'], status: 'pending' },
|
|
393
|
+
{ id: 'recommend-fixes', description: 'Recommend remediation steps', domain: 'security', category: 'communication', tools: [], dependencies: ['analyze-vulns'], status: 'pending' }
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
generateDefenseTasks(prompt) {
|
|
397
|
+
const lower = prompt.toLowerCase();
|
|
398
|
+
// Drone coordination systems
|
|
399
|
+
if (/drone\s*coordination|fighter\s*drone|6th\s*gen/i.test(lower)) {
|
|
400
|
+
return [
|
|
401
|
+
{ id: 'analyze-requirements', description: 'Analyze coordination system requirements', domain: 'defense', category: 'analysis', tools: ['Read'], dependencies: [], status: 'pending' },
|
|
402
|
+
{ id: 'design-architecture', description: 'Design swarm coordination architecture', domain: 'defense', category: 'analysis', tools: ['Write'], dependencies: ['analyze-requirements'], status: 'pending' },
|
|
403
|
+
{ id: 'implement-protocols', description: 'Implement communication protocols', domain: 'defense', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['design-architecture'], status: 'pending' },
|
|
404
|
+
{ id: 'build-simulation', description: 'Build coordination simulation', domain: 'defense', category: 'generation', tools: ['Write', 'Bash'], dependencies: ['implement-protocols'], status: 'pending' },
|
|
405
|
+
{ id: 'implement-algorithms', description: 'Implement decision algorithms', domain: 'defense', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['design-architecture'], status: 'pending' },
|
|
406
|
+
{ id: 'test-system', description: 'Test coordination system', domain: 'defense', category: 'verification', tools: ['Bash'], dependencies: ['build-simulation', 'implement-algorithms'], status: 'pending' }
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
// Ballistic/reentry vehicle systems
|
|
410
|
+
if (/ballistic|reentry|mrv|mirv|hypersonic|maneuverable/i.test(lower)) {
|
|
411
|
+
return [
|
|
412
|
+
{ id: 'analyze-requirements', description: 'Analyze targeting system requirements', domain: 'defense', category: 'analysis', tools: ['Read'], dependencies: [], status: 'pending' },
|
|
413
|
+
{ id: 'design-network', description: 'Design informational network architecture', domain: 'defense', category: 'analysis', tools: ['Write'], dependencies: ['analyze-requirements'], status: 'pending' },
|
|
414
|
+
{ id: 'implement-tracking', description: 'Implement target tracking algorithms', domain: 'defense', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['design-network'], status: 'pending' },
|
|
415
|
+
{ id: 'implement-prediction', description: 'Implement trajectory prediction', domain: 'defense', category: 'computation', tools: ['Write', 'Bash'], dependencies: ['implement-tracking'], status: 'pending' },
|
|
416
|
+
{ id: 'build-coordination', description: 'Build coordination layer for mobile targets', domain: 'defense', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['implement-prediction'], status: 'pending' },
|
|
417
|
+
{ id: 'validate-system', description: 'Validate targeting accuracy', domain: 'defense', category: 'verification', tools: ['Bash'], dependencies: ['build-coordination'], status: 'pending' }
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
// General defense systems
|
|
421
|
+
return [
|
|
422
|
+
{ id: 'analyze-requirements', description: 'Analyze defense system requirements', domain: 'defense', category: 'analysis', tools: ['Read', 'WebSearch'], dependencies: [], status: 'pending' },
|
|
423
|
+
{ id: 'design-system', description: 'Design system architecture', domain: 'defense', category: 'analysis', tools: ['Write'], dependencies: ['analyze-requirements'], status: 'pending' },
|
|
424
|
+
{ id: 'implement-core', description: 'Implement core functionality', domain: 'defense', category: 'generation', tools: ['Write', 'Edit'], dependencies: ['design-system'], status: 'pending' },
|
|
425
|
+
{ id: 'build-simulation', description: 'Build simulation environment', domain: 'defense', category: 'generation', tools: ['Write', 'Bash'], dependencies: ['implement-core'], status: 'pending' },
|
|
426
|
+
{ id: 'validate', description: 'Validate system performance', domain: 'defense', category: 'verification', tools: ['Bash'], dependencies: ['build-simulation'], status: 'pending' }
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
generateGeneralTasks(prompt) {
|
|
430
|
+
return [
|
|
431
|
+
{ id: 'understand', description: 'Understand the request and context', domain: 'general', category: 'analysis', tools: ['Glob', 'Read'], dependencies: [], status: 'pending' },
|
|
432
|
+
{ id: 'execute', description: 'Execute the requested task', domain: 'general', category: 'execution', tools: ['Bash', 'Edit'], dependencies: ['understand'], status: 'pending' },
|
|
433
|
+
{ id: 'verify', description: 'Verify task completion', domain: 'general', category: 'verification', tools: ['Bash', 'Read'], dependencies: ['execute'], status: 'pending' }
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
// ==========================================================================
|
|
437
|
+
// TOOL CALL GENERATION
|
|
438
|
+
// ==========================================================================
|
|
439
|
+
generateToolCalls(tasks, domain) {
|
|
440
|
+
const calls = [];
|
|
441
|
+
const knowledge = this.context.memory.projectKnowledge;
|
|
442
|
+
for (const task of tasks) {
|
|
443
|
+
for (const tool of task.tools) {
|
|
444
|
+
const spec = this.createToolCallSpec(tool, task, knowledge, domain);
|
|
445
|
+
if (spec)
|
|
446
|
+
calls.push(spec);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return calls;
|
|
450
|
+
}
|
|
451
|
+
createToolCallSpec(tool, task, knowledge, domain) {
|
|
452
|
+
switch (tool) {
|
|
453
|
+
case 'Bash':
|
|
454
|
+
return this.createBashSpec(task, knowledge, domain);
|
|
455
|
+
case 'Grep':
|
|
456
|
+
return this.createGrepSpec(task, domain);
|
|
457
|
+
case 'Glob':
|
|
458
|
+
return this.createGlobSpec(task, domain);
|
|
459
|
+
case 'Read':
|
|
460
|
+
return { tool: 'Read', args: { file_path: this.inferFilePath(task) }, description: task.description, taskId: task.id };
|
|
461
|
+
case 'Edit':
|
|
462
|
+
case 'Write':
|
|
463
|
+
return { tool, args: { file_path: this.inferFilePath(task) }, description: task.description, taskId: task.id };
|
|
464
|
+
case 'WebSearch':
|
|
465
|
+
return { tool: 'WebSearch', args: { query: this.inferSearchQuery(task) }, description: task.description, taskId: task.id };
|
|
466
|
+
default:
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
createBashSpec(task, knowledge, domain) {
|
|
471
|
+
const id = task.id.toLowerCase();
|
|
472
|
+
const desc = task.description.toLowerCase();
|
|
473
|
+
// Software domain commands
|
|
474
|
+
if (domain === 'software' || domain === 'devops') {
|
|
475
|
+
if (id.includes('lint') || desc.includes('lint')) {
|
|
476
|
+
return { tool: 'Bash', args: { command: knowledge.lintCommand || 'npm run lint 2>&1 || true', description: 'Run linter' }, description: task.description, taskId: task.id };
|
|
477
|
+
}
|
|
478
|
+
if (id.includes('type') || desc.includes('type')) {
|
|
479
|
+
return { tool: 'Bash', args: { command: 'npx tsc --noEmit 2>&1 || true', description: 'Type check' }, description: task.description, taskId: task.id };
|
|
480
|
+
}
|
|
481
|
+
if (id.includes('test') || desc.includes('test')) {
|
|
482
|
+
return { tool: 'Bash', args: { command: knowledge.testCommand || 'npm test 2>&1 || true', description: 'Run tests' }, description: task.description, taskId: task.id };
|
|
483
|
+
}
|
|
484
|
+
if (id.includes('audit') || desc.includes('audit')) {
|
|
485
|
+
return { tool: 'Bash', args: { command: 'npm audit 2>&1 || true', description: 'Security audit' }, description: task.description, taskId: task.id };
|
|
486
|
+
}
|
|
487
|
+
if (id.includes('build') || desc.includes('build')) {
|
|
488
|
+
return { tool: 'Bash', args: { command: knowledge.buildSystem || 'npm run build 2>&1 || true', description: 'Build project' }, description: task.description, taskId: task.id };
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// Data science / research commands
|
|
492
|
+
if (domain === 'data_science' || domain === 'research' || domain === 'scientific_computing') {
|
|
493
|
+
if (desc.includes('model') || desc.includes('train')) {
|
|
494
|
+
return { tool: 'Bash', args: { command: 'python -m pytest tests/ 2>&1 || python train.py 2>&1 || true', description: 'Train model' }, description: task.description, taskId: task.id };
|
|
495
|
+
}
|
|
496
|
+
if (desc.includes('visualization') || desc.includes('chart')) {
|
|
497
|
+
return { tool: 'Bash', args: { command: 'python visualize.py 2>&1 || jupyter nbconvert --execute analysis.ipynb 2>&1 || true', description: 'Generate visualizations' }, description: task.description, taskId: task.id };
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// Defense/simulation commands
|
|
501
|
+
if (domain === 'defense') {
|
|
502
|
+
if (desc.includes('simulation') || desc.includes('test')) {
|
|
503
|
+
return { tool: 'Bash', args: { command: 'npm test 2>&1 || python -m pytest 2>&1 || true', description: 'Run simulation tests' }, description: task.description, taskId: task.id };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
createGrepSpec(task, domain) {
|
|
509
|
+
const desc = task.description.toLowerCase();
|
|
510
|
+
if (desc.includes('todo') || desc.includes('fixme') || desc.includes('issue')) {
|
|
511
|
+
return { tool: 'Grep', args: { pattern: 'TODO|FIXME|BUG|HACK|XXX', output_mode: 'content' }, description: task.description, taskId: task.id };
|
|
512
|
+
}
|
|
513
|
+
if (desc.includes('security') || desc.includes('unsafe')) {
|
|
514
|
+
return { tool: 'Grep', args: { pattern: 'eval\\(|exec\\(|innerHTML|dangerouslySetInnerHTML|password|secret|api[_-]?key', output_mode: 'content' }, description: task.description, taskId: task.id };
|
|
515
|
+
}
|
|
516
|
+
return { tool: 'Grep', args: { pattern: '.*', output_mode: 'files_with_matches' }, description: task.description, taskId: task.id };
|
|
517
|
+
}
|
|
518
|
+
createGlobSpec(task, domain) {
|
|
519
|
+
const patterns = {
|
|
520
|
+
software: 'src/**/*.{ts,js,tsx,jsx}',
|
|
521
|
+
data_science: '**/*.{py,ipynb}',
|
|
522
|
+
research: '**/*.{py,md,ipynb}',
|
|
523
|
+
scientific_computing: '**/*.{py,m,jl}',
|
|
524
|
+
legal: '**/*.{md,txt,docx}',
|
|
525
|
+
business: '**/*.{md,txt,csv,xlsx}',
|
|
526
|
+
finance: '**/*.{xlsx,csv,py}',
|
|
527
|
+
automation: '**/*.{sh,py,yaml,yml}',
|
|
528
|
+
devops: '**/*.{yaml,yml,Dockerfile,tf}',
|
|
529
|
+
monitoring: '**/*.{yaml,yml,json}',
|
|
530
|
+
security: '**/*.{ts,js,py,sh}',
|
|
531
|
+
defense: '**/*.{ts,js,py,rs,cpp}',
|
|
532
|
+
general: '**/*',
|
|
533
|
+
};
|
|
534
|
+
return { tool: 'Glob', args: { pattern: patterns[domain] || '**/*' }, description: task.description, taskId: task.id };
|
|
535
|
+
}
|
|
536
|
+
inferFilePath(task) {
|
|
537
|
+
// Smart file path inference based on task
|
|
538
|
+
if (task.domain === 'software')
|
|
539
|
+
return 'package.json';
|
|
540
|
+
if (task.domain === 'devops')
|
|
541
|
+
return '.github/workflows/ci.yml';
|
|
542
|
+
if (task.domain === 'data_science')
|
|
543
|
+
return 'analysis.py';
|
|
544
|
+
if (task.domain === 'legal')
|
|
545
|
+
return 'complaint.md';
|
|
546
|
+
if (task.domain === 'finance')
|
|
547
|
+
return 'financial_report.md';
|
|
548
|
+
return 'README.md';
|
|
549
|
+
}
|
|
550
|
+
inferSearchQuery(task) {
|
|
551
|
+
if (task.domain === 'legal')
|
|
552
|
+
return `${task.description} legal precedent case law`;
|
|
553
|
+
if (task.domain === 'research')
|
|
554
|
+
return `${task.description} research papers`;
|
|
555
|
+
return task.description;
|
|
556
|
+
}
|
|
557
|
+
// ==========================================================================
|
|
558
|
+
// AMBIGUITY DETECTION
|
|
559
|
+
// ==========================================================================
|
|
560
|
+
checkAmbiguity(prompt, domain) {
|
|
561
|
+
const questions = [];
|
|
562
|
+
const lower = prompt.toLowerCase();
|
|
563
|
+
if (/all|everything|entire|whole/i.test(lower)) {
|
|
564
|
+
questions.push('The request has broad scope. Should I focus on specific areas first?');
|
|
565
|
+
}
|
|
566
|
+
if (domain === 'software' && !/specific|file|function|module/i.test(lower)) {
|
|
567
|
+
questions.push('Are there specific files or modules to prioritize?');
|
|
568
|
+
}
|
|
569
|
+
if (domain === 'legal' && !/jurisdiction|court|state|federal/i.test(lower)) {
|
|
570
|
+
questions.push('What jurisdiction should this be filed in?');
|
|
571
|
+
}
|
|
572
|
+
if (domain === 'finance' && !/period|year|quarter/i.test(lower)) {
|
|
573
|
+
questions.push('What time period should this cover?');
|
|
574
|
+
}
|
|
575
|
+
return questions;
|
|
576
|
+
}
|
|
577
|
+
// ==========================================================================
|
|
578
|
+
// LEARNING
|
|
579
|
+
// ==========================================================================
|
|
580
|
+
learnFromSuccess(prompt, approach, tools, domain) {
|
|
581
|
+
const existing = this.context.memory.patterns.find(p => this.normalizePrompt(p.trigger) === this.normalizePrompt(prompt));
|
|
582
|
+
if (existing) {
|
|
583
|
+
existing.successCount++;
|
|
584
|
+
existing.lastUsed = Date.now();
|
|
585
|
+
existing.approach = approach;
|
|
586
|
+
existing.tools = tools;
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
this.context.memory.patterns.push({
|
|
590
|
+
id: `pattern-${Date.now()}`,
|
|
591
|
+
trigger: prompt,
|
|
592
|
+
approach,
|
|
593
|
+
tools,
|
|
594
|
+
domain,
|
|
595
|
+
successCount: 1,
|
|
596
|
+
lastUsed: Date.now(),
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
this.context.memory.patterns = this.context.memory.patterns
|
|
600
|
+
.sort((a, b) => (b.successCount * 0.7 + (b.lastUsed - a.lastUsed) / 86400000 * 0.3) -
|
|
601
|
+
(a.successCount * 0.7 + (a.lastUsed - b.lastUsed) / 86400000 * 0.3))
|
|
602
|
+
.slice(0, 100);
|
|
603
|
+
this.saveMemory();
|
|
604
|
+
}
|
|
605
|
+
recordOperation(op) {
|
|
606
|
+
this.context.memory.recentOps.unshift(op);
|
|
607
|
+
this.context.memory.recentOps = this.context.memory.recentOps.slice(0, 50);
|
|
608
|
+
this.saveMemory();
|
|
609
|
+
}
|
|
610
|
+
getLearnedApproach(prompt) {
|
|
611
|
+
const normalized = this.normalizePrompt(prompt);
|
|
612
|
+
return this.context.memory.patterns.find(p => this.normalizePrompt(p.trigger) === normalized ||
|
|
613
|
+
this.promptSimilarity(p.trigger, prompt) > 0.7) || null;
|
|
614
|
+
}
|
|
615
|
+
normalizePrompt(prompt) {
|
|
616
|
+
return prompt.toLowerCase().trim().replace(/[^\w\s]/g, '');
|
|
617
|
+
}
|
|
618
|
+
promptSimilarity(a, b) {
|
|
619
|
+
const wordsA = new Set(this.normalizePrompt(a).split(/\s+/));
|
|
620
|
+
const wordsB = new Set(this.normalizePrompt(b).split(/\s+/));
|
|
621
|
+
const intersection = new Set([...wordsA].filter(x => wordsB.has(x)));
|
|
622
|
+
const union = new Set([...wordsA, ...wordsB]);
|
|
623
|
+
return intersection.size / union.size;
|
|
624
|
+
}
|
|
625
|
+
createFromLearnedPattern(prompt, pattern) {
|
|
626
|
+
return {
|
|
627
|
+
originalPrompt: prompt,
|
|
628
|
+
interpretation: `Using learned approach: ${pattern.approach}`,
|
|
629
|
+
domain: pattern.domain,
|
|
630
|
+
confidence: 0.95,
|
|
631
|
+
tasks: pattern.tools.map((tool, i) => ({
|
|
632
|
+
id: `learned-${i}`,
|
|
633
|
+
description: `Execute ${tool} based on learned pattern`,
|
|
634
|
+
domain: pattern.domain,
|
|
635
|
+
category: 'execution',
|
|
636
|
+
tools: [tool],
|
|
637
|
+
dependencies: i > 0 ? [`learned-${i - 1}`] : [],
|
|
638
|
+
status: 'pending',
|
|
639
|
+
})),
|
|
640
|
+
toolCalls: pattern.tools.map((tool, i) => ({
|
|
641
|
+
tool,
|
|
642
|
+
args: {},
|
|
643
|
+
description: `Learned pattern step ${i + 1}`,
|
|
644
|
+
taskId: `learned-${i}`,
|
|
645
|
+
})),
|
|
646
|
+
clarificationNeeded: [],
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
// ==========================================================================
|
|
650
|
+
// PUBLIC API
|
|
651
|
+
// ==========================================================================
|
|
652
|
+
getContext() {
|
|
653
|
+
return this.context;
|
|
654
|
+
}
|
|
655
|
+
getProjectKnowledge() {
|
|
656
|
+
return this.context.memory.projectKnowledge;
|
|
657
|
+
}
|
|
658
|
+
getRecentOperations(limit = 10) {
|
|
659
|
+
return this.context.memory.recentOps.slice(0, limit);
|
|
660
|
+
}
|
|
661
|
+
getLearnedPatterns() {
|
|
662
|
+
return this.context.memory.patterns;
|
|
663
|
+
}
|
|
664
|
+
getDomainCapabilities() {
|
|
665
|
+
return this.context.domain.domainCapabilities;
|
|
666
|
+
}
|
|
667
|
+
refreshProjectKnowledge() {
|
|
668
|
+
this.analyzeProject();
|
|
669
|
+
return this.context.memory.projectKnowledge;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
// ============================================================================
|
|
673
|
+
// SINGLETON
|
|
674
|
+
// ============================================================================
|
|
675
|
+
let instance = null;
|
|
676
|
+
export function getUnifiedAGI(workingDir) {
|
|
677
|
+
if (!instance || (workingDir && workingDir !== instance.getContext().workingDir)) {
|
|
678
|
+
instance = new UnifiedAGI(workingDir);
|
|
679
|
+
}
|
|
680
|
+
return instance;
|
|
681
|
+
}
|
|
682
|
+
export function resetUnifiedAGI() {
|
|
683
|
+
instance = null;
|
|
684
|
+
}
|
|
685
|
+
//# sourceMappingURL=unifiedAGI.js.map
|