mindcode 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. mindcode-0.2.0/PKG-INFO +244 -0
  2. mindcode-0.2.0/README.md +229 -0
  3. mindcode-0.2.0/mindcode/__init__.py +5 -0
  4. mindcode-0.2.0/mindcode/__main__.py +4 -0
  5. mindcode-0.2.0/mindcode/_version.py +11 -0
  6. mindcode-0.2.0/mindcode/approval.py +105 -0
  7. mindcode-0.2.0/mindcode/bench/__init__.py +19 -0
  8. mindcode-0.2.0/mindcode/bench/adapters/__init__.py +22 -0
  9. mindcode-0.2.0/mindcode/bench/adapters/base.py +45 -0
  10. mindcode-0.2.0/mindcode/bench/adapters/mini_bfcl.py +18 -0
  11. mindcode-0.2.0/mindcode/bench/adapters/mini_gaia.py +18 -0
  12. mindcode-0.2.0/mindcode/bench/adapters/mini_terminal.py +18 -0
  13. mindcode-0.2.0/mindcode/bench/adapters/swe_bench.py +86 -0
  14. mindcode-0.2.0/mindcode/bench/adapters/terminal_bench.py +107 -0
  15. mindcode-0.2.0/mindcode/bench/fake_tools.py +73 -0
  16. mindcode-0.2.0/mindcode/bench/jsonutil.py +20 -0
  17. mindcode-0.2.0/mindcode/bench/paths.py +10 -0
  18. mindcode-0.2.0/mindcode/bench/predictions.py +65 -0
  19. mindcode-0.2.0/mindcode/bench/report.py +48 -0
  20. mindcode-0.2.0/mindcode/bench/runner.py +250 -0
  21. mindcode-0.2.0/mindcode/bench/schema.py +78 -0
  22. mindcode-0.2.0/mindcode/bench/scorers/base.py +22 -0
  23. mindcode-0.2.0/mindcode/bench/scorers/composite.py +57 -0
  24. mindcode-0.2.0/mindcode/bench/scorers/exact.py +30 -0
  25. mindcode-0.2.0/mindcode/bench/scorers/json_call.py +44 -0
  26. mindcode-0.2.0/mindcode/bench/scorers/swe.py +29 -0
  27. mindcode-0.2.0/mindcode/bench/scorers/terminal.py +43 -0
  28. mindcode-0.2.0/mindcode/bench/scorers/terminal_bench.py +25 -0
  29. mindcode-0.2.0/mindcode/bench/trace.py +34 -0
  30. mindcode-0.2.0/mindcode/bench/workspace.py +127 -0
  31. mindcode-0.2.0/mindcode/cli/__init__.py +112 -0
  32. mindcode-0.2.0/mindcode/cli/_shared.py +43 -0
  33. mindcode-0.2.0/mindcode/cli/commands/__init__.py +1 -0
  34. mindcode-0.2.0/mindcode/cli/commands/bench.py +365 -0
  35. mindcode-0.2.0/mindcode/cli/commands/chat.py +86 -0
  36. mindcode-0.2.0/mindcode/cli/commands/config_cmd.py +197 -0
  37. mindcode-0.2.0/mindcode/cli/commands/remote.py +146 -0
  38. mindcode-0.2.0/mindcode/cli/commands/shell.py +108 -0
  39. mindcode-0.2.0/mindcode/cli/commands/status.py +37 -0
  40. mindcode-0.2.0/mindcode/cli/commands/task.py +417 -0
  41. mindcode-0.2.0/mindcode/cli/commands/terminal.py +124 -0
  42. mindcode-0.2.0/mindcode/cli/shell/__init__.py +5 -0
  43. mindcode-0.2.0/mindcode/cli/shell/completion.py +72 -0
  44. mindcode-0.2.0/mindcode/cli/shell/menu.py +88 -0
  45. mindcode-0.2.0/mindcode/cli/shell/repl.py +597 -0
  46. mindcode-0.2.0/mindcode/cli/shell/slash.py +480 -0
  47. mindcode-0.2.0/mindcode/cli/shell/startup.py +55 -0
  48. mindcode-0.2.0/mindcode/cli/shell/tui.py +897 -0
  49. mindcode-0.2.0/mindcode/config.py +173 -0
  50. mindcode-0.2.0/mindcode/mcp.py +205 -0
  51. mindcode-0.2.0/mindcode/policy.py +173 -0
  52. mindcode-0.2.0/mindcode/remote.py +216 -0
  53. mindcode-0.2.0/mindcode/render.py +458 -0
  54. mindcode-0.2.0/mindcode/runtime.py +541 -0
  55. mindcode-0.2.0/mindcode/skills.py +154 -0
  56. mindcode-0.2.0/mindcode/subagents.py +43 -0
  57. mindcode-0.2.0/mindcode/tasking.py +281 -0
  58. mindcode-0.2.0/mindcode/terminal/__init__.py +1 -0
  59. mindcode-0.2.0/mindcode/terminal/__main__.py +17 -0
  60. mindcode-0.2.0/mindcode/terminal_core.py +264 -0
  61. mindcode-0.2.0/mindcode.egg-info/PKG-INFO +244 -0
  62. mindcode-0.2.0/mindcode.egg-info/SOURCES.txt +86 -0
  63. mindcode-0.2.0/mindcode.egg-info/dependency_links.txt +1 -0
  64. mindcode-0.2.0/mindcode.egg-info/entry_points.txt +2 -0
  65. mindcode-0.2.0/mindcode.egg-info/requires.txt +6 -0
  66. mindcode-0.2.0/mindcode.egg-info/top_level.txt +1 -0
  67. mindcode-0.2.0/pyproject.toml +27 -0
  68. mindcode-0.2.0/setup.cfg +4 -0
  69. mindcode-0.2.0/tests/test_approval.py +153 -0
  70. mindcode-0.2.0/tests/test_bench.py +268 -0
  71. mindcode-0.2.0/tests/test_cli_commands.py +368 -0
  72. mindcode-0.2.0/tests/test_config.py +117 -0
  73. mindcode-0.2.0/tests/test_diff_capture.py +74 -0
  74. mindcode-0.2.0/tests/test_exec_command_guard.py +86 -0
  75. mindcode-0.2.0/tests/test_policy_choice.py +177 -0
  76. mindcode-0.2.0/tests/test_policy_timeout.py +207 -0
  77. mindcode-0.2.0/tests/test_remote.py +223 -0
  78. mindcode-0.2.0/tests/test_render_exec.py +126 -0
  79. mindcode-0.2.0/tests/test_shell_channels.py +292 -0
  80. mindcode-0.2.0/tests/test_shell_completion.py +100 -0
  81. mindcode-0.2.0/tests/test_shell_session.py +320 -0
  82. mindcode-0.2.0/tests/test_shell_tui.py +391 -0
  83. mindcode-0.2.0/tests/test_skills_mcp.py +185 -0
  84. mindcode-0.2.0/tests/test_subagents.py +188 -0
  85. mindcode-0.2.0/tests/test_system_prompt.py +51 -0
  86. mindcode-0.2.0/tests/test_task_resume.py +201 -0
  87. mindcode-0.2.0/tests/test_tasking.py +86 -0
  88. mindcode-0.2.0/tests/test_terminal.py +73 -0
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: mindcode
3
+ Version: 0.2.0
4
+ Summary: codex-style interactive coding agent on top of mindagent
5
+ Author: mindcode
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: mindagent
10
+ Requires-Dist: rich>=13
11
+ Requires-Dist: openai>=1.0
12
+ Requires-Dist: python-dotenv>=1.0
13
+ Requires-Dist: typer>=0.12
14
+ Requires-Dist: prompt-toolkit>=3.0.30
15
+
16
+ # mindcode
17
+
18
+ codex 风格的交互式 Coding Agent CLI,构建在 [mindagent](../) 之上。
19
+
20
+ ## 核心能力
21
+
22
+ - workspace 内的代码读取、编辑和命令执行
23
+ - 交互式会话与一次性任务
24
+ - 前台/后台任务记录和进程重启后的语义恢复
25
+ - 本地持久终端和 SSH 远程命令
26
+ - mini、SWE-bench 和 Terminal-Bench 评测入口
27
+
28
+ ## 特性
29
+
30
+ - **typer 多子命令**:`mindcode shell` / `chat` / `status` / `config`(默认 `mindcode` 等于 `mindcode shell`)
31
+ - **可选 Subagent 模式**:`mindcode shell --subagents` 启用受限的 master/coder 协作;master 仅能委派,coder 才能访问 workspace
32
+ - 全屏 TUI:顶部 logo/会话信息、可滚动 Markdown 消息区、固定带边框多行输入框与状态栏
33
+ - 顶部信息栏显示本会话累计 token 消耗;provider 未返回 usage 时显示 `tokens —`
34
+ - Rich 富渲染:Markdown、彩色工具面板、file_edit diff 高亮和流式 LLM 输出
35
+ - TUI 内选择菜单:`/models`、`/permissions` 用方向键选择
36
+ - REPL 权限模式:`ask_user`(默认,逐项询问)/ `full_accept`(全部接受)
37
+ - 会话持久化与恢复:基于 `LocalConversationStore`,存到 `~/.cache/mindcode/sessions/`
38
+ - OpenAI-compatible Provider 配置:首次启动时在 `~/.cache/mindcode/config.toml` 生成 rotor 示例
39
+ - 丰富 slash 命令:`/models` `/compact` `/permissions` `/status` `/config` `/sessions` `/history` `/diff` `/clear` `/help` `/exit`
40
+
41
+ ## VS Code 插件
42
+
43
+ 与 CLI 配套的 VS Code 聊天插件位于 [`vscode-extension/`](vscode-extension/)。
44
+ 进入该目录并按其 README 构建后,可在 VS Code 中按 `F5` 启动 Extension Development Host。
45
+
46
+ ## 安装
47
+
48
+ 先确保父项目 `mindagent` 已经以 editable 模式安装:
49
+
50
+ ```bash
51
+ cd /path/to/mindagent
52
+ pip install -e ".[openai]"
53
+ ```
54
+
55
+ 然后安装 mindcode:
56
+
57
+ ```bash
58
+ cd app/mindcode
59
+ pip install -e .
60
+ ```
61
+
62
+ ## 命令结构
63
+
64
+ ```
65
+ mindcode # 默认 = mindcode shell
66
+ mindcode shell [PROMPT] [选项] # 交互式 REPL(默认子命令)
67
+ mindcode chat -m "..." [选项] # 一次性 prompt
68
+ mindcode status # 显示全局状态
69
+ mindcode task <subcmd> # 运行、恢复、查看和取消任务
70
+ mindcode terminal <subcmd> # 管理本地持久终端
71
+ mindcode remote <subcmd> # 管理 SSH 目标并执行命令
72
+ mindcode bench <subcmd> # 运行或查看 benchmark
73
+ mindcode config <subcmd> # 配置管理
74
+ mindcode config providers # 列出所有 provider
75
+ mindcode config models <provider> # 列出 provider 的模型
76
+ mindcode config api-key <p> <k> # 设置 api_key
77
+ mindcode config get <p> <field> # 读取字段
78
+ mindcode config set <p> <f> <v> # 修改字段
79
+ mindcode config list # 显示完整配置(脱敏)
80
+ mindcode config path # 显示配置文件路径
81
+ mindcode --version
82
+ mindcode --help
83
+ ```
84
+
85
+ ## 配置
86
+
87
+ 首次启动 `mindcode` 会自动在 `~/.cache/mindcode/config.toml` 创建一个
88
+ OpenAI-compatible rotor 示例。默认地址是本机 `http://127.0.0.1:8000/v1`,使用前应按实际网关修改。
89
+
90
+ 模板节选:
91
+
92
+ ```toml
93
+ default_provider = "rotor"
94
+
95
+ [providers.rotor]
96
+ protocol = "openai"
97
+ api_key = ""
98
+ base_url = "http://127.0.0.1:8000/v1"
99
+ default_model = "glm-5.2"
100
+ models = ["glm-5.2", "glm-5.1", "glm-4.7"]
101
+ ```
102
+
103
+ ### 方式 A:命令行(脚本化)
104
+
105
+ ```bash
106
+ mindcode config api-key rotor sk-xxxxxxxxxxxx # 设置密钥
107
+ mindcode config providers # 列出所有 provider
108
+ mindcode config models rotor # 列出 rotor 的模型
109
+ mindcode config set rotor default_model glm-5.1
110
+ mindcode config list # 完整配置(脱敏)
111
+ ```
112
+
113
+ ### 方式 B:REPL 内 slash 命令(交互式)
114
+
115
+ ```
116
+ /models # 方向键选择切换
117
+ /compact # 生成摘要以压缩会话上下文
118
+ /permissions # Ask User / Full Accept
119
+ /config # 显示当前配置
120
+ /status # Rich Panel 状态
121
+ /help # 完整命令列表
122
+ ```
123
+
124
+ 也可直接编辑 `~/.cache/mindcode/config.toml`。
125
+
126
+ ## 使用
127
+
128
+ ### 一次性模式
129
+
130
+ ```bash
131
+ mindcode chat -m "读取 README.md 的前 5 行并总结"
132
+ # 或
133
+ mindcode shell "读取 README.md 的前 5 行并总结"
134
+ # 需要 master/coder 协作时(默认仍为单 agent)
135
+ mindcode shell --subagents "审查当前改动并运行相关测试"
136
+ ```
137
+
138
+ ### 交互模式
139
+
140
+ - `Enter` 发送;`Esc` + `Enter` 插入换行;多行输入框会自动增高。
141
+ - 输入 `/` 显示全部 slash 命令;继续输入会筛选。`↑` / `↓` 选择,`Enter` 先填入默认第一项,再按一次才执行。
142
+ - `/models` 与 `/permissions` 使用统一的灰阶选择框:`↑` / `↓` 切换,`Enter` 应用,`Esc` 取消;需要自由输入参数时仍在底部输入框内编辑和粘贴。
143
+ - `Page Up` / `Page Down` 或鼠标滚轮滚动消息;`End` 回到底部。
144
+ - 鼠标拖选消息会复制所选文本;`Ctrl` + `Y` 复制最新一条助手回复。
145
+ - 单行文字在输入框和用户消息卡片内上下居中;多行内容向下撑开。
146
+ - 用户消息会以与输入框相同的边框卡片进入对话,助手消息保留 Markdown 排版。
147
+ - Agent 运行时显示 `Working…`,输入框仍可提交后续消息并按顺序排队。
148
+ - 工具状态使用简洁标签:`Edit`、`Command`、`Read`、`Search`、`Context`、`Memory`、`Image`、`Time`、`Calculate`、`Delegate`;完成或失败时原地更新。
149
+
150
+ ```bash
151
+ mindcode # 默认进 shell
152
+ › 在 workspace 创建 hello.txt 写入 hi
153
+ › file_edit (create) hello.txt [WRITE]
154
+ ask_user 将在执行前询问;也可切换到 /permissions full_accept
155
+ ┌─ diff: hello.txt ──────────────────────┐
156
+ │ +hi │
157
+ └─────────────────────────────────────────┘
158
+ › /diff
159
+ › /sessions
160
+ › /exit
161
+ ```
162
+
163
+ ### 恢复会话
164
+
165
+ ```bash
166
+ mindcode shell -r sess-1718530000
167
+ › 我刚才创建了什么文件?
168
+ ```
169
+
170
+ ### `mindcode shell` 参数
171
+
172
+ ```
173
+ mindcode shell [PROMPT] [-w WORKSPACE] [-a {ask_user,full_accept}]
174
+ [-p PROVIDER] [-m MODEL]
175
+ [-r SESSION_ID] [-s SESSION_ID] [--no-stream] [--subagents]
176
+ ```
177
+
178
+ | 参数 | 说明 |
179
+ |---|---|
180
+ | `PROMPT` | 一次性 prompt;省略进入交互模式 |
181
+ | `-w, --workspace` | workspace 根目录(默认 `.`) |
182
+ | `-a, --approve-mode` | 权限模式:`ask_user`(默认,逐项询问)或 `full_accept`(全部接受);`ask`/`full`/`auto` 为兼容别名 |
183
+ | `-p, --provider` | 覆盖 config.toml 中的 default_provider |
184
+ | `-m, --model` | 覆盖 provider 中的 default_model |
185
+ | `-r, --resume` | 恢复指定 session_id |
186
+ | `-s, --session` | 指定新 session_id |
187
+ | `--no-stream` | 关闭流式输出 |
188
+ | `--subagents` | 启用 master/coder 委派模式。master 只允许 `agent_delegate`,coder 负责 workspace 工具调用;委派固定等待结果,不会启动后台任务。 |
189
+
190
+ ## 测试
191
+
192
+ ```bash
193
+ PYTHONPATH=src:app/mindcode python -m pytest -q app/mindcode/tests
194
+ ```
195
+
196
+ ## 模块结构(对齐 mindbot/src/mindbot/cli/)
197
+
198
+ ```
199
+ mindcode/
200
+ ├── _version.py # __version__, __logo__
201
+ ├── config.py # MindcodeConfig + ProviderConfig + load/save
202
+ ├── runtime.py # build_runtime/build_master_worker_system + DiffingFileEditTool
203
+ ├── subagents.py # MasterWorkerSystem 生命周期边界
204
+ ├── policy.py # ApprovalMode + AskUserPolicy/FullAcceptPolicy
205
+ ├── render.py # RichRenderer(event handler)
206
+ ├── tasking.py # 本地任务记录与事件持久化
207
+ ├── terminal_core.py # 本地持久终端
208
+ ├── remote.py # SSH 配置与命令执行
209
+ ├── bench/ # benchmark adapter、runner 和 scorer
210
+ └── cli/
211
+ ├── __init__.py # typer app + 命令注册
212
+ ├── _shared.py # 共享 console + find_config_file
213
+ ├── commands/
214
+ │ ├── shell.py # `mindcode shell`
215
+ │ ├── chat.py # `mindcode chat -m "..."`
216
+ │ ├── status.py # `mindcode status`
217
+ │ ├── config_cmd.py # `mindcode config providers/models/api-key/...`
218
+ │ ├── task.py # `mindcode task ...`
219
+ │ ├── terminal.py # `mindcode terminal ...`
220
+ │ ├── remote.py # `mindcode remote ...`
221
+ │ └── bench.py # `mindcode bench ...`
222
+ └── shell/
223
+ ├── repl.py # Shell 类 + REPL 主循环
224
+ ├── slash.py # slash 命令分发
225
+ ├── tui.py # 全屏布局、Markdown 消息流与状态栏
226
+ ├── menu.py # interactive_menu(ChoiceInput 包装)
227
+ └── startup.py # build_welcome_banner(Rich Panel)
228
+ ```
229
+
230
+ ## 设计要点
231
+
232
+ - `DiffingFileEditTool` 包装 mindagent 的 `FileEditTool`,在调用前后捕获文件内容,生成 unified diff 注入到 `Observation.result["mindcode_diff"]`。
233
+ - diff 渲染监听 `OBSERVATION_CREATED` 事件而非 `ACTION_FINISHED`,因为 result payload 只在前者。
234
+ - REPL 的 `/permissions` 通过重建当前 runtime 切换 `ask_user` 与 `full_accept`;前者逐项询问,后者全部接受,切换只影响当前会话。
235
+ - typer app 用自定义 `TyperGroup.parse_args`:`mindcode` 无参数或第一参数是 shell 的 flag → 自动注入 `shell` 子命令,复用完整参数解析。
236
+ - 全屏 TUI 用 Prompt Toolkit 管理固定输入框和消息视口;Rich 负责 Markdown 与工具输出渲染。
237
+ - ChoiceInput 失败时(旧版 prompt_toolkit)会自动 fallback 到序号输入。
238
+
239
+ ## 局限
240
+
241
+ - 不支持 `/undo`:`exec_command` 的副作用可能不可逆,回滚复杂。
242
+ - 会话恢复只续聊 user/assistant 历史,不恢复 TaskState / Evidence / pending continuation。
243
+ - `task resume` 是重新观察 workspace 后创建新 Run,不会重放未确认的旧 Action。
244
+ - 后台任务目前依赖本机 PID;不提供跨主机监督或精确进程身份恢复。
@@ -0,0 +1,229 @@
1
+ # mindcode
2
+
3
+ codex 风格的交互式 Coding Agent CLI,构建在 [mindagent](../) 之上。
4
+
5
+ ## 核心能力
6
+
7
+ - workspace 内的代码读取、编辑和命令执行
8
+ - 交互式会话与一次性任务
9
+ - 前台/后台任务记录和进程重启后的语义恢复
10
+ - 本地持久终端和 SSH 远程命令
11
+ - mini、SWE-bench 和 Terminal-Bench 评测入口
12
+
13
+ ## 特性
14
+
15
+ - **typer 多子命令**:`mindcode shell` / `chat` / `status` / `config`(默认 `mindcode` 等于 `mindcode shell`)
16
+ - **可选 Subagent 模式**:`mindcode shell --subagents` 启用受限的 master/coder 协作;master 仅能委派,coder 才能访问 workspace
17
+ - 全屏 TUI:顶部 logo/会话信息、可滚动 Markdown 消息区、固定带边框多行输入框与状态栏
18
+ - 顶部信息栏显示本会话累计 token 消耗;provider 未返回 usage 时显示 `tokens —`
19
+ - Rich 富渲染:Markdown、彩色工具面板、file_edit diff 高亮和流式 LLM 输出
20
+ - TUI 内选择菜单:`/models`、`/permissions` 用方向键选择
21
+ - REPL 权限模式:`ask_user`(默认,逐项询问)/ `full_accept`(全部接受)
22
+ - 会话持久化与恢复:基于 `LocalConversationStore`,存到 `~/.cache/mindcode/sessions/`
23
+ - OpenAI-compatible Provider 配置:首次启动时在 `~/.cache/mindcode/config.toml` 生成 rotor 示例
24
+ - 丰富 slash 命令:`/models` `/compact` `/permissions` `/status` `/config` `/sessions` `/history` `/diff` `/clear` `/help` `/exit`
25
+
26
+ ## VS Code 插件
27
+
28
+ 与 CLI 配套的 VS Code 聊天插件位于 [`vscode-extension/`](vscode-extension/)。
29
+ 进入该目录并按其 README 构建后,可在 VS Code 中按 `F5` 启动 Extension Development Host。
30
+
31
+ ## 安装
32
+
33
+ 先确保父项目 `mindagent` 已经以 editable 模式安装:
34
+
35
+ ```bash
36
+ cd /path/to/mindagent
37
+ pip install -e ".[openai]"
38
+ ```
39
+
40
+ 然后安装 mindcode:
41
+
42
+ ```bash
43
+ cd app/mindcode
44
+ pip install -e .
45
+ ```
46
+
47
+ ## 命令结构
48
+
49
+ ```
50
+ mindcode # 默认 = mindcode shell
51
+ mindcode shell [PROMPT] [选项] # 交互式 REPL(默认子命令)
52
+ mindcode chat -m "..." [选项] # 一次性 prompt
53
+ mindcode status # 显示全局状态
54
+ mindcode task <subcmd> # 运行、恢复、查看和取消任务
55
+ mindcode terminal <subcmd> # 管理本地持久终端
56
+ mindcode remote <subcmd> # 管理 SSH 目标并执行命令
57
+ mindcode bench <subcmd> # 运行或查看 benchmark
58
+ mindcode config <subcmd> # 配置管理
59
+ mindcode config providers # 列出所有 provider
60
+ mindcode config models <provider> # 列出 provider 的模型
61
+ mindcode config api-key <p> <k> # 设置 api_key
62
+ mindcode config get <p> <field> # 读取字段
63
+ mindcode config set <p> <f> <v> # 修改字段
64
+ mindcode config list # 显示完整配置(脱敏)
65
+ mindcode config path # 显示配置文件路径
66
+ mindcode --version
67
+ mindcode --help
68
+ ```
69
+
70
+ ## 配置
71
+
72
+ 首次启动 `mindcode` 会自动在 `~/.cache/mindcode/config.toml` 创建一个
73
+ OpenAI-compatible rotor 示例。默认地址是本机 `http://127.0.0.1:8000/v1`,使用前应按实际网关修改。
74
+
75
+ 模板节选:
76
+
77
+ ```toml
78
+ default_provider = "rotor"
79
+
80
+ [providers.rotor]
81
+ protocol = "openai"
82
+ api_key = ""
83
+ base_url = "http://127.0.0.1:8000/v1"
84
+ default_model = "glm-5.2"
85
+ models = ["glm-5.2", "glm-5.1", "glm-4.7"]
86
+ ```
87
+
88
+ ### 方式 A:命令行(脚本化)
89
+
90
+ ```bash
91
+ mindcode config api-key rotor sk-xxxxxxxxxxxx # 设置密钥
92
+ mindcode config providers # 列出所有 provider
93
+ mindcode config models rotor # 列出 rotor 的模型
94
+ mindcode config set rotor default_model glm-5.1
95
+ mindcode config list # 完整配置(脱敏)
96
+ ```
97
+
98
+ ### 方式 B:REPL 内 slash 命令(交互式)
99
+
100
+ ```
101
+ /models # 方向键选择切换
102
+ /compact # 生成摘要以压缩会话上下文
103
+ /permissions # Ask User / Full Accept
104
+ /config # 显示当前配置
105
+ /status # Rich Panel 状态
106
+ /help # 完整命令列表
107
+ ```
108
+
109
+ 也可直接编辑 `~/.cache/mindcode/config.toml`。
110
+
111
+ ## 使用
112
+
113
+ ### 一次性模式
114
+
115
+ ```bash
116
+ mindcode chat -m "读取 README.md 的前 5 行并总结"
117
+ # 或
118
+ mindcode shell "读取 README.md 的前 5 行并总结"
119
+ # 需要 master/coder 协作时(默认仍为单 agent)
120
+ mindcode shell --subagents "审查当前改动并运行相关测试"
121
+ ```
122
+
123
+ ### 交互模式
124
+
125
+ - `Enter` 发送;`Esc` + `Enter` 插入换行;多行输入框会自动增高。
126
+ - 输入 `/` 显示全部 slash 命令;继续输入会筛选。`↑` / `↓` 选择,`Enter` 先填入默认第一项,再按一次才执行。
127
+ - `/models` 与 `/permissions` 使用统一的灰阶选择框:`↑` / `↓` 切换,`Enter` 应用,`Esc` 取消;需要自由输入参数时仍在底部输入框内编辑和粘贴。
128
+ - `Page Up` / `Page Down` 或鼠标滚轮滚动消息;`End` 回到底部。
129
+ - 鼠标拖选消息会复制所选文本;`Ctrl` + `Y` 复制最新一条助手回复。
130
+ - 单行文字在输入框和用户消息卡片内上下居中;多行内容向下撑开。
131
+ - 用户消息会以与输入框相同的边框卡片进入对话,助手消息保留 Markdown 排版。
132
+ - Agent 运行时显示 `Working…`,输入框仍可提交后续消息并按顺序排队。
133
+ - 工具状态使用简洁标签:`Edit`、`Command`、`Read`、`Search`、`Context`、`Memory`、`Image`、`Time`、`Calculate`、`Delegate`;完成或失败时原地更新。
134
+
135
+ ```bash
136
+ mindcode # 默认进 shell
137
+ › 在 workspace 创建 hello.txt 写入 hi
138
+ › file_edit (create) hello.txt [WRITE]
139
+ ask_user 将在执行前询问;也可切换到 /permissions full_accept
140
+ ┌─ diff: hello.txt ──────────────────────┐
141
+ │ +hi │
142
+ └─────────────────────────────────────────┘
143
+ › /diff
144
+ › /sessions
145
+ › /exit
146
+ ```
147
+
148
+ ### 恢复会话
149
+
150
+ ```bash
151
+ mindcode shell -r sess-1718530000
152
+ › 我刚才创建了什么文件?
153
+ ```
154
+
155
+ ### `mindcode shell` 参数
156
+
157
+ ```
158
+ mindcode shell [PROMPT] [-w WORKSPACE] [-a {ask_user,full_accept}]
159
+ [-p PROVIDER] [-m MODEL]
160
+ [-r SESSION_ID] [-s SESSION_ID] [--no-stream] [--subagents]
161
+ ```
162
+
163
+ | 参数 | 说明 |
164
+ |---|---|
165
+ | `PROMPT` | 一次性 prompt;省略进入交互模式 |
166
+ | `-w, --workspace` | workspace 根目录(默认 `.`) |
167
+ | `-a, --approve-mode` | 权限模式:`ask_user`(默认,逐项询问)或 `full_accept`(全部接受);`ask`/`full`/`auto` 为兼容别名 |
168
+ | `-p, --provider` | 覆盖 config.toml 中的 default_provider |
169
+ | `-m, --model` | 覆盖 provider 中的 default_model |
170
+ | `-r, --resume` | 恢复指定 session_id |
171
+ | `-s, --session` | 指定新 session_id |
172
+ | `--no-stream` | 关闭流式输出 |
173
+ | `--subagents` | 启用 master/coder 委派模式。master 只允许 `agent_delegate`,coder 负责 workspace 工具调用;委派固定等待结果,不会启动后台任务。 |
174
+
175
+ ## 测试
176
+
177
+ ```bash
178
+ PYTHONPATH=src:app/mindcode python -m pytest -q app/mindcode/tests
179
+ ```
180
+
181
+ ## 模块结构(对齐 mindbot/src/mindbot/cli/)
182
+
183
+ ```
184
+ mindcode/
185
+ ├── _version.py # __version__, __logo__
186
+ ├── config.py # MindcodeConfig + ProviderConfig + load/save
187
+ ├── runtime.py # build_runtime/build_master_worker_system + DiffingFileEditTool
188
+ ├── subagents.py # MasterWorkerSystem 生命周期边界
189
+ ├── policy.py # ApprovalMode + AskUserPolicy/FullAcceptPolicy
190
+ ├── render.py # RichRenderer(event handler)
191
+ ├── tasking.py # 本地任务记录与事件持久化
192
+ ├── terminal_core.py # 本地持久终端
193
+ ├── remote.py # SSH 配置与命令执行
194
+ ├── bench/ # benchmark adapter、runner 和 scorer
195
+ └── cli/
196
+ ├── __init__.py # typer app + 命令注册
197
+ ├── _shared.py # 共享 console + find_config_file
198
+ ├── commands/
199
+ │ ├── shell.py # `mindcode shell`
200
+ │ ├── chat.py # `mindcode chat -m "..."`
201
+ │ ├── status.py # `mindcode status`
202
+ │ ├── config_cmd.py # `mindcode config providers/models/api-key/...`
203
+ │ ├── task.py # `mindcode task ...`
204
+ │ ├── terminal.py # `mindcode terminal ...`
205
+ │ ├── remote.py # `mindcode remote ...`
206
+ │ └── bench.py # `mindcode bench ...`
207
+ └── shell/
208
+ ├── repl.py # Shell 类 + REPL 主循环
209
+ ├── slash.py # slash 命令分发
210
+ ├── tui.py # 全屏布局、Markdown 消息流与状态栏
211
+ ├── menu.py # interactive_menu(ChoiceInput 包装)
212
+ └── startup.py # build_welcome_banner(Rich Panel)
213
+ ```
214
+
215
+ ## 设计要点
216
+
217
+ - `DiffingFileEditTool` 包装 mindagent 的 `FileEditTool`,在调用前后捕获文件内容,生成 unified diff 注入到 `Observation.result["mindcode_diff"]`。
218
+ - diff 渲染监听 `OBSERVATION_CREATED` 事件而非 `ACTION_FINISHED`,因为 result payload 只在前者。
219
+ - REPL 的 `/permissions` 通过重建当前 runtime 切换 `ask_user` 与 `full_accept`;前者逐项询问,后者全部接受,切换只影响当前会话。
220
+ - typer app 用自定义 `TyperGroup.parse_args`:`mindcode` 无参数或第一参数是 shell 的 flag → 自动注入 `shell` 子命令,复用完整参数解析。
221
+ - 全屏 TUI 用 Prompt Toolkit 管理固定输入框和消息视口;Rich 负责 Markdown 与工具输出渲染。
222
+ - ChoiceInput 失败时(旧版 prompt_toolkit)会自动 fallback 到序号输入。
223
+
224
+ ## 局限
225
+
226
+ - 不支持 `/undo`:`exec_command` 的副作用可能不可逆,回滚复杂。
227
+ - 会话恢复只续聊 user/assistant 历史,不恢复 TaskState / Evidence / pending continuation。
228
+ - `task resume` 是重新观察 workspace 后创建新 Run,不会重放未确认的旧 Action。
229
+ - 后台任务目前依赖本机 PID;不提供跨主机监督或精确进程身份恢复。
@@ -0,0 +1,5 @@
1
+ """mindcode — task execution and development supervision agent."""
2
+
3
+ from ._version import __logo__, __version__
4
+
5
+ __all__ = ["__logo__", "__version__"]
@@ -0,0 +1,4 @@
1
+ from .cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
@@ -0,0 +1,11 @@
1
+ """mindcode 版本与品牌信息。"""
2
+
3
+ __version__ = "0.2.0"
4
+
5
+ __logo__ = r"""
6
+ [bold cyan] _ _[/bold cyan]
7
+ [bold cyan] _ __ ___ ___ _ __ ___ (_) ___ ___| |_[/bold cyan]
8
+ [bold cyan] | '_ ` _ \ / _ \ '_ ` _ \| |/ _ \/ __| __|[/bold cyan]
9
+ [bold cyan] | | | | | | __/ | | | | | | __/ (__| |_[/bold cyan]
10
+ [bold cyan] |_| |_| |_|\___|_| |_| |_|_|\___|\___|\__|[/bold cyan]
11
+ """
@@ -0,0 +1,105 @@
1
+ """审批文案与审批回调装配(TUI 优先,裸终端回退)。
2
+
3
+ ``describe_action`` 只依赖 ``mindagent.core`` 的数据结构,不碰
4
+ prompt_toolkit;``make_shell_approval`` 在运行时动态读取 chooser,
5
+ TUI 全屏运行时走 ``MindcodeTui.choose`` 的 RadioList 浮层,
6
+ one-shot / TUI 未启动时回退到 ``menu.prompt_yes_no``。
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ from collections.abc import Awaitable, Callable
13
+ from typing import Any
14
+
15
+ from mindagent.core import ActionRequest, AgentContext
16
+
17
+ from .policy import ApprovalCallback
18
+
19
+
20
+ def risk_label(risk: Any) -> str:
21
+ """ActionRisk 中文化;未知值回退到其 value/str。"""
22
+ from mindagent.core import ActionRisk
23
+
24
+ mapping = {
25
+ ActionRisk.READ_ONLY: "只读",
26
+ ActionRisk.WRITE: "写操作",
27
+ ActionRisk.DANGEROUS: "危险操作",
28
+ }
29
+ if risk in mapping:
30
+ return mapping[risk]
31
+ return str(getattr(risk, "value", risk))
32
+
33
+
34
+ def _one_line(text: Any) -> str:
35
+ return str(text).replace("\r", " ").replace("\n", " ")
36
+
37
+
38
+ def describe_action(action: ActionRequest) -> str:
39
+ """按工具类型生成一行友好摘要(保证单行,供 TUI 单行 title 用)。"""
40
+ name = action.name
41
+ arguments = (
42
+ action.arguments if isinstance(action.arguments, dict) else {}
43
+ )
44
+ if name in ("file_edit", "file_write"):
45
+ verb = "Edit" if name == "file_edit" else "Write"
46
+ path = _one_line(arguments.get("path", "?"))
47
+ return f"{verb} {path} [{risk_label(action.risk)}]"
48
+ if name == "exec_command":
49
+ command = arguments.get("command", "")
50
+ if isinstance(command, list):
51
+ preview = " ".join(_one_line(item) for item in command)
52
+ else:
53
+ preview = _one_line(command)
54
+ if len(preview) > 120:
55
+ preview = preview[:117] + "..."
56
+ return f"Command {preview} [{risk_label(action.risk)}]"
57
+ if name in ("file_read", "memory_read"):
58
+ path = _one_line(arguments.get("path", "?"))
59
+ return f"Read {path} [{risk_label(action.risk)}]"
60
+ payload = json.dumps(arguments, ensure_ascii=False, sort_keys=True)
61
+ if len(payload) > 240:
62
+ payload = payload[:237] + "..."
63
+ return f"{name} {payload}"
64
+
65
+
66
+ Chooser = Callable[
67
+ [str, list[tuple[str, str]], str | None],
68
+ Awaitable[str | None],
69
+ ]
70
+
71
+
72
+ def make_shell_approval(
73
+ get_chooser: Callable[[], Chooser | None],
74
+ ) -> ApprovalCallback:
75
+ """装配 `(context, action) -> bool` 审批回调。
76
+
77
+ TUI 运行时 ``get_chooser()`` 返回 ``MindcodeTui.choose``(与 slash
78
+ 命令的 ``_choose_option`` 同一条路),用 RadioList 浮层二选一;
79
+ 返回 None(取消/Esc/TUI 未运行)一律视为拒绝。chooser 不可用时
80
+ 回退到裸 ``menu.prompt_yes_no``(one-shot / 非 TUI 路径)。
81
+ """
82
+
83
+ async def _approve(
84
+ context: AgentContext,
85
+ action: ActionRequest,
86
+ ) -> bool:
87
+ summary = describe_action(action)
88
+ chooser = get_chooser()
89
+ if chooser is not None:
90
+ # choose 的 dialog title 是 height=1 的单行 Window,
91
+ # 多行会被裁掉,故 summary 必须压成单行。
92
+ result = await chooser(
93
+ f"允许执行? {summary}",
94
+ [("allow", "允许"), ("deny", "拒绝")],
95
+ "deny",
96
+ )
97
+ return result == "allow"
98
+ # Lazy import:非交互进程构造 policy 时不引入 prompt_toolkit。
99
+ from .cli.shell.menu import prompt_yes_no
100
+
101
+ return await prompt_yes_no(
102
+ f"允许执行 {summary}?", default_yes=False
103
+ )
104
+
105
+ return _approve
@@ -0,0 +1,19 @@
1
+ """Benchmark facility for mindcode."""
2
+
3
+ from .schema import (
4
+ BenchmarkCase,
5
+ BenchmarkFile,
6
+ BenchmarkResult,
7
+ BenchmarkRunConfig,
8
+ CaseTrace,
9
+ ScoreResult,
10
+ )
11
+
12
+ __all__ = [
13
+ "BenchmarkCase",
14
+ "BenchmarkFile",
15
+ "BenchmarkResult",
16
+ "BenchmarkRunConfig",
17
+ "CaseTrace",
18
+ "ScoreResult",
19
+ ]
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+
3
+ from .base import BenchmarkAdapter
4
+ from .mini_bfcl import MiniBfclAdapter
5
+ from .mini_gaia import MiniGaiaAdapter
6
+ from .mini_terminal import MiniTerminalAdapter
7
+ from .swe_bench import SWEBenchAdapter
8
+ from .terminal_bench import TerminalBenchAdapter
9
+
10
+
11
+ def built_in_adapters() -> dict[str, BenchmarkAdapter]:
12
+ adapters: list[BenchmarkAdapter] = [
13
+ MiniBfclAdapter(),
14
+ MiniTerminalAdapter(),
15
+ MiniGaiaAdapter(),
16
+ SWEBenchAdapter(),
17
+ TerminalBenchAdapter(),
18
+ ]
19
+ return {adapter.suite: adapter for adapter in adapters}
20
+
21
+
22
+ __all__ = ["BenchmarkAdapter", "built_in_adapters"]