claude-everything-workflow 0.1.0
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.
- package/AGENTS.md +36 -0
- package/CLAUDE.md +7 -0
- package/LICENSE +22 -0
- package/README.md +369 -0
- package/agents/architect.md +59 -0
- package/agents/code-reviewer.md +57 -0
- package/agents/database-reviewer.md +44 -0
- package/agents/e2e-runner.md +153 -0
- package/agents/harness-optimizer.md +92 -0
- package/agents/planner.md +124 -0
- package/agents/refactor-cleaner.md +54 -0
- package/agents/security-reviewer.md +47 -0
- package/agents/tdd-guide.md +101 -0
- package/bin/claude-everything-workflow.js +91 -0
- package/commands/code-review.md +27 -0
- package/commands/e2e.md +28 -0
- package/commands/evolve.md +42 -0
- package/commands/harness-audit.md +27 -0
- package/commands/instinct-status.md +38 -0
- package/commands/learn-eval.md +91 -0
- package/commands/pr.md +88 -0
- package/commands/projects.md +27 -0
- package/commands/promote.md +29 -0
- package/commands/prune.md +46 -0
- package/commands/tdd.md +27 -0
- package/commands/verify.md +93 -0
- package/homunculus/instincts/personal/always-test-first.md +28 -0
- package/homunculus/instincts/personal/pr-ci-quality-gate.md +30 -0
- package/hooks/check-console-log.js +37 -0
- package/hooks/commit-quality.js +143 -0
- package/hooks/evaluate-session.js +59 -0
- package/hooks/pre-compact.js +92 -0
- package/hooks/runtime/hook-flags.js +40 -0
- package/hooks/runtime/run-with-flags.js +141 -0
- package/hooks/runtime/session-utils.js +45 -0
- package/hooks/session-end.js +62 -0
- package/hooks/session-start.js +60 -0
- package/package.json +48 -0
- package/references/agents/database-reviewer.md +657 -0
- package/references/agents/refactor-cleaner.md +75 -0
- package/references/agents/security-reviewer.md +542 -0
- package/rules/01-base.md +49 -0
- package/rules/02-code-size.md +13 -0
- package/rules/03-architecture.md +64 -0
- package/rules/04-error-handling.md +27 -0
- package/rules/05-git-workflow.md +56 -0
- package/rules/06-comments.md +44 -0
- package/rules/07-forbidden.md +43 -0
- package/rules/08-ecc-integration.md +46 -0
- package/rules/common/agent-orchestration.md +54 -0
- package/rules/common/context-hygiene.md +85 -0
- package/rules/common/harness-engineering.md +46 -0
- package/rules/common/hooks.md +87 -0
- package/rules/common/implementation.md +25 -0
- package/rules/common/performance.md +71 -0
- package/rules/common/pr-automation.md +73 -0
- package/rules/common/security.md +19 -0
- package/rules/common/skills-learning.md +39 -0
- package/rules/common/testing.md +68 -0
- package/scripts/install.ps1 +286 -0
- package/scripts/install.sh +214 -0
- package/scripts/learning/migrate-homunculus.js +93 -0
- package/scripts/learning/project-utils.js +214 -0
- package/scripts/learning/projects.js +60 -0
- package/scripts/learning/promote.js +98 -0
- package/scripts/learning/review-confidence.js +455 -0
- package/scripts/verify-harness.js +868 -0
- package/settings.json +77 -0
- package/skills/brainstorming/SKILL.md +185 -0
- package/skills/brainstorming/agents/openai.yaml +3 -0
- package/skills/brainstorming/scripts/frame-template.html +214 -0
- package/skills/brainstorming/scripts/helper.js +88 -0
- package/skills/brainstorming/scripts/server.cjs +354 -0
- package/skills/brainstorming/scripts/start-server.sh +148 -0
- package/skills/brainstorming/scripts/stop-server.sh +56 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +287 -0
- package/skills/continuous-learning-v2/SKILL.md +74 -0
- package/skills/continuous-learning-v2/agents/observer.md +129 -0
- package/skills/continuous-learning-v2/agents/start-observer.sh +83 -0
- package/skills/continuous-learning-v2/config.json +58 -0
- package/skills/continuous-learning-v2/hooks/observe-v2.js +144 -0
- package/skills/documentation-lookup/SKILL.md +90 -0
- package/skills/e2e-testing/SKILL.md +326 -0
- package/skills/executing-plans/SKILL.md +66 -0
- package/skills/find-skills/SKILL.md +142 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +356 -0
- package/skills/skill-creator/references/output-patterns.md +82 -0
- package/skills/skill-creator/references/workflows.md +28 -0
- package/skills/skill-creator/scripts/init_skill.py +303 -0
- package/skills/skill-creator/scripts/package_skill.py +110 -0
- package/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/skills/systematic-debugging/SKILL.md +59 -0
- package/skills/test-driven-development/SKILL.md +71 -0
- package/skills/using-git-worktrees/SKILL.md +64 -0
- package/skills/verification-before-completion/SKILL.md +77 -0
- package/skills/writing-plans/SKILL.md +183 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# PR 自动化与 CI 质量门
|
|
2
|
+
|
|
3
|
+
本规则沉淀自成熟 monorepo 的 PR 工作流:本地先分层验证,CI 再并行复核,PR 描述必须可审阅、可追溯、可回滚。
|
|
4
|
+
|
|
5
|
+
## 目标
|
|
6
|
+
|
|
7
|
+
- 提交前尽早发现 lint、单测、构建、E2E 问题。
|
|
8
|
+
- 避免把无关脏文件、临时备份文件或未验证变更混入 PR。
|
|
9
|
+
- 让 PR 描述包含背景、改动、验证结果和风险点。
|
|
10
|
+
- 用户明确要求推送时可直接执行;创建 PR 前保留用户确认,不静默创建 PR。
|
|
11
|
+
|
|
12
|
+
## 分支与工作区
|
|
13
|
+
|
|
14
|
+
1. 不要在 `main`、`master`、`prod` 等受保护分支上直接提交。
|
|
15
|
+
2. 开始 PR 流程前运行 `git status --short --branch`,区分本次任务改动和无关脏文件。
|
|
16
|
+
3. 只暂存本次任务相关文件;遇到用户已有修改,保留并说明,不要回滚。
|
|
17
|
+
4. 提交信息使用 conventional commit。
|
|
18
|
+
|
|
19
|
+
## 分层验证
|
|
20
|
+
|
|
21
|
+
优先按改动范围选择最小验证,再在 PR 前补齐完整质量门。
|
|
22
|
+
|
|
23
|
+
| 层级 | 目的 | 常见命令 |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| 仓库卫生 | 捕获临时文件、备份文件、调试残留 | `pnpm lint:repo-files`、自定义脚本 |
|
|
26
|
+
| Lint / Format | 捕获风格、导入顺序和明显 bug | `pnpm lint`、目标文件 lint |
|
|
27
|
+
| 单元测试 | 覆盖纯逻辑、服务、组件和工具函数 | `pnpm test`、`pnpm --filter <pkg> test` |
|
|
28
|
+
| 构建 / 类型 | 验证类型边界和打包产物 | `pnpm build`、`pnpm --filter <pkg> build` |
|
|
29
|
+
| E2E | 验证关键用户路径和跨服务集成 | `pnpm test:e2e`、`npx playwright test` |
|
|
30
|
+
|
|
31
|
+
如果仓库是 monorepo,先识别 package 依赖。内部 package 以 `dist/` 暴露时,consumer 测试或构建前必须先构建被依赖 package。
|
|
32
|
+
|
|
33
|
+
## E2E 最佳实践
|
|
34
|
+
|
|
35
|
+
- E2E 使用独立目录,例如 `e2e/`,配置 `playwright.config`、`fixtures/`、`helpers/`、`tests/`。
|
|
36
|
+
- `globalSetup` 先等待 API 和 Web 健康检查,服务未就绪时明确失败。
|
|
37
|
+
- 本地 worktree 使用独立 `.env.worktree` 或等价机制隔离端口和环境变量。
|
|
38
|
+
- 测试认证优先使用专用 bypass token、测试账号或 fixture,不依赖真实用户会话。
|
|
39
|
+
- 对网络、SSE、外部模型等不稳定边界,优先 mock 可控响应;真正集成 smoke test 单独标记。
|
|
40
|
+
- CI 中启用失败制品:Playwright trace、screenshot、HTML report、test-results。
|
|
41
|
+
|
|
42
|
+
## CI 工作流
|
|
43
|
+
|
|
44
|
+
推荐把 PR checks 拆成独立 job:
|
|
45
|
+
|
|
46
|
+
1. `lint`:安装依赖后运行仓库 lint。
|
|
47
|
+
2. `test`:构建内部 package 后运行后端、前端或共享包单测。
|
|
48
|
+
3. `e2e`:准备环境变量、恢复 Playwright 浏览器缓存、运行 E2E,失败时上传制品。
|
|
49
|
+
|
|
50
|
+
CI 应设置 concurrency,新的 PR 更新取消旧运行,避免重复消耗资源。
|
|
51
|
+
|
|
52
|
+
## PR 描述
|
|
53
|
+
|
|
54
|
+
没有仓库模板时,默认使用以下结构:
|
|
55
|
+
|
|
56
|
+
```markdown
|
|
57
|
+
## 背景
|
|
58
|
+
|
|
59
|
+
## 核心改动
|
|
60
|
+
|
|
61
|
+
## 验证
|
|
62
|
+
- [ ] 命令:结果
|
|
63
|
+
|
|
64
|
+
## 风险与回滚
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
验证项必须写真实执行结果。未运行的检查要明确写“未运行”并说明原因。
|
|
68
|
+
|
|
69
|
+
## 自动化边界
|
|
70
|
+
|
|
71
|
+
- 可以自动检查状态、运行验证、整理提交内容和草拟 PR 描述。
|
|
72
|
+
- 用户明确要求推送分支时可直接执行;创建 PR、合并 PR 属于外部写操作,执行前必须向用户确认。
|
|
73
|
+
- 检查失败时先修复可安全修复的问题,再重跑相关验证;不要跳过失败检查直接提交。
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 安全优先原则
|
|
2
|
+
|
|
3
|
+
## 必须遵守
|
|
4
|
+
|
|
5
|
+
| 规则 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| 输入验证 | 所有外部输入必须验证 |
|
|
8
|
+
| 敏感信息保护 | 禁止硬编码 API keys/tokens/secrets |
|
|
9
|
+
| 安全检查 | 不绕过验证 hooks |
|
|
10
|
+
| 沙箱隔离 | 危险操作使用沙箱环境 |
|
|
11
|
+
|
|
12
|
+
## AgentShield 集成
|
|
13
|
+
|
|
14
|
+
提交前按风险运行安全扫描:
|
|
15
|
+
|
|
16
|
+
- SQL 注入检测
|
|
17
|
+
- XSS 漏洞检测
|
|
18
|
+
- 敏感信息泄露检测
|
|
19
|
+
- 依赖漏洞扫描
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Skills 与持续学习
|
|
2
|
+
|
|
3
|
+
## Skills 工作流
|
|
4
|
+
|
|
5
|
+
每个 skill 应包含:
|
|
6
|
+
|
|
7
|
+
- **When to Use**:何时使用。
|
|
8
|
+
- **How It Works**:工作原理。
|
|
9
|
+
- **Examples**:实际示例。
|
|
10
|
+
- **Codemaps**:代码库导航地图,可选。
|
|
11
|
+
|
|
12
|
+
保持 skill 精简;详细参考内容应拆到 references,并按需读取。
|
|
13
|
+
|
|
14
|
+
## 按需学习
|
|
15
|
+
|
|
16
|
+
- 默认不后台学习,不持续采集大上下文。
|
|
17
|
+
- 解决非平凡问题后,优先使用 `/learn-eval --preview` 评估是否值得保存。
|
|
18
|
+
- 确认模式可复用后,再运行 `/learn-eval` 保存。
|
|
19
|
+
- 学习产物必须按分类保存到 `skills/learn/<category>/`,例如 `skills/learn/pr/xxx.md`;禁止直接平铺到 `skills/learn/` 根目录。
|
|
20
|
+
- `homunculus`、project instincts、global instincts 和 `observations.jsonl` 只作为观察、候选或迁移来源;最终可复用学习产物以 `skills/learn/<category>/` 为准。
|
|
21
|
+
- 后台观察或 observer 只在明确需要时开启。
|
|
22
|
+
|
|
23
|
+
## 外部 Skill 仓库学习
|
|
24
|
+
|
|
25
|
+
从外部 skill、agent 或 command 仓库学习时,先提炼模式,再决定是否落地:
|
|
26
|
+
|
|
27
|
+
1. 识别它修复的具体 agent 失败模式,例如需求未澄清、未复现就修复、测试铺太开、架构建议泛泛而谈。
|
|
28
|
+
2. 映射到本项目已有层次:`rules/` 放长期硬规则,`skills/` 放自动触发能力,`agents/` 放隔离委托,`commands/` 放用户主动入口,`hooks/` 放可验证的自动检查。
|
|
29
|
+
3. 优先保存为 `skills/learn/<category>/` 下的学习模式,验证确实高频、稳定、可组合后再演化为正式 skill、agent 或 command。
|
|
30
|
+
4. 不整段复制外部仓库内容;只保留触发条件、执行步骤、验证闭环和本项目特定约束。
|
|
31
|
+
5. 涉及 README、命令入口、发布清单或安装脚本时,同步更新验证脚本,防止索引漂移。
|
|
32
|
+
|
|
33
|
+
评估问题:
|
|
34
|
+
|
|
35
|
+
- 是否有明确触发条件和退出条件?
|
|
36
|
+
- 是否能减少上下文噪音或工具误用?
|
|
37
|
+
- 是否有可运行的测试、脚本、审查清单或人工验收标准?
|
|
38
|
+
- 是否和现有规则重复,应该吸收而不是新增?
|
|
39
|
+
- 是否符合本项目中文交流和高风险操作确认规则?
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# 测试与验证
|
|
2
|
+
|
|
3
|
+
## 默认验证策略
|
|
4
|
+
|
|
5
|
+
| 场景 | 验证方式 |
|
|
6
|
+
| -------------- | ----------------------------------- |
|
|
7
|
+
| 小改动 | 运行相关单测 |
|
|
8
|
+
| 后端逻辑改动 | 相关单测 + `pnpm exec tsc --noEmit` |
|
|
9
|
+
| 提交前 | `pnpm test` + `pnpm run build` |
|
|
10
|
+
| 前端单文件改动 | 对目标文件运行 ESLint |
|
|
11
|
+
| 前端提交前 | 项目能承受时再运行全量 build |
|
|
12
|
+
| PR 前 | lint + 相关单测 + build + 关键路径 E2E |
|
|
13
|
+
|
|
14
|
+
## 验证分层
|
|
15
|
+
|
|
16
|
+
成熟项目应把验证拆成可组合层级,而不是每次都盲目全量运行:
|
|
17
|
+
|
|
18
|
+
1. 仓库卫生:临时文件、备份文件、调试残留、配置漂移。
|
|
19
|
+
2. Lint / Format:风格、导入顺序、静态问题。
|
|
20
|
+
3. 单元测试:纯逻辑、服务、组件、工具函数。
|
|
21
|
+
4. 构建 / 类型:跨模块类型边界、产物生成、框架编译。
|
|
22
|
+
5. E2E:核心用户路径、认证、跨服务集成、发布前冒烟。
|
|
23
|
+
|
|
24
|
+
monorepo 中先识别 package 依赖。若内部 package 以 `dist/` 暴露,consumer 测试和构建前必须先构建上游 package。
|
|
25
|
+
|
|
26
|
+
## 验证频率
|
|
27
|
+
|
|
28
|
+
- 中间步骤只运行与当前改动范围匹配的最小必要验证。
|
|
29
|
+
- 完成阶段统一运行一次完整的相关验证。
|
|
30
|
+
- 遇到失败、跨模块影响、高风险改动、发布或 PR 前质量门时,立即升级验证范围。
|
|
31
|
+
- 不要因为每次小改动都默认运行全量测试或完整 build;验证范围应和风险、改动面、反馈成本匹配。
|
|
32
|
+
- “完整验证”不是每次编辑后的默认动作,而是阶段性质量门;不能为了省时间跳过最终质量门。
|
|
33
|
+
- 无法运行完整验证时,必须说明原因、已运行的替代检查和剩余风险。
|
|
34
|
+
|
|
35
|
+
## Build 使用原则
|
|
36
|
+
|
|
37
|
+
- 不要每次改动都默认打包。
|
|
38
|
+
- 涉及跨模块类型、接口、store、workflow 或构建配置时,运行 `pnpm run build` 确认最终可编译。
|
|
39
|
+
- 如果全量 build 成本高,优先运行更窄的类型检查、单测或目标文件 lint。
|
|
40
|
+
- 无法运行验证时,明确说明原因和剩余风险。
|
|
41
|
+
|
|
42
|
+
## TDD 工作流
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
1. 理解需求 -> 编写测试
|
|
46
|
+
2. 运行测试 -> 确认失败
|
|
47
|
+
3. 实现功能 -> 最小化实现
|
|
48
|
+
4. 运行测试 -> 确认通过
|
|
49
|
+
5. 重构代码 -> 保持测试通过
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 测试要求
|
|
53
|
+
|
|
54
|
+
| 要求 | 标准 |
|
|
55
|
+
| -------- | ------------------------- |
|
|
56
|
+
| 覆盖率 | >= 80% |
|
|
57
|
+
| 测试先行 | 新功能/bug 修复优先补测试 |
|
|
58
|
+
| 关键路径 | 合并前覆盖或明确缺口 |
|
|
59
|
+
| 提交前 | 运行与改动范围匹配的验证 |
|
|
60
|
+
|
|
61
|
+
## 端到端测试
|
|
62
|
+
|
|
63
|
+
- 技能:`skills/e2e-testing/SKILL.md`,包含 Playwright 目录结构、POM、配置、CI、制品、flake 处理。
|
|
64
|
+
- 代理:`e2e-runner`,默认 CLI,MCP 仅用于探索和调试。
|
|
65
|
+
- 入口:`/e2e`,复杂或从零搭建时可委派 `e2e-runner`。
|
|
66
|
+
- E2E 应有 `globalSetup` 或等价健康检查,等待 API/Web ready 后再跑用例。
|
|
67
|
+
- 本地多 worktree 开发时,端口和环境变量应隔离,例如 `.env.worktree`。
|
|
68
|
+
- CI 失败时上传 Playwright trace、screenshot、HTML report 和 `test-results`。
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[switch]$ClaudeOnly,
|
|
3
|
+
[switch]$CodexOnly,
|
|
4
|
+
[switch]$DryRun
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
$ErrorActionPreference = "Stop"
|
|
8
|
+
|
|
9
|
+
$RootDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
|
10
|
+
$HomeDir = if ($env:USERPROFILE) { $env:USERPROFILE } else { $HOME }
|
|
11
|
+
|
|
12
|
+
if (-not $HomeDir) {
|
|
13
|
+
throw "USERPROFILE or HOME is required"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
$InstallClaude = -not $CodexOnly
|
|
17
|
+
$InstallCodex = -not $ClaudeOnly
|
|
18
|
+
|
|
19
|
+
function Invoke-InstallCommand {
|
|
20
|
+
param(
|
|
21
|
+
[scriptblock]$Action,
|
|
22
|
+
[string]$Description
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if ($DryRun) {
|
|
26
|
+
Write-Host "[dry-run] $Description"
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
& $Action
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Backup-IfChanged {
|
|
34
|
+
param(
|
|
35
|
+
[string]$Source,
|
|
36
|
+
[string]$Destination
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (-not (Test-Path -LiteralPath $Destination)) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
$sourceHash = Get-FileHash -LiteralPath $Source -Algorithm SHA256
|
|
44
|
+
$destHash = Get-FileHash -LiteralPath $Destination -Algorithm SHA256
|
|
45
|
+
if ($sourceHash.Hash -eq $destHash.Hash) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
$backup = "$Destination.bak.$(Get-Date -Format 'yyyyMMddHHmmss')"
|
|
50
|
+
Write-Host "Backup: $Destination -> $backup"
|
|
51
|
+
Invoke-InstallCommand `
|
|
52
|
+
-Description "Copy-Item '$Destination' '$backup'" `
|
|
53
|
+
-Action { Copy-Item -LiteralPath $Destination -Destination $backup -Force }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Copy-ConfigFile {
|
|
57
|
+
param(
|
|
58
|
+
[string]$Source,
|
|
59
|
+
[string]$Destination
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
Backup-IfChanged -Source $Source -Destination $Destination
|
|
63
|
+
Invoke-InstallCommand `
|
|
64
|
+
-Description "Copy-Item '$Source' '$Destination'" `
|
|
65
|
+
-Action { Copy-Item -LiteralPath $Source -Destination $Destination -Force }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function Copy-ClaudeSettings {
|
|
69
|
+
param(
|
|
70
|
+
[string]$Source,
|
|
71
|
+
[string]$Destination
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
Backup-IfChanged -Source $Source -Destination $Destination
|
|
75
|
+
|
|
76
|
+
if ($DryRun) {
|
|
77
|
+
Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing env and mcpServers"
|
|
78
|
+
return
|
|
79
|
+
}
|
|
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
|
+
}
|
|
87
|
+
|
|
88
|
+
$merged = [ordered]@{}
|
|
89
|
+
|
|
90
|
+
foreach ($property in $existingSettings.PSObject.Properties) {
|
|
91
|
+
$merged[$property.Name] = $property.Value
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
foreach ($property in $sourceSettings.PSObject.Properties) {
|
|
95
|
+
$merged[$property.Name] = $property.Value
|
|
96
|
+
}
|
|
97
|
+
|
|
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
|
+
}
|
|
112
|
+
|
|
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
|
+
}
|
|
127
|
+
|
|
128
|
+
[pscustomobject]$merged | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $Destination -Encoding UTF8
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function Convert-ClaudeSettingsHookPaths {
|
|
132
|
+
param([string]$SettingsPath)
|
|
133
|
+
|
|
134
|
+
if ($DryRun) {
|
|
135
|
+
Write-Host "[dry-run] Convert hook paths in '$SettingsPath' to Windows absolute paths"
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
$settings = Get-Content -LiteralPath $SettingsPath -Raw | ConvertFrom-Json
|
|
140
|
+
$claudeHome = Join-Path $HomeDir ".claude"
|
|
141
|
+
|
|
142
|
+
function Update-Commands {
|
|
143
|
+
param($Value)
|
|
144
|
+
|
|
145
|
+
if ($null -eq $Value) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if ($Value -is [System.Array]) {
|
|
150
|
+
foreach ($item in $Value) {
|
|
151
|
+
Update-Commands -Value $item
|
|
152
|
+
}
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if ($Value -isnot [psobject]) {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if ($Value.PSObject.Properties.Name -contains "command" -and $Value.command -is [string]) {
|
|
161
|
+
$Value.command = $Value.command.Replace('$HOME/.claude', $claudeHome)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
foreach ($property in $Value.PSObject.Properties) {
|
|
165
|
+
Update-Commands -Value $property.Value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Update-Commands -Value $settings.hooks
|
|
170
|
+
$settings | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $SettingsPath -Encoding UTF8
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function Copy-DirectoryMerge {
|
|
174
|
+
param(
|
|
175
|
+
[string]$Name,
|
|
176
|
+
[string]$DestinationRoot
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
$sourceDir = Join-Path $RootDir $Name
|
|
180
|
+
if (-not (Test-Path -LiteralPath $sourceDir -PathType Container)) {
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
$destDir = Join-Path $DestinationRoot $Name
|
|
185
|
+
Invoke-InstallCommand `
|
|
186
|
+
-Description "New-Item -ItemType Directory '$destDir'" `
|
|
187
|
+
-Action { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }
|
|
188
|
+
|
|
189
|
+
Invoke-InstallCommand `
|
|
190
|
+
-Description "Copy-Item '$sourceDir\*' '$destDir' -Recurse -Force" `
|
|
191
|
+
-Action { Copy-Item -Path (Join-Path $sourceDir '*') -Destination $destDir -Recurse -Force }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function Install-SharedDirs {
|
|
195
|
+
param([string]$Destination)
|
|
196
|
+
|
|
197
|
+
$dirs = @(
|
|
198
|
+
"rules",
|
|
199
|
+
"agents",
|
|
200
|
+
"commands",
|
|
201
|
+
"scripts",
|
|
202
|
+
"hooks",
|
|
203
|
+
"skills",
|
|
204
|
+
"homunculus",
|
|
205
|
+
"references"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
foreach ($dir in $dirs) {
|
|
209
|
+
Copy-DirectoryMerge -Name $dir -DestinationRoot $Destination
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function Remove-ObsoleteWorkflowPaths {
|
|
214
|
+
param([string]$Destination)
|
|
215
|
+
|
|
216
|
+
$obsoleteFiles = @(
|
|
217
|
+
"scripts\hooks\run-with-flags.js",
|
|
218
|
+
"scripts\hooks\commit-quality.js",
|
|
219
|
+
"scripts\hooks\session-start.js",
|
|
220
|
+
"scripts\hooks\session-end.js",
|
|
221
|
+
"scripts\lib\hook-flags.js",
|
|
222
|
+
"scripts\lib\utils.js",
|
|
223
|
+
"hooks\review-confidence.js"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
foreach ($relative in $obsoleteFiles) {
|
|
227
|
+
$target = Join-Path $Destination $relative
|
|
228
|
+
if (Test-Path -LiteralPath $target -PathType Leaf) {
|
|
229
|
+
Invoke-InstallCommand `
|
|
230
|
+
-Description "Remove-Item '$target'" `
|
|
231
|
+
-Action { Remove-Item -LiteralPath $target -Force }
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
foreach ($relative in @("scripts\hooks", "scripts\lib")) {
|
|
236
|
+
$target = Join-Path $Destination $relative
|
|
237
|
+
if (Test-Path -LiteralPath $target -PathType Container) {
|
|
238
|
+
$children = Get-ChildItem -LiteralPath $target -Force
|
|
239
|
+
if ($children.Count -eq 0) {
|
|
240
|
+
Invoke-InstallCommand `
|
|
241
|
+
-Description "Remove-Item '$target'" `
|
|
242
|
+
-Action { Remove-Item -LiteralPath $target -Force }
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function Install-ClaudeWorkflow {
|
|
249
|
+
$dest = Join-Path $HomeDir ".claude"
|
|
250
|
+
|
|
251
|
+
Write-Host "Installing Claude workflow to $dest"
|
|
252
|
+
Invoke-InstallCommand `
|
|
253
|
+
-Description "New-Item -ItemType Directory '$dest'" `
|
|
254
|
+
-Action { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
|
|
255
|
+
|
|
256
|
+
Remove-ObsoleteWorkflowPaths -Destination $dest
|
|
257
|
+
Copy-ConfigFile -Source (Join-Path $RootDir "CLAUDE.md") -Destination (Join-Path $dest "CLAUDE.md")
|
|
258
|
+
Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md")
|
|
259
|
+
$settingsPath = Join-Path $dest "settings.json"
|
|
260
|
+
Copy-ClaudeSettings -Source (Join-Path $RootDir "settings.json") -Destination $settingsPath
|
|
261
|
+
Convert-ClaudeSettingsHookPaths -SettingsPath $settingsPath
|
|
262
|
+
Install-SharedDirs -Destination $dest
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function Install-CodexWorkflow {
|
|
266
|
+
$dest = Join-Path $HomeDir ".codex"
|
|
267
|
+
|
|
268
|
+
Write-Host "Installing Codex workflow to $dest"
|
|
269
|
+
Invoke-InstallCommand `
|
|
270
|
+
-Description "New-Item -ItemType Directory '$dest'" `
|
|
271
|
+
-Action { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
|
|
272
|
+
|
|
273
|
+
Remove-ObsoleteWorkflowPaths -Destination $dest
|
|
274
|
+
Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md")
|
|
275
|
+
Install-SharedDirs -Destination $dest
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if ($InstallClaude) {
|
|
279
|
+
Install-ClaudeWorkflow
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if ($InstallCodex) {
|
|
283
|
+
Install-CodexWorkflow
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
Write-Host "Install complete."
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
|
+
HOME_DIR="${HOME:?HOME is required}"
|
|
6
|
+
|
|
7
|
+
INSTALL_CLAUDE=1
|
|
8
|
+
INSTALL_CODEX=1
|
|
9
|
+
DRY_RUN=0
|
|
10
|
+
|
|
11
|
+
usage() {
|
|
12
|
+
cat <<'EOF'
|
|
13
|
+
Usage: scripts/install.sh [options]
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--claude-only Only install to ~/.claude
|
|
17
|
+
--codex-only Only install to ~/.codex
|
|
18
|
+
--dry-run Print operations without writing files
|
|
19
|
+
-h, --help Show this help
|
|
20
|
+
EOF
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
while [ "$#" -gt 0 ]; do
|
|
24
|
+
case "$1" in
|
|
25
|
+
--claude-only)
|
|
26
|
+
INSTALL_CLAUDE=1
|
|
27
|
+
INSTALL_CODEX=0
|
|
28
|
+
;;
|
|
29
|
+
--codex-only)
|
|
30
|
+
INSTALL_CLAUDE=0
|
|
31
|
+
INSTALL_CODEX=1
|
|
32
|
+
;;
|
|
33
|
+
--dry-run)
|
|
34
|
+
DRY_RUN=1
|
|
35
|
+
;;
|
|
36
|
+
-h|--help)
|
|
37
|
+
usage
|
|
38
|
+
exit 0
|
|
39
|
+
;;
|
|
40
|
+
*)
|
|
41
|
+
echo "Unknown option: $1" >&2
|
|
42
|
+
usage >&2
|
|
43
|
+
exit 1
|
|
44
|
+
;;
|
|
45
|
+
esac
|
|
46
|
+
shift
|
|
47
|
+
done
|
|
48
|
+
|
|
49
|
+
run() {
|
|
50
|
+
if [ "$DRY_RUN" -eq 1 ]; then
|
|
51
|
+
printf '[dry-run] %q' "$1"
|
|
52
|
+
shift
|
|
53
|
+
for arg in "$@"; do
|
|
54
|
+
printf ' %q' "$arg"
|
|
55
|
+
done
|
|
56
|
+
printf '\n'
|
|
57
|
+
else
|
|
58
|
+
"$@"
|
|
59
|
+
fi
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
backup_if_changed() {
|
|
63
|
+
local src="$1"
|
|
64
|
+
local dest="$2"
|
|
65
|
+
|
|
66
|
+
if [ ! -f "$dest" ] || cmp -s "$src" "$dest"; then
|
|
67
|
+
return
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
local backup="${dest}.bak.$(date +%Y%m%d%H%M%S)"
|
|
71
|
+
echo "Backup: $dest -> $backup"
|
|
72
|
+
run cp "$dest" "$backup"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
copy_file() {
|
|
76
|
+
local src="$1"
|
|
77
|
+
local dest="$2"
|
|
78
|
+
|
|
79
|
+
backup_if_changed "$src" "$dest"
|
|
80
|
+
run cp "$src" "$dest"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
copy_claude_settings() {
|
|
84
|
+
local src="$1"
|
|
85
|
+
local dest="$2"
|
|
86
|
+
|
|
87
|
+
backup_if_changed "$src" "$dest"
|
|
88
|
+
if [ "$DRY_RUN" -eq 1 ]; then
|
|
89
|
+
echo "[dry-run] merge '$src' into '$dest' preserving existing env and mcpServers"
|
|
90
|
+
return
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
node - "$src" "$dest" <<'NODE'
|
|
94
|
+
const fs = require('fs')
|
|
95
|
+
|
|
96
|
+
const [, , sourcePath, destinationPath] = process.argv
|
|
97
|
+
const source = JSON.parse(fs.readFileSync(sourcePath, 'utf8'))
|
|
98
|
+
const existing = fs.existsSync(destinationPath)
|
|
99
|
+
? JSON.parse(fs.readFileSync(destinationPath, 'utf8'))
|
|
100
|
+
: {}
|
|
101
|
+
|
|
102
|
+
const merged = {
|
|
103
|
+
...existing,
|
|
104
|
+
...source,
|
|
105
|
+
env: {
|
|
106
|
+
...(source.env || {}),
|
|
107
|
+
...(existing.env || {})
|
|
108
|
+
},
|
|
109
|
+
mcpServers: {
|
|
110
|
+
...(source.mcpServers || {}),
|
|
111
|
+
...(existing.mcpServers || {})
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fs.writeFileSync(destinationPath, JSON.stringify(merged, null, 2) + '\n')
|
|
116
|
+
NODE
|
|
117
|
+
chmod 600 "$dest"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
copy_dir() {
|
|
121
|
+
local name="$1"
|
|
122
|
+
local dest_root="$2"
|
|
123
|
+
|
|
124
|
+
if [ ! -d "$ROOT_DIR/$name" ]; then
|
|
125
|
+
return
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
run mkdir -p "$dest_root/$name"
|
|
129
|
+
run rsync -a "$ROOT_DIR/$name/" "$dest_root/$name/"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
require_rsync() {
|
|
133
|
+
if [ "$DRY_RUN" -eq 1 ]; then
|
|
134
|
+
return
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
if ! command -v rsync >/dev/null 2>&1; then
|
|
138
|
+
echo "rsync is required. Please install rsync and retry." >&2
|
|
139
|
+
exit 1
|
|
140
|
+
fi
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
install_shared_dirs() {
|
|
144
|
+
local dest="$1"
|
|
145
|
+
|
|
146
|
+
copy_dir rules "$dest"
|
|
147
|
+
copy_dir agents "$dest"
|
|
148
|
+
copy_dir commands "$dest"
|
|
149
|
+
copy_dir scripts "$dest"
|
|
150
|
+
copy_dir hooks "$dest"
|
|
151
|
+
copy_dir skills "$dest"
|
|
152
|
+
copy_dir homunculus "$dest"
|
|
153
|
+
copy_dir references "$dest"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
remove_obsolete_workflow_paths() {
|
|
157
|
+
local dest="$1"
|
|
158
|
+
local file
|
|
159
|
+
local dir
|
|
160
|
+
|
|
161
|
+
for file in \
|
|
162
|
+
"scripts/hooks/run-with-flags.js" \
|
|
163
|
+
"scripts/hooks/commit-quality.js" \
|
|
164
|
+
"scripts/hooks/session-start.js" \
|
|
165
|
+
"scripts/hooks/session-end.js" \
|
|
166
|
+
"scripts/lib/hook-flags.js" \
|
|
167
|
+
"scripts/lib/utils.js" \
|
|
168
|
+
"hooks/review-confidence.js"
|
|
169
|
+
do
|
|
170
|
+
if [ -f "$dest/$file" ]; then
|
|
171
|
+
run rm -f "$dest/$file"
|
|
172
|
+
fi
|
|
173
|
+
done
|
|
174
|
+
|
|
175
|
+
for dir in "scripts/hooks" "scripts/lib"; do
|
|
176
|
+
if [ -d "$dest/$dir" ] && [ -z "$(find "$dest/$dir" -mindepth 1 -print -quit)" ]; then
|
|
177
|
+
run rmdir "$dest/$dir"
|
|
178
|
+
fi
|
|
179
|
+
done
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
install_claude() {
|
|
183
|
+
local dest="$HOME_DIR/.claude"
|
|
184
|
+
|
|
185
|
+
echo "Installing Claude workflow to $dest"
|
|
186
|
+
run mkdir -p "$dest"
|
|
187
|
+
remove_obsolete_workflow_paths "$dest"
|
|
188
|
+
copy_file "$ROOT_DIR/CLAUDE.md" "$dest/CLAUDE.md"
|
|
189
|
+
copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md"
|
|
190
|
+
copy_claude_settings "$ROOT_DIR/settings.json" "$dest/settings.json"
|
|
191
|
+
install_shared_dirs "$dest"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
install_codex() {
|
|
195
|
+
local dest="$HOME_DIR/.codex"
|
|
196
|
+
|
|
197
|
+
echo "Installing Codex workflow to $dest"
|
|
198
|
+
run mkdir -p "$dest"
|
|
199
|
+
remove_obsolete_workflow_paths "$dest"
|
|
200
|
+
copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md"
|
|
201
|
+
install_shared_dirs "$dest"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
require_rsync
|
|
205
|
+
|
|
206
|
+
if [ "$INSTALL_CLAUDE" -eq 1 ]; then
|
|
207
|
+
install_claude
|
|
208
|
+
fi
|
|
209
|
+
|
|
210
|
+
if [ "$INSTALL_CODEX" -eq 1 ]; then
|
|
211
|
+
install_codex
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
echo "Install complete."
|