import type { AuthorizationEvidence, AuthorizationEvidenceReference } from '../policy/types.js'; import type { IdentitySubject } from '../policy/types.js'; import type { ProjectAction } from '../canonical/permissions.js'; import type { ProjectStore, SafeRedactionSummary } from '../project-store/types.js'; export type KnowledgeTier = 'K0' | 'K1' | 'K2' | 'K3' | 'K4' | 'K5'; export type KnowledgeState = 'active' | 'quarantined' | 'superseded' | 'discarded'; export type InstructionMode = 'authoritative' | 'trusted-reference' | 'quote-only' | 'inactive'; export type Sensitivity = 'pii' | 'secret' | 'client-confidential'; export type ContextRenderMode = 'instruction' | 'reference' | 'quoted-evidence'; export type KnowledgeTrust = 'maximum' | 'high' | 'project-scoped' | 'untrusted' | 'quarantine'; export interface Clock { now(): string; } export interface KnowledgeProvenance { provider: string; externalId?: string; sourceUri?: string; providerRevision?: string; sourceIds?: string[]; sourcePath?: string; upstreamPath?: string; upstreamVersion?: string; upstreamVerifiedAt?: Record; license?: string; actor: string; acquiredAt: string; approvalEventId?: string; approvalKeyId?: string; approvalSignature?: string; proposalId?: string; } export interface KnowledgeEntry { id: string; tier: KnowledgeTier; state: KnowledgeState; title: string; content: string; projectId?: string; sha256: string; mediaType: string; revision: number; provenance: KnowledgeProvenance; sensitivity: Sensitivity[]; instructionMode: InstructionMode; catalogId?: string; tags?: string[]; catalogType?: string; catalogVersion?: string; catalogAuthority?: 'trusted-reference' | 'quality-gate' | 'implementation-reference'; redactions?: SafeRedactionSummary[]; } export interface QuerySelector { tiers: KnowledgeTier[]; topK: number; projectScoped: boolean; tags?: string[]; match?: 'any' | 'all'; } export interface QueryProfile { workflowId: string; mandatoryIds: string[]; requiredReferenceIds?: string[]; allowedPlaybookIds?: string[]; contextScope?: 'project' | 'studio'; selectors: QuerySelector[]; budget: { totalTokens: number; perTier: Partial>; }; } export interface RetrievalRequest { workflowId: string; query: string; projectId?: string; requestId?: string; authorizationEvidence?: AuthorizationEvidence; subject?: IdentitySubject; projectAction?: ProjectAction; bindingDigest?: string; } export interface RetrievalDependencies { clock: Clock; projectStore?: ProjectStore; } export interface ContextItem { sourceId: string; tier: KnowledgeTier; projectId?: string; trust: KnowledgeTrust; instructionMode: InstructionMode; provenance: KnowledgeProvenance; retrievedAt: string; reason: 'mandatory' | 'profile-required' | 'project-core' | 'query-match'; tokenBudget: number; renderAs: ContextRenderMode; content: string; sha256: string; state: KnowledgeState; title: string; mediaType: string; revision: number; catalogId?: string; tags: string[]; catalogType?: string; catalogVersion?: string; catalogAuthority?: 'trusted-reference' | 'quality-gate' | 'implementation-reference'; redactions?: SafeRedactionSummary[]; } export type ContextOmissionReason = 'selector-mismatch' | 'no-score' | 'top-k' | 'tier-budget' | 'total-budget' | 'source-missing'; export interface ContextOmission { sourceId: string; catalogId?: string; reason: ContextOmissionReason; } export interface ContextManifest { queryId: string; workflowId: string; projectId?: string; authorization?: AuthorizationEvidenceReference; snapshotGeneration?: string; tokenBudget: number; tokensUsed: number; items: ContextItem[]; omitted: ContextOmission[]; } export type KnowledgeRetrievalErrorCode = 'PROFILE_NOT_FOUND' | 'MANDATORY_SOURCE_MISSING' | 'MANDATORY_SOURCE_INVALID' | 'MANDATORY_BUDGET_EXCEEDED' | 'CATALOG_SOURCE_MISMATCH' | 'PROJECT_REQUIRED' | 'AUTHORIZATION_REQUIRED' | 'AUTHORIZATION_INVALID'; export declare class KnowledgeRetrievalError extends Error { readonly code: KnowledgeRetrievalErrorCode; constructor(code: KnowledgeRetrievalErrorCode, message: string); } export type PromotionErrorCode = 'APPROVAL_REQUIRED' | 'AUTHORIZATION_REQUIRED' | 'INVALID_SOURCE_TIER' | 'INVALID_SOURCE_STATE' | 'INVALID_APPROVAL' | 'SECRET_REMAINS'; export declare class PromotionError extends Error { readonly code: PromotionErrorCode; constructor(code: PromotionErrorCode, message: string); }