Debug

From markmhendrickson/neotoma · View interactive version

Debug is an AI agent skill from the GitHub repository markmhendrickson/neotoma. Debug workflow per foundation command.

How to use this skill

Skill file

Debug Command

Purpose

Check for pending error reports and debug/resolve them. Supports cross-repo error queue checking for sibling repositories. Also manages the error debugging automation watcher.

Command Usage

/debug [action|target-repo-name]

Modes of Operation:

The command operates in two modes based on the first argument:

1. Watcher Management Mode

If the first argument is a watcher management action (start, stop, status, logs, restart), manage the error debugging automation watcher:

/debug start      # Start the error debugging watcher
/debug stop       # Stop the running watcher
/debug status     # Check watcher status
/debug logs       # Show watcher logs
/debug restart    # Restart the watcher

2. Error Debugging Mode (Default)

If the first argument is not a watcher action (or no arguments provided), check and debug pending errors:

/debug                    # Check current repo's pending errors (default)
/debug neotoma            # Check sibling repo's pending errors
/debug personal-project   # Check another sibling repo

Note: To check watcher status, use /debug status. The default behavior (no arguments) checks for pending errors in the current repository.

Parameters:

Examples:

# Watcher management
/debug start      # Start watcher
/debug status     # Check watcher status
/debug logs        # View watcher logs
/debug stop        # Stop watcher

# Error debugging
/debug                    # Check current repo's pending errors
/debug neotoma            # Check sibling repo's pending errors
/debug --list-only       # List errors without debugging
/debug --all --auto      # Process all errors automatically

Workflow

Mode Detection

  1. Check First Argument:

Watcher Management Mode

Action: `start`
  1. Check if already running:
  1. Verify configuration:
  1. Create necessary directories:
  1. Start watcher in background:
  1. Verify start:
Action: `stop`
  1. Check if running:
  1. Verify process exists:
  1. Stop process:
Action: `status` (default)
  1. Check PID file:
  1. Check if process is running:
  1. If running, show:
  1. Also show pending errors count:
Action: `logs`
  1. Check log file:
  1. Display logs:
Action: `restart`
  1. Run stop action (if running)
  2. Wait 1 second
  3. Run start action

Implementation Notes for Watcher Management:

Error Debugging Mode

1. Target Repository Resolution

  1. Get Current Repository Path:

```bash

git rev-parse --show-toplevel

```

Store as current_repo_path

  1. Resolve Target Repository Path:
  1. Validate Target Repository:

2. Load Pending Errors

  1. Read Pending Queue:

```javascript

const pendingPath = path.join(targetRepoPath, '.cursor', 'error_reports', 'pending.json');

if (!fs.existsSync(pendingPath)) {

console.log(No pending errors found in ${targetRepoName}.);

return;

}

const pending = JSON.parse(fs.readFileSync(pendingPath, 'utf8'));

if (pending.length === 0) {

console.log(No pending errors found in ${targetRepoName}. All clear!);

return;

}

```

  1. Sort by Priority:

```javascript

const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };

pending.sort((a, b) => {

// Sort by severity first

const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];

if (severityDiff !== 0) return severityDiff;

// Then by timestamp (oldest first)

return new Date(a.timestamp) - new Date(b.timestamp);

});

```

  1. Display Pending Errors:

```

Found {count} pending error(s) in {target_repo_name}:

1. [CRITICAL] Build Error (error_20250131_143022_build.json)

2. [HIGH] Runtime Error (error_20250131_144510_runtime.json)

```

3. Select Error to Debug

Default Behavior: Auto-select highest priority

  1. Select First Error:
  1. Prompt User for Confirmation:

```

Debugging highest priority error:

Error ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0

Category: build

Severity: critical

Message: Cannot find module '../db'

Affected files: src/services/raw_storage.ts

Proceed with debugging? (yes/no/choose-different/list-only)

```

  1. Handle User Response:

4. Load Error Details

  1. Read Full Error Report:

```javascript

const errorJsonPath = pending[selectedIndex].file_path;

const errorReport = JSON.parse(fs.readFileSync(errorJsonPath, 'utf8'));

```

  1. Display Error Details:

```

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Error Report Details

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Error ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0

Category: build

Severity: critical

Timestamp: 2025-01-31T14:30:22Z

Error Message:

Cannot find module '../db'

Stack Trace:

Error: Cannot find module '../db'

at Object.<anonymous> (src/services/raw_storage.ts:1:1)

at Module._compile (node:internal/modules/cjs/loader:1376:14)

...

Affected Files:

Affected Modules:

Original Task:

Transfer contacts from Parquet to Neotoma

Source Repository:

personal-project (/Users/user/Projects/personal-project)

Target Repository:

neotoma (/Users/user/Projects/neotoma)

Environment:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

```

5. Debug & Fix Error

Integration with fix_feature_bug Command:

  1. Prepare Context for Bug Fix:
  1. Trigger Bug Fix Workflow:
  1. Follow Standard Bug Fix Process:
  1. Alternative: Manual Debugging Mode:

6. Update Resolution Status

After successful fix:

  1. Update Error Report:

```javascript

errorReport.resolution_status = 'resolved';

errorReport.resolution_notes = 'Fixed by correcting import path in raw_storage.ts';

errorReport.resolved_at = new Date().toISOString();

errorReport.resolved_by = 'cursor-agent';

fs.writeFileSync(errorJsonPath, JSON.stringify(errorReport, null, 2), 'utf8');

```

  1. Move to Resolved Directory:

```javascript

const resolvedDir = path.join(targetRepoPath, '.cursor', 'error_reports', 'resolved');

fs.mkdirSync(resolvedDir, { recursive: true });

const jsonBasename = path.basename(errorJsonPath);

const mdBasename = jsonBasename.replace('.json', '.md');

const resolvedJsonPath = path.join(resolvedDir, jsonBasename);

const resolvedMdPath = path.join(resolvedDir, mdBasename);

const errorMdPath = errorJsonPath.replace('.json', '.md');

fs.renameSync(errorJsonPath, resolvedJsonPath);

if (fs.existsSync(errorMdPath)) {

fs.renameSync(errorMdPath, resolvedMdPath);

}

```

  1. Remove from Pending Queue:

```javascript

const pending = JSON.parse(fs.readFileSync(pendingPath, 'utf8'));

const filtered = pending.filter(e => e.error_id !== errorReport.error_id);

fs.writeFileSync(pendingPath, JSON.stringify(filtered, null, 2), 'utf8');

```

  1. Update Markdown Summary:

If fix fails:

  1. Update Status to Failed:

```javascript

errorReport.resolution_status = 'failed';

errorReport.resolution_notes = 'Fix attempted but tests still failing. Requires manual investigation.';

errorReport.failed_at = new Date().toISOString();

fs.writeFileSync(errorJsonPath, JSON.stringify(errorReport, null, 2), 'utf8');

```

  1. Keep in Pending Queue:

7. Output Summary

On Successful Resolution:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error Resolved Successfully
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Error ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
Category: build
Severity: critical

Resolution:
Fixed by correcting import path in raw_storage.ts

Files Changed:
- src/services/raw_storage.ts

Tests Added:
- tests/integration/import_resolution.test.ts

Archived to:
- {target_repo}/.cursor/error_reports/resolved/error_20250131_143022_build.json
- {target_repo}/.cursor/error_reports/resolved/error_20250131_143022_build.md

Remaining pending errors: 1
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Scenario 6: Watcher Management

# Check watcher status (default)
/debug
/debug status

# Start watcher
/debug start

# View logs
/debug logs

# Stop watcher
/debug stop

# Restart watcher
/debug restart

Output (status):

Error Debugging Watcher Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Status: Running
PID: 12345
Uptime: 2h 15m 30s
Configuration: Enabled

Pending Errors: 2
Last Activity: 2025-01-31T15:30:00Z

Use /debug to debug pending errors.

On Failed Resolution:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error Resolution Failed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Error ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
Category: build
Severity: critical

Status: Failed
Notes: Fix attempted but tests still failing. Requires manual investigation.

Error remains in pending queue for retry.

Remaining pending errors: 2
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Command Flags

--list-only

Display pending errors without debugging:

/debug --list-only
/debug neotoma --list-only

Behavior:

--all

Process all pending errors in priority order:

/debug --all
/debug neotoma --all

Behavior:

--auto

Skip confirmation prompts:

/debug --auto
/debug neotoma --auto

Behavior:

Combined Flags

/debug neotoma --all --auto

Process all pending errors in neotoma repo without prompts

Error Handling

Validation Failures

No Error Reports Directory:

No error reports found in {target_repo}.

Directory .cursor/error_reports/ does not exist.
Use /report to create error reports.

Empty Pending Queue:

No pending errors found in {target_repo}.

All clear!

Invalid Target Repo:

Error: Target repository not found: /Users/user/Projects/non-existent-repo

Check repo name and try again.

Invalid Repo Name (Path Traversal):

Error: Invalid repo name: ../secret-repo. Only alphanumeric, hyphens, underscores, and dots allowed.

Permission Error:

Error: No write permission for target repository: /Users/user/Projects/neotoma

Cannot update error reports. Check file permissions.

Configuration

Add to foundation-config.yaml:

development:
  error_debugging:
    enabled: true
    auto_select_highest_priority: true
    require_confirmation: true  # Prompt before debugging
    integrate_fix_feature_bug: true  # Use fix_feature_bug for resolution
    max_errors_to_display: 10
    auto_archive_resolved: true  # Move resolved errors to archive
    automation:
      watch_mode: true  # Enable continuous monitoring via watcher
      cursor_cli:
        # ... cursor_cli configuration ...

Watcher Management:

Integration Points

With `report` Command

With `fix_feature_bug` Command

With Cursor Cloud Agent

Example Usage Scenarios

Scenario 1: Check & Debug Current Repo

/debug

Output:

Found 2 pending error(s) in neotoma:

1. [CRITICAL] Build Error (error_20250131_143022_build.json)
   - ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
   - Timestamp: 2025-01-31T14:30:22Z
   - Message: Cannot find module '../db'

2. [HIGH] Runtime Error (error_20250131_144510_runtime.json)
   - ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U1
   - Timestamp: 2025-01-31T14:45:10Z
   - Message: MCP error -32603: UNKNOWN_CAPABILITY

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Debugging highest priority error (CRITICAL):

Error ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
Category: build
Severity: critical
Message: Cannot find module '../db'

Affected files:
- src/services/raw_storage.ts
- src/services/interpretation.ts
- src/services/entity_queries.ts

Proceed with debugging? (yes/no/choose-different/list-only)

Scenario 2: Check Sibling Repo

/debug neotoma

Output:

Checking pending errors in: /Users/user/Projects/neotoma

Found 1 pending error(s) in neotoma:

1. [HIGH] Runtime Error (error_20250131_144510_runtime.json)
   - ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U1
   - Timestamp: 2025-01-31T14:45:10Z
   - Message: Storage bucket not found
   - Source: personal-project

Debugging error...

[Proceeds with debugging workflow]

Scenario 3: List Only Mode

/debug --list-only

Output:

Found 2 pending error(s) in neotoma:

1. [CRITICAL] Build Error (2025-01-31T14:30:22Z)
   - ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
   - Message: Cannot find module '../db'
   - Affected: src/services/raw_storage.ts

2. [HIGH] Runtime Error (2025-01-31T14:45:10Z)
   - ID: 01JQZ8X9K2M3N4P5Q6R7S8T9U1
   - Message: MCP error -32603: UNKNOWN_CAPABILITY
   - Affected: src/server.ts

Use /debug to debug highest priority error.

Scenario 4: No Pending Errors

/debug

Output (if no watcher action specified, shows status):

Error Debugging Watcher Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Status: Running
PID: 12345
Uptime: 2h 15m 30s

Pending Errors: 0

All clear! No pending errors to debug.

Or if checking errors directly:

No pending errors found in current repository.

All clear!

Scenario 5: Debug All Errors

/debug --all

Output:

Found 3 pending error(s). Processing all in priority order...

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Processing error 1 of 3: [CRITICAL] Build Error
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[Debugging workflow for error 1]

[After error 1 resolved]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Processing error 2 of 3: [HIGH] Runtime Error
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[Debugging workflow for error 2]

...

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All Errors Processed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Total errors: 3
Resolved: 2
Failed: 1

Remaining pending errors: 1

Implementation Checklist

Mode Detection

Watcher Management Mode

Error Debugging Mode

Repository Metadata Collection

For each error report, collect repository metadata:

function getRepositoryMetadata(repoPath) {
  const name = path.basename(repoPath);
  
  let remoteUrl = null;
  try {
    remoteUrl = execSync('git remote get-url origin', { cwd: repoPath })
      .toString()
      .trim();
  } catch {
    // No remote or error getting remote
  }
  
  return {
    path: repoPath,
    name: name,
    remote_url: remoteUrl
  };
}

Testing Scenarios

Test 1: Debug Current Repo with Pending Errors

Setup: Create sample pending.json with 2 errors

Expected: Display errors, debug highest priority

Test 2: Debug Sibling Repo with Pending Errors

Setup: Create errors in sibling repo

Expected: Display errors from sibling repo, debug highest priority

Test 3: No Pending Errors

Setup: Empty or missing pending.json

Expected: Message "No pending errors found. All clear!"

Test 4: Missing Error Reports Directory

Setup: Target repo without .cursor/error_reports/

Expected: Error message with instruction to use /report

Test 5: Invalid Target Repo Name

Setup: Use non-existent sibling repo name

Expected: Error message about target repo not found

Test 6: List Only Mode

Setup: Pending errors exist

Expected: Display errors without debugging, exit

Test 7: Debug All Mode

Setup: Multiple pending errors

Expected: Process all errors in priority order

Test 8: Auto Mode

Setup: Pending errors exist

Expected: Debug highest priority without confirmation prompt

Test 9: Manual Debugging Mode

Setup: Error exists, user chooses manual mode

Expected: Display error details, wait for user to fix, then update status

Test 10: Failed Fix

Setup: Fix attempt fails (tests still failing)

Expected: Update status to 'failed', keep in pending queue

Best Practices

  1. Always validate target repo before reading error reports
  2. Sort by priority to debug critical errors first
  3. Prompt for confirmation unless --auto flag specified
  4. Archive resolved errors for audit trail
  5. Update resolution notes with details of fix
  6. Handle failed fixes gracefully - update status, don't remove from queue
  7. Support manual mode for errors that need human investigation
  8. Display clear summaries of pending errors and resolution results

Watcher Management Examples

Check Watcher Status

/debug
/debug status

Output:

Error Debugging Watcher Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Status: Running
PID: 12345
Uptime: 2h 15m 30s
Configuration: Enabled

Pending Errors: 2
Last Activity: 2025-01-31T15:30:00Z

Use /debug to debug pending errors.

Start Watcher

/debug start

Output:

Started error debugging watcher (PID: 12345)

Watcher is monitoring for new errors and will automatically
debug them when found.

View Watcher Logs

/debug logs
/debug logs --follow  # Tail logs

Output:

Error Debugging Watcher Logs (last 50 lines)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

2025-01-31T15:30:00Z [INFO] Checking for pending errors...
2025-01-31T15:30:00Z [INFO] Found 2 pending errors
2025-01-31T15:30:01Z [INFO] Debugging error: 01JQZ8X9K2M3N4P5Q6R7S8T9U0
2025-01-31T15:30:05Z [INFO] Error resolved successfully
...

Related Documentation

Deprecated Commands

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.