trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
99 lines • 2.89 kB
TypeScript
/**
* Sync Policy and Safety Gates (TRL-334)
*
* Defines safety policies for realtime sync to prevent accidental
* mutations, deletions, and corruptions from propagating between environments.
*/
import type { NackReason } from '../sync/types.js';
export interface SyncPolicy {
/** Require manual approval for destructive ops from remote. */
blockRemoteDestructive: boolean;
/** Require confirmation for bulk deletes (>N entities). */
bulkDeleteThreshold: number;
/** Block sync if local has uncommitted changes. */
requireCleanWorkingTree: boolean;
/** Quarantine suspicious ops for review. */
quarantineSuspicious: boolean;
}
export interface ChangeRisk {
risk: 'safe' | 'elevated' | 'destructive' | 'critical';
reason: string;
}
export interface QuarantineEntry {
id: string;
timestamp: string;
sourcePeerId: string;
message: any;
risk: ChangeRisk;
reason: NackReason;
reviewed: boolean;
}
/**
* Op kinds that never leave the local desk unless a team opts in.
*
* Chat transcripts are local-only by default (privacy is the default; sync is
* the decision). Peer-sync producers must filter ops by kind through
* `isLocalOnlyOpKind` before delivery.
*/
export declare const LOCAL_ONLY_OP_KINDS: readonly string[];
export declare function isLocalOnlyOpKind(kind: string): boolean;
/**
* Default policies by environment type.
*/
export declare const DEFAULT_POLICIES: Record<string, SyncPolicy>;
/**
* Get sync policy from environment or default.
*/
export declare function getSyncPolicy(): SyncPolicy;
/**
* Classify change risk based on message content.
*/
export declare function classifyChangeRisk(message: any): ChangeRisk;
/**
* Check if a message should be blocked by sync policy.
*/
export declare function shouldBlockMessage(message: any, policy: SyncPolicy): {
blocked: boolean;
reason?: NackReason;
details?: string;
};
/**
* Quarantine store for suspicious changes.
* Encrypted at rest with AES-256-GCM and HMAC integrity verification.
*/
export declare class QuarantineStore {
private entries;
private storagePath;
private encryptionKey;
private hmacKey;
constructor(storagePath?: string);
/**
* Add an entry to quarantine.
*/
add(message: any, sourcePeerId: string, reason: NackReason): string;
/**
* Get all quarantine entries.
*/
getAll(): QuarantineEntry[];
/**
* Get a specific quarantine entry.
*/
get(id: string): QuarantineEntry | undefined;
/**
* Mark an entry as reviewed.
*/
markReviewed(id: string): void;
/**
* Remove an entry from quarantine.
*/
remove(id: string): void;
/**
* Load quarantine from disk.
*/
private load;
/**
* Save quarantine to disk.
*/
private save;
}
//# sourceMappingURL=sync-policy.d.ts.map