-
Notifications
You must be signed in to change notification settings - Fork 0
feat(core,cli): norms capture with lookback window consensus #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aridyckovsky
wants to merge
7
commits into
main
Choose a base branch
from
feat/norms-capture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add DirectoryStatus, Norm, DirectorySummary schemas with comprehensive JSDoc - Add TaggedErrors: NoCheckpointsError, InvalidDirectoryError, NormDetectionError, SummaryWriteError - Export Severity schema from amp.ts for reuse (DRY principle) - All exports tagged @SInCE 0.6.0 - Includes usage examples and error handling patterns BREAKING CHANGE: None (purely additive) Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9 Co-authored-by: Amp <amp@ampcode.com>
- Add detectExtinctNorms: lookback window consensus algorithm - Add computeDirectoryStats: file statistics with history union - Add determineStatus: migrated/in-progress/not-started logic - Add findCleanTimestamp: clean state detection - Pure functions (100% side-effect-free) for testability - Comprehensive unit tests (23 tests, 100% coverage) - All functions documented with @param, @returns, @example Algorithm: - Detects rules that went to zero across K checkpoints (default 5) - Requires prior non-zero evidence - Uses peak-to-zero for violationsFixed - Directory stats: union of history for total, latest for violations Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9 Co-authored-by: Amp <amp@ampcode.com>
- Implement DirectorySummarizerService with Context.Tag + Live layer - Integrates with checkpoint-manager (readManifest, readCheckpoint) - Converts NormData (plain objects) to Norm (Schema types with DateTimeUtc) - Proper layer composition with FileSystem and Path services - Integration tests (15 tests) with realistic checkpoint fixtures - Tests cover: norm detection, status determination, schema conversion, error handling Service orchestrates: 1. Load most recent N checkpoints from manifest 2. Call pure detection logic 3. Convert to Schema types 4. Return DirectorySummary with norms and status Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9 Co-authored-by: Amp <amp@ampcode.com>
- Implement normsCaptureCommand with rich options:
- --prepare-only (default): preview without writes
- --status: filter by migrated/in-progress/all
- --directory: single directory analysis
- --lookback: customize consensus window
- --min-files: filter small directories
- --overwrite: replace existing summaries
- Uses Schema.encodeSync for proper DateTimeUtc serialization
- Error handling with Cause.pretty
- User guidance for next steps
- CLI integration tests (15 tests) covering all options and edge cases
Output: .amp/effect-migrate/norms/{directory}.json
Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9
Co-authored-by: Amp <amp@ampcode.com>
- Export norms types, errors, pure functions, DirectorySummarizer from core - Register normsCommand in CLI subcommands - Feature now accessible via 'effect-migrate norms capture' Public API exports: - Types: DirectoryStatus, Norm, DirectorySummary - Errors: NoCheckpointsError, InvalidDirectoryError, NormDetectionError, SummaryWriteError - Pure: detectExtinctNorms, computeDirectoryStats, determineStatus, findCleanTimestamp - Service: DirectorySummarizer, DirectorySummarizerLive, DirectorySummarizerService Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9 Co-authored-by: Amp <amp@ampcode.com>
- Add implementation plan with oracle improvements - Add PR draft following team format - Document algorithm, architecture, and testing strategy Related: - Plan v2 incorporates oracle analysis and bug fixes - PR draft ready for review Amp-Thread-ID: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9 Co-authored-by: Amp <amp@ampcode.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
amp:audit
Audit context and structured violation output
boundaries
Architectural boundaries
changeset:next-minor
Changes planned for next minor version
effect-ts
Effect-TS patterns and usage
migration
Migration tooling and patterns
pkg:cli
Issues related to @effect-migrate/cli package
pkg:core
Issues related to @effect-migrate/core package
pr:size:large
Large PR (> 500 lines)
priority:medium
Medium priority
schema
Schema validation and types
services
Service layers and dependency injection
type:feature
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Norms Capture MVP: Detect and document established migration norms from checkpoint history using lookback window consensus algorithm.
New Services: DirectorySummarizer service for analyzing audit checkpoints and computing directory-level migration statistics.
Why
Enable teams to surface durable migration agreements from real audit history. A "norm" is a rule that went to zero violations and stayed there across K consecutive checkpoints (lookback window), with evidence of prior violations. This provides:
Scope
Packages affected:
@effect-migrate/core- Norms schemas, pure detection logic, DirectorySummarizer service@effect-migrate/cli-norms capturecommand with filtering and output optionsChangeset
Changeset summary:
Testing
All checks pass: ✅
New tests added:
packages/core/test/norms/pure.test.ts(23 tests) - Pure function unit tests with 100% coveragepackages/core/test/norms/DirectorySummarizer.test.ts(15 tests) - Service integration with realistic fixturespackages/cli/test/commands/norms.test.ts(15 tests) - CLI command with all options and error pathsTotal: 53 new tests, 358 tests passing across all packages (+28)
Manual testing verified:
Implementation Details
Norm Detection Algorithm
For each rule in a directory:
establishedAt= timestamp of first checkpoint where count became 0violationsFixed= peak violations before zero transitionKey improvements from oracle analysis:
slice(-checkpointLimit)violationsFixedas max before zero (not last count)Schema Reuse (DRY)
Pure + IO Separation
Pure layer (
pure.ts):detectExtinctNorms,computeDirectoryStats,determineStatus,findCleanTimestampIO layer (
DirectorySummarizer.ts):CLI Commands
Output structure:
Files Changed
New Files (8)
Core:
src/norms/types.ts(~160 LOC) - DirectoryStatus, Norm, DirectorySummary schemassrc/norms/errors.ts(~60 LOC) - TaggedErrors with usage examplessrc/norms/pure.ts(~380 LOC) - Pure detection logic with algorithm docssrc/norms/DirectorySummarizer.ts(~250 LOC) - Effect service with JSDoctest/norms/pure.test.ts(~560 LOC) - Comprehensive unit teststest/norms/DirectorySummarizer.test.ts(~800 LOC) - Integration tests with fixturesCLI:
src/commands/norms.ts(~270 LOC) - CLI command with all optionstest/commands/norms.test.ts(~700 LOC) - CLI integration testsModified Files (3)
Core:
src/schema/amp.ts(+2 lines) - ExportedSeverityschemasrc/index.ts(+4 lines) - Norms module exportsCLI:
src/index.ts(+2 lines) - RegisterednormsCommandTotal: ~2,180 new LOC
Documentation Quality
✅ Comprehensive JSDoc:
@since 0.6.0@param,@returns,@throwsEffect.catchTag@category Schema,@category Pure Function, etc.)Example documentation:
Breaking Changes
None - purely additive feature.
Next Steps
After merge:
norms capture --prepare-onlyto preview directory summariesSuccess Criteria
@since 0.6.0Related
Plan: docs/agents/plans/pr7-norms-capture-mvp-v2.md
Thread: https://ampcode.com/threads/T-ef7148f3-339e-4252-9824-286bde77eee9
Dependencies: PR #46 (JSON checkpoints) - ✅ MERGED