claude-everything-workflow 0.2.4 → 0.2.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 (46) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/AGENTS.md +6 -4
  4. package/bin/claude-everything-workflow.js +15 -0
  5. package/commands/pr.md +2 -2
  6. package/harness/manifest.json +1 -1
  7. package/hooks/check-code-size.js +1 -1
  8. package/package.json +2 -1
  9. package/rules/01-base.md +4 -1
  10. package/rules/02-implementation.md +27 -0
  11. package/rules/05-git-workflow.md +2 -1
  12. package/rules/08-specialty-rules-index.md +1 -1
  13. package/rules/09-first-principles-adversarial-testing.md +1 -2
  14. package/rules/common/testing.md +1 -0
  15. package/scripts/install.ps1 +28 -44
  16. package/scripts/install.sh +31 -3
  17. package/scripts/learning/migrate-homunculus.js +10 -5
  18. package/scripts/learning/project-utils.js +9 -0
  19. package/scripts/learning/promote.js +27 -10
  20. package/scripts/merge-claude-settings.cjs +88 -25
  21. package/scripts/verify/install-rules.test.js +183 -0
  22. package/scripts/verify/learning.test.js +122 -0
  23. package/scripts/verify/metadata-checks.js +57 -4
  24. package/scripts/verify/skill-invocation.test.js +6 -1
  25. package/scripts/verify/skill-manifest-checks.js +7 -4
  26. package/scripts/verify/workflow-checks.js +0 -1
  27. package/skills/README.md +1 -1
  28. package/skills/code-review/SKILL.md +7 -2
  29. package/skills/code-review/references/spec-reviewer-prompt.md +7 -4
  30. package/skills/continuous-learning-v2/SKILL.md +1 -0
  31. package/skills/continuous-learning-v2/config.json +1 -1
  32. package/skills/continuous-learning-v2/hooks/observe-v2.js +2 -9
  33. package/skills/feature-acceptance/SKILL.md +13 -5
  34. package/skills/feature-acceptance/references/project-verification.md +55 -0
  35. package/skills/implement/SKILL.md +3 -1
  36. package/skills/implement/agents/openai.yaml +2 -0
  37. package/skills/spec-gate/SKILL.md +9 -21
  38. package/skills/spec-gate/references/spec-template.md +23 -0
  39. package/skills/systematic-debugging/SKILL.md +6 -6
  40. package/skills/systematic-debugging/references/debugging-methods.md +30 -0
  41. package/skills/systematic-debugging/references/diagnostic-scenarios.md +1 -1
  42. package/skills/using-superpowers/SKILL.md +9 -1
  43. package/rules/02-code-size.md +0 -7
  44. package/rules/03-architecture.md +0 -12
  45. package/rules/04-error-handling.md +0 -5
  46. package/rules/06-comments.md +0 -4
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Evidence-based engineering workflows: implement, debug, review and verify.",
5
5
  "author": { "name": "xu91102" },
6
6
  "homepage": "https://github.com/xu91102/claude-everything-Workflow",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Evidence-based engineering workflows: implement, debug, review and verify.",
5
5
  "author": { "name": "xu91102" },
6
6
  "homepage": "https://github.com/xu91102/claude-everything-Workflow",
package/AGENTS.md CHANGED
@@ -6,9 +6,14 @@
6
6
  - 默认使用日常中文。必须使用专业术语、错误码或英文缩写时,紧跟一句解释它对用户意味着什么。
7
7
  - 解释变更、故障或排查结果时,简单说明;明确区分已确认事实、推测和阻塞项。
8
8
  - 除非用户要求,不贴大段原始日志、命令或实现细节;只保留支持结论所需的最小证据。
9
+ - 同一事实只说一次;简单任务短答,复杂任务按需展开。进展只报告新发现、阻塞和关键决定,不逐条播报工具操作。
10
+ - 精简不改变含义或技术原文,有歧义时完整说明。
11
+ - 工具结果优先读取相关片段,大结果只展示摘要并保留原文入口、实际退出码和关键错误,不凭截断结果判定成功。
9
12
 
10
13
  > 规则按需读取,不要默认全量加载 `rules/` 或 `rules/common/`。
11
14
 
15
+ - 工程交付(实现、修复、测试、审查)先进入 `using-superpowers`,按其判断选择并读取后续流程。
16
+
12
17
  ## 规则加载策略
13
18
 
14
19
  - 默认不全量读取 `rules/`;涉及代码修改、审查、测试、提交或 Harness 调整时,只读取与当前任务直接相关的规则文件,回退场景不改变该原则。
@@ -21,11 +26,8 @@
21
26
  | 规则文件 | 内容与触发场景 |
22
27
  | -------------------------------------------- | ------------------------------------------------------ |
23
28
  | `01-base.md` | 执行原则、最小实现决策阶梯、流程边界;实现或审查前读取 |
24
- | `02-code-size.md` | 项目规模标准优先、Hook 提示和职责审查 |
25
- | `03-architecture.md` | 既有架构、局部性、重构兼容、跨平台脚本 |
26
- | `04-error-handling.md` | 错误责任、不吞错、显式降级与异步处理 |
29
+ | `02-implementation.md` | 架构与兼容、错误处理、代码规模、注释 |
27
30
  | `05-git-workflow.md` | Worktree 分支开发、提交格式、PR 授权边界 |
28
- | `06-comments.md` | 项目注释惯例与非显然约束 |
29
31
  | `07-forbidden.md` | 禁止事项:代码、安全、提交禁止项 |
30
32
  | `08-specialty-rules-index.md` | 专项规则触发矩阵,按需跳转到 `rules/common/` 专项规则 |
31
33
  | `09-first-principles-adversarial-testing.md` | 第一性原则与对抗性测试,复杂/高风险任务按需加载 |
@@ -30,6 +30,21 @@ function main() {
30
30
  }
31
31
 
32
32
  function runInstall(args) {
33
+ const supported = new Set(["--claude-only", "--codex-only", "--dry-run", "--help", "-h"]);
34
+ const unknown = args.find((arg) => !supported.has(arg));
35
+ if (unknown) {
36
+ process.stderr.write(`Unknown option: ${unknown}\n`);
37
+ process.exit(1);
38
+ }
39
+ if (args.includes("--claude-only") && args.includes("--codex-only")) {
40
+ process.stderr.write("--claude-only and --codex-only cannot be used together\n");
41
+ process.exit(1);
42
+ }
43
+ if (args.includes("--help") || args.includes("-h")) {
44
+ printHelp();
45
+ process.exit(0);
46
+ }
47
+
33
48
  if (process.platform === "win32") {
34
49
  const script = path.join(root, "scripts", "install.ps1");
35
50
  const psArgs = [
package/commands/pr.md CHANGED
@@ -36,7 +36,7 @@ description: 提交、推送和创建 Pull Request 的标准工作流
36
36
  5. 修复可安全修复的失败项,并重跑相关验证。
37
37
  6. 只暂存本次任务相关文件。
38
38
  7. 使用 conventional commit 提交。
39
- 8. 用户明确要求推送时可直接推送;创建 PR 前仍需确认外部写操作。
39
+ 8. 按 `rules/05-git-workflow.md` 的授权边界执行推送与创建 PR。
40
40
  9. 创建 PR 后报告链接、验证结果、风险点和未运行检查。
41
41
 
42
42
  若当前工作来自 tracker ticket,在 commit/PR 描述中加入不会误触发关闭的 ticket reference
@@ -84,4 +84,4 @@ pnpm --filter <pkg> build
84
84
  - 不要跳过失败检查直接提交,除非用户明确授权。
85
85
  - 不要把无关文件混入提交。
86
86
  - 不要在受保护分支直接提交。
87
- - 用户明确要求推送时可直接执行;创建 PR、合并 PR 前必须再次确认。
87
+ - Git/PR 操作的授权边界统一见 `rules/05-git-workflow.md`。
@@ -108,7 +108,7 @@
108
108
  "codex"
109
109
  ],
110
110
  "allowedTools": null,
111
- "invocation": "implicit"
111
+ "invocation": "explicit-only"
112
112
  },
113
113
  {
114
114
  "name": "improve-codebase-architecture",
@@ -3,7 +3,7 @@
3
3
  * Check Code Size Hook
4
4
  *
5
5
  * 编辑后只检查本次改动的代码文件:文件行数上限与单行长度。
6
- * 正常静默,避免增加上下文噪音。对应 rules/02-code-size.md。
6
+ * 正常静默,避免增加上下文噪音。对应 rules/02-implementation.md。
7
7
  */
8
8
 
9
9
  'use strict'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Claude Code and Codex harness with rules, skills, agents, hooks, and verification gates.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -21,6 +21,7 @@
21
21
  "test:invocation": "node scripts/verify/skill-invocation.test.js",
22
22
  "test:continuation": "node scripts/verify/continuation-checks.test.js",
23
23
  "test:install-rules": "node scripts/verify/install-rules.test.js",
24
+ "test:learning": "node --test scripts/verify/learning.test.js",
24
25
  "test:plugins": "node --test scripts/verify/plugin-distribution.test.js",
25
26
  "verify:upstream": "node scripts/verify-upstream-capability-map.js",
26
27
  "pack:dry-run": "npm pack --dry-run"
package/rules/01-base.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # 执行原则
2
2
 
3
3
  - 先理解用户目标和真实调用链,可查事实自行读取。只询问会实质改变结果且无法查明的用户决策。
4
- - 改动必须对应需求、失败用例或验收标准;保留已有用户改动,无关问题只记录。
4
+ - 实施前简述当前目标、预计修改范围和验收标准;用户已明确时直接沿用。已授权范围内自主完成,不重复索要确认;
5
+ 必须扩大已约定的目标、修改边界或验收标准时,先说明必要性、影响与最小方案,获准后再扩大。
6
+ - 改动必须对应当前任务的需求、失败用例或验收标准;保留已有用户改动,无关问题只记录,不自动纳入本次任务。
5
7
  - 优先复用项目现有入口、标准库和已安装依赖;最后才写最小新增代码,并修在共同根因位置。
6
8
  - 最小实现不得省略安全、输入校验、错误处理、兼容性、无障碍和必要验证。
7
9
  - 目标项目的架构、lint、类型、测试和风格配置优先于本套通用默认值;没有配置时才使用相关规则的回退建议。
10
+ - 收尾核对完整实际差异(含新增文件),撤回本轮引入的无关改动;约定验收与必要审查验证通过后结束,不自行追加目标。
8
11
  - 流程路由与升级条件只由 `skills/using-superpowers/SKILL.md` 维护;验证范围见 `rules/common/testing.md`,
9
12
  Git 与授权见 `rules/05-git-workflow.md`。不在 rules 重写 Skill 的状态机。
@@ -0,0 +1,27 @@
1
+ # 实现规范
2
+
3
+ ## 架构与兼容
4
+
5
+ - 遵循目标项目的目录、分层和依赖方向;仅调整影响当前需求的职责与耦合。
6
+ - 抽象应隐藏细节、减少调用方复杂度;不为假设的复用增加接口或透传层。
7
+ - 局部修复只改变已授权的目标场景;修改共享逻辑前检查相关调用方,在需求范围内修复共同根因,并用相称回归证据确认非目标调用方的输入输出、错误、重试/超时及副作用不变。
8
+ - 复杂度相近时,优先边界行为正确、维护成本低的方案。
9
+ - 实现、测试和类型保持局部性;跨域共用目录只承接已出现的稳定复用。
10
+ - 状态变化显式,遵循项目更新惯例;保留公共接口和既有工作流,破坏性变更需用户批准。
11
+ - 重构增量、可验证、可回退,正常与边界路径有相称验证。
12
+
13
+ ## 错误处理
14
+
15
+ - 错误必须保留原因和必要上下文,不吞错、不把失败伪装为成功。
16
+ - 沿用目标项目已有的错误边界、中间件或调用方处理约定;每个错误有明确处理责任,避免逐层重复捕获和提示。
17
+ - 降级、重试与批量部分失败应显式区分;异步拒绝必须有处理方。
18
+
19
+ ## 代码规模
20
+
21
+ 没有项目约束时,用函数约 80 行、参数 5 个、嵌套 4 层作为职责审查提示。超限先判断职责和可读性,
22
+ 不为满足数值拆出透传层,也不机械压缩代码;文件和行长由 Hook 提示,不在规则中重复维护。
23
+
24
+ ## 注释
25
+
26
+ 沿用项目文档惯例。注释说明不明显的原因、约束、兼容性处理、复杂算法或外部契约;
27
+ 公共 API 按项目要求提供文档。自解释代码不补逐句说明,不重复类型已表达的参数和返回值。
@@ -27,5 +27,6 @@
27
27
  ## PR 授权边界
28
28
 
29
29
  - 不在 `main`、`master`、`prod` 等受保护分支直接提交。
30
- - 用户明确要求推送分支时可直接执行;创建 PR、合并 PR 前必须向用户确认。
30
+ - 用户明确要求推送分支或创建 PR 时,可在同一任务与授权范围内直接执行,无需重复确认。未获明确授权、授权不清,或范围/风险发生实质变化时,先向用户确认。
31
+ - 创建 PR 的授权不覆盖合并 PR 或发布;合并和发布必须分别获得用户对该动作的明确授权,同一范围内已有授权不重复索要。
31
32
  - 用户要求提交、推送、创建 PR 时,读取 `commands/pr.md` 和 `rules/common/pr-automation.md`;后者只维护 PR 的 CI、制品和描述,不重复本文件的 Git 与授权规则。
@@ -15,4 +15,4 @@
15
15
  | 测试策略、TDD、E2E、验证范围 | `common/testing.md` |
16
16
  | 提交、推送、PR、CI 质量门 | `05-git-workflow.md`、`common/pr-automation.md` |
17
17
  | 安全敏感实现或安全审查 | `07-forbidden.md` |
18
- | 跨平台脚本、不可变性 | `03-architecture.md` |
18
+ | 架构与兼容、错误处理、代码规模、注释 | `02-implementation.md` |
@@ -27,5 +27,4 @@
27
27
  ## 与其他规则的关系
28
28
 
29
29
  - 具体测试分层和命令选择见 `rules/common/testing.md`。
30
- - 架构分层、兼容迁移和重构步骤见 `rules/03-architecture.md`。
31
- - 错误处理细节见 `rules/04-error-handling.md`。
30
+ - 架构与兼容、错误处理和代码规模约束见 `rules/02-implementation.md`。
@@ -10,6 +10,7 @@
10
10
  ## 默认策略
11
11
 
12
12
  - 先识别仓库已有的 lint、format、单测、类型、构建和 E2E 命令,不发明替代流程。
13
+ - 项目验收合同要求真实流程时,按 `skills/feature-acceptance/SKILL.md` 复用项目验收入口和功能地图;普通验证不自动创建验收基础设施。
13
14
  - 中间步骤运行覆盖当前改动面的最小验证;完成、跨模块、高风险、发布或 PR 前升级到完整相关质量门。
14
15
  - 无法运行某项检查时,说明原因、替代证据和剩余风险;不得把未运行写成通过。
15
16
  - monorepo 的 consumer 依赖内部构建产物时,先构建对应上游 package。
@@ -6,6 +6,13 @@ param(
6
6
 
7
7
  $ErrorActionPreference = "Stop"
8
8
 
9
+ if ($args.Count -gt 0) {
10
+ throw "Unknown option: $($args[0])"
11
+ }
12
+ if ($ClaudeOnly -and $CodexOnly) {
13
+ throw "-ClaudeOnly and -CodexOnly cannot be used together"
14
+ }
15
+
9
16
  $RootDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
10
17
  $HomeDir = if ($env:USERPROFILE) { $env:USERPROFILE } else { $HOME }
11
18
 
@@ -74,55 +81,16 @@ function Copy-ClaudeSettings {
74
81
  Backup-IfChanged -Source $Source -Destination $Destination
75
82
 
76
83
  if ($DryRun) {
77
- Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing env and mcpServers"
84
+ Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing user hooks, env and mcpServers"
78
85
  Write-Host "[dry-run] Purge legacy hook paths while merging Claude settings"
79
86
  return
80
87
  }
81
88
 
82
89
  $mergeScript = Join-Path $RootDir "scripts\merge-claude-settings.cjs"
83
- & node $mergeScript $Source $Destination
84
- }
85
-
86
- function Convert-ClaudeSettingsHookPaths {
87
- param([string]$SettingsPath)
88
-
89
- if ($DryRun) {
90
- Write-Host "[dry-run] Convert hook paths in '$SettingsPath' to Windows absolute paths"
91
- return
92
- }
93
-
94
- $settings = Get-Content -LiteralPath $SettingsPath -Raw | ConvertFrom-Json
95
- $claudeHome = Join-Path $HomeDir ".claude"
96
-
97
- function Update-Commands {
98
- param($Value)
99
-
100
- if ($null -eq $Value) {
101
- return
102
- }
103
-
104
- if ($Value -is [System.Array]) {
105
- foreach ($item in $Value) {
106
- Update-Commands -Value $item
107
- }
108
- return
109
- }
110
-
111
- if ($Value -isnot [psobject]) {
112
- return
113
- }
114
-
115
- if ($Value.PSObject.Properties.Name -contains "command" -and $Value.command -is [string]) {
116
- $Value.command = $Value.command.Replace('$HOME/.claude', $claudeHome)
117
- }
118
-
119
- foreach ($property in $Value.PSObject.Properties) {
120
- Update-Commands -Value $property.Value
121
- }
90
+ & node $mergeScript $Source $Destination --windows-paths
91
+ if ($LASTEXITCODE -ne 0) {
92
+ throw "Claude settings merge failed with exit code $LASTEXITCODE"
122
93
  }
123
-
124
- Update-Commands -Value $settings.hooks
125
- $settings | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $SettingsPath -Encoding UTF8
126
94
  }
127
95
 
128
96
  function Copy-DirectoryMerge {
@@ -191,6 +159,7 @@ function Remove-PackageOnlyPaths {
191
159
  "scripts\verify\skill-invocation.test.js",
192
160
  "scripts\verify\continuation-checks.test.js",
193
161
  "scripts\verify\install-rules.test.js",
162
+ "scripts\verify\learning.test.js",
194
163
  "scripts\verify\plugin-distribution.test.js"
195
164
  )
196
165
 
@@ -297,6 +266,15 @@ function Test-RetiredSkillManifest {
297
266
  }
298
267
  }
299
268
 
269
+ function Test-InstallRoot {
270
+ param([string]$Destination)
271
+
272
+ $existing = Get-Item -LiteralPath $Destination -Force -ErrorAction SilentlyContinue
273
+ if ($null -ne $existing -and ($existing.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
274
+ throw "Refusing symlinked install root: $Destination"
275
+ }
276
+ }
277
+
300
278
  function Install-ClaudeWorkflow {
301
279
  $dest = Join-Path $HomeDir ".claude"
302
280
 
@@ -310,7 +288,6 @@ function Install-ClaudeWorkflow {
310
288
  Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md")
311
289
  $settingsPath = Join-Path $dest "settings.json"
312
290
  Copy-ClaudeSettings -Source (Join-Path $RootDir "settings.json") -Destination $settingsPath
313
- Convert-ClaudeSettingsHookPaths -SettingsPath $settingsPath
314
291
  Install-SharedDirs -Destination $dest
315
292
  Install-WorkflowRules -Destination $dest -HostName "claude-code"
316
293
  Remove-RetiredSkills -Destination $dest
@@ -344,6 +321,13 @@ function Install-WorkflowRules {
344
321
  }
345
322
  }
346
323
 
324
+ if ($InstallClaude) {
325
+ Test-InstallRoot -Destination (Join-Path $HomeDir ".claude")
326
+ }
327
+ if ($InstallCodex) {
328
+ Test-InstallRoot -Destination (Join-Path $HomeDir ".codex")
329
+ }
330
+
347
331
  Test-RetiredSkillManifest
348
332
 
349
333
  if ($InstallClaude) {
@@ -7,6 +7,7 @@ HOME_DIR="${HOME:?HOME is required}"
7
7
  INSTALL_CLAUDE=1
8
8
  INSTALL_CODEX=1
9
9
  DRY_RUN=0
10
+ SHOW_HELP=0
10
11
 
11
12
  usage() {
12
13
  cat <<'EOF'
@@ -23,10 +24,18 @@ EOF
23
24
  while [ "$#" -gt 0 ]; do
24
25
  case "$1" in
25
26
  --claude-only)
27
+ if [ "$INSTALL_CLAUDE" -eq 0 ]; then
28
+ echo "--claude-only and --codex-only cannot be used together" >&2
29
+ exit 1
30
+ fi
26
31
  INSTALL_CLAUDE=1
27
32
  INSTALL_CODEX=0
28
33
  ;;
29
34
  --codex-only)
35
+ if [ "$INSTALL_CODEX" -eq 0 ]; then
36
+ echo "--claude-only and --codex-only cannot be used together" >&2
37
+ exit 1
38
+ fi
30
39
  INSTALL_CLAUDE=0
31
40
  INSTALL_CODEX=1
32
41
  ;;
@@ -34,8 +43,7 @@ while [ "$#" -gt 0 ]; do
34
43
  DRY_RUN=1
35
44
  ;;
36
45
  -h|--help)
37
- usage
38
- exit 0
46
+ SHOW_HELP=1
39
47
  ;;
40
48
  *)
41
49
  echo "Unknown option: $1" >&2
@@ -46,6 +54,11 @@ while [ "$#" -gt 0 ]; do
46
54
  shift
47
55
  done
48
56
 
57
+ if [ "$SHOW_HELP" -eq 1 ]; then
58
+ usage
59
+ exit 0
60
+ fi
61
+
49
62
  run() {
50
63
  if [ "$DRY_RUN" -eq 1 ]; then
51
64
  printf '[dry-run] %q' "$1"
@@ -86,7 +99,7 @@ copy_claude_settings() {
86
99
 
87
100
  backup_if_changed "$src" "$dest"
88
101
  if [ "$DRY_RUN" -eq 1 ]; then
89
- echo "[dry-run] merge '$src' into '$dest' preserving existing env and mcpServers"
102
+ echo "[dry-run] merge '$src' into '$dest' preserving existing user hooks, env and mcpServers"
90
103
  echo "[dry-run] purge legacy hook paths while merging Claude settings"
91
104
  return
92
105
  fi
@@ -157,6 +170,7 @@ remove_package_only_paths() {
157
170
  "scripts/verify/skill-invocation.test.js" \
158
171
  "scripts/verify/continuation-checks.test.js" \
159
172
  "scripts/verify/install-rules.test.js" \
173
+ "scripts/verify/learning.test.js" \
160
174
  "scripts/verify/plugin-distribution.test.js"
161
175
  do
162
176
  if [ -f "$dest/$file" ]; then
@@ -232,6 +246,13 @@ validate_retired_skill_manifest() {
232
246
  node "$ROOT_DIR/scripts/cleanup-retired-skills.js" --validate
233
247
  }
234
248
 
249
+ check_install_root() {
250
+ if [ -L "$1" ]; then
251
+ echo "Refusing symlinked install root: $1" >&2
252
+ exit 1
253
+ fi
254
+ }
255
+
235
256
  install_claude() {
236
257
  local dest="$HOME_DIR/.claude"
237
258
 
@@ -270,6 +291,13 @@ install_workflow_rules() {
270
291
  }
271
292
 
272
293
  validate_retired_skill_manifest
294
+ if [ "$INSTALL_CLAUDE" -eq 1 ]; then
295
+ check_install_root "$HOME_DIR/.claude"
296
+ fi
297
+ if [ "$INSTALL_CODEX" -eq 1 ]; then
298
+ check_install_root "$HOME_DIR/.codex"
299
+ fi
300
+
273
301
  require_rsync
274
302
 
275
303
  if [ "$INSTALL_CLAUDE" -eq 1 ]; then
@@ -15,14 +15,14 @@ const {
15
15
  getProjectContext,
16
16
  getProjectInstinctsDir,
17
17
  loadConfig,
18
- registerProject
18
+ registerProject,
19
+ shouldApply
19
20
  } = require('./project-utils')
20
21
 
21
22
  function parseArgs() {
22
23
  const args = process.argv.slice(2)
23
24
  return {
24
- apply: args.includes('--apply'),
25
- dryRun: args.includes('--dry-run') || !args.includes('--apply'),
25
+ apply: shouldApply(args),
26
26
  scope: parseStringArg(args, '--scope') || 'project',
27
27
  source: parseStringArg(args, '--source') ||
28
28
  path.join(os.homedir(), '.claude', 'homunculus', 'instincts')
@@ -63,7 +63,7 @@ function main() {
63
63
  ? getGlobalInstinctsDir(dataRoot)
64
64
  : getProjectInstinctsDir(dataRoot, context.project_id)
65
65
 
66
- if (options.scope !== 'global') {
66
+ if (options.apply && options.scope !== 'global') {
67
67
  registerProject(dataRoot, context)
68
68
  }
69
69
 
@@ -90,4 +90,9 @@ function main() {
90
90
  }
91
91
  }
92
92
 
93
- main()
93
+ try {
94
+ main()
95
+ } catch (error) {
96
+ console.error(`[Migrate] ${error.message}`)
97
+ process.exitCode = 1
98
+ }
@@ -68,6 +68,14 @@ function ensureDir(dirPath) {
68
68
  return dirPath
69
69
  }
70
70
 
71
+ function shouldApply(args) {
72
+ const apply = args.includes('--apply')
73
+ if (apply && args.includes('--dry-run')) {
74
+ throw new Error('--dry-run and --apply cannot be used together')
75
+ }
76
+ return apply
77
+ }
78
+
71
79
  function runGit(args, cwd) {
72
80
  return execFileSync('git', args, {
73
81
  cwd,
@@ -210,5 +218,6 @@ module.exports = {
210
218
  readJson,
211
219
  registerProject,
212
220
  scanInstincts,
221
+ shouldApply,
213
222
  writeJson
214
223
  }
@@ -15,16 +15,31 @@ const {
15
15
  getProjectInstinctsDir,
16
16
  loadConfig,
17
17
  parseFrontmatter,
18
- scanInstincts
18
+ scanInstincts,
19
+ shouldApply
19
20
  } = require('./project-utils')
20
21
 
22
+ function parseConfidence(value) {
23
+ if (typeof value === 'string' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value.trim())) {
24
+ value = Number(value)
25
+ }
26
+ return Number.isFinite(value) && value >= 0 && value <= 1 ? value : undefined
27
+ }
28
+
21
29
  function parseArgs() {
22
30
  const args = process.argv.slice(2)
31
+ const apply = shouldApply(args)
32
+ const flag = '--min-confidence'
33
+ const thresholds = args.filter(arg => arg === flag || arg.startsWith(`${flag}=`))
34
+ const raw = thresholds[0] === flag ? args[args.indexOf(flag) + 1] : thresholds[0]?.slice(flag.length + 1)
35
+ const minConfidence = thresholds.length === 0 ? 0.7 : parseConfidence(raw)
36
+ if (thresholds.length > 1 || minConfidence === undefined) {
37
+ throw new Error('--min-confidence requires a single number between 0 and 1')
38
+ }
23
39
  return {
24
- apply: args.includes('--apply'),
25
- dryRun: args.includes('--dry-run') || !args.includes('--apply'),
40
+ apply,
26
41
  projectId: parseStringArg(args, '--project-id'),
27
- minConfidence: parseFloat(parseStringArg(args, '--min-confidence') || '0.7')
42
+ minConfidence
28
43
  }
29
44
  }
30
45
 
@@ -51,11 +66,8 @@ function main() {
51
66
  for (const fileInfo of files) {
52
67
  const content = fs.readFileSync(fileInfo.path, 'utf8')
53
68
  const { meta } = parseFrontmatter(content)
54
- const confidence = typeof meta.confidence === 'number'
55
- ? meta.confidence
56
- : parseFloat(meta.confidence) || 0
57
-
58
- if (confidence < options.minConfidence) continue
69
+ const confidence = parseConfidence(meta.confidence)
70
+ if (confidence === undefined || confidence < options.minConfidence) continue
59
71
 
60
72
  const destination = path.join(globalInstinctsDir, fileInfo.category, candidateSlug(fileInfo.path))
61
73
  candidates.push({
@@ -95,4 +107,9 @@ function main() {
95
107
  }
96
108
  }
97
109
 
98
- main()
110
+ try {
111
+ main()
112
+ } catch (error) {
113
+ console.error(`[Promote] ${error.message}`)
114
+ process.exitCode = 1
115
+ }