beans-memory 0.0.0-stage → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 firasmpratama
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.id.md ADDED
@@ -0,0 +1,354 @@
1
+ <p align="center">
2
+ <img src="docs/wordmark.svg" alt="beans-memory" width="520">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Memory lokal dan permanen untuk coding agent. Satu file SQLite. Tanpa daemon, tanpa cloud, tanpa akun.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/firasmpratama/beans-memory/tags"><img src="https://img.shields.io/github/v/tag/firasmpratama/beans-memory" alt="Tag terbaru"></a>
11
+ <a href="LICENSE"><img src="https://img.shields.io/github/license/firasmpratama/beans-memory" alt="Lisensi: MIT"></a>
12
+ <a href="https://github.com/firasmpratama/beans-memory/stargazers"><img src="https://img.shields.io/github/stars/firasmpratama/beans-memory" alt="GitHub stars"></a>
13
+ <img src="https://img.shields.io/github/last-commit/firasmpratama/beans-memory" alt="Commit terakhir">
14
+ <img src="https://img.shields.io/badge/Bun-%3E%3D1.2-000000?logo=bun&logoColor=white" alt="Bun 1.2+">
15
+ <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey" alt="Platform">
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="README.md">English</a> | Bahasa Indonesia
20
+ </p>
21
+
22
+ Agent bisa menyimpan catatan saat bekerja, mencarinya lagi nanti, dan menerima index kecil di awal setiap sesi.
23
+
24
+ ## Cara kerja
25
+
26
+ ```
27
+ OpenCode (runtime Bun)
28
+ ├── plugin src/plugin.ts hook + tool memory_*, jalan di dalam proses
29
+ ├── MCP src/mcp.ts tool yang sama lewat stdio, untuk klien lain
30
+ └── SQLite ~/.local/share/beans-memory/memory.db
31
+ observations + FTS5 + prompts + sessions
32
+ ```
33
+
34
+ - **Plugin** mencatat prompt user, mencatat file yang disentuh tool edit/write, dan menyuntik 8 judul catatan terbaru sekali per sesi.
35
+ - **Tool** membuat agent bisa menulis dan mencari catatan permanen. Ringkasan ditulis oleh agent sendiri, jadi tidak ada panggilan model tambahan dan tidak ada worker latar.
36
+ - **MCP** membuka store yang sama untuk klien MCP mana pun (Claude Desktop, Cursor, skrip).
37
+ - **Pencarian** memakai SQLite FTS5: AND dulu, OR sebagai fallback, diurutkan dengan BM25.
38
+ - Semua gagal terbuka. Kalau database atau plugin rusak, OpenCode tetap jalan tanpa memory.
39
+
40
+ ## Kebutuhan
41
+
42
+ - OpenCode 2
43
+ - Bun 1.2+ untuk CLI, server MCP, importer, dan test. Tidak perlu untuk plugin saja: plugin berjalan di Bun bawaan OpenCode.
44
+ - `curl -fsSL https://bun.sh/install | bash`
45
+ - macOS atau Linux. Windows secara teori bisa, belum diuji.
46
+
47
+ ## Mulai cepat
48
+
49
+ ```bash
50
+ git clone https://github.com/firasmpratama/beans-memory ~/tools/beans-memory
51
+ cd ~/tools/beans-memory
52
+ ./install.sh
53
+ ```
54
+
55
+ Restart OpenCode, lalu minta agent memanggil `memory_stats`. Di instalasi baru hasilnya nol catatan.
56
+
57
+ Script memasang loader plugin, membuat launcher CLI `beans-memory` kalau Bun tersedia, dan menyalin skill. Script tidak mengubah `opencode.json` dan tidak menyalakan service.
58
+
59
+ Tidak punya git? Unduh arsip source dari halaman Releases, ekstrak di lokasi permanen, lalu jalankan `./install.sh` di folder itu.
60
+
61
+ ### Instalasi manual
62
+
63
+ <details>
64
+ <summary>Kalau mau memasang sendiri, atau script gagal</summary>
65
+
66
+ 1. Simpan kode di lokasi permanen:
67
+
68
+ ```bash
69
+ git clone https://github.com/firasmpratama/beans-memory ~/tools/beans-memory
70
+ cd ~/tools/beans-memory
71
+ bun test # opsional, butuh Bun; memakai database sementara
72
+ ```
73
+
74
+ 2. Buat loader OpenCode:
75
+
76
+ ```bash
77
+ mkdir -p ~/.config/opencode/plugins/memory
78
+ ```
79
+
80
+ `~/.config/opencode/plugins/memory/index.ts`:
81
+
82
+ ```ts
83
+ import { pathToFileURL } from "node:url";
84
+
85
+ const ENTRY = "/path/absolut/ke/beans-memory/src/plugin.ts";
86
+
87
+ const noop = {
88
+ id: "memory",
89
+ async setup() {
90
+ return () => {};
91
+ },
92
+ };
93
+
94
+ let plugin: unknown = noop;
95
+
96
+ try {
97
+ const loaded = await import(pathToFileURL(ENTRY).href);
98
+ if (loaded?.default?.setup) plugin = loaded.default;
99
+ } catch (error) {
100
+ console.error("[memory] plugin tidak dimuat:", error);
101
+ }
102
+
103
+ export default plugin;
104
+ ```
105
+
106
+ Ganti `ENTRY` dengan path sebenarnya. Pertahankan fallback: kalau kode ada di disk eksternal yang tidak ter-mount, OpenCode tetap start dengan memory nonaktif, bukan gagal.
107
+
108
+ Nama folder dan nama file bebas. OpenCode memuat file `.ts` apa pun di `~/.config/opencode/plugins/`.
109
+
110
+ 3. Restart OpenCode.
111
+
112
+ 4. Verifikasi. Minta agent memanggil `memory_stats`. Di instalasi baru hasilnya nol catatan. Kalau tool tidak muncul, lihat Troubleshooting.
113
+
114
+ Cek loader tanpa OpenCode, kalau Bun terpasang:
115
+
116
+ ```bash
117
+ bun -e 'import("/path/absolut/ke/beans-memory/src/plugin.ts").then((m) => console.log(typeof m.default.setup))'
118
+ ```
119
+
120
+ Hasilnya harus `function`. Error path atau import di sini juga akan membuat plugin gagal di OpenCode.
121
+
122
+ </details>
123
+
124
+ ## Pemakaian
125
+
126
+ Tool yang didaftarkan plugin:
127
+
128
+ | Tool | Fungsi |
129
+ |---|---|
130
+ | `memory_note` | Simpan catatan: judul, isi, tipe, file, konsep |
131
+ | `memory_search` | Pencarian full-text, hasil ringkas berisi id |
132
+ | `memory_get` | Isi lengkap berdasarkan id |
133
+ | `memory_stats` | Jumlah catatan dan tanggal catatan terakhir |
134
+
135
+ Alur yang disarankan untuk agent: panggil `memory_note` setelah tugas yang menghasilkan keputusan, bugfix, atau temuan wiring yang tidak jelas dari kode. Cari dulu dengan `memory_search`, lalu ambil hanya baris yang perlu dengan `memory_get`.
136
+
137
+ Dengan panduan di `AGENTS.md`, agent sebaiknya menulis catatan singkat: apa yang berubah, kenapa, dan file mana yang penting.
138
+
139
+ ## Server MCP (opsional)
140
+
141
+ Untuk klien yang tidak bisa memuat plugin:
142
+
143
+ ```jsonc
144
+ {
145
+ "mcp": {
146
+ "servers": {
147
+ "beans_memory": {
148
+ "type": "local",
149
+ "command": ["/path/absolut/ke/bun", "/path/absolut/ke/beans-memory/src/mcp.ts"]
150
+ }
151
+ }
152
+ }
153
+ }
154
+ ```
155
+
156
+ - Server memakai JSON-RPC lewat stdio, satu pesan per baris.
157
+ - Tool: `memory_search`, `memory_get`, `memory_note`, `memory_stats`.
158
+ - Pemilihan database: `MEMORY_DB`, kalau kosong `~/.local/share/beans-memory/memory.db`.
159
+ - Nama project: `MEMORY_PROJECT`, kalau kosong basename dari working directory proses.
160
+
161
+ Contoh Claude Desktop:
162
+
163
+ ```json
164
+ {
165
+ "mcpServers": {
166
+ "beans-memory": {
167
+ "command": "/path/absolut/ke/bun",
168
+ "args": ["/path/absolut/ke/beans-memory/src/mcp.ts"],
169
+ "env": { "MEMORY_DB": "/Users/kamu/.local/share/beans-memory/memory.db" }
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ## CLI dan skill (opsional)
176
+
177
+ Store yang sama bisa dipakai tanpa registrasi tool:
178
+
179
+ ```bash
180
+ bun src/cli.ts search "query" --limit 5
181
+ bun src/cli.ts get 12 13
182
+ bun src/cli.ts note --title "Judul" --type decision --body "Apa yang berubah dan kenapa"
183
+ bun src/cli.ts note --title "Judul" --stdin <<'EOF'
184
+ Isi multi-baris.
185
+ EOF
186
+ bun src/cli.ts recent --limit 5
187
+ bun src/cli.ts stats
188
+ bun src/cli.ts projects
189
+ ```
190
+
191
+ Flag: `--limit`, `--type`, `--files a,b`, `--concepts x,y`, `--json`, `--db <path>`, `--project <name>`.
192
+
193
+ Pasang launcher ke PATH:
194
+
195
+ ```bash
196
+ printf '#!/bin/sh\nexec /ABSOLUTE/PATH/TO/bun /ABSOLUTE/PATH/TO/beans-memory/src/cli.ts "$@"\n' \
197
+ > ~/.local/bin/beans-memory
198
+ chmod +x ~/.local/bin/beans-memory
199
+ ```
200
+
201
+ Skill di `skills/beans-memory/SKILL.md` mengajari agent kapan harus menjalankan perintah itu. Copy ke `~/.claude/skills/beans-memory/SKILL.md`; OpenCode dan Claude Code sama-sama membaca folder tersebut.
202
+
203
+ Kalau ingin skill sebagai satu-satunya jalur, set `MEMORY_TOOLS=off` sebelum OpenCode dijalankan. Hook plugin tetap menangkap prompt dan menyuntik konteks; empat tool plugin tidak didaftarkan.
204
+
205
+ ## Agent lain
206
+
207
+ Server MCP bisa dipakai klien apa pun yang mendukung stdio MCP. Semua agent di mesin yang sama berbagi satu database, jadi catatan dari Claude Code terlihat di Codex, Gemini CLI, dan OpenCode.
208
+
209
+ File siap pakai ada di `examples/`. Ganti `/ABSOLUTE/PATH/TO/` dengan path sebenarnya.
210
+
211
+ ### Claude Code
212
+
213
+ ```bash
214
+ claude mcp add --scope user --transport stdio beans_memory -- \
215
+ /ABSOLUTE/PATH/TO/bun /ABSOLUTE/PATH/TO/beans-memory/src/mcp.ts
216
+ ```
217
+
218
+ Atau copy `examples/claude-code.mcp.json` ke `.mcp.json` di root project untuk server ber-scope project yang bisa dipakai satu tim.
219
+
220
+ Nama tool diberi prefix: `mcp__beans_memory__memory_search`.
221
+
222
+ ### Codex
223
+
224
+ Gabungkan `examples/codex.config.toml` ke `~/.codex/config.toml`. Untuk scope project, pakai `.codex/config.toml` di dalam project yang sudah dipercaya.
225
+
226
+ ### Gemini CLI
227
+
228
+ ```bash
229
+ gemini mcp add -s user beans-memory \
230
+ /ABSOLUTE/PATH/TO/bun /ABSOLUTE/PATH/TO/beans-memory/src/mcp.ts
231
+ ```
232
+
233
+ Atau gabungkan `examples/gemini.settings.json` ke `~/.gemini/settings.json`.
234
+
235
+ Pertahankan tanda hubung di nama server (`beans-memory`). Gemini menyusun nama tool sebagai `mcp_<server>_<tool>` dan parser policy-nya memecah pada underscore pertama, jadi underscore di nama server merusak aturan wildcard.
236
+
237
+ ### Beri tahu agent cara memakainya
238
+
239
+ Config hanya membuka tool. Tambahkan `examples/memory-instructions.md` ke file instruksi agent: `CLAUDE.md`, `AGENTS.md`, atau `GEMINI.md`.
240
+
241
+ ## Data
242
+
243
+ Lokasi default:
244
+
245
+ ```
246
+ ~/.local/share/beans-memory/memory.db
247
+ ```
248
+
249
+ Ubah dengan `MEMORY_DB=/path/ke/memory.db`. Semua project memakai satu file; kolom `project` yang memisahkan. Nama project diambil dari basename working directory, jadi `~/work/api` menjadi project `api`.
250
+
251
+ Backup, dengan OpenCode tertutup:
252
+
253
+ ```bash
254
+ cp ~/.local/share/beans-memory/memory.db ~/backup-memory.db
255
+ ```
256
+
257
+ Atau saat database hidup:
258
+
259
+ ```bash
260
+ sqlite3 ~/.local/share/beans-memory/memory.db ".backup '/path/ke/copy.db'"
261
+ ```
262
+
263
+ Reset: hentikan OpenCode, hapus file, jalankan lagi. Skema dibuat ulang dalam keadaan kosong.
264
+
265
+ Timestamp disimpan dalam UTC dan ditampilkan dalam waktu lokal.
266
+
267
+ ## Import dari claude-mem (opsional)
268
+
269
+ Kalau punya `~/.claude-mem/claude-mem.db` lama:
270
+
271
+ ```bash
272
+ cd /path/ke/beans-memory
273
+
274
+ # observasi; baris bertipe discovery dilewati secara default
275
+ bun src/import-claude-mem-db.ts --dry-run
276
+ bun src/import-claude-mem-db.ts
277
+
278
+ # ringkasan sesi dan prompt historis
279
+ bun src/import-claude-mem-extras.ts --dry-run
280
+ bun src/import-claude-mem-extras.ts
281
+ ```
282
+
283
+ Flag: `--source`, `--db`, `--project`, `--include-discovery`, `--dry-run`.
284
+
285
+ Untuk memindahkan database dari versi lama project ini:
286
+
287
+ ```bash
288
+ bun src/migrate-legacy-db.ts --from /lama/memory.db
289
+ ```
290
+
291
+ ## Keamanan
292
+
293
+ - Data tetap di mesin ini. Tidak ada panggilan jaringan, tidak ada telemetri.
294
+ - Catatan disimpan apa adanya. Tidak ada redaksi rahasia pada catatan. Jangan simpan token, password, atau isi `.env` ke dalam catatan.
295
+ - Prompt yang ditangkap otomatis diredaksi untuk pola rahasia umum: API key OpenAI/GitHub/AWS/Google, webhook Slack/Discord, dan pola `password=` / `token:`. Redaksi ini tidak lengkap, jadi tetap jangan menempelkan rahasia ke chat.
296
+ - Database bisa dibaca proses apa pun yang berjalan sebagai user kamu. Perlakukan seperti file catatan, bukan vault.
297
+ - Laporkan kerentanan lewat [pelaporan privat GitHub](https://github.com/firasmpratama/beans-memory/security/advisories/new), bukan issue publik. Lihat [SECURITY.md](.github/SECURITY.md) untuk isi laporan.
298
+
299
+ ## Troubleshooting
300
+
301
+ - `memory_stats` tidak muncul setelah restart: cek path `ENTRY` di loader dan jalankan pengecekan `bun -e` di atas. OpenCode mencatat error loader di `~/.local/share/opencode/log/opencode.log`.
302
+ - Plugin diam saja: loader menangkap error import, biasanya karena kode ada di disk yang tidak ter-mount. Mount lalu restart.
303
+ - `Cannot use import statement outside a module`: buat `~/.config/opencode/plugins/package.json` berisi `{"type":"module"}`.
304
+ - `database is locked`: ada proses lain yang menulis. Tutup agent lain atau tunggu; database memakai WAL dengan busy timeout 5 detik.
305
+ - Permission denied pada database: file `0600` dan folder `0700` memang disengaja. Jalankan sebagai user yang membuatnya.
306
+
307
+ ## Keterbatasan
308
+
309
+ - Pencarian hanya kata kunci, tanpa embedding.
310
+ - Tidak ada ringkasan otomatis. Catatan hanya ada kalau agent menulisnya.
311
+ - Injeksi konteks hanya index singkat (8 judul), bukan isi lengkap.
312
+ - Identitas project adalah basename working directory. Dua repo berbeda dengan nama folder sama akan berbagi catatan, kecuali kamu set `MEMORY_PROJECT`.
313
+ - Satu pengguna, satu mesin. Tanpa sinkronisasi.
314
+ - SQLite diakses oleh proses plugin dan proses MCP. Mode WAL plus busy timeout 5 detik menangani itu; penulisan konkuren berat bukan target desain.
315
+
316
+ ## Development
317
+
318
+ Install dependency dev sekali, lalu pakai script:
319
+
320
+ ```bash
321
+ bun install
322
+ bun test
323
+ bun run typecheck
324
+ bun run test:coverage
325
+ ```
326
+
327
+ ## Struktur
328
+
329
+ ```
330
+ src/db.ts skema, FTS5, migrasi
331
+ src/repo.ts query: sesi, prompt, observasi, pencarian
332
+ src/plugin.ts plugin OpenCode: hook dan tool
333
+ src/mcp.ts server MCP stdio
334
+ src/cli.ts CLI untuk pemakaian lewat skill
335
+ src/time.ts format UTC ke waktu lokal
336
+ src/redact.ts redaksi rahasia untuk prompt yang ditangkap
337
+ src/rehash.ts migrasi hash sekali jalan
338
+ src/redact-prompts.ts redaksi baris prompt lama
339
+ src/import-claude-mem-db.ts import observasi dari claude-mem
340
+ src/import-claude-mem-extras.ts import ringkasan dan prompt
341
+ src/migrate-legacy-db.ts salin database beans-memory versi lama
342
+ skills/beans-memory/ skill agent untuk CLI
343
+ test/ bun test: repo, edge, time, MCP, CLI, redaksi
344
+ ```
345
+
346
+ ## Uninstall
347
+
348
+ 1. Hapus `~/.config/opencode/plugins/memory/`.
349
+ 2. Hapus entri `beans_memory` dari `opencode.json` kalau pernah ditambahkan.
350
+ 3. Hapus `~/.local/share/beans-memory/` kalau catatan tidak ingin disimpan.
351
+
352
+ ## Lisensi
353
+
354
+ MIT. Lihat [LICENSE](LICENSE).