@wnlen/agent-execution-template 0.8.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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +440 -0
  3. package/README.zh-CN.md +447 -0
  4. package/bin/agent-execution-template.js +792 -0
  5. package/docs/SPEC.md +1039 -0
  6. package/docs/token-efficient-protocol-v0.1.md +101 -0
  7. package/package.json +35 -0
  8. package/template/en/ai/README.md +130 -0
  9. package/template/en/ai/project/archive/.gitkeep +0 -0
  10. package/template/en/ai/project/inbox/.gitkeep +1 -0
  11. package/template/en/ai/project/inbox/ideas/.gitkeep +1 -0
  12. package/template/en/ai/project/inbox/processed/.gitkeep +0 -0
  13. package/template/en/ai/project/inbox/raw/.gitkeep +1 -0
  14. package/template/en/ai/project/metrics.json +20 -0
  15. package/template/en/ai/project/project.md +42 -0
  16. package/template/en/ai/project/proposals/final-shape-updates/.gitkeep +1 -0
  17. package/template/en/ai/project/proposals/final-shape-updates/_template.md +64 -0
  18. package/template/en/ai/project/refs/architecture.md +23 -0
  19. package/template/en/ai/project/refs/commands.md +43 -0
  20. package/template/en/ai/project/refs/constraints.md +24 -0
  21. package/template/en/ai/project/refs/decisions.md +13 -0
  22. package/template/en/ai/project/refs/final-shape.md +59 -0
  23. package/template/en/ai/project/refs/module-map.md +31 -0
  24. package/template/en/ai/project/refs/roadmap.md +31 -0
  25. package/template/en/ai/project/result.json +34 -0
  26. package/template/en/ai/project/result.md +32 -0
  27. package/template/en/ai/project/runtime.md +74 -0
  28. package/template/en/ai/project/task.md +110 -0
  29. package/template/en/ai/template/LANG +1 -0
  30. package/template/en/ai/template/VERSION +1 -0
  31. package/template/en/ai/template/bootstrap.md +194 -0
  32. package/template/en/ai/template/prompt.md +118 -0
  33. package/template/en/ai/template/protocol.md +332 -0
  34. package/template/en/ai/template/reconcile.md +140 -0
  35. package/template/en/ai/template/rules/core.md +197 -0
  36. package/template/en/ai/template/rules/output.md +51 -0
  37. package/template/en/ai/template/schemas/metrics.schema.json +119 -0
  38. package/template/en/ai/template/schemas/result.schema.json +234 -0
  39. package/template/zh/ai/README.md +129 -0
  40. package/template/zh/ai/project/archive/.gitkeep +0 -0
  41. package/template/zh/ai/project/inbox/.gitkeep +1 -0
  42. package/template/zh/ai/project/inbox/ideas/.gitkeep +1 -0
  43. package/template/zh/ai/project/inbox/processed/.gitkeep +0 -0
  44. package/template/zh/ai/project/inbox/raw/.gitkeep +1 -0
  45. package/template/zh/ai/project/metrics.json +20 -0
  46. package/template/zh/ai/project/project.md +42 -0
  47. package/template/zh/ai/project/proposals/final-shape-updates/.gitkeep +1 -0
  48. package/template/zh/ai/project/proposals/final-shape-updates/_template.md +64 -0
  49. package/template/zh/ai/project/refs/architecture.md +23 -0
  50. package/template/zh/ai/project/refs/commands.md +43 -0
  51. package/template/zh/ai/project/refs/constraints.md +24 -0
  52. package/template/zh/ai/project/refs/decisions.md +13 -0
  53. package/template/zh/ai/project/refs/final-shape.md +54 -0
  54. package/template/zh/ai/project/refs/module-map.md +30 -0
  55. package/template/zh/ai/project/refs/roadmap.md +29 -0
  56. package/template/zh/ai/project/result.json +34 -0
  57. package/template/zh/ai/project/result.md +32 -0
  58. package/template/zh/ai/project/runtime.md +74 -0
  59. package/template/zh/ai/project/task.md +106 -0
  60. package/template/zh/ai/template/LANG +1 -0
  61. package/template/zh/ai/template/VERSION +1 -0
  62. package/template/zh/ai/template/bootstrap.md +180 -0
  63. package/template/zh/ai/template/prompt.md +104 -0
  64. package/template/zh/ai/template/protocol.md +300 -0
  65. package/template/zh/ai/template/reconcile.md +134 -0
  66. package/template/zh/ai/template/rules/core.md +174 -0
  67. package/template/zh/ai/template/rules/output.md +51 -0
  68. package/template/zh/ai/template/schemas/metrics.schema.json +119 -0
  69. package/template/zh/ai/template/schemas/result.schema.json +234 -0
  70. package/test/selftest.js +280 -0
@@ -0,0 +1,174 @@
1
+ # 核心规则
2
+
3
+ ## 就绪门
4
+
5
+ 编辑代码前,检查 `ai/project/task.md` 是否清楚定义:
6
+
7
+ - 目标
8
+ - 范围
9
+ - 验收
10
+ - 权限
11
+
12
+ 如果未就绪,不要编辑代码。将阻塞结果写入:
13
+
14
+ - `ai/project/result.json`
15
+ - `ai/project/result.md`
16
+ - `ai/project/metrics.json`
17
+
18
+ ## 引导门
19
+
20
+ 如果 `ai/project/project.md` 为空、只有占位内容、不完整,或用户要求整理项目上下文,
21
+ 先执行 `ai/template/bootstrap.md`,再进入执行。
22
+
23
+ 引导模式只能写项目上下文文件:
24
+
25
+ - `ai/project/project.md`
26
+ - `ai/project/refs/final-shape.md`
27
+ - `ai/project/refs/module-map.md`
28
+ - `ai/project/refs/roadmap.md`
29
+ - `ai/project/refs/architecture.md`
30
+ - `ai/project/refs/commands.md`
31
+ - `ai/project/refs/constraints.md`
32
+ - `ai/project/refs/decisions.md`
33
+
34
+ 只有在人类同时提供当前任务目标时,引导模式才可以写 `ai/project/task.md`。
35
+ 此时只能起草任务契约,不能进入实现。
36
+
37
+ 引导模式不得编辑源码、测试、配置、依赖文件、生成文件、运行时文件、结果文件或指标文件。
38
+
39
+ 写完引导草稿后,使用 `ai/template/bootstrap.md` 中的“引导后交接”停止。
40
+ 交接必须在聊天里给出可确认摘要和推荐下一步,不要只让人类打开文件检查。
41
+ 如果人类已经提供当前任务目标,可以同轮起草 `ai/project/task.md`,但仍必须停止等待确认,不能进入实现。
42
+
43
+ ## 引导读取范围
44
+
45
+ 默认只读取高价值项目来源:
46
+
47
+ - 根目录文档:`README*`、`AGENTS.md`、`CLAUDE.md`、`CONTRIBUTING*`、`CHANGELOG*`
48
+ - 清单文件:`package.json`、`pyproject.toml`、`Cargo.toml`、`go.mod`、
49
+ `pom.xml`、`build.gradle*`、`Makefile`
50
+ - 项目文档:`docs/**`,优先阅读概览、架构、安装、测试、部署、API、ADR 和决策文件
51
+ - 现有 AI 引用:`ai/project/refs/*.md`
52
+ - 源码、测试、配置、文档目录的浅层列表
53
+ - 如果文档缺失或不足,有限读取可能的入口目录,例如 `src/`、`app/`、`lib/`、
54
+ `packages/`、`services/`、`cmd/`、`internal/`、`server/`、`client/`、
55
+ `test/`、`tests/`
56
+
57
+ 除非用户明确授权或引用,不要读取依赖目录、构建产物、覆盖率输出、密钥文件、
58
+ 环境文件或归档目录。
59
+
60
+ ## 任务草稿门
61
+
62
+ 如果项目上下文已确认,但 `ai/project/task.md` 为空、只有占位内容、不完整,
63
+ 或人类提供了新的任务目标,根据已确认的项目上下文起草 `ai/project/task.md`,
64
+ 并在实现前停止等待人类确认。
65
+
66
+ 任务草稿模式只能写:
67
+
68
+ - `ai/project/task.md`
69
+
70
+ 任务草稿模式必须以 `ai/template/prompt.md` 中的“任务草稿交接”结束。
71
+
72
+ ## 上下文整合门
73
+
74
+ 如果用户提供新的权威业务、产品、架构或流程资料,并希望合并到既有上下文,
75
+ 或说“整合 ai/project/inbox/ 里的新资料”,执行 `ai/template/reconcile.md`,
76
+ 不要重新 bootstrap,也不要全量覆盖。
77
+
78
+ 新资料优先放在:
79
+
80
+ - `ai/project/inbox/*.md`
81
+ - `ai/project/inbox/raw/*.md`
82
+ - `docs/**`
83
+
84
+ 已整合资料统一移动到 `ai/project/inbox/processed/`,默认不再触发上下文整合。
85
+
86
+ 上下文整合必须先输出整合计划,等待人类确认后才更新文件。
87
+
88
+ 上下文整合默认只能更新:
89
+
90
+ - `ai/project/project.md`
91
+ - `ai/project/runtime.md`
92
+ - `ai/project/refs/*.md`
93
+
94
+ 如果新资料会改变北极星、模块地图或路线图的方向性内容,只能建议创建
95
+ `strategy_update` 提案,不能在上下文整合中直接修改:
96
+
97
+ - `ai/project/refs/final-shape.md`
98
+ - `ai/project/refs/module-map.md`
99
+ - `ai/project/refs/roadmap.md`
100
+
101
+ 除非人类明确授权,不要修改当前任务、结果、指标、归档、源码、测试、配置或依赖文件。
102
+
103
+ ## 策略修订门
104
+
105
+ 如果用户要求更新项目北极星、最终形态、产品宪法、模块地图、路线图或项目方向,
106
+ 或 `ai/project/inbox/ideas/` 中存在 `.gitkeep` 之外的新灵感,执行
107
+ `strategy_update`。
108
+
109
+ `strategy_update` 只能:
110
+
111
+ - 读取正式方向文档、决策、约束和灵感输入;
112
+ - 以 `ai/project/proposals/final-shape-updates/_template.md` 为结构模板;
113
+ - 创建 `ai/project/proposals/final-shape-updates/YYYYMMDD-topic.md`;
114
+ - 将新提案状态写为 `proposed`;
115
+ - 停止等待人类确认。
116
+
117
+ 它不能直接修改正式方向文档、源码、测试、配置或依赖文件。
118
+
119
+ 只有人类明确确认某个 proposal 后,才可以执行 `apply_strategy_update`。
120
+ 应用时:
121
+
122
+ - 被确认的提案应从 `proposed` 更新为 `accepted`,或已经是 `accepted`;
123
+ - 合并完成后,将提案更新为 `applied` 并填写 `applied_at`;
124
+ - 如果人类拒绝提案,保留文件并将 `status` 更新为 `rejected`;
125
+ - 只应用已确认内容,不顺手扩展新方向。
126
+
127
+ ## 风险门
128
+
129
+ 编辑代码或运行命令前,检查任务是否涉及:
130
+
131
+ - 数据迁移
132
+ - 认证 / 授权
133
+ - 支付 / 短信 / 外部回调
134
+ - 公共 API 变更
135
+ - 生产部署
136
+ - 大范围重构
137
+ - 不可逆或破坏性操作
138
+
139
+ 如果风险高且 `ai/project/task.md` 中未明确授权,停止并写入阻塞结果。
140
+
141
+ ## 引用加载
142
+
143
+ 只在需要时,或 `ai/project/task.md` 要求时读取引用文件:
144
+
145
+ - 最终形态 / 北极星 / 任务价值判断 -> `ai/project/refs/final-shape.md`
146
+ - 当前模块结构 / 边界 / 依赖方向 -> `ai/project/refs/module-map.md`
147
+ - 阶段目标 / 近期路线 / 暂缓事项 -> `ai/project/refs/roadmap.md`
148
+ - 架构 / API / 模块边界 -> `ai/project/refs/architecture.md`
149
+ - 历史决策 -> `ai/project/refs/decisions.md`
150
+ - 安全 / 兼容性 / 性能 / 数据 / 部署 -> `ai/project/refs/constraints.md`
151
+ - 构建 / 测试 / 运行 / 部署命令 -> `ai/project/refs/commands.md`
152
+
153
+ 在 `ai/project/result.json.refs_read` 中记录每个已读取引用及原因。
154
+
155
+ ## 执行规则
156
+
157
+ - 当前任务优先。
158
+ - 不要扩大范围。
159
+ - 不要扫描无关文件。
160
+ - 不要重写无关模块。
161
+ - 先读文件,再做判断。
162
+ - 只修改 `ai/project/task.md` 允许的文件。
163
+ - 只运行 `ai/project/task.md` 和 `ai/project/refs/commands.md` 允许的命令。
164
+ - 优先做最小且安全的改动。
165
+ - 在 `ai/project/result.json` 中记录假设。
166
+ - 尽可能验证。
167
+ - 除非验证通过,不要标记 `status = "success"`。
168
+ - 除非 `ai/project/task.md` 明确允许,不要编辑 `ai/project/runtime.md`。
169
+ - 如果需要更新运行时上下文,在 `ai/project/result.json.runtime_update` 中提出建议。
170
+
171
+ ## 运行时治理
172
+
173
+ `ai/project/runtime.md` 只存放稳定且当前有效的执行上下文。
174
+ 它不是项目日志。历史任务和结果应放在 `ai/project/archive/`。
@@ -0,0 +1,51 @@
1
+ # 输出规则
2
+
3
+ 每次执行都必须写入:
4
+
5
+ - `ai/project/result.json`
6
+ - `ai/project/result.md`
7
+ - `ai/project/metrics.json`
8
+
9
+ ## 状态
10
+
11
+ 使用以下值之一:
12
+
13
+ - `success`
14
+ - `partial`
15
+ - `failed`
16
+ - `blocked`
17
+
18
+ 除非验证通过,不要使用 `success`。
19
+
20
+ ## 结果 JSON
21
+
22
+ `ai/project/result.json` 是权威的机器可读结果。
23
+ 它必须包含范围、读取的文件、读取的引用、变更文件、命令、验证、假设、问题、
24
+ 下一步和运行时更新建议。
25
+
26
+ ## 结果 Markdown
27
+
28
+ `ai/project/result.md` 是给人看的摘要。保持简短:
29
+
30
+ ```md
31
+ ## 状态
32
+ success | partial | failed | blocked
33
+
34
+ ## 变更
35
+ - file
36
+
37
+ ## 验证
38
+ - level
39
+ - evidence
40
+
41
+ ## 问题
42
+ - issue if any
43
+
44
+ ## 下一步
45
+ - next step
46
+ ```
47
+
48
+ ## 指标
49
+
50
+ `ai/project/metrics.json` 记录模型档位、升级触发条件、强模型角色、token 估算、
51
+ 耗时、成功状态、是否需要人工修复,以及复用潜力。
@@ -0,0 +1,119 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Agent Execution Template 指标 Schema",
4
+ "type": "object",
5
+ "required": [
6
+ "protocol_version",
7
+ "task_id",
8
+ "task_type",
9
+ "model",
10
+ "model_tier",
11
+ "escalated",
12
+ "escalation_reason",
13
+ "model_policy_followed",
14
+ "escalation_trigger_hit",
15
+ "strong_model_role",
16
+ "input_tokens_estimated",
17
+ "output_tokens_estimated",
18
+ "duration_minutes",
19
+ "success",
20
+ "human_fix_required",
21
+ "failure_reason",
22
+ "reuse_potential",
23
+ "notes"
24
+ ],
25
+ "properties": {
26
+ "protocol_version": {
27
+ "const": "0.8"
28
+ },
29
+ "task_id": {
30
+ "type": "string"
31
+ },
32
+ "task_type": {
33
+ "type": "string"
34
+ },
35
+ "model": {
36
+ "type": "string"
37
+ },
38
+ "model_tier": {
39
+ "enum": [
40
+ "cheap",
41
+ "standard",
42
+ "strong"
43
+ ]
44
+ },
45
+ "escalated": {
46
+ "type": "boolean"
47
+ },
48
+ "escalation_reason": {
49
+ "type": "string"
50
+ },
51
+ "model_policy_followed": {
52
+ "type": "boolean"
53
+ },
54
+ "escalation_trigger_hit": {
55
+ "type": "string"
56
+ },
57
+ "strong_model_role": {
58
+ "type": "string"
59
+ },
60
+ "input_tokens_estimated": {
61
+ "type": "integer",
62
+ "minimum": 0
63
+ },
64
+ "output_tokens_estimated": {
65
+ "type": "integer",
66
+ "minimum": 0
67
+ },
68
+ "duration_minutes": {
69
+ "type": "number",
70
+ "minimum": 0
71
+ },
72
+ "success": {
73
+ "type": "boolean"
74
+ },
75
+ "human_fix_required": {
76
+ "type": "boolean"
77
+ },
78
+ "failure_reason": {
79
+ "type": "string"
80
+ },
81
+ "reuse_potential": {
82
+ "enum": [
83
+ "low",
84
+ "medium",
85
+ "high"
86
+ ]
87
+ },
88
+ "notes": {
89
+ "type": "array",
90
+ "items": {
91
+ "type": "string"
92
+ }
93
+ }
94
+ },
95
+ "allOf": [
96
+ {
97
+ "if": {
98
+ "properties": {
99
+ "escalated": {
100
+ "const": true
101
+ }
102
+ }
103
+ },
104
+ "then": {
105
+ "properties": {
106
+ "escalation_reason": {
107
+ "minLength": 1
108
+ },
109
+ "escalation_trigger_hit": {
110
+ "minLength": 1
111
+ },
112
+ "strong_model_role": {
113
+ "minLength": 1
114
+ }
115
+ }
116
+ }
117
+ }
118
+ ]
119
+ }
@@ -0,0 +1,234 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Agent Execution Template 结果 Schema",
4
+ "type": "object",
5
+ "required": [
6
+ "protocol_version",
7
+ "status",
8
+ "scope_followed",
9
+ "files_read",
10
+ "refs_read",
11
+ "files_changed",
12
+ "commands_run",
13
+ "verification",
14
+ "assumptions",
15
+ "issues",
16
+ "next",
17
+ "runtime_update"
18
+ ],
19
+ "properties": {
20
+ "protocol_version": {
21
+ "const": "0.8"
22
+ },
23
+ "status": {
24
+ "enum": [
25
+ "success",
26
+ "partial",
27
+ "failed",
28
+ "blocked"
29
+ ]
30
+ },
31
+ "task_id": {
32
+ "type": "string"
33
+ },
34
+ "task_summary": {
35
+ "type": "string"
36
+ },
37
+ "scope_followed": {
38
+ "type": "boolean"
39
+ },
40
+ "files_read": {
41
+ "type": "array",
42
+ "items": {
43
+ "type": "string"
44
+ }
45
+ },
46
+ "refs_read": {
47
+ "type": "array",
48
+ "items": {
49
+ "type": "object",
50
+ "required": [
51
+ "file",
52
+ "reason"
53
+ ],
54
+ "properties": {
55
+ "file": {
56
+ "type": "string"
57
+ },
58
+ "reason": {
59
+ "type": "string"
60
+ }
61
+ }
62
+ }
63
+ },
64
+ "files_changed": {
65
+ "type": "array",
66
+ "items": {
67
+ "type": "object",
68
+ "required": [
69
+ "file",
70
+ "change_type",
71
+ "reason"
72
+ ],
73
+ "properties": {
74
+ "file": {
75
+ "type": "string"
76
+ },
77
+ "change_type": {
78
+ "enum": [
79
+ "created",
80
+ "modified",
81
+ "deleted"
82
+ ]
83
+ },
84
+ "reason": {
85
+ "type": "string"
86
+ }
87
+ }
88
+ }
89
+ },
90
+ "commands_run": {
91
+ "type": "array",
92
+ "items": {
93
+ "type": "object",
94
+ "required": [
95
+ "command",
96
+ "result",
97
+ "notes"
98
+ ],
99
+ "properties": {
100
+ "command": {
101
+ "type": "string"
102
+ },
103
+ "result": {
104
+ "enum": [
105
+ "passed",
106
+ "failed",
107
+ "skipped"
108
+ ]
109
+ },
110
+ "notes": {
111
+ "type": "string"
112
+ }
113
+ }
114
+ }
115
+ },
116
+ "verification": {
117
+ "type": "object",
118
+ "required": [
119
+ "level",
120
+ "passed",
121
+ "evidence"
122
+ ],
123
+ "properties": {
124
+ "level": {
125
+ "enum": [
126
+ "none",
127
+ "read_only",
128
+ "static",
129
+ "command",
130
+ "test",
131
+ "manual"
132
+ ]
133
+ },
134
+ "passed": {
135
+ "type": "boolean"
136
+ },
137
+ "evidence": {
138
+ "type": "array",
139
+ "items": {
140
+ "type": "string"
141
+ }
142
+ }
143
+ }
144
+ },
145
+ "evidence": {
146
+ "type": "object",
147
+ "properties": {
148
+ "git_diff_summary": {
149
+ "type": "string"
150
+ },
151
+ "changed_files_from_git": {
152
+ "type": "array",
153
+ "items": {
154
+ "type": "string"
155
+ }
156
+ },
157
+ "command_outputs": {
158
+ "type": "array",
159
+ "items": {
160
+ "type": "string"
161
+ }
162
+ },
163
+ "unverified_claims": {
164
+ "type": "array",
165
+ "items": {
166
+ "type": "string"
167
+ }
168
+ }
169
+ }
170
+ },
171
+ "assumptions": {
172
+ "type": "array",
173
+ "items": {
174
+ "type": "string"
175
+ }
176
+ },
177
+ "issues": {
178
+ "type": "array",
179
+ "items": {
180
+ "type": "string"
181
+ }
182
+ },
183
+ "next": {
184
+ "type": "array",
185
+ "items": {
186
+ "type": "string"
187
+ }
188
+ },
189
+ "runtime_update": {
190
+ "type": "object",
191
+ "required": [
192
+ "required",
193
+ "changes",
194
+ "reason"
195
+ ],
196
+ "properties": {
197
+ "required": {
198
+ "type": "boolean"
199
+ },
200
+ "changes": {
201
+ "type": "array",
202
+ "items": {
203
+ "type": "string"
204
+ }
205
+ },
206
+ "reason": {
207
+ "type": "string"
208
+ }
209
+ }
210
+ }
211
+ },
212
+ "allOf": [
213
+ {
214
+ "if": {
215
+ "properties": {
216
+ "status": {
217
+ "const": "success"
218
+ }
219
+ }
220
+ },
221
+ "then": {
222
+ "properties": {
223
+ "verification": {
224
+ "properties": {
225
+ "passed": {
226
+ "const": true
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+ }
233
+ ]
234
+ }