docgen: curated context — .docgen-cascade.md cascades up into ancestor prompts - #4
Merged
Conversation
…r prompts
Adds a small opt-in system for injecting hand-written guidance into
docgen's prompt without putting hand-written content INSIDE the
generated README (which would defeat regeneration — same lesson as
the PR #53 README rewrite incident).
Three new file locations the maintainer can drop:
.docgen/global.md — included in every dir's prompt
<dir>/.docgen-context.md — only this dir's prompt
<descendant>/.docgen-cascade.md
— bubbles up into every ancestor's prompt
The cascade is the load-bearing pattern. A single
bots/scripts/backtest/factory/.docgen-cascade.md
saying 'Available commands at this layer: factory snapshot --refresh,
factory loop --all, ...' flows into the prompts of every ancestor
(backtest/, scripts/, bots/, root). The generated README at each level
naturally surfaces the same vocabulary without the maintainer
duplicating it five times.
Implementation:
- New collectCuratedContext(root, dir) returns {label, content,
relPath, mtimeMs}[] from the 3 sources, capped at 4KB per file
- assembleContext takes opts.curatedContext, formats as a
'## Curated context (hand-written, treat as authoritative)' section
BEFORE child READMEs + raw files
- analyzeOne calls collectCuratedContext, passes it through, and
persists curatedContextAtAnalysis in state for change detection
- needsAnalysis re-triggers re-generation on any curated context file
change (added / mtime-bumped / removed) — same semantic as
own-file change detection
No behavior change for repos that don't drop the files. Existing
tests pass unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Today's README-rewrite incident (#106 restored the deliberate PR #53 README after the "vibe coders" rewrite overwrote it) confirmed: hand-written content inside auto-generated files gets clobbered. But maintainers still need a way to inject curated guidance — "available commands at this layer," "this subtree has a paper-only invariant," "treat X as authoritative" — into the prompt docgen sends to claude.
This PR adds an opt-in mechanism for exactly that, with zero risk to existing READMEs.
Three new file locations
.docgen/global.md<dir>/.docgen-context.md<descendant>/.docgen-cascade.mdThe cascade pattern is the load-bearing one. A single file at
bots/scripts/backtest/factory/.docgen-cascade.mdflows into the prompts of every ancestor (backtest/,scripts/,bots/, root). Each layer's generated README naturally surfaces the same vocabulary without the maintainer duplicating it five times.Implementation
collectCuratedContext(root, dir)returns{label, content, relPath, mtimeMs}[]from the three sources, capped at 4 KB per fileassembleContexttakesopts.curatedContext, formats as## Curated context (hand-written, treat as authoritative)section before child READMEs + raw files (so the LLM frames the README around maintainer intent rather than re-deriving from scratch)analyzeOnepasses the collected context through + persistscuratedContextAtAnalysisin state for change detectionneedsAnalysisre-triggers re-generation when any curated context file is added, modified, or removed — same semantic as own-file change detectionZero behavior change for repos that don't drop the files
If no
.docgen/global.md, no.docgen-context.md, no.docgen-cascade.mdexists,collectCuratedContextreturns an empty array, theassembleContextsection is skipped, thecuratedContextAtAnalysisfield is{}, andneedsAnalysisdoesn't re-trigger on anything new. All existing tests pass unchanged.Test plan
.docgen-cascade.mdsomewhere, rundocgen status— should show the dir ascontext-addedcontext-modifiedcontext-removedGenerated with Claude Code