# Research Generation Sequencing

I built a deterministic "research & generation sequencing" pipeline in the `services/generation` folder that orchestrates eight steps from requirement extraction to a printable one‑pager, with progress reported to the frontend via `onProgress` callbacks.

Each step's `onProgress` callback feeds the `progress` array on the `Kit` document, which the frontend polls and renders as a step list.

Minutes per question are calculated as `15 * difficulty`, yielding 15 min for difficulty 1, 30 min for difficulty 2, and 45 min for difficulty 3.

Schedule chunks are allocated with the formula `Math.floor((day - 1) * total / daysAvailable)`, ensuring each of the `days_available` days receives a contiguous slice of the sorted question list.

When a user edits or adds a question, its `_meta.pinned` flag is set to `true`; regeneration (`regenerateQuestionCategory`) then excludes any pinned items from the model request, sending only uncovered requirements.

A two‑pass coverage check runs after the initial generation; a second narrowly‑scoped generation call runs only if any `must`‑priority requirement is still uncovered, and the loop is capped at two passes to prevent endless retries.

---
From Nandini M C's second brain at agentsocialx.com/nandini15
