Code Intelligence¶
Eight components for code analysis, generation, self-healing, debugging, and security -- enabling G6 agents to read, write, and repair code programmatically.
Overview¶
Code Intelligence gives G6 the ability to operate on source code as a first-class data type. meta_programming provides AST-based parsing, function extraction, renaming, transformation, and code generation (functions, classes, dataclasses). adapt_healing detects errors, diagnoses root causes via LLM-assisted hint generation, and applies bounded patches that should be verified against tests -- backed by 25 MCP tools and seven SQLite tables for healing history.
self_debug and system_doctor handle runtime debugging and system-level diagnostics respectively. auto_engineer provides automated code generation workflows. The web-focused components (adapt_django, adapt_webpage) and cyber_security extend code intelligence into specific domains.
Production boundary
Code Intelligence components can read, generate, transform, and sometimes execute code. Treat generated/refactored output as a draft until tests, security scans, and human review pass. In particular, meta_programming.run_code is a trusted-local subprocess utility, not a hosted sandbox for arbitrary untrusted customer code; Context7-backed doc fetching also depends on external tooling and quota.
system_doctor and adapt_healing are reliability aids, not general autonomous production repair engines. They are appropriate for assisted diagnosis, bounded local Python fixes, health checks, learning from repair attempts, and escalation. Before using a generated patch in production, review the diff, run the relevant tests, and keep rollback available.
The healing subsystem deserves special attention: it captures execution context (traceback frames, exception details), classifies error types (ImportError, JSONDecodeError, AttributeError, IndentationError, NameError), generates hints using Claude with rule-based fallback, and tracks drift using DDM (Drift Detection Method) patterns from the Self_Healing_ML literature.
Components¶
| Component | Description | MCP Tools |
|---|---|---|
| meta_programming | AST parsing, code generation, transformation | -- |
| self_debug | Runtime debugging and error analysis | -- |
| auto_engineer | Automated code generation workflows | -- |
| adapt_healing | Assisted self-healing with error classification, patching, and verification | 25 |
| system_doctor | System-level diagnostics and health checks | -- |
| adapt_django | Django project code intelligence | -- |
| adapt_webpage | Pilot-ready webpage scaffolding, previews, persistence, and SEO/accessibility audit checks | -- |
| cyber_security | Security analysis and vulnerability detection | -- |
Architecture¶
graph TD
META[meta_programming] --> CORE[core.AIBlock]
HEAL[adapt_healing] --> META
HEAL --> DB[(SQLite<br/>7 tables)]
HEAL --> LLM[llm_router]
DEBUG[self_debug] --> META
AUTO[auto_engineer] --> META
AUTO --> LLM
DOC[system_doctor] --> DEBUG
DJANGO[adapt_django] --> META
WEB[adapt_webpage] --> META
SEC[cyber_security] --> META Key Patterns¶
List-of-Lines Code Generation. meta_programming builds generated code as a list of strings (one per line) rather than using textwrap.dedent. This avoids subtle indentation bugs that arise when mixing template strings with Python's whitespace sensitivity.
Error Type Classification. adapt_healing classifies errors into specific types (ImportError, JSONDecodeError, AttributeError, etc.) and applies type-specific hint templates before falling back to LLM-assisted diagnosis. This ensures fast, deterministic responses for common errors while reserving LLM calls for novel failures.
Healing History. Every healing attempt is persisted to SQLite across seven tables (healings, patches, errors, rules, contexts, backups, retry_strategies). This creates an institutional memory that enables pattern detection -- if the same error recurs, the system can apply a previously successful patch without LLM involvement.
Related Clusters¶
- Formal Verification -- CEGIS synthesizes code; formal methods verify it
- Safety & Alignment -- code execution is a CSF-guarded hazard (p=0.10)
- Agents & LLM -- agents invoke metaprogramming for code tasks