chore: 合并 AGENTS 配置为单文件 AGENTS.md,精简 reasonix.toml

- 删除 AGENTS/ 目录下 8 个拆分 .md 文件,统一为根目录 AGENTS.md
- 删除 .reasonix.toml,配置合并到 reasonix.toml
- reasonix.toml 精简为仅保留实际生效的 3 项配置
- KlineInterval 类型导出源从 kline.entity 改到 ../../types
This commit is contained in:
Rekey
2026-06-16 13:32:05 +08:00
parent d8a2f4bb52
commit b540b7611c
12 changed files with 73 additions and 157 deletions
-4
View File
@@ -1,4 +0,0 @@
# 项目级 Reasonix 配置 — 优先级高于全局 config.toml
# 参考: ~/Library/Application Support/reasonix/config.toml
[agent]
reasoning_language = "zh" # 强制推理过程使用中文
+68
View File
@@ -0,0 +1,68 @@
# trade — 数字货币量化交易系统
Python + TypeScript (Bun) 混合架构:数据层 TS 采集行情入库,业务层 Python 跑策略/回测/风控。
## 项目
- **`data/`**TypeScript (Bun),行情采集、K 线合成、数据写入 TimescaleDB。workdir 必须是 `data/`
- **`engine/`**Python 3.10+,策略引擎、回测、信号分发。workdir 必须是 `engine/`,导入用 `from common import ...`
- 两模块通过 Redis Pub/Sub 通信(设计阶段,尚未实现)。
- 数据库:TimescaleDBDocker Compose 启动,端口 5432)。配置在根 `env.yaml`
## 命令
```bash
# 基础设施
docker compose up -d # 启动 TimescaleDB + Adminer(:8080)
# data/ (TS) — 必须先 cd data
cd data && bun install # 安装依赖
bun run data/run/exchange.ts --concurrency 2 # 拉取历史 K 线
bun run data/run/build_aggregates_sql.ts # 连续聚合刷新 (dry-run)
bun run data/run/build_aggregates_sql.ts --execute # 实际执行聚合刷新
bun run lint # eslint
bun run format # prettier
bun run build # tsc 类型检查
```
## 架构
```
data/ engine/
exchanges/rest.ts Binance common/base.py 策略基类
types/base.ts 类型定义 common/models.py Pydantic 数据模型
types/kline.ts K线类型 common/logger.py 日志
entities/ TypeORM backtest/ 回测引擎
run/exchange.ts 拉取入口 indicators/ 技术指标
run/build_aggregates_sql.ts example/ 策略示例+回测脚本
```
- **K 线复合主键**`[exchange, symbol, interval, time]`TimescaleDB 超表按 `time` 分区。
- **`synchronize: false`**TypeORM 不自动 sync schema,改实体需手动迁移。
- **`@timescaledb/typeorm` 是 v0.0.1 实验版**,连续聚合用原生 SQL 视图(`klines_5m` / `klines_15m` 等)。
- TS 侧价格字段为 `string`(精度),Python 侧 Pydantic `field_validator` 转 float。
- `KLINE_INTERVAL_MS` 定义在 `data/exchanges/rest.ts``data/types/kline.ts` 两处,新增周期需同步。
## 约定
- **中文优先**:所有回答和推理用中文;代码、标识符、文件名、技术术语保持原文。
- **运行时是 Bun,不是 Node.js**TS 执行用 `bun run <file>`,禁止 `node`/`npm`/`npx`
- **workdir 严格分离**TS 命令在 `data/`Python 命令在 `engine/``package.json``data/` 中。
- **先确认再动手**:涉及多文件或架构决策时先出方案等用户点头。不做未要求的改动。
- **一次改一处**:逐步 edit_file,不批量 multi_edit。改完让用户看到再继续。
- **拒绝时先问原因**:操作被 declined 不要立即换方式重试。
- **配置单一源**`env.yaml` 是 TS 和 Python 共享的唯一配置,含 API Key,禁止硬编码密钥。
- **Python 虚拟环境**`engine/.venv/`,未安装依赖(pydantic 等)需先 `pip install`
## 现状
- ✅ TS 数据模块:配置加载、TypeORM 实体、Binance REST K 线拉取+UPSERT、连续聚合刷新。
- ❌ 未实现:WebSocket 行情、K 线合成管道、Redis 发布、策略管理器、信号总线、回测引擎、参数优化器、风控、交易执行、API 网关。
- ❌ 无测试、无 CI。
- `data/run/main.ts` 不存在,`dev`/`start` 脚本指向未创建文件。
## 注意事项
- `env.yaml` 含明文密钥且被 git 追踪,不可提交到公开仓库。
- 数据库当前指向远程 `10.0.0.7`,本地开发改 `env.yaml` 中 host 为 `localhost`
- `db/pgsql/` 是 Docker volume 数据目录,已在 `.gitignore`
-7
View File
@@ -1,7 +0,0 @@
# 最关键
- **中文优先**:所有回答和推理过程必须使用中文,代码、标识符、文件名、技术术语保持原文不翻译。
- **运行时是 Bun,不是 Node.js**。执行 TS 文件用 `bun run <file>`,不能用 `node``npm``npx`
- **双语言项目**`data/` 是 TypeScript (Bun)`engine/` 是 Python 3.10+。两个模块通过 Redis Pub/Sub 通信。
- **data/ 必须在 data/ 目录下运行**:`package.json``data/` 中,依赖安装到 `data/node_modules`。命令如 `bun install``bun run lint` 需要 `workdir=data`
- **engine/ 必须在 engine/ 目录下运行**Python 虚拟环境在 `engine/.venv/`,导入包使用相对路径(`from common import Kline`)。命令如 `python -c "from common import Kline"` 需要 `workdir=engine`
-21
View File
@@ -1,21 +0,0 @@
# 常用命令
```bash
# 依赖安装(在 data/ 目录下)
bun install
# 运行数据补全(拉取历史 K 线)
bun run data/run/exchange.ts --concurrency 2
# 运行连续聚合刷新(dry-run 看 SQL,加 --execute 实际执行)
bun run data/run/build_aggregates_sql.ts # 纯输出 SQL
bun run data/run/build_aggregates_sql.ts --execute # 实际刷新
bun run data/run/build_aggregates_sql.ts --start 2025-01 --end 2025-06 --execute
# 代码检查与格式化
bun run lint # eslint
bun run format # prettier
# 构建检查
bun run build # tsc 类型检查
```
-5
View File
@@ -1,5 +0,0 @@
# 基础设施
- **数据库**`docker compose up -d` 启动 TimescaleDB(端口 5432+ Adminer(端口 8080)。
- **配置源**:项目根目录 `env.yaml` 是 TS 和 Python 共享的唯一配置。`data/config/index.ts` 读取并校验它。
- **数据库连接**host 在 `env.yaml` 中配,当前指向 `10.0.0.7`(远程)。本地开发需改为 `localhost`
-6
View File
@@ -1,6 +0,0 @@
# 架构约定
- **`synchronize: false`**TypeORM 不会自动同步 schema。修改实体后需要手动迁移或手动改表。
- **`@timescaledb/typeorm` 是 v0.0.1 实验版**。K 线实体的 `@Hypertable` 装饰器可能不稳定。标准 SQL 集成用 TimescaleDB 连续聚合视图(`klines_5m``klines_15m` 等)。
- **数据模型对齐**TS 侧 `data/types/base.ts` 定义的类型与 Python 侧 `engine/common/models.py` 的 Pydantic 模型必须保持字段一致。TS 侧 K 线价格为 `string` 类型(精度),写库时 `Number()` 转换。
- **K 线 4 列复合主键**`[exchange, symbol, interval, time]`。K 线分区列是 `time`TimescaleDB 要求分区列必须在主键中)。
-7
View File
@@ -1,7 +0,0 @@
# Python 引擎
- **workdir 必须是 engine/**:导入包使用 `from common import ...`(如 `from common import Kline, BaseStrategy`)。
- **未完成模块**:策略管理器、信号总线、回测引擎、参数优化器仅存在于 `ENGINE.md` 设计文档中,尚未实现。当前仅 `common/base.py`(策略基类)和 `common/models.py`(数据模型)、`common/logger.py`(日志)可用。
- 引擎入口 `engine/__init__.py` 导出 `Kline, KlineInterval, OrderBook, Ticker, Trade`
- 引擎配置在 `engine/env.yaml`(与根 `env.yaml` 不同,是引擎专属配置)。
- Pydantic v2 的 `field_validator` 处理 TS 侧字符串 → Python float/int 转换。
-6
View File
@@ -1,6 +0,0 @@
# 项目现状
- **已实现**:TS 数据模块的配置加载、TypeORM 实体、Binance REST K 线拉取与批量 UPSERT、连续聚合刷新脚本。
- **未实现**WebSocket 行情采集、K 线合成管道、Redis 发布、策略管理器、信号总线、回测、风控、交易执行、API 网关。这些在 `README.md``engine/ENGINE.md` 中有详细设计文档。
- **`data/run/main.ts` 不存在**`dev` 脚本指向的文件尚未创建。当前实际可运行的入口是 `run/exchange.ts`(数据补全)和 `run/build_aggregates_sql.ts`(聚合刷新)。
- **无测试、无 CI**`package.json` 定义了 `vitest` 脚本但测试尚未编写。无 CI 配置文件。
-7
View File
@@ -1,7 +0,0 @@
# 注意事项
- **所有 API Key 统一在 `env.yaml` 中管理**,禁止在代码中硬编码。新增交易所时在 `exchange` 段添加对应子配置即可。
- `env.yaml` 包含明文密钥和数据库密码且被 git 追踪,注意安全,不要提交到公开仓库。
- 未安装 Python 依赖(如 pydantic),`engine/` 目录有独立的 `.venv/`
- `db/pgsql/``.gitignore` 中,这是 TimescaleDB 数据目录(Docker volume 映射)。
- `KLINE_INTERVAL_MS` 常量定义了两处:`data/exchanges/rest.ts``data/types/kline.ts` 的类型定义。新增周期需同步。
-8
View File
@@ -1,8 +0,0 @@
# 边界与执行纪律
- **严格执行指定范围**:用户说"执行第一步",就只做第一步,不准提前做第二步。哪怕第一步做完后系统自动推进了任务列表,也要停下来等用户明确指示下一步。
- **先确认,再动手**:改动涉及多个文件或架构决策时,先以方案/计划形式呈现,等用户点头再实施。不默认用户同意。
- **不做未要求的改动**:不顺手修 bug、不重构、不加功能,除非用户明确提出。哪怕看起来是"顺便"的小改动,也可能干扰用户意图。
- **read_file 不属于"动手写"**:读文件没问题。改一个文件前先读清楚当前内容。
- **一次改一处**:宁可用多个单步 edit_file 提交,也不用 multi_edit 批量改整个文件。改完一个文件让用户看到,再继续下一个。
- **拒绝时停下来问**:用户拒绝一个操作(declined),不要立即换一种方式重试。先搞清为什么被拒绝。
+1 -1
View File
@@ -9,4 +9,4 @@ export { CommonBaseEntity } from "./common.entity";
export { Exchange } from "./exchange.entity"; export { Exchange } from "./exchange.entity";
export { TradingPair } from "./trading-pair.entity"; export { TradingPair } from "./trading-pair.entity";
export { Kline } from "./kline.entity"; export { Kline } from "./kline.entity";
export type { KlineInterval } from "./kline.entity"; export type { KlineInterval } from "../../types";
+4 -85
View File
@@ -1,88 +1,7 @@
# Reasonix configuration. # 项目级 Reasonix 配置 — 优先级高于全局 config.toml
# Resolution order: flag > ./reasonix.toml > ~/Library/Application Support/reasonix/config.toml > built-in defaults. # 参考: ~/Library/Application Support/reasonix/config.toml
# Secrets come from the environment via api_key_env; never put keys here.
config_version = 2 # schema marker for diagnostics; old versions may ignore it
default_model = "deepseek-pro"
language = "zh" # ui/model language; empty = auto-detect from $LANG / $REASONIX_LANG
[agent] [agent]
# system_prompt = """...""" # omit to use the built-in prompt for this version reasoning_language = "zh" # 强制推理过程使用中文
# system_prompt_file = "prompts/system.md" # overrides system_prompt when set
max_steps = 0 # executor tool-call rounds; 0 = no limit
planner_max_steps = 12 # planner read-only tool-call rounds; 0 = no limit
temperature = 0.0
auto_plan = "off" # off|on; off keeps plan mode manual
reasoning_language = "zh" # visible reasoning language: auto|zh|en
# auto_plan_classifier = "deepseek-pro" # optional; only used for borderline tasks
soft_compact_ratio = 0.5 # notice only; keeps cache-first prefix intact
compact_ratio = 0.8 # try compacting when prompt reaches this fraction
compact_force_ratio = 0.9 # force compacting at this high-water mark
cold_resume_prune = true # elide stale tool results when reopening a session past the provider cache window
# planner_model = "mimo" # optional: enable two-model collaboration
# subagent_model = "deepseek-pro" # optional default for runAs=subagent skills
# subagent_models = { review = "deepseek-pro", security_review = "deepseek-pro" } # per-skill overrides
# subagent_effort = "high" # optional default effort for subagents
# subagent_efforts = { review = "max", task = "high" } # per-tool/skill effort overrides
# output_style = "explanatory" # explanatory | learning | concise | custom; empty = default
[tools]
enabled = [] # empty = all built-in tools
bash_timeout_seconds = 120 # foreground safety cap; set 0 for no tool-local cap
[codegraph] [codegraph]
enabled = true # built-in MCP server; off by default for first-run sessions enabled = true
auto_install = true # fetch the runtime when CodeGraph is enabled but missing
# path = "" # empty = cache, then PATH, then a bundle beside reasonix
[builtin_mcp]
time_enabled = true # built-in Time MCP; off until manually enabled
context7_enabled = false # built-in Context7 MCP; off until manually enabled
[lsp]
enabled = true # language server tools; servers launch lazily when used
# [lsp.servers.go]
# command = "gopls"
# args = []
# extensions = [".go"]
[skills]
# paths = ["~/my-skills", "../shared/skills"] # extra custom skill roots
# excluded_paths = ["~/.agents/skills"] # hide convention roots without deleting folders
# max_depth = 3 # nested scan depth; set 1 for legacy root-only discovery
# disabled_skills = ["review"] # hide noisy or unwanted skills
[permissions]
# Per-call gating. mode = writer fallback when no rule matches: ask|allow|deny.
# Readers always default to allow. Precedence: deny > ask > allow > fallback.
# Rules are "Tool" or "Tool(specifier)"; e.g. Bash(go test:*), Edit(src/**).
mode = "ask"
# deny = ["Bash(rm -rf*)", "Bash(git push*)"] # hard-blocked in every mode
allow = ["Bash(cd /Users/rekey/Documents/Code/trade && git status)", "Bash(cd /Users/rekey/Documents/Code/trade && cat reasonix.toml)"]
# ask = ["Edit(src/**)"] # force a prompt even if otherwise allowed
[sandbox]
# Confine tool blast radius. File-writers (write_file/edit_file/multi_edit)
# may only write under workspace_root (empty = current dir) + allow_write.
# bash = "enforce" (default) jails each command in an OS sandbox (macOS now;
# graceful fallback elsewhere); "off" disables it. network allows egress.
# workspace_root = "" # default: current working directory
# allow_write = ["/tmp"] # extra dirs writers may also modify
bash = "enforce"
network = true
[statusline]
# A custom status line: a command whose first stdout line replaces the built-in
# data row. It receives {"model","contextUsed","contextWindow","cwd"} as JSON on stdin.
# command = "my-statusline.sh"
# External MCP servers. type: "stdio" (default, a subprocess) | "http" | "sse".
# ${VAR} / ${VAR:-default} are expanded from the environment in command/args/env/url/headers.
# [[plugins]]
# name = "example"
# command = "reasonix-plugin-example"
# [[plugins]] # a remote server over Streamable HTTP
# name = "stripe"
# type = "http"
# url = "https://mcp.stripe.com"
# headers = { Authorization = "Bearer ${STRIPE_KEY}" }