import { type ContextCostReport } from "../hosts/claude/context-cost.js"; import type { FrameworkId } from "../schema.js"; import type { CostGateVerdict } from "./cost-gate.js"; /** * D-CAP / D-GOV surface measurement for one project's surface set. Reuses the * cost-gate/context-cost `counts` shape verbatim and adds the managed-block bit * (D-GOV's "+1 if a managed CLAUDE.md routing block is present"). */ export interface FrameworkSurfaceMeasurement { /** Reused {@link ContextCostReport} count shape (never re-derived here). */ counts: ContextCostReport["counts"]; /** 1 when a managed CLAUDE.md routing block is present (a host-level D-GOV surface). */ managedBlock: 0 | 1; /** Non-authoritative label, e.g. "aih static tree measurement". */ evidence: string; } /** * Sum {@link estimateContextCostFromTree}'s `counts` over the surface roots a * project loads — the Q3 measurement input contract: the caller passes the bind * report's INSTALLED-surfaces roots so the invocable count is honest (the raw * component-root tree estimate can understate — e.g. ECC-Lean's `skills:0`). * Baseline C passes `[]` (all-zero). Fails closed with the same * `ClaudeHostWriteError` a bad tree path already raises via the reused call. * * `managedBlock` is always `0` here: a tree-path sum cannot observe a * host-level managed routing block, which is not part of a component tree. A * caller that has evidence of one constructs the measurement as * `{ ...measureFrameworkSurfaces(paths), managedBlock: 1 }`. */ export declare function measureFrameworkSurfaces(treePaths: readonly string[]): FrameworkSurfaceMeasurement; /** * The decisive signal — the OPTIONAL runtime hole the acceptance driver fills * from the check-11 transcript; never fabricated by this module. `undefined` * (with {@link FrameworkValueThresholds.requireCharacteristicWorkflow}) drives * `INCOMPLETE_MEASUREMENT`. */ export interface CharacteristicWorkflowResult { /** e.g. "ecc-review" | "superpowers-brainstorm-plan". */ name: string; /** check-11 live adjudication. */ succeeded: boolean; /** The same invocation is rejected/absent in Project C (check 3). */ baselineAbsent: boolean; /** Transcript / evidence id (path-free per H3). */ evidence: string; } /** Ratifiable knobs with defaults, recorded with provenance (W4 `CostGateBudget` precedent). */ export interface FrameworkValueThresholds { /** The "not pure cost" floor — Δtotal must reach this. Default 1 (ratifiable). */ minSurfaceDelta: number; /** The workflow signal is mandatory; absent ⇒ INCOMPLETE. Default true (ratifiable). */ requireCharacteristicWorkflow: boolean; approvedBy: string; approvedOn: string; } /** Maintainer-ratified defaults (2026-07-23): the honest, non-gameable package. */ export declare const DEFAULT_VALUE_THRESHOLDS: FrameworkValueThresholds; export type FrameworkValueVerdict = "DELIVERS_VALUE" | "INSUFFICIENT_VALUE" | "INCOMPLETE_MEASUREMENT"; /** The framework identity a record is built for (kept off the surface measurement). */ export interface FrameworkValueIdentity { framework: FrameworkId; mode?: "lean" | "full"; } /** Measured surface deltas (framework − baseline). May be negative on a dirty baseline (Q8). */ export interface FrameworkValueDeltas { invocable: number; governance: number; total: number; } /** * The JSON-serializable value-gate record — the D14 evidence written to * `14-value-gate.json`. Surface measurements + deltas are OMITTED (not fabricated * as zero) when the corresponding dimension was not measured; a fully-measured * DELIVERS/INSUFFICIENT record carries all of them. */ export interface FrameworkValueRecord { framework: FrameworkId; mode?: "lean" | "full"; /** Project C (expected all-zero); absent when the baseline was not measured. */ baseline?: FrameworkSurfaceMeasurement; /** The bound framework's measured surfaces; absent when not measured. */ framework_?: FrameworkSurfaceMeasurement; /** Present iff BOTH baseline and framework surfaces were measured. */ deltas?: FrameworkValueDeltas; /** The context-cost debit (disclosed, not gated here — its pass/fail is the cost gate's). */ costTokens?: number; costVerdict?: CostGateVerdict; characteristicWorkflow?: CharacteristicWorkflowResult; thresholds: FrameworkValueThresholds; /** Honest per-dimension delivery, e.g. ["capability(+5)","governance(+122)","workflow:ecc-review"]. */ dimensionsDelivered: string[]; verdict: FrameworkValueVerdict; } /** * Build the pure, deterministic {@link FrameworkValueRecord}. Verdict logic * (design §"Verdict function"): * * 1. FAIL CLOSED to `INCOMPLETE_MEASUREMENT` on any missing dimension — no * baseline, no framework surface measurement, no cost measurement, or (when * `requireCharacteristicWorkflow`) no workflow result. Never a false green. * 2. Surface deltas are measured, disjoint, and may be negative (a contaminated * baseline honestly drives INSUFFICIENT rather than being clamped to clean). * 3. The decisive signal is `workflow.succeeded AND workflow.baselineAbsent` — * surface counts alone can NEVER pass (V3: 500 stubs with a dead workflow * FAIL). * 4. `DELIVERS_VALUE` iff `Δtotal >= minSurfaceDelta` AND the workflow signal * holds; otherwise `INSUFFICIENT_VALUE`. * * `dimensionsDelivered` honestly enumerates the dimensions that positively * contributed, independent of the overall verdict (an INSUFFICIENT record whose * surfaces cleared the floor still lists them). Cost is DISCLOSED, never gated * here (V1). Pure: no wall-clock, no `Math.random` — byte-identical per inputs. */ export declare function buildFrameworkValueRecord(identity: FrameworkValueIdentity, baseline: FrameworkSurfaceMeasurement | undefined, frameworkM: FrameworkSurfaceMeasurement | undefined, cost: { tokens?: number; verdict?: CostGateVerdict; } | undefined, workflow: CharacteristicWorkflowResult | undefined, thresholds?: FrameworkValueThresholds): FrameworkValueRecord;