3.7 KiB
SUB STORE 项目重构
ref/sub-store-cloudflare 是一个使用cloudflare部署的机场订阅转换助手,我们需要参考原项目,完成GO语言、SQLITE数据库的重构。
项目约束
- 全新项目,无历史数据包袱:不存在存量用户、存量配置、存量过滤器需要迁移。所有"向后兼容"、"存量 script 过滤器迁移"、"process→FilterRule 转换"等问题均不需要考虑——直接按 Go 版自身的设计实现即可,不必复刻原项目的兼容逻辑。
- ProxyNode 类型自由选择:不强制与原项目
Record<string, unknown>保持一致,按 Go 最佳实践选择 struct 或 map。 - 前端适配后端:前端尚未实现,后端 API 设计可自由定义,不需要兼容原前端格式。
开发决议
开发前必读 docs/review-resolutions.md — 45 条 review 问题的逐条决议(ProxyNode 类型、token 双哈希、SQLite PRAGMA、sing-box 完整结构等)。开发中不得偏离已定决议;如需变更,先改本文档再改代码。
关键决议摘要:
- ProxyNode =
map[string]any,深拷贝用 json.Marshal/Unmarshal - token 校验先 SHA-256 再 ConstantTimeCompare(防长度泄露时序攻击)
- SQLite: WAL + busy_timeout=5000 + foreign_keys=ON + MaxOpenConns=1
- CSP 收紧为
script-src 'self'(无 unsafe-eval) - custom 规则链上限 32 条,替代 JS script 过滤器
- modernc.org/sqlite(纯 Go),接受写性能 tradeoff
CodeGraph
This project has a CodeGraph MCP server (codegraph_* tools) configured. CodeGraph is a tree-sitter-parsed knowledge graph of every symbol, edge, and file. Reads are sub-millisecond and return structural information grep cannot.
When to prefer codegraph over native search
Use codegraph for structural questions — what calls what, what would break, where is X defined, what is X's signature. Use native grep/read only for literal text queries (string contents, comments, log messages) or after you already have a specific file open.
| Question | Tool |
|---|---|
| "Where is X defined?" / "Find symbol named X" | codegraph_search |
| "What calls function Y?" | codegraph_callers |
| "What does Y call?" | codegraph_callees |
| "What would break if I changed Z?" | codegraph_impact |
| "Show me Y's signature / source / docstring" | codegraph_node |
| "Give me focused context for a task/area" | codegraph_context |
| "Survey an unfamiliar module/topic" | codegraph_explore |
| "What files exist under path/" | codegraph_files |
| "Is the index healthy?" | codegraph_status |
Rules of thumb
- Trust codegraph results. They come from a full AST parse. Do NOT re-verify them with grep — that's slower, less accurate, and wastes context.
- Don't grep first when looking up a symbol by name.
codegraph_searchis faster and returns kind + location + signature in one call. - Don't chain
codegraph_search+codegraph_nodewhen you just want context —codegraph_contextis one call. codegraph_exploreis the heavy hitter for unfamiliar areas — it returns full source from all relevant files in one call, but is token-heavy. If your harness supports parallel subagents (e.g., Claude Code's Task tool), spawn one for explore-class questions to keep main session context clean.- Index lag: the file watcher debounces ~500ms behind writes; don't re-query immediately after editing a file in the same turn.
If .codegraph/ doesn't exist
The MCP server returns "not initialized." Ask the user: "I notice this project doesn't have CodeGraph initialized. Want me to run codegraph init -i to build the index?"