@productbrain/mcp 0.0.1-beta.8955 → 0.0.1-beta.8962

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.
@@ -2424,6 +2424,41 @@ async function runConflictPreflight(name, description, collectionHint) {
2424
2424
  }
2425
2425
  }
2426
2426
 
2427
+ // src/lib/judgeWait.ts
2428
+ var JUDGE_TIMEOUT_MS = 3e4;
2429
+ var JUDGE_CALLS_PER_RUN = 2;
2430
+ var JUDGE_WAIT_BOUND_MS = JUDGE_CALLS_PER_RUN * JUDGE_TIMEOUT_MS + 5e3;
2431
+ var POLL_MS = 1e3;
2432
+ async function settleVerdictBeforeAccept(evaluate, readLatest, opts = {}) {
2433
+ const now = opts.now ?? Date.now;
2434
+ const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
2435
+ const bound = opts.boundMs ?? JUDGE_WAIT_BOUND_MS;
2436
+ let evaluation = null;
2437
+ try {
2438
+ evaluation = await evaluate();
2439
+ } catch {
2440
+ return { evaluation: null, latest: null, waitedMs: 0, judged: false };
2441
+ }
2442
+ if (!evaluation?.judgeInFlight && !evaluation?.reused) return { evaluation, latest: null, waitedMs: 0, judged: false };
2443
+ const inFlight = evaluation.judgeInFlight === true;
2444
+ const start = now();
2445
+ let latest = null;
2446
+ for (; ; ) {
2447
+ try {
2448
+ latest = await readLatest();
2449
+ } catch {
2450
+ return { evaluation, latest, waitedMs: now() - start, judged: false };
2451
+ }
2452
+ if (latest?.verdict?.llmStatus !== "pending") return { evaluation, latest, waitedMs: now() - start, judged: inFlight };
2453
+ if (now() - start >= bound) return { evaluation, latest, waitedMs: now() - start, judged: false };
2454
+ await sleep(POLL_MS);
2455
+ }
2456
+ }
2457
+ function judgedAcceptedLine(wait) {
2458
+ if (!wait?.judged) return null;
2459
+ return `Judged in ${Math.max(1, Math.round(wait.waitedMs / 1e3))} s, accepted.`;
2460
+ }
2461
+
2427
2462
  // src/tools/knowledge/updateEntryAppliedFields.ts
2428
2463
  function computeUpdateEntryAppliedFields(args, normalization, provenanceApplied = {}, revertedFields = []) {
2429
2464
  const rejectedDataFields = normalization?.rejected ?? [];
@@ -2671,16 +2706,12 @@ async function handleCommitEntry({ entryId, preview, steeringOverrideReason, coh
2671
2706
  confidence: c.confidence,
2672
2707
  explanation: c.explanation
2673
2708
  })) : [];
2674
- let coachingResult = null;
2675
- if (!preview) {
2676
- try {
2677
- coachingResult = await kernelMutation("quality.evaluateHeuristicAndSchedule", {
2678
- entryId,
2679
- context: "commit"
2680
- });
2681
- } catch {
2682
- }
2683
- }
2709
+ const judgeWait = preview ? null : await settleVerdictBeforeAccept(
2710
+ () => kernelMutation("quality.evaluateHeuristicAndSchedule", { entryId, context: "commit" }),
2711
+ () => kernelQuery("quality.getLatestVerdictForEntry", { entryId })
2712
+ );
2713
+ const stored = judgeWait?.latest?.verdict;
2714
+ const coachingResult = stored ? { verdict: stored, source: stored.source } : judgeWait?.evaluation ?? null;
2684
2715
  let result2;
2685
2716
  try {
2686
2717
  result2 = await kernelMutation("chain.commitEntry", {
@@ -2760,8 +2791,10 @@ No DB writes \u2014 call without \`preview:true\` to accept for real.` }],
2760
2791
  commit_method: "manual",
2761
2792
  surface: "mcp_commit_tool"
2762
2793
  });
2794
+ const judged = judgedAcceptedLine(judgeWait);
2763
2795
  const lines = [
2764
2796
  `# Accepted: ${entryId}`,
2797
+ ...judged ? [judged] : [],
2765
2798
  `**${entry.name}** promoted to SSOT on the Chain.`,
2766
2799
  `**Workspace:** ${wsCtx.workspaceSlug} (${wsCtx.workspaceId})`
2767
2800
  ];
@@ -2792,7 +2825,8 @@ No DB writes \u2014 call without \`preview:true\` to accept for real.` }],
2792
2825
  source: coachingResult.source ?? "heuristic",
2793
2826
  criteria_total: v.criteria?.length ?? 0,
2794
2827
  criteria_failed: failedCount,
2795
- llm_scheduled: v.tier !== "passive",
2828
+ llm_scheduled: judgeWait?.evaluation?.reused !== true && v.tier !== "passive",
2829
+ // TASK-612: a reused verdict schedules nothing
2796
2830
  methodology_version: v.methodologyVersion
2797
2831
  });
2798
2832
  } catch {
@@ -2862,6 +2896,8 @@ No DB writes \u2014 call without \`preview:true\` to accept for real.` }],
2862
2896
  outcome: "committed",
2863
2897
  qualityVerdict: coachingResult?.verdict ?? void 0,
2864
2898
  source: coachingResult?.source ?? void 0,
2899
+ ...judgeWait?.judged ? { judgedInMs: judgeWait.waitedMs } : {},
2900
+ // TASK-612
2865
2901
  contradictions: advisoryWarnings.length,
2866
2902
  ...epistemic ? { epistemicStatus: epistemic } : {},
2867
2903
  ...steeringAdvisory ? { steeringAdvisory } : {},
@@ -13612,4 +13648,4 @@ export {
13612
13648
  createProductBrainServer,
13613
13649
  initFeatureFlags
13614
13650
  };
13615
- //# sourceMappingURL=chunk-AXHFX5FE.js.map
13651
+ //# sourceMappingURL=chunk-FJ7SUWUN.js.map