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
24 changes: 12 additions & 12 deletions .claude/ralph/prd.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Typecheck passes"
],
"priority": 1,
"passes": false,
"passes": true,
"notes": "Foundation story. .claude/ already exists with settings.local.json — add to it, don't overwrite. CLAUDE.md doesn't exist yet."
},
{
Expand All @@ -34,7 +34,7 @@
"Typecheck passes"
],
"priority": 2,
"passes": false,
"passes": true,
"notes": "State file enables session continuity. ContinuousScanner already has _run_smart_loop() at src/scanner/automation/continuous.py:257."
},
{
Expand All @@ -51,7 +51,7 @@
"Typecheck passes"
],
"priority": 3,
"passes": false,
"passes": true,
"notes": "sync_closed_trades_rl() is at src/scanner/execution.py. Each journal entry has full context: gates, agents, regime, outcome."
},
{
Expand All @@ -68,7 +68,7 @@
"Typecheck passes"
],
"priority": 4,
"passes": false,
"passes": true,
"notes": "This is the evolution mechanism. Patterns that repeat become rules that actively gate or adjust trading behavior."
},
{
Expand All @@ -85,7 +85,7 @@
"Typecheck passes"
],
"priority": 5,
"passes": false,
"passes": true,
"notes": "This closes the loop: trade outcome → learning → rule → config change → better trades. Bounds prevent runaway tuning."
},
{
Expand All @@ -102,7 +102,7 @@
"Typecheck passes"
],
"priority": 6,
"passes": false,
"passes": true,
"notes": "Per-pair tuning is critical. EUR_USD 13.6 ATR behaves differently from USD_JPY 27.3 ATR. The scan phase calculates SL/TP in engine.py around line 1397."
},
{
Expand All @@ -119,7 +119,7 @@
"Typecheck passes"
],
"priority": 7,
"passes": false,
"passes": true,
"notes": "This is the meta-learning dashboard. Without metrics, we can't know if the learning system itself is improving."
},
{
Expand All @@ -135,7 +135,7 @@
"Typecheck passes"
],
"priority": 8,
"passes": false,
"passes": true,
"notes": "Observations build context even from non-trades. This data can later feed into a more sophisticated meta-learner."
},
{
Expand All @@ -152,7 +152,7 @@
"Typecheck passes"
],
"priority": 9,
"passes": false,
"passes": true,
"notes": "self_refine.py exists at project root. This wires LLM reasoning into the learning loop for qualitative insights."
},
{
Expand All @@ -168,7 +168,7 @@
"Typecheck passes"
],
"priority": 10,
"passes": false,
"passes": true,
"notes": "Context discipline. Files must stay concise or they become noise. Archive aggressively."
},
{
Expand All @@ -186,7 +186,7 @@
"Typecheck passes"
],
"priority": 11,
"passes": false,
"passes": true,
"notes": "buddy_scanner.py already has CLI with scan/watch/trade subcommands. Add 'learn' alongside."
},
{
Expand All @@ -206,7 +206,7 @@
"Typecheck passes"
],
"priority": 12,
"passes": false,
"passes": true,
"notes": "This is the integration story. All components from US-002 through US-010 get wired into the continuous loop here."
}
]
Expand Down
54 changes: 45 additions & 9 deletions .claude/ralph/progress.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
# Ralph Progress - Buddy Self-Improvement Loop

## Stories: 0/12 completed

## Context
- ML Engine FX trading bot (Buddy)
- Currently: scan → trade → RL feedback loop works
- Missing: persistent learning, cross-session memory, adaptive config
- Key files: src/scanner/automation/continuous.py, src/scanner/execution.py, src/scanner/agents.py
- Trade journal: trained_data/trade_journal_rl.json (5 trades, 3 won / 2 lost)
- Account: OANDA practice, NAV ~$102,580
## Stories: 12/12 completed

## Completed
- US-001: Bootstrap .claude/ learning infrastructure ✓ (CLAUDE.md, learnings.md, rules/)
- US-002: Session state engine ✓ (src/scanner/automation/state_engine.py — StateEngine class)
- US-003: Trade outcome analyzer ✓ (src/scanner/automation/learning_engine.py — LearningEngine.analyze_trade)
- US-004: Rule promotion ✓ (LearningEngine.check_promotions — 3+ observations → promoted rule)
- US-005: Adaptive config tuner ✓ (src/scanner/automation/config_tuner.py — ConfigTuner class)
- US-006: Per-pair SL/TP adaptation ✓ (LearningEngine.update_pair_sl_tp + engine.py reads pair_sl_tp_config.json)
- US-007: Improvement tracker ✓ (src/scanner/automation/improvement_tracker.py — ImprovementTracker class)
- US-008: Observation logging ✓ (src/scanner/automation/observation_log.py — ObservationLog class)
- US-009: LLM deep analysis ✓ (LearningEngine.deep_analyze_loss + enable_llm_trade_analysis config flag)
- US-010: Consolidation guards ✓ (LearningEngine.audit/consolidate — archive promoted, cap files)
- US-011: Learn CLI command ✓ (cli/learn_commands.py + main.py dispatch — buddy learn [--analyze|--promote|--consolidate|--report|--status])
- US-012: Full learning loop integration ✓ (continuous.py _run_learning_loop — wires all components into watch mode)

## New Files Created
- src/scanner/automation/state_engine.py — StateEngine for cross-session state
- src/scanner/automation/learning_engine.py — LearningEngine for trade analysis + promotion + consolidation
- src/scanner/automation/config_tuner.py — ConfigTuner for adaptive config from rules
- src/scanner/automation/improvement_tracker.py — ImprovementTracker for meta-learning metrics
- src/scanner/automation/observation_log.py — ObservationLog for market pattern capture
- cli/learn_commands.py — CLI handler for `buddy learn` command

## Modified Files
- src/scanner/automation/continuous.py — Added _run_learning_loop(), observation logging, config tuning
- src/scanner/engine.py — Per-pair SL/TP override from pair_sl_tp_config.json
- src/scanner/config.py — Added enable_llm_trade_analysis flag + smart profile enablement
- cli/argparser.py — Added 'learn' command + arguments
- main.py — Wired handle_learn into dispatch table

## Architecture
```
Scanner (engine.py) → Agents (agents.py) → Gates → Execution (execution.py) → OANDA
↑ ↓
├── Config Tuner ← Rules ← Learnings ← RL Feedback ←── Trade Outcomes
├── Observation Log (non-trade patterns) ↓
├── Per-pair SL/TP config Learning Engine (analyze_trade)
└── State Engine (session continuity) ↓
Rule Promotion (3+ observations)
Config Tuner (apply_to_config)
Improvement Tracker (meta-metrics)
```
23 changes: 17 additions & 6 deletions .claude/state.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
"Minimum R:R ratio gate (1.2:1)",
"Scan cycle JSONL logging",
"Per-pair performance tracking",
"Bootstrap .claude/ learning infrastructure"
"Bootstrap .claude/ learning infrastructure",
"US-002: Session state engine (StateEngine class)",
"US-003: Trade outcome analyzer (LearningEngine.analyze_trade)",
"US-004: Rule promotion (3+ observations → promoted rules)",
"US-005: Adaptive config tuner (rules → config changes)",
"US-006: Per-pair adaptive SL/TP multipliers",
"US-007: Improvement tracker and meta-learning metrics",
"US-008: Observation logging for market patterns",
"US-009: LLM deep analysis for losing trades (>$100)",
"US-010: Learnings consolidation and anti-proliferation",
"US-011: buddy learn CLI command",
"US-012: Full learning loop integration into ContinuousScanner"
],
"next": "Run next scan cycle with improved position sizing and analyze results",
"next": "Run scan cycle in watch mode to validate full learning loop end-to-end",
"open_questions": [
"EUR_USD model predicted LONG but pair was bearish — is the model stale or is this a regime issue?",
"Should we increase min_confidence threshold given EUR_USD losses at 67% confidence?",
"Walk-forward orchestrator (US-005 from old PRD) still deferred — needs train-joint run first"
"Should we increase min_confidence threshold given EUR_USD losses at 67% confidence?"
],
"last_updated": "2026-03-17T06:15:00Z",
"last_updated": "2026-03-18T00:00:00Z",
"portfolio_snapshot": {
"nav": 102580.84,
"open_trades": 0,
Expand All @@ -33,5 +43,6 @@
"session_losses": 2,
"win_rate": 0.60
},
"improvement_focus": "Self-improvement loop infrastructure (learnings → rules → config adaptation)"
"improvement_focus": "Full self-improvement loop live — monitoring learning extraction and rule promotion",
"scan_cycle_count": 0
}
37 changes: 37 additions & 0 deletions cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"monitor",
"find-candles",
"transfer",
"learn",
]

CLI_EPILOG = """
Expand Down Expand Up @@ -947,6 +948,41 @@ def _add_correlation_transfer_arguments(parser: argparse.ArgumentParser) -> None
parser.add_argument("--transfer-epochs", type=int, default=50, help=argparse.SUPPRESS)


def _add_learn_arguments(parser: argparse.ArgumentParser) -> None:
"""Add learning loop CLI arguments (buddy learn command)."""
learn_group = parser.add_argument_group("Learn", "Self-improvement learning loop commands")
learn_group.add_argument(
"--analyze",
action="store_true",
default=False,
help="For learn: run trade outcome analysis on all unanalyzed journal entries",
)
learn_group.add_argument(
"--promote",
action="store_true",
default=False,
help="For learn: run promotion check and promote qualifying patterns to rules",
)
learn_group.add_argument(
"--consolidate",
action="store_true",
default=False,
help="For learn: run learnings consolidation (archive promoted, group by category)",
)
learn_group.add_argument(
"--report",
action="store_true",
default=False,
help="For learn: print improvement tracker report (total trades, win rate, trends)",
)
learn_group.add_argument(
"--status",
action="store_true",
default=False,
help="For learn: print current state from .claude/state.json and recent learnings",
)


def create_argument_parser() -> argparse.ArgumentParser:
"""Create and configure the main argument parser.

Expand Down Expand Up @@ -979,6 +1015,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
_add_wandb_arguments(parser)
_add_multi_pair_arguments(parser)
_add_correlation_transfer_arguments(parser)
_add_learn_arguments(parser)

return parser

Expand Down
Loading
Loading