evolinkai-debug-assistant 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Debug Assistant — npm installer
2
+
3
+ This package installs the Debug Assistant skill for OpenClaw / Claude Code.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npx evolinkai-debug-assistant
9
+ ```
10
+
11
+ ## What it does
12
+
13
+ Copies the Debug Assistant skill files into your project's `skills/` directory.
14
+
15
+ ## Links
16
+
17
+ - [ClawHub](https://clawhub.ai/evolinkai/debug-assistant)
18
+ - [GitHub](https://github.com/EvoLinkAI/debug-skill-for-openclaw)
package/bin/install.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const SLUG = "debug-assistant";
7
+ const VERSION = "1.0.0";
8
+ const SKILL_FILES_DIR = path.join(__dirname, "..", "skill-files");
9
+
10
+ function findWorkdir() {
11
+ const envDir = process.env.CLAWHUB_WORKDIR?.trim() || process.env.CLAWDHUB_WORKDIR?.trim();
12
+ if (envDir) return path.resolve(envDir);
13
+
14
+ let dir = process.cwd();
15
+ while (true) {
16
+ if (fs.existsSync(path.join(dir, ".clawhub")) || fs.existsSync(path.join(dir, ".clawdhub"))) {
17
+ return dir;
18
+ }
19
+ const parent = path.dirname(dir);
20
+ if (parent === dir) break;
21
+ dir = parent;
22
+ }
23
+ return process.cwd();
24
+ }
25
+
26
+ function copyDirSync(src, dest) {
27
+ fs.mkdirSync(dest, { recursive: true });
28
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
29
+ const srcPath = path.join(src, entry.name);
30
+ const destPath = path.join(dest, entry.name);
31
+ if (entry.isDirectory()) copyDirSync(srcPath, destPath);
32
+ else fs.copyFileSync(srcPath, destPath);
33
+ }
34
+ }
35
+
36
+ function updateLockfile(workdir) {
37
+ const lockDir = path.join(workdir, ".clawhub");
38
+ const lockFile = path.join(lockDir, "lock.json");
39
+ fs.mkdirSync(lockDir, { recursive: true });
40
+
41
+ let lock = { skills: {} };
42
+ if (fs.existsSync(lockFile)) {
43
+ try { lock = JSON.parse(fs.readFileSync(lockFile, "utf8")); if (!lock.skills) lock.skills = {}; }
44
+ catch { lock = { skills: {} }; }
45
+ }
46
+
47
+ lock.skills[SLUG] = { version: VERSION, installedAt: Date.now() };
48
+ fs.writeFileSync(lockFile, JSON.stringify(lock, null, 2) + "\n");
49
+ }
50
+
51
+ function writeOrigin(targetDir) {
52
+ fs.writeFileSync(path.join(targetDir, ".clawhub-origin.json"),
53
+ JSON.stringify({ version: 1, registry: "https://api.clawhub.ai", slug: SLUG, installedVersion: VERSION, installedAt: Date.now() }, null, 2) + "\n");
54
+ }
55
+
56
+ function main() {
57
+ console.log(`\n Debug Assistant — OpenClaw Skill Installer v${VERSION}`);
58
+ console.log(` Powered by evolink.ai\n`);
59
+
60
+ const workdir = findWorkdir();
61
+ const targetDir = path.join(workdir, "skills", SLUG);
62
+
63
+ if (fs.existsSync(targetDir)) {
64
+ console.log(` Already installed at: ${targetDir}`);
65
+ console.log(` Use "npx clawhub update ${SLUG}" to update.\n`);
66
+ process.exit(0);
67
+ }
68
+
69
+ console.log(` Installing to: ${targetDir}`);
70
+ copyDirSync(SKILL_FILES_DIR, targetDir);
71
+ writeOrigin(targetDir);
72
+ updateLockfile(workdir);
73
+ console.log(` Installed ${SLUG}@${VERSION}\n`);
74
+
75
+ console.log(" Next steps:");
76
+ console.log(" 1. export EVOLINK_API_KEY=\"your-key-here\"");
77
+ console.log(" Get a free key: https://evolink.ai/signup");
78
+ console.log(" 2. bash scripts/debug.sh analyze error.log");
79
+ console.log(" 3. bash scripts/debug.sh help");
80
+ console.log("");
81
+ }
82
+
83
+ main();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "evolinkai-debug-assistant",
3
+ "version": "1.0.0",
4
+ "description": "AI-powered debugging assistant. Analyze error logs, explain errors, parse stack traces, get fix suggestions. OpenClaw skill installer. Powered by evolink.ai",
5
+ "bin": {
6
+ "evolinkai-debug-assistant": "bin/install.js"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "skill-files/"
11
+ ],
12
+ "keywords": [
13
+ "openclaw",
14
+ "clawhub",
15
+ "debug",
16
+ "debugging",
17
+ "error",
18
+ "stacktrace",
19
+ "ai",
20
+ "claude",
21
+ "evolink",
22
+ "skill"
23
+ ],
24
+ "author": "EvoLinkAI <support@evolink.ai>",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/EvoLinkAI/debug-skill-for-openclaw"
29
+ },
30
+ "homepage": "https://clawhub.ai/evolinkai/debug-assistant"
31
+ }
@@ -0,0 +1,130 @@
1
+ ---
2
+ name: Debug Assistant
3
+ description: AI-powered debugging assistant. Analyze error logs, explain error messages, parse stack traces, and get fix suggestions with cheatsheets for 8 languages. Powered by evolink.ai
4
+ version: 1.0.0
5
+ homepage: https://github.com/EvoLinkAI/debug-skill-for-openclaw
6
+ metadata: {"openclaw":{"homepage":"https://github.com/EvoLinkAI/debug-skill-for-openclaw","requires":{"bins":["python3","curl"],"env":["EVOLINK_API_KEY"]},"primaryEnv":"EVOLINK_API_KEY"}}
7
+ ---
8
+
9
+ # Debug Assistant
10
+
11
+ AI-powered debugging from your terminal. Analyze error logs, explain error messages, parse stack traces, get fix suggestions, and access debugging cheatsheets for 8 languages.
12
+
13
+ Powered by [Evolink.ai](https://evolink.ai?utm_source=clawhub&utm_medium=skill&utm_campaign=debug)
14
+
15
+ ## When to Use
16
+
17
+ - User shares an error log and asks "what went wrong?"
18
+ - User pastes an error message and wants an explanation
19
+ - User has a stack trace and needs help understanding it
20
+ - User has buggy code and a known error, wants fix suggestions
21
+ - User needs quick debugging commands for a specific language
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Set your EvoLink API key
26
+
27
+ export EVOLINK_API_KEY="your-key-here"
28
+
29
+ Get a free key: [evolink.ai/signup](https://evolink.ai/signup?utm_source=clawhub&utm_medium=skill&utm_campaign=debug)
30
+
31
+ ### 2. Analyze an error
32
+
33
+ bash scripts/debug.sh analyze error.log
34
+
35
+ bash scripts/debug.sh explain "Cannot read property 'map' of undefined"
36
+
37
+ ### 3. Get a cheatsheet
38
+
39
+ bash scripts/debug.sh cheatsheet python
40
+
41
+ ## Capabilities
42
+
43
+ ### AI Commands (require EVOLINK_API_KEY)
44
+
45
+ | Command | Description |
46
+ |---------|-------------|
47
+ | `analyze <file>` | Analyze error log — summary, root cause, error chain, fix steps |
48
+ | `explain <error_message>` | Explain error — meaning, common causes, quick fix, proper fix |
49
+ | `trace <file>` | Parse stack trace — origin, call chain, root cause, fix |
50
+ | `suggest <file> --error <msg>` | Fix suggestions — bug location, why it fails, corrected code |
51
+
52
+ ### Info Commands (no API key needed)
53
+
54
+ | Command | Description |
55
+ |---------|-------------|
56
+ | `languages` | List all supported languages |
57
+ | `cheatsheet [language]` | Debugging commands and common errors |
58
+
59
+ ### Supported Languages
60
+
61
+ | Language | Debugger | Key Tools |
62
+ |----------|----------|-----------|
63
+ | `javascript` | Node --inspect, Chrome DevTools | console.trace, memory profiling |
64
+ | `python` | pdb, breakpoint() | tracemalloc, cProfile |
65
+ | `go` | Delve | -race flag, pprof |
66
+ | `rust` | rust-gdb, rust-lldb | RUST_BACKTRACE, env_logger |
67
+ | `java` | Remote JDWP | jmap, jstack, GC logging |
68
+ | `network` | curl -v, dig | lsof, netstat, ss |
69
+ | `css` | Outline trick | Grid/Flex inspectors |
70
+ | `git` | git bisect | Automated bisect with test scripts |
71
+
72
+ ## Examples
73
+
74
+ ### Analyze an error log
75
+
76
+ bash scripts/debug.sh analyze server-crash.log
77
+
78
+ Output:
79
+
80
+ **Error Summary:** Node.js process crashed due to unhandled promise rejection
81
+ in the database connection pool.
82
+
83
+ **Root Cause:** The PostgreSQL connection string contains an expired SSL
84
+ certificate path, causing all new connections to fail silently...
85
+
86
+ **Fix Steps:**
87
+ 1. Update the SSL certificate at /etc/ssl/certs/db.pem
88
+ 2. ...
89
+
90
+ ### Explain an error message
91
+
92
+ bash scripts/debug.sh explain "ECONNREFUSED 127.0.0.1:5432"
93
+
94
+ ### Parse a stack trace
95
+
96
+ bash scripts/debug.sh trace crash-dump.txt
97
+
98
+ ### Suggest fixes for buggy code
99
+
100
+ bash scripts/debug.sh suggest api/handler.py --error "KeyError: 'user_id'"
101
+
102
+ ## Configuration
103
+
104
+ | Variable | Default | Required | Description |
105
+ |---|---|---|---|
106
+ | `EVOLINK_API_KEY` | — | Yes | Your EvoLink API key. [Get one free](https://evolink.ai/signup?utm_source=clawhub&utm_medium=skill&utm_campaign=debug) |
107
+ | `EVOLINK_MODEL` | `claude-opus-4-6` | No | Model for AI analysis |
108
+
109
+ Required binaries: `python3`, `curl`
110
+
111
+ ## Security
112
+
113
+ **Data Transmission**
114
+
115
+ AI commands send user-provided content (error logs, messages, code files) to `api.evolink.ai` for analysis by Claude. By setting `EVOLINK_API_KEY` and using these commands, you consent to this transmission. Data is not stored after the response is returned. The `languages` and `cheatsheet` commands run entirely locally and never transmit data.
116
+
117
+ **Network Access**
118
+
119
+ - `api.evolink.ai` — AI error analysis (AI commands only)
120
+
121
+ **Persistence & Privilege**
122
+
123
+ This skill creates temporary files for API payload construction which are cleaned up automatically. No credentials or persistent data are stored. The skill only reads files explicitly passed as arguments — it never scans or reads files on its own.
124
+
125
+ ## Links
126
+
127
+ - [GitHub](https://github.com/EvoLinkAI/debug-skill-for-openclaw)
128
+ - [EvoLink API](https://docs.evolink.ai/en/api-manual/language-series/claude/claude-messages-api?utm_source=clawhub&utm_medium=skill&utm_campaign=debug)
129
+ - [Community](https://discord.com/invite/5mGHfA24kn)
130
+ - [Support](mailto:support@evolink.ai)
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "Debug Assistant",
3
+ "version": "1.0.0",
4
+ "description": "AI-powered debugging assistant. Analyze error logs, explain error messages, parse stack traces, and get fix suggestions. Includes cheatsheets for 8 languages. Powered by evolink.ai",
5
+ "author": "EvoLinkAI",
6
+ "license": "MIT",
7
+ "type": "tool",
8
+ "requiredFiles": [],
9
+ "requiredEnvVars": ["EVOLINK_API_KEY"],
10
+ "optionalEnvVars": ["EVOLINK_MODEL"],
11
+ "requiredBinaries": ["python3", "curl"],
12
+ "externalServices": [
13
+ "api.evolink.ai"
14
+ ],
15
+ "dataTransmission": {
16
+ "api.evolink.ai": "AI commands (analyze, explain, trace, suggest) send user-provided error logs, messages, or code to api.evolink.ai for analysis by Claude. No data is stored after the response is returned. Info commands (languages, cheatsheet) run locally and never transmit data."
17
+ }
18
+ }
@@ -0,0 +1,460 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Debug Assistant — AI-powered debugging for error logs, stack traces, and code
5
+ # Usage: bash debug.sh <command> [options]
6
+ #
7
+ # Commands:
8
+ # languages — List supported languages
9
+ # cheatsheet [language] — Quick debugging commands
10
+ # analyze <file> — AI analyze error log file
11
+ # explain <error_message> — AI explain an error message
12
+ # trace <file> — AI parse and explain stack trace
13
+ # suggest <file> --error <message> — AI suggest fixes for code with error
14
+
15
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16
+ EVOLINK_API="https://api.evolink.ai/v1/messages"
17
+
18
+ # --- Helpers ---
19
+ err() { echo "Error: $*" >&2; exit 1; }
20
+
21
+ to_native_path() {
22
+ if [[ "$1" =~ ^/([a-zA-Z])/ ]]; then
23
+ echo "${BASH_REMATCH[1]}:/${1:3}"
24
+ else
25
+ echo "$1"
26
+ fi
27
+ }
28
+
29
+ check_deps() {
30
+ command -v python3 &>/dev/null || err "python3 not found."
31
+ command -v curl &>/dev/null || err "curl not found."
32
+ }
33
+
34
+ read_file() {
35
+ local file="$1"
36
+ [ -f "$file" ] || err "File not found: $file"
37
+ cat "$file"
38
+ }
39
+
40
+ evolink_ai() {
41
+ local prompt="$1"
42
+ local content="$2"
43
+
44
+ local api_key="${EVOLINK_API_KEY:?Set EVOLINK_API_KEY for AI features. Get one at https://evolink.ai/signup}"
45
+ local model="${EVOLINK_MODEL:-claude-opus-4-6}"
46
+
47
+ local tmp_prompt tmp_content tmp_payload
48
+ tmp_prompt=$(mktemp)
49
+ tmp_content=$(mktemp)
50
+ tmp_payload=$(mktemp)
51
+ trap "rm -f '$tmp_prompt' '$tmp_content' '$tmp_payload'" EXIT
52
+
53
+ printf '%s' "$prompt" > "$tmp_prompt"
54
+ printf '%s' "$content" > "$tmp_content"
55
+
56
+ local native_prompt native_content native_payload
57
+ native_prompt=$(to_native_path "$tmp_prompt")
58
+ native_content=$(to_native_path "$tmp_content")
59
+ native_payload=$(to_native_path "$tmp_payload")
60
+
61
+ python3 -c "
62
+ import json, sys
63
+
64
+ with open(sys.argv[1], 'r', encoding='utf-8') as f:
65
+ prompt = f.read()
66
+ with open(sys.argv[2], 'r', encoding='utf-8') as f:
67
+ content = f.read()
68
+
69
+ data = {
70
+ 'model': sys.argv[4],
71
+ 'max_tokens': 4096,
72
+ 'messages': [
73
+ {
74
+ 'role': 'user',
75
+ 'content': prompt + '\n\n' + content
76
+ }
77
+ ]
78
+ }
79
+ with open(sys.argv[3], 'w', encoding='utf-8') as f:
80
+ json.dump(data, f)
81
+ " "$native_prompt" "$native_content" "$native_payload" "$model"
82
+
83
+ local response
84
+ response=$(curl -s -X POST "$EVOLINK_API" \
85
+ -H "Authorization: Bearer $api_key" \
86
+ -H "Content-Type: application/json" \
87
+ -d "@$tmp_payload")
88
+
89
+ echo "$response" | python3 -c "
90
+ import json, sys
91
+ data = json.load(sys.stdin)
92
+ if 'content' in data:
93
+ for block in data['content']:
94
+ if block.get('type') == 'text':
95
+ print(block['text'])
96
+ elif 'error' in data:
97
+ print(f\"AI Error: {data['error'].get('message', str(data['error']))}\", file=sys.stderr)
98
+ else:
99
+ print(json.dumps(data, indent=2))
100
+ "
101
+ }
102
+
103
+ # --- Cheatsheets ---
104
+
105
+ cheatsheet_js() {
106
+ cat <<'EOF'
107
+ JavaScript / TypeScript Debugging:
108
+
109
+ # Node.js debugger
110
+ node --inspect-brk app.js
111
+ # Then open chrome://inspect
112
+
113
+ # Console debugging
114
+ console.log(JSON.stringify(obj, null, 2))
115
+ console.trace('Call stack here')
116
+ console.time('perf'); /* code */ console.timeEnd('perf')
117
+
118
+ # Memory leaks
119
+ node --expose-gc --max-old-space-size=4096 app.js
120
+
121
+ # Common errors:
122
+ Cannot read property of undefined → Add optional chaining (?.) or validate data
123
+ Module not found → npm install, check tsconfig paths
124
+ Hydration mismatch (React) → Ensure consistent SSR/CSR, use useEffect
125
+ EOF
126
+ }
127
+
128
+ cheatsheet_python() {
129
+ cat <<'EOF'
130
+ Python Debugging:
131
+
132
+ # Built-in debugger
133
+ python -m pdb script.py
134
+
135
+ # Breakpoint in code (Python 3.7+)
136
+ breakpoint()
137
+
138
+ # Memory tracing
139
+ python -X tracemalloc script.py
140
+
141
+ # Profiling
142
+ python -m cProfile -s cumulative script.py
143
+
144
+ # Common errors:
145
+ IndexError: list index out of range → Check list length before access
146
+ KeyError → Use dict.get(key, default)
147
+ ImportError / ModuleNotFoundError → pip install, check sys.path
148
+ TypeError: NoneType → Function returning None unexpectedly
149
+ EOF
150
+ }
151
+
152
+ cheatsheet_go() {
153
+ cat <<'EOF'
154
+ Go Debugging:
155
+
156
+ # Delve debugger
157
+ dlv debug main.go
158
+ (dlv) break main.main
159
+ (dlv) continue
160
+ (dlv) print myVar
161
+ (dlv) goroutines
162
+
163
+ # Race condition detection
164
+ go run -race main.go
165
+ go test -race ./...
166
+
167
+ # Profiling
168
+ go test -cpuprofile cpu.prof -memprofile mem.prof -bench .
169
+ go tool pprof cpu.prof
170
+
171
+ # Common errors:
172
+ nil pointer dereference → Check nil before accessing struct fields
173
+ deadlock → Review goroutine/channel usage, use -race
174
+ cannot use X as type Y → Check interface implementation
175
+ EOF
176
+ }
177
+
178
+ cheatsheet_rust() {
179
+ cat <<'EOF'
180
+ Rust Debugging:
181
+
182
+ # GDB / LLDB
183
+ rust-gdb target/debug/myapp
184
+ rust-lldb target/debug/myapp
185
+
186
+ # Verbose compiler output
187
+ RUST_BACKTRACE=1 cargo run
188
+ RUST_BACKTRACE=full cargo run
189
+
190
+ # Logging
191
+ RUST_LOG=debug cargo run # requires env_logger
192
+
193
+ # Common errors:
194
+ borrow checker errors → Review ownership, use clone() or Rc/Arc
195
+ cannot move out of borrowed → Use references or .clone()
196
+ thread 'main' panicked → Check unwrap() calls, use match/if let
197
+ EOF
198
+ }
199
+
200
+ cheatsheet_java() {
201
+ cat <<'EOF'
202
+ Java Debugging:
203
+
204
+ # Remote debugging
205
+ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar app.jar
206
+
207
+ # Heap dump
208
+ jmap -dump:format=b,file=heap.hprof <pid>
209
+
210
+ # Thread dump
211
+ jstack <pid>
212
+
213
+ # GC logging
214
+ java -Xlog:gc*:file=gc.log -jar app.jar
215
+
216
+ # Common errors:
217
+ NullPointerException → Null check or use Optional
218
+ ClassNotFoundException → Check classpath, dependency versions
219
+ OutOfMemoryError → Increase -Xmx, check for leaks
220
+ ConcurrentModificationException → Use Iterator.remove() or CopyOnWriteArrayList
221
+ EOF
222
+ }
223
+
224
+ cheatsheet_network() {
225
+ cat <<'EOF'
226
+ Network Debugging:
227
+
228
+ # HTTP debugging
229
+ curl -v https://api.example.com/endpoint
230
+ curl -w "time_total: %{time_total}s\n" -o /dev/null -s https://example.com
231
+
232
+ # DNS
233
+ dig example.com
234
+ nslookup example.com
235
+
236
+ # Ports
237
+ lsof -i :3000
238
+ netstat -tlnp
239
+
240
+ # TCP connections
241
+ ss -tunapl
242
+
243
+ # Common errors:
244
+ ECONNREFUSED → Service not running on expected port
245
+ CORS error → Backend missing CORS headers
246
+ ETIMEDOUT → Firewall, DNS, or service unreachable
247
+ SSL certificate → Check cert expiry, chain, hostname match
248
+ EOF
249
+ }
250
+
251
+ cheatsheet_css() {
252
+ cat <<'EOF'
253
+ CSS / Layout Debugging:
254
+
255
+ /* Outline all elements */
256
+ * { outline: 1px solid red !important; }
257
+
258
+ /* Debug specific element */
259
+ .debug { background: rgba(255,0,0,0.1) !important; }
260
+
261
+ /* Show overflow */
262
+ * { overflow: visible !important; }
263
+
264
+ Common issues:
265
+ Element not visible → Check display, visibility, opacity, z-index
266
+ Unexpected overflow → Find element wider than viewport with outline trick
267
+ Flexbox not working → Check parent display:flex, child flex properties
268
+ Grid misalignment → Use Firefox Grid Inspector
269
+ EOF
270
+ }
271
+
272
+ cheatsheet_git() {
273
+ cat <<'EOF'
274
+ Git Bisect (binary search for bugs):
275
+
276
+ git bisect start
277
+ git bisect bad # Current commit is broken
278
+ git bisect good abc1234 # Known good commit
279
+ # Git checks out middle commit — test it, then:
280
+ git bisect good # or git bisect bad
281
+ # Repeat until root cause commit is found
282
+ git bisect reset
283
+
284
+ # Automated bisect with test script
285
+ git bisect start HEAD abc1234
286
+ git bisect run npm test
287
+ EOF
288
+ }
289
+
290
+ # --- Commands ---
291
+
292
+ cmd_languages() {
293
+ echo "Supported Languages & Tools:"
294
+ echo ""
295
+ echo " javascript JS/TS — Node.js debugger, console, memory"
296
+ echo " python pdb, breakpoint, tracemalloc, cProfile"
297
+ echo " go Delve, race detection, pprof"
298
+ echo " rust GDB/LLDB, RUST_BACKTRACE, env_logger"
299
+ echo " java Remote debug, jmap, jstack, GC logging"
300
+ echo " network curl, dig, lsof, netstat, ss"
301
+ echo " css Outline tricks, layout debugging"
302
+ echo " git git bisect for binary search debugging"
303
+ }
304
+
305
+ cmd_cheatsheet() {
306
+ local lang="${1:-all}"
307
+ case "$lang" in
308
+ javascript|js|typescript|ts) cheatsheet_js ;;
309
+ python|py) cheatsheet_python ;;
310
+ go|golang) cheatsheet_go ;;
311
+ rust|rs) cheatsheet_rust ;;
312
+ java|jvm) cheatsheet_java ;;
313
+ network|net) cheatsheet_network ;;
314
+ css|layout) cheatsheet_css ;;
315
+ git|bisect) cheatsheet_git ;;
316
+ all)
317
+ cheatsheet_js; echo ""; echo "---"; echo ""
318
+ cheatsheet_python; echo ""; echo "---"; echo ""
319
+ cheatsheet_go; echo ""; echo "---"; echo ""
320
+ cheatsheet_rust; echo ""; echo "---"; echo ""
321
+ cheatsheet_java; echo ""; echo "---"; echo ""
322
+ cheatsheet_network; echo ""; echo "---"; echo ""
323
+ cheatsheet_css; echo ""; echo "---"; echo ""
324
+ cheatsheet_git ;;
325
+ *) err "Unknown language: $lang. Run 'debug.sh languages' for the list." ;;
326
+ esac
327
+ }
328
+
329
+ cmd_analyze() {
330
+ local file="${1:?Usage: debug.sh analyze <error-log-file>}"
331
+ check_deps
332
+
333
+ echo "Reading log file..." >&2
334
+ local content
335
+ content=$(read_file "$file")
336
+ local truncated
337
+ truncated=$(echo "$content" | head -c 12000)
338
+
339
+ echo "Analyzing errors..." >&2
340
+ evolink_ai "You are a senior debugging engineer. Analyze this error log and provide:
341
+
342
+ 1. **Error Summary** — What went wrong, in one sentence.
343
+ 2. **Root Cause** — The most likely underlying cause.
344
+ 3. **Error Chain** — If multiple errors exist, show the causal chain (which error triggered which).
345
+ 4. **Affected Components** — Which parts of the system are involved.
346
+ 5. **Fix Steps** — Numbered, actionable steps to resolve the issue.
347
+ 6. **Prevention** — How to prevent this from happening again.
348
+
349
+ Be specific. Reference exact error messages, line numbers, and file paths from the log. Do not give generic advice." "ERROR LOG:
350
+ $truncated"
351
+ }
352
+
353
+ cmd_explain() {
354
+ local message="$*"
355
+ [ -z "$message" ] && err "Usage: debug.sh explain <error_message>"
356
+ check_deps
357
+
358
+ echo "Analyzing error..." >&2
359
+ evolink_ai "You are a senior debugging engineer. Explain this error message:
360
+
361
+ 1. **What it means** — Plain English explanation.
362
+ 2. **Common causes** — Top 3 most likely causes, ranked by probability.
363
+ 3. **Quick fix** — The fastest way to resolve it.
364
+ 4. **Proper fix** — The correct long-term solution.
365
+ 5. **Related errors** — Other errors that often appear alongside this one.
366
+
367
+ Be concise and practical. No filler." "ERROR MESSAGE:
368
+ $message"
369
+ }
370
+
371
+ cmd_trace() {
372
+ local file="${1:?Usage: debug.sh trace <stacktrace-file>}"
373
+ check_deps
374
+
375
+ echo "Reading stack trace..." >&2
376
+ local content
377
+ content=$(read_file "$file")
378
+ local truncated
379
+ truncated=$(echo "$content" | head -c 12000)
380
+
381
+ echo "Parsing stack trace..." >&2
382
+ evolink_ai "You are a senior debugging engineer. Parse and explain this stack trace:
383
+
384
+ 1. **Exception/Error** — The top-level error type and message.
385
+ 2. **Origin** — The exact file, line, and function where the error originated.
386
+ 3. **Call Chain** — Simplified call chain from entry point to error (skip framework internals, focus on user code).
387
+ 4. **Root Cause** — What most likely went wrong at the origin point.
388
+ 5. **Fix** — Specific code change to resolve this.
389
+
390
+ Format the call chain as a clean, readable list. Highlight user code vs framework/library code." "STACK TRACE:
391
+ $truncated"
392
+ }
393
+
394
+ cmd_suggest() {
395
+ local file=""
396
+ local error_msg=""
397
+
398
+ while [[ $# -gt 0 ]]; do
399
+ case "$1" in
400
+ --error) shift; error_msg="$*"; break ;;
401
+ -*) err "Unknown option: $1" ;;
402
+ *) file="$1"; shift ;;
403
+ esac
404
+ done
405
+
406
+ [ -z "$file" ] && err "Usage: debug.sh suggest <code-file> --error <error_message>"
407
+ [ -z "$error_msg" ] && err "Missing --error. Provide the error message."
408
+ check_deps
409
+
410
+ echo "Reading code..." >&2
411
+ local content
412
+ content=$(read_file "$file")
413
+ local truncated
414
+ truncated=$(echo "$content" | head -c 12000)
415
+
416
+ echo "Generating fix suggestions..." >&2
417
+ evolink_ai "You are a senior debugging engineer. The user has this code file that produces the error shown below.
418
+
419
+ 1. **Bug Location** — Identify the exact line(s) causing the error.
420
+ 2. **Why It Fails** — Explain the root cause.
421
+ 3. **Fix** — Show the corrected code (minimal diff, only change what's needed).
422
+ 4. **Verification** — How to verify the fix works.
423
+
424
+ Show the fix as a before/after code diff. Do not rewrite the entire file — only show the relevant section." "ERROR: $error_msg
425
+
426
+ CODE FILE ($file):
427
+ $truncated"
428
+ }
429
+
430
+ # --- Main ---
431
+ COMMAND="${1:-help}"
432
+ shift || true
433
+
434
+ case "$COMMAND" in
435
+ languages) cmd_languages ;;
436
+ cheatsheet) cmd_cheatsheet "$@" ;;
437
+ analyze) cmd_analyze "$@" ;;
438
+ explain) cmd_explain "$@" ;;
439
+ trace) cmd_trace "$@" ;;
440
+ suggest) cmd_suggest "$@" ;;
441
+ help|*)
442
+ echo "Debug Assistant — AI-powered debugging from your terminal"
443
+ echo ""
444
+ echo "Usage: bash debug.sh <command> [options]"
445
+ echo ""
446
+ echo "Info Commands (no API key needed):"
447
+ echo " languages List supported languages"
448
+ echo " cheatsheet [language] Debugging commands cheatsheet"
449
+ echo ""
450
+ echo "AI Commands (requires EVOLINK_API_KEY):"
451
+ echo " analyze <file> Analyze error log file"
452
+ echo " explain <error_message> Explain an error message"
453
+ echo " trace <file> Parse and explain stack trace"
454
+ echo " suggest <file> --error <message> Suggest fixes for code"
455
+ echo ""
456
+ echo "Languages: javascript, python, go, rust, java, network, css, git"
457
+ echo ""
458
+ echo "Get a free EvoLink API key: https://evolink.ai/signup"
459
+ ;;
460
+ esac