plugins/beaver/skills/beaver-design-doc/SKILL.md
Write and submit a design document for a Beaver size/L issue in status/design-pending. Trigger when the user wants to write a design doc, start design review, or work on a design-pending issue.
npx skillsauth add primatrix/skills beaver-design-docInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Write a design document for a size/L issue in status/design-pending. Collects design details through iterative Q&A, writes a structured design doc, submits it as a PR to primatrix/wiki, and comments on the original issue.
References beaver-engine for: label ops (Section 4), state machine validation (Section 2), QA loop & HARD-GATE (Section 7), Discovery Triad (Section 8), doc quality constraints (Section 9).
gh auth status must succeedowner/repo#issue-numberdigraph design_doc {
"Load & Validate Issue" [shape=box];
"Context Collection (Q&A)" [shape=box];
"Draft Design Doc" [shape=box];
"Sectional Review" [shape=box];
"All sections approved?" [shape=diamond];
"Submit to Wiki" [shape=box];
"Comment on Issue" [shape=box];
"Load & Validate Issue" -> "Context Collection (Q&A)";
"Context Collection (Q&A)" -> "Draft Design Doc";
"Draft Design Doc" -> "Sectional Review";
"Sectional Review" -> "All sections approved?" ;
"All sections approved?" -> "Sectional Review" [label="no, revise"];
"All sections approved?" -> "Submit to Wiki" [label="yes"];
"Submit to Wiki" -> "Comment on Issue";
}
Extract owner, repo, and issue_number from the argument. Format: owner/repo#number.
If the argument does not match this format, stop and inform user:
gh api repos/{owner}/{repo}/issues/{number} --jq '{title, body, state, labels: [.labels[].name]}'
Parse labels per engine Section 4. Verify:
size/L labelstatus/design-pending labelIf either is missing, stop and inform user:
size/L: "This issue is not size/L. Design docs only apply to size/L issues."status/design-pending: "This issue is not in design-pending status. Cannot start a design doc. Current status: {current_status}"Parse Goals and Acceptance Criteria from the issue body. Display to user as starting context.
Before the first question, execute engine §8 Discovery Triad. Use the issue title + objective as the keyword source. Print the Discovery Brief in the §8.3 format. Do NOT proceed to Phase 2 Section 1 until the Brief has been printed (HARD-GATE per §8 introduction).
Q&A discipline is governed by engine §7 (one question at a time, approval grammar per §7.5, skip-detection per §7.4). Doc quality is governed by engine §9 (bilingual rule §9.1, anti-hallucination §9.2, completeness checklist §9.3 to be presented before each section's Approved? (y/revise) prompt).
Design-doc-specific additions:
Read any @-referenced file before continuing.WebFetch or Read it before continuing.Collect information across the following 4 sections one by one. Each section does not have a fixed list of questions; dynamically determine the next question based on Discovery Brief findings and previously-collected answers:
Goal: Understand the environment and boundaries of the project; establish objective background facts
Starting Points:
Completion Criteria: A reader should be able to understand, solely from this section, what environment the new system will be built in and what is being built. Concise, objective, and fact-oriented.
Goal: Clarify goals, non-goals, and success metrics
Starting Points:
Completion Criteria: Goals cover user scenarios, non-goals have clear boundaries, and success metrics are measurable.
Goal: Architecture, components, interfaces, data flow, trade-offs, plus lightweight test strategy and deployment dependencies
Starting Points:
Key Focus: Focus on trade-offs. The core value of a design doc lies in recording the trade-offs made during design. Given the context (facts) and goals (requirements), the design should demonstrate why a particular approach best satisfies those goals.
Completion Criteria: Architecture boundaries are clear, technology choices are justified, trade-offs are explicitly recorded, and testing and deployment have lightweight coverage.
Goal: Collect other approaches the user considered and the reasons they were rejected
Starting Points:
Completion Criteria: After reading this section, the reader should understand why the current approach is optimal and why other seemingly viable approaches fell short.
Based on all collected information, write the design doc using the template below.
Present each of the 4 sections individually. For each section:
Approved? (y/revise)y/yes/ok/approve/approved/lgtm/继续/通过 count). Anything else means revise.After all sections approved, show full document and ask for final confirmation.
# If ~/Code/wiki exists, check clean state and pull latest
if [ -d ~/Code/wiki ]; then
if [ -n "$(git -C ~/Code/wiki status --porcelain)" ]; then
echo "~/Code/wiki has uncommitted changes. Please commit or stash before proceeding."
exit 1
fi
git -C ~/Code/wiki checkout main && git -C ~/Code/wiki pull
else
gh repo clone primatrix/wiki ~/Code/wiki
fi
Generate slug from issue title (lowercase, hyphens, no special chars).
git -C ~/Code/wiki checkout -B design/{issue_number}-{slug}
Ensure the docs/designs/ directory exists, then write the design doc:
mkdir -p ~/Code/wiki/docs/designs
Write to: ~/Code/wiki/docs/designs/YYYY-MM-DD-{issue-slug}.md
git -C ~/Code/wiki add docs/designs/YYYY-MM-DD-{issue-slug}.md
git -C ~/Code/wiki commit -m "docs: add design doc for {owner}/{repo}#{number}"
git -C ~/Code/wiki push -u origin design/{issue_number}-{slug}
PR_BODY_FILE=$(mktemp)
cat > "$PR_BODY_FILE" << 'EOF'
## Design Document
Related Issue: {owner}/{repo}#{number}
### Summary
{one-paragraph summary of the design}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
gh pr create --repo primatrix/wiki \
--title "Design: {issue_title}" \
--body-file "$PR_BODY_FILE"
rm "$PR_BODY_FILE"
BODY_FILE=$(mktemp)
cat > "$BODY_FILE" << 'BEAVEREOF'
Design document submitted: {PR_URL}
Please review the design document in the PR. Once the review is approved, transition this issue from `status/design-pending` to `status/ready-to-develop`.
BEAVEREOF
gh api repos/{owner}/{repo}/issues/{number}/comments \
--method POST -F body=@"$BODY_FILE"
rm "$BODY_FILE"
Print summary: PR URL, design doc path, issue status (remains design-pending).
Then print the next-step hint (do NOT auto-invoke):
Next step: after the design doc PR is reviewed and merged, run:
beaver-decompose {owner}/{repo}#{number}
to break the size/L Task into SubTasks.
---
issue: {owner}/{repo}#{number}
title: {issue_title}
date: {YYYY-MM-DD}
status: design-pending
---
# {Issue Title} Design Document
## 1. Context & Scope
{Objective background facts. The technical environment the new system operates in and what is being built. Concise, no opinions.}
## 2. Design Goals
### 2.1 Goals
{List of goals}
### 2.2 Non-Goals
{Things that could reasonably be goals but are explicitly chosen not to pursue. Not negative goals.}
### 2.3 Success Metrics
{How to measure the success of the design}
## 3. The Design
### 3.1 System Context Diagram
{Where the new system fits within the larger technical landscape, helping readers place the new design in a familiar context}
### 3.2 Core Architecture
{Key components, system boundaries, technology choices and rationale}
### 3.3 Interfaces & Data Flow
{API overview (avoid pasting complete interface definitions; focus on parts relevant to design trade-offs), data storage approach, data flow between modules}
### 3.4 Trade-offs
{Key trade-offs made in the design and their rationale. This is the core value of a design document.}
### 3.5 Test Strategy
{Key test paths, mock strategy — brief description}
### 3.6 Deployment & Dependencies
{Deployment approach, external dependencies — brief description}
## 4. Alternatives Considered
{Other viable approaches and their trade-offs. Focus on the trade-offs of each alternative and why the current approach is better given the stated goals.}
## 5. Open Questions
{Items raised during Q&A that are recorded but not yet decided. For each: question, owner, expected resolution time. Empty list is acceptable but the section header must be present.}
<!-- provenance
- "<fact 1>" ← <source: Discovery D1/D2/D3 line, or QA round N>
- "<fact 2>" ← <source>
-->
General red flags are defined in engine §7.4. Below are design-doc-specific additions only:
| Thought | Reality | |---------|---------| | "I can derive the trade-offs from the code" | Trade-offs are design decisions, not code facts. They must come from the user. Ask. | | "I'll skip §5 Open Questions to look more decisive" | Forcing closure on open items causes hallucination later. List them honestly. | | "The Provenance block is paperwork, I'll skip it" | Provenance is the audit trail that prevents future drift. It is required. |
size/L + status/design-pending labels<!-- provenance --> block per §9.2 and a ## 5. Open Questions sectiondesign-pending — no automatic transitionbeaver-decompose, but does NOT auto-invoke it~/Code/wikidevelopment
Use when analyzing TPU pretraining HBM occupancy from a profile directory — locates the static HBM peak (the same number TensorBoard's Memory Viewer shows), enumerates every buffer alive at the peak schedule moment with size / HLO instruction / opcode / op_name, and rolls the alive set up by opcode and op_name. Reads compile-time `*.hlo_proto.pb` (BufferAssignmentProto) as the primary source; runtime `*.xplane.pb` allocator events are a secondary, often-truncated signal.
testing
Use when analyzing TPU pretraining compute efficiency from xplane.pb — produces source-line-aggregated HLO duration tables, layer-scoped breakdowns, non-compute (padding/cast/copy) audits, and v7x roofline shortfall vs theoretical peak. Reads schema documented by profile-anatomy.
tools
--- name: comm-analysis description: Use when analyzing communication on a TPU pretraining profile — extracts every comm primitive (async + sync, TC + SparseCore), attributes axes via HLO replica_groups, computes per-row NCCL bus BW vs per-axis peak ICI BW (peak_link × k_torus_dims × directions_per_dim; TPUv7x: 200 GB/s bidir per link on a 3D torus; util% requires `--mesh-spec` with topology), and reports per-step compute/comm overlap. Builds on profile-anatomy. --- # Communication Analysis **
documentation
Use when reading TPU pretraining profiles (xplane.pb, trace.json.gz) — describes the on-disk layout, the XSpace/XPlane/XLine/XEvent/XStat hierarchy, and provides reference scripts that future tpu-perf skills can read as schema documentation.