opencode-self-improvement 0.16.0 → 0.16.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/README.md +7 -3
- package/package.json +1 -1
- package/src/core/guidance.ts +13 -0
- package/src/portable/import.ts +4 -1
- package/src/status/payload.ts +3 -3
- package/src/status/report.ts +11 -15
- package/src/tools/remember.ts +2 -1
- package/src/tools/status-tool.ts +1 -1
- package/src/tools/update.ts +5 -2
- package/src/tui/panel.tsx +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Four gates run before anything is stored, and each emits an ordered evidence lin
|
|
|
116
116
|
3. **GATE-3 — no duplicates.** Near-duplicates collapse into the existing row; a contradiction with a superseded memory is rejected.
|
|
117
117
|
4. **GATE-4 — promotion or block.** The row lands, or the call returns the reason.
|
|
118
118
|
|
|
119
|
-
Nothing is deleted: `memory_update` supersedes the previous row, `memory_forget` records a retirement, and `memory_undo` restores a snapshot. `memory_update` takes a `query` that picks the row — its id, a clock fragment such as `00:11:22.123`, or a unique substring of its text. Omit it to update the newest entry of that scope and type. A `query` that matches nothing, or several rows, writes nothing and says so. A prose edit
|
|
119
|
+
Nothing is deleted: `memory_update` supersedes the previous row, `memory_forget` records a retirement, and `memory_undo` restores a snapshot. `memory_update` takes a `query` that picks the row — its id, a clock fragment such as `00:11:22.123`, or a unique substring of its text. Omit it to update the newest entry of that scope and type. A `query` that matches nothing, or several rows, writes nothing and says so. A prose edit carries over ordinary tags, issue link, retrieval keywords, open/settled standing, and repository to the new row, while capture-only guidance provenance is removed — updating a `global` row from one machine keeps it global for every other. Naming a row an earlier update already superseded reports the duplicate when the live successor already holds that exact content; when only the metadata you name differs, the update runs against the successor instead of dead-ending. And a failure after the new row is durable is reported as `PARTIAL` — the message names what failed, the replacement stands on disk, and `memory_undo` (merge or force) brings the old row back.
|
|
120
120
|
|
|
121
121
|
## Repo scoping
|
|
122
122
|
|
|
@@ -140,19 +140,21 @@ Gate-authored evidence and its init/capture lifecycle records capture attributio
|
|
|
140
140
|
|
|
141
141
|
**Bench** — deterministic workload (50 memories, 20 prompts, 3 mid-session store writes made *by the measured session*) through the plugin's real injection code. Every column is measured on the full memory section — the bytes a request actually sends — because prompt caching is a property of those bytes:
|
|
142
142
|
|
|
143
|
-
| Policy | Recomputes |
|
|
143
|
+
| Policy | Recomputes | Epochs whose bytes moved | Injected chars (20 turns) | Avg/turn | Worst section |
|
|
144
144
|
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
145
145
|
| A — recompute per prompt, uncapped (naive) | 20 | 19 | 60996 | 3049.8 | 3404 |
|
|
146
146
|
| B — block frozen on store fingerprint, digest rebuilt per turn | 4 | 3 | 55478 | 2773.9 | 2867 |
|
|
147
147
|
| C — section frozen on rendered bytes | 4 | 3 | 55258 | 2762.9 | 2856 |
|
|
148
148
|
| D — C + riding bytes (shipped) | 1 | 0 | 53500 | 2675.0 | 2675 |
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
The byte-change counter records epochs whose memory-section bytes differ from the previous epoch; it does not measure provider cache misses or re-prefill cost. All three synthetic writes change B and C's bytes; D records no change for these self-writes. Corrections, removals and writes by another session can still move D's bytes, as pinned by `test/epoch.test.ts`. D also injects 12.3% fewer characters than the naive policy, measured over the whole section. Reproduce this deterministic byte workload:
|
|
151
151
|
|
|
152
152
|
```sh
|
|
153
153
|
bun run bench
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
**Author-reported provider audit**, not a new measurement here: [#346's six-turn local-seat audit](https://github.com/abogartz/opencode-self-improvement/issues/346#issuecomment-6714172764) compared `ee769ef` with frozen `29268ef`. The changed build used 2,065 additional input tokens over six turns (~344/turn), with one 3,257-input-token spike, and 94.4% cache share versus 97.5%. The block rode late in the system prompt, after a stable prefix; a byte-moving epoch did not re-bill the whole conversation. This run included two guided rows, so it does not isolate prompt rescoring from the hint channel or establish a bound for every provider. The status counter remains a byte-change count; provider receipts report actual cache reuse separately.
|
|
157
|
+
|
|
156
158
|
## Recall quality
|
|
157
159
|
|
|
158
160
|
No vector database, no embedding model, no API key. **Bench** — what the keyword matcher gives up, measured against classic BM25 on a deterministic eval (store of 200, k=3 — the production injection limit):
|
|
@@ -262,6 +264,8 @@ Review the full row in the memory viewer's **quarantined** filter. **Release qua
|
|
|
262
264
|
|
|
263
265
|
This is a heuristic review queue, not a complete prompt-injection detector: legitimate documentation or quoted code can match. Markdown-bold role headers and download-then-`&&`-execute forms are recognized, but alternate role delimiters such as `[INST]` / `<<SYS>>`, base64-to-shell pipelines, paraphrased instructions, and indirect execution can evade it. Direct `memory_remember` and human viewer edits are explicit writes and are not automatically scanned: a session with that tool still has a prose channel, mitigated by the existing framing and provenance rather than quarantine. Those defenses still apply to released rows.
|
|
264
266
|
|
|
267
|
+
Always-ride guidance priority is reserved to auto-capture provenance. `memory_remember`, `memory_update` replacements, and JSONL imports silently remove `user-guided` (including comma-delimited tag entries) before the write gate; their field allowlists also exclude `ref`, `claim`, and `klass`. Ordinary tags and prose can still promote normally, but a portable file, even with an export header, cannot attest that the local user stated it. The capture path owns guidance metadata; this boundary protection does not authenticate a directly edited store or guarantee that a capture model classified a statement correctly. This reservation is in place before the opt-in hint/contradiction channel lands (#342, #349).
|
|
268
|
+
|
|
265
269
|
The viewer is a trusted admin editor: its edits and deleted-entry restores do not run the model-facing grounding or deduplication gates, but they honor the same exact and near-match value rejections. Rejected edits leave the original row, snapshots and edit audit unchanged; rejected restores append nothing. The refusal names the rejection hash so you can explicitly lift it under **Rejections → un-reject** before retrying. Corrected numeric values and polarity changes retain the rejection check's existing exceptions. This check does not change whole-snapshot rollback policy.
|
|
266
270
|
|
|
267
271
|
Existing stores are not rescanned. A byte-identical import that collapses into an existing row does not retroactively tag that row. Export preserves quarantined rows and their tags to avoid data loss; an exported released row can be quarantined again when re-import promotes it on another machine.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.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": {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Capture-only provenance: grants always-ride priority in the hint channel. */
|
|
2
|
+
export const USER_GUIDED_TAG = "user-guided";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tool/import input cannot grant capture provenance. Split the storage
|
|
6
|
+
* delimiter first: ["ordinary,user-guided"] reads back as two tags too.
|
|
7
|
+
* Silently drop the reserved tag; ordinary prose still faces the write gate.
|
|
8
|
+
*/
|
|
9
|
+
export function nonCaptureTags(tags?: string[]): string[] | undefined {
|
|
10
|
+
return tags
|
|
11
|
+
?.flatMap((tag) => tag.split(","))
|
|
12
|
+
.filter((tag) => tag !== USER_GUIDED_TAG);
|
|
13
|
+
}
|
package/src/portable/import.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { getCurrent } from "../core/state.ts";
|
|
|
12
12
|
import { TYPES } from "../core/types.ts";
|
|
13
13
|
import type { WriteCandidate } from "../gate/gate.ts";
|
|
14
14
|
import { flattenMemoryText } from "../store/sanitize.ts";
|
|
15
|
+
import { nonCaptureTags } from "../core/guidance.ts";
|
|
15
16
|
import { EXPORT_VERSION, exportHeader, stamp } from "./export.ts";
|
|
16
17
|
|
|
17
18
|
// --- import -------------------------------------------------------------------
|
|
@@ -75,7 +76,9 @@ function parseRow(line: string): WriteCandidate | null {
|
|
|
75
76
|
};
|
|
76
77
|
if (r.status === "open" || r.status === "settled") c.status = r.status;
|
|
77
78
|
if (Array.isArray(r.tags) && r.tags.every((t) => typeof t === "string"))
|
|
78
|
-
c.tags = r.tags;
|
|
79
|
+
c.tags = nonCaptureTags(r.tags);
|
|
80
|
+
// ref/claim/klass are deliberately absent from this allowlist: a file
|
|
81
|
+
// (including one carrying our export header) cannot attest user guidance.
|
|
79
82
|
if (kw?.length) c.kw = kw;
|
|
80
83
|
if (typeof r.issue === "string" && r.issue) c.issue = r.issue;
|
|
81
84
|
// Origin stamps survive an export/import hop (repokey.ts): a row written
|
package/src/status/payload.ts
CHANGED
|
@@ -50,15 +50,15 @@ export interface StoreCounts {
|
|
|
50
50
|
* Per-session ledger, incremented at the session.context injection decision
|
|
51
51
|
* (so counts match exactly what was injected — an aborted turn still rode the
|
|
52
52
|
* bytes). Cumulative fields are session-lifetime; epochRequests resets when a
|
|
53
|
-
* new epoch freezes.
|
|
54
|
-
*
|
|
53
|
+
* new epoch freezes. `invalidations` counts epochs whose bytes moved (the
|
|
54
|
+
* first epoch is not one), not provider cache misses or re-prefill tokens.
|
|
55
55
|
*/
|
|
56
56
|
export interface SessionStats {
|
|
57
57
|
requests: number; // provider requests that injected through session.context
|
|
58
58
|
abstained: number; // requests where the epoch block was empty
|
|
59
59
|
cumChars: number; // lifetime sum of injected block chars
|
|
60
60
|
epochRequests: number; // requests the CURRENT epoch block has ridden
|
|
61
|
-
invalidations: number; //
|
|
61
|
+
invalidations: number; // epochs whose bytes moved; provider cost is separate
|
|
62
62
|
lastInvalidation: { at: string; reason: string } | null;
|
|
63
63
|
}
|
|
64
64
|
|
package/src/status/report.ts
CHANGED
|
@@ -49,31 +49,27 @@ export function cacheLines(p: StatusPayload): string[] {
|
|
|
49
49
|
const inv =
|
|
50
50
|
st.invalidations === 0
|
|
51
51
|
? [
|
|
52
|
-
"
|
|
53
|
-
" conversation, so the provider can serve history from cache",
|
|
52
|
+
" epochs whose bytes moved 0 — memory-section bytes have not moved this session",
|
|
54
53
|
]
|
|
55
54
|
: [
|
|
56
|
-
`
|
|
55
|
+
` epochs whose bytes moved ${st.invalidations} this session · last ${
|
|
57
56
|
st.lastInvalidation
|
|
58
57
|
? `${st.lastInvalidation.at.slice(11, 19)} (${st.lastInvalidation.reason})`
|
|
59
58
|
: "-"
|
|
60
59
|
}`,
|
|
61
|
-
"
|
|
62
|
-
" already said it (#165). A correction, a removal, or a row",
|
|
63
|
-
" another session wrote costs exactly one, and the prefix",
|
|
64
|
-
" re-warms on the following turn",
|
|
60
|
+
" counts memory-section byte changes, not provider cache misses",
|
|
65
61
|
];
|
|
66
62
|
const rate = cacheRate(p.measured);
|
|
67
63
|
const receipts = rate
|
|
68
64
|
? [
|
|
69
65
|
` receipts ${fmtCount(rate.read)}/${fmtCount(rate.prompt)} prompt tok served from cache (${rate.pct}%)`,
|
|
70
66
|
rate.pct >= 90
|
|
71
|
-
? " —
|
|
72
|
-
: " —
|
|
67
|
+
? " — observed session-wide cache reuse; memory-only cost is not measured"
|
|
68
|
+
: " — lower observed reuse; this receipt does not identify the cause",
|
|
73
69
|
]
|
|
74
70
|
: [
|
|
75
|
-
" receipts provider reports no cache usage yet —
|
|
76
|
-
` the
|
|
71
|
+
" receipts provider reports no cache usage yet — byte history only:",
|
|
72
|
+
` the block rode ${st.epochRequests} request(s) with ${st.invalidations} byte-moving epochs`,
|
|
77
73
|
];
|
|
78
74
|
return [
|
|
79
75
|
...inv,
|
|
@@ -85,7 +81,7 @@ export function cacheLines(p: StatusPayload): string[] {
|
|
|
85
81
|
/**
|
|
86
82
|
* CONTEXT WINDOW — the "is memory bloating my context?" answer, built ONLY from
|
|
87
83
|
* numbers we trust: the exact injected block (we wrote those bytes), the
|
|
88
|
-
* provider's own cache receipts, and the memory-
|
|
84
|
+
* provider's own cache receipts, and the memory byte-change count. No estimated
|
|
89
85
|
* decomposition of the system prompt or history (we cannot measure those); the
|
|
90
86
|
* one honest share we can state is memory as a slice of what was actually sent.
|
|
91
87
|
*/
|
|
@@ -105,7 +101,7 @@ export function windowLines(p: StatusPayload): string[] {
|
|
|
105
101
|
);
|
|
106
102
|
out.push(
|
|
107
103
|
rate
|
|
108
|
-
? ` cache served ${rate.pct}% of that prompt from cache
|
|
104
|
+
? ` cache served ${rate.pct}% of that prompt from cache — provider-reported share, not a memory-only cost estimate`
|
|
109
105
|
: " cache served provider has not reported a split yet",
|
|
110
106
|
);
|
|
111
107
|
} else {
|
|
@@ -113,9 +109,9 @@ export function windowLines(p: StatusPayload): string[] {
|
|
|
113
109
|
" of what you sent not measured yet — receipts appear after the first assistant turn",
|
|
114
110
|
);
|
|
115
111
|
}
|
|
116
|
-
const
|
|
112
|
+
const moved = p.stats?.invalidations ?? 0;
|
|
117
113
|
out.push(
|
|
118
|
-
`
|
|
114
|
+
` epochs whose bytes moved ${moved} this session${moved ? "" : " — memory-section bytes have not moved"}`,
|
|
119
115
|
);
|
|
120
116
|
return out;
|
|
121
117
|
}
|
package/src/tools/remember.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { ToolRegister } from "./deps.ts";
|
|
|
5
5
|
import { auditCaveat, runWriteGate } from "../gate/gate.ts";
|
|
6
6
|
import type { WriteCandidate } from "../gate/gate.ts";
|
|
7
7
|
import { RememberArgs, validated } from "./schema.ts";
|
|
8
|
+
import { nonCaptureTags } from "../core/guidance.ts";
|
|
8
9
|
|
|
9
10
|
export const register: ToolRegister = (editor, deps) => {
|
|
10
11
|
const {
|
|
@@ -28,7 +29,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
28
29
|
scope: args.scope,
|
|
29
30
|
content: args.content,
|
|
30
31
|
issue: args.issue,
|
|
31
|
-
tags: args.tags,
|
|
32
|
+
tags: nonCaptureTags(args.tags),
|
|
32
33
|
kw: args.kw,
|
|
33
34
|
status: args.status,
|
|
34
35
|
repo: args.global ? "global" : undefined,
|
package/src/tools/status-tool.ts
CHANGED
|
@@ -26,7 +26,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
26
26
|
validated(EmptyArgs, {
|
|
27
27
|
name: "memory_status",
|
|
28
28
|
description:
|
|
29
|
-
"Plain-text memory report for chat clients (desktop/web/IDE), same sections as the terminal /memory panel: CONTEXT (this session's injected block, budget use, cumulative ride and abstentions), CACHE (
|
|
29
|
+
"Plain-text memory report for chat clients (desktop/web/IDE), same sections as the terminal /memory panel: CONTEXT (this session's injected block, budget use, cumulative ride and abstentions), CACHE (epochs whose bytes moved, plus provider-reported cache receipts; byte changes are not a cache-miss estimate), the block verbatim, recent blocked writes with gate reasons (filtered to this reader's evidence visibility, #306), and store stats. Aggregate STORE counts are machine-wide — they count every repository's rows by decision (#213 B), not this reader's. Reads only — no model call.",
|
|
30
30
|
options: direct,
|
|
31
31
|
async execute(_args, context): Promise<{ content: string }> {
|
|
32
32
|
// In-process truth: the live epoch + ledger, fresher than any file.
|
package/src/tools/update.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type { Memory } from "../store/model/memory.ts";
|
|
|
15
15
|
import { UpdateArgs, validated } from "./schema.ts";
|
|
16
16
|
import { redactSecrets } from "../store/secrets.ts";
|
|
17
17
|
import { join } from "node:path";
|
|
18
|
+
import { nonCaptureTags } from "../core/guidance.ts";
|
|
18
19
|
|
|
19
20
|
export const register: ToolRegister = (editor, deps) => {
|
|
20
21
|
const {
|
|
@@ -29,7 +30,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
29
30
|
validated(UpdateArgs, {
|
|
30
31
|
name: "memory_update",
|
|
31
32
|
description:
|
|
32
|
-
"Update an existing memory (gated like remember; the prior entry is superseded, not erased). `query` selects which row to update: its exact id (ts), a clock fragment (e.g. HH:MM:SS.mmm), or a unique substring of its content. Omitting `query` targets the most recent active row of scope+type. An unmatched or ambiguous `query` fails closed and writes nothing. A prose edit carries over everything the call does not name — tags, issue, keywords, status, and the row's repository. Naming a row that was already updated to exactly this content (metadata included) reports the duplicate; if its live successor holds the prose and only the metadata you name differs, the successor is updated. A failure after the write is reported as PARTIAL: the replacement is durable and memory_undo merge/force restores the old row.",
|
|
33
|
+
"Update an existing memory (gated like remember; the prior entry is superseded, not erased). `query` selects which row to update: its exact id (ts), a clock fragment (e.g. HH:MM:SS.mmm), or a unique substring of its content. Omitting `query` targets the most recent active row of scope+type. An unmatched or ambiguous `query` fails closed and writes nothing. A prose edit carries over everything the call does not name — ordinary tags, issue, keywords, status, and the row's repository. Capture-only guidance provenance is removed from replacements. Naming a row that was already updated to exactly this content (metadata included) reports the duplicate; if its live successor holds the prose and only the metadata you name differs, the successor is updated. A failure after the write is reported as PARTIAL: the replacement is durable and memory_undo merge/force restores the old row.",
|
|
33
34
|
options: direct,
|
|
34
35
|
async execute(args, context): Promise<{ content: string }> {
|
|
35
36
|
const { sid } = toolIds(context);
|
|
@@ -183,7 +184,9 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
183
184
|
// "already standing" on a row holding ["old-alias"].
|
|
184
185
|
const requested = {
|
|
185
186
|
kw: args.kw ?? target.kw,
|
|
186
|
-
|
|
187
|
+
// A model-authored successor cannot attest that the user
|
|
188
|
+
// stated its prose, even when it replaces a captured row.
|
|
189
|
+
tags: nonCaptureTags(target.tags),
|
|
187
190
|
issue: target.issue,
|
|
188
191
|
status: args.status ?? target.status ?? "settled",
|
|
189
192
|
repo: target.repo ?? "global",
|