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-db via DocGenDbContext (Wolverine self-provisions saga + inbox/outbox tables).
  • Receives claim-check keys from S3, runs pure AI logic (IAIService only, no DB access), writes results back to S3, and replies with completion events.
  • NEVER touches milton-db directly.

Document Processing Pipeline (Message-Only)

  1. (API) InstantiateDocumentHandler materializes template → Document + Section + ContentBlock rows in milton-db, then publishes DocumentCreatedEvent.
  2. (DocGen) DocumentProcessingSaga consumes it and dispatches each block to the API via PrepareXGenerationCommand.
  3. (API) PrepareX handler gathers block, source code context (S3), LLM presets, writes payload to S3 claim-check store, and replies with XGenerationRequested.
  4. (DocGen) Worker reads claim-check input, runs pure core (IAIService only, no DB), writes result back to claim-check store, and replies with XGenerationCompleted.
  5. (API) ApplyX handler reads result, updates milton-db, notifies clients, and replies with BlockProcessedEvent so saga advances.
  6. (DocGen) On completion, saga emits GeneratePdfCommand (handled by API) and DocumentGenerationCompletedEvent.

Owned Paths

  • MILTON.DocumentGenerator/Features/ — vertical slices: Common, Requirements, Scanners, TestCases
  • MILTON.DocumentGenerator/Sagas/ — Wolverine sagas (DocumentProcessingSaga, AiAgentSaga)
  • MILTON.DocumentGenerator/Contracts/ — per-producer [MessageIdentity] records
  • MILTON.DocumentGenerator/Domain/ — domain models and pure generation cores
  • MILTON.DocumentGenerator/Infrastructure/ — claim-check, AI clients, persistence
  • MILTON.DocumentGenerator/Persistence/ — DbContext and migrations
  • MILTON.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 with MILTON API
  • Depends on MILTON.Platform and MILTON.ServiceDefaults

Contracts This Service Owns

  • RequirementGenerationRequested / RequirementGenerationCompleted
  • ScannerGenerationRequested / ScannerGenerationCompleted
  • TestCaseGenerationRequested / TestCaseGenerationCompleted
  • AgentSessionMessages and saga commands (ContinueAgentSessionCommand)

Working Rules

  1. Load and follow milton-vertical-slice before creating any new MILTON.DocumentGenerator/Features/<Feature>.
  2. Load and follow milton-tdd before writing or changing behavior. Strict RED-GREEN-REFACTOR.
  3. Keep handlers static and message-only (no direct DB access).
  4. Do not read/write milton-db; receive all needed data via messages and claim checks.
  5. Maintain [MessageIdentity] parity with MILTON API 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.DocumentGenerator succeeds with no warnings.
  • dotnet test MILTON.Tests/ passes for affected DocumentGenerator tests.
  • Cross-service [MessageIdentity] strings match MILTON API mirrors.