trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
94 lines • 2.83 kB
TypeScript
/**
* Sync Daemon for Background Realtime Sync (TRL-334)
*
* Background process that maintains persistent sync connection
* and auto-syncs full graph state between environments.
* Transport-agnostic — works with WebSocket, Iroh, or any SyncTransport.
*/
import type { SyncTransport } from './types.js';
import type { VcsOp } from '../vcs/types.js';
export interface SyncDaemonOptions {
/** WebSocket server URL (used when transport is not provided). */
url?: string;
/** Sync transport. Defaults to WebSocketTransport if not provided. */
transport?: SyncTransport;
/** Local peer ID. */
localPeerId: string;
/** Function to get local ops. */
getLocalOps: () => VcsOp[];
/** Function to apply received ops. */
onOpsReceived: (ops: VcsOp[]) => void | Promise<void>;
/** Sync interval in ms (default: 1000). */
syncInterval?: number;
/** Root path for audit trail and config. */
rootPath?: string;
/** Authentication token (optional - reads from .trellis-db.json if not provided). */
authToken?: string;
/** Enable automatic bootstrap for empty remotes. */
enableBootstrap?: boolean;
}
export interface SyncDaemonState {
running: boolean;
connected: boolean;
lastSyncTime?: string;
syncCount: number;
quarantineCount: number;
}
/**
* Background sync daemon.
* Maintains connection and auto-syncs on interval.
*/
export declare class SyncDaemon {
private options;
private engine;
private transport;
private quarantine;
private auditTrail;
private rateLimiter;
private interval;
private state;
constructor(opts: SyncDaemonOptions);
/**
* Start the sync daemon.
*/
start(): Promise<void>;
/**
* Stop the sync daemon.
*/
stop(): void;
/**
* Get current daemon state.
*/
getState(): SyncDaemonState;
/**
* Slice C — stamp this machine's device state after a sync cycle. No-op for
* machines without a paired device key (`markDeviceSeen` returns false).
*/
private markSeen;
/**
* Slice D — a peer revoked one of this identity's devices: update the local
* person registry so the resolver fails closed on the revoked key.
*/
private handleDeviceRevoked;
/**
* Check remote state to determine if bootstrap is needed.
*/
private checkRemoteState;
/**
* Bootstrap remote with full local state.
*/
private bootstrapRemote;
/**
* Public method to explicitly bootstrap remote.
*/
bootstrap(): Promise<void>;
/**
* Apply a quarantined message.
*/
applyQuarantine(id: string): Promise<void>;
/**
* Reject a quarantined message.
*/
rejectQuarantine(id: string): void;
}
//# sourceMappingURL=sync-daemon.d.ts.map