From 330fd690132616e62046a05dc184a25522b8099f Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:13:46 +0800 Subject: [PATCH 1/2] Show verification evidence in the Goal research workbench Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- .../presentation/dashboard/src/data/status.ts | 10 ++ .../personal-workspace/goal-overview.tsx | 11 +- .../goal-research-history.tsx | 27 ++- .../goal-research-workbench.tsx | 3 +- .../goal-verification-workbench.css | 52 ++++++ .../goal-verification-workbench.tsx | 165 ++++++++++++++++++ .../personal-workspace-model.ts | 3 +- .../personal-workspace-page.tsx | 15 +- .../dashboard/src/views/dashboard-page.tsx | 1 + loopx/capabilities/explore/README.md | 19 ++ loopx/capabilities/explore/README.zh-CN.md | 13 ++ .../explore_execution_observation.ts | 14 +- .../explore_verification_evidence.ts | 91 ++++++++++ .../presentation/explore_history.ts | 5 +- .../presentation/verification_workbench.ts | 56 ++++++ .../verification_workbench.test.ts | 82 +++++++++ 16 files changed, 553 insertions(+), 14 deletions(-) create mode 100644 apps/presentation/dashboard/src/features/personal-workspace/goal-verification-workbench.css create mode 100644 apps/presentation/dashboard/src/features/personal-workspace/goal-verification-workbench.tsx create mode 100644 loopx/control_plane/capabilities/explore_verification_evidence.ts create mode 100644 loopx/control_plane/presentation/verification_workbench.ts create mode 100644 tests/control_plane_ts/verification_workbench.test.ts diff --git a/apps/presentation/dashboard/src/data/status.ts b/apps/presentation/dashboard/src/data/status.ts index 4c778ac672..8537274fa4 100644 --- a/apps/presentation/dashboard/src/data/status.ts +++ b/apps/presentation/dashboard/src/data/status.ts @@ -552,7 +552,17 @@ export const runRecordSchema = z.object({ project_map: projectMapSchema.optional().nullable(), }); +const goalArtifactLifecycleSchema = z.object({ + schema_version: z.literal("goal_artifact_lifecycle_projection_v0"), + goal_id: z.string(), + guards: z.array(z.object({ + id: z.string(), kind: z.string(), owner: z.string(), blocked: z.boolean(), + })), +}); +export type GoalArtifactLifecycle = z.infer; + export const runGoalSchema = z.object({ + artifact_lifecycle: goalArtifactLifecycleSchema.optional().nullable().catch(null), source_access: z.object({namespace: z.string(), label: z.string(), read_only: z.literal(true), original_goal_id: z.string().optional()}).optional(), parent_goal_id: z.string().nullable().optional().catch(null), goal_objective: z.string().nullable().optional().catch(null), diff --git a/apps/presentation/dashboard/src/features/personal-workspace/goal-overview.tsx b/apps/presentation/dashboard/src/features/personal-workspace/goal-overview.tsx index 54f97a3148..c7f10f130d 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/goal-overview.tsx +++ b/apps/presentation/dashboard/src/features/personal-workspace/goal-overview.tsx @@ -29,7 +29,8 @@ function relativeLookLabel(iso: string, locale: string): string { return new Intl.DateTimeFormat(locale === "zh-CN" ? "zh-CN" : "en", { month: "short", day: "numeric" }).format(then); } -export function GoalOverview({ active, goal, items, userTodos, readOnly, onOpenDetails, onSelect, onView, selectedTodoId, board, proposals, onPreview, historyRefreshRevision, review, digest, railOpen, onCloseRail, onOpenAgentConversation, sinceYouLooked, onMarkSeen }: { +export function GoalOverview({ active, goal, items, userTodos, readOnly, onOpenDetails, onSelect, onView, onOpenVerification, selectedTodoId, board, proposals, onPreview, historyRefreshRevision, review, digest, railOpen, onCloseRail, onOpenAgentConversation, sinceYouLooked, onMarkSeen }: { + onOpenVerification: () => void; onOpenAgentConversation?: (agentId: string) => void; /** Material changes since the owner's last acknowledged look; null when none. */ sinceYouLooked?: SinceYouLookedDelta | null; onMarkSeen?: () => void; @@ -109,8 +110,14 @@ export function GoalOverview({ active, goal, items, userTodos, readOnly, onOpenD {moreAttention ? : null} : null} map={readOnly ?

{copy.remote}

: }/> - {readOnly ? + {readOnly ? <> + {goal.sourceAccess ? : null} : + } ; diff --git a/apps/presentation/dashboard/src/features/personal-workspace/goal-research-history.tsx b/apps/presentation/dashboard/src/features/personal-workspace/goal-research-history.tsx index e695ca134a..fe4efcd34a 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/goal-research-history.tsx +++ b/apps/presentation/dashboard/src/features/personal-workspace/goal-research-history.tsx @@ -2,6 +2,7 @@ import {ExecutionObservationReadback, WorkYardstickReadback} from "./work-yardst import {GoalSourceStrategies, useGoalStrategyLocation} from "./goal-source-strategies"; import {exploreFindingCopy} from "./explore-finding-copy"; import {AlertCircle, ArrowLeft, ArrowRight, Circle, CircleHelp, FlaskConical, GitBranch, RefreshCw, Search} from "lucide-react"; +import {GoalVerificationWorkbench, type GoalVerificationSources} from "./goal-verification-workbench"; import {Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState} from "react"; import {defaultParseSearch} from "@tanstack/react-router"; import {ResearchRecordSearch, useResearchRecordsLocation} from "./research-record-browser"; @@ -53,9 +54,11 @@ const viewFromUrl = (goal: string) => { /** An effect-free history consumer. Its source is Explore, not raw sessions or * a judge. All recorded updates survive; unsupported analysis stays unavailable. */ -export function GoalResearchHistory({goalId, originalGoalId = goalId, preferHistory = false, active, zh, refreshRevision = 0, readSourceUrl, onOpenSourceTasks}: { +export function GoalResearchHistory({goalId, originalGoalId = goalId, preferHistory = false, active, zh, refreshRevision = 0, readSourceUrl, onOpenSourceTasks, verification, showVerification}: { goalId: string; originalGoalId?: string; preferHistory?: boolean; active: boolean; zh: boolean; refreshRevision?: number; readSourceUrl?: string; onOpenSourceTasks?: () => void; + verification?: GoalVerificationSources; + showVerification?: number; }) { const strategies = useGoalStrategyLocation(goalId, readSourceUrl); const analysis = useResearchAnalysis(goalId, active, zh, readSourceUrl); @@ -75,7 +78,15 @@ export function GoalResearchHistory({goalId, originalGoalId = goalId, preferHist const deferHistory = requestedCase === true && caseViewAvailable; const historySource = JSON.stringify([goalId, originalGoalId, readSourceUrl]); const [openedHistorySource, setOpenedHistorySource] = useState(null); - const readHistory = active && (!deferHistory || openedHistorySource === historySource); + const [openVerificationSource, setOpenVerificationSource] = useState(null); + const verificationOpen = openVerificationSource === historySource; + const verificationEntry = useRef(null); + useEffect(() => { + if (!active || !showVerification) return; + setOpenVerificationSource(historySource); + verificationEntry.current?.querySelector("summary")?.focus(); + }, [active, showVerification, historySource]); + const readHistory = active && (verificationOpen || !deferHistory || openedHistorySource === historySource); useEffect(() => { const changed = () => setCaseReading(readCaseMode()); changed(); window.addEventListener("popstate", changed); @@ -302,6 +313,11 @@ export function GoalResearchHistory({goalId, originalGoalId = goalId, preferHist ? findingVersions.find(finding => finding.event_id === selection.event && (!selection.finding || finding.result_id === selection.finding)) : selection.finding ? selected.findings.find(finding => finding.result_id === selection.finding) : defaultFinding(selected)); + const verificationFinding = selectedFinding + ? history.canonical?.events.find(item => item.event_id === selectedFinding.event_id) + : !selection.nodes.length && selection.day === null + ? history.canonical?.findings.filter(item => item.status === "confirmed" && (item.work_yardstick || item.execution_observation)).at(-1) + : undefined; const hasSeparateQuestion = Boolean(selected?.findings.length && selectedFinding?.title !== selected.latest.title); const selectedGroup = selection.day !== null ? grouped.groups.find(group => group.day === selection.day) : undefined; const selectedMembers = selectedGroup?.nodes ?? (selection.nodes.length > 1 ? value?.nodes.filter(node => selection.nodes.includes(node.id)) : undefined); @@ -527,6 +543,13 @@ export function GoalResearchHistory({goalId, originalGoalId = goalId, preferHist sourceUrl={readSourceUrl} zh={zh} selection={selectedStrategy} onSelect={strategies.choose} onClose={() => strategies.choose(null)}/> : null; return <> + {verification ?
setOpenVerificationSource(event.currentTarget.open ? historySource : null)}> + {zh ? "验证证据包" : "Verification evidence packet"} + {verificationOpen ? : null} +
: null} {caseViewAvailable ?
: null}{p?.decision ? {p.decision.authoritative.evaluation_ref} : null} + {p?.candidate ? {checked.length ? labels.included : labels.unbound} : null} + {fidelity} + {gaps.length ? <>{labels.sourceGaps}
    {gaps.map(item =>
  • {item}
  • )}
: null} + {guards?.length ?
    {guards.map((item, index) =>
  • {item.id} · {item.owner}
  • )}
: null} + {!gaps.length && !guards?.length ? guards ? labels.noOpenGuards : unknown : null}
+ +
+

{labels.baseline}

+ {p?.evidence?.host ?? unknown} + {depth === null ? unknown : `L${depth}`} + + + + {p?.candidate ? {p.candidate} : unknown} +
+

{labels.negative}

+ {p?.alternatives.length ?
    {p.alternatives.map(row =>
  • {row.title} + {row.summary ?
    {row.summary}
    : null} + {row.evidence_refs.length ? row.evidence_refs.map(ref => {ref}) : unknown}
  • )}
:

{unknown}

} + {p?.decision?.counterevidence_refs.filter(ref => !alternativeRefs.has(ref)).map(ref => {ref})} +
+

{labels.comparison}

+ {([["proxy", labels.proxy], ["authoritative", labels.final]] as const).map(([key, label]) => { + const pair = p?.[key]; + return {pair ? <> + {format.format(pair.before.value!)} → {format.format(pair.after.value!)} {pair.after.unit} + {pair.before.evidence_ref} → {pair.after.evidence_ref} + : unknown}; + })} +
{p?.authoritative && p.proxy ?

{labels.relation}

: null} + {checked.map(({evidence, criterionId}) => )} +
+

{labels.costs}

+ {costRows.map(([key, label]) => { + const cost = p?.evidence?.costs?.[key]; + return {cost ? <>{format.format(cost.value)}{cost.evidence_ref} : unknown}; + })} +
+
+
; +} diff --git a/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-model.ts b/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-model.ts index 8c2af83600..860f26fbf6 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-model.ts +++ b/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-model.ts @@ -7,7 +7,7 @@ import type { ActionReviewPlan } from "../../../../../../loopx/control_plane/pre import type { GoalAcceptanceObservation } from "../../data/goal-acceptance-observation"; import type { AttentionDetails } from "./attention-details"; import type { WorkspaceLoadError, WorkspaceReadScope } from "../../data/workspace-progressive-status"; -import type { TodoItem } from "../../data/status"; +import type { GoalArtifactLifecycle, TodoItem } from "../../data/status"; import type { TodoUpdateSourceBasis } from "../../data/action-source-basis"; import { goalWorkKind, type GoalHostThreadActivity, type WorkspaceGoalExecution } from "./goal-activity"; import { receiptRetryReadback } from "./monitor-readback"; @@ -172,6 +172,7 @@ export type WorkspaceGoal = { /** Bounded, safe text from this Goal's declared source document. */ objective?: string | null; acceptanceObservation?: GoalAcceptanceObservation | null; + artifactLifecycle?: GoalArtifactLifecycle | null; /** Driver readback only; it never changes Goal activation or grants work. */ workerObservations?: { read_status: "read" | "stale" | "unreadable"; diff --git a/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-page.tsx b/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-page.tsx index d25f60a4e9..8f138dbc46 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-page.tsx +++ b/apps/presentation/dashboard/src/features/personal-workspace/personal-workspace-page.tsx @@ -983,6 +983,7 @@ export function PersonalWorkspacePage({ const managerChatOpen = selectedWorkspaceRef !== null || selectedGoalTab === "chat"; const workspaceUnavailable = selectedWorkspaceRef !== null && workspaceConversations?.projects != null && !selectedWorkspaceProject; const workspaceTitle = selectedWorkspaceRef ? selectedWorkspaceProject?.title ?? t("workspace.unknownTitle") : null; + const [verificationVisit, setVerificationVisit] = useState<{scope: string; count: number} | null>(null); function setSelectedGoalTab(view: WorkspaceGoalTab) { if (view === "chat" && originalConversation && workspaceConversations?.onOpenOriginal) { workspaceConversations.onOpenOriginal(originalConversation.target); @@ -2935,7 +2936,14 @@ export function PersonalWorkspacePage({ ? selectGoal(id, "research")} onOpenTasks={() => setSelectedGoalTab("tasks")} active={!settingsOpen && selectedGoalTab === "research"} zh={locale === "zh-CN"} refreshRevision={historyRefreshRevision} readSourceUrl={researchReadSourceUrl} - directoryReadSourceUrl={directoryReadSourceUrl} statusNotice={goalStatusNotice} /> + directoryReadSourceUrl={directoryReadSourceUrl} statusNotice={goalStatusNotice} + showVerification={verificationVisit?.scope === selectionScope ? verificationVisit.count : undefined} + verification={{ + acceptance: workspaceReview.usable ? workspaceReview.snapshot?.acceptance ?? selectedGoal.acceptanceObservation + : selectedGoal.acceptanceObservation, + lifecycle: selectedGoal.artifactLifecycle, + liveAcceptance: !readOnly && !selectedGoal.sourceAccess, + }} /> : goalStatusNotice ??

{locale === "zh-CN" ? "此来源尚未提供研究记录的读取入口。" : "This source does not provide a research history endpoint."}

; return ( <> @@ -3108,7 +3116,10 @@ export function PersonalWorkspacePage({ overview: null, tasks: null, research: researchPanel, files: null, chat: null, } : { overview: setRailScope(null)} digest={workspaceDigest} review={workspaceReview} active={!settingsOpen && selectedGoalTab === "overview"} goal={selectedGoal} items={items} userTodos={model.userTodos} readOnly={readOnly} - onOpenDetails={() => setSelection({ kind: "goal", item: selectedGoal })} onSelect={setSelection} onView={setSelectedGoalTab} + onOpenDetails={() => setSelection({ kind: "goal", item: selectedGoal })} onSelect={setSelection} onView={setSelectedGoalTab} onOpenVerification={() => { + setVerificationVisit(previous => ({scope: selectionScope, count: (previous?.count ?? 0) + 1})); + setSelectedGoalTab("research"); + }} selectedTodoId={drawerSelection?.kind === "todo" ? drawerSelection.item.todoId : null} board={taskBoard(!settingsOpen && selectedGoalTab === "overview")} historyRefreshRevision={historyRefreshRevision} proposals={proposals} onPreview={createPreview} />, diff --git a/apps/presentation/dashboard/src/views/dashboard-page.tsx b/apps/presentation/dashboard/src/views/dashboard-page.tsx index a3a6eabbba..34d4ed8df9 100644 --- a/apps/presentation/dashboard/src/views/dashboard-page.tsx +++ b/apps/presentation/dashboard/src/views/dashboard-page.tsx @@ -1142,6 +1142,7 @@ function buildPersonalHomeModel( })), } : undefined, acceptanceObservation: goal.acceptance_observation, + artifactLifecycle: goal.artifact_lifecycle, workerObservations: !goal.host_worker_observations ? null : goal.host_worker_observations.goal_id === goal.id ? goal.host_worker_observations : {read_status: "unreadable", rows: []}, diff --git a/loopx/capabilities/explore/README.md b/loopx/capabilities/explore/README.md index ed0c98a38d..188555e0ee 100644 --- a/loopx/capabilities/explore/README.md +++ b/loopx/capabilities/explore/README.md @@ -16,6 +16,25 @@ When the observed execution used the finding's tested input revision, result attachments can bind it once and select the evidence to reuse. Readback and standalone observations keep the complete observation form. [Execution evidence authoring](../../../docs/reference/protocols/explore-result-from-path-delta-v0.md#execution-evidence-on-the-same-input) +An existing candidate execution observation can also carry optional +`verification_evidence`. Supply `baseline`, `environment` and `source` as +`{ref, sha256}` pairs. Use the actual observed `host` identifier. Each +`proofs` item (`external_verifier`, `warm_session_cache`, `white_box_hooks`, +`receipt_compaction`) adds its owning `criterion_id` to the versioned reference. In `costs`, +record measured `{value, evidence_ref}` for `warm_cache_tokens`, +`cold_cache_tokens`, `verifier_seconds`, `human_confirmations`, or +`tool_interceptions`. All references belong to the enclosing observation. +Omit an unmeasured field. A measured zero is a value. + +The **Verification evidence packet** on **Research** reads these records and +the Goal's existing acceptance and lifecycle projections. A current owner-pinned +check must attest the same candidate and receipt versions as outputs of the +named criterion to show a verified tier. +L0 covers independent evaluation, L1 also covers the warm session, and L2 adds +tool hooks and receipt compaction. The reader works with opaque host names and +uses existing acceptance reads for local version freshness. Opening the packet +reads saved evidence without launching a verifier. + ## Read execution evidence in the App Open a Goal's **Research / 研究** view, select its question in the history, diff --git a/loopx/capabilities/explore/README.zh-CN.md b/loopx/capabilities/explore/README.zh-CN.md index eb489895d6..6c055b2797 100644 --- a/loopx/capabilities/explore/README.zh-CN.md +++ b/loopx/capabilities/explore/README.zh-CN.md @@ -9,6 +9,19 @@ 不认证执行真实性或收益;finding、replan 和既有研究历程详情保留相同信息,缺省仍兼容 旧事件。参见[本地探针生产路径](../../../benchmark/runtime/EXECUTION_OBSERVATIONS.md)。 +既有候选执行记录可选携带 `verification_evidence`。`baseline`、`environment`、 +`source` 使用 `{ref, sha256}`,`host` 填实际观测的宿主标识。`proofs` 中 +`external_verifier`、`warm_session_cache`、`white_box_hooks`、`receipt_compaction` +使用同一版本引用格式并携带对应验收项的 `criterion_id`。`costs` 用 `{value, evidence_ref}` 记录实测的 +`warm_cache_tokens`、`cold_cache_tokens`、`verifier_seconds`、 +`human_confirmations` 或 `tool_interceptions`。引用必须属于该执行记录。 +缺测省略对应字段,实测的零保留。 + +Goal 的**研究 → 验证证据包**使用这些记录及既有验收和产物生命周期投影。 +当前独立检查把同一候选与回执版本确认为对应验收项的输出后才显示档位。L0 覆盖独立终评,L1 加上温缓存, +L2 再覆盖工具钩子与回执压缩。工作台按证据展示,打开时只读取已保存的记录和当前 +产物版本。 + ## 量化结论 普通结果附件可附带 `measurements`,保存到既有节点所属的 finding。关系图和 diff --git a/loopx/control_plane/capabilities/explore_execution_observation.ts b/loopx/control_plane/capabilities/explore_execution_observation.ts index bd77857053..4a99f83fff 100644 --- a/loopx/control_plane/capabilities/explore_execution_observation.ts +++ b/loopx/control_plane/capabilities/explore_execution_observation.ts @@ -5,18 +5,21 @@ import type {JsonObject} from "../runtime_decode.ts"; import {EffectRuntimeRequestError} from "../effect_runtime_errors.ts"; import {requireJsonObject} from "../runtime_decode.ts"; import {BARE_SHA256_PATTERN} from "../content_digest.ts"; +import {normalizeCandidateVerificationEvidence, type CandidateVerificationEvidence} from "./explore_verification_evidence.ts"; import {isExploreEvidenceRef} from "./explore_evidence_ref.ts"; export const EXPLORE_EXECUTION_OBSERVATION_SCHEMA = "explore_execution_observation_v0"; -export function normalizeExploreExecutionObservation(params: JsonObject): JsonObject { +export type ExploreExecutionObservation = JsonObject & {verification_evidence?: CandidateVerificationEvidence}; + +export function normalizeExploreExecutionObservation(params: JsonObject): ExploreExecutionObservation { const row = requireJsonObject(params.observation, "execution observation"); const required = ["schema_version", "candidate_sha256", "input_revision", "planned_method_id", "executed_method_id", "change_reason", "elapsed_seconds", "limit_seconds", "search_iterations", "stop_reason", "evidence_refs"]; if (row.schema_version !== EXPLORE_EXECUTION_OBSERVATION_SCHEMA || required.some(key => !Object.hasOwn(row, key)) - || Object.keys(row).some(key => ![...required, "exit_code", "result_ref", "result_candidate_sha256"].includes(key))) { + || Object.keys(row).some(key => ![...required, "exit_code", "result_ref", "result_candidate_sha256", "verification_evidence"].includes(key))) { throw new EffectRuntimeRequestError("execution observation fields are missing or unsupported"); } const text = (value: unknown, field: string, max: number): string => { @@ -62,7 +65,7 @@ export function normalizeExploreExecutionObservation(params: JsonObject): JsonOb if (!Array.isArray(row.evidence_refs) || !row.evidence_refs.length || row.evidence_refs.length > 8) { throw new EffectRuntimeRequestError("execution observation requires one to eight evidence references"); } - const result: JsonObject = {schema_version: row.schema_version, + const result: ExploreExecutionObservation = {schema_version: row.schema_version, candidate_sha256: sha(row.candidate_sha256), input_revision: text(row.input_revision, "input_revision", 160), planned_method_id: planned, executed_method_id: executed, change_reason: change, elapsed_seconds: measured(row.elapsed_seconds, "elapsed_seconds"), @@ -84,5 +87,10 @@ export function normalizeExploreExecutionObservation(params: JsonObject): JsonOb throw new EffectRuntimeRequestError("result evidence must name this executed candidate and an included evidence reference"); } } + if (Object.hasOwn(row, "verification_evidence")) { + result.verification_evidence = normalizeCandidateVerificationEvidence( + row.verification_evidence, result.evidence_refs as string[], + ); + } return result; } diff --git a/loopx/control_plane/capabilities/explore_verification_evidence.ts b/loopx/control_plane/capabilities/explore_verification_evidence.ts new file mode 100644 index 0000000000..391e907180 --- /dev/null +++ b/loopx/control_plane/capabilities/explore_verification_evidence.ts @@ -0,0 +1,91 @@ +/** Optional source readback on the existing candidate execution observation. + * Host names are opaque. Each capability claim and cost belongs to this + * candidate and cites a retained source. Authority is resolved by the reader. + */ +import {BARE_SHA256_PATTERN} from "../content_digest.ts"; +import {EffectRuntimeRequestError} from "../effect_runtime_errors.ts"; +import {requireJsonObject} from "../runtime_decode.ts"; +import {isExploreEvidenceRef} from "./explore_evidence_ref.ts"; + +export type VerificationEvidenceRef = {ref: string; sha256: string}; +export type VerificationProof = VerificationEvidenceRef & {criterion_id: string}; +const proofKeys = ["external_verifier", "warm_session_cache", "white_box_hooks", "receipt_compaction"] as const; +const costKeys = ["warm_cache_tokens", "cold_cache_tokens", "verifier_seconds", "human_confirmations", "tool_interceptions"] as const; +export type CandidateVerificationEvidence = { + baseline?: VerificationEvidenceRef; + environment?: VerificationEvidenceRef; + source?: VerificationEvidenceRef; + host?: string; + proofs?: Partial>; + costs?: Partial>; +}; + +function evidence(value: unknown, allowedRefs: ReadonlySet): VerificationEvidenceRef { + const row = requireJsonObject(value, "verification evidence reference"); + if (Object.keys(row).length !== 2 || typeof row.ref !== "string" || !allowedRefs.has(row.ref) + || typeof row.sha256 !== "string" || !BARE_SHA256_PATTERN.test(row.sha256)) { + throw new EffectRuntimeRequestError("verification evidence requires a captured reference and its exact SHA-256"); + } + return {ref: row.ref, sha256: row.sha256}; +} + +export function normalizeCandidateVerificationEvidence(value: unknown, evidenceRefs: readonly string[]): CandidateVerificationEvidence { + const row = requireJsonObject(value, "candidate verification evidence"); + const allowedRefs = new Set(evidenceRefs); + const result: CandidateVerificationEvidence = {}; + for (const key of Object.keys(row)) { + if (!["baseline", "environment", "source", "host", "proofs", "costs"].includes(key)) { + throw new EffectRuntimeRequestError("unsupported candidate verification evidence field"); + } + } + for (const key of ["baseline", "environment", "source"] as const) { + if (Object.hasOwn(row, key)) result[key] = evidence(row[key], allowedRefs); + } + if (Object.hasOwn(row, "host")) { + if (typeof row.host !== "string" || !isExploreEvidenceRef(row.host) || !/^[a-z0-9][a-z0-9_.-]{0,63}$/.test(row.host)) { + throw new EffectRuntimeRequestError("verification host requires an opaque identifier"); + } + result.host = row.host; + } + if (Object.hasOwn(row, "proofs")) { + const proofs = requireJsonObject(row.proofs, "verification proofs"); + result.proofs = {}; + for (const key of Object.keys(proofs)) { + const kind = proofKeys.find(item => item === key); + if (!kind) throw new EffectRuntimeRequestError("unsupported verification proof"); + const {criterion_id, ...version} = requireJsonObject(proofs[key], "verification proof"); + if (typeof criterion_id !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(criterion_id)) { + throw new EffectRuntimeRequestError("verification proof requires its owning acceptance criterion"); + } + result.proofs[kind] = {...evidence(version, allowedRefs), criterion_id}; + } + } + if (Object.hasOwn(row, "costs")) { + const costs = requireJsonObject(row.costs, "verification costs"); + result.costs = {}; + for (const key of Object.keys(costs)) { + const kind = costKeys.find(item => item === key); + if (!kind) throw new EffectRuntimeRequestError("unsupported verification cost"); + const cost = requireJsonObject(costs[key], "verification cost"); + if (Object.keys(cost).length !== 2 || typeof cost.value !== "number" || !Number.isFinite(cost.value) || cost.value < 0 + || (kind !== "verifier_seconds" && !Number.isSafeInteger(cost.value)) + || typeof cost.evidence_ref !== "string" || !allowedRefs.has(cost.evidence_ref)) { + throw new EffectRuntimeRequestError("verification cost requires a nonnegative measurement and a captured reference"); + } + result.costs[kind] = {value: cost.value, evidence_ref: cost.evidence_ref}; + } + } + return result; +} + +/** Independent checks are attached by exact receipt ref and digest. A host name + * or the mere presence of a producer claim cannot upgrade the verified tier. */ +export function verifiedHostDepth(evidence: CandidateVerificationEvidence | undefined, checked: readonly VerificationProof[]) { + const proofs = evidence?.proofs; + if (!evidence?.host || !proofs) return null; + const has = (proof?: VerificationProof) => + !!proof && checked.some(ref => ref.ref === proof.ref && ref.sha256 === proof.sha256 && ref.criterion_id === proof.criterion_id); + if (!has(proofs.external_verifier)) return null; + if (!has(proofs.warm_session_cache)) return 0; + return has(proofs.white_box_hooks) && has(proofs.receipt_compaction) ? 2 : 1; +} diff --git a/loopx/control_plane/presentation/explore_history.ts b/loopx/control_plane/presentation/explore_history.ts index e0f137e243..a03b7d8f52 100644 --- a/loopx/control_plane/presentation/explore_history.ts +++ b/loopx/control_plane/presentation/explore_history.ts @@ -2,17 +2,16 @@ * Event kinds/statuses/relationships remain owned by Explore result_log.py. * Local display grouping must not turn parentage or time into supporting evidence. */ -import {normalizeExploreExecutionObservation} from "../capabilities/explore_execution_observation.ts"; +import {normalizeExploreExecutionObservation, type ExploreExecutionObservation} from "../capabilities/explore_execution_observation.ts"; import {normalizeExploreMeasurements, projectExploreMeasurementFeedback, type ExploreMeasurement} from "../capabilities/explore_measurements.ts"; import {normalizeWorkYardstickCapture, type WorkYardstickCapture} from "../work_items/yardstick_decision.ts"; -import type {JsonObject} from "../runtime_decode.ts"; export type ExploreHistoryEvent = { schema_version: string; event_id: string; goal_id: string; event_kind: string; result_id: string; recorded_at: string; title: string; summary: string; status: string; node_kind: string; blocked_reason: string; parent_id: string; node_id: string; from_node: string; to_node: string; edge_type: string; agent_id: string; run_id: string; evidence_refs: string[]; supersedes: string; confidence: number | null; - execution_observation?: JsonObject; + execution_observation?: ExploreExecutionObservation; measurements?: ExploreMeasurement[]; work_yardstick?: WorkYardstickCapture; }; diff --git a/loopx/control_plane/presentation/verification_workbench.ts b/loopx/control_plane/presentation/verification_workbench.ts new file mode 100644 index 0000000000..54c6bf154d --- /dev/null +++ b/loopx/control_plane/presentation/verification_workbench.ts @@ -0,0 +1,56 @@ +/** A reader for existing Explore evidence. A matched pair reports observed + * ordering; the independent Goal receipt remains the acceptance source. */ +import type {ExploreMeasurement} from "../capabilities/explore_measurements.ts"; +import type {VerificationEvidenceRef} from "../capabilities/explore_verification_evidence.ts"; +import type {WorkYardstickProfile} from "../work_items/yardstick_decision.ts"; +import {BARE_SHA256_PATTERN} from "../content_digest.ts"; +import type {ExploreHistoryEvent} from "./explore_history.ts"; + +function observedPair( + measurements: readonly ExploreMeasurement[], + profile: WorkYardstickProfile, + baseline: VerificationEvidenceRef, + candidate: string, +) { + const matching = measurements.filter(row => row.metric === profile.metric && row.unit === profile.unit + && row.higher_is_better === profile.higher_is_better && row.comparison_scope === profile.comparison_scope + && row.input_revision === profile.input_revision && row.evaluation_ref === profile.evaluation_ref); + const point = (sha: string) => { + const items = matching.filter(row => row.candidate_ref === `sha256:${sha}` && row.value !== null); + return items.length === 1 ? items[0] : undefined; + }; + const before = point(baseline.sha256), after = point(candidate); + if (!before || !after || before.value === null || after.value === null) return null; + const delta = (after.value - before.value) * (profile.higher_is_better ? 1 : -1); + return Number.isFinite(delta) ? {before, after, delta} : null; +} + +export function projectVerificationWorkbench( + finding: ExploreHistoryEvent | undefined, + findings: readonly ExploreHistoryEvent[], +) { + if (!finding || finding.event_kind !== "finding") return null; + const decision = finding.work_yardstick?.decision; + const execution = finding.execution_observation; + const evidence = execution?.verification_evidence; + const candidate = typeof execution?.candidate_sha256 === "string" && BARE_SHA256_PATTERN.test(execution.candidate_sha256) + ? execution.candidate_sha256 : null; + const alternatives = findings.filter(row => row.goal_id === finding.goal_id && row.node_id === finding.node_id + && row.event_kind === "finding" && row.event_id !== finding.event_id && row.status === "refuted" + && Boolean(finding.node_id)); + const cited = new Set([...finding.evidence_refs, ...(execution?.evidence_refs as string[] | undefined ?? [])]); + // Candidate identity and explicit citations allow use across findings on + // this question. Chronology and a shared host provide no such binding. + const measurements = findings.flatMap(row => row.goal_id === finding.goal_id && row.node_id === finding.node_id + && row.event_kind === "finding" && (row.event_id === finding.event_id || row.status === "confirmed") + ? row.measurements?.filter(item => cited.has(item.evidence_ref)) ?? [] : []); + const exactBaseline = candidate && evidence?.baseline && evidence.baseline.sha256 !== candidate ? evidence.baseline : null; + const authoritative = candidate && exactBaseline && decision + ? observedPair(measurements, decision.authoritative, exactBaseline, candidate) : null; + const proxy = candidate && exactBaseline && decision?.proxy + ? observedPair(measurements, decision.proxy, exactBaseline, candidate) : null; + const fidelity = authoritative && proxy && decision?.authoritative.input_revision === decision?.proxy?.input_revision + ? Math.sign(authoritative.delta) === Math.sign(proxy.delta) ? "same_order" : "different_order" + : "unknown"; + return {decision, evidence, candidate, alternatives, authoritative, proxy, fidelity}; +} diff --git a/tests/control_plane_ts/verification_workbench.test.ts b/tests/control_plane_ts/verification_workbench.test.ts new file mode 100644 index 0000000000..1eaa3c01f4 --- /dev/null +++ b/tests/control_plane_ts/verification_workbench.test.ts @@ -0,0 +1,82 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import {normalizeExploreExecutionObservation} from "../../loopx/control_plane/capabilities/explore_execution_observation.ts"; +import {verifiedHostDepth} from "../../loopx/control_plane/capabilities/explore_verification_evidence.ts"; +import {parseExploreHistoryPage} from "../../loopx/control_plane/presentation/explore_history.ts"; +import {projectVerificationWorkbench} from "../../loopx/control_plane/presentation/verification_workbench.ts"; + +const baseline = {ref: "fixtures:baseline", sha256: "a".repeat(64)}; +const candidate = "b".repeat(64); +const external = {criterion_id: "external", ref: "receipts:external", sha256: "c".repeat(64)}; +const warm = {criterion_id: "warm", ref: "receipts:warm", sha256: "d".repeat(64)}; +const hooks = {criterion_id: "hooks", ref: "receipts:hooks", sha256: "e".repeat(64)}; +const compaction = {criterion_id: "compaction", ref: "receipts:compaction", sha256: "f".repeat(64)}; +const receipts = [external, warm, hooks, compaction]; +const evidenceRefs = [baseline, ...receipts].map(item => item.ref); +const execution = { + schema_version: "explore_execution_observation_v0", candidate_sha256: candidate, input_revision: "inputs-v1", + planned_method_id: "screen", executed_method_id: "screen", change_reason: null, + elapsed_seconds: 10, limit_seconds: null, search_iterations: null, stop_reason: null, evidence_refs: evidenceRefs, +}; +const exact = {metric: "loss", unit: "points", higher_is_better: false, + comparison_scope: "scope:matched", input_revision: "inputs-v1", evaluation_ref: "check:exact"}; +const proxy = {...exact, metric: "cost", evaluation_ref: "check:proxy"}; +const measure = (profile: typeof exact, sha: string, value: number, ref: string) => + ({...profile, candidate_ref: `sha256:${sha}`, value, evidence_ref: ref}); +const finding = (id: string, fields: Record = {}) => parseExploreHistoryPage({ + ok: true, goal_id: "goal", total: 1, next_cursor: null, + items: [{schema_version: "loopx_explore_result_event_v0", event_kind: "finding", event_id: id, goal_id: "goal", + result_id: id, title: id, agent_id: "worker", recorded_at: "2026-11-21T12:00:00Z", node_id: "question", + status: "confirmed", ...fields}], +}, "goal").items[0]!; + +test("legacy execution and generic CLI retain unknown costs and tier, while measured zero survives", () => { + assert.equal(normalizeExploreExecutionObservation({observation: execution}).verification_evidence, undefined); + const readback = normalizeExploreExecutionObservation({observation: {...execution, + verification_evidence: {host: "generic-cli", costs: {human_confirmations: {value: 0, evidence_ref: external.ref}}}}}); + assert.equal(readback.verification_evidence?.costs?.warm_cache_tokens, undefined); + assert.equal(readback.verification_evidence?.costs?.human_confirmations?.value, 0); + assert.equal(verifiedHostDepth(readback.verification_evidence, receipts), null); +}); + +test("the same exact checked receipts qualify every host name; absent or changed proof caps the tier", () => { + for (const host of ["codex", "pi", "dsh", "generic-cli", "future-host"]) { + const record = normalizeExploreExecutionObservation({observation: {...execution, + verification_evidence: {host, proofs: {external_verifier: external, warm_session_cache: warm, + white_box_hooks: hooks, receipt_compaction: compaction}}}}).verification_evidence; + assert.equal(verifiedHostDepth(record, [warm, hooks, compaction]), null); + assert.equal(verifiedHostDepth(record, [external, {...warm, sha256: compaction.sha256}]), 0); + assert.equal(verifiedHostDepth(record, [external, warm, hooks]), 1); + assert.equal(verifiedHostDepth(record, [external, warm, hooks, {...compaction, criterion_id: "other"}]), 1); + assert.equal(verifiedHostDepth(record, receipts), 2); + } + assert.throws(() => normalizeExploreExecutionObservation({observation: {...execution, + verification_evidence: {baseline: {...baseline, ref: "uncaptured"}}}}), /captured reference/); + assert.throws(() => normalizeExploreExecutionObservation({observation: {...execution, + verification_evidence: {costs: {human_confirmations: {value: -1, evidence_ref: external.ref}}}}}), + /nonnegative/); +}); + +test("fidelity uses the exact bounded pair and explicit negative or comparison evidence", () => { + const selected = finding("selected", {evidence_refs: evidenceRefs, work_yardstick: { + binding: {goal_id: "goal", agent_id: "worker", todo_id: "todo_case", turn_instance_id: "turn-1"}, + decision: {schema_version: "work_yardstick_decision_v0", + target: {summary: "Reduce errors", scope: "Frozen input", acceptance_ref: "check:exact"}, + authoritative: exact, proxy, counterevidence_refs: [], prior_finding_id: null, + next_action: {method_id: "screen", reason: "Compare on fixed inputs", cost_bound: "One evaluation"}}, + }, execution_observation: {...execution, verification_evidence: {baseline}}, + measurements: [measure(exact, candidate, 5, external.ref), measure(proxy, candidate, 8, warm.ref)]}); + const control = finding("control", {measurements: [ + measure(exact, baseline.sha256, 9, baseline.ref), measure(proxy, baseline.sha256, 4, baseline.ref), + ]}); + const negative = finding("negative", {status: "refuted", evidence_refs: [hooks.ref]}); + const foreign = {...control, goal_id: "other"}; + const nearby = {...negative, node_id: "nearby"}; + const projection = projectVerificationWorkbench(selected, [selected, control, negative, foreign, nearby])!; + assert.equal(projection.fidelity, "different_order"); + assert.deepEqual([projection.authoritative?.delta, projection.proxy?.delta], [4, -4]); + assert.deepEqual(projection.alternatives.map(item => item.event_id), ["negative"]); + assert.equal(projectVerificationWorkbench(selected, [selected, foreign])?.fidelity, "unknown"); + assert.equal(projectVerificationWorkbench(selected, [selected, control, {...control, event_id: "duplicate"}])?.fidelity, "unknown"); + assert.equal(projectVerificationWorkbench(selected, [selected, {...control, measurements: control.measurements?.map(row => ({...row, evidence_ref: "uncited"}))}])?.fidelity, "unknown"); +}); From fdcf9996743404a224b835c3b2730555a89de24d Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:30:37 +0800 Subject: [PATCH 2/2] Pin the verification evidence digest consumers Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- tests/control_plane_ts/content_digest_single_owner.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/control_plane_ts/content_digest_single_owner.test.ts b/tests/control_plane_ts/content_digest_single_owner.test.ts index eccc73e8ae..365f370be5 100644 --- a/tests/control_plane_ts/content_digest_single_owner.test.ts +++ b/tests/control_plane_ts/content_digest_single_owner.test.ts @@ -107,6 +107,7 @@ const CANONICAL_CONSUMERS = [ "control_plane/capabilities/content_media_image.ts", "control_plane/capabilities/explore_execution_observation.ts", "control_plane/capabilities/explore_result_page.ts", + "control_plane/capabilities/explore_verification_evidence.ts", "control_plane/capabilities/external_evidence.ts", "control_plane/capabilities/goal_capability_organization.ts", "control_plane/capabilities/native_child_result_inbox.ts", @@ -162,6 +163,7 @@ const CANONICAL_CONSUMERS = [ "control_plane/presentation/action_review_plan.ts", "control_plane/presentation/goal_source_links.ts", "control_plane/presentation/report_review.ts", + "control_plane/presentation/verification_workbench.ts", "control_plane/quota/heartbeat_receipt_identity.ts", "control_plane/quota/refresh_external_delivery.ts", "control_plane/quota/settlement_readback.ts",