Codex/feat add by hsc 20260926 - #15
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A confirmed logic bug in candidate_safety_blockers uses ambiguous ternary/or precedence and can incorrectly reject valid candidates.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
This PR expands AI4BINANCE’s deterministic, research-only pipeline by introducing a typed “Trading Intelligence” evidence chain (structures/levels/trend/patterns/derivatives → scenarios), binding candidates to a selected scenario, and tightening downstream risk/validation contracts (including scenario-bound sizing and futures margin projection) while keeping RESEARCH_ONLY / LIVE_ORDER_BLOCKED invariants.
Changes:
- Add new
ai4binance.intelligencecontracts + engines and integrate them into the orchestrator state/candidate flow. - Strengthen risk + validation gates with scenario-bound checks (net R/R, sizing evidence, candidate identity safety blockers).
- Improve market-universe + persistence boundaries (canonical universe source constant, stricter retention rules, canonical bounded JSONL tail reader), with broad new/updated tests.
| File | Description |
|---|---|
| tests/test_virtual_runtime.py | Adds futures projected-margin-after-costs entry test. |
| tests/test_trading_intelligence.py | New deterministic intelligence evidence-chain test suite. |
| tests/test_research_market_universe.py | Asserts universe source constant matches canonical domain contract; adds non-ASCII retention case. |
| tests/test_opportunity_monitor.py | Verifies monitor uses canonical universe source when reading cache. |
| tests/test_oos_maturity.py | Validates maturity flow with real RiskEngine assessment metadata. |
| tests/test_kaizen_quality.py | Updates architecture migration ledger expectations for intelligence contracts move. |
| tests/test_config_reporting.py | Updates default market_history_coin_m_enabled expectation. |
| tests/test_cli.py | Updates cached market universe monkeypatches to accept kwargs. |
| tests/test_advanced_agents.py | Adds test asserting derivatives context can be non-directional (supplementary). |
| src/ai4binance/storage/jsonl.py | Removes duplicated tail-reader logic; re-exports canonical bounded JSONL tail reader. |
| src/ai4binance/schemas.py | Extends AnalysisState to carry TradingIntelligenceState with identity validation. |
| src/ai4binance/risk.py | Adds scenario-bound safety helpers (candidate_safety_blockers, candidate_risk_distance), net R/R rules, and richer RiskAssessment. |
| src/ai4binance/research/virtual_runtime.py | Adds futures projected margin utilization checks accounting for fees/funding/mark-loss. |
| src/ai4binance/research/virtual_runtime_risk.py | Adds simulated leverage assessment contract + tighter futures entry blockers. |
| src/ai4binance/research/virtual_runtime_request.py | Adds non-finite numeric input validation and leverage type enforcement. |
| src/ai4binance/ops/architecture_migration.py | Adds migration routing for intelligence package to domain path. |
| src/ai4binance/intelligence/trend.py | New trend-geometry engine producing bounded trend-zone evidence. |
| src/ai4binance/intelligence/trading.py | New trading intelligence engine that synthesizes evidence into scenarios and binds candidates. |
| src/ai4binance/intelligence/structure.py | New confirmed-swing market structure engine (no look-ahead). |
| src/ai4binance/intelligence/patterns.py | New pattern hypothesis fabric normalizing pattern detectors into lifecycle-bound hypotheses. |
| src/ai4binance/intelligence/levels.py | New structural level-map engine producing reusable support/resistance zones. |
| src/ai4binance/intelligence/derivatives.py | New typed futures context engine with provenance/freshness/metric validation. |
| src/ai4binance/intelligence/contracts.py | New immutable evidence contracts for deterministic trading intelligence state. |
| src/ai4binance/intelligence/__init__.py | Adds side-effect-free package initializer. |
| src/ai4binance/integrations/research_market_universe.py | Uses canonical universe source constant and canonical JSONL tail reader; enables coin-m transport passthrough. |
| src/ai4binance/infrastructure/persistence/safe_json.py | Removes duplicated tail-reader logic; re-exports canonical bounded JSONL tail reader. |
| src/ai4binance/domain/universe.py | Defines canonical RESEARCH_MARKET_UNIVERSE_SOURCE in domain contract. |
| src/ai4binance/domain.py | Extends TradeCandidate with scenario/economics fields + stronger finiteness/contract validation. |
| src/ai4binance/data/market_universe_retention.py | Tightens retention to remove out-of-universe non-symbol directories/files safely. |
| src/ai4binance/data/market_history_continuous.py | Extends progress reporting to include universe source/selection/retention context. |
| src/ai4binance/core/__init__.py | Introduces canonical read_bounded_jsonl_tail implementation in core boundary. |
| src/ai4binance/config.py | Enables coin-m market history by default. |
| src/ai4binance/compatibility/opportunity_monitor.py | Imports canonical universe source constant from domain. |
| src/ai4binance/agents/validation_gate.py | Tightens validation with scenario binding, candidate safety blockers, and sizing evidence checks. |
| src/ai4binance/agents/technical.py | Updates market structure agent to use confirmed-swing engine while preserving legacy metadata fields. |
| src/ai4binance/agents/risk_gate.py | Adds scenario/economics provenance into risk-agent metadata and assessments. |
| src/ai4binance/agents/orchestrator.py | Builds trading intelligence state per cycle, binds candidates, and carries state into AnalysisState. |
| src/ai4binance/agents/advanced.py | Adds source_timeframe to advanced-agent metadata; allows derivatives context to be non-directional. |
| docs/compliance/registry_compliance_matrix.md | Bumps compliance matrix version and records intelligence boundary/quality closure linkage. |
| config/governance/governed_document_lock_manifest.json | Adds written owner approval record + updates locked hash/version for compliance matrix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hscicek
previously approved these changes
Sep 26, 2026
hscicek
approved these changes
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


No description provided.