@vasilvestre/opencode-dream-memory 0.3.0 → 0.4.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/.opencode/plugins/dream-memory.js +15 -4
- package/README.md +11 -2
- package/dream/agents/dream-deep.md +8 -1
- package/dream/dream +12 -3
- package/dream/dream-corpus +14 -7
- package/package.json +1 -1
|
@@ -75,9 +75,20 @@ export default {
|
|
|
75
75
|
const location = ctx.location ?? {};
|
|
76
76
|
const directory =
|
|
77
77
|
location.project?.canonical || location.project?.directory || location.directory;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
const register = async (name) => {
|
|
79
|
+
await ctx.session.hook(name, (event) => {
|
|
80
|
+
try {
|
|
81
|
+
const block = memoryBlock(directory);
|
|
82
|
+
// Both events carry a system array of text parts. Compaction reads the
|
|
83
|
+
// same memory the agent loop does, so the summary keeps it. We append
|
|
84
|
+
// and never set event.result: the model still writes the summary.
|
|
85
|
+
if (block) event.system.push({ type: 'text', text: block });
|
|
86
|
+
} catch {
|
|
87
|
+
// A throwing hook breaks the request it runs on. Inject nothing.
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
await register('context');
|
|
92
|
+
await register('compaction');
|
|
82
93
|
},
|
|
83
94
|
};
|
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ Two pieces that give an OpenCode agent memory across sessions:
|
|
|
10
10
|
summarizes the conversation and the instructions file goes with it. A plugin
|
|
11
11
|
hook runs on every agent-loop request, so the same block is re-sent each turn.
|
|
12
12
|
|
|
13
|
+
The plugin also registers the `compaction` hook, so the memory reaches the
|
|
14
|
+
request that writes the summary. The model still writes the summary; the plugin
|
|
15
|
+
only adds context. Without that hook, a long session could compact away the
|
|
16
|
+
memory it just read.
|
|
17
|
+
|
|
13
18
|
## Install
|
|
14
19
|
|
|
15
20
|
Requirements: `opencode` and `jq` on `PATH`, `curl` or `wget` to download, and
|
|
@@ -168,6 +173,9 @@ and that flag beats the agent's pinned model. Override the file path with
|
|
|
168
173
|
- A run takes a lock on `$DREAM_HOME/.dreams/run.lock`. A second run exits at
|
|
169
174
|
once instead of interleaving writes, so the 04:30 timer cannot collide with a
|
|
170
175
|
manual run.
|
|
176
|
+
- The corpus goes back to each project's last successful run, and never further
|
|
177
|
+
than 24 hours. After missed nights, run `DREAM_SINCE_HOURS=96 dream` to widen
|
|
178
|
+
that window, for example to 96 hours.
|
|
171
179
|
- The files are read on each request, never cached, so a nightly rewrite shows
|
|
172
180
|
up in the next turn at the cost of two small reads.
|
|
173
181
|
|
|
@@ -194,10 +202,11 @@ the same thing as the two subcommands.
|
|
|
194
202
|
npm test
|
|
195
203
|
```
|
|
196
204
|
|
|
197
|
-
The plugin checks:
|
|
205
|
+
The plugin checks: both hooks register, missing files inject nothing, shared
|
|
198
206
|
memory alone injects one block, the current project's file is appended after it
|
|
199
207
|
while another project's stays out, an oversized file is truncated without the
|
|
200
|
-
whole block growing,
|
|
208
|
+
whole block growing, titles are dropped, the `compaction` hook injects the same
|
|
209
|
+
block as the `context` hook, and it never sets `result`. Then the corpus checks: the dream's
|
|
201
210
|
own sessions stay out, a labelled secret is redacted, a torn session export is
|
|
202
211
|
skipped instead of fatal, and a git data directory gets a preimage commit before
|
|
203
212
|
the deep pass.
|
|
@@ -57,7 +57,14 @@ fits. Deleting a stale fact is part of this pass, not an exception to it.
|
|
|
57
57
|
- Add or update the entry in place. Never duplicate one.
|
|
58
58
|
- Remove entries this candidate makes false. A wrong memory is worse than a
|
|
59
59
|
missing one.
|
|
60
|
-
- Keep each file curated:
|
|
60
|
+
- Keep each file curated: one fact per line, at most ~120 characters, no
|
|
61
|
+
chronology. Merge lines that state one fact.
|
|
62
|
+
- Memory costs context on every request. When a file in the project already
|
|
63
|
+
documents a fact, promote a one-line pointer to that file instead of the
|
|
64
|
+
fact itself, for example: `Seedbox rename gotchas: see new-seedbox-runbook.md §8`.
|
|
65
|
+
A fact that is one `grep` away is not worth a memory line.
|
|
66
|
+
- When a file would exceed its budget, delete the weakest facts to make room.
|
|
67
|
+
Never shorten a line below readability to make it fit.
|
|
61
68
|
- Write a fact about a machine, a repository or a setup into that project's
|
|
62
69
|
file, not into shared memory.
|
|
63
70
|
- If shared memory holds a fact about one project, move it into that project's
|
package/dream/dream
CHANGED
|
@@ -143,7 +143,16 @@ fi
|
|
|
143
143
|
echo "dream: deep"
|
|
144
144
|
if run_agent dream-deep \
|
|
145
145
|
"Promote today's candidates and write the diary entry for $day." "deep $day"; then
|
|
146
|
-
# Advance
|
|
147
|
-
# retried on the same slice instead of losing it.
|
|
148
|
-
|
|
146
|
+
# Advance each project's cursor only after both passes succeeded, so a failed
|
|
147
|
+
# run is retried on the same slice instead of losing it. A project without a
|
|
148
|
+
# git repo is skipped by dream-corpus, so it keeps a zero cursor and its full
|
|
149
|
+
# history is backfilled the first time it becomes a git repo.
|
|
150
|
+
now_ms=$(date +%s%3N)
|
|
151
|
+
mkdir -p "$root/.dreams/last-run"
|
|
152
|
+
while IFS= read -r project; do
|
|
153
|
+
case $project in ''|\#*) continue ;; esac
|
|
154
|
+
[ -d "$project/.git" ] || continue
|
|
155
|
+
name=$(basename "$project")
|
|
156
|
+
printf '%s\n' "$now_ms" > "$root/.dreams/last-run/$name"
|
|
157
|
+
done < "$list"
|
|
149
158
|
fi
|
package/dream/dream-corpus
CHANGED
|
@@ -10,14 +10,16 @@ root="${DREAM_HOME:-$HOME/dreams}"
|
|
|
10
10
|
list="${DREAM_PROJECTS:-$HOME/.config/opencode/dream-projects}"
|
|
11
11
|
day=$(date +%F)
|
|
12
12
|
now=$(( $(date +%s) * 1000 ))
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
hours=${DREAM_SINCE_HOURS:-24}
|
|
14
|
+
case $hours in ''|*[!0-9]*) hours=24 ;; esac
|
|
15
|
+
# Incremental, per project: each project ingests sessions since its own last
|
|
16
|
+
# successful run, never earlier than 24h ago. DREAM_SINCE_HOURS raises that
|
|
17
|
+
# floor, to catch up after missed runs. A project with no cursor is new,
|
|
18
|
+
# so it ingests its full 24h history instead of being skipped by another
|
|
19
|
+
# project's cursor. Without this, adding a project after a run silently drops
|
|
20
|
+
# its past sessions.
|
|
15
21
|
state="$root/.dreams/last-run"
|
|
16
|
-
|
|
17
|
-
[ -r "$state" ] && last=$(cat "$state" 2>/dev/null || true)
|
|
18
|
-
case $last in ''|*[!0-9]*) last=0 ;; esac
|
|
19
|
-
cutoff=$(( now - 86400000 ))
|
|
20
|
-
[ "$last" -gt "$cutoff" ] && cutoff=$last
|
|
22
|
+
[ -d "$state" ] || { rm -f "$state"; mkdir -p "$state"; }
|
|
21
23
|
command -v opencode >/dev/null || { echo "dream-corpus: opencode not on PATH" >&2; exit 1; }
|
|
22
24
|
|
|
23
25
|
out="$root/.dreams/session-corpus/$day.txt"
|
|
@@ -46,6 +48,11 @@ while IFS= read -r project; do
|
|
|
46
48
|
case $project in ''|\#*) continue ;; esac
|
|
47
49
|
[ -d "$project/.git" ] || { echo "dream-corpus: skip $project (not a git repo)" >&2; continue; }
|
|
48
50
|
name=$(basename "$project")
|
|
51
|
+
last=0
|
|
52
|
+
[ -r "$state/$name" ] && last=$(cat "$state/$name" 2>/dev/null || true)
|
|
53
|
+
case $last in ''|*[!0-9]*) last=0 ;; esac
|
|
54
|
+
cutoff=$(( now - hours * 3600000 ))
|
|
55
|
+
[ "$last" -gt "$cutoff" ] && cutoff=$last
|
|
49
56
|
cd "$project"
|
|
50
57
|
|
|
51
58
|
before=$(wc -l < "$out")
|
package/package.json
CHANGED