Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
[issue-11657] Share goal-fidelity evidence pass orchestration (#11702)
[._.]/3da3b6a80ec9
diff --git a/server/services/codeReview.goalFidelityEvidence.test.js b/server/services/codeReview.goalFidelityEvidence.test.jsnew file mode 100644index 0000000000..cd933a9a6e--- /dev/null+++ b/server/services/codeReview.goalFidelityEvidence.test.js@@ -0,0 +1,81 @@+import { describe, it, expect, vi, afterAll, afterEach } from 'vitest'+import { writeFileSync, rmSync } from 'node:fs'+import { join } from 'node:path'+import sharp from 'sharp'+import { mockJsonResponse } from '../lib/testHelper.js'++const fixturePaths = vi.hoisted(() => ({ root: null, screenshots: null }))+vi.mock('../lib/fileUtils.js', async (importOriginal) => {+ const actual = await importOriginal()+ const { mkdtempSync, mkdirSync } = await import('node:fs')+ const { tmpdir } = await import('node:os')+ const { join } = await import('node:path')+ fixturePaths.root = mkdtempSync(join(tmpdir(), 'portos-fidelity-evidence-'))+ fixturePaths.screenshots = join(fixturePaths.root, 'screenshots')+ mkdirSync(fixturePaths.screenshots)+ return { ...actual, PATHS: { ...actual.PATHS, screenshots: fixturePaths.screenshots } }+})+vi.mock('./ollamaManager.js', () => ({ getModelCapabilities: async () => null }))++import { runLocalGoalFidelityReview } from './codeReview.js'++// Unlike primary-only vision coverage, this exercises both secondary passes+// with images, overlapping objective scopes, and one shared timeout budget.+describe('goal-fidelity evidence workflow', () => {+ afterAll(() => fixturePaths.root && rmSync(fixturePaths.root, { recursive: true, force: true }))+ afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals() })++ it('keeps screenshot context and primary findings through retained and after-change checks', async () => {+ const image = await sharp({ create: { width: 8, height: 8, channels: 3, background: '#ffffff' } }).png().toBuffer()+ writeFileSync(join(fixturePaths.screenshots, 'card.png'), image)+ const objective = 'Keep summaries hidden on completed-agent cards until Show.\n\nAudit expected processes and implement one finding: remove retired-worker.'+ const diff = [+ 'diff --git a/runtime.js b/runtime.js', '--- a/runtime.js', '+++ b/runtime.js',+ '@@ -1,2 +1,2 @@', '-const names = ["retired-worker"];', '+const names = [];',+ ' const process = { name: "retired-worker" };',+ ].join('\n')+ const primary = { verdict: 'fix-first', missing: ['primary finding'], unrequested: ['primary scope'], evidence: 'primary verification note' }+ const verdicts = [primary,+ { verdict: 'fix-first', missing: ['retained finding', 'primary finding'], unrequested: ['secondary scope'], evidence: 'retained note' },+ { verdict: 'rethink', missing: [], unrequested: ['after-change scope'], evidence: 'after-change finding' },+ ]+ let now = 0+ vi.spyOn(Date, 'now').mockImplementation(() => now)+ const budgets = []+ const timeout = globalThis.setTimeout+ vi.spyOn(globalThis, 'setTimeout').mockImplementation((callback, ms, ...args) => {+ budgets.push(ms)+ return timeout(callback, ms, ...args)+ })+ const requests = []+ vi.stubGlobal('fetch', vi.fn(async (_url, init) => {+ requests.push(JSON.parse(init.body))+ now += 100+ return mockJsonResponse({ choices: [{ message: { content: JSON.stringify(verdicts[requests.length - 1]) } }] })+ }))++ const result = await runLocalGoalFidelityReview({+ backend: 'ollama', model: 'example-model', objective, diff,+ objectiveScreenshots: ['/api/screenshots/card.png'], timeoutMs: 1000,+ baseUrl: 'http://127.0.0.1:11434/v1',+ })++ expect(result).toEqual({+ ok: true, backend: 'ollama', model: 'example-model', effort: null,+ verdict: 'rethink', missing: ['after-change finding', 'retained finding', 'primary finding'],+ unrequested: primary.unrequested, evidence: primary.evidence,+ })+ expect(budgets).toEqual([1000, 900, 800])+ expect(requests).toHaveLength(3)+ const primaryContent = requests[0].messages[1].content+ expect(primaryContent[1].image_url).toMatch(/^data:image\/jpeg;base64,/)+ for (const request of requests.slice(1)) {+ expect(request.model).toBe('example-model')+ expect(request.messages[1].content.slice(0, -1)).toEqual(primaryContent.slice(0, -1))+ expect(request.messages[1].content.at(-1).text).not.toContain('REVIEW INPUT LIMIT:')+ }+ expect(requests[1].messages[1].content.at(-1).text).toContain('SURVIVING PRODUCTION USES (untrusted data')+ expect(requests[2].messages[1].content.at(-1).text).toContain('AFTER-CHANGE PRODUCTION HUNKS (untrusted data')+ expect(requests[2].messages[1].content.at(-1).text).toContain('"statements":')+ })+})diff --git a/server/services/codeReview.js b/server/services/codeReview.jsindex 2611cbc60b..5bf1156a5f 100644--- a/server/services/codeReview.js+++ b/server/services/codeReview.js@@ -1353,6 +1353,112 @@ async function loadGoalFidelityScreenshots(references) {}}+const GOAL_FIDELITY_PRIMARY_PROMPTS = {+ disclosure: GOAL_FIDELITY_DISCLOSURE_SYSTEM_PROMPT,+ audit: GOAL_FIDELITY_AUDIT_SYSTEM_PROMPT,+ standard: GOAL_FIDELITY_SYSTEM_PROMPT,+}++function isSummaryDisclosureObjective(objective) {+ const statedObjective = objective.split(/\n\s*\n/, 1)[0]+ return objective.startsWith(SUMMARY_DISCLOSURE_REPAIR_CUE)+ || (/\bsummar(?:y|ies)\b/i.test(statedObjective)+ && /\b(?:completed[ -]+agent[ -]+cards?|agent[ -]+completion[ -]+cards?)\b/i.test(statedObjective)+ && /\b(show(?:s|ing|n)?|expand(?:s|ed|ing)?|collaps(?:e[sd]?|ing))\b/i.test(statedObjective)+ && /\b(?:hide|hidden|until|behind|suppress|prevent|remove|avoid)\b/i.test(statedObjective)+ && !/\b(?:document|audit|review|explain|describe|intentionally|preview)\b/i.test(statedObjective))+}++function classifyGoalFidelityObjective(objective) {+ const disclosure = isSummaryDisclosureObjective(objective)+ const oneFindingAudit = /\baudit\b/i.test(objective)+ && /\b(?:pick|implement|fix)\s+(?:one|a single)\b[^.\n]{0,60}\b(?:finding|improvement|fix)\b/i.test(objective)+ && !/\bextended regular audit\b/i.test(objective)+ const backfill = oneFindingAudit && /\bbackfill(?:FromHistory)?\b/i.test(objective)+ return {+ kind: disclosure ? 'disclosure' : oneFindingAudit ? 'audit' : 'standard',+ // Audit scope can coexist with a disclosure objective in a later paragraph.+ audit: oneFindingAudit,+ backfill,+ accountingOutcome: backfill && /\bexclude\b[^.\n]{0,100}\bfail(?:ed|ures?)?\b[^.\n]{0,100}\b(?:success|total|count)\b/i.test(objective),+ warningSummaryOutcome: backfill && /\b(?:emit|log|report)\b[^.\n]{0,80}\bwarn(?:ing)?\b[^.\n]{0,40}\bsummary\b/i.test(objective),+ }+}++function evidenceContent(userContent, objectiveBlock, block) {+ return Array.isArray(userContent)+ ? [...userContent.slice(0, -1), { type: 'text', text: block }]+ : `${objectiveBlock}\n\n${block}`+}++async function runGoalFidelityEvidencePass({ backend, model, effort, baseUrl, startedAt, timeoutMs, systemPrompt, content, timeoutError, verdictError }) {+ const remainingMs = timeoutMs - (Date.now() - startedAt)+ if (remainingMs <= 0) return { ok: false, backend, model, error: timeoutError }+ const audit = await runReviewerCompletion({+ backend, model, effort, timeoutMs: remainingMs, baseUrl,+ messages: [+ { role: 'system', content: systemPrompt },+ { role: 'user', content: content() },+ ],+ })+ if (!audit.ok) return audit+ const parsed = extractJson(audit.content, { shapePredicate: value => value !== null && typeof value === 'object' && !Array.isArray(value) }).value+ const verdict = normalizeGoalFidelityVerdict(parsed)+ if (!verdict) return { ok: false, backend, model, error: verdictError }+ return { ok: true, verdict }+}++function escalateGoalFidelityVerdict(verdict, nextVerdict, findings, { normalize = true } = {}) {+ const escalated = {+ ...verdict,+ verdict: nextVerdict,+ missing: [...new Set([...findings, ...verdict.missing])],+ }+ // The contextual-catch pass historically defers normalization to the primary merge.+ Object.assign(verdict, normalize ? normalizeGoalFidelityVerdict(escalated) : escalated)+}++function goalFidelityProductionChecks(objectiveClass, diff) {+ const { audit: oneFindingAudit } = objectiveClass+ const rows = oneFindingAudit ? productionAuditEvidence(diff) : productionAfterChangeHunks(diff)+ const checks = [{+ label: 'AFTER-CHANGE PRODUCTION HUNKS',+ prompt: oneFindingAudit ? GOAL_FIDELITY_AUDIT_PRODUCTION_PROMPT : GOAL_FIDELITY_DISCLOSURE_PRODUCTION_PROMPT,+ evidence: rows,+ }]+ // A holistic audit can still overlook one requested outcome. Check these+ // named backfill outcomes independently with focused syntax evidence.+ if (objectiveClass.accountingOutcome) checks.push({+ label: 'HANDLED-REJECTION ACCOUNTING',+ format: 'text',+ prompt: GOAL_FIDELITY_ACCOUNTING_PROMPT,+ objective: 'Exclude failed records from the success total.',+ evidence: rows.some(row => row.handledRejectionScenarios.length)+ ? rows.flatMap(row => row.handledRejectionScenarios.map(scenario =>+ `File: ${row.file}\nHunk: ${row.hunk}\nAssumption: ${scenario.assumption}\nAwaited binding statement: ${scenario.bindingStatement}\n${scenario.trace}`)).join('\n\n')+ : JSON.stringify(rows.map(({ file, hunk, source }) => ({ file, hunk, source }))),+ })+ if (objectiveClass.warningSummaryOutcome) checks.push({+ label: 'SUMMARY LEVEL ARGUMENTS',+ format: 'text',+ prompt: GOAL_FIDELITY_SEVERITY_PROMPT,+ objective: 'Emit a warning summary when failed records exist.',+ evidence: rows.flatMap(row => row.statements.flatMap(statement => statement.facts+ .filter(fact => fact.kind === 'call' && fact.callee === 'emitLog')+ .map(fact => `File: ${row.file}\nHunk: ${row.hunk}\nSyntax: ${statement.syntax}\nComplete statement: ${statement.source}\nLogging call: ${fact.source}\nLevel argument: ${fact.arguments[0]}\nParsed conditions: ${JSON.stringify(fact.conditions)}\nCallback contexts: ${JSON.stringify(fact.callbacks)}`))).join('\n\n')+ || JSON.stringify(rows.map(({ file, hunk, source }) => ({ file, hunk, source }))),+ })+ return checks.map(check => ({ ...check, evidence: typeof check.evidence === 'string' ? check.evidence : JSON.stringify(check.evidence) }))+}++function mergeGoalFidelityEvidenceVerdict(verdict, auditedVerdict) {+ if (auditedVerdict.verdict === 'ship') return+ // A narrow evidence pass adds findings without replacing the primary+ // verification and scope assessment.+ const findings = auditedVerdict.missing.length ? auditedVerdict.missing : [auditedVerdict.evidence].filter(Boolean)+ escalateGoalFidelityVerdict(verdict, auditedVerdict.verdict, findings)+}+export async function runLocalGoalFidelityReview({ backend, model, objective, diff, objectiveScreenshots, effort = null, timeoutMs = 120000, baseUrl = null } = {}) {if (!isLocalLlmReviewer(backend)) {return { ok: false, error: `Unsupported reviewer backend: ${backend}` }@@ -1399,19 +1505,10 @@ export async function runLocalGoalFidelityReview({ backend, model, objective, di{ type: 'text', text: `${diffBlock}\n\n${coverageNote}` },]: `${objectiveBlock}\n\n${diffBlock}\n\n${coverageNote}`- const statedObjective = trimmedObjective.split(/\n\s*\n/, 1)[0]- const summaryDisclosureObjective = trimmedObjective.startsWith(SUMMARY_DISCLOSURE_REPAIR_CUE)- || (/\bsummar(?:y|ies)\b/i.test(statedObjective)- && /\b(?:completed[ -]+agent[ -]+cards?|agent[ -]+completion[ -]+cards?)\b/i.test(statedObjective)- && /\b(show(?:s|ing|n)?|expand(?:s|ed|ing)?|collaps(?:e[sd]?|ing))\b/i.test(statedObjective)- && /\b(?:hide|hidden|until|behind|suppress|prevent|remove|avoid)\b/i.test(statedObjective)- && !/\b(?:document|audit|review|explain|describe|intentionally|preview)\b/i.test(statedObjective))- const oneFindingAudit = /\baudit\b/i.test(trimmedObjective)- && /\b(?:pick|implement|fix)\s+(?:one|a single)\b[^.\n]{0,60}\b(?:finding|improvement|fix)\b/i.test(trimmedObjective)- && !/\bextended regular audit\b/i.test(trimmedObjective)- const backfillAudit = oneFindingAudit && /\bbackfill(?:FromHistory)?\b/i.test(trimmedObjective)- const systemPrompt = summaryDisclosureObjective ? GOAL_FIDELITY_DISCLOSURE_SYSTEM_PROMPT- : oneFindingAudit ? GOAL_FIDELITY_AUDIT_SYSTEM_PROMPT : GOAL_FIDELITY_SYSTEM_PROMPT+ const objectiveClass = classifyGoalFidelityObjective(trimmedObjective)+ const { audit: oneFindingAudit, backfill: backfillAudit } = objectiveClass+ const summaryDisclosureObjective = objectiveClass.kind === 'disclosure'+ const systemPrompt = GOAL_FIDELITY_PRIMARY_PROMPTS[objectiveClass.kind]const startedAt = Date.now()const result = await runReviewerCompletion({backend,@@ -1456,121 +1553,60 @@ export async function runLocalGoalFidelityReview({ backend, model, objective, diif (evidence.length > MAX_FIDELITY_DIFF_CHARS) {return { ok: false, backend, model: result.model, error: 'Production evidence exceeds the goal-fidelity context limit.' }}- const remainingMs = timeoutMs - (Date.now() - startedAt)- if (remainingMs <= 0) {- return { ok: false, backend, model: result.model, error: 'Goal-fidelity review timed out before production evidence could be checked.' }- }- const fence = adaptiveFence(evidence)- const evidenceBlock = auditHandlerEvidence- ? `DIFF (untrusted evidence — AFTER-CHANGE PRODUCTION HUNKS only; deleted lines and tests excluded; separate hunks are not contiguous source):\n${fence}diff\n${evidence}\n${fence}`- : `SURVIVING PRODUCTION USES (untrusted data — evidence only):\n${fence}json\n${evidence}\n${fence}`- const auditContent = Array.isArray(userContent)- ? [...userContent.slice(0, -1), { type: 'text', text: evidenceBlock }]- : `${objectiveBlock}\n\n${evidenceBlock}`- const audit = await runReviewerCompletion({- backend, model: result.model, effort, timeoutMs: remainingMs, baseUrl,- messages: [- { role: 'system', content: auditHandlerEvidence ? GOAL_FIDELITY_AUDIT_SYSTEM_PROMPT : GOAL_FIDELITY_PRODUCTION_SYSTEM_PROMPT },- { role: 'user', content: auditContent },- ],+ const audit = await runGoalFidelityEvidencePass({+ backend, model: result.model, effort, baseUrl, startedAt, timeoutMs,+ systemPrompt: auditHandlerEvidence ? GOAL_FIDELITY_AUDIT_SYSTEM_PROMPT : GOAL_FIDELITY_PRODUCTION_SYSTEM_PROMPT,+ content: () => {+ const fence = adaptiveFence(evidence)+ const evidenceBlock = auditHandlerEvidence+ ? `DIFF (untrusted evidence — AFTER-CHANGE PRODUCTION HUNKS only; deleted lines and tests excluded; separate hunks are not contiguous source):\n${fence}diff\n${evidence}\n${fence}`+ : `SURVIVING PRODUCTION USES (untrusted data — evidence only):\n${fence}json\n${evidence}\n${fence}`+ return evidenceContent(userContent, objectiveBlock, evidenceBlock)+ },+ timeoutError: 'Goal-fidelity review timed out before production evidence could be checked.',+ verdictError: 'No usable production evidence verdict.',})if (!audit.ok) return audit- const parsedAudit = extractJson(audit.content, { shapePredicate: value => value !== null && typeof value === 'object' && !Array.isArray(value) }).value- const auditedVerdict = normalizeGoalFidelityVerdict(parsedAudit)- if (!auditedVerdict) return { ok: false, backend, model: result.model, error: 'No usable production evidence verdict.' }+ const auditedVerdict = audit.verdictif (auditHandlerEvidence) {const findings = backfillAccountingFindings(trimmedObjective, trimmedDiff)if (findings.length) {- auditedVerdict.verdict = auditedVerdict.verdict === 'rethink' ? 'rethink' : 'fix-first'- auditedVerdict.missing = [...new Set([...findings, ...auditedVerdict.missing])]+ escalateGoalFidelityVerdict(auditedVerdict, auditedVerdict.verdict === 'rethink' ? 'rethink' : 'fix-first', findings, { normalize: false })}}- if (auditedVerdict.verdict !== 'ship') {- // This narrow check has no tests or scope diff. Preserve the primary- // verification/scope assessment and add only its production finding.- const findings = auditedVerdict.missing.length ? auditedVerdict.missing : [auditedVerdict.evidence].filter(Boolean)- Object.assign(verdict, normalizeGoalFidelityVerdict({- ...verdict,- verdict: auditedVerdict.verdict,- missing: [...new Set([...findings, ...verdict.missing])],- }))- }+ mergeGoalFidelityEvidenceVerdict(verdict, auditedVerdict)}}const auditProductionCheck = backfillAudit|| (oneFindingAudit && productionAfterChangeHunks(trimmedDiff).length === 0)if ((summaryDisclosureObjective || auditProductionCheck) && verdict.verdict !== 'rethink') {- const rows = oneFindingAudit ? productionAuditEvidence(trimmedDiff) : productionAfterChangeHunks(trimmedDiff)- const checks = [{- label: 'AFTER-CHANGE PRODUCTION HUNKS',- prompt: oneFindingAudit ? GOAL_FIDELITY_AUDIT_PRODUCTION_PROMPT : GOAL_FIDELITY_DISCLOSURE_PRODUCTION_PROMPT,- evidence: rows,- }]- // A holistic audit can still overlook one requested outcome. Check these- // named backfill outcomes independently with focused syntax evidence.- if (backfillAudit && /\bexclude\b[^.\n]{0,100}\bfail(?:ed|ures?)?\b[^.\n]{0,100}\b(?:success|total|count)\b/i.test(trimmedObjective)) checks.push({- label: 'HANDLED-REJECTION ACCOUNTING',- format: 'text',- prompt: GOAL_FIDELITY_ACCOUNTING_PROMPT,- objective: 'Exclude failed records from the success total.',- evidence: rows.some(row => row.handledRejectionScenarios.length)- ? rows.flatMap(row => row.handledRejectionScenarios.map(scenario =>- `File: ${row.file}\nHunk: ${row.hunk}\nAssumption: ${scenario.assumption}\nAwaited binding statement: ${scenario.bindingStatement}\n${scenario.trace}`)).join('\n\n')- : JSON.stringify(rows.map(({ file, hunk, source }) => ({ file, hunk, source }))),- })- if (backfillAudit && /\b(?:emit|log|report)\b[^.\n]{0,80}\bwarn(?:ing)?\b[^.\n]{0,40}\bsummary\b/i.test(trimmedObjective)) checks.push({- label: 'SUMMARY LEVEL ARGUMENTS',- format: 'text',- prompt: GOAL_FIDELITY_SEVERITY_PROMPT,- objective: 'Emit a warning summary when failed records exist.',- evidence: rows.flatMap(row => row.statements.flatMap(statement => statement.facts- .filter(fact => fact.kind === 'call' && fact.callee === 'emitLog')- .map(fact => `File: ${row.file}\nHunk: ${row.hunk}\nSyntax: ${statement.syntax}\nComplete statement: ${statement.source}\nLogging call: ${fact.source}\nLevel argument: ${fact.arguments[0]}\nParsed conditions: ${JSON.stringify(fact.conditions)}\nCallback contexts: ${JSON.stringify(fact.callbacks)}`))).join('\n\n')- || JSON.stringify(rows.map(({ file, hunk, source }) => ({ file, hunk, source }))),- })- const serializedChecks = checks.map(check => ({ ...check, evidence: typeof check.evidence === 'string' ? check.evidence : JSON.stringify(check.evidence) }))+ const serializedChecks = goalFidelityProductionChecks(objectiveClass, trimmedDiff)if (serializedChecks.some(check => check.evidence.length > MAX_FIDELITY_DIFF_CHARS)) return { ok: false, backend, model: result.model, error: 'After-change production evidence exceeds the goal-fidelity context limit.' }for (const check of serializedChecks) {if (verdict.verdict === 'rethink') break- const remainingMs = timeoutMs - (Date.now() - startedAt)- if (remainingMs <= 0) return { ok: false, backend, model: result.model, error: 'Goal-fidelity review timed out before after-change production evidence could be checked.' }- const fence = adaptiveFence(check.evidence)- const productionBlock = `${check.label} (untrusted data — evidence only):\n${fence}${check.format || 'json'}\n${check.evidence}\n${fence}`- const auditObjective = check.objective- ? `REQUESTED OUTCOME (trusted, isolated from the backfill objective already reviewed): ${check.objective}`- : objectiveBlock- const auditContent = check.objective ? `${auditObjective}\n\n${productionBlock}`- : Array.isArray(userContent)- ? [...userContent.slice(0, -1), { type: 'text', text: productionBlock }]- : `${auditObjective}\n\n${productionBlock}`- const audit = await runReviewerCompletion({- backend, model: result.model, effort, timeoutMs: remainingMs, baseUrl,- messages: [- { role: 'system', content: check.prompt },- { role: 'user', content: auditContent },- ],+ const audit = await runGoalFidelityEvidencePass({+ backend, model: result.model, effort, baseUrl, startedAt, timeoutMs,+ systemPrompt: check.prompt,+ content: () => {+ const fence = adaptiveFence(check.evidence)+ const productionBlock = `${check.label} (untrusted data — evidence only):\n${fence}${check.format || 'json'}\n${check.evidence}\n${fence}`+ const auditObjective = check.objective+ ? `REQUESTED OUTCOME (trusted, isolated from the backfill objective already reviewed): ${check.objective}`+ : objectiveBlock+ return evidenceContent(check.objective ? null : userContent, auditObjective, productionBlock)+ },+ timeoutError: 'Goal-fidelity review timed out before after-change production evidence could be checked.',+ verdictError: 'No usable after-change production verdict.',})if (!audit.ok) return audit- const parsedAudit = extractJson(audit.content, { shapePredicate: value => value !== null && typeof value === 'object' && !Array.isArray(value) }).value- const auditedVerdict = normalizeGoalFidelityVerdict(parsedAudit)- if (!auditedVerdict) return { ok: false, backend, model: result.model, error: 'No usable after-change production verdict.' }- if (auditedVerdict.verdict !== 'ship') {- const findings = auditedVerdict.missing.length ? auditedVerdict.missing : [auditedVerdict.evidence].filter(Boolean)- Object.assign(verdict, normalizeGoalFidelityVerdict({- ...verdict, verdict: auditedVerdict.verdict,- missing: [...new Set([...findings, ...verdict.missing])],- }))- }+ mergeGoalFidelityEvidenceVerdict(verdict, audit.verdict)}}// Preserve the fail-only production floor from the contextual-catch// calibration. Focused model checks above cannot waive proven contradictions.if (backfillAudit && verdict.verdict !== 'rethink') {const findings = backfillAccountingFindings(trimmedObjective, trimmedDiff)- if (findings.length) Object.assign(verdict, normalizeGoalFidelityVerdict({- ...verdict, verdict: 'fix-first',- missing: [...new Set([...findings, ...verdict.missing])],- }))+ if (findings.length) escalateGoalFidelityVerdict(verdict, 'fix-first', findings)}return {