th-memory-mcp 2.2.4 → 2.2.7

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,7 +1,7 @@
1
1
  # th-memory-mcp v2 — Architecture & Implementation Specification
2
2
 
3
3
  **Status:** ✅ Released — `th-memory-mcp v2.0.0` is published (npm + Official MCP Registry + Glama).
4
- **Baseline:** v1.2.2 → **Current:** v2.0.0
4
+ **Baseline:** v1.2.2 → **Current:** v2.2.7
5
5
  **Primary goal:** evolve th-memory-mcp from a structured local memory MCP into a durable, temporal, conflict-aware, hybrid-retrieval memory engine for AI agents.
6
6
 
7
7
  > **Audience guide:** End users should read [README.md](README.md) (install, tools, usage). This document is the **canonical architecture & agent-rules spec** for developers and AI coding agents — the single source of truth for structure and behavior. The former `design.md` build log has been folded into §40 Implementation Status.
@@ -16,7 +16,7 @@ The project must retain these v1 properties:
16
16
 
17
17
  - Local-first and offline by default.
18
18
  - SQLite as the primary persistence layer.
19
- - FTS5 and local semantic search.
19
+ - FTS5 and lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a).
20
20
  - Thai/English support.
21
21
  - Auto-capture and cross-harness compatibility.
22
22
  - Secret filtering and safe export.
@@ -69,7 +69,7 @@ Core operations must work without an LLM:
69
69
 
70
70
  - persistence
71
71
  - FTS search
72
- - semantic search
72
+ - lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a)
73
73
  - metadata filtering
74
74
  - scoring
75
75
  - RRF fusion
@@ -373,7 +373,9 @@ project_id
373
373
 
374
374
  The implementation may use a maintained FTS5 virtual table or separate indexes, but every mutation of searchable memory must keep indexes synchronized transactionally where possible.
375
375
 
376
- Local semantic search remains supported. The implementation must preserve the dependency-light/offline property of v1.
376
+ Lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a) remains supported. The implementation must preserve the dependency-light/offline property of v1.
377
+
378
+ > **Caveat — lexical fuzzy, not concept-level:** The vector signal is lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a) — hashed word tokens + character 3-grams via FNV-1a into 512 dimensions — not transformer / concept-level semantic search. It tolerates minor lexical variation (typos, small edits) but paraphrases that share no token or 3-gram overlap will not be linked by the vector signal (FTS also requires token overlap). Distant paraphrases may therefore remain `unrelated` rather than being classified as `duplicate`/`contradiction`.
377
379
 
378
380
  ---
379
381
 
@@ -591,6 +593,8 @@ final_score =
591
593
 
592
594
  The exact formula must be benchmarked.
593
595
 
596
+ > **Caveat — lexical fuzzy, not concept-level:** The vector signal in this hybrid pipeline is lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a) — hashed word tokens + character 3-grams via FNV-1a into 512 dimensions — not transformer / concept-level semantic search. It tolerates minor lexical variation (typos, small edits) but paraphrases that share no token or 3-gram overlap will not be linked by the vector signal (FTS also requires token overlap), so RRF cannot recover concept-level matches from the vector side alone. The `conflict-resolver` similarity threshold also operates on this lexical signal, so distant paraphrases may be classified as `unrelated` rather than `duplicate`/`contradiction`.
597
+
594
598
  ---
595
599
 
596
600
  # 14. Graph Retrieval
@@ -705,7 +709,7 @@ Do not expand to dozens of tools. v2.1.0 ships **16 tools** (the original spec t
705
709
 
706
710
  ### Core / compatibility (carried from v1)
707
711
  1. `remember` — store a memory using the unified model (type + metadata)
708
- 2. `recall` — hybrid FTS + semantic search (v1 behavior preserved)
712
+ 2. `recall` — hybrid FTS + lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a) (v1 behavior preserved)
709
713
  3. `forget` — soft delete by default
710
714
  4. `get_profile` — compact profile projection/cache
711
715
  5. `search_history` — search raw interactions
@@ -1593,5 +1597,11 @@ All previously-deferred future features are implemented. AI-assisted extraction
1593
1597
  - v2.1.0: implemented and tested locally; publish skipped (superseded by v2.2.0).
1594
1598
  - v2.2.0: fully released — tag + GitHub Release, **npm published** (`th-memory-mcp@2.2.0`), Official MCP Registry auto-ingested from npm (manual `mcp-publisher publish` is redundant and errors `duplicate version`), Glama synced. Only `npm publish` + Glama Sync are required.
1595
1599
  - v2.2.1: Glama quality fix (server failed to start — better-sqlite3 native binding missing under pnpm 10 on Node 24). Added `pnpm.onlyBuiltDependencies: ["better-sqlite3"]` so pnpm runs the install script that downloads the Node 24 prebuild; bumped better-sqlite3 to `^12.9.0`; added `ip-address@^10.2.0` overrides (npm + pnpm) to clear transitive XSS via `@modelcontextprotocol/sdk`. No code changes. Pending `npm publish` + Glama re-test.
1600
+ - v2.2.2: baseline for benchmark spec v1.0 (retrieval quality harness initial).
1601
+ - v2.2.3: security + performance hardening per `report_checkup.md` (scope-enforced retrieval, graph scope isolation, export/import round-trip, realpath symlink protection, strict import validation, N+1 elimination, cold/ablation benchmark, `MEMORY_RETRIEVAL_MODE` switch — 25/25 tests).
1602
+ - v2.2.4: docs — tidy README badge layout.
1603
+ - v2.2.5: docs — sync README/design/ARCHITECTURE/PUBLISH to project (lexical fuzzy matching, 25 suites, benchmark viewer, result versioning) + SECURITY.md.
1604
+ - v2.2.6: docs — translate all docs to English except `README.th.md` (benchmark/README, METHODOLOGY, repro/README, viewer HTML, PUBLISH checklist).
1605
+ - v2.2.7: bugfix — synced secret filter (6-pattern redact) between Claude hook (`scripts/claude-capture.mjs`) and `capture-core.ts`, fixed `err()` to return `isError:true` per MCP spec (`src/db/index.ts`), fixed backup rotation to backup only when migrations pending + prune to 5 (`src/db/migrations.ts`), added `data/hook-errors.log` logging for SessionEnd distill failures; benchmark — upgraded to v2.3 spec draft (semantic-hard 8 categories, enhanced scope contamination, graph effectiveness, token efficiency @128 budget, scalability profiles quick→extreme up to 10M with resumable generation, ablation with scope+graph, reliability suite).
1596
1606
 
1597
1607
  **Packaging note (Glama / Smithery):** these registries build with `pnpm install` + `pnpm run build` on **Node 24** and disable postinstall scripts by default (pnpm 10). Any native dependency (e.g. `better-sqlite3`) MUST be listed in `pnpm.onlyBuiltDependencies` in `package.json`, otherwise its native binary is never fetched and the server crashes at startup with `Could not locate the bindings file`.
package/README.md CHANGED
@@ -4,12 +4,14 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/th-memory-mcp.svg)](https://www.npmjs.com/package/th-memory-mcp)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
6
  [![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
7
+ [![CI](https://github.com/worakorn-prince/th-memory-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/worakorn-prince/th-memory-mcp/actions/workflows/ci.yml)
8
+ [![Version Sync](https://github.com/worakorn-prince/th-memory-mcp/actions/workflows/version-sync.yml/badge.svg)](https://github.com/worakorn-prince/th-memory-mcp/actions/workflows/version-sync.yml)
7
9
  [![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/worakorn-prince/th-memory-mcp)
8
10
 
9
11
  [![th-memory-mcp MCP server](https://glama.ai/mcp/servers/worakorn-prince/th-memory-mcp/badges/card.svg)](https://glama.ai/mcp/servers/worakorn-prince/th-memory-mcp)
10
12
 
11
13
 
12
- **Status:** v2.2.4 — a temporal, conflict-aware, hybrid-retrieval memory engine. 16 MCP tools, 25 passing test suites. Non-destructive schema migration from v1 (all v1 data preserved). New in v2.2: lifecycle states, temporal validity, conflict/dedup resolution with USER/SESSION/PROJECT/GLOBAL scope, hybrid FTS+vector retrieval (RRF), memory graph, `get_context` assembly, periodic consolidation, and `link_memory` / `merge_memory` / `update_memory` / `import_memory` / `extract_memories`. New in v2.2.3: scope-enforced retrieval, graph scope isolation, export/import round-trip, hardened import path (realpath), strict import validation, N+1 query elimination, cold/ablation benchmark, and `MEMORY_RETRIEVAL_MODE` switch.
14
+ **Status:** v2.2.7 — a temporal, conflict-aware, hybrid-retrieval memory engine. 16 MCP tools, 25 passing test suites. Non-destructive schema migration from v1 (all v1 data preserved). New in v2.2: lifecycle states, temporal validity, conflict/dedup resolution with USER/SESSION/PROJECT/GLOBAL scope, hybrid FTS+vector retrieval (RRF), memory graph, `get_context` assembly, periodic consolidation, and `link_memory` / `merge_memory` / `update_memory` / `import_memory` / `extract_memories`. New in v2.2.3: scope-enforced retrieval, graph scope isolation, export/import round-trip, hardened import path (realpath), strict import validation, N+1 query elimination, cold/ablation benchmark, and `MEMORY_RETRIEVAL_MODE` switch. New in v2.2.7: synced secret filter between Claude hook and capture-core (6-pattern redact instead of line-drop), fixed `err()` to return `isError:true` per MCP spec, fixed backup rotation (backup only when migrations pending + prune to 5 files), and added hook error logging for SessionEnd distill.
13
15
 
14
16
  ## Requirements
15
17
 
@@ -94,7 +96,7 @@ our hooks bridge; Codex and Cursor use the tools manually (no hook runtime yet).
94
96
  | 16 MCP tools | ✅ | ✅ | ✅ | ✅ | ✅ |
95
97
  | Auto-capture (background) | ✅ plugin | ✅ [hooks](CLAUDE_CODE_HOOKS.md) | ⚠️ adapter | ❌ manual | ❌ Rules |
96
98
  | Profile injection | ✅ compaction | ✅ UserPromptSubmit | ❌ `get_profile` | ❌ `get_profile` | ❌ `get_profile` |
97
- | Local semantic search | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) |
99
+ | Lexical fuzzy matching | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) | ✅ (v2.0) |
98
100
 
99
101
  - **Claude Code:** see [CLAUDE_CODE_HOOKS.md](CLAUDE_CODE_HOOKS.md) — drop-in hooks replicate the OpenCode plugin (capture + profile injection on `UserPromptSubmit`/`PreCompact`, rule-based distill on `SessionEnd`).
100
102
  - **Qwen Code:** see [QWEN_SETUP.md](QWEN_SETUP.md) — MCP works fully; hooks use the Gemini-CLI schema so auto-capture needs a small adapter.
@@ -117,7 +119,7 @@ anywhere is readable everywhere.
117
119
  update/supersession resolution preserve both sides of ambiguous evidence
118
120
  instead of silently overwriting.
119
121
  - **Hybrid retrieval** — `get_context` blends FTS5 keyword search with a
120
- dependency-free local vector embedding (RRF fusion + scoring), then assembles
122
+ dependency-free lexical fuzzy matching (hashed n-gram similarity, 512-dim FNV-1a) (RRF fusion + scoring), then assembles
121
123
  a token-budgeted context with optional memory-graph expansion.
122
124
  - **Consolidation** — periodic clustering of similar memories into derived
123
125
  memories with full provenance (`derived_from` links).
@@ -138,7 +140,7 @@ anywhere is readable everywhere.
138
140
  | `npm run build` | compile TypeScript → `dist/` |
139
141
  | `npm start` | run the MCP server (stdio) from `dist/index.js` |
140
142
  | `npm run distill` | rule-based distill: interactions → profile sections + prune old data (env `RETENTION_DAYS` default 30) |
141
- | `npm test` | full suite: capture, distill, lifecycle, temporal, conflict, retrieval, graph, context, consolidation, benchmark, security, tools_v21, smoke, e2e_transport, retrieval_benchmark, recall_regression, scope, profile, entity_extraction, conflict_benchmark |
143
+ | `npm test` | full suite: capture, distill, lifecycle, temporal, conflict, retrieval, graph, context, consolidation, benchmark, security, tools_v21, smoke, e2e_transport, retrieval_benchmark, recall_regression, scope, profile, entity_extraction, conflict_benchmark, security_regression, export_import_roundtrip |
142
144
  | `node test/capture.test.mjs` | test capture-core (filter secrets, dedupe, truncate, insert SQL) |
143
145
  | `node test/distill.test.mjs` | test distill-core (Thai tokenize, stats, profile sections, prune) |
144
146
  | `node test/lifecycle.test.mjs` | test lifecycle engine (states, decay, supersession) |
@@ -215,6 +217,52 @@ data/
215
217
  - DB path can be overridden via the `MEMORY_DB_PATH` env var
216
218
  - everything in `data/` is git-ignored
217
219
 
220
+ ## Benchmark — internal self-reported (not third-party)
221
+
222
+ > **⚠️ Internal self-reported benchmark — not third-party benchmark**
223
+ > - **internal small-N**: **180 records/30 topics** (B.retrieval: 30 topics × 5 relevant + 30 distractors = 180; full run also uses small-N storage/temporal/context subsets)
224
+ > - **single-machine self-run**: single developer machine, single OS/Node/better-sqlite3 build — not cross-machine, not independently verified
225
+ > - **not third-party benchmark**: self-reported, not independently verified; do not compare as if from an external evaluator
226
+ > - Dataset and harness are in `repro/` (commitable) and `benchmark/` (full framework, see `TH_MEMORY_MCP_BENCHMARK_SPEC.md` and `benchmark/README.md`).
227
+
228
+ **Two modes**
229
+
230
+ | Mode | Command | Data | Suites | Use case |
231
+ |------|---------|------|--------|----------|
232
+ | Normal | `npm run benchmark` | 180 records / 30 topics | retrieval | quick check (<5s) |
233
+ | Heavy | `npm run benchmark:heavy` | 600 records / 100 topics + 2k scale | all (storage/retrieval/temporal/context/performance/scalability/cold/ablation) | stress / regression |
234
+
235
+ Reproduce:
236
+
237
+ ```powershell
238
+ npm run build
239
+ # Normal — quick
240
+ npm run benchmark
241
+ npm run benchmark -- --k 10
242
+ npm run benchmark -- --out repro/results
243
+
244
+ # Heavy — full framework, more data
245
+ npm run benchmark:heavy
246
+ # or custom:
247
+ node benchmark/run.mjs --suite all --topics 100 --distractors 100 --scale 2000 --out benchmark/results
248
+ ```
249
+
250
+ **Viewer — compare last 3 versions (table + charts)**
251
+
252
+ ```powershell
253
+ npm run benchmark:viewer
254
+ # or: npx serve . -l 3000
255
+ # open http://localhost:3000/benchmark/viewer/ or http://localhost:3000/result/viewer.html
256
+ ```
257
+
258
+ The viewer loads `benchmark/results/history.jsonl`, groups by version, takes the **latest run of the 3 most recent versions** (e.g. 2.2.2 / 2.2.3 / 2.2.4) and shows a highlighted table (1 row per version) + bar charts for `Recall@5 / MRR / NDCG@5` and `Latency p95`. Results are also saved per version in `result/v*_benchmark_result.md` and `benchmark/results/versions/<ver>/`.
259
+
260
+ Last internal run (v2.2.4, warm, same dataset — not third-party): Recall@5=0.92, Precision@5=0.92, MRR=1.00, NDCG@5=0.94 over 30 topics/180 records. See `result/v2.2.4_benchmark_result.md` and `repro/README.md` for details and caveats (internal small-N, single-machine self-run).
261
+
262
+ ## Known Limitations
263
+
264
+ - **No encryption at rest (plaintext-at-rest)** — `data/memory.db` (WAL mode, `better-sqlite3`) is a plain, unencrypted SQLite file. `100% local & private` means no cloud or network exfiltration — it does **not** mean encrypted at rest. Anyone with filesystem access (shared machine, backup, malware, stolen device) can read preferences/lessons/interactions in plaintext. For sensitive data, use OS-level full-disk encryption (BitLocker / FileVault / LUKS) or an opt-in SQLCipher build (requires native rebuild and key management). No SQLCipher/in-code encryption is applied by default and `src/db/index.ts` documents this explicitly.
265
+
218
266
  ## License
219
267
 
220
268
  [MIT](LICENSE) © 2026 worakorn-prince
package/README.th.md CHANGED
@@ -1,177 +1,177 @@
1
- # th-memory-mcp
2
-
3
- [![npm version](https://img.shields.io/npm/v/th-memory-mcp.svg)](https://www.npmjs.com/package/th-memory-mcp)
4
- [![npm downloads](https://img.shields.io/npm/dm/th-memory-mcp.svg)](https://www.npmjs.com/package/th-memory-mcp)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
7
-
8
- MCP server ความจำระยะยาวสำหรับ OpenCode — เก็บ preferences, lessons, ประวัติการใช้งาน ลง SQLite ไฟล์เดียว (local 100%, ไม่มี external API) เพื่อให้ AI "จำและปรับตัว" กับผู้ใช้ผ่าน context-based learning
9
-
10
- **สถานะ:** v2.2.4 — engine ความจำแบบ temporal, conflict-aware, hybrid-retrieval 16 MCP tools, 25 ชุดเทสผ่าน อัปเกรด schema แบบ non-destructive จาก v1 (ข้อมูล v1 ทั้งหมดถูกเก็บรักษา) ฟีเจอร์ใหม่ใน v2.2: lifecycle states, temporal validity, การแก้ conflict/dedup พร้อม scope USER/SESSION/PROJECT/GLOBAL, hybrid FTS+vector retrieval (RRF), memory graph, ประกอบ `get_context`, consolidation, และ `link_memory` / `merge_memory` / `update_memory` / `import_memory` / `extract_memories` ใหม่ใน v2.2.3: บังคับ scope ใน retrieval, แยก scope ใน graph, export/import แบบ round-trip, ป้องกัน symlink ด้วย realpath, ตรวจ import เข้มงวด, เลิก N+1 query, benchmark cold/ablation และสวิตช์ `MEMORY_RETRIEVAL_MODE`
11
-
12
- > English: [README.md](README.md)
13
-
14
- ## Requirements (ความต้องการระบบ)
15
-
16
- - **Node.js >= 20** — server ใช้ API ของ Node โดยเฉพาะ (better-sqlite3 แบบ native build และการหา path ด้วย `import.meta.url`) และ MCP SDK ต้องการ runtime สมัยใหม่ CI ของเราทดสอบบน Node 20.x และ 22.x
17
- - **npm** — สำหรับติดตั้ง dependencies และรัน build/test (`npm install`, `npm run build`, `npm test`)
18
- - **OpenCode** — โปรแกรมหลักที่โหลด MCP server นี้และ plugin auto-capture ใช้ OpenCode รุ่นที่รองรับ MCP (stdio) + plugins (plugin รันบน Bun ที่มากับ OpenCode)
19
- - **OS: Windows / macOS / Linux** — server ข้ามแพลตฟอร์มได้ (Node) plugin auto-capture รันได้ทุกที่ที่มี Bun ของ OpenCode หมายเหตุสำหรับ Windows: ตั้ง `MEMORY_DB_PATH` ง่ายสุดด้วย `setx` ส่วน macOS/Linux ใช้ `export` ใน shell profile
20
-
21
- ไม่ต้องมีบริการภายนอก บัญชี หรือ API key — ทุกอย่างอยู่ในไฟล์ SQLite ภายในเครื่อง
22
-
23
- ## Quick Start (เริ่มใช้งานไว)
24
-
25
- **ทางที่เร็วที่สุด:** หลัง clone ให้รัน `npm run quickstart` — มันจะ build, ต่อไฟล์ `opencode.json`, วาง plugin และตั้ง `MEMORY_DB_PATH` ให้ในคำสั่งเดียว ขั้นตอนด้านล่างคือสิ่งที่สคริปต์ทำ (ใช้ได้หากอยากควบคุมเองทีละขั้น)
26
-
27
- **ติดตั้งผ่าน npm (อีกทางเลือก):** ติดตั้ง server แบบ global ด้วย `npm install -g th-memory-mcp` (หรือรันทันทีด้วย `npx th-memory-mcp`) แล้วชี้ `command` ของ `mcp` ใน `opencode.json` ไปที่ `th-memory-mcp` แทน `dist/index.js` ที่ build แล้ว plugin auto-capture ยังคงมาจาก repo นี้ (คัดลอก `src/plugin/learning-capture.ts` ตามขั้นตอน 4 ด้านล่าง)
28
-
29
- ```bash
30
- # 1. Clone และ build
31
- git clone https://github.com/worakorn-prince/th-memory-mcp.git
32
- cd th-memory-mcp
33
- npm install
34
- npm run build
35
-
36
- # 2. ให้ server และ plugin ใช้ DB เดียวกัน
37
- # Windows (PowerShell):
38
- setx MEMORY_DB_PATH "$PWD/data/memory.db"
39
- # macOS / Linux (เพิ่มใน shell profile เช่น ~/.zshrc):
40
- # export MEMORY_DB_PATH="$PWD/data/memory.db"
41
- ```
42
-
43
- 3. นำไป merge ใน `~/.config/opencode/opencode.json` (แทน `<REPO>` ด้วย path เต็มของโฟลเดอร์ที่ clone):
44
-
45
- ```json
46
- {
47
- "instructions": ["<REPO>/AGENTS.memory.example.md"],
48
- "mcp": {
49
- "memory": {
50
- "type": "local",
51
- "command": ["node", "<REPO>/dist/index.js"],
52
- "enabled": true,
53
- "environment": { "MEMORY_DB_PATH": "<REPO>/data/memory.db" }
54
- }
55
- }
56
- }
57
- ```
58
-
59
- 4. (Optional) เปิด auto-capture: คัดลอก `src/plugin/learning-capture.ts` → `~/.config/opencode/plugins/`
60
- 5. **Restart OpenCode**
61
- 6. ลองใช้: *"จำไว้ว่าฉันชอบใช้ pnpm"* → เปิด session ใหม่ → *"ฉันชอบ package manager อะไร?"*
62
-
63
- ## สถาปัตยกรรม
64
-
65
- ```
66
- OpenCode ──┬─ Plugin learning-capture (Bun) ── จับ prompt/tool/error ลง DB อัตโนมัติ
67
- │ └─ ฉีด profile กลับ context ตอน compaction
68
- └─ MCP th-memory-mcp (Node.js stdio) ── tools 16 ตัว อ่าน/เขียน SQLite เดียวกัน
69
- ▲
70
- Global instructions (memory-protocol.md) สอน AI ใช้ tools
71
- ```
72
-
73
- รายละเอียดสถาปัตยกรรมเต็มอยู่ใน [ARCHITECTURE_v2.md](ARCHITECTURE_v2.md) — คู่มืออัปเกรดจาก v1 ดูได้ที่ [MIGRATION_v2.md](MIGRATION_v2.md)
74
-
75
- ## ทำไมต้องใช้ th-memory-mcp?
76
-
77
- LLM ไม่ได้จำคุณข้าม session — แชทใหม่ทุกครั้งเริ่มจากศูนย์ th-memory-mcp มอบความจำระยะยาวแบบส่วนตัว ภายในเครื่อง ให้ AI ของคุณ:
78
-
79
- - **เรียนรู้แบบ context-based ไม่ใช่ fine-tuning** — จับความชอบ/การถูกแก้/พฤติกรรม ของคุณ แล้วเรียกกลับเข้า context ครั้งหน้า กลไกเดียวกับฟีเจอร์ความจำของ AI ชั้นนำ โดยไม่ส่งข้อมูลออกนอกเครื่อง
80
- - **local 100% และเป็นส่วนตัว** — ไฟล์ SQLite เดียว ไม่มีคลาวด์ ไม่มี external API มีการกรอง secret ก่อนบันทึกเสมอ
81
- - **โอเวอร์เฮดต่ำ** — ทุก tool call มีเพดาน (latency < 10 ms, ขนาด output จำกัด) และ AI ค้นความจำเฉพาะตอนจำเป็น จึงไม่บวม context
82
- - **ทนทาน** — ทุก tool ทำ graceful degradation ถ้า DB ไม่ได้เปิด AI ก็ทำงานต่อได้แทนที่จะพัง
83
- - **Lifecycle & temporal** — ทุกความจำมี lifecycle state (active/stale/superseded/archived), คะแนน confidence/importance/salience, decay ต่อ type, และ validity intervals ให้ AI เหตุผลเรื่อง point-in-time truth และ supersession chains ได้
84
- - **Conflict-aware** — ตรวจจับ duplicate / contradiction และแก้ด้วย update/supersession โดยเก็บทั้งสองฝ่ายของหลักฐานที่ขัดแย้งแทนการเขียนทับเงียบๆ
85
- - **Hybrid retrieval** — `get_context` ผสาน FTS5 + local vector embedding (RRF fusion + scoring) แล้วประกอบ context แบบมี token budget พร้อมขยายผ่าน memory graph
86
- - **Consolidation** — จัดคลัสเตอร์ความจำที่คล้ายกันเป็น derived memory พร้อม provenance (`derived_from` links)
87
- - **เปิดกว้างและต่อยอดได้** — MIT license, 11 tools ที่อธิบายครบ, มี rule-based distill และ plugin auto-capture ที่คุณปรับแต่งได้
88
-
89
- ## Scripts
90
-
91
- | Command | คำอธิบาย |
92
- |---------|----------|
93
- | `npm run build` | compile TypeScript → `dist/` |
94
- | `npm start` | รัน MCP server (stdio) จาก `dist/index.js` |
95
- | `npm run distill` | rule-based distill: interactions → profile sections + prune ข้อมูลเก่า (env `RETENTION_DAYS` default 30) |
96
- | `npm test` | ชุดเทสครบ: capture, distill, lifecycle, temporal, conflict, retrieval, graph, context, consolidation, benchmark, security, tools_v21, smoke, e2e_transport, retrieval_benchmark, recall_regression, scope, profile, entity_extraction, conflict_benchmark |
97
- | `node test/capture.test.mjs` | ทดสอบ capture-core (filter secrets, dedupe, truncate, insert SQL) |
98
- | `node test/distill.test.mjs` | ทดสอบ distill-core (tokenize ไทย, stats, profile sections, prune) |
99
- | `node test/lifecycle.test.mjs` | ทดสอบ lifecycle engine (states, decay, supersession) |
100
- | `node test/temporal.test.mjs` | ทดสอบ temporal model (validity, historical retrieval) |
101
- | `node test/conflict.test.mjs` | ทดสอบ conflict & dedup resolution |
102
- | `node test/retrieval.test.mjs` | ทดสอบ hybrid FTS+vector+RRF retrieval |
103
- | `node test/graph.test.mjs` | ทดสอบ memory graph (entities, relations, traversal) |
104
- | `node test/context.test.mjs` | ทดสอบ context assembly + token budgeting |
105
- | `node test/consolidation.test.mjs` | ทดสอบ clustering + derived memories |
106
- | `node test/benchmark.test.mjs` | เทสความเร็วบนความจำ 300 รายการ |
107
- | `node test/security.test.mjs` | ตรวจการ injection / ความปลอดภัย |
108
- | `node test/smoke.mjs` | smoke test end-to-end ผ่าน JSON-RPC (11 tools) |
109
-
110
- ## Tools (16)
111
-
112
- | Tool | คำอธิบาย |
113
- |------|----------|
114
- | `remember` | upsert preference (category+key) — ยืนยันซ้ำ confidence +0.1 (cap 1.0) |
115
- | `recall` | ค้น preferences + lessons (FTS5) + interactions ล่าสุดที่ match ตาม topic |
116
- | `get_profile` | ภาพรวมผู้ใช้: profile sections + top preferences + lessons ล่าสุด 5 รายการ |
117
- | `save_lesson` | บันทึกบทเรียนจากการถูกแก้ (situation / mistake / correction) |
118
- | `search_history` | ค้น prompt เก่าด้วย keyword (snippet 200 chars/รายการ) |
119
- | `forget` | ลบ row เดียว (preference/lesson/interaction) ตาม id (+type กัน id ชนข้ามตาราง) |
120
- | `memory_stats` | สถิติความจำ: counts แยก kind, ขนาด DB, oldest/newest interaction, profile sections |
121
- | `get_recent_interactions` | ดึง interactions ล่าสุดแบบดิบ (กรองตาม kind ได้) — วัตถุดิบของ Smart Distill |
122
- | `export_memory` | export ความจำเป็น JSON ลง `data/exports/` เท่านั้น (sanitize filename ให้เอง) |
123
- | `get_context` | ประกอบความจำที่เกี่ยวข้องกับงานปัจจุบันผ่าน hybrid retrieval (+ ขยายผ่าน memory graph ได้) พร้อม token budgeting |
124
- | `consolidate` | จัดคลัสเตอร์ความจำที่คล้ายกันด้วย embedding cosine และสร้าง derived/consolidated memory ที่ผูกด้วย `derived_from` ได้ |
125
- | `link_memory` | สร้างความสัมพันธ์แบบมีประเภทระหว่างความจำสองอันในกราฟ |
126
- | `merge_memory` | รวมความจำที่ซ้ำเข้ากับความจำหลัก (ต้นทางถูก superseded, เก็บ provenance ไว้ใน `metadata.merged_from`) |
127
- | `update_memory` | อัปเดตฟิลด์ที่เปลี่ยนได้แบบไม่เปลี่ยนตัวตน หรือสร้างความจำแทนที่เมื่อ `content` เปลี่ยน (ตั้ง `supersede=false` เพื่อแก้ในที่) |
128
- | `import_memory` | นำเข้าความจำจาก JSON (ตรวจสอบ type, dedup กับของเดิม, ไม่เขียนทับแบบมืดบอด); ค่าเริ่มต้น dry-run, ตั้ง `apply=true` เพื่อเพิ่ม |
129
- | `extract_memories` | สแกน interactions ล่าสุดหาเจตนาบันทึกความจำ และเสนอ/สร้างความจำ (ไม่ใช้ LLM); ค่าเริ่มต้น dry-run, ตั้ง `apply=true` เพื่อสร้าง (source=captured) |
130
-
131
- ## ติดตั้งกับ OpenCode
132
-
133
- 1. Merge `mcp` section จาก [`opencode.example.json`](opencode.example.json) เข้า `opencode.json` (global หรือ project-level)
134
- - **สำคัญ:** ตั้ง `MEMORY_DB_PATH` ให้ชี้ที่ไฟล์ DB เดียวกันทั้ง server และ plugin (ในตัวอย่างคือ `<ABSOLUTE_PATH>/th-memory-mcp/data/memory.db`) มิฉะนั้น auto-capture plugin จะเขียนลง DB คนละไฟล์กับที่ AI อ่าน
135
- - วิธีตั้ง (เลือกหนึ่ง):
136
- - กำหนดใน `environment` ของ mcp (ดูตัวอย่าง) — ครอบคลุมเฉพาะ MCP server
137
- - **หรือ** กำหนดเป็น environment variable ระดับระบบ/ผู้ใช้ (เช่น `setx MEMORY_DB_PATH "D:/path/to/memory.db"` บน Windows) — ครอบคลุมทั้ง server และ plugin เพราะ plugin รันใน process เดียวกับ OpenCode
138
- 2. ผูกกฎความจำระดับ global — เพิ่มใน `opencode.json`:
139
- ```json
140
- "instructions": ["C:/Users/<user>/.config/opencode/memory-protocol.md"]
141
- ```
142
- (ตัวอย่างเนื้อหากฎอยู่ใน [`AGENTS.memory.example.md`](AGENTS.memory.example.md) — ใช้แนบระดับโปรเจกต์แทนได้)
143
- 3. (Optional) Deploy plugin auto-capture: copy `src/plugin/learning-capture.ts` → `~/.config/opencode/plugins/learning-capture.ts`
144
- 4. **Restart OpenCode** (config โหลดตอน start เท่านั้น)
145
- 5. ทดสอบ: *"จำไว้ว่าฉันชอบใช้ pnpm"* → เปิด session ใหม่ถามกลับ
146
-
147
- ## การใช้งานประจำวัน
148
-
149
- AI รองรับสองภาษา (ไทย/อังกฤษ) สลับกันได้ตลอด โดยไม่ต้องแจ้งล่วงหน้า
150
-
151
- | ไทย | English | สิ่งที่เกิด |
152
- |------|---------|-----------|
153
- | "จำไว้ว่า..." | "Remember that..." | `remember` — บันทึกความชอบ |
154
- | "สรุปความจำ" / "distill memory" | "Summarize memory" / "distill memory" | **Smart Distill** — AI อ่าน `get_recent_interactions` วิเคราะห์ pattern แล้วบันทึก insight เอง |
155
- | "ระบบความจำเป็นไงบ้าง" | "How is my memory?" / "memory status" | `memory_stats` |
156
- | "สำรองความจำ" | "Export memory" / "backup memory" | `export_memory` |
157
- | "ค้นประวัติ..." | "Search history..." | `search_history` |
158
- | "ลืม..." | "Forget..." | `forget` |
159
-
160
- ดูแลระยะยาว: รัน `npm run distill` เป็นครั้งคราวเพื่อสรุปสถิติ + ลบ interactions เก่าเกิน 30 วัน
161
-
162
- ## โครงสร้าง data/
163
-
164
- ```
165
- data/
166
- ├── memory.db # SQLite (WAL mode) — DB หลัก (+ .db-wal, .db-shm)
167
- └── exports/ # ไฟล์ JSON จาก tool export_memory (เขียนได้เฉพาะ dir นี้)
168
- ```
169
-
170
- - path ของ DB override ได้ผ่าน env `MEMORY_DB_PATH`
171
- - ทุกอย่างใน `data/` ถูก git ignore
172
-
173
- ## License
174
-
175
- [MIT](LICENSE) © 2026 worakorn-prince
176
-
177
- โปรเจกต์นี้เผยแพร่ภายใต้สัญญาอนุญาต MIT — อ่านข้อความฉบับเต็มได้ในไฟล์ [LICENSE](LICENSE)
1
+ # th-memory-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/th-memory-mcp.svg)](https://www.npmjs.com/package/th-memory-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/th-memory-mcp.svg)](https://www.npmjs.com/package/th-memory-mcp)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
7
+
8
+ MCP server ความจำระยะยาวสำหรับ OpenCode — เก็บ preferences, lessons, ประวัติการใช้งาน ลง SQLite ไฟล์เดียว (local 100%, ไม่มี external API) เพื่อให้ AI "จำและปรับตัว" กับผู้ใช้ผ่าน context-based learning
9
+
10
+ **สถานะ:** v2.2.7 — engine ความจำแบบ temporal, conflict-aware, hybrid-retrieval 16 MCP tools, 25 ชุดเทสผ่าน อัปเกรด schema แบบ non-destructive จาก v1 (ข้อมูล v1 ทั้งหมดถูกเก็บรักษา) ฟีเจอร์ใหม่ใน v2.2: lifecycle states, temporal validity, การแก้ conflict/dedup พร้อม scope USER/SESSION/PROJECT/GLOBAL, hybrid FTS+vector retrieval (RRF), memory graph, ประกอบ `get_context`, consolidation, และ `link_memory` / `merge_memory` / `update_memory` / `import_memory` / `extract_memories` ใหม่ใน v2.2.3: บังคับ scope ใน retrieval, แยก scope ใน graph, export/import แบบ round-trip, ป้องกัน symlink ด้วย realpath, ตรวจ import เข้มงวด, เลิก N+1 query, benchmark cold/ablation และสวิตช์ `MEMORY_RETRIEVAL_MODE` ใหม่ใน v2.2.7: ซิงค์ secret filter ระหว่าง Claude hook กับ capture-core (redact 6 patterns แทนทิ้งบรรทัด), แก้ `err()` ให้ส่ง `isError:true` ตาม MCP spec, แก้ backup rotation (backup เฉพาะเมื่อมี migration pending + prune เก็บ 5 ไฟล์ล่าสุด) และเพิ่ม hook error logging สำหรับ SessionEnd distill
11
+
12
+ > English: [README.md](README.md)
13
+
14
+ ## Requirements (ความต้องการระบบ)
15
+
16
+ - **Node.js >= 20** — server ใช้ API ของ Node โดยเฉพาะ (better-sqlite3 แบบ native build และการหา path ด้วย `import.meta.url`) และ MCP SDK ต้องการ runtime สมัยใหม่ CI ของเราทดสอบบน Node 20.x และ 22.x
17
+ - **npm** — สำหรับติดตั้ง dependencies และรัน build/test (`npm install`, `npm run build`, `npm test`)
18
+ - **OpenCode** — โปรแกรมหลักที่โหลด MCP server นี้และ plugin auto-capture ใช้ OpenCode รุ่นที่รองรับ MCP (stdio) + plugins (plugin รันบน Bun ที่มากับ OpenCode)
19
+ - **OS: Windows / macOS / Linux** — server ข้ามแพลตฟอร์มได้ (Node) plugin auto-capture รันได้ทุกที่ที่มี Bun ของ OpenCode หมายเหตุสำหรับ Windows: ตั้ง `MEMORY_DB_PATH` ง่ายสุดด้วย `setx` ส่วน macOS/Linux ใช้ `export` ใน shell profile
20
+
21
+ ไม่ต้องมีบริการภายนอก บัญชี หรือ API key — ทุกอย่างอยู่ในไฟล์ SQLite ภายในเครื่อง
22
+
23
+ ## Quick Start (เริ่มใช้งานไว)
24
+
25
+ **ทางที่เร็วที่สุด:** หลัง clone ให้รัน `npm run quickstart` — มันจะ build, ต่อไฟล์ `opencode.json`, วาง plugin และตั้ง `MEMORY_DB_PATH` ให้ในคำสั่งเดียว ขั้นตอนด้านล่างคือสิ่งที่สคริปต์ทำ (ใช้ได้หากอยากควบคุมเองทีละขั้น)
26
+
27
+ **ติดตั้งผ่าน npm (อีกทางเลือก):** ติดตั้ง server แบบ global ด้วย `npm install -g th-memory-mcp` (หรือรันทันทีด้วย `npx th-memory-mcp`) แล้วชี้ `command` ของ `mcp` ใน `opencode.json` ไปที่ `th-memory-mcp` แทน `dist/index.js` ที่ build แล้ว plugin auto-capture ยังคงมาจาก repo นี้ (คัดลอก `src/plugin/learning-capture.ts` ตามขั้นตอน 4 ด้านล่าง)
28
+
29
+ ```bash
30
+ # 1. Clone และ build
31
+ git clone https://github.com/worakorn-prince/th-memory-mcp.git
32
+ cd th-memory-mcp
33
+ npm install
34
+ npm run build
35
+
36
+ # 2. ให้ server และ plugin ใช้ DB เดียวกัน
37
+ # Windows (PowerShell):
38
+ setx MEMORY_DB_PATH "$PWD/data/memory.db"
39
+ # macOS / Linux (เพิ่มใน shell profile เช่น ~/.zshrc):
40
+ # export MEMORY_DB_PATH="$PWD/data/memory.db"
41
+ ```
42
+
43
+ 3. นำไป merge ใน `~/.config/opencode/opencode.json` (แทน `<REPO>` ด้วย path เต็มของโฟลเดอร์ที่ clone):
44
+
45
+ ```json
46
+ {
47
+ "instructions": ["<REPO>/AGENTS.memory.example.md"],
48
+ "mcp": {
49
+ "memory": {
50
+ "type": "local",
51
+ "command": ["node", "<REPO>/dist/index.js"],
52
+ "enabled": true,
53
+ "environment": { "MEMORY_DB_PATH": "<REPO>/data/memory.db" }
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ 4. (Optional) เปิด auto-capture: คัดลอก `src/plugin/learning-capture.ts` → `~/.config/opencode/plugins/`
60
+ 5. **Restart OpenCode**
61
+ 6. ลองใช้: *"จำไว้ว่าฉันชอบใช้ pnpm"* → เปิด session ใหม่ → *"ฉันชอบ package manager อะไร?"*
62
+
63
+ ## สถาปัตยกรรม
64
+
65
+ ```
66
+ OpenCode ──┬─ Plugin learning-capture (Bun) ── จับ prompt/tool/error ลง DB อัตโนมัติ
67
+ │ └─ ฉีด profile กลับ context ตอน compaction
68
+ └─ MCP th-memory-mcp (Node.js stdio) ── tools 16 ตัว อ่าน/เขียน SQLite เดียวกัน
69
+ ▲
70
+ Global instructions (memory-protocol.md) สอน AI ใช้ tools
71
+ ```
72
+
73
+ รายละเอียดสถาปัตยกรรมเต็มอยู่ใน [ARCHITECTURE_v2.md](ARCHITECTURE_v2.md) — คู่มืออัปเกรดจาก v1 ดูได้ที่ [MIGRATION_v2.md](MIGRATION_v2.md)
74
+
75
+ ## ทำไมต้องใช้ th-memory-mcp?
76
+
77
+ LLM ไม่ได้จำคุณข้าม session — แชทใหม่ทุกครั้งเริ่มจากศูนย์ th-memory-mcp มอบความจำระยะยาวแบบส่วนตัว ภายในเครื่อง ให้ AI ของคุณ:
78
+
79
+ - **เรียนรู้แบบ context-based ไม่ใช่ fine-tuning** — จับความชอบ/การถูกแก้/พฤติกรรม ของคุณ แล้วเรียกกลับเข้า context ครั้งหน้า กลไกเดียวกับฟีเจอร์ความจำของ AI ชั้นนำ โดยไม่ส่งข้อมูลออกนอกเครื่อง
80
+ - **local 100% และเป็นส่วนตัว** — ไฟล์ SQLite เดียว ไม่มีคลาวด์ ไม่มี external API มีการกรอง secret ก่อนบันทึกเสมอ
81
+ - **โอเวอร์เฮดต่ำ** — ทุก tool call มีเพดาน (latency < 10 ms, ขนาด output จำกัด) และ AI ค้นความจำเฉพาะตอนจำเป็น จึงไม่บวม context
82
+ - **ทนทาน** — ทุก tool ทำ graceful degradation ถ้า DB ไม่ได้เปิด AI ก็ทำงานต่อได้แทนที่จะพัง
83
+ - **Lifecycle & temporal** — ทุกความจำมี lifecycle state (active/stale/superseded/archived), คะแนน confidence/importance/salience, decay ต่อ type, และ validity intervals ให้ AI เหตุผลเรื่อง point-in-time truth และ supersession chains ได้
84
+ - **Conflict-aware** — ตรวจจับ duplicate / contradiction และแก้ด้วย update/supersession โดยเก็บทั้งสองฝ่ายของหลักฐานที่ขัดแย้งแทนการเขียนทับเงียบๆ
85
+ - **Hybrid retrieval** — `get_context` ผสาน FTS5 + local vector embedding (RRF fusion + scoring) แล้วประกอบ context แบบมี token budget พร้อมขยายผ่าน memory graph
86
+ - **Consolidation** — จัดคลัสเตอร์ความจำที่คล้ายกันเป็น derived memory พร้อม provenance (`derived_from` links)
87
+ - **เปิดกว้างและต่อยอดได้** — MIT license, 11 tools ที่อธิบายครบ, มี rule-based distill และ plugin auto-capture ที่คุณปรับแต่งได้
88
+
89
+ ## Scripts
90
+
91
+ | Command | คำอธิบาย |
92
+ |---------|----------|
93
+ | `npm run build` | compile TypeScript → `dist/` |
94
+ | `npm start` | รัน MCP server (stdio) จาก `dist/index.js` |
95
+ | `npm run distill` | rule-based distill: interactions → profile sections + prune ข้อมูลเก่า (env `RETENTION_DAYS` default 30) |
96
+ | `npm test` | ชุดเทสครบ: capture, distill, lifecycle, temporal, conflict, retrieval, graph, context, consolidation, benchmark, security, tools_v21, smoke, e2e_transport, retrieval_benchmark, recall_regression, scope, profile, entity_extraction, conflict_benchmark |
97
+ | `node test/capture.test.mjs` | ทดสอบ capture-core (filter secrets, dedupe, truncate, insert SQL) |
98
+ | `node test/distill.test.mjs` | ทดสอบ distill-core (tokenize ไทย, stats, profile sections, prune) |
99
+ | `node test/lifecycle.test.mjs` | ทดสอบ lifecycle engine (states, decay, supersession) |
100
+ | `node test/temporal.test.mjs` | ทดสอบ temporal model (validity, historical retrieval) |
101
+ | `node test/conflict.test.mjs` | ทดสอบ conflict & dedup resolution |
102
+ | `node test/retrieval.test.mjs` | ทดสอบ hybrid FTS+vector+RRF retrieval |
103
+ | `node test/graph.test.mjs` | ทดสอบ memory graph (entities, relations, traversal) |
104
+ | `node test/context.test.mjs` | ทดสอบ context assembly + token budgeting |
105
+ | `node test/consolidation.test.mjs` | ทดสอบ clustering + derived memories |
106
+ | `node test/benchmark.test.mjs` | เทสความเร็วบนความจำ 300 รายการ |
107
+ | `node test/security.test.mjs` | ตรวจการ injection / ความปลอดภัย |
108
+ | `node test/smoke.mjs` | smoke test end-to-end ผ่าน JSON-RPC (11 tools) |
109
+
110
+ ## Tools (16)
111
+
112
+ | Tool | คำอธิบาย |
113
+ |------|----------|
114
+ | `remember` | upsert preference (category+key) — ยืนยันซ้ำ confidence +0.1 (cap 1.0) |
115
+ | `recall` | ค้น preferences + lessons (FTS5) + interactions ล่าสุดที่ match ตาม topic |
116
+ | `get_profile` | ภาพรวมผู้ใช้: profile sections + top preferences + lessons ล่าสุด 5 รายการ |
117
+ | `save_lesson` | บันทึกบทเรียนจากการถูกแก้ (situation / mistake / correction) |
118
+ | `search_history` | ค้น prompt เก่าด้วย keyword (snippet 200 chars/รายการ) |
119
+ | `forget` | ลบ row เดียว (preference/lesson/interaction) ตาม id (+type กัน id ชนข้ามตาราง) |
120
+ | `memory_stats` | สถิติความจำ: counts แยก kind, ขนาด DB, oldest/newest interaction, profile sections |
121
+ | `get_recent_interactions` | ดึง interactions ล่าสุดแบบดิบ (กรองตาม kind ได้) — วัตถุดิบของ Smart Distill |
122
+ | `export_memory` | export ความจำเป็น JSON ลง `data/exports/` เท่านั้น (sanitize filename ให้เอง) |
123
+ | `get_context` | ประกอบความจำที่เกี่ยวข้องกับงานปัจจุบันผ่าน hybrid retrieval (+ ขยายผ่าน memory graph ได้) พร้อม token budgeting |
124
+ | `consolidate` | จัดคลัสเตอร์ความจำที่คล้ายกันด้วย embedding cosine และสร้าง derived/consolidated memory ที่ผูกด้วย `derived_from` ได้ |
125
+ | `link_memory` | สร้างความสัมพันธ์แบบมีประเภทระหว่างความจำสองอันในกราฟ |
126
+ | `merge_memory` | รวมความจำที่ซ้ำเข้ากับความจำหลัก (ต้นทางถูก superseded, เก็บ provenance ไว้ใน `metadata.merged_from`) |
127
+ | `update_memory` | อัปเดตฟิลด์ที่เปลี่ยนได้แบบไม่เปลี่ยนตัวตน หรือสร้างความจำแทนที่เมื่อ `content` เปลี่ยน (ตั้ง `supersede=false` เพื่อแก้ในที่) |
128
+ | `import_memory` | นำเข้าความจำจาก JSON (ตรวจสอบ type, dedup กับของเดิม, ไม่เขียนทับแบบมืดบอด); ค่าเริ่มต้น dry-run, ตั้ง `apply=true` เพื่อเพิ่ม |
129
+ | `extract_memories` | สแกน interactions ล่าสุดหาเจตนาบันทึกความจำ และเสนอ/สร้างความจำ (ไม่ใช้ LLM); ค่าเริ่มต้น dry-run, ตั้ง `apply=true` เพื่อสร้าง (source=captured) |
130
+
131
+ ## ติดตั้งกับ OpenCode
132
+
133
+ 1. Merge `mcp` section จาก [`opencode.example.json`](opencode.example.json) เข้า `opencode.json` (global หรือ project-level)
134
+ - **สำคัญ:** ตั้ง `MEMORY_DB_PATH` ให้ชี้ที่ไฟล์ DB เดียวกันทั้ง server และ plugin (ในตัวอย่างคือ `<ABSOLUTE_PATH>/th-memory-mcp/data/memory.db`) มิฉะนั้น auto-capture plugin จะเขียนลง DB คนละไฟล์กับที่ AI อ่าน
135
+ - วิธีตั้ง (เลือกหนึ่ง):
136
+ - กำหนดใน `environment` ของ mcp (ดูตัวอย่าง) — ครอบคลุมเฉพาะ MCP server
137
+ - **หรือ** กำหนดเป็น environment variable ระดับระบบ/ผู้ใช้ (เช่น `setx MEMORY_DB_PATH "D:/path/to/memory.db"` บน Windows) — ครอบคลุมทั้ง server และ plugin เพราะ plugin รันใน process เดียวกับ OpenCode
138
+ 2. ผูกกฎความจำระดับ global — เพิ่มใน `opencode.json`:
139
+ ```json
140
+ "instructions": ["C:/Users/<user>/.config/opencode/memory-protocol.md"]
141
+ ```
142
+ (ตัวอย่างเนื้อหากฎอยู่ใน [`AGENTS.memory.example.md`](AGENTS.memory.example.md) — ใช้แนบระดับโปรเจกต์แทนได้)
143
+ 3. (Optional) Deploy plugin auto-capture: copy `src/plugin/learning-capture.ts` → `~/.config/opencode/plugins/learning-capture.ts`
144
+ 4. **Restart OpenCode** (config โหลดตอน start เท่านั้น)
145
+ 5. ทดสอบ: *"จำไว้ว่าฉันชอบใช้ pnpm"* → เปิด session ใหม่ถามกลับ
146
+
147
+ ## การใช้งานประจำวัน
148
+
149
+ AI รองรับสองภาษา (ไทย/อังกฤษ) สลับกันได้ตลอด โดยไม่ต้องแจ้งล่วงหน้า
150
+
151
+ | ไทย | English | สิ่งที่เกิด |
152
+ |------|---------|-----------|
153
+ | "จำไว้ว่า..." | "Remember that..." | `remember` — บันทึกความชอบ |
154
+ | "สรุปความจำ" / "distill memory" | "Summarize memory" / "distill memory" | **Smart Distill** — AI อ่าน `get_recent_interactions` วิเคราะห์ pattern แล้วบันทึก insight เอง |
155
+ | "ระบบความจำเป็นไงบ้าง" | "How is my memory?" / "memory status" | `memory_stats` |
156
+ | "สำรองความจำ" | "Export memory" / "backup memory" | `export_memory` |
157
+ | "ค้นประวัติ..." | "Search history..." | `search_history` |
158
+ | "ลืม..." | "Forget..." | `forget` |
159
+
160
+ ดูแลระยะยาว: รัน `npm run distill` เป็นครั้งคราวเพื่อสรุปสถิติ + ลบ interactions เก่าเกิน 30 วัน
161
+
162
+ ## โครงสร้าง data/
163
+
164
+ ```
165
+ data/
166
+ ├── memory.db # SQLite (WAL mode) — DB หลัก (+ .db-wal, .db-shm)
167
+ └── exports/ # ไฟล์ JSON จาก tool export_memory (เขียนได้เฉพาะ dir นี้)
168
+ ```
169
+
170
+ - path ของ DB override ได้ผ่าน env `MEMORY_DB_PATH`
171
+ - ทุกอย่างใน `data/` ถูก git ignore
172
+
173
+ ## License
174
+
175
+ [MIT](LICENSE) © 2026 worakorn-prince
176
+
177
+ โปรเจกต์นี้เผยแพร่ภายใต้สัญญาอนุญาต MIT — อ่านข้อความฉบับเต็มได้ในไฟล์ [LICENSE](LICENSE)
package/SECURITY.md ADDED
@@ -0,0 +1,40 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 2.2.x | :white_check_mark: |
8
+ | < 2.2 | :x: |
9
+
10
+ We support the latest `2.2.x` release line. Older major/minor lines receive no security updates.
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ **Please do not open a public issue for security reports.**
15
+
16
+ Use one of these private channels:
17
+
18
+ 1. **GitHub Security Advisories (preferred):** https://github.com/worakorn-prince/th-memory-mcp/security/advisories/new
19
+ 2. **Email:** open a draft advisory and we will triage within 72 hours.
20
+
21
+ ### What to include
22
+
23
+ - Affected version / commit
24
+ - Steps to reproduce (minimal PoC)
25
+ - Impact assessment (data loss, leak, DoS, scope bypass, etc.)
26
+ - Suggested fix if you have one
27
+
28
+ ### What to expect
29
+
30
+ - Acknowledgement within 72 hours
31
+ - Triage and severity assessment using the same legend as `HealthCheck_Final.md` (Critical / High / Medium / Low)
32
+ - Fix in a patch release and credit in release notes if desired
33
+
34
+ ## Scope
35
+
36
+ This policy covers the MCP server (`src/`), SQLite store (`data/memory.db`), and the auto-capture plugin (`src/plugin/learning-capture.ts`). The benchmark harness (`benchmark/`, `repro/`) and result files (`result/`) are out of scope.
37
+
38
+ ## Disclosure
39
+
40
+ We follow coordinated disclosure. Please give us reasonable time to release a fix before public disclosure. We will publish a GitHub Release and update `SECURITY.md` with the fix version.