Skip to content

Commit 998feb7

Browse files
QUSETIONSclaude
andcommitted
docs: add accurate STRUCTURE.md for the canonical minicode/ package
Replaces the stale CODE_WIKI directory trees (which described the removed py-src/minicode mirror) with a current, subsystem-grouped map of the real minicode/ + tools/ + tui/ layout. CODE_WIKI banner now points to it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e89d9c7 commit 998feb7

2 files changed

Lines changed: 180 additions & 1 deletion

File tree

docs/CODE_WIKI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> MiniCode —— 轻量、开源、多语言实现的 AI 编码代理(Agent),灵感源自 Claude Code。
44
5-
> ⚠️ **部分内容过时(2026-06-16)**:本文档的部分目录树与模块清单描述的是早期 `py-src/minicode/` 镜像,该镜像及其 `gateway.py`/`protocol.py`/`safe_execution.py`/`cron_runner.py`/`agent_protocol.py`/`context_isolation.py` 已在产品化中移除。**当前规范实现是仓库根目录的 `minicode/`**,以实际文件为准。本文保留作历史参考,不再逐行同步。
5+
> ⚠️ **部分内容过时(2026-06-16)**:本文档的部分目录树与模块清单描述的是早期 `py-src/minicode/` 镜像,该镜像及其 `gateway.py`/`protocol.py`/`safe_execution.py`/`cron_runner.py`/`agent_protocol.py`/`context_isolation.py` 已在产品化中移除。**当前规范实现是仓库根目录的 `minicode/`,准确结构见 [`STRUCTURE.md`](STRUCTURE.md)** 本文档保留作历史参考,不再逐行同步。
66
77
---
88

docs/STRUCTURE.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# MiniCode Python — 包结构(STRUCTURE)
2+
3+
> 规范实现:仓库根目录的 `minicode/` 包。本文按子系统列出当前真实结构与模块职责(以实际文件为准,2026-06-16 校对)。
4+
> 模块数:`minicode/` 顶层 80 · `tools/` 30 · `tui/` 19。
5+
6+
---
7+
8+
## 入口与运行时
9+
10+
| 模块 | 职责 |
11+
|---|---|
12+
| `main.py` | CLI 入口;参数解析(`--log-level`/`--structured-logs`/`--allow-edits`/`--rewind` 等),启动 TTY 或 headless。 |
13+
| `headless.py` | 非交互一次性执行(CI/CD);`run_headless`,支持 `--allow-edits`/`MINI_CODE_ALLOW_EDITS` 免交互编辑。 |
14+
| `tty_app.py` | 全屏 TTY 应用主循环(事件驱动、raw 输入、节流渲染、自动保存)。 |
15+
| `manage_cli.py` | `/model``/mcp` 等管理子命令。 |
16+
| `install.py` | 跨平台启动器安装(PATH 指引)。 |
17+
| `config.py` | 运行时配置加载(`~/.mini-code/settings.json``.env`、环境变量)。 |
18+
| `workspace.py` | 工作区路径解析(`resolve_tool_path`、cwd 边界)。 |
19+
| `state.py` | 应用状态 Store(busy/cost/context-usage 等状态机)。 |
20+
21+
## Agent 循环与编排
22+
23+
| 模块 | 职责 |
24+
|---|---|
25+
| `agent_loop.py` | 核心 agent 循环(think/act/verify 递归、工具调度、压缩触发、控制信号反馈)。 |
26+
| `turn_kernel.py` | 单轮状态机(max_steps、widen、重试、verification)。 |
27+
| `agent_intelligence.py` | 运行时智能启发(并发/模式信号)。 |
28+
| `agent_router.py` | 任务复杂度分类 → 模型路由。 |
29+
| `agent_reflection.py` | 任务后自省引擎。 |
30+
| `smart_router.py` | 智能工具/路径路由。 |
31+
| `intent_parser.py` | 用户意图解析(CODE/DEBUG/REFACTOR/SEARCH…)。 |
32+
| `domain_classifier.py` | 领域分类。 |
33+
| `pipeline_engine.py` | 多步流水线引擎。 |
34+
| `task_graph.py` / `task_object.py` / `task_tracker.py` | 任务图、任务对象、任务追踪。 |
35+
36+
## 工具系统
37+
38+
| 模块 | 职责 |
39+
|---|---|
40+
| `tooling.py` | `ToolRegistry`/`ToolDefinition`/`ToolResult``execute` 带异常兜底 + 工具执行日志。 |
41+
| `local_tool_shortcuts.py` | `/ls` `/grep` `/read` `/write` `/edit` `/cmd` 等快捷解析。 |
42+
| `capability_registry.py` | 能力注册与执行统计。 |
43+
| `tools/` | 内置工具集(见下)。 |
44+
45+
### `tools/`(30 个内置工具)
46+
- **文件**`read_file` `write_file` `edit_file` `modify_file` `patch_file` `list_files` `file_tree` `grep_files` `batch_ops` `archive_utils`
47+
- **执行**`run_command`(支持 `MINI_CODE_COMMAND_ENCODING` 编码开关)`test_runner` `git`
48+
- **代码**`code_nav` `code_review` `diff_viewer`
49+
- **网络**`web_fetch` `web_search` `http_utils`
50+
- **交互**`ask_user` `todo_write` `task`(子 agent)`load_skill`
51+
- **工具函数**`text_utils` `regex_utils` `json_utils` `csv_utils` `encoding_utils`
52+
53+
## TUI(终端界面,`tui/`
54+
55+
| 模块 | 职责 |
56+
|---|---|
57+
| `renderer.py` | 整屏渲染(缓存 header/footer、增量 hash)。 |
58+
| `screen.py` | alt-screen / VT 处理 / Windows VT 启用 / dumb 终端判定。 |
59+
| `transcript.py` | 会话流渲染 + BM25/CJK 视觉换行滚动(端口自 TS `wrapPanelBodyLine`)。 |
60+
| `input_parser.py` | raw 输入 → 事件(按键/文本/滚轮/粘贴,多行粘贴不提交)。 |
61+
| `input_handler.py` | `_handle_input`(命令分发、agent turn 启动、工具生命周期)。 |
62+
| `event_flow.py` | 事件路由(普通/审批/反馈模式)。 |
63+
| `navigation.py` | 滚动/历史/斜杠命令匹配。 |
64+
| `chrome.py` | banner/panel/footer/permission 渲染原语 + 终端尺寸缓存。 |
65+
| `session_flow.py` | TTY 会话加载/创建/快照/收尾。 |
66+
| `runtime_control.py` | 节流渲染器、alt-screen 进出、SIGWINCH。 |
67+
| `tool_lifecycle.py` / `tool_helpers.py` | 工具条目推送/折叠/收尾。 |
68+
| `state.py` | `ScreenState`/`TtyAppArgs`|
69+
| `theme.py` `markdown.py` `input.py` `ui_hints.py` `types.py` | 主题、markdown 渲染、输入提示框、UI 提示、类型。 |
70+
71+
## 模型适配与注册
72+
73+
| 模块 | 职责 |
74+
|---|---|
75+
| `anthropic_adapter.py` | Anthropic Messages API(流式/工具/缓存计费)。 |
76+
| `openai_adapter.py` | OpenAI 兼容 API(流式/工具/计费,支持代理)。 |
77+
| `mock_model.py` | 测试用 ScriptedModel 基类。 |
78+
| `model_registry.py` | 模型注册表、`create_model_adapter`、Provider 解析、模型状态格式化。 |
79+
| `model_switcher.py` | 运行时模型热切换(`switch_to`/fallback)。 |
80+
| `api_retry.py` | 可重试状态判定 + 指数退避 + Retry-After 解析。 |
81+
82+
## 上下文与压缩
83+
84+
| 模块 | 职责 |
85+
|---|---|
86+
| `context_manager.py` | token 估算(CJK 感知)、`get_model_context_window``compute_context_stats``token_count_with_estimation`|
87+
| `context_compactor.py` | `AutoCompactDispatcher`(熔断 + 自动恢复)、`ReactiveCompactEngine``ToolResultBudgetManager``ReadDedupManager`、microcompact/session-memory 引擎。 |
88+
| `micro_compact.py` | 轻量工具结果裁剪(时间/预算双策略,超预算 trim 最旧)。 |
89+
| `circuit_breaker.py` | 通用 `CompactionCircuitBreaker`(auto-reset)。 |
90+
| `layered_context.py` / `working_memory.py` | 分层上下文 / 工作记忆。 |
91+
| `timeline_memory.py` | 时间线记忆。 |
92+
| `vector_memory.py` | 向量记忆。 |
93+
| `prompt.py` / `prompt_pipeline.py` | 系统提示组装(静态前缀 + 动态后缀,含 malformed 输入加固)。 |
94+
95+
## 记忆系统
96+
97+
| 模块 | 职责 |
98+
|---|---|
99+
| `memory.py` | 三层 `MemoryManager`(user/project/local)+ BM25/TF-IDF 检索(`MemoryEntry` content 强制 str)。 |
100+
| `memory_pipeline.py` | 记忆流水线编排。 |
101+
| `memory_curator_agent.py` | 记忆策展 agent。 |
102+
| `memory_injector.py` | 上下文感知记忆注入控制器。 |
103+
| `memory_reranker.py` | 检索结果重排。 |
104+
105+
## 会话 / 持久化
106+
107+
| 模块 | 职责 |
108+
|---|---|
109+
| `session.py` | 会话持久化(全量 + 增量 delta + 合并)、checkpoint、rewind;`update_metadata` 容错。 |
110+
| `history.py` | 提示历史(`~/.mini-code/history.json`,TTL 缓存,str 强制)。 |
111+
| `hooks.py` | 钩子系统(USER_INPUT/ASSISTANT_OUTPUT 等事件)。 |
112+
| `background_tasks.py` | 后台任务注册/列表。 |
113+
114+
## 权限与安全
115+
116+
| 模块 | 职责 |
117+
|---|---|
118+
| `permissions.py` | `PermissionManager`(路径/命令/编辑审批 + auto 模式 + 结构化日志)。 |
119+
| `auto_mode.py` | `AutoModeChecker`(风险评估、`detect_prompt_injection``classify_output_safety`)。 |
120+
| `file_review.py` | 文件改动审查(diff 预览、`apply_reviewed_file_change`)。 |
121+
122+
## MCP / 技能 / 用户
123+
124+
| 模块 | 职责 |
125+
|---|---|
126+
| `mcp.py` | MCP stdio 客户端(懒启动、npx/`.cmd` 解析、协议自动探测、安全白名单)。 |
127+
| `skills.py` | SKILL.md 工作流发现与加载。 |
128+
| `user_profile.py` | 用户画像(语言/风格,USER.md)。 |
129+
130+
## 日志
131+
132+
| 模块 | 职责 |
133+
|---|---|
134+
| `logging_config.py` | `setup_logging`(按大小轮转)、`StructuredFormatter``log_api_call`/`log_tool_execution`/`log_permission_check`/`log_session_event``--structured-logs`/`MINI_CODE_LOG_STRUCTURED`|
135+
136+
## 控制论子系统(cybernetic)
137+
138+
> 自适应控制回路:传感器 → PID 控制器 → 执行器,黑盒调节 agent 行为。
139+
140+
| 模块 | 职责 |
141+
|---|---|
142+
| `cybernetic_orchestrator.py` | 控制回路编排总入口。 |
143+
| `cybernetic_supervisor.py` | 全局健康/风险聚合。 |
144+
| `cybernetic_ablation.py` | 控制回路消融开关。 |
145+
| `context_cybernetics.py` | 上下文压力 PID + 预测。 |
146+
| `feedback_controller.py` | 反馈 PID(含 `SystemState`/`ControlSignal`,抗饱和)。 |
147+
| `feedforward_controller.py` | 前馈预配置(意图→PreemptiveConfig)。 |
148+
| `predictive_controller.py` | 指数平滑/移动平均预测。 |
149+
| `decoupling_controller.py` | 解耦控制。 |
150+
| `adaptive_pid_tuner.py` | 自适应 PID 整定。 |
151+
| `state_observer.py` | 系统状态观测。 |
152+
| `progress_controller.py` | 任务进度/停滞控制。 |
153+
| `stability_monitor.py` | 稳定性监测。 |
154+
| `cost_control.py` | 成本速率 PID + 预算调节。 |
155+
| `cost_tracker.py` | 成本/用量统计(`calculate_cost``ModelUsage`)。 |
156+
| `agent_metrics.py` | 工具历史指标(`ToolHistoricalStats`)。 |
157+
| `verification_controller.py` | 风险自适应验证规划。 |
158+
| `self_healing_engine.py` | 自愈引擎。 |
159+
| `decision_audit.py` | 决策审计。 |
160+
| `runtime_profiles.py` / `runtime_profile_eval.py` | 运行时画像与评估。 |
161+
| `release_readiness.py` | 发布就绪评估。 |
162+
| `product_surfaces.py` | 产品快照(指令/钩子/委派/扩展/就绪摘要)。 |
163+
164+
## 共享类型
165+
166+
| 模块 | 职责 |
167+
|---|---|
168+
| `types.py` | `ChatMessage``AgentStep``ModelAdapter``RuntimeEvent``StepDiagnostics` 等核心类型。 |
169+
170+
---
171+
172+
## 测试与配置(仓库根,非包内)
173+
174+
- `tests/` — pytest 套件(含 `test_integration_rounds.py` 端到端、`test_ts_ported.py` TS 对齐、各子系统单测)。
175+
- `conftest.py` — pytest 共享夹具。
176+
- `pyproject.toml` — 包定义(`minicode-py`,入口 `minicode-py` / `minicode-headless`)。
177+
- `.env.example` — 环境变量样例(含 `MINI_CODE_COMMAND_ENCODING`)。
178+
- `ts-src/` — TypeScript 原版(移植参考,保留)。
179+
- `py-src/experiments/` — 研究 harness(未跟踪,`test_sealed_mini_study` 使用)。

0 commit comments

Comments
 (0)