opencode-self-improvement 0.14.20 → 0.14.22

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
@@ -305,6 +305,8 @@ bun run gate # typecheck + lint + unit tests + terminal smoke & BDD
305
305
  bun run gate:hooks # once per clone: run the gate on `git push`
306
306
  ```
307
307
 
308
+ Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun run test:e2e` run files across at most four worker processes with Bun's file isolation; cases inside each file stay sequential because fixtures share environment variables and module state. The local gate uses those same scripts. To diagnose order-dependent failures in the original shared-process mode, run `bun test ./test/` or `bun test ./e2e/ --timeout 240000` directly.
309
+
308
310
  **Feature order is BDD-first.** A new feature starts by adding or fixing a scenario in `e2e/` that describes the behavior as a user would observe it — before implementation code and before unit tests. Then the unit tests for the pieces, then the code until everything is green. If no scenario turns red first, the feature has no observable contract.
309
311
 
310
312
  `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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.14.20",
3
+ "version": "0.14.22",
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": {
@@ -60,8 +60,8 @@
60
60
  "typescript": "^7.0.2"
61
61
  },
62
62
  "scripts": {
63
- "test": "bun test ./test/",
64
- "test:e2e": "bun test ./e2e/ --timeout 240000",
63
+ "test": "bun test ./test/ --parallel=4",
64
+ "test:e2e": "bun test ./e2e/ --parallel=4 --timeout 240000",
65
65
  "gate": "bun scripts/merge-gate.ts",
66
66
  "gate:hooks": "git config core.hooksPath .githooks",
67
67
  "typecheck": "bun x tsc --noEmit -p tsconfig.json",
package/src/index.ts CHANGED
@@ -755,8 +755,20 @@ const impl = {
755
755
  // a human (or an update on the survivor) decides.
756
756
  const survivorTs = outcome.collapsedWith;
757
757
  if (target && survivorTs && survivorTs !== target.ts) {
758
- const survivor = (await loadAll()).find((m) => m.ts === survivorTs && !m.superseded_by);
758
+ // #175: the gate can observe a session move after this call captured
759
+ // its reader. Recheck before trusting or describing the survivor.
760
+ const survivor = (await loadAll()).find(
761
+ (m) => m.ts === survivorTs && !m.superseded_by && isVisibleTo(m, reader),
762
+ );
759
763
  if (survivor) {
764
+ // #175: private rows are visible by key OR path. Equal keys alone
765
+ // can drop another checkout's access after an origin change.
766
+ // For global rows, isVisibleTo ignores paths.
767
+ // Match raw paths like isVisibleTo; filesystem aliases need not
768
+ // grant the same readers access. This restricts automatic folds;
769
+ // explicit merge_review authorizes both seats under #131 instead.
770
+ const samePathVisibility = requested.repo === "global" ||
771
+ (target.repoPath ?? "") === (survivor.repoPath ?? "");
760
772
  // The predicate is the REQUESTED state vs the survivor
761
773
  // (round 3): content equality is already proven by the
762
774
  // collapse, so the fold is loss-free only when the
@@ -771,7 +783,8 @@ const impl = {
771
783
  sameStrList(requested.tags, survivor.tags) &&
772
784
  requested.issue === survivor.issue &&
773
785
  requested.status === (survivor.status ?? "settled") &&
774
- requested.repo === (survivor.repo ?? "global")
786
+ requested.repo === (survivor.repo ?? "global") &&
787
+ samePathVisibility
775
788
  ) {
776
789
  const done = await markSuperseded(target.ts, {
777
790
  superseded_by: survivorTs,
@@ -799,12 +812,14 @@ const impl = {
799
812
  differs.push(`tags [${(requested.tags ?? []).join(", ") || "-"}] vs [${(survivor.tags ?? []).join(", ") || "-"}]`);
800
813
  if (requested.repo !== (survivor.repo ?? "global"))
801
814
  differs.push(`visibility ${requested.repo} vs ${survivor.repo ?? "global"}`);
815
+ if (!samePathVisibility) differs.push("repository path visibility differs");
802
816
  return {
803
817
  content:
804
818
  `Duplicate: ${args.type}/${args.scope} stands active as ${survivorTs}, but ${target.ts} ` +
805
819
  `was NOT retired — the survivor does not carry what this update asked for ` +
806
- `(${differs.join("; ")}), and the fold would drop it. Both stay active: restate them ` +
807
- `onto ${survivorTs} with a memory_update, or memory_forget the row that should lose.`,
820
+ `(${differs.join("; ")}), and the fold would drop it. Both stay active. To deliberately ` +
821
+ `keep only the survivor, use memory_merge_review with loser="${target.ts}", ` +
822
+ `survivor="${survivorTs}", and an explicit reason. This keeps the survivor's metadata and visibility.`,
808
823
  };
809
824
  }
810
825
  }
package/src/state.ts CHANGED
@@ -33,7 +33,9 @@ export interface SessionState {
33
33
  pendingGate: {
34
34
  call: string;
35
35
  cmd: string;
36
- chain: ToolResult[];
36
+ chain: string[];
37
+ count: number;
38
+ fix?: { call: string; index: number };
37
39
  } | null;
38
40
  // Bounded provenance for write telemetry (#163), independent of the full
39
41
  // calls ledger used by grounding, attribution, and convergence.
package/src/triggers.ts CHANGED
@@ -33,6 +33,17 @@ export interface AfterOutput {
33
33
  const ENGAGEMENT_TOOLS = new Set(["grep", "glob", "read", "edit", "write", "bash", "shell"]);
34
34
 
35
35
  const RECENT_EVIDENCE_CALLS = 10;
36
+ // Pending recovery stores IDs only; the full attribution ledger stays in calls.
37
+ function trackPending(s: SessionState, rec: ToolResult): void {
38
+ const pending = s.pendingGate;
39
+ if (!pending) return;
40
+ pending.count++;
41
+ if (rec.tool === "edit" || rec.tool === "write") {
42
+ pending.fix = { call: rec.call, index: pending.count };
43
+ }
44
+ pending.chain.push(rec.call);
45
+ if (pending.chain.length > RECENT_EVIDENCE_CALLS) pending.chain.shift();
46
+ }
36
47
  // Recent engagement + latest gate check + FAIL/fix/PASS + tool FAIL/PASS.
37
48
  export const MAX_WRITE_EVIDENCE_REFS = RECENT_EVIDENCE_CALLS + 1 + 3 + 2;
38
49
 
@@ -149,12 +160,12 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
149
160
  rec.cmd = family;
150
161
  await record("gate_check", { cmd: family, status }, true, sid);
151
162
  if (status === "FAIL") {
152
- s.pendingGate = { call, cmd: family, chain: [] };
163
+ s.pendingGate = { call, cmd: family, chain: [], count: 0 };
153
164
  } else if (s.pendingGate && s.pendingGate.cmd === family) {
154
165
  const pend = s.pendingGate;
155
- const chainCalls = [pend.call, ...pend.chain.map((c) => c.call), call];
156
- const edits = pend.chain.filter((c) => c.tool === "edit" || c.tool === "write");
157
- const fix = edits.length ? edits[edits.length - 1].call : call;
166
+ const fix = pend.fix?.call ?? call;
167
+ const oldFix = pend.fix && pend.fix.index <= pend.count - pend.chain.length;
168
+ const chainCalls = [pend.call, ...(oldFix ? [fix] : []), ...pend.chain, call];
158
169
  await record(
159
170
  "t4_learning",
160
171
  {
@@ -164,6 +175,7 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
164
175
  to: "PASS",
165
176
  gate_couple: true,
166
177
  evidence_chain: `[${chainCalls.join(",")}]`,
178
+ evidence_chain_count: pend.count + 2,
167
179
  fix_ref: fix,
168
180
  },
169
181
  false,
@@ -173,14 +185,14 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
173
185
  s.writeEvidence.gateRecovery = [pend.call, fix, call];
174
186
  s.pendingGate = null;
175
187
  } else if (s.pendingGate) {
176
- s.pendingGate.chain.push(rec);
188
+ trackPending(s, rec);
177
189
  }
178
190
  trackCall(s, rec);
179
191
  return;
180
192
  }
181
193
 
182
194
  // Keep the pending gate chain (grep/read/edit between FAIL and PASS).
183
- if (s.pendingGate) s.pendingGate.chain.push(rec);
195
+ trackPending(s, rec);
184
196
  trackCall(s, rec);
185
197
 
186
198
  // ---- Failed -> fixed retry (non-gate tools) -------------------------------