import type { TaskFactProjection } from './task-facts.js'; export interface Owner { readonly accountId: string; readonly userId: string; } export interface Authorization { enabled: boolean; automaticCollection: boolean; epoch: number; effectiveAt: string; policyVersion: string; collectionConsent?: CollectionConsent; } /** Stable pi entries observed by the trusted host at the authorization boundary. */ export interface CollectionBoundary { sessionId: string; entryId: string | null; branchId: string | null; } export interface CollectionConsent { revision: number; effectiveAt: string; policyVersion: string; scope: string | null; boundaries: CollectionBoundary[]; } export type DeliveryPhase = 'queued' | 'session_unknown' | 'session_created' | 'message_unknown' | 'message_delivered' | 'commit_unknown' | 'processing' | 'ready' | 'failed' | 'blocked_by_pause' | 'blocked'; export interface Source { sessionId: string; entryId: string; branchId: string; contentVersion: string; } /** Original persisted entry timestamp is preserved when pi copies fork ancestors. */ export interface CollectionSource extends Source { entryTimestamp: string; } export interface CollectedSource { operationId: string; payloadDigest: string; } export interface Operation { id: string; owner: Owner; scope: string | null; source: Source; kind: 'explicit' | 'automatic'; authorizationEpoch: number; collectionRevision?: number; collectionSources?: CollectionSource[]; collectionEvidence?: Array<{ source: CollectionSource; quoteDigest: string; projection?: TaskFactProjection; }>; createdAt: string; updatedAt: string; phase: DeliveryPhase; remoteSessionId: string; payload?: string; /** Digest of this operation's single source fact, retained after payload erasure. */ factDigest?: string; taskId?: string; archiveId?: string; memoryUris?: string[]; errorCode?: string; /** Last phase retained when automatic reconciliation exhausts its budget. */ reconciliationPhase?: DeliveryPhase; deliveryAttempts?: number; nextAttemptAt?: number; } /** Metadata only: messages remain in pi's original session store. */ export interface CollectionRequest { id: string; sessionId: string; baselineEntryId: string | null; settledEntryId?: string; scope: string | null; authorizationEpoch: number; collectionRevision: number; phase: 'running' | 'settled' | 'processed' | 'discarded' | 'blocked_by_pause' | 'selection_failed'; /** Adjacent completed assistant proposition, evidence only, never a new source. */ completedAssistant?: CollectionSource; confirmationReference?: { requestId: string; entryId: string; }; selectionAttempts?: number; selectionNextAttemptAt?: number; selectionLease?: { id: string; expiresAt: number; }; selectionErrorCode?: string; selectionDigest?: string; operationIds?: string[]; createdAt: string; updatedAt: string; sourceEntries: string[]; } export interface GovernanceJob { id: string; revision: number; kind: 'forget' | 'correct' | 'clear'; scope: string | null; phase: 'draining' | 'applying' | 'complete'; memoryUris: string[]; operationIds: string[]; /** All pre-barrier scope writers must be reconciled or edited before release. */ writerOperationIds: string[]; /** Pre-barrier automatic requests must settle before the edit is acknowledged. */ collectionRequestIds?: string[]; /** Hashes of stable entry identity, never deleted plaintext. */ sourceKeys: string[]; /** Entry-level replay fence activated only after pre-barrier collection drains. */ replaySourceKeys?: string[]; /** Auditable decisions for pre-barrier facts whose text may paraphrase the target. */ writerClassifications?: Record; /** Owner-reviewed exact derivative text to remove from a shared target document. */ mergedResolutions?: Record; /** Exact documents staged before source deletion; replayable after a lost reply or restart. */ preservedDocuments?: Record; /** Non-target documents kept after removing a multi-fact source. */ preservedUris?: string[]; /** A confirmed whole-scope clear replaces this unfinished selective job. */ supersededBy?: string; cancelledByRetirement?: boolean; /** Transient exact-text plan. Removed after verified selective cleanup. */ selectivePlan?: { memoryUri: string; selectedText: string; replacementText: string; }; errorCode?: string; completedAt?: string; createdAt: string; } export interface OwnerState { version: 1; owner: Owner; revision: number; authorization: Authorization; /** Durable account retirement fence; only removed after remote clear and host cleanup. */ retirement?: { id: string; phase: 'requested' | 'remote_cleared'; requestedAt: string; }; operations: Record; governance?: { revision: number; jobs: Record; }; /** Source receipts contain no conversation text and survive consent changes. */ collectedSources?: Record; collectionRequests?: Record; /** Host-validated owner-private pi source paths, never browser/model input. */ collectionSessionFiles?: Record; } export interface StateStore { readonly owner: Owner; read(signal?: AbortSignal): Promise; /** Synchronous mutation, serialized across processes and committed before return. */ transact(mutation: (state: OwnerState) => T, signal?: AbortSignal): Promise; } export declare function checkedOwner(owner: Owner): Owner; export declare function sameOwner(a: Owner, b: Owner): boolean; export declare function isCollectionSource(value: unknown): value is CollectionSource; /** A reference can cross a processed batch, but never a consent/scope boundary. */ export declare function collectionReferenceRequest(state: OwnerState, request: CollectionRequest): CollectionRequest | undefined;