|
| 1 | +--- |
| 2 | +name: update-command-knowledge |
| 3 | +description: Auto-detect changed subcommand dirs from staged git changes and regenerate their README.md + CLAUDE.md knowledge docs |
| 4 | +--- |
| 5 | + |
| 6 | +# Update Command Knowledge |
| 7 | + |
| 8 | +This skill generates and updates per-subcommand knowledge docs (README.md + CLAUDE.md) in each `internal/verda-cli/cmd/*/` directory. It can be invoked headlessly via `claude -p "/update-command-knowledge"` or interactively via `/update-command-knowledge`. |
| 9 | + |
| 10 | +## Step 1: Determine which command directories to process |
| 11 | + |
| 12 | +If the argument contains `--all`, process ALL command directories: |
| 13 | +- auth, vm, sshkey, startupscript, volume, settings, version, update |
| 14 | + |
| 15 | +Otherwise, detect changed dirs from staged files: |
| 16 | + |
| 17 | +1. Run `git diff --cached --name-only` using the Bash tool |
| 18 | +2. From the output, extract unique directory names matching the pattern `internal/verda-cli/cmd/<dir>/` where `<dir>` is not `util` |
| 19 | +3. Exclude any matches that are just files in `internal/verda-cli/cmd/` itself (like `cmd.go`, `helper.go`) — only include actual subdirectories |
| 20 | + |
| 21 | +If no directories are found, print exactly: |
| 22 | +> No command directories with staged changes. Nothing to update. |
| 23 | +
|
| 24 | +Then stop. Do not generate any files. |
| 25 | + |
| 26 | +## Step 2: For each affected directory, read and analyze the source |
| 27 | + |
| 28 | +For each directory `internal/verda-cli/cmd/<domain>/`: |
| 29 | + |
| 30 | +1. Use the Glob tool to find all `*.go` files in the directory |
| 31 | +2. Use the Read tool to read every `.go` file found |
| 32 | +3. Analyze the code to extract: |
| 33 | + - **Parent command**: The `Use`, `Aliases`, and `Short` fields from the parent cobra command (usually in `<domain>.go`) |
| 34 | + - **Subcommands**: Each subcommand's `Use`, `Short`, `Long`, `Example`, and flags (from `cmd.Flags()` calls) |
| 35 | + - **API calls**: SDK client methods used (e.g., `client.VirtualMachines.List`, `client.SSHKeys.Create`) |
| 36 | + - **Business logic**: Pricing calculations, status mappings, validation rules, formatting |
| 37 | + - **Wizard flows**: If a `wizard.go` exists, document the steps, `clientFunc`, `apiCache` usage |
| 38 | + - **Interactive vs non-interactive**: Which flags allow non-interactive mode, what gets prompted when missing |
| 39 | + |
| 40 | +Do NOT guess or infer — extract all information directly from the source code. |
| 41 | + |
| 42 | +## Step 3: Generate README.md |
| 43 | + |
| 44 | +For each directory, generate `internal/verda-cli/cmd/<domain>/README.md` using the Write tool. |
| 45 | + |
| 46 | +If a README.md already exists in the directory, read it first with the Read tool before generating — you will need to preserve manually-added sections. |
| 47 | + |
| 48 | +Follow this template: |
| 49 | + |
| 50 | +```markdown |
| 51 | +# verda <domain> — <Short description from parent command> |
| 52 | + |
| 53 | +## Commands |
| 54 | + |
| 55 | +| Command | Description | Key Flags | |
| 56 | +|---------|-------------|-----------| |
| 57 | +| `verda <domain> <sub>` | Short desc | `--flag1`, `--flag2` | |
| 58 | + |
| 59 | +## Usage Examples |
| 60 | + |
| 61 | +### <Subcommand 1> |
| 62 | +\`\`\`bash |
| 63 | +# Interactive |
| 64 | +verda <domain> <sub> |
| 65 | + |
| 66 | +# Non-interactive |
| 67 | +verda <domain> <sub> --flag value |
| 68 | +\`\`\` |
| 69 | + |
| 70 | +(Repeat for each subcommand. Use the `Example` field from cobra commands when available.) |
| 71 | + |
| 72 | +## Interactive vs Non-Interactive |
| 73 | + |
| 74 | +Describe which flags enable non-interactive mode, what happens when flags are missing (prompts). |
| 75 | + |
| 76 | +## Architecture Notes |
| 77 | + |
| 78 | +- List key files and what each does |
| 79 | +- API endpoints/SDK methods used |
| 80 | +- Business logic (pricing, status mappings, etc.) |
| 81 | +- Wizard flows if applicable |
| 82 | +``` |
| 83 | + |
| 84 | +If the old README.md had manually-added sections titled "Gotchas" or "Notes", append them at the end of the newly generated content. |
| 85 | + |
| 86 | +## Step 4: Generate CLAUDE.md |
| 87 | + |
| 88 | +For each directory, generate `internal/verda-cli/cmd/<domain>/CLAUDE.md` using the Write tool. |
| 89 | + |
| 90 | +If a CLAUDE.md already exists in the directory, read it first with the Read tool before generating — you will need to preserve manually-added gotchas. |
| 91 | + |
| 92 | +Follow this template: |
| 93 | + |
| 94 | +```markdown |
| 95 | +# <Domain> Command Knowledge |
| 96 | + |
| 97 | +## Quick Reference |
| 98 | +- Parent: `verda <domain>` (aliases: <aliases or "none">) |
| 99 | +- Subcommands: <comma-separated list> |
| 100 | +- Files: list each .go file and a brief description of its role |
| 101 | + |
| 102 | +## Domain-Specific Logic |
| 103 | +- Pricing calculations, status mappings, validation rules |
| 104 | +- Any non-obvious business rules extracted from the code |
| 105 | + |
| 106 | +## Gotchas & Edge Cases |
| 107 | +- Things that aren't obvious from reading the code |
| 108 | +- Common mistakes when modifying this command |
| 109 | + |
| 110 | +## Relationships |
| 111 | +- Dependencies on other packages (util, SDK types, wizard engine) |
| 112 | +- Shared state (apiCache, clientFunc patterns) |
| 113 | +``` |
| 114 | + |
| 115 | +If the old CLAUDE.md had manually-added items in the "Gotchas & Edge Cases" section, append them below any auto-detected gotchas (avoid exact duplicates). |
| 116 | + |
| 117 | +## Step 5: Stage the updated docs |
| 118 | + |
| 119 | +After all files are written, run a single `git add` command using the Bash tool to stage all the README.md and CLAUDE.md files that were created or updated. For example: |
| 120 | + |
| 121 | +```bash |
| 122 | +git add internal/verda-cli/cmd/vm/README.md internal/verda-cli/cmd/vm/CLAUDE.md internal/verda-cli/cmd/sshkey/README.md internal/verda-cli/cmd/sshkey/CLAUDE.md |
| 123 | +``` |
| 124 | + |
| 125 | +## Important rules |
| 126 | + |
| 127 | +- Use the Write tool to create/update doc files — do NOT use Bash (echo/cat) for file creation |
| 128 | +- Use Bash only for `git diff --cached --name-only` and `git add` |
| 129 | +- Read ALL .go files in a directory before generating docs — accuracy matters |
| 130 | +- If a directory has no .go files or no parent command definition, skip it and note why |
| 131 | +- Do not modify any .go source files — this skill only creates/updates README.md and CLAUDE.md |
| 132 | +- Do not create docs for `internal/verda-cli/cmd/util/` — always skip this directory |
0 commit comments