opencode-self-improvement 0.15.10 → 0.15.12

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
@@ -257,6 +257,8 @@ Review the full row in the memory viewer's **quarantined** filter. **Release qua
257
257
 
258
258
  This is a heuristic review queue, not a complete prompt-injection detector: legitimate documentation or quoted code can match. Markdown-bold role headers and download-then-`&&`-execute forms are recognized, but alternate role delimiters such as `[INST]` / `<<SYS>>`, base64-to-shell pipelines, paraphrased instructions, and indirect execution can evade it. Direct `memory_remember` and human viewer edits are explicit writes and are not automatically scanned: a session with that tool still has a prose channel, mitigated by the existing framing and provenance rather than quarantine. Those defenses still apply to released rows.
259
259
 
260
+ The viewer is a trusted admin editor: its edits and deleted-entry restores do not run the model-facing grounding or deduplication gates, but they honor the same exact and near-match value rejections. Rejected edits leave the original row, snapshots and edit audit unchanged; rejected restores append nothing. The refusal names the rejection hash so you can explicitly lift it under **Rejections → un-reject** before retrying. Corrected numeric values and polarity changes retain the rejection check's existing exceptions. This check does not change whole-snapshot rollback policy.
261
+
260
262
  Existing stores are not rescanned. A byte-identical import that collapses into an existing row does not retroactively tag that row. Export preserves quarantined rows and their tags to avoid data loss; an exported released row can be quarantined again when re-import promotes it on another machine.
261
263
 
262
264
  An open row is exempt from reference grounding, so that status is honored only for files carrying an export header. Even with a header: an open row claiming `repo:"global"` is downgraded, and imported `repo` / `repoPath` stamps are kept only when they match the importing session's current repo — foreign stamps are dropped and the row is stamped for the importing repo. Re-running the same import in the same repo is a no-op.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.15.10",
3
+ "version": "0.15.12",
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": {
@@ -2,7 +2,7 @@
2
2
  // index.ts; this module owns frozen bytes, refresh decisions, and their status.
3
3
  import { loadAll, malformedCount } from "../store/files/load.ts"
4
4
  import { type Memory } from "../store/model/memory.ts"
5
- import { isActive, isInjectable } from "../store/model/predicates.ts"
5
+ import { isInjectable } from "../store/model/predicates.ts"
6
6
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
7
7
  import { SESSION_CAP, SessionLru } from "../core/lru.ts";
8
8
  import { record } from "../evidence/record.ts";
@@ -11,7 +11,8 @@ import { systemDigest } from "./digest.ts"
11
11
  import { storeVersion } from "./version.ts"
12
12
  import { selectRelevant } from "../recall/relevant.ts";
13
13
  import { attributeSession, deriveMemoryRefs, type MemoryRefs } from "./attribution.ts";
14
- import { neverRetrieved, readLedger, useSignals } from "../hits/ledger.ts";
14
+ import { readLedger, useSignals } from "../hits/ledger.ts";
15
+ import { summarizeStore } from "../status/store-summary.ts";
15
16
  import { emptyStats, type Measured, type SessionStats, type StatusPayload } from "../status/payload.ts"
16
17
  import { writeStatus } from "../status/write.ts";
17
18
  import { callsFor } from "../capture/triggers.ts";
@@ -105,7 +106,6 @@ export function createInjectionEpochs({
105
106
  const ep = epoch.get(sid);
106
107
  if (!ep) return null;
107
108
  const all = await loadAll();
108
- const act = all.filter(isActive);
109
109
  const led = await readLedger();
110
110
  return {
111
111
  at: ep.at,
@@ -116,15 +116,7 @@ export function createInjectionEpochs({
116
116
  blockChars: ep.block.length,
117
117
  sectionChars: ep.prefix.length,
118
118
  budget,
119
- store: {
120
- active: act.length,
121
- superseded: all.length - act.length,
122
- open: act.filter((m) => m.status === "open").length,
123
- scopes: new Set(act.map((m) => m.scope)).size,
124
- malformed: malformedCount(),
125
- neverRetrieved: neverRetrieved(act, led).length,
126
- ledgerSince: led.since,
127
- },
119
+ store: summarizeStore(all, led, malformedCount()).counts,
128
120
  stats: statsFor(sid),
129
121
  measured: measuredTurns.get(sid) ?? null,
130
122
  attribution: attributeSession(callsFor(sid), ep.refs),
@@ -0,0 +1,26 @@
1
+ // Shared store counts for epoch payloads and the chat report (#168).
2
+ // Callers own I/O and visibility policy; this summarizes exactly their rows.
3
+ import { neverRetrieved, type UseLedger } from "../hits/ledger.ts";
4
+ import type { Memory } from "../store/model/memory.ts";
5
+ import { isActive } from "../store/model/predicates.ts";
6
+ import type { StoreCounts } from "./payload.ts";
7
+
8
+ export function summarizeStore(
9
+ rows: Memory[],
10
+ ledger: UseLedger,
11
+ malformed: number,
12
+ ): { active: Memory[]; counts: StoreCounts } {
13
+ const active = rows.filter(isActive);
14
+ return {
15
+ active,
16
+ counts: {
17
+ active: active.length,
18
+ superseded: rows.length - active.length,
19
+ open: active.filter((m) => m.status === "open").length,
20
+ scopes: new Set(active.map((m) => m.scope)).size,
21
+ malformed,
22
+ neverRetrieved: neverRetrieved(active, ledger).length,
23
+ ledgerSince: ledger.since,
24
+ },
25
+ };
26
+ }
@@ -1,18 +1,16 @@
1
- // The memory_status tool, extracted from index.ts (#168). Schema, description
2
- // and handler are byte-identical to the pre-split source; closure access arrives
3
- // through ToolDeps.
1
+ // The memory_status tool, extracted from index.ts (#168).
2
+ // Closure access arrives through ToolDeps.
4
3
  import type { ToolRegister } from "./deps.ts";
5
- import { neverRetrieved, readLedger } from "../hits/ledger.ts";
4
+ import { readLedger } from "../hits/ledger.ts";
6
5
  import { formatMemory } from "../inject/format.ts";
7
6
  import { loadAll, malformedCount } from "../store/files/load.ts"
8
- import { isActive } from "../store/model/predicates.ts"
9
7
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
10
8
  import { isQuarantined, quarantineReasons } from "../store/quarantine/quarantine.ts";
11
9
  import { EmptyArgs, validated } from "./schema.ts";
12
10
  import { captureLag, captureLagLines, rowsPerDay } from "../status/metrics.ts"
13
11
  import { renderMemoryReport } from "../status/report.ts"
14
12
  import { blockedRecent } from "../status/write.ts";
15
- import type { StoreCounts } from "../status/payload.ts";
13
+ import { summarizeStore } from "../status/store-summary.ts";
16
14
 
17
15
  export const register: ToolRegister = (editor, deps) => {
18
16
  const { toolIds, sessions, direct } = deps;
@@ -28,19 +26,11 @@ export const register: ToolRegister = (editor, deps) => {
28
26
  if (sid !== "?") await sessions.refresh(sid);
29
27
  const status = sid === "?" ? null : await sessions.buildPayload(sid);
30
28
  const all = await loadAll();
31
- const act = all.filter(isActive);
32
- const store: StoreCounts = {
33
- active: act.length,
34
- superseded: all.length - act.length,
35
- open: act.filter((m) => m.status === "open").length,
36
- scopes: new Set(act.map((m) => m.scope)).size,
37
- malformed: malformedCount(),
38
- };
29
+ const malformed = malformedCount();
39
30
  // Use ledger (#42): how much of the store has never been surfaced.
40
31
  // Reported, never acted on — retirement is a decision, not a metric.
41
32
  const ledger = await readLedger();
42
- store.neverRetrieved = neverRetrieved(act, ledger).length;
43
- store.ledgerSince = ledger.since;
33
+ const { active: act, counts: store } = summarizeStore(all, ledger, malformed);
44
34
  // Self-metrics (#44): what the store costs, how fast it grows, and how
45
35
  // stale a capture is when it fires. Same rule as above — the numbers
46
36
  // are the point, not a verdict on them.
@@ -21,6 +21,7 @@ import { snapshotFiles } from "../store/files/snapshots.ts"
21
21
  import { markSuperseded } from "../store/files/supersede.ts"
22
22
  import { type Memory } from "../store/model/memory.ts"
23
23
  import { releaseQuarantine } from "../store/quarantine/release.ts";
24
+ import { assertViewerWriteAllowed } from "./rejections.ts";
24
25
 
25
26
  export interface EditInput {
26
27
  ts: string;
@@ -75,6 +76,9 @@ export async function editMemory(input: EditInput): Promise<MutationResult> {
75
76
  const chain = chainId();
76
77
  const target = await findMemory(input.ts);
77
78
 
79
+ // Editing is not an implicit un-reject. Refuse before snapshots, appends,
80
+ // retirement or audit so a rejected edit leaves its original row intact.
81
+ await assertViewerWriteAllowed(input.content);
78
82
  const snapshot = await snapshotFiles([target.file]);
79
83
  const newTs = await appendMemory({
80
84
  type: input.type || target.type,
@@ -0,0 +1,15 @@
1
+ // Viewer writes are deliberate admin edits, independent of model grounding
2
+ // gates. They still honor value rejections until an explicit release (#222).
3
+ import { redactSecrets } from "../store/secrets.ts";
4
+ import { probeRejection } from "../store/tombstones/rejection.ts";
5
+
6
+ export async function assertViewerWriteAllowed(content: string): Promise<void> {
7
+ // Match the bytes appendMemory persists, as the write gate already does.
8
+ // Read/probe errors propagate: an unavailable rejection set cannot grant a write.
9
+ const { rejection } = await probeRejection(redactSecrets(content));
10
+ if (!rejection) return;
11
+ throw new Error(
12
+ `viewer write blocked: previously_rejected (${rejection.kind}; hash ${rejection.tombstone.ch}). ` +
13
+ "Nothing was stored. Use Rejections → un-reject in the viewer to explicitly lift that rejection before retrying.",
14
+ );
15
+ }
@@ -20,6 +20,7 @@ import { releaseQuarantinedMemory } from "./mutate.ts";
20
20
  import { isQuarantined, quarantineReasons } from "../store/quarantine/quarantine.ts";
21
21
  import { deleteMemory, editMemory, blockMemory, unblockMemory, unrejectMemory, type MutationResult } from "./mutate.ts";
22
22
  import { tombstones } from "../store/tombstones/tombstone.ts";
23
+ import { assertViewerWriteAllowed } from "./rejections.ts";
23
24
 
24
25
  const PAGE = join(import.meta.dir, "page.html");
25
26
  const HOST = process.env.OPENCODE_VIEWER_HOST || "127.0.0.1";
@@ -315,6 +316,7 @@ async function unrejectRoute(body: z.infer<typeof UnrejectBody>): Promise<Respon
315
316
  }
316
317
 
317
318
  async function restoreEntryRoute(body: z.infer<typeof RestoreEntryBody>): Promise<Response> {
319
+ await assertViewerWriteAllowed(body.content);
318
320
  // Origin survives the restore round trip (#129): when the audit line carried
319
321
  // a repo stamp, the restored row carries it again — the viewer's own missing
320
322
  // repository scope must never be what decides a row's visibility. No repo