@lmaksym/agent-mem 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/context.md +24 -0
- package/.claude/skills/agent-mem/SKILL.md +66 -0
- package/.claude/skills/agent-mem/references/branching-merging.md +34 -0
- package/.claude/skills/agent-mem/references/coexistence.md +19 -0
- package/.claude/skills/agent-mem/references/collaboration.md +33 -0
- package/.claude/skills/agent-mem/references/reflection-compaction.md +104 -0
- package/.claude/skills/agent-mem/references/sub-agent-patterns.md +60 -0
- package/LICENSE +21 -0
- package/README.md +235 -0
- package/bin/agent-context.js +95 -0
- package/bin/parse-args.js +85 -0
- package/package.json +58 -0
- package/src/commands/branch.js +57 -0
- package/src/commands/branch.test.js +91 -0
- package/src/commands/branches.js +34 -0
- package/src/commands/commit.js +55 -0
- package/src/commands/compact.js +307 -0
- package/src/commands/compact.test.js +110 -0
- package/src/commands/config.js +47 -0
- package/src/commands/core.test.js +166 -0
- package/src/commands/diff.js +157 -0
- package/src/commands/diff.test.js +64 -0
- package/src/commands/forget.js +77 -0
- package/src/commands/forget.test.js +68 -0
- package/src/commands/help.js +99 -0
- package/src/commands/import.js +83 -0
- package/src/commands/init.js +269 -0
- package/src/commands/init.test.js +80 -0
- package/src/commands/lesson.js +95 -0
- package/src/commands/lesson.test.js +93 -0
- package/src/commands/merge.js +105 -0
- package/src/commands/pin.js +34 -0
- package/src/commands/pull.js +80 -0
- package/src/commands/push.js +80 -0
- package/src/commands/read.js +62 -0
- package/src/commands/reflect.js +328 -0
- package/src/commands/remember.js +95 -0
- package/src/commands/resolve.js +230 -0
- package/src/commands/resolve.test.js +167 -0
- package/src/commands/search.js +70 -0
- package/src/commands/share.js +65 -0
- package/src/commands/snapshot.js +106 -0
- package/src/commands/status.js +37 -0
- package/src/commands/switch.js +31 -0
- package/src/commands/sync.js +328 -0
- package/src/commands/track.js +61 -0
- package/src/commands/unpin.js +28 -0
- package/src/commands/write.js +58 -0
- package/src/core/auto-commit.js +22 -0
- package/src/core/config.js +93 -0
- package/src/core/context-root.js +28 -0
- package/src/core/fs.js +137 -0
- package/src/core/git.js +182 -0
- package/src/core/importers.js +210 -0
- package/src/core/lock.js +62 -0
- package/src/core/reflect-defrag.js +287 -0
- package/src/core/reflect-gather.js +360 -0
- package/src/core/reflect-parse.js +168 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Manage Project Context
|
|
2
|
+
|
|
3
|
+
Use agent-mem CLI to manage your project's persistent memory.
|
|
4
|
+
|
|
5
|
+
## Arguments
|
|
6
|
+
$ARGUMENTS: `snapshot | commit <msg> | remember --<category> <text> | lesson "<problem> -> <resolution>" | branch <name> | search <query> | compact [--dry-run|--hard] | resolve [--dry-run] | diff <branch> | forget <path>`
|
|
7
|
+
|
|
8
|
+
## Instructions
|
|
9
|
+
|
|
10
|
+
1. If no arguments or "snapshot": run `agent-mem snapshot` and present the context tree
|
|
11
|
+
2. If "commit": run `agent-mem commit <message>`
|
|
12
|
+
3. If "remember": run `agent-mem remember --<category> "<text>"`
|
|
13
|
+
3b. If "lesson": run `agent-mem lesson "<problem> -> <resolution>"` or with flags `--problem`, `--resolution`, `--tags`
|
|
14
|
+
4. If "branch": run `agent-mem branch <name> "<purpose>"`
|
|
15
|
+
5. If "search": run `agent-mem search "<query>"`
|
|
16
|
+
6. If "compact": run `agent-mem compact [flags]` — archive stale context, keep pins + recent
|
|
17
|
+
7. If "resolve": run `agent-mem resolve [flags]` — auto-resolve merge conflicts in .context/
|
|
18
|
+
8. If "diff": run `agent-mem diff <branch>` — compare branch with main
|
|
19
|
+
9. If "forget": run `agent-mem forget <path>` — remove memory file (archived first)
|
|
20
|
+
10. For any other command, pass directly: `agent-mem <args>`
|
|
21
|
+
|
|
22
|
+
If `.context/` doesn't exist, run `agent-mem init` first.
|
|
23
|
+
|
|
24
|
+
Always show the command output to the user.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agent-mem
|
|
3
|
+
description: Persistent, git-backed memory across sessions. Use at session start (snapshot), after decisions/fixes/mistakes (remember/lesson), to checkpoint work (commit), before risky exploration (branch), or to check prior context (search).
|
|
4
|
+
argument-hint: "[command] [args] — e.g., snapshot, remember --decision <text>, lesson \"problem -> fix\", commit <msg>"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# agent-mem
|
|
8
|
+
|
|
9
|
+
Git-backed memory for coding sessions via the `amem` CLI.
|
|
10
|
+
|
|
11
|
+
If `$ARGUMENTS` is provided, run `agent-mem $ARGUMENTS` and show output.
|
|
12
|
+
|
|
13
|
+
## When to Use (triggers)
|
|
14
|
+
|
|
15
|
+
**Starting a session →** `amem snapshot`
|
|
16
|
+
Load context tree, pinned files, memory summary. Run `amem init` if no `.context/` exists.
|
|
17
|
+
|
|
18
|
+
**You chose between alternatives →** `amem remember --decision "chose X because Y"`
|
|
19
|
+
|
|
20
|
+
**You noticed a repeatable approach →** `amem remember --pattern "always do X before Y"`
|
|
21
|
+
|
|
22
|
+
**You did something wrong →** `amem remember --mistake "never do X"`
|
|
23
|
+
|
|
24
|
+
**You solved a problem after investigation →** `amem lesson "problem -> how you fixed it"`
|
|
25
|
+
Use the `->` shorthand, or `--problem`/`--resolution`/`--tags` flags for richer entries.
|
|
26
|
+
|
|
27
|
+
**You completed meaningful work →** `amem commit "what you did"`
|
|
28
|
+
|
|
29
|
+
**You're about to try something that might not work →** `amem branch name "purpose"`
|
|
30
|
+
Merge back with findings: `amem merge name "outcome"`. Even failed branches are valuable.
|
|
31
|
+
|
|
32
|
+
**You're about to make a decision that might have prior context →** `amem search "query"`
|
|
33
|
+
|
|
34
|
+
**Session is long, you've learned a lot →** `amem reflect`
|
|
35
|
+
Synthesizes patterns, lessons, stale entries from recent activity.
|
|
36
|
+
|
|
37
|
+
## Quick Reference
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
amem snapshot # start of session
|
|
41
|
+
amem remember --decision "text" # decision / --pattern / --mistake / --note
|
|
42
|
+
amem lesson "problem -> resolution" # problem you solved
|
|
43
|
+
amem commit "message" # checkpoint progress
|
|
44
|
+
amem branch name "purpose" # explore uncertain idea
|
|
45
|
+
amem merge name "outcome" # merge back findings
|
|
46
|
+
amem search "query" # check prior context
|
|
47
|
+
amem read <path> # read specific file
|
|
48
|
+
amem write <path> --content "text" # write specific file
|
|
49
|
+
amem pin <path> / amem unpin <path> # manage pinned files (system/)
|
|
50
|
+
amem reflect # gather reflection input
|
|
51
|
+
amem compact [--dry-run|--hard] # archive stale context
|
|
52
|
+
amem status / amem config / amem help # info commands
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Remember vs Lesson
|
|
56
|
+
|
|
57
|
+
**Remember** = one-liner facts: decisions, patterns, mistakes, notes.
|
|
58
|
+
**Lesson** = problem + resolution pair. If you investigated and fixed something, it's a lesson.
|
|
59
|
+
|
|
60
|
+
## References
|
|
61
|
+
|
|
62
|
+
- [Reflection & compaction](references/reflection-compaction.md)
|
|
63
|
+
- [Branching & merging](references/branching-merging.md)
|
|
64
|
+
- [Sub-agent patterns](references/sub-agent-patterns.md)
|
|
65
|
+
- [Collaboration & sharing](references/collaboration.md)
|
|
66
|
+
- [Coexistence with CLAUDE.md](references/coexistence.md)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Branching, Merging & Cleanup
|
|
2
|
+
|
|
3
|
+
## Diff — compare before merging
|
|
4
|
+
|
|
5
|
+
Compare a branch's context against main before merging:
|
|
6
|
+
```bash
|
|
7
|
+
amem diff try-qdrant # summary view
|
|
8
|
+
amem diff try-qdrant --verbose # show actual line changes
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Resolve — auto-resolve merge conflicts
|
|
12
|
+
|
|
13
|
+
After git operations that create merge conflicts in `.context/`:
|
|
14
|
+
```bash
|
|
15
|
+
amem resolve --dry-run # Preview resolution strategy per file
|
|
16
|
+
amem resolve # Auto-resolve all conflicts
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Resolution strategies (automatic):**
|
|
20
|
+
- `memory/` files — append-only merge (keep both sides, deduplicate exact matches)
|
|
21
|
+
- `config.yaml` — prefer-ours (keep local settings)
|
|
22
|
+
- Other files — keep-both (concatenate with separator)
|
|
23
|
+
|
|
24
|
+
## Forget — remove obsolete memory
|
|
25
|
+
|
|
26
|
+
Remove obsolete memory files (archived first for safety):
|
|
27
|
+
```bash
|
|
28
|
+
amem forget memory/old-notes.md
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Safety rules:**
|
|
32
|
+
- Cannot forget pinned `system/` files — run `amem unpin` first
|
|
33
|
+
- Cannot forget `config.yaml`
|
|
34
|
+
- Always archives to `archive/forgotten-YYYY-MM-DD/` before deleting
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Coexistence with CLAUDE.md
|
|
2
|
+
|
|
3
|
+
If the project has a CLAUDE.md:
|
|
4
|
+
- `agent-mem init --from-claude` imports it into `memory/imported-claude-md.md`
|
|
5
|
+
- `.context/system/` becomes the living version of project conventions
|
|
6
|
+
- CLAUDE.md can reference `.context/` for dynamic context
|
|
7
|
+
- Both can coexist — CLAUDE.md for agent instructions, `.context/` for versioned memory
|
|
8
|
+
|
|
9
|
+
## Syncing to IDE rule files
|
|
10
|
+
|
|
11
|
+
Export `.context/` content to IDE rule files:
|
|
12
|
+
```bash
|
|
13
|
+
amem sync --claude # CLAUDE.md
|
|
14
|
+
amem sync --codex # AGENTS.md
|
|
15
|
+
amem sync --cursor # .cursorrules
|
|
16
|
+
amem sync --windsurf # .windsurfrules
|
|
17
|
+
amem sync --gemini # GEMINI.md
|
|
18
|
+
amem sync --all # all of the above
|
|
19
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Collaboration & Sharing
|
|
2
|
+
|
|
3
|
+
## Track — git tracking control
|
|
4
|
+
|
|
5
|
+
Toggle whether `.context/` is tracked in the project's git repo:
|
|
6
|
+
```bash
|
|
7
|
+
amem track # show current tracking status
|
|
8
|
+
amem track --enable # add .context/ to project git
|
|
9
|
+
amem track --disable # remove .context/ from project git
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Push / Pull — remote sync
|
|
13
|
+
|
|
14
|
+
Sync `.context/` to a separate remote (independent of project git):
|
|
15
|
+
```bash
|
|
16
|
+
amem push # push to configured remote
|
|
17
|
+
amem push --remote <url> # push to specific remote
|
|
18
|
+
amem pull # pull from configured remote
|
|
19
|
+
amem pull --remote <url> # clone/pull from specific remote
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Share / Import — portable snapshots
|
|
23
|
+
|
|
24
|
+
Generate a portable snapshot of your context for sharing with teammates or other agents:
|
|
25
|
+
```bash
|
|
26
|
+
amem share # generate snapshot file
|
|
27
|
+
amem share --output path.json # custom output path
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Import a shared snapshot:
|
|
31
|
+
```bash
|
|
32
|
+
amem import <file> # import shared snapshot into .context/
|
|
33
|
+
```
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Reflection & Compaction
|
|
2
|
+
|
|
3
|
+
## When to Reflect
|
|
4
|
+
|
|
5
|
+
Reflection synthesizes what you've learned across multiple commits into structured insights.
|
|
6
|
+
|
|
7
|
+
**Always reflect:**
|
|
8
|
+
- After completing a multi-step feature (5+ commits)
|
|
9
|
+
- Before ending a long session
|
|
10
|
+
- When you notice you keep re-discovering the same things
|
|
11
|
+
|
|
12
|
+
**Consider reflecting:**
|
|
13
|
+
- After merging an exploration branch
|
|
14
|
+
- After a debugging session that taught you something
|
|
15
|
+
- When switching between very different problem domains
|
|
16
|
+
|
|
17
|
+
### The Reflect Cycle
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Step 1: Gather context (CLI reads git history + memory state)
|
|
21
|
+
amem reflect
|
|
22
|
+
|
|
23
|
+
# Step 2: Think about:
|
|
24
|
+
# - What patterns emerged?
|
|
25
|
+
# - Do any memories contradict each other?
|
|
26
|
+
# - What knowledge is missing? What's outdated?
|
|
27
|
+
|
|
28
|
+
# Step 3: Save your reflection with structured output
|
|
29
|
+
amem reflect save --content "## Patterns Identified
|
|
30
|
+
- WebSocket reconnection needs state validation
|
|
31
|
+
|
|
32
|
+
## Decisions Validated
|
|
33
|
+
- PKCE for mobile OAuth confirmed as correct
|
|
34
|
+
|
|
35
|
+
## Contradictions Found
|
|
36
|
+
- Earlier said REST-only, now using WebSocket for streaming. Resolution: REST for CRUD, WS for real-time.
|
|
37
|
+
|
|
38
|
+
## Stale Entries
|
|
39
|
+
- memory/patterns.md: Use REST for all API endpoints
|
|
40
|
+
|
|
41
|
+
## Gaps Filled
|
|
42
|
+
- type: pattern
|
|
43
|
+
text: Always validate WebSocket readiness state, not just connection status
|
|
44
|
+
- type: decision
|
|
45
|
+
text: REST for CRUD operations, WebSocket for streaming
|
|
46
|
+
|
|
47
|
+
## Themes
|
|
48
|
+
- Real-time architecture is the dominant concern
|
|
49
|
+
|
|
50
|
+
## Summary
|
|
51
|
+
Focused on real-time reliability. Key insight: connection != readiness."
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Reflection Output Format
|
|
55
|
+
|
|
56
|
+
Include these sections (omit empty ones):
|
|
57
|
+
- `## Patterns Identified` — recurring approaches that work
|
|
58
|
+
- `## Lessons Learned` — problems solved: use `type: lesson`, `text:`, `problem:`, `resolution:` fields
|
|
59
|
+
- `## Decisions Validated` — earlier decisions confirmed by recent work
|
|
60
|
+
- `## Contradictions Found` — memory entries that conflict (include resolution)
|
|
61
|
+
- `## Stale Entries` — entries to flag as outdated (format: `file: entry text`)
|
|
62
|
+
- `## Gaps Filled` — new entries to add (use `type:` and `text:` sub-fields)
|
|
63
|
+
- `## Themes` — overarching directions
|
|
64
|
+
- `## Summary` — 2-3 sentences
|
|
65
|
+
|
|
66
|
+
### Reflection History
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
amem reflect history # See past reflections + recurring themes
|
|
70
|
+
amem reflect history --last 3 # Last 3 only
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Memory Defrag
|
|
74
|
+
|
|
75
|
+
When memory files get large or stale:
|
|
76
|
+
```bash
|
|
77
|
+
amem reflect defrag --dry-run # Analyze memory health (read-only)
|
|
78
|
+
amem reflect defrag # Apply stale markers (non-destructive)
|
|
79
|
+
# Then clean up manually
|
|
80
|
+
amem write memory/patterns.md "<cleaned content>"
|
|
81
|
+
amem commit "defrag: consolidated patterns"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## When to Compact
|
|
85
|
+
|
|
86
|
+
Compact when your context is bloated and you want to continue with less noise.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
amem compact --dry-run # Preview what would be archived
|
|
90
|
+
amem compact # Default: archive stale entries, keep pins + last 7 days
|
|
91
|
+
amem compact --hard # Keep only pinned files, archive everything else
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Use compact when:**
|
|
95
|
+
- Context window is filling up mid-task
|
|
96
|
+
- You want lower noise without losing critical decisions
|
|
97
|
+
- Switching focus within the same session
|
|
98
|
+
|
|
99
|
+
**Compact always:**
|
|
100
|
+
- Auto-commits before running (safety net)
|
|
101
|
+
- Archives to `.context/archive/compact-YYYY-MM-DD/` (never deletes)
|
|
102
|
+
- Reports byte size before/after
|
|
103
|
+
|
|
104
|
+
**Compact vs Reflect:** Compact is a pruner (removes noise). Reflect is a synthesizer (extracts insights). Different tools, clean separation.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Sub-Agent Patterns
|
|
2
|
+
|
|
3
|
+
## Spawn Template
|
|
4
|
+
|
|
5
|
+
Embed amem calls as workflow steps (not a separate block). Agents skip separate instruction blocks but follow numbered steps.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
STEP 1: Run amem snapshot — read the output, this is your starting context.
|
|
9
|
+
STEP 2: [First item of actual work]. Then run: amem remember --note "<what you found>"
|
|
10
|
+
STEP 3: [Next item]. Then run: amem remember --note "<what you found>"
|
|
11
|
+
...continue pattern: do work → save finding...
|
|
12
|
+
STEP N (every 3 items): Run amem commit "checkpoint: items 1-3 done"
|
|
13
|
+
FINAL STEP: Write output file, then run: amem commit "done: <summary>"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Key principle:** Interleave amem into the task flow. Make `remember` the step right after each research item, not a separate section the agent can skip.
|
|
17
|
+
|
|
18
|
+
## Retry/Resume Template
|
|
19
|
+
|
|
20
|
+
For sub-agents retrying a timed-out task:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
STEP 1: Run amem snapshot — review what the previous run saved.
|
|
24
|
+
STEP 2: Run amem read memory/notes.md — these are completed items, skip them.
|
|
25
|
+
STEP 3: Continue from the first item NOT in notes.md.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Splitting Large Tasks
|
|
29
|
+
|
|
30
|
+
Never spawn one agent for 15+ sequential operations. Split instead:
|
|
31
|
+
|
|
32
|
+
**Bad:** 1 agent x 20 items x (search + fetch + analyze) = timeout
|
|
33
|
+
|
|
34
|
+
**Good:** 4 agents x 5 items each = parallel, each checkpoints independently
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Each sub-agent gets its own branch:
|
|
38
|
+
amem branch batch-1 "items 1-5"
|
|
39
|
+
amem branch batch-2 "items 6-10"
|
|
40
|
+
|
|
41
|
+
# After all complete, merge branches:
|
|
42
|
+
amem merge batch-1 "findings from items 1-5"
|
|
43
|
+
amem merge batch-2 "findings from items 6-10"
|
|
44
|
+
amem commit "consolidated all research"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Timeout Recommendations
|
|
48
|
+
|
|
49
|
+
| Task type | Recommended timeout |
|
|
50
|
+
|-----------|-------------------|
|
|
51
|
+
| Simple (1-3 tool calls) | 120-300s |
|
|
52
|
+
| Research (5-10 searches) | 600s |
|
|
53
|
+
| Deep research (10+ searches) | 900s |
|
|
54
|
+
| Code review | 600s |
|
|
55
|
+
| Browser automation | 300-600s |
|
|
56
|
+
|
|
57
|
+
## Model Selection for Sub-Agents
|
|
58
|
+
|
|
59
|
+
- **Sonnet/Haiku** for research tasks — faster, cheaper, less likely to timeout
|
|
60
|
+
- **Opus** for complex reasoning, code architecture decisions
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maksym Lypivskyi
|
|
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,235 @@
|
|
|
1
|
+
# agent-mem
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@lmaksym/agent-mem)
|
|
4
|
+
[](https://github.com/lmaksym/agent-context/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Persistent, git-backed memory for AI coding agents.
|
|
8
|
+
|
|
9
|
+
> **Alpha** — functional and evolving. Feedback welcome.
|
|
10
|
+
|
|
11
|
+
## The Problem
|
|
12
|
+
|
|
13
|
+
AI coding agents lose context between sessions. `CLAUDE.md` is manual. Memory files get stale. Every new session, you re-teach the agent your project conventions, past decisions, and what you already tried.
|
|
14
|
+
|
|
15
|
+
**agent-mem** gives agents a structured, versioned context filesystem they can read and write through bash. It works with Claude Code, Codex CLI, Cursor, Windsurf, Gemini CLI — any agent that can run shell commands.
|
|
16
|
+
|
|
17
|
+
On `init`, the skill is automatically installed to the three [Agent Skills](https://agentskills.io) directories (`.claude/skills/`, `.agents/skills/`, `.github/skills/`), covering Claude Code, Codex CLI, Copilot, Gemini CLI, and more. It also auto-syncs trigger-based instructions to detected IDE rule files (CLAUDE.md, GEMINI.md, AGENTS.md, `.cursor/rules/`, `.windsurfrules`).
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @lmaksym/agent-mem
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires Node.js 20+. Zero runtime dependencies.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
agent-mem init # Bootstrap from codebase
|
|
31
|
+
agent-mem snapshot # Agent's primary context view
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Example `snapshot` output
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
CONTEXT SNAPSHOT
|
|
38
|
+
Project: my-app | Branch: main | Commits: 12
|
|
39
|
+
Last commit: "refactored WebRTC signaling" (2h ago)
|
|
40
|
+
|
|
41
|
+
PINNED (system/) — always in agent context:
|
|
42
|
+
--- system/project.md ---
|
|
43
|
+
# my-app
|
|
44
|
+
Real-time AI interview platform using Gemini Live.
|
|
45
|
+
## Stack
|
|
46
|
+
Next.js 15, TypeScript, Gemini 2.5, WebRTC, GCP
|
|
47
|
+
|
|
48
|
+
--- system/conventions.md ---
|
|
49
|
+
# Conventions
|
|
50
|
+
- Domain-driven folder structure
|
|
51
|
+
- Server components by default
|
|
52
|
+
|
|
53
|
+
MEMORY (3 files):
|
|
54
|
+
decisions.md — "12 entries, last: Chose Payload CMS over Directus"
|
|
55
|
+
patterns.md — "8 patterns, last: Always check Grafana before fixing"
|
|
56
|
+
mistakes.md — "3 entries, last: Never skip code review"
|
|
57
|
+
|
|
58
|
+
BRANCHES (1):
|
|
59
|
+
try-qdrant — "evaluate vector search vs Pinecone" (3 commits)
|
|
60
|
+
|
|
61
|
+
CONFIG: auto_commit=false | reflection=manual
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Pinned files are loaded in full. Everything else is a summary — drill down with `agent-mem read <path>`.
|
|
65
|
+
|
|
66
|
+
## How Agents Use It
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# 1. Start session — understand current state
|
|
70
|
+
agent-mem snapshot
|
|
71
|
+
agent-mem read memory/decisions.md
|
|
72
|
+
|
|
73
|
+
# 2. Do work...
|
|
74
|
+
|
|
75
|
+
# 3. Record decisions, patterns, mistakes
|
|
76
|
+
agent-mem remember --decision "Chose PKCE over implicit grant for mobile OAuth"
|
|
77
|
+
agent-mem remember --pattern "Always validate WebSocket reconnection with heartbeat"
|
|
78
|
+
agent-mem remember --mistake "Don't use dynamic imports for server components"
|
|
79
|
+
|
|
80
|
+
# 4. Record lessons learned
|
|
81
|
+
agent-mem lesson "WebSocket reconnect -> validate readiness state, not just connection"
|
|
82
|
+
|
|
83
|
+
# 5. Checkpoint progress
|
|
84
|
+
agent-mem commit "implemented OAuth PKCE flow"
|
|
85
|
+
|
|
86
|
+
# 6. Explore something uncertain
|
|
87
|
+
agent-mem branch try-qdrant "evaluate Qdrant vs Pinecone"
|
|
88
|
+
# ... experiment ...
|
|
89
|
+
agent-mem merge try-qdrant "Qdrant wins — self-hosted, better filtering"
|
|
90
|
+
|
|
91
|
+
# 7. Next session — everything is still there
|
|
92
|
+
agent-mem snapshot
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Commands
|
|
96
|
+
|
|
97
|
+
### Core
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
agent-mem init [--from-claude] # Bootstrap .context/ + install skill + sync IDE rules
|
|
101
|
+
agent-mem snapshot # Context tree with pinned content
|
|
102
|
+
agent-mem read <path> # Read a specific context file
|
|
103
|
+
agent-mem write <path> --content "text" # Write a context file (also reads stdin)
|
|
104
|
+
agent-mem commit [message] # Git-backed checkpoint
|
|
105
|
+
agent-mem status # Quick status overview
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`--from-claude` imports your existing `CLAUDE.md` into `.context/memory/` so past conventions are preserved.
|
|
109
|
+
|
|
110
|
+
### Memory
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
agent-mem remember --decision "chose X because Y" # -> memory/decisions.md
|
|
114
|
+
agent-mem remember --pattern "always do X before Y" # -> memory/patterns.md
|
|
115
|
+
agent-mem remember --mistake "never do X" # -> memory/mistakes.md
|
|
116
|
+
agent-mem remember --note "general observation" # -> memory/notes.md
|
|
117
|
+
agent-mem lesson "API 429 -> implement backoff" # -> memory/lessons.md
|
|
118
|
+
agent-mem lesson "fix" --problem "OOM" --resolution "close DB conns" --tags "infra"
|
|
119
|
+
agent-mem search <query> # Grep across all context files
|
|
120
|
+
agent-mem pin <path> # Move to system/ (always in context)
|
|
121
|
+
agent-mem unpin <path> # Move out of system/
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Branches
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
agent-mem branch <name> [purpose] # Create exploration branch
|
|
128
|
+
agent-mem switch <name> # Switch active branch
|
|
129
|
+
agent-mem merge <name> [summary] # Merge findings back to main
|
|
130
|
+
agent-mem branches # List all branches
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Compaction & Maintenance
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
agent-mem compact # Archive stale entries, keep pins + recent
|
|
137
|
+
agent-mem compact --dry-run # Preview what would be archived
|
|
138
|
+
agent-mem compact --hard # Keep only pins, archive everything else
|
|
139
|
+
agent-mem forget <path> # Remove memory file (archived, never deleted)
|
|
140
|
+
agent-mem resolve # Auto-resolve .context/ merge conflicts
|
|
141
|
+
agent-mem resolve --dry-run # Preview resolution strategy
|
|
142
|
+
agent-mem diff <branch> # Compare branch context with main
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Reflection
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
agent-mem reflect # Gather reflection input
|
|
149
|
+
agent-mem reflect save --content "..." # Save structured reflection
|
|
150
|
+
agent-mem reflect history # Past reflections and themes
|
|
151
|
+
agent-mem reflect defrag # Analyze memory health
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Sync & Sharing
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
agent-mem sync # Export to IDE rule files (auto-detect)
|
|
158
|
+
agent-mem sync --claude # Export to CLAUDE.md
|
|
159
|
+
agent-mem sync --codex # Export to AGENTS.md
|
|
160
|
+
agent-mem sync --cursor # Export to .cursor/rules/
|
|
161
|
+
agent-mem sync --windsurf # Export to .windsurfrules
|
|
162
|
+
agent-mem sync --gemini # Export to GEMINI.md
|
|
163
|
+
agent-mem sync --all # Export to all formats
|
|
164
|
+
agent-mem track # Toggle .context/ in project git
|
|
165
|
+
agent-mem push # Push .context/ to remote
|
|
166
|
+
agent-mem pull # Pull .context/ from remote
|
|
167
|
+
agent-mem share # Generate portable snapshot
|
|
168
|
+
agent-mem import <file> # Import shared snapshot
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Config
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
agent-mem config # Show current config
|
|
175
|
+
agent-mem config set <key> <val> # Update config
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Directory Structure
|
|
179
|
+
|
|
180
|
+
`agent-mem init` creates a `.context/` directory in your project:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
.context/
|
|
184
|
+
├── main.md # Project roadmap and goals
|
|
185
|
+
├── config.yaml # Settings
|
|
186
|
+
├── system/ # Always loaded into agent context (pinned)
|
|
187
|
+
│ ├── project.md # Auto-detected: name, stack, structure
|
|
188
|
+
│ └── conventions.md # Coding conventions and style rules
|
|
189
|
+
├── memory/ # Learned context (tree visible, content on demand)
|
|
190
|
+
│ ├── decisions.md # Architectural decisions with rationale
|
|
191
|
+
│ ├── patterns.md # Learned best practices
|
|
192
|
+
│ ├── mistakes.md # Anti-patterns to avoid
|
|
193
|
+
│ └── lessons.md # Lessons learned (problem/resolution pairs)
|
|
194
|
+
├── branches/ # Exploration branches with purpose tracking
|
|
195
|
+
├── reflections/ # Reflection outputs and synthesis
|
|
196
|
+
└── archive/ # Archived context from compact/forget (never deleted)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Every change is git-versioned inside `.context/`. Human-readable markdown, diffable, shareable.
|
|
200
|
+
|
|
201
|
+
## Aliases
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
agent-mem snapshot
|
|
205
|
+
amem snapshot # short alias
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Design Principles
|
|
209
|
+
|
|
210
|
+
- **CLI-first** — bash commands, works in any IDE and agent
|
|
211
|
+
- **Agent-native output** — structured text optimized for LLMs
|
|
212
|
+
- **Zero config** — `init` and go
|
|
213
|
+
- **Git-backed** — every change versioned and diffable
|
|
214
|
+
- **Progressive disclosure** — tree shows structure, drill down for details
|
|
215
|
+
- **Zero dependencies** — Node.js built-ins only
|
|
216
|
+
|
|
217
|
+
## Roadmap
|
|
218
|
+
|
|
219
|
+
- **Multi-agent coordination** — git worktrees for concurrent agent sessions
|
|
220
|
+
- **Semantic search** — vector-based retrieval across context
|
|
221
|
+
- **Automated reflection** — triggered by commit thresholds
|
|
222
|
+
|
|
223
|
+
## Inspired By
|
|
224
|
+
|
|
225
|
+
- [GCC](https://arxiv.org/abs/2508.00031) — Git-inspired COMMIT/BRANCH/MERGE for context management
|
|
226
|
+
- [Letta Context Repos](https://www.letta.com/blog/context-repositories) — Git-backed memory filesystem
|
|
227
|
+
- [Anthropic Context Engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) — Progressive disclosure patterns
|
|
228
|
+
|
|
229
|
+
## Contributing
|
|
230
|
+
|
|
231
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
[MIT](LICENSE)
|