opencode-self-improvement 0.14.18 → 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/README.md CHANGED
@@ -82,6 +82,8 @@ Zero configuration is the default. To tune, use the object form of the plugin en
82
82
 
83
83
  ## How memory is written
84
84
 
85
+ Promotion evidence keeps a bounded sample of call IDs: the ten most recent code-engagement calls, plus the latest gate check, the latest recorded gate FAIL/fix/PASS recovery, and the latest recorded tool FAIL/PASS retry (at most 16 distinct IDs). `evidence_refs_count` is the total number of recorded session calls before sampling, including non-code tools; the sampled IDs are audit pointers, not a complete history. Grounding and memory attribution still use the full in-memory ledger. Existing evidence day-files are left unchanged: this upgrade does not backfill, compact, or delete historical audit records.
86
+
85
87
  Four gates run before anything is stored, and each emits an ordered evidence line:
86
88
 
87
89
  1. **GATE-1 — code references resolve.** Call signatures and paths embedded in the memory are checked against your live source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.14.18",
3
+ "version": "0.14.19",
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.ts CHANGED
@@ -1,26 +1,13 @@
1
- // Opt-in auto-capture core. Pure and dependency-free: no opencode
2
- // imports, no filesystem, no ambient clock — the transcript, the model call
3
- // and time are all injected by the caller (src/index.ts), so everything here
4
- // is unit-testable. Every candidate that leaves this module still flows
1
+ // Opt-in auto-capture parsing, prompt, and lag helpers. Host access and model
2
+ // calls live in src/index.ts. Every candidate that leaves this module flows
5
3
  // through runWriteGate in index.ts: capture NEVER writes memories directly,
6
4
  // so dupes/stale/canonical rules keep the moat (same as model-authored writes).
7
5
  // All parsing functions are TOTAL: any malformed input yields [] / "" / null,
8
6
  // never a throw.
9
- import { STATUSES, TYPES } from "./types.ts";
7
+ import { TYPES } from "./types.ts";
10
8
  import { flattenMemoryText } from "./sanitize.ts";
11
9
  import { redactSecrets } from "./secrets.ts";
12
10
 
13
- export interface CaptureOptions {
14
- model: string; // "provider/id"
15
- max: number;
16
- }
17
-
18
- export interface CaptureDeps {
19
- generate: (prompt: string) => Promise<string>;
20
- sessionText: string;
21
- now: () => Date;
22
- }
23
-
24
11
  export interface CaptureCandidate {
25
12
  type: string;
26
13
  scope: string;
package/src/gates.ts CHANGED
@@ -6,7 +6,6 @@ import { memoryRoot, canonicalFile } from "./config.ts";
6
6
  import { bracketList, parseLine, readLines } from "./logfmt.ts";
7
7
  import {
8
8
  appendMemory,
9
- loadAll,
10
9
  loadScope,
11
10
  markManySupersededReport,
12
11
  snapshotFiles,
@@ -16,6 +15,7 @@ import {
16
15
  } from "./memory.ts";
17
16
  import { chainId, contentHash, record, recordWriteBlocked } from "./evidence.ts";
18
17
  import { noteAuthored } from "./state.ts";
18
+ import { MAX_WRITE_EVIDENCE_REFS } from "./triggers.ts";
19
19
  import { flattenMemoryText } from "./sanitize.ts";
20
20
  import { containsSecret, redactSecrets } from "./secrets.ts";
21
21
  import { readerForSession } from "./memory.ts";
@@ -70,6 +70,9 @@ export const auditCaveat = (outcome: GateOutcome): string =>
70
70
  export interface GateContext {
71
71
  liveRoot: string;
72
72
  evidenceCalls: string[];
73
+ // Total before the telemetry window was selected. Legacy/direct callers
74
+ // may still supply their complete list; the writer bounds that too.
75
+ evidenceCallsCount?: number;
73
76
  hasGateCheck: boolean;
74
77
  // The session this write belongs to, when the caller knows it by name.
75
78
  // Repo-stamp resolution prefers it over the mutable global current, which
@@ -96,8 +99,9 @@ export interface GateContext {
96
99
  durable?: string[];
97
100
  }
98
101
 
99
- export interface GateOutcome {
100
- action: "promoted" | "blocked" | "collapsed";
102
+ // Shared optional fields remain readable by diagnostic callers before they
103
+ // narrow on action. The variants below require the fields each verdict owes.
104
+ interface GateOutcomeFields {
101
105
  reason?: string;
102
106
  ts?: string;
103
107
  chain: string;
@@ -116,6 +120,11 @@ export interface GateOutcome {
116
120
  collapsedWith?: string;
117
121
  }
118
122
 
123
+ export type GateOutcome =
124
+ | (GateOutcomeFields & { action: "promoted"; ts: string })
125
+ | (GateOutcomeFields & { action: "blocked"; reason: string })
126
+ | (GateOutcomeFields & { action: "collapsed" });
127
+
119
128
  const STOPWORDS = new Set([
120
129
  "use",
121
130
  "using",
@@ -753,7 +762,8 @@ export async function runWriteGate(
753
762
  ch,
754
763
  supersedes: supersededTs ?? "-",
755
764
  canonical: canon ? `canonical.logfmt:${canon.entry.ts}` : "-",
756
- evidence_refs: bracketList(ctx.evidenceCalls),
765
+ evidence_refs: bracketList(ctx.evidenceCalls.slice(-MAX_WRITE_EVIDENCE_REFS)),
766
+ evidence_refs_count: ctx.evidenceCallsCount ?? ctx.evidenceCalls.length,
757
767
  snapshot: snapshot[0] ?? "-",
758
768
  trusted: ctx.trusted ? true : undefined,
759
769
  grounded_by: groundedByEngagement ? "engagement" : undefined,
package/src/host.ts ADDED
@@ -0,0 +1,97 @@
1
+ // Compatibility boundary for host payloads. These adapters only read data;
2
+ // repository binding, ambient fallbacks, clocks, and I/O belong to the caller.
3
+ function fields(value: unknown): Record<string, unknown> {
4
+ return value !== null && typeof value === "object" ? value as Record<string, unknown> : {};
5
+ }
6
+
7
+ export interface ToolIdentity {
8
+ sessionID?: string;
9
+ callID?: string;
10
+ }
11
+
12
+ /** V2 ToolContext uses `id` for the call; absent/empty fields need a fallback. */
13
+ export function toolIdentity(context: unknown): ToolIdentity {
14
+ const { sessionID, id } = fields(context);
15
+ return {
16
+ sessionID: typeof sessionID === "string" && sessionID ? sessionID : undefined,
17
+ callID: typeof id === "string" && id ? id : undefined,
18
+ };
19
+ }
20
+
21
+ export interface SessionIdentity {
22
+ sessionID: string;
23
+ directory?: string;
24
+ }
25
+
26
+ /** A directory-less identity still lets the caller resolve the session row. */
27
+ export function sessionIdentityEvent(raw: unknown): SessionIdentity | undefined {
28
+ const event = fields(raw);
29
+ if (
30
+ event.type !== "session.created" &&
31
+ event.type !== "session.execution.started" &&
32
+ event.type !== "session.moved"
33
+ ) return undefined;
34
+ const data = fields(event.data ?? event.properties);
35
+ const info = fields(data.info ?? data);
36
+ const sessionID = info.sessionID ?? data.sessionID;
37
+ const directory = fields(info.location).directory ?? fields(data.location).directory
38
+ ?? fields(event.location).directory ?? info.directory;
39
+ if (typeof sessionID !== "string") return undefined;
40
+ return { sessionID, directory: typeof directory === "string" ? directory : undefined };
41
+ }
42
+
43
+ /** Legacy context messages sometimes carry location directly or inside info. */
44
+ export function sessionDirectoryFromMessages(messages: unknown): string | undefined {
45
+ if (!Array.isArray(messages)) return undefined;
46
+ for (const message of messages) {
47
+ const row = fields(message);
48
+ const directory = fields(row.location).directory ?? fields(fields(row.info).location).directory;
49
+ if (typeof directory === "string" && directory) return directory;
50
+ }
51
+ return undefined;
52
+ }
53
+
54
+ /** session.get returns either a row or a {data: row} response. */
55
+ export function sessionDirectoryFromRow(result: unknown): string | undefined {
56
+ const response = fields(result);
57
+ const row = fields(response.data ?? response);
58
+ const directory = fields(row.location).directory ?? row.directory;
59
+ return typeof directory === "string" && directory ? directory : undefined;
60
+ }
61
+
62
+ export interface SessionUsage {
63
+ sessionID: string;
64
+ input: number;
65
+ read: number;
66
+ write: number;
67
+ }
68
+
69
+ /** V2 session usage, or the assistant-message usage emitted by older hosts. */
70
+ export function sessionUsageEvent(raw: unknown): SessionUsage | undefined {
71
+ const event = fields(raw);
72
+ let info: Record<string, unknown>;
73
+ if (event.type === "session.usage.updated") {
74
+ info = fields(event.data);
75
+ } else if (event.type === "message.updated") {
76
+ info = fields(fields(event.properties).info ?? event.info ?? fields(event.data).info);
77
+ if (info.role !== "assistant") return undefined;
78
+ } else {
79
+ return undefined;
80
+ }
81
+ if (typeof info.sessionID !== "string" || !info.tokens) return undefined;
82
+ const tokens = fields(info.tokens);
83
+ const cache = fields(tokens.cache);
84
+ return {
85
+ sessionID: info.sessionID,
86
+ input: Number(tokens.input) || 0,
87
+ read: Number(cache.read) || 0,
88
+ write: Number(cache.write) || 0,
89
+ };
90
+ }
91
+
92
+ /** Session ID envelopes accepted by capture; trigger selection stays separate. */
93
+ export function captureSessionID(raw: unknown): string | undefined {
94
+ const event = fields(raw);
95
+ const sessionID = fields(event.data).sessionID ?? event.sessionID ?? fields(event.properties).sessionID;
96
+ return typeof sessionID === "string" ? sessionID : undefined;
97
+ }