opencode-self-improvement 0.18.0 → 0.18.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/package.json +1 -1
- package/src/inject/epochs.ts +32 -18
- package/src/status/payload.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
package/src/inject/epochs.ts
CHANGED
|
@@ -45,7 +45,8 @@ export function createInjectionEpochs({
|
|
|
45
45
|
// Per-session frozen injection epochs: the whole memory section (digest +
|
|
46
46
|
// frontier + relevance) plus the store fingerprint it was rendered from.
|
|
47
47
|
// Recomputed on the first prompt of a tracked session, when injectable rows
|
|
48
|
-
// change,
|
|
48
|
+
// change, when a new prompt re-scores the block (#335), or after a
|
|
49
|
+
// compaction (see the prompt/context/compaction hooks).
|
|
49
50
|
// The RENDERED BYTES, not the fingerprint, decide whether the epoch moved
|
|
50
51
|
// (issue #162): a write that changes nothing the model is shown must not
|
|
51
52
|
// cost the next request a full re-prefill. And a pure addition the session
|
|
@@ -77,7 +78,7 @@ export function createInjectionEpochs({
|
|
|
77
78
|
*/
|
|
78
79
|
prompt: string;
|
|
79
80
|
at: string;
|
|
80
|
-
reason: "first" | "store_changed";
|
|
81
|
+
reason: "first" | "store_changed" | "prompt_reveal";
|
|
81
82
|
refs: MemoryRefs;
|
|
82
83
|
}
|
|
83
84
|
>();
|
|
@@ -201,17 +202,26 @@ export function createInjectionEpochs({
|
|
|
201
202
|
const mems = rows ?? (await injectableRows(sid));
|
|
202
203
|
const version = await storeVersion(mems);
|
|
203
204
|
const cached = epoch.get(sid);
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
|
|
205
|
+
const prompt = latestPrompt.get(sid) ?? "";
|
|
206
|
+
// Cheap pre-check: no injectable row moved AND the frozen bytes were
|
|
207
|
+
// already scored against THIS prompt. Skips re-scoring and the use-ledger
|
|
208
|
+
// write on ordinary turns and on every tool-loop request within a turn.
|
|
209
|
+
// A new prompt does re-score (#335, the epoch-freeze flaw): a block
|
|
210
|
+
// frozen at the first request carried the first topic's rows for the
|
|
211
|
+
// whole session and never picked up the rows a later prompt genuinely
|
|
212
|
+
// matches. Cache is still safe — the epoch only MOVES when the rendered
|
|
213
|
+
// bytes actually change, and a prompt change that keeps the same rows
|
|
214
|
+
// adopts silently below.
|
|
215
|
+
if (cached?.version === version && cached.prompt === prompt) return;
|
|
207
216
|
const built = await buildMemorySection(sid, mems);
|
|
208
|
-
// The store moved. A
|
|
209
|
-
// not relevant to this prompt, supersession
|
|
210
|
-
// never sees rendered identically — must
|
|
211
|
-
// cache. Adopt the new fingerprint
|
|
212
|
-
// nothing: an invalidation has
|
|
217
|
+
// The store and/or the prompt moved. A change that alters nothing
|
|
218
|
+
// RENDERED — a row that is not relevant to this prompt, supersession
|
|
219
|
+
// elsewhere, a scope the reader never sees rendered identically — must
|
|
220
|
+
// not cost this session a prompt cache. Adopt the new fingerprint and
|
|
221
|
+
// prompt, keep riding the same bytes, emit nothing: an invalidation has
|
|
222
|
+
// to mean bytes actually moved.
|
|
213
223
|
if (cached && cached.prefix === built.prefix) {
|
|
214
|
-
epoch.set(sid, { ...cached, version });
|
|
224
|
+
epoch.set(sid, { ...cached, version, prompt });
|
|
215
225
|
return;
|
|
216
226
|
}
|
|
217
227
|
// Riding bytes (#165): a pure addition this session wrote itself is
|
|
@@ -240,15 +250,18 @@ export function createInjectionEpochs({
|
|
|
240
250
|
}
|
|
241
251
|
}
|
|
242
252
|
}
|
|
243
|
-
const prompt = latestPrompt.get(sid) ?? "";
|
|
244
253
|
// Use ledger (#42): the rows that actually rode the block, credited with
|
|
245
254
|
// the terms the prompt and those rows shared (never the prompt itself).
|
|
246
255
|
// Only once the build is ADOPTED — a discarded rebuild must not credit
|
|
247
256
|
// rows that were already offered under the frozen epoch.
|
|
248
257
|
await noteHits(sid, built.rode, prompt);
|
|
249
258
|
const at = new Date().toISOString();
|
|
250
|
-
|
|
251
|
-
|
|
259
|
+
// Which input moved decides the reason: the store outranks the prompt, so
|
|
260
|
+
// a turn that did both is accounted as the (cache-critical) store change.
|
|
261
|
+
const reason: "first" | "store_changed" | "prompt_reveal" = cached
|
|
262
|
+
? cached.version !== version
|
|
263
|
+
? "store_changed"
|
|
264
|
+
: "prompt_reveal"
|
|
252
265
|
: "first";
|
|
253
266
|
epoch.set(sid, {
|
|
254
267
|
version,
|
|
@@ -275,12 +288,13 @@ export function createInjectionEpochs({
|
|
|
275
288
|
evidenceContext,
|
|
276
289
|
);
|
|
277
290
|
epochRecomputes++;
|
|
278
|
-
// Ledger:
|
|
279
|
-
// invalidation (the first epoch of a session busts nothing
|
|
280
|
-
//
|
|
291
|
+
// Ledger: any recompute of a live epoch that MOVED the bytes is an
|
|
292
|
+
// invalidation (the first epoch of a session busts nothing; a re-score
|
|
293
|
+
// that kept the bytes never reaches this line). The epoch request count
|
|
294
|
+
// restarts with the new block.
|
|
281
295
|
const st = statsFor(sid);
|
|
282
296
|
st.epochRequests = 0;
|
|
283
|
-
if (reason
|
|
297
|
+
if (reason !== "first") {
|
|
284
298
|
st.invalidations++;
|
|
285
299
|
st.lastInvalidation = { at, reason };
|
|
286
300
|
}
|
package/src/status/payload.ts
CHANGED
|
@@ -90,7 +90,7 @@ export interface StatusPayload {
|
|
|
90
90
|
/** ISO instant of the epoch recompute that produced this snapshot. */
|
|
91
91
|
at: string;
|
|
92
92
|
sessionID: string;
|
|
93
|
-
reason: "first" | "store_changed";
|
|
93
|
+
reason: "first" | "store_changed" | "prompt_reveal";
|
|
94
94
|
/** epoch recomputes since the server process started, ALL sessions. */
|
|
95
95
|
recomputes: number;
|
|
96
96
|
/** exact injected block ("" = abstained: no vocabulary overlap). */
|