opencode-self-improvement 0.20.0 → 0.22.0

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.
@@ -48,6 +48,26 @@ const CONFLICT_REF_RE = /^[A-Za-z_][A-Za-z0-9_]{1,63}$/;
48
48
 
49
49
  export const MAX_CLAIM_CHARS = 32;
50
50
 
51
+ /** Cap on the verbatim user utterance a guided row may carry (bench #347 follow-up). */
52
+ export const MAX_ORIGINAL_CHARS = 300;
53
+
54
+ /**
55
+ * Normalise the verbatim user utterance stored beside a guided row. TOTAL on
56
+ * purpose, like the conflict fields: a junk or over-long quote drops the
57
+ * field, never the row. The value must already be whitespace-flattened; the
58
+ * capture runtime verifies it is a true substring of what the model saw, so
59
+ * a stored quote is the user's own words, not the capture model's paraphrase
60
+ * (FINDINGS mystery 2, candidate 4: a paraphrased hint made the bench's
61
+ * exact-text needle miss a row that actually rode).
62
+ */
63
+ export function normalizeOriginal(original: unknown): string | undefined {
64
+ if (typeof original !== "string") return undefined;
65
+ const o = original.trim();
66
+ if (!o || o.length > MAX_ORIGINAL_CHARS) return undefined;
67
+ if (flattenMemoryText(o) !== o) return undefined;
68
+ return o;
69
+ }
70
+
51
71
  /**
52
72
  * Normalise the contradiction-surface fields of a guided candidate. TOTAL on
53
73
  * purpose, like keywords: a junk ref/claim/klass drops the fields, never the
@@ -101,6 +121,11 @@ export interface Memory {
101
121
  ref?: string;
102
122
  claim?: string;
103
123
  klass?: "spec" | "behavior";
124
+ // Verbatim user utterance behind a guided row, written by capture after a
125
+ // substring check against the transcript the capture model saw. Injection
126
+ // renders it, so the user's exact words reach the next session's wire bytes
127
+ // even when the distilled content paraphrases them.
128
+ original?: string;
104
129
  file: string;
105
130
  index: number;
106
131
  }
@@ -1,6 +1,6 @@
1
1
  // predicates — split from src/memory.ts (#168 domain restructure). Declaration bodies are unchanged.
2
2
  import { isQuarantined } from "../quarantine/quarantine.ts";
3
- import { type Memory } from "./memory.ts";
3
+ import type { Memory } from "./memory.ts";
4
4
 
5
5
  export function isActive(m: Memory): boolean {
6
6
  return !m.superseded_by;
@@ -1,15 +1,15 @@
1
1
  // Repository visibility, shared by memory rows, restore lines, and evidence.
2
2
  import { createHash } from "node:crypto";
3
+ import { parseLine } from "../../core/logfmt/format.ts";
4
+ import { getCurrent } from "../../core/state.ts";
3
5
  import {
4
6
  normalizeDirPath,
7
+ type RepoScope,
5
8
  repoScopeFor,
6
9
  sessionScope,
7
- type RepoScope,
8
10
  } from "../../identity/repokey.ts";
9
- import { getCurrent } from "../../core/state.ts";
10
- import { parseLine } from "../../core/logfmt/format.ts";
11
11
  import { prune } from "../files/prune.ts";
12
- import { type Memory } from "./memory.ts";
12
+ import type { Memory } from "./memory.ts";
13
13
 
14
14
  // --- repo visibility ---------------------------------------------------------
15
15
  // A READER is an immutable caller identity, resolved once at the entry of a
@@ -2,9 +2,9 @@
2
2
  // reversible (snapshot) and never touches a repo. The `prune` evidence line is
3
3
  // emitted after prune() returns so S5 can assert the reason and snapshot.
4
4
  import { deletionsFile } from "../core/config/paths.ts";
5
- import { prune, type PruneResult } from "./files/prune.ts";
6
- import { readerFromSid } from "./model/visibility.ts";
7
5
  import { record } from "../evidence/record.ts";
6
+ import { type PruneResult, prune } from "./files/prune.ts";
7
+ import { readerFromSid } from "./model/visibility.ts";
8
8
 
9
9
  export async function pruneMemory(
10
10
  scope: string,
@@ -41,15 +41,24 @@ export function quarantineReasons(row: { tags?: string[] }): string[] {
41
41
  }
42
42
 
43
43
  export function quarantineCandidate<
44
- T extends { content: string; scope?: string; tags?: string[] },
44
+ T extends {
45
+ content: string;
46
+ scope?: string;
47
+ original?: string;
48
+ tags?: string[];
49
+ },
45
50
  >(candidate: T): T {
46
51
  // #205: scope renders model-facing (inject/format.ts prints it on every
47
- // injected line), so the scanner covers it as well as content. Hits are
48
- // merged and deduplicated; provenance tags survive untouched.
52
+ // injected line), so the scanner covers it as well as content. #364 review:
53
+ // so does `original`, the verbatim quote the same line prints as
54
+ // `(user said: "...")` — a benign summary carrying an instruction-shaped
55
+ // quote reached the prompt untagged. Hits are merged and deduplicated;
56
+ // provenance tags survive untouched.
49
57
  const hits = [
50
58
  ...new Set([
51
59
  ...quarantinePatterns(candidate.content),
52
60
  ...(candidate.scope ? quarantinePatterns(candidate.scope) : []),
61
+ ...(candidate.original ? quarantinePatterns(candidate.original) : []),
53
62
  ]),
54
63
  ];
55
64
  if (!hits.length) return candidate;
@@ -1,29 +1,46 @@
1
1
  // release — split from src/memory.ts (#168 domain restructure). Declaration bodies are unchanged.
2
- import { join } from "node:path";
3
- import { formatLine } from "../../core/logfmt/format.ts";
4
- import { QUARANTINE_TAG, quarantineReasons } from "./quarantine.ts";
5
- import { memoryFiles } from "../files/load.ts";
2
+ import { type Fields, formatLine } from "../../core/logfmt/format.ts";
3
+ import { filesHoldingTs, memoryFiles } from "../files/load.ts";
6
4
  import { stampRow } from "../files/snapshots.ts";
5
+ import { QUARANTINE_TAG, quarantineReasons } from "./quarantine.ts";
7
6
 
8
7
  // Human viewer action only. Preserve identity, origin, and all non-quarantine
9
8
  // metadata; stampRow snapshots and atomically publishes under the store lock.
10
9
  export async function releaseQuarantine(
11
10
  ts: string,
12
11
  ): Promise<"released" | "not_found" | "not_quarantined"> {
12
+ const release = (fields: Fields) => {
13
+ const tags = typeof fields.tags === "string" ? fields.tags.split(",") : [];
14
+ if (!tags.includes(QUARANTINE_TAG)) return null;
15
+ const scanTags = new Set([
16
+ QUARANTINE_TAG,
17
+ ...quarantineReasons({ tags }).map((id) => `quarantine:${id}`),
18
+ ]);
19
+ const kept = tags.filter((tag) => !scanTags.has(tag));
20
+ if (kept.length) fields.tags = kept.join(",");
21
+ else delete fields.tags;
22
+ return formatLine(fields);
23
+ };
24
+ // #215 + #373 review: release every copy. The day file the ts names is the
25
+ // common case; the previous day's file joins ONLY when a scan finds the same
26
+ // identity in it, which is what an older midnight-boundary append could write.
27
+ // Leaving a duplicate quarantined beside a released copy would keep the row
28
+ // hidden from the operator who just released it.
29
+ const candidates = await filesHoldingTs(ts);
30
+ let found = false;
31
+ let released = false;
32
+ for (const file of candidates) {
33
+ const result = await stampRow(file, ts, release);
34
+ if (result === null) continue;
35
+ found = true;
36
+ released = released || result;
37
+ }
38
+ if (found) return released ? "released" : "not_quarantined";
39
+ // Never seen where it should be: the sweep this replaced, unchanged.
40
+ const tried = new Set(candidates);
13
41
  for (const file of await memoryFiles()) {
14
- const result = await stampRow(file, ts, (fields) => {
15
- const tags =
16
- typeof fields.tags === "string" ? fields.tags.split(",") : [];
17
- if (!tags.includes(QUARANTINE_TAG)) return null;
18
- const scanTags = new Set([
19
- QUARANTINE_TAG,
20
- ...quarantineReasons({ tags }).map((id) => `quarantine:${id}`),
21
- ]);
22
- const kept = tags.filter((tag) => !scanTags.has(tag));
23
- if (kept.length) fields.tags = kept.join(",");
24
- else delete fields.tags;
25
- return formatLine(fields);
26
- });
42
+ if (tried.has(file)) continue;
43
+ const result = await stampRow(file, ts, release);
27
44
  if (result !== null) return result ? "released" : "not_quarantined";
28
45
  }
29
46
  return "not_found";
@@ -1,13 +1,13 @@
1
1
  // rejection — split from src/tombstones.ts (#168 domain restructure). Declaration bodies are unchanged.
2
2
  import { join } from "node:path";
3
- import { contentHash } from "../../evidence/record.ts";
4
3
  import { memoryRoot } from "../../core/config/paths.ts";
4
+ import { contentHash } from "../../evidence/record.ts";
5
5
  import {
6
+ differsIn,
6
7
  NEAR_FLOOR,
7
8
  NEAR_MIN_SHARED,
8
- type Tombstone,
9
- differsIn,
10
9
  sketchOf,
10
+ type Tombstone,
11
11
  tombstone,
12
12
  tombstones,
13
13
  valueSigOf,
@@ -42,10 +42,10 @@
42
42
  // Not snapshotted. snapshotFiles() walks memoryFiles(), which excludes every
43
43
  // RESERVED name, so `memory_undo` cannot resurrect a tombstone any more than
44
44
  // it can resurrect a blocklist entry — and conversely cannot erase one.
45
- import { readFile } from "node:fs/promises";
45
+
46
46
  import { createHash } from "node:crypto";
47
+ import { readFile } from "node:fs/promises";
47
48
  import { join } from "node:path";
48
- import { contentHash } from "../../evidence/record.ts";
49
49
  import { formatLine, parseLine } from "../../core/logfmt/format.ts";
50
50
  import {
51
51
  appendLog,
@@ -53,19 +53,20 @@ import {
53
53
  writeAtomic,
54
54
  } from "../../core/logfmt/publish.ts";
55
55
  import { readLines } from "../../core/logfmt/read.ts";
56
- import { withStoreLock, LOCK_WRITE } from "../lock.ts";
57
- import { redactSecrets } from "../secrets.ts";
58
56
  import {
59
- STOPWORDS,
60
- tokens,
61
57
  numericTokens,
62
58
  polaritySigns,
59
+ STOPWORDS,
60
+ tokens,
63
61
  } from "../../core/tokenize.ts";
62
+ import { contentHash } from "../../evidence/record.ts";
63
+ import { LOCK_WRITE, withStoreLock } from "../lock.ts";
64
+ import { redactSecrets } from "../secrets.ts";
64
65
  import {
65
- type Rejection,
66
- type ValueDifference,
67
66
  findRejection,
67
+ type Rejection,
68
68
  rejectedFile,
69
+ type ValueDifference,
69
70
  } from "./rejection.ts";
70
71
 
71
72
  /** How many lowest token-hashes the sketch keeps. */
package/src/store/undo.ts CHANGED
@@ -29,8 +29,6 @@
29
29
  import { lstat, readFile, realpath, stat } from "node:fs/promises";
30
30
  import { basename, isAbsolute, join, relative, resolve } from "node:path";
31
31
  import { deletionsFile, snapshotDir } from "../core/config/paths.ts";
32
- import { contentHash } from "../evidence/record.ts";
33
- import { isWithin } from "./containment.ts";
34
32
  import { parseLine } from "../core/logfmt/format.ts";
35
33
  import {
36
34
  ensureDir,
@@ -38,14 +36,16 @@ import {
38
36
  writeAtomic,
39
37
  } from "../core/logfmt/publish.ts";
40
38
  import { readLines } from "../core/logfmt/read.ts";
41
- import { withStoreLock, LOCK_RESTORE } from "./lock.ts";
39
+ import { contentHash } from "../evidence/record.ts";
40
+ import { isWithin } from "./containment.ts";
42
41
  import { snapshotFiles } from "./files/snapshots.ts";
43
- import { tombstones } from "./tombstones/tombstone.ts";
42
+ import { LOCK_RESTORE, withStoreLock } from "./lock.ts";
44
43
  import {
45
44
  ADMIN_READER,
46
45
  lineVisibleTo,
47
46
  type Reader,
48
47
  } from "./model/visibility.ts";
48
+ import { tombstones } from "./tombstones/tombstone.ts";
49
49
 
50
50
  const SNAPSHOT_NAME = /^(\d+)-(\d{4}-\d{2}-\d{2}\.logfmt)$/;
51
51
 
@@ -1,21 +1,22 @@
1
1
  // The memory_update tool, extracted from index.ts (#168). Schema, description
2
2
  // and handler are byte-identical to the pre-split source; closure access arrives
3
3
  // through ToolDeps.
4
- import type { ToolRegister } from "./deps.ts";
4
+
5
+ import { join } from "node:path";
5
6
  import { memoryRoot } from "../core/config/paths.ts";
7
+ import { nonCaptureTags } from "../core/guidance.ts";
6
8
  import { record } from "../evidence/record.ts";
7
9
  import { auditCaveat, runWriteGate, sameStrList } from "../gate/gate.ts";
8
- import { withStoreLock } from "../store/lock.ts";
9
10
  import { loadAll } from "../store/files/load.ts";
10
11
  import { markSuperseded } from "../store/files/supersede.ts";
11
12
  import { resolveMemoryTarget } from "../store/files/target.ts";
13
+ import { withStoreLock } from "../store/lock.ts";
14
+ import type { Memory } from "../store/model/memory.ts";
12
15
  import { isActive } from "../store/model/predicates.ts";
13
16
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
14
- import type { Memory } from "../store/model/memory.ts";
15
- import { UpdateArgs, validated } from "./schema.ts";
16
17
  import { redactSecrets } from "../store/secrets.ts";
17
- import { join } from "node:path";
18
- import { nonCaptureTags } from "../core/guidance.ts";
18
+ import type { ToolRegister } from "./deps.ts";
19
+ import { UpdateArgs, validated } from "./schema.ts";
19
20
 
20
21
  export const register: ToolRegister = (editor, deps) => {
21
22
  const {
@@ -221,7 +222,18 @@ export const register: ToolRegister = (editor, deps) => {
221
222
  const partial = (why: string) => ({
222
223
  content:
223
224
  `memory_update PARTIAL: replacement ${replacement} IS on disk (memory_undo merge or force ` +
224
- `restores ${retired}), but ${why}. Re-running this update reports the duplicate.`,
225
+ `restores ${retired}), but ${why}. Re-running this update reports the duplicate.` +
226
+ // #215 narrowed a single-row supersede to the day file its ts
227
+ // names, so a busy file now faults HERE instead of faulting
228
+ // somewhere in the gate's sweep. The gate may still have
229
+ // retired OTHER rows at GATE-2 (drift, canonical) before that
230
+ // fault — those tombstones are on disk, and a PARTIAL that
231
+ // omits them reads as "only the target was touched".
232
+ (gateDurable.length > 0
233
+ ? ` This call had ALREADY retired ${gateDurable.length} other row(s) (${gateDurable.join(
234
+ ", ",
235
+ )}): those retirements ARE on disk; reconcile with memory_evidence.`
236
+ : ""),
225
237
  });
226
238
  let retiredNow = false;
227
239
  try {