This document outlines how repository scans are transformed into AI instruction defaults inside DevContext. It covers the major touchpoints so you can extend or debug the pipeline with confidence.
-
Scan the repository (
app/api/scan-repo/route.ts)- Detect languages, frameworks, tooling, structure hints, and enriched metadata.
- Load stack question metadata (
loadStackQuestionMetadata) so detection lists (e.g., testing tools) map onto the same canonical values the wizard exposes. - Reuse those canonical values to expand stack-specific heuristics (e.g., Python’s Behave directories, Next.js routing shapes) without hard-coding strings inside the scanner.
- Infer the primary stack using
inferStackFromScan. - Load stack conventions (
loadStackConventions) to determine which structure hints matter and whether stack-specific rules exist. - Attach
summary.conventionsso the UI knows which directories to highlight and whether a conventions file was found.
-
Build wizard defaults (
lib/scan-to-wizard.ts)- Start with an empty
WizardResponsesobject. - Layer in detections from the scan (tooling, testing, naming signals, etc.), matching scan values against the question catalog so defaults stay in sync with the wizard.
- Run convention rules to tweak values based on detected tooling/testing.
- Pull default answers directly from the stack’s question set (
loadStackQuestionMetadata) and fill any remaining empty responses. We track which questions were auto-defaulted (defaultedQuestionIds) so the summary can explain why.
- Start with an empty
-
Persist and surface responses
lib/scan-prefill.tsmerges the generated responses into local wizard state and stores bothautoFilledMapanddefaultedMapin localStorage.- The instructions wizard and stack summary pages read these maps to highlight that values came from a scan or from default recommendations.
components/wizard-completion-summary.tsxdisplays a “Default applied” badge for any question filled solely by defaults.
-
Generate instruction files
- From the repo-scan UI, clicking “Generate” calls
lib/scan-generate.ts, which posts to/api/scan-generate/[fileId]. - The API reuses
buildResponsesFromScanserver-side to ensure consistency, then renders the target template withrenderTemplate. - Template rendering pulls
applyToGlobfrom conventions so Copilot instructions target stack-appropriate file globs (e.g.**/*.{py,pyi,md}for Python). - When a field falls back to a stack default because the scan lacked a signal,
renderTemplateannotates the generated instruction with a note that it came from the default rather than the scan.
- From the repo-scan UI, clicking “Generate” calls
| Location | Purpose |
|---|---|
conventions/default.json & /conventions/<stack>.json |
Declarative rules, applyToGlob, and structure hints for each stack. |
lib/question-metadata.ts |
Caches question answers/defaults per stack so both the scanner and wizard share a single source of truth. |
lib/wizard-responses.ts |
Produces empty WizardResponses objects and guards response keys. |
data/stacks.json |
List of stacks exposed to the wizard; each should have a matching conventions file. |
data/questions/<stack>.json |
Stack-specific questions with default answers and metadata. These defaults are now honored automatically when scan data is missing. |
- Add a new stack: create
conventions/<stack>.json, add questions underdata/questions/<stack>.json, and register the stack indata/stacks.json. The pipeline will pick it up automatically. - Add scan heuristics: update
app/api/scan-repo/route.ts(e.g., detect tooling/testing) so conventions rules have richer signals to work with. Shared helpers mean you can usually expand detection by tweaking the convention file plus a small matcher (seedetectPythonTestingSignalsfor the current pattern). - Adjust defaults: edit the stack’s question JSON to set a new
isDefaultanswer; the scan pipeline will adopt it whenever the repo lacks an explicit signal. - Customize templates: templates consume the final
WizardResponses, so any new fields surfaced via conventions should be represented there before referencing them in markdown/JSON output.
- If a stack lacks a conventions file, the repo-scan page shows a call-to-action to add one. Structure hints fall back to the global defaults.
- The completion summary distinguishes between values detected from the scan (
isAutoFilled) and those populated strictly because a question has a default (isDefaultApplied). - The
/api/scan-generateendpoint keeps the server-side and client-side generation logic aligned, preventing divergence between UI previews and API output.