opencode-self-improvement 0.29.0 → 0.30.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/README.md +2 -2
- package/package.json +1 -1
- package/src/recall/dedupe.ts +44 -10
- package/src/recall/gate.ts +32 -16
- package/src/tools/recall.ts +7 -6
package/README.md
CHANGED
|
@@ -87,9 +87,9 @@ Zero configuration is the default. To tune, use the object form of the plugin en
|
|
|
87
87
|
| `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS` | Operator-only. When truthy, `memory_export`/`memory_import` accept paths anywhere on disk instead of confining themselves to the store. Off by default. See [Export and move between machines](#export-and-move-between-machines). |
|
|
88
88
|
| `OPENCODE_MEMORY_INJECT_BUDGET` | Fallback for `injectBudget`. |
|
|
89
89
|
| `OPENCODE_MEMORY_FRONTIER_BUDGET` | Fallback for `frontierBudget`. |
|
|
90
|
-
| `OPENCODE_MEMORY_DEDUP` | Near-duplicate suppression inside a `memory_recall` window.
|
|
90
|
+
| `OPENCODE_MEMORY_DEDUP` | Near-duplicate suppression inside a `memory_recall` window. **ON by default at `0.8`** (content-token Jaccard): a row that is a near-copy (same scope, Jaccard at or above the threshold) of a row already returned is skipped — the newest copy of a clash survives — so the window fills with distinct facts instead of repeats of the top hit. Rows that disagree on a negation word, or carry too little comparable content, are never suppressed. Set `0` for the plain top-`limit` slice, byte-identical to the old behavior; an explicit value below `0.5` or above `1`, or one that is not a number, is a misconfiguration and turns the pass off; see [#409](https://github.com/abogartz/opencode-self-improvement/issues/409). |
|
|
91
91
|
| `OPENCODE_MEMORY_SYMPTOM` | Enforces the capture convention (#419): `learning` and `blocker` rows must open their content with the observable trigger a future session will hit, as `"When <symptom>: <fact>"`. A diary-shaped lesson ("In this session we fixed...") shares no words with the query the future session types — measured: surfaced 0/8 as diary, ranks 1-7 symptom-first — so the write gate blocks it with a rephrase hint instead of storing something that can never be recalled. ON by default; set `off` (or `0`/`false`) for automation holding a pre-convention backlog. A rewrite that keeps the supersede target's content byte-identical (a metadata-only `memory_update`, retag repair) is exempt — the rule shapes new lesson prose, not legacy-row maintenance. Other types (`context`, `decision`, `pattern`, `preference`) are unaffected. `scripts/symptom-fixer.ts` repairs old rows offline, grounding each symptom in the store's own query ledger. |
|
|
92
|
-
| `OPENCODE_MEMORY_QUERY_GATE` |
|
|
92
|
+
| `OPENCODE_MEMORY_QUERY_GATE` | **ON by default**: a `memory_recall` match must share **two** whole words of the query once the query has three content words — the rule the injected relevance block already applies, so both paths agree on when nothing is a good enough answer. Set `off` (also `0`, `no`, `n`, `false`, or any zero) to restore the matcher's permissive one-word admission. |
|
|
93
93
|
| `OPENCODE_COMMANDS_DIR` | Where the plugin mirrors its slash commands (default `~/.config/opencode/commands`). |
|
|
94
94
|
| `OPENCODE_VIEWER_HOST` | Interface the editor binds to (default `127.0.0.1`). A non-loopback bind serves the store over plain HTTP with no authentication — only do it on a network you control. See [Surfaces](#surfaces). |
|
|
95
95
|
| `OPENCODE_VIEWER_PORT` | Admin editor port (default `8787`). |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
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/recall/dedupe.ts
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
// the threshold, keeping the NEWEST copy of a clash (§17's adoption rule: the
|
|
13
13
|
// live duplicates are stale cursors and superseded snapshots, so the row that
|
|
14
14
|
// survives is the one written last, not the one that ranked highest). No model,
|
|
15
|
-
// no new index, and
|
|
15
|
+
// no new index, and ON by default — a window padded with near-copies of the top
|
|
16
|
+
// hit is paid-for context nobody reads, and a quality fix behind an opt-in flag
|
|
17
|
+
// is not a fix. Explicit opt-out:
|
|
16
18
|
//
|
|
17
|
-
// OPENCODE_MEMORY_DEDUP=0
|
|
19
|
+
// OPENCODE_MEMORY_DEDUP=0 (the plain top-limit slice, byte-identical)
|
|
18
20
|
//
|
|
19
21
|
// Threshold guidance from the live replay (§17): 0.5-0.7 suppresses rows that
|
|
20
22
|
// are merely related (92% of them at 0.5) and forces the window deep into the
|
|
@@ -56,6 +58,13 @@ export const MIN_THRESHOLD = 0.5;
|
|
|
56
58
|
/** A row with fewer content tokens than this is never compared (§17 floor). */
|
|
57
59
|
export const MIN_CONTENT = 4;
|
|
58
60
|
|
|
61
|
+
/**
|
|
62
|
+
* The default when the flag is unset: 0.8 is the live-replay point that
|
|
63
|
+
* suppresses only near-identical copies (§17) — it touched 17% of calls,
|
|
64
|
+
* never changed top-1, and never dropped a term's last carrier.
|
|
65
|
+
*/
|
|
66
|
+
export const DEFAULT_THRESHOLD = 0.8;
|
|
67
|
+
|
|
59
68
|
/**
|
|
60
69
|
* Tokens that reverse a row's meaning. If exactly one row of a candidate pair
|
|
61
70
|
* carries any of them, the rows disagree, and disagreement is not duplication.
|
|
@@ -75,12 +84,17 @@ export const POLARITY_WORDS = new Set([
|
|
|
75
84
|
"banned",
|
|
76
85
|
]);
|
|
77
86
|
|
|
78
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Threshold from the environment. Unset or empty means DEFAULT_THRESHOLD (on).
|
|
89
|
+
* `0` means off — the documented escape hatch. An explicit value that is
|
|
90
|
+
* unparsable, < MIN_THRESHOLD or > 1 is a misconfiguration and turns the pass
|
|
91
|
+
* off rather than silently running something the user did not ask for.
|
|
92
|
+
*/
|
|
79
93
|
export function dedupeThreshold(
|
|
80
94
|
env: Record<string, string | undefined> = process.env,
|
|
81
95
|
): number {
|
|
82
96
|
const raw = env[DEDUPE_ENV];
|
|
83
|
-
if (
|
|
97
|
+
if (raw === undefined || raw.trim() === "") return DEFAULT_THRESHOLD;
|
|
84
98
|
const n = Number(raw);
|
|
85
99
|
return Number.isFinite(n) && n >= MIN_THRESHOLD && n <= 1 ? n : 0;
|
|
86
100
|
}
|
|
@@ -155,11 +169,31 @@ export function dedupeWindow(
|
|
|
155
169
|
threshold: number,
|
|
156
170
|
): Memory[] {
|
|
157
171
|
if (threshold <= 0 || ranked.length <= 1) return ranked.slice(0, limit);
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
// Token sets are built lazily and cached per index: the loop stops once
|
|
173
|
+
// `limit` rows are kept, so eager tokenization of every candidate costs
|
|
174
|
+
// 1.7ms/12.5ms/96.4ms at 200/2k/10k candidates on every query recall
|
|
175
|
+
// (review #426). Lazy cost is window-sized.
|
|
176
|
+
const tokenCache = new Map<number, Set<string>>();
|
|
177
|
+
const tokensOf = (i: number): Set<string> => {
|
|
178
|
+
let t = tokenCache.get(i);
|
|
179
|
+
if (t === undefined) {
|
|
180
|
+
t = contentTokens(ranked[i]!);
|
|
181
|
+
tokenCache.set(i, t);
|
|
182
|
+
}
|
|
183
|
+
return t;
|
|
184
|
+
};
|
|
185
|
+
const polarityCache = new Map<number, boolean>();
|
|
186
|
+
const polarityOf = (i: number): boolean => {
|
|
187
|
+
let p = polarityCache.get(i);
|
|
188
|
+
if (p === undefined) {
|
|
189
|
+
p = hasPolarity(tokensOf(i));
|
|
190
|
+
polarityCache.set(i, p);
|
|
191
|
+
}
|
|
192
|
+
return p;
|
|
193
|
+
};
|
|
160
194
|
const kept: number[] = [];
|
|
161
195
|
for (let i = 0; i < ranked.length && kept.length < limit; i++) {
|
|
162
|
-
if (
|
|
196
|
+
if (tokensOf(i).size < MIN_CONTENT) {
|
|
163
197
|
kept.push(i);
|
|
164
198
|
continue;
|
|
165
199
|
}
|
|
@@ -168,10 +202,10 @@ export function dedupeWindow(
|
|
|
168
202
|
const k = kept[pos]!;
|
|
169
203
|
if (
|
|
170
204
|
ranked[k]!.scope === ranked[i]!.scope &&
|
|
171
|
-
|
|
172
|
-
|
|
205
|
+
tokensOf(k).size >= MIN_CONTENT &&
|
|
206
|
+
polarityOf(k) === polarityOf(i) &&
|
|
173
207
|
sameDroppedChunks(ranked[k]!, ranked[i]!) &&
|
|
174
|
-
jaccard(
|
|
208
|
+
jaccard(tokensOf(i), tokensOf(k)) >= threshold
|
|
175
209
|
) {
|
|
176
210
|
clash = pos;
|
|
177
211
|
break;
|
package/src/recall/gate.ts
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
// enough to be a deliberate search (LONG_QUERY_TOKENS in score.ts). This applies
|
|
14
14
|
// that rule to the tool, so the two paths agree on when nothing is a good enough
|
|
15
15
|
// answer. It changes admission only: ranking, scoring and the window size are
|
|
16
|
-
// untouched
|
|
16
|
+
// untouched. ON by default — the two paths disagreeing was the bug, and a
|
|
17
|
+
// quality fix that nobody flips on is not a fix. Explicit opt-out:
|
|
17
18
|
//
|
|
18
|
-
// OPENCODE_MEMORY_QUERY_GATE=
|
|
19
|
+
// OPENCODE_MEMORY_QUERY_GATE=off (also 0 / no / n / false)
|
|
19
20
|
//
|
|
20
21
|
// WHY THE GATE COUNTS WORDS AND THE SCORER COUNTS SUBSTRINGS
|
|
21
22
|
//
|
|
@@ -39,21 +40,26 @@
|
|
|
39
40
|
// first version's numbers were measured with substring counting and are void.
|
|
40
41
|
// See https://github.com/abogartz/opencode-self-improvement/issues/409.
|
|
41
42
|
import type { Memory } from "../store/model/memory.ts";
|
|
42
|
-
import { LONG_QUERY_TOKENS, QUERY_STOPWORDS } from "./score.ts";
|
|
43
|
+
import { LONG_QUERY_TOKENS, QUERY_STOPWORDS, words } from "./score.ts";
|
|
43
44
|
|
|
44
45
|
export const GATE_ENV = "OPENCODE_MEMORY_QUERY_GATE";
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* `
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* ON by default. Off only for an explicit negative: the off words (`off`, `no`,
|
|
49
|
+
* `n`, `false`) and any number equal to zero — `0`, `00`, `0.0` all mean off,
|
|
50
|
+
* which is what a shell user writing `=no` means. Unset, empty, or anything
|
|
51
|
+
* else is on: a default-ON quality path must not be disableable by typo.
|
|
51
52
|
*/
|
|
52
53
|
export function gateEnabled(
|
|
53
54
|
env: Record<string, string | undefined> = process.env,
|
|
54
55
|
): boolean {
|
|
55
56
|
const raw = env[GATE_ENV]?.trim().toLowerCase();
|
|
56
|
-
|
|
57
|
+
if (!raw) return true;
|
|
58
|
+
if (raw === "off" || raw === "no" || raw === "n" || raw === "false")
|
|
59
|
+
return false;
|
|
60
|
+
const n = Number(raw);
|
|
61
|
+
if (Number.isFinite(n)) return n !== 0;
|
|
62
|
+
return true;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/**
|
|
@@ -63,9 +69,13 @@ export function gateEnabled(
|
|
|
63
69
|
* another. Distinct from score.ts's `haystack`, which orders the same fields for
|
|
64
70
|
* the injection scorer.
|
|
65
71
|
*/
|
|
66
|
-
|
|
72
|
+
function recallHaystackRaw(m: Memory): string {
|
|
67
73
|
const kw = m.kw?.length ? ` ${m.kw.join(" ")}` : "";
|
|
68
|
-
return `${m.type} ${m.scope} ${m.content}${kw}
|
|
74
|
+
return `${m.type} ${m.scope} ${m.content}${kw}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function recallHaystack(m: Memory): string {
|
|
78
|
+
return recallHaystackRaw(m).toLowerCase();
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
// Split into whole words at whitespace and punctuation. Underscore stays inside a
|
|
@@ -91,14 +101,20 @@ export function queryConcepts(query: string): string[] {
|
|
|
91
101
|
|
|
92
102
|
/** The row's concepts, as a set for whole-word membership tests. */
|
|
93
103
|
export function rowConcepts(m: Memory): Set<string> {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
// Union of two vocabularies (#426 review). The #417 scorer tokenizer over
|
|
105
|
+
// the ORIGINAL-case haystack carries whole identifiers plus camel/separator
|
|
106
|
+
// segments, so a prose query is admitted against an identifier written in
|
|
107
|
+
// any style. But words() segments at EVERY separator: `table.db_id` yields
|
|
108
|
+
// table/db/id, never `db_id` whole, and an exact `db_id` query is one
|
|
109
|
+
// concept — so the WORD split (underscore inside, everything else a
|
|
110
|
+
// separator) is unioned back in. Both sides keep their length floor, so
|
|
111
|
+
// `build2837` still shares nothing with `283` and admission stays word-level.
|
|
112
|
+
const out = new Set(words(recallHaystackRaw(m)));
|
|
113
|
+
for (const w of recallHaystack(m).split(WORD)) if (w.length > 2) out.add(w);
|
|
114
|
+
return out;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
/** How many of `concepts` the row contains as whole words. */
|
|
117
|
+
/** How many of `concepts` the row contains as whole words (or identifier segments). */
|
|
102
118
|
export function sharedConcepts(
|
|
103
119
|
m: Memory,
|
|
104
120
|
concepts: readonly string[],
|
package/src/tools/recall.ts
CHANGED
|
@@ -51,9 +51,9 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
51
51
|
results = results.filter((m) => m.scope.includes(args.scope!));
|
|
52
52
|
if (args.type) results = results.filter((m) => m.type === args.type);
|
|
53
53
|
if (args.query) {
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
54
|
+
// Default on: a row must share two whole words of the query — the
|
|
55
|
+
// concepts rule, not the scorer's substring test (src/recall/gate.ts,
|
|
56
|
+
// #409). OPENCODE_MEMORY_QUERY_GATE=off restores the old matcher.
|
|
57
57
|
const gate = gateEnabled();
|
|
58
58
|
const concepts = gate ? queryConcepts(args.query) : [];
|
|
59
59
|
results = results
|
|
@@ -71,9 +71,10 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
71
71
|
// Non-positive or fractional limits are coerced, never trusted: a
|
|
72
72
|
// negative slice(0, n) / slice(-n) silently returns MORE rows, not fewer.
|
|
73
73
|
const limit = args.limit && args.limit > 0 ? Math.floor(args.limit) : 5;
|
|
74
|
-
// #409 dedup lane (RESULTS §17):
|
|
75
|
-
//
|
|
76
|
-
//
|
|
74
|
+
// #409 dedup lane (RESULTS §17): default on at 0.8 — near-duplicate
|
|
75
|
+
// copies are skipped so the window fills with distinct rows instead of
|
|
76
|
+
// repeats of the top hit. OPENCODE_MEMORY_DEDUP=0 restores the plain
|
|
77
|
+
// slice.
|
|
77
78
|
const dedupeAt = dedupeThreshold();
|
|
78
79
|
const limited = args.query
|
|
79
80
|
? dedupeWindow(results, limit, dedupeAt)
|