@tangle-network/agent-knowledge 3.2.0 → 3.2.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/dist/index.js CHANGED
@@ -2485,24 +2485,32 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
2485
2485
  if (state.status === "promoted" && !promotedCandidate) {
2486
2486
  throw new Error("promoted knowledge state has no promoted candidate");
2487
2487
  }
2488
- await withKnowledgeMutation(options.root, () => void 0);
2489
- await ensureBaselineSnapshot(runDir, options.root, state.baseHash);
2490
2488
  if (state.status === "promoted") {
2491
2489
  const promoted = promotedCandidate;
2492
- return await applyKnowledgeCandidateTarget(
2493
- {
2494
- root: options.root,
2490
+ const promotedState = state;
2491
+ return withKnowledgeMutation(options.root, async () => {
2492
+ const currentHash = await hashKnowledgeBase(options.root);
2493
+ if (currentHash !== promoted.candidateHash) {
2494
+ throw new Error(
2495
+ `promoted knowledge base changed: expected ${promoted.candidateHash}, got ${currentHash}`
2496
+ );
2497
+ }
2498
+ const evidence2 = await assertCandidateEvidence(
2495
2499
  runDir,
2496
- state,
2497
- candidateRef: candidateRefFor(runId, state, promoted),
2498
- leaseTtlMs: options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS,
2499
- assertRunOwned: lease.assertOwned,
2500
- now,
2501
- onState: options.onState
2502
- },
2503
- "candidate"
2504
- );
2500
+ candidateRefFor(runId, promotedState, promoted)
2501
+ );
2502
+ return {
2503
+ runId,
2504
+ state: promotedState,
2505
+ candidate: promoted,
2506
+ evaluation: evidence2.evaluation,
2507
+ promoted: true,
2508
+ blocked: false
2509
+ };
2510
+ });
2505
2511
  }
2512
+ await withKnowledgeMutation(options.root, () => void 0);
2513
+ await ensureBaselineSnapshot(runDir, options.root, state.baseHash);
2506
2514
  if (state.status === "blocked") {
2507
2515
  return { runId, state, promoted: false, blocked: true };
2508
2516
  }