$npx -y skills add Negai-ai/AgentClaw --skill coding_skillInspect, edit, test, refactor, and validate project code inside the configured project directory. Use when the task involves source search, code reading, bug fixes, implementation changes, syntax checks, automated tests, file moves, or refactors.
| 1 | # Coding Skill (Primary Playbook) |
| 2 | |
| 3 | This `SKILL.md` is the default guide for common coding tasks. |
| 4 | Focus on reliable tool usage and verifiable code changes. |
| 5 | Load `references/*` only when needed. |
| 6 | |
| 7 | ## 1) Scope and Boundary |
| 8 | |
| 9 | - This skill covers generic coding work: discover, read, edit, refactor, and validate code. |
| 10 | - This skill is tool-centric. Keep guidance about product/domain-specific implementation out of the main flow. |
| 11 | - All coding-tool paths are resolved under `project_dir`. Paths outside `project_dir` are invalid. |
| 12 | - Use minimal edits first; escalate to broad rewrites only when partial edits are unstable. |
| 13 | - Do not introduce hardcoded secrets, machine-specific absolute paths, or environment-specific install commands in generated code. |
| 14 | |
| 15 | ## 2) Zero-Context Execution Flow (Default) |
| 16 | |
| 17 | When repository context is limited, use this fixed sequence: |
| 18 | |
| 19 | 1. `search_code` to locate files/snippets. |
| 20 | 2. Run quick environment preflight for path/tool consistency: |
| 21 | - confirm `project_dir`-relative target paths |
| 22 | - avoid bare `pip`; prefer interpreter-scoped install commands when needed |
| 23 | 3. `read_code` to load exact edit context. |
| 24 | 4. Apply smallest safe edit (`replace_in_file` or `update_code`). |
| 25 | 5. For Python edits: |
| 26 | - If you used `write_code`: syntax is already validated (pre-write check). Do NOT call `syntax_check` in the same tool call — the file won't exist yet when parallel tools run. Only use `syntax_check` separately for `replace_in_file` / `update_code` edits. |
| 27 | - `python -m py_compile <changed_file>.py` (optional, for import-level validation; on Windows you may also use `py -3 -m py_compile`) |
| 28 | 6. If syntax fails, patch the failing region with local edits first (`replace_in_file` / `update_code`), then re-run checks. |
| 29 | 7. Re-read changed region (`read_code`) when ambiguity/count errors occurred. |
| 30 | 8. Report changed files, validations, and unresolved risks. |
| 31 | |
| 32 | Prefer not to skip to later steps when an earlier step fails. |
| 33 | |
| 34 | ## 3) Tool Contract (Default) |
| 35 | |
| 36 | ### 3.1 `search_code` |
| 37 | |
| 38 | Purpose: text/regex discovery in project files. Returns `file:line:col: matched_text` for each match. |
| 39 | |
| 40 | **Important**: This tool only returns the matching line text, NOT full function/class definitions or surrounding code. To read the full implementation of a matched symbol, use `read_code` with the file path and line range from search results. |
| 41 | |
| 42 | Required: |
| 43 | - `query` (string) |
| 44 | |
| 45 | Common optional: |
| 46 | - `path` (default `"."`) |
| 47 | - `file_glob` (default `"**/*"`) |
| 48 | - `use_regex` (default `false`) |
| 49 | - `max_results` (default `200`, range `1-1000`) |
| 50 | |
| 51 | Example: |
| 52 | |
| 53 | ```json |
| 54 | { |
| 55 | "query": "class Workflow", |
| 56 | "path": "agentclaw", |
| 57 | "file_glob": "**/*.py" |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | ### 3.2 `read_code` |
| 62 | |
| 63 | Purpose: read file content by line range or Python symbol. |
| 64 | |
| 65 | Required: |
| 66 | - `path` |
| 67 | |
| 68 | Optional: |
| 69 | - `start_line`, `end_line` |
| 70 | - `symbol` (Python only) |
| 71 | - `symbol_type` (`auto|function|class`) |
| 72 | |
| 73 | Examples: |
| 74 | |
| 75 | ```json |
| 76 | { |
| 77 | "path": "agentclaw/graph/workflow.py", |
| 78 | "start_line": 60, |
| 79 | "end_line": 180 |
| 80 | } |
| 81 | ``` |
| 82 | |
| 83 | ```json |
| 84 | { |
| 85 | "path": "agentclaw/node/llm.py", |
| 86 | "symbol": "_build_messages", |
| 87 | "symbol_type": "function" |
| 88 | } |
| 89 | ``` |
| 90 | |
| 91 | ### 3.3 `syntax_check` |
| 92 | |
| 93 | Purpose: language-aware syntax diagnostics. |
| 94 | |
| 95 | Required: |
| 96 | - `path` |
| 97 | |
| 98 | Optional: |
| 99 | - `language` override (`py|js|ts|json|yaml|toml`) |
| 100 | - `context_lines` (default `3`, range `0-8`) |
| 101 | - `include_source_context` (default `true`) |
| 102 | |
| 103 | Example: |
| 104 | |
| 105 | ```json |
| 106 | {"path":"agentclaw/node/llm.py"} |
| 107 | ``` |
| 108 | |
| 109 | When to use: |
| 110 | - immediately after editing Python/JS/TS/JSON/YAML/TOML files |
| 111 | - before `py_compile`/register/runtime checks |
| 112 | |
| 113 | When NOT to use: |
| 114 | - for semantic/runtime logic debugging (it is syntax-focused) |
| 115 | - as a replacement for import/runtime validation |
| 116 | |
| 117 | Common failure shapes -> next action: |
| 118 | - `path_not_found` / `Not a file` |
| 119 | - align path with `project_dir`, then retry same check |
| 120 | - `PY_SYNTAX_ERROR` / syntax diagnostics with line+col |
| 121 | - patch failing region via `replace_in_file` or `update_code`, then re-run `syntax_check` |
| 122 | - checker unavailable (`node`, `tsc`, `PyYAML`, `tomli`) |
| 123 | - report dependency gap and continue with partial validation |
| 124 | |
| 125 | Output format: |
| 126 | - Human-readable block first (error message, source context with `>` marker, smart HINT), followed by structured JSON. |
| 127 | - HINT line detects common root causes: |
| 128 | - `HTML entities (" > ')` → use `write_code` instead of `write_file` to auto-sanitize. |
| 129 | - `double-escaped sequences (\\\\n)` → use literal multi-line content or single `\\n`. |
| 130 | - `ok=true` + `status=success`: syntax pass with no flagged risk pattern. |
| 131 | - `ok=true` + `status=warning`: syntax pass but `risk_diagnostics` is non-empty. |
| 132 | - treat as unresolved risk and patch before claiming completion. |
| 133 | - `ok=false` + `diagnostics`: syntax failure; repair same region first. |
| 134 | |
| 135 | ### 3.4 `update_code` |
| 136 | |
| 137 | Purpose: regex-based code update wi |