homunculus-code 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/CONTRIBUTING.md +56 -0
- package/LICENSE +21 -0
- package/README.md +443 -0
- package/bin/init.js +317 -0
- package/commands/eval-skill.md +48 -0
- package/commands/evolve.md +67 -0
- package/commands/improve-skill.md +50 -0
- package/core/evaluate-session.js +173 -0
- package/core/observe.sh +51 -0
- package/core/prune-instincts.js +159 -0
- package/docs/nightly-agent.md +130 -0
- package/examples/reference/README.md +47 -0
- package/examples/reference/architecture.yaml +886 -0
- package/examples/reference/evolved-agents/assistant-explorer.md +86 -0
- package/examples/reference/evolved-agents/shell-debugger.md +108 -0
- package/examples/reference/evolved-agents/tdd-runner.md +112 -0
- package/examples/reference/evolved-evals/api-system-diagnosis.eval.yaml +125 -0
- package/examples/reference/evolved-evals/assistant-system-management.eval.yaml +123 -0
- package/examples/reference/evolved-evals/claude-code-reference.eval.yaml +394 -0
- package/examples/reference/evolved-evals/development-verification-patterns.eval.yaml +117 -0
- package/examples/reference/evolved-evals/multi-agent-design-patterns.eval.yaml +151 -0
- package/examples/reference/evolved-evals/shell-automation-patterns.eval.yaml +209 -0
- package/examples/reference/evolved-evals/tdd-workflow.eval.yaml +191 -0
- package/examples/reference/evolved-evals/workflows.eval.yaml +148 -0
- package/examples/reference/evolved-skills/api-system-diagnosis.md +234 -0
- package/examples/reference/evolved-skills/assistant-system-management.md +199 -0
- package/examples/reference/evolved-skills/development-verification-patterns.md +243 -0
- package/examples/reference/evolved-skills/multi-agent-design-patterns.md +259 -0
- package/examples/reference/evolved-skills/shell-automation-patterns.md +347 -0
- package/examples/reference/evolved-skills/tdd-workflow.md +272 -0
- package/examples/reference/evolved-skills/workflows.md +237 -0
- package/package.json +25 -0
- package/templates/CLAUDE.md.template +36 -0
- package/templates/architecture.template.yaml +41 -0
- package/templates/rules/evolution-system.md +29 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Skill: tdd-workflow
|
|
2
|
+
**Version:** 1.2
|
|
3
|
+
**Icon:** poison
|
|
4
|
+
**Abbr:** TDD
|
|
5
|
+
**Evolved from:** (manual — 參考 Affaan/everything-claude-code TDD Guide + aihero.dev TDD Skill,適配小J環境)
|
|
6
|
+
**Created:** 2026-03-16
|
|
7
|
+
**Use when:** Forge 任務寫測試、AC 對應 test case、紅綠迴圈執行、quest-board endpoint 測試、habit/forge API discriminator
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
AC-driven 開發中的自動化測試層。AC 定義「什麼算完成」,TDD 提供「自動驗證做對了沒」的紅綠迴圈。
|
|
12
|
+
|
|
13
|
+
**核心立場**:AC 是主人,測試是僕人。不是所有 AC 都能自動測試。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 適用場景
|
|
18
|
+
|
|
19
|
+
- 新增 API endpoint
|
|
20
|
+
- 修 bug(先寫重現測試,再修)
|
|
21
|
+
- 重構(先確保測試綠,改完仍綠)
|
|
22
|
+
- 任何 Forge 任務中標記為 `[testable]` 的 AC
|
|
23
|
+
|
|
24
|
+
**不適用**:UI 外觀、UX 體驗、文件撰寫 — 這些用 `[manual]` AC。
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 紅綠重構迴圈
|
|
29
|
+
|
|
30
|
+
### Step 1: RED — 寫失敗的測試
|
|
31
|
+
|
|
32
|
+
從 `[testable]` AC 出發,為每條寫一個測試:
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const { describe, it, before, after } = require('node:test');
|
|
36
|
+
const assert = require('node:assert');
|
|
37
|
+
const { request, backupState, restoreState } = require('./helpers');
|
|
38
|
+
|
|
39
|
+
describe('POST /api/forge/review', () => {
|
|
40
|
+
before(() => backupState());
|
|
41
|
+
after(() => restoreState());
|
|
42
|
+
|
|
43
|
+
it('returns verdict field in response', async () => {
|
|
44
|
+
const { status, data } = await request('POST', '/api/forge/review', {
|
|
45
|
+
id: 'r17',
|
|
46
|
+
ac_results: [{ criterion: 'test', passed: true }],
|
|
47
|
+
});
|
|
48
|
+
assert.strictEqual(status, 200);
|
|
49
|
+
assert.ok(data.verdict, 'response should contain verdict');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns 400 when id is missing', async () => {
|
|
53
|
+
const { status } = await request('POST', '/api/forge/review', {
|
|
54
|
+
ac_results: [],
|
|
55
|
+
});
|
|
56
|
+
assert.strictEqual(status, 400);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Step 2: 確認 RED
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
node --test tests/<task-id>.test.js
|
|
65
|
+
# 預期:全部失敗(因為功能還沒實作)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
如果測試意外通過 → 測試寫錯了(太寬鬆),或功能已存在。
|
|
69
|
+
|
|
70
|
+
### Step 3: GREEN — 最少 code 讓測試過
|
|
71
|
+
|
|
72
|
+
只寫剛好能通過測試的 code。不多做。
|
|
73
|
+
|
|
74
|
+
### Step 4: 確認 GREEN
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
node --test tests/<task-id>.test.js
|
|
78
|
+
# 預期:全部通過
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Step 5: REFACTOR — 保持綠燈
|
|
82
|
+
|
|
83
|
+
重構 code,每改一步就跑測試。測試變紅 = 改壞了,回退。
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 測試 Pattern
|
|
88
|
+
|
|
89
|
+
### Pattern A:API Endpoint 測試
|
|
90
|
+
|
|
91
|
+
最常用。HTTP request → assert response status + body。
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
it('POST /api/quest/add creates a task', async () => {
|
|
95
|
+
const { status, data } = await request('POST', '/api/quest/add', {
|
|
96
|
+
title: 'test-quest',
|
|
97
|
+
});
|
|
98
|
+
assert.strictEqual(status, 200);
|
|
99
|
+
assert.ok(data.task, 'should return created task');
|
|
100
|
+
assert.strictEqual(data.task.title, 'test-quest');
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Pattern B:State 持久化測試
|
|
105
|
+
|
|
106
|
+
操作後直接讀 state.json 驗資料一致性。
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
it('completing quest adds XP to player', async () => {
|
|
110
|
+
const before = readState();
|
|
111
|
+
await request('POST', '/api/quest/complete', { id: 'r1' });
|
|
112
|
+
const after = readState();
|
|
113
|
+
assert.ok(after.player.xp > before.player.xp, 'XP should increase');
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Pattern C:Shell Script 測試
|
|
118
|
+
|
|
119
|
+
驗 exit code + stdout,不驗內部實作。
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
const { execSync } = require('child_process');
|
|
123
|
+
|
|
124
|
+
it('heartbeat.sh exits 0 on success', () => {
|
|
125
|
+
const result = execSync('zsh ~/assistant/heartbeat/heartbeat.sh 2>&1', {
|
|
126
|
+
timeout: 30000,
|
|
127
|
+
encoding: 'utf8',
|
|
128
|
+
});
|
|
129
|
+
// 驗 output 格式,不驗具體內容
|
|
130
|
+
assert.ok(result.includes('[') || result.length > 0);
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Pattern D:JSON Schema 驗證
|
|
135
|
+
|
|
136
|
+
確認 state.json 必要欄位存在。
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
it('state.json has required structure', () => {
|
|
140
|
+
const state = readState();
|
|
141
|
+
assert.ok(state.player, 'missing player');
|
|
142
|
+
assert.ok(Array.isArray(state.tasks), 'tasks should be array');
|
|
143
|
+
assert.ok(typeof state.player.xp === 'number', 'xp should be number');
|
|
144
|
+
assert.ok(typeof state.player.gold === 'number', 'gold should be number');
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## State 隔離
|
|
151
|
+
|
|
152
|
+
**每個 test suite 必須隔離 state**,避免互相污染:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
before(() => backupState()); // 備份
|
|
156
|
+
after(() => restoreState()); // 還原
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`helpers.js` 的 `backupState()`/`restoreState()` 用 file copy 實作,簡單可靠。
|
|
160
|
+
|
|
161
|
+
**注意**:`helpers.js` 使用 pid-unique backup(`state.test-backup-<pid>.json`),多數測試可並發跑。
|
|
162
|
+
但若測試需要直接寫 state.json(如 habit 測試,無對應 API),必須用 `--test-concurrency=1`:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# 一般情況(大多數 API 測試,pid-unique backup 已解決 race):
|
|
166
|
+
node --test tests/*.test.js
|
|
167
|
+
|
|
168
|
+
# 含直接寫 state.json 的測試時:
|
|
169
|
+
node --test --test-concurrency=1 tests/*.test.js
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
⚠️ `--concurrency=1` 不是有效的 node:test flag,正確是 `--test-concurrency=1`(Node.js v22+)。
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Session Start Pattern(既有專案)
|
|
177
|
+
|
|
178
|
+
**觸發**:接手或繼續有測試基礎的既有專案(非全新 Forge 任務)。
|
|
179
|
+
|
|
180
|
+
先跑現有測試,再開始任何改動:
|
|
181
|
+
```bash
|
|
182
|
+
node --test quest-board/tests/*.test.js # 或對應的測試命令
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**三個目的(Simon Willison, 2026-03)**:
|
|
186
|
+
1. 確認 agent 知道如何跑測試(為後續改動建立習慣)
|
|
187
|
+
2. 提供專案脈絡(測試本身就是功能規格)
|
|
188
|
+
3. 建立基線 — 知道改動前幾個測試通過,才能確認改動後不退步
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Anti-Patterns
|
|
193
|
+
|
|
194
|
+
### ❌ 不 mock server
|
|
195
|
+
quest-board 是我們自己的服務,直接測真實 server。Mock 會隱藏真實問題。
|
|
196
|
+
|
|
197
|
+
### ❌ 不測 UI render
|
|
198
|
+
沒有前端框架,UI 驗證用 `[manual]` AC + Playwright 截圖。
|
|
199
|
+
|
|
200
|
+
### ❌ 不追求 100% 覆蓋
|
|
201
|
+
單人系統,核心 API 80% 覆蓋即可。邊界情況按風險決定。
|
|
202
|
+
|
|
203
|
+
### ❌ 不改測試來通過
|
|
204
|
+
RED 階段寫完的測試就是規格。如果測試過不了,改 code 不改 test。除非 AC 本身定義有誤。
|
|
205
|
+
|
|
206
|
+
### ❌ 不在測試中驗內部狀態
|
|
207
|
+
```javascript
|
|
208
|
+
// ❌ 測內部實作
|
|
209
|
+
assert.strictEqual(server._handlers.length, 5);
|
|
210
|
+
|
|
211
|
+
// ✅ 測可觀察行為
|
|
212
|
+
const { status } = await request('GET', '/api/health');
|
|
213
|
+
assert.strictEqual(status, 200);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 測試品質標準
|
|
219
|
+
|
|
220
|
+
1. **測行為不測實作** — assert response / output,不 assert internal state
|
|
221
|
+
2. **每個測試獨立** — backup/restore 隔離,不依賴執行順序
|
|
222
|
+
3. **測試名 = 規格** — `it('returns 400 when id is missing')` 讀起來就是需求
|
|
223
|
+
4. **邊界案例** — null / empty string / invalid type / 不存在的 id
|
|
224
|
+
5. **錯誤路徑** — 測 4xx 回應,不只測 happy path
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 與 forge-dev 整合
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
/forge-dev define-ac <id>
|
|
232
|
+
→ AC 標記 [testable] / [manual]
|
|
233
|
+
|
|
234
|
+
/forge-dev gen-tests <id>
|
|
235
|
+
→ 讀 [testable] AC → 生成 tests/<id>.test.js → 跑一次確認 RED
|
|
236
|
+
|
|
237
|
+
/forge-dev start <id>
|
|
238
|
+
→ 紅綠迴圈:實作 → node --test → 修到全綠
|
|
239
|
+
|
|
240
|
+
/forge-dev review <id>
|
|
241
|
+
→ 自動跑 node --test → ac_results 自動生成
|
|
242
|
+
→ [manual] AC 仍用手動驗證(Read/curl/Glob)
|
|
243
|
+
→ 混合結果合併計算 pass_rate
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 夜間 Backfill
|
|
249
|
+
|
|
250
|
+
夜間 agent 為既有 API 補測試:
|
|
251
|
+
|
|
252
|
+
1. 掃描 server.js 的 endpoint → 比對 tests/ 已有覆蓋 → 產出缺口清單
|
|
253
|
+
2. 每晚補 1-2 個 endpoint,優先:forge > quest > habit > state
|
|
254
|
+
3. 新測試必須全綠且不破壞舊測試
|
|
255
|
+
4. Night report 追蹤:「測試覆蓋:X/Y endpoints(Z%)」
|
|
256
|
+
|
|
257
|
+
**Habit 測試特殊注意**:habit API 使用 `questId`(非 `id`),且 habits 在 `state.today.habits`。
|
|
258
|
+
由於沒有 add-habit API,測試 setup 需直接注入 state.json → 須搭配 `--test-concurrency=1`。
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 選擇指引
|
|
263
|
+
|
|
264
|
+
| 情境 | 做法 |
|
|
265
|
+
|------|------|
|
|
266
|
+
| 新 API endpoint | Pattern A(endpoint 測試)+ Pattern B(state 持久化) |
|
|
267
|
+
| 修改既有 endpoint 格式 | 在**同一個 module 測試檔**(如 quest-api.test.js)中新增 assert,不建新檔 |
|
|
268
|
+
| 修 API bug | 先寫重現 bug 的測試(RED)→ 修復 → GREEN |
|
|
269
|
+
| 重構 server.js | 先確保所有現有測試 GREEN → 重構 → 仍 GREEN |
|
|
270
|
+
| Shell script 修改 | Pattern C(exit code + stdout) |
|
|
271
|
+
| state.json 結構變更 | Pattern D(schema 驗證) |
|
|
272
|
+
| UI 相關變更 | 不寫測試,用 `[manual]` AC |
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Skill: Workflows
|
|
2
|
+
|
|
3
|
+
**Version:** 1.2
|
|
4
|
+
**Icon:** wind-1
|
|
5
|
+
**Abbr:** Workflows
|
|
6
|
+
**Evolved from:** Phase 1 Discord Bridge 開發中的架構領悟 — 「流程是知識,不是基礎設施」
|
|
7
|
+
**Evolved:** 2026-03-14
|
|
8
|
+
**Use when:** 判斷該用哪個標準 workflow:forge-dev 開發流、研究任務、skill evolution、系統性 debug vs 孤立 bug
|
|
9
|
+
|
|
10
|
+
## 用途
|
|
11
|
+
|
|
12
|
+
定義小J助理的常用工作流模板。當用戶觸發對應情境時,自動依循流程執行。
|
|
13
|
+
Workflow 只定義**重複性流程**,一次性或高度隨機的互動不套用。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 核心原則
|
|
18
|
+
|
|
19
|
+
1. **流程是知識,不是程式碼**:不需要 workflow engine,agent 讀到就會做
|
|
20
|
+
2. **只管步驟,不限細節**:每個步驟怎麼做由 agent 當下判斷
|
|
21
|
+
3. **可跳步**:用戶明確說「不用 X」就跳過,不死板
|
|
22
|
+
4. **自然演化**:用了幾次發現缺步驟或多餘步驟,直接更新此 skill
|
|
23
|
+
|
|
24
|
+
## 使用追蹤
|
|
25
|
+
|
|
26
|
+
**[MUST]** 完成任何 workflow 後,**靜默** POST 記錄(不需要告訴用戶)。這是數據驅動演化的基礎 — 沒有記錄就無法分析哪些 workflow 需要改進。
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
curl -sf http://localhost:3000/api/workflow/log -X POST -H 'Content-Type: application/json' -d '{
|
|
30
|
+
"workflow": "<workflow-id>",
|
|
31
|
+
"steps_completed": ["step1", "step2"],
|
|
32
|
+
"steps_skipped": ["step3"],
|
|
33
|
+
"outcome": "success|partial|failure|aborted"
|
|
34
|
+
}' > /dev/null 2>&1
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Workflow ID 對應:`research` / `study` / `feature-dev` / `project-init` / `learning-path` / `tech-eval` / `debug` / `daily-review`
|
|
38
|
+
|
|
39
|
+
**Subagent tracking 已自動化**:observe.sh hook 在每次 Agent tool 呼叫後自動 POST `/api/subagent/log`,不需要手動記錄。
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Workflow 1:技術研究(Research)
|
|
44
|
+
|
|
45
|
+
**觸發**:收到 URL、「研究 X」、「X 是什麼」、「幫我看看這個」
|
|
46
|
+
|
|
47
|
+
**步驟**:
|
|
48
|
+
1. 抓取/搜尋內容(WebFetch / WebSearch)
|
|
49
|
+
2. 摘要:主題(1-2 句)+ 關鍵要點(3-5 點)+ 來源
|
|
50
|
+
3. **Goal 適用性評估**:對照 `architecture.yaml` 目標樹,分類為:
|
|
51
|
+
- `[informational]` — 有趣但不直接影響系統
|
|
52
|
+
- `[adoptable]` — 可直接納入,標記 `affected_goals: [goal.path]`
|
|
53
|
+
- `[testable]` — 需實驗驗證,標記 `affected_goals` + 建議實驗
|
|
54
|
+
- `[irrelevant]` — 與系統目標無關
|
|
55
|
+
4. 如果值得記住 → 更新 research-notes memory
|
|
56
|
+
5. 如果 adoptable → 建議開 Forge(標明服務哪個 goal)
|
|
57
|
+
6. 如果 testable → 建議實驗(寫入 experiments/queue.jsonl)
|
|
58
|
+
7. **如果值得沉澱為知識** → 產出知識卡片到 `knowledge-cards/candidates/`(或用 `/study` 深度研究)
|
|
59
|
+
|
|
60
|
+
**產出**:摘要回覆 + 分類標記 + 可選的 memory 更新 + 可選的行動建議 + 可選的知識卡片
|
|
61
|
+
|
|
62
|
+
**判斷是否產出知識卡片**:
|
|
63
|
+
- 有具體案例、數據、機制可拆解 → 產出卡片
|
|
64
|
+
- 純概念問答或與 Javan 領域無關 → 不產出
|
|
65
|
+
|
|
66
|
+
**不套用**:單純的「X 是什麼」知識問答(直接回答就好)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Workflow 2:功能開發(Feature Dev)
|
|
71
|
+
|
|
72
|
+
**觸發**:「做 X 功能」、「修這個 bug」、「加一個 API」、Forge 任務開發
|
|
73
|
+
|
|
74
|
+
**步驟**:
|
|
75
|
+
1. 讀取相關檔案,確認現有架構
|
|
76
|
+
2. **前置評估** → `/forge-dev evaluate`(goal 定位 + impact 預判 + 成本合理性 → proceed/defer/reject)
|
|
77
|
+
3. 如果是 Forge 且沒有 AC → `/forge-dev define-ac`(參考 evaluate 的預期變更清單,標記 `[testable]`/`[manual]`)
|
|
78
|
+
4. **[optional]** 如果有 `[testable]` AC → `/forge-dev gen-tests`(生成測試,確認 RED)— 實際多數情況直接在紅綠迴圈中寫測試
|
|
79
|
+
5. 實作改動(有測試 → 紅綠迴圈;無測試 → 直接實作)
|
|
80
|
+
6. 語法預檢(`node -c`、`zsh -n`、`jq empty` 等)
|
|
81
|
+
7. 服務重啟(如果改了跑中的服務)
|
|
82
|
+
8. 端點/功能驗證:`[testable]` AC 跑 `node --test`、`[manual]` AC 手動驗證
|
|
83
|
+
9. **系統整合** → `/forge-dev complete`(architecture.yaml + CLAUDE.md + health_check + test 指標同步)
|
|
84
|
+
10. 回報結果
|
|
85
|
+
|
|
86
|
+
**產出**:可用功能 + 測試通過 + 驗證結果 + 系統一致性確認
|
|
87
|
+
|
|
88
|
+
**已有支撐**:`/forge-dev` command、`development-verification-patterns` skill、`tdd-workflow` skill
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Workflow 3:開啟項目(Project Init)
|
|
93
|
+
|
|
94
|
+
**觸發**:「開個項目追蹤 X」、「我想長期做 X」、「這個值得開項目」
|
|
95
|
+
|
|
96
|
+
**步驟**:
|
|
97
|
+
1. 建立 `~/assistant/projects/{slug}/README.md`(目標、背景、里程碑)
|
|
98
|
+
2. 建立 Forge 任務(或多個,依規模拆分)
|
|
99
|
+
3. 問用戶要不要在 Discord 開 thread 做長期討論
|
|
100
|
+
4. 更新 memory 索引(如果是重要項目)
|
|
101
|
+
|
|
102
|
+
**產出**:項目目錄 + Forge 任務 + 可選的 Discord thread
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Workflow 4:學習計劃(Learning Path)
|
|
107
|
+
|
|
108
|
+
**觸發**:「我想學 X」、「幫我規劃學 X」
|
|
109
|
+
|
|
110
|
+
**步驟**:
|
|
111
|
+
1. 快速研究 X 的學習路徑(搜尋 + 自身知識)
|
|
112
|
+
2. 依照 Project Init workflow 建立項目
|
|
113
|
+
3. 拆成 3-5 個里程碑(由淺到深)
|
|
114
|
+
4. 建議第一步(具體、可執行)
|
|
115
|
+
5. 設定 check-in 頻率(每週?每天?)
|
|
116
|
+
|
|
117
|
+
**產出**:學習項目 + 里程碑 Forge + 第一步行動
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Workflow 5:技術評估(Tech Eval)
|
|
122
|
+
|
|
123
|
+
**觸發**:「X 值得用嗎」、「X 跟 Y 比哪個好」、「要不要換成 X」
|
|
124
|
+
|
|
125
|
+
**步驟**:
|
|
126
|
+
1. 快速研究 X(官方文檔 + 社群評價)
|
|
127
|
+
2. 跟現有系統/方案比較(功能、成本、複雜度)
|
|
128
|
+
3. **Goal 適用性評估**:標記 `affected_goals` + 分類(adoptable/testable/informational)
|
|
129
|
+
4. 明確結論:採用 / 不採用 / 觀望
|
|
130
|
+
5. 如果採用 → 建議具體行動(Forge,標明服務哪個 goal)
|
|
131
|
+
6. 記入 research-notes(不論結論,留作知識儲備)
|
|
132
|
+
|
|
133
|
+
**產出**:評估結論 + 分類標記 + 行動建議 + memory 更新
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Workflow 6:系統除錯(Debug)
|
|
138
|
+
|
|
139
|
+
**觸發**:「X 壞了」、「這個 error 怎麼回事」、服務異常
|
|
140
|
+
|
|
141
|
+
**步驟**:
|
|
142
|
+
1. 查看相關 log(`/tmp/*.log`、`heartbeat/logs/`)
|
|
143
|
+
2. 定位根因(不要急著修,先理解)
|
|
144
|
+
3. 修復
|
|
145
|
+
4. 驗證修復有效
|
|
146
|
+
5. 判斷是否系統性問題 → 決定是否加防護:
|
|
147
|
+
|
|
148
|
+
**系統性問題(應加防護)**:
|
|
149
|
+
- 邊界條件可重現:空檔案、null 值、網路逾時、並發衝突
|
|
150
|
+
- 根因是外部輸入或環境不確定性(非 typo)
|
|
151
|
+
- 影響多個呼叫路徑或會反覆觸發
|
|
152
|
+
- 例:空 state.json → `jq '.x // []'`;API timeout → retry + fallback
|
|
153
|
+
|
|
154
|
+
**孤立 bug(修完即可)**:
|
|
155
|
+
- 邏輯錯誤、typo、hardcoded 值錯誤
|
|
156
|
+
- 有明確的「不應該發生這種情況」的前提
|
|
157
|
+
- 修完後不會在正常使用中再次出現
|
|
158
|
+
- 例:API path 拼錯、filter 條件相反
|
|
159
|
+
|
|
160
|
+
**產出**:問題修復 + 根因說明 + 可選的防護措施
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Workflow 7:每日回顧(Daily Review)
|
|
165
|
+
|
|
166
|
+
**觸發**:夜間 heartbeat P1 / 用戶問「今天做了什麼」
|
|
167
|
+
|
|
168
|
+
**步驟**:
|
|
169
|
+
1. 讀取當天 session summaries
|
|
170
|
+
2. 統計:sessions 數、工具使用、主要工作項目
|
|
171
|
+
3. 評估未完成的任務,標記需延續的
|
|
172
|
+
4. 識別可擷取的 instinct(信心 > 0.7)
|
|
173
|
+
5. 寫入 night report 或直接回覆
|
|
174
|
+
|
|
175
|
+
**產出**:回顧摘要 + instinct 候選
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 不適合 Workflow 的場景
|
|
180
|
+
|
|
181
|
+
以下情境**不要套用 workflow**,直接靈活回應:
|
|
182
|
+
- 一般閒聊、腦力激盪(`#general` 頻道日常)
|
|
183
|
+
- 一次性快問快答(「X 多少錢」「翻譯這句」)
|
|
184
|
+
- 大型架構決策(需要深度推理,固定步驟反而限制思考)
|
|
185
|
+
- 跨 session 的開放式探索(沒有明確完成標準)
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Eval Spec
|
|
190
|
+
|
|
191
|
+
### Scenario 1: URL 研究觸發
|
|
192
|
+
**Input:** 用戶貼了一個技術文章 URL
|
|
193
|
+
**Expected:** 依循 Workflow 1 — 摘要 + 關聯性評估 + 必要時更新 memory
|
|
194
|
+
**Criteria:** 有摘要、有與系統關聯的評估、不做無謂的 Forge 建議
|
|
195
|
+
**Rating:** ⭐ 完整流程 / ✅ 有摘要但缺評估 / ❌ 只貼連結內容
|
|
196
|
+
|
|
197
|
+
### Scenario 2: 開項目請求
|
|
198
|
+
**Input:** 「幫我開個項目追蹤 Rust 學習」
|
|
199
|
+
**Expected:** 依循 Workflow 3+4 — 建目錄 + README + Forge + 里程碑 + 建議第一步
|
|
200
|
+
**Criteria:** 有 projects/ 目錄、有 Forge 任務、有具體下一步
|
|
201
|
+
**Rating:** ⭐ 完整 / ✅ 有目錄但缺里程碑 / ❌ 只回覆「好的」
|
|
202
|
+
|
|
203
|
+
### Scenario 3: 技術評估
|
|
204
|
+
**Input:** 「Bun 值得用來替換 Node 嗎?」
|
|
205
|
+
**Expected:** 依循 Workflow 5 — 研究 + 比較 + 明確結論 + 行動建議
|
|
206
|
+
**Criteria:** 有對比表、有結論、結論有理由支撐
|
|
207
|
+
**Rating:** ⭐ 完整 / ✅ 有結論但缺比較 / ❌ 模糊回覆
|
|
208
|
+
|
|
209
|
+
### Scenario 4: 不該套用 workflow
|
|
210
|
+
**Input:** 「今天晚餐吃什麼好?」
|
|
211
|
+
**Expected:** 直接輕鬆回答,不套用任何 workflow
|
|
212
|
+
**Criteria:** 自然回覆、不出現「步驟 1」之類的結構
|
|
213
|
+
**Rating:** ⭐ 自然回覆 / ❌ 硬套 workflow
|
|
214
|
+
|
|
215
|
+
### Scenario 5: Debug 流程
|
|
216
|
+
**Input:** 「heartbeat 好像沒有跑,幫我看看」
|
|
217
|
+
**Expected:** 依循 Workflow 6 — 查 log → 定位 → 修復 → 驗證
|
|
218
|
+
**Criteria:** 先查 log 不急著猜、修完有驗證
|
|
219
|
+
**Rating:** ⭐ 完整 / ✅ 有修但沒驗證 / ❌ 盲猜修改
|
|
220
|
+
|
|
221
|
+
### Scenario 6: 功能開發
|
|
222
|
+
**Input:** 「在 Quest Board 加一個 /api/stats endpoint」
|
|
223
|
+
**Expected:** 依循 Workflow 2 — 讀架構 → 實作 → 預檢 → 重啟 → 驗證
|
|
224
|
+
**Criteria:** 有語法檢查、有服務重啟、有端點測試
|
|
225
|
+
**Rating:** ⭐ 完整 / ✅ 能用但跳過驗證 / ❌ 寫完就走
|
|
226
|
+
|
|
227
|
+
### Scenario 7: 案例研究產出知識卡片 (boundary)
|
|
228
|
+
**Input:** 「研究這個:<URL to a detailed Stripe Agent Toolkit article>」
|
|
229
|
+
**Expected:** 依循 Workflow 1 步驟 1-7 — 摘要 + 評估 + 產出知識卡片到 candidates/
|
|
230
|
+
**Criteria:** 有卡片(正確 frontmatter + connections)、有確認摘要、卡片在 candidates/ 不在 cards/
|
|
231
|
+
**Rating:** ⭐ 完整卡片+摘要 / ✅ 有摘要但沒產卡片 / ❌ 只貼內容
|
|
232
|
+
|
|
233
|
+
### Scenario 8: 一般研究不產卡片 (boundary)
|
|
234
|
+
**Input:** 「台灣明天天氣怎樣」
|
|
235
|
+
**Expected:** 直接回答,不產出知識卡片
|
|
236
|
+
**Criteria:** 不產出卡片、不走完整 research workflow
|
|
237
|
+
**Rating:** ⭐ 直接回答 / ❌ 硬產卡片
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "homunculus-code",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A self-evolving AI assistant that grows smarter every night",
|
|
5
|
+
"bin": {
|
|
6
|
+
"homunculus": "./bin/init.js"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"ai",
|
|
10
|
+
"claude-code",
|
|
11
|
+
"self-evolving",
|
|
12
|
+
"ai-assistant",
|
|
13
|
+
"goal-tree",
|
|
14
|
+
"evolution"
|
|
15
|
+
],
|
|
16
|
+
"author": "Javan <https://github.com/JavanC>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/JavanC/Homunculus.git"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# {{PROJECT_NAME}} — Homunculus-Powered AI Assistant
|
|
2
|
+
|
|
3
|
+
You are an evolving AI assistant. You improve over time through observation, pattern extraction, and goal-driven evolution.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Evolution System
|
|
8
|
+
|
|
9
|
+
- **Goal Tree**: `architecture.yaml` defines what matters — all evolution decisions align with goals
|
|
10
|
+
- **Instincts**: Auto-extracted behavioral patterns in `homunculus/instincts/personal/`
|
|
11
|
+
- **Skills**: Tested, versioned knowledge in `homunculus/evolved/skills/`
|
|
12
|
+
- **Eval Specs**: Scenario tests in `homunculus/evolved/evals/`
|
|
13
|
+
|
|
14
|
+
### Memory Hierarchy (most to least persistent)
|
|
15
|
+
1. `CLAUDE.md` + `rules/` — Always loaded, most authoritative
|
|
16
|
+
2. `homunculus/evolved/skills/` — Loaded when relevant
|
|
17
|
+
3. `homunculus/instincts/personal/` — Selected at session start
|
|
18
|
+
|
|
19
|
+
### Evolution Commands
|
|
20
|
+
- `/eval-skill` — Run scenario tests on a skill
|
|
21
|
+
- `/improve-skill` — Auto-improve until eval passes
|
|
22
|
+
- `/evolve` — Aggregate instincts into a skill
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Goals
|
|
27
|
+
|
|
28
|
+
See `architecture.yaml` for the complete goal tree.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Verification
|
|
33
|
+
|
|
34
|
+
- Validate before committing: run tests, check syntax
|
|
35
|
+
- Prefer fixing root causes over workarounds
|
|
36
|
+
- When blocked, try alternative approaches before retrying
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# architecture.yaml — Your goal tree
|
|
2
|
+
# Each node is a GOAL, not a system. Systems are means to achieve goals.
|
|
3
|
+
# The evolution system uses this to decide what to improve.
|
|
4
|
+
#
|
|
5
|
+
# Node schema:
|
|
6
|
+
# purpose: Why this goal exists
|
|
7
|
+
# realized_by: What implements it (file path, system, or description)
|
|
8
|
+
# metrics: How to measure success [{name, source, healthy}]
|
|
9
|
+
# goals: Sub-goals (recursive)
|
|
10
|
+
# health_check: Machine-executable check
|
|
11
|
+
# - command: shell command (exit 0 = healthy)
|
|
12
|
+
# - expected: human-readable description
|
|
13
|
+
|
|
14
|
+
version: "1.0"
|
|
15
|
+
|
|
16
|
+
root:
|
|
17
|
+
purpose: "{{PROJECT_PURPOSE}}"
|
|
18
|
+
|
|
19
|
+
goals:
|
|
20
|
+
# === Add your goals below ===
|
|
21
|
+
# Example:
|
|
22
|
+
#
|
|
23
|
+
# code_quality:
|
|
24
|
+
# purpose: "Write better, more maintainable code"
|
|
25
|
+
# metrics:
|
|
26
|
+
# - name: test_coverage
|
|
27
|
+
# source: coverage report
|
|
28
|
+
# healthy: "> 80%"
|
|
29
|
+
# health_check:
|
|
30
|
+
# command: "npm test 2>/dev/null; echo $?"
|
|
31
|
+
# expected: "all tests pass"
|
|
32
|
+
#
|
|
33
|
+
# productivity:
|
|
34
|
+
# purpose: "Complete tasks faster with fewer iterations"
|
|
35
|
+
# goals:
|
|
36
|
+
# task_completion:
|
|
37
|
+
# purpose: "Finish tasks in fewer back-and-forth cycles"
|
|
38
|
+
# tool_mastery:
|
|
39
|
+
# purpose: "Use the right tool for the job on first try"
|
|
40
|
+
|
|
41
|
+
# Your goals here:
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Evolution System (Homunculus)
|
|
2
|
+
|
|
3
|
+
## Evolution Artifacts (all in `homunculus/evolved/`)
|
|
4
|
+
|
|
5
|
+
| Artifact | Location | Evolution Method |
|
|
6
|
+
|----------|----------|-----------------|
|
|
7
|
+
| **Skills** | `evolved/skills/` | Instinct aggregation (`/evolve`), eval→improve loop |
|
|
8
|
+
| **Agents** | `evolved/agents/` | Extract repetitive main-thread patterns into subagents |
|
|
9
|
+
| **Evals** | `evolved/evals/` | Accompany each skill, scenario-based testing |
|
|
10
|
+
|
|
11
|
+
## Evolution Flow
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Observe (observations.jsonl) → Pattern detection (confidence > 0.7) → instincts/personal/*.md
|
|
15
|
+
↓
|
|
16
|
+
/evolve → evolved/skills/*.md
|
|
17
|
+
↓
|
|
18
|
+
eval → improve loop → 100% pass
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Manual Triggers
|
|
22
|
+
- `/evolve` — Aggregate instincts into a skill
|
|
23
|
+
- `/eval-skill` — Test a skill against its eval spec
|
|
24
|
+
- `/improve-skill` — Auto-improve until eval passes
|
|
25
|
+
|
|
26
|
+
## Automatic Maintenance
|
|
27
|
+
- Instinct extraction from session observations
|
|
28
|
+
- Instinct pruning (confidence decay, skill coverage check)
|
|
29
|
+
- Skill eval → improve pipeline
|