/** * EnvironmentManager — Multi-environment isolation for Network-AI * * Provides strict data directory separation between environments * (dev, st, sit, qa, sandbox, preprod, prod) with promotion chain * enforcement, approval gates, and automatic backup/restore. * * Promotion chain: dev → st → sit → qa → preprod → prod * Sandbox is a dead-end (non-promotable testing space). * * Gate types: * - auto: promotion proceeds without human interaction * - confirm: promotion requires `confirmedBy` string to be set * - approval: promotion requires `approvedBy` string to be set * * @module EnvironmentManager * @version 1.0.0 */ /** A named environment. The well-known set is dev/st/sit/qa/sandbox/preprod/prod. */ export type EnvName = 'dev' | 'st' | 'sit' | 'qa' | 'sandbox' | 'preprod' | 'prod' | string; /** Gate type controlling what is required for promotion into an environment. */ export type GateType = 'auto' | 'confirm' | 'approval'; /** * Configuration for the EnvironmentManager. * Can be overridden via `data/env-config.json`. */ export interface EnvConfig { /** Ordered promotion chain. Environments not in this list are non-promotable. */ chain: EnvName[]; /** Per-environment gate requirements. Defaults applied if not specified. */ gates: Record; /** How many backups to retain per environment (default: 10). */ backupRetain: number; } /** Result of a promotion operation. */ export interface PromotionResult { from: EnvName; to: EnvName; configsCopied: string[]; skipped: string[]; approvedBy?: string; confirmedBy?: string; timestamp: string; } /** A single file difference between two environments. */ export interface EnvFileDiff { file: string; status: 'added' | 'removed' | 'changed'; } /** Result of an env diff operation. */ export interface EnvDiff { env1: EnvName; env2: EnvName; differences: EnvFileDiff[]; } /** Result of a backup operation. */ export interface BackupResult { backupId: string; env: EnvName; path: string; filesCount: number; } /** Entry in the backup manifest for an environment. */ export interface BackupEntry { backupId: string; env: EnvName; timestamp: string; sizeBytes: number; path: string; } /** Result of a restore operation. */ export interface RestoreResult { backupId: string; env: EnvName; filesRestored: number; } /** Options for a promote() call. */ export interface PromoteOptions { /** Required for gates of type 'confirm'. */ confirmedBy?: string; /** Required for gates of type 'approval'. */ approvedBy?: string; } /** * Manages isolated data directories for multiple deployment environments. * * @example * ```typescript * const mgr = new EnvironmentManager('/path/to/project/data'); * mgr.initAll(); * const devDir = mgr.getDataDir('dev'); // → /path/to/project/data/dev * mgr.promote('dev', 'st'); // auto-gate * mgr.promote('qa', 'preprod', { confirmedBy: 'ops-lead' }); * mgr.promote('preprod', 'prod', { approvedBy: 'cto@example.com' }); * ``` */ export declare class EnvironmentManager { private readonly baseDir; private readonly config; private readonly _enforcePromotionChain; /** * @param baseDir - Root data directory (e.g. `path.join(process.cwd(), 'data')`). * @param config - Optional overrides for chain, gates, backup retention, and strict mode. */ constructor(baseDir: string, config?: Partial & { enforcePromotionChain?: boolean; }); /** * Returns the isolated data directory for the given environment. * Creates it if it does not exist. */ getDataDir(env: EnvName): string; /** * Scaffold the standard subdirectory layout for a single environment. * Idempotent — safe to call multiple times. */ init(env: EnvName): void; /** Scaffold all environments in the promotion chain plus sandbox. */ initAll(): void; /** * Promotes configuration artefacts from one environment to the next. * Live state (audit log, active grants, pending changes, blackboard entries) * is never promoted. * * When `enforcePromotionChain: true` was passed at construction, each environment * (except the first in the chain) must have a `.promotion-record.json` proving it * was previously promoted to via this manager before it can be promoted from. * This creates a verifiable chain-of-custody for config artefacts. * * @throws {Error} If gate requirements are not met, or sandbox is the source. */ promote(from: EnvName, to: EnvName, options?: PromoteOptions): PromotionResult; /** * Compares configuration artefacts between two environments. * Only compares promotion-safe files. */ diff(env1: EnvName, env2: EnvName): EnvDiff; /** List all environments, whether they exist, and how many blackboard keys each has. */ list(): Array<{ name: EnvName; exists: boolean; keyCount: number; }>; /** Returns the configured promotion chain. */ getChain(): EnvName[]; /** * Returns true if the environment can be used as a promotion source. * 'sandbox' is always false. */ isPromotable(env: EnvName): boolean; /** * Returns the next environment in the chain after `env`, or null if `env` * is the last in the chain or not in the chain. */ getNextEnv(env: EnvName): EnvName | null; /** Returns the gate type controlling promotion INTO the given environment. */ getGateType(env: EnvName): GateType; /** * Creates a timestamped backup of an environment's data directory. * Stored at `data//.backups//`. * Automatically prunes old backups to retain at most `backupRetain` copies. */ backup(env: EnvName): BackupResult; /** * Restores an environment from a previously created backup. * * @param env - The environment to restore into. * @param backupId - The backup ID (from `listBackups()`). */ restore(env: EnvName, backupId: string): RestoreResult; /** * Lists all backups for an environment, newest first. */ listBackups(env: EnvName): BackupEntry[]; /** * Removes old backups for an environment, keeping only the `keep` most recent. * @returns Number of backups deleted. */ pruneBackups(env: EnvName, keep: number): number; private _loadEnvConfig; private _touchJson; private _touchFile; private _listConfigFiles; private _collectBackupFiles; private _dirSize; } //# sourceMappingURL=env-manager.d.ts.map