Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:07:22 +08:00
commit fab98d059b
179 changed files with 46209 additions and 0 deletions

View File

@@ -0,0 +1,416 @@
# Diagnostic Workflows
**Version**: 2.0
**Source**: Bootstrap-003 Error Recovery Methodology
**Last Updated**: 2025-10-18
**Coverage**: 78.7% of errors (8 workflows)
Step-by-step diagnostic procedures for common error categories.
---
## Workflow 1: Build/Compilation Errors (15.0%)
**MTTD**: 2-5 minutes
### Symptoms
- `go build` fails
- Error messages: `*.go:[line]:[col]: [error]`
### Diagnostic Steps
**Step 1: Identify Error Location**
```bash
go build 2>&1 | tee build-error.log
grep "\.go:" build-error.log
```
**Step 2: Classify Error Type**
- Syntax error (braces, semicolons)
- Type error (mismatches)
- Import error (unused/missing)
- Definition error (undefined references)
**Step 3: Inspect Context**
```bash
sed -n '[line-5],[line+5]p' [file]
```
### Tools
- `go build`, `grep`, `sed`
- IDE/editor
### Success Criteria
- Root cause identified
- Fix approach clear
### Automation
Medium (linters, IDE integration)
---
## Workflow 2: Test Failures (11.2%)
**MTTD**: 3-10 minutes
### Symptoms
- `go test` fails
- `FAIL` messages in output
### Diagnostic Steps
**Step 1: Identify Failing Test**
```bash
go test ./... -v 2>&1 | tee test-output.log
grep "FAIL:" test-output.log
```
**Step 2: Isolate Test**
```bash
go test ./internal/parser -run TestParseSession
```
**Step 3: Analyze Failure**
- Assertion failure (expected vs actual)
- Panic (runtime error)
- Timeout
- Setup failure
**Step 4: Inspect Code/Data**
```bash
cat [test_file].go | grep -A 20 "func Test[Name]"
cat tests/fixtures/[fixture]
```
### Tools
- `go test`, `grep`
- Test fixtures
### Success Criteria
- Understand why assertion failed
- Know expected vs actual behavior
### Automation
Low (requires understanding intent)
---
## Workflow 3: File Not Found (18.7%)
**MTTD**: 1-3 minutes
### Symptoms
- `File does not exist`
- `No such file or directory`
### Diagnostic Steps
**Step 1: Verify Non-Existence**
```bash
ls [path]
find . -name "[filename]"
```
**Step 2: Search for Similar Files**
```bash
find . -iname "*[partial_name]*"
ls [directory]/
```
**Step 3: Classify Issue**
- Path typo (wrong name/location)
- File not created yet
- Wrong working directory
- Case sensitivity issue
**Step 4: Fuzzy Match**
```bash
# Use automation tool
./scripts/validate-path.sh [attempted_path]
```
### Tools
- `ls`, `find`
- `validate-path.sh` (automation)
### Success Criteria
- Know exact cause (typo vs missing)
- Found correct path or know file needs creation
### Automation
**High** (path validation, fuzzy matching)
---
## Workflow 4: File Size Exceeded (6.3%)
**MTTD**: 1-2 minutes
### Symptoms
- `File content exceeds maximum allowed tokens`
- Read operation fails with size error
### Diagnostic Steps
**Step 1: Check File Size**
```bash
wc -l [file]
du -h [file]
```
**Step 2: Determine Strategy**
- Use offset/limit parameters
- Use grep/head/tail
- Process in chunks
**Step 3: Execute Alternative**
```bash
# Option A: Pagination
Read [file] offset=0 limit=1000
# Option B: Selective reading
grep "pattern" [file]
head -n 1000 [file]
```
### Tools
- `wc`, `du`
- Read tool with pagination
- `grep`, `head`, `tail`
- `check-file-size.sh` (automation)
### Success Criteria
- Got needed information without full read
### Automation
**Full** (size check, auto-pagination)
---
## Workflow 5: Write Before Read (5.2%)
**MTTD**: 1-2 minutes
### Symptoms
- `File has not been read yet`
- Write/Edit tool error
### Diagnostic Steps
**Step 1: Verify File Exists**
```bash
ls [file]
```
**Step 2: Determine Operation Type**
- Modification → Use Edit tool
- Complete rewrite → Read then Write
- New file → Write directly (no Read needed)
**Step 3: Add Read Step**
```bash
Read [file]
Edit [file] old_string="..." new_string="..."
```
### Tools
- Read, Edit, Write tools
- `check-read-before-write.sh` (automation)
### Success Criteria
- File read before modification
- Correct tool chosen (Edit vs Write)
### Automation
**Full** (auto-insert Read step)
---
## Workflow 6: Command Not Found (3.7%)
**MTTD**: 2-5 minutes
### Symptoms
- `command not found`
- Bash execution fails
### Diagnostic Steps
**Step 1: Identify Command Type**
```bash
which [command]
type [command]
```
**Step 2: Check if Project Binary**
```bash
ls ./[command]
ls bin/[command]
```
**Step 3: Build if Needed**
```bash
# Check build system
ls Makefile
cat Makefile | grep [command]
# Build
make build
```
**Step 4: Execute with Path**
```bash
./[command] [args]
# OR
PATH=$PATH:./bin [command] [args]
```
### Tools
- `which`, `type`
- `make`
- Project build system
### Success Criteria
- Command found or built
- Can execute successfully
### Automation
Medium (can detect and suggest build)
---
## Workflow 7: JSON Parsing Errors (6.0%)
**MTTD**: 3-8 minutes
### Diagnostic Steps
**Step 1: Validate JSON Syntax**
```bash
jq . [file.json]
cat [file.json] | python -m json.tool
```
**Step 2: Locate Parsing Error**
```bash
# Error message shows line/field
# View context around error
sed -n '[line-5],[line+5]p' [file.json]
```
**Step 3: Classify Issue**
- Syntax error (commas, braces)
- Type mismatch (string vs int)
- Missing field
- Schema change
**Step 4: Fix or Update**
- Fix JSON structure
- Update Go struct definition
- Update test fixtures
### Tools
- `jq`, `python -m json.tool`
- Go compiler (for schema errors)
### Success Criteria
- JSON is valid
- Schema matches code expectations
### Automation
Medium (syntax validation yes, schema fix no)
---
## Workflow 8: String Not Found (Edit) (3.2%)
**MTTD**: 1-3 minutes
### Symptoms
- `String to replace not found in file`
- Edit operation fails
### Diagnostic Steps
**Step 1: Re-Read File**
```bash
Read [file]
```
**Step 2: Locate Target Section**
```bash
grep -n "target_pattern" [file]
```
**Step 3: Copy Exact String**
- View file content
- Copy exact string (including whitespace)
- Don't retype (preserves formatting)
**Step 4: Retry Edit**
```bash
Edit [file] old_string="[exact_copied_string]" new_string="[new]"
```
### Tools
- Read tool
- `grep -n`
### Success Criteria
- Found exact current string
- Edit succeeds
### Automation
High (auto-refresh before edit)
---
## Diagnostic Workflow Selection
### Decision Tree
```
Error occurs
├─ Build fails? → Workflow 1
├─ Test fails? → Workflow 2
├─ File not found? → Workflow 3 ⚠️ AUTOMATE
├─ File too large? → Workflow 4 ⚠️ AUTOMATE
├─ Write before read? → Workflow 5 ⚠️ AUTOMATE
├─ Command not found? → Workflow 6
├─ JSON parsing? → Workflow 7
├─ Edit string not found? → Workflow 8
└─ Other? → See taxonomy.md
```
---
## Best Practices
### General Diagnostic Approach
1. **Reproduce**: Ensure error is reproducible
2. **Classify**: Match to error category
3. **Follow workflow**: Use appropriate diagnostic workflow
4. **Document**: Note findings for future reference
5. **Verify**: Confirm diagnosis before fix
### Time Management
- Set time limit per diagnostic step (5-10 min)
- If stuck, escalate or try different approach
- Use automation tools when available
### Common Mistakes
❌ Skip verification steps
❌ Assume root cause without evidence
❌ Try fixes without diagnosis
✅ Follow workflow systematically
✅ Use tools/automation
✅ Document findings
---
**Source**: Bootstrap-003 Error Recovery Methodology
**Framework**: BAIME (Bootstrapped AI Methodology Engineering)
**Status**: Production-ready, validated with 1336 errors

View File

@@ -0,0 +1,461 @@
# Error Prevention Guidelines
**Version**: 1.0
**Source**: Bootstrap-003 Error Recovery Methodology
**Last Updated**: 2025-10-18
Proactive strategies to prevent common errors before they occur.
---
## Overview
**Prevention is better than recovery**. This document provides actionable guidelines to prevent the most common error categories.
**Automation Impact**: 3 automated tools prevent 23.7% of all errors (317/1336)
---
## Category 1: Build/Compilation Errors (15.0%)
### Prevention Strategies
**1. Pre-Commit Linting**
```bash
# Add to .git/hooks/pre-commit
gofmt -w .
golangci-lint run
go build
```
**2. IDE Integration**
- Use IDE with real-time syntax checking (VS Code, GoLand)
- Enable "save on format" (gofmt)
- Configure inline linter warnings
**3. Incremental Compilation**
```bash
# Build frequently during development
go build ./... # Fast incremental build
```
**4. Type Safety**
- Use strict type checking
- Avoid `interface{}` when possible
- Add type assertions with error checks
### Effectiveness
Prevents ~60% of Category 1 errors
---
## Category 2: Test Failures (11.2%)
### Prevention Strategies
**1. Run Tests Before Commit**
```bash
# Add to .git/hooks/pre-commit
go test ./...
```
**2. Test-Driven Development (TDD)**
- Write test first
- Write minimal code to pass
- Refactor
**3. Fixture Management**
```bash
# Version control test fixtures
git add tests/fixtures/
# Update fixtures with code changes
./scripts/update-fixtures.sh
```
**4. Continuous Integration**
```yaml
# .github/workflows/test.yml
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: go test ./...
```
### Effectiveness
Prevents ~70% of Category 2 errors
---
## Category 3: File Not Found (18.7%) ⚠️ AUTOMATABLE
### Prevention Strategies
**1. Path Validation Tool**
```bash
# Use automation before file operations
./scripts/validate-path.sh [path]
# Returns:
# - File exists: OK
# - File missing: Suggests similar paths
```
**2. Autocomplete**
- Use shell/IDE autocomplete for paths
- Tab completion reduces typos by 95%
**3. Existence Checks**
```go
// In code
if _, err := os.Stat(path); os.IsNotExist(err) {
return fmt.Errorf("file not found: %s", path)
}
```
**4. Working Directory Awareness**
```bash
# Always know where you are
pwd
# Use absolute paths when unsure
realpath [relative_path]
```
### Effectiveness
**Prevents 65.2% of Category 3 errors** with automation
---
## Category 4: File Size Exceeded (6.3%) ⚠️ AUTOMATABLE
### Prevention Strategies
**1. Size Check Tool**
```bash
# Use automation before reading
./scripts/check-file-size.sh [file]
# Returns:
# - OK to read
# - Too large, use pagination
# - Suggests offset/limit values
```
**2. Pre-Read Size Check**
```bash
# Manual check
wc -l [file]
du -h [file]
# If >10000 lines, use pagination
```
**3. Use Selective Reading**
```bash
# Instead of full read
head -n 1000 [file]
grep "pattern" [file]
tail -n 1000 [file]
```
**4. Streaming for Large Files**
```go
// In code, process line-by-line
scanner := bufio.NewScanner(file)
for scanner.Scan() {
processLine(scanner.Text())
}
```
### Effectiveness
**Prevents 100% of Category 4 errors** with automation
---
## Category 5: Write Before Read (5.2%) ⚠️ AUTOMATABLE
### Prevention Strategies
**1. Read-Before-Write Check**
```bash
# Use automation before Write/Edit
./scripts/check-read-before-write.sh [file]
# Returns:
# - File already read: OK to write
# - File not read: Suggests Read first
```
**2. Always Read First**
```bash
# Workflow pattern
Read [file] # Step 1: Always read
Edit [file] ... # Step 2: Then edit
```
**3. Use Edit for Modifications**
- Edit: Requires prior read (safer)
- Write: For new files or complete rewrites
**4. Session Context Awareness**
- Track what files have been read
- Clear workflow: Read → Analyze → Edit
### Effectiveness
**Prevents 100% of Category 5 errors** with automation
---
## Category 6: Command Not Found (3.7%)
### Prevention Strategies
**1. Build Before Execute**
```bash
# Always build first
make build
./command [args]
```
**2. PATH Verification**
```bash
# Check command availability
which [command] || echo "Command not found, build first"
```
**3. Use Absolute Paths**
```bash
# For project binaries
./bin/meta-cc [args]
# Not: meta-cc [args]
```
**4. Dependency Checks**
```bash
# Check required tools
command -v jq >/dev/null || echo "jq not installed"
command -v go >/dev/null || echo "go not installed"
```
### Effectiveness
Prevents ~80% of Category 6 errors
---
## Category 7: JSON Parsing Errors (6.0%)
### Prevention Strategies
**1. Validate JSON Before Use**
```bash
# Validate syntax
jq . [file.json] > /dev/null
# Validate and pretty-print
cat [file.json] | python -m json.tool
```
**2. Schema Validation**
```bash
# Use JSON schema validator
jsonschema -i [data.json] [schema.json]
```
**3. Test Fixtures with Code**
```go
// Test that fixtures parse correctly
func TestFixtureParsing(t *testing.T) {
data, _ := os.ReadFile("tests/fixtures/sample.json")
var result MyStruct
if err := json.Unmarshal(data, &result); err != nil {
t.Errorf("Fixture doesn't match schema: %v", err)
}
}
```
**4. Type Safety**
```go
// Use strong typing
type Config struct {
Port int `json:"port"` // Not string
Name string `json:"name"`
}
```
### Effectiveness
Prevents ~70% of Category 7 errors
---
## Category 13: String Not Found (Edit) (3.2%)
### Prevention Strategies
**1. Always Re-Read Before Edit**
```bash
# Workflow
Read [file] # Fresh read
Edit [file] old="..." new="..." # Then edit
```
**2. Copy Exact Strings**
- Don't retype old_string
- Copy from file viewer
- Preserves whitespace/formatting
**3. Include Context**
```go
// Not: old_string="x"
// Yes: old_string=" x = 1\n y = 2" // Includes indentation
```
**4. Verify File Hasn't Changed**
```bash
# Check file modification time
ls -l [file]
# Or use version control
git status [file]
```
### Effectiveness
Prevents ~80% of Category 13 errors
---
## Cross-Cutting Prevention Strategies
### 1. Automation First
**High-Priority Automated Tools**:
1. `validate-path.sh` (65.2% of Category 3)
2. `check-file-size.sh` (100% of Category 4)
3. `check-read-before-write.sh` (100% of Category 5)
**Combined Impact**: 23.7% of ALL errors prevented
**Installation**:
```bash
# Add to PATH
export PATH=$PATH:./scripts
# Or use as hooks
./scripts/install-hooks.sh
```
### 2. Pre-Commit Hooks
```bash
#!/bin/bash
# .git/hooks/pre-commit
# Format code
gofmt -w .
# Run linters
golangci-lint run
# Run tests
go test ./...
# Build
go build
# If any fail, prevent commit
if [ $? -ne 0 ]; then
echo "Pre-commit checks failed"
exit 1
fi
```
### 3. Continuous Integration
```yaml
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
- name: Lint
run: golangci-lint run
- name: Test
run: go test ./... -cover
- name: Build
run: go build
```
### 4. Development Workflow
**Standard Workflow**:
1. Write code
2. Format (gofmt)
3. Lint (golangci-lint)
4. Test (go test)
5. Build (go build)
6. Commit
**TDD Workflow**:
1. Write test (fails - red)
2. Write code (passes - green)
3. Refactor
4. Repeat
---
## Prevention Metrics
### Impact by Category
| Category | Baseline Frequency | Prevention | Remaining |
|----------|-------------------|------------|-----------|
| File Not Found (3) | 250 (18.7%) | -163 (65.2%) | 87 (6.5%) |
| File Size (4) | 84 (6.3%) | -84 (100%) | 0 (0%) |
| Write Before Read (5) | 70 (5.2%) | -70 (100%) | 0 (0%) |
| **Total Automated** | **404 (30.2%)** | **-317 (78.5%)** | **87 (6.5%)** |
### ROI Analysis
**Time Investment**:
- Setup automation: 2 hours
- Maintain automation: 15 min/week
**Time Saved**:
- 317 errors × 3 min avg recovery = 951 minutes = 15.9 hours
- **ROI**: 7.95x in first month alone
---
## Best Practices
### Do's
✅ Use automation tools when available
✅ Run pre-commit hooks
✅ Test before commit
✅ Build incrementally
✅ Validate inputs (paths, JSON, etc.)
✅ Use type safety
✅ Check file existence before operations
### Don'ts
❌ Skip validation steps to save time
❌ Commit without running tests
❌ Ignore linter warnings
❌ Manually type file paths (use autocomplete)
❌ Skip pre-read for file edits
❌ Ignore automation tool suggestions
---
**Source**: Bootstrap-003 Error Recovery Methodology
**Framework**: BAIME (Bootstrapped AI Methodology Engineering)
**Status**: Production-ready, validated with 1336 errors
**Automation Coverage**: 23.7% of errors prevented

View File

@@ -0,0 +1,418 @@
# Recovery Strategy Patterns
**Version**: 1.0
**Source**: Bootstrap-003 Error Recovery Methodology
**Last Updated**: 2025-10-18
This document provides proven recovery patterns for each error category.
---
## Pattern 1: Syntax Error Fix-and-Retry
**Applicable to**: Build/Compilation Errors (Category 1)
**Strategy**: Fix syntax error in source code and rebuild
**Steps**:
1. **Locate**: Identify file and line from error (`file.go:line:col`)
2. **Read**: Read the problematic file section
3. **Fix**: Edit file to correct syntax error
4. **Verify**: Run `go build` or `go test`
5. **Retry**: Retry original operation
**Automation**: Semi-automated (detection automatic, fix manual)
**Success Rate**: >90%
**Time to Recovery**: 2-5 minutes
**Example**:
```
Error: cmd/root.go:4:2: "fmt" imported and not used
Recovery:
1. Read cmd/root.go
2. Edit cmd/root.go - remove line 4: import "fmt"
3. Bash: go build
4. Verify: Build succeeds
```
---
## Pattern 2: Test Fixture Update
**Applicable to**: Test Failures (Category 2)
**Strategy**: Update test fixtures or expectations to match current code
**Steps**:
1. **Analyze**: Understand test expectation vs code output
2. **Decide**: Determine if code or test is incorrect
3. **Update**: Fix code or update test fixture/assertion
4. **Verify**: Run test again
5. **Full test**: Run complete test suite
**Automation**: Low (requires human judgment)
**Success Rate**: >85%
**Time to Recovery**: 5-15 minutes
**Example**:
```
Error: --- FAIL: TestLoadFixture (0.00s)
fixtures_test.go:34: Missing 'sequence' field
Recovery:
1. Read tests/fixtures/sample-session.jsonl
2. Identify missing 'sequence' field
3. Edit fixture to add 'sequence' field
4. Bash: go test ./internal/testutil -v
5. Verify: Test passes
```
---
## Pattern 3: Path Correction ⚠️ AUTOMATABLE
**Applicable to**: File Not Found (Category 3)
**Strategy**: Correct file path or create missing file
**Steps**:
1. **Verify**: Confirm file doesn't exist (`ls` or `find`)
2. **Locate**: Search for file with correct name
3. **Decide**: Path typo vs file not created
4. **Fix**:
- If typo: Correct path
- If not created: Create file or reorder workflow
5. **Retry**: Retry with correct path
**Automation**: High (path validation, fuzzy matching, "did you mean?")
**Success Rate**: >95%
**Time to Recovery**: 1-3 minutes
**Example**:
```
Error: No such file: /path/internal/testutil/fixture.go
Recovery:
1. Bash: ls /path/internal/testutil/
2. Find: File is fixtures.go (not fixture.go)
3. Bash: wc -l /path/internal/testutil/fixtures.go
4. Verify: Success
```
---
## Pattern 4: Read-Then-Write ⚠️ AUTOMATABLE
**Applicable to**: Write Before Read (Category 5)
**Strategy**: Add Read step before Write, or use Edit
**Steps**:
1. **Check existence**: Verify file exists
2. **Decide tool**:
- For modifications: Use Edit
- For complete rewrite: Read then Write
3. **Read**: Read existing file content
4. **Write/Edit**: Perform operation
5. **Verify**: Confirm desired content
**Automation**: Fully automated (can auto-insert Read step)
**Success Rate**: >98%
**Time to Recovery**: 1-2 minutes
**Example**:
```
Error: File has not been read yet.
Recovery:
1. Bash: ls internal/testutil/fixtures.go
2. Read internal/testutil/fixtures.go
3. Edit internal/testutil/fixtures.go
4. Verify: Updated successfully
```
---
## Pattern 5: Build-Then-Execute
**Applicable to**: Command Not Found (Category 6)
**Strategy**: Build binary before executing, or add to PATH
**Steps**:
1. **Identify**: Determine missing command
2. **Check buildable**: Is this a project binary?
3. **Build**: Run build command (`make build`)
4. **Execute**: Use local path or install to PATH
5. **Verify**: Command executes
**Automation**: Medium (can detect and suggest build)
**Success Rate**: >90%
**Time to Recovery**: 2-5 minutes
**Example**:
```
Error: meta-cc: command not found
Recovery:
1. Bash: ls meta-cc (check if exists)
2. If not: make build
3. Bash: ./meta-cc --version
4. Verify: Command runs
```
---
## Pattern 6: Pagination for Large Files ⚠️ AUTOMATABLE
**Applicable to**: File Size Exceeded (Category 4)
**Strategy**: Use offset/limit or alternative tools
**Steps**:
1. **Detect**: File size check before read
2. **Choose approach**:
- **Option A**: Read with offset/limit
- **Option B**: Use grep/head/tail
- **Option C**: Process in chunks
3. **Execute**: Apply chosen approach
4. **Verify**: Obtained needed information
**Automation**: Fully automated (can auto-detect and paginate)
**Success Rate**: 100%
**Time to Recovery**: 1-2 minutes
**Example**:
```
Error: File exceeds 25000 tokens
Recovery:
1. Bash: wc -l large-file.jsonl # Check size
2. Read large-file.jsonl offset=0 limit=1000 # Read first 1000 lines
3. OR: Bash: head -n 1000 large-file.jsonl
4. Verify: Got needed content
```
---
## Pattern 7: JSON Schema Fix
**Applicable to**: JSON Parsing Errors (Category 7)
**Strategy**: Fix JSON structure or update schema
**Steps**:
1. **Validate**: Use `jq` to check JSON validity
2. **Locate**: Find exact parsing error location
3. **Analyze**: Determine if JSON or code schema is wrong
4. **Fix**:
- If JSON: Fix structure (commas, braces, types)
- If schema: Update Go struct tags/types
5. **Test**: Verify parsing succeeds
**Automation**: Medium (syntax validation yes, schema fix no)
**Success Rate**: >85%
**Time to Recovery**: 3-8 minutes
**Example**:
```
Error: json: cannot unmarshal string into field .count of type int
Recovery:
1. Read testdata/fixture.json
2. Find: "count": "42" (string instead of int)
3. Edit: Change to "count": 42
4. Bash: go test ./internal/parser
5. Verify: Test passes
```
---
## Pattern 8: String Exact Match
**Applicable to**: String Not Found (Edit Errors) (Category 13)
**Strategy**: Re-read file and copy exact string
**Steps**:
1. **Re-read**: Read file to get current content
2. **Locate**: Find target section (grep or visual)
3. **Copy exact**: Copy current string exactly (no retyping)
4. **Retry Edit**: Use exact old_string
5. **Verify**: Edit succeeds
**Automation**: High (auto-refresh content before edit)
**Success Rate**: >95%
**Time to Recovery**: 1-3 minutes
**Example**:
```
Error: String to replace not found in file
Recovery:
1. Read internal/parser/parse.go # Fresh read
2. Grep: Search for target function
3. Copy exact string from current file
4. Edit with exact old_string
5. Verify: Edit succeeds
```
---
## Pattern 9: MCP Server Health Check
**Applicable to**: MCP Server Errors (Category 9)
**Strategy**: Check server health, restart if needed
**Steps**:
1. **Check status**: Verify MCP server is running
2. **Test connection**: Simple query to test connectivity
3. **Restart**: If down, restart MCP server
4. **Optimize query**: If timeout, add pagination/filters
5. **Retry**: Retry original query
**Automation**: Medium (health checks yes, query optimization no)
**Success Rate**: >80%
**Time to Recovery**: 2-10 minutes
**Example**:
```
Error: MCP server connection failed
Recovery:
1. Bash: ps aux | grep mcp-server
2. If not running: Restart MCP server
3. Test: Simple query (e.g., get_session_stats)
4. If working: Retry original query
5. Verify: Query succeeds
```
---
## Pattern 10: Permission Fix
**Applicable to**: Permission Denied (Category 10)
**Strategy**: Change permissions or use appropriate user
**Steps**:
1. **Check current**: `ls -la` to see permissions
2. **Identify owner**: `ls -l` shows file owner
3. **Fix permission**:
- Option A: `chmod` to add permissions
- Option B: `chown` to change owner
- Option C: Use sudo (if appropriate)
4. **Retry**: Retry original operation
5. **Verify**: Operation succeeds
**Automation**: Low (security implications)
**Success Rate**: >90%
**Time to Recovery**: 1-3 minutes
**Example**:
```
Error: Permission denied: /path/to/file
Recovery:
1. Bash: ls -la /path/to/file
2. See: -r--r--r-- (read-only)
3. Bash: chmod u+w /path/to/file
4. Retry: Write operation
5. Verify: Success
```
---
## Recovery Pattern Selection
### Decision Tree
```
Error occurs
├─ Build/compilation? → Pattern 1 (Fix-and-Retry)
├─ Test failure? → Pattern 2 (Test Fixture Update)
├─ File not found? → Pattern 3 (Path Correction) ⚠️ AUTOMATE
├─ File too large? → Pattern 6 (Pagination) ⚠️ AUTOMATE
├─ Write before read? → Pattern 4 (Read-Then-Write) ⚠️ AUTOMATE
├─ Command not found? → Pattern 5 (Build-Then-Execute)
├─ JSON parsing? → Pattern 7 (JSON Schema Fix)
├─ String not found (Edit)? → Pattern 8 (String Exact Match)
├─ MCP server? → Pattern 9 (MCP Health Check)
├─ Permission denied? → Pattern 10 (Permission Fix)
└─ Other? → Consult taxonomy for category
```
---
## Automation Priority
**High Priority** (Full automation possible):
1. Pattern 3: Path Correction (validate-path.sh)
2. Pattern 4: Read-Then-Write (check-read-before-write.sh)
3. Pattern 6: Pagination (check-file-size.sh)
**Medium Priority** (Partial automation):
4. Pattern 5: Build-Then-Execute
5. Pattern 7: JSON Schema Fix
6. Pattern 9: MCP Server Health
**Low Priority** (Manual required):
7. Pattern 1: Syntax Error Fix
8. Pattern 2: Test Fixture Update
9. Pattern 10: Permission Fix
---
## Best Practices
### General Recovery Workflow
1. **Classify**: Match error to category (use taxonomy.md)
2. **Select pattern**: Choose appropriate recovery pattern
3. **Execute steps**: Follow pattern steps systematically
4. **Verify**: Confirm recovery successful
5. **Document**: Note if pattern needs refinement
### Efficiency Tips
- Keep taxonomy.md open for quick classification
- Use automation tools when available
- Don't skip verification steps
- Track recurring errors for prevention
### Common Mistakes
**Don't**: Retry without understanding error
**Don't**: Skip verification step
**Don't**: Ignore automation opportunities
**Do**: Classify error first
**Do**: Follow pattern steps systematically
**Do**: Verify recovery completely
---
**Source**: Bootstrap-003 Error Recovery Methodology
**Framework**: BAIME (Bootstrapped AI Methodology Engineering)
**Status**: Production-ready, validated with 1336 errors

View File

@@ -0,0 +1,461 @@
# Error Classification Taxonomy
**Version**: 2.0
**Source**: Bootstrap-003 Error Recovery Methodology
**Last Updated**: 2025-10-18
**Coverage**: 95.4% of observed errors
**Categories**: 13 complete categories
This taxonomy classifies errors systematically for effective recovery and prevention.
---
## Overview
This taxonomy is:
- **MECE** (Mutually Exclusive, Collectively Exhaustive): 95.4% coverage
- **Actionable**: Each category has clear recovery paths
- **Observable**: Each category has detectable symptoms
- **Universal**: 85-90% applicable to other software projects
**Automation Coverage**: 23.7% of errors preventable with 3 automated tools
---
## 13 Error Categories
### Category 1: Build/Compilation Errors (15.0%)
**Definition**: Syntax errors, type mismatches, import issues preventing compilation
**Examples**:
- `cmd/root.go:4:2: "fmt" imported and not used`
- `undefined: someFunction`
- `cannot use x (type int) as type string`
**Common Causes**:
- Unused imports after refactoring
- Type mismatches from incomplete changes
- Missing function definitions
- Syntax errors
**Detection Pattern**: `*.go:[line]:[col]: [error message]`
**Prevention**:
- Pre-commit linting (gofmt, golangci-lint)
- IDE real-time syntax checking
- Incremental compilation
**Recovery**: Fix syntax/type issue, retry `go build`
**Automation Potential**: Medium
---
### Category 2: Test Failures (11.2%)
**Definition**: Unit or integration test assertions that fail during execution
**Examples**:
- `--- FAIL: TestLoadFixture (0.00s)`
- `Fixture content should contain 'sequence' field`
- `FAIL github.com/project/package 0.003s`
**Common Causes**:
- Test fixture data mismatch
- Assertion failures from code changes
- Missing test data files
- Incorrect expected values
**Detection Pattern**: `--- FAIL:`, `FAIL\t`, assertion messages
**Prevention**:
- Run tests before commit
- Update test fixtures with code changes
- Test-driven development (TDD)
**Recovery**: Update test expectations or fix code
**Automation Potential**: Low (requires understanding test intent)
---
### Category 3: File Not Found (18.7%) ⚠️ AUTOMATABLE
**Definition**: Attempts to access non-existent files or directories
**Examples**:
- `File does not exist.`
- `wc: /path/to/file: No such file or directory`
- `File does not exist. Did you mean file.md?`
**Common Causes**:
- Typos in file paths
- Files moved or deleted
- Incorrect working directory
- Case sensitivity issues
**Detection Pattern**: `File does not exist`, `No such file or directory`
**Prevention**:
- **Automation: `validate-path.sh`** ✅ (prevents 65.2% of category 3 errors)
- Validate paths before file operations
- Use autocomplete for paths
- Check file existence first
**Recovery**: Correct file path, create missing file, or change directory
**Automation Potential**: **HIGH**
---
### Category 4: File Size Exceeded (6.3%) ⚠️ AUTOMATABLE
**Definition**: Attempted to read files exceeding token limit
**Examples**:
- `File content (46892 tokens) exceeds maximum allowed tokens (25000)`
- `File too large to read in single operation`
**Common Causes**:
- Reading large generated files without pagination
- Reading entire JSON files
- Reading log files without limiting lines
**Detection Pattern**: `exceeds maximum allowed tokens`, `File too large`
**Prevention**:
- **Automation: `check-file-size.sh`** ✅ (prevents 100% of category 4 errors)
- Pre-check file size before reading
- Use offset/limit parameters
- Use grep/head/tail instead of full Read
**Recovery**: Use Read with offset/limit, or use grep
**Automation Potential**: **FULL**
---
### Category 5: Write Before Read (5.2%) ⚠️ AUTOMATABLE
**Definition**: Attempted to Write/Edit a file without reading it first
**Examples**:
- `File has not been read yet. Read it first before writing to it.`
**Common Causes**:
- Forgetting to read file before edit
- Reading wrong file, editing intended file
- Session context lost
- Workflow error
**Detection Pattern**: `File has not been read yet`
**Prevention**:
- **Automation: `check-read-before-write.sh`** ✅ (prevents 100% of category 5 errors)
- Always Read before Write/Edit
- Use Edit instead of Write for existing files
- Check read history
**Recovery**: Read the file, then retry Write/Edit
**Automation Potential**: **FULL**
---
### Category 6: Command Not Found (3.7%)
**Definition**: Bash commands that don't exist or aren't in PATH
**Examples**:
- `/bin/bash: line 1: meta-cc: command not found`
- `command not found: gofmt`
**Common Causes**:
- Binary not built yet
- Binary not in PATH
- Typo in command name
- Required tool not installed
**Detection Pattern**: `command not found`
**Prevention**:
- Build before running commands
- Verify tool installation
- Use absolute paths for project binaries
**Recovery**: Build binary, install tool, or correct command
**Automation Potential**: Medium
---
### Category 7: JSON Parsing Errors (6.0%)
**Definition**: Malformed JSON or schema mismatches
**Examples**:
- `json: cannot unmarshal string into Go struct field`
- `invalid character '}' looking for beginning of value`
**Common Causes**:
- Schema changes without updating code
- Malformed JSON in test fixtures
- Type mismatches
- Missing or extra commas/braces
**Detection Pattern**: `json:`, `unmarshal`, `invalid character`
**Prevention**:
- Validate JSON with jq before use
- Use JSON schema validation
- Test JSON fixtures with actual code
**Recovery**: Fix JSON structure or update schema
**Automation Potential**: Medium
---
### Category 8: Request Interruption (2.2%)
**Definition**: User manually interrupted tool execution
**Examples**:
- `[Request interrupted by user for tool use]`
- `Command aborted before execution`
**Common Causes**:
- User realized mistake mid-execution
- User wants to change approach
- Long-running command needs stopping
**Detection Pattern**: `interrupted by user`, `aborted before execution`
**Prevention**: Not applicable (user decision)
**Recovery**: Not needed (intentional)
**Automation Potential**: N/A
---
### Category 9: MCP Server Errors (17.1%)
**Definition**: Errors from Model Context Protocol tool integrations
**Subcategories**:
- 9a. Connection Errors (server unavailable)
- 9b. Timeout Errors (query exceeds time limit)
- 9c. Query Errors (invalid parameters)
- 9d. Data Errors (unexpected format)
**Examples**:
- `MCP server connection failed`
- `Query timeout after 30s`
- `Invalid parameter: status must be 'error' or 'success'`
**Common Causes**:
- MCP server not running
- Network issues
- Query too broad
- Invalid parameters
- Schema changes
**Prevention**:
- Check MCP server status before queries
- Use pagination for large queries
- Validate query parameters
- Handle connection errors gracefully
**Recovery**: Restart MCP server, optimize query, or fix parameters
**Automation Potential**: Medium
---
### Category 10: Permission Denied (0.7%)
**Definition**: Insufficient permissions to access file or execute command
**Examples**:
- `Permission denied: /path/to/file`
- `Operation not permitted`
**Common Causes**:
- File permissions too restrictive
- Directory not writable
- User doesn't own file
**Detection Pattern**: `Permission denied`, `Operation not permitted`
**Prevention**:
- Verify permissions before operations
- Use appropriate user context
- Avoid modifying system files
**Recovery**: Change permissions (chmod/chown)
**Automation Potential**: Low
---
### Category 11: Empty Command String (1.1%)
**Definition**: Bash tool invoked with empty or whitespace-only command
**Examples**:
- `/bin/bash: line 1: : command not found`
**Common Causes**:
- Variable expansion to empty string
- Conditional command construction error
- Copy-paste error
**Detection Pattern**: `/bin/bash: line 1: : command not found`
**Prevention**:
- Validate command strings are non-empty
- Check variable values
- Use bash -x to debug
**Recovery**: Provide valid command string
**Automation Potential**: High
---
### Category 12: Go Module Already Exists (0.4%)
**Definition**: Attempted `go mod init` when go.mod already exists
**Examples**:
- `go: /path/to/go.mod already exists`
**Common Causes**:
- Forgot to check for existing go.mod
- Re-running initialization script
**Detection Pattern**: `go.mod already exists`
**Prevention**:
- Check for go.mod existence before init
- Idempotent scripts
**Recovery**: No action needed
**Automation Potential**: Full
---
### Category 13: String Not Found (Edit Errors) (3.2%)
**Definition**: Edit tool attempts to replace non-existent string
**Examples**:
- `String to replace not found in file.`
- `String: {old content} not found`
**Common Causes**:
- File changed since last inspection (stale old_string)
- Whitespace differences (tabs vs spaces)
- Line ending differences (LF vs CRLF)
- Copy-paste errors
**Detection Pattern**: `String to replace not found in file`
**Prevention**:
- Re-read file immediately before Edit
- Use exact string copies
- Include sufficient context in old_string
- Verify file hasn't changed
**Recovery**:
1. Re-read file to get current content
2. Locate target section
3. Copy exact current string
4. Retry Edit with correct old_string
**Automation Potential**: High
---
## Uncategorized Errors (4.6%)
**Remaining**: 61 errors
**Breakdown**:
- Low-frequency unique errors: ~35 errors (2.6%)
- Rare edge cases: ~15 errors (1.1%)
- Other tool-specific errors: ~11 errors (0.8%)
These occur too infrequently (<0.5% each) to warrant dedicated categories.
---
## Automation Summary
**Automated Prevention Available**:
| Category | Errors | Tool | Coverage |
|----------|--------|------|----------|
| File Not Found | 250 (18.7%) | `validate-path.sh` | 65.2% |
| File Size Exceeded | 84 (6.3%) | `check-file-size.sh` | 100% |
| Write Before Read | 70 (5.2%) | `check-read-before-write.sh` | 100% |
| **Total Automated** | **317 (23.7%)** | **3 tools** | **Weighted avg** |
**Automation Speedup**: 20.9x for automated categories
---
## Transferability
**Universal Categories** (90-100% transferable):
- Build/Compilation Errors
- Test Failures
- File Not Found
- File Size Limits
- Permission Denied
- Empty Command
**Portable Categories** (70-90% transferable):
- Command Not Found
- JSON Parsing
- String Not Found
**Context-Specific Categories** (40-70% transferable):
- Write Before Read (Claude Code specific)
- Request Interruption (AI assistant specific)
- MCP Server Errors (MCP-enabled systems)
- Go Module Exists (Go-specific)
**Overall Transferability**: ~85-90%
---
## Usage
### For Developers
1. **Error occurs** → Match to category using detection pattern
2. **Review common causes** → Identify root cause
3. **Apply prevention** → Check if automated tool available
4. **Execute recovery** → Follow category-specific steps
### For Tool Builders
1. **High automation potential** → Prioritize Categories 3, 4, 5, 11, 12
2. **Medium automation** → Consider Categories 6, 7, 9
3. **Low automation** → Manual handling for Categories 2, 8, 10
### For Project Adaptation
1. **Start with universal categories** (1-7, 10, 11, 13)
2. **Adapt context-specific** (8, 9, 12)
3. **Monitor uncategorized** → Create new categories if patterns emerge
---
**Source**: Bootstrap-003 Error Recovery Methodology
**Framework**: BAIME (Bootstrapped AI Methodology Engineering)
**Status**: Production-ready, validated with 1336 errors
**Coverage**: 95.4% (converged)