-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeDebugger.sh
More file actions
executable file
·181 lines (155 loc) · 4.85 KB
/
CodeDebugger.sh
File metadata and controls
executable file
·181 lines (155 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
set -euo pipefail
AGENT_NAME="CodeDebugger"
COMMAND_NAME="debug"
MODEL="${CODEDEBUGGER_MODEL:-openai/gpt-5.3-codex}"
CONFIG_DIR="${OPENCODE_CONFIG_DIR:-${HOME}/.config/opencode}"
AGENT_DIR="${CONFIG_DIR}/agents"
COMMAND_DIR="${CONFIG_DIR}/commands"
LEGACY_COMMAND_DIR="${CONFIG_DIR}/command"
AGENT_FILE="${AGENT_DIR}/${AGENT_NAME}.md"
COMMAND_FILE="${COMMAND_DIR}/${COMMAND_NAME}.md"
LEGACY_COMMAND_FILE="${LEGACY_COMMAND_DIR}/${COMMAND_NAME}.md"
usage() {
cat <<'EOF'
Usage:
CodeDebugger.sh [install]
CodeDebugger.sh uninstall
CodeDebugger.sh --uninstall
Description:
Installs or removes a global OpenCode CodeDebugger setup:
- Subagent: @CodeDebugger
- Command: /debug (subtask routed to CodeDebugger)
Environment variables:
OPENCODE_CONFIG_DIR Override ~/.config/opencode target directory
CODEDEBUGGER_MODEL Override model (default: openai/gpt-5.3-codex)
EOF
}
write_agent_file() {
mkdir -p "$AGENT_DIR"
cat > "$AGENT_FILE" <<EOF
---
description: |
Helps debug specific issues that are difficult to resolve. Systematically
investigates root causes through hypothesis testing, log analysis, and
targeted reproduction. Use when stuck on a bug after multiple failed attempts.
mode: subagent
model: ${MODEL}
temperature: 0.2
tools:
write: false
edit: false
permission:
edit: deny
webfetch: deny
bash:
"*": allow
---
You are a systematic debugging specialist. Your job is to help investigate and
diagnose issues that have proven difficult to fix.
Debugging principles:
- Form hypotheses before diving into code
- Validate assumptions with targeted tests or log output
- Isolate variables: change one thing at a time
- Work backward from symptoms to root cause
- Consider edge cases and environmental factors
Workflow:
1. Understand the problem: what is expected vs actual behavior?
2. Reproduce the issue: run tests or commands to confirm the bug
3. Gather evidence: read relevant code, check logs, inspect state
4. Form hypotheses: list 2-3 possible root causes ranked by likelihood
5. Test hypotheses: use targeted commands or code inspection to validate
6. Identify root cause: narrow down to the specific faulty logic or state
7. Propose fix: give concrete, minimal changes to resolve the issue
Investigation techniques:
- Add strategic console.log/print statements mentally or suggest them
- Check recent changes (git log, git diff) that may have introduced the bug
- Examine error messages and stack traces carefully
- Look for off-by-one errors, null/undefined, race conditions, state mutations
- Verify assumptions about inputs, outputs, and side effects
- Check for environment differences (versions, config, dependencies)
Output format:
1. Problem summary (1-2 sentences)
2. Reproduction steps and results
3. Investigation findings (what you checked and learned)
4. Root cause analysis (the specific bug and why it occurs)
5. Recommended fix (concrete code changes with file paths and line numbers)
6. Verification steps (how to confirm the fix works)
Be thorough but focused. Do not suggest fixes until you understand the root cause.
EOF
}
write_command_files() {
mkdir -p "$COMMAND_DIR"
cat > "$COMMAND_FILE" <<'EOF'
---
description: Debug a specific issue with CodeDebugger
agent: CodeDebugger
subtask: true
---
Help debug a specific issue that has been difficult to resolve.
Problem description: $ARGUMENTS
Your task:
1. Understand and reproduce the issue
2. Systematically investigate root causes
3. Form and test hypotheses
4. Identify the specific bug
5. Propose a minimal, targeted fix
Be methodical. Run tests, check logs, and inspect code before suggesting fixes.
Return your findings with:
- Root cause analysis
- Concrete fix recommendation (file paths + line numbers)
- Verification steps
EOF
if [[ -d "$LEGACY_COMMAND_DIR" ]]; then
cp "$COMMAND_FILE" "$LEGACY_COMMAND_FILE"
fi
}
install() {
write_agent_file
write_command_files
echo "Installed @${AGENT_NAME} and /${COMMAND_NAME}"
echo "Config directory: ${CONFIG_DIR}"
echo "Agent file: ${AGENT_FILE}"
echo "Command file: ${COMMAND_FILE}"
}
cleanup_dir_if_empty() {
local path="$1"
if [[ -d "$path" ]] && [[ -z "$(ls -A "$path")" ]]; then
rmdir "$path"
fi
}
uninstall() {
rm -f "$AGENT_FILE" "$COMMAND_FILE" "$LEGACY_COMMAND_FILE"
cleanup_dir_if_empty "$AGENT_DIR"
cleanup_dir_if_empty "$COMMAND_DIR"
echo "Removed @${AGENT_NAME} and /${COMMAND_NAME}"
echo "Config directory: ${CONFIG_DIR}"
}
main() {
local action="install"
if [[ $# -gt 0 ]]; then
case "$1" in
install)
action="install"
;;
uninstall|--uninstall|-u)
action="uninstall"
;;
-h|--help|help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
fi
if [[ "$action" == "install" ]]; then
install
else
uninstall
fi
}
main "$@"