opencode-self-improvement 0.33.9 → 0.33.11
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 +1 -1
- package/docs/internals/use-ledger.md +45 -4
- package/package.json +1 -1
- package/src/capture/attest.ts +168 -0
- package/src/capture/runtime.ts +112 -72
- package/src/consolidate/propose.ts +27 -29
- package/src/consolidate/render.ts +5 -1
- package/src/events.ts +128 -26
- package/src/index.ts +6 -3
- package/src/inject/pull-receipts.ts +215 -0
- package/src/inject/pull.ts +10 -9
- package/src/portable/decay.ts +4 -5
- package/src/status/report.ts +35 -2
- package/src/store/lock.ts +79 -101
- package/src/telemetry/ledger.ts +54 -6
- package/src/telemetry/record.ts +134 -0
- package/src/tools/merge-review.ts +70 -7
- package/src/tools/schema.ts +6 -0
- package/src/tools/status-tool.ts +4 -0
|
@@ -4,12 +4,17 @@ import type { ToolRegister } from "./deps.ts";
|
|
|
4
4
|
import { memoryRoot } from "../core/config/paths.ts";
|
|
5
5
|
import { record } from "../telemetry/record.ts";
|
|
6
6
|
import { withStoreBatch } from "../store/lock.ts";
|
|
7
|
-
import { loadAll } from "../store/files/load.ts";
|
|
7
|
+
import { loadAll, toMemory } from "../store/files/load.ts";
|
|
8
|
+
import { stampRow } from "../store/files/snapshots.ts";
|
|
9
|
+
import { formatLine } from "../core/logfmt/format.ts";
|
|
10
|
+
import {
|
|
11
|
+
absorbAliases,
|
|
12
|
+
sameConsolidationScope,
|
|
13
|
+
} from "../consolidate/propose.ts";
|
|
8
14
|
import { clearSuperseded, markSuperseded } from "../store/files/supersede.ts";
|
|
9
15
|
import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
|
|
10
|
-
import { isActive } from "../store/model/predicates.ts";
|
|
16
|
+
import { isActive, isInjectable } from "../store/model/predicates.ts";
|
|
11
17
|
import { MergeReviewArgs, validated } from "./schema.ts";
|
|
12
|
-
import { join } from "node:path";
|
|
13
18
|
|
|
14
19
|
export const register: ToolRegister = (editor, deps) => {
|
|
15
20
|
const { toolIds, bindSessionIdentity, direct } = deps;
|
|
@@ -55,6 +60,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
55
60
|
// A batch may publish the loser then refuse a later file. The sink
|
|
56
61
|
// records that publish before the overall promise settles.
|
|
57
62
|
const mergeDurable: string[] = [];
|
|
63
|
+
let consolidationStarted = false;
|
|
58
64
|
try {
|
|
59
65
|
return await withStoreBatch(
|
|
60
66
|
memoryRoot(),
|
|
@@ -126,6 +132,52 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
126
132
|
` after this review was written; reviving the survivor would erase that supersession. Nothing was done. No evidence written.`,
|
|
127
133
|
};
|
|
128
134
|
}
|
|
135
|
+
if (args.consolidate) {
|
|
136
|
+
if (
|
|
137
|
+
!isInjectable(loserRow) ||
|
|
138
|
+
!isInjectable(survivorRow) ||
|
|
139
|
+
loserRow.status === "open" ||
|
|
140
|
+
survivorRow.status === "open" ||
|
|
141
|
+
!sameConsolidationScope(loserRow, survivorRow) ||
|
|
142
|
+
all.filter(
|
|
143
|
+
(m) => m.ts === args.loser || m.ts === args.survivor,
|
|
144
|
+
).length !== 2
|
|
145
|
+
) {
|
|
146
|
+
return {
|
|
147
|
+
content:
|
|
148
|
+
"Consolidation blocked: the proposal requires two distinct, available settled rows of the same type, scope and repository. Run memory_consolidate again.",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// Publish the aliases first. If retirement fails, the loser
|
|
152
|
+
// remains searchable and reapplying the union is idempotent.
|
|
153
|
+
consolidationStarted = true;
|
|
154
|
+
const present = await stampRow(
|
|
155
|
+
survivorRow.file,
|
|
156
|
+
survivorRow.ts,
|
|
157
|
+
(fields) => {
|
|
158
|
+
const current = toMemory(
|
|
159
|
+
fields,
|
|
160
|
+
survivorRow.file,
|
|
161
|
+
survivorRow.index,
|
|
162
|
+
);
|
|
163
|
+
if (
|
|
164
|
+
!current ||
|
|
165
|
+
!isInjectable(current) ||
|
|
166
|
+
current.status === "open" ||
|
|
167
|
+
!sameConsolidationScope(current, loserRow)
|
|
168
|
+
) {
|
|
169
|
+
throw new Error("survivor changed since the proposal");
|
|
170
|
+
}
|
|
171
|
+
const merged = absorbAliases(current, loserRow);
|
|
172
|
+
const kw = merged.kw?.join(",");
|
|
173
|
+
const tags = merged.tags!.join(",");
|
|
174
|
+
if (fields.kw === kw && fields.tags === tags) return null;
|
|
175
|
+
return formatLine({ ...fields, kw, tags });
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
if (present === null)
|
|
179
|
+
throw new Error("survivor no longer exists");
|
|
180
|
+
}
|
|
129
181
|
const ok = await markSuperseded(
|
|
130
182
|
args.loser,
|
|
131
183
|
{
|
|
@@ -138,6 +190,11 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
138
190
|
mergeDurable,
|
|
139
191
|
);
|
|
140
192
|
if (!ok) {
|
|
193
|
+
if (args.consolidate)
|
|
194
|
+
return {
|
|
195
|
+
content:
|
|
196
|
+
"Consolidation incomplete: the survivor has its aliases, but the loser was unavailable for retirement. Run memory_consolidate again.",
|
|
197
|
+
};
|
|
141
198
|
return {
|
|
142
199
|
content:
|
|
143
200
|
"merge_review: loser not found or already superseded — nothing to resolve. No evidence written.",
|
|
@@ -149,10 +206,12 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
149
206
|
// but only the marker this review owns: the guard above
|
|
150
207
|
// already refused anything else, and this re-check runs under the
|
|
151
208
|
// file lock against the line as it is at mutation time.
|
|
152
|
-
const revived =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
209
|
+
const revived =
|
|
210
|
+
!args.consolidate &&
|
|
211
|
+
(await clearSuperseded(args.survivor, {
|
|
212
|
+
supersededBy: args.loser,
|
|
213
|
+
reason: args.reason,
|
|
214
|
+
}));
|
|
156
215
|
// The response has always claimed "Evidence recorded" — now it
|
|
157
216
|
// is true, and it names the session the merge ran FOR (
|
|
158
217
|
// residue on this line). The host tool_result hook covers
|
|
@@ -197,6 +256,10 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
197
256
|
// follow-up (evidence/revive), not a blanket "nothing was done".
|
|
198
257
|
const why = err instanceof Error ? err.message : String(err);
|
|
199
258
|
if (mergeDurable.length === 0) {
|
|
259
|
+
if (consolidationStarted)
|
|
260
|
+
return {
|
|
261
|
+
content: `Consolidation incomplete: no retirement confirmed. The survivor may already have the aliases. Retry after checking the store. ${why}`,
|
|
262
|
+
};
|
|
200
263
|
return {
|
|
201
264
|
content: `merge_review blocked: ${why} — nothing was done. Retry.`,
|
|
202
265
|
};
|
package/src/tools/schema.ts
CHANGED
|
@@ -147,6 +147,12 @@ export const EvidenceArgs = z.object({
|
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
export const MergeReviewArgs = z.object({
|
|
150
|
+
consolidate: z
|
|
151
|
+
.boolean()
|
|
152
|
+
.optional()
|
|
153
|
+
.describe(
|
|
154
|
+
"Apply a consolidation proposal, retaining the absorbed row's retrieval aliases on its same-scope survivor",
|
|
155
|
+
),
|
|
150
156
|
loser: z
|
|
151
157
|
.string()
|
|
152
158
|
.describe(
|
package/src/tools/status-tool.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
import { renderMemoryReport } from "../status/report.ts";
|
|
30
30
|
import { blockedRecent } from "../status/write.ts";
|
|
31
31
|
import { summarizeStore } from "../status/store-summary.ts";
|
|
32
|
+
import { droppedEvidenceWrites } from "../telemetry/record.ts";
|
|
32
33
|
|
|
33
34
|
export const register: ToolRegister = (editor, deps) => {
|
|
34
35
|
const { toolIds, sessions, direct } = deps;
|
|
@@ -91,6 +92,9 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
91
92
|
// capture state read from the same evidence window, so the
|
|
92
93
|
// chat surface distinguishes off / misconfigured / inert / alive.
|
|
93
94
|
capture: captureHealth(evidenceLines),
|
|
95
|
+
// Lost evidence writes cannot report themselves through the log, so
|
|
96
|
+
// this one number comes from this process instead.
|
|
97
|
+
evidence: droppedEvidenceWrites(),
|
|
94
98
|
}),
|
|
95
99
|
};
|
|
96
100
|
},
|