import { type PlanVersionV1 } from './plan-version.js'; import { type TaskContractV1 } from './task-contract.js'; import { type GovernanceActor, type TransitionFacts } from './transition-engine.js'; import type { WorkflowState } from './workflow-state.js'; interface GovernanceCommandMetadata { readonly commandId: string; readonly taskId: string; readonly expectedRevision: number; readonly actor: GovernanceActor; readonly issuedAt: string; } export type GovernanceCommand = GovernanceCommandMetadata & ({ readonly type: 'create_task'; readonly projectId: string; readonly contract: TaskContractV1; } | { readonly type: 'attach_plan_version'; readonly plan: PlanVersionV1; } | { readonly type: 'transition_task'; readonly to: WorkflowState; }); export interface GovernanceDecisionContext { /** Trusted facts computed by deterministic policy/adapters, never copied from model arguments. */ readonly transitionFacts?: TransitionFacts | undefined; } type GovernanceEventPayload = { readonly type: 'task_created'; readonly projectId: string; readonly contract: TaskContractV1; } | { readonly type: 'plan_version_attached'; readonly plan: PlanVersionV1; } | { readonly type: 'workflow_transitioned'; readonly from: WorkflowState; readonly to: WorkflowState; }; export interface GovernanceEvent { readonly eventId: string; readonly commandId: string; readonly taskId: string; readonly revision: number; readonly actor: GovernanceActor; readonly occurredAt: string; readonly payload: GovernanceEventPayload; } export interface TaskAggregate { readonly taskId: string; readonly projectId: string; readonly revision: number; readonly state: WorkflowState; readonly contracts: readonly TaskContractV1[]; readonly activeContractVersion: number; readonly plans: readonly PlanVersionV1[]; readonly activePlanVersion: number | null; readonly replanRequestedFromPlanVersion: number | null; readonly createdAt: string; readonly updatedAt: string; } type CommandRejectionCode = 'stale_revision' | 'task_already_exists' | 'task_missing' | 'task_identity_mismatch' | 'project_identity_mismatch' | 'initial_contract_version_invalid' | 'contract_invalid' | 'plan_invalid' | 'plan_supersession_invalid' | 'plan_attach_state_invalid' | 'active_plan_missing' | 'replan_version_missing' | 'transition_facts_missing' | 'transition_rejected'; export type GovernanceCommandDecision = { readonly accepted: true; readonly event: GovernanceEvent; } | { readonly accepted: false; readonly code: CommandRejectionCode; readonly message: string; readonly details?: readonly unknown[] | undefined; }; type EventApplyRejectionCode = 'first_event_not_task_created' | 'duplicate_task_created' | 'task_id_mismatch' | 'event_revision_gap' | 'event_state_mismatch' | 'event_requires_existing_task'; type EventApplyResult = { readonly applied: true; readonly aggregate: TaskAggregate; } | { readonly applied: false; readonly code: EventApplyRejectionCode; readonly message: string; }; type TaskReplayResult = { readonly replayed: true; readonly aggregate: TaskAggregate; } | { readonly replayed: false; readonly eventIndex: number; readonly code: EventApplyRejectionCode; readonly message: string; }; export declare function decideGovernanceCommand(aggregate: TaskAggregate | null, command: GovernanceCommand, context?: GovernanceDecisionContext): GovernanceCommandDecision; export declare function applyGovernanceEvent(aggregate: TaskAggregate | null, event: GovernanceEvent): EventApplyResult; export declare function replayTaskEvents(events: readonly GovernanceEvent[]): TaskReplayResult; export {}; //# sourceMappingURL=task-aggregate.d.ts.map