opencode-self-improvement 0.33.4 → 0.33.5
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/docs/internals/write-gates.md +2 -0
- package/package.json +2 -1
- package/src/gate/gate.ts +1 -1
- package/src/gate/resolver.ts +114 -14
- package/src/store/lock.ts +38 -1
|
@@ -14,6 +14,8 @@ Promotion evidence keeps a bounded sample of call IDs: the ten most recent code-
|
|
|
14
14
|
|
|
15
15
|
A settled claim about code must point at a file the repository has, so a write naming a missing path is refused with `ref_path_missing`. That check runs on writes only. A row that was correct when it was saved goes stale on its own the moment a later refactor moves the file, and nothing notices: recall keeps quoting a path the reader cannot open.
|
|
16
16
|
|
|
17
|
+
For a retired file, write the history lookup as a single backticked command, for example `git log -- bench/runners/append-cost-198.ts`. The gate verifies every such path against file names in the checkout’s available Git history from HEAD. A missing path or unavailable history refuses a settled write. Use the exact inline spelling shown above. A plain citation of the same path still needs a file in the current tree, and the repair report lists unverified pointers for a human. The command contributes no evidence that the file exists now. The usual grounding rules still apply.
|
|
18
|
+
|
|
17
19
|
`scripts/ref-fixer.ts` repairs the mechanical cases. The default is a dry run; `--apply` writes through the same gated update path as `memory_update`, so the old row is superseded rather than edited and `memory_undo` stays the recovery path. It repoints a path under two rules, and each is narrow for a specific reason:
|
|
18
20
|
|
|
19
21
|
1. **A scored rename.** Git records a rename scored at least `R90` whose chain ends at a file that exists today and whose basename is unchanged. The floor is measured rather than guessed: this repository's renames cluster at `R090`..`R100` — the domain restructure, where the only content change is the import lines inside the moved file — and the outliers below it (`R058`, `R072`, `R080`, `R086`, `R088`) are files git scored as renames after much of their content was rewritten. The basename matters because it is what a query matches on — `src/lock.ts` to `src/store/lock.ts` still says "lock", so the row stays findable by the words that found it before.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.5",
|
|
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": {
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@babel/parser": "7.29.9",
|
|
80
|
+
"@lezer/markdown": "1.8.1",
|
|
80
81
|
"zod": "4.6.7"
|
|
81
82
|
}
|
|
82
83
|
}
|
package/src/gate/gate.ts
CHANGED
|
@@ -907,7 +907,7 @@ export async function runWriteGate(
|
|
|
907
907
|
// created.
|
|
908
908
|
blockReason = "ref_path_missing";
|
|
909
909
|
blockFlags = [`missing=${g1.missingPaths.join(",")}`];
|
|
910
|
-
hint = `Path ref(s) not found in the repo: ${g1.missingPaths.join(", ")}.
|
|
910
|
+
hint = `Path ref(s) not found in the repo: ${g1.missingPaths.join(", ")}. Correct the live citation, or cite a committed retired file as a single inline command: \`git log -- <path>\`. Each history pointer must exist in this checkout's Git history; use status="open" if the file is planned, not existing.`;
|
|
911
911
|
} else if (canon && !canon.aligns) {
|
|
912
912
|
blockReason = "conflicts_with_canonical";
|
|
913
913
|
blockFlags = [
|
package/src/gate/resolver.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// GATE-1 resolver. Extracts embedded path/symbol refs from a memory/evidence
|
|
2
2
|
// candidate and re-resolves them against the live source tree. Deterministic:
|
|
3
|
-
//
|
|
4
|
-
import {
|
|
3
|
+
// Markdown span boundaries, literal Git paths and balanced-paren scanning.
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { join, posix } from "node:path";
|
|
5
7
|
import { opendir } from "node:fs/promises";
|
|
8
|
+
import { parser as markdown } from "@lezer/markdown";
|
|
6
9
|
import { type Memory } from "../store/model/memory.ts";
|
|
7
10
|
|
|
8
11
|
export interface CallForm {
|
|
@@ -160,8 +163,94 @@ const PATH_RE =
|
|
|
160
163
|
/[A-Za-z0-9_@./-]+\.(?:ts|tsx|js|jsx|mjs|cjs)(?!\w|\.\w)(?::\d+)?/g;
|
|
161
164
|
|
|
162
165
|
export function extractPathRefs(content: string): string[] {
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
return scanPathRefs(content).live.map((m) => m[0]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// A single path in the documented Git history command is a lookup instruction.
|
|
170
|
+
// It cannot ground a claim about the live tree. Keep offsets in the original
|
|
171
|
+
// text so a second, live citation of the same path is still checked and repaired.
|
|
172
|
+
function scanPathRefs(content: string) {
|
|
173
|
+
const live: RegExpExecArray[] = [];
|
|
174
|
+
const history = new Set<string>();
|
|
175
|
+
if (content.length > REGEX_SCAN_MAX_CHARS) return { live, history };
|
|
176
|
+
const prefix = "`git log -- ";
|
|
177
|
+
let tree: ReturnType<typeof markdown.parse> | undefined;
|
|
178
|
+
for (const m of content.matchAll(PATH_RE)) {
|
|
179
|
+
const end = m.index + m[0].length;
|
|
180
|
+
if (
|
|
181
|
+
content.endsWith(prefix, m.index) &&
|
|
182
|
+
content[end] === "`" &&
|
|
183
|
+
!m[0].includes(":")
|
|
184
|
+
) {
|
|
185
|
+
// Escaped backticks and commands quoted inside examples are literal text.
|
|
186
|
+
tree ??= markdown.parse(content);
|
|
187
|
+
const span = tree.resolveInner(m.index);
|
|
188
|
+
if (
|
|
189
|
+
span.name === "InlineCode" &&
|
|
190
|
+
span.from === m.index - prefix.length &&
|
|
191
|
+
span.to === end + 1
|
|
192
|
+
) {
|
|
193
|
+
history.add(m[0]);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
live.push(m);
|
|
198
|
+
}
|
|
199
|
+
return { live, history };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const git = promisify(execFile);
|
|
203
|
+
|
|
204
|
+
// Resolve all pointers in one path-limited history walk. Compare literal file
|
|
205
|
+
// names: a directory with the requested spelling is not a historical file.
|
|
206
|
+
export async function missingHistoryPaths(
|
|
207
|
+
root: string,
|
|
208
|
+
history: ReadonlySet<string>,
|
|
209
|
+
): Promise<string[]> {
|
|
210
|
+
if (!history.size) return [];
|
|
211
|
+
const paths = [...history];
|
|
212
|
+
const local = paths.filter(
|
|
213
|
+
(p) => !p.startsWith("/") && !p.split("/").includes(".."),
|
|
214
|
+
);
|
|
215
|
+
if (!root || !local.length) return paths;
|
|
216
|
+
try {
|
|
217
|
+
const { stdout } = await git(
|
|
218
|
+
"git",
|
|
219
|
+
[
|
|
220
|
+
"--literal-pathspecs",
|
|
221
|
+
"log",
|
|
222
|
+
"--format=",
|
|
223
|
+
"--name-only",
|
|
224
|
+
"-z",
|
|
225
|
+
"--relative",
|
|
226
|
+
"--full-history",
|
|
227
|
+
"-m",
|
|
228
|
+
"--root",
|
|
229
|
+
"--diff-filter=AD",
|
|
230
|
+
"--no-renames",
|
|
231
|
+
"HEAD",
|
|
232
|
+
"--",
|
|
233
|
+
...local,
|
|
234
|
+
],
|
|
235
|
+
{
|
|
236
|
+
cwd: root,
|
|
237
|
+
// A host launched by a Git hook can carry another checkout's GIT_DIR.
|
|
238
|
+
env: Object.fromEntries(
|
|
239
|
+
Object.entries(process.env).filter(([k]) => !k.startsWith("GIT_")),
|
|
240
|
+
),
|
|
241
|
+
timeout: 5000,
|
|
242
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
243
|
+
windowsHide: true,
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
const found = new Set(stdout.split("\0"));
|
|
247
|
+
return paths.filter(
|
|
248
|
+
(p) => !local.includes(p) || !found.has(posix.normalize(p)),
|
|
249
|
+
);
|
|
250
|
+
} catch {
|
|
251
|
+
// Missing Git, an unborn HEAD or incomplete output proves no exception.
|
|
252
|
+
return paths;
|
|
253
|
+
}
|
|
165
254
|
}
|
|
166
255
|
|
|
167
256
|
// Directory-qualified, repo-relative path refs whose existence gate1 can check
|
|
@@ -186,9 +275,13 @@ export interface PathRefSpan {
|
|
|
186
275
|
* never refuse, because it never sees it. Editing spans cannot.
|
|
187
276
|
*/
|
|
188
277
|
export function checkablePathRefSpans(content: string): PathRefSpan[] {
|
|
189
|
-
|
|
278
|
+
return liveSpans(scanPathRefs(content).live);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function liveSpans(matches: RegExpExecArray[]): PathRefSpan[] {
|
|
190
282
|
const out: PathRefSpan[] = [];
|
|
191
|
-
for (const m of
|
|
283
|
+
for (const m of matches) {
|
|
284
|
+
const content = m.input;
|
|
192
285
|
const ref = m[0].replace(/:\d+$/, "");
|
|
193
286
|
const prev = m.index && m.index > 0 ? content[m.index - 1] : "";
|
|
194
287
|
if (prev === "$" || prev === "~" || prev === "/") continue;
|
|
@@ -210,6 +303,11 @@ export function checkablePathRefSpans(content: string): PathRefSpan[] {
|
|
|
210
303
|
return out;
|
|
211
304
|
}
|
|
212
305
|
|
|
306
|
+
export function auditPathRefs(content: string) {
|
|
307
|
+
const { live, history } = scanPathRefs(content);
|
|
308
|
+
return { spans: liveSpans(live), history };
|
|
309
|
+
}
|
|
310
|
+
|
|
213
311
|
export function checkablePathRefs(content: string): string[] {
|
|
214
312
|
const out: string[] = [];
|
|
215
313
|
for (const s of checkablePathRefSpans(content))
|
|
@@ -497,9 +595,9 @@ export interface ResolveInput {
|
|
|
497
595
|
|
|
498
596
|
export async function gate1(input: ResolveInput): Promise<Gate1Result> {
|
|
499
597
|
const forms = extractCallForms(input.content);
|
|
500
|
-
const
|
|
501
|
-
const refs = forms.length +
|
|
502
|
-
if (refs === 0)
|
|
598
|
+
const { live, history } = scanPathRefs(input.content);
|
|
599
|
+
const refs = forms.length + live.length;
|
|
600
|
+
if (refs === 0 && !history.size)
|
|
503
601
|
return {
|
|
504
602
|
refs: 0,
|
|
505
603
|
resolved: [],
|
|
@@ -514,11 +612,13 @@ export async function gate1(input: ResolveInput): Promise<Gate1Result> {
|
|
|
514
612
|
// Existence check for repo-relative path refs. When liveRoot is not a real
|
|
515
613
|
// tree (unit tests, deleted worktree) nothing is verifiable, so report no
|
|
516
614
|
// missing paths rather than flagging everything.
|
|
517
|
-
const missingPaths
|
|
518
|
-
|
|
519
|
-
|
|
615
|
+
const missingPaths = new Set(
|
|
616
|
+
await missingHistoryPaths(input.liveRoot, history),
|
|
617
|
+
);
|
|
618
|
+
if (live.length && (await isDirectory(input.liveRoot))) {
|
|
619
|
+
for (const ref of new Set(liveSpans(live).map((s) => s.ref))) {
|
|
520
620
|
if (!(await Bun.file(join(input.liveRoot, ref)).exists()))
|
|
521
|
-
missingPaths.
|
|
621
|
+
missingPaths.add(ref);
|
|
522
622
|
}
|
|
523
623
|
}
|
|
524
624
|
|
|
@@ -563,6 +663,6 @@ export async function gate1(input: ResolveInput): Promise<Gate1Result> {
|
|
|
563
663
|
resolved,
|
|
564
664
|
drift,
|
|
565
665
|
candidateStale: drift?.source === "candidate",
|
|
566
|
-
missingPaths,
|
|
666
|
+
missingPaths: [...missingPaths],
|
|
567
667
|
};
|
|
568
668
|
}
|
package/src/store/lock.ts
CHANGED
|
@@ -53,7 +53,15 @@
|
|
|
53
53
|
import { Database } from "bun:sqlite";
|
|
54
54
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
55
55
|
import { chmod, unlink } from "node:fs/promises";
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
basename,
|
|
58
|
+
dirname,
|
|
59
|
+
isAbsolute,
|
|
60
|
+
join,
|
|
61
|
+
relative,
|
|
62
|
+
resolve,
|
|
63
|
+
sep,
|
|
64
|
+
} from "node:path";
|
|
57
65
|
import { ensureDir } from "../core/logfmt/publish.ts";
|
|
58
66
|
import { record } from "../telemetry/record.ts";
|
|
59
67
|
|
|
@@ -690,3 +698,32 @@ export function lockDatabaseFor(file: string): string {
|
|
|
690
698
|
export function heldLockDatabases(): string[] {
|
|
691
699
|
return [...lockDbs.keys()];
|
|
692
700
|
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Test seam: the lock databases under `dir` whose SECTION is still running in
|
|
704
|
+
* this process, so a caller can tell a handle it can free from one it cannot.
|
|
705
|
+
*
|
|
706
|
+
* A section is a callback awaiting the event loop. `closeAllLockDatabases`
|
|
707
|
+
* leaves it alone — closing would give up a lock its writer still believes it
|
|
708
|
+
* holds — and nothing else in the same turn can make it finish either. So a
|
|
709
|
+
* teardown that owns the loop (a synchronous `afterEach`) learns from this that
|
|
710
|
+
* waiting is pointless, while a teardown that can await learns that one gap is
|
|
711
|
+
* all it needs.
|
|
712
|
+
*/
|
|
713
|
+
export function heldLockSectionsUnder(dir: string): string[] {
|
|
714
|
+
const root = resolve(dir);
|
|
715
|
+
const out: string[] = [];
|
|
716
|
+
for (const [dbPath, pinned] of lockDbs) {
|
|
717
|
+
if (pinned.inUse === 0) continue;
|
|
718
|
+
const below = relative(root, resolve(dbPath));
|
|
719
|
+
if (
|
|
720
|
+
below &&
|
|
721
|
+
!below.startsWith(`..${sep}`) &&
|
|
722
|
+
below !== ".." &&
|
|
723
|
+
!isAbsolute(below)
|
|
724
|
+
) {
|
|
725
|
+
out.push(dbPath);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return out;
|
|
729
|
+
}
|