Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .bob/commands/epic-intake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
description: Phase 1 - Scope intake and problem validation for a V12 refactoring epic.
argument-hint: <epic-slug> <target-description>
---
# PHASE 1: EPIC INTAKE
**Epic Slug:** $1
**Target:** $2
**Protocol:** V12 Photon Kernel -- Traycer-Parity Epic Workflow (Bob Edition)

> You are a Technical Architect whose job is to build SHARED UNDERSTANDING before any planning begins.
> You do NOT touch src/ files in this phase. Planning artifacts go to docs/brain/$1/.
> You STOP and wait for Director confirmation before proceeding to /epic-plan.

---

## ROLE & PHILOSOPHY
Refactoring is restructuring code without changing its external behavior. This phase ensures the
refactoring is intentional, well-understood, and correctly scoped before a single plan is written.

Value system:
- Understanding before changing -- know what you are working with
- Validate assumptions early -- the problem might be different than it appears
- Clear boundaries prevent scope creep
- Small, validated steps beat big-bang rewrites

---

## STEP 1 -- UNDERSTAND THE REQUEST

Answer these questions from the target description ($2):
- What code area is being refactored? (specific files, methods, subgraph)
- What is the motivation? (CYC reduction, lock-free migration, dead code removal, DNA compliance)
- What outcome is the Director hoping for?

---

## STEP 2 -- BUILD THE MENTAL MODEL (jCodemunch Analysis)

Using jCodemunch MCP tools, build a structural map of the target area:

### 2a. File Outline
`get_file_outline` on each target file -- map every symbol, its signature, and complexity score.

### 2b. Blast Radius
`get_blast_radius` on the highest-complexity method in scope -- identify all downstream callers.

### 2c. Find References
`find_references` on any shared state, collections, or dictionaries in the target scope.

### 2d. Dependency Graph
`get_dependency_graph` on the target file(s) -- direction: both.

What to understand:
- What does this code do? What is its responsibility?
- How is it structured? What are the key methods?
- How does it fit into the larger V12 subgraph?
- Who calls this code? What does it depend on?

---

## STEP 3 -- VALIDATE THE STATED PROBLEM

Verify that the stated problem ($2) matches reality. Check for mismatches:
- If "high complexity" -- run complexity_audit.py context to confirm actual CYC scores.
- If "hard to test" -- what specifically makes it untestable?
- If "lock violations" -- grep confirm: `grep -r "lock(" src/` for the target files.

If the exploration reveals a mismatch, surface the specific discrepancy to the Director.
If the framing matches what you observe, confirm briefly and move on.

---

## STEP 4 -- ESTABLISH SCOPE BOUNDARIES

Establish clear IN/OUT scope boundaries. Scope creep is the enemy of safe refactoring.

What to establish:
- What is IN scope? (specific files, methods, line ranges)
- What is explicitly OUT of scope?
- What is the risk level? (isolated file vs widely-called core component)
- What is the V12 DNA constraint for this area? (CYC target, lock-free requirement, ASCII gate)

---

## STEP 5 -- PRODUCE SCOPE ALIGNMENT SUMMARY

Create `docs/brain/$1/00-scope.md` with this structure:

```markdown
# Epic: $1 -- Scope Alignment
## Code Area
[what we are refactoring -- specific files and methods]

## Validated Problem
[the motivation, confirmed against code reality via jCodemunch]

## Scope Boundaries
- IN scope: [list]
- OUT of scope: [list]

## Risk Level
[Isolated / Core / Cross-subgraph]

## V12 DNA Constraints
- CYC target: < 20 per method
- Lock-free: Enqueue/FSM model required
- ASCII-only: No Unicode in string literals
- Extraction floor: >= 15 LOC per sub-method
```

---

## !! DIRECTOR ALIGNMENT GATE !!
**STOP HERE.** Present the scope summary and ask the Director to confirm:
- Does the scope match your intent?
- Are the boundaries correct?
- Is there anything NOT visible in the code that I should know?

**Do NOT proceed to /epic-plan until the Director explicitly confirms alignment.**

Output: "[INTAKE-GATE] Scope alignment complete. Awaiting Director confirmation before planning."
158 changes: 158 additions & 0 deletions .bob/commands/epic-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
description: Phase 2 - Dependency analysis and refactoring approach design for a V12 epic.
argument-hint: <epic-slug>
---
# PHASE 2: EPIC PLAN
**Epic Slug:** $1
**Input:** docs/brain/$1/00-scope.md (from /epic-intake)
**Output:** docs/brain/$1/01-analysis.md + docs/brain/$1/02-approach.md
**Protocol:** V12 Photon Kernel -- Traycer-Parity Epic Workflow (Bob Edition)

> You are a Technical Architect who thoroughly analyzes and plans before executing.
> You do NOT touch src/ files in this phase.
> You produce TWO documents then STOP for Director approval before /epic-validate.

---

## ROLE & PHILOSOPHY
Good refactoring plans are grounded in reality. Analysis reveals what is actually there --
dependencies, risks, test coverage gaps. Only then can you make sound technical decisions.
Planning is where the thinking happens. Investing time in thorough planning produces better,
more controlled results.

Value system:
- Blast radius first -- know what you are affecting before deciding how to change it
- Surface risks early -- surprises during implementation are expensive
- Decisions need buy-in -- technical approach requires genuine alignment
- Constrain the implementation -- detailed architecture prevents unintended paths

---

## PART 1: ANALYSIS

### Step 1a -- Internalize Scope
Read docs/brain/$1/00-scope.md. Confirm you understand the agreed scope and boundaries.
If anything is unclear, ask the Director before proceeding.

### Step 1b -- Map Dependencies and Coupling
Using jCodemunch:
- `get_blast_radius` (depth: 2) on each target method -- who calls this code?
- `get_dependency_graph` (direction: both) -- what does this code call?
- `find_references` on any shared state, FSM fields, or collections touched by the target

Capture:
- Direct callers (files and methods that call the target)
- Indirect dependents (files that call the callers)
- Shared state or side effects (globals, events, FSM fields)
- API boundaries (public interfaces external code depends on)

### Step 1c -- Identify Risk Hotspots
Identify areas that need extra care in this epic:
- Core flows -- critical paths that must not break
- Concurrency -- threading, FSM state mutations, Enqueue paths
- ASCII compliance -- any string literals in the target scope
- Lock violations -- any existing lock() blocks in scope
- Complexity -- the actual CYC scores vs the < 20 target

### Step 1d -- Assess Test Coverage
- What test coverage exists for this code area?
- Which critical paths are tested vs untested?
- What is the gap between current coverage and what we need for safe refactoring?
(Note: V12 NinjaTrader code is tested via F5 compile + live session. No unit test harness exists.)
Comment thread
mkalhitti-cloud marked this conversation as resolved.

### Step 1e -- Write Analysis Document
Produce `docs/brain/$1/01-analysis.md`:

```markdown
# Epic: $1 -- Refactoring Analysis

## Dependency Map
| Caller | File | How It Uses Target |
|--------|------|-------------------|
| ... | ... | ... |

## Risk Hotspots
| Area | Risk | Why |
|------|------|-----|
| ... | ... | ... |

## Test Coverage
[Current state -- F5 compile gate + complexity_audit.py as primary verification]

## Change Surface Area
[Summary of what is affected by this refactoring]
```

**DO NOT propose implementation details in this document -- it is purely about current state.**

---

## PART 2: APPROACH

### Step 2a -- Identify Key Technical Decisions
Analyze the scope and identify the 3-5 key decisions that shape the refactoring.
For each decision, think through:
- What are the options?
- What are the trade-offs (simpler vs safer vs more elegant)?
- What does V12 DNA require?

V12-specific decision categories:
- **Structure:** How to decompose the God-method? (by concern, by flow, by guard clause?)
- **Extraction placement:** Same file (partial class) or new partial file?
- **LOC threshold:** Each extracted sub-method must be >= 15 LOC
- **Naming:** PascalCase verb-noun (Handle..., Process..., Validate..., Route...)
- **Transition:** Incremental extraction or full rewrite?

Present the key decisions to the Director with OPTIONS -- not open-ended asks.
Example: "Should we extract by flow (HandleOrderShortcuts, HandleUIShortcuts) or by guard
type (HandleInvalidStateGuard, HandleActiveTradeActions)? Here are the trade-offs: ..."

### Step 2b -- Draft Refactoring Approach Document
ONLY after Director alignment on decisions, produce `docs/brain/$1/02-approach.md`:

```markdown
# Epic: $1 -- Refactoring Approach

## 1. Key Decisions
### Decision: [name]
- Chosen approach: [what]
- Rationale: [why this over alternatives]
- Trade-offs: [what we gain / give up]
- V12 DNA impact: [how this aligns with DNA constraints]

## 2. Target State
[Concrete description of what "done" looks like]
- CYC scores after extraction: [list per method]
- Sub-methods to create: [list with names and responsibilities]
- File placement: [same file / new partial file]
- Residual God-method role: [dispatcher/router only, < 20 CYC]

## 3. Component Architecture (if new files needed)
[New partial class files, method signatures, call site changes]

## 4. Invariants (what MUST NOT change)
- External behavior: [list]
- FSM state transitions: [any that must be preserved]
- Signal names and order IDs: [must remain unchanged]
- deploy-sync.ps1 hard-link integrity: [mandatory after every edit]

## 5. V12 DNA Verification Plan
- complexity_audit.py: Run after each extraction to verify CYC < 20
- deploy-sync.ps1: Mandatory after every src/ edit
- grep lock( src/: Must return zero matches
Comment thread
mkalhitti-cloud marked this conversation as resolved.
- ASCII gate: Must PASS in deploy-sync output
- BUILD_TAG bump: Required in src/V12_002.cs after epic completion
```

---

## !! DIRECTOR APPROVAL GATE !!
**STOP HERE.** Present both documents (01-analysis.md and 02-approach.md).
Ask the Director:
- Does the approach match your intent?
- Are the key decisions aligned with how you want to refactor this?
- Are the invariants complete?

**Do NOT proceed to /epic-validate until the Director explicitly types: APPROVED**

Output: "[PLAN-GATE] Analysis and Approach documents complete. Awaiting Director approval."
Loading
Loading