4.1 KiB
Iteration Plan (Implementation Tracks)
To safely refactor a linear, single-agent codebase into the 4-Tier Multi-Model Architecture without breaking the working prototype, the implementation should be sequenced into these five isolated Epics (Tracks):
Track 1: The Memory Foundations (AST Parser)
Goal: Build the engine that prevents token-bloat by turning massive source files into curated memory views. Implementation Details:
- Integrate
tree-sitterand language bindings intofile_cache.py. - Build
ASTParserextraction rules:- Skeleton View: Strip function/class bodies, preserving only signatures, parameters, and type hints.
- Curated View: Preserve class structures, module docstrings, and bodies of functions marked
# [HOT]or@core_logic. Replace standard bodies with... # Hidden.
- Acceptance:
file_cache.get_curated_view('script.py')returns a perfectly formatted summary string in the terminal.
Track 2: State Machine & Data Structures
Goal: Define the rigid Python objects the AI agents will pass to each other to rely on structured data, not loose chat strings. Implementation Details:
- Create
models.pywithpydanticordataclassesforTrack(Epic) andTicket(Task). - Define
WorkerContextholding the Ticket ID, assigned model (fromagents.toml), isolatedcredentials.tomlinjection, and amessagespayload array. - Add helper methods for state mutators (e.g.,
ticket.mark_blocked(),ticket.mark_complete()). - Acceptance: Instantiate a
Trackwith 3Ticketsand successfully enforce state changes in Python without AI involvement.
Track 3: The Linear Orchestrator & Execution Clutch
Goal: Build the synchronous, debuggable core loop that runs a single Tier 3 Worker and pauses for human approval. Implementation Details:
- Create
multi_agent_conductor.pywith arun_worker_lifecycle(ticket: Ticket)function. - Inject context (Raw View from
file_cache.py) and format themessagesarray for the API. - Implement the Clutch (HITL):
input()pause for CLI or wait state for GUI before executing the returned tool (e.g.,write_file). Allow manual memory mutation of the JSON payload. - Acceptance: The script sends a hardcoded Ticket to DeepSeek, pauses in the terminal showing a diff, waits for user approval, applies the diff via
mcp_client.py, and wipes the worker's history.
Track 4: Tier 4 QA Interception
Goal: Stop error traces from destroying the Worker's token window by routing crashes through a stateless translator. Implementation Details:
- In
shell_runner.py, interceptstderr(e.g.,returncode != 0). - Do not append
stderrto the main Worker's history. Instead, instantiate a synchronous API call to thedefault_cheapmodel. - Prompt: "You are an error parser. Output only a 1-2 sentence instruction on how to fix this syntax error." Send the raw
stderrand target file snippet. - Append the translated 20-word fix to the main Worker's history as a "System Hint".
- Acceptance: A deliberate syntax error triggers the execution engine to silently ping the cheap API, returning a 20-word correction to the Worker instead of a 200-line stack trace.
Track 5: UI Decoupling & Tier 1/2 Routing (The Final Boss)
Goal: Bring the system online by letting Tier 1 and Tier 2 dynamically generate Tickets managed by the async Event Bus. Implementation Details:
- Implement an
asyncio.Queueinmulti_agent_conductor.py. - Write Tier 1 & 2 system prompts forcing output as strict JSON arrays (Tracks and Tickets).
- Write the Dispatcher async loop to convert JSON into
Ticketobjects and push to the queue. - Enforce the Stub Resolver: If a Ticket archetype is
contract_stubber, pause dependent Tickets, run the stubber, triggerfile_cache.pyto rebuild the Skeleton View, then resume. - Acceptance: Vague prompt ("Refactor config system") results in Tier 1 Track, Tier 2 Tickets (Interface stub + Implementation). System executes stub, updates AST, and finishes implementation automatically (or steps through if Linear toggle is on).