Skip to content
Open
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
9 changes: 8 additions & 1 deletion .agent/workflows/multi_agent_audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Mandatory for any change touching: order submission, position sizing, FSM state

1. Identify the implementation to audit (file path, diff, or code block).
2. Define audit criteria:
- **Systemic Anti-Patterns (MANDATORY)**: Mandate the grouping of localized flaws under root-cause architectural patterns (e.g., TOCTOU, Bypassing Enqueue, Non-Atomic mutations).
- **Safety**: ghost orders, naked positions, shutdown races
- **Correctness**: FSM state coverage, edge cases
- **DNA compliance**: no locks, correct pattern (Enqueue vs direct-write), ASCII gate
Expand All @@ -23,6 +24,8 @@ Mandatory for any change touching: order submission, position sizing, FSM state

Invoke each auditor with IDENTICAL input. They must NOT see each other's output.

**CRITICAL PROMPT INSTRUCTION:** All auditors MUST audit the architectural contracts, not just the execution paths. Do not simply list individual bugs. You must synthesize and group every localized bug under a systemic structural anti-pattern or V12 DNA violation.

| Auditor | Tool | Focus |
| --------- | --------------- | ------------------------------------ |
| FORENSICS | Codex forensics | Logic trace, state sequence proof |
Expand All @@ -36,8 +39,12 @@ RED TEAM AUDIT — [Auditor Name] — [Date]

VERDICT: [PASS / FAIL / CONDITIONAL]

Systemic Anti-Patterns:
1. [Pattern Name]: [Description] (Affects Findings X, Y)
2. ...

Findings:
1. [Finding + severity: CRITICAL / WARNING / INFO]
1. [Finding + severity: CRITICAL / WARNING / INFO] (Maps to Pattern X)
2. ...

Recommendation: [APPROVE / REVISE / BLOCK]
Expand Down
185 changes: 185 additions & 0 deletions .bob/commands/bob-tdd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
description: Execute a single complexity extraction ticket using the full P2-P6 TDD Red-Green-Refactor pipeline.
argument-hint: <traycer-ticket-content>
---
# MISSION: Bob TDD -- V12 Photon Kernel Complexity Extraction
**Spec Ref**: docs/brain/bob_tdd_workflow.md
**Protocol**: V12 Photon Kernel DNA (Lock-Free, ASCII-Only, TDD Red-Green-Refactor)

---

## STEP 1 -- P2 FORENSICS (Plan Mode)

Before writing any code or plan, run forensic analysis:

### 1a. jCodemunch Structural Scan
- `get_file_outline` on the target file -- map every symbol, signature, complexity score
- `get_blast_radius` on the target method -- identify all downstream callers
- `find_references` on any shared state accessed in the method

### 1b. Complexity Baseline
Run: `python scripts/complexity_audit.py`
Record the BEFORE CYC score for the target method.

### 1c. Graphify Caller Map
Run: `graphify update .`
Read `graphify-out/GRAPH_REPORT.md` -- confirm caller impact scope.

**Output**: Write `docs/brain/forensics_report_t[ID].md` with:
- Target method name + current CYC score
- Blast radius (callers list)
- Proposed extraction boundary (helper name + signature draft)
- DNA risks identified

---

## STEP 2 -- P3 ARCHITECT PLAN (Plan Mode)

Produce a written implementation plan:

```
## Bob TDD Plan: [ticket ID] -- [method name]
### Extraction Design
| Helper Name | Signature | Lines Extracted | CYC Impact |
|-------------|-----------|-----------------|------------|
| ... | ... | ... | ... |

### Caller Impact
| Caller File | Caller Method | Change Required |
|-------------|---------------|-----------------|
| ... | ... | ... |

### TDD Contract Tests Required
| Test # | Scenario | Expected Result |
|--------|-----------------|-----------------|
| 1 | Happy path | ... |
| 2 | Null/guard edge | ... |
| 3 | Caller invariant| ... |
```
Comment on lines +40 to +58
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add explicit language tags for these fenced blocks.

Both blocks are missing a fence language and trigger markdownlint MD040.

Also applies to: 158-173

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 40-40: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.bob/commands/bob-tdd.md around lines 40 - 58, The fenced code blocks in
.bob/commands/bob-tdd.md (the block under "## Bob TDD Plan: [ticket ID] --
[method name]" and the similar block around lines 158-173) are missing a
language tag and trigger markdownlint MD040; update each opening triple-backtick
fence to include an explicit language (e.g., ```markdown or ```text) so the
blocks are lint-compliant, making the change where the fences appear near the
"Extraction Design / Caller Impact / TDD Contract Tests Required" sections.


**Output**: Write `docs/brain/implementation_plan_t[ID].md`

### !!! DIRECTOR APPROVAL GATE !!!
**STOP HERE. Do NOT proceed to Step 3 until the Director explicitly confirms.**

Output: "[BOB-TDD-GATE] Plan written to docs/brain/implementation_plan_t[ID].md. Awaiting Director approval."

---

## STEP 3 -- P4 ADJUDICATOR AUDIT (Internal)

Perform adversarial self-audit of the plan against V12 DNA:

Checklist:
- [ ] Zero lock() usage in proposed code
- [ ] No Thread.Sleep in proposed tests
- [ ] Extraction is >= 15 LOC (extraction floor)
- [ ] No logic drift -- pure structural extraction
- [ ] ASCII-only in all string literals
- [ ] deploy-sync.ps1 is included in post-edit sequence

**Output**: Write `docs/brain/adjudicator_audit_t[ID].md`

If any checklist item FAILS: return `CONDITIONAL PASS` with specific clarification.
If all pass: return `PASS -- CLEARED FOR P5 EXECUTION`.

---

## STEP 4 -- P5 ENGINEER (Advanced/Code Mode) -- RED-GREEN

### RED Phase: Write Failing Contract Tests FIRST

Before touching src/, write the contract tests to `tests/[SubgraphName]IntegrationTests.cs`:

Required scenarios:
1. **Happy path**: normal input -> expected extracted-helper output
2. **Null/guard edge**: boundary condition -> must not throw or corrupt state
3. **Caller invariant**: call site behavior is identical before and after extraction

The tests MUST fail at this point (RED). Do NOT proceed if they pass -- that means
the test is not actually targeting the new helper.

### GREEN Phase: Extract the Method

Apply surgical extraction:
- Use `v12_split.py` for any extraction exceeding 50 lines (manual copy-paste BANNED)
- Touch ONLY the target method and its new helper
- NEVER mutate whitespace, indentation, or adjacent unrelated code
- After extraction, run the contract tests -- they must now PASS (GREEN)

**Self-healing retry**: If GREEN fails, re-examine extraction boundary and retry up to 3 times.
If 3 attempts fail: HALT. Report exact failure trace. Do NOT proceed.

### Post-Edit Deployment (MANDATORY)
```powershell
# Re-establish hard links + ASCII gate
powershell -File .\deploy-sync.ps1

# Lock regression audit (must return ZERO matches)
grep -r "lock(" src/

# Unicode regression audit (must return ZERO matches)
grep -Prn "[^\x00-\x7F]" src/
```

All three must PASS before proceeding to P6.

---

## STEP 5 -- P6 VERIFIER (Plan/Code Mode) -- REFACTOR

Run full verification suite:

```powershell
# Full test suite
dotnet test tests/

# Complexity audit -- confirm CYC delta meets ticket target
python scripts/complexity_audit.py

# Final hard-link sync
powershell -File .\deploy-sync.ps1
```

**Output**: Write `docs/brain/verification_report_t[ID].md` containing:
- Test pass rate (e.g., `20/20 PASS`)
- CYC before/after delta
- Lock audit: CLEAN
- Unicode audit: CLEAN
- deploy-sync.ps1: PASS
- BUILD_TAG (bump now)

---

## STEP 6 -- HANDOFF TO DIRECTOR

Only after ALL Step 5 audits PASS, output:

```
[BOB-TDD-COMPLETE]
Ticket: [ID]
Method: [target method]
CYC: [before] -> [after]
Tests: [N]/[N] PASS
BUILD_TAG: [new tag]
Status: READY FOR F5 COMPILE

Director Post-Ticket Checklist:
[ ] Press F5 in NinjaTrader -- verify BUILD_TAG banner
[ ] Confirm complexity_audit.py pass in verification report
[ ] Confirm test pass rate in verification report
[ ] Commit forensics + plan + verification reports
[ ] Update BUILD_TAG_BASELINE in next ticket's header prompt
```

---

## BANNED PATTERNS (immediate halt)

- `lock(anything)` -- BANNED
- `Monitor.Enter` / `Monitor.Exit` -- BANNED
- `Thread.Sleep()` anywhere -- BANNED
- Unicode / emoji / curly quotes in any string literal -- BANNED
- Manual copy-paste for extractions > 50 lines -- BANNED (use v12_split.py)
- Skipping RED phase (writing GREEN without a failing test first) -- BANNED
- Proceeding past any GATE without explicit Director confirmation -- BANNED
112 changes: 112 additions & 0 deletions .bob/commands/bug-bounty-consolidate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
description: Consolidate 7 cluster bug reports into a validated, hallucination-filtered, ranked repair plan. Run after all 7 cluster-bug-hunt reports are complete.
argument-hint: runner (optional -- runner suffix, e.g. bob, qwen, jules, gemini. Defaults to bob)
---
# MISSION: Bug Bounty Consolidation -- V12 Photon Kernel
**Spec Ref**: docs/brain/bug_bounty_workflow.md
**Input**: docs/brain/bug_report_s1_[runner].md through bug_report_s7_[runner].md (all 7 must exist)
**Output**: docs/brain/cluster_bug_bounty_report_[runner].md
Comment on lines +7 to +8
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix runner filename contract mismatch in ingestion step.

The declared input format uses bug_report_sN_[runner].md, but Step 1 reads bug_report_sN.md. This will miss runner-suffixed reports and can halt valid runs.

Suggested fix
- Read the following files in order:
- - docs/brain/bug_report_s1.md (S1: SIMA Core)
- - docs/brain/bug_report_s2.md (S2: Execution Engine)
- - docs/brain/bug_report_s3.md (S3: UI & Photon IO)
- - docs/brain/bug_report_s4.md (S4: REAPER Defense)
- - docs/brain/bug_report_s5.md (S5: Kernel State)
- - docs/brain/bug_report_s6.md (S6: Signals & Entries)
- - docs/brain/bug_report_s7.md (S7: Kernel Infrastructure)
+ Read the following files in order:
+ - docs/brain/bug_report_s1_[runner].md (S1: SIMA Core)
+ - docs/brain/bug_report_s2_[runner].md (S2: Execution Engine)
+ - docs/brain/bug_report_s3_[runner].md (S3: UI & Photon IO)
+ - docs/brain/bug_report_s4_[runner].md (S4: REAPER Defense)
+ - docs/brain/bug_report_s5_[runner].md (S5: Kernel State)
+ - docs/brain/bug_report_s6_[runner].md (S6: Signals & Entries)
+ - docs/brain/bug_report_s7_[runner].md (S7: Kernel Infrastructure)

Also applies to: 16-22

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.bob/commands/bug-bounty-consolidate.md around lines 7 - 8, The input
pattern declared expects files named like bug_report_sN_[runner].md but the
ingestion step is reading bug_report_sN.md (missing the _[runner] suffix),
causing valid runner-specific reports to be skipped; update the ingestion logic
in the step that reads the seven reports (and the similar block referenced
around lines 16-22) to use the runner-aware filename pattern (e.g., construct
filenames as bug_report_s${N}_[runner].md or use a glob that matches
bug_report_s*_ [runner].md) so the code that opens/parses the files (the
ingestion function/loop that references bug_report_sN.md) uses the correct names
and will fail only when the runner-suffixed files are absent.

**Mode**: Plan mode -- READ ONLY. No src/ edits.

---

## STEP 1 -- INGEST ALL 7 REPORTS

Read the following files in order:
- docs/brain/bug_report_s1.md (S1: SIMA Core)
- docs/brain/bug_report_s2.md (S2: Execution Engine)
- docs/brain/bug_report_s3.md (S3: UI & Photon IO)
- docs/brain/bug_report_s4.md (S4: REAPER Defense)
- docs/brain/bug_report_s5.md (S5: Kernel State)
- docs/brain/bug_report_s6.md (S6: Signals & Entries)
- docs/brain/bug_report_s7.md (S7: Kernel Infrastructure)

If any file is missing: HALT and report to Director which clusters are incomplete.

---

## STEP 2 -- HALLUCINATION FILTER

For EVERY reported bug across all 7 reports:
1. Use jCodemunch `search_symbols` to verify the cited method exists
2. Use `get_file_content` to verify the cited code pattern matches actual src/
3. Use `find_references` to confirm the cited shared state is actually accessed

Disposition for each bug:
- VALIDATED: evidence confirmed in src/
- FILTERED: cited method/pattern does not match src/ reality
- UNCERTAIN: partially verifiable -- flag for Director review

Track and report the filter rate per cluster.

---

## STEP 3 -- CROSS-CLUSTER DEDUPLICATION

Identify bugs reported by multiple agents for the same root cause:
- Match on: same file + same method + same root cause mechanism
- Merge into single canonical entry
- List all clusters that reported it
- Elevate severity if blast radius spans 2+ clusters

---

## STEP 4 -- SEVERITY RANKING

Final ranking of all validated bugs:
- Critical: Data corruption, race conditions, use-after-free
- High: FSM state leaks, ghost order windows, O(N^2) hot paths, semaphore leaks
- Med: Missing null guards, incomplete resets, inefficient lookups
- Low: Style violations, minor inefficiencies

---

## STEP 5 -- OUTPUT

Write docs/brain/cluster_bug_bounty_report_[runner].md containing:

```
# V12 Cluster Bug Bounty Report
Generated: [date]

## Summary
Total bugs found (raw): [N]
Validated: [N] | Filtered (hallucinations): [N] | Uncertain (Director review): [N]
Critical: [N] | High: [N] | Med: [N] | Low: [N]

## Filter Rate by Cluster
| Cluster | Found | Validated | Filtered |
|---------|-------|-----------|----------|
| S1 SIMA | N | N | N |
...

## Validated Bug List (ranked by severity)
[full list in BUG-[S#]-[NNN] format]

## Recommended Repair Sequence
[cluster order based on Critical count and dependency graph]

## /epic-tdd Ticket Blocks
[copy-paste ready ticket for each validated bug]
```

---

## STEP 6 -- HANDOFF

Output:
```
[BUG-BOUNTY-CONSOLIDATION-COMPLETE]
Total validated: [N]
Filtered: [N]
Uncertain (needs Director review): [N]
Report: docs/brain/cluster_bug_bounty_report_[runner].md
Next: Director reviews report -> selects cluster -> /epic-tdd for repairs
```

---

## BANNED
- Any src/ edit -- BANNED
- Fixing bugs inline -- BANNED
- Marking a bug VALIDATED without jCodemunch verification -- BANNED
Loading
Loading