@geekbeer/minion 2.10.3 → 2.11.1

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.
@@ -1,67 +1,9 @@
1
- # Minion Agent Environment
1
+ # Minion API Reference
2
2
 
3
- You are running on a Minion VPS managed by the @geekbeer/minion package.
4
- A local Agent API server runs at `http://localhost:3001` and a CLI tool `minion-cli` is available.
3
+ このドキュメントはミニオンが利用可能なAPIの全仕様です。
4
+ HQのソースコードを読む必要はありません 必要な情報はすべてここに記載されています。
5
5
 
6
- ## Architecture: Project / Workflow / Routine
7
-
8
- ```
9
- Project (組織・課金単位)
10
- ├── Context (markdown, PMが更新)
11
- ├── Members (minion + role: pm | engineer)
12
- └── Workflows (何をするか + オプションのcronスケジュール)
13
- ├── Versions (pipeline の不変スナップショット)
14
- └── Executions (実行履歴, ステップごとの進捗)
15
-
16
- Minion
17
- └── Routines (いつ・何を, cron付き, ミニオンローカルのタスク)
18
- ```
19
-
20
- - **Workflow** はプロジェクトスコープ。バージョン管理されたパイプライン(スキル列)を持つ。オプションで `cron_expression` によるスケジュール実行が可能。HQ UIからワンショット実行もできる。
21
- - **Routine** はミニオンスコープ。ミニオンローカルの定期タスク。cron_expression を持ち自律トリガーする。
22
- - ミニオンは複数プロジェクトに `pm` または `engineer` として参加できる。
23
- - ワークフローの各ステップには `assigned_role`(pm/engineer)と `requires_review` フラグがある。
24
-
25
- ## Workflow Execution Model (DB ステートマシン)
26
-
27
- ワークフロー実行はHQのDBがステートマシンとして管理する。ミニオン間通信は不要。
28
-
29
- ```
30
- 1. Execution 作成 (HQ UIのRunボタン or cronスケジュール)
31
- → workflow_execution (status='pending')
32
- → workflow_step_executions (全ステップ status='pending')
33
-
34
- 2. ミニオンエージェントが GET /api/minion/pending-steps をポーリング
35
- → 自分のロールに該当 & 前ステップ完了済みのステップを取得
36
-
37
- 3. ミニオンがステップを実行し完了を報告
38
- → POST /api/minion/execution で status/outcome を更新
39
-
40
- 4. 次ステップが eligible に → 別のミニオンが検知して実行
41
- → requires_review=true の場合はHQでレビュー承認後に次へ
42
-
43
- 5. 全ステップ完了 → execution 全体を completed に
44
- ```
45
-
46
- **ポイント:**
47
- - HQの責務は「executionレコードを作る(指示書発行)」だけ
48
- - 各ミニオンは自分の担当ステップだけをポーリングして実行
49
- - ミニオンエージェント(Port 3001)が軽量HTTPポーリングを行い、pending検知時のみClaude Codeを起動(トークン節約)
50
-
51
- ## CLI Commands
52
-
53
- ```bash
54
- minion-cli status # Get current status (online/offline/busy)
55
- minion-cli health # Health check
56
- minion-cli set-status <status> [task] # Set status and optional task description
57
- minion-cli skill push <name> # Push local skill to HQ
58
- minion-cli skill fetch <name> # Fetch skill from HQ to local
59
- minion-cli skill list # List skills on HQ
60
- minion-cli skill list --local # List local deployed skills
61
- minion-cli --version # Show package version
62
- # Service management (requires sudo):
63
- # sudo minion-cli start | stop | restart
64
- ```
6
+ ---
65
7
 
66
8
  ## Agent API Endpoints (http://localhost:3001)
67
9
 
@@ -142,6 +84,8 @@ Files are stored in `~/files/`. Max upload size: 50MB.
142
84
 
143
85
  Available commands: `restart-agent`, `update-agent`, `restart-display`, `status-services`
144
86
 
87
+ ---
88
+
145
89
  ## HQ API Endpoints (https://<HQ_URL>)
146
90
 
147
91
  Authentication: `Authorization: Bearer $API_TOKEN` header.
@@ -230,6 +174,60 @@ POST body (push):
230
174
 
231
175
  push するとパイプライン内のスキル名が `skill_version_id` に解決され、新バージョンが自動作成される。
232
176
 
177
+ ### Workflow Structure
178
+
179
+ ```json
180
+ {
181
+ "name": "my-workflow",
182
+ "pipeline_skill_names": ["skill-1", "skill-2", "execution-report"],
183
+ "pipeline": [
184
+ {
185
+ "skill_version_id": "uuid",
186
+ "skill_name": "skill-1",
187
+ "skill_display_name": "Skill One",
188
+ "skill_version": 2,
189
+ "assigned_role": "engineer",
190
+ "requires_review": false,
191
+ "is_my_step": true
192
+ }
193
+ ],
194
+ "content": "Markdown description of the workflow",
195
+ "version": 2,
196
+ "cron_expression": "0 9 * * *",
197
+ "project_id": "uuid"
198
+ }
199
+ ```
200
+
201
+ | Field | Type | Description |
202
+ |-------|------|-------------|
203
+ | `name` | string | Slug identifier (`/^[a-z0-9-]+$/`) |
204
+ | `pipeline_skill_names` | string[] | Ordered skill names (for display/push) |
205
+ | `pipeline` | PipelineStep[] | Resolved pipeline with version IDs and roles |
206
+ | `content` | string | Markdown body describing the workflow |
207
+ | `version` | number | Current version number (auto-incremented on push) |
208
+ | `cron_expression` | string\|null | Cron schedule (null = manual/one-shot only) |
209
+ | `project_id` | string | UUID of the parent project |
210
+
211
+ ### Pipeline Step Fields
212
+
213
+ | Field | Type | Description |
214
+ |-------|------|-------------|
215
+ | `skill_version_id` | string | UUID of the specific skill version |
216
+ | `skill_name` | string | Skill slug name |
217
+ | `skill_display_name` | string | Human-readable skill name |
218
+ | `skill_version` | number | Skill version number |
219
+ | `assigned_role` | string | `"pm"` or `"engineer"` — who executes this step |
220
+ | `requires_review` | boolean | If true, human review required after completion |
221
+ | `is_my_step` | boolean | Whether this minion's role matches assigned_role |
222
+
223
+ ### Syncing Workflows with HQ
224
+
225
+ - `POST /api/workflows/push/:name` — Push local workflow to HQ. Pipeline skills are auto-pushed first.
226
+ - `POST /api/workflows/fetch/:name` — Fetch workflow from HQ. Missing pipeline skills are auto-fetched.
227
+ - `GET /api/workflows/remote` — List workflows available on HQ.
228
+
229
+ Pipeline skills must be deployed locally (in `~/.claude/skills/`) before pushing a workflow.
230
+
233
231
  ### Pending Steps (軽量ポーリング)
234
232
 
235
233
  | Method | Endpoint | Description |
@@ -237,7 +235,6 @@ push するとパイプライン内のスキル名が `skill_version_id` に解
237
235
  | GET | `/api/minion/pending-steps` | 自分が実行すべき pending ステップ一覧 |
238
236
 
239
237
  **このエンドポイントはミニオンエージェント(非AI)による高頻度ポーリング用。**
240
- Claude Code(AIスキル実行)はステップ検知時のみ起動する。
241
238
 
242
239
  Response:
243
240
  ```json
@@ -329,7 +326,7 @@ Response:
329
326
 
330
327
  使用可能なラベル: `bug`, `enhancement`, `critical`, `minor`
331
328
 
332
- **使い方:** サービスのバグや改善点を発見したら、このエンドポイントで GitHub Issue を起票する。報告者のミニオン名と ID が自動で本文に付記される。
329
+ 報告者のミニオン名と ID が自動で本文に付記される。
333
330
 
334
331
  ### Routines (minion-scoped)
335
332
 
@@ -355,127 +352,7 @@ Response:
355
352
  ]
356
353
  ```
357
354
 
358
- ### Skills
359
-
360
- | Method | Endpoint | Description |
361
- |--------|----------|-------------|
362
- | GET | `/api/minion/skills` | HQ に登録されたスキル一覧 |
363
- | GET | `/api/minion/skills/[name]` | スキル詳細取得(content, files 含む) |
364
- | POST | `/api/minion/skills` | スキル登録/更新(新バージョン自動作成) |
365
-
366
- スキルはバージョン管理される。push ごとに新バージョンが作成され、ファイルは Supabase Storage に保存される。
367
-
368
- ## Environment Variables
369
-
370
- | Variable | Description |
371
- |----------|-------------|
372
- | `HQ_URL` | HQ server URL (empty = standalone mode) |
373
- | `API_TOKEN` | Bearer token for HQ and local API auth |
374
- | `MINION_ID` | UUID assigned by HQ |
375
- | `AGENT_PORT` | Agent HTTP port (default: 3001) |
376
- | `MINION_USER` | System user running the agent |
377
-
378
- ## Skills Directory Structure
379
-
380
- Skills are stored in `~/.claude/skills/<name>/`:
381
-
382
- ```
383
- ~/.claude/skills/<name>/
384
- SKILL.md # Skill definition (YAML frontmatter + markdown body)
385
- references/ # Optional supporting files
386
- ```
387
-
388
- SKILL.md format:
389
- ```markdown
390
- ---
391
- name: my-skill
392
- description: What this skill does
393
- ---
394
-
395
- Skill instructions here...
396
- ```
397
-
398
- ## HQ Connection
399
-
400
- When `HQ_URL` and `API_TOKEN` are set, the agent sends heartbeats and syncs with HQ.
401
- Use `minion-cli skill push/fetch` to sync skills between local and HQ.
402
- Use the workflow API endpoints (`/api/workflows/push/:name`, `/api/workflows/fetch/:name`) to sync workflows.
403
- When not configured, the agent runs in standalone mode and HQ-dependent features return errors.
404
-
405
- ## Workflow Structure
406
-
407
- Workflows are project-scoped and versioned. Each version is an immutable snapshot of the pipeline.
408
- Fetched from HQ via `GET /api/minion/workflows`. Also stored locally in `workflows.json`.
409
-
410
- ```json
411
- {
412
- "name": "my-workflow",
413
- "pipeline_skill_names": ["skill-1", "skill-2", "execution-report"],
414
- "pipeline": [
415
- {
416
- "skill_version_id": "uuid",
417
- "skill_name": "skill-1",
418
- "skill_display_name": "Skill One",
419
- "skill_version": 2,
420
- "assigned_role": "engineer",
421
- "requires_review": false,
422
- "is_my_step": true
423
- }
424
- ],
425
- "content": "Markdown description of the workflow",
426
- "version": 2,
427
- "cron_expression": "0 9 * * *",
428
- "project_id": "uuid"
429
- }
430
- ```
431
-
432
- | Field | Type | Description |
433
- |-------|------|-------------|
434
- | `name` | string | Slug identifier (`/^[a-z0-9-]+$/`) |
435
- | `pipeline_skill_names` | string[] | Ordered skill names (for display/push) |
436
- | `pipeline` | PipelineStep[] | Resolved pipeline with version IDs and roles |
437
- | `content` | string | Markdown body describing the workflow |
438
- | `version` | number | Current version number (auto-incremented on push) |
439
- | `cron_expression` | string\|null | Cron schedule (null = manual/one-shot only) |
440
- | `project_id` | string | UUID of the parent project |
441
-
442
- ### Pipeline Step Fields
443
-
444
- | Field | Type | Description |
445
- |-------|------|-------------|
446
- | `skill_version_id` | string | UUID of the specific skill version |
447
- | `skill_name` | string | Skill slug name |
448
- | `skill_display_name` | string | Human-readable skill name |
449
- | `skill_version` | number | Skill version number |
450
- | `assigned_role` | string | `"pm"` or `"engineer"` — who executes this step |
451
- | `requires_review` | boolean | If true, human review required after completion |
452
- | `is_my_step` | boolean | Whether this minion's role matches assigned_role |
453
-
454
- ### Syncing workflows with HQ
455
-
456
- - `POST /api/workflows/push/:name` — Push local workflow to HQ. Pipeline skills are auto-pushed first.
457
- - `POST /api/workflows/fetch/:name` — Fetch workflow from HQ. Missing pipeline skills are auto-fetched.
458
- - `GET /api/workflows/remote` — List workflows available on HQ.
459
-
460
- Pipeline skills must be deployed locally (in `~/.claude/skills/`) before pushing a workflow.
461
-
462
- ## Routine Structure
463
-
464
- Routines are minion-scoped and fetched from HQ via `GET /api/minion/routines`.
465
- They are also stored locally in `routines.json`. Each routine object:
466
-
467
- ```json
468
- {
469
- "id": "uuid",
470
- "name": "morning-work",
471
- "pipeline_skill_names": ["project-workflow-check", "execution-report"],
472
- "content": "Markdown description of the routine",
473
- "cron_expression": "0 9 * * 1-5",
474
- "is_active": true,
475
- "last_run": "2026-02-10T09:00:00.000Z",
476
- "next_run": "2026-02-11T09:00:00.000Z"
477
- }
478
- ```
355
+ ### Routine Structure
479
356
 
480
357
  | Field | Type | Description |
481
358
  |-------|------|-------------|
@@ -488,44 +365,12 @@ They are also stored locally in `routines.json`. Each routine object:
488
365
  | `last_run` | string\|null | ISO timestamp of last execution |
489
366
  | `next_run` | string\|null | ISO timestamp of next scheduled run |
490
367
 
491
- ## Routine Execution
492
-
493
- Routines run on cron schedules. Each execution:
494
- 1. Creates a tmux session
495
- 2. Runs skills in pipeline order via `claude --dangerously-skip-permissions`
496
- 3. Appends `execution-report` skill to report outcome
497
- 4. Environment variables `MINION_EXECUTION_ID`, `MINION_ROUTINE_ID`, `MINION_ROUTINE_NAME` are available during execution
498
-
499
- ## Workflow Step Execution via Pending Steps
500
-
501
- ミニオンエージェントは `GET /api/minion/pending-steps` を定期ポーリングし、
502
- 自分の担当ステップを検知したら Claude Code を起動してスキルを実行する。
503
-
504
- ```
505
- ミニオンエージェント (Port 3001, 常駐, トークン不要)
506
-
507
- ├── 軽量ポーリング: N秒ごとに GET /api/minion/pending-steps
508
- │ → HTTPのみ、AIなし、コストゼロ
509
- │ → pendingステップがなければ何もしない
510
-
511
- └── ステップ検知時のみ:
512
- 1. Claude Code 起動 → 該当スキルを実行
513
- 2. POST /api/minion/execution → ステップ完了を報告
514
- 3. Claude Code 終了 → トークン消費はここだけ
515
- ```
516
-
517
- ### Workflow Execution via Routine (従来方式)
368
+ ### Skills
518
369
 
519
- ワークフローは `project-workflow-check` システムスキルを通じてルーティンからも実行可能:
370
+ | Method | Endpoint | Description |
371
+ |--------|----------|-------------|
372
+ | GET | `/api/minion/skills` | HQ に登録されたスキル一覧 |
373
+ | GET | `/api/minion/skills/[name]` | スキル詳細取得(content, files 含む) |
374
+ | POST | `/api/minion/skills` | スキル登録/更新(新バージョン自動作成) |
520
375
 
521
- ```
522
- ルーティン: "morning-work" (cron: 0 9 * * 1-5)
523
- pipeline: [project-workflow-check, execution-report]
524
-
525
- project-workflow-check:
526
- 1. GET /api/minion/me/projects → 参加プロジェクト一覧
527
- 2. GET /api/minion/workflows → active なワークフロー一覧
528
- 3. 各ワークフローの pipeline を順に実行
529
-
530
- execution-report → HQ に結果報告
531
- ```
376
+ スキルはバージョン管理される。push ごとに新バージョンが作成され、ファイルは Supabase Storage に保存される。
@@ -0,0 +1,217 @@
1
+ # Minion Task Guides
2
+
3
+ よくある操作の手順書です。API仕様の詳細は `~/.minion/docs/api-reference.md` を参照してください。
4
+
5
+ ---
6
+
7
+ ## スキルの修正
8
+
9
+ ### 1. ローカルのスキルを編集する
10
+
11
+ ```bash
12
+ # スキル一覧を確認
13
+ minion-cli skill list --local
14
+
15
+ # SKILL.md を編集
16
+ vi ~/.claude/skills/<name>/SKILL.md
17
+ ```
18
+
19
+ SKILL.md フォーマット:
20
+ ```markdown
21
+ ---
22
+ name: my-skill
23
+ display_name: My Skill
24
+ description: What this skill does
25
+ ---
26
+
27
+ Skill instructions here...
28
+ ```
29
+
30
+ ### 2. HQ に反映する
31
+
32
+ ```bash
33
+ minion-cli skill push <name>
34
+ ```
35
+
36
+ push するとHQ上で新バージョンが自動作成されます。
37
+
38
+ ### 3. HQ からスキルを取得する
39
+
40
+ ```bash
41
+ # HQ上のスキル一覧
42
+ minion-cli skill list
43
+
44
+ # 特定のスキルをローカルにデプロイ
45
+ minion-cli skill fetch <name>
46
+ ```
47
+
48
+ ---
49
+
50
+ ## ワークフローの修正 (PM のみ)
51
+
52
+ ### パイプライン構成の変更
53
+
54
+ ```bash
55
+ # API経由で push (新バージョン自動作成)
56
+ curl -s -X POST "$HQ_URL/api/minion/workflows" \
57
+ -H "Authorization: Bearer $API_TOKEN" \
58
+ -H "Content-Type: application/json" \
59
+ -d '{
60
+ "name": "my-workflow",
61
+ "pipeline_skill_names": ["skill-1", "skill-2"],
62
+ "content": "Workflow description",
63
+ "project_id": "<project-uuid>",
64
+ "change_summary": "Updated pipeline"
65
+ }'
66
+ ```
67
+
68
+ ### ステップごとのロール・レビュー設定
69
+
70
+ ```bash
71
+ curl -s -X POST "$HQ_URL/api/minion/workflows" \
72
+ -H "Authorization: Bearer $API_TOKEN" \
73
+ -H "Content-Type: application/json" \
74
+ -d '{
75
+ "name": "my-workflow",
76
+ "pipeline_skill_names": ["skill-1", "skill-2"],
77
+ "pipeline_steps": [
78
+ { "assigned_role": "engineer", "requires_review": false },
79
+ { "assigned_role": "pm", "requires_review": true }
80
+ ],
81
+ "content": "Workflow description",
82
+ "project_id": "<project-uuid>"
83
+ }'
84
+ ```
85
+
86
+ ### ローカルワークフローの同期
87
+
88
+ ```bash
89
+ # HQからワークフローを取得 (不足スキルも自動fetch)
90
+ curl -s -X POST "http://localhost:3001/api/workflows/fetch/<name>" \
91
+ -H "Authorization: Bearer $API_TOKEN"
92
+
93
+ # ローカルワークフローをHQにpush (スキルも自動push)
94
+ curl -s -X POST "http://localhost:3001/api/workflows/push/<name>" \
95
+ -H "Authorization: Bearer $API_TOKEN"
96
+ ```
97
+
98
+ ---
99
+
100
+ ## プロジェクトコンテキストの操作
101
+
102
+ ### 取得
103
+
104
+ ```bash
105
+ # プロジェクト一覧を取得
106
+ curl -s "$HQ_URL/api/minion/me/projects" \
107
+ -H "Authorization: Bearer $API_TOKEN"
108
+
109
+ # コンテキストを取得
110
+ curl -s "$HQ_URL/api/minion/me/project/<project-id>/context" \
111
+ -H "Authorization: Bearer $API_TOKEN"
112
+ ```
113
+
114
+ ### 更新 (PM のみ)
115
+
116
+ ```bash
117
+ curl -s -X PUT "$HQ_URL/api/minion/me/project/<project-id>/context" \
118
+ -H "Authorization: Bearer $API_TOKEN" \
119
+ -H "Content-Type: application/json" \
120
+ -d '{ "content": "Updated context markdown" }'
121
+ ```
122
+
123
+ ---
124
+
125
+ ## 実行結果の確認
126
+
127
+ ### ローカル実行履歴
128
+
129
+ ```bash
130
+ # 最近の実行一覧
131
+ curl -s "http://localhost:3001/api/executions?limit=10" \
132
+ -H "Authorization: Bearer $API_TOKEN"
133
+
134
+ # 特定の実行ログ
135
+ curl -s "http://localhost:3001/api/executions/<id>/log" \
136
+ -H "Authorization: Bearer $API_TOKEN"
137
+ ```
138
+
139
+ ### 実行結果の報告
140
+
141
+ ```bash
142
+ curl -s -X POST "http://localhost:3001/api/executions/<id>/outcome" \
143
+ -H "Content-Type: application/json" \
144
+ -d '{
145
+ "outcome": "success",
146
+ "summary": "Brief summary",
147
+ "details": "## Detailed Report\n\n- Action 1\n- Action 2"
148
+ }'
149
+ ```
150
+
151
+ outcome values: `success`, `failure`, `partial`
152
+
153
+ ---
154
+
155
+ ## GitHub Issue の起票
156
+
157
+ バグや改善点を発見した場合:
158
+
159
+ ```bash
160
+ curl -s -X POST "$HQ_URL/api/minion/report" \
161
+ -H "Authorization: Bearer $API_TOKEN" \
162
+ -H "Content-Type: application/json" \
163
+ -d '{
164
+ "title": "Issue title",
165
+ "body": "## 状況\n...\n\n## 再現手順\n...",
166
+ "labels": ["bug"]
167
+ }'
168
+ ```
169
+
170
+ 使用可能なラベル: `bug`, `enhancement`, `critical`, `minor`
171
+
172
+ Node.js API も利用可能:
173
+
174
+ ```javascript
175
+ const { reportIssue } = require('@geekbeer/minion/api')
176
+ await reportIssue({ title: '...', body: '...', labels: ['bug'] })
177
+ ```
178
+
179
+ ---
180
+
181
+ ## トラブルシューティング
182
+
183
+ ### HQ APIの仕様がわからない
184
+
185
+ `~/.minion/docs/api-reference.md` に全エンドポイントの仕様が記載されています。
186
+ **HQのソースコードを読みに行く必要はありません。**
187
+
188
+ ### スキルが見つからない
189
+
190
+ ```bash
191
+ # ローカルスキル一覧
192
+ minion-cli skill list --local
193
+
194
+ # HQから再取得
195
+ minion-cli skill fetch <name>
196
+ ```
197
+
198
+ ### ワークフローが実行されない
199
+
200
+ ```bash
201
+ # ローカルワークフロー一覧 (next_run を確認)
202
+ curl -s "http://localhost:3001/api/workflows" \
203
+ -H "Authorization: Bearer $API_TOKEN"
204
+
205
+ # 手動トリガー
206
+ curl -s -X POST "http://localhost:3001/api/workflows/trigger" \
207
+ -H "Authorization: Bearer $API_TOKEN" \
208
+ -H "Content-Type: application/json" \
209
+ -d '{ "workflow_id": "<workflow-uuid>" }'
210
+ ```
211
+
212
+ ### エージェントの状態確認
213
+
214
+ ```bash
215
+ minion-cli health
216
+ minion-cli status
217
+ ```
package/minion-cli.sh CHANGED
@@ -628,8 +628,13 @@ SUPEOF
628
628
 
629
629
  if [ -d "$BUNDLED_RULES_DIR" ]; then
630
630
  $RUN_AS mkdir -p "$CLAUDE_RULES_DIR"
631
- $RUN_AS cp "$BUNDLED_RULES_DIR"/minion.md "$CLAUDE_RULES_DIR"/minion.md
632
- echo " -> Deployed Claude rules: minion.md"
631
+ $RUN_AS cp "$BUNDLED_RULES_DIR"/core.md "$CLAUDE_RULES_DIR"/core.md
632
+ echo " -> Deployed Claude rules: core.md"
633
+ # Remove legacy minion.md if present
634
+ if [ -f "$CLAUDE_RULES_DIR/minion.md" ]; then
635
+ $RUN_AS rm -f "$CLAUDE_RULES_DIR/minion.md"
636
+ echo " -> Removed legacy rules: minion.md"
637
+ fi
633
638
  fi
634
639
 
635
640
  # Step 10 (optional): Cloudflare Tunnel setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekbeer/minion",
3
- "version": "2.10.3",
3
+ "version": "2.11.1",
4
4
  "description": "AI Agent runtime for Minion - manages status and skill deployment on VPS",
5
5
  "main": "server.js",
6
6
  "bin": {
@@ -20,6 +20,8 @@
20
20
  "routes/",
21
21
  "skills/",
22
22
  "rules/",
23
+ "roles/",
24
+ "docs/",
23
25
  "settings/",
24
26
  "minion-cli.sh",
25
27
  ".env.example"
@@ -0,0 +1,31 @@
1
+ # Engineer Role Guidelines
2
+
3
+ このセッションではあなたは **Engineer** ロールとして行動します。
4
+
5
+ ## 責務
6
+
7
+ - **スキル実行**: 割り当てられたワークフローステップ(スキル)を確実に実行する
8
+ - **タスク完了**: スキルの指示に従い、成果物を生成する
9
+ - **結果報告**: 実行結果を `/execution-report` または API 経由で報告する
10
+
11
+ ## 重要なルール
12
+
13
+ - **ワークフローの構造変更(パイプライン構成、ステップ追加/削除)はPMの責任です。** 自分では変更しないでください。
14
+ - 割り当てられたスキルの実行に集中してください。
15
+ - スキルの内容(SKILL.md)の修正は可能です。修正後は `minion-cli skill push <name>` でHQに反映してください。
16
+
17
+ ## スキル修正
18
+
19
+ スキルの内容を改善する場合:
20
+
21
+ 1. `~/.claude/skills/<name>/SKILL.md` を編集
22
+ 2. `minion-cli skill push <name>` でHQに反映
23
+
24
+ 詳細な手順は `~/.minion/docs/task-guides.md` を参照。
25
+
26
+ ## 実行コンテキスト
27
+
28
+ ワークフロー実行中は以下の環境変数が利用可能:
29
+ - `MINION_EXECUTION_ID` — 現在の実行UUID
30
+ - `MINION_WORKFLOW_ID` — ワークフローUUID
31
+ - `MINION_WORKFLOW_NAME` — ワークフロー名
package/roles/pm.md ADDED
@@ -0,0 +1,58 @@
1
+ # PM Role Guidelines
2
+
3
+ このセッションではあなたは **PM (Project Manager)** ロールとして行動します。
4
+
5
+ ## 責務
6
+
7
+ - **ワークフロー管理**: ワークフローの作成・修正・バージョン管理
8
+ - **プロジェクトコンテキスト管理**: プロジェクトの共有コンテキスト(markdown)の更新
9
+ - **オーケストレーション**: ワークフローステップのディスパッチ、エンジニアミニオンへの指示
10
+ - **レビュー**: `requires_review=true` のステップの承認判断
11
+
12
+ ## Workflow Execution Model
13
+
14
+ ワークフロー実行はHQのDBがステートマシンとして管理する。ミニオン間の直接通信は不要。
15
+
16
+ ```
17
+ 1. Execution 作成 → workflow_execution + 全 step_executions (status='pending')
18
+ 2. ミニオンエージェントが GET /api/minion/pending-steps をポーリング
19
+ → 自分のロールに該当 & 前ステップ完了済みのステップを取得
20
+ 3. ミニオンがステップを実行し完了を報告
21
+ 4. 次ステップが eligible に → 別のミニオンが検知して実行
22
+ 5. 全ステップ完了 → execution 全体を completed に
23
+ ```
24
+
25
+ ポイント:
26
+ - HQの責務は「executionレコードを作る(指示書発行)」だけ
27
+ - 各ミニオンは自分の担当ステップだけをポーリングして実行
28
+ - ミニオンエージェント(Port 3001)が軽量HTTPポーリングを行い、pending検知時のみClaude Codeを起動
29
+
30
+ ## Workflow 管理
31
+
32
+ ワークフローはプロジェクトスコープ・バージョン管理される。
33
+
34
+ - 作成/修正: `POST /api/minion/workflows` で push(新バージョン自動作成)
35
+ - 各ステップに `assigned_role` (pm/engineer) と `requires_review` を設定可能
36
+ - `is_my_step` フラグで自分の担当ステップを確認
37
+
38
+ 詳細な API 仕様とリクエスト/レスポンス形式は `~/.minion/docs/api-reference.md` を参照。
39
+ ワークフロー修正の具体的な手順は `~/.minion/docs/task-guides.md` を参照。
40
+
41
+ ## Project Context 管理
42
+
43
+ - `GET /api/minion/me/project/[id]/context` でコンテキスト取得
44
+ - `PUT /api/minion/me/project/[id]/context` でコンテキスト更新(PMのみ)
45
+
46
+ ## Routine (従来方式)
47
+
48
+ ワークフローは `project-workflow-check` システムスキルを通じてルーティンからも実行可能:
49
+
50
+ ```
51
+ ルーティン: "morning-work" (cron: 0 9 * * 1-5)
52
+ pipeline: [project-workflow-check, execution-report]
53
+
54
+ project-workflow-check:
55
+ 1. GET /api/minion/me/projects → 参加プロジェクト一覧
56
+ 2. GET /api/minion/workflows → active なワークフロー一覧
57
+ 3. 各ワークフローの pipeline を順に実行
58
+ ```
package/routes/skills.js CHANGED
@@ -288,7 +288,7 @@ async function skillRoutes(fastify) {
288
288
  return { success: false, error: 'Unauthorized' }
289
289
  }
290
290
 
291
- const { skill_name, execution_id, step_index, workflow_name } = request.body || {}
291
+ const { skill_name, execution_id, step_index, workflow_name, role } = request.body || {}
292
292
 
293
293
  if (!skill_name) {
294
294
  reply.code(400)
@@ -335,6 +335,7 @@ async function skillRoutes(fastify) {
335
335
  // because the post-execution hook below handles completion reporting.
336
336
  const isDispatchedStep = execution_id && step_index != null
337
337
  const runOptions = isDispatchedStep ? { skipExecutionReport: true } : {}
338
+ if (role) runOptions.role = role
338
339
 
339
340
  // Run asynchronously — respond immediately
340
341
  const executionPromise = (async () => {
package/routine-runner.js CHANGED
@@ -97,7 +97,13 @@ async function executeRoutineSession(routine, executionId, skillNames) {
97
97
 
98
98
  // Build prompt: run each skill in sequence, then execution-report
99
99
  const skillCommands = skillNames.map(name => `/${name}`).join(', then ')
100
- const prompt = `Run the following skills in order: ${skillCommands}. After completing all skills, run /execution-report to report the results.`
100
+
101
+ // Inject routine context as prompt prefix (mirrors workflow-runner's role injection pattern)
102
+ const contextPrefix = routine.context
103
+ ? `## Context\n\n${routine.context}\n\n---\n\n`
104
+ : ''
105
+
106
+ const prompt = `${contextPrefix}Run the following skills in order: ${skillCommands}. After completing all skills, run /execution-report to report the results.`
101
107
 
102
108
  // Extend PATH to include common CLI installation locations
103
109
  const additionalPaths = [
package/routine-store.js CHANGED
@@ -94,6 +94,7 @@ async function upsertFromHQ(routineData) {
94
94
  name: routineData.name,
95
95
  pipeline_skill_names: routineData.pipeline_skill_names,
96
96
  content: routineData.content || '',
97
+ context: routineData.context || null,
97
98
  is_active: routineData.is_active,
98
99
  cron_expression: routineData.cron_expression || '',
99
100
  }
@@ -103,6 +104,7 @@ async function upsertFromHQ(routineData) {
103
104
  name: routineData.name,
104
105
  pipeline_skill_names: routineData.pipeline_skill_names || [],
105
106
  content: routineData.content || '',
107
+ context: routineData.context || null,
106
108
  is_active: routineData.is_active ?? false,
107
109
  cron_expression: routineData.cron_expression || '',
108
110
  last_run: routineData.last_run || null,
package/rules/core.md ADDED
@@ -0,0 +1,94 @@
1
+ # Minion Agent
2
+
3
+ You are an AI agent running on a Minion VPS, managed by @geekbeer/minion.
4
+
5
+ ## Important Principles
6
+
7
+ - **HQサーバーのソースコードを読みに行く必要はありません。** 必要なAPI仕様はすべてドキュメントに記載されています。
8
+ - API の詳細仕様が必要な場合は `~/.minion/docs/api-reference.md` を参照してください。
9
+ - タスクの手順が不明な場合は `~/.minion/docs/task-guides.md` を参照してください。
10
+
11
+ ## Architecture
12
+
13
+ ```
14
+ Project (組織・課金単位)
15
+ ├── Context (markdown, PMが更新)
16
+ ├── Members (minion + role: pm | engineer)
17
+ └── Workflows (スキルのパイプライン + オプションcronスケジュール)
18
+ ├── Versions (pipeline の不変スナップショット)
19
+ └── Executions (実行履歴, ステップごとの進捗)
20
+
21
+ Minion
22
+ └── Routines (ミニオンローカルの定期タスク, cron付き)
23
+ ```
24
+
25
+ - **Workflow**: プロジェクトスコープ。バージョン管理されたスキルパイプライン。
26
+ - **Routine**: ミニオンスコープ。ミニオンローカルの定期タスク。
27
+ - ミニオンは複数プロジェクトに `pm` または `engineer` として参加できる。
28
+
29
+ ## Available Tools
30
+
31
+ ### CLI
32
+
33
+ ```bash
34
+ minion-cli status # ステータス確認
35
+ minion-cli health # ヘルスチェック
36
+ minion-cli set-status <status> [task] # ステータス更新
37
+ minion-cli skill push <name> # スキルをHQにpush
38
+ minion-cli skill fetch <name> # HQからスキルをfetch
39
+ minion-cli skill list [--local] # スキル一覧
40
+ minion-cli --version # バージョン確認
41
+ ```
42
+
43
+ ### Local Agent API
44
+
45
+ `http://localhost:3001` — 認証: `Authorization: Bearer $API_TOKEN`
46
+
47
+ 主なカテゴリ: Health, Skills, Workflows, Executions, Terminal, Files, Commands
48
+
49
+ ### HQ API
50
+
51
+ `$HQ_URL/api/minion/*` — 認証: `Authorization: Bearer $API_TOKEN`
52
+
53
+ 主なカテゴリ: Projects, Context, Workflows, Skills, Executions, Routines, Reports
54
+
55
+ ## Environment Variables
56
+
57
+ | Variable | Description |
58
+ |----------|-------------|
59
+ | `HQ_URL` | HQ server URL (empty = standalone mode) |
60
+ | `API_TOKEN` | Bearer token for HQ and local API auth |
61
+ | `MINION_ID` | UUID assigned by HQ |
62
+ | `AGENT_PORT` | Agent HTTP port (default: 3001) |
63
+ | `MINION_USER` | System user running the agent |
64
+
65
+ Workflow/Routine 実行中は以下も利用可能:
66
+ - `MINION_EXECUTION_ID` — 実行UUID
67
+ - `MINION_WORKFLOW_ID` / `MINION_ROUTINE_ID` — ワークフロー/ルーティンUUID
68
+ - `MINION_WORKFLOW_NAME` / `MINION_ROUTINE_NAME` — 名前
69
+
70
+ ## Skills Directory
71
+
72
+ ```
73
+ ~/.claude/skills/<name>/
74
+ SKILL.md # スキル定義 (YAML frontmatter + markdown)
75
+ references/ # 参照ファイル (オプション)
76
+ ```
77
+
78
+ ## HQ Connection
79
+
80
+ `HQ_URL` と `API_TOKEN` が設定されている場合、HQと同期。
81
+ 未設定の場合はスタンドアロンモードで動作。
82
+
83
+ ## Role Context
84
+
85
+ ワークフロー実行時、ロールに応じたガイドラインがプロンプトで指示されます。
86
+ ロールファイルは `~/.minion/roles/` に配置されています:
87
+ - `pm.md` — PM (Project Manager) のガイドライン
88
+ - `engineer.md` — Engineer のガイドライン
89
+
90
+ ## Documentation
91
+
92
+ API仕様やタスク手順の詳細は以下を参照:
93
+ - `~/.minion/docs/api-reference.md` — ローカルAPI・HQ APIの全エンドポイント仕様
94
+ - `~/.minion/docs/task-guides.md` — スキル修正・ワークフロー管理等の手順書
package/server.js CHANGED
@@ -103,7 +103,8 @@ function syncTmuxConfig() {
103
103
 
104
104
  /**
105
105
  * Sync bundled rules from the package to ~/.claude/rules/.
106
- * Runs on every server start to ensure rules stay up-to-date after package updates.
106
+ * Deploys core.md only. Role context is injected per-execution, not as rules.
107
+ * Removes legacy files (minion.md, role-*.md) if present.
107
108
  */
108
109
  function syncBundledRules() {
109
110
  const bundledRulesDir = path.join(__dirname, 'rules')
@@ -114,24 +115,90 @@ function syncBundledRules() {
114
115
 
115
116
  fs.mkdirSync(targetRulesDir, { recursive: true })
116
117
 
117
- for (const file of fs.readdirSync(bundledRulesDir)) {
118
+ // Always deploy core.md
119
+ const coreSrc = path.join(bundledRulesDir, 'core.md')
120
+ if (fs.existsSync(coreSrc)) {
121
+ fs.copyFileSync(coreSrc, path.join(targetRulesDir, 'core.md'))
122
+ console.log('[Rules] Synced: core.md')
123
+ }
124
+
125
+ // Remove legacy files if present
126
+ for (const legacy of ['minion.md', 'role-pm.md', 'role-engineer.md']) {
127
+ const legacyPath = path.join(targetRulesDir, legacy)
128
+ if (fs.existsSync(legacyPath)) {
129
+ fs.unlinkSync(legacyPath)
130
+ console.log(`[Rules] Removed legacy: ${legacy}`)
131
+ }
132
+ }
133
+ } catch (err) {
134
+ console.error(`[Rules] Failed to sync bundled rules: ${err.message}`)
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Sync bundled role context files to ~/.minion/roles/.
140
+ * These are NOT loaded as Claude Code rules — they are injected
141
+ * into the prompt at execution time based on the minion's role.
142
+ */
143
+ function syncBundledRoles() {
144
+ const bundledRolesDir = path.join(__dirname, 'roles')
145
+ const targetRolesDir = path.join(config.HOME_DIR, '.minion', 'roles')
146
+
147
+ try {
148
+ if (!fs.existsSync(bundledRolesDir)) return
149
+
150
+ fs.mkdirSync(targetRolesDir, { recursive: true })
151
+
152
+ for (const file of fs.readdirSync(bundledRolesDir)) {
118
153
  if (!file.endsWith('.md')) continue
119
- const src = path.join(bundledRulesDir, file)
120
- const dest = path.join(targetRulesDir, file)
154
+ const src = path.join(bundledRolesDir, file)
155
+ const dest = path.join(targetRolesDir, file)
121
156
  fs.copyFileSync(src, dest)
122
- console.log(`[Rules] Synced: ${file}`)
157
+ console.log(`[Roles] Synced: ${file}`)
123
158
  }
124
159
  } catch (err) {
125
- console.error(`[Rules] Failed to sync bundled rules: ${err.message}`)
160
+ console.error(`[Roles] Failed to sync bundled roles: ${err.message}`)
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Sync bundled documentation files to ~/.minion/docs/.
166
+ * These are reference documents accessed on-demand by Claude Code,
167
+ * NOT loaded automatically as rules.
168
+ */
169
+ function syncBundledDocs() {
170
+ const bundledDocsDir = path.join(__dirname, 'docs')
171
+ const targetDocsDir = path.join(config.HOME_DIR, '.minion', 'docs')
172
+
173
+ try {
174
+ if (!fs.existsSync(bundledDocsDir)) return
175
+
176
+ fs.mkdirSync(targetDocsDir, { recursive: true })
177
+
178
+ for (const file of fs.readdirSync(bundledDocsDir)) {
179
+ if (!file.endsWith('.md')) continue
180
+ const src = path.join(bundledDocsDir, file)
181
+ const dest = path.join(targetDocsDir, file)
182
+ fs.copyFileSync(src, dest)
183
+ console.log(`[Docs] Synced: ${file}`)
184
+ }
185
+ } catch (err) {
186
+ console.error(`[Docs] Failed to sync bundled docs: ${err.message}`)
126
187
  }
127
188
  }
128
189
 
129
190
  // Start server
130
191
  async function start() {
131
192
  try {
132
- // Sync bundled rules to ~/.claude/rules/ (keeps rules fresh after package updates)
193
+ // Sync bundled rules to ~/.claude/rules/ (core.md only)
133
194
  syncBundledRules()
134
195
 
196
+ // Sync bundled roles to ~/.minion/roles/ (injected per-execution)
197
+ syncBundledRoles()
198
+
199
+ // Sync bundled docs to ~/.minion/docs/ (on-demand reference)
200
+ syncBundledDocs()
201
+
135
202
  // Sync bundled permissions to ~/.claude/settings.json (broad allow + deny-list)
136
203
  syncPermissions()
137
204
 
@@ -98,9 +98,15 @@ async function executeWorkflowSession(workflow, executionId, skillNames, options
98
98
  // When skipExecutionReport is true (dispatched step), the minion server's
99
99
  // post-execution hook handles completion reporting instead of /execution-report.
100
100
  const skillCommands = skillNames.map(name => `/${name}`).join(', then ')
101
+
102
+ // Inject role context if provided (e.g. "pm" or "engineer")
103
+ const rolePrefix = options.role
104
+ ? `You are acting as the "${options.role}" role in this session. Read ~/.minion/roles/${options.role}.md for your role guidelines before proceeding.\n\n`
105
+ : ''
106
+
101
107
  const prompt = options.skipExecutionReport
102
- ? `Run the following skills in order: ${skillCommands}.`
103
- : `Run the following skills in order: ${skillCommands}. After completing all skills, run /execution-report to report the results.`
108
+ ? `${rolePrefix}Run the following skills in order: ${skillCommands}.`
109
+ : `${rolePrefix}Run the following skills in order: ${skillCommands}. After completing all skills, run /execution-report to report the results.`
104
110
 
105
111
  // Extend PATH to include common CLI installation locations
106
112
  const additionalPaths = [