myagentmemory 0.4.3

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 Jay Zeng
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.md ADDED
@@ -0,0 +1,231 @@
1
+ # agent-memory
2
+
3
+ Persistent memory for coding agents — [Claude Code](https://claude.ai/code) and [OpenAI Codex](https://github.com/openai/codex). Semantic search powered by [qmd](https://github.com/tobi/qmd).
4
+
5
+ Thanks to https://github.com/skyfallsin/pi-mem for inspiration.
6
+
7
+ Long-term facts, daily logs, and a scratchpad checklist stored as plain markdown files. Optional qmd integration adds keyword, semantic, and hybrid search across all memory files, plus automatic selective injection of relevant past memories into every turn.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ # Install the CLI globally
13
+ npm install -g myagentmemory
14
+
15
+ # Or build from source
16
+ bun run build:cli
17
+ # => produces dist/agent-memory
18
+
19
+ # Initialize memory directory
20
+ agent-memory init
21
+
22
+ # Install skill files for Claude Code and Codex
23
+ bash scripts/install-skills.sh
24
+ pwsh -File scripts/install-skills.ps1
25
+ ```
26
+
27
+ This installs:
28
+ - `~/.claude/skills/agent-memory/SKILL.md` — Claude Code skill
29
+ - `~/.codex/skills/agent-memory/SKILL.md` — Codex skill
30
+ - `%USERPROFILE%\.claude\skills\agent-memory\SKILL.md` — Claude Code skill (Windows)
31
+ - `%USERPROFILE%\.codex\skills\agent-memory\SKILL.md` — Codex skill (Windows)
32
+
33
+ ### Optional: Enable search with qmd
34
+
35
+ When qmd is installed, the collection is automatically set up via `agent-memory init`.
36
+
37
+ Note: `memory_search` **semantic**/**deep** modes require vector embeddings. If you see a warning like "need embeddings", run `qmd embed` once and retry.
38
+
39
+ If you prefer manual setup:
40
+
41
+ ```bash
42
+ qmd collection add ~/.agent-memory --name agent-memory
43
+ qmd embed
44
+ ```
45
+
46
+ Without qmd, all core tools (write/read/scratchpad) work normally. Only `memory_search` and selective injection require qmd.
47
+
48
+ ## Architecture
49
+
50
+ ```
51
+ ┌──────────────┐
52
+ │ src/core.ts │ ← all logic (paths, truncation, scratchpad,
53
+ │ │ context builder, qmd, tool functions)
54
+ └──────┬───────┘
55
+
56
+ ┌────┴─────────────────┐
57
+ ▼ ▼
58
+ ┌──────────┐ ┌──────────────┐
59
+ │ src/ │ │ skills/ │
60
+ │ cli.ts │ │ ├─ claude-code/SKILL.md
61
+ │ │ │ └─ codex/SKILL.md
62
+ └──────────┘ └──────────────┘
63
+ CLI binary instruction files
64
+ `agent-memory` that invoke CLI
65
+ ```
66
+
67
+ The memory directory defaults to `~/.agent-memory/`. Override with `AGENT_MEMORY_DIR` env var or `--dir` flag.
68
+
69
+ ## CLI Commands
70
+
71
+ | Command | Purpose |
72
+ |---------|---------|
73
+ | `agent-memory context [--no-search]` | Build & print context injection string to stdout |
74
+ | `agent-memory write --target <long_term\|daily> --content <text> [--mode append\|overwrite]` | Write to memory files |
75
+ | `agent-memory read --target <long_term\|scratchpad\|daily\|list> [--date YYYY-MM-DD]` | Read memory files |
76
+ | `agent-memory scratchpad <add\|done\|undo\|clear_done\|list> [--text <text>]` | Manage checklist |
77
+ | `agent-memory search --query <text> [--mode keyword\|semantic\|deep] [--limit N]` | Search via qmd |
78
+ | `agent-memory init` | Create dirs, detect qmd, setup collection |
79
+ | `agent-memory status` | Show config, qmd status, file counts |
80
+
81
+ Global flags: `--dir <path>` (override directory), `--json` (machine output)
82
+
83
+ ### memory_search modes
84
+
85
+ | Mode | Speed | Method | Best for |
86
+ |------|-------|--------|----------|
87
+ | `keyword` | ~30ms | BM25 | Specific terms, dates, names, #tags, [[links]] |
88
+ | `semantic` | ~2s | Vector search | Related concepts, different wording |
89
+ | `deep` | ~10s | Hybrid + reranking | When other modes miss |
90
+
91
+ If the first search doesn't find what you need, try rephrasing or switching modes.
92
+
93
+ ## File layout
94
+
95
+ ```
96
+ ~/.agent-memory/
97
+ MEMORY.md # Curated long-term memory
98
+ SCRATCHPAD.md # Checklist of things to fix/remember
99
+ daily/
100
+ 2026-02-15.md # Daily append-only log
101
+ 2026-02-14.md
102
+ ...
103
+ ```
104
+
105
+ ## How it works
106
+
107
+ ### Context injection
108
+
109
+ Before every agent turn, the following are injected into the system prompt (in priority order):
110
+
111
+ 1. **Open scratchpad items** (up to 2K chars)
112
+ 2. **Today's daily log** (up to 3K chars, tail)
113
+ 3. **Relevant memories via qmd search** (up to 2.5K chars) — searches using the user's current prompt to surface related past context
114
+ 4. **MEMORY.md** (up to 4K chars, middle-truncated)
115
+ 5. **Yesterday's daily log** (up to 3K chars, tail — lowest priority, trimmed first)
116
+
117
+ Total injection is capped at 16K chars. When qmd is unavailable, step 3 is skipped and the rest works as before.
118
+
119
+ For Claude Code, context is injected via the `!`agent-memory context`` syntax in the SKILL.md. For Codex, the agent runs `agent-memory context` at session start.
120
+
121
+ ### Selective injection
122
+
123
+ When qmd is available, the system automatically searches memory using the user's prompt on demand (CLI). The top 3 keyword results are injected alongside the standard context.
124
+
125
+ The search has a 3-second timeout and fails silently. If qmd is down or the query returns nothing, injection falls back to the standard behavior.
126
+
127
+ ### Tags and links
128
+
129
+ Use `#tags` and `[[wiki-links]]` in memory content to improve searchability:
130
+
131
+ ```markdown
132
+ #decision [[database-choice]] Chose PostgreSQL for all backend services.
133
+ #preference [[editor]] User prefers Neovim with LazyVim config.
134
+ #lesson [[api-versioning]] URL prefix versioning (/v1/) avoids CDN cache issues.
135
+ ```
136
+
137
+ These are content conventions, not enforced metadata. qmd's full-text indexing makes them searchable for free.
138
+
139
+ ### Other behavior
140
+
141
+ - **Persistence**: Memory files are plain markdown on disk — readable, editable, and git-friendly.
142
+ - **Tool response previews**: Write/scratchpad tools return size-capped previews instead of full file contents.
143
+ - **qmd auto-setup**: Via `agent-memory init`, the collection and path contexts are created automatically.
144
+ - **qmd re-indexing**: After every write, a debounced `qmd update` runs in the background (fire-and-forget, non-blocking) unless disabled via `AGENT_MEMORY_QMD_UPDATE`.
145
+ - **qmd embeddings**: Semantic/deep search needs vector embeddings. If you see "need embeddings" warnings, run `qmd embed` once and retry.
146
+ - **Graceful degradation**: If qmd is not installed, core tools work fine. `memory_search` returns install instructions.
147
+
148
+ ### Configuration
149
+
150
+ | Variable | Values | Default | Description |
151
+ |----------|--------|---------|-------------|
152
+ | `AGENT_MEMORY_DIR` | path | `~/.agent-memory` | Memory directory |
153
+ | `AGENT_MEMORY_QMD_UPDATE` | `background`, `manual`, `off` | `background` | Controls automatic `qmd update` after writes |
154
+
155
+ ## Running tests
156
+
157
+ ```bash
158
+ # Unit tests (no LLM, no qmd — fast, deterministic)
159
+ bun test test/unit.test.ts
160
+ bun test test/cli.test.ts
161
+ ```
162
+
163
+ ### Test levels
164
+
165
+ | Level | File | Requirements | What it tests |
166
+ |-------|------|-------------|---------------|
167
+ | Unit | `test/unit.test.ts` | None | Utilities, scratchpad parsing, context builder, qmd helpers, tool functions |
168
+ | CLI | `test/cli.test.ts` | None | CLI commands, subprocess integration |
169
+
170
+ ## Development
171
+
172
+ ```bash
173
+ # Build the CLI binary
174
+ bun run build:cli
175
+
176
+ # Test CLI
177
+ agent-memory write --target long_term --content "test" && agent-memory read --target long_term
178
+
179
+ # Install skills
180
+ bash scripts/install-skills.sh
181
+ pwsh -File scripts/install-skills.ps1
182
+ ```
183
+
184
+ ## Publishing (maintainers)
185
+
186
+ ```bash
187
+ # Confirm package name is available
188
+ npm view agent-memory
189
+
190
+ # Bump version (choose patch/minor/major)
191
+ npm version patch
192
+
193
+ # Publish to npm (public)
194
+ npm publish --access public
195
+ ```
196
+
197
+ ## Changelog
198
+
199
+ ### 0.5.0
200
+
201
+ - **Removed pi extension**: Removed `index.ts` and all pi-specific code (`@mariozechner/pi-ai`, `@mariozechner/pi-coding-agent`, `@sinclair/typebox` peer dependencies).
202
+ - **Standalone tool functions**: Extracted `memoryWrite()`, `memoryRead()`, `scratchpadAction()`, `memorySearch()` into `src/core.ts` as standalone functions usable without any framework.
203
+ - **Renamed package**: `pi-memory` → `agent-memory`.
204
+ - **Renamed env var**: `PI_MEMORY_QMD_UPDATE` → `AGENT_MEMORY_QMD_UPDATE` (old name still works as fallback).
205
+ - **Default memory directory**: Now always `~/.agent-memory/`.
206
+ - **Removed pi-specific tests**: Deleted `test/e2e.ts`, `test/eval-recall.ts`, `test/unit.ts`.
207
+
208
+ ### 0.4.0
209
+
210
+ - **Multi-platform support**: Memory system now works with Claude Code and OpenAI Codex via CLI + skills, in addition to pi.
211
+ - **Extracted shared core**: `src/core.ts` contains platform-agnostic logic (paths, truncation, scratchpad, context builder, qmd) with zero pi peer dependencies.
212
+ - **CLI binary**: `agent-memory` CLI with subcommands: `context`, `write`, `read`, `scratchpad`, `search`, `init`, `status`.
213
+ - **Skill files**: `skills/claude-code/SKILL.md` and `skills/codex/SKILL.md` for installation into respective platforms.
214
+ - **Configurable memory directory**: `AGENT_MEMORY_DIR` env var or `--dir` flag (default: `~/.agent-memory/`).
215
+ - **CLI tests**: `test/cli.test.ts` with unit and subprocess tests.
216
+
217
+ ### 0.2.0
218
+
219
+ - **Selective injection**: Before each turn, the user's prompt is searched against memory via qmd. Top results are injected into the system prompt alongside standard context, surfacing relevant past decisions without explicit tool calls.
220
+ - **qmd auto-setup**: The extension automatically creates the collection and path contexts on session start when qmd is available. No manual `qmd collection add` needed.
221
+ - **Tags and links**: `memory_write` and context injection now encourage `#tags` and `[[wiki-links]]` as searchable content conventions.
222
+ - **Context priority reordering**: Injection order is now scratchpad > today > search results > MEMORY.md > yesterday.
223
+ - **Unit tests**: Added deterministic tests (no LLM/qmd needed).
224
+ - **Recall eval**: Added recall effectiveness evaluation.
225
+
226
+ ### 0.1.0
227
+
228
+ - Initial release: `memory_write`, `memory_read`, `scratchpad`, `memory_search` tools.
229
+ - Context injection of MEMORY.md, scratchpad, and today/yesterday daily logs.
230
+ - qmd integration for keyword, semantic, and hybrid search.
231
+ - Debounced background `qmd update` after writes.
Binary file
package/dist/cli.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * agent-memory CLI
4
+ *
5
+ * Subcommands:
6
+ * context — Build & print context injection string to stdout
7
+ * write — Write to memory files
8
+ * read — Read memory files
9
+ * scratchpad — Manage checklist
10
+ * search — Search via qmd
11
+ * init — Create dirs, detect qmd, setup collection
12
+ * status — Show config, qmd status, file counts
13
+ *
14
+ * Global flags:
15
+ * --dir <path> Override memory directory
16
+ * --json Machine-readable JSON output
17
+ */
18
+ export {};