Implement BD_GUIDE.md generation for version-stamped documentation (bd-woro)
This implements the ability to separate bd-specific instructions from project-specific instructions by generating a canonical BD_GUIDE.md file. ## Changes 1. Added `--output` flag to `bd onboard` command - Generates version-stamped BD_GUIDE.md at specified path - Includes both agentsContent and copilotInstructionsContent - Auto-generated header warns against manual editing 2. Version tracking integration - checkAndSuggestBDGuideUpdate() detects outdated BD_GUIDE.md - Suggests regeneration when bd version changes - Integrated with maybeShowUpgradeNotification() 3. Comprehensive test coverage - Tests for BD_GUIDE.md generation - Tests for version stamp validation - Tests for content inclusion 4. Documentation updates - Updated AGENTS.md with BD_GUIDE.md workflow - Added regeneration instructions to upgrade workflow ## Benefits - Clear separation of concerns (bd vs project instructions) - Deterministic updates (no LLM involved) - Git-trackable diffs show exactly what changed - Progressive disclosure (agents read when needed) ## Usage \`\`\`bash # Generate BD_GUIDE.md bd onboard --output .beads/BD_GUIDE.md # After upgrading bd bd onboard --output .beads/BD_GUIDE.md # Regenerate \`\`\` Closes bd-woro
This commit is contained in:
@@ -415,6 +415,66 @@ func renderOnboardInstructions(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// bdGuideContent generates the canonical BD_GUIDE.md content
|
||||
const bdGuideHeader = `<!-- Auto-generated by bd v%s - DO NOT EDIT MANUALLY -->
|
||||
<!-- Run 'bd onboard --output .beads/BD_GUIDE.md' to regenerate -->
|
||||
|
||||
# BD (Beads) Guide for AI Agents
|
||||
|
||||
This file contains canonical bd (beads) workflow instructions for AI agents.
|
||||
It is auto-generated and version-stamped to track bd upgrades.
|
||||
|
||||
> **For project-specific instructions**, see AGENTS.md in the repository root.
|
||||
> This file only covers bd tool usage, not project-specific workflows.
|
||||
|
||||
---
|
||||
|
||||
`
|
||||
|
||||
// generateBDGuide creates a version-stamped BD_GUIDE.md file
|
||||
func generateBDGuide(outputPath string) error {
|
||||
// Create output file
|
||||
f, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Write header with version stamp
|
||||
if _, err := fmt.Fprintf(f, bdGuideHeader, Version); err != nil {
|
||||
return fmt.Errorf("failed to write header: %w", err)
|
||||
}
|
||||
|
||||
// Write AGENTS.md content (bd-specific instructions)
|
||||
if _, err := f.WriteString(agentsContent); err != nil {
|
||||
return fmt.Errorf("failed to write agents content: %w", err)
|
||||
}
|
||||
|
||||
// Write separator
|
||||
if _, err := f.WriteString("\n\n---\n\n"); err != nil {
|
||||
return fmt.Errorf("failed to write separator: %w", err)
|
||||
}
|
||||
|
||||
// Write Copilot instructions content (comprehensive technical guide)
|
||||
if _, err := f.WriteString(copilotInstructionsContent); err != nil {
|
||||
return fmt.Errorf("failed to write copilot content: %w", err)
|
||||
}
|
||||
|
||||
// Write footer with regeneration instructions
|
||||
footer := fmt.Sprintf("\n\n---\n\n"+
|
||||
"**Generated by bd v%s**\n\n"+
|
||||
"To regenerate this file after upgrading bd:\n"+
|
||||
"```bash\n"+
|
||||
"bd onboard --output .beads/BD_GUIDE.md\n"+
|
||||
"```\n", Version)
|
||||
|
||||
if _, err := f.WriteString(footer); err != nil {
|
||||
return fmt.Errorf("failed to write footer: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var onboardCmd = &cobra.Command{
|
||||
Use: "onboard",
|
||||
Short: "Display instructions for configuring AGENTS.md",
|
||||
@@ -422,8 +482,29 @@ var onboardCmd = &cobra.Command{
|
||||
|
||||
This command outputs instructions that AI agents should follow to integrate bd
|
||||
into the project's agent documentation. The agent will intelligently merge the
|
||||
content into AGENTS.md and update CLAUDE.md if present.`,
|
||||
content into AGENTS.md and update CLAUDE.md if present.
|
||||
|
||||
Use --output to generate a canonical BD_GUIDE.md file instead:
|
||||
bd onboard --output .beads/BD_GUIDE.md
|
||||
|
||||
The generated BD_GUIDE.md is version-stamped and auto-generated - it should
|
||||
never be manually edited. This separates bd-specific instructions (which change
|
||||
with bd upgrades) from project-specific instructions in AGENTS.md.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
outputPath, _ := cmd.Flags().GetString("output")
|
||||
|
||||
if outputPath != "" {
|
||||
// Generate BD_GUIDE.md instead of onboarding instructions
|
||||
if err := generateBDGuide(outputPath); err != nil {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Error generating BD_GUIDE.md: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("✓ Generated %s (bd v%s)\n", outputPath, Version)
|
||||
fmt.Println(" This file is auto-generated - do not edit manually")
|
||||
fmt.Println(" Update your AGENTS.md to reference this file instead of duplicating bd instructions")
|
||||
return
|
||||
}
|
||||
|
||||
if err := renderOnboardInstructions(cmd.OutOrStdout()); err != nil {
|
||||
if _, writeErr := fmt.Fprintf(cmd.ErrOrStderr(), "Error rendering onboarding instructions: %v\n", err); writeErr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error rendering onboarding instructions: %v (stderr write failed: %v)\n", err, writeErr)
|
||||
@@ -434,5 +515,6 @@ content into AGENTS.md and update CLAUDE.md if present.`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
onboardCmd.Flags().String("output", "", "Generate BD_GUIDE.md at the specified path (e.g., .beads/BD_GUIDE.md)")
|
||||
rootCmd.AddCommand(onboardCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user