opencode-self-improvement 0.18.1 → 0.19.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/package.json +1 -1
- package/src/capture/prompt.ts +9 -0
- package/src/capture/runtime.ts +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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/capture/prompt.ts
CHANGED
|
@@ -39,8 +39,10 @@ export function buildCapturePrompt(
|
|
|
39
39
|
transcript: string,
|
|
40
40
|
max = 3,
|
|
41
41
|
userProse = "",
|
|
42
|
+
known = "",
|
|
42
43
|
): string {
|
|
43
44
|
const prose = redactSecrets(userProse).trim();
|
|
45
|
+
const knownList = redactSecrets(known).trim();
|
|
44
46
|
return [
|
|
45
47
|
"You mine one coding-agent session transcript for durable memories worth keeping across future sessions.",
|
|
46
48
|
"",
|
|
@@ -54,8 +56,15 @@ export function buildCapturePrompt(
|
|
|
54
56
|
"- content: one self-contained fact, 20-600 characters, useful in a NEW session.",
|
|
55
57
|
"- kw: 3-5 search keywords for how a DIFFERENT session would ask for this — synonyms and alternate names, other verb forms, the literal command or file name. They are indexed for retrieval and never shown to a model. Omit (or []) when the content already uses those words.",
|
|
56
58
|
"- guided: true ONLY when the user STATED this fact in their own words — a value, rate, number, rule or correction that appears in a user: line or the REQUESTS block. Omit guided for anything the agent discovered by itself.",
|
|
59
|
+
"- A guided row states the user's value or rule and NOTHING more: never claim what hidden tests, graders or suites 'encode' — you cannot see them, and the claim makes the row impossible to check.",
|
|
57
60
|
"- Keep: decisions made, working commands, user preferences, blockers hit, durable context, conventions.",
|
|
58
61
|
"- Skip: anything derivable from the code or git history, small talk, and details that only mattered inside this conversation.",
|
|
62
|
+
...(knownList
|
|
63
|
+
? [
|
|
64
|
+
"- Already stored for this repo — do NOT output these or restatements of them:",
|
|
65
|
+
knownList,
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
59
68
|
...(prose
|
|
60
69
|
? [
|
|
61
70
|
// The brief is its own block, so the rule about it is its own too.
|
package/src/capture/runtime.ts
CHANGED
|
@@ -13,6 +13,15 @@ import { lagSince } from "./lag.ts";
|
|
|
13
13
|
import { buildCapturePrompt } from "./prompt.ts";
|
|
14
14
|
import { type SessionModelRef, sessionModel } from "./session-model.ts";
|
|
15
15
|
import { flattenTranscript, splitTranscript } from "./transcript.ts";
|
|
16
|
+
import { loadAll } from "../store/files/load.ts";
|
|
17
|
+
import { isInjectable } from "../store/model/predicates.ts";
|
|
18
|
+
import {
|
|
19
|
+
readerFromSid,
|
|
20
|
+
visibleTo,
|
|
21
|
+
type Reader,
|
|
22
|
+
} from "../store/model/visibility.ts";
|
|
23
|
+
import { flattenMemoryText } from "../store/sanitize.ts";
|
|
24
|
+
import { cmpTs } from "../core/cmp-ts.ts";
|
|
16
25
|
import { AUTO_CAPTURE_TAG, USER_GUIDED_TAG } from "../core/tags.ts";
|
|
17
26
|
|
|
18
27
|
interface CaptureHost {
|
|
@@ -43,6 +52,34 @@ interface CaptureDependencies {
|
|
|
43
52
|
// distinction the auto_capture_compaction_* evidence lines carry.
|
|
44
53
|
const CAPTURE_COMPACT_TAG = "auto_capture_compaction";
|
|
45
54
|
|
|
55
|
+
async function knownRowsFor(reader: Reader): Promise<string> {
|
|
56
|
+
try {
|
|
57
|
+
const rows = visibleTo(await loadAll(), reader)
|
|
58
|
+
.filter(isInjectable)
|
|
59
|
+
.sort((a, b) => cmpTs(b.ts, a.ts))
|
|
60
|
+
.slice(0, 15);
|
|
61
|
+
const lines: string[] = [];
|
|
62
|
+
let length = 0;
|
|
63
|
+
for (const row of rows) {
|
|
64
|
+
// Scrub complete legacy values before cropping, or a token prefix can
|
|
65
|
+
// fall outside the window and leave an unrecognizable secret fragment.
|
|
66
|
+
const scope = flattenMemoryText(redactSecrets(row.scope));
|
|
67
|
+
const content = flattenMemoryText(redactSecrets(row.content)).slice(
|
|
68
|
+
0,
|
|
69
|
+
90,
|
|
70
|
+
);
|
|
71
|
+
const line = `- ${scope}: ${content}`;
|
|
72
|
+
if (length + line.length > 1400) break;
|
|
73
|
+
lines.push(line);
|
|
74
|
+
length += line.length + 1;
|
|
75
|
+
}
|
|
76
|
+
return lines.join("\n");
|
|
77
|
+
} catch {
|
|
78
|
+
// The write gate still deduplicates when this optional context is absent.
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
46
83
|
// Auto-capture cooldown, shared by EVERY setup() registration (#108): setup
|
|
47
84
|
// runs for more than one location, and per-closure cooldown maps made those
|
|
48
85
|
// registrations strangers - one compaction could pay for two model calls on
|
|
@@ -215,6 +252,7 @@ export function configureAutoCapture(
|
|
|
215
252
|
gate?: GateContext,
|
|
216
253
|
): Promise<void> {
|
|
217
254
|
const captureGate = gate ?? bindCapture(sid);
|
|
255
|
+
const captureReader = captureGate.reader ?? readerFromSid(sid);
|
|
218
256
|
// #139: resolve the model BEFORE any skip so every capture evidence
|
|
219
257
|
// line below can carry model= (cost attributable to a named model —
|
|
220
258
|
// the real answer to the cost-surprise concern that justified the
|
|
@@ -304,6 +342,7 @@ export function configureAutoCapture(
|
|
|
304
342
|
redactSecrets(work).slice(-7000),
|
|
305
343
|
captureMax,
|
|
306
344
|
redactSecrets(userProse).slice(-1500),
|
|
345
|
+
await knownRowsFor(captureReader),
|
|
307
346
|
),
|
|
308
347
|
});
|
|
309
348
|
const text = typeof out === "string" ? out : (out?.text ?? "");
|