aico-cli 0.2.2 → 0.2.5

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.
@@ -0,0 +1,219 @@
1
+ # 🌐 跨平台兼容性指南
2
+
3
+ ## 支持的操作系统
4
+
5
+ ### ✅ 完全支持
6
+ - **Windows 10/11** (通过以下环境)
7
+ - Git Bash (推荐)
8
+ - Cygwin
9
+ - WSL (Windows Subsystem for Linux)
10
+ - MSYS2
11
+
12
+ - **macOS** (10.15+)
13
+ - 原生终端
14
+ - iTerm2
15
+ - 任何兼容的终端环境
16
+
17
+ - **Linux** (主流发行版)
18
+ - Ubuntu/Debian
19
+ - CentOS/RHEL
20
+ - Fedora
21
+ - Arch Linux
22
+ - 其他基于 GNU/Linux 的系统
23
+
24
+ ## 🛠️ 环境要求
25
+
26
+ ### 基本依赖
27
+ 所有平台都需要以下基本工具:
28
+ - `bash` (版本 4.0+)
29
+ - `coreutils` (包含基本 Unix 命令)
30
+ - `grep`
31
+ - `sed`
32
+ - `head`/`tail`
33
+ - `mkdir`/`cat`/`echo`
34
+
35
+ ### Windows 特定设置
36
+
37
+ #### 选项1: Git for Windows (推荐)
38
+ ```bash
39
+ # 1. 下载安装 Git for Windows
40
+ # https://git-scm.com/download/win
41
+
42
+ # 2. 启动 Git Bash
43
+ # 3. 导航到脚本目录
44
+ cd /c/path/to/your/project
45
+
46
+ # 4. 运行脚本
47
+ ./requirement-launcher.sh "您的需求"
48
+ ```
49
+
50
+ #### 选项2: WSL (Windows Subsystem for Linux)
51
+ ```bash
52
+ # 1. 启用 WSL
53
+ wsl --install
54
+
55
+ # 2. 安装 Ubuntu
56
+ wsl --install -d Ubuntu
57
+
58
+ # 3. 启动 WSL
59
+ wsl
60
+
61
+ # 4. 安装必要工具
62
+ sudo apt update && sudo apt install git bash
63
+
64
+ # 5. 运行脚本
65
+ ./requirement-launcher.sh "您的需求"
66
+ ```
67
+
68
+ #### 选项3: Cygwin
69
+ ```bash
70
+ # 1. 安装 Cygwin
71
+ # https://www.cygwin.com/
72
+
73
+ # 2. 确保安装以下包:
74
+ # - bash
75
+ # - coreutils
76
+ # - grep
77
+ # - sed
78
+
79
+ # 3. 运行脚本
80
+ ./requirement-launcher.sh "您的需求"
81
+ ```
82
+
83
+ ### macOS 设置
84
+ ```bash
85
+ # 确保已安装 Xcode Command Line Tools
86
+ xcode-select --install
87
+
88
+ # 或者使用 Homebrew 安装最新工具
89
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
90
+ brew install coreutils
91
+
92
+ # 运行脚本
93
+ ./requirement-launcher.sh "您的需求"
94
+ ```
95
+
96
+ ### Linux 设置
97
+ ```bash
98
+ # Ubuntu/Debian
99
+ sudo apt update && sudo apt install bash coreutils
100
+
101
+ # CentOS/RHEL
102
+ sudo yum install bash coreutils
103
+
104
+ # Fedora
105
+ sudo dnf install bash coreutils
106
+
107
+ # 运行脚本
108
+ ./requirement-launcher.sh "您的需求"
109
+ ```
110
+
111
+ ## 📁 文件结构
112
+
113
+ ```
114
+ agents/aico/requirement/
115
+ ├── requirement-functions-crossplatform.sh # 跨平台主函数库
116
+ ├── requirement-launcher.sh # 跨平台启动器
117
+ ├── requirement-functions.sh # 原版函数库 (Unix only)
118
+ ├── PLATFORM_COMPATIBILITY.md # 本文件
119
+ └── *.md # 其他文档文件
120
+ ```
121
+
122
+ ## 🔧 技术实现细节
123
+
124
+ ### 平台检测
125
+ 脚本会自动检测运行环境:
126
+ - `Darwin` → macOS
127
+ - `Linux` → Linux
128
+ - `CYGWIN*|MINGW*|MSYS*` → Windows
129
+
130
+ ### 路径处理
131
+ - **Windows**: 自动处理路径分隔符 (`/` → `\\`)
132
+ - **临时目录**: 使用平台适当的临时目录
133
+ - **家目录**: 自动识别 Windows (`%USERPROFILE%`) 和 Unix (`$HOME`)
134
+
135
+ ### 命令兼容性
136
+ - 使用 `command -v` 代替 `which`
137
+ - 提供命令回退机制
138
+ - 统一的错误处理
139
+
140
+ ## 🚀 快速开始
141
+
142
+ ### 所有平台通用命令
143
+ ```bash
144
+ # 1. 确保脚本有执行权限
145
+ chmod +x requirement-launcher.sh
146
+ chmod +x requirement-functions-crossplatform.sh
147
+
148
+ # 2. 运行需求识别
149
+ ./requirement-launcher.sh "需要开发用户登录功能"
150
+
151
+ # 3. 或者直接使用函数库
152
+ source requirement-functions-crossplatform.sh
153
+ main_workflow "需要修复页面加载性能问题"
154
+ ```
155
+
156
+ ### Windows 特定示例
157
+ ```bash
158
+ # 在 Git Bash 中:
159
+ cd /c/Users/YourName/project
160
+ ./requirement-launcher.sh "创建新的API接口"
161
+
162
+ # 在 PowerShell 中启动 Git Bash:
163
+ Start-Process "C:\\Program Files\\Git\\git-bash.exe" -ArgumentList "-c", "cd /c/path/to/project && ./requirement-launcher.sh '您的需求'"
164
+ ```
165
+
166
+ ## 🧪 测试验证
167
+
168
+ ### 基本功能测试
169
+ ```bash
170
+ # 测试平台检测
171
+ ./requirement-launcher.sh "测试平台兼容性"
172
+
173
+ # 测试需求分析
174
+ ./requirement-launcher.sh "需要添加数据导出功能"
175
+
176
+ # 测试文档生成
177
+ ./requirement-launcher.sh "创建用户管理模块"
178
+ ```
179
+
180
+ ### 跨平台一致性验证
181
+ 确保在所有平台上产生相同的结果:
182
+ - 相同的需求识别结果
183
+ - 相同的文档输出格式
184
+ - 相同的状态管理行为
185
+
186
+ ## ⚠️ 已知限制
187
+
188
+ 1. **Windows 原生 CMD/PowerShell**: 不支持,必须使用兼容环境
189
+ 2. **非常旧的系统**: 可能需要手动安装更新版本的 bash
190
+ 3. **特殊字符处理**: 某些特殊字符在不同 shell 中可能有不同行为
191
+ 4. **文件权限**: Windows 和 Unix 文件权限模型不同
192
+
193
+ ## 🔄 更新和维护
194
+
195
+ ### 添加新平台支持
196
+ 1. 在 `detect_platform()` 中添加新的平台检测
197
+ 2. 在相应的平台分支中添加特殊处理逻辑
198
+ 3. 更新测试用例
199
+ 4. 更新本文档
200
+
201
+ ### 维护跨平台兼容性
202
+ - 避免使用平台特定的命令
203
+ - 使用 POSIX 兼容的语法
204
+ - 提供适当的回退机制
205
+ - 定期在不同平台上测试
206
+
207
+ ## 📞 技术支持
208
+
209
+ 如果遇到平台兼容性问题:
210
+
211
+ 1. 检查 `detect_platform` 函数的输出
212
+ 2. 验证基本依赖是否安装
213
+ 3. 查看具体的错误信息
214
+ 4. 参考对应平台的设置指南
215
+
216
+ ---
217
+
218
+ **最后更新**: $(date '+%Y-%m-%d')
219
+ **兼容性状态**: ✅ 生产环境就绪
@@ -0,0 +1,307 @@
1
+ #!/usr/bin/env bash
2
+ # 跨平台工具库 - 支持 Windows/Linux/macOS
3
+ # 为所有智能体脚本提供统一的跨平台功能
4
+
5
+ # 平台检测函数
6
+ detect_platform() {
7
+ case "$(uname -s)" in
8
+ Darwin)
9
+ PLATFORM="macos"
10
+ ;;
11
+ Linux)
12
+ PLATFORM="linux"
13
+ ;;
14
+ CYGWIN*|MINGW*|MSYS*)
15
+ PLATFORM="windows"
16
+ ;;
17
+ *)
18
+ PLATFORM="unknown"
19
+ ;;
20
+ esac
21
+ echo "🌐 检测到平台: $PLATFORM"
22
+ }
23
+
24
+ # 跨平台临时目录
25
+ get_temp_dir() {
26
+ case "$PLATFORM" in
27
+ windows)
28
+ # Windows: 使用用户临时目录
29
+ if [ -n "$TEMP" ]; then
30
+ echo "$TEMP"
31
+ elif [ -n "$TMP" ]; then
32
+ echo "$TMP"
33
+ else
34
+ echo "/tmp"
35
+ fi
36
+ ;;
37
+ *)
38
+ # Linux/macOS: 使用标准临时目录
39
+ echo "/tmp"
40
+ ;;
41
+ esac
42
+ }
43
+
44
+ # 跨平台文件路径处理
45
+ normalize_path() {
46
+ local path="$1"
47
+ case "$PLATFORM" in
48
+ windows)
49
+ # 将路径转换为 Windows 兼容格式
50
+ echo "$path" | sed 's|/|\\|g'
51
+ ;;
52
+ *)
53
+ echo "$path"
54
+ ;;
55
+ esac
56
+ }
57
+
58
+ # 跨平台家目录
59
+ get_home_dir() {
60
+ case "$PLATFORM" in
61
+ windows)
62
+ echo "$USERPROFILE"
63
+ ;;
64
+ *)
65
+ echo "$HOME"
66
+ ;;
67
+ esac
68
+ }
69
+
70
+ # 跨平台命令检查
71
+ command_exists() {
72
+ command -v "$1" >/dev/null 2>&1
73
+ }
74
+
75
+ # 跨平台文件查找
76
+ find_files() {
77
+ local pattern="$1"
78
+ local max_results="${2:-10}"
79
+
80
+ # 使用兼容的 find 命令
81
+ if command_exists "find"; then
82
+ find . -name "$pattern" 2>/dev/null | head -n "$max_results"
83
+ else
84
+ # Windows 回退方案
85
+ ls -la "$pattern" 2>/dev/null | head -n "$max_results"
86
+ fi
87
+ }
88
+
89
+ # 跨平台文件读取
90
+ safe_read_file() {
91
+ local file_path="$1"
92
+ local max_lines="${2:-50}"
93
+
94
+ if [ -f "$file_path" ]; then
95
+ # 使用兼容的读取方式
96
+ if command_exists "head"; then
97
+ head -n "$max_lines" "$file_path" 2>/dev/null
98
+ else
99
+ # Windows 回退方案
100
+ sed -n "1,${max_lines}p" "$file_path" 2>/dev/null
101
+ fi
102
+ else
103
+ echo "文件不存在: $file_path"
104
+ fi
105
+ }
106
+
107
+ # 跨平台包管理器检测
108
+ detect_package_manager() {
109
+ if command_exists "npm"; then
110
+ echo "npm"
111
+ elif command_exists "yarn"; then
112
+ echo "yarn"
113
+ elif command_exists "pnpm"; then
114
+ echo "pnpm"
115
+ elif command_exists "pip"; then
116
+ echo "pip"
117
+ elif command_exists "cargo"; then
118
+ echo "cargo"
119
+ else
120
+ echo "unknown"
121
+ fi
122
+ }
123
+
124
+ # 跨平台 Git 命令
125
+ git_safe() {
126
+ if command_exists "git"; then
127
+ git "$@" 2>/dev/null
128
+ else
129
+ echo "Git 未安装"
130
+ fi
131
+ }
132
+
133
+ # 跨平台目录创建
134
+ safe_mkdir() {
135
+ local dir_path="$1"
136
+
137
+ if command_exists "mkdir"; then
138
+ mkdir -p "$dir_path" 2>/dev/null
139
+ else
140
+ # Windows 回退方案
141
+ md "$dir_path" 2>/dev/null
142
+ fi
143
+ }
144
+
145
+ # 跨平台文件复制
146
+ safe_cp() {
147
+ local source="$1"
148
+ local destination="$2"
149
+
150
+ if command_exists "cp"; then
151
+ cp "$source" "$destination" 2>/dev/null
152
+ else
153
+ # Windows 回退方案
154
+ copy "$source" "$destination" 2>/dev/null
155
+ fi
156
+ }
157
+
158
+ # 跨平台文件移动
159
+ safe_mv() {
160
+ local source="$1"
161
+ local destination="$2"
162
+
163
+ if command_exists "mv"; then
164
+ mv "$source" "$destination" 2>/dev/null
165
+ else
166
+ # Windows 回退方案
167
+ move "$source" "$destination" 2>/dev/null
168
+ fi
169
+ }
170
+
171
+ # 跨平台文件删除
172
+ safe_rm() {
173
+ local file_path="$1"
174
+
175
+ if command_exists "rm"; then
176
+ rm -f "$file_path" 2>/dev/null
177
+ else
178
+ # Windows 回退方案
179
+ del "$file_path" 2>/dev/null
180
+ fi
181
+ }
182
+
183
+ # 跨平台目录删除
184
+ safe_rmdir() {
185
+ local dir_path="$1"
186
+
187
+ if command_exists "rm"; then
188
+ rm -rf "$dir_path" 2>/dev/null
189
+ else
190
+ # Windows 回退方案
191
+ rmdir /s /q "$dir_path" 2>/dev/null
192
+ fi
193
+ }
194
+
195
+ # 跨平台环境变量设置
196
+ set_env() {
197
+ local var_name="$1"
198
+ local var_value="$2"
199
+
200
+ case "$PLATFORM" in
201
+ windows)
202
+ set "$var_name=$var_value"
203
+ ;;
204
+ *)
205
+ export "$var_name=$var_value"
206
+ ;;
207
+ esac
208
+ }
209
+
210
+ # 跨平台脚本执行
211
+ execute_script() {
212
+ local script_path="$1"
213
+
214
+ if [ -f "$script_path" ]; then
215
+ if command_exists "bash"; then
216
+ bash "$script_path"
217
+ else
218
+ # Windows 回退方案
219
+ cmd /c "$script_path"
220
+ fi
221
+ else
222
+ echo "脚本文件不存在: $script_path"
223
+ fi
224
+ }
225
+
226
+ # 跨平台进程检查
227
+ check_process() {
228
+ local process_name="$1"
229
+
230
+ case "$PLATFORM" in
231
+ windows)
232
+ tasklist | grep -i "$process_name" >/dev/null 2>&1
233
+ ;;
234
+ *)
235
+ ps aux | grep -v "grep" | grep -i "$process_name" >/dev/null 2>&1
236
+ ;;
237
+ esac
238
+ }
239
+
240
+ # 跨平台端口检查
241
+ check_port() {
242
+ local port="$1"
243
+
244
+ case "$PLATFORM" in
245
+ windows)
246
+ netstat -ano | grep ":$port " >/dev/null 2>&1
247
+ ;;
248
+ *)
249
+ lsof -i ":$port" >/dev/null 2>&1
250
+ ;;
251
+ esac
252
+ }
253
+
254
+ # 跨平台网络请求
255
+ safe_curl() {
256
+ if command_exists "curl"; then
257
+ curl "$@" 2>/dev/null
258
+ elif command_exists "wget"; then
259
+ wget -q -O - "$@" 2>/dev/null
260
+ else
261
+ echo "网络工具未安装"
262
+ fi
263
+ }
264
+
265
+ # 跨平台日期时间
266
+ get_timestamp() {
267
+ case "$PLATFORM" in
268
+ windows)
269
+ date "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "$(date +'%Y-%m-%d %H:%M:%S')"
270
+ ;;
271
+ *)
272
+ date '+%Y-%m-%d %H:%M:%S'
273
+ ;;
274
+ esac
275
+ }
276
+
277
+ # 跨平台文件权限设置
278
+ set_executable() {
279
+ local file_path="$1"
280
+
281
+ case "$PLATFORM" in
282
+ windows)
283
+ # Windows 不需要设置执行权限
284
+ :
285
+ ;;
286
+ *)
287
+ chmod +x "$file_path" 2>/dev/null
288
+ ;;
289
+ esac
290
+ }
291
+
292
+ # 跨平台路径分隔符
293
+ get_path_separator() {
294
+ case "$PLATFORM" in
295
+ windows)
296
+ echo ";"
297
+ ;;
298
+ *)
299
+ echo ":"
300
+ ;;
301
+ esac
302
+ }
303
+
304
+ # 初始化平台检测
305
+ detect_platform
306
+
307
+ echo "✅ 跨平台工具库已加载 (支持 Windows/Linux/macOS)"