opencode-self-improvement 0.14.2 → 0.14.3

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 CHANGED
@@ -36,7 +36,7 @@ After that, memory is just conversation: ask the agent to remember something and
36
36
  - **`/repo-init`** — per-repo setup: code graph index plus build/test commands, keyed to the git head.
37
37
  - **Write gates** — code references are verified against your actual repo, near-duplicates are collapsed, contradictions with superseded memories are rejected. Blocked writes are logged with a reason in `memory_evidence`.
38
38
  - **Memory-aware compaction** — durable memories are handed to the compaction summarizer, so a long session keeps its facts.
39
- - **Auto-capture (opt-in)** — on the idle and compaction triggers, one cheap model pass proposes candidates, which face the same write gates. Off by default.
39
+ - **Auto-capture (opt-in)** — on the idle and compaction triggers, one cheap model pass per trigger proposes candidates, which face the same write gates; a 5-minute cooldown per session and trigger bounds the spend ([per-trigger numbers](bench/capture-trigger-results.md)). Off by default.
40
40
  - **Repo scoping** — rows belong to the repo that wrote them; project A's facts never surface in project B.
41
41
  - **Safe across concurrent sessions** — whole-file rewrites hold a per-file lock honored across processes and hand the new file over with an atomic rename.
42
42
  - **Decay** — `memory_decay` retires stale open threads. Dry run by default, snapshot-first, undoable.
@@ -64,7 +64,7 @@ Zero configuration is the default. To tune, use the object form of the plugin en
64
64
  | `autoCapture` | `false` | Master switch for auto-capture. Off by default, so the install stays zero-token. |
65
65
  | `captureModel` | — | `"provider/id"` model used for auto-capture. Required when `autoCapture` is on; missing or invalid disables capture with a startup warning. |
66
66
  | `captureMax` | `3` | Maximum candidates proposed per capture pass. |
67
- | `captureOnCompact` | `true` | When `autoCapture` is on, also mine the transcript at compaction, before the summarizer replaces it. Setting it while `autoCapture` is off does nothing and reports a startup warning. |
67
+ | `captureOnCompact` | `true` | When `autoCapture` is on, also mine the transcript at compaction, before the summarizer replaces it. Its 5-minute cooldown is separate from the idle one, so the two triggers' hit-rates stay measurable. Setting it while `autoCapture` is off does nothing and reports a startup warning. |
68
68
  | `notifyBlocked` | `true` | Terminal (TUI) only: toast when a write gate blocks a write. Blocks are always in `memory_evidence` either way. |
69
69
 
70
70
  ### Environment variables
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
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
@@ -196,6 +196,34 @@ const CAPTURE_COMPACT_TAG = "auto_capture_compaction";
196
196
  // more than one location).
197
197
  let bunFloorChecked = false;
198
198
 
199
+ // Auto-capture cooldown, shared by EVERY setup() registration (#108): setup
200
+ // runs for more than one location, and per-closure cooldown maps made those
201
+ // registrations strangers - one compaction could pay for two model calls on
202
+ // one transcript. Same module-level shape as `turns` in src/lock.ts; the key
203
+ // names the trigger, so measuring one trigger is still not confounded by the
204
+ // other having fired moments ago.
205
+ const lastCaptureRun = new Map<string, number>();
206
+
207
+ const CAPTURE_COOLDOWN_MS = 5 * 60_000;
208
+
209
+ /** True if this trigger may fire for this session now; records the fire. */
210
+ function captureCooldownPasses(trigger: "idle" | "compaction", sid: string, now: number): boolean {
211
+ const key = `${trigger}:${sid}`;
212
+ if (now - (lastCaptureRun.get(key) ?? 0) < CAPTURE_COOLDOWN_MS) return false;
213
+ // Sessions churn and a long-lived server must not grow one entry per
214
+ // session forever; oldest-inserted go first (the ledger throttle's rule).
215
+ if (lastCaptureRun.size > 2000) {
216
+ for (const k of [...lastCaptureRun.keys()].slice(0, 1000)) lastCaptureRun.delete(k);
217
+ }
218
+ lastCaptureRun.set(key, now);
219
+ return true;
220
+ }
221
+
222
+ /** Clear the cooldown windows (tests; also what a process restart does). */
223
+ export function resetCaptureCooldowns(): void {
224
+ lastCaptureRun.clear();
225
+ }
226
+
199
227
  // The real setup implementation, written against the loose local PluginCtx
200
228
  // (the only members of the V2 context this plugin actually touches).
201
229
  const impl = {
@@ -1075,7 +1103,6 @@ const impl = {
1075
1103
  );
1076
1104
  } else {
1077
1105
  const controller = new AbortController();
1078
- const lastRun = new Map<string, number>();
1079
1106
  const eventApi = ctx.event;
1080
1107
  const generateApi = ctx.generate;
1081
1108
  // Arrow wrapper: keep the receiver bound. The harness fakes are closures,
@@ -1150,8 +1177,7 @@ const impl = {
1150
1177
  if (typeof sid !== "string") continue;
1151
1178
  setCurrent({ sessionID: sid });
1152
1179
  const now = Date.now();
1153
- if (now - (lastRun.get(sid) ?? 0) < 5 * 60_000) continue; // 5-min cooldown
1154
- lastRun.set(sid, now);
1180
+ if (!captureCooldownPasses("idle", sid, now)) continue; // 5-min cooldown, shared across setups
1155
1181
  try {
1156
1182
  await captureSession(sid, "", "idle");
1157
1183
  } catch {
@@ -1165,16 +1191,16 @@ const impl = {
1165
1191
  captureCleanup = () => controller.abort();
1166
1192
 
1167
1193
  // The compaction trigger needs no extra subscription: the session
1168
- // compaction hook (registered above) calls through this seam. Separate
1169
- // cooldown map from idle, so measuring a trigger is not confounded by
1170
- // the other trigger having fired moments ago.
1194
+ // compaction hook (registered above) calls through this seam. The
1195
+ // cooldown names the trigger, so measuring a compaction capture is
1196
+ // not confounded by an idle fire moments before - and lives at
1197
+ // module level, so a second setup() cannot double-pay one
1198
+ // compaction (#108).
1171
1199
  if (captureOnCompact) {
1172
- const lastCompactRun = new Map<string, number>();
1173
1200
  onCompactCapture = (sid, messages) => {
1174
1201
  if (controller.signal.aborted) return;
1175
1202
  const now = Date.now();
1176
- if (now - (lastCompactRun.get(sid) ?? 0) < 5 * 60_000) return; // 5-min cooldown
1177
- lastCompactRun.set(sid, now);
1203
+ if (!captureCooldownPasses("compaction", sid, now)) return; // 5-min cooldown
1178
1204
  void guarded("session.compaction (auto-capture)", () =>
1179
1205
  captureSession(sid, flattenTranscript(messages), "compaction", messages),
1180
1206
  );