opencode-self-improvement 0.9.0 → 0.9.2
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/index.ts +40 -24
- package/src/inject.ts +20 -3
- package/src/status.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
compactionAnchor,
|
|
37
37
|
contextualPull,
|
|
38
38
|
formatMemory,
|
|
39
|
+
injectedRows,
|
|
39
40
|
selectRelevant,
|
|
40
41
|
storeVersion,
|
|
41
42
|
systemDigest,
|
|
@@ -741,9 +742,10 @@ const impl = {
|
|
|
741
742
|
if (cached?.version === version) return;
|
|
742
743
|
const sel = await selectRelevant(latestPrompt.get(sid) ?? "", 5, mems); // widen candidate pool
|
|
743
744
|
const block = sel.block ? capToBudget(sel.block, budget) : "";
|
|
744
|
-
// Refs the injected rows assert (paths + commands), the join key
|
|
745
|
-
// attribution. Derived
|
|
746
|
-
|
|
745
|
+
// Refs the ACTUALLY-injected rows assert (paths + commands), the join key
|
|
746
|
+
// for attribution. Derived from the budget-surviving rows, not the wider
|
|
747
|
+
// candidate pool — crediting paths the model never saw would overclaim.
|
|
748
|
+
const refs = deriveMemoryRefs(injectedRows(block, sel.selected));
|
|
747
749
|
const at = new Date().toISOString();
|
|
748
750
|
const reason: "first" | "store_changed" = cached ? "store_changed" : "first";
|
|
749
751
|
epoch.set(sid, { version, block, at, reason, refs });
|
|
@@ -877,15 +879,16 @@ const impl = {
|
|
|
877
879
|
}),
|
|
878
880
|
);
|
|
879
881
|
|
|
880
|
-
// ---- measured prompt-cache health (
|
|
881
|
-
// Zero-model by design:
|
|
882
|
-
//
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// the
|
|
887
|
-
//
|
|
888
|
-
//
|
|
882
|
+
// ---- measured prompt-cache health (usage events) -----------------------
|
|
883
|
+
// Zero-model by design: usage arrives on `session.usage.updated` (v2 hosts)
|
|
884
|
+
// or `message.updated` assistant info (older hosts), carrying tokens
|
|
885
|
+
// {input, output, reasoning, cache.read/write}; the session-wide
|
|
886
|
+
// read/(read+input+write) share is the honest receipt behind the
|
|
887
|
+
// byte-stability proxy. Streaming updates arrive repeatedly — overwriting
|
|
888
|
+
// with the latest is correct because the final update carries the complete
|
|
889
|
+
// usage. Flushes the per-session status file so the TUI badge refreshes
|
|
890
|
+
// once per turn instead of per step. Degrades to "not measured" when the
|
|
891
|
+
// host exposes no event stream.
|
|
889
892
|
const measuredController = new AbortController();
|
|
890
893
|
if (ctx.event?.subscribe) {
|
|
891
894
|
const eventApi = ctx.event;
|
|
@@ -912,20 +915,33 @@ const impl = {
|
|
|
912
915
|
else if (typeof sid === "string") void guarded("session bind (api)", () => bindSessionFromApi(sid));
|
|
913
916
|
continue;
|
|
914
917
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
918
|
+
// Token usage: v2 hosts (>=2.0.x) emit `session.usage.updated` with
|
|
919
|
+
// data.{sessionID, tokens}; older hosts carried the same TokenUsage
|
|
920
|
+
// on message.updated's assistant info. Accept both so `measured`
|
|
921
|
+
// populates regardless of host version.
|
|
922
|
+
let usid: unknown;
|
|
923
|
+
let ut: { input?: number; cache?: { read?: number; write?: number } } | undefined;
|
|
924
|
+
if (ev?.type === "session.usage.updated") {
|
|
925
|
+
usid = ev.data?.sessionID;
|
|
926
|
+
ut = ev.data?.tokens;
|
|
927
|
+
} else if (ev?.type === "message.updated") {
|
|
928
|
+
const info = ev.properties?.info ?? ev.info ?? ev.data?.info;
|
|
929
|
+
if (info && info.role === "assistant") {
|
|
930
|
+
usid = info.sessionID;
|
|
931
|
+
ut = info.tokens;
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (typeof usid !== "string" || !ut) continue;
|
|
937
|
+
sessions.touch(usid);
|
|
938
|
+
measuredTurns.set(usid, {
|
|
923
939
|
at: new Date().toISOString(),
|
|
924
|
-
input: Number(
|
|
925
|
-
read: Number(
|
|
926
|
-
write: Number(
|
|
940
|
+
input: Number(ut.input) || 0,
|
|
941
|
+
read: Number(ut.cache?.read) || 0,
|
|
942
|
+
write: Number(ut.cache?.write) || 0,
|
|
927
943
|
});
|
|
928
|
-
await guarded("status flush (measured)", () => flushStatus(
|
|
944
|
+
await guarded("status flush (measured)", () => flushStatus(usid));
|
|
929
945
|
}
|
|
930
946
|
} catch {
|
|
931
947
|
// the subscription ended (abort or host error); nothing to do
|
package/src/inject.ts
CHANGED
|
@@ -104,15 +104,22 @@ const LONG_QUERY_TOKENS = 3;
|
|
|
104
104
|
// piles of common ones — the same idf form the bench's BM25 row uses).
|
|
105
105
|
// Exported for bench/recall-quality.ts — the benchmark measures the shipped
|
|
106
106
|
// matcher.
|
|
107
|
+
//
|
|
108
|
+
// Superseded rows are dropped HERE, not only by the callers. Every model-facing
|
|
109
|
+
// sink already passes isActive() rows, but a scorer that can be handed a raw
|
|
110
|
+
// loadAll() result must not be the one place a retired memory leaks back into
|
|
111
|
+
// an injected block (#43 item 1: forbidden hits). The drop also keeps a
|
|
112
|
+
// retired row from diluting the document frequencies the ranking depends on.
|
|
107
113
|
export function scoreMemories(term: string, mems: Memory[], limit: number): Memory[] {
|
|
114
|
+
const live = mems.filter((m) => !m.superseded_by);
|
|
108
115
|
const query = new Set(words(term).filter((t) => !QUERY_STOPWORDS.has(t)));
|
|
109
116
|
if (!query.size) return [];
|
|
110
117
|
const needShared = query.size >= LONG_QUERY_TOKENS ? 2 : 1;
|
|
111
|
-
const hays =
|
|
118
|
+
const hays = live.map((m) => new Set(words(`${m.scope} ${m.type} ${m.content}`)));
|
|
112
119
|
const df = new Map<string, number>();
|
|
113
120
|
for (const h of hays) for (const t of h) df.set(t, (df.get(t) ?? 0) + 1);
|
|
114
|
-
const n =
|
|
115
|
-
return
|
|
121
|
+
const n = live.length || 1;
|
|
122
|
+
return live
|
|
116
123
|
.map((m, i) => {
|
|
117
124
|
let shared = 0;
|
|
118
125
|
let score = 0;
|
|
@@ -264,6 +271,16 @@ export async function relevantKnowledge(message: string, limit = 3, rows?: Memor
|
|
|
264
271
|
return (await selectRelevant(message, limit, rows)).block;
|
|
265
272
|
}
|
|
266
273
|
|
|
274
|
+
// The candidate rows that ACTUALLY survived capToBudget into `block`, in order.
|
|
275
|
+
// capToBudget drops whole lines, so attribution must key off these — not the
|
|
276
|
+
// pre-budget candidates — or it would credit the model with paths and commands
|
|
277
|
+
// it was never shown. capToBudget keeps whole lines verbatim, so a candidate is
|
|
278
|
+
// present iff its rendered line is a substring of the block.
|
|
279
|
+
export function injectedRows(block: string, candidates: Memory[]): Memory[] {
|
|
280
|
+
if (!block) return [];
|
|
281
|
+
return candidates.filter((m) => block.includes(formatMemory(m)));
|
|
282
|
+
}
|
|
283
|
+
|
|
267
284
|
// Deterministic fingerprint of the rows that can affect injection. Hash the
|
|
268
285
|
// exact rendered row plus its full id, in load order: content edits, blocklist
|
|
269
286
|
// changes and supersession all invalidate an epoch, while evidence, hidden
|
package/src/status.ts
CHANGED
|
@@ -55,10 +55,10 @@ export function emptyStats(): SessionStats {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Measured prompt-cache usage from the last
|
|
59
|
-
* (message.updated
|
|
60
|
-
* SESSION-WIDE prompt cache — the
|
|
61
|
-
* never billed as our block's own rate.
|
|
58
|
+
* Measured prompt-cache usage from the last usage event — `session.usage.updated`
|
|
59
|
+
* (v2 hosts) or `message.updated` assistant info (older hosts) — carrying tokens
|
|
60
|
+
* {input, cache.read, cache.write}. This is the SESSION-WIDE prompt cache — the
|
|
61
|
+
* honest receipt for "are we busting cache", never billed as our block's own rate.
|
|
62
62
|
*/
|
|
63
63
|
export interface Measured {
|
|
64
64
|
at: string;
|