wasurenagusa-mcp 0.4.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +355 -0
  3. package/README.md +224 -0
  4. package/dist/analyzer/conversation-meta.d.ts +10 -0
  5. package/dist/analyzer/conversation-meta.js +25 -0
  6. package/dist/analyzer/gemini-client.d.ts +2 -0
  7. package/dist/analyzer/gemini-client.js +9 -0
  8. package/dist/analyzer/gemini.d.ts +9 -0
  9. package/dist/analyzer/gemini.js +85 -0
  10. package/dist/analyzer/index.d.ts +1 -0
  11. package/dist/analyzer/index.js +1 -0
  12. package/dist/analyzer/prompt-loader.d.ts +1 -0
  13. package/dist/analyzer/prompt-loader.js +10 -0
  14. package/dist/autonomous/action-list.d.ts +10 -0
  15. package/dist/autonomous/action-list.js +34 -0
  16. package/dist/autonomous/command-generator.d.ts +9 -0
  17. package/dist/autonomous/command-generator.js +55 -0
  18. package/dist/autonomous/constants.d.ts +10 -0
  19. package/dist/autonomous/constants.js +22 -0
  20. package/dist/autonomous/evaluator.d.ts +9 -0
  21. package/dist/autonomous/evaluator.js +59 -0
  22. package/dist/autonomous/notifier.d.ts +39 -0
  23. package/dist/autonomous/notifier.js +211 -0
  24. package/dist/autonomous/project-initializer.d.ts +13 -0
  25. package/dist/autonomous/project-initializer.js +105 -0
  26. package/dist/autonomous/project-scanner.d.ts +25 -0
  27. package/dist/autonomous/project-scanner.js +125 -0
  28. package/dist/autonomous/task-markdown.d.ts +68 -0
  29. package/dist/autonomous/task-markdown.js +239 -0
  30. package/dist/autonomous/task-store.d.ts +19 -0
  31. package/dist/autonomous/task-store.js +198 -0
  32. package/dist/cli/analyze.d.ts +9 -0
  33. package/dist/cli/analyze.js +126 -0
  34. package/dist/cli/consolidate-worker.d.ts +11 -0
  35. package/dist/cli/consolidate-worker.js +38 -0
  36. package/dist/cli/context.d.ts +19 -0
  37. package/dist/cli/context.js +129 -0
  38. package/dist/cli/rebuild.d.ts +2 -0
  39. package/dist/cli/rebuild.js +107 -0
  40. package/dist/cli/spec-update.d.ts +11 -0
  41. package/dist/cli/spec-update.js +589 -0
  42. package/dist/cli/transcript-reader.d.ts +10 -0
  43. package/dist/cli/transcript-reader.js +48 -0
  44. package/dist/config.d.ts +20 -0
  45. package/dist/config.js +51 -0
  46. package/dist/consolidator/dont-consolidator.d.ts +7 -0
  47. package/dist/consolidator/dont-consolidator.js +43 -0
  48. package/dist/consolidator/formatter.d.ts +2 -0
  49. package/dist/consolidator/formatter.js +11 -0
  50. package/dist/consolidator/index.d.ts +3 -0
  51. package/dist/consolidator/index.js +3 -0
  52. package/dist/consolidator/staleness.d.ts +4 -0
  53. package/dist/consolidator/staleness.js +41 -0
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.js +110 -0
  56. package/dist/llm/provider.d.ts +5 -0
  57. package/dist/llm/provider.js +54 -0
  58. package/dist/scheduler/change-logger.d.ts +42 -0
  59. package/dist/scheduler/change-logger.js +146 -0
  60. package/dist/scheduler/executor.d.ts +6 -0
  61. package/dist/scheduler/executor.js +88 -0
  62. package/dist/scheduler/prompt-builder.d.ts +6 -0
  63. package/dist/scheduler/prompt-builder.js +42 -0
  64. package/dist/scheduler/task-queue.d.ts +37 -0
  65. package/dist/scheduler/task-queue.js +148 -0
  66. package/dist/storage/formatter.d.ts +9 -0
  67. package/dist/storage/formatter.js +36 -0
  68. package/dist/storage/index.d.ts +1 -0
  69. package/dist/storage/index.js +1 -0
  70. package/dist/storage/markdown.d.ts +19 -0
  71. package/dist/storage/markdown.js +321 -0
  72. package/dist/storage/parser.d.ts +9 -0
  73. package/dist/storage/parser.js +97 -0
  74. package/dist/tools/delete.d.ts +3 -0
  75. package/dist/tools/delete.js +23 -0
  76. package/dist/tools/getContext.d.ts +3 -0
  77. package/dist/tools/getContext.js +19 -0
  78. package/dist/tools/getDetail.d.ts +3 -0
  79. package/dist/tools/getDetail.js +25 -0
  80. package/dist/tools/index.d.ts +9 -0
  81. package/dist/tools/index.js +9 -0
  82. package/dist/tools/projectInit.d.ts +3 -0
  83. package/dist/tools/projectInit.js +81 -0
  84. package/dist/tools/save.d.ts +3 -0
  85. package/dist/tools/save.js +76 -0
  86. package/dist/tools/search.d.ts +3 -0
  87. package/dist/tools/search.js +46 -0
  88. package/dist/tools/taskActionList.d.ts +3 -0
  89. package/dist/tools/taskActionList.js +77 -0
  90. package/dist/tools/taskStatus.d.ts +3 -0
  91. package/dist/tools/taskStatus.js +26 -0
  92. package/dist/tools/taskSubmit.d.ts +3 -0
  93. package/dist/tools/taskSubmit.js +88 -0
  94. package/dist/types.d.ts +287 -0
  95. package/dist/types.js +1 -0
  96. package/dist/utils/owner-profile.d.ts +20 -0
  97. package/dist/utils/owner-profile.js +69 -0
  98. package/dist/utils/projectRoot.d.ts +5 -0
  99. package/dist/utils/projectRoot.js +24 -0
  100. package/dist/utils/prompt-escape.d.ts +5 -0
  101. package/dist/utils/prompt-escape.js +15 -0
  102. package/dist/utils/sanitize-error.d.ts +5 -0
  103. package/dist/utils/sanitize-error.js +15 -0
  104. package/dist/utils/validate-webhook-url.d.ts +11 -0
  105. package/dist/utils/validate-webhook-url.js +24 -0
  106. package/dist/utils/zombie-reaper.d.ts +36 -0
  107. package/dist/utils/zombie-reaper.js +212 -0
  108. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tsutushi0628
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.ja.md ADDED
@@ -0,0 +1,355 @@
1
+ # wasurenagusa-mcp
2
+
3
+ **wasurenagusa**(忘れな草) — 「私を忘れないで」という花言葉を持つ花。
4
+
5
+ **Claude Code に記憶を与える MCP サーバー。同じミスは、もう繰り返さない。**
6
+
7
+ > 「ポートは3000って言ったよね?」「さっき決めたでしょ?」
8
+ >
9
+ > Claude Code との会話で、同じことを何度も説明した経験はありませんか。
10
+ > wasurenagusa は、AI アシスタントに「記憶」を与える MCP サーバーです。
11
+ > 設定情報、やってはいけないこと、過去の決定事項を自動で記録・自動で注入。
12
+ > あなたは普段通りに会話するだけ。裏側で LLM が会話を分析し、重要な情報を蓄積していきます。
13
+
14
+ ---
15
+
16
+ ## wasurenagusa が解決する3つの「忘れる」
17
+
18
+ ### 1. プロジェクトの知識
19
+
20
+ Claude Code はセッションが変わるたびに、すべてを忘れる。
21
+ API の URL、ポート番号、「ログを読んでから質問して」というルール、先週決めたアーキテクチャ。
22
+
23
+ wasurenagusa は **Hooks 連携で完全自動化** されている。
24
+ セッション開始時に設定とルールが自動注入され、会話終了時に重要な情報が自動保存される。
25
+ ユーザーが手動で何かする必要は、一切ない。
26
+
27
+ ### 2. ドキュメントの最新化
28
+
29
+ コードは毎日変わるのに、Spec ドキュメントは書いた日のまま放置される。
30
+ wasurenagusa は夜間にコード変更を検知し、ドキュメントを自動で更新する。
31
+
32
+ ### 3. トークン枠を使い切り
33
+
34
+ Claude Code の 5 時間レート制限。寝ている間の枠は、普通なら無駄になる。
35
+ wasurenagusa のスケジューラは、アイドル時間を使って自律タスクを自動実行する。
36
+ Spec ドキュメントの更新、リファクタリング、テスト追加 ── `task_submit` で投入したタスクを Claude が 24/365 で処理し、LLM が完了条件を評価してリトライまでやる。
37
+
38
+ ---
39
+
40
+ ## 仕組み
41
+
42
+ ```
43
+ [セッション開始]
44
+ │ SessionStart Hook
45
+
46
+ wasurenagusa-context 実行
47
+ → config + dont を自動注入(設定・ルール・過去のミス)
48
+
49
+
50
+ [会話中] ─── AIが必要に応じて memory_search → memory_get_detail を自律呼び出し
51
+
52
+
53
+ [Claude 応答完了]
54
+ │ Stop Hook
55
+
56
+ wasurenagusa-analyze 実行
57
+ → LLM で会話を自動分析
58
+ → 重要情報を自動保存(怒り検知・リトライパターン検出含む)
59
+ → 変更ファイルをログに記録(Spec 自動更新用)
60
+ ```
61
+
62
+ **ユーザーの操作: ゼロ。**
63
+
64
+ ---
65
+
66
+ ## 他のメモリ MCP との違い
67
+
68
+ | | wasurenagusa | 一般的なメモリ MCP |
69
+ |---|---|---|
70
+ | 保存方式 | LLM が会話を自動分析・自動保存 | ユーザーが手動で保存指示 |
71
+ | 注入方式 | SessionStart Hook で自動注入 | 毎回手動で読み込み指示 |
72
+ | トークン効率 | 段階的開示で 70-90% 削減 | 全件フル返却でコンテキスト圧迫 |
73
+ | 感情検知 | 怒り・悲しみ・諦めを自動検出 | なし |
74
+ | AI 自己学習 | リトライパターンを自動検出・記録 | なし |
75
+ | dont 統合 | 数十件 → 数個の原則に自動圧縮 | エントリが増え続けてノイズ化 |
76
+
77
+ ---
78
+
79
+ ## 主要機能
80
+
81
+ ### 自動記憶(Hooks 連携)
82
+
83
+ - **SessionStart Hook**: セッション開始時に config(設定)と dont(やってはいけないこと)を自動注入
84
+ - **Stop Hook**: 会話終了時に LLM で分析し、重要情報を自動保存
85
+
86
+ ### 感情検知
87
+
88
+ ユーザーの怒り・悲しみ・失望・諦めを検知し、「❌何をした → 💡なぜダメか → ✅どうすべきか」の 3 点セットで記録。
89
+ テキストパターンだけでなく、メッセージ長の急減少やポジティブ反応の長期不在といったメタ情報でも検出する。
90
+
91
+ ### AI リトライパターン検出
92
+
93
+ 同じ API を 3 回以上実行、同じエラーが 3 回以上発生 ── AI 自身の失敗パターンも自動で学習し、「正しいやり方」を記録する。
94
+
95
+ ### 段階的開示(トークン最適化)
96
+
97
+ 検索結果はインデックス(ID・タイトル・タグ)のみ返し、必要な項目だけフル取得する 2 段階設計。
98
+ 従来の全件返却と比較して **トークン消費を 70-90% 削減**。
99
+
100
+ ### 重複検出
101
+
102
+ LLM ベースのセマンティック重複検出。同じテーマの新しい情報は既存エントリを自動で置換する。
103
+
104
+ ### dont 統合
105
+
106
+ dont エントリが増えすぎた場合、LLM で 5-6 個の行動原則に自動統合。
107
+ 元エントリは保持したまま、コンテキスト注入サイズを 36KB → 3-4KB に圧縮する。
108
+
109
+ ### 自律タスク実行
110
+
111
+ `task_submit` でタスクを投入すると、スケジューラが Claude CLI をサブプロセスとして起動し自動実行する。
112
+ LLM が実行結果を完了条件と照合し、未達ならリトライする。Spec 更新、リファクタリング、テスト追加など汎用的に使える。
113
+
114
+ ### Spec 自動更新(スケジューラ)
115
+
116
+ 自律タスクの代表的なユースケース。夜間の 5 時間ウィンドウで、変更されたコードに対応する Spec ドキュメントを自動更新。
117
+ タスクがない場合は keep-alive ping でレート制限枠をリセットする。
118
+
119
+ ### Owner Profile
120
+
121
+ MCP サーバー初回起動時に `.wasurenagusa/owner-profile.md` が自動生成される。
122
+ 優先順位、設計方針、コミュニケーションスタイルなど 20 の質問に答えておくと、AI が自律タスク実行時にその基準で判断する。
123
+
124
+ ---
125
+
126
+ ## セットアップ
127
+
128
+ ### 前提条件
129
+
130
+ - Node.js 18+
131
+ - Claude Code(CLI)
132
+ - Gemini API キー([Google AI Studio](https://aistudio.google.com/) で取得)
133
+
134
+ ### 1. クローンとビルド
135
+
136
+ ```bash
137
+ git clone git@github.com:tsutushi0628/wasurenagusa-mcp.git
138
+ cd wasurenagusa-mcp
139
+ npm install
140
+ npm run build
141
+ ```
142
+
143
+ ### 2. CLI コマンドを PATH に通す
144
+
145
+ ```bash
146
+ npm link
147
+ ```
148
+
149
+ これで `wasurenagusa-context`、`wasurenagusa-analyze`、`wasurenagusa-spec-update` がグローバルに使えるようになる。
150
+
151
+ ### 3. 環境変数の設定
152
+
153
+ ```bash
154
+ cp .env.example .env
155
+ ```
156
+
157
+ `.env` を編集:
158
+
159
+ ```
160
+ GEMINI_API_KEY=your_gemini_api_key_here
161
+ MEMORY_DIR=.wasurenagusa
162
+ SLACK_WEBHOOK_URL= # オプション: Slack通知を有効にする場合
163
+ ```
164
+
165
+ | 変数 | 必須 | 説明 |
166
+ |------|------|------|
167
+ | `GEMINI_API_KEY` | 必須 | Gemini API キー |
168
+ | `MEMORY_DIR` | 任意 | メモリ保存先ディレクトリ(デフォルト: `.wasurenagusa`) |
169
+ | `SLACK_WEBHOOK_URL` | 任意 | 自律タスクの完了/失敗を Slack に通知 |
170
+
171
+ ### 4. Claude Code に MCP サーバーを登録
172
+
173
+ ```bash
174
+ claude mcp add wasurenagusa -- node /path/to/wasurenagusa-mcp/dist/index.js
175
+ ```
176
+
177
+ ### 5. Hooks の設定
178
+
179
+ `~/.claude/settings.local.json`(または プロジェクトの `.claude/settings.local.json`)に以下を追加:
180
+
181
+ ```json
182
+ {
183
+ "hooks": {
184
+ "SessionStart": [
185
+ {
186
+ "hooks": [
187
+ {
188
+ "type": "command",
189
+ "command": "wasurenagusa-context",
190
+ "timeout": 5
191
+ }
192
+ ]
193
+ }
194
+ ],
195
+ "Stop": [
196
+ {
197
+ "hooks": [
198
+ {
199
+ "type": "command",
200
+ "command": "wasurenagusa-analyze",
201
+ "timeout": 30
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ }
207
+ }
208
+ ```
209
+
210
+ ### 6. 動作確認
211
+
212
+ Claude Code を起動する。初回は `.wasurenagusa/` ディレクトリが自動作成され、`owner-profile.md` のテンプレートが配置される。
213
+
214
+ ```
215
+ .wasurenagusa/
216
+ ├── owner-profile.md ← 初回自動生成。編集するとAIの自律判断に反映
217
+ ├── config.md ← 会話から自動蓄積
218
+ ├── dont.md ← 会話から自動蓄積
219
+ ├── decisions.md ← 会話から自動蓄積
220
+ ├── snippets.md ← 会話から自動蓄積
221
+ └── logs/ ← 日付別ログ
222
+ ```
223
+
224
+ 最初の会話を終えると、Stop Hook が起動して LLM が会話を分析し、重要情報が自動保存される。
225
+ 2 回目以降のセッションでは、蓄積された情報が SessionStart Hook で自動注入される。
226
+
227
+ > **重要**: `.wasurenagusa/` にはプロジェクト固有の記憶データが保存される。あなたのプロジェクトの `.gitignore` に追加しておくこと。
228
+ >
229
+ > ```bash
230
+ > echo '.wasurenagusa/' >> .gitignore
231
+ > ```
232
+
233
+ ### 7. (オプション)プロジェクト初期設定
234
+
235
+ 自律タスク機能(Spec 自動更新など)を使う場合は、Claude Code 上で `project_init` ツールを実行する。
236
+ プロジェクトの品質基準・フェーズ・判断基準を選択式で登録できる。
237
+
238
+ ### 8. (オプション)Spec 自動更新スケジューラ
239
+
240
+ 夜間にドキュメントを自動更新するには、cron や launchd で `wasurenagusa-spec-update` を定期実行する。
241
+
242
+ ```bash
243
+ # 例: 毎日深夜1時に実行(cron)
244
+ 0 1 * * * cd /path/to/your-project && wasurenagusa-spec-update
245
+ ```
246
+
247
+ ---
248
+
249
+ ## メモリカテゴリ
250
+
251
+ | カテゴリ | 説明 | 保存先 |
252
+ |---------|------|--------|
253
+ | **config** | API URL、ポート番号、認証情報の場所 | `.wasurenagusa/config.md` |
254
+ | **dont** | やってはいけないこと、過去のミス | `.wasurenagusa/dont.md` |
255
+ | **decision** | 技術選定、アーキテクチャ決定 | `.wasurenagusa/decisions.md` |
256
+ | **log** | 実装完了、エラー解決の記録 | `.wasurenagusa/logs/YYYY-MM-DD.md` |
257
+ | **snippet** | よく使うコマンド、クエリ | `.wasurenagusa/snippets.md` |
258
+
259
+ ---
260
+
261
+ ## MCP ツール
262
+
263
+ | ツール名 | 実行方式 | 説明 |
264
+ |---------|---------|------|
265
+ | `memory_get_context` | AI 自律 | config + dont を一括取得 |
266
+ | `memory_search` | AI 自律 | 軽量インデックス検索(ID・タイトル・タグのみ) |
267
+ | `memory_get_detail` | AI 自律 | 指定 ID のフル詳細を取得 |
268
+ | `memory_save` | 手動(オプション) | 明示的な記憶保存 |
269
+ | `memory_delete` | 手動 | エントリ削除(ID 指定、複数一括可) |
270
+ | `task_submit` | AI 自律 | 自律タスクの投入 |
271
+ | `task_status` | AI 自律 | タスク状態の確認 |
272
+ | `task_action_list` | AI 自律 | 実行可能アクション一覧 |
273
+ | `project_init` | 手動 | プロジェクト初期設定 |
274
+
275
+ ---
276
+
277
+ ## CLI コマンド
278
+
279
+ | コマンド | 用途 | 呼び出し元 |
280
+ |---------|------|-----------|
281
+ | `wasurenagusa-context` | config + dont をstdoutに出力 | SessionStart Hook |
282
+ | `wasurenagusa-analyze` | 会話を LLM 分析し自動保存 | Stop Hook |
283
+ | `wasurenagusa-spec-update` | Spec ドキュメント自動更新 | cron / systemd timer |
284
+
285
+ ---
286
+
287
+ ## 技術スタック
288
+
289
+ | 技術 | 用途 |
290
+ |------|------|
291
+ | TypeScript | 実装言語 |
292
+ | MCP SDK (`@modelcontextprotocol/sdk`) | MCP プロトコル |
293
+ | Gemini API (`@google/generative-ai`) | 会話分析・重複検出・dont統合 |
294
+ | Markdown | ストレージ形式 |
295
+ | STDIO | トランスポート |
296
+
297
+ ---
298
+
299
+ ## ディレクトリ構成
300
+
301
+ ```
302
+ wasurenagusa-mcp/
303
+ ├── src/
304
+ │ ├── index.ts # MCP サーバーエントリポイント
305
+ │ ├── config.ts # 設定管理
306
+ │ ├── types.ts # 型定義
307
+ │ ├── cli/
308
+ │ │ ├── context.ts # SessionStart Hook 用 CLI
309
+ │ │ ├── analyze.ts # Stop Hook 用 CLI
310
+ │ │ └── spec-update.ts # Spec 自動更新 CLI
311
+ │ ├── tools/ # MCP ツール定義
312
+ │ ├── storage/ # Markdown ストレージ
313
+ │ ├── analyzer/ # Gemini 連携・会話分析
314
+ │ ├── autonomous/ # 自律タスク実行
315
+ │ ├── consolidator/ # dont 統合
316
+ │ ├── scheduler/ # Spec 更新スケジューラ
317
+ │ ├── notifier/ # Slack 通知
318
+ │ └── utils/ # ユーティリティ
319
+ ├── prompts/ # Gemini プロンプト(外部化)
320
+ ├── docs/
321
+ │ └── spec.md # 完全実装仕様書
322
+ ├── .env.example
323
+ ├── package.json
324
+ └── tsconfig.json
325
+ ```
326
+
327
+ ---
328
+
329
+ ## 開発
330
+
331
+ ```bash
332
+ # ビルド
333
+ npm run build
334
+
335
+ # テスト
336
+ npm test
337
+
338
+ # テスト(ウォッチモード)
339
+ npm run test:watch
340
+ ```
341
+
342
+ ---
343
+
344
+ ## 設計思想
345
+
346
+ - **自律自動が基本、手動はオプション** — ユーザーに手動操作を強いない。Hooks で完全自動化
347
+ - **コンテキストを圧迫しない軽量設計** — 段階的開示で必要な情報だけ取得
348
+ - **プロンプト外部化** — `prompts/` に LLM プロンプトをテキストファイルとして配置。デプロイなしで改善可能
349
+ - **ローカル実行** — セットアップ簡単。外部サービスは Gemini API のみ
350
+
351
+ ---
352
+
353
+ ## ライセンス
354
+
355
+ MIT
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # wasurenagusa
2
+
3
+ **Teach your AI coding agent to learn from its mistakes.**
4
+
5
+ > *wasurenagusa* (忘れな草) — "forget-me-not" in Japanese.
6
+
7
+ ---
8
+
9
+ ## The Problem
10
+
11
+ AI coding agents are geniuses that forget everything the moment a session ends. Your project conventions, past failures, your preferences — all gone. Every new session starts from zero.
12
+
13
+ The native solution (CLAUDE.md) silently stops working after 200 lines. Your AI stops following rules and you don't even know why.
14
+
15
+ ## The Solution
16
+
17
+ wasurenagusa is an MCP server that gives AI agents human-like memory:
18
+
19
+ 1. **Auto-detect mistakes** — Detects retry patterns, user frustration, and repeated failures
20
+ 2. **Auto-consolidate lessons** — LLM compresses hundreds of "don't do this" entries into a few core principles
21
+ 3. **Auto-inject on session start** — Every new session begins with the accumulated wisdom of all past sessions
22
+
23
+ **Zero manual effort.** Hooks handle everything automatically.
24
+
25
+ ### Real-world results
26
+
27
+ From the author's daily use across 8 projects:
28
+
29
+ ```
30
+ 508 mistake entries → 7 principles (auto-consolidated)
31
+ 788 KB of raw data → 3 KB injected per session (99.6% reduction)
32
+ ```
33
+
34
+ ---
35
+
36
+ ## How It Works
37
+
38
+ ```
39
+ Session Start (Hook)
40
+ → wasurenagusa injects config + consolidated principles
41
+
42
+ During Session
43
+ → AI calls memory_search / memory_save as needed
44
+
45
+ Session End (Hook)
46
+ → LLM analyzes the conversation
47
+ → Detects mistakes, frustration, retry patterns
48
+ → Auto-saves important context
49
+
50
+ Background (optional)
51
+ → Consolidates growing "dont" entries into principles
52
+ → Runs autonomous tasks (spec updates, refactoring)
53
+ ```
54
+
55
+ ---
56
+
57
+ ## What Makes This Different
58
+
59
+ | | wasurenagusa | claude-mem | Cipher | CLAUDE.md |
60
+ |---|---|---|---|---|
61
+ | Auto-detect mistakes | Yes (retry + sentiment) | No | No | No |
62
+ | Auto-consolidate to principles | Yes (LLM-powered) | No | No | No |
63
+ | Zero-effort via hooks | Yes | Yes | No | No |
64
+ | Human-readable storage | Yes (Markdown) | No | No | Yes |
65
+ | Token-efficient retrieval | Yes (70-90% savings) | Yes | No | No |
66
+
67
+ ---
68
+
69
+ ## Quick Start
70
+
71
+ ### Prerequisites
72
+
73
+ - Node.js 18+
74
+ - Claude Code (CLI)
75
+ - Gemini API key ([Google AI Studio](https://aistudio.google.com/))
76
+
77
+ ### 1. Install & Build
78
+
79
+ ```bash
80
+ git clone https://github.com/tsutushi0628/wasurenagusa-mcp.git
81
+ cd wasurenagusa-mcp
82
+ npm install && npm run build
83
+ npm link
84
+ ```
85
+
86
+ ### 2. Set API Key
87
+
88
+ ```bash
89
+ cp .env.example .env
90
+ # Edit .env → set GEMINI_API_KEY
91
+ ```
92
+
93
+ ### 3. Register MCP Server
94
+
95
+ ```bash
96
+ claude mcp add wasurenagusa -- node /path/to/wasurenagusa-mcp/dist/index.js
97
+ ```
98
+
99
+ ### 4. Configure Hooks
100
+
101
+ Add to `~/.claude/settings.local.json`:
102
+
103
+ ```json
104
+ {
105
+ "hooks": {
106
+ "SessionStart": [
107
+ {
108
+ "hooks": [
109
+ {
110
+ "type": "command",
111
+ "command": "wasurenagusa-context",
112
+ "timeout": 5
113
+ }
114
+ ]
115
+ }
116
+ ],
117
+ "Stop": [
118
+ {
119
+ "hooks": [
120
+ {
121
+ "type": "command",
122
+ "command": "wasurenagusa-analyze",
123
+ "timeout": 30
124
+ }
125
+ ]
126
+ }
127
+ ]
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### 5. Start Using
133
+
134
+ Launch Claude Code. That's it.
135
+
136
+ - First session: `.wasurenagusa/` directory is created automatically
137
+ - After first conversation: Stop Hook saves important context
138
+ - Second session onward: context is auto-injected at start
139
+
140
+ > Add `.wasurenagusa/` to your `.gitignore` — it contains project-specific memory data.
141
+
142
+ ---
143
+
144
+ ## Memory Categories
145
+
146
+ | Category | What it stores | File |
147
+ |----------|---------------|------|
148
+ | **config** | API URLs, ports, auth locations | `config.md` |
149
+ | **dont** | Mistakes, anti-patterns, user frustrations | `dont.md` |
150
+ | **decision** | Architecture decisions, tech choices | `decisions.md` |
151
+ | **log** | Implementation records, resolved errors | `logs/YYYY-MM-DD.md` |
152
+ | **snippet** | Frequently used commands & queries | `snippets.md` |
153
+
154
+ ---
155
+
156
+ ## MCP Tools
157
+
158
+ | Tool | Description |
159
+ |------|-------------|
160
+ | `memory_get_context` | Get config + dont (auto-called at session start) |
161
+ | `memory_search` | Lightweight index search (ID, title, tags only) |
162
+ | `memory_get_detail` | Get full detail by ID |
163
+ | `memory_save` | Explicitly save a memory |
164
+ | `memory_delete` | Delete entries by ID |
165
+ | `task_submit` | Submit autonomous task (24/7 execution) |
166
+ | `task_status` | Check task status |
167
+ | `project_init` | Initialize project settings |
168
+
169
+ ---
170
+
171
+ ## Advanced Features
172
+
173
+ ### Dont Consolidation
174
+
175
+ When "dont" entries pile up, the LLM automatically compresses them into 5-7 behavioral principles. Raw entries are preserved; only the consolidated summary is injected at session start.
176
+
177
+ ### Autonomous Tasks
178
+
179
+ Submit tasks via `task_submit` and wasurenagusa runs them using Claude CLI as a subprocess. The LLM evaluates completion conditions and retries if needed. Useful for spec updates, refactoring, and test generation.
180
+
181
+ ### Sentiment Detection
182
+
183
+ Detects user frustration through text patterns, message length changes, and absence of positive signals. Records what went wrong, why, and what to do instead.
184
+
185
+ ### Owner Profile
186
+
187
+ On first run, an `owner-profile.md` template is generated. Fill it in to teach the AI your decision-making preferences for autonomous task execution.
188
+
189
+ ---
190
+
191
+ ## Current Limitations
192
+
193
+ - **Gemini only** — Currently requires a Gemini API key. OpenAI/Anthropic provider support is planned.
194
+ - **Claude Code only** — Hook-based auto-injection is Claude Code specific. The MCP server itself works with any MCP-compatible tool, but without auto-injection.
195
+ - **No memory size limits** — Long-running projects may accumulate large memory files. Consolidation mitigates this for "dont" entries, but logs can grow unbounded.
196
+
197
+ ---
198
+
199
+ ## Design Philosophy
200
+
201
+ - **Autonomous by default, manual by choice** — Never require manual operation. Hooks automate everything.
202
+ - **Token-conscious** — Two-stage retrieval (index → detail) reduces context consumption by 70-90%.
203
+ - **Human-readable storage** — All memory stored as Markdown. No database, no vendor lock-in.
204
+ - **Externalized prompts** — LLM prompts live in `prompts/` as plain text files. Iterate without redeploying.
205
+
206
+ ---
207
+
208
+ ## Development
209
+
210
+ ```bash
211
+ npm run build # Compile TypeScript
212
+ npm test # Run tests
213
+ npm run test:watch
214
+ ```
215
+
216
+ ---
217
+
218
+ ## License
219
+
220
+ MIT
221
+
222
+ ---
223
+
224
+ [日本語 README](./README.ja.md)
@@ -0,0 +1,10 @@
1
+ export interface ParsedMessage {
2
+ role: string;
3
+ text: string;
4
+ }
5
+ export interface ConversationMeta {
6
+ avgUserMessageLength: number;
7
+ currentMessageLength: number;
8
+ turnsSinceLastPositive: number;
9
+ }
10
+ export declare function computeConversationMeta(messages: ParsedMessage[]): ConversationMeta;
@@ -0,0 +1,25 @@
1
+ const POSITIVE_PATTERNS = /ありがとう|いいね|よさそう|完璧|おけ|ok|good|great|nice|👍|🎉|素晴らしい|助かる/i;
2
+ export function computeConversationMeta(messages) {
3
+ const userMessages = messages.filter(m => m.role === "user");
4
+ if (userMessages.length === 0) {
5
+ return { avgUserMessageLength: 0, currentMessageLength: 0, turnsSinceLastPositive: 0 };
6
+ }
7
+ const current = userMessages[userMessages.length - 1];
8
+ const currentLength = current.text.length;
9
+ // 直近5件のユーザーメッセージで平均を計算
10
+ const recent = userMessages.slice(-5);
11
+ const avgLength = recent.reduce((sum, m) => sum + m.text.length, 0) / recent.length;
12
+ // 最後のポジティブ反応からの経過ターン数
13
+ let turnsSincePositive = 0;
14
+ for (let i = userMessages.length - 1; i >= 0; i--) {
15
+ if (POSITIVE_PATTERNS.test(userMessages[i].text)) {
16
+ break;
17
+ }
18
+ turnsSincePositive++;
19
+ }
20
+ return {
21
+ avgUserMessageLength: Math.round(avgLength),
22
+ currentMessageLength: currentLength,
23
+ turnsSinceLastPositive: turnsSincePositive,
24
+ };
25
+ }
@@ -0,0 +1,2 @@
1
+ import type { GenerativeModel } from "@google/generative-ai";
2
+ export declare function createGeminiModel(): GenerativeModel;
@@ -0,0 +1,9 @@
1
+ import { GoogleGenerativeAI } from "@google/generative-ai";
2
+ import { config } from "../config.js";
3
+ export function createGeminiModel() {
4
+ if (!config.geminiApiKey) {
5
+ throw new Error("GEMINI_API_KEY is not set");
6
+ }
7
+ const genAI = new GoogleGenerativeAI(config.geminiApiKey);
8
+ return genAI.getGenerativeModel({ model: config.geminiModel });
9
+ }
@@ -0,0 +1,9 @@
1
+ import { AnalysisResult, AnalysisInput, DuplicateCheckInput } from "../types.js";
2
+ import { GenerateTextFn } from "../llm/provider.js";
3
+ export declare class Analyzer {
4
+ private generateText;
5
+ constructor(generateText?: GenerateTextFn);
6
+ analyze(input: AnalysisInput): Promise<AnalysisResult>;
7
+ checkDuplicate(input: DuplicateCheckInput): Promise<string | null>;
8
+ private defaultResult;
9
+ }