claude-everything-workflow 0.1.4 → 0.1.6

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 +50 -19
  2. package/hooks/check-code-size.js +111 -0
  3. package/package.json +1 -1
  4. package/rules/02-code-size.md +11 -2
  5. package/rules/common/hooks.md +2 -1
  6. package/rules/common/skills-learning.md +7 -0
  7. package/scripts/install.ps1 +80 -43
  8. package/scripts/install.sh +56 -3
  9. package/scripts/verify-harness.js +156 -26
  10. package/settings.json +8 -40
  11. package/skills/brainstorming/scripts/frame-template.html +25 -26
  12. package/skills/brainstorming/scripts/helper.js +101 -22
  13. package/skills/brainstorming/scripts/server.cjs +399 -30
  14. package/skills/brainstorming/scripts/start-server.sh +70 -9
  15. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  16. package/skills/brainstorming/visual-companion.md +33 -22
  17. package/skills/learn/.gitkeep +0 -0
  18. package/skills/learn/README.md +15 -0
  19. package/skills/learn/debugging/.gitkeep +0 -0
  20. package/skills/learn/pr/.gitkeep +0 -0
  21. package/skills/learn/testing/.gitkeep +0 -0
  22. package/skills/subagent-driven-development/SKILL.md +425 -0
  23. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  24. package/skills/subagent-driven-development/scripts/review-package +44 -0
  25. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  26. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  27. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  28. package/skills/using-superpowers/SKILL.md +75 -0
  29. package/skills/writing-plans/SKILL.md +25 -2
  30. package/commands/acceptance.md +0 -73
  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,13 @@ claude-everything-Workflow/
140
158
  │ └── review-confidence.js # 置信度审查报告
141
159
  │
142
160
  ├── skills/
161
+ │ ├── using-superpowers/ # Skill 路由、优先级与门禁纪律
162
+ │ │ └── SKILL.md
163
+ │ ├── subagent-driven-development/ # SDD:task brief、review package、progress ledger
164
+ │ │ ├── SKILL.md
165
+ │ │ ├── implementer-prompt.md
166
+ │ │ ├── task-reviewer-prompt.md
167
+ │ │ └── scripts/
143
168
  │ ├── using-git-worktrees/ # 隔离式 worktree 执行准备
144
169
  │ │ └── SKILL.md
145
170
  │ ├── executing-plans/ # 按计划执行、检查点、审查与验证
@@ -164,14 +189,10 @@ claude-everything-Workflow/
164
189
  ├── hooks/ # 钩子脚本
165
190
  │ ├── runtime/ # Hook 运行时与 Profile 控制
166
191
  │ │ ├── run-with-flags.js
167
- │ │ ├── hook-flags.js
168
- │ │ └── session-utils.js
169
- │ ├── session-start.js # 会话启动上下文
170
- │ ├── session-end.js # 会话结束持久化
192
+ │ │ └── hook-flags.js
171
193
  │ ├── commit-quality.js # 可选 Pre-commit 质量门
172
194
  │ ├── check-console-log.js # console.log 检测
173
- │ ├── evaluate-session.js # 会话评估
174
- │ └── pre-compact.js # 压缩前保存上下文
195
+ │ └── check-code-size.js # 代码规模检测
175
196
  │
176
197
  └── homunculus/ # 自主学习系统
177
198
  └── instincts/
@@ -245,7 +266,6 @@ claude-everything-Workflow/
245
266
  | ------------------ | ---------------------------------------------------------- |
246
267
  | `/pr` | 提交、推送和创建 PR 的标准工作流 |
247
268
  | `/verify` | 运行全面验证检查 |
248
- | `/acceptance` | 对照需求、spec、plan、diff 和验证证据输出验收结论 |
249
269
  | `/learn-eval` | 从会话提取模式 (含质量门评估) |
250
270
  | `/instinct-status` | 查看学习状态和待审查报告 |
251
271
  | `/projects` | 查看 Continuous Learning 项目注册表 |
@@ -262,6 +282,9 @@ claude-everything-Workflow/
262
282
  ```bash
263
283
  node scripts/verify-harness.js
264
284
  bash scripts/install.sh --dry-run
285
+ ```
286
+
287
+ ```powershell
265
288
  powershell -ExecutionPolicy Bypass -File .\scripts\install.ps1 -DryRun
266
289
  ```
267
290
 
@@ -279,7 +302,7 @@ export ECC_HOOK_PROFILE=standard
279
302
  export ECC_DISABLED_HOOKS="post:edit:console-log"
280
303
  ```
281
304
 
282
- 当前仓库以根目录 `settings.json` 作为 Claude Code hooks 入口;`hooks/` 目录统一保存 Hook 运行时和脚本实现。`scripts/learning/` 只保存手动学习治理脚本,不作为 Hook 自动触发。
305
+ 当前仓库以根目录 `settings.json` 作为 Claude Code hooks 入口;`hooks/` 目录统一保存低噪音 Hook 运行时和脚本实现。默认不启用会话启动、会话结束、停止或压缩前的弱摘要 Hook,避免污染上下文。`scripts/learning/` 只保存手动学习治理脚本,不作为 Hook 自动触发。
283
306
  Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件而自动启用 Claude Code hooks;如未来需要 Codex 原生自动化,应新增明确 adapter。
284
307
 
285
308
  ## Superpowers 风格开发闭环
@@ -288,36 +311,45 @@ Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件
288
311
 
289
312
  ```text
290
313
  复杂任务
314
+ -> using-superpowers 先路由到相关 process skill
291
315
  -> brainstorming 澄清需求
292
316
  -> 写 design spec
293
317
  -> 用户审核 spec
294
318
  -> using-git-worktrees 按需创建隔离工作区
295
319
  -> writing-plans 写实施计划
296
- -> executing-plans 按计划执行
320
+ -> subagent-driven-development 或 executing-plans 按计划执行
297
321
  -> TDD 红绿重构
298
322
  -> 需求符合性审查
299
323
  -> 代码质量审查
300
324
  -> verification-before-completion 完成声明前确认新鲜验证证据
301
325
  -> /verify 质量门
302
- -> /acceptance 验收结论
303
326
  -> /pr 提交/PR
304
327
  -> /learn-eval --preview 学习沉淀
305
328
  ```
306
329
 
307
330
  硬门禁:
308
331
 
332
+ - 开始非平凡任务前,先用 `using-superpowers` 判断并加载相关 process skill。
309
333
  - 没有 spec,不进入 plan。
310
334
  - 没有用户审核,不进入实现。
335
+ - 计划必须包含 `Global Constraints` 和每任务 `Interfaces`,让 implementer/reviewer 不依赖父会话记忆。
311
336
  - 没有 failing test,不写行为代码。
312
337
  - 没有 review,不标记任务完成。
313
338
  - 没有新鲜验证证据,不声明完成、通过、已修复或 ready。
314
339
  - 没有 verify,不进入 PR。
315
- - 没有 acceptance,不把复杂任务声明为验收通过。
316
340
  - 有脏工作区、并行任务或高风险改动时,先考虑 `using-git-worktrees`。
341
+ - 只有用户明确批准 commit/PR/SDD 执行时,才使用 `subagent-driven-development` 的 per-task commit 流;否则用 `executing-plans` 或 inline execution。
342
+
343
+ ### 对齐 Superpowers v6.0.3 的能力
344
+
345
+ - `subagent-driven-development` 使用 `.superpowers/sdd/` 保存 task brief、implementer report、review package 和 `progress.md`,避免把 scratch 写进 `.git/`。
346
+ - 每个任务使用一个 `task-reviewer-prompt.md` 同时返回 spec compliance 和 code quality verdict,减少重复 reviewer 上下文。
347
+ - `writing-plans` 强制 `Global Constraints` 和每任务 `Interfaces`,把跨任务约束、输入输出契约传给 implementer 和 reviewer。
348
+ - Brainstorming visual companion 使用带 `?key=` 的 per-session URL,HTTP/WebSocket 请求都需要 session key;默认 idle timeout 为 4 小时,可用 `--idle-timeout-minutes` 调整。
317
349
 
318
350
  复杂任务包括新功能、架构调整、多文件行为变化、高风险实现,以及需求存在多种合理解释的工作。简单问答、翻译、格式调整、窄范围文档修正和无行为变化的小修复,可以直接处理,但完成前仍需运行与改动范围匹配的最小验证。
319
351
 
320
- 收尾阶段按 `/verify` -> `/acceptance` -> `/pr` -> `/learn-eval --preview` 推进。`/learn-eval --preview` 是非阻塞学习建议门,只在模式高频、稳定、可复用时保存。
352
+ 收尾阶段按 `/verify` -> `/pr` -> `/learn-eval --preview` 推进。`/learn-eval --preview` 是非阻塞学习建议门,只在模式高频、稳定、可复用时保存。
321
353
 
322
354
  ## Continuous Learning v2
323
355
 
@@ -363,11 +395,10 @@ Codex 安装同一套 `hooks/` 脚本材料,但不会因为安装本仓文件
363
395
  6. 使用 /tdd 委派 tdd-guide 规划测试先行实现
364
396
  7. 关键路径使用 /e2e 委派 e2e-runner 维护 Playwright
365
397
  8. 使用 /verify 验证
366
- 9. 使用 /acceptance 输出需求验收结论
367
- 10. 使用 /code-review 委派 code-reviewer 审查
368
- 11. 使用 /learn-eval 将稳定模式沉淀到 skills/learn/<category>/
369
- 12. 使用 /projects 查看项目级学习来源
370
- 13. 使用 /promote --dry-run 评估是否推广为全局直觉
371
- 14. 使用 /evolve 评估是否演化
372
- 15. 使用 /prune 清理已人工标记删除的直觉
398
+ 9. 使用 /code-review 委派 code-reviewer 审查
399
+ 10. 使用 /learn-eval 将稳定模式沉淀到 skills/learn/<category>/
400
+ 11. 使用 /projects 查看项目级学习来源
401
+ 12. 使用 /promote --dry-run 评估是否推广为全局直觉
402
+ 13. 使用 /evolve 评估是否演化
403
+ 14. 使用 /prune 清理已人工标记删除的直觉
373
404
  ```
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Check Code Size Hook
4
+ *
5
+ * 编辑后只检查本次改动的代码文件,正常静默,避免增加上下文噪音。
6
+ */
7
+
8
+ 'use strict'
9
+
10
+ const fs = require('fs')
11
+
12
+ const DEFAULT_MAX_LINES = 600
13
+ const TEST_MAX_LINES = 1000
14
+ const CODE_EXTENSIONS = new Set([
15
+ '.c',
16
+ '.cc',
17
+ '.cpp',
18
+ '.cs',
19
+ '.css',
20
+ '.go',
21
+ '.h',
22
+ '.hpp',
23
+ '.html',
24
+ '.java',
25
+ '.js',
26
+ '.jsx',
27
+ '.kt',
28
+ '.lua',
29
+ '.mjs',
30
+ '.php',
31
+ '.py',
32
+ '.rb',
33
+ '.rs',
34
+ '.sh',
35
+ '.swift',
36
+ '.ts',
37
+ '.tsx',
38
+ '.vue'
39
+ ])
40
+
41
+ function getExtension(filePath) {
42
+ const match = filePath.match(/(\.[^.\\/]+)$/)
43
+ return match ? match[1].toLowerCase() : ''
44
+ }
45
+
46
+ function isCodeFile(filePath) {
47
+ return CODE_EXTENSIONS.has(getExtension(filePath))
48
+ }
49
+
50
+ function isTestFile(filePath) {
51
+ return /(^|[\\/])__tests__([\\/]|$)/.test(filePath) ||
52
+ /\.(test|spec)\.[^.\\/]+$/.test(filePath)
53
+ }
54
+
55
+ function getMaxLines(filePath) {
56
+ return isTestFile(filePath) ? TEST_MAX_LINES : DEFAULT_MAX_LINES
57
+ }
58
+
59
+ function countLines(content) {
60
+ if (content.length === 0) return 0
61
+ const lines = content.split(/\r?\n/)
62
+ return content.endsWith('\n') ? lines.length - 1 : lines.length
63
+ }
64
+
65
+ function run(raw) {
66
+ let input
67
+ try {
68
+ input = JSON.parse(raw)
69
+ } catch {
70
+ return { exitCode: 0 }
71
+ }
72
+
73
+ const filePath = input.tool_input?.file_path
74
+ if (!filePath || !isCodeFile(filePath) || !fs.existsSync(filePath)) {
75
+ return { exitCode: 0 }
76
+ }
77
+
78
+ let content
79
+ try {
80
+ content = fs.readFileSync(filePath, 'utf8')
81
+ } catch {
82
+ return { exitCode: 0 }
83
+ }
84
+
85
+ const maxLines = getMaxLines(filePath)
86
+ const lineCount = countLines(content)
87
+ if (lineCount <= maxLines) {
88
+ return { exitCode: 0 }
89
+ }
90
+
91
+ return {
92
+ exitCode: 0,
93
+ stderr:
94
+ `[Hook] 代码文件超过 ${maxLines} 行: ` +
95
+ `${filePath} (${lineCount} 行),请拆分后继续。\n`
96
+ }
97
+ }
98
+
99
+ module.exports = { run }
100
+
101
+ if (require.main === module) {
102
+ let data = ''
103
+ process.stdin.setEncoding('utf8')
104
+ process.stdin.on('data', chunk => { data += chunk })
105
+ process.stdin.on('end', () => {
106
+ const result = run(data)
107
+ if (result.stderr) process.stderr.write(result.stderr)
108
+ if (result.stdout) process.stdout.write(result.stdout)
109
+ process.exit(result.exitCode || 0)
110
+ })
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Claude Code and Codex harness with rules, skills, agents, hooks, and verification gates.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -4,10 +4,19 @@
4
4
 
5
5
  | 约束项 | 限制 | 违反后果 |
6
6
  | ----------- | -------------- | ---------------------- |
7
- | 单文件行数 | **≤ 600 行** | 必须拆分文件 |
7
+ | 单代码文件行数 | **≤ 600 行** | 必须拆分文件 |
8
+ | 单测试文件行数 | **≤ 1000 行** | 必须拆分测试场景 |
8
9
  | 单函数/方法 | **≤ 80 行** | 必须提取子函数 |
9
10
  | 函数参数 | **≤ 5 个** | 必须封装为对象 |
10
11
  | 嵌套层级 | **≤ 4 层** | 必须提前返回或提取函数 |
11
12
  | 单行长度 | **≤ 120 字符** | 必须换行 |
12
13
 
13
- **超限处理**:文件过长→拆分 | 函数过长→提取 | 参数过多→封装对象 | 嵌套过深→早返回
14
+ **超限处理**:代码文件过长→拆分 | 测试文件过长→拆分场景 | 函数过长→提取 | 参数过多→封装对象 | 嵌套过深→早返回
15
+
16
+ ## 执行要求
17
+
18
+ - 编辑代码后必须触发轻量代码规模检查,只检查本次编辑的代码文件。
19
+ - `*.test.*`、`*.spec.*` 和 `__tests__/` 下的测试文件上限为 1000 行。
20
+ - 文档、设计稿、规则说明等非代码文件不受 600 行限制。
21
+ - 检查通过时保持静默;只有代码文件超过对应上限时输出短警告。
22
+ - 收到超限警告后,先拆分职责、提取模块或拆分测试场景,再继续实现。
@@ -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
 
@@ -11,6 +11,13 @@
11
11
 
12
12
  保持 skill 精简;详细参考内容应拆到 references,并按需读取。
13
13
 
14
+ ### Superpowers 路由纪律
15
+
16
+ - 非平凡任务开始前,先用 `skills/using-superpowers/SKILL.md` 判断应加载的 process skill。
17
+ - process skill 优先于 implementation skill:先决定工作方法,再做代码、文档、测试或 PR 动作。
18
+ - 不凭记忆执行 skill;skill 可能已更新,必须读取当前 `SKILL.md`。
19
+ - 用户直接指令、`AGENTS.md`、`CLAUDE.md` 和项目规则优先于 skill;冲突影响结果时要说明。
20
+
14
21
  ## 按需学习
15
22
 
16
23
  - 默认不后台学习,不持续采集大上下文。
@@ -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"