/** * Principle Tree Ledger — file-based ledger for principle entries. * * Lives in principles-core so pd-cli can read/write the ledger without * importing openclaw-plugin private code. * * M8: Single-path ledger. The ledger file is at: * {stateDir}/principle_training_state.json * * PRI-459: This module is the SINGLE source of truth for parsing, * serialization, AND mutation of principle_training_state.json. Every * read-modify-write acquires a cross-process file lock (see withLock above), * eliminating the dual-writer lost-update class. The openclaw-plugin ledger * is now a thin re-export adapter over this module. */ import type { Principle, Rule, Implementation, PrincipleValueMetrics, LedgerPrinciple, LedgerRule, LedgerTreeStore, LegacyPrincipleTrainingState, LegacyPrincipleTrainingStore, HybridLedgerStore } from './runtime-v2/types/ledger-store.js'; import { TREE_NAMESPACE } from './runtime-v2/types/ledger-store.js'; import type { ImplementationLifecycleState } from './runtime-v2/types/principle-enums.js'; export type { Principle, Rule, Implementation, PrincipleValueMetrics, LedgerPrinciple, LedgerRule, LedgerTreeStore, LegacyPrincipleTrainingState, LegacyPrincipleTrainingStore, HybridLedgerStore, ImplementationLifecycleState, }; export { TREE_NAMESPACE }; export declare class LockAcquisitionError extends Error { readonly filePath: string; readonly lockPath: string; constructor(message: string, filePath: string, lockPath: string); } interface LockOptions { maxRetries?: number; baseRetryDelayMs?: number; maxRetryDelayMs?: number; lockStaleMs?: number; lockSuffix?: string; } /** * Run `fn` while holding the ledger file lock. FAIL-LOUD: if the lock cannot * be acquired after bounded retries, throws LockAcquisitionError carrying the * file + lock path (EP-03 / ERR-009 — no silent fallback). * * Exported so tests and integrators can drive the lock primitive directly with * a tight retry budget (the public mutators use production defaults). */ export declare function withLock(filePath: string, fn: () => T, options?: LockOptions): T; export declare function loadLedger(stateDir: string): HybridLedgerStore; export declare function saveLedger(stateDir: string, store: HybridLedgerStore): void; export declare function addPrincipleToLedger(stateDir: string, principle: LedgerPrinciple): LedgerPrinciple; export declare function updatePrinciple(stateDir: string, principleId: string, updates: Partial): LedgerPrinciple; export declare function updatePrincipleValueMetrics(stateDir: string, principleId: string, metrics: PrincipleValueMetrics): PrincipleValueMetrics; export declare function getLedgerFilePathPublic(stateDir: string): string; export interface PrincipleSubtree { principle: LedgerPrinciple; rules: { rule: LedgerRule; implementations: Implementation[]; }[]; } export declare function createRule(stateDir: string, rule: LedgerRule): LedgerRule; export declare function createImplementation(stateDir: string, implementation: Implementation): Implementation; export declare function updateRule(stateDir: string, ruleId: string, updates: Partial): LedgerRule; export declare function deleteRule(stateDir: string, ruleId: string): LedgerRule | undefined; export declare function updateImplementation(stateDir: string, implementationId: string, updates: Partial): Implementation; export declare function deleteImplementation(stateDir: string, implementationId: string): Implementation | undefined; export declare function listImplementationsForRule(stateDir: string, ruleId: string): Implementation[]; export declare function getPrincipleSubtree(stateDir: string, principleId: string): PrincipleSubtree | undefined; export declare function isValidLifecycleTransition(from: ImplementationLifecycleState, to: ImplementationLifecycleState): boolean; export declare function getAllowedTransitions(from: ImplementationLifecycleState): ImplementationLifecycleState[]; /** * Transition an implementation's lifecycle state with validation. * Throws on invalid transitions or missing implementation (fail loud). */ export declare function transitionImplementationState(stateDir: string, implementationId: string, newState: ImplementationLifecycleState): Implementation; export declare function listRuleImplementationsByState(stateDir: string, ruleId: string, state: ImplementationLifecycleState): Implementation[]; export declare function findActiveImplementation(stateDir: string, ruleId: string): Implementation | null; export declare function saveLedgerAsync(stateDir: string, store: HybridLedgerStore): Promise; export declare function updateTrainingStore(stateDir: string, mutate: (store: LegacyPrincipleTrainingStore) => void): void; //# sourceMappingURL=principle-tree-ledger.d.ts.map