aico-cli 0.3.12 → 0.3.14
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.
- package/dist/chunks/simple-config.mjs +1 -1
- package/package.json +1 -1
- package/templates/commands/base//344/272/247/345/223/201/350/256/276/350/256/241/346/231/272/350/203/275/344/275/223.md +106 -0
- package/templates/hooks/README.md +265 -0
- package/templates/hooks/claude-code-hook-config.json +35 -0
- package/templates/hooks/hooks-config.json +47 -0
- package/templates/hooks/requirement/common-utils.sh +186 -0
- package/templates/hooks/requirement/post-requirement-aligner.sh +61 -0
- package/templates/hooks/requirement/post-requirement-identifier.sh +58 -0
- package/templates/hooks/requirement/post-task-executor-validator.sh +96 -0
- package/templates/hooks/requirement/post-task-executor.sh +78 -0
- package/templates/hooks/requirement/post-task-splitter-validator.sh +73 -0
- package/templates/hooks/requirement/pre-requirement-aligner.sh +70 -0
- package/templates/hooks/requirement/pre-requirement-identifier.sh +61 -0
- package/templates/hooks/requirement/pre-task-executor-validator.sh +81 -0
- package/templates/hooks/requirement/pre-task-executor.sh +91 -0
- package/templates/hooks/requirement/pre-task-splitter-validator.sh +61 -0
- package/templates/hooks/requirement-processor.sh +180 -0
- package/templates/personality.md +6 -0
|
@@ -13,7 +13,7 @@ import { join as join$1 } from 'node:path';
|
|
|
13
13
|
import { join, dirname, basename } from 'pathe';
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
15
|
|
|
16
|
-
const version = "0.3.
|
|
16
|
+
const version = "0.3.14";
|
|
17
17
|
|
|
18
18
|
function displayBanner(subtitle) {
|
|
19
19
|
const defaultSubtitle = "\u4E00\u952E\u914D\u7F6E\u4F60\u7684\u5F00\u53D1\u73AF\u5883";
|
package/package.json
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 基于苹果设计哲学的产品界面设计智能体,生成极简、直观、优雅的HTML界面
|
|
3
|
+
allowed-tools: Read(**), Write(.aico/prd/**/*.html), Edit(.aico/prd/**/*.html)
|
|
4
|
+
argument-hint: <产品需求描述>
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 目标
|
|
8
|
+
|
|
9
|
+
基于苹果产品设计哲学,为用户描述的产品需求生成高质量的HTML交互界面:
|
|
10
|
+
|
|
11
|
+
- **极简主义**:去除冗余元素,聚焦核心功能
|
|
12
|
+
- **直观交互**:用户无需学习即可上手
|
|
13
|
+
- **优雅动效**:流畅的过渡和反馈
|
|
14
|
+
- **统一视觉**:一致的色彩、字体和间距
|
|
15
|
+
|
|
16
|
+
## 苹果设计哲学核心原则
|
|
17
|
+
|
|
18
|
+
### 1. 极简主义
|
|
19
|
+
- 去除一切不必要的装饰和元素
|
|
20
|
+
- 聚焦核心功能和用户体验
|
|
21
|
+
- 留白空间的艺术性运用
|
|
22
|
+
|
|
23
|
+
### 2. 直观交互
|
|
24
|
+
- 符合用户心理模型的界面设计
|
|
25
|
+
- 清晰的视觉层次和信息架构
|
|
26
|
+
- 自然的交互流程和反馈机制
|
|
27
|
+
|
|
28
|
+
### 3. 优雅动效
|
|
29
|
+
- 流畅的页面过渡和状态变化
|
|
30
|
+
- 适度的微交互增强用户体验
|
|
31
|
+
- 性能优先的动画实现
|
|
32
|
+
|
|
33
|
+
### 4. 统一视觉
|
|
34
|
+
- 苹果设计系统配色方案
|
|
35
|
+
- 标准化的间距和布局系统
|
|
36
|
+
|
|
37
|
+
## 执行流程
|
|
38
|
+
|
|
39
|
+
**步骤 1**:分析产品需求,识别核心功能和用户场景
|
|
40
|
+
|
|
41
|
+
**步骤 2**:应用苹果设计哲学进行界面设计规划
|
|
42
|
+
- 确定信息架构和导航模式
|
|
43
|
+
- 设计视觉层次和交互流程
|
|
44
|
+
- 选择适合的色彩和字体方案
|
|
45
|
+
|
|
46
|
+
**步骤 3**:生成HTML界面文件
|
|
47
|
+
- 创建符合苹果设计规范的HTML结构
|
|
48
|
+
- 实现响应式布局和优雅动效
|
|
49
|
+
- 确保跨浏览器兼容性
|
|
50
|
+
|
|
51
|
+
**步骤 4**:输出到项目目录的 `.aico/prd/` 目录
|
|
52
|
+
- 按产品模块组织文件结构
|
|
53
|
+
- 提供预览和修改建议
|
|
54
|
+
|
|
55
|
+
## HTML生成规范
|
|
56
|
+
|
|
57
|
+
### 布局系统
|
|
58
|
+
- **网格系统**:12列响应式网格
|
|
59
|
+
- **间距规范**:8px基础单位的间距系统
|
|
60
|
+
- **边距规范**:标准化的页面边距
|
|
61
|
+
|
|
62
|
+
### 组件规范
|
|
63
|
+
- **按钮**:圆角、阴影、悬停效果
|
|
64
|
+
- **表单**:清晰的标签和输入框
|
|
65
|
+
- **导航**:直观的导航模式和指示器
|
|
66
|
+
- **卡片**:阴影和圆角的卡片设计
|
|
67
|
+
|
|
68
|
+
## 输出要求
|
|
69
|
+
|
|
70
|
+
- 在 `.aico/prd/` 目录下生成HTML文件
|
|
71
|
+
- 按产品模块组织文件结构
|
|
72
|
+
- 包含完整的CSS样式和JavaScript交互
|
|
73
|
+
- 提供响应式设计和移动端适配
|
|
74
|
+
- 确保代码质量和可维护性
|
|
75
|
+
|
|
76
|
+
## 示例输出结构
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
.aico/prd/
|
|
80
|
+
├── 产品名称/
|
|
81
|
+
│ ├── index.html # 主界面
|
|
82
|
+
│ ├── components/ # 组件库
|
|
83
|
+
│ │ ├── buttons.html
|
|
84
|
+
│ │ ├── forms.html
|
|
85
|
+
│ │ └── navigation.html
|
|
86
|
+
│ ├── styles/ # 样式文件
|
|
87
|
+
│ │ ├── main.css
|
|
88
|
+
│ │ └── components.css
|
|
89
|
+
│ └── scripts/ # 交互脚本
|
|
90
|
+
│ ├── main.js
|
|
91
|
+
│ └── animations.js
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 质量保证
|
|
95
|
+
|
|
96
|
+
- **设计一致性**:严格遵循苹果设计规范
|
|
97
|
+
- **代码质量**:语义化HTML、模块化CSS、可维护JavaScript
|
|
98
|
+
- **用户体验**:充分的用户测试和反馈收集
|
|
99
|
+
- **性能优化**:快速加载和流畅交互
|
|
100
|
+
|
|
101
|
+
## 扩展性考虑
|
|
102
|
+
|
|
103
|
+
- 支持自定义设计主题
|
|
104
|
+
- 可配置的组件库
|
|
105
|
+
- 模块化的代码结构
|
|
106
|
+
- 易于维护和迭代
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# AICO 需求管理 Hook 系统
|
|
2
|
+
|
|
3
|
+
## 📋 概述
|
|
4
|
+
|
|
5
|
+
将原有的需求管理脚本重构为基于 Hook 触发的模块化系统,支持需求生命周期的全流程自动化处理。
|
|
6
|
+
|
|
7
|
+
## 🏗️ 架构设计
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
templates/hooks/
|
|
11
|
+
├── hooks-config.json # Hook 配置中心
|
|
12
|
+
├── requirement-processor.sh # 🔧 主要使用脚本
|
|
13
|
+
├── requirement/ # Hook 机制
|
|
14
|
+
│ ├── common-utils.sh # 核心工具库
|
|
15
|
+
│ ├── pre-requirement-identifier.sh
|
|
16
|
+
│ ├── post-requirement-identifier.sh
|
|
17
|
+
│ ├── pre-requirement-aligner.sh
|
|
18
|
+
│ ├── post-requirement-aligner.sh
|
|
19
|
+
│ ├── pre-task-splitter-validator.sh
|
|
20
|
+
│ ├── post-task-splitter-validator.sh
|
|
21
|
+
│ ├── pre-task-executor.sh
|
|
22
|
+
│ ├── post-task-executor.sh
|
|
23
|
+
│ ├── pre-task-executor-validator.sh
|
|
24
|
+
│ └── post-task-executor-validator.sh
|
|
25
|
+
└── ../agents/aico/requirement/ # 🎯 原有核心逻辑
|
|
26
|
+
├── crossplatform-utils.sh # 跨平台工具库
|
|
27
|
+
└── requirement-functions-crossplatform.sh # 需求分析算法
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🚀 使用方法
|
|
31
|
+
|
|
32
|
+
### 1. 基本需求处理(推荐)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 处理完整需求生命周期
|
|
36
|
+
./templates/hooks/requirement-processor.sh "需要开发一个用户登录功能"
|
|
37
|
+
|
|
38
|
+
# 查看帮助
|
|
39
|
+
./templates/hooks/requirement-processor.sh --help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. 单独调用 Hook(高级用法)
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 需求识别前置处理
|
|
46
|
+
./templates/hooks/requirement/pre-requirement-identifier.sh "需求描述"
|
|
47
|
+
|
|
48
|
+
# 需求识别后置处理
|
|
49
|
+
./templates/hooks/requirement/post-requirement-identifier.sh "需求描述" "共识文档路径"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. 手动调用原有脚本(兼容性)
|
|
53
|
+
|
|
54
|
+
原有的核心逻辑仍然保留,可以通过以下方式使用:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# 使用原有的跨平台工具库
|
|
58
|
+
source templates/agents/aico/requirement/crossplatform-utils.sh
|
|
59
|
+
|
|
60
|
+
# 使用原有的需求分析函数
|
|
61
|
+
source templates/agents/aico/requirement/requirement-functions-crossplatform.sh
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 📊 脚本用途说明
|
|
65
|
+
|
|
66
|
+
### ✅ 有用的脚本(保留)
|
|
67
|
+
|
|
68
|
+
| 脚本 | 用途 | 是否核心 |
|
|
69
|
+
|------|------|----------|
|
|
70
|
+
| `requirement-processor.sh` | 🎯 **主要使用脚本**,整合所有功能 | ✅ 是 |
|
|
71
|
+
| `common-utils.sh` | Hook 框架核心,日志、状态管理 | ✅ 是 |
|
|
72
|
+
| 10个 `pre/post` hook 脚本 | 生命周期各阶段的前后置处理 | ✅ 是 |
|
|
73
|
+
| `crossplatform-utils.sh` | 跨平台兼容性工具库 | ✅ 是 |
|
|
74
|
+
| `requirement-functions-crossplatform.sh` | 需求分析核心算法 | ✅ 是 |
|
|
75
|
+
| `hooks-config.json` | Hook 配置管理 | ✅ 是 |
|
|
76
|
+
|
|
77
|
+
### ❌ 已删除的脚本(冗余)
|
|
78
|
+
|
|
79
|
+
| 原因 | 删除的脚本 |
|
|
80
|
+
|------|------------|
|
|
81
|
+
| 仅用于开发调试 | 所有 `test-*.sh` 脚本 |
|
|
82
|
+
| 被 Hook 机制替代 | `requirement-launcher.sh` |
|
|
83
|
+
|
|
84
|
+
## 🔄 工作流程
|
|
85
|
+
|
|
86
|
+
### 完整生命周期流程
|
|
87
|
+
|
|
88
|
+
1. **需求识别阶段** (`requirement-identifier`)
|
|
89
|
+
- 前置 Hook: 环境检查、参数验证
|
|
90
|
+
- 核心逻辑: 需求分析、意图识别
|
|
91
|
+
- 后置 Hook: 状态更新、摘要生成
|
|
92
|
+
|
|
93
|
+
2. **需求对齐阶段** (`requirement-aligner`)
|
|
94
|
+
- 前置 Hook: 技术栈分析、依赖检查
|
|
95
|
+
- 核心逻辑: 技术方案设计
|
|
96
|
+
- 后置 Hook: 对齐状态更新
|
|
97
|
+
|
|
98
|
+
3. **任务拆分阶段** (`task-splitter-validator`)
|
|
99
|
+
- 前置 Hook: 任务复杂度分析
|
|
100
|
+
- 核心逻辑: 任务分解、优先级排序
|
|
101
|
+
- 后置 Hook: 拆分摘要生成
|
|
102
|
+
|
|
103
|
+
4. **任务执行阶段** (`task-executor`)
|
|
104
|
+
- 前置 Hook: 执行环境检查
|
|
105
|
+
- 核心逻辑: 代码实现、单元测试
|
|
106
|
+
- 后置 Hook: 执行统计汇总
|
|
107
|
+
|
|
108
|
+
5. **质量验证阶段** (`task-executor-validator`)
|
|
109
|
+
- 前置 Hook: 验证环境准备
|
|
110
|
+
- 核心逻辑: 质量检查、集成测试
|
|
111
|
+
- 后置 Hook: 验证报告生成
|
|
112
|
+
|
|
113
|
+
## 🎯 最佳实践
|
|
114
|
+
|
|
115
|
+
### 推荐使用方式
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# 日常使用 - 一步到位
|
|
119
|
+
./templates/hooks/requirement-processor.sh "功能需求描述"
|
|
120
|
+
|
|
121
|
+
# 开发调试 - 分步执行
|
|
122
|
+
./templates/hooks/requirement/pre-requirement-identifier.sh "需求"
|
|
123
|
+
# ... 检查前置处理结果 ...
|
|
124
|
+
./templates/hooks/requirement/post-requirement-identifier.sh "需求" "文档"
|
|
125
|
+
|
|
126
|
+
# 自定义流程 - 组合使用
|
|
127
|
+
source templates/hooks/requirement/common-utils.sh
|
|
128
|
+
execute_hook "pre" "requirement-identifier" "自定义参数"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 🛠️ 配置管理
|
|
132
|
+
|
|
133
|
+
### 1. 需求管理 Hook 配置
|
|
134
|
+
|
|
135
|
+
编辑 `hooks-config.json` 可以:
|
|
136
|
+
|
|
137
|
+
- 启用/禁用特定 Hook
|
|
138
|
+
- 设置超时时间
|
|
139
|
+
- 配置依赖关系
|
|
140
|
+
- 调整重试策略
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"hooks": {
|
|
145
|
+
"requirement-identifier": {
|
|
146
|
+
"enabled": true,
|
|
147
|
+
"timeout": 30000,
|
|
148
|
+
"dependencies": []
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 2. Claude Code 语音提醒配置
|
|
155
|
+
|
|
156
|
+
语音提醒功能需要在 Claude Code 的 `settings.json` 中配置 Hook。使用 `claude-code-hook-config.json` 作为模板:
|
|
157
|
+
|
|
158
|
+
**部署步骤:**
|
|
159
|
+
|
|
160
|
+
1. **复制配置文件**
|
|
161
|
+
```bash
|
|
162
|
+
# 将模板配置添加到 Claude Code 配置中
|
|
163
|
+
cat templates/hooks/claude-code-hook-config.json >> ~/.claude/settings.json
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
2. **或者手动添加配置**
|
|
167
|
+
在 `~/.claude/settings.json` 的 `hooks` 字段中添加:
|
|
168
|
+
```json
|
|
169
|
+
"hooks": {
|
|
170
|
+
"UserPromptSubmit": [
|
|
171
|
+
{
|
|
172
|
+
"hooks": [
|
|
173
|
+
{
|
|
174
|
+
"type": "command",
|
|
175
|
+
"command": "~/.claude/hooks/notify.sh input"
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"Stop": [
|
|
181
|
+
{
|
|
182
|
+
"hooks": [
|
|
183
|
+
{
|
|
184
|
+
"type": "command",
|
|
185
|
+
"command": "~/.claude/hooks/notify.sh complete"
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"Notification": [
|
|
191
|
+
{
|
|
192
|
+
"hooks": [
|
|
193
|
+
{
|
|
194
|
+
"type": "command",
|
|
195
|
+
"command": "~/.claude/hooks/notify.sh complete"
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**功能说明:**
|
|
204
|
+
|
|
205
|
+
- **UserPromptSubmit**: 当 Claude 需要用户输入时播放提示音
|
|
206
|
+
- **Stop**: 当 Claude 停止工作时播放完成音(退出提醒)
|
|
207
|
+
- **Notification**: 当 Claude 发送通知时播放完成音(任务完成提醒)
|
|
208
|
+
|
|
209
|
+
**验证配置:**
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# 测试语音提醒脚本
|
|
213
|
+
~/.claude/hooks/notify.sh input
|
|
214
|
+
~/.claude/hooks/notify.sh complete
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**重启 Claude Code** 使配置生效。
|
|
218
|
+
|
|
219
|
+
## 🔧 扩展开发
|
|
220
|
+
|
|
221
|
+
### 添加新的 Hook
|
|
222
|
+
|
|
223
|
+
1. 在对应目录创建 `pre-stage-name.sh` 和 `post-stage-name.sh`
|
|
224
|
+
2. 在 `hooks-config.json` 中添加配置
|
|
225
|
+
3. 更新 `requirement-processor.sh` 中的流程调用
|
|
226
|
+
|
|
227
|
+
### 自定义处理逻辑
|
|
228
|
+
|
|
229
|
+
原有脚本的核心逻辑函数可以在 Hook 中直接调用:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
source ../agents/aico/requirement/requirement-functions-crossplatform.sh
|
|
233
|
+
|
|
234
|
+
# 在 Hook 中调用原有函数
|
|
235
|
+
analyze_requirement "$user_input"
|
|
236
|
+
generate_consensus_document
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## ⚠️ 注意事项
|
|
240
|
+
|
|
241
|
+
1. **依赖关系**: Hook 严格按照依赖顺序执行
|
|
242
|
+
2. **状态管理**: 每个 Hook 会更新对应的状态文件
|
|
243
|
+
3. **错误处理**: Hook 失败会中断整个流程
|
|
244
|
+
4. **跨平台**: 保持与原有脚本的跨平台兼容性
|
|
245
|
+
|
|
246
|
+
## 📚 迁移指南
|
|
247
|
+
|
|
248
|
+
如果你之前使用 `requirement-launcher.sh`,现在可以这样迁移:
|
|
249
|
+
|
|
250
|
+
### 旧方式
|
|
251
|
+
```bash
|
|
252
|
+
./templates/agents/aico/requirement/requirement-launcher.sh "需求描述"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 新方式(推荐)
|
|
256
|
+
```bash
|
|
257
|
+
./templates/hooks/requirement-processor.sh "需求描述"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
新方式的优势:
|
|
261
|
+
- ✅ 自动 Hook 触发
|
|
262
|
+
- ✅ 更好的状态管理
|
|
263
|
+
- ✅ 更强的错误处理
|
|
264
|
+
- ✅ 模块化架构
|
|
265
|
+
- ✅ 易于扩展
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"UserPromptSubmit": [
|
|
5
|
+
{
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "~/.claude/hooks/notify.sh input"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"Stop": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "~/.claude/hooks/notify.sh complete"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"Notification": [
|
|
25
|
+
{
|
|
26
|
+
"hooks": [
|
|
27
|
+
{
|
|
28
|
+
"type": "command",
|
|
29
|
+
"command": "~/.claude/hooks/notify.sh complete"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"description": "需求管理生命周期 Hook 配置",
|
|
4
|
+
"hooks": {
|
|
5
|
+
"requirement-identifier": {
|
|
6
|
+
"pre": "requirement/pre-requirement-identifier.sh",
|
|
7
|
+
"post": "requirement/post-requirement-identifier.sh",
|
|
8
|
+
"dependencies": [],
|
|
9
|
+
"timeout": 30000,
|
|
10
|
+
"enabled": true
|
|
11
|
+
},
|
|
12
|
+
"requirement-aligner": {
|
|
13
|
+
"pre": "requirement/pre-requirement-aligner.sh",
|
|
14
|
+
"post": "requirement/post-requirement-aligner.sh",
|
|
15
|
+
"dependencies": ["requirement-identifier"],
|
|
16
|
+
"timeout": 30000,
|
|
17
|
+
"enabled": true
|
|
18
|
+
},
|
|
19
|
+
"task-splitter-validator": {
|
|
20
|
+
"pre": "requirement/pre-task-splitter-validator.sh",
|
|
21
|
+
"post": "requirement/post-task-splitter-validator.sh",
|
|
22
|
+
"dependencies": ["requirement-aligner"],
|
|
23
|
+
"timeout": 30000,
|
|
24
|
+
"enabled": true
|
|
25
|
+
},
|
|
26
|
+
"task-executor": {
|
|
27
|
+
"pre": "requirement/pre-task-executor.sh",
|
|
28
|
+
"post": "requirement/post-task-executor.sh",
|
|
29
|
+
"dependencies": ["task-splitter-validator"],
|
|
30
|
+
"timeout": 60000,
|
|
31
|
+
"enabled": true
|
|
32
|
+
},
|
|
33
|
+
"task-executor-validator": {
|
|
34
|
+
"pre": "requirement/pre-task-executor-validator.sh",
|
|
35
|
+
"post": "requirement/post-task-executor-validator.sh",
|
|
36
|
+
"dependencies": ["task-executor"],
|
|
37
|
+
"timeout": 30000,
|
|
38
|
+
"enabled": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"global": {
|
|
42
|
+
"maxRetries": 3,
|
|
43
|
+
"retryDelay": 1000,
|
|
44
|
+
"logLevel": "info",
|
|
45
|
+
"tempDir": "/tmp/aico-hooks"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 需求管理 Hook 通用工具库
|
|
3
|
+
|
|
4
|
+
# 加载跨平台基础工具
|
|
5
|
+
# 计算相对路径
|
|
6
|
+
HOOKS_DIR="$(dirname "$(dirname "${BASH_SOURCE[0]}")")"
|
|
7
|
+
CROSSPLATFORM_UTILS="$HOOKS_DIR/../agents/aico/requirement/crossplatform-utils.sh"
|
|
8
|
+
|
|
9
|
+
if [ -f "$CROSSPLATFORM_UTILS" ]; then
|
|
10
|
+
source "$CROSSPLATFORM_UTILS"
|
|
11
|
+
else
|
|
12
|
+
echo "⚠️ 跨平台工具库未找到: $CROSSPLATFORM_UTILS"
|
|
13
|
+
# 提供基本的兼容函数
|
|
14
|
+
get_timestamp() { date '+%Y-%m-%d %H:%M:%S'; }
|
|
15
|
+
safe_mkdir() { mkdir -p "$1"; }
|
|
16
|
+
safe_rmdir() { rm -rf "$1" 2>/dev/null || true; }
|
|
17
|
+
get_temp_dir() { echo "/tmp"; }
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
# Hook 日志函数
|
|
21
|
+
hook_log() {
|
|
22
|
+
local level="$1"
|
|
23
|
+
local message="$2"
|
|
24
|
+
local timestamp=$(get_timestamp)
|
|
25
|
+
|
|
26
|
+
case "$level" in
|
|
27
|
+
"INFO") echo "[INFO] $timestamp - $message" ;;
|
|
28
|
+
"WARN") echo "[WARN] $timestamp - $message" >&2 ;;
|
|
29
|
+
"ERROR") echo "[ERROR] $timestamp - $message" >&2 ;;
|
|
30
|
+
"DEBUG") echo "[DEBUG] $timestamp - $message" ;;
|
|
31
|
+
*) echo "[$level] $timestamp - $message" ;;
|
|
32
|
+
esac
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# 检查 Hook 前置条件
|
|
36
|
+
check_hook_prerequisites() {
|
|
37
|
+
local hook_name="$1"
|
|
38
|
+
local config_file="$HOOKS_DIR/hooks-config.json"
|
|
39
|
+
|
|
40
|
+
if [ ! -f "$config_file" ]; then
|
|
41
|
+
hook_log "WARN" "Hook 配置文件不存在: $config_file,跳过配置检查"
|
|
42
|
+
return 0
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# 检查 Hook 是否启用
|
|
46
|
+
if command -v jq >/dev/null 2>&1; then
|
|
47
|
+
local enabled=$(jq -r ".hooks.\"$hook_name\".enabled" "$config_file" 2>/dev/null)
|
|
48
|
+
if [ "$enabled" != "true" ]; then
|
|
49
|
+
hook_log "WARN" "Hook $hook_name 未启用,跳过执行"
|
|
50
|
+
return 2
|
|
51
|
+
fi
|
|
52
|
+
else
|
|
53
|
+
hook_log "DEBUG" "jq 命令不可用,跳过配置检查"
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
return 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# 执行 Hook 脚本
|
|
60
|
+
execute_hook() {
|
|
61
|
+
local hook_type="$1" # pre 或 post
|
|
62
|
+
local hook_name="$2" # hook 名称
|
|
63
|
+
local hook_args="${@:3}" # 额外参数
|
|
64
|
+
|
|
65
|
+
local config_file="$HOOKS_DIR/hooks-config.json"
|
|
66
|
+
local hook_script=""
|
|
67
|
+
|
|
68
|
+
if [ -f "$config_file" ] && command -v jq >/dev/null 2>&1; then
|
|
69
|
+
hook_script=$(jq -r ".hooks.\"$hook_name\".\"$hook_type\"" "$config_file" 2>/dev/null)
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
# 如果没有配置文件或 jq 不可用,使用默认路径
|
|
73
|
+
if [ -z "$hook_script" ] || [ "$hook_script" = "null" ]; then
|
|
74
|
+
hook_script="requirement/$hook_type-$hook_name.sh"
|
|
75
|
+
hook_log "DEBUG" "使用默认 Hook 路径: $hook_script"
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
local full_script_path="$HOOKS_DIR/$hook_script"
|
|
79
|
+
|
|
80
|
+
if [ ! -f "$full_script_path" ]; then
|
|
81
|
+
hook_log "ERROR" "Hook 脚本不存在: $full_script_path"
|
|
82
|
+
return 1
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
if [ ! -x "$full_script_path" ]; then
|
|
86
|
+
set_executable "$full_script_path"
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
hook_log "INFO" "执行 $hook_type hook: $hook_name"
|
|
90
|
+
|
|
91
|
+
# 执行 hook 脚本
|
|
92
|
+
if "$full_script_path" $hook_args; then
|
|
93
|
+
hook_log "INFO" "Hook $hook_name $hook_type 执行成功"
|
|
94
|
+
return 0
|
|
95
|
+
else
|
|
96
|
+
hook_log "ERROR" "Hook $hook_name $hook_type 执行失败"
|
|
97
|
+
return 1
|
|
98
|
+
fi
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# 检查依赖关系
|
|
102
|
+
check_dependencies() {
|
|
103
|
+
local hook_name="$1"
|
|
104
|
+
local config_file="$(dirname "${BASH_SOURCE[0]}")/../../hooks-config.json"
|
|
105
|
+
|
|
106
|
+
local dependencies=$(jq -r ".hooks.\"$hook_name\".dependencies[]" "$config_file" 2>/dev/null)
|
|
107
|
+
|
|
108
|
+
for dep in $dependencies; do
|
|
109
|
+
if [ -n "$dep" ] && [ "$dep" != "null" ]; then
|
|
110
|
+
# 检查依赖的 hook 是否已成功执行
|
|
111
|
+
local dep_status_file="$(get_temp_dir)/aico-hooks/$dep.status"
|
|
112
|
+
if [ ! -f "$dep_status_file" ] || [ "$(cat "$dep_status_file")" != "success" ]; then
|
|
113
|
+
hook_log "ERROR" "依赖的 hook $dep 未成功执行"
|
|
114
|
+
return 1
|
|
115
|
+
fi
|
|
116
|
+
fi
|
|
117
|
+
done
|
|
118
|
+
|
|
119
|
+
return 0
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# 更新 Hook 状态
|
|
123
|
+
update_hook_status() {
|
|
124
|
+
local hook_name="$1"
|
|
125
|
+
local status="$2" # success 或 failed
|
|
126
|
+
|
|
127
|
+
local status_dir="$(get_temp_dir)/aico-hooks"
|
|
128
|
+
safe_mkdir "$status_dir"
|
|
129
|
+
|
|
130
|
+
echo "$status" > "$status_dir/$hook_name.status"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# 获取 Hook 状态
|
|
134
|
+
get_hook_status() {
|
|
135
|
+
local hook_name="$1"
|
|
136
|
+
local status_file="$(get_temp_dir)/aico-hooks/$hook_name.status"
|
|
137
|
+
|
|
138
|
+
if [ -f "$status_file" ]; then
|
|
139
|
+
cat "$status_file"
|
|
140
|
+
else
|
|
141
|
+
echo "unknown"
|
|
142
|
+
fi
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# 清理临时状态
|
|
146
|
+
cleanup_hook_status() {
|
|
147
|
+
local hook_name="$1"
|
|
148
|
+
local status_dir="$(get_temp_dir)/aico-hooks"
|
|
149
|
+
|
|
150
|
+
safe_rm "$status_dir/$hook_name.status"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# 验证需求文档状态
|
|
154
|
+
validate_requirement_status() {
|
|
155
|
+
local requirement_name="$1"
|
|
156
|
+
local expected_status="$2" # 如 "已确认"
|
|
157
|
+
|
|
158
|
+
local doc_dir=".aico/docs/$requirement_name"
|
|
159
|
+
local status_file="$doc_dir/状态"
|
|
160
|
+
|
|
161
|
+
if [ ! -f "$status_file" ]; then
|
|
162
|
+
hook_log "ERROR" "需求状态文件不存在: $status_file"
|
|
163
|
+
return 1
|
|
164
|
+
fi
|
|
165
|
+
|
|
166
|
+
local current_status=$(cat "$status_file")
|
|
167
|
+
if [ "$current_status" != "$expected_status" ]; then
|
|
168
|
+
hook_log "ERROR" "需求状态不匹配。期望: $expected_status, 实际: $current_status"
|
|
169
|
+
return 1
|
|
170
|
+
fi
|
|
171
|
+
|
|
172
|
+
return 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# 初始化 Hook 环境
|
|
176
|
+
init_hook_environment() {
|
|
177
|
+
export AICO_HOOKS_DIR="$(dirname "${BASH_SOURCE[0]}")/../.."
|
|
178
|
+
export AICO_HOOKS_TEMP_DIR="$(get_temp_dir)/aico-hooks"
|
|
179
|
+
|
|
180
|
+
safe_mkdir "$AICO_HOOKS_TEMP_DIR"
|
|
181
|
+
|
|
182
|
+
# 设置日志级别
|
|
183
|
+
if [ -z "$AICO_HOOKS_LOG_LEVEL" ]; then
|
|
184
|
+
export AICO_HOOKS_LOG_LEVEL="info"
|
|
185
|
+
fi
|
|
186
|
+
}
|