Skip to content

Commit 06b2333

Browse files
authored
feat: add auto-dream consolidation support (#4)
1 parent 9c01a5f commit 06b2333

3 files changed

Lines changed: 382 additions & 79 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ OpenCode plugin that replicates Claude Code's persistent memory system. TypeScri
66

77
```
88
.
9-
├── bin/opencode-memory # Bash wrapper: shell hook install + post-session memory extraction via --fork
9+
├── bin/opencode-memory # Bash wrapper: shell hook install + post-session extraction + auto-dream consolidation
1010
├── src/
1111
│ ├── index.ts # Plugin entry: MemoryPlugin export, 5 tools + system prompt hook
1212
│ ├── memory.ts # CRUD: save/delete/list/search/read + MEMORY.md index management
@@ -94,4 +94,5 @@ git push origin main
9494
- `sanitizePath()` + `djb2Hash()` are exact copies from Claude Code source to guarantee byte-identical paths
9595
- The bash wrapper (`bin/opencode-memory`) uses `mktemp` timestamp comparison to detect if the main agent already wrote memories — if so, extraction is skipped
9696
- Shell hook is installed via `opencode-memory install`, which writes an `opencode()` function to `~/.zshrc` or `~/.bashrc` — shell functions take priority over PATH binaries
97+
- Auto-dream gate state is tracked with a per-project consolidation lock file under `~/.claude/opencode-memory/`
9798
- `package-lock.json` is gitignored (Bun runtime, not npm)

README.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Claude Code writes memory → OpenCode reads it. OpenCode writes memory → Clau
2424
Install + enable plugin, then keep using `opencode` as usual.
2525
- **Local-first, no migration**
2626
Memory stays as local Markdown files in the same directory Claude Code already uses.
27+
- **Auto-dream consolidation**
28+
Periodically runs a background memory consolidation pass (Claude-style auto-dream gating).
2729

2830
## 🚀 Quick Start
2931

@@ -36,7 +38,7 @@ opencode-memory install # one-time: installs shell hook
3638

3739
This installs:
3840
- The **plugin** — memory tools + system prompt injection
39-
- The `opencode-memory` **CLI** — wraps opencode with post-session memory extraction
41+
- The `opencode-memory` **CLI** — wraps opencode with automatic memory extraction + auto-dream consolidation
4042
- A **shell hook** — defines an `opencode()` function in your `.zshrc`/`.bashrc` that delegates to `opencode-memory`
4143

4244
### 2. Configure
@@ -54,7 +56,7 @@ This installs:
5456
opencode
5557
```
5658

57-
That’s it. Memory extraction runs in the background after each session.
59+
That’s it. Memory extraction runs in the background after each session, and auto-dream consolidation is checked with time/session gates.
5860

5961
To uninstall:
6062

@@ -92,17 +94,22 @@ graph LR
9294
B --> C[opencode-memory finds real binary]
9395
C --> D[Runs opencode normally]
9496
D --> E[You exit]
95-
E --> F[Fork session + extract memories]
96-
F --> G[Memories saved to ~/.claude/projects/]
97+
E --> F[Extract memories if needed]
98+
F --> G[Evaluate auto-dream gate]
99+
G --> H[Consolidate memories if gate passes]
100+
H --> I[Memories saved to ~/.claude/projects/]
97101
```
98102

99103
The shell hook defines an `opencode()` function that delegates to `opencode-memory`:
100104

101105
1. Shell function intercepts `opencode` command (higher priority than PATH)
102106
2. `opencode-memory` finds the real `opencode` binary in PATH
103107
3. Runs it with all your arguments
104-
4. After you exit, forks the session with a memory extraction prompt
105-
5. Extraction runs **in the background** — you're never blocked
108+
4. After you exit, it checks whether the session already wrote memory files
109+
5. If needed, it forks the session with a memory extraction prompt
110+
6. It evaluates the auto-dream gate (default: at least 24h since last consolidation and 5 touched sessions)
111+
7. If the gate passes, it runs a background consolidation pass to merge/prune memories
112+
8. Maintenance runs **in the background** unless `OPENCODE_MEMORY_FOREGROUND=1`
106113

107114
### Compatibility details
108115

@@ -137,22 +144,35 @@ File-based memory is transparent, local-first, easy to inspect/diff/back up, and
137144

138145
Yes. Set `OPENCODE_MEMORY_EXTRACT=0`.
139146

147+
### Can I disable auto-dream?
148+
149+
Yes. Set `OPENCODE_MEMORY_AUTODREAM=0`. You can also tune gates with:
150+
- `OPENCODE_MEMORY_AUTODREAM_MIN_HOURS`
151+
- `OPENCODE_MEMORY_AUTODREAM_MIN_SESSIONS`
152+
140153
## 🔧 Configuration
141154

142155
### Environment variables
143156

144-
- `OPENCODE_MEMORY_EXTRACT` (default `1`): set `0` to disable auto-extraction
145-
- `OPENCODE_MEMORY_FOREGROUND` (default `0`): set `1` to run extraction in foreground
157+
- `OPENCODE_MEMORY_EXTRACT` (default `1`): set `0` to disable automatic memory extraction
158+
- `OPENCODE_MEMORY_FOREGROUND` (default `0`): set `1` to run maintenance in foreground
146159
- `OPENCODE_MEMORY_MODEL`: override model used for extraction
147160
- `OPENCODE_MEMORY_AGENT`: override agent used for extraction
161+
- `OPENCODE_MEMORY_AUTODREAM` (default `1`): set `0` to disable auto-dream consolidation
162+
- `OPENCODE_MEMORY_AUTODREAM_MIN_HOURS` (default `24`): min hours between consolidation runs
163+
- `OPENCODE_MEMORY_AUTODREAM_MIN_SESSIONS` (default `5`): min touched sessions since last consolidation
164+
- `OPENCODE_MEMORY_AUTODREAM_MODEL`: override model used for auto-dream
165+
- `OPENCODE_MEMORY_AUTODREAM_AGENT`: override agent used for auto-dream
148166

149167
### Logs
150168

151-
Extraction logs are written to `$TMPDIR/opencode-memory-logs/extract-*.log`.
169+
Logs are written to `$TMPDIR/opencode-memory-logs/`:
170+
- `extract-*.log`: automatic memory extraction
171+
- `dream-*.log`: auto-dream consolidation
152172

153173
### Concurrency safety
154174

155-
A file lock prevents multiple extractions from running simultaneously on the same project. Stale locks are cleaned up automatically.
175+
Lock files prevent concurrent extraction/consolidation runs per project root. Stale locks are cleaned up automatically.
156176

157177
## 📝 Memory format
158178

0 commit comments

Comments
 (0)