Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions data/community-patterns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{ "id": "cp_001", "commandRegex": "^git push", "errorRegex": "Updates were rejected because the tip of your current branch is behind", "os": [], "shell": [], "fix": "git pull --rebase && git push", "confidence": 0.9 },
{ "id": "cp_002", "commandRegex": "^npm install", "errorRegex": "npm ERR! code ERESOLVE", "os": [], "shell": [], "fix": "npm install --legacy-peer-deps", "confidence": 0.8 },
{ "id": "cp_003", "commandRegex": "^npm install", "errorRegex": "npm ERR! cb() never called", "os": [], "shell": [], "fix": "npm cache clean --force && npm install", "confidence": 0.7 },
{ "id": "cp_004", "commandRegex": "^docker build", "errorRegex": "failed to solve: rpc error: code = Unknown", "os": [], "shell": [], "fix": "docker builder prune -f && docker build .", "confidence": 0.7 },
{ "id": "cp_005", "commandRegex": "^docker run", "errorRegex": "port is already allocated", "os": [], "shell": [], "fix": "docker ps -q | xargs docker stop", "confidence": 0.6 },
{ "id": "cp_006", "commandRegex": "^git commit", "errorRegex": "Please tell me who you are", "os": [], "shell": [], "fix": "git config --global user.email \"user@example.com\" && git config --global user.name \"User\"", "confidence": 0.8 },
{ "id": "cp_007", "commandRegex": "^node ", "errorRegex": "Cannot find module", "os": [], "shell": [], "fix": "npm install", "confidence": 0.7 },
{ "id": "cp_008", "commandRegex": "^python", "errorRegex": "ModuleNotFoundError: No module named", "os": [], "shell": [], "fix": "pip install -r requirements.txt", "confidence": 0.7 },
{ "id": "cp_009", "commandRegex": "^pip install", "errorRegex": "error: externally-managed-environment", "os": ["linux"], "shell": [], "fix": "pip install --break-system-packages", "confidence": 0.5 },
{ "id": "cp_010", "commandRegex": "^curl", "errorRegex": "Could not resolve host", "os": [], "shell": [], "fix": "ping 8.8.8.8", "confidence": 0.5 },
{ "id": "cp_011", "commandRegex": "^make", "errorRegex": "missing separator", "os": [], "shell": [], "fix": "sed -i 's/^[ ]*/\\t/' Makefile", "confidence": 0.6 },
{ "id": "cp_012", "commandRegex": "^rm ", "errorRegex": "Directory not empty", "os": [], "shell": [], "fix": "rm -rf", "confidence": 0.7 },
{ "id": "cp_013", "commandRegex": "^chown", "errorRegex": "Operation not permitted", "os": [], "shell": [], "fix": "sudo chown", "confidence": 0.8 },
{ "id": "cp_014", "commandRegex": "^apt-get install", "errorRegex": "Could not open lock file", "os": ["linux"], "shell": [], "fix": "sudo rm /var/lib/dpkg/lock-frontend && sudo apt-get install", "confidence": 0.6 },
{ "id": "cp_015", "commandRegex": "^brew install", "errorRegex": "Another active Homebrew update process is already in progress", "os": ["darwin"], "shell": [], "fix": "rm -rf $(brew --prefix)/var/homebrew/locks", "confidence": 0.7 },
{ "id": "cp_016", "commandRegex": "^composer install", "errorRegex": "Allowed memory size of", "os": [], "shell": [], "fix": "COMPOSER_MEMORY_LIMIT=-1 composer install", "confidence": 0.9 },
{ "id": "cp_017", "commandRegex": "^yarn install", "errorRegex": "There appears to be trouble with your network connection", "os": [], "shell": [], "fix": "yarn config set network-timeout 600000 -g && yarn install", "confidence": 0.8 },
{ "id": "cp_018", "commandRegex": "^go get", "errorRegex": "module declares its path as", "os": [], "shell": [], "fix": "go mod tidy", "confidence": 0.7 },
{ "id": "cp_019", "commandRegex": "^cargo build", "errorRegex": "failed to download", "os": [], "shell": [], "fix": "cargo clean && cargo build", "confidence": 0.7 },
{ "id": "cp_020", "commandRegex": "^terraform init", "errorRegex": "Failed to query available provider packages", "os": [], "shell": [], "fix": "rm -rf .terraform && terraform init", "confidence": 0.8 },
{ "id": "cp_021", "commandRegex": "^kubectl get", "errorRegex": "connection refused", "os": [], "shell": [], "fix": "minikube start", "confidence": 0.6 },
{ "id": "cp_022", "commandRegex": "^git clone", "errorRegex": "Permission denied \\(publickey\\)", "os": [], "shell": [], "fix": "ssh-keygen -t rsa -b 4096", "confidence": 0.5 },
{ "id": "cp_023", "commandRegex": "^ls", "errorRegex": "No such file or directory", "os": [], "shell": [], "fix": "pwd", "confidence": 0.4 },
{ "id": "cp_024", "commandRegex": "^cd", "errorRegex": "Not a directory", "os": [], "shell": [], "fix": "cat", "confidence": 0.3 },
{ "id": "cp_025", "commandRegex": "^vim", "errorRegex": "command not found", "os": ["linux"], "shell": [], "fix": "sudo apt install vim", "confidence": 0.8 },
{ "id": "cp_026", "commandRegex": "^nano", "errorRegex": "command not found", "os": ["linux"], "shell": [], "fix": "sudo apt install nano", "confidence": 0.8 },
{ "id": "cp_027", "commandRegex": "^tar", "errorRegex": "Not found in archive", "os": [], "shell": [], "fix": "tar -tvf", "confidence": 0.5 },
{ "id": "cp_028", "commandRegex": "^unzip", "errorRegex": "command not found", "os": ["linux"], "shell": [], "fix": "sudo apt install unzip", "confidence": 0.8 },
{ "id": "cp_029", "commandRegex": "^psql", "errorRegex": "role .* does not exist", "os": [], "shell": [], "fix": "createuser -s root", "confidence": 0.5 },
{ "id": "cp_030", "commandRegex": "^mysql", "errorRegex": "Access denied for user", "os": [], "shell": [], "fix": "mysql -u root -p", "confidence": 0.6 },
{ "id": "cp_031", "commandRegex": "^ssh", "errorRegex": "REMOTE HOST IDENTIFICATION HAS CHANGED", "os": [], "shell": [], "fix": "ssh-keygen -R", "confidence": 0.8 },
{ "id": "cp_032", "commandRegex": "^scp", "errorRegex": "Permission denied", "os": [], "shell": [], "fix": "chmod 400", "confidence": 0.6 },
{ "id": "cp_033", "commandRegex": "^systemctl", "errorRegex": "Failed to connect to bus", "os": ["linux"], "shell": [], "fix": "sudo systemctl", "confidence": 0.7 },
{ "id": "cp_034", "commandRegex": "^service", "errorRegex": "unrecognized service", "os": ["linux"], "shell": [], "fix": "systemctl status", "confidence": 0.6 },
{ "id": "cp_035", "commandRegex": "^journalctl", "errorRegex": "No journal files were found", "os": ["linux"], "shell": [], "fix": "sudo journalctl", "confidence": 0.7 },
{ "id": "cp_036", "commandRegex": "^nvm use", "errorRegex": "N/A: version .* is not yet installed", "os": [], "shell": [], "fix": "nvm install", "confidence": 0.9 },
{ "id": "cp_037", "commandRegex": "^rvm use", "errorRegex": "is not installed", "os": [], "shell": [], "fix": "rvm install", "confidence": 0.9 },
{ "id": "cp_038", "commandRegex": "^pyenv install", "errorRegex": "BUILD FAILED", "os": [], "shell": [], "fix": "sudo apt install build-essential libssl-dev zlib1g-dev", "confidence": 0.7 },
{ "id": "cp_039", "commandRegex": "^grep", "errorRegex": "invalid option", "os": [], "shell": [], "fix": "grep --help", "confidence": 0.5 },
{ "id": "cp_040", "commandRegex": "^find", "errorRegex": "paths must precede expression", "os": [], "shell": [], "fix": "find . -name", "confidence": 0.6 },
{ "id": "cp_041", "commandRegex": "^xargs", "errorRegex": "argument line too long", "os": [], "shell": [], "fix": "xargs -n 1", "confidence": 0.8 },
{ "id": "cp_042", "commandRegex": "^awk", "errorRegex": "syntax error", "os": [], "shell": [], "fix": "awk '{print $1}'", "confidence": 0.4 },
{ "id": "cp_043", "commandRegex": "^sed", "errorRegex": "unterminated `s' command", "os": [], "shell": [], "fix": "sed 's/foo/bar/g'", "confidence": 0.5 },
{ "id": "cp_044", "commandRegex": "^cat", "errorRegex": "Is a directory", "os": [], "shell": [], "fix": "ls -la", "confidence": 0.8 },
{ "id": "cp_045", "commandRegex": "^tail", "errorRegex": "cannot open .* for reading", "os": [], "shell": [], "fix": "sudo tail", "confidence": 0.7 },
{ "id": "cp_046", "commandRegex": "^less", "errorRegex": "No such file or directory", "os": [], "shell": [], "fix": "ls", "confidence": 0.6 },
{ "id": "cp_047", "commandRegex": "^chmod", "errorRegex": "invalid mode", "os": [], "shell": [], "fix": "chmod +x", "confidence": 0.7 },
{ "id": "cp_048", "commandRegex": "^ping", "errorRegex": "unknown host", "os": [], "shell": [], "fix": "cat /etc/resolv.conf", "confidence": 0.6 },
{ "id": "cp_049", "commandRegex": "^netstat", "errorRegex": "command not found", "os": ["linux"], "shell": [], "fix": "sudo apt install net-tools", "confidence": 0.8 },
{ "id": "cp_050", "commandRegex": "^ifconfig", "errorRegex": "command not found", "os": ["linux"], "shell": [], "fix": "ip a", "confidence": 0.9 }
]
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"dependencies": {
"@google/generative-ai": "^0.24.1",
"bash-parser": "^0.5.0",
"better-sqlite3": "^13.0.3",
"chalk": "^5.6.2",
"dotenv": "^17.2.3",
"groq-sdk": "^0.37.0",
Expand Down
55 changes: 55 additions & 0 deletions patch_advanced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from 'fs';

let content = fs.readFileSync('src/commands/advanced-session.js', 'utf8');

// Import TaxonomySystem
if (!content.includes('TaxonomySystem')) {
content = content.replace(
"import NamespacedVectorMemory from '../services/namespaced-memory.js';",
"import NamespacedVectorMemory from '../services/namespaced-memory.js';\nimport { TaxonomySystem } from '../services/taxonomy.js';"
);
}

// Instantiate
if (!content.includes('const taxonomy = new TaxonomySystem()')) {
content = content.replace(
"const memory = new NamespacedVectorMemory();",
"const memory = new NamespacedVectorMemory();\nconst taxonomy = new TaxonomySystem();\n// Load community patterns on startup if exists\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\ntaxonomy.loadCommunityPatterns(path.join(__dirname, '../../data/community-patterns.json'));"
);
}

// Update handleAutoHealingSafe
const healRegex = /async function handleAutoHealingSafe\(command, result\) \{\s*try \{\s*const errorMsg = result\.stderr \|\| 'Unknown error';/m;
if (content.match(healRegex)) {
const replacement = `async function handleAutoHealingSafe(command, result) {
try {
const errorMsg = result.stderr || 'Unknown error';

// 0. Taxonomy Pattern Check (Instant, Local, Proven)
const patternMatch = taxonomy.match(command, errorMsg);
if (patternMatch) {
console.log((await import('chalk')).default.green(\`\\n🛡️ Taxonomy Fix (Confidence \${Math.round(patternMatch.effectiveConfidence * 100)}%):\`));
console.log((await import('chalk')).default.bold(patternMatch.fix));

const inquirer = (await import('inquirer')).default;
const { confirm } = await inquirer.prompt([{
type: 'confirm', name: 'confirm', message: 'Execute?', default: true
}]);

if (confirm) {
try {
const output = await executeSystemCommand(patternMatch.fix, { cwd: SessionContext.getCwd() });
console.log(output);
taxonomy.updateConfidence(patternMatch.id, true);
} catch(e) {
console.log((await import('chalk')).default.red(\`Fix failed: \${e.message}\`));
taxonomy.updateConfidence(patternMatch.id, false);
}
}
return;
}
`;
content = content.replace(healRegex, replacement);
}

fs.writeFileSync('src/commands/advanced-session.js', content);
19 changes: 19 additions & 0 deletions patch_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'fs';

let content = fs.readFileSync('src/index.js', 'utf8');

const setupCommand = "if (cleanedArgs[0] === 'setup') {";
const newCommand = `if (cleanedArgs[0] === 'taxonomy') {
const { handleTaxonomyCommand } = await import('./commands/taxonomy.js');
await handleTaxonomyCommand(cleanedArgs.slice(1));
return;
}

if (cleanedArgs[0] === 'setup') {`;

if (content.includes(setupCommand) && !content.includes("cleanedArgs[0] === 'taxonomy'")) {
content = content.replace(setupCommand, newCommand);
fs.writeFileSync('src/index.js', content);
} else {
console.log("Could not find setup command block or already patched.");
}
45 changes: 45 additions & 0 deletions patch_index_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from 'fs';

let content = fs.readFileSync('src/index.js', 'utf8');

// Ensure TaxonomySystem is imported at the top if not already (it's in the same file so might be hard to patch at top, let's just inline import)
const searchStr = "console.log(chalk.yellow('\\n🤖 Nebula is analyzing the failure...'));\\n\\n try {";
const replacement = `console.log(chalk.yellow('\\n🤖 Nebula is analyzing the failure...'));

try {
// 0. Taxonomy Pattern Check
const { TaxonomySystem } = await import('./services/taxonomy.js');
const taxonomy = new TaxonomySystem();
const { fileURLToPath } = await import('url');
const path = await import('path');
const __dirname = path.dirname(fileURLToPath(import.meta.url));
taxonomy.loadCommunityPatterns(path.join(__dirname, '../data/community-patterns.json'));

const patternMatch = taxonomy.match(command, error.message);
if (patternMatch) {
console.log(chalk.green(\`\\n🛡️ Taxonomy Fix (Confidence \${Math.round(patternMatch.effectiveConfidence * 100)}%):\`));
console.log(chalk.bold(patternMatch.fix));

const { confirm } = await inquirer.prompt([{
type: 'confirm', name: 'confirm', message: 'Execute?', default: true
}]);

if (confirm) {
try {
const output = await executeSystemCommand(patternMatch.fix, { cwd: process.cwd(), dryRun: flags.dryRun });
console.log(output);
taxonomy.updateConfidence(patternMatch.id, true);
} catch(e) {
console.log(chalk.red(\`Fix failed: \${e.message}\`));
taxonomy.updateConfidence(patternMatch.id, false);
}
}
return;
}`;

if (content.match(/console\.log\(chalk\.yellow\('\\n🤖 Nebula is analyzing the failure\.\.\.'\)\);\s*try \{/)) {
content = content.replace(/console\.log\(chalk\.yellow\('\\n🤖 Nebula is analyzing the failure\.\.\.'\)\);\s*try \{/, replacement);
fs.writeFileSync('src/index.js', content);
} else {
console.log("Could not find the target string in index.js");
}
55 changes: 55 additions & 0 deletions patch_session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from 'fs';

let content = fs.readFileSync('src/commands/session.js', 'utf8');

// Import TaxonomySystem
if (!content.includes('TaxonomySystem')) {
content = content.replace(
"import NamespacedVectorMemory from '../services/namespaced-memory.js';",
"import NamespacedVectorMemory from '../services/namespaced-memory.js';\nimport { TaxonomySystem } from '../services/taxonomy.js';"
);
}

// Instantiate
if (!content.includes('const taxonomy = new TaxonomySystem()')) {
content = content.replace(
"const memory = new NamespacedVectorMemory();",
"const memory = new NamespacedVectorMemory();\nconst taxonomy = new TaxonomySystem();\n// Load community patterns on startup if exists\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\ntaxonomy.loadCommunityPatterns(path.join(__dirname, '../../data/community-patterns.json'));"
);
}

// Update handleAutoHealingSafe
const healRegex = /async function handleAutoHealingSafe\(command, result, rl\) \{\s*try \{\s*const errorMsg = result\.stderr \|\| 'Unknown error';/m;
if (content.match(healRegex)) {
const replacement = `async function handleAutoHealingSafe(command, result, rl) {
try {
const errorMsg = result.stderr || 'Unknown error';

// 0. Taxonomy Pattern Check (Instant, Local, Proven)
const patternMatch = taxonomy.match(command, errorMsg);
if (patternMatch) {
console.log((await import('chalk')).default.green(\`\\n🛡️ Taxonomy Fix (Confidence \${Math.round(patternMatch.effectiveConfidence * 100)}%):\`));
console.log((await import('chalk')).default.bold(patternMatch.fix));

const inquirer = (await import('inquirer')).default;
const { confirm } = await inquirer.prompt([{
type: 'confirm', name: 'confirm', message: 'Execute?', default: true
}]);

if (confirm) {
try {
const output = await executeSystemCommand(patternMatch.fix, { cwd: SessionContext.getCwd() });
console.log(output);
taxonomy.updateConfidence(patternMatch.id, true);
} catch(e) {
console.log((await import('chalk')).default.red(\`Fix failed: \${e.message}\`));
taxonomy.updateConfidence(patternMatch.id, false);
}
}
return;
}
`;
content = content.replace(healRegex, replacement);
}

fs.writeFileSync('src/commands/session.js', content);
Loading
Loading