@bd7pil/opencode-deep-memory 0.3.6 → 0.4.1
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/README.md +81 -24
- package/dist/index.js +583 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,16 +37,16 @@ OpenCode auto-installs on startup. Memory appears at `.deep-memory/` in your pro
|
|
|
37
37
|
│ repo map (code symbols) │
|
|
38
38
|
└─────────────────────────────┘
|
|
39
39
|
▲
|
|
40
|
-
┌──────────────┐ ┌──────────────┐ │
|
|
41
|
-
│ chat.message │ │ chat.params │ │ │messages.
|
|
42
|
-
│ keyword→notes│ │ agent→budget │ │ │ strip
|
|
43
|
-
│ "记住"/"rem" │ │ main 800t │ │ │
|
|
44
|
-
│ │ │ oracle 400t │ │ │
|
|
45
|
-
└──────────────┘ └──────────────┘ │ │
|
|
46
|
-
│
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
┌──────────────┐ ┌──────────────┐ │ ┌───────────────────────────┐
|
|
41
|
+
│ chat.message │ │ chat.params │ │ │ messages.transform │
|
|
42
|
+
│ keyword→notes│ │ agent→budget │ │ │ ① Layer 1: strip reason. │
|
|
43
|
+
│ "记住"/"rem" │ │ main 800t │ │ │ ② Layer 2: deep compress │
|
|
44
|
+
│ │ │ oracle 400t │ │ │ dedup / error purge / │
|
|
45
|
+
└──────────────┘ └──────────────┘ │ │ tool compress / JSON / │
|
|
46
|
+
│ │ message prune / CCR │
|
|
47
|
+
┌──────────────┘ └───────────────────────────┘
|
|
48
|
+
│
|
|
49
|
+
┌────────────────────┴────────────────────────┐
|
|
50
50
|
│ event │
|
|
51
51
|
│ session.created → resume + dream schedule │
|
|
52
52
|
│ session.idle → enrichment + notify │
|
|
@@ -56,23 +56,51 @@ OpenCode auto-installs on startup. Memory appears at `.deep-memory/` in your pro
|
|
|
56
56
|
|
|
57
57
|
## Context compression
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
with sentinels so message structure stays intact and prompt caching is preserved.
|
|
59
|
+
Two compression layers run automatically, no LLM calls required.
|
|
60
|
+
|
|
61
|
+
### Layer 1: Deterministic stripping
|
|
62
|
+
|
|
63
|
+
Always active, strips disposable content from old messages:
|
|
65
64
|
|
|
66
65
|
| What gets stripped | How | Why safe |
|
|
67
66
|
|--------------------|-----|----------|
|
|
68
|
-
| `reasoning_details` metadata | Delete the JSON blob
|
|
69
|
-
| Old reasoning text |
|
|
70
|
-
| System injections | Replace
|
|
71
|
-
| Tool errors >100 chars | Truncate
|
|
72
|
-
| Inline `<thinking>` tags | Regex strip
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
| `reasoning_details` metadata | Delete the JSON blob | Billing metadata, never reaches model |
|
|
68
|
+
| Old reasoning text | Replace with `[cleared]` | Conclusions are in assistant text |
|
|
69
|
+
| System injections | Replace with `[stripped]` | `<system-reminder>` stale after one turn |
|
|
70
|
+
| Tool errors >100 chars | Truncate | An old error only needs "it failed" |
|
|
71
|
+
| Inline `<thinking>` tags | Regex strip | Process, not product |
|
|
72
|
+
|
|
73
|
+
### Layer 2: Deep compression (pressure-triggered)
|
|
74
|
+
|
|
75
|
+
Activates when context pressure exceeds thresholds. Inspired by
|
|
76
|
+
[DCP](https://github.com/Opencode-DCP/opencode-dynamic-context-pruning),
|
|
77
|
+
[Headroom](https://github.com/chopratejas/headroom), and
|
|
78
|
+
[Edgee](https://github.com/edgee-ai/edgee).
|
|
79
|
+
|
|
80
|
+
| Pressure | Threshold | Actions |
|
|
81
|
+
|----------|-----------|---------|
|
|
82
|
+
| **always** | every turn | tool dedup + error purge + tool output compress + JSON crush (all reversible via CCR) |
|
|
83
|
+
| **medium** | ≥ 30% context | + old message text truncation (lossy, extracts key info) |
|
|
84
|
+
| **high** | ≥ 50% context | + nudge (alerts model to save important findings)
|
|
85
|
+
|
|
86
|
+
What gets compressed at medium+:
|
|
87
|
+
|
|
88
|
+
| Target | Strategy | Source |
|
|
89
|
+
|--------|----------|--------|
|
|
90
|
+
| Duplicate tool calls | Signature matching (`toolName::sortedParams`) | DCP |
|
|
91
|
+
| Old error inputs | Purge inputs after 4 turns | DCP |
|
|
92
|
+
| File reads | Keep first 50 + key lines + last 20 | Edgee |
|
|
93
|
+
| Command outputs | Keep errors + last 30 lines | Edgee |
|
|
94
|
+
| Search results | Keep top-20, group by file | Edgee |
|
|
95
|
+
| JSON arrays | Keep first 30% + last 15% + dedup middle | Headroom SmartCrusher |
|
|
96
|
+
| Old assistant text | Extract key info (headings, code, errors) | DCP |
|
|
97
|
+
|
|
98
|
+
All compressed content is **reversible** via CCR (Compress-Cache-Retrieve):
|
|
99
|
+
originals are cached with SHA-256 hash and 5-minute TTL.
|
|
100
|
+
Models can retrieve them via the `deep_expand` tool.
|
|
101
|
+
|
|
102
|
+
**Never touched**: user messages, recent 8 messages, protected tools
|
|
103
|
+
(question, edit, write, todowrite, memory_store/search/forget).
|
|
76
104
|
|
|
77
105
|
## Toast notifications
|
|
78
106
|
|
|
@@ -141,6 +169,17 @@ updated incrementally on writes.
|
|
|
141
169
|
└── sessions/<sid>/ per-session archive
|
|
142
170
|
```
|
|
143
171
|
|
|
172
|
+
## Tools
|
|
173
|
+
|
|
174
|
+
| Tool | Purpose |
|
|
175
|
+
|------|---------|
|
|
176
|
+
| `memory_search` | Search persistent memory across sessions (BM25 + CJK) |
|
|
177
|
+
| `memory_store` | Store decisions, constraints, gotchas, facts, notes |
|
|
178
|
+
| `memory_forget` | Remove memory entries matching a query |
|
|
179
|
+
| `memory_expand` | Decompress a sentinel reference to its original content |
|
|
180
|
+
| `deep_expand` | Retrieve original content compressed by CCR (use `[ccr:HASH]` marker) |
|
|
181
|
+
| `deep_expand` | Retrieve original content compressed by CCR (use `[ccr:HASH]` marker) |
|
|
182
|
+
|
|
144
183
|
## Commands
|
|
145
184
|
|
|
146
185
|
Copy `.opencode/command/*.md` to your project:
|
|
@@ -185,6 +224,18 @@ and JetBrains plugin.
|
|
|
185
224
|
|
|
186
225
|
**[Plandex][]** — an AI coding agent designed for large tasks and real world projects.
|
|
187
226
|
|
|
227
|
+
**[DCP][]** — Dynamic Context Pruning for OpenCode. Our tool deduplication, error purging,
|
|
228
|
+
and nudge system are inspired by DCP's architecture.
|
|
229
|
+
|
|
230
|
+
**[Headroom][]** — compress tool outputs, logs, files, RAG chunks for AI agents.
|
|
231
|
+
Our JSON array crush and CCR (Compress-Cache-Retrieve) are derived from Headroom's SmartCrusher.
|
|
232
|
+
|
|
233
|
+
**[Edgee][]** — agent gateway that compresses tokens before LLM providers.
|
|
234
|
+
Our per-tool compression strategies (read, bash, grep, glob) are inspired by Edgee's approach.
|
|
235
|
+
|
|
236
|
+
**[Contextomizer][]** — ultra-fast deterministic library for transforming bloated tool outputs.
|
|
237
|
+
Our content type detection pipeline is inspired by Contextomizer's approach.
|
|
238
|
+
|
|
188
239
|
[MiMo-Code]: https://github.com/XiaomiMiMo/MiMo-Code
|
|
189
240
|
[Magic Context]: https://github.com/cortexkit/magic-context
|
|
190
241
|
[Aider]: https://github.com/Aider-AI/aider
|
|
@@ -192,6 +243,10 @@ and JetBrains plugin.
|
|
|
192
243
|
[Continue]: https://github.com/continuedev/continue
|
|
193
244
|
[OpenHands]: https://github.com/All-Hands-AI/OpenHands
|
|
194
245
|
[Plandex]: https://github.com/plandex-ai/plandex
|
|
246
|
+
[DCP]: https://github.com/Opencode-DCP/opencode-dynamic-context-pruning
|
|
247
|
+
[Headroom]: https://github.com/chopratejas/headroom
|
|
248
|
+
[Edgee]: https://github.com/edgee-ai/edgee
|
|
249
|
+
[Contextomizer]: https://github.com/GandalFran/contextomizer
|
|
195
250
|
|
|
196
251
|
## Development
|
|
197
252
|
|
|
@@ -200,6 +255,8 @@ npm install
|
|
|
200
255
|
npm run verify # typecheck + test (363) + build + smoke (49)
|
|
201
256
|
```
|
|
202
257
|
|
|
258
|
+
Stats: 54 source files, 27 test files (363 tests), 10 compress modules, 49 smoke checks.
|
|
259
|
+
|
|
203
260
|
## CI/CD (npm Trusted Publishing)
|
|
204
261
|
|
|
205
262
|
Releases use npm OIDC Trusted Publishing — no token needed. To set up for a fork:
|