opencode-self-improvement 0.14.24 → 0.14.26
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/package.json +1 -1
- package/src/gates.ts +82 -43
- package/src/hits.ts +3 -0
- package/src/index.ts +49 -30
- package/src/lock.ts +8 -6
- package/src/logfmt.ts +6 -9
- package/src/memory.ts +35 -7
- package/src/prune.ts +16 -4
- package/src/schema.ts +4 -0
- package/src/tokenize.ts +208 -0
- package/src/tombstones.ts +454 -0
- package/src/viewer/mutate.ts +51 -6
- package/src/viewer/page.html +34 -1
- package/src/viewer/server.ts +27 -5
package/src/viewer/mutate.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// All mutations require a reason and write audit + evidence lines.
|
|
9
9
|
import { deletionsFile } from "../config.ts";
|
|
10
10
|
import { addBlock, removeBlock } from "../blocklist.ts";
|
|
11
|
-
import { record, chainId } from "../evidence.ts";
|
|
11
|
+
import { record, chainId, contentHash } from "../evidence.ts";
|
|
12
|
+
import { removeTombstone, tombstone } from "../tombstones.ts";
|
|
12
13
|
import { redactSecrets } from "../secrets.ts";
|
|
13
14
|
import { appendLog, fileIdentity, formatLine, parseLine, readLines, writeAtomic } from "../logfmt.ts";
|
|
14
15
|
import { withStoreLock, LOCK_WRITE } from "../lock.ts";
|
|
@@ -89,10 +90,15 @@ export async function editMemory(input: EditInput): Promise<MutationResult> {
|
|
|
89
90
|
repo: target.repo ?? "global",
|
|
90
91
|
repoPath: target.repo ? target.repoPath : undefined,
|
|
91
92
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const retired: string[] = [];
|
|
94
|
+
try {
|
|
95
|
+
await markSuperseded(input.ts, {
|
|
96
|
+
superseded_by: newTs,
|
|
97
|
+
reason: "human_edit",
|
|
98
|
+
}, retired);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
throw new Error(`viewer edit PARTIAL: replacement ${newTs} IS on disk; original ${input.ts} ${retired.includes(input.ts) ? "IS retired" : "was NOT retired by this edit"}. Stopped: ${String(err)}. Inspect the rows or use memory_undo before retrying.`);
|
|
101
|
+
}
|
|
96
102
|
await audit("edited", target, input.ts, newTs, input.reason);
|
|
97
103
|
await record("viewer_edit", {
|
|
98
104
|
chain,
|
|
@@ -188,4 +194,43 @@ async function audit(
|
|
|
188
194
|
);
|
|
189
195
|
}
|
|
190
196
|
|
|
191
|
-
|
|
197
|
+
// Blocking is a human rejection, so it tombstones the VALUE as well as hiding
|
|
198
|
+
// the row (#35): without that, re-ingesting the source stores the same content
|
|
199
|
+
// again under a fresh `ts` and the block silently stops protecting anything.
|
|
200
|
+
// Order matters — the block is what the operator asked for and lands first; a
|
|
201
|
+
// failure to tombstone leaves the row hidden (no data loss) rather than the
|
|
202
|
+
// reverse (row visible, rejection half-applied).
|
|
203
|
+
export async function blockMemory(input: { ts: string; reason: string }): Promise<string> {
|
|
204
|
+
requireReason(input.reason);
|
|
205
|
+
const mem = await findMemory(input.ts);
|
|
206
|
+
await addBlock(input.ts, input.reason);
|
|
207
|
+
await tombstone(mem.content, {
|
|
208
|
+
reason: redactSecrets(input.reason),
|
|
209
|
+
source: "block",
|
|
210
|
+
scope: mem.scope,
|
|
211
|
+
type: mem.type,
|
|
212
|
+
});
|
|
213
|
+
return input.ts;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Un-blocking withdraws the rejection, so it lifts the tombstone too — leaving
|
|
217
|
+
// it would mean the value stays refused while the row it was refused on is
|
|
218
|
+
// back in view. The tombstone is keyed on the value, so this withdraws the
|
|
219
|
+
// rejection of that content wherever else a copy of it was blocked; that is the
|
|
220
|
+
// same decision the tombstone made when it was written.
|
|
221
|
+
export async function unblockMemory(ts: string): Promise<boolean> {
|
|
222
|
+
const removed = await removeBlock(ts);
|
|
223
|
+
const mem = (await loadAll()).find((x) => x.ts === ts);
|
|
224
|
+
if (mem) await removeTombstone(contentHash(mem.content));
|
|
225
|
+
return removed;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// The explicit un-tombstone escape hatch (#35): lifts a rejection recorded by
|
|
229
|
+
// `forget`, which has no row left to un-block. Human-only — this is reachable
|
|
230
|
+
// from the viewer and deliberately from NO plugin tool, so a session whose
|
|
231
|
+
// write was refused cannot clear its own refusal and retry in the same turn.
|
|
232
|
+
export async function unrejectMemory(ch: string): Promise<boolean> {
|
|
233
|
+
return removeTombstone(ch);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { addBlock, removeBlock };
|
package/src/viewer/page.html
CHANGED
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
<span>superseded <b id="cSuper">0</b></span>
|
|
86
86
|
<span>blocked <b id="cBlocked">0</b></span>
|
|
87
87
|
<span>deleted <b id="cDeleted">0</b></span>
|
|
88
|
+
<span>rejected <b id="cRejected">0</b></span>
|
|
88
89
|
</div>
|
|
89
90
|
<span class="spacer"></span>
|
|
90
91
|
<code id="rootLabel" style="color:var(--muted);font-size:12px"></code>
|
|
@@ -102,6 +103,7 @@
|
|
|
102
103
|
<option value="superseded">superseded</option>
|
|
103
104
|
<option value="blocked">blocked</option>
|
|
104
105
|
<option value="deleted">deleted</option>
|
|
106
|
+
<option value="rejected">rejected values</option>
|
|
105
107
|
</select>
|
|
106
108
|
</div>
|
|
107
109
|
|
|
@@ -185,6 +187,7 @@ function currentList() {
|
|
|
185
187
|
const fus = $("fStatus").value;
|
|
186
188
|
if (fus === "blocked") return { list: DATA.blocked, kind: "blocked" };
|
|
187
189
|
if (fus === "deleted") return { list: DATA.deleted, kind: "deleted" };
|
|
190
|
+
if (fus === "rejected") return { list: DATA.rejections, kind: "rejected" };
|
|
188
191
|
if (fus === "superseded") return { list: DATA.memories.filter((m) => m.superseded_by), kind: "superseded" };
|
|
189
192
|
if (fus === "all") return { list: DATA.memories, kind: "all" };
|
|
190
193
|
return { list: DATA.memories.filter((m) => !m.superseded_by), kind: "active" };
|
|
@@ -199,7 +202,24 @@ function render() {
|
|
|
199
202
|
let rows = list.slice();
|
|
200
203
|
if (fs) rows = rows.filter((m) => m.scope === fs);
|
|
201
204
|
if (ft) rows = rows.filter((m) => m.type === ft);
|
|
202
|
-
if (q) rows = rows.filter((m) => `${m.type} ${m.scope} ${m.content}`.toLowerCase().includes(q));
|
|
205
|
+
if (q) rows = rows.filter((m) => `${m.type} ${m.scope} ${m.content ?? m.ch ?? ""}`.toLowerCase().includes(q));
|
|
206
|
+
|
|
207
|
+
// Rejected VALUES (#35) have no row and no prose — the tombstone stores a
|
|
208
|
+
// hash by design, so they get their own row shape rather than pretending to
|
|
209
|
+
// be memories with an empty content cell.
|
|
210
|
+
if (kind === "rejected") {
|
|
211
|
+
$("rows").innerHTML = rows.map((t) => `<tr>
|
|
212
|
+
<td class="ts">${esc(t.rejected_at)}</td>
|
|
213
|
+
<td>${badge("type", t.type || "-")}</td>
|
|
214
|
+
<td>${badge("scope", t.scope || "-")}</td>
|
|
215
|
+
<td class="content"><code>${esc(t.ch)}</code> ${esc(t.reason || "(no reason recorded)")} <span style="color:var(--muted)">· rejected via ${esc(t.source)}</span></td>
|
|
216
|
+
<td>${badge("status-blocked", "rejected")}</td>
|
|
217
|
+
<td class="actions"><button class="btn warn" data-action="un-reject" data-ch="${esc(t.ch)}" title="Lift this rejection so the value can be stored again">un-reject</button></td>
|
|
218
|
+
</tr>`).join("");
|
|
219
|
+
$("empty").style.display = rows.length ? "none" : "block";
|
|
220
|
+
$("cRejected").textContent = DATA.rejections.length;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
203
223
|
|
|
204
224
|
$("rows").innerHTML = rows.map((m) => {
|
|
205
225
|
const status = kind === "blocked" ? "blocked" : kind === "deleted" ? "deleted"
|
|
@@ -228,6 +248,7 @@ function render() {
|
|
|
228
248
|
$("cSuper").textContent = DATA.memories.filter((m) => m.superseded_by).length;
|
|
229
249
|
$("cBlocked").textContent = DATA.blocked.length;
|
|
230
250
|
$("cDeleted").textContent = DATA.deleted.length;
|
|
251
|
+
$("cRejected").textContent = DATA.rejections.length;
|
|
231
252
|
}
|
|
232
253
|
|
|
233
254
|
async function refresh() {
|
|
@@ -306,6 +327,17 @@ async function unblock(ts) {
|
|
|
306
327
|
} catch (e) { toast(String(e.message), true); }
|
|
307
328
|
}
|
|
308
329
|
|
|
330
|
+
// The human-only escape hatch for #35. No confirmation prompt asking "why": the
|
|
331
|
+
// operator already owns the store, and a rejection they are lifting is by
|
|
332
|
+
// definition one they no longer agree with.
|
|
333
|
+
async function unreject(ch) {
|
|
334
|
+
try {
|
|
335
|
+
await api("/api/unreject", { ch });
|
|
336
|
+
toast(`rejection lifted for ${ch} — the value can be stored again`);
|
|
337
|
+
await refresh();
|
|
338
|
+
} catch (e) { toast(String(e.message), true); }
|
|
339
|
+
}
|
|
340
|
+
|
|
309
341
|
function restoreEntry(type, scope, content, repo, repoPath) {
|
|
310
342
|
askModal(
|
|
311
343
|
"Restore deleted memory?",
|
|
@@ -337,6 +369,7 @@ $("rows").addEventListener("click", (e) => {
|
|
|
337
369
|
else if (action === "delete") del(ts);
|
|
338
370
|
else if (action === "block") block(ts);
|
|
339
371
|
else if (action === "unblock") unblock(ts);
|
|
372
|
+
else if (action === "un-reject") unreject(btn.dataset.ch);
|
|
340
373
|
else if (action === "restore-deleted") {
|
|
341
374
|
const { type, scope, content, repo, repoPath } = btn.dataset;
|
|
342
375
|
restoreEntry(type, scope, content, repo, repoPath);
|
package/src/viewer/server.ts
CHANGED
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
import { basename, join } from "node:path";
|
|
8
8
|
import { serve, type Server } from "bun";
|
|
9
9
|
import { z, type ZodTypeAny } from "zod";
|
|
10
|
-
import { BlockBody, DeleteBody, EditBody, RestoreEntryBody, UnblockBody } from "../schema.ts";
|
|
10
|
+
import { BlockBody, DeleteBody, EditBody, RestoreEntryBody, UnblockBody, UnrejectBody } from "../schema.ts";
|
|
11
11
|
import { deletionsFile, memoryRoot, snapshotDir } from "../config.ts";
|
|
12
12
|
import { blockedEntries } from "../blocklist.ts";
|
|
13
13
|
import { listSnapshots, restoreSnapshot } from "../undo.ts";
|
|
14
14
|
import { appendMemory, loadAll, memoryFiles } from "../memory.ts";
|
|
15
15
|
import { parseLine, readLines } from "../logfmt.ts";
|
|
16
|
-
import { deleteMemory, editMemory,
|
|
16
|
+
import { deleteMemory, editMemory, blockMemory, unblockMemory, unrejectMemory, type MutationResult } from "./mutate.ts";
|
|
17
|
+
import { tombstones } from "../tombstones.ts";
|
|
17
18
|
|
|
18
19
|
const PAGE = join(import.meta.dir, "page.html");
|
|
19
20
|
const HOST = process.env.OPENCODE_VIEWER_HOST || "127.0.0.1";
|
|
@@ -174,11 +175,12 @@ export async function startViewer(port: number = PORT): Promise<ViewerServer> {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
async function loaded(): Promise<Record<string, unknown>> {
|
|
177
|
-
const [memories, blocked, deleted, snaps] = await Promise.all([
|
|
178
|
+
const [memories, blocked, deleted, snaps, rejections] = await Promise.all([
|
|
178
179
|
loadAll(),
|
|
179
180
|
blockedRows(),
|
|
180
181
|
deletedRows(),
|
|
181
182
|
listSnapshots(),
|
|
183
|
+
tombstones(),
|
|
182
184
|
]);
|
|
183
185
|
const blockedByTs = new Set(blocked.map((b) => b.ts));
|
|
184
186
|
return {
|
|
@@ -200,6 +202,18 @@ async function loaded(): Promise<Record<string, unknown>> {
|
|
|
200
202
|
})),
|
|
201
203
|
blocked,
|
|
202
204
|
deleted,
|
|
205
|
+
// #35: the value-keyed rejections. Hashes and metadata only — the store
|
|
206
|
+
// never held the prose, so there is nothing to reveal here either. The
|
|
207
|
+
// sketch is omitted: it is matching machinery, not something a reader can
|
|
208
|
+
// act on.
|
|
209
|
+
rejections: rejections.map((t) => ({
|
|
210
|
+
ch: t.ch,
|
|
211
|
+
reason: t.reason,
|
|
212
|
+
source: t.source,
|
|
213
|
+
scope: t.scope ?? "",
|
|
214
|
+
type: t.type ?? "",
|
|
215
|
+
rejected_at: t.rejected_at,
|
|
216
|
+
})),
|
|
203
217
|
snapshots: snaps.map((s) => ({ name: s.name, bytes: s.bytes })),
|
|
204
218
|
};
|
|
205
219
|
}
|
|
@@ -211,6 +225,7 @@ async function route(req: Request, url: URL): Promise<Response> {
|
|
|
211
225
|
if (url.pathname === "/api/delete") return parseWith(DeleteBody, body, deleteRoute);
|
|
212
226
|
if (url.pathname === "/api/block") return parseWith(BlockBody, body, blockRoute);
|
|
213
227
|
if (url.pathname === "/api/unblock") return parseWith(UnblockBody, body, unblockRoute);
|
|
228
|
+
if (url.pathname === "/api/unreject") return parseWith(UnrejectBody, body, unrejectRoute);
|
|
214
229
|
if (url.pathname === "/api/restore-entry") return parseWith(RestoreEntryBody, body, restoreEntryRoute);
|
|
215
230
|
// /api/restore is deliberately NOT schema-parsed here: its name check is
|
|
216
231
|
// basename + pinned-grammar CONTAINMENT, not a shape gate,
|
|
@@ -258,11 +273,18 @@ async function deleteRoute(body: z.infer<typeof DeleteBody>): Promise<Response>
|
|
|
258
273
|
}
|
|
259
274
|
|
|
260
275
|
async function blockRoute(body: z.infer<typeof BlockBody>): Promise<Response> {
|
|
261
|
-
return json({ ts: await
|
|
276
|
+
return json({ ts: await blockMemory(body) });
|
|
262
277
|
}
|
|
263
278
|
|
|
264
279
|
async function unblockRoute(body: z.infer<typeof UnblockBody>): Promise<Response> {
|
|
265
|
-
return json({ unblocked: await
|
|
280
|
+
return json({ unblocked: await unblockMemory(body.ts) });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// The only way a rejection is ever lifted (#35). Human-only: the plugin exposes
|
|
284
|
+
// no tool for this, so a session whose write was refused cannot clear the
|
|
285
|
+
// refusal and re-submit the rejected value.
|
|
286
|
+
async function unrejectRoute(body: z.infer<typeof UnrejectBody>): Promise<Response> {
|
|
287
|
+
return json({ unrejected: await unrejectMemory(body.ch) });
|
|
266
288
|
}
|
|
267
289
|
|
|
268
290
|
async function restoreEntryRoute(body: z.infer<typeof RestoreEntryBody>): Promise<Response> {
|