@tangle-network/agent-eval 0.117.0 → 0.117.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to `@tangle-network/agent-eval` and its sibling `agent-eval-
4
4
 
5
5
  ---
6
6
 
7
+ ## [0.117.1] — 2026-07-13 — retry-safe code-candidate cleanup
8
+
9
+ ### Fixed
10
+
11
+ - `gitWorktreeAdapter().discard()` now reconciles worktree and branch removal independently.
12
+ Repeated cleanup is safe, partial cleanup can be retried, and a Git command that reports an error after completing its mutation no longer strands candidate branches or worktrees.
13
+
7
14
  ## [0.117.0] — 2026-07-13 — durable cost and bounded behavioral evidence
8
15
 
9
16
  ### Added
@@ -17,7 +17,7 @@ import {
17
17
  runBenchmarkAdapter,
18
18
  summarizeBenchmarkCampaign
19
19
  } from "../chunk-JSDVRFAP.js";
20
- import "../chunk-ZUXV7UWZ.js";
20
+ import "../chunk-JSJZ4PJ6.js";
21
21
  import "../chunk-HQPHZGL6.js";
22
22
  import "../chunk-IDZTTFRR.js";
23
23
  import "../chunk-3YYRZDON.js";
@@ -3069,7 +3069,7 @@ interface WorktreeAdapter {
3069
3069
  /** Commit pending changes, freeze the exact Git objects + binary patch, and
3070
3070
  * verify the worktree still matches that identity. */
3071
3071
  finalize(worktree: Worktree, summary: string): Promise<CodeSurface>;
3072
- /** Remove the worktree (and its branch) called for losing candidates. */
3072
+ /** Idempotently remove the worktree and branch. Safe to retry after partial cleanup. */
3073
3073
  discard(worktree: Worktree): Promise<void>;
3074
3074
  }
3075
3075
  /** Typed failure from a `WorktreeAdapter` operation (create/finalize/discard) — wraps the underlying git error as `cause`. */
@@ -66,7 +66,7 @@ import {
66
66
  userStoryScoreboard,
67
67
  validateSearchLedgerEvent,
68
68
  verifyCodeSurface
69
- } from "../chunk-ZUXV7UWZ.js";
69
+ } from "../chunk-JSJZ4PJ6.js";
70
70
  import {
71
71
  assertCodeSurfaceIdentity,
72
72
  buildEvidenceVector,
@@ -7483,6 +7483,45 @@ function gitBytes(git, args, cwd, env) {
7483
7483
  function gitText(git, args, cwd, env) {
7484
7484
  return gitBytes(git, args, cwd, env).toString("utf8").trim();
7485
7485
  }
7486
+ function hasRegisteredWorktree(git, repoRoot, path) {
7487
+ const expected = Buffer.from(`worktree ${resolve3(path)}`, "utf8");
7488
+ const records = gitBytes(git, ["worktree", "list", "--porcelain", "-z"], repoRoot);
7489
+ let start = 0;
7490
+ while (start < records.length) {
7491
+ const end = records.indexOf(0, start);
7492
+ if (end < 0) {
7493
+ throw new WorktreeAdapterError("Git worktree list output was not NUL-terminated");
7494
+ }
7495
+ if (records.subarray(start, end).equals(expected)) return true;
7496
+ start = end + 1;
7497
+ }
7498
+ return false;
7499
+ }
7500
+ function hasLocalBranch(git, repoRoot, branch) {
7501
+ const ref = `refs/heads/${branch}`;
7502
+ return gitText(git, ["for-each-ref", "--format=%(refname)", "--", ref], repoRoot).split("\n").some((candidate) => candidate === ref);
7503
+ }
7504
+ function reconcileAbsent(exists, remove) {
7505
+ try {
7506
+ if (!exists()) return void 0;
7507
+ } catch (err) {
7508
+ return err;
7509
+ }
7510
+ try {
7511
+ remove();
7512
+ return void 0;
7513
+ } catch (removeError) {
7514
+ try {
7515
+ if (!exists()) return void 0;
7516
+ } catch (recheckError) {
7517
+ return new AggregateError(
7518
+ [removeError, recheckError],
7519
+ "Removal failed and the resulting resource state could not be checked"
7520
+ );
7521
+ }
7522
+ return removeError;
7523
+ }
7524
+ }
7486
7525
  function sha2562(bytes) {
7487
7526
  return `sha256:${createHash8("sha256").update(bytes).digest("hex")}`;
7488
7527
  }
@@ -7947,8 +7986,23 @@ function gitWorktreeAdapter(opts) {
7947
7986
  return surface;
7948
7987
  },
7949
7988
  async discard(worktree) {
7950
- gitText(git, ["worktree", "remove", "--force", worktree.path], opts.repoRoot);
7951
- gitText(git, ["branch", "-D", worktree.branch], opts.repoRoot);
7989
+ const failures = [
7990
+ reconcileAbsent(
7991
+ () => hasRegisteredWorktree(git, opts.repoRoot, worktree.path),
7992
+ () => gitText(git, ["worktree", "remove", "--force", "--", worktree.path], opts.repoRoot)
7993
+ ),
7994
+ reconcileAbsent(
7995
+ () => hasLocalBranch(git, opts.repoRoot, worktree.branch),
7996
+ () => gitText(git, ["branch", "-D", "--", worktree.branch], opts.repoRoot)
7997
+ )
7998
+ ].filter((failure) => failure !== void 0);
7999
+ if (failures.length > 0) {
8000
+ const cause = failures.length === 1 ? failures[0] : new AggregateError(failures, "Multiple Git resources could not be removed");
8001
+ throw new WorktreeAdapterError(
8002
+ `Failed to discard worktree ${worktree.path} and branch ${worktree.branch}`,
8003
+ cause
8004
+ );
8005
+ }
7952
8006
  }
7953
8007
  };
7954
8008
  }
@@ -8044,4 +8098,4 @@ export {
8044
8098
  verifyCodeSurface,
8045
8099
  resolveWorktreePath
8046
8100
  };
8047
- //# sourceMappingURL=chunk-ZUXV7UWZ.js.map
8101
+ //# sourceMappingURL=chunk-JSJZ4PJ6.js.map