aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
216 lines • 6.13 kB
TypeScript
/**
* WorkspaceMigrator - Migrate legacy .aiwg/ workspaces to framework-scoped structure
*
* Migrates legacy workspace structure (.aiwg/intake/, .aiwg/requirements/, etc.)
* to framework-scoped structure (.aiwg/frameworks/{framework-id}/projects/{project-id}/).
*
* Features:
* - Detection of legacy workspace structure
* - Framework detection from artifact patterns
* - Validation of migration safety (conflict detection)
* - Atomic migration with rollback capability
* - Backup creation before migration
* - Dry-run mode for simulation
* - Detailed migration reports
*
* @module src/plugin/workspace-migrator
* @version 1.0.0
* @since 2025-10-23
*
* @example
* ```typescript
* const migrator = new WorkspaceMigrator('/path/to/project');
* await migrator.initialize();
*
* // Detect legacy workspace
* const legacy = await migrator.detectLegacyWorkspace();
* if (legacy) {
* console.log(`Found legacy workspace with ${legacy.artifactCount} artifacts`);
*
* // Detect frameworks
* const frameworks = await migrator.detectFrameworks();
* console.log(`Detected frameworks: ${frameworks.map(f => f.name).join(', ')}`);
*
* // Validate migration
* const validation = await migrator.validateMigration({
* sourcePath: legacy.path,
* targetPath: `.aiwg/frameworks/${frameworks[0].name}/projects/default`,
* framework: frameworks[0].name
* });
*
* if (validation.safe) {
* // Perform migration
* const result = await migrator.migrate({
* source: legacy.path,
* target: `.aiwg/frameworks/${frameworks[0].name}/projects/default`,
* framework: frameworks[0].name,
* backup: true,
* dryRun: false,
* overwrite: false
* });
*
* console.log(migrator.generateReport(result));
* }
* }
* ```
*/
export interface LegacyWorkspaceInfo {
path: string;
artifactCount: number;
frameworks: string[];
size: number;
hasGit: boolean;
}
export interface FrameworkInfo {
name: string;
path: string;
version?: string;
artifactCount: number;
}
export interface MigrationTarget {
sourcePath: string;
targetPath: string;
framework: string;
}
export interface ValidationResult {
safe: boolean;
warnings: string[];
conflicts: Conflict[];
estimatedDuration: number;
}
export interface Conflict {
type: 'file' | 'directory' | 'permission';
path: string;
description: string;
resolution: 'overwrite' | 'skip' | 'merge' | 'manual';
}
export interface MigrationOptions {
source: string;
target: string;
framework: string;
backup: boolean;
dryRun: boolean;
overwrite: boolean;
}
export interface MigrationResult {
id: string;
success: boolean;
filesMovedCount: number;
filesCopiedCount: number;
filesSkippedCount: number;
errors: MigrationError[];
duration: number;
backupPath?: string;
}
export interface MigrationError {
path: string;
error: string;
severity: 'warning' | 'error' | 'critical';
}
export declare class WorkspaceMigrator {
private projectRoot;
private sandboxPath;
private readonly LEGACY_DIRS;
private readonly FRAMEWORK_PATTERNS;
constructor(projectRoot: string);
/**
* Initialize the migrator
*/
initialize(): Promise<void>;
/**
* Detect legacy workspace structure
*
* Returns information about legacy workspace if found, null otherwise.
*
* @returns Legacy workspace info or null if not found
*/
detectLegacyWorkspace(): Promise<LegacyWorkspaceInfo | null>;
/**
* Detect frameworks from artifact structure
*
* Analyzes artifact patterns to identify which frameworks are in use.
*
* @returns Array of detected frameworks
*/
detectFrameworks(): Promise<FrameworkInfo[]>;
/**
* Detect frameworks from artifacts (internal helper)
*
* @param basePath - Base path to search
* @returns Array of framework names
*/
private detectFrameworksFromArtifacts;
/**
* Validate migration safety
*
* Checks for conflicts, permission issues, and estimates duration.
*
* @param target - Migration target configuration
* @returns Validation result
*/
validateMigration(target: MigrationTarget): Promise<ValidationResult>;
/**
* Check for conflicts between source and target
*
* @param source - Source directory path
* @param target - Target directory path
* @returns Array of conflicts
*/
checkConflicts(source: string, target: string): Promise<Conflict[]>;
/**
* Perform workspace migration
*
* Migrates legacy workspace to framework-scoped structure.
* Supports dry-run mode, backup creation, and atomic operations.
*
* @param options - Migration options
* @returns Migration result
*/
migrate(options: MigrationOptions): Promise<MigrationResult>;
/**
* Rollback migration
*
* Restores workspace from backup created during migration.
*
* @param migrationId - Migration ID to rollback
*/
rollback(migrationId: string): Promise<void>;
/**
* Generate migration report
*
* Creates human-readable migration report with statistics and errors.
*
* @param result - Migration result
* @returns Formatted report string
*/
generateReport(result: MigrationResult): string;
/**
* Get directory information (file count and size)
*/
private getDirectoryInfo;
/**
* Check if directory has git repository
*/
private hasGitRepo;
/**
* List all files recursively
*/
private listFilesRecursive;
/**
* Check permissions for all files in directory
*/
private checkPermissions;
/**
* Create backup of workspace
*/
private createBackup;
/**
* Update framework registry after migration
*/
private updateRegistry;
/**
* Generate unique migration ID
*/
private generateMigrationId;
}
//# sourceMappingURL=workspace-migrator.d.ts.map