beeops 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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +156 -0
  3. package/README.md +80 -0
  4. package/bin/beeops.js +502 -0
  5. package/command/bo.md +120 -0
  6. package/contexts/agent-modes.json +100 -0
  7. package/contexts/code-reviewer.md +118 -0
  8. package/contexts/coder.md +247 -0
  9. package/contexts/default.md +1 -0
  10. package/contexts/en/agent-modes.json +100 -0
  11. package/contexts/en/code-reviewer.md +129 -0
  12. package/contexts/en/coder.md +247 -0
  13. package/contexts/en/default.md +1 -0
  14. package/contexts/en/fb.md +15 -0
  15. package/contexts/en/leader.md +158 -0
  16. package/contexts/en/log.md +16 -0
  17. package/contexts/en/queen.md +240 -0
  18. package/contexts/en/review-leader.md +190 -0
  19. package/contexts/en/reviewer-base.md +27 -0
  20. package/contexts/en/security-reviewer.md +200 -0
  21. package/contexts/en/test-auditor.md +146 -0
  22. package/contexts/en/tester.md +135 -0
  23. package/contexts/en/worker-base.md +69 -0
  24. package/contexts/fb.md +15 -0
  25. package/contexts/ja/agent-modes.json +100 -0
  26. package/contexts/ja/code-reviewer.md +129 -0
  27. package/contexts/ja/coder.md +247 -0
  28. package/contexts/ja/default.md +1 -0
  29. package/contexts/ja/fb.md +15 -0
  30. package/contexts/ja/leader.md +158 -0
  31. package/contexts/ja/log.md +17 -0
  32. package/contexts/ja/queen.md +240 -0
  33. package/contexts/ja/review-leader.md +190 -0
  34. package/contexts/ja/reviewer-base.md +27 -0
  35. package/contexts/ja/security-reviewer.md +200 -0
  36. package/contexts/ja/test-auditor.md +146 -0
  37. package/contexts/ja/tester.md +135 -0
  38. package/contexts/ja/worker-base.md +68 -0
  39. package/contexts/leader.md +158 -0
  40. package/contexts/log.md +16 -0
  41. package/contexts/queen.md +240 -0
  42. package/contexts/review-leader.md +190 -0
  43. package/contexts/reviewer-base.md +27 -0
  44. package/contexts/security-reviewer.md +200 -0
  45. package/contexts/test-auditor.md +146 -0
  46. package/contexts/tester.md +135 -0
  47. package/contexts/worker-base.md +69 -0
  48. package/hooks/checkpoint.py +89 -0
  49. package/hooks/prompt-context.py +139 -0
  50. package/hooks/resolve-log-path.py +93 -0
  51. package/hooks/run-log.py +429 -0
  52. package/package.json +42 -0
  53. package/scripts/launch-leader.sh +282 -0
  54. package/scripts/launch-worker.sh +184 -0
  55. package/skills/bo-dispatch/SKILL.md +299 -0
  56. package/skills/bo-issue-sync/SKILL.md +103 -0
  57. package/skills/bo-leader-dispatch/SKILL.md +211 -0
  58. package/skills/bo-log-writer/SKILL.md +101 -0
  59. package/skills/bo-review-backend/SKILL.md +234 -0
  60. package/skills/bo-review-database/SKILL.md +243 -0
  61. package/skills/bo-review-frontend/SKILL.md +236 -0
  62. package/skills/bo-review-operations/SKILL.md +268 -0
  63. package/skills/bo-review-process/SKILL.md +181 -0
  64. package/skills/bo-review-security/SKILL.md +214 -0
  65. package/skills/bo-review-security/references/finance-security.md +351 -0
  66. package/skills/bo-self-improver/SKILL.md +145 -0
  67. package/skills/bo-self-improver/refs/agent-manager.md +61 -0
  68. package/skills/bo-self-improver/refs/command-manager.md +46 -0
  69. package/skills/bo-self-improver/refs/skill-manager.md +59 -0
  70. package/skills/bo-self-improver/scripts/analyze.py +359 -0
  71. package/skills/bo-task-decomposer/SKILL.md +130 -0
@@ -0,0 +1,214 @@
1
+ ---
2
+ name: bo-review-security
3
+ description: "[Cross-cutting skill] Always triggered in pair with bo-review-backend/frontend/database during code reviews. Checks authentication, authorization, encryption, and input validation. OAuth 2.1, Zero Trust, mTLS, OWASP countermeasures."
4
+ ---
5
+
6
+ ## Usage Contract
7
+
8
+ When using this skill, always include the following at the beginning of your output:
9
+
10
+ ```
11
+ [SKILL_USED: bo-review-security]
12
+ ```
13
+
14
+ ---
15
+
16
+ # Security Review Guide
17
+
18
+ Security-focused review checklist.
19
+
20
+ ---
21
+
22
+ ## Authentication
23
+
24
+ ### OAuth 2.1 Compliance
25
+
26
+ - [ ] Is PKCE (Proof Key for Code Exchange) used?
27
+ - [ ] Is exact Redirect URI matching enforced?
28
+ - [ ] Are deprecated grant types (Implicit, Password) not used?
29
+ - [ ] Are short-lived tokens + refresh tokens used?
30
+
31
+ ### Token Management
32
+
33
+ | Item | Recommendation |
34
+ | -------------------------- | --------------------------------------- |
35
+ | Access token lifetime | 15 min - 1 hour |
36
+ | Refresh token | Rotation required |
37
+ | Storage | HttpOnly Cookie or Secure Storage |
38
+ | Static API keys | Avoid (use short-lived tokens) |
39
+
40
+ ### mTLS (Mutual TLS)
41
+
42
+ - [ ] Is mTLS used for service-to-service communication?
43
+ - [ ] Is client certificate verification performed?
44
+ - [ ] Is there a certificate rotation plan?
45
+
46
+ ---
47
+
48
+ ## Authorization
49
+
50
+ ### Zero Trust Principles
51
+
52
+ > "Never trust, always verify"
53
+
54
+ - [ ] Is authorization checked on every request?
55
+ - [ ] Are requests from internal networks also verified?
56
+ - [ ] Is the principle of least privilege followed?
57
+
58
+ ### RBAC / ABAC
59
+
60
+ - [ ] Is there role-based or attribute-based access control?
61
+ - [ ] Is there resource-level authorization (BOLA prevention)?
62
+ - [ ] Is authorization logic centralized?
63
+
64
+ ### OWASP API Security Top 10 Countermeasures
65
+
66
+ | Threat | Countermeasure |
67
+ | ------------------------------------------- | ------------------------------------ |
68
+ | BOLA (Broken Object Level Authorization) | Owner check per resource |
69
+ | BFLA (Broken Function Level Authorization) | Permission check per endpoint |
70
+ | Excessive Data Exposure | Return minimum necessary data only |
71
+ | Mass Assignment | Accept only permitted fields |
72
+
73
+ ---
74
+
75
+ ## Encryption
76
+
77
+ ### In-Transit Encryption
78
+
79
+ - [ ] Is TLS 1.3 used?
80
+ - [ ] Is TLS 1.2 and below disabled?
81
+ - [ ] Is the HSTS header set?
82
+
83
+ ### At-Rest Encryption
84
+
85
+ - [ ] Are passwords hashed with bcrypt/Argon2?
86
+ - [ ] Is sensitive data encrypted with AES-256?
87
+ - [ ] Are encryption keys managed securely (KMS, etc.)?
88
+
89
+ ### Secret Management
90
+
91
+ - [ ] Are secrets not hardcoded in source code?
92
+ - [ ] Are environment variables or Secret Manager used?
93
+ - [ ] Is there a secret rotation plan?
94
+
95
+ ---
96
+
97
+ ## Input Validation
98
+
99
+ ### Validation
100
+
101
+ - [ ] Is all external input validated server-side?
102
+ - [ ] Are type, length, format, and range checked?
103
+ - [ ] Is an allowlist approach adopted?
104
+
105
+ ### Injection Prevention
106
+
107
+ | Attack | Countermeasure |
108
+ | ----------------- | ----------------------------- |
109
+ | SQL Injection | Parameterized queries |
110
+ | NoSQL Injection | Input type checking, sanitize |
111
+ | XSS | Output escaping, CSP |
112
+ | Command Injection | Avoid shell invocations |
113
+
114
+ ### Rate Limiting
115
+
116
+ - [ ] Are rate limits set on APIs?
117
+ - [ ] Is there brute force attack prevention?
118
+ - [ ] Is there DDoS protection (WAF, CDN)?
119
+
120
+ ---
121
+
122
+ ## Logging & Monitoring
123
+
124
+ ### Security Logging
125
+
126
+ - [ ] Are authentication successes/failures logged?
127
+ - [ ] Are authorization failures logged?
128
+ - [ ] Is sensitive information excluded from logs?
129
+
130
+ ### Anomaly Detection
131
+
132
+ - [ ] Can abnormal access patterns be detected?
133
+ - [ ] Are alerting rules configured?
134
+ - [ ] Are incident response procedures in place?
135
+
136
+ ---
137
+
138
+ ## AI Threat Detection (Current Trends)
139
+
140
+ - [ ] Has AI/ML-based anomaly detection been considered?
141
+ - [ ] Is API behavior analysis in place?
142
+ - [ ] Is automated threat response available?
143
+
144
+ ---
145
+
146
+ ## Final Checklist
147
+
148
+ - [ ] Has each item of OWASP Top 10 been verified?
149
+ - [ ] Has penetration testing been conducted?
150
+ - [ ] Has a security review been performed?
151
+
152
+ ---
153
+
154
+ ## Output Format
155
+
156
+ ```
157
+ ## Security Review Result
158
+ [LGTM / Needs Changes / Needs Discussion]
159
+
160
+ ## Check Results
161
+ | Category | Status | Notes |
162
+ |----------|--------|-------|
163
+ | Authentication | OK/NG | ... |
164
+ | Authorization | OK/NG | ... |
165
+ | Encryption | OK/NG | ... |
166
+ | Input Validation | OK/NG | ... |
167
+ | Logging & Monitoring | OK/NG | ... |
168
+
169
+ ## Issues Found
170
+ - Threat: [what is the issue]
171
+ - Risk: [High/Medium/Low]
172
+ - Countermeasure: [how to fix]
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Financial Security (Additional)
178
+
179
+ Additional checks for critical transactions involving finance, payments, points, etc.
180
+
181
+ See `references/finance-security.md` for details.
182
+
183
+ ### Race Condition Prevention
184
+
185
+ - [ ] Is optimistic locking (version column) used?
186
+ - [ ] Is pessimistic locking (SELECT FOR UPDATE) used appropriately?
187
+ - [ ] Have concurrent request tests been conducted?
188
+
189
+ ### Transaction Integrity
190
+
191
+ - [ ] Are critical operations executed within transactions?
192
+ - [ ] Is the transaction isolation level appropriate?
193
+ - [ ] Are partial commits prevented?
194
+
195
+ ### Idempotency (Double Processing Prevention)
196
+
197
+ - [ ] Is an Idempotency Key used?
198
+ - [ ] Is double processing prevented on retry?
199
+ - [ ] Is there a duplicate request check?
200
+
201
+ ### Enhanced Session Management
202
+
203
+ - [ ] Is there session fixation attack prevention?
204
+ - [ ] Is concurrent login control in place?
205
+ - [ ] Is re-authentication required for high-risk operations?
206
+
207
+ ---
208
+
209
+ ## References
210
+
211
+ - [OWASP API Security Top 10](https://owasp.org/API-Security/)
212
+ - [OAuth 2.1 Draft](https://oauth.net/2.1/)
213
+ - [Zero Trust Architecture (NIST)](https://www.nist.gov/publications/zero-trust-architecture)
214
+ - `references/finance-security.md` - Financial security details
@@ -0,0 +1,351 @@
1
+ # 金融系セキュリティ詳細ガイド
2
+
3
+ 金融・決済・ポイント等の重要トランザクションを扱う場合の詳細なセキュリティチェックリスト。
4
+
5
+ ---
6
+
7
+ ## 1. レースコンディション対策
8
+
9
+ ### 1.1 楽観的ロック
10
+
11
+ データ競合を検出するためのバージョン管理。
12
+
13
+ ```typescript
14
+ // Prismaでの実装例
15
+ const updated = await prisma.account.update({
16
+ where: {
17
+ id: accountId,
18
+ version: currentVersion, // バージョンチェック
19
+ },
20
+ data: {
21
+ balance: { decrement: amount },
22
+ version: { increment: 1 },
23
+ },
24
+ });
25
+
26
+ if (!updated) {
27
+ throw new OptimisticLockError('データが更新されました。再試行してください');
28
+ }
29
+ ```
30
+
31
+ ### 1.2 悲観的ロック
32
+
33
+ トランザクション中に他のアクセスをブロック。
34
+
35
+ ```typescript
36
+ // SELECT FOR UPDATEの使用
37
+ await prisma.$transaction(async (tx) => {
38
+ // 行ロックを取得
39
+ const account = await tx.$queryRaw`
40
+ SELECT * FROM accounts WHERE id = ${accountId} FOR UPDATE
41
+ `;
42
+
43
+ // 残高チェック
44
+ if (account.balance < amount) {
45
+ throw new InsufficientBalanceError();
46
+ }
47
+
48
+ // 更新
49
+ await tx.account.update({
50
+ where: { id: accountId },
51
+ data: { balance: { decrement: amount } },
52
+ });
53
+ });
54
+ ```
55
+
56
+ ### 1.3 チェックリスト
57
+
58
+ | 項目 | 必須 | 備考 |
59
+ | --------------------------- | ---- | ---------------- |
60
+ | version列の追加 | ✅ | 楽観的ロック用 |
61
+ | 更新時のバージョンチェック | ✅ | WHERE句に含める |
62
+ | 残高変更はSELECT FOR UPDATE | ✅ | 悲観的ロック |
63
+ | ロック取得順序の統一 | ✅ | デッドロック防止 |
64
+ | 並行リクエストテストの実施 | ✅ | 100並列等で検証 |
65
+
66
+ ---
67
+
68
+ ## 2. トランザクション整合性
69
+
70
+ ### 2.1 トランザクション分離レベル
71
+
72
+ | レベル | 用途 | PostgreSQLデフォルト |
73
+ | --------------- | -------------------- | -------------------- |
74
+ | READ COMMITTED | 一般的なCRUD | ✅ |
75
+ | REPEATABLE READ | レポート生成、集計 | |
76
+ | SERIALIZABLE | 金融トランザクション | 推奨 |
77
+
78
+ ```typescript
79
+ // Serializableトランザクション
80
+ await prisma.$transaction(
81
+ async (tx) => {
82
+ // 金融処理
83
+ },
84
+ {
85
+ isolationLevel: 'Serializable',
86
+ }
87
+ );
88
+ ```
89
+
90
+ ### 2.2 アトミック操作
91
+
92
+ ```typescript
93
+ // ❌ 悪い例: 残高チェックと更新が分離
94
+ const account = await prisma.account.findUnique({ where: { id } });
95
+ if (account.balance >= amount) {
96
+ await prisma.account.update({ where: { id }, data: { balance: { decrement: amount } } });
97
+ }
98
+
99
+ // ✅ 良い例: 単一のアトミック操作
100
+ const result = await prisma.account.updateMany({
101
+ where: {
102
+ id: accountId,
103
+ balance: { gte: amount }, // 条件と更新を一体化
104
+ },
105
+ data: {
106
+ balance: { decrement: amount },
107
+ },
108
+ });
109
+
110
+ if (result.count === 0) {
111
+ throw new InsufficientBalanceError();
112
+ }
113
+ ```
114
+
115
+ ### 2.3 チェックリスト
116
+
117
+ | 項目 | 必須 | 備考 |
118
+ | ---------------------------------- | ---- | ------------------------- |
119
+ | 複数テーブル更新はトランザクション | ✅ | 部分的コミット防止 |
120
+ | 金融処理はSerializable | ✅ | 最高分離レベル |
121
+ | 残高チェックはアトミック | ✅ | 読み取り→更新を分離しない |
122
+ | ロールバック処理の実装 | ✅ | 外部API呼び出し時 |
123
+
124
+ ---
125
+
126
+ ## 3. 二重処理防止(べき等性)
127
+
128
+ ### 3.1 べき等性キー
129
+
130
+ ```typescript
131
+ // クライアント側: 一意のキーを生成
132
+ const idempotencyKey = crypto.randomUUID();
133
+
134
+ // サーバー側: キーをチェック
135
+ async function processPayment(key: string, data: PaymentData) {
136
+ // 既存のリクエストをチェック
137
+ const existing = await redis.get(`idempotency:${key}`);
138
+ if (existing) {
139
+ return JSON.parse(existing); // 前回の結果を返す
140
+ }
141
+
142
+ // 処理実行
143
+ const result = await executePayment(data);
144
+
145
+ // 結果をキャッシュ(24時間保持)
146
+ await redis.setex(`idempotency:${key}`, 86400, JSON.stringify(result));
147
+
148
+ return result;
149
+ }
150
+ ```
151
+
152
+ ### 3.2 データベースレベルの重複防止
153
+
154
+ ```sql
155
+ -- ユニーク制約
156
+ ALTER TABLE transactions ADD CONSTRAINT unique_idempotency_key
157
+ UNIQUE (idempotency_key);
158
+
159
+ -- 挿入時
160
+ INSERT INTO transactions (id, idempotency_key, amount, ...)
161
+ VALUES (..., 'key-123', 1000, ...)
162
+ ON CONFLICT (idempotency_key) DO NOTHING
163
+ RETURNING *;
164
+ ```
165
+
166
+ ### 3.3 チェックリスト
167
+
168
+ | 項目 | 必須 | 備考 |
169
+ | ---------------------- | ---- | --------------------- |
170
+ | べき等性キーの受け入れ | ✅ | APIヘッダーで受け取る |
171
+ | 重複リクエストの検出 | ✅ | Redis/DBでチェック |
172
+ | 前回結果の返却 | ✅ | 同じ結果を返す |
173
+ | キーの有効期限設定 | ✅ | 24時間〜7日程度 |
174
+ | DBユニーク制約 | ✅ | 最終防衛線 |
175
+
176
+ ---
177
+
178
+ ## 4. セッション管理強化
179
+
180
+ ### 4.1 セッション固定攻撃対策
181
+
182
+ ```typescript
183
+ // ログイン成功時にセッションIDを再生成
184
+ async function login(credentials: Credentials) {
185
+ const user = await authenticate(credentials);
186
+
187
+ // 古いセッションを破棄
188
+ await session.destroy();
189
+
190
+ // 新しいセッションを作成
191
+ await session.regenerate();
192
+ session.userId = user.id;
193
+
194
+ return user;
195
+ }
196
+ ```
197
+
198
+ ### 4.2 同時ログイン制御
199
+
200
+ ```typescript
201
+ // ログイン時に既存セッションを無効化
202
+ async function login(userId: string) {
203
+ // 既存のセッションをすべて無効化
204
+ await redis.del(`sessions:user:${userId}:*`);
205
+
206
+ // 新しいセッションを作成
207
+ const sessionId = crypto.randomUUID();
208
+ await redis.setex(`sessions:user:${userId}:${sessionId}`, 3600, 'active');
209
+
210
+ return sessionId;
211
+ }
212
+
213
+ // または、最大セッション数を制限
214
+ async function enforceSessionLimit(userId: string, maxSessions = 3) {
215
+ const sessions = await redis.keys(`sessions:user:${userId}:*`);
216
+ if (sessions.length >= maxSessions) {
217
+ // 最も古いセッションを削除
218
+ await redis.del(sessions[0]);
219
+ }
220
+ }
221
+ ```
222
+
223
+ ### 4.3 高リスク操作時の再認証
224
+
225
+ ```typescript
226
+ // 送金、パスワード変更等の前に再認証を要求
227
+ async function transferMoney(userId: string, data: TransferData) {
228
+ const lastAuth = await getLastAuthTime(userId);
229
+ const now = Date.now();
230
+
231
+ // 5分以内に認証していない場合は再認証を要求
232
+ if (now - lastAuth > 5 * 60 * 1000) {
233
+ throw new ReauthenticationRequired('高リスク操作のため再認証が必要です');
234
+ }
235
+
236
+ return executeTransfer(data);
237
+ }
238
+ ```
239
+
240
+ ### 4.4 チェックリスト
241
+
242
+ | 項目 | 必須 | 備考 |
243
+ | ------------------------------ | ---- | ------------------------ |
244
+ | ログイン時のセッションID再生成 | ✅ | 固定攻撃対策 |
245
+ | セッションの有効期限設定 | ✅ | 1時間〜24時間 |
246
+ | 同時ログイン制御 | 推奨 | 最大3-5セッション |
247
+ | 高リスク操作の再認証 | ✅ | 送金、設定変更等 |
248
+ | セッションハイジャック検出 | 推奨 | IPアドレス、UA変化の検知 |
249
+
250
+ ---
251
+
252
+ ## 5. 監査ログ
253
+
254
+ ### 5.1 記録すべき項目
255
+
256
+ | 項目 | 例 |
257
+ | -------------- | ------------------------- |
258
+ | タイムスタンプ | 2024-01-15T10:30:00.000Z |
259
+ | ユーザーID | user_123 |
260
+ | アクション | TRANSFER, WITHDRAW, LOGIN |
261
+ | 対象リソース | account_456 |
262
+ | 変更前の値 | { balance: 10000 } |
263
+ | 変更後の値 | { balance: 9000 } |
264
+ | IPアドレス | 192.168.1.1 |
265
+ | 結果 | SUCCESS, FAILED, DENIED |
266
+ | 失敗理由 | INSUFFICIENT_BALANCE |
267
+
268
+ ### 5.2 実装例
269
+
270
+ ```typescript
271
+ async function auditLog(entry: AuditEntry) {
272
+ await prisma.auditLog.create({
273
+ data: {
274
+ timestamp: new Date(),
275
+ userId: entry.userId,
276
+ action: entry.action,
277
+ resourceType: entry.resourceType,
278
+ resourceId: entry.resourceId,
279
+ beforeValue: entry.before ? JSON.stringify(entry.before) : null,
280
+ afterValue: entry.after ? JSON.stringify(entry.after) : null,
281
+ ipAddress: entry.ipAddress,
282
+ userAgent: entry.userAgent,
283
+ result: entry.result,
284
+ errorCode: entry.errorCode,
285
+ },
286
+ });
287
+ }
288
+ ```
289
+
290
+ ### 5.3 チェックリスト
291
+
292
+ | 項目 | 必須 | 備考 |
293
+ | -------------------- | ---- | ------------------- |
294
+ | 全金融操作のログ記録 | ✅ | 送金、残高変更等 |
295
+ | 変更前後の値を記録 | ✅ | 追跡可能性 |
296
+ | ログの改ざん防止 | ✅ | 別DBまたは追記のみ |
297
+ | ログの保持期間設定 | ✅ | 法令に準拠(7年等) |
298
+
299
+ ---
300
+
301
+ ## 6. エラーハンドリング
302
+
303
+ ### 6.1 安全なエラーレスポンス
304
+
305
+ ```typescript
306
+ // ❌ 悪い例: 内部情報の漏洩
307
+ throw new Error(`User ${userId} has insufficient balance: ${balance} < ${amount}`);
308
+
309
+ // ✅ 良い例: 一般的なエラーメッセージ
310
+ throw new ApplicationError('INSUFFICIENT_BALANCE', '残高が不足しています');
311
+ ```
312
+
313
+ ### 6.2 トランザクション失敗時のリカバリ
314
+
315
+ ```typescript
316
+ async function safeTransfer(data: TransferData) {
317
+ const txId = crypto.randomUUID();
318
+
319
+ try {
320
+ // 1. 送金トランザクションを記録(PENDING)
321
+ await recordTransaction(txId, data, 'PENDING');
322
+
323
+ // 2. 送金処理
324
+ await executeTransfer(data);
325
+
326
+ // 3. ステータス更新(COMPLETED)
327
+ await updateTransactionStatus(txId, 'COMPLETED');
328
+ } catch (error) {
329
+ // 失敗時はステータスを更新(FAILED)
330
+ await updateTransactionStatus(txId, 'FAILED', error.message);
331
+
332
+ // 補償トランザクションが必要な場合
333
+ await compensate(txId, data);
334
+
335
+ throw error;
336
+ }
337
+ }
338
+ ```
339
+
340
+ ---
341
+
342
+ ## まとめ: 必須チェック項目
343
+
344
+ | カテゴリ | 必須項目 |
345
+ | -------------------- | ------------------------------- |
346
+ | レースコンディション | 楽観的/悲観的ロック、並行テスト |
347
+ | トランザクション | 分離レベル、アトミック操作 |
348
+ | べき等性 | べき等性キー、重複防止 |
349
+ | セッション | 再生成、有効期限、再認証 |
350
+ | 監査ログ | 全操作記録、改ざん防止 |
351
+ | エラー処理 | 情報漏洩防止、リカバリ |
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: bo-self-improver
3
+ description: Analyze accumulated log JSONL to automatically improve skills, commands, and agents. Runs automatically on session exit.
4
+ argument-hint: ["scan" or date]
5
+ ---
6
+
7
+ # bo-self-improver: Self-Improvement
8
+
9
+ Analyze accumulated log JSONL to improve skills, commands, and agents.
10
+
11
+ ## Scan Targets
12
+
13
+ Resources exist in two layers: global and project. **Scan both.**
14
+
15
+ | Target | Global (`~/.claude/`) | Project (`.claude/`) |
16
+ |--------|--------------------------|--------------------------|
17
+ | Skills | `~/.claude/skills/` | `.claude/skills/` |
18
+ | Commands | `~/.claude/commands/` | `.claude/commands/` |
19
+ | Agents | `~/.claude/agents/` | `.claude/agents/` |
20
+
21
+ ## Procedure
22
+
23
+ ### 1. Run Analysis Script (Automates Steps 1-4)
24
+
25
+ ```bash
26
+ python3 .claude/skills/bo-self-improver/scripts/analyze.py
27
+ ```
28
+
29
+ The script performs all of the following in batch and outputs JSON:
30
+ - Log path resolution (via `resolve-log-path.py`)
31
+ - Cursor management + analysis mode determination
32
+ - Diff log extraction
33
+ - Resource usage frequency tallying (skills_used / agents_used / commands_used)
34
+ - Rule-based agent gap detection
35
+ - Error-skill correlation analysis (effectiveness)
36
+
37
+ **Output JSON structure:**
38
+
39
+ ```json
40
+ {
41
+ "status": { "total", "cursor", "new_lines", "mode" },
42
+ "frequency": {
43
+ "counts": { "skills": {}, "agents": {}, "commands": {} },
44
+ "classification": { "skills": { "high", "low", "unused" }, ... }
45
+ },
46
+ "all_resources": { "skills": [], "agents": [], "commands": [] },
47
+ "agent_gaps": { "agent_name": { "missed": N, "examples": [...] } },
48
+ "effectiveness": {
49
+ "total_entries", "error_entries",
50
+ "repeated_error_tags", "skills_with_errors", "effective_skills"
51
+ },
52
+ "entries": [{ "title", "category", "has_errors", "learnings", "patterns" }]
53
+ }
54
+ ```
55
+
56
+ - `status.mode == "no_new"` → "No new logs" — exit
57
+ - `status.mode == "diff+full"` → In addition to diff analysis, also read `$LOG_BASE/self-improve/*.md` for long-term trends
58
+
59
+ ### 2. Skill Gap Analysis (LLM Judgment)
60
+
61
+ The script only detects rule-based agent gaps. **Skill gaps must be judged by the LLM.**
62
+
63
+ ```
64
+ Procedure:
65
+ 1. Review entries in the output JSON
66
+ 2. From each entry's category + learnings, infer "which skill should have been used"
67
+ 3. Compare with actual skills_used
68
+ 4. Tally the gaps
69
+ ```
70
+
71
+ ### 3. Reduction Evaluation (LLM Judgment)
72
+
73
+ Steps 1-2 produce "add/update" candidates, but **evaluate reductions first**. Prioritize reduction over addition.
74
+
75
+ | Check Item | Criteria | Action |
76
+ |---|---|---|
77
+ | Unused resources | 0 usage in frequency + similar resource exists | Merge or delete |
78
+ | Highly duplicated | Two skills with 80%+ content overlap | Merge into one |
79
+ | Bloated content | 15+ checklist items, or SKILL.md > 200 lines | Remove items / split to references |
80
+ | Out-of-date content | Content doesn't match current code | Update to match or delete section |
81
+ | Verbose description | Description > 2 lines, or repeats common knowledge | Simplify |
82
+
83
+ **Required output**: Must explicitly state one of:
84
+ - Reduction candidates found → List specific resource names and reduction details
85
+ - No reduction targets → State rationale in one line (e.g., "All skills used within past 2 weeks, no duplicates")
86
+
87
+ ### 4. Execute Resource Improvements (LLM Judgment)
88
+
89
+ Based on Steps 1-3, improve resources following the reference documents below.
90
+ **Execute reductions (Step 3) before additions/updates.**
91
+
92
+ | Target | Reference Document | Content |
93
+ |--------|-------------------|---------|
94
+ | Skills | `refs/skill-manager.md` | Creation/merge/deletion criteria, naming rules |
95
+ | Commands | `refs/command-manager.md` | Creation/update/merge/deletion criteria, format |
96
+ | Agents | `refs/agent-manager.md` | Creation/merge/deletion criteria, format |
97
+
98
+ After executing improvements, record to `log.jsonl` via bo-log-writer. Include creation/update details in the `resources_created` field.
99
+
100
+ ### 5. Update Cursor
101
+
102
+ ```bash
103
+ python3 .claude/skills/bo-self-improver/scripts/analyze.py --update-cursor
104
+ ```
105
+
106
+ ### 6. Persist Analysis Results & Record to Log
107
+
108
+ 1. **Persist analysis results**: Save to `$LOG_BASE/self-improve/{YYYY-MM-DD}.md`
109
+
110
+ ```markdown
111
+ # {YYYY-MM-DD} self-improve analysis results
112
+
113
+ ## Analysis Scope
114
+ - Log lines: {cursor+1} to {total} ({new_lines} lines)
115
+ - Mode: diff analysis / diff+full analysis
116
+
117
+ ## Frequency
118
+ | Resource Type | Name | Usage Count | Classification |
119
+ |---|---|---|---|
120
+
121
+ ## Gaps
122
+ | Resource Type | Name | Missed Count | Representative Miss Pattern |
123
+ |---|---|---|---|
124
+
125
+ ## Reduction Evaluation
126
+ | Target Resource | Decision | Rationale |
127
+ |---|---|---|
128
+
129
+ *Even if no reduction targets, state the rationale*
130
+
131
+ ## Effectiveness
132
+ | Pattern | Details |
133
+ |---|---|
134
+
135
+ ## Improvement Actions Taken
136
+ - ...
137
+ ```
138
+
139
+ 2. **Log recording**: Record improvement actions to `log.jsonl` via bo-log-writer skill format.
140
+
141
+ ## Rules
142
+
143
+ - Execute all creation, update, deletion, merge, and split actions automatically, leaving a log
144
+ - Never delete log JSONL (permanent storage)
145
+ - Do not end with "text edits only". Always execute frequency analysis and duplication analysis, recording results