opencode-self-improvement 0.15.17 → 0.15.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.
Files changed (93) hide show
  1. package/README.md +4 -0
  2. package/package.json +4 -2
  3. package/src/capture/candidates.ts +17 -6
  4. package/src/capture/lag.ts +6 -2
  5. package/src/capture/prompt.ts +1 -1
  6. package/src/capture/runtime.ts +85 -21
  7. package/src/capture/session-model.ts +2 -1
  8. package/src/capture/transcript.ts +10 -4
  9. package/src/capture/triggers.ts +48 -14
  10. package/src/command/ensure.ts +6 -1
  11. package/src/consolidate/propose.ts +47 -17
  12. package/src/consolidate/render.ts +3 -1
  13. package/src/core/cmp-ts.ts +2 -2
  14. package/src/core/config/budgets.ts +0 -1
  15. package/src/core/config/paths.ts +2 -3
  16. package/src/core/hooks.ts +8 -3
  17. package/src/core/host.ts +8 -3
  18. package/src/core/logfmt/format.ts +20 -5
  19. package/src/core/logfmt/publish.ts +21 -4
  20. package/src/core/lru.ts +20 -20
  21. package/src/core/permissions.ts +21 -5
  22. package/src/core/runtime.ts +7 -3
  23. package/src/core/state.ts +12 -2
  24. package/src/core/time.ts +0 -1
  25. package/src/core/tokenize.ts +16 -5
  26. package/src/core/types.ts +8 -1
  27. package/src/events.ts +74 -18
  28. package/src/evidence/record.ts +29 -9
  29. package/src/gate/gate.ts +208 -64
  30. package/src/gate/resolver.ts +105 -20
  31. package/src/hits/ledger.ts +35 -10
  32. package/src/identity/host-events.ts +35 -11
  33. package/src/identity/repokey.ts +27 -9
  34. package/src/identity/session-context.ts +39 -8
  35. package/src/index.ts +108 -42
  36. package/src/init/detect.ts +62 -12
  37. package/src/init/run.ts +50 -11
  38. package/src/inject/anchor.ts +11 -5
  39. package/src/inject/attribution.ts +29 -6
  40. package/src/inject/budget.ts +9 -2
  41. package/src/inject/digest.ts +16 -8
  42. package/src/inject/epochs.ts +43 -15
  43. package/src/inject/pull.ts +11 -5
  44. package/src/inject/version.ts +10 -5
  45. package/src/portable/decay.ts +20 -9
  46. package/src/portable/export.ts +30 -10
  47. package/src/portable/import.ts +43 -12
  48. package/src/recall/relevant.ts +11 -5
  49. package/src/recall/score.ts +5 -3
  50. package/src/status/format.ts +8 -2
  51. package/src/status/metrics.ts +22 -6
  52. package/src/status/payload.ts +7 -2
  53. package/src/status/report.ts +63 -18
  54. package/src/status/write.ts +21 -7
  55. package/src/store/blocklist.ts +16 -4
  56. package/src/store/containment.ts +27 -8
  57. package/src/store/files/append.ts +57 -37
  58. package/src/store/files/deletions.ts +5 -2
  59. package/src/store/files/load.ts +37 -11
  60. package/src/store/files/prune.ts +18 -5
  61. package/src/store/files/snapshots.ts +6 -2
  62. package/src/store/files/supersede.ts +32 -12
  63. package/src/store/files/target.ts +4 -1
  64. package/src/store/lock.ts +10 -2
  65. package/src/store/model/visibility.ts +26 -6
  66. package/src/store/prune.ts +1 -1
  67. package/src/store/quarantine/quarantine.ts +36 -9
  68. package/src/store/quarantine/release.ts +9 -3
  69. package/src/store/secrets.ts +4 -2
  70. package/src/store/tombstones/rejection.ts +21 -5
  71. package/src/store/tombstones/tombstone.ts +48 -11
  72. package/src/store/undo.ts +43 -18
  73. package/src/tools/consolidate.ts +18 -8
  74. package/src/tools/decay.ts +37 -9
  75. package/src/tools/deps.ts +10 -2
  76. package/src/tools/evidence.ts +7 -4
  77. package/src/tools/export.ts +10 -4
  78. package/src/tools/forget.ts +15 -5
  79. package/src/tools/import.ts +16 -5
  80. package/src/tools/init.ts +13 -4
  81. package/src/tools/list.ts +12 -6
  82. package/src/tools/merge-review.ts +52 -20
  83. package/src/tools/recall.ts +17 -9
  84. package/src/tools/registry.ts +4 -1
  85. package/src/tools/remember.ts +21 -7
  86. package/src/tools/schema.ts +55 -18
  87. package/src/tools/status-tool.ts +29 -11
  88. package/src/tools/undo.ts +23 -8
  89. package/src/tools/update.ts +116 -40
  90. package/src/tui/panel.tsx +119 -30
  91. package/src/viewer/mutate.ts +57 -20
  92. package/src/viewer/rejections.ts +1 -1
  93. package/src/viewer/server.ts +88 -28
package/src/events.ts CHANGED
@@ -8,9 +8,20 @@ import type { HitSource } from "./hits/ledger.ts";
8
8
  import type { Memory } from "./store/model/memory.ts";
9
9
  import { useSignals } from "./hits/ledger.ts";
10
10
  import { setCurrent } from "./core/state.ts";
11
- import { bindSessionProvisional, rememberSessionDir } from "./identity/repokey.ts";
12
- import { sessionIdentityEvent, sessionUsageEvent } from "./identity/host-events.ts";
13
- import { afterTool, markTurn, checkNewSession, onCompacting } from "./capture/triggers.ts";
11
+ import {
12
+ bindSessionProvisional,
13
+ rememberSessionDir,
14
+ } from "./identity/repokey.ts";
15
+ import {
16
+ sessionIdentityEvent,
17
+ sessionUsageEvent,
18
+ } from "./identity/host-events.ts";
19
+ import {
20
+ afterTool,
21
+ markTurn,
22
+ checkNewSession,
23
+ onCompacting,
24
+ } from "./capture/triggers.ts";
14
25
  import { recordSessionModel } from "./capture/session-model.ts";
15
26
  import { contextualPull } from "./inject/pull.ts";
16
27
  import { pullQuery } from "./recall/relevant.ts";
@@ -21,12 +32,19 @@ interface HookDependencies {
21
32
  sessions: ReturnType<typeof createInjectionEpochs>;
22
33
  instanceDir: string | undefined;
23
34
  budget: number;
24
- noteHits: (src: HitSource, sid: string, rows: Memory[], query: string) => Promise<void>;
35
+ noteHits: (
36
+ src: HitSource,
37
+ sid: string,
38
+ rows: Memory[],
39
+ query: string,
40
+ ) => Promise<void>;
25
41
  bindSessionIdentity: (sid: string | undefined) => Promise<void>;
26
42
  bindSessionFromApi: (sid: string | undefined) => Promise<void>;
27
43
  measuredTurns: Map<string, Measured>;
28
44
  flushStatus: (sid: string) => Promise<void>;
29
- getCompactCapture: () => ((sid: string, messages: unknown) => void) | undefined;
45
+ getCompactCapture: () =>
46
+ | ((sid: string, messages: unknown) => void)
47
+ | undefined;
30
48
  }
31
49
 
32
50
  // Best-effort extraction of a tool's textual output + metadata from the V2
@@ -57,8 +75,18 @@ function resultMeta(result: unknown): Record<string, unknown> {
57
75
 
58
76
  export async function registerHooks(
59
77
  ctx: PluginCtx,
60
- { guarded, sessions, instanceDir, budget, noteHits, bindSessionIdentity,
61
- bindSessionFromApi, measuredTurns, flushStatus, getCompactCapture }: HookDependencies,
78
+ {
79
+ guarded,
80
+ sessions,
81
+ instanceDir,
82
+ budget,
83
+ noteHits,
84
+ bindSessionIdentity,
85
+ bindSessionFromApi,
86
+ measuredTurns,
87
+ flushStatus,
88
+ getCompactCapture,
89
+ }: HookDependencies,
62
90
  ) {
63
91
  // Bookkeeping: track the active session/tool/call before a tool runs.
64
92
  await ctx.tool?.hook("execute.before", (event: any) =>
@@ -87,14 +115,33 @@ export async function registerHooks(
87
115
  if (typeof event?.sessionID === "string") {
88
116
  bindSessionProvisional(event.sessionID, instanceDir);
89
117
  }
90
- const out = { output: resultText(event?.result), metadata: resultMeta(event?.result) };
118
+ const out = {
119
+ output: resultText(event?.result),
120
+ metadata: resultMeta(event?.result),
121
+ };
91
122
  await afterTool(input, out);
92
- const pulled = await contextualPull(input, out as { output?: unknown }, budget, await useSignals());
93
- if (pulled.length) await noteHits("pull", String(event?.sessionID ?? ""), pulled, pullQuery(input.args));
123
+ const pulled = await contextualPull(
124
+ input,
125
+ out as { output?: unknown },
126
+ budget,
127
+ await useSignals(),
128
+ );
129
+ if (pulled.length)
130
+ await noteHits(
131
+ "pull",
132
+ String(event?.sessionID ?? ""),
133
+ pulled,
134
+ pullQuery(input.args),
135
+ );
94
136
  // Write a contextual-pull append back when the tool result is text we own.
95
- if (event?.result && typeof event.result === "object" && typeof event.result.content === "string") {
137
+ if (
138
+ event?.result &&
139
+ typeof event.result === "object" &&
140
+ typeof event.result.content === "string"
141
+ ) {
96
142
  const text = resultText(event.result);
97
- if (out.output && out.output !== text) event.result.content = out.output;
143
+ if (out.output && out.output !== text)
144
+ event.result.content = out.output;
98
145
  }
99
146
  }),
100
147
  );
@@ -106,7 +153,8 @@ export async function registerHooks(
106
153
  // the sid is captured from the event BEFORE any await and carried
107
154
  // explicitly — the global current set here is legacy bookkeeping
108
155
  // only, never the identity this flow filters with (#127).
109
- const sid = typeof event?.sessionID === "string" ? event.sessionID : undefined;
156
+ const sid =
157
+ typeof event?.sessionID === "string" ? event.sessionID : undefined;
110
158
  setCurrent({ sessionID: event?.sessionID });
111
159
  if (typeof sid === "string") sessions.touch(sid);
112
160
  // #139: SessionRequest declares a readonly model, so the host already
@@ -120,7 +168,9 @@ export async function registerHooks(
120
168
  // already bound firmly in production, so no host lookup belongs in
121
169
  // this hot path (#127).
122
170
  if (typeof sid === "string") bindSessionProvisional(sid, instanceDir);
123
- await sessions.deliver(sid, (text) => event?.system?.push?.({ type: "text", text }));
171
+ await sessions.deliver(sid, (text) =>
172
+ event?.system?.push?.({ type: "text", text }),
173
+ );
124
174
  }),
125
175
  );
126
176
 
@@ -155,7 +205,8 @@ export async function registerHooks(
155
205
  // while it still exists, BEFORE the summarizer replaces it.
156
206
  await ctx.session?.hook("compaction", (event: any) =>
157
207
  guarded("session.compaction (onCompacting)", async () => {
158
- const sid = typeof event?.sessionID === "string" ? event.sessionID : undefined;
208
+ const sid =
209
+ typeof event?.sessionID === "string" ? event.sessionID : undefined;
159
210
  setCurrent({ sessionID: event?.sessionID });
160
211
  // The anchor read and the capture pass below partition by the session's
161
212
  // repository; SYNC provisional bind only — a host lookup from this
@@ -193,7 +244,9 @@ export async function registerHooks(
193
244
  const eventApi = ctx.event;
194
245
  void (async () => {
195
246
  try {
196
- for await (const raw of eventApi.subscribe({ signal: measuredController.signal })) {
247
+ for await (const raw of eventApi.subscribe({
248
+ signal: measuredController.signal,
249
+ })) {
197
250
  // Session identity: created fires for new sessions, execution.started
198
251
  // every turn (covers sessions resumed across a restart), moved on a
199
252
  // workspace change. Stamps and visibility resolve through this.
@@ -203,7 +256,8 @@ export async function registerHooks(
203
256
  if (dir !== undefined) rememberSessionDir(sid, dir);
204
257
  // 2.1.4 serve sends execution.started with no location at all:
205
258
  // resolve the session row instead of leaving the session unbound.
206
- else void guarded("session bind (api)", () => bindSessionFromApi(sid));
259
+ else
260
+ void guarded("session bind (api)", () => bindSessionFromApi(sid));
207
261
  continue;
208
262
  }
209
263
  const usage = sessionUsageEvent(raw);
@@ -216,7 +270,9 @@ export async function registerHooks(
216
270
  read,
217
271
  write,
218
272
  });
219
- await guarded("status flush (measured)", () => flushStatus(sessionID));
273
+ await guarded("status flush (measured)", () =>
274
+ flushStatus(sessionID),
275
+ );
220
276
  }
221
277
  } catch {
222
278
  // the subscription ended (abort or host error); nothing to do
@@ -4,11 +4,15 @@
4
4
  import { existsSync, realpathSync } from "node:fs";
5
5
  import { dirname, join, resolve } from "node:path";
6
6
  import { createHash } from "node:crypto";
7
- import { evidenceDir } from "../core/config/paths.ts"
7
+ import { evidenceDir } from "../core/config/paths.ts";
8
8
  import { dateStr } from "../core/time.ts";
9
- import { formatLine } from "../core/logfmt/format.ts"
9
+ import { formatLine } from "../core/logfmt/format.ts";
10
10
  import { appendLog } from "../core/logfmt/publish.ts";
11
- import { repoScope, sessionScope, type RepoScope } from "../identity/repokey.ts";
11
+ import {
12
+ repoScope,
13
+ sessionScope,
14
+ type RepoScope,
15
+ } from "../identity/repokey.ts";
12
16
  import { getCurrent } from "../core/state.ts";
13
17
  import { redactSecrets } from "../store/secrets.ts";
14
18
 
@@ -27,7 +31,11 @@ export function evidenceFileFor(date?: string): string | null {
27
31
  if (!m) return null;
28
32
  const [y, mo, day] = [Number(m[1]), Number(m[2]), Number(m[3])];
29
33
  const probe = new Date(Date.UTC(y, mo - 1, day));
30
- if (probe.getUTCFullYear() !== y || probe.getUTCMonth() !== mo - 1 || probe.getUTCDate() !== day) {
34
+ if (
35
+ probe.getUTCFullYear() !== y ||
36
+ probe.getUTCMonth() !== mo - 1 ||
37
+ probe.getUTCDate() !== day
38
+ ) {
31
39
  return null;
32
40
  }
33
41
  const dir = resolve(evidenceDir());
@@ -36,7 +44,8 @@ export function evidenceFileFor(date?: string): string | null {
36
44
  if (existsSync(file)) {
37
45
  // A day file symlinked out of the store still has to land inside it.
38
46
  try {
39
- if (realpathSync(file) !== join(realpathSync(dir), `${d}.logfmt`)) return null;
47
+ if (realpathSync(file) !== join(realpathSync(dir), `${d}.logfmt`))
48
+ return null;
40
49
  } catch {
41
50
  return null; // an unreadable link is not a file we will follow
42
51
  }
@@ -79,7 +88,8 @@ export function captureEvidenceContext(sessionID?: string): EvidenceContext {
79
88
  // Normal tool hooks setCurrent before execute; this snapshot never guesses
80
89
  // a missing operation call from a later hook. See #121 for identity context.
81
90
  const sid = sessionID ?? cur.sid;
82
- const call = sessionID !== undefined && sessionID !== cur.sid ? undefined : cur.call;
91
+ const call =
92
+ sessionID !== undefined && sessionID !== cur.sid ? undefined : cur.call;
83
93
  // Read-side partitioning of the shared log (#131's rule, applied to
84
94
  // evidence; the re-review closed the last two gaps in it). A NAMED session
85
95
  // is stamped from its OWN resolved scope only — the module scope is never
@@ -94,7 +104,11 @@ export function captureEvidenceContext(sessionID?: string): EvidenceContext {
94
104
  // scope-less process) keep their historical global reading.
95
105
  const named = typeof sid === "string" && sid !== "" && sid !== "?";
96
106
  const scope = named ? sessionScope(sid) : repoScope();
97
- return Object.freeze({ sid, call, scope: scope ? Object.freeze({ ...scope }) : null });
107
+ return Object.freeze({
108
+ sid,
109
+ call,
110
+ scope: scope ? Object.freeze({ ...scope }) : null,
111
+ });
98
112
  }
99
113
 
100
114
  export async function record(
@@ -111,7 +125,11 @@ export async function record(
111
125
  // A captured unresolved owner still needs a privacy label: without sid or
112
126
  // repo, evidenceVisibleTo treats a line as legacy/global. Suppress call
113
127
  // metadata as requested, but never turn an explicit private owner global.
114
- ...(includeContext ? { sid, call } : context && !scope && sid && sid !== "?" ? { sid } : {}),
128
+ ...(includeContext
129
+ ? { sid, call }
130
+ : context && !scope && sid && sid !== "?"
131
+ ? { sid }
132
+ : {}),
115
133
  ...(scope ? { repo: scope.key, repoPath: scope.path } : {}),
116
134
  ...scrubFields(fields),
117
135
  });
@@ -150,7 +168,9 @@ export async function recordCaptureLag(
150
168
  "capture_lag",
151
169
  {
152
170
  session,
153
- ...(lagMs !== null && Number.isFinite(lagMs) && lagMs >= 0 ? { lag: Math.round(lagMs) } : {}),
171
+ ...(lagMs !== null && Number.isFinite(lagMs) && lagMs >= 0
172
+ ? { lag: Math.round(lagMs) }
173
+ : {}),
154
174
  outcome,
155
175
  ...(model ? { model } : {}),
156
176
  },