opencode-self-improvement 0.15.6 → 0.15.7

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
@@ -326,6 +326,18 @@ Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun r
326
326
 
327
327
  `e2e/` boots the **real opencode CLI** against each candidate in a fully isolated instance (fresh config, fresh db, fresh memory store, empty `HOME`) driven by a scripted OpenAI-compatible fake model — no API keys. It covers loading from the source tree and from the packed npm artifact installed runtime-deps-only, plus BDD flows for remember, recall, exact and near duplicates, ungrounded claims, and forget. Needs `opencode` on `PATH` locally, or set `OPENCODE_BIN`. A `test-windows` leg also runs the suite on Windows; it reports without gating merges.
328
328
 
329
+ ### Mutation sweep
330
+
331
+ ```sh
332
+ bun run sweep:test
333
+ ```
334
+
335
+ `bun run sweep:test` (`scripts/test-sweep.ts`) audits the test suite rather than testing the plugin. Each mutant breaks exactly one claimed invariant in a detached `git worktree` of HEAD, runs the `test/` suite (unit + scenario) against that mutated tree, and reports whether the suite noticed. A mutant no test kills is an unpinned invariant: the test titles may claim coverage, but nothing died with the invariant. The clean tree is measured first and its failing tests are subtracted from every mutant run, so only new failures count as a kill and a flake never masquerades as one. Mutants are applied only to scratch worktrees beside the checkout, never to the working tree under your feet.
336
+
337
+ The output is a canonical mutation score — killed over total, with equivalent mutants and load errors excluded from the denominator — plus the survivors, the unpinned invariants. Survivors are the audit's output, not a scandal: some mutants are expected to survive and become entries on the unpinned list rather than red CI.
338
+
339
+ Run it when you want to know whether the suite still has teeth — after changing tests or coverage, or as a pre-release gate with `bun scripts/test-sweep.ts --fail-on-survivors`, which exits 4 when anything survives. Two cheaper checks come first: `bun scripts/test-sweep.ts --validate` confirms every mutation pattern still lands on exactly one source site without running the suite, and `bun scripts/test-sweep.ts --selftest` plants a mutation in a trivially-tested pure function and fails unless the suite kills it — proof the instrument itself can go red.
340
+
329
341
  ## Troubleshooting
330
342
 
331
343
  | Problem | Fix |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.15.6",
3
+ "version": "0.15.7",
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": {
@@ -16,7 +16,7 @@
16
16
  // tests) and legacy rows predate the field: both read as GLOBAL — visible
17
17
  // everywhere — which keeps every upgrade non-breaking.
18
18
  import { createHash } from "node:crypto";
19
- import { realpathSync } from "node:fs";
19
+ import { lstatSync, realpathSync, statSync } from "node:fs";
20
20
 
21
21
  export interface RepoScope {
22
22
  key: string;
@@ -59,11 +59,91 @@ function git(args: string[], cwd: string): string | null {
59
59
  }
60
60
  }
61
61
 
62
+ // --- case-sensitivity probe (#109) --------------------------------------------
63
+ // Folding case by PLATFORM leaked rows across directories: a case-SENSITIVE
64
+ // APFS volume is a legitimate macOS choice (and NTFS has per-directory
65
+ // sensitivity), where "Foo" and "foo" really are two dirs that must not share
66
+ // one repo= key. Probe the filesystem instead: flip one cased character of the
67
+ // deepest existing component; if the flipped spelling still names the SAME
68
+ // dev+inode without following a symlink at the changed component, the probe
69
+ // accepts case folding. A case-variant symlink is an alias, not evidence of
70
+ // filesystem case folding. Answers cache per path (volume semantics do not
71
+ // change at runtime). The map is FIFO-capped like the session map.
72
+ // Undecided — nothing of the path exists, or no
73
+ // component carries case — falls back to the old platform rule, which is also
74
+ // a no-op whenever the path has no cased characters to fold.
75
+ const caseFoldCache = new Map<string, boolean>();
76
+
77
+ function statOrNull(p: string) {
78
+ try {
79
+ return statSync(p);
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ // Return the component whose LAST cased character is flipped. Trim any
86
+ // uncased descendants: lstat("Foo/123") would still follow a symlink at Foo,
87
+ // whereas lstat("Foo") lets the caller distinguish that alias from a real
88
+ // case-insensitive lookup. Index 0 stays untouched for Windows drive letters.
89
+ function caseProbePair(p: string): { original: string; flipped: string } | null {
90
+ for (let i = p.length - 1; i > 0; i--) {
91
+ const c = p[i];
92
+ const f = c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase();
93
+ if (f !== c) {
94
+ const suffix = p.slice(i).search(/[\\/]/);
95
+ const end = suffix < 0 ? p.length : i + suffix;
96
+ return {
97
+ original: p.slice(0, end),
98
+ flipped: p.slice(0, i) + f + p.slice(i + 1, end),
99
+ };
100
+ }
101
+ }
102
+ return null;
103
+ }
104
+
105
+ /**
106
+ * Does the filesystem holding `dir` name-match across case? true = fold is
107
+ * safe; false = "Foo" and "foo" are distinct; null = undecided (fall back to
108
+ * the platform rule). Walks up to the nearest existing component when `dir`
109
+ * itself is gone, and flips an ancestor's name when the deepest name has no
110
+ * case to flip.
111
+ */
112
+ export function isCaseInsensitivePath(dir: string): boolean | null {
113
+ const cached = caseFoldCache.get(dir);
114
+ if (cached !== undefined) return cached;
115
+ let cur = dir;
116
+ for (let up = 0; up < 10; up++) {
117
+ const st = statOrNull(cur);
118
+ if (st) {
119
+ const pair = caseProbePair(cur);
120
+ if (pair) {
121
+ let ans = false;
122
+ try {
123
+ const original = lstatSync(pair.original);
124
+ const flipped = lstatSync(pair.flipped);
125
+ ans = !original.isSymbolicLink() && !flipped.isSymbolicLink()
126
+ && original.dev === flipped.dev && original.ino === flipped.ino;
127
+ } catch {
128
+ // Missing or unreadable alternate spelling cannot justify folding.
129
+ }
130
+ if (caseFoldCache.size >= 64)
131
+ caseFoldCache.delete(caseFoldCache.keys().next().value as string);
132
+ caseFoldCache.set(dir, ans);
133
+ return ans;
134
+ }
135
+ }
136
+ const parent = cur.replace(/[\\/]+$/, "").replace(/[\\/][^\\/]*$/, "");
137
+ if (!parent || parent === cur) break;
138
+ cur = parent;
139
+ }
140
+ return null;
141
+ }
142
+
62
143
  // Normalize a directory for hashing: symlinks, junctions, and Windows 8.3
63
144
  // aliases collapse to the real path (realpath), separators unify to "/",
64
- // a trailing separator disappears, and case folds ONLY on the
65
- // case-insensitive filesystems (win32/darwin) where two spellings are the
66
- // same directory — Linux folds nothing, there "Foo" and "foo" are two dirs.
145
+ // a trailing separator disappears, and case folds ONLY where the probe says
146
+ // the volume folds names itself (#109) — never trusting the platform alone.
67
147
  export function normalizeDirPath(p: string): string {
68
148
  let r = p;
69
149
  try {
@@ -72,7 +152,8 @@ export function normalizeDirPath(p: string): string {
72
152
  // deleted/unreadable mid-resolve: hash the given spelling rather than throw
73
153
  }
74
154
  r = r.replace(/\\/g, "/").replace(/\/+$/, "");
75
- if (process.platform === "win32" || process.platform === "darwin") r = r.toLowerCase();
155
+ const fold = isCaseInsensitivePath(r) ?? (process.platform === "win32" || process.platform === "darwin");
156
+ if (fold) r = r.toLowerCase();
76
157
  return r || "/";
77
158
  }
78
159