deep-agent-cli 0.2.0__tar.gz → 0.2.2__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 (142) hide show
  1. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/PKG-INFO +17 -14
  2. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/README.md +10 -7
  3. deep_agent_cli-0.2.2/agent/__init__.py +38 -0
  4. deep_agent_cli-0.2.2/agent/bootstrap/__init__.py +1 -0
  5. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/bootstrap}/config.py +34 -166
  6. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/bootstrap}/factory.py +130 -19
  7. deep_agent_cli-0.2.0/agent/bootstrap.py → deep_agent_cli-0.2.2/agent/bootstrap/setup.py +2 -1
  8. deep_agent_cli-0.2.2/agent/cli/__init__.py +9 -0
  9. deep_agent_cli-0.2.2/agent/cli/access_selection.py +351 -0
  10. deep_agent_cli-0.2.2/agent/cli/app.py +1299 -0
  11. deep_agent_cli-0.2.2/agent/cli/attachments_controller.py +176 -0
  12. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/clipboard.py +1 -0
  13. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/commands.py +9 -8
  14. deep_agent_cli-0.2.2/agent/cli/completion.py +99 -0
  15. deep_agent_cli-0.2.2/agent/cli/context_compaction.py +79 -0
  16. deep_agent_cli-0.2.2/agent/cli/display.py +43 -0
  17. deep_agent_cli-0.2.2/agent/cli/formatting.py +73 -0
  18. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/gitinfo.py +5 -3
  19. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/input_actions.py +8 -3
  20. deep_agent_cli-0.2.2/agent/cli/interaction_flow.py +209 -0
  21. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/interactions.py +4 -3
  22. deep_agent_cli-0.2.2/agent/cli/key_bindings.py +238 -0
  23. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/lifecycle.py +49 -20
  24. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/main.py +31 -11
  25. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/mcp_controller.py +1 -0
  26. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/mcp_ui.py +18 -16
  27. deep_agent_cli-0.2.2/agent/cli/model_selection.py +249 -0
  28. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/pasted_content.py +1 -0
  29. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/previews.py +21 -3
  30. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/rendering.py +191 -94
  31. deep_agent_cli-0.2.2/agent/cli/run_dispatch.py +266 -0
  32. deep_agent_cli-0.2.2/agent/cli/run_events_controller.py +131 -0
  33. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/session_controller.py +102 -71
  34. deep_agent_cli-0.2.2/agent/cli/session_summaries.py +88 -0
  35. deep_agent_cli-0.2.2/agent/cli/skill_selection.py +98 -0
  36. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/skills.py +3 -1
  37. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/state.py +35 -12
  38. deep_agent_cli-0.2.2/agent/cli/transcript_navigation.py +264 -0
  39. deep_agent_cli-0.2.2/agent/cli/view_state.py +35 -0
  40. deep_agent_cli-0.2.2/agent/cli/widgets.py +180 -0
  41. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/working_messages.py +0 -1
  42. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/config.example.yaml +41 -24
  43. deep_agent_cli-0.2.2/agent/execution/__init__.py +1 -0
  44. deep_agent_cli-0.2.2/agent/execution/backend.py +245 -0
  45. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/execution}/environment.py +6 -4
  46. deep_agent_cli-0.2.2/agent/execution/filesystem.py +922 -0
  47. deep_agent_cli-0.2.2/agent/execution/layout.py +489 -0
  48. deep_agent_cli-0.2.0/agent/sandbox_mounts.py → deep_agent_cli-0.2.2/agent/execution/mounts.py +5 -11
  49. deep_agent_cli-0.2.0/agent/file_mutation.py → deep_agent_cli-0.2.2/agent/execution/mutations.py +2 -0
  50. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/execution}/network.py +2 -0
  51. deep_agent_cli-0.2.2/agent/execution/policy.py +83 -0
  52. deep_agent_cli-0.2.0/agent/sandbox_pool.py → deep_agent_cli-0.2.2/agent/execution/pool.py +4 -2
  53. deep_agent_cli-0.2.2/agent/execution/ports.py +12 -0
  54. deep_agent_cli-0.2.2/agent/execution/process.py +455 -0
  55. deep_agent_cli-0.2.2/agent/execution/types.py +22 -0
  56. deep_agent_cli-0.2.2/agent/mcp/__init__.py +13 -0
  57. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/adapter.py +13 -4
  58. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/bridge.py +1 -0
  59. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/config.py +1 -0
  60. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/content.py +1 -0
  61. deep_agent_cli-0.2.2/agent/mcp/contracts.py +20 -0
  62. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/logging.py +1 -0
  63. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/manager.py +2 -18
  64. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/middleware.py +2 -0
  65. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/names.py +2 -0
  66. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/oauth.py +2 -1
  67. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/oauth_storage.py +3 -2
  68. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/mcp/tools.py +2 -0
  69. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/attachments.py +4 -2
  70. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/cancel_tools.py +2 -1
  71. deep_agent_cli-0.2.2/agent/middleware/current_time.py +34 -0
  72. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/pause.py +3 -2
  73. deep_agent_cli-0.2.2/agent/middleware/payload_recovery.py +109 -0
  74. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/recovery.py +2 -26
  75. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/runtime_config.py +1 -0
  76. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/steering.py +8 -2
  77. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/tool_arg_hints.py +2 -1
  78. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/usage.py +1 -0
  79. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/workspace_filesystem.py +27 -1
  80. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/write_operation.py +2 -1
  81. deep_agent_cli-0.2.2/agent/models/__init__.py +1 -0
  82. deep_agent_cli-0.2.2/agent/models/catalog.py +30 -0
  83. deep_agent_cli-0.2.0/agent/llm.py → deep_agent_cli-0.2.2/agent/models/client.py +12 -10
  84. deep_agent_cli-0.2.0/agent/http_environment.py → deep_agent_cli-0.2.2/agent/models/http.py +2 -0
  85. deep_agent_cli-0.2.0/agent/stream.py → deep_agent_cli-0.2.2/agent/models/messages.py +35 -10
  86. deep_agent_cli-0.2.2/agent/models/profile.py +62 -0
  87. deep_agent_cli-0.2.2/agent/models/session_summary.py +47 -0
  88. deep_agent_cli-0.2.0/agent/llm_stream.py → deep_agent_cli-0.2.2/agent/models/stream_lifecycle.py +12 -1
  89. deep_agent_cli-0.2.2/agent/runtime/__init__.py +1 -0
  90. deep_agent_cli-0.2.0/agent/cancel.py → deep_agent_cli-0.2.2/agent/runtime/cancellation.py +1 -0
  91. deep_agent_cli-0.2.2/agent/runtime/configuration.py +68 -0
  92. deep_agent_cli-0.2.2/agent/runtime/contracts.py +74 -0
  93. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/runtime}/control.py +31 -1
  94. deep_agent_cli-0.2.0/agent/run_events.py → deep_agent_cli-0.2.2/agent/runtime/events.py +14 -73
  95. deep_agent_cli-0.2.2/agent/runtime/graph_execution.py +75 -0
  96. deep_agent_cli-0.2.2/agent/runtime/metrics.py +244 -0
  97. deep_agent_cli-0.2.0/agent/permission.py → deep_agent_cli-0.2.2/agent/runtime/permissions.py +2 -1
  98. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/runtime}/runner.py +211 -286
  99. deep_agent_cli-0.2.2/agent/sessions/__init__.py +1 -0
  100. {deep_agent_cli-0.2.0/agent → deep_agent_cli-0.2.2/agent/sessions}/attachments.py +11 -143
  101. deep_agent_cli-0.2.2/agent/sessions/contracts.py +59 -0
  102. deep_agent_cli-0.2.2/agent/sessions/images.py +160 -0
  103. deep_agent_cli-0.2.0/agent/session_runtime.py → deep_agent_cli-0.2.2/agent/sessions/lifecycle.py +20 -23
  104. deep_agent_cli-0.2.0/agent/session_lock.py → deep_agent_cli-0.2.2/agent/sessions/locks.py +2 -0
  105. deep_agent_cli-0.2.2/agent/sessions/ports.py +36 -0
  106. deep_agent_cli-0.2.2/agent/sessions/reader.py +42 -0
  107. deep_agent_cli-0.2.2/agent/sessions/recovery.py +31 -0
  108. deep_agent_cli-0.2.2/agent/sessions/snapshots.py +38 -0
  109. deep_agent_cli-0.2.0/agent/session.py → deep_agent_cli-0.2.2/agent/sessions/store.py +36 -167
  110. deep_agent_cli-0.2.2/agent/sessions/summary.py +91 -0
  111. deep_agent_cli-0.2.2/agent/sessions/transcript.py +126 -0
  112. deep_agent_cli-0.2.2/agent/subagents/__init__.py +1 -0
  113. deep_agent_cli-0.2.2/agent/subagents/configuration.py +38 -0
  114. deep_agent_cli-0.2.2/agent/subagents/log_store.py +92 -0
  115. deep_agent_cli-0.2.2/agent/subagents/manager.py +51 -0
  116. deep_agent_cli-0.2.2/agent/subagents/runtime.py +213 -0
  117. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/examples.py +2 -1
  118. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/execute.py +4 -1
  119. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/grep.py +7 -3
  120. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/human_input.py +10 -16
  121. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/human_interaction.py +3 -1
  122. deep_agent_cli-0.2.2/agent/tools/subagent_logs.py +21 -0
  123. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/web_search.py +3 -2
  124. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/version.py +1 -0
  125. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/pyproject.toml +7 -7
  126. deep_agent_cli-0.2.2//347/273/210/347/253/257.png +0 -0
  127. deep_agent_cli-0.2.0/agent/__init__.py +0 -42
  128. deep_agent_cli-0.2.0/agent/cli/__init__.py +0 -5
  129. deep_agent_cli-0.2.0/agent/cli/app.py +0 -2965
  130. deep_agent_cli-0.2.0/agent/mcp/__init__.py +0 -4
  131. deep_agent_cli-0.2.0/agent/performance.py +0 -118
  132. deep_agent_cli-0.2.0/agent/sandbox.py +0 -2029
  133. deep_agent_cli-0.2.0//347/273/210/347/253/257.png +0 -0
  134. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/.gitignore +0 -0
  135. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/LICENSE +0 -0
  136. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/input.py +0 -0
  137. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/cli/working_messages.yaml +0 -0
  138. /deep_agent_cli-0.2.0/agent/sandbox_worker.py → /deep_agent_cli-0.2.2/agent/execution/worker.py +0 -0
  139. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/middleware/__init__.py +0 -0
  140. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/__init__.py +0 -0
  141. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/agent/tools/_grep_worker.py +0 -0
  142. {deep_agent_cli-0.2.0 → deep_agent_cli-0.2.2}/assets/readme/runtime-map.svg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deep-agent-cli
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A sandboxed coding agent CLI for Linux and WSL2
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -11,13 +11,13 @@ Classifier: Programming Language :: Python :: 3.13
11
11
  Classifier: Topic :: Software Development
12
12
  Requires-Python: >=3.12
13
13
  Requires-Dist: cryptography<51,>=43
14
- Requires-Dist: deepagents<0.8.0,>=0.7.17
14
+ Requires-Dist: deepagents<0.8.0,>=0.7.35
15
15
  Requires-Dist: httpx[socks]<1,>=0.27
16
- Requires-Dist: langchain-core<2.0,>=1.0
17
- Requires-Dist: langchain-openai<1.7.0,>=1.6.2
18
- Requires-Dist: langchain[mcp]<2.0,>=1.4.2
19
- Requires-Dist: langgraph-checkpoint-sqlite<4,>=3.1.1
20
- Requires-Dist: langgraph<2.0,>=1.0
16
+ Requires-Dist: langchain-core<2.0,>=1.7.7
17
+ Requires-Dist: langchain-openai<1.8.0,>=1.7.4
18
+ Requires-Dist: langchain[mcp]<2.0,>=1.4.9
19
+ Requires-Dist: langgraph-checkpoint-sqlite<4,>=3.1.3
20
+ Requires-Dist: langgraph<2.0,>=1.2.20
21
21
  Requires-Dist: prompt-toolkit<4.0,>=3.0.48
22
22
  Requires-Dist: py-key-value-aio[filetree]<0.5,>=0.4.4
23
23
  Requires-Dist: pyyaml<7.0,>=6.0
@@ -46,20 +46,21 @@ OpenAI 兼容接口 · Bubblewrap
46
46
  <img src="终端.png" width="760" alt="deep-agent 真实终端空闲界面,底栏显示工作区、模型来源、SANDBOXED 和 perm:ask。">
47
47
  </p>
48
48
 
49
- `deep-agent` 是基于 [Deep Agents](https://github.com/langchain-ai/deepagents) 和 LangGraph 的终端 Coding Agent。它在当前项目中工作,默认在文件变更、命令执行和网页搜索前请求批准,通过 [Bubblewrap](https://github.com/containers/bubblewrap) 隔离命令执行。
49
+ `deep-agent` 是基于 [Deep Agents](https://github.com/langchain-ai/deepagents) 和 LangGraph 的终端 Coding Agent。它在当前项目中工作,主 Agent 默认在文件变更、命令执行和网页搜索前请求批准,通过 [Bubblewrap](https://github.com/containers/bubblewrap) 隔离命令执行。
50
50
 
51
51
  在项目目录运行 `deep-agent` 进入交互式终端,用 `deep-agent resume` 恢复已有会话。要在其他 Python 程序里复用同一套运行核心,使用 [Python API](docs/library.md)。
52
52
 
53
- > 当前版本 **0.2.0**,处于早期开发阶段。稳定版前,配置、会话存储格式和 Python API 可能出现不兼容变更。
53
+ > 当前版本 **0.2.2**,处于早期开发阶段。稳定版前,配置、会话存储格式和 Python API 可能出现不兼容变更。
54
54
 
55
55
  ## 能做什么
56
56
 
57
57
  - **查代码、改文件** — 浏览、读取、正则搜索、编辑和删除;`Ctrl+R` 审阅完整改动,`F2` 处理审批。
58
58
  - **运行项目命令** — 实时查看输出,会话内复用持久沙箱;默认审批、隔离直接 IP 网络。
59
59
  - **随时介入任务** — 追加指令、排队后续任务、暂停、取消,以及结构化人工输入。
60
+ - **拆分独立任务** — 仅当问题能分解为多个独立、互不干扰的子问题时派生 SubAgent;默认最多并行 2 个,主 Agent 同步等待最终结果。TUI 为每个子任务显示独立卡片、状态及可展开的完整返回结果,内部思考和工具输出保持隔离。
60
61
  - **保留工作上下文** — SQLite 会话恢复、模型与推理强度切换、上下文压缩;支持图片输入的模型可接收附件。
61
62
 
62
- 支持通过 Skills 和 `AGENTS.md` 扩展项目指令。
63
+ 支持通过 Skills 和 `AGENTS.md` 扩展项目指令。SubAgent 配置、独立思考强度及日志查询见 [SubAgent 委派](docs/configuration.md#subagent-委派)。
63
64
 
64
65
  ## 快速开始
65
66
 
@@ -146,7 +147,7 @@ llm:
146
147
  <summary>恢复会话、升级与虚拟环境安装</summary>
147
148
 
148
149
  ```bash
149
- deep-agent resume # 选择已保存的会话
150
+ deep-agent resume # 按中文摘要选择会话,无摘要时显示 ID
150
151
  deep-agent resume 01a08aae # 换成已有会话的 ID 或前缀
151
152
  pipx upgrade deep-agent-cli
152
153
  ```
@@ -199,6 +200,8 @@ SQLite 保存会话状态。模型工具表不包含 `grep` 和 `glob`。代码
199
200
  | **沙箱 + `ask`**(默认) | 文件变更、命令、网页搜索、MCP 调用及增删服务需批准 | 默认隔离直接 IP 网络;`network=true` 获批后共享宿主网络 |
200
201
  | 沙箱 + `allow` | 所有工具免审批,包括 MCP 工具、`mcp_add`、`mcp_remove` | 所有 execute 共享宿主网络 |
201
202
 
203
+ SubAgent 共享已验证的沙箱 Backend 和 Pool,使用独立的 `allow` 权限,即使主 Agent 处于 `ask` 也不弹出子任务审批;子 Agent 不装载 MCP、人工输入或递归委派工具。其默认思考强度使用子模型原生默认,不继承主 Agent 的强度。
204
+
202
205
  只读文件工具免审批;`/permission` 统一控制原生与 MCP 工具审批,`allow` 仅限沙箱模式。MCP 在宿主进程中运行,不经过 Bubblewrap,也不受沙箱网络策略限制。配置在 `~/.deep-agent/mcp.json`,根级 `enabled` 是全局开关(默认开启);用 `/mcp`、`/mcp enable`、`/mcp disable` 或 `mcp_add` / `mcp_remove` 管理。全局关闭时不连接、不启动 stdio、不打开 OAuth,也不把 MCP 工具交给模型;配置和令牌缓存仍保留。**工作区内的 `.env`、`.git` 同样可访问,取消不回滚已发生的副作用。**
203
206
 
204
207
  全局开关打开时,启动会自动连接各服务里 `enabled: true` 的项。OAuth 优先使用加密缓存并刷新令牌,无法刷新时打开浏览器授权;无需鉴权的服务直接连接。`/mcp` 先显示 `MCP: Enabled` 或 `MCP: Disabled`,开启时再列出 `服务名 状态 N tools`;`connected` 为绿色,其余状态为红色。连接恢复、附件处理和后台日志见 [MCP 配置](docs/configuration.md#mcpmcpjson),命令和状态说明见 [TUI 文档](docs/tui.md#mcp-服务)。
@@ -206,10 +209,10 @@ SQLite 保存会话状态。模型工具表不包含 `grep` 和 `glob`。代码
206
209
  <details>
207
210
  <summary>更多边界与当前限制</summary>
208
211
 
209
- - **网络与进程**:无网命名空间不阻断通过共享 Unix socket、FIFO 或文件实现的间接通信。有网实例可访问互联网、localhost 和局域网;切回 `ask` 不停止此前的后台进程。会话切换及关闭时清理沙箱。
212
+ - **网络与进程**:无网命名空间不阻断通过共享 Unix socket、FIFO 或文件实现的间接通信。有网实例可访问互联网、localhost 和局域网;切回 `ask` 不停止此前的后台进程。模型与会话切换复用 Pool,关闭 Runner 或更换文件系统模式时清理沙箱。
210
213
  - **挂载与资源**:用户可通过现有挂载列表扩大或缩小文件系统可见范围,审批逻辑保持独立。只读挂载仍允许读取其中的敏感文件。没有 CPU、内存、磁盘或进程数硬配额。Skills、`AGENTS.md` 和提示词不是操作系统安全边界。
211
- - **本地状态**:同一会话只允许一个进程持有;工作区可能产生 `.deep-agent/` 命令日志和 `.deepagents/` 压缩历史,程序不修改 `.gitignore`。
212
- - **客户端**:模型、MCP、Tavily 和子进程统一使用全局 [`trust_env`](docs/configuration.md#全局网络环境trust_env) 配置,默认忽略代理与 CA 环境变量;剪贴板图片仅支持 WSL,其他环境通过文件添加。MCP 支持 Streamable HTTP 和 stdio 工具调用及工具返回的内嵌资源;不提供独立 Resources / Prompts 接口、Sampling 回调、旧式服务端 Elicitation、MCP Apps UI 或子 Agent。
214
+ - **本地状态**:SubAgent 执行摘要独立保存在受保护配置目录的 `subagents/` 下,仅记录任务起止、工具状态和有界最终结果,不保存模型 Token、思考或原始工具输出,只精确替换已知模型及 Tavily Key;同一会话只允许一个进程持有;工作区可能产生 `.deep-agent/` 命令日志和 `.deepagents/` 压缩历史,程序不修改 `.gitignore`。
215
+ - **客户端**:模型、MCP、Tavily 和子进程统一使用全局 [`trust_env`](docs/configuration.md#全局网络环境trust_env) 配置,默认忽略代理与 CA 环境变量;剪贴板图片仅支持 WSL,其他环境通过文件添加。MCP 支持 Streamable HTTP 和 stdio 工具调用及工具返回的内嵌资源;不提供独立 Resources / Prompts 接口、Sampling 回调、旧式服务端 Elicitation、MCP Apps UI。MCP 工具仅向主 Agent 提供。
213
216
 
214
217
  完整隔离范围与环境变量见 [沙箱与权限](docs/sandbox.md)。
215
218
 
@@ -15,20 +15,21 @@ OpenAI 兼容接口 · Bubblewrap
15
15
  <img src="终端.png" width="760" alt="deep-agent 真实终端空闲界面,底栏显示工作区、模型来源、SANDBOXED 和 perm:ask。">
16
16
  </p>
17
17
 
18
- `deep-agent` 是基于 [Deep Agents](https://github.com/langchain-ai/deepagents) 和 LangGraph 的终端 Coding Agent。它在当前项目中工作,默认在文件变更、命令执行和网页搜索前请求批准,通过 [Bubblewrap](https://github.com/containers/bubblewrap) 隔离命令执行。
18
+ `deep-agent` 是基于 [Deep Agents](https://github.com/langchain-ai/deepagents) 和 LangGraph 的终端 Coding Agent。它在当前项目中工作,主 Agent 默认在文件变更、命令执行和网页搜索前请求批准,通过 [Bubblewrap](https://github.com/containers/bubblewrap) 隔离命令执行。
19
19
 
20
20
  在项目目录运行 `deep-agent` 进入交互式终端,用 `deep-agent resume` 恢复已有会话。要在其他 Python 程序里复用同一套运行核心,使用 [Python API](docs/library.md)。
21
21
 
22
- > 当前版本 **0.2.0**,处于早期开发阶段。稳定版前,配置、会话存储格式和 Python API 可能出现不兼容变更。
22
+ > 当前版本 **0.2.2**,处于早期开发阶段。稳定版前,配置、会话存储格式和 Python API 可能出现不兼容变更。
23
23
 
24
24
  ## 能做什么
25
25
 
26
26
  - **查代码、改文件** — 浏览、读取、正则搜索、编辑和删除;`Ctrl+R` 审阅完整改动,`F2` 处理审批。
27
27
  - **运行项目命令** — 实时查看输出,会话内复用持久沙箱;默认审批、隔离直接 IP 网络。
28
28
  - **随时介入任务** — 追加指令、排队后续任务、暂停、取消,以及结构化人工输入。
29
+ - **拆分独立任务** — 仅当问题能分解为多个独立、互不干扰的子问题时派生 SubAgent;默认最多并行 2 个,主 Agent 同步等待最终结果。TUI 为每个子任务显示独立卡片、状态及可展开的完整返回结果,内部思考和工具输出保持隔离。
29
30
  - **保留工作上下文** — SQLite 会话恢复、模型与推理强度切换、上下文压缩;支持图片输入的模型可接收附件。
30
31
 
31
- 支持通过 Skills 和 `AGENTS.md` 扩展项目指令。
32
+ 支持通过 Skills 和 `AGENTS.md` 扩展项目指令。SubAgent 配置、独立思考强度及日志查询见 [SubAgent 委派](docs/configuration.md#subagent-委派)。
32
33
 
33
34
  ## 快速开始
34
35
 
@@ -115,7 +116,7 @@ llm:
115
116
  <summary>恢复会话、升级与虚拟环境安装</summary>
116
117
 
117
118
  ```bash
118
- deep-agent resume # 选择已保存的会话
119
+ deep-agent resume # 按中文摘要选择会话,无摘要时显示 ID
119
120
  deep-agent resume 01a08aae # 换成已有会话的 ID 或前缀
120
121
  pipx upgrade deep-agent-cli
121
122
  ```
@@ -168,6 +169,8 @@ SQLite 保存会话状态。模型工具表不包含 `grep` 和 `glob`。代码
168
169
  | **沙箱 + `ask`**(默认) | 文件变更、命令、网页搜索、MCP 调用及增删服务需批准 | 默认隔离直接 IP 网络;`network=true` 获批后共享宿主网络 |
169
170
  | 沙箱 + `allow` | 所有工具免审批,包括 MCP 工具、`mcp_add`、`mcp_remove` | 所有 execute 共享宿主网络 |
170
171
 
172
+ SubAgent 共享已验证的沙箱 Backend 和 Pool,使用独立的 `allow` 权限,即使主 Agent 处于 `ask` 也不弹出子任务审批;子 Agent 不装载 MCP、人工输入或递归委派工具。其默认思考强度使用子模型原生默认,不继承主 Agent 的强度。
173
+
171
174
  只读文件工具免审批;`/permission` 统一控制原生与 MCP 工具审批,`allow` 仅限沙箱模式。MCP 在宿主进程中运行,不经过 Bubblewrap,也不受沙箱网络策略限制。配置在 `~/.deep-agent/mcp.json`,根级 `enabled` 是全局开关(默认开启);用 `/mcp`、`/mcp enable`、`/mcp disable` 或 `mcp_add` / `mcp_remove` 管理。全局关闭时不连接、不启动 stdio、不打开 OAuth,也不把 MCP 工具交给模型;配置和令牌缓存仍保留。**工作区内的 `.env`、`.git` 同样可访问,取消不回滚已发生的副作用。**
172
175
 
173
176
  全局开关打开时,启动会自动连接各服务里 `enabled: true` 的项。OAuth 优先使用加密缓存并刷新令牌,无法刷新时打开浏览器授权;无需鉴权的服务直接连接。`/mcp` 先显示 `MCP: Enabled` 或 `MCP: Disabled`,开启时再列出 `服务名 状态 N tools`;`connected` 为绿色,其余状态为红色。连接恢复、附件处理和后台日志见 [MCP 配置](docs/configuration.md#mcpmcpjson),命令和状态说明见 [TUI 文档](docs/tui.md#mcp-服务)。
@@ -175,10 +178,10 @@ SQLite 保存会话状态。模型工具表不包含 `grep` 和 `glob`。代码
175
178
  <details>
176
179
  <summary>更多边界与当前限制</summary>
177
180
 
178
- - **网络与进程**:无网命名空间不阻断通过共享 Unix socket、FIFO 或文件实现的间接通信。有网实例可访问互联网、localhost 和局域网;切回 `ask` 不停止此前的后台进程。会话切换及关闭时清理沙箱。
181
+ - **网络与进程**:无网命名空间不阻断通过共享 Unix socket、FIFO 或文件实现的间接通信。有网实例可访问互联网、localhost 和局域网;切回 `ask` 不停止此前的后台进程。模型与会话切换复用 Pool,关闭 Runner 或更换文件系统模式时清理沙箱。
179
182
  - **挂载与资源**:用户可通过现有挂载列表扩大或缩小文件系统可见范围,审批逻辑保持独立。只读挂载仍允许读取其中的敏感文件。没有 CPU、内存、磁盘或进程数硬配额。Skills、`AGENTS.md` 和提示词不是操作系统安全边界。
180
- - **本地状态**:同一会话只允许一个进程持有;工作区可能产生 `.deep-agent/` 命令日志和 `.deepagents/` 压缩历史,程序不修改 `.gitignore`。
181
- - **客户端**:模型、MCP、Tavily 和子进程统一使用全局 [`trust_env`](docs/configuration.md#全局网络环境trust_env) 配置,默认忽略代理与 CA 环境变量;剪贴板图片仅支持 WSL,其他环境通过文件添加。MCP 支持 Streamable HTTP 和 stdio 工具调用及工具返回的内嵌资源;不提供独立 Resources / Prompts 接口、Sampling 回调、旧式服务端 Elicitation、MCP Apps UI 或子 Agent。
183
+ - **本地状态**:SubAgent 执行摘要独立保存在受保护配置目录的 `subagents/` 下,仅记录任务起止、工具状态和有界最终结果,不保存模型 Token、思考或原始工具输出,只精确替换已知模型及 Tavily Key;同一会话只允许一个进程持有;工作区可能产生 `.deep-agent/` 命令日志和 `.deepagents/` 压缩历史,程序不修改 `.gitignore`。
184
+ - **客户端**:模型、MCP、Tavily 和子进程统一使用全局 [`trust_env`](docs/configuration.md#全局网络环境trust_env) 配置,默认忽略代理与 CA 环境变量;剪贴板图片仅支持 WSL,其他环境通过文件添加。MCP 支持 Streamable HTTP 和 stdio 工具调用及工具返回的内嵌资源;不提供独立 Resources / Prompts 接口、Sampling 回调、旧式服务端 Elicitation、MCP Apps UI。MCP 工具仅向主 Agent 提供。
182
185
 
183
186
  完整隔离范围与环境变量见 [沙箱与权限](docs/sandbox.md)。
184
187
 
@@ -0,0 +1,38 @@
1
+ """Public application API with lazy adapter loading."""
2
+ from importlib import import_module
3
+
4
+ _EXPORTS = {
5
+ 'ModelProfile': ('agent.models.profile', 'ModelProfile'),
6
+ 'BindMount': ('agent.execution.policy', 'BindMount'),
7
+ 'SandboxConfig': ('agent.execution.policy', 'SandboxConfig'),
8
+ 'RunController': ('agent.runtime.control', 'RunController'),
9
+ 'AgentSpec': ('agent.bootstrap.factory', 'AgentSpec'),
10
+ 'PreparedAgent': ('agent.bootstrap.factory', 'PreparedAgent'),
11
+ 'build_agent': ('agent.bootstrap.factory', 'build_agent'),
12
+ 'create_agent': ('agent.bootstrap.factory', 'create_agent'),
13
+ 'PermissionMode': ('agent.runtime.permissions', 'PermissionMode'),
14
+ 'AgentRunner': ('agent.runtime.runner', 'AgentRunner'),
15
+ 'InterruptKind': ('agent.runtime.contracts', 'InterruptKind'),
16
+ 'InterruptState': ('agent.runtime.contracts', 'InterruptState'),
17
+ 'RunEvent': ('agent.runtime.contracts', 'RunEvent'),
18
+ 'RunResult': ('agent.runtime.contracts', 'RunResult'),
19
+ 'UnknownInterruptError': ('agent.runtime.contracts', 'UnknownInterruptError'),
20
+ 'ExecutionMode': ('agent.execution.types', 'ExecutionMode'),
21
+ 'SandboxUnavailableError': ('agent.execution.types', 'SandboxUnavailableError'),
22
+ 'ImageAttachment': ('agent.sessions.images', 'ImageAttachment'),
23
+ 'ImageAttachmentRef': ('agent.sessions.images', 'ImageAttachmentRef'),
24
+ 'SessionStore': ('agent.sessions.store', 'SessionStore'),
25
+ 'SessionInfo': ('agent.sessions.contracts', 'SessionInfo'),
26
+ 'StopReason': ('agent.sessions.contracts', 'StopReason'),
27
+ 'StreamDeltaCallback': ('agent.models.messages', 'StreamDeltaCallback'),
28
+ }
29
+ __all__ = list(_EXPORTS)
30
+
31
+
32
+ def __getattr__(name: str):
33
+ if name not in _EXPORTS:
34
+ raise AttributeError(name)
35
+ module, symbol = _EXPORTS[name]
36
+ value = getattr(import_module(module), symbol)
37
+ globals()[name] = value
38
+ return value
@@ -0,0 +1 @@
1
+ """Bootstrap bounded context."""
@@ -4,117 +4,34 @@ from dataclasses import dataclass, field, replace
4
4
  import os
5
5
  import re
6
6
  from pathlib import Path
7
- from typing import Any, Literal, Mapping
7
+ from typing import Any, Mapping
8
8
  from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
9
-
10
9
  import yaml
11
10
 
12
- SAFE_INHERITED_ENV = (
13
- "LANG",
14
- "TERM",
15
- "COLORTERM",
16
- "NO_COLOR",
17
- "TZ",
11
+ from agent.execution.policy import BindMount, SandboxMode, parse_sandbox_mode, SandboxConfig
12
+ from agent.subagents.configuration import SubAgentConfig
13
+ from agent.cli.display import UiDisplayLimits, DEFAULT_UI_TIMEZONE
14
+ from agent.execution.policy import default_skills_dir
15
+ from agent.models.profile import DEFAULT_REQUEST_TIMEOUT
16
+ from agent.models.catalog import ModelCatalog
17
+ from agent.models.profile import (
18
+ InputKind,
19
+ ModelProfile,
20
+ _model_max_retries,
21
+ _model_stream_chunk_timeout,
18
22
  )
19
23
 
24
+
20
25
  _DEFAULT_CONFIG_NAME = "config.yaml"
21
- DEFAULT_UI_TIMEZONE = "Asia/Shanghai"
22
- DEFAULT_STREAM_CHUNK_TIMEOUT = 120.0
23
- DEFAULT_REQUEST_TIMEOUT = 60.0
24
26
 
25
27
 
26
28
  class ConfigError(ValueError):
27
29
  """A user configuration error safe to display without a traceback."""
28
30
 
29
31
 
30
- def default_skills_dir() -> Path:
31
- return Path.home() / ".deep-agent" / "skills"
32
-
33
-
34
- @dataclass(frozen=True)
35
- class BindMount:
36
- """An explicit host-to-sandbox mount.
37
-
38
- ``modes`` is ``None`` when the mount applies in both filesystem modes.
39
- That is the historical behavior for entries that omit the field.
40
- """
41
-
42
- source: Path
43
- destination: str
44
- optional: bool = False
45
- dev_bind: bool = False
46
- modes: tuple["SandboxMode", ...] | None = None
47
-
48
-
49
- @dataclass(frozen=True)
50
- class ModelProfile:
51
- """Named OpenAI-compatible chat model profile."""
52
-
53
- id: str
54
- model: str
55
- api_key: str = "sk-local"
56
- base_url: str = "http://localhost:8000/v1"
57
- input: tuple["InputKind", ...] = ("text",)
58
- api: Literal["responses", "chat_completions"] = "responses"
59
- # 0 = unknown, so the UI can hide the context meter instead of guessing.
60
- context_window: int = 0
61
- source: str = ""
62
- reasoning_efforts: tuple[str, ...] = ()
63
- max_retries: int = 5
64
- stream_chunk_timeout: float = DEFAULT_STREAM_CHUNK_TIMEOUT
65
-
66
- def __post_init__(self) -> None:
67
- object.__setattr__(self, "max_retries", _model_max_retries(self.max_retries, field_name="max_retries"))
68
- object.__setattr__(
69
- self, "stream_chunk_timeout",
70
- _model_stream_chunk_timeout(self.stream_chunk_timeout, field_name="stream_chunk_timeout"),
71
- )
72
-
73
- def supports_input(self, kind: "InputKind") -> bool:
74
- return kind in self.input
75
-
76
-
77
- InputKind = Literal["text", "image"]
78
32
  _INPUT_KINDS = frozenset({"text", "image"})
79
33
 
80
34
 
81
- SandboxMode = Literal["restricted", "full-access"]
82
- _SANDBOX_MODES = frozenset({"restricted", "full-access"})
83
-
84
-
85
- def parse_sandbox_mode(value: str) -> SandboxMode | None:
86
- key = value.strip().lower()
87
- if key == "restricted":
88
- return "restricted"
89
- if key == "full-access":
90
- return "full-access"
91
- return None
92
-
93
-
94
- @dataclass(frozen=True)
95
- class SandboxConfig:
96
- """Bubblewrap policy. ``restricted`` is the default filesystem boundary."""
97
-
98
- workspace: Path = field(default_factory=Path.cwd)
99
- bwrap_path: str = "bwrap"
100
- mode: SandboxMode = "restricted"
101
- timeout_seconds: int | None = None
102
- max_output_bytes: int = 100_000
103
- env_allowlist: tuple[str, ...] = ()
104
- env_set: dict[str, str] = field(default_factory=dict)
105
- extra_read_only_mounts: tuple[BindMount, ...] = ()
106
- extra_read_write_mounts: tuple[BindMount, ...] = ()
107
- protected_config_dir: Path | None = None
108
- protected_files: tuple[Path, ...] = ()
109
- trust_env: bool = False
110
-
111
- def __post_init__(self) -> None:
112
- if self.mode not in _SANDBOX_MODES:
113
- raise ValueError(
114
- f"sandbox.mode must be restricted or full-access, got {self.mode!r}"
115
- )
116
-
117
-
118
35
  def _default_profiles() -> tuple[ModelProfile, ...]:
119
36
  return (
120
37
  ModelProfile(
@@ -126,44 +43,11 @@ def _default_profiles() -> tuple[ModelProfile, ...]:
126
43
  )
127
44
 
128
45
 
129
- @dataclass(frozen=True)
130
- class UiDisplayLimits:
131
- """Content folding limits, loaded from the main configuration's ui section."""
132
-
133
- head_lines: int = 4
134
- tail_lines: int = 4
135
- explore_preview_items: int = 5
136
- explore_failure_items: int = 3
137
- create_preview_items: int = 5
138
- editor_max_lines: int = 10
139
- completion_menu_lines: int = 8
140
-
141
- def __post_init__(self) -> None:
142
- for name in self.__dataclass_fields__:
143
- value = getattr(self, name)
144
- if isinstance(value, bool) or not isinstance(value, int) or value < 1:
145
- raise ValueError(f"ui.{name} must be a positive integer")
146
-
147
- @classmethod
148
- def from_mapping(cls, ui: Mapping[str, Any]) -> "UiDisplayLimits":
149
- removed = (
150
- "thinking_tail_lines", "execute_tail_lines", "tool_tail_lines", "expanded_tool_lines",
151
- "edit_preview_changed_lines", "write_preview_lines", "failure_preview_lines",
152
- "command_failure_tail_lines",
153
- )
154
- obsolete = [name for name in removed if name in ui]
155
- if obsolete:
156
- raise ValueError(f"Removed ui settings: {', '.join(obsolete)}; use ui.head_lines and ui.tail_lines")
157
- return cls(**{name: ui[name] for name in cls.__dataclass_fields__ if name in ui})
158
-
159
-
160
- DEFAULT_UI_DISPLAY_LIMITS = UiDisplayLimits()
161
-
162
-
163
46
  @dataclass(frozen=True)
164
47
  class Settings:
165
48
  llm_profiles: tuple[ModelProfile, ...] = field(default_factory=_default_profiles)
166
49
  llm_default: str = "default"
50
+ subagents: SubAgentConfig = field(default_factory=SubAgentConfig)
167
51
  sandbox: SandboxConfig = field(default_factory=SandboxConfig)
168
52
  state_path: Path | None = None
169
53
  config_dir: Path | None = None
@@ -175,10 +59,23 @@ class Settings:
175
59
  tavily_api_key: str | None = field(default=None, repr=False)
176
60
  trust_env: bool = False
177
61
  request_timeout: float = DEFAULT_REQUEST_TIMEOUT
62
+ compaction_threshold: float = 0.85
178
63
 
179
64
  def __post_init__(self) -> None:
65
+ if (isinstance(self.compaction_threshold, bool)
66
+ or not isinstance(self.compaction_threshold, (int, float))
67
+ or not 0 < self.compaction_threshold <= 1):
68
+ raise ValueError("agent.compaction_threshold must be a number greater than 0 and at most 1")
180
69
  if not isinstance(self.trust_env, bool):
181
70
  raise ValueError("trust_env must be a boolean")
71
+ profile = self.active_profile
72
+ if self.subagents.model is not None:
73
+ profile = next((p for p in self.llm_profiles if p.id == self.subagents.model), None)
74
+ if profile is None:
75
+ raise ValueError(f"Unknown subagents.model: {self.subagents.model}")
76
+ effort = self.subagents.reasoning_effort
77
+ if effort != "default" and effort not in profile.reasoning_efforts:
78
+ raise ValueError(f"Unsupported subagents.reasoning_effort for {profile.id}: {effort}")
182
79
  object.__setattr__(self, "sandbox", replace(self.sandbox, trust_env=self.trust_env))
183
80
  object.__setattr__(
184
81
  self, "request_timeout",
@@ -201,20 +98,12 @@ class Settings:
201
98
  def active_profile(self) -> ModelProfile:
202
99
  return self.get_profile(self.llm_default)
203
100
 
101
+ @property
102
+ def model_catalog(self) -> ModelCatalog:
103
+ return ModelCatalog(self.llm_profiles, self.llm_default)
104
+
204
105
  def get_profile(self, id_or_prefix: str) -> ModelProfile:
205
- key = id_or_prefix.strip()
206
- if not key:
207
- raise KeyError("model id is empty")
208
- exact = next((item for item in self.llm_profiles if item.id == key), None)
209
- if exact is not None:
210
- return exact
211
- matches = [item for item in self.llm_profiles if item.id.startswith(key)]
212
- if len(matches) == 1:
213
- return matches[0]
214
- if not matches:
215
- raise KeyError(f"Unknown model: {id_or_prefix}")
216
- ids = ", ".join(item.id for item in matches)
217
- raise KeyError(f"Ambiguous model prefix {id_or_prefix!r}: {ids}")
106
+ return self.model_catalog.get_profile(id_or_prefix)
218
107
 
219
108
  def list_profiles(self) -> tuple[ModelProfile, ...]:
220
109
  return self.llm_profiles
@@ -299,6 +188,7 @@ class Settings:
299
188
  result = cls(
300
189
  trust_env=trust_env,
301
190
  hidden_tools=tuple(dict.fromkeys(name.strip() for name in hidden_tools)),
191
+ subagents=SubAgentConfig.from_mapping(_section(raw, "subagents")),
302
192
  llm_profiles=profiles,
303
193
  llm_default=default_id,
304
194
  sandbox=_sandbox_from_mapping(sandbox_raw, base_dir=root),
@@ -306,6 +196,7 @@ class Settings:
306
196
  config_dir=_optional_path(paths.get("config_dir"), base_dir=root),
307
197
  source_path=source_path.resolve() if source_path is not None else None,
308
198
  agent_instructions=instructions,
199
+ compaction_threshold=agent.get("compaction_threshold", 0.85),
309
200
  ui_timezone=timezone_name,
310
201
  ui_display_limits=display_limits,
311
202
  tavily_api_key=os.environ.get("TAVILY_API_KEY") or _optional_secret(
@@ -735,29 +626,6 @@ def _sandbox_from_mapping(data: Mapping[str, Any], *, base_dir: Path) -> Sandbox
735
626
  )
736
627
 
737
628
 
738
- def _model_max_retries(value: Any, *, field_name: str) -> int:
739
- if value is None:
740
- return 5
741
- if type(value) is not int or value < 0:
742
- raise ValueError(f"{field_name} must be a non-negative integer")
743
- return value
744
-
745
-
746
- def _model_stream_chunk_timeout(value: Any, *, field_name: str) -> float:
747
- """Seconds without a parsed stream chunk before the current model request retries.
748
-
749
- ``0`` disables the idle timeout. ``None`` keeps the 120 second default.
750
- """
751
- if value is None:
752
- return DEFAULT_STREAM_CHUNK_TIMEOUT
753
- if isinstance(value, bool) or not isinstance(value, (int, float)):
754
- raise ValueError(f"{field_name} must be a non-negative number of seconds")
755
- number = float(value)
756
- if not (number >= 0 and number < float("inf")):
757
- raise ValueError(f"{field_name} must be a non-negative number of seconds")
758
- return number
759
-
760
-
761
629
  def _model_request_timeout(value: Any, *, field_name: str) -> float:
762
630
  """Shared HTTP wait for the first response bytes. ``None`` keeps 60 seconds."""
763
631
  if value is None: