- Fix TOCTOU race conditions by wrapping read-modify-write cycles under single-file locks in execution_state, portfolio_service, precheck_state, state_manager, and precheck_service. - Add missing test coverage (96 tests total): - test_review_service.py (15 tests) - test_check_api.py (6 tests) - test_external_gate.py main branches (+10 tests) - test_trade_execution.py new commands (+8 tests) - Unify all agent-consumed JSON messages to English. - Config-ize hardcoded values (volume filter, schema_version) via get_user_config with sensible defaults. - Add 1-hour TTL to exchange cache with force_new override. - Add ruff and mypy to dev dependencies; fix all type errors. - Add __all__ declarations to 11 service modules. - Sync README with new commands, config tuning docs, and PyPI badge. - Publish package as coinhunter==1.0.0 on PyPI with MIT license. - Deprecate coinhunter-cli==1.0.1 with runtime warning. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5.1 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development commands
- Editable install:
pip install -e . - Run the CLI locally:
python -m coinhunter --help - Install for end users:
./scripts/install_local.sh(standardpip install -e .wrapper) - Tests: There is no test suite yet. The README lists next priorities as adding pytest coverage for runtime paths, state manager, and trigger analyzer.
- Lint / type-check: Not configured yet.
CLI command routing
src/coinhunter/cli.py is the single entrypoint. It resolves aliases to canonical commands, maps canonical commands to Python modules via MODULE_MAP, then imports the module and calls module.main() after mutating sys.argv to match the display name.
Active commands live in src/coinhunter/commands/ and are thin adapters that delegate to src/coinhunter/services/. Root-level backward-compat facades (e.g., precheck.py, smart_executor.py, review_engine.py, review_context.py) re-export the moved commands.
Architecture
Layer responsibilities
- CLI (
cli.py) — argument parsing, alias resolution, module dispatch. - Commands (
commands/) — thin, stateless adapters that call into services. - Services (
services/) — orchestration, domain logic, and exchange interaction. - Runtime (
runtime.py) — path resolution, env loading, hermes binary discovery. - Logger (
logger.py) — structured JSONL logging to~/.coinhunter/logs/.
Runtime and environment
runtime.py defines RuntimePaths and get_runtime_paths(). User data lives in ~/.coinhunter/ by default (override with COINHUNTER_HOME). Credentials are loaded from ~/.hermes/.env by default (override with COINHUNTER_ENV_FILE). Modules should call get_runtime_paths() at function scope rather than eagerly at import time.
Smart executor (exec)
commands/smart_executor.py → services/smart_executor_service.py → services/trade_execution.py.
Supported verbs: bal, overview, hold, buy SYMBOL USDT, flat SYMBOL, rotate FROM TO.
smart_executor_parser.pynormalizes legacy argv and exposesparse_cli_args().trade_common.pyholds a global dry-run flag (set_dry_run/is_dry_run).execution_state.pytracks decision IDs in JSON to prevent duplicate executions.exchange_service.pywrapsccxt.binanceand handles symbol normalization.portfolio_service.pymanagespositions.jsonload/save/reconcile.
Precheck
commands/precheck.py → services/precheck_service.py.
The precheck workflow:
- Load and sanitize state (
precheck_state.py— clears stale triggers and run requests). - Build a market snapshot (
precheck_snapshot.py→snapshot_builder.py). - Analyze whether to trigger deep analysis (
precheck_analysis.py→trigger_analyzer.py). - Update and save state (
precheck_state.update_state_after_observation).
State is stored in ~/.coinhunter/state/precheck_state.json.
Review commands
review N(commands/review_context.py→services/review_service.py) — generates review context for the last N hours.recap N(commands/review_engine.py→services/review_service.py) — generates a full review report by reading JSONL decision/trade/error logs, computing PnL estimates, missed opportunities, and saving a report to~/.coinhunter/reviews/.
Logging model
logger.py writes JSONL to dated files in ~/.coinhunter/logs/:
decisions_YYYYMMDD.jsonltrades_YYYYMMDD.jsonlerrors_YYYYMMDD.jsonlsnapshots_YYYYMMDD.jsonl
Use get_logs_last_n_hours(log_type, hours) to query recent entries.
Common command reference
# Diagnostics
python -m coinhunter diag
python -m coinhunter paths
python -m coinhunter api-check
# Execution (dry-run)
python -m coinhunter exec bal
python -m coinhunter exec overview
python -m coinhunter exec buy ENJUSDT 50 --dry-run
python -m coinhunter exec flat ENJUSDT --dry-run
# Precheck
python -m coinhunter precheck
python -m coinhunter precheck --ack "analysis completed"
python -m coinhunter precheck --mark-run-requested "reason"
# Review
python -m coinhunter review 12
python -m coinhunter recap 12
Skill routing
When the user's request matches an available skill, ALWAYS invoke it using the Skill tool as your FIRST action. Do NOT answer directly, do NOT use other tools first. The skill has specialized workflows that produce better results than ad-hoc answers.
Key routing rules:
- Product ideas, "is this worth building", brainstorming → invoke office-hours
- Bugs, errors, "why is this broken", 500 errors → invoke investigate
- Ship, deploy, push, create PR → invoke ship
- QA, test the site, find bugs → invoke qa
- Code review, check my diff → invoke review
- Update docs after shipping → invoke document-release
- Weekly retro → invoke retro
- Design system, brand → invoke design-consultation
- Visual audit, design polish → invoke design-review
- Architecture review → invoke plan-eng-review
- Save progress, checkpoint, resume → invoke checkpoint
- Code quality, health check → invoke health