opencode-self-improvement 0.14.17 → 0.14.19

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/src/triggers.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  session,
11
11
  setLastSeenSid,
12
12
  lastSeenSid,
13
+ type SessionState,
13
14
  type ToolResult,
14
15
  } from "./state.ts";
15
16
 
@@ -31,6 +32,21 @@ export interface AfterOutput {
31
32
  // running commands. Empirical behavior substitutes for hand-copied refs.
32
33
  const ENGAGEMENT_TOOLS = new Set(["grep", "glob", "read", "edit", "write", "bash", "shell"]);
33
34
 
35
+ const RECENT_EVIDENCE_CALLS = 10;
36
+ // Recent engagement + latest gate check + FAIL/fix/PASS + tool FAIL/PASS.
37
+ export const MAX_WRITE_EVIDENCE_REFS = RECENT_EVIDENCE_CALLS + 1 + 3 + 2;
38
+
39
+ function trackCall(s: SessionState, rec: ToolResult): void {
40
+ s.calls.push(rec);
41
+ s.writeEvidence ??= { recent: [] };
42
+ const evidence = s.writeEvidence;
43
+ if (ENGAGEMENT_TOOLS.has(rec.tool)) {
44
+ evidence.recent.push(rec.call);
45
+ if (evidence.recent.length > RECENT_EVIDENCE_CALLS) evidence.recent.shift();
46
+ }
47
+ if (rec.gateCheck) evidence.gateCheck = rec.call;
48
+ }
49
+
34
50
  // True once the session has exercised the codebase (the FAIL->PASS signals use
35
51
  // the same whitelist, so engagement == "a tool_result was recorded for a code
36
52
  // tool").
@@ -153,17 +169,19 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
153
169
  false,
154
170
  sid,
155
171
  );
172
+ s.writeEvidence ??= { recent: [] };
173
+ s.writeEvidence.gateRecovery = [pend.call, fix, call];
156
174
  s.pendingGate = null;
157
175
  } else if (s.pendingGate) {
158
176
  s.pendingGate.chain.push(rec);
159
177
  }
160
- s.calls.push(rec);
178
+ trackCall(s, rec);
161
179
  return;
162
180
  }
163
181
 
164
182
  // Keep the pending gate chain (grep/read/edit between FAIL and PASS).
165
183
  if (s.pendingGate) s.pendingGate.chain.push(rec);
166
- s.calls.push(rec);
184
+ trackCall(s, rec);
167
185
 
168
186
  // ---- Failed -> fixed retry (non-gate tools) -------------------------------
169
187
  if (["grep", "glob", "read"].includes(tool)) {
@@ -181,6 +199,8 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
181
199
  false,
182
200
  sid,
183
201
  );
202
+ s.writeEvidence ??= { recent: [] };
203
+ s.writeEvidence.toolRecovery = [prev.call, call];
184
204
  }
185
205
  s.lastByTool.set(tool, { status, call, emitted: prev?.emitted ?? false });
186
206
  }
@@ -201,10 +221,28 @@ export async function onCompacting(input: AfterInput): Promise<void> {
201
221
  await finalizeSession(sid);
202
222
  }
203
223
 
224
+ // Full IDs for callers that explicitly need the ledger. Production write
225
+ // contexts use writeEvidence so they do not allocate this growing list.
204
226
  export function evidenceCalls(sid: string): string[] {
205
227
  return session(sid).calls.map((c) => c.call);
206
228
  }
207
229
 
230
+ // A detached, bounded snapshot for GateContext. Do not map the entire ledger
231
+ // on each write: it grows throughout the session. Pin the actual trigger
232
+ // witnesses when recorded rather than trying to reconstruct a FAIL->PASS
233
+ // pairing from a cropped tail. The full ledger remains available above.
234
+ export function writeEvidence(sid: string): { evidenceCalls: string[]; evidenceCallsCount: number } {
235
+ const s = session(sid);
236
+ const evidence = s.writeEvidence;
237
+ const refs = new Set([
238
+ ...(evidence?.gateRecovery ?? []),
239
+ ...(evidence?.toolRecovery ?? []),
240
+ ...(evidence?.gateCheck !== undefined ? [evidence.gateCheck] : []),
241
+ ...(evidence?.recent ?? []),
242
+ ]);
243
+ return { evidenceCalls: [...refs], evidenceCallsCount: s.calls.length };
244
+ }
245
+
208
246
  // The full per-session tool ledger, for memory attribution (src/attribution.ts).
209
247
  export function callsFor(sid: string): ToolResult[] {
210
248
  return session(sid).calls;
@@ -264,7 +302,7 @@ export async function finalizeSession(sid: string): Promise<void> {
264
302
  );
265
303
  }
266
304
 
267
- // Called from chat.message: opening a new session closes the previous one
305
+ // Called from the session prompt hook: opening a new session closes the previous one
268
306
  // (the host has no session-end hook, so a push handoff — new session in the
269
307
  // same process — is the closest deterministic close).
270
308
  export async function checkNewSession(sid: string): Promise<void> {
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Shared memory-row enums. Lives outside index.ts so the pure capture core
2
2
  // (src/capture.ts) can reference the admissible values without importing the
3
- // plugin entry. index.ts feeds these into the tool JSON Schemas; capture.ts
4
- // uses them to prompt and validate.
3
+ // plugin entry. schema.ts uses these in tool schemas; capture.ts uses TYPES
4
+ // to prompt and validate.
5
5
  export const TYPES = ["decision", "learning", "preference", "blocker", "context", "pattern"] as const;
6
6
  export const STATUSES = ["open", "settled"] as const;