ma-agents 2.20.3 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/skills/.ma-agents.json +241 -0
- package/.opencode/skills/MANIFEST.yaml +254 -0
- package/.opencode/skills/ai-audit-trail/SKILL.md +23 -0
- package/.opencode/skills/auto-bug-detection/SKILL.md +169 -0
- package/.opencode/skills/cmake-best-practices/SKILL.md +64 -0
- package/.opencode/skills/cmake-best-practices/examples/cmake.md +59 -0
- package/.opencode/skills/code-documentation/SKILL.md +57 -0
- package/.opencode/skills/code-documentation/examples/cpp.md +29 -0
- package/.opencode/skills/code-documentation/examples/csharp.md +28 -0
- package/.opencode/skills/code-documentation/examples/javascript_typescript.md +28 -0
- package/.opencode/skills/code-documentation/examples/python.md +57 -0
- package/.opencode/skills/code-review/SKILL.md +43 -0
- package/.opencode/skills/commit-message/SKILL.md +79 -0
- package/.opencode/skills/cpp-best-practices/SKILL.md +234 -0
- package/.opencode/skills/cpp-best-practices/examples/modern-idioms.md +189 -0
- package/.opencode/skills/cpp-best-practices/examples/naming-and-organization.md +102 -0
- package/.opencode/skills/cpp-concurrency-safety/SKILL.md +60 -0
- package/.opencode/skills/cpp-concurrency-safety/examples/concurrency.md +73 -0
- package/.opencode/skills/cpp-const-correctness/SKILL.md +63 -0
- package/.opencode/skills/cpp-const-correctness/examples/const_correctness.md +54 -0
- package/.opencode/skills/cpp-memory-handling/SKILL.md +42 -0
- package/.opencode/skills/cpp-memory-handling/examples/modern-cpp.md +49 -0
- package/.opencode/skills/cpp-memory-handling/examples/smart-pointers.md +46 -0
- package/.opencode/skills/cpp-modern-composition/SKILL.md +64 -0
- package/.opencode/skills/cpp-modern-composition/examples/composition.md +51 -0
- package/.opencode/skills/cpp-robust-interfaces/SKILL.md +55 -0
- package/.opencode/skills/cpp-robust-interfaces/examples/interfaces.md +56 -0
- package/.opencode/skills/create-hardened-docker-skill/SKILL.md +637 -0
- package/.opencode/skills/create-hardened-docker-skill/scripts/create-all.sh +489 -0
- package/.opencode/skills/csharp-best-practices/SKILL.md +278 -0
- package/.opencode/skills/docker-hardening-verification/SKILL.md +28 -0
- package/.opencode/skills/docker-hardening-verification/scripts/verify-hardening.sh +39 -0
- package/.opencode/skills/docker-image-signing/SKILL.md +28 -0
- package/.opencode/skills/docker-image-signing/scripts/sign-image.sh +33 -0
- package/.opencode/skills/document-revision-history/SKILL.md +104 -0
- package/.opencode/skills/git-workflow-skill/SKILL.md +194 -0
- package/.opencode/skills/git-workflow-skill/hooks/commit-msg +61 -0
- package/.opencode/skills/git-workflow-skill/hooks/pre-commit +38 -0
- package/.opencode/skills/git-workflow-skill/hooks/prepare-commit-msg +56 -0
- package/.opencode/skills/git-workflow-skill/scripts/finish-feature.sh +192 -0
- package/.opencode/skills/git-workflow-skill/scripts/install-hooks.sh +55 -0
- package/.opencode/skills/git-workflow-skill/scripts/start-feature.sh +110 -0
- package/.opencode/skills/git-workflow-skill/scripts/validate-workflow.sh +229 -0
- package/.opencode/skills/js-ts-dependency-mgmt/SKILL.md +49 -0
- package/.opencode/skills/js-ts-dependency-mgmt/examples/dependency_mgmt.md +60 -0
- package/.opencode/skills/js-ts-security-skill/SKILL.md +64 -0
- package/.opencode/skills/js-ts-security-skill/scripts/verify-security.sh +136 -0
- package/.opencode/skills/logging-best-practices/SKILL.md +50 -0
- package/.opencode/skills/logging-best-practices/examples/cpp.md +36 -0
- package/.opencode/skills/logging-best-practices/examples/csharp.md +49 -0
- package/.opencode/skills/logging-best-practices/examples/javascript.md +77 -0
- package/.opencode/skills/logging-best-practices/examples/python.md +57 -0
- package/.opencode/skills/logging-best-practices/references/logging-standards.md +29 -0
- package/.opencode/skills/open-presentation/SKILL.md +35 -0
- package/.opencode/skills/opentelemetry-best-practices/SKILL.md +34 -0
- package/.opencode/skills/opentelemetry-best-practices/examples/go.md +32 -0
- package/.opencode/skills/opentelemetry-best-practices/examples/javascript.md +58 -0
- package/.opencode/skills/opentelemetry-best-practices/examples/python.md +37 -0
- package/.opencode/skills/opentelemetry-best-practices/references/otel-standards.md +37 -0
- package/.opencode/skills/python-best-practices/SKILL.md +385 -0
- package/.opencode/skills/python-dependency-mgmt/SKILL.md +42 -0
- package/.opencode/skills/python-dependency-mgmt/examples/dependency_mgmt.md +67 -0
- package/.opencode/skills/python-security-skill/SKILL.md +56 -0
- package/.opencode/skills/python-security-skill/examples/security.md +56 -0
- package/.opencode/skills/self-signed-cert/SKILL.md +42 -0
- package/.opencode/skills/self-signed-cert/scripts/generate-cert.ps1 +45 -0
- package/.opencode/skills/self-signed-cert/scripts/generate-cert.sh +43 -0
- package/.opencode/skills/skill-creator/SKILL.md +196 -0
- package/.opencode/skills/skill-creator/references/output-patterns.md +82 -0
- package/.opencode/skills/skill-creator/references/workflows.md +28 -0
- package/.opencode/skills/skill-creator/scripts/init_skill.py +208 -0
- package/.opencode/skills/skill-creator/scripts/package_skill.py +99 -0
- package/.opencode/skills/skill-creator/scripts/quick_validate.py +113 -0
- package/.opencode/skills/story-status-lookup/SKILL.md +78 -0
- package/.opencode/skills/test-accompanied-development/SKILL.md +50 -0
- package/.opencode/skills/test-generator/SKILL.md +65 -0
- package/.opencode/skills/vercel-react-best-practices/SKILL.md +109 -0
- package/.opencode/skills/verify-hardened-docker-skill/SKILL.md +442 -0
- package/.opencode/skills/verify-hardened-docker-skill/scripts/verify-docker-hardening.sh +439 -0
- package/AiAudit.md +5 -0
- package/QUICK_START.md +11 -5
- package/README.md +52 -1
- package/bin/cli.js +31 -4
- package/docs/BMAD_AI_Development_Training.pptx +0 -0
- package/docs/technical-notes/context-persistence-research.md +434 -0
- package/docs/technical-notes/enforcement-hooks-research.md +415 -0
- package/lib/agents.js +34 -0
- package/lib/bmad-extension/agents/bmm-architect.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-bmad-master.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-cyber.customize.yaml +30 -0
- package/lib/bmad-extension/agents/bmm-dev.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-devops.customize.yaml +30 -0
- package/lib/bmad-extension/agents/bmm-mil498.customize.yaml +42 -0
- package/lib/bmad-extension/agents/bmm-pm.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-qa.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-sm.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-sre.customize.yaml +30 -0
- package/lib/bmad-extension/agents/bmm-tech-writer.customize.yaml +5 -0
- package/lib/bmad-extension/agents/bmm-ux-designer.customize.yaml +5 -0
- package/lib/bmad-extension/module-help.csv +7 -0
- package/lib/bmad-extension/module.yaml +3 -0
- package/lib/bmad-extension/workflows/add-sprint/workflow.md +112 -0
- package/lib/bmad-extension/workflows/add-to-sprint/workflow.md +206 -0
- package/lib/bmad-extension/workflows/create-bug-story/workflow.md +186 -0
- package/lib/bmad-extension/workflows/modify-sprint/workflow.md +250 -0
- package/lib/bmad-extension/workflows/project-context-expansion/workflow.md +229 -0
- package/lib/bmad-extension/workflows/sprint-status-view/workflow.md +193 -0
- package/lib/bmad.js +168 -36
- package/lib/hooks/claude-code/verify-manifest.js +56 -0
- package/lib/installer.js +282 -1
- package/lib/methodology/BMAD_AI_Development_Training.pptx +0 -0
- package/lib/methodology/version.json +7 -0
- package/lib/skill-authoring.js +732 -0
- package/lib/templates/project-context.template.md +47 -0
- package/opencode.json +8 -0
- package/package.json +2 -2
- package/skills/auto-bug-detection/SKILL.md +165 -0
- package/skills/auto-bug-detection/skill.json +8 -0
- package/skills/code-review/SKILL.md +40 -0
- package/skills/cpp-best-practices/SKILL.md +230 -0
- package/skills/cpp-best-practices/examples/modern-idioms.md +189 -0
- package/skills/cpp-best-practices/examples/naming-and-organization.md +102 -0
- package/skills/cpp-best-practices/skill.json +25 -0
- package/skills/csharp-best-practices/SKILL.md +274 -0
- package/skills/csharp-best-practices/skill.json +23 -0
- package/skills/git-workflow-skill/skill.json +1 -1
- package/skills/open-presentation/SKILL.md +31 -0
- package/skills/open-presentation/skill.json +11 -0
- package/skills/python-best-practices/SKILL.md +381 -0
- package/skills/python-best-practices/skill.json +26 -0
- package/skills/story-status-lookup/SKILL.md +74 -0
- package/skills/story-status-lookup/skill.json +8 -0
- package/test/agent-injection-strategy.test.js +13 -7
- package/test/bmad-extension.test.js +237 -0
- package/test/bmad-output-policy.test.js +119 -0
- package/test/build-bmad-args.test.js +361 -0
- package/test/create-agent.test.js +232 -0
- package/test/enforcement-hooks.test.js +324 -0
- package/test/generate-project-context.test.js +337 -0
- package/test/integration-verification.test.js +402 -0
- package/test/opencode-agent.test.js +150 -0
- package/test/opencode-json-error.test.js +260 -0
- package/test/opencode-json-injection.test.js +256 -0
- package/test/opencode-json-merge.test.js +299 -0
- package/test/skill-authoring.test.js +272 -0
- package/test/skill-customize-agent.test.js +253 -0
- package/test/skill-mandatory.test.js +235 -0
- package/test/skill-validation.test.js +378 -0
- package/test/yes-flag.test.js +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
<!-- ma-agents-template-version: 1.0 -->
|
|
3
|
+
<!-- Generated by ma-agents at install time — this is a living document -->
|
|
4
|
+
<!--
|
|
5
|
+
EXPAND THIS FILE over time:
|
|
6
|
+
- After architecture phase: run /bmad-generate-project-context
|
|
7
|
+
- After each sprint: run /project-context-expansion (post-retrospective companion)
|
|
8
|
+
- Manually: add conventions you notice agents getting wrong
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
## AI Agent Mandatory Rules
|
|
12
|
+
|
|
13
|
+
### Pre-Task (EVERY task, no exceptions)
|
|
14
|
+
|
|
15
|
+
1. Read the MANIFEST.yaml for your platform:
|
|
16
|
+
<!-- ma-agents:manifest-paths-start -->
|
|
17
|
+
{{MANIFEST_PATHS_LIST}}
|
|
18
|
+
<!-- ma-agents:manifest-paths-end -->
|
|
19
|
+
2. Load ALL skills marked `always_load: true` completely before doing anything
|
|
20
|
+
3. Select additional skills relevant to the specific task type
|
|
21
|
+
|
|
22
|
+
### Git Workflow (ALL file-changing tasks)
|
|
23
|
+
|
|
24
|
+
1. Create a fresh worktree: `git worktree add ../<project>-<branch> -b <branch>`
|
|
25
|
+
2. ALL work happens inside that worktree — never in the main working tree
|
|
26
|
+
3. Use conventional commits: `feat/fix/chore/docs/refactor`
|
|
27
|
+
4. Open a PR to main — never commit directly to main, never auto-merge
|
|
28
|
+
5. After human approval and merge: `git worktree remove ../<project>-<branch>`
|
|
29
|
+
|
|
30
|
+
### Agent Mission Lifecycle
|
|
31
|
+
|
|
32
|
+
1. **Pre-flight:** Read MANIFEST.yaml, load always_load skills, select task skills
|
|
33
|
+
2. **Worktree:** `git worktree add` creates fresh, isolated working surface
|
|
34
|
+
3. **Implementation:** Execute task within the worktree
|
|
35
|
+
4. **Self-review:** Run `code-review` skill on own output before opening PR
|
|
36
|
+
5. **PR:** Conventional commit + PR opened — clear title and description
|
|
37
|
+
6. **Human review gate:** Await approval — do NOT auto-merge under any circumstance
|
|
38
|
+
7. **Merge + cleanup:** After approval: merge, `git worktree remove`, delete branch
|
|
39
|
+
8. **Post-mission:** Update story status to done, append session to AiAudit.md
|
|
40
|
+
|
|
41
|
+
## Technology Stack
|
|
42
|
+
<!-- TODO: Populated after architecture phase via /bmad-generate-project-context -->
|
|
43
|
+
<!-- Run: /bmad-generate-project-context to auto-detect your stack -->
|
|
44
|
+
|
|
45
|
+
## Project-Specific Rules
|
|
46
|
+
<!-- TODO: Grows through retrospectives and manual additions -->
|
|
47
|
+
<!-- Run: /bmad-retrospective after each sprint to surface new conventions -->
|
package/opencode.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"instructions": [
|
|
3
|
+
{
|
|
4
|
+
"_source": "ma-agents",
|
|
5
|
+
"text": "# AI Agent Skills - Planning Instruction\n\nYou have access to a library of skills in your skills directory. Before starting any task:\n\n1. Read the skill manifest at .opencode/skills/MANIFEST.yaml\n2. Based on the task description, select which skills are relevant\n3. Read only the selected skill files\n4. Then proceed with the task\n\nAlways load skills marked with always_load: true.\nDo not load skills that are not relevant to the current task."
|
|
6
|
+
}
|
|
7
|
+
]
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ma-agents",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "NPX tool to install skills for AI coding agents (Claude Code, Gemini, Copilot, Kilocode, Cline, Cursor)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node bin/cli.js",
|
|
11
|
-
"test": "node test/yes-flag.test.js",
|
|
11
|
+
"test": "node test/yes-flag.test.js && node test/skill-authoring.test.js && node test/skill-validation.test.js && node test/skill-mandatory.test.js && node test/skill-customize-agent.test.js && node test/create-agent.test.js && node test/generate-project-context.test.js && node test/build-bmad-args.test.js",
|
|
12
12
|
"build:bmad-cache": "node scripts/build-bmad-cache.js"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Auto Bug Detection
|
|
2
|
+
|
|
3
|
+
Proactively identify and report defects found in already-delivered code during all agent sessions.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
When you encounter code that has already been delivered (story/task marked done), you must scan for defects
|
|
8
|
+
and report them using the structured format below. Do not silently ignore bugs in delivered code.
|
|
9
|
+
|
|
10
|
+
## Detection Scope
|
|
11
|
+
|
|
12
|
+
### Delivered Code (MUST scan and report bugs)
|
|
13
|
+
|
|
14
|
+
- Code whose associated story/task is marked **done** or **completed**, regardless of branch.
|
|
15
|
+
- Committed code on `main` or release branches.
|
|
16
|
+
- Committed code on feature branches whose **parent story is completed**.
|
|
17
|
+
|
|
18
|
+
### Work-in-Progress (DO NOT flag as bugs)
|
|
19
|
+
|
|
20
|
+
- Uncommitted changes in the working tree.
|
|
21
|
+
- Committed code on a branch whose associated story is still **in-progress** or **not-started**.
|
|
22
|
+
- `TODO` / `FIXME` markers in code added as part of the **current story under review**.
|
|
23
|
+
- Incomplete implementations explicitly tied to an active story.
|
|
24
|
+
|
|
25
|
+
### Ambiguous Boundary — Feature Branches
|
|
26
|
+
|
|
27
|
+
Committed code on a feature branch where the story status is **unknown** must be treated as WIP.
|
|
28
|
+
|
|
29
|
+
To resolve the status, use the `story-status-lookup` skill — it defines how to identify the story slug,
|
|
30
|
+
which file to read, and how to map status values to delivered vs WIP. Follow its fallback rule:
|
|
31
|
+
when status cannot be determined, **default to WIP and do NOT flag as a bug**.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Detection Criteria
|
|
36
|
+
|
|
37
|
+
Scan delivered code for the following categories of defects. Each category includes examples of what qualifies.
|
|
38
|
+
|
|
39
|
+
### 1. Logic Errors
|
|
40
|
+
|
|
41
|
+
Incorrect computational logic, wrong conditionals, or inverted boolean expressions that cause the code
|
|
42
|
+
to produce incorrect results.
|
|
43
|
+
|
|
44
|
+
**Examples:**
|
|
45
|
+
- Using `>` instead of `>=` in a boundary check, silently excluding a valid edge value.
|
|
46
|
+
- An accumulator initialized to `1` instead of `0`, skewing totals.
|
|
47
|
+
- A loop that iterates one too many or one too few times (off-by-one error).
|
|
48
|
+
|
|
49
|
+
### 2. Unhandled Edge Cases
|
|
50
|
+
|
|
51
|
+
Inputs or states that the code does not handle, leading to incorrect behavior or crashes.
|
|
52
|
+
|
|
53
|
+
**Examples:**
|
|
54
|
+
- A function that accepts a list but does not handle an empty list, throwing an index error.
|
|
55
|
+
- A parser that crashes on a valid but empty string input.
|
|
56
|
+
- Division without a zero-check on the divisor.
|
|
57
|
+
|
|
58
|
+
### 3. Missing Error Handling
|
|
59
|
+
|
|
60
|
+
Absence of error handling for operations that can fail, causing unhandled exceptions or silent failures.
|
|
61
|
+
|
|
62
|
+
**Examples:**
|
|
63
|
+
- File I/O calls with no try/catch, crashing the process on a missing file.
|
|
64
|
+
- Network requests with no timeout or error callback.
|
|
65
|
+
- A database query whose rejection is swallowed without logging or recovery.
|
|
66
|
+
|
|
67
|
+
### 4. Broken Contracts
|
|
68
|
+
|
|
69
|
+
Code that violates the API contract it published: wrong return types, missing required fields in
|
|
70
|
+
responses, or side effects not documented in the interface.
|
|
71
|
+
|
|
72
|
+
**Examples:**
|
|
73
|
+
- A function documented to return `string | null` but sometimes returns `undefined`.
|
|
74
|
+
- A REST endpoint returning HTTP 200 for a failed operation instead of the correct 4xx/5xx code.
|
|
75
|
+
- A class method mutating shared state that is not documented as a side effect.
|
|
76
|
+
|
|
77
|
+
### 5. Regressions
|
|
78
|
+
|
|
79
|
+
Previously working behavior that is now broken, typically introduced by a change in a related component.
|
|
80
|
+
|
|
81
|
+
**Examples:**
|
|
82
|
+
- A utility function refactored to accept a new parameter that broke all existing callers that pass no argument.
|
|
83
|
+
- A config key renamed in one place but not updated in all consumers, causing silent runtime failures.
|
|
84
|
+
- A test that was green before a dependency upgrade and now fails due to an incompatible API change.
|
|
85
|
+
|
|
86
|
+
### 6. Security Vulnerabilities
|
|
87
|
+
|
|
88
|
+
Code patterns that introduce exploitable security weaknesses in existing, delivered functionality.
|
|
89
|
+
|
|
90
|
+
**Examples:**
|
|
91
|
+
- User-supplied input passed directly into a shell command without sanitization (command injection).
|
|
92
|
+
- Secrets or API keys hard-coded in source files committed to the repository.
|
|
93
|
+
- SQL queries constructed via string concatenation with unsanitized user input (SQL injection).
|
|
94
|
+
- Sensitive data (passwords, tokens) logged at INFO level in production code.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Reporting Format
|
|
99
|
+
|
|
100
|
+
When a defect is detected in delivered code, report it using this structured template:
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
## Bug Report
|
|
104
|
+
|
|
105
|
+
**Title:** [Short, descriptive title]
|
|
106
|
+
**Severity:** [critical | high | medium | low]
|
|
107
|
+
**Category:** [logic-error | unhandled-edge-case | missing-error-handling | broken-contract | regression | security-vulnerability]
|
|
108
|
+
**Affected Component:** [Module, file, or system area]
|
|
109
|
+
|
|
110
|
+
**Reproduction Steps:**
|
|
111
|
+
1. [Step 1]
|
|
112
|
+
2. [Step 2]
|
|
113
|
+
|
|
114
|
+
**Expected Behavior:**
|
|
115
|
+
[What should happen]
|
|
116
|
+
|
|
117
|
+
**Actual Behavior:**
|
|
118
|
+
[What actually happens]
|
|
119
|
+
|
|
120
|
+
**Affected Files:**
|
|
121
|
+
- path/to/file.ext (line N)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Severity Guidelines:**
|
|
125
|
+
- `critical` — Data loss, security breach, or system crash in normal usage.
|
|
126
|
+
- `high` — Core feature broken or serious security risk; blocks users.
|
|
127
|
+
- `medium` — Feature partially broken or degraded; workaround exists.
|
|
128
|
+
- `low` — Minor issue, cosmetic defect, or edge case with minimal user impact.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## What NOT to Flag
|
|
133
|
+
|
|
134
|
+
Do **not** report the following as bugs:
|
|
135
|
+
|
|
136
|
+
- **Work-in-progress code** — Uncommitted changes or code on a branch with an active story.
|
|
137
|
+
- **TODO / FIXME comments** in code added as part of the **current story** being reviewed.
|
|
138
|
+
- **Incomplete implementations** explicitly tied to an active or not-yet-started story.
|
|
139
|
+
- **Style preferences** — Naming conventions, formatting, or architectural opinions not related to correctness.
|
|
140
|
+
- **Speculative issues** — Theoretical attack scenarios or failure modes with no demonstrable code path in the current codebase (e.g., an attack vector that requires filesystem access the process can never obtain).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Required Action on Detection
|
|
145
|
+
|
|
146
|
+
The required action depends on severity:
|
|
147
|
+
|
|
148
|
+
### critical or high severity
|
|
149
|
+
|
|
150
|
+
**Immediately run `/create-bug-story`** without waiting for user confirmation. These defects represent
|
|
151
|
+
broken core functionality or security risks that must not be left untracked. Inform the user as you act:
|
|
152
|
+
|
|
153
|
+
> "I found a **[severity]** bug in delivered code — running `create-bug-story` now to ensure it is tracked."
|
|
154
|
+
|
|
155
|
+
Do not ask permission. Do not proceed with other tasks until the bug story is created.
|
|
156
|
+
|
|
157
|
+
### medium or low severity
|
|
158
|
+
|
|
159
|
+
**Recommend** that the user create a formal bug story, but do not act without their confirmation:
|
|
160
|
+
|
|
161
|
+
> "I found a **[severity]** bug in delivered code. Would you like me to run `create-bug-story` to log it
|
|
162
|
+
> formally so it can be scheduled in the sprint?"
|
|
163
|
+
|
|
164
|
+
If the user declines or does not respond, note the finding in your response and continue. The bug report
|
|
165
|
+
remains visible in the conversation but is not written to a file.
|
|
@@ -18,6 +18,46 @@ Perform comprehensive code reviews following industry best practices.
|
|
|
18
18
|
- Suggest refactoring opportunities
|
|
19
19
|
- Assess test coverage and documentation
|
|
20
20
|
|
|
21
|
+
## Bug Detection During Review
|
|
22
|
+
|
|
23
|
+
When reviewing code, also evaluate **delivered code** (code whose associated story is marked done) for
|
|
24
|
+
pre-existing defects — not just the changes under review.
|
|
25
|
+
|
|
26
|
+
### Scope Distinction
|
|
27
|
+
|
|
28
|
+
- **Review feedback** (style, suggestions, correctness of the diff) → applies to the **current story's changes**
|
|
29
|
+
- **Bug reports** (defects in delivered code) → applies to **pre-existing code**, tracked independently
|
|
30
|
+
|
|
31
|
+
Do NOT block the current story review because of pre-existing bugs. Log them separately and continue.
|
|
32
|
+
|
|
33
|
+
### Detection During Review
|
|
34
|
+
|
|
35
|
+
The `auto-bug-detection` skill (always_load: true) provides the full detection criteria. During code review,
|
|
36
|
+
apply those criteria to the delivered code you encounter while reviewing the diff context.
|
|
37
|
+
|
|
38
|
+
When you detect a bug in delivered code:
|
|
39
|
+
|
|
40
|
+
1. **Label it clearly** with severity (critical / high / medium / low) and mark it as `[BUG]` — distinct from review findings
|
|
41
|
+
2. **Do not conflate it** with the review outcome — a story can pass review even if pre-existing bugs are found nearby
|
|
42
|
+
3. **Recommend the reviewer invoke `/create-bug-story`** to formally log the bug into the backlog
|
|
43
|
+
|
|
44
|
+
### Bug Finding Format (within review output)
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
### [BUG] <short title>
|
|
48
|
+
**Severity:** <critical|high|medium|low>
|
|
49
|
+
**Category:** <logic-error|unhandled-edge-case|missing-error-handling|broken-contract|regression|security-vulnerability>
|
|
50
|
+
**Affected Component:** <module or system area>
|
|
51
|
+
**Affected Files:** <file:line>
|
|
52
|
+
**Description:** <what the defect is — include expected vs actual behavior>
|
|
53
|
+
**Action:** Run `/create-bug-story` to log this formally → it will be tracked independently of this review.
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Note on Skill Interaction
|
|
57
|
+
|
|
58
|
+
The `auto-bug-detection` skill defines *what* to look for. This section defines *when* and *how* to
|
|
59
|
+
surface bug findings during a structured code review session.
|
|
60
|
+
|
|
21
61
|
## Output Format
|
|
22
62
|
|
|
23
63
|
```
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# C++ Best Practices
|
|
2
|
+
|
|
3
|
+
This skill establishes baseline C++ coding standards applicable to modern C++ projects (C++17/20/23). It covers naming conventions, code organization, memory management, error handling, modern idioms, and build guidelines. Domain-specific topics are handled by dedicated sibling skills — this skill provides the umbrella foundation and cross-references those skills where relevant.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Naming Conventions
|
|
8
|
+
|
|
9
|
+
### Rule: Use consistent case styles by identifier type.
|
|
10
|
+
|
|
11
|
+
| Identifier | Convention | Example |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| Types (class, struct, enum, alias) | `PascalCase` | `UserAccount`, `ConnectionPool` |
|
|
14
|
+
| Functions and methods | `camelCase` | `getUserName()`, `processData()` |
|
|
15
|
+
| Variables (local, parameter) | `camelCase` | `userName`, `itemCount` |
|
|
16
|
+
| Member variables (private) | `camelCase_` with trailing underscore | `name_`, `bufferSize_` |
|
|
17
|
+
| Constants and enumerators | `UPPER_SNAKE_CASE` | `MAX_RETRY_COUNT`, `DEFAULT_TIMEOUT` |
|
|
18
|
+
| Macros | `UPPER_SNAKE_CASE` | `ASSERT_NOT_NULL`, `LOG_LEVEL` |
|
|
19
|
+
| Namespaces | `lowercase_snake_case` | `network::http`, `core::utils` |
|
|
20
|
+
| Template parameters | `PascalCase` | `template<typename ValueType>` |
|
|
21
|
+
| Files | `snake_case.cpp` / `snake_case.h` | `user_account.cpp`, `connection_pool.h` |
|
|
22
|
+
|
|
23
|
+
**Action:** Do not abbreviate unless the abbreviation is universally understood in the domain (e.g., `id`, `url`, `http`). Avoid single-letter names except for loop indices (`i`, `j`, `k`) and template parameters (`T`, `U`).
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 2. Code Organization
|
|
28
|
+
|
|
29
|
+
### Rule: One primary type per header file; name the file after the type.
|
|
30
|
+
|
|
31
|
+
**Action:**
|
|
32
|
+
- Place class declarations in `.h` files; place definitions in `.cpp` files.
|
|
33
|
+
- Use `#pragma once` at the top of every header (preferred over include guards in new code).
|
|
34
|
+
- Group headers: project headers first, then third-party, then standard library — each group separated by a blank line.
|
|
35
|
+
- Keep headers self-contained: every header must include what it needs to compile in isolation.
|
|
36
|
+
|
|
37
|
+
### Rule: Use namespaces to model the logical module hierarchy.
|
|
38
|
+
|
|
39
|
+
**Action:**
|
|
40
|
+
- Prefer deeply nested namespaces over flat ones: `namespace myapp::network::http { ... }`.
|
|
41
|
+
- Avoid `using namespace` in header files. Restrict `using namespace std;` to `.cpp` file scope if used at all.
|
|
42
|
+
- Use `inline namespace` only for versioning public APIs (e.g., `inline namespace v2`).
|
|
43
|
+
|
|
44
|
+
### Rule: Keep translation units small and focused.
|
|
45
|
+
|
|
46
|
+
**Action:**
|
|
47
|
+
- Limit headers to declarations and inline functions under ~20 lines.
|
|
48
|
+
- Move non-trivial inline logic into `.inl` files included at the bottom of the header.
|
|
49
|
+
- Use forward declarations in headers to reduce compilation dependencies.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 3. Memory Management
|
|
54
|
+
|
|
55
|
+
**Action:** Apply RAII (Resource Acquisition Is Initialization) for all resources. Never allocate resources without an owning object responsible for releasing them.
|
|
56
|
+
|
|
57
|
+
Key policies:
|
|
58
|
+
- Prefer stack allocation. Use heap allocation only when lifetime exceeds scope or size is dynamic.
|
|
59
|
+
- Use `std::make_unique<T>()` for exclusive ownership; `std::make_shared<T>()` only when shared ownership is truly required.
|
|
60
|
+
- Never use raw `new` or `delete` outside of a low-level container implementation.
|
|
61
|
+
- Use standard containers (`std::vector`, `std::string`, `std::array`) instead of raw arrays and buffers.
|
|
62
|
+
|
|
63
|
+
> For detailed memory management patterns, see the `cpp-memory-handling` skill if installed.
|
|
64
|
+
> It covers RAII, smart pointer selection, Rule of Zero/Five, and ownership transfer patterns.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 4. Modern C++ Idioms
|
|
69
|
+
|
|
70
|
+
### C++17
|
|
71
|
+
|
|
72
|
+
**Action:** Use these C++17 features where they improve clarity:
|
|
73
|
+
|
|
74
|
+
- **Structured bindings**: `auto [key, value] = myMap.begin()->first;` — prefer over `first`/`second`.
|
|
75
|
+
- **`std::optional<T>`**: Return optional values instead of `nullptr` sentinels or output parameters.
|
|
76
|
+
- **`std::variant<T...>`**: Model sum types explicitly instead of void pointers or inheritance hierarchies.
|
|
77
|
+
- **`if constexpr`**: Replace SFINAE with readable compile-time branching in templates.
|
|
78
|
+
- **Fold expressions**: Simplify variadic template expansions: `(args + ... + 0)`.
|
|
79
|
+
- **`std::filesystem`**: Use `std::filesystem::path` for all file path manipulation; never concatenate paths with string operations.
|
|
80
|
+
- **Class template argument deduction (CTAD)**: Write `std::pair p{1, "hello"s}` instead of `std::make_pair`.
|
|
81
|
+
|
|
82
|
+
### C++20
|
|
83
|
+
|
|
84
|
+
**Action:** Adopt C++20 features when targeting C++20 or later:
|
|
85
|
+
|
|
86
|
+
- **Concepts**: Constrain template parameters with `requires` clauses instead of relying on substitution failures.
|
|
87
|
+
```cpp
|
|
88
|
+
template<std::integral T>
|
|
89
|
+
T clamp(T value, T lo, T hi);
|
|
90
|
+
```
|
|
91
|
+
- **Ranges**: Replace hand-written loops over containers with range adaptors (`std::views::filter`, `std::views::transform`, `std::ranges::sort`).
|
|
92
|
+
- **`std::format`**: Replace `printf`/`sprintf`/`ostringstream` with `std::format("{} has {} items", name, count)`.
|
|
93
|
+
- **Three-way comparison (`<=>`)**: Define `operator<=>` to implement all comparison operators at once.
|
|
94
|
+
- **Coroutines**: Use for asynchronous I/O and generator patterns; avoid raw `co_await` boilerplate — prefer a library abstraction (e.g., cppcoro, Asio).
|
|
95
|
+
- **Modules**: New projects targeting C++20+ should plan for module adoption; existing headers remain valid but prefer named module interface units for new public APIs.
|
|
96
|
+
|
|
97
|
+
### C++23
|
|
98
|
+
|
|
99
|
+
**Action:** Use C++23 features when the toolchain supports them:
|
|
100
|
+
|
|
101
|
+
- **`std::expected<T, E>`**: Return `expected<Result, ErrorCode>` from functions that can fail, eliminating exception-based control flow for expected failures.
|
|
102
|
+
- **`std::print` / `std::println`**: Replace `std::cout` for formatted output.
|
|
103
|
+
- **Deducing `this`**: Use explicit object parameter `this` to eliminate CRTP boilerplate and write recursive lambdas cleanly.
|
|
104
|
+
- **`std::flat_map` / `std::flat_set`**: Prefer over `std::map`/`std::set` for small to medium sorted collections requiring cache-friendly iteration.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 5. Const-Correctness
|
|
109
|
+
|
|
110
|
+
### Rule: Make everything const by default; relax only when mutation is required.
|
|
111
|
+
|
|
112
|
+
**Action:**
|
|
113
|
+
- Declare local variables `const auto` unless reassignment is needed.
|
|
114
|
+
- Mark member functions `const` whenever they do not modify observable state.
|
|
115
|
+
- Use `constexpr` for values and functions computable at compile-time.
|
|
116
|
+
- Pass large types by `const&`; pass cheap types (scalars, pointers, `string_view`) by value.
|
|
117
|
+
- Never return `const` by value from a function — it prevents move semantics.
|
|
118
|
+
|
|
119
|
+
> For detailed const-correctness policies, see the `cpp-const-correctness` skill if installed.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 6. Error Handling
|
|
124
|
+
|
|
125
|
+
### Rule: Choose an error-handling strategy per layer and apply it consistently.
|
|
126
|
+
|
|
127
|
+
| Context | Preferred Mechanism |
|
|
128
|
+
|---|---|
|
|
129
|
+
| Programmer errors (precondition violations) | `assert()` or contracts (C++26); never exceptions |
|
|
130
|
+
| Expected failures in library APIs | `std::expected<T, E>` (C++23) or error codes |
|
|
131
|
+
| Exceptional conditions that prevent normal flow | Exceptions (`std::runtime_error` hierarchy) |
|
|
132
|
+
| Async / coroutine code | Error channels in the coroutine framework |
|
|
133
|
+
|
|
134
|
+
**Action:**
|
|
135
|
+
- Mark functions that cannot throw `noexcept`. Destructors, move constructors, and swap functions MUST be `noexcept`.
|
|
136
|
+
- Catch exceptions by `const&` only: `catch (const std::exception& e)`.
|
|
137
|
+
- Never catch `...` (catch-all) except at top-level handlers or plugin boundaries.
|
|
138
|
+
- Do not use exceptions for control flow or expected failure paths — use `std::optional` or `std::expected` instead.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 7. Class Design
|
|
143
|
+
|
|
144
|
+
### Rule: Follow the Rule of Zero.
|
|
145
|
+
|
|
146
|
+
**Action:**
|
|
147
|
+
- Design classes so that the compiler-generated special members (copy/move constructor, copy/move assignment, destructor) are correct by default.
|
|
148
|
+
- Use RAII members (smart pointers, standard containers) to make this automatic.
|
|
149
|
+
- If you must define any special member function, define all five (destructor, copy ctor, move ctor, copy assign, move assign) — the Rule of Five.
|
|
150
|
+
|
|
151
|
+
### Rule: Prefer composition over inheritance for code reuse.
|
|
152
|
+
|
|
153
|
+
**Action:**
|
|
154
|
+
- Use `public` inheritance only to model true "is-a" relationships with polymorphic behavior.
|
|
155
|
+
- Mark base class destructors `virtual` when the class is intended to be used polymorphically.
|
|
156
|
+
- Mark overriding methods `override`; mark non-overridable methods `final`.
|
|
157
|
+
- Prefer free functions over member functions for operations that do not require access to private state.
|
|
158
|
+
- Mark factory functions and pure query methods with `[[nodiscard]]` (C++17) to turn silent result-discard into a compiler warning.
|
|
159
|
+
|
|
160
|
+
> For detailed composition patterns and elimination of legacy C patterns, see the `cpp-modern-composition` skill if installed.
|
|
161
|
+
> For interface design contracts and strong typing, see the `cpp-robust-interfaces` skill if installed.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 8. Concurrency
|
|
166
|
+
|
|
167
|
+
### Rule: Never share mutable state between threads without synchronization.
|
|
168
|
+
|
|
169
|
+
**Action:**
|
|
170
|
+
- Prefer task-based concurrency (`std::async`, thread pools) over raw `std::thread`. Always specify `std::launch::async` explicitly — `std::async` without a launch policy may run deferred (synchronously on the calling thread), which defeats the purpose of async execution.
|
|
171
|
+
- Protect shared data with `std::mutex`; always use `std::lock_guard` or `std::unique_lock` — never call `lock()`/`unlock()` manually.
|
|
172
|
+
- Declare data accessed from multiple threads as `std::atomic<T>` when appropriate (single-variable synchronization, counters, flags).
|
|
173
|
+
- Avoid `volatile` for inter-thread communication; use `std::atomic` instead.
|
|
174
|
+
|
|
175
|
+
> For detailed concurrency safety patterns, see the `cpp-concurrency-safety` skill if installed.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 9. Build and Compilation Guidelines
|
|
180
|
+
|
|
181
|
+
### Rule: Enable high-warning levels and treat warnings as errors.
|
|
182
|
+
|
|
183
|
+
**Action:**
|
|
184
|
+
- GCC/Clang: `-Wall -Wextra -Wpedantic -Wconversion -Wshadow -Werror`
|
|
185
|
+
- MSVC: `/W4 /WX`
|
|
186
|
+
- Do not disable warnings without an inline comment explaining the rationale.
|
|
187
|
+
|
|
188
|
+
### Rule: Use sanitizers during development and CI.
|
|
189
|
+
|
|
190
|
+
| Sanitizer | Flag (GCC/Clang) | Detects |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| AddressSanitizer | `-fsanitize=address` | Buffer overflows, use-after-free |
|
|
193
|
+
| UndefinedBehaviorSanitizer | `-fsanitize=undefined` | UB (integer overflow, null deref) |
|
|
194
|
+
| ThreadSanitizer | `-fsanitize=thread` | Data races |
|
|
195
|
+
|
|
196
|
+
**Action:** Enable at least `-fsanitize=address,undefined` in Debug and CI builds. Do not ship sanitizer builds.
|
|
197
|
+
|
|
198
|
+
### Rule: Set the C++ standard explicitly.
|
|
199
|
+
|
|
200
|
+
**Action:** Always specify `-std=c++17` (or higher) explicitly. Do not rely on compiler defaults, which differ across vendors.
|
|
201
|
+
|
|
202
|
+
> For CMake-specific build configuration patterns, see the `cmake-best-practices` skill if installed.
|
|
203
|
+
> It covers target-based CMake, `target_compile_options`, and compiler flag propagation.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 10. General Code Quality
|
|
208
|
+
|
|
209
|
+
### Rule: Prefer clarity over cleverness.
|
|
210
|
+
|
|
211
|
+
**Action:**
|
|
212
|
+
- Write code for the next reader, not the compiler. Compilers optimize well; humans struggle with obfuscation.
|
|
213
|
+
- Extract magic numbers into named `constexpr` constants.
|
|
214
|
+
- Prefer algorithms from `<algorithm>` and `<numeric>` over hand-written loops.
|
|
215
|
+
- Limit function length to what fits on one screen (~50 lines). If longer, extract named helper functions.
|
|
216
|
+
- Avoid deep nesting (more than 3 levels). Use early-return and guard clauses to flatten control flow.
|
|
217
|
+
|
|
218
|
+
### Rule: Use `auto` judiciously.
|
|
219
|
+
|
|
220
|
+
**Action:**
|
|
221
|
+
- Use `auto` when the type is verbose and already clear from context (e.g., iterators, lambda types, CTAD).
|
|
222
|
+
- Do not use `auto` when the type communicates intent and is not immediately obvious from the right-hand side.
|
|
223
|
+
- Always specify `auto&` or `const auto&` for range-for loops over containers of non-trivial types.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Resources
|
|
228
|
+
|
|
229
|
+
- [Naming and Organization Examples](examples/naming-and-organization.md)
|
|
230
|
+
- [Modern C++ Idioms Examples](examples/modern-idioms.md)
|