| 1 | # Context Doctor Plugin DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Repair malformed Agent Zero tool-call JSON and preserve raw output as compact thoughts JSON when repair cannot produce a tool call. |
| 6 | |
| 7 | ## Ownership |
| 8 | |
| 9 | - `helpers/context_doctor.py` transforms output and refreshes log fields. |
| 10 | - `hooks.py` installs the exact root-pinned repair dependency in the framework runtime. |
| 11 | - `extensions/python/startup_migration/` prepares that dependency after startup and self-update. |
| 12 | - `extensions/python/message_loop_result/` normalizes completed model output before default processing. |
| 13 | - `webui/config.html` exposes XML suppression and log-detail settings. |
| 14 | |
| 15 | ## Local Contracts |
| 16 | |
| 17 | - Repaired and fallback JSON is always minified. |
| 18 | - Nonempty non-tool output becomes `{"thoughts":[raw]}`; XML-like output becomes `{}` only when suppression is enabled. |
| 19 | - Log kvps retain streamed `reasoning` and normalized `thoughts`, then add |
| 20 | transformed output; `update_log` controls only View Details content. |
| 21 | - A repaired `response` tool call refreshes the response log item when streaming did not create it. |
| 22 | - Runtime setup reads the `json_repair` pin from root `requirements.txt`; do not duplicate its version in plugin code. |
| 23 | |
| 24 | ## Work Guidance |
| 25 | |
| 26 | - Keep repair scoped to complete tool-call JSON. |
| 27 | - Use framework-installed `json_repair`; apply plugin-local parser patch before repair. Do not vendor dependencies. |
| 28 | |
| 29 | ## Verification |
| 30 | |
| 31 | - Run `pytest plugins/_context_doctor/tests`. |
| 32 | |
| 33 | ## Child DOX Index |
| 34 | |
| 35 | No child DOX files. |