|
| 1 | +# 配置本地 Shell 和 Python 执行默认目录 Spec |
| 2 | + |
| 3 | +## Why |
| 4 | + |
| 5 | +目前本地 shell 和 python 执行时的工作目录是硬编码的,用户无法自定义默认工作目录。需要在 `computer_use_runtime=local` 时支持通过配置指定默认的 shell 和 python 运行目录,提升灵活性和可用性。 |
| 6 | + |
| 7 | +## What Changes |
| 8 | + |
| 9 | +- 新增配置项 `computer_use_local_shell_cwd` 用于指定本地 shell 执行默认目录 |
| 10 | +- 新增配置项 `computer_use_local_python_cwd` 用于指定本地 python 执行默认目录 |
| 11 | +- 当 `computer_use_runtime=local` 时生效 |
| 12 | +- 如果未配置,则默认使用 astrbot 根目录 |
| 13 | +- WebUI 中添加相应的配置描述 |
| 14 | +- 支持多语言配置描述 |
| 15 | + |
| 16 | +## Impact |
| 17 | + |
| 18 | +- Affected specs: 本地计算机执行能力 |
| 19 | +- Affected code: |
| 20 | + - `astrbot/core/computer/booters/local.py` |
| 21 | + - `astrbot/core/computer/tools/shell.py` |
| 22 | + - `astrbot/core/computer/tools/python.py` |
| 23 | + - `astrbot/core/config/default.py` (WebUI配置) |
| 24 | + - 配置模块和配置加载逻辑 |
| 25 | + |
| 26 | +## ADDED Requirements |
| 27 | + |
| 28 | +### Requirement: 本地 Shell 默认工作目录配置 |
| 29 | + |
| 30 | +系统 SHALL 支持在配置中指定本地 shell 执行的默认工作目录 |
| 31 | + |
| 32 | +#### Scenario: 配置自定义目录 |
| 33 | + |
| 34 | +- **WHEN** 用户设置 `computer_use_local_shell_cwd` 配置项且 `computer_use_runtime=local` |
| 35 | +- **THEN** 本地 shell 执行时使用配置的目录作为默认工作目录 |
| 36 | + |
| 37 | +#### Scenario: 使用默认目录 |
| 38 | + |
| 39 | +- **WHEN** 用户未设置 `computer_use_local_shell_cwd` 配置项 |
| 40 | +- **THEN** 本地 shell 执行时使用 astrbot 根目录作为默认工作目录 |
| 41 | + |
| 42 | +### Requirement: 本地 Python 默认工作目录配置 |
| 43 | + |
| 44 | +系统 SHALL 支持在配置中指定本地 python 执行的默认工作目录 |
| 45 | + |
| 46 | +#### Scenario: 配置自定义目录 |
| 47 | + |
| 48 | +- **WHEN** 用户设置 `computer_use_local_python_cwd` 配置项且 `computer_use_runtime=local` |
| 49 | +- **THEN** 本地 python 执行时使用配置的目录作为默认工作目录 |
| 50 | + |
| 51 | +#### Scenario: 使用默认目录 |
| 52 | + |
| 53 | +- **WHEN** 用户未设置 `computer_use_local_python_cwd` 配置项 |
| 54 | +- **THEN** 本地 python 执行时使用 astrbot 根目录作为默认工作目录 |
| 55 | + |
| 56 | +### Requirement: WebUI 配置界面 |
| 57 | + |
| 58 | +系统 SHALL 在 WebUI 中提供配置项的描述和说明 |
| 59 | + |
| 60 | +#### Scenario: 显示配置项 |
| 61 | + |
| 62 | +- **WHEN** 用户在 WebUI 中打开 Agent Computer Use 配置 |
| 63 | +- **THEN** 应显示 `computer_use_local_shell_cwd` 和 `computer_use_local_python_cwd` 配置项 |
| 64 | +- **AND** 配置项应仅在 `computer_use_runtime=local` 时可见 |
| 65 | + |
| 66 | +#### Scenario: 配置项描述 |
| 67 | + |
| 68 | +- **WHEN** 用户查看配置项描述 |
| 69 | +- **THEN** 应显示中文、英文等多种语言的描述 |
| 70 | +- **AND** 应提供适当的 hint 说明配置的用途和限制 |
| 71 | + |
| 72 | +### Requirement: 多语言配置描述 |
| 73 | + |
| 74 | +系统 SHALL 支持配置项的多语言描述 |
| 75 | + |
| 76 | +#### Scenario: 中文描述 |
| 77 | + |
| 78 | +- **WHEN** 用户使用中文界面 |
| 79 | +- **THEN** 配置项应显示中文名称和中文描述 |
| 80 | + |
| 81 | +#### Scenario: 英文描述 |
| 82 | + |
| 83 | +- **WHEN** 用户使用英文界面 |
| 84 | +- **THEN** 配置项应显示英文名称和英文描述 |
| 85 | + |
| 86 | +## MODIFIED Requirements |
| 87 | + |
| 88 | +### Requirement: LocalShellComponent.exec 工作目录逻辑 |
| 89 | + |
| 90 | +**Original**: 工作目录默认为 `get_astrbot_root()` |
| 91 | +**Modified**: 工作目录默认为配置值或 `get_astrbot_root()` |
| 92 | + |
| 93 | +### Requirement: LocalPythonComponent.exec 工作目录逻辑 |
| 94 | + |
| 95 | +**Original**: 使用 subprocess 默认工作目录(进程启动目录) |
| 96 | +**Modified**: 支持通过配置指定工作目录,默认使用 astrbot 根目录 |
| 97 | + |
| 98 | +## REMOVED Requirements |
| 99 | + |
| 100 | +无 |
| 101 | + |
| 102 | +## 配置项说明 |
| 103 | + |
| 104 | +### 运行时配置 (provider_settings) |
| 105 | + |
| 106 | +```json |
| 107 | +{ |
| 108 | + "provider_settings": { |
| 109 | + "computer_use_runtime": "local", |
| 110 | + "computer_use_local_shell_cwd": "/custom/shell/path", |
| 111 | + "computer_use_local_python_cwd": "/custom/python/path" |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +### WebUI 配置项 (default.py) |
| 117 | + |
| 118 | +```python |
| 119 | +"provider_settings.computer_use_local_shell_cwd": { |
| 120 | + "description": "本地 Shell 默认工作目录", |
| 121 | + "type": "string", |
| 122 | + "hint": "设置本地 shell 命令执行时的默认工作目录。仅在 computer_use_runtime=local 时生效。", |
| 123 | + "condition": { |
| 124 | + "provider_settings.computer_use_runtime": "local", |
| 125 | + }, |
| 126 | +}, |
| 127 | + |
| 128 | +"provider_settings.computer_use_local_python_cwd": { |
| 129 | + "description": "本地 Python 默认工作目录", |
| 130 | + "type": "string", |
| 131 | + "hint": "设置本地 Python 代码执行时的默认工作目录。仅在 computer_use_runtime=local 时生效。", |
| 132 | + "condition": { |
| 133 | + "provider_settings.computer_use_runtime": "local", |
| 134 | + }, |
| 135 | +}, |
| 136 | +``` |
| 137 | + |
| 138 | +### 多语言配置 |
| 139 | + |
| 140 | +需要在 default.py 中实现多语言配置支持,参考现有配置项的结构: |
| 141 | + |
| 142 | +- 中文 (zh): "本地 Shell 默认工作目录" |
| 143 | +- 英文 (en): "Local Shell Default Working Directory" |
| 144 | +- 其他语言根据系统支持情况 |
| 145 | + |
| 146 | +## 安全考虑 |
| 147 | + |
| 148 | +- 自定义路径仍然需要通过 `_ensure_safe_path` 进行安全检查 |
| 149 | +- 只能访问 astrbot 根目录、数据目录和临时目录 |
0 commit comments