opencode-self-improvement 0.15.22 → 0.15.23
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/package.json +1 -1
- package/src/store/files/deletions.ts +10 -0
- package/src/tools/schema.ts +9 -0
- package/src/viewer/mutate.ts +8 -0
- package/src/viewer/page.html +17 -5
- package/src/viewer/server.ts +123 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.23",
|
|
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": {
|
|
@@ -28,6 +28,16 @@ export async function logDeletion(
|
|
|
28
28
|
// stamp writes no stamp here — the legacy global path, unchanged.
|
|
29
29
|
repo: memory.repo,
|
|
30
30
|
repoPath: memory.repoPath,
|
|
31
|
+
// #207: the visibility- and provenance-bearing metadata survives here
|
|
32
|
+
// too. tags carry the quarantine marker, so a restore that reads this
|
|
33
|
+
// line cannot silently release quarantine; issue and kw keep provenance
|
|
34
|
+
// and recall aliases alive; status keeps an open thread open. Comma-
|
|
35
|
+
// joined scalars match the memory line, and a row without them writes
|
|
36
|
+
// nothing — the legacy fallback the restore documents.
|
|
37
|
+
tags: memory.tags?.length ? memory.tags.join(",") : undefined,
|
|
38
|
+
kw: memory.kw?.length ? memory.kw.join(",") : undefined,
|
|
39
|
+
issue: memory.issue,
|
|
40
|
+
status: memory.status,
|
|
31
41
|
reason: redactSecrets(reason),
|
|
32
42
|
}),
|
|
33
43
|
);
|
package/src/tools/schema.ts
CHANGED
|
@@ -244,7 +244,16 @@ export const UnrejectBody = z.object({
|
|
|
244
244
|
// repo/repoPath (#129): the origin stamp of the DELETED row, replayed from the
|
|
245
245
|
// audit line so a restore-entry keeps the row's original visibility instead of
|
|
246
246
|
// silently landing global. Both absent = the documented legacy global restore.
|
|
247
|
+
// ts (#207): identity of the deleted row. The server resolves the row's
|
|
248
|
+
// metadata (tags/kw/issue/status, and the origin stamp) from the deletion
|
|
249
|
+
// audit line itself — by ts when present, falling back to type/scope/content
|
|
250
|
+
// when that ts matches no audit line, else directly by type/scope/content —
|
|
251
|
+
// so the client can neither launder a quarantined row into an injectable one
|
|
252
|
+
// nor forge a provenance the audit does not carry. The client-replay fallback
|
|
253
|
+
// above applies only to rows the audit does not carry at all. The metadata
|
|
254
|
+
// fields are deliberately NOT in this schema.
|
|
247
255
|
export const RestoreEntryBody = z.object({
|
|
256
|
+
ts: isoTs.optional(),
|
|
248
257
|
type: z.enum(TYPES),
|
|
249
258
|
scope: memoryField.min(1),
|
|
250
259
|
content: z.string().min(1),
|
package/src/viewer/mutate.ts
CHANGED
|
@@ -209,6 +209,14 @@ async function audit(
|
|
|
209
209
|
// legacy/unstamped case — restore leaves it global, as documented.
|
|
210
210
|
repo: mem.repo,
|
|
211
211
|
repoPath: mem.repoPath,
|
|
212
|
+
// #207: tags (which carry quarantine), kw, issue and status survive the
|
|
213
|
+
// same way, so restoring a deleted row cannot silently release
|
|
214
|
+
// quarantine or drop provenance. Absent metadata writes nothing — the
|
|
215
|
+
// legacy fallback the restore path documents.
|
|
216
|
+
tags: mem.tags?.length ? mem.tags.join(",") : undefined,
|
|
217
|
+
kw: mem.kw?.length ? mem.kw.join(",") : undefined,
|
|
218
|
+
issue: mem.issue,
|
|
219
|
+
status: mem.status,
|
|
212
220
|
// Same write-boundary rule as evidence (#128): an audit reason is
|
|
213
221
|
// human prose and must not persist a recognized credential.
|
|
214
222
|
reason: redactSecrets(reason),
|
package/src/viewer/page.html
CHANGED
|
@@ -228,6 +228,12 @@ function render() {
|
|
|
228
228
|
: m.superseded_by ? "superseded" : m.quarantined ? "quarantined" : "active";
|
|
229
229
|
const stBadge = status === "superseded" ? badge("status-superseded", "superseded \u2192 " + m.superseded_by.slice(0,8))
|
|
230
230
|
: badge("status-" + status, status);
|
|
231
|
+
// #207: a deleted row that was quarantined must SAY so next to its
|
|
232
|
+
// deleted badge — restore keeps the quarantine, and the operator must
|
|
233
|
+
// see both facts before clicking.
|
|
234
|
+
const stCell = kind === "deleted" && m.quarantined
|
|
235
|
+
? stBadge + " " + badge("status-quarantined", "quarantined")
|
|
236
|
+
: stBadge;
|
|
231
237
|
const actions = kind === "blocked"
|
|
232
238
|
? `<button class="btn warn" data-action="unblock" data-ts="${esc(m.ts)}" title="Restore this memory to the read paths">unblock</button>`
|
|
233
239
|
: kind === "deleted"
|
|
@@ -241,7 +247,7 @@ function render() {
|
|
|
241
247
|
<td>${badge("type", m.type)}</td>
|
|
242
248
|
<td>${badge("scope", m.scope)}</td>
|
|
243
249
|
<td class="content">${esc(m.content)}</td>
|
|
244
|
-
<td>${
|
|
250
|
+
<td>${stCell}</td>
|
|
245
251
|
<td class="actions">${actions}</td>
|
|
246
252
|
</tr>`;
|
|
247
253
|
}).join("");
|
|
@@ -357,16 +363,21 @@ async function unreject(ch) {
|
|
|
357
363
|
} catch (e) { toast(String(e.message), true); }
|
|
358
364
|
}
|
|
359
365
|
|
|
360
|
-
function restoreEntry(type, scope, content, repo, repoPath) {
|
|
366
|
+
function restoreEntry(ts, type, scope, content, repo, repoPath, quarantined) {
|
|
361
367
|
askModal(
|
|
362
368
|
"Restore deleted memory?",
|
|
363
|
-
|
|
369
|
+
quarantined
|
|
370
|
+
? "This entry is QUARANTINED. The restore re-adds it STILL QUARANTINED — withheld from recall and injection until you release quarantine deliberately."
|
|
371
|
+
: "Re-adds this entry to memory from its audit record.",
|
|
364
372
|
"Restore",
|
|
365
373
|
async () => {
|
|
366
374
|
try {
|
|
367
375
|
// The audit line's origin stamp rides along (#129): a restore keeps the
|
|
368
376
|
// row's ORIGINAL visibility instead of silently landing global.
|
|
369
|
-
|
|
377
|
+
// #207: the deleted ts keys the server-side audit lookup, so tags,
|
|
378
|
+
// keywords, issue and status come back from the store's record — this
|
|
379
|
+
// page cannot launder a quarantined row into an injectable one.
|
|
380
|
+
await api("/api/restore-entry", { ts, type, scope, content, repo: repo || undefined, repoPath: repoPath || undefined });
|
|
370
381
|
toast("restored to memory");
|
|
371
382
|
await refresh();
|
|
372
383
|
} catch (e) { toast(String(e.message), true); }
|
|
@@ -392,7 +403,8 @@ $("rows").addEventListener("click", (e) => {
|
|
|
392
403
|
else if (action === "un-reject") unreject(btn.dataset.ch);
|
|
393
404
|
else if (action === "restore-deleted") {
|
|
394
405
|
const { type, scope, content, repo, repoPath } = btn.dataset;
|
|
395
|
-
|
|
406
|
+
const m = DATA.deleted.find((d) => d.ts === ts);
|
|
407
|
+
restoreEntry(ts, type, scope, content, repo, repoPath, !!m?.quarantined);
|
|
396
408
|
}
|
|
397
409
|
});
|
|
398
410
|
|
package/src/viewer/server.ts
CHANGED
|
@@ -39,6 +39,7 @@ import { blockedEntries } from "../store/blocklist.ts";
|
|
|
39
39
|
import { listSnapshots, restoreSnapshot } from "../store/undo.ts";
|
|
40
40
|
import { appendMemory } from "../store/files/append.ts";
|
|
41
41
|
import { loadAll, memoryFiles } from "../store/files/load.ts";
|
|
42
|
+
import { type MemoryStatus } from "../store/model/memory.ts";
|
|
42
43
|
import { parseLine } from "../core/logfmt/format.ts";
|
|
43
44
|
import { readLines } from "../core/logfmt/read.ts";
|
|
44
45
|
import { releaseQuarantinedMemory } from "./mutate.ts";
|
|
@@ -303,6 +304,50 @@ interface Row {
|
|
|
303
304
|
// restore-entry round trip can restore the row's ORIGINAL visibility.
|
|
304
305
|
repo?: string;
|
|
305
306
|
repoPath?: string;
|
|
307
|
+
// #207: the deleted row's metadata, read back from the audit line, so the
|
|
308
|
+
// deleted-entry UI can show WHAT is being restored — in particular whether
|
|
309
|
+
// it is quarantined. Only deletion rows carry these; blocked rows do not.
|
|
310
|
+
tags?: string[];
|
|
311
|
+
kw?: string[];
|
|
312
|
+
issue?: string;
|
|
313
|
+
status?: string;
|
|
314
|
+
quarantined?: boolean;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Comma-joined scalars back into arrays, the inverse of the audit write.
|
|
318
|
+
function splitScalar(value: unknown): string[] | undefined {
|
|
319
|
+
return typeof value === "string" && value
|
|
320
|
+
? value.split(",").filter(Boolean)
|
|
321
|
+
: undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// The metadata a deletion audit line carries for the deleted row (#207).
|
|
325
|
+
// Kept out of the client contract: restore resolves it here, from the store's
|
|
326
|
+
// own record, rather than trusting replayed bytes.
|
|
327
|
+
interface DeletionMeta {
|
|
328
|
+
tags?: string[];
|
|
329
|
+
kw?: string[];
|
|
330
|
+
issue?: string;
|
|
331
|
+
status?: MemoryStatus;
|
|
332
|
+
repo?: string;
|
|
333
|
+
repoPath?: string;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function auditMeta(f: NonNullable<ReturnType<typeof parseLine>>): DeletionMeta {
|
|
337
|
+
const tags = splitScalar(f.tags);
|
|
338
|
+
const kw = splitScalar(f.kw);
|
|
339
|
+
return {
|
|
340
|
+
...(tags ? { tags } : {}),
|
|
341
|
+
...(kw ? { kw } : {}),
|
|
342
|
+
...(typeof f.issue === "string" && f.issue ? { issue: f.issue } : {}),
|
|
343
|
+
...(f.status === "open" || f.status === "settled"
|
|
344
|
+
? { status: f.status }
|
|
345
|
+
: {}),
|
|
346
|
+
...(typeof f.repo === "string" && f.repo ? { repo: f.repo } : {}),
|
|
347
|
+
...(typeof f.repoPath === "string" && f.repoPath
|
|
348
|
+
? { repoPath: f.repoPath }
|
|
349
|
+
: {}),
|
|
350
|
+
};
|
|
306
351
|
}
|
|
307
352
|
|
|
308
353
|
// Deleted entries live only in the audit log (their memory line was removed),
|
|
@@ -312,17 +357,58 @@ async function deletedRows(): Promise<Row[]> {
|
|
|
312
357
|
return lines
|
|
313
358
|
.map((l) => parseLine(l))
|
|
314
359
|
.filter((f): f is NonNullable<typeof f> => f !== null)
|
|
315
|
-
.map((f) =>
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
:
|
|
325
|
-
|
|
360
|
+
.map((f) => {
|
|
361
|
+
const meta = auditMeta(f);
|
|
362
|
+
return {
|
|
363
|
+
ts: String(f.original_ts ?? f.ts ?? ""),
|
|
364
|
+
type: String(f.type ?? ""),
|
|
365
|
+
scope: String(f.scope ?? ""),
|
|
366
|
+
content: String(f.content ?? ""),
|
|
367
|
+
reason: String(f.reason ?? ""),
|
|
368
|
+
...meta,
|
|
369
|
+
// #207: the operator must SEE that a deleted row was quarantined —
|
|
370
|
+
// restoring it must not read as a way to release quarantine.
|
|
371
|
+
...(meta.tags
|
|
372
|
+
? { quarantined: isQuarantined({ tags: meta.tags }) }
|
|
373
|
+
: {}),
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// The authoritative record of what a deleted row carried, keyed by the deleted
|
|
379
|
+
// row's ts (#207). The LAST matching line wins: a row edited then deleted has
|
|
380
|
+
// its newest state last, and that is the state a restore re-adds. Lines
|
|
381
|
+
// written before #207 carry no metadata — the documented fallback.
|
|
382
|
+
async function deletionAuditFor(ts: string): Promise<DeletionMeta | undefined> {
|
|
383
|
+
let found: DeletionMeta | undefined;
|
|
384
|
+
for (const line of await readLines(deletionsFile())) {
|
|
385
|
+
const f = parseLine(line);
|
|
386
|
+
if (!f || f.original_ts !== ts) continue;
|
|
387
|
+
found = auditMeta(f);
|
|
388
|
+
}
|
|
389
|
+
return found;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Same record, keyed by the deleted row's identity instead of its ts (#207 F2).
|
|
393
|
+
// A restore request that omits ts is a legacy REQUEST, not a legacy record:
|
|
394
|
+
// if the audit carries a matching line, that line is still the authoritative
|
|
395
|
+
// copy of what the row carried, and resolving it here closes the laundering
|
|
396
|
+
// path (omitting ts must not restore a known quarantined row as injectable).
|
|
397
|
+
// Only when NO line matches — a client older than the viewer, or a row whose
|
|
398
|
+
// deletion predates the audit — does the route fall back to client replay.
|
|
399
|
+
async function deletionAuditByRow(
|
|
400
|
+
type: string,
|
|
401
|
+
scope: string,
|
|
402
|
+
content: string,
|
|
403
|
+
): Promise<DeletionMeta | undefined> {
|
|
404
|
+
let found: DeletionMeta | undefined;
|
|
405
|
+
for (const line of await readLines(deletionsFile())) {
|
|
406
|
+
const f = parseLine(line);
|
|
407
|
+
if (!f || f.type !== type || f.scope !== scope || f.content !== content)
|
|
408
|
+
continue;
|
|
409
|
+
found = auditMeta(f);
|
|
410
|
+
}
|
|
411
|
+
return found;
|
|
326
412
|
}
|
|
327
413
|
|
|
328
414
|
// Blocked entries are still on disk but hidden by the blocklist; scan every
|
|
@@ -581,16 +667,36 @@ async function restoreEntryRoute(
|
|
|
581
667
|
body: z.infer<typeof RestoreEntryBody>,
|
|
582
668
|
): Promise<Response> {
|
|
583
669
|
await assertViewerWriteAllowed(body.content);
|
|
584
|
-
//
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
//
|
|
670
|
+
// #207: every field that controls visibility or provenance is resolved from
|
|
671
|
+
// the audit line itself — the store's own record — so a restore cannot
|
|
672
|
+
// silently release quarantine (the quarantine tags come back with the row;
|
|
673
|
+
// releasing it stays the deliberate, reason-required release-quarantine
|
|
674
|
+
// action), cannot drop import provenance, and a client-forged repo stamp
|
|
675
|
+
// loses to the authoritative one. With ts the lookup is by row identity, and
|
|
676
|
+
// a ts that matches no audit line still resolves by type/scope/content
|
|
677
|
+
// before any fallback: an unknown explicit ts is an unresolved identity, not
|
|
678
|
+
// permission to replay (F2 residual). Without ts the lookup is by
|
|
679
|
+
// type/scope/content directly. Either way, omitting or missing ts cannot
|
|
680
|
+
// launder a KNOWN quarantined row back to injectable (F2). The client-replay
|
|
681
|
+
// fallback (#129 origin stamp, no metadata) survives only for rows the audit
|
|
682
|
+
// does not carry at all — a legacy record, not a legacy request.
|
|
683
|
+
const src =
|
|
684
|
+
(body.ts && (await deletionAuditFor(body.ts))) ||
|
|
685
|
+
(await deletionAuditByRow(body.type, body.scope, body.content));
|
|
588
686
|
const t = await appendMemory({
|
|
589
687
|
type: body.type,
|
|
590
688
|
scope: body.scope,
|
|
591
689
|
content: body.content,
|
|
592
|
-
|
|
593
|
-
|
|
690
|
+
...(src
|
|
691
|
+
? {
|
|
692
|
+
tags: src.tags,
|
|
693
|
+
kw: src.kw,
|
|
694
|
+
issue: src.issue,
|
|
695
|
+
status: src.status,
|
|
696
|
+
repo: src.repo,
|
|
697
|
+
repoPath: src.repoPath,
|
|
698
|
+
}
|
|
699
|
+
: { repo: body.repo, repoPath: body.repoPath }),
|
|
594
700
|
});
|
|
595
701
|
return json({ restored: t });
|
|
596
702
|
}
|