Skip to content

Add C# reflection-based decomposition strategy#18

Merged
JMRussas merged 2 commits intomainfrom
feature/csharp-reflection-decomposition
Mar 6, 2026
Merged

Add C# reflection-based decomposition strategy#18
JMRussas merged 2 commits intomainfrom
feature/csharp-reflection-decomposition

Conversation

@JMRussas
Copy link
Owner

@JMRussas JMRussas commented Mar 6, 2026

Summary

  • Add a csharp_reflection decomposition strategy that uses .NET Reflection to extract type metadata and generate function-level implementation tasks with typed contracts
  • New .NET console app (tools/dotnet-reflector/) loads assemblies via MetadataLoadContext and outputs structured JSON (classes, methods, signatures, properties, constructors)
  • C# planner prompt variant injects the reflected type map, generating method-level tasks with target_signature, available_methods, and constructor_params
  • WorkerInstruction XML prompt constrains AI workers to output only the method body using strictly available methods
  • Decomposer auto-creates assembly tasks (one per class) that stitch method bodies and run dotnet build
  • Build verification utility in task_lifecycle.py for compile-time validation

Files changed

  • New: tools/dotnet-reflector/ (.NET reflector app), backend/tools/dotnet_reflection.py (Python wrapper)
  • Modified: planner.py (C# prompt + strategy routing), claude_agent.py (WorkerInstruction), decomposer.py (C# context + assembly tasks), task_lifecycle.py (build verification), container.py (tool_registry → planner), registry.py (register reflector)
  • Tests: 4 new test files, 40 new tests (779 total)

Test plan

  • 40 new tests cover: reflection tool (mocked subprocess), C# planner prompt construction, worker prompt XML structure, decomposer assembly task creation, build verification
  • CI doesn't need .NET SDK — reflection tool tests mock subprocess calls
  • Full suite: 779 passed, lint clean

Generated by Claude Code · Claude Opus 4.6

JMRussas and others added 2 commits March 5, 2026 22:51
Three-phase feature for function-level C# code generation:

Phase 1 - Reflection Scanner:
- .NET console app (tools/dotnet-reflector/) using MetadataLoadContext
  to extract type metadata from assemblies without execution
- Python tool wrapper (backend/tools/dotnet_reflection.py) with
  build, reflect, and format_type_map functions
- Registered in ToolRegistry (conditional on dotnet CLI availability)

Phase 2 - C# Planner Prompt:
- New decomposition_strategy "csharp_reflection" in project config
- Planner runs reflection, injects type map into planning prompt
- Claude generates method-level tasks with typed contracts
  (target_signature, available_methods, constructor_params)
- Falls back to generic planner if reflection fails

Phase 3 - Worker Prompt + Assembly:
- WorkerInstruction XML prompt in claude_agent.py for csharp_method
  tasks — constrains AI to output only the method body
- Decomposer injects C# context fields and auto-creates assembly
  tasks (one per class, depends on all method tasks)
- Build verification via dotnet build in task_lifecycle.py

40 new tests across 4 test files. 779 total passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JMRussas JMRussas merged commit 1629747 into main Mar 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant