@aipper/aiws-spec 0.0.1

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 (145) hide show
  1. package/README.md +12 -0
  2. package/docs/cli-interface.md +288 -0
  3. package/docs/spec-contract.md +183 -0
  4. package/package.json +18 -0
  5. package/templates/workspace/.agents/skills/aiws-change-archive/SKILL.md +23 -0
  6. package/templates/workspace/.agents/skills/aiws-change-list/SKILL.md +18 -0
  7. package/templates/workspace/.agents/skills/aiws-change-new/SKILL.md +26 -0
  8. package/templates/workspace/.agents/skills/aiws-change-next/SKILL.md +19 -0
  9. package/templates/workspace/.agents/skills/aiws-change-start/SKILL.md +27 -0
  10. package/templates/workspace/.agents/skills/aiws-change-status/SKILL.md +19 -0
  11. package/templates/workspace/.agents/skills/aiws-change-sync/SKILL.md +19 -0
  12. package/templates/workspace/.agents/skills/aiws-change-templates-init/SKILL.md +18 -0
  13. package/templates/workspace/.agents/skills/aiws-change-templates-which/SKILL.md +18 -0
  14. package/templates/workspace/.agents/skills/aiws-change-validate/SKILL.md +23 -0
  15. package/templates/workspace/.agents/skills/aiws-hooks-install/SKILL.md +30 -0
  16. package/templates/workspace/.agents/skills/aiws-hooks-status/SKILL.md +18 -0
  17. package/templates/workspace/.agents/skills/aiws-init/SKILL.md +27 -0
  18. package/templates/workspace/.agents/skills/aiws-rollback/SKILL.md +18 -0
  19. package/templates/workspace/.agents/skills/aiws-update/SKILL.md +26 -0
  20. package/templates/workspace/.agents/skills/aiws-validate/SKILL.md +22 -0
  21. package/templates/workspace/.agents/skills/ws-analyze/SKILL.md +26 -0
  22. package/templates/workspace/.agents/skills/ws-commit/SKILL.md +50 -0
  23. package/templates/workspace/.agents/skills/ws-dev/SKILL.md +34 -0
  24. package/templates/workspace/.agents/skills/ws-migrate/SKILL.md +54 -0
  25. package/templates/workspace/.agents/skills/ws-plan/SKILL.md +39 -0
  26. package/templates/workspace/.agents/skills/ws-preflight/SKILL.md +29 -0
  27. package/templates/workspace/.agents/skills/ws-req-change/SKILL.md +33 -0
  28. package/templates/workspace/.agents/skills/ws-req-contract-sync/SKILL.md +17 -0
  29. package/templates/workspace/.agents/skills/ws-req-contract-validate/SKILL.md +12 -0
  30. package/templates/workspace/.agents/skills/ws-req-flow-sync/SKILL.md +28 -0
  31. package/templates/workspace/.agents/skills/ws-req-review/SKILL.md +32 -0
  32. package/templates/workspace/.agents/skills/ws-review/SKILL.md +24 -0
  33. package/templates/workspace/.agents/skills/ws-rule/SKILL.md +23 -0
  34. package/templates/workspace/.aiws/manifest.json +36 -0
  35. package/templates/workspace/.claude/commands/aiws-init.md +19 -0
  36. package/templates/workspace/.claude/commands/aiws-rollback.md +12 -0
  37. package/templates/workspace/.claude/commands/aiws-update.md +18 -0
  38. package/templates/workspace/.claude/commands/aiws-validate.md +13 -0
  39. package/templates/workspace/.claude/commands/ws-analyze.md +27 -0
  40. package/templates/workspace/.claude/commands/ws-dev.md +24 -0
  41. package/templates/workspace/.claude/commands/ws-migrate.md +22 -0
  42. package/templates/workspace/.claude/commands/ws-preflight.md +27 -0
  43. package/templates/workspace/.claude/commands/ws-req-change.md +34 -0
  44. package/templates/workspace/.claude/commands/ws-req-contract-sync.md +18 -0
  45. package/templates/workspace/.claude/commands/ws-req-contract-validate.md +13 -0
  46. package/templates/workspace/.claude/commands/ws-req-flow-sync.md +20 -0
  47. package/templates/workspace/.claude/commands/ws-req-review.md +33 -0
  48. package/templates/workspace/.claude/commands/ws-review.md +25 -0
  49. package/templates/workspace/.claude/commands/ws-rule.md +24 -0
  50. package/templates/workspace/.codex/prompts/aiws-init.md +23 -0
  51. package/templates/workspace/.codex/prompts/aiws-rollback.md +16 -0
  52. package/templates/workspace/.codex/prompts/aiws-update.md +22 -0
  53. package/templates/workspace/.codex/prompts/aiws-validate.md +17 -0
  54. package/templates/workspace/.codex/prompts/ws-analyze.md +32 -0
  55. package/templates/workspace/.codex/prompts/ws-dev.md +29 -0
  56. package/templates/workspace/.codex/prompts/ws-migrate.md +27 -0
  57. package/templates/workspace/.codex/prompts/ws-preflight.md +32 -0
  58. package/templates/workspace/.codex/prompts/ws-req-change.md +39 -0
  59. package/templates/workspace/.codex/prompts/ws-req-contract-sync.md +23 -0
  60. package/templates/workspace/.codex/prompts/ws-req-contract-validate.md +18 -0
  61. package/templates/workspace/.codex/prompts/ws-req-flow-sync.md +25 -0
  62. package/templates/workspace/.codex/prompts/ws-req-review.md +38 -0
  63. package/templates/workspace/.codex/prompts/ws-review.md +30 -0
  64. package/templates/workspace/.codex/prompts/ws-rule.md +29 -0
  65. package/templates/workspace/.githooks/pre-commit +32 -0
  66. package/templates/workspace/.githooks/pre-push +32 -0
  67. package/templates/workspace/.iflow/agents/feature-reviewer.md +27 -0
  68. package/templates/workspace/.iflow/agents/requirements-analyst.md +24 -0
  69. package/templates/workspace/.iflow/agents/server-commit-manager.md +28 -0
  70. package/templates/workspace/.iflow/agents/server-fix-implementer.md +31 -0
  71. package/templates/workspace/.iflow/agents/server-test-planner.md +28 -0
  72. package/templates/workspace/.iflow/agents/server-test-triager.md +30 -0
  73. package/templates/workspace/.iflow/commands/aiws-init.toml +24 -0
  74. package/templates/workspace/.iflow/commands/aiws-rollback.toml +18 -0
  75. package/templates/workspace/.iflow/commands/aiws-update.toml +23 -0
  76. package/templates/workspace/.iflow/commands/aiws-validate.toml +18 -0
  77. package/templates/workspace/.iflow/commands/server-commit.toml +27 -0
  78. package/templates/workspace/.iflow/commands/server-drain.toml +99 -0
  79. package/templates/workspace/.iflow/commands/server-fix-and-commit.toml +27 -0
  80. package/templates/workspace/.iflow/commands/server-fix.toml +65 -0
  81. package/templates/workspace/.iflow/commands/server-test-plan.toml +62 -0
  82. package/templates/workspace/.iflow/commands/server-test.toml +58 -0
  83. package/templates/workspace/.iflow/commands/server-triage.toml +38 -0
  84. package/templates/workspace/.iflow/commands/server_test-plan.toml +12 -0
  85. package/templates/workspace/.iflow/commands/server_test.toml +12 -0
  86. package/templates/workspace/.iflow/commands/ws-analyze.toml +33 -0
  87. package/templates/workspace/.iflow/commands/ws-contract-check.toml +69 -0
  88. package/templates/workspace/.iflow/commands/ws-dev.toml +34 -0
  89. package/templates/workspace/.iflow/commands/ws-doctor.toml +141 -0
  90. package/templates/workspace/.iflow/commands/ws-env-doctor.toml +74 -0
  91. package/templates/workspace/.iflow/commands/ws-feature-deliver.toml +44 -0
  92. package/templates/workspace/.iflow/commands/ws-feature-plan.toml +47 -0
  93. package/templates/workspace/.iflow/commands/ws-init.toml +53 -0
  94. package/templates/workspace/.iflow/commands/ws-memory-bank-init.toml +100 -0
  95. package/templates/workspace/.iflow/commands/ws-migrate.toml +59 -0
  96. package/templates/workspace/.iflow/commands/ws-preflight.toml +30 -0
  97. package/templates/workspace/.iflow/commands/ws-req-change.toml +52 -0
  98. package/templates/workspace/.iflow/commands/ws-req-contract-sync.toml +25 -0
  99. package/templates/workspace/.iflow/commands/ws-req-contract-validate.toml +16 -0
  100. package/templates/workspace/.iflow/commands/ws-req-flow-sync.toml +36 -0
  101. package/templates/workspace/.iflow/commands/ws-req-review.toml +56 -0
  102. package/templates/workspace/.iflow/commands/ws-review.toml +32 -0
  103. package/templates/workspace/.iflow/commands/ws-rule.toml +43 -0
  104. package/templates/workspace/.opencode/command/aiws-init.md +19 -0
  105. package/templates/workspace/.opencode/command/aiws-rollback.md +12 -0
  106. package/templates/workspace/.opencode/command/aiws-update.md +18 -0
  107. package/templates/workspace/.opencode/command/aiws-validate.md +13 -0
  108. package/templates/workspace/.opencode/command/ws-analyze.md +27 -0
  109. package/templates/workspace/.opencode/command/ws-dev.md +24 -0
  110. package/templates/workspace/.opencode/command/ws-migrate.md +22 -0
  111. package/templates/workspace/.opencode/command/ws-preflight.md +27 -0
  112. package/templates/workspace/.opencode/command/ws-req-change.md +34 -0
  113. package/templates/workspace/.opencode/command/ws-req-contract-sync.md +18 -0
  114. package/templates/workspace/.opencode/command/ws-req-contract-validate.md +13 -0
  115. package/templates/workspace/.opencode/command/ws-req-flow-sync.md +20 -0
  116. package/templates/workspace/.opencode/command/ws-req-review.md +33 -0
  117. package/templates/workspace/.opencode/command/ws-review.md +25 -0
  118. package/templates/workspace/.opencode/command/ws-rule.md +24 -0
  119. package/templates/workspace/AGENTS.md +22 -0
  120. package/templates/workspace/AI_PROJECT.md +86 -0
  121. package/templates/workspace/AI_WORKSPACE.md +167 -0
  122. package/templates/workspace/REQUIREMENTS.md +94 -0
  123. package/templates/workspace/changes/README.md +55 -0
  124. package/templates/workspace/changes/templates/design.md +29 -0
  125. package/templates/workspace/changes/templates/proposal.md +59 -0
  126. package/templates/workspace/changes/templates/tasks.md +33 -0
  127. package/templates/workspace/issues/problem-issues.csv +2 -0
  128. package/templates/workspace/manifest.json +205 -0
  129. package/templates/workspace/memory-bank/README.md +14 -0
  130. package/templates/workspace/memory-bank/architecture.md +9 -0
  131. package/templates/workspace/memory-bank/implementation-plan.md +11 -0
  132. package/templates/workspace/memory-bank/progress.md +10 -0
  133. package/templates/workspace/memory-bank/tech-stack.md +11 -0
  134. package/templates/workspace/requirements/CHANGELOG.md +13 -0
  135. package/templates/workspace/requirements/requirements-issues.csv +2 -0
  136. package/templates/workspace/secrets/test-accounts.example.json +32 -0
  137. package/templates/workspace/tools/iflow_watchdog.sh +138 -0
  138. package/templates/workspace/tools/install_iflow_watchdog_systemd_user.sh +118 -0
  139. package/templates/workspace/tools/requirements_contract.py +285 -0
  140. package/templates/workspace/tools/requirements_contract_sync.py +290 -0
  141. package/templates/workspace/tools/requirements_flow_gen.py +250 -0
  142. package/templates/workspace/tools/server_test_runner.py +1902 -0
  143. package/templates/workspace/tools/systemd/iflow-watchdog@.service +16 -0
  144. package/templates/workspace/tools/systemd/iflow-watchdog@.timer +11 -0
  145. package/templates/workspace/tools/ws_change_check.py +323 -0
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @aipper/aiws-spec
2
+
3
+ 本包存放 aiws 的规范与模板(单一真值来源)。
4
+
5
+ 当前已从 dotfiles 复制一份 AI Workspace 模板到:
6
+ - `templates/workspace/`
7
+
8
+ 后续 `@aipper/aiws` CLI 将以此为输入生成/更新目标仓库内的真值文件与 tool-native 配置文件。
9
+
10
+ 另见(本包内文档):
11
+ - `docs/spec-contract.md`:模板契约(required/optional、managed markers、tool matrix、`.aiws/manifest.json` 约定)
12
+ - `docs/cli-interface.md`:CLI 行为语义(仅定义,不实现)
@@ -0,0 +1,288 @@
1
+ # CLI Interface(@aipper/aiws)
2
+
3
+ 本文件只定义 `@aipper/aiws` CLI 的行为语义(不包含实现)。
4
+
5
+ ## 目标与非目标
6
+
7
+ 目标:
8
+ - 在任意仓库内执行 `init/update/validate/rollback`,落盘“真值文件 + 变更工件流程 + 门禁校验”,并可回滚。
9
+
10
+ 非目标:
11
+ - 不承诺所有工具启动即自动加载规则(以 tool-native 文件能力为准)。
12
+ - 不写入任何 secrets。
13
+
14
+ ## 通用约定
15
+
16
+ - 默认模板:`--template workspace`
17
+ - 默认生成:required + optional(模板 manifest 里标注)
18
+ - 更新策略:
19
+ - `replace_file`:整文件由 aiws 托管
20
+ - `managed_blocks`:只更新 `AIWS_MANAGED_BEGIN/END` 托管块
21
+ - 备份目录:`.aiws/backups/<timestamp>/`
22
+ - manifest:`.aiws/manifest.json` 必须入 git,记录模板/版本与托管面 hash(详见 `docs/spec-contract.md`)
23
+ - 模板内置的 `.aiws/manifest.json` 允许是占位(含 `<sha256>` / epoch 时间戳),但 `aiws init` 必须重写为真实值;`aiws validate` 必须把占位 manifest 视为未初始化并失败。
24
+ - `managed` 字段不包含 `.aiws/manifest.json` 自身(避免 self-hash),但 `validate` 仍必须校验 manifest 可解析且字段完整。
25
+
26
+ 退出码(建议):
27
+ - `0`:成功
28
+ - `2`:校验失败/门禁失败/用户输入不合法
29
+ - `1`:CLI 自身错误(异常/IO 等)
30
+
31
+ ## `aiws init`
32
+
33
+ 语义:
34
+ - 在目标仓库根目录写入/补齐模板(默认 `workspace`)。
35
+ - 默认生成 required + optional 文件/目录。
36
+ - 写入/更新 tool-native 文件(默认覆盖 Claude/OpenCode/Codex/iFlow;Codex 为 repo skills:`.agents/skills/`)。
37
+ - 写入/更新 `.gitignore` 的 aiws 托管块(其余内容保留)。
38
+ - 生成并写入 `.aiws/manifest.json`:
39
+ - 记录 `template_id/spec_version/aiws_version`
40
+ - 记录托管面 hash(用于后续 `validate`)
41
+
42
+ 接口(仅定义):
43
+ - `aiws init [path]`
44
+ - `aiws init [path] --template <template_id>`
45
+
46
+ 幂等性:
47
+ - 重复执行不应破坏用户在“托管块外”的自定义内容。
48
+
49
+ ## `aiws update`
50
+
51
+ 语义:
52
+ - 从当前 `spec_version`(或用户指定版本)刷新模板与 tool-native 文件。
53
+ - 更新前必须备份将改动的文件到 `.aiws/backups/<timestamp>/`。
54
+ - 只允许更新:
55
+ - `replace_file` 文件:整文件覆盖
56
+ - `managed_blocks` 文件:仅更新托管块
57
+ - required 但不在上述两类中的文件:不改动内容(最多补齐缺失文件)
58
+ - 若某个 `managed_blocks` 文件缺失指定 block、marker 不成对、或 marker 被破坏:必须失败(退出码 `2`),不做自动修复(提示用户重新 `aiws init` 或手工修复)。
59
+ - 更新完成后刷新 `.aiws/manifest.json`(版本与 hash)。
60
+
61
+ 接口(仅定义):
62
+ - `aiws update [path]`
63
+
64
+ ## `aiws rollback`
65
+
66
+ 语义:
67
+ - 从 `.aiws/backups/` 恢复到某一次备份的快照。
68
+
69
+ 接口(仅定义):
70
+ - `aiws rollback [path] <timestamp|latest>`
71
+
72
+ ## `aiws validate`
73
+
74
+ 语义(强门禁):
75
+ - 缺 `python3` 或缺 required 脚本直接失败(退出码非 0)。
76
+ - `.aiws/manifest.json` 若仍为占位(含 `<sha256>` / epoch 时间戳等)必须失败(退出码 `2`),提示先运行 `aiws init`。
77
+ - 可选:开启 stamping(证据落盘):
78
+ - 方式 A:`aiws validate [path] --stamp`
79
+ - 方式 B:设置环境变量 `AIWS_VALIDATE_STAMP=1` 后执行 `aiws validate [path]`
80
+ - 产物:写入 `.agentdocs/tmp/aiws-validate/<timestamp>.json`(`.agentdocs/` 由 `.gitignore` 忽略;stamp 不应包含 secrets)
81
+ - 校验范围至少包含:
82
+ 1) 文件结构:required 文件/目录存在(以模板 manifest 为准)
83
+ 2) `.gitignore`:存在且包含 aiws 托管块
84
+ 3) `.aiws/manifest.json`:存在且可解析;托管面 hash 与当前一致(漂移检测)
85
+ 4) 执行门禁脚本(示例):
86
+ - `python3 tools/ws_change_check.py --strict`
87
+ - `python3 tools/requirements_contract.py validate`
88
+
89
+ 接口(仅定义):
90
+ - `aiws validate [path] [--stamp]`
91
+
92
+ ## `aiws codex install-skills`
93
+
94
+ 背景:
95
+ - Codex 推荐使用 repo skills(`.agents/skills/`);但对于“未初始化的任意仓库”,用户可能仍希望能直接调用一组通用 skills(如 `$ws-dev`、`$ws-preflight`)来引导回 AIWS 工作流。
96
+ - 因此提供**全局 skills 安装**:把模板内的 repo skills 安装到 Codex 的全局 skills 目录中,使其在任意仓库都可显式调用(是否自动发现/是否需要重启由 Codex 实现决定;aiws 不做保证)。
97
+
98
+ 语义:
99
+ - 将模板内的 skills(`templates/<template_id>/.agents/skills/*/SKILL.md`)安装到 Codex 的全局 skills 目录:
100
+ - 默认:`~/.codex/skills/`
101
+ - 若设置了 `CODEX_HOME`:`$CODEX_HOME/skills/`
102
+ - 幂等:重复执行应只更新 AIWS 托管块,不破坏用户在文件托管块外追加的说明。
103
+ - 若目标文件已存在但不含 AIWS 托管块:默认失败(退出码 `2`);需用户显式 `--force` 才允许覆盖(覆盖前应备份)。
104
+ - 支持预演:`--dry-run` 仅输出将创建/更新/覆盖的 skills 清单,不写入任何文件。
105
+
106
+ 接口(仅定义):
107
+ - `aiws codex install-skills [--template <template_id>] [--dir <path>] [--force] [--dry-run]`
108
+
109
+ > `--dir` 可覆盖默认全局 skills 目录(用于 CI/沙箱验证,避免写入真实 home)。
110
+
111
+ ## `aiws codex status-skills`
112
+
113
+ 语义:
114
+ - 检查 Codex 全局 skills 目录中,模板期望的 skills 是否就绪,并输出每个 skill 的状态:
115
+ - `ok`:存在且 AIWS 托管块与模板一致
116
+ - `missing`:不存在
117
+ - `unmanaged`:存在但不含 AIWS 托管块(aiws 不会自动覆盖)
118
+ - `outdated`:存在且含 AIWS 托管块,但块内内容与模板不一致(建议重新 `install-skills`)
119
+ - 默认只做信息输出(不修改任何文件;退出码 `0` 表示命令执行成功,不代表全部为 `ok`)。
120
+
121
+ 接口(仅定义):
122
+ - `aiws codex status-skills [--template <template_id>] [--dir <path>]`
123
+
124
+ ## `aiws codex uninstall-skills`
125
+
126
+ 语义:
127
+ - 从 Codex 全局 skills 目录卸载 AIWS 托管的 skills:
128
+ - 仅处理“含 AIWS 托管块”的文件(避免误删用户自建 skills)
129
+ - 移除前必须备份到:`<skillsDir>/.aiws/backups/codex-skills/<timestamp>/`
130
+
131
+ 接口(仅定义):
132
+ - `aiws codex uninstall-skills [--template <template_id>] [--dir <path>]`
133
+
134
+ ---
135
+
136
+ ## `aiws codex install-prompts`
137
+
138
+ 背景(legacy):
139
+ - prompts 为遗留机制(deprecated);优先使用 repo skills(`.agents/skills/`)或全局 skills(`aiws codex install-skills`)。
140
+ - Codex 的自定义 prompts 主要从全局目录发现(通常为 `~/.codex/prompts/`)。
141
+ - 因此项目内的 `.codex/prompts/*.md` 不能保证会被 Codex 自动加载;需要显式安装到全局目录。
142
+
143
+ 语义:
144
+ - 将模板内的 Codex prompt 文件(`templates/<template_id>/.codex/prompts/*.md`)安装到 Codex 的全局 prompts 目录:
145
+ - 默认:`~/.codex/prompts/`
146
+ - 若设置了 `CODEX_HOME`:`$CODEX_HOME/prompts/`
147
+ - 幂等:重复执行应只更新 AIWS 托管块,不破坏用户在文件托管块外追加的说明。
148
+ - 若目标文件已存在但不含 AIWS 托管块:默认失败(退出码 `2`);需用户显式 `--force` 才允许覆盖(覆盖前应备份)。
149
+ - 支持预演:`--dry-run` 仅输出将创建/更新/覆盖的文件清单,不写入任何文件。
150
+
151
+ 接口(仅定义):
152
+ - `aiws codex install-prompts [--template <template_id>] [--dir <path>] [--force] [--dry-run]`
153
+
154
+ ## `aiws codex status`
155
+
156
+ 语义:
157
+ - 检查 Codex 全局 prompts 目录中,模板期望的 prompts 文件是否就绪,并输出每个文件的状态:
158
+ - `ok`:存在且 AIWS 托管块与模板一致
159
+ - `missing`:不存在
160
+ - `unmanaged`:存在但不含 AIWS 托管块(aiws 不会自动覆盖)
161
+ - `outdated`:存在且含 AIWS 托管块,但块内内容与模板不一致(建议重新 `install-prompts`)
162
+ - 默认只做信息输出(不修改文件;退出码 `0` 表示命令执行成功,不代表全部为 `ok`)。
163
+
164
+ 接口(仅定义):
165
+ - `aiws codex status [--template <template_id>] [--dir <path>]`
166
+
167
+ ## `aiws codex uninstall-prompts`
168
+
169
+ 语义:
170
+ - 从 Codex 全局 prompts 目录卸载 AIWS 托管的 prompts:
171
+ - 仅处理“含 AIWS 托管块”的文件(避免误删用户自建 prompts)
172
+ - 移除前必须备份到:`<promptsDir>/.aiws/backups/codex-prompts/<timestamp>/`
173
+
174
+ 接口(仅定义):
175
+ - `aiws codex uninstall-prompts [--template <template_id>] [--dir <path>]`
176
+
177
+ ## `aiws hooks install`
178
+
179
+ 语义:
180
+ - 为当前 git 仓库启用 aiws 门禁 hooks:
181
+ 1) 自动补齐 `.githooks/pre-commit` 与 `.githooks/pre-push`(从模板复制;若已存在则不覆盖)
182
+ 2) 设置 `git config core.hooksPath .githooks`(使 `git commit`/`git push` 触发 `aiws validate .`)
183
+ - 若需要临时绕过 hooks:设置环境变量 `WS_CHANGE_HOOK_BYPASS=1`。
184
+
185
+ 接口(仅定义):
186
+ - `aiws hooks install [path]`
187
+
188
+ ## `aiws hooks status`
189
+
190
+ 语义:
191
+ - 输出当前仓库 hooks 状态(不修改任何文件):
192
+ - git 仓库根目录
193
+ - `core.hooksPath` 当前值(是否指向 `.githooks`)
194
+ - `.githooks/pre-commit` / `.githooks/pre-push` 是否存在且可执行
195
+ - 失败时应给出下一步建议命令(如 `aiws hooks install .` 或 `aiws init .`)。
196
+
197
+ 接口(仅定义):
198
+ - `aiws hooks status [path]`
199
+
200
+ ## `aiws change`
201
+
202
+ 背景:
203
+ - `changes/` 用于保存每次变更的可审计工件:`proposal.md` / `tasks.md` / `design.md`(可选)/ `.ws-change.json`(基线元信息)。
204
+ - 门禁脚本:`tools/ws_change_check.py`(通常由 git hooks/CI 触发;也可手工执行)。
205
+
206
+ 约束:
207
+ - 不依赖 dotfiles;由 `@aipper/aiws` 提供 `aiws change ...` 子命令。
208
+ - 必须在 git 仓库内执行,且仓库根目录存在真值文件:`AI_PROJECT.md` / `AI_WORKSPACE.md` / `REQUIREMENTS.md`。
209
+
210
+ ### `aiws change new`
211
+
212
+ 语义:
213
+ - 生成 `changes/<change-id>/` 目录与工件:
214
+ - `proposal.md`
215
+ - `tasks.md`
216
+ - `design.md`(可选;`--no-design` 可跳过)
217
+ - `.ws-change.json`(记录 `created_at` 与 `base_truth_files` 作为基线)
218
+ - 模板来源优先级:
219
+ 1) `changes/templates/`
220
+ 2) `workflow/changes/templates/`(兼容旧布局)
221
+ 3) `@aipper/aiws-spec` 内置模板:`templates/<template_id>/changes/templates/`
222
+
223
+ 接口(仅定义):
224
+ - `aiws change new <change-id> [--title <title>] [--no-design]`
225
+
226
+ ### `aiws change start`
227
+
228
+ 语义:
229
+ - 切分支:`change/<change-id>`(存在则切换;不存在则创建)。
230
+ - 若 `changes/<change-id>/` 不存在:等价执行 `aiws change new ...`。
231
+ - 可选:`--hooks` 等价于 `aiws hooks install .`。
232
+
233
+ 接口(仅定义):
234
+ - `aiws change start <change-id> [--title <title>] [--no-design] [--hooks]`
235
+
236
+ ### `aiws change sync`
237
+
238
+ 语义:
239
+ - 刷新 `.ws-change.json` 的 truth baseline:
240
+ - 写入 `synced_at` / `synced_truth_files`
241
+ - 追加 `sync_events`(保留最近 20 条)
242
+ - 写入 stamp(不含 secrets):`.agentdocs/tmp/change-sync/<timestamp>-<change-id>.json`
243
+
244
+ 接口(仅定义):
245
+ - `aiws change sync [<change-id>]`
246
+
247
+ ### `aiws change validate`
248
+
249
+ 语义:
250
+ - 调用 `python3 tools/ws_change_check.py` 校验单个 change 工件目录。
251
+ - `--strict`:强门禁(例如 WS:TODO、占位符、缺归因、truth drift 等都失败)。
252
+ - `--allow-truth-drift`:仅用于紧急场景跳过 truth drift gating(仍会输出 warnings;不建议常用)。
253
+
254
+ 接口(仅定义):
255
+ - `aiws change validate [<change-id>] [--strict] [--allow-truth-drift]`
256
+
257
+ ### `aiws change archive`
258
+
259
+ 语义:
260
+ - 严格校验后归档:将 `changes/<id>/` 移动到 `changes/archive/<YYYY-MM-DD>-<id>/`。
261
+ - 默认要求 `tasks.md` 无未勾选任务;`--force` 可跳过(不建议)。
262
+ - 更新 `.ws-change.json`:
263
+ - `archived_at`
264
+ - `archived_to`
265
+ - `archived_truth_files`
266
+ - 写入 stamp(不含 secrets):`.agentdocs/tmp/change-archive/<timestamp>-<change-id>.json`
267
+
268
+ 接口(仅定义):
269
+ - `aiws change archive [<change-id>] [--date YYYY-MM-DD] [--force]`
270
+
271
+ ### `aiws change list/status/next`
272
+
273
+ 语义:
274
+ - 信息性命令:列出当前 changes 进度与下一步建议(不修改任何文件)。
275
+
276
+ 接口(仅定义):
277
+ - `aiws change list`
278
+ - `aiws change status [<change-id>]`
279
+ - `aiws change next [<change-id>]`
280
+
281
+ ### `aiws change templates which/init`
282
+
283
+ 语义:
284
+ - 查看/初始化 change 工件模板。
285
+
286
+ 接口(仅定义):
287
+ - `aiws change templates which`
288
+ - `aiws change templates init`
@@ -0,0 +1,183 @@
1
+ # Spec Contract(@aipper/aiws-spec)
2
+
3
+ 本文件定义 `@aipper/aiws-spec` 的模板契约与“可更新/可校验/可回滚”的边界。实现与发布以本文件与 `packages/spec/templates/*/manifest.json` 为准。
4
+
5
+ ## 目标与非目标
6
+
7
+ 目标:
8
+ - 约束 `aiws init/update/validate/rollback` 的**文件结构**与**更新策略**,避免规则漂移。
9
+ - 明确单一真值(SSOT):`@aipper/aiws-spec`(`packages/spec/`)。
10
+
11
+ 非目标:
12
+ - 不保证所有 AI 工具都“启动即自动加载规则”;对不支持者提供可触发的入口文件。
13
+ - 不在 spec/模板中写入任何 secrets(token、账号、内网端点等)。
14
+
15
+ ## 核心概念
16
+
17
+ - `template_id`:模板标识,等于 `templates/<template_id>/` 的目录名;默认 `workspace`。
18
+ - managed surface(可托管面):
19
+ - `replace_file`:该文件由 aiws 全量托管(更新可整文件覆盖)。
20
+ - `managed_blocks`:只更新文件内 `AIWS_MANAGED_BEGIN/END` 标记的托管块;块外内容保留给用户自定义。
21
+ - unmanaged required(必需但不托管):
22
+ - 模板 `manifest.json` 里的 `required` 仅表示“init/validate 必须存在”。
23
+ - 若某个 required 文件不在 `update.replace_file` 且不在 `update.managed_blocks` 中:视为用户自主管理内容;`aiws update` 不应修改其内容(最多只补齐缺失文件)。
24
+ - SSOT:
25
+ - 机器可读契约:`templates/<template_id>/manifest.json`
26
+ - 人类可读说明:本文件
27
+
28
+ ## 模板结构契约(SSOT)
29
+
30
+ 模板目录结构:
31
+ - `packages/spec/templates/<template_id>/`:一份可落盘到目标仓库根目录的模板快照
32
+ - `packages/spec/templates/<template_id>/manifest.json`:该模板的 required/optional 文件列表与每个文件的更新策略
33
+
34
+ 默认模板:
35
+ - `workspace`
36
+
37
+ ## Managed markers 约定
38
+
39
+ 统一格式:
40
+ - `AIWS_MANAGED_BEGIN:<id>`
41
+ - `AIWS_MANAGED_END:<id>`
42
+
43
+ 注释语法(按文件类型):
44
+ - Markdown:`<!-- AIWS_MANAGED_BEGIN:<id> -->`
45
+ - `.gitignore` / `*.sh` / `*.yaml` / `*.yml` / `*.toml`:`# AIWS_MANAGED_BEGIN:<id>`
46
+
47
+ 规则:
48
+ - `<id>` 必须稳定且可读(推荐:`area:purpose`,如 `agents`、`gitignore`、`claude:aiws-init`)。
49
+ - 托管块应当是**连续整块文本**;aiws 只允许更新托管块内容,不触碰块外内容(除非该文件策略为 `replace_file`)。
50
+ - 对于模板 manifest 声明为 `managed_blocks` 的文件:若目标仓库缺失指定 block、marker 不成对、或 marker 被破坏,`aiws update` 必须失败(不做自动修复)。
51
+
52
+ ## `.gitignore` 托管块(默认约定)
53
+
54
+ 目标仓库的 `.gitignore` 必须包含以下托管块(块外可自由扩展):
55
+
56
+ ```gitignore
57
+ # AIWS_MANAGED_BEGIN:gitignore
58
+ .agentdocs/
59
+ .aiws/backups/
60
+ secrets/test-accounts.json
61
+ .env
62
+ .env.*
63
+ !.env.example
64
+ !.env.*.example
65
+ # AIWS_MANAGED_END:gitignore
66
+ ```
67
+
68
+ 说明:
69
+ - aiws 只负责维护托管块内容;不会帮你维护 `node_modules/`、`dist/`、`target/` 等项目特定忽略项。
70
+ - 你可以把项目自己的 ignore 规则追加在托管块之外;`aiws update` 会保留块外内容不变。
71
+
72
+ ## `.aiws/manifest.json` 契约(漂移检测锚点)
73
+
74
+ 位置与版本控制:
75
+ - `.aiws/manifest.json`:必须入 git(可审计、可复现)
76
+ - `.aiws/backups/`:必须被 `.gitignore` 忽略
77
+
78
+ 用途:
79
+ - 记录当前仓库“来自哪个模板 + 版本锚点 + 托管面 hash”,用于 `aiws validate` 的漂移检测。
80
+ - `managed` 清单应覆盖模板 `manifest.json` 中声明的所有可托管面(`update.replace_file` + `update.managed_blocks`),用于精确定位漂移点。
81
+ - 例外:**不包含** `.aiws/manifest.json` 本身(避免“manifest 自己哈自己”的悖论);但 `validate` 仍必须校验 manifest 可解析且字段完整。
82
+
83
+ 推荐字段(schema 级别约定;实际以 `cli-interface.md` 为准):
84
+ - `manifest_version`:整数,便于未来升级
85
+ - `template_id`
86
+ - `spec_version`:`@aipper/aiws-spec` 版本
87
+ - `aiws_version`:`@aipper/aiws` 版本
88
+ - `installed_at` / `updated_at`:ISO 8601 UTC 时间
89
+ - `tools`:`["claude","opencode","codex","iflow"]` 的子集
90
+ - `managed`:托管面清单(文件级或托管块级 hash)
91
+
92
+ hash 规则(用于跨平台稳定性):
93
+ - 算法:SHA-256
94
+ - 文本归一化:计算前将 `\r\n` 统一转为 `\n`(不做其它 trim)
95
+ - `replace_file`:对整个文件内容计算 hash
96
+ - `managed_blocks`:对每个托管块的“块内内容”计算 hash(不包含 begin/end 行)
97
+
98
+ 示例(仅示意;hash 由 `aiws init/update` 填充):
99
+
100
+ ```json
101
+ {
102
+ "manifest_version": 1,
103
+ "template_id": "workspace",
104
+ "spec_version": "0.0.0",
105
+ "aiws_version": "0.0.0",
106
+ "installed_at": "2026-01-25T00:00:00Z",
107
+ "updated_at": "2026-01-25T00:00:00Z",
108
+ "tools": ["claude", "opencode", "codex", "iflow"],
109
+ "managed": [
110
+ { "path": ".githooks/pre-commit", "mode": "replace_file", "sha256": "<sha256>" },
111
+ { "path": ".gitignore", "mode": "managed_blocks", "blocks": { "gitignore": "<sha256>" } }
112
+ ]
113
+ }
114
+ ```
115
+
116
+ 模板内置占位(重要):
117
+ - 模板目录中的 `templates/<template_id>/.aiws/manifest.json` 允许出现 `<sha256>` 与占位时间戳(例如 `1970-01-01T00:00:00Z`),仅用于让 `init` 能直接落盘一个“结构正确的 manifest”。
118
+ - 一旦仓库通过 `aiws init` 初始化成功:该文件必须被重写为真实值(版本号/时间戳/hash)。
119
+ - `aiws validate` 必须把“占位 manifest”(仍含 `<sha256>` / epoch 时间戳等)视为 **未初始化/不可校验** 并失败(提示用户运行 `aiws init` 或 `aiws update`)。
120
+
121
+ ## Tool-native 文件矩阵(第一期覆盖)
122
+
123
+ 说明:
124
+ - tool-native 文件是 derived 产物;aiws 按模板 `manifest.json` 的 `update` 策略维护(`managed_blocks` 或 `replace_file`)。
125
+ - 默认覆盖:Claude Code / OpenCode / Codex / iFlow。
126
+
127
+ 约定路径(示例;最终以模板 manifest 为准):
128
+ - Claude Code:`.claude/commands/aiws-*.md`(commands)
129
+ - OpenCode:`.opencode/command/aiws-*.md`(command)
130
+ - Codex:`.agents/skills/*/SKILL.md`(skills)
131
+ - iFlow:`.iflow/commands/aiws-*.toml`(commands)
132
+
133
+ 补充(workflow 入口,同样由模板提供;最终以模板 manifest 为准):
134
+ - Claude Code:`.claude/commands/ws-*.md`
135
+ - OpenCode:`.opencode/command/ws-*.md`
136
+ - Codex:`.agents/skills/ws-*/SKILL.md`
137
+ - iFlow:`.iflow/commands/ws-*.toml`
138
+
139
+ 注意(Codex):
140
+ - Codex 的 repo skills 目录为 `.agents/skills/`(可随仓库共享;prompts 已 deprecated)。
141
+ - 如需在任意仓库也能显式使用 AIWS skills:可用 `aiws codex install-skills` 从模板 `.agents/skills/*/SKILL.md` 安装到 `~/.codex/skills/` 或 `$CODEX_HOME/skills`。
142
+ - 如仍需使用全局 prompts(遗留机制):可用 `aiws codex install-prompts` 从模板 `.codex/prompts/*.md` 安装到 `~/.codex/prompts/` 或 `$CODEX_HOME/prompts`。
143
+
144
+ 能力边界(必须在文档中不夸大):
145
+ - aiws **不保证** 工具会自动加载/自动注册这些文件(是否自动发现、是否需要重启/重新打开会话,由工具实现决定)。
146
+ - aiws 的最低承诺是:这些文件提供一致的“工作流入口”(例如引导执行 `npx @aipper/aiws init|update|validate|rollback`),从而把用户带回同一套真值文件与门禁。
147
+
148
+ 每个文件的托管方式(推荐):
149
+ - 对于 commands 类文件(如 `.claude/commands/*.md`、`.opencode/command/*.md`):每个文件包含**一个且仅一个**托管块(block id 形如 `claude:aiws-init`),aiws update 只更新托管块,块外内容保留给用户追加说明。
150
+ - 对于 Codex skills(`.agents/skills/*/SKILL.md`):由于文件顶部 YAML front matter 需要保持一致性,默认采用 `replace_file` 全量托管;如需自定义请新增独立 skill 目录。
151
+
152
+ 最小矩阵(建议写清以下字段,便于未来实现与验收):
153
+ - `path_pattern`:文件路径模式
154
+ - `purpose`:它是“可执行入口/提示入口/命令入口”还是“自动注入规则”
155
+ - `autodiscovery`:是否依赖工具自动发现(未知/不保证/已知支持)
156
+ - `reload_needed`:更新后是否通常需要重启/重新加载(未知/不保证/通常需要)
157
+ - `fallback`:若不生效,用户如何手动触发(直接运行 `npx @aipper/aiws ...`)
158
+
159
+ 建议的默认取值(与 `workspace` 模板一致):
160
+ - Claude Code
161
+ - `path_pattern`:`.claude/commands/aiws-*.md`
162
+ - `purpose`:提供“在 Claude 内可见的命令入口/说明”,引导用户运行 `npx @aipper/aiws ...`
163
+ - `autodiscovery`:不作为契约要求(由工具决定;aiws 不做保证)
164
+ - `reload_needed`:不作为契约要求
165
+ - `fallback`:在 shell 直接运行 `npx @aipper/aiws init|update|validate|rollback`
166
+ - OpenCode
167
+ - `path_pattern`:`.opencode/command/aiws-*.md`
168
+ - `purpose`:提供命令入口/说明(同上)
169
+ - `autodiscovery`:不作为契约要求
170
+ - `reload_needed`:不作为契约要求
171
+ - `fallback`:同上
172
+ - Codex
173
+ - `path_pattern`:`.agents/skills/*/SKILL.md`
174
+ - `purpose`:提供 skills(显式 `$<skill>` 或隐式套用工作流),引导用户运行 `npx @aipper/aiws ...`
175
+ - `autodiscovery`:不作为契约要求(由工具决定;aiws 不做保证)
176
+ - `reload_needed`:不作为契约要求
177
+ - `fallback`:显式使用 `$ws-preflight` / `$ws-plan` / `$ws-dev` / `$ws-review` / `$ws-commit`(或在 shell 直接运行 `npx @aipper/aiws init|update|validate|rollback`)
178
+ - iFlow
179
+ - `path_pattern`:`.iflow/commands/aiws-*.toml`
180
+ - `purpose`:提供 commands/命令入口/说明(同上)
181
+ - `autodiscovery`:不作为契约要求
182
+ - `reload_needed`:不作为契约要求
183
+ - `fallback`:同上
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@aipper/aiws-spec",
3
+ "version": "0.0.1",
4
+ "description": "AIWS spec and templates (single source of truth).",
5
+ "type": "module",
6
+ "files": [
7
+ "templates",
8
+ "docs",
9
+ "README.md"
10
+ ],
11
+ "engines": {
12
+ "node": ">=20"
13
+ },
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ }
18
+ }
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: aiws-change-archive
3
+ description: 归档变更工件(会先做严格校验)
4
+ ---
5
+
6
+ 目标:
7
+ - 将 `changes/<change-id>/` 归档到 `changes/archive/<YYYY-MM-DD>/...`
8
+
9
+ 执行(在仓库根目录):
10
+ ```bash
11
+ change_id="<change-id>"
12
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
13
+ ./node_modules/.bin/aiws change archive "$change_id"
14
+ elif command -v aiws >/dev/null 2>&1; then
15
+ aiws change archive "$change_id"
16
+ else
17
+ npx @aipper/aiws change archive "$change_id"
18
+ fi
19
+ ```
20
+
21
+ 说明:
22
+ - `archive` 默认会先跑严格校验并要求 tasks 全部勾选
23
+ - `--force` 会绕过部分门禁(不推荐)
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: aiws-change-list
3
+ description: 列出 changes 工件(只读)
4
+ ---
5
+
6
+ 目标:
7
+ - 列出当前仓库的变更工件与状态
8
+
9
+ 执行(在仓库根目录):
10
+ ```bash
11
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
12
+ ./node_modules/.bin/aiws change list
13
+ elif command -v aiws >/dev/null 2>&1; then
14
+ aiws change list
15
+ else
16
+ npx @aipper/aiws change list
17
+ fi
18
+ ```
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: aiws-change-new
3
+ description: 创建 changes/<change-id> 工件
4
+ ---
5
+
6
+ 目标:
7
+ - 创建 `changes/<change-id>/` 工件目录与基础文件(proposal/tasks/可选 design)
8
+
9
+ 要求:
10
+ - `change-id` 必须是 kebab-case:`^[a-z0-9]+(-[a-z0-9]+)*$`
11
+
12
+ 执行(在仓库根目录):
13
+ ```bash
14
+ change_id="<change-id>"
15
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
16
+ ./node_modules/.bin/aiws change new "$change_id"
17
+ elif command -v aiws >/dev/null 2>&1; then
18
+ aiws change new "$change_id"
19
+ else
20
+ npx @aipper/aiws change new "$change_id"
21
+ fi
22
+ ```
23
+
24
+ 可选参数:
25
+ - `--title <title>`:写入标题
26
+ - `--no-design`:不生成 design.md
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: aiws-change-next
3
+ description: 给出下一步建议(只读)
4
+ ---
5
+
6
+ 目标:
7
+ - 基于当前仓库与 changes 工件状态,输出最小下一步建议
8
+
9
+ 执行(在仓库根目录):
10
+ ```bash
11
+ change_id="<change-id>"
12
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
13
+ ./node_modules/.bin/aiws change next "$change_id"
14
+ elif command -v aiws >/dev/null 2>&1; then
15
+ aiws change next "$change_id"
16
+ else
17
+ npx @aipper/aiws change next "$change_id"
18
+ fi
19
+ ```
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: aiws-change-start
3
+ description: 切分支并初始化变更工件(可选安装 hooks)
4
+ ---
5
+
6
+ 目标:
7
+ - 切到分支 `change/<change-id>` 并初始化 `changes/<change-id>/` 工件
8
+
9
+ 要求:
10
+ - 需要 git 仓库;若不是 git 仓库先 `git init`
11
+
12
+ 执行(在仓库根目录):
13
+ ```bash
14
+ change_id="<change-id>"
15
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
16
+ ./node_modules/.bin/aiws change start "$change_id"
17
+ elif command -v aiws >/dev/null 2>&1; then
18
+ aiws change start "$change_id"
19
+ else
20
+ npx @aipper/aiws change start "$change_id"
21
+ fi
22
+ ```
23
+
24
+ 可选参数:
25
+ - `--hooks`:同时执行 `aiws hooks install .`
26
+ - `--title <title>`:写入标题
27
+ - `--no-design`:不生成 design.md
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: aiws-change-status
3
+ description: 查看单个变更工件状态(只读)
4
+ ---
5
+
6
+ 目标:
7
+ - 查看指定 `change-id` 的工件状态与下一步建议
8
+
9
+ 执行(在仓库根目录):
10
+ ```bash
11
+ change_id="<change-id>"
12
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
13
+ ./node_modules/.bin/aiws change status "$change_id"
14
+ elif command -v aiws >/dev/null 2>&1; then
15
+ aiws change status "$change_id"
16
+ else
17
+ npx @aipper/aiws change status "$change_id"
18
+ fi
19
+ ```
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: aiws-change-sync
3
+ description: 同步真值基线到 changes/<change-id>(写入 .ws-change.json)
4
+ ---
5
+
6
+ 目标:
7
+ - 将当前真值文件(`AI_PROJECT.md` / `AI_WORKSPACE.md` / `REQUIREMENTS.md`)的 hash 快照同步到 `changes/<change-id>/.ws-change.json`
8
+
9
+ 执行(在仓库根目录):
10
+ ```bash
11
+ change_id="<change-id>"
12
+ if [[ -x "./node_modules/.bin/aiws" ]]; then
13
+ ./node_modules/.bin/aiws change sync "$change_id"
14
+ elif command -v aiws >/dev/null 2>&1; then
15
+ aiws change sync "$change_id"
16
+ else
17
+ npx @aipper/aiws change sync "$change_id"
18
+ fi
19
+ ```