Skip to content

@modernizespec/sdk

@modernizespec/sdk is the full SDK for working with ModernizeSpec files programmatically. It wraps the core types and schemas with file I/O, codebase analysis, progress tracking, and parity comparison utilities.

Terminal window
npm install @modernizespec/sdk
CapabilityWithout SDKWith SDK
Read spec filesManual JSON.parse + path resolutionModernizeSpec.load(projectDir)
Validate complianceWrite your own schema validationspec.validate() with typed errors
Generate from codebaseBuild your own AST analysisModernizeSpec.analyze(projectDir)
Track progressParse migration-state.json manuallyspec.state.advance("Accounts", 0.45)
Compare legacy vs modernCustom diff logicspec.parity.compare(legacy, modern)
import { ModernizeSpec } from "@modernizespec/sdk";
// Load existing spec from project
const spec = await ModernizeSpec.load("/path/to/project");
// Access typed data
const domains = spec.domains; // Typed bounded contexts
const hotspots = spec.complexity; // Extraction tiers, God-classes
const plan = spec.extractionPlan; // Phased sequence with risk
const state = spec.migrationState; // Current progress
// Validate all files against schemas
const errors = spec.validate();
if (errors.length > 0) {
for (const error of errors) {
console.error(`${error.file}: ${error.path}${error.message}`);
}
}
// Generate spec from codebase analysis
const generated = await ModernizeSpec.analyze("/path/to/legacy", {
language: "python",
framework: "frappe",
});
// Review the generated domains
console.log(generated.domains.contexts);
// Update progress for a context
state.updateContext("Accounts", {
progress: 0.45,
entitiesMigrated: 12,
parityTests: { passing: 68, failing: 4, total: 72 },
});
// Write back to disk
await spec.save();
// Compare legacy and modern behavior
const diff = spec.parity.compare(
legacyOutput,
modernOutput,
{ tolerance: 0.001 } // numeric precision tolerance
);
console.log(diff.matches); // true if within tolerance
console.log(diff.deviations); // list of field-level differences

The main entry point. Static methods for loading and analyzing. Instance methods for accessing, validating, and saving.

MethodDescription
ModernizeSpec.load(dir)Load spec from .agents/modernization/
ModernizeSpec.analyze(dir, options)Generate spec from codebase analysis
spec.validate()Validate all files against schemas
spec.save()Write all modified files back to disk

Access bounded context data.

Property/MethodDescription
spec.domains.contextsArray of all bounded contexts
spec.domains.contextMapArray of context relationships
spec.domains.getContextForFile(path)Find which context owns a file
spec.domains.getContext(name)Get a specific context by name

Access extraction tier and hotspot data.

Property/MethodDescription
spec.complexity.tiersArray of extraction tiers
spec.complexity.hotspotsArray of complexity hotspots
spec.complexity.getTier(module)Get tier for a module

Read and update progress.

Property/MethodDescription
spec.migrationState.overallProgressOverall progress (0-1)
spec.migrationState.contextsPer-context progress array
spec.migrationState.blockersActive blockers
spec.migrationState.velocityVelocity metrics
spec.migrationState.updateContext(name, data)Update context progress
spec.migrationState.addBlocker(blocker)Add a new blocker
spec.migrationState.resolveBlocker(id)Mark blocker as resolved

The SDK uses typed errors:

import { SpecNotFoundError, ValidationError, AnalysisError } from "@modernizespec/sdk";
try {
const spec = await ModernizeSpec.load("/path/to/project");
} catch (error) {
if (error instanceof SpecNotFoundError) {
console.error("No .agents/modernization/ directory found");
}
}