import { Actor, AuthorityDecision } from './authority-policy'; import { EvolithError } from './errors'; export type ScopeEffect = 'read' | 'write' | 'delete' | 'execute' | 'network'; export declare function isWithin(parent: string, child: string): boolean; export interface ScopeSpec { readonly id: string; readonly root: string; readonly include: readonly string[]; readonly exclude?: readonly string[]; readonly effects: readonly ScopeEffect[]; readonly declaredBy: string; readonly reason: string; } export interface DeclaredScope { readonly state: 'declared'; readonly id: string; readonly root: string; readonly include: readonly string[]; readonly exclude: readonly string[]; readonly effects: readonly ScopeEffect[]; readonly declaredBy: string; readonly reason: string; } export interface ScopeWidening { readonly at: string; readonly byActorId: string; readonly byActorKind: string; readonly reason: string; readonly addedInclude: readonly string[]; readonly addedEffects: readonly ScopeEffect[]; readonly decision: AuthorityDecision; } export interface EffectiveScope { readonly state: 'effective'; readonly declared: DeclaredScope; readonly include: readonly string[]; readonly exclude: readonly string[]; readonly effects: readonly ScopeEffect[]; readonly widenings: readonly ScopeWidening[]; } export declare class ScopeContractError extends EvolithError { constructor(message: string, context?: Record); } export declare function declareScope(spec: ScopeSpec): DeclaredScope; export declare function activateScope(declared: DeclaredScope): EffectiveScope; export interface ScopeNarrowing { readonly include?: readonly string[]; readonly exclude?: readonly string[]; readonly effects?: readonly ScopeEffect[]; } export declare function narrowScope(scope: DeclaredScope | EffectiveScope, narrowing: ScopeNarrowing): EffectiveScope; export type ScopeResolution = { readonly ok: true; readonly scope: EffectiveScope; } | { readonly ok: false; readonly reason: string; readonly cause?: unknown; }; export declare class ScopeResolutionError extends EvolithError { readonly scopeId: string; readonly cause?: unknown | undefined; constructor(scopeId: string, reason: string, cause?: unknown | undefined); } export declare function resolveScope(declared: DeclaredScope, resolver: () => ScopeNarrowing): ScopeResolution; export declare function requireResolvedScope(declared: DeclaredScope, resolver: () => ScopeNarrowing): EffectiveScope; export interface ScopeWideningRequest { readonly authorisedBy: Actor; readonly reason: string; readonly include?: readonly string[]; readonly effects?: readonly ScopeEffect[]; readonly at?: string; } export type ScopeWideningOutcome = { readonly widened: true; readonly scope: EffectiveScope; readonly decision: AuthorityDecision; } | { readonly widened: false; readonly decision: AuthorityDecision; }; export declare function widenScope(scope: EffectiveScope, request: ScopeWideningRequest): ScopeWideningOutcome; export type ScopeRuleId = 'SC-R01' | 'SC-R02' | 'SC-R03' | 'SC-R04' | 'SC-R05' | 'SC-R06'; export interface ScopeCheck { readonly path: string; readonly effect: ScopeEffect; } export interface ScopeDecision { readonly permitted: boolean; readonly reason: string; readonly rule: ScopeRuleId; readonly citation: string; } export declare function evaluateScope(scope: EffectiveScope, check: ScopeCheck): ScopeDecision; export declare function isInScope(scope: EffectiveScope, check: ScopeCheck): boolean; export declare class ScopeViolationError extends EvolithError { readonly decision: ScopeDecision; readonly scopeId: string; readonly check: ScopeCheck; constructor(decision: ScopeDecision, scopeId: string, check: ScopeCheck); } export declare function requireScope(scope: EffectiveScope, check: ScopeCheck): void; export interface ScopeDelta { readonly identical: boolean; readonly narrowed: readonly string[]; readonly widened: readonly string[]; readonly droppedEffects: readonly ScopeEffect[]; readonly addedEffects: readonly ScopeEffect[]; readonly widenings: readonly ScopeWidening[]; } export declare function compareToDeclared(scope: EffectiveScope): ScopeDelta; export declare function hasWidened(scope: EffectiveScope): boolean; export declare function formatScopeDecision(decision: ScopeDecision): string; export declare function formatScopeContract(scope: EffectiveScope): string;