AgentSkillsCN

DDD Filter Management

为去中心化诊断守护者(DDD)提供创建、调试与维护输出过滤器的操作指南。

SKILL.md
--- frontmatter
name: DDD Filter Management
description: Instructions for creating, debugging, and maintaining output filters for the Decentralized Diagnostics Daemon (DDD).

DDD Filter Management Skill

The Decentralized Diagnostics Daemon (DDD) uses "Filters" to parse raw build output strings into structured JSON diagnostics. These diagnostics are used by the "Mechanic" (Autofix) system to repair code.

As an Agent, you are responsible for maintaining these filters to ensuring the Mechanic can "see" errors correctly.

📍 Locations

  • Project Filters: <project_root>/.ddd/filters/
    • Place custom filters here. They are loaded automatically by dd-daemon.py if the project root is configured correctly.
    • Best Practice: Always create new filters here unless instructed to patch the core.
  • Core Filters: mission/internal/scripts/ddd/src/filters/
    • Built-in filters (e.g. gcc_json.py). Modify only if patching the Mission Pack itself.

🛠️ How to Create a Filter

  1. Read the Template: Use view_file on .ddd/filters/templates/filter.template.py (or see the template below).
  2. Implementation:
    • Inherit from BaseFilter.
    • Implement process(self, text) -> str.
    • Input: Raw text (stdout/stderr) from the build command.
    • Output: A JSON string representing a list of diagnostic objects.
    • Decorator: Use @register_filter("my_filter_name").
  3. Deploy: Write the file to <project_root>/.ddd/filters/<name>.py.

Diagnostic Object Format

Your JSON output must be a list of objects with these keys:

json
[
  {
    "file": "src/main.c",
    "line": 10,
    "col": 5,           // Optional
    "type": "error",    // "error", "warning", "note"
    "message": "expected ';'"
  }
]

🔍 Debugging Filters

If the Mechanic isn't fixing an error, the filter might be failing to parse the log.

  1. Check Raw Log: tail -n 50 .ddd/run/build.log
    • Ensure the error text actually appears there.
  2. Check Report: cat .ddd/run/build_report.json
    • If this is empty [] or null, your regex is likely wrong.
  3. Test Locally:
    • Create a test script that imports your filter and runs process() against a sample string.
    • Do NOT rely on waiting for the daemon loop for tight iteration.

📝 Template

python
import re
import json
from . import register_filter
from .base import BaseFilter

@register_filter("custom_parser")
class CustomParserFilter(BaseFilter):
    def process(self, text):
        results = []
        # Regex Example: "Error at line 10 in file.c: Bad syntax"
        regex = re.compile(r"Error at line (\d+) in (.+): (.+)")
        
        for match in regex.finditer(text):
            results.append({
                "line": int(match.group(1)),
                "file": match.group(2),
                "type": "error",
                "message": match.group(3)
            })
            
        return json.dumps(results)