claude-everything-workflow 0.1.5 → 0.1.7

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 (35) hide show
  1. package/README.md +56 -9
  2. package/package.json +1 -1
  3. package/rules/common/hooks.md +2 -1
  4. package/rules/common/skills-learning.md +9 -0
  5. package/scripts/install.ps1 +80 -43
  6. package/scripts/install.sh +56 -3
  7. package/scripts/verify-harness.js +225 -5
  8. package/settings.json +3 -40
  9. package/skills/README.md +35 -0
  10. package/skills/brainstorming/scripts/frame-template.html +25 -26
  11. package/skills/brainstorming/scripts/helper.js +101 -22
  12. package/skills/brainstorming/scripts/server.cjs +399 -30
  13. package/skills/brainstorming/scripts/start-server.sh +70 -9
  14. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  15. package/skills/brainstorming/visual-companion.md +33 -22
  16. package/skills/context-budget/SKILL.md +59 -0
  17. package/skills/iterative-retrieval/SKILL.md +75 -0
  18. package/skills/learn/.gitkeep +0 -0
  19. package/skills/learn/README.md +15 -0
  20. package/skills/learn/debugging/.gitkeep +0 -0
  21. package/skills/learn/pr/.gitkeep +0 -0
  22. package/skills/learn/testing/.gitkeep +0 -0
  23. package/skills/subagent-driven-development/SKILL.md +425 -0
  24. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  25. package/skills/subagent-driven-development/scripts/review-package +44 -0
  26. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  27. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  28. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  29. package/skills/using-superpowers/SKILL.md +75 -0
  30. package/skills/writing-plans/SKILL.md +25 -2
  31. package/hooks/evaluate-session.js +0 -59
  32. package/hooks/pre-compact.js +0 -92
  33. package/hooks/runtime/session-utils.js +0 -45
  34. package/hooks/session-end.js +0 -62
  35. package/hooks/session-start.js +0 -60
package/README.md CHANGED
@@ -57,6 +57,20 @@ npm pack --dry-run
57
57
  npm publish --dry-run
58
58
  ```
59
59
 
60
+ ## npm 自动发布
61
+
62
+ 合并到 `main` 后,GitHub Actions 会运行 `.github/workflows/npm-publish.yml`:
63
+
64
+ 1. 运行 `npm run verify` 和 `npm run pack:dry-run`。
65
+ 2. 读取 npm registry 的当前 `latest` 版本,默认在此基础上计算下一个 patch 版本。
66
+ 3. 提交 `package.json` 版本号变更并打 `v<version>` tag。
67
+ 4. 通过 npm 受信任的发布商 OIDC 认证执行 `npm publish`。
68
+ 5. 发布成功后把版本提交和 tag 推回 `main`。
69
+
70
+ 也可以在 Actions 页面手动触发 `Publish npm`,选择 `patch`、`minor` 或 `major`。
71
+
72
+ npm 包设置里必须添加 GitHub Actions 受信任的发布商,仓库为 `xu91102/claude-everything-Workflow`,workflow 文件名为 `npm-publish.yml`,并允许 `npm publish`。
73
+
60
74
  安装目标:
61
75
 
62
76
  - Claude Code: `~/.claude/`
@@ -86,6 +100,10 @@ claude-everything-Workflow/
86
100
  ├── AGENTS.md # Codex 与通用权威规则入口
87
101
  ├── CLAUDE.md # Claude Code 最小 bootstrap 入口
88
102
  ├── settings.json # Claude Code Hooks 配置入口
103
+ ├── .github/
104
+ │ └── workflows/
105
+ │ ├── ci.yml # PR / main 校验
106
+ │ └── npm-publish.yml # main 合并后自动 bump version 并发布 npm
89
107
  │
90
108
  ├── rules/ # 规则索引与按需加载规则
91
109
  │ ├── 01-base.md # 基础设定
@@ -140,6 +158,14 @@ claude-everything-Workflow/
140
158
  │ └── review-confidence.js # 置信度审查报告
141
159
  │
142
160
  ├── skills/
161
+ │ ├── README.md # Skill 分类索引;物理目录保持平铺以兼容发现
162
+ │ ├── using-superpowers/ # Skill 路由、优先级与门禁纪律
163
+ │ │ └── SKILL.md
164
+ │ ├── subagent-driven-development/ # SDD:task brief、review package、progress ledger
165
+ │ │ ├── SKILL.md
166
+ │ │ ├── implementer-prompt.md
167
+ │ │ ├── task-reviewer-prompt.md
168
+ │ │ └── scripts/
143
169
  │ ├── using-git-worktrees/ # 隔离式 worktree 执行准备
144
170
  │ │ └── SKILL.md
145
171
  │ ├── executing-plans/ # 按计划执行、检查点、审查与验证
@@ -150,6 +176,10 @@ claude-everything-Workflow/
150
176
  │ │ └── SKILL.md
151
177
  │ ├── e2e-testing/ # Playwright E2E 模式(POM、CI、制品)
152
178
  │ │ └── SKILL.md
179
+ │ ├── context-budget/ # 上下文与 MCP 常驻开销审计
180
+ │ │ └── SKILL.md
181
+ │ ├── iterative-retrieval/ # Subagent 迭代检索与上下文收敛
182
+ │ │ └── SKILL.md
153
183
  │ ├── continuous-learning-v2/ # 自主学习系统
154
184
  │ │ ├── SKILL.md # 技能说明
155
185
  │ │ ├── config.json # 配置
@@ -164,20 +194,18 @@ claude-everything-Workflow/
164
194
  ├── hooks/ # 钩子脚本
165
195
  │ ├── runtime/ # Hook 运行时与 Profile 控制
166
196
  │ │ ├── run-with-flags.js
167
- │ │ ├── hook-flags.js
168
- │ │ └── session-utils.js
169
- │ ├── session-start.js # 会话启动上下文
170
- │ ├── session-end.js # 会话结束持久化
197
+ │ │ └── hook-flags.js
171
198
  │ ├── commit-quality.js # 可选 Pre-commit 质量门
172
199
  │ ├── check-console-log.js # console.log 检测
173
- │ ├── evaluate-session.js # 会话评估
174
- │ └── pre-compact.js # 压缩前保存上下文
200
+ │ └── check-code-size.js # 代码规模检测
175
201
  │
176
202
  └── homunculus/ # 自主学习系统
177
203
  └── instincts/
178
204
  └── personal/ # 个人直觉
179
205
  ```
180
206
 
207
+ 正式 skill 目录保持 `skills/<skill-name>/SKILL.md` 平铺结构,避免破坏 Claude Code、Codex 和安装脚本的发现方式;分类维护在 `skills/README.md`。只有学习产物使用物理分类目录 `skills/learn/<category>/`。
208
+
181
209
  ## 规则加载策略
182
210
 
183
211
  - 默认入口只加载 `AGENTS.md` 或 `CLAUDE.md` 中的硬规则和最小索引。
@@ -188,10 +216,12 @@ claude-everything-Workflow/
188
216
  - 回退只改变查找位置,不改变按需读取原则;仍然只读取当前任务直接相关的规则文件,不要默认全量加载 `rules/` 或 `rules/common/`。
189
217
  - `rules/common/` 是专项参考区,只在命令、agent、skill 或当前任务明确触发时读取。
190
218
 
191
- ## 与主仓对齐:Context7 MCP、`~/.claude` 用户级配置与省 Token
219
+ ## 与主仓对齐:按需 MCP、Context7 与省 Token
192
220
 
193
221
  本目录已含 **`skills/documentation-lookup/`**,行为与 [everything-claude-code](https://github.com/affaan-m/everything-claude-code) 主仓一致:通过 Context7 的 **`resolve-library-id` → `query-docs`** 查第三方库最新文档。技能不负责启动 MCP,需在 **Claude Code** 或 **Cursor** 中启用。
194
222
 
223
+ 本仓继续吸收 ECC 最新的 Context Budget 原则:默认 MCP 必须同时满足“通用”和“MCP 明显优于 CLI/API/原生能力”。GitHub、文档查询、Exa 搜索、Playwright E2E、memory 和 sequential-thinking 这类纯请求/响应或已有原生替代的能力,优先通过 skill、CLI/API 或 harness 原生能力按需触发,而不是默认常驻。需要审计本机上下文开销时,使用 `context-budget` skill。
224
+
195
225
  ### 1. Claude Code:用户级 `~/.claude/settings.json`
196
226
 
197
227
  复制 Workflow 到 `~/.claude/` 后,在 **`~/.claude/settings.json`**(没有则新建)里配置 **`mcpServers`**,与主仓根目录 **`.mcp.json`** 中 **`context7`** 条目保持一致:
@@ -234,6 +264,7 @@ claude-everything-Workflow/
234
264
  ```
235
265
 
236
266
  - **跑 ECC 安装/同步且你已有同名自建 MCP**:可设置 `export ECC_DISABLED_MCPS="github,context7,exa,playwright,sequential-thinking,memory"`,避免重复写入(见主仓 README)。
267
+ - **新增 MCP 前先审计**:使用 `context-budget` 判断它是否应该默认启用、按需启用,还是改为 CLI/API skill。
237
268
 
238
269
  ### 3. Cursor
239
270
 
@@ -261,6 +292,9 @@ claude-everything-Workflow/
261
292
  ```bash
262
293
  node scripts/verify-harness.js
263
294
  bash scripts/install.sh --dry-run
295
+ ```
296
+
297
+ ```powershell
264
298
  powershell -ExecutionPolicy Bypass -File .\scripts\install.ps1 -DryRun
265
299
  ```
266
300
 
@@ -278,7 +312,7 @@ export ECC_HOOK_PROFILE=standard
278
312
  export ECC_DISABLED_HOOKS="post:edit:console-log"
279
313
  ```
280
314
 
281
- 当前仓库以根目录 `settings.json` 作为 Claude Code hooks 入口;`hooks/` 目录统一保存 Hook 运行时和脚本实现。`scripts/learning/` 只保存手动学习治理脚本,不作为 Hook 自动触发。
315
+ 当前仓库以根目录 `settings.json` 作为 Claude Code hooks 入口;`hooks/` 目录统一保存低噪音 Hook 运行时和脚本实现。默认不启用会话启动、会话结束、停止或压缩前的弱摘要 Hook,避免污染上下文。`scripts/learning/` 只保存手动学习治理脚本,不作为 Hook 自动触发。
282
316
  Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件而自动启用 Claude Code hooks;如未来需要 Codex 原生自动化,应新增明确 adapter。
283
317
 
284
318
  ## Superpowers 风格开发闭环
@@ -287,12 +321,13 @@ Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件
287
321
 
288
322
  ```text
289
323
  复杂任务
324
+ -> using-superpowers 先路由到相关 process skill
290
325
  -> brainstorming 澄清需求
291
326
  -> 写 design spec
292
327
  -> 用户审核 spec
293
328
  -> using-git-worktrees 按需创建隔离工作区
294
329
  -> writing-plans 写实施计划
295
- -> executing-plans 按计划执行
330
+ -> subagent-driven-development 或 executing-plans 按计划执行
296
331
  -> TDD 红绿重构
297
332
  -> 需求符合性审查
298
333
  -> 代码质量审查
@@ -304,13 +339,25 @@ Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件
304
339
 
305
340
  硬门禁:
306
341
 
342
+ - 开始非平凡任务前,先用 `using-superpowers` 判断并加载相关 process skill。
343
+ - 上下文或工具面变重时,先用 `context-budget` 找出常驻 Token 开销,再决定新增或删除 MCP/skill/agent。
344
+ - 子代理需要探索大仓库时,先用 `iterative-retrieval` 的 Dispatch/Evaluate/Refine/Loop 闭环收敛上下文,再回传证据。
307
345
  - 没有 spec,不进入 plan。
308
346
  - 没有用户审核,不进入实现。
347
+ - 计划必须包含 `Global Constraints` 和每任务 `Interfaces`,让 implementer/reviewer 不依赖父会话记忆。
309
348
  - 没有 failing test,不写行为代码。
310
349
  - 没有 review,不标记任务完成。
311
350
  - 没有新鲜验证证据,不声明完成、通过、已修复或 ready。
312
351
  - 没有 verify,不进入 PR。
313
352
  - 有脏工作区、并行任务或高风险改动时,先考虑 `using-git-worktrees`。
353
+ - 只有用户明确批准 commit/PR/SDD 执行时,才使用 `subagent-driven-development` 的 per-task commit 流;否则用 `executing-plans` 或 inline execution。
354
+
355
+ ### 对齐 Superpowers v6.0.3 的能力
356
+
357
+ - `subagent-driven-development` 使用 `.superpowers/sdd/` 保存 task brief、implementer report、review package 和 `progress.md`,避免把 scratch 写进 `.git/`。
358
+ - 每个任务使用一个 `task-reviewer-prompt.md` 同时返回 spec compliance 和 code quality verdict,减少重复 reviewer 上下文。
359
+ - `writing-plans` 强制 `Global Constraints` 和每任务 `Interfaces`,把跨任务约束、输入输出契约传给 implementer 和 reviewer。
360
+ - Brainstorming visual companion 使用带 `?key=` 的 per-session URL,HTTP/WebSocket 请求都需要 session key;默认 idle timeout 为 4 小时,可用 `--idle-timeout-minutes` 调整。
314
361
 
315
362
  复杂任务包括新功能、架构调整、多文件行为变化、高风险实现,以及需求存在多种合理解释的工作。简单问答、翻译、格式调整、窄范围文档修正和无行为变化的小修复,可以直接处理,但完成前仍需运行与改动范围匹配的最小验证。
316
363
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Claude Code and Codex harness with rules, skills, agents, hooks, and verification gates.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -11,10 +11,11 @@
11
11
 
12
12
  ## 摘要类 Hook 规范
13
13
 
14
- - 优先在 `PreCompact` 保存压缩前关键上下文,在 `SessionEnd` 保存会话结束状态;不要用普通工具调用 hook 频繁总结对话。
14
+ - 只有在能产生明确恢复价值时,才启用 `PreCompact` / `SessionEnd` 摘要类 Hook;不要保留只写弱状态、占位统计或提示语的生命周期 Hook。
15
15
  - 摘要目标是恢复工作现场,不是提高模型智力;只记录目标、决策、关键文件、待办、验证结果、风险和未决问题。
16
16
  - 不机械总结“前 N 轮对话”,也不把完整 transcript 写回上下文;轮数不是有效信息密度的可靠指标。
17
17
  - Hook 输出应短、结构化、可恢复;默认写入持久化文件,stderr 只给必要提示,stdout 保持静默,避免污染协议输出。
18
+ - 默认模板不启用会话启动、会话结束、停止或压缩前的弱摘要 Hook;这类 Hook 必须先证明恢复价值高于上下文噪音成本。
18
19
  - 自动摘要不得覆盖用户明确写下的规则、计划或决策;发现冲突时记录冲突并要求后续人工确认。
19
20
  - 涉及敏感信息、凭据、外部链接 token 或用户私密内容时,默认只记录存在风险和证据位置,不保存原文。
20
21
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Skills 工作流
4
4
 
5
+ 正式 skill 目录保持 `skills/<skill-name>/SKILL.md` 平铺结构,以兼容 Claude Code、Codex 和安装脚本的发现方式;分类维护在 `skills/README.md`,不要把正式 skill 物理嵌套到分类目录下。
6
+
5
7
  每个 skill 应包含:
6
8
 
7
9
  - **When to Use**:何时使用。
@@ -11,6 +13,13 @@
11
13
 
12
14
  保持 skill 精简;详细参考内容应拆到 references,并按需读取。
13
15
 
16
+ ### Superpowers 路由纪律
17
+
18
+ - 非平凡任务开始前,先用 `skills/using-superpowers/SKILL.md` 判断应加载的 process skill。
19
+ - process skill 优先于 implementation skill:先决定工作方法,再做代码、文档、测试或 PR 动作。
20
+ - 不凭记忆执行 skill;skill 可能已更新,必须读取当前 `SKILL.md`。
21
+ - 用户直接指令、`AGENTS.md`、`CLAUDE.md` 和项目规则优先于 skill;冲突影响结果时要说明。
22
+
14
23
  ## 按需学习
15
24
 
16
25
  - 默认不后台学习,不持续采集大上下文。
@@ -74,58 +74,90 @@ function Copy-ClaudeSettings {
74
74
  Backup-IfChanged -Source $Source -Destination $Destination
75
75
 
76
76
  if ($DryRun) {
77
- Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing env and mcpServers"
77
+ Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing env and mcpServers, purging legacy hook paths"
78
78
  return
79
79
  }
80
80
 
81
- $sourceSettings = Get-Content -LiteralPath $Source -Raw | ConvertFrom-Json
82
- $existingSettings = if (Test-Path -LiteralPath $Destination) {
83
- Get-Content -LiteralPath $Destination -Raw | ConvertFrom-Json
84
- } else {
85
- [pscustomobject]@{}
86
- }
81
+ # 使用 Node 脚本合并 settings.json,同时清理旧版 Hook 路径
82
+ $mergeScript = @'
83
+ const fs = require('fs')
84
+
85
+ const [, , sourcePath, destinationPath] = process.argv
86
+ const source = JSON.parse(fs.readFileSync(sourcePath, 'utf8'))
87
+ const existing = fs.existsSync(destinationPath)
88
+ ? JSON.parse(fs.readFileSync(destinationPath, 'utf8'))
89
+ : {}
90
+
91
+ const LEGACY_HOOK_PATTERNS = [
92
+ 'scripts/hooks/run-with-flags.js',
93
+ 'scripts/hooks/commit-quality.js',
94
+ 'scripts/hooks/session-start.js',
95
+ 'scripts/hooks/session-end.js',
96
+ 'scripts/lib/hook-flags.js',
97
+ 'scripts/lib/utils.js',
98
+ 'hooks/observe.js',
99
+ 'hooks/review-confidence.js',
100
+ 'hooks/session-start.js',
101
+ 'hooks/session-end.js',
102
+ 'hooks/evaluate-session.js',
103
+ 'hooks/pre-compact.js',
104
+ 'hooks/runtime/session-utils.js'
105
+ ]
106
+
107
+ function isLegacyHook(hookDef) {
108
+ if (typeof hookDef !== 'object' || !hookDef.command) return false
109
+ return LEGACY_HOOK_PATTERNS.some(p => hookDef.command.includes(p))
110
+ }
87
111
 
88
- $merged = [ordered]@{}
112
+ function filterHooks(hooksArray) {
113
+ if (!Array.isArray(hooksArray)) return hooksArray
114
+ return hooksArray.map(entry => {
115
+ if (!entry || !Array.isArray(entry.hooks)) return entry
116
+ const filtered = entry.hooks.filter(h => !isLegacyHook(h))
117
+ return { ...entry, hooks: filtered }
118
+ }).filter(entry => entry.hooks && entry.hooks.length > 0)
119
+ }
89
120
 
90
- foreach ($property in $existingSettings.PSObject.Properties) {
91
- $merged[$property.Name] = $property.Value
121
+ function cleanHooks(hooksObj) {
122
+ if (!hooksObj || typeof hooksObj !== 'object') return hooksObj
123
+ const cleaned = {}
124
+ for (const [eventType, entries] of Object.entries(hooksObj)) {
125
+ const filtered = filterHooks(entries)
126
+ if (filtered.length > 0) {
127
+ cleaned[eventType] = filtered
128
+ }
92
129
  }
130
+ return cleaned
131
+ }
93
132
 
94
- foreach ($property in $sourceSettings.PSObject.Properties) {
95
- $merged[$property.Name] = $property.Value
96
- }
133
+ const merged = {
134
+ ...existing,
135
+ ...source,
136
+ env: {
137
+ ...(source.env || {}),
138
+ ...(existing.env || {})
139
+ },
140
+ mcpServers: {
141
+ ...(source.mcpServers || {}),
142
+ ...(existing.mcpServers || {})
143
+ },
144
+ hooks: cleanHooks({
145
+ ...(existing.hooks || {}),
146
+ ...(source.hooks || {})
147
+ })
148
+ }
97
149
 
98
- $env = [ordered]@{}
99
- if ($sourceSettings.PSObject.Properties.Name -contains "env") {
100
- foreach ($property in $sourceSettings.env.PSObject.Properties) {
101
- $env[$property.Name] = $property.Value
102
- }
103
- }
104
- if ($existingSettings.PSObject.Properties.Name -contains "env") {
105
- foreach ($property in $existingSettings.env.PSObject.Properties) {
106
- $env[$property.Name] = $property.Value
107
- }
108
- }
109
- if ($env.Count -gt 0) {
110
- $merged["env"] = $env
111
- }
150
+ fs.writeFileSync(destinationPath, JSON.stringify(merged, null, 2) + '\n')
151
+ '@
112
152
 
113
- $mcpServers = [ordered]@{}
114
- if ($sourceSettings.PSObject.Properties.Name -contains "mcpServers") {
115
- foreach ($property in $sourceSettings.mcpServers.PSObject.Properties) {
116
- $mcpServers[$property.Name] = $property.Value
117
- }
118
- }
119
- if ($existingSettings.PSObject.Properties.Name -contains "mcpServers") {
120
- foreach ($property in $existingSettings.mcpServers.PSObject.Properties) {
121
- $mcpServers[$property.Name] = $property.Value
122
- }
123
- }
124
- if ($mcpServers.Count -gt 0) {
125
- $merged["mcpServers"] = $mcpServers
126
- }
153
+ $scriptFile = [System.IO.Path]::GetTempFileName()
154
+ Set-Content -LiteralPath $scriptFile -Value $mergeScript -Encoding UTF8
127
155
 
128
- [pscustomobject]$merged | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $Destination -Encoding UTF8
156
+ try {
157
+ & node $scriptFile $Source $Destination
158
+ } finally {
159
+ Remove-Item -LiteralPath $scriptFile -Force -ErrorAction SilentlyContinue
160
+ }
129
161
  }
130
162
 
131
163
  function Convert-ClaudeSettingsHookPaths {
@@ -238,7 +270,12 @@ function Remove-ObsoleteWorkflowPaths {
238
270
  "scripts\hooks\session-end.js",
239
271
  "scripts\lib\hook-flags.js",
240
272
  "scripts\lib\utils.js",
241
- "hooks\review-confidence.js"
273
+ "hooks\review-confidence.js",
274
+ "hooks\session-start.js",
275
+ "hooks\session-end.js",
276
+ "hooks\evaluate-session.js",
277
+ "hooks\pre-compact.js",
278
+ "hooks\runtime\session-utils.js"
242
279
  )
243
280
 
244
281
  foreach ($relative in $obsoleteFiles) {
@@ -86,7 +86,7 @@ copy_claude_settings() {
86
86
 
87
87
  backup_if_changed "$src" "$dest"
88
88
  if [ "$DRY_RUN" -eq 1 ]; then
89
- echo "[dry-run] merge '$src' into '$dest' preserving existing env and mcpServers"
89
+ echo "[dry-run] merge '$src' into '$dest' preserving existing env and mcpServers, purging legacy hook paths"
90
90
  return
91
91
  fi
92
92
 
@@ -99,6 +99,49 @@ const existing = fs.existsSync(destinationPath)
99
99
  ? JSON.parse(fs.readFileSync(destinationPath, 'utf8'))
100
100
  : {}
101
101
 
102
+ // 清理旧版 Hook 路径模式,避免合并后残留不存在的文件引用
103
+ const LEGACY_HOOK_PATTERNS = [
104
+ 'scripts/hooks/run-with-flags.js',
105
+ 'scripts/hooks/commit-quality.js',
106
+ 'scripts/hooks/session-start.js',
107
+ 'scripts/hooks/session-end.js',
108
+ 'scripts/lib/hook-flags.js',
109
+ 'scripts/lib/utils.js',
110
+ 'hooks/observe.js',
111
+ 'hooks/review-confidence.js',
112
+ 'hooks/session-start.js',
113
+ 'hooks/session-end.js',
114
+ 'hooks/evaluate-session.js',
115
+ 'hooks/pre-compact.js',
116
+ 'hooks/runtime/session-utils.js'
117
+ ]
118
+
119
+ function isLegacyHook(hookDef) {
120
+ if (typeof hookDef !== 'object' || !hookDef.command) return false
121
+ return LEGACY_HOOK_PATTERNS.some(p => hookDef.command.includes(p))
122
+ }
123
+
124
+ function filterHooks(hooksArray) {
125
+ if (!Array.isArray(hooksArray)) return hooksArray
126
+ return hooksArray.map(entry => {
127
+ if (!entry || !Array.isArray(entry.hooks)) return entry
128
+ const filtered = entry.hooks.filter(h => !isLegacyHook(h))
129
+ return { ...entry, hooks: filtered }
130
+ }).filter(entry => entry.hooks && entry.hooks.length > 0)
131
+ }
132
+
133
+ function cleanHooks(hooksObj) {
134
+ if (!hooksObj || typeof hooksObj !== 'object') return hooksObj
135
+ const cleaned = {}
136
+ for (const [eventType, entries] of Object.entries(hooksObj)) {
137
+ const filtered = filterHooks(entries)
138
+ if (filtered.length > 0) {
139
+ cleaned[eventType] = filtered
140
+ }
141
+ }
142
+ return cleaned
143
+ }
144
+
102
145
  const merged = {
103
146
  ...existing,
104
147
  ...source,
@@ -109,7 +152,12 @@ const merged = {
109
152
  mcpServers: {
110
153
  ...(source.mcpServers || {}),
111
154
  ...(existing.mcpServers || {})
112
- }
155
+ },
156
+ // hooks 以 source 为权威,清理 existing 中的旧版残留
157
+ hooks: cleanHooks({
158
+ ...(existing.hooks || {}),
159
+ ...(source.hooks || {})
160
+ })
113
161
  }
114
162
 
115
163
  fs.writeFileSync(destinationPath, JSON.stringify(merged, null, 2) + '\n')
@@ -178,7 +226,12 @@ remove_obsolete_workflow_paths() {
178
226
  "scripts/hooks/session-end.js" \
179
227
  "scripts/lib/hook-flags.js" \
180
228
  "scripts/lib/utils.js" \
181
- "hooks/review-confidence.js"
229
+ "hooks/review-confidence.js" \
230
+ "hooks/session-start.js" \
231
+ "hooks/session-end.js" \
232
+ "hooks/evaluate-session.js" \
233
+ "hooks/pre-compact.js" \
234
+ "hooks/runtime/session-utils.js"
182
235
  do
183
236
  if [ -f "$dest/$file" ]; then
184
237
  run rm -f "$dest/$file"