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.
Files changed (99) hide show
  1. package/AGENTS.md +36 -0
  2. package/CLAUDE.md +7 -0
  3. package/LICENSE +22 -0
  4. package/README.md +369 -0
  5. package/agents/architect.md +59 -0
  6. package/agents/code-reviewer.md +57 -0
  7. package/agents/database-reviewer.md +44 -0
  8. package/agents/e2e-runner.md +153 -0
  9. package/agents/harness-optimizer.md +92 -0
  10. package/agents/planner.md +124 -0
  11. package/agents/refactor-cleaner.md +54 -0
  12. package/agents/security-reviewer.md +47 -0
  13. package/agents/tdd-guide.md +101 -0
  14. package/bin/claude-everything-workflow.js +91 -0
  15. package/commands/code-review.md +27 -0
  16. package/commands/e2e.md +28 -0
  17. package/commands/evolve.md +42 -0
  18. package/commands/harness-audit.md +27 -0
  19. package/commands/instinct-status.md +38 -0
  20. package/commands/learn-eval.md +91 -0
  21. package/commands/pr.md +88 -0
  22. package/commands/projects.md +27 -0
  23. package/commands/promote.md +29 -0
  24. package/commands/prune.md +46 -0
  25. package/commands/tdd.md +27 -0
  26. package/commands/verify.md +93 -0
  27. package/homunculus/instincts/personal/always-test-first.md +28 -0
  28. package/homunculus/instincts/personal/pr-ci-quality-gate.md +30 -0
  29. package/hooks/check-console-log.js +37 -0
  30. package/hooks/commit-quality.js +143 -0
  31. package/hooks/evaluate-session.js +59 -0
  32. package/hooks/pre-compact.js +92 -0
  33. package/hooks/runtime/hook-flags.js +40 -0
  34. package/hooks/runtime/run-with-flags.js +141 -0
  35. package/hooks/runtime/session-utils.js +45 -0
  36. package/hooks/session-end.js +62 -0
  37. package/hooks/session-start.js +60 -0
  38. package/package.json +48 -0
  39. package/references/agents/database-reviewer.md +657 -0
  40. package/references/agents/refactor-cleaner.md +75 -0
  41. package/references/agents/security-reviewer.md +542 -0
  42. package/rules/01-base.md +49 -0
  43. package/rules/02-code-size.md +13 -0
  44. package/rules/03-architecture.md +64 -0
  45. package/rules/04-error-handling.md +27 -0
  46. package/rules/05-git-workflow.md +56 -0
  47. package/rules/06-comments.md +44 -0
  48. package/rules/07-forbidden.md +43 -0
  49. package/rules/08-ecc-integration.md +46 -0
  50. package/rules/common/agent-orchestration.md +54 -0
  51. package/rules/common/context-hygiene.md +85 -0
  52. package/rules/common/harness-engineering.md +46 -0
  53. package/rules/common/hooks.md +87 -0
  54. package/rules/common/implementation.md +25 -0
  55. package/rules/common/performance.md +71 -0
  56. package/rules/common/pr-automation.md +73 -0
  57. package/rules/common/security.md +19 -0
  58. package/rules/common/skills-learning.md +39 -0
  59. package/rules/common/testing.md +68 -0
  60. package/scripts/install.ps1 +286 -0
  61. package/scripts/install.sh +214 -0
  62. package/scripts/learning/migrate-homunculus.js +93 -0
  63. package/scripts/learning/project-utils.js +214 -0
  64. package/scripts/learning/projects.js +60 -0
  65. package/scripts/learning/promote.js +98 -0
  66. package/scripts/learning/review-confidence.js +455 -0
  67. package/scripts/verify-harness.js +868 -0
  68. package/settings.json +77 -0
  69. package/skills/brainstorming/SKILL.md +185 -0
  70. package/skills/brainstorming/agents/openai.yaml +3 -0
  71. package/skills/brainstorming/scripts/frame-template.html +214 -0
  72. package/skills/brainstorming/scripts/helper.js +88 -0
  73. package/skills/brainstorming/scripts/server.cjs +354 -0
  74. package/skills/brainstorming/scripts/start-server.sh +148 -0
  75. package/skills/brainstorming/scripts/stop-server.sh +56 -0
  76. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  77. package/skills/brainstorming/visual-companion.md +287 -0
  78. package/skills/continuous-learning-v2/SKILL.md +74 -0
  79. package/skills/continuous-learning-v2/agents/observer.md +129 -0
  80. package/skills/continuous-learning-v2/agents/start-observer.sh +83 -0
  81. package/skills/continuous-learning-v2/config.json +58 -0
  82. package/skills/continuous-learning-v2/hooks/observe-v2.js +144 -0
  83. package/skills/documentation-lookup/SKILL.md +90 -0
  84. package/skills/e2e-testing/SKILL.md +326 -0
  85. package/skills/executing-plans/SKILL.md +66 -0
  86. package/skills/find-skills/SKILL.md +142 -0
  87. package/skills/skill-creator/LICENSE.txt +202 -0
  88. package/skills/skill-creator/SKILL.md +356 -0
  89. package/skills/skill-creator/references/output-patterns.md +82 -0
  90. package/skills/skill-creator/references/workflows.md +28 -0
  91. package/skills/skill-creator/scripts/init_skill.py +303 -0
  92. package/skills/skill-creator/scripts/package_skill.py +110 -0
  93. package/skills/skill-creator/scripts/quick_validate.py +95 -0
  94. package/skills/systematic-debugging/SKILL.md +59 -0
  95. package/skills/test-driven-development/SKILL.md +71 -0
  96. package/skills/using-git-worktrees/SKILL.md +64 -0
  97. package/skills/verification-before-completion/SKILL.md +77 -0
  98. package/skills/writing-plans/SKILL.md +183 -0
  99. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
@@ -0,0 +1,287 @@
1
+ # Visual Companion Guide
2
+
3
+ Browser-based visual brainstorming companion for showing mockups, diagrams, and options.
4
+
5
+ ## When to Use
6
+
7
+ Decide per-question, not per-session. The test: **would the user understand this better by seeing it than reading it?**
8
+
9
+ **Use the browser** when the content itself is visual:
10
+
11
+ - **UI mockups** — wireframes, layouts, navigation structures, component designs
12
+ - **Architecture diagrams** — system components, data flow, relationship maps
13
+ - **Side-by-side visual comparisons** — comparing two layouts, two color schemes, two design directions
14
+ - **Design polish** — when the question is about look and feel, spacing, visual hierarchy
15
+ - **Spatial relationships** — state machines, flowcharts, entity relationships rendered as diagrams
16
+
17
+ **Use the terminal** when the content is text or tabular:
18
+
19
+ - **Requirements and scope questions** — "what does X mean?", "which features are in scope?"
20
+ - **Conceptual A/B/C choices** — picking between approaches described in words
21
+ - **Tradeoff lists** — pros/cons, comparison tables
22
+ - **Technical decisions** — API design, data modeling, architectural approach selection
23
+ - **Clarifying questions** — anything where the answer is words, not a visual preference
24
+
25
+ A question *about* a UI topic is not automatically a visual question. "What kind of wizard do you want?" is conceptual — use the terminal. "Which of these wizard layouts feels right?" is visual — use the browser.
26
+
27
+ ## How It Works
28
+
29
+ The server watches a directory for HTML files and serves the newest one to the browser. You write HTML content to `screen_dir`, the user sees it in their browser and can click to select options. Selections are recorded to `state_dir/events` that you read on your next turn.
30
+
31
+ **Content fragments vs full documents:** If your HTML file starts with `<!DOCTYPE` or `<html`, the server serves it as-is (just injects the helper script). Otherwise, the server automatically wraps your content in the frame template — adding the header, CSS theme, selection indicator, and all interactive infrastructure. **Write content fragments by default.** Only write full documents when you need complete control over the page.
32
+
33
+ ## Starting a Session
34
+
35
+ ```bash
36
+ # Start server with persistence (mockups saved to project)
37
+ scripts/start-server.sh --project-dir /path/to/project
38
+
39
+ # Returns: {"type":"server-started","port":52341,"url":"http://localhost:52341",
40
+ # "screen_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/content",
41
+ # "state_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/state"}
42
+ ```
43
+
44
+ Save `screen_dir` and `state_dir` from the response. Tell user to open the URL.
45
+
46
+ **Finding connection info:** The server writes its startup JSON to `$STATE_DIR/server-info`. If you launched the server in the background and didn't capture stdout, read that file to get the URL and port. When using `--project-dir`, check `<project>/.superpowers/brainstorm/` for the session directory.
47
+
48
+ **Note:** Pass the project root as `--project-dir` so mockups persist in `.superpowers/brainstorm/` and survive server restarts. Without it, files go to `/tmp` and get cleaned up. Remind the user to add `.superpowers/` to `.gitignore` if it's not already there.
49
+
50
+ **Launching the server by platform:**
51
+
52
+ **Claude Code (macOS / Linux):**
53
+ ```bash
54
+ # Default mode works — the script backgrounds the server itself
55
+ scripts/start-server.sh --project-dir /path/to/project
56
+ ```
57
+
58
+ **Claude Code (Windows):**
59
+ ```bash
60
+ # Windows auto-detects and uses foreground mode, which blocks the tool call.
61
+ # Use run_in_background: true on the Bash tool call so the server survives
62
+ # across conversation turns.
63
+ scripts/start-server.sh --project-dir /path/to/project
64
+ ```
65
+ When calling this via the Bash tool, set `run_in_background: true`. Then read `$STATE_DIR/server-info` on the next turn to get the URL and port.
66
+
67
+ **Codex:**
68
+ ```bash
69
+ # Codex reaps background processes. The script auto-detects CODEX_CI and
70
+ # switches to foreground mode. Run it normally — no extra flags needed.
71
+ scripts/start-server.sh --project-dir /path/to/project
72
+ ```
73
+
74
+ **Gemini CLI:**
75
+ ```bash
76
+ # Use --foreground and set is_background: true on your shell tool call
77
+ # so the process survives across turns
78
+ scripts/start-server.sh --project-dir /path/to/project --foreground
79
+ ```
80
+
81
+ **Other environments:** The server must keep running in the background across conversation turns. If your environment reaps detached processes, use `--foreground` and launch the command with your platform's background execution mechanism.
82
+
83
+ If the URL is unreachable from your browser (common in remote/containerized setups), bind a non-loopback host:
84
+
85
+ ```bash
86
+ scripts/start-server.sh \
87
+ --project-dir /path/to/project \
88
+ --host 0.0.0.0 \
89
+ --url-host localhost
90
+ ```
91
+
92
+ Use `--url-host` to control what hostname is printed in the returned URL JSON.
93
+
94
+ ## The Loop
95
+
96
+ 1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`:
97
+ - Before each write, check that `$STATE_DIR/server-info` exists. If it doesn't (or `$STATE_DIR/server-stopped` exists), the server has shut down — restart it with `start-server.sh` before continuing. The server auto-exits after 30 minutes of inactivity.
98
+ - Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html`
99
+ - **Never reuse filenames** — each screen gets a fresh file
100
+ - Use Write tool — **never use cat/heredoc** (dumps noise into terminal)
101
+ - Server automatically serves the newest file
102
+
103
+ 2. **Tell user what to expect and end your turn:**
104
+ - Remind them of the URL (every step, not just first)
105
+ - Give a brief text summary of what's on screen (e.g., "Showing 3 layout options for the homepage")
106
+ - Ask them to respond in the terminal: "Take a look and let me know what you think. Click to select an option if you'd like."
107
+
108
+ 3. **On your next turn** — after the user responds in the terminal:
109
+ - Read `$STATE_DIR/events` if it exists — this contains the user's browser interactions (clicks, selections) as JSON lines
110
+ - Merge with the user's terminal text to get the full picture
111
+ - The terminal message is the primary feedback; `state_dir/events` provides structured interaction data
112
+
113
+ 4. **Iterate or advance** — if feedback changes current screen, write a new file (e.g., `layout-v2.html`). Only move to the next question when the current step is validated.
114
+
115
+ 5. **Unload when returning to terminal** — when the next step doesn't need the browser (e.g., a clarifying question, a tradeoff discussion), push a waiting screen to clear the stale content:
116
+
117
+ ```html
118
+ <!-- filename: waiting.html (or waiting-2.html, etc.) -->
119
+ <div style="display:flex;align-items:center;justify-content:center;min-height:60vh">
120
+ <p class="subtitle">Continuing in terminal...</p>
121
+ </div>
122
+ ```
123
+
124
+ This prevents the user from staring at a resolved choice while the conversation has moved on. When the next visual question comes up, push a new content file as usual.
125
+
126
+ 6. Repeat until done.
127
+
128
+ ## Writing Content Fragments
129
+
130
+ Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, selection indicator, and all interactive infrastructure).
131
+
132
+ **Minimal example:**
133
+
134
+ ```html
135
+ <h2>Which layout works better?</h2>
136
+ <p class="subtitle">Consider readability and visual hierarchy</p>
137
+
138
+ <div class="options">
139
+ <div class="option" data-choice="a" onclick="toggleSelect(this)">
140
+ <div class="letter">A</div>
141
+ <div class="content">
142
+ <h3>Single Column</h3>
143
+ <p>Clean, focused reading experience</p>
144
+ </div>
145
+ </div>
146
+ <div class="option" data-choice="b" onclick="toggleSelect(this)">
147
+ <div class="letter">B</div>
148
+ <div class="content">
149
+ <h3>Two Column</h3>
150
+ <p>Sidebar navigation with main content</p>
151
+ </div>
152
+ </div>
153
+ </div>
154
+ ```
155
+
156
+ That's it. No `<html>`, no CSS, no `<script>` tags needed. The server provides all of that.
157
+
158
+ ## CSS Classes Available
159
+
160
+ The frame template provides these CSS classes for your content:
161
+
162
+ ### Options (A/B/C choices)
163
+
164
+ ```html
165
+ <div class="options">
166
+ <div class="option" data-choice="a" onclick="toggleSelect(this)">
167
+ <div class="letter">A</div>
168
+ <div class="content">
169
+ <h3>Title</h3>
170
+ <p>Description</p>
171
+ </div>
172
+ </div>
173
+ </div>
174
+ ```
175
+
176
+ **Multi-select:** Add `data-multiselect` to the container to let users select multiple options. Each click toggles the item. The indicator bar shows the count.
177
+
178
+ ```html
179
+ <div class="options" data-multiselect>
180
+ <!-- same option markup — users can select/deselect multiple -->
181
+ </div>
182
+ ```
183
+
184
+ ### Cards (visual designs)
185
+
186
+ ```html
187
+ <div class="cards">
188
+ <div class="card" data-choice="design1" onclick="toggleSelect(this)">
189
+ <div class="card-image"><!-- mockup content --></div>
190
+ <div class="card-body">
191
+ <h3>Name</h3>
192
+ <p>Description</p>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ ```
197
+
198
+ ### Mockup container
199
+
200
+ ```html
201
+ <div class="mockup">
202
+ <div class="mockup-header">Preview: Dashboard Layout</div>
203
+ <div class="mockup-body"><!-- your mockup HTML --></div>
204
+ </div>
205
+ ```
206
+
207
+ ### Split view (side-by-side)
208
+
209
+ ```html
210
+ <div class="split">
211
+ <div class="mockup"><!-- left --></div>
212
+ <div class="mockup"><!-- right --></div>
213
+ </div>
214
+ ```
215
+
216
+ ### Pros/Cons
217
+
218
+ ```html
219
+ <div class="pros-cons">
220
+ <div class="pros"><h4>Pros</h4><ul><li>Benefit</li></ul></div>
221
+ <div class="cons"><h4>Cons</h4><ul><li>Drawback</li></ul></div>
222
+ </div>
223
+ ```
224
+
225
+ ### Mock elements (wireframe building blocks)
226
+
227
+ ```html
228
+ <div class="mock-nav">Logo | Home | About | Contact</div>
229
+ <div style="display: flex;">
230
+ <div class="mock-sidebar">Navigation</div>
231
+ <div class="mock-content">Main content area</div>
232
+ </div>
233
+ <button class="mock-button">Action Button</button>
234
+ <input class="mock-input" placeholder="Input field">
235
+ <div class="placeholder">Placeholder area</div>
236
+ ```
237
+
238
+ ### Typography and sections
239
+
240
+ - `h2` — page title
241
+ - `h3` — section heading
242
+ - `.subtitle` — secondary text below title
243
+ - `.section` — content block with bottom margin
244
+ - `.label` — small uppercase label text
245
+
246
+ ## Browser Events Format
247
+
248
+ When the user clicks options in the browser, their interactions are recorded to `$STATE_DIR/events` (one JSON object per line). The file is cleared automatically when you push a new screen.
249
+
250
+ ```jsonl
251
+ {"type":"click","choice":"a","text":"Option A - Simple Layout","timestamp":1706000101}
252
+ {"type":"click","choice":"c","text":"Option C - Complex Grid","timestamp":1706000108}
253
+ {"type":"click","choice":"b","text":"Option B - Hybrid","timestamp":1706000115}
254
+ ```
255
+
256
+ The full event stream shows the user's exploration path — they may click multiple options before settling. The last `choice` event is typically the final selection, but the pattern of clicks can reveal hesitation or preferences worth asking about.
257
+
258
+ If `$STATE_DIR/events` doesn't exist, the user didn't interact with the browser — use only their terminal text.
259
+
260
+ ## Design Tips
261
+
262
+ - **Scale fidelity to the question** — wireframes for layout, polish for polish questions
263
+ - **Explain the question on each page** — "Which layout feels more professional?" not just "Pick one"
264
+ - **Iterate before advancing** — if feedback changes current screen, write a new version
265
+ - **2-4 options max** per screen
266
+ - **Use real content when it matters** — for a photography portfolio, use actual images (Unsplash). Placeholder content obscures design issues.
267
+ - **Keep mockups simple** — focus on layout and structure, not pixel-perfect design
268
+
269
+ ## File Naming
270
+
271
+ - Use semantic names: `platform.html`, `visual-style.html`, `layout.html`
272
+ - Never reuse filenames — each screen must be a new file
273
+ - For iterations: append version suffix like `layout-v2.html`, `layout-v3.html`
274
+ - Server serves newest file by modification time
275
+
276
+ ## Cleaning Up
277
+
278
+ ```bash
279
+ scripts/stop-server.sh $SESSION_DIR
280
+ ```
281
+
282
+ If the session used `--project-dir`, mockup files persist in `.superpowers/brainstorm/` for later reference. Only `/tmp` sessions get deleted on stop.
283
+
284
+ ## Reference
285
+
286
+ - Frame template (CSS reference): `scripts/frame-template.html`
287
+ - Helper script (client-side): `scripts/helper.js`
@@ -0,0 +1,74 @@
1
+ ---
2
+ name: continuous-learning-v2
3
+ description: 基于直觉的学习系统。用于配置或审查 Hook 观察、project/global instinct、置信度、项目推广、迁移和演化为 skills/commands/agents 的流程。
4
+ version: 2.1.0
5
+ ---
6
+
7
+ # Continuous Learning v2.1
8
+
9
+ 本 skill 只保留使用决策和关键边界;实现细节在 `scripts/learning/`、`hooks/`、`commands/` 和 `config.json` 中。
10
+
11
+ ## 何时使用
12
+
13
+ - 配置或排查自动观察 Hook。
14
+ - 查看、审查、迁移 project/global instincts。
15
+ - 判断 project instinct 是否应推广到 global。
16
+ - 评估 instinct 是否应演化为 skill、command 或 agent。
17
+
18
+ ## 核心模型
19
+
20
+ - **Observation**:Hook 记录工具调用,默认写入 `${XDG_DATA_HOME:-~/.local/share}/ecc-homunculus/projects/<project-id>/observations.jsonl`。
21
+ - **Project instinct**:默认作用域,只服务当前项目,避免跨项目污染。
22
+ - **Global instinct**:经用户确认后才跨项目应用。
23
+ - **Confidence**:`0.3/0.5/0.7/0.9`,不会因时间自动衰减;长期未观察只进入待审查。
24
+ - **Promotion**:先 `/promote --dry-run` 预览,再由用户确认是否 `--apply`。
25
+
26
+ ## 数据布局
27
+
28
+ ```text
29
+ ${XDG_DATA_HOME:-~/.local/share}/ecc-homunculus/
30
+ ├── projects.json
31
+ ├── projects/<project-id>/
32
+ │ ├── observations.jsonl
33
+ │ └── instincts/{personal,inherited}/
34
+ └── global/
35
+ └── instincts/{personal,inherited}/
36
+ ```
37
+
38
+ 旧版 `~/.claude/homunculus/instincts` 作为 legacy 来源兼容;需要迁移时先 dry-run。
39
+
40
+ ## 命令
41
+
42
+ | 命令 | 作用 |
43
+ | --- | --- |
44
+ | `/learn-eval` | 从当前会话提取可复用模式,保存前走质量门 |
45
+ | `/instinct-status --review` | 调用 `scripts/learning/review-confidence.js` 审查 project/global/legacy instincts |
46
+ | `/projects` | 调用 `scripts/learning/projects.js` 查看项目注册表 |
47
+ | `/promote --dry-run` | 调用 `scripts/learning/promote.js` 预览 project -> global |
48
+ | `/evolve` | 聚类 instinct,评估是否演化为 skill/command/agent |
49
+ | `/prune` | 只清理人工标记删除、拒绝或归档的 instinct |
50
+
51
+ ## 脚本入口
52
+
53
+ - `skills/continuous-learning-v2/hooks/observe-v2.js`:Hook 观察入口。
54
+ - `scripts/learning/project-utils.js`:项目检测、数据根目录、注册表和 frontmatter 工具。
55
+ - `scripts/learning/review-confidence.js`:置信度审查报告。
56
+ - `scripts/learning/projects.js`:项目注册表。
57
+ - `scripts/learning/promote.js`:项目直觉推广预览/应用。
58
+ - `scripts/learning/migrate-homunculus.js`:legacy 迁移,默认 dry-run。
59
+
60
+ ## 安全边界
61
+
62
+ - 默认不启用后台 observer;`observer.enabled` 保持 `false`,避免额外 token 和误学习。
63
+ - 不自动导入、导出、推广或删除 instinct。
64
+ - 不把 raw observations 当作可共享知识;共享前只处理 instinct。
65
+ - 不把 project instinct 自动提升为 global。
66
+
67
+ ## 迁移
68
+
69
+ ```bash
70
+ node scripts/learning/migrate-homunculus.js --dry-run
71
+ node scripts/learning/migrate-homunculus.js --scope project --apply
72
+ ```
73
+
74
+ 迁移只复制,不删除旧数据。需要全局化时先运行 `--scope global --dry-run`。
@@ -0,0 +1,129 @@
1
+ ---
2
+ name: observer
3
+ description: 后台代理,分析会话观察以检测模式并创建直觉。使用 Haiku 以提高成本效益。
4
+ model: haiku
5
+ run_mode: background
6
+ ---
7
+
8
+ # Observer Agent
9
+
10
+ 分析 Claude Code 会话观察数据以检测模式并创建直觉的后台代理。
11
+
12
+ ## 何时运行
13
+
14
+ - 会话活动显著后 (20+ 工具调用)
15
+ - 用户运行 `/analyze-patterns` 时
16
+ - 按计划间隔 (可配置,默认 5 分钟)
17
+ - 观察 hook 触发时 (SIGUSR1)
18
+
19
+ ## 输入
20
+
21
+ 读取 `~/.claude/homunculus/observations.jsonl`,并优先按当前 `project_id` / `project_root` 过滤,避免跨项目污染:
22
+
23
+ ```jsonl
24
+ {"timestamp":"2026-01-22T10:30:00Z","event":"tool_start","session":"abc123","project_id":"a1b2c3d4e5f6","project_root":"/repo/app","tool":"Edit","input":"..."}
25
+ {"timestamp":"2026-01-22T10:30:01Z","event":"tool_complete","session":"abc123","project_id":"a1b2c3d4e5f6","project_root":"/repo/app","tool":"Edit","output":"..."}
26
+ {"timestamp":"2026-01-22T10:30:05Z","event":"tool_start","session":"abc123","project_id":"a1b2c3d4e5f6","project_root":"/repo/app","tool":"Bash","input":"npm test"}
27
+ ```
28
+
29
+ ## 模式检测
30
+
31
+ 在观察中寻找以下模式:
32
+
33
+ ### 1. 用户纠正
34
+ 当用户的后续消息纠正了 Claude 的先前行为:
35
+ - "不对,用 X 而不是 Y"
36
+ - "实际上,我是说..."
37
+ - 立即撤销/重做模式
38
+
39
+ → 创建直觉: "做 X 时,优先 Y"
40
+
41
+ ### 2. 错误解决
42
+ 当错误后跟着修复:
43
+ - 工具输出包含错误
44
+ - 接下来几次工具调用修复了它
45
+ - 相同错误类型多次以类似方式解决
46
+
47
+ → 创建直觉: "遇到错误 X 时,尝试 Y"
48
+
49
+ ### 3. 重复工作流
50
+ 当相同工具序列多次使用:
51
+ - 相同工具序列,相似输入
52
+ - 一起变化的文件模式
53
+ - 时间聚类操作
54
+
55
+ → 创建工作流直觉: "做 X 时,遵循步骤 Y, Z, W"
56
+
57
+ ### 4. 工具偏好
58
+ 当某些工具始终被优先使用:
59
+ - 总是在 Edit 之前使用 Grep
60
+ - 优先 Read 而非 Bash cat
61
+ - 对特定任务使用特定 Bash 命令
62
+
63
+ → 创建直觉: "需要 X 时,使用工具 Y"
64
+
65
+ ## 输出
66
+
67
+ 在 `~/.claude/homunculus/instincts/personal/` 创建/更新直觉:
68
+
69
+ ```yaml
70
+ ---
71
+ id: prefer-grep-before-edit
72
+ trigger: "搜索要修改的代码时"
73
+ confidence: 0.65
74
+ domain: "workflow"
75
+ source: "session-observation"
76
+ ---
77
+
78
+ # 优先在 Edit 前 Grep
79
+
80
+ ## 行为
81
+ 在使用 Edit 之前始终使用 Grep 找到确切位置。
82
+
83
+ ## 证据
84
+ - 在会话 abc123 中观察到 8 次
85
+ - 模式: Grep → Read → Edit 序列
86
+ - 最后观察: 2026-01-22
87
+ ```
88
+
89
+ ## 置信度计算
90
+
91
+ 基于观察频率的初始置信度:
92
+ - 1-2 观察: 0.3 (试探性)
93
+ - 3-5 观察: 0.5 (中等)
94
+ - 6-10 观察: 0.7 (强)
95
+ - 11+ 观察: 0.85 (很强)
96
+
97
+ 置信度基于新证据调整:
98
+ - +0.05: 每次确认观察
99
+ - -0.1: 每次矛盾观察
100
+
101
+ 长期无观察不自动降低置信度;标记为“待审查”,由用户或审查流程决定保留、更新、合并或删除。
102
+
103
+ ## 重要指南
104
+
105
+ 1. **保守** - 只为明确模式创建直觉 (3+ 观察)
106
+ 2. **具体** - 窄触发器优于宽触发器
107
+ 3. **追踪证据** - 始终包含导致直觉的观察
108
+ 4. **尊重隐私** - 不包含实际代码片段,只有模式
109
+ 5. **合并相似** - 如果新直觉与现有相似,更新而非重复
110
+
111
+ ## 示例分析会话
112
+
113
+ 给定观察:
114
+ ```jsonl
115
+ {"event":"tool_start","tool":"Grep","input":"pattern: useState"}
116
+ {"event":"tool_complete","tool":"Grep","output":"Found in 3 files"}
117
+ {"event":"tool_start","tool":"Read","input":"src/hooks/useAuth.ts"}
118
+ {"event":"tool_complete","tool":"Read","output":"[file content]"}
119
+ {"event":"tool_start","tool":"Edit","input":"src/hooks/useAuth.ts..."}
120
+ ```
121
+
122
+ 分析:
123
+ - 检测到工作流: Grep → Read → Edit
124
+ - 频率: 本会话见过 5 次
125
+ - 创建直觉:
126
+ - trigger: "修改代码时"
127
+ - action: "使用 Grep 搜索,使用 Read 确认,然后 Edit"
128
+ - confidence: 0.6
129
+ - domain: "workflow"
@@ -0,0 +1,83 @@
1
+ #!/bin/bash
2
+ #
3
+ # start-observer.sh - 启动 Observer Agent
4
+ #
5
+ # 后台运行的观察代理,定期分析会话观察数据,
6
+ # 检测模式并创建直觉。
7
+ #
8
+
9
+ set -e
10
+
11
+ # 配置
12
+ CLAUDE_HOME="${CLAUDE_HOME:-$HOME/.claude}"
13
+ OBSERVATIONS_FILE="$CLAUDE_HOME/homunculus/observations.jsonl"
14
+ INSTINCTS_DIR="$CLAUDE_HOME/homunculus/instincts/personal"
15
+ CONFIG_FILE="$CLAUDE_HOME/skills/continuous-learning-v2/config.json"
16
+ LOG_FILE="$CLAUDE_HOME/homunculus/observer.log"
17
+ PID_FILE="$CLAUDE_HOME/homunculus/observer.pid"
18
+
19
+ # 默认配置
20
+ INTERVAL_MINUTES=5
21
+ MIN_OBSERVATIONS=20
22
+
23
+ # 确保目录存在
24
+ mkdir -p "$INSTINCTS_DIR"
25
+ mkdir -p "$(dirname "$LOG_FILE")"
26
+
27
+ # 读取配置
28
+ if [ -f "$CONFIG_FILE" ]; then
29
+ INTERVAL_MINUTES=$(jq -r '.observer.run_interval_minutes // 5' "$CONFIG_FILE")
30
+ MIN_OBSERVATIONS=$(jq -r '.observer.min_observations_to_analyze // 20' "$CONFIG_FILE")
31
+ fi
32
+
33
+ log() {
34
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
35
+ }
36
+
37
+ check_observations() {
38
+ if [ -f "$OBSERVATIONS_FILE" ]; then
39
+ wc -l < "$OBSERVATIONS_FILE"
40
+ else
41
+ echo 0
42
+ fi
43
+ }
44
+
45
+ analyze_patterns() {
46
+ log "开始分析模式..."
47
+
48
+ # 这里应该调用 Claude API (Haiku) 进行分析
49
+ # 由于需要 API 密钥,这里只是示例
50
+
51
+ OBSERVATION_COUNT=$(check_observations)
52
+ log "观察数量: $OBSERVATION_COUNT"
53
+
54
+ if [ "$OBSERVATION_COUNT" -lt "$MIN_OBSERVATIONS" ]; then
55
+ log "观察不足,跳过分析 (需要 $MIN_OBSERVATIONS,当前 $OBSERVATION_COUNT)"
56
+ return
57
+ fi
58
+
59
+ log "分析完成"
60
+
61
+ # 清理已处理的观察
62
+ # tail -n 100 "$OBSERVATIONS_FILE" > "$OBSERVATIONS_FILE.tmp"
63
+ # mv "$OBSERVATIONS_FILE.tmp" "$OBSERVATIONS_FILE"
64
+ }
65
+
66
+ stop_observer() {
67
+ log "停止 Observer..."
68
+ rm -f "$PID_FILE"
69
+ exit 0
70
+ }
71
+
72
+ trap stop_observer SIGTERM SIGINT
73
+
74
+ # 启动
75
+ log "Observer 启动"
76
+ log "配置: 间隔=${INTERVAL_MINUTES}分钟, 最小观察=${MIN_OBSERVATIONS}"
77
+ echo $$ > "$PID_FILE"
78
+
79
+ # 主循环
80
+ while true; do
81
+ analyze_patterns
82
+ sleep $((INTERVAL_MINUTES * 60))
83
+ done
@@ -0,0 +1,58 @@
1
+ {
2
+ "version": "2.1",
3
+ "homunculus": {
4
+ "data_root": "~/.local/share/ecc-homunculus",
5
+ "legacy_root": "~/.claude/homunculus"
6
+ },
7
+ "observation": {
8
+ "enabled": true,
9
+ "store_path": "~/.local/share/ecc-homunculus",
10
+ "project_scoped": true,
11
+ "max_file_size_mb": 10,
12
+ "max_tool_input_chars": 2000,
13
+ "max_tool_output_chars": 500,
14
+ "archive_after_days": 7,
15
+ "capture_tools": [
16
+ "Edit",
17
+ "Write",
18
+ "Bash"
19
+ ],
20
+ "ignore_tools": [
21
+ "TodoWrite"
22
+ ]
23
+ },
24
+ "instincts": {
25
+ "global_path": "~/.local/share/ecc-homunculus/global/instincts/",
26
+ "project_path": "~/.local/share/ecc-homunculus/projects/<project-id>/instincts/",
27
+ "legacy_personal_path": "~/.claude/homunculus/instincts/personal/",
28
+ "legacy_inherited_path": "~/.claude/homunculus/instincts/inherited/",
29
+ "min_confidence": 0.3,
30
+ "auto_approve_threshold": 0.7,
31
+ "stale_threshold_days": 30,
32
+ "review_mode": "report",
33
+ "max_instincts": 100
34
+ },
35
+ "observer": {
36
+ "enabled": false,
37
+ "model": "haiku",
38
+ "run_interval_minutes": 5,
39
+ "min_observations_to_analyze": 20,
40
+ "patterns_to_detect": [
41
+ "user_corrections",
42
+ "error_resolutions",
43
+ "repeated_workflows",
44
+ "tool_preferences",
45
+ "file_patterns"
46
+ ]
47
+ },
48
+ "evolution": {
49
+ "cluster_threshold": 3,
50
+ "evolved_path": "~/.local/share/ecc-homunculus/evolved/",
51
+ "promotion_min_confidence": 0.7,
52
+ "auto_evolve": false
53
+ },
54
+ "integration": {
55
+ "skill_creator_api": "https://skill-creator.app/api",
56
+ "backward_compatible_v1": true
57
+ }
58
+ }