/** * why-authorized / why-context / why-effect — pure explainers over effect + auth records. */ import type { ConfidentialityLabel, EffectDecl, IntegrityLabel, WhyAuthorized, WhyContext, WhyEffect } from "./types.ts"; import { type WriteIntentRecord } from "../resources/journal.ts"; export interface WhyInput { effect: EffectDecl; runId: string; phaseId?: string; principalId?: string; /** Capability binding ids that covered this effect (if any). */ capabilityBindingIds?: string[]; /** Whether static/admit validation allowed the effect. */ allowed: boolean; allowReasons: string[]; denyReasons?: string[]; intentId?: string; journalStatus?: string; status: WhyEffect["status"]; workspaceRoot?: string; defaultConfidentiality?: ConfidentialityLabel; defaultIntegrity?: IntegrityLabel; } export declare function whyAuthorized(input: WhyInput): WhyAuthorized; export declare function whyContext(input: WhyInput): WhyContext; export declare function whyEffect(input: WhyInput): WhyEffect; /** Minimal flow shape for effect lookup (Taskflow / FlowIR phases). */ export interface WhyEffectFlowLike { phases?: ReadonlyArray<{ id?: string; effects?: unknown; dependsOn?: unknown; from?: unknown; } | null | undefined>; } export interface WhyEffectFromFlowInput { /** Flow definition that declares effects (typically RunState.def). */ flow: WhyEffectFlowLike; runId: string; /** Effect id as declared, or `phaseId/effectId` composite. */ effectId: string; /** Disambiguate when the same effect id appears on multiple phases. */ phaseId?: string; workspaceRoot?: string; /** Runtime lifecycle status; MCP defaults to `declared` (read-only explain). */ status?: WhyEffect["status"]; intentId?: string; principalId?: string; capabilityBindingIds?: string[]; } export type WhyEffectFromFlowResult = { ok: true; why: WhyEffect; phaseId?: string; } | { ok: false; error: string; }; interface LocatedEffect { effect: EffectDecl; phaseId?: string; /** Id used for bag validation (phase-prefixed when from a phase). */ bagId: string; } /** Collect declared effects from each phase (original ids preserved). */ export declare function collectDeclaredEffects(flow: WhyEffectFlowLike): LocatedEffect[]; /** * Pure: resolve a declared effect from a flow and explain authorization + context. * * Fail-closed: if static validation reports any error for this effect (or the * bag cannot be validated), `authorized.allowed` is false with deny reasons. * Missing effect → `{ ok: false }` (MCP returns isError). * * Zero tokens / no I/O. Runtime commit status is optional (`status` defaults * to `"declared"`). Use `whyEffectFromLedger` for authorization claims. */ export declare function whyEffectFromFlow(input: WhyEffectFromFlowInput): WhyEffectFromFlowResult; export interface WhyEffectFromLedgerInput extends Omit { intents: readonly WriteIntentRecord[]; ledgerError?: string; } /** * Explain authority from the durable resource ledger, not from declaration * alone. A statically valid effect without a matching write intent remains * unauthorized because no mutation permit was durably admitted for it. */ export declare function whyEffectFromLedger(input: WhyEffectFromLedgerInput): WhyEffectFromFlowResult; export declare function whyEffectFromDurableJournal(input: Omit & { controlDirectory?: string; }): Promise; /** Plain-text render for MCP / CLI (no markdown fences). */ export declare function formatWhyEffect(why: WhyEffect): string; export {}; //# sourceMappingURL=why.d.ts.map