MILTON.DocumentGenerator Service Context
You are working in the MILTON.DocumentGenerator worker service — the document generation pipeline.
Responsibilities
- Background document generation using AI.
- Owns
docgen-dbviaDocGenDbContext(Wolverine self-provisions saga + inbox/outbox tables). - Receives claim-check keys from S3, runs pure AI logic (
IAIServiceonly, no DB access), writes results back to S3, and replies with completion events. - NEVER touches
milton-dbdirectly.
Document Processing Pipeline (Message-Only)
- (API)
InstantiateDocumentHandlermaterializes template →Document+Section+ContentBlockrows inmilton-db, then publishesDocumentCreatedEvent. - (DocGen)
DocumentProcessingSagaconsumes it and dispatches each block to the API viaPrepareXGenerationCommand. - (API)
PrepareXhandler gathers block, source code context (S3), LLM presets, writes payload to S3 claim-check store, and replies withXGenerationRequested. - (DocGen) Worker reads claim-check input, runs pure core (
IAIServiceonly, no DB), writes result back to claim-check store, and replies withXGenerationCompleted. - (API)
ApplyXhandler reads result, updatesmilton-db, notifies clients, and replies withBlockProcessedEventso saga advances. - (DocGen) On completion, saga emits
GeneratePdfCommand(handled by API) andDocumentGenerationCompletedEvent.
Owned Paths
MILTON.DocumentGenerator/Features/— vertical slices: Common, Requirements, Scanners, TestCasesMILTON.DocumentGenerator/Sagas/— Wolverine sagas (DocumentProcessingSaga,AiAgentSaga)MILTON.DocumentGenerator/Contracts/— per-producer[MessageIdentity]recordsMILTON.DocumentGenerator/Domain/— domain models and pure generation coresMILTON.DocumentGenerator/Infrastructure/— claim-check, AI clients, persistenceMILTON.DocumentGenerator/Persistence/— DbContext and migrationsMILTON.DocumentGenerator/Tools/— agent tools used during generation
Key Technologies
- Wolverine Sagas and static handlers
- S3 Claim-Check pattern (
IClaimCheckStore) - Pure generation Cores (e.g.,
RequirementGenerationCore) [MessageIdentity]messaging withMILTONAPI- Depends on
MILTON.PlatformandMILTON.ServiceDefaults
Contracts This Service Owns
RequirementGenerationRequested/RequirementGenerationCompletedScannerGenerationRequested/ScannerGenerationCompletedTestCaseGenerationRequested/TestCaseGenerationCompletedAgentSessionMessagesand saga commands (ContinueAgentSessionCommand)
Working Rules
- Load and follow
milton-vertical-slicebefore creating any newMILTON.DocumentGenerator/Features/<Feature>. - Load and follow
milton-tddbefore writing or changing behavior. Strict RED-GREEN-REFACTOR. - Keep handlers static and message-only (no direct DB access).
- Do not read/write
milton-db; receive all needed data via messages and claim checks. - Maintain
[MessageIdentity]parity withMILTONAPI contract mirrors.
Migrations & Verification
# Add EF Core migration for docgen-db (from solution root)
dotnet ef migrations add MigrationName --project MILTON.DocumentGenerator --startup-project MILTON.DocumentGenerator
# Apply DocGen migration manually (normally done by MILTON.DocumentGeneratorMigrationService on startup)
dotnet ef database update --project MILTON.DocumentGenerator --startup-project MILTON.DocumentGenerator- New behavior has a failing-then-passing test.
-
dotnet build MILTON.DocumentGeneratorsucceeds with no warnings. -
dotnet test MILTON.Tests/passes for affected DocumentGenerator tests. - Cross-service
[MessageIdentity]strings matchMILTONAPI mirrors.