codebase-audit
$
npx mdskill add TencentCloudBase/CloudBase-MCP/codebase-auditEnd-to-end workflow: systematically review the entire codebase, report findings as GitHub issues, fix each issue in an isolated git worktree, and submit PRs — all in one session.
SKILL.md
.github/skills/codebase-auditView on GitHub ↗
---
name: codebase-audit
description: Perform a full codebase review, categorize findings by severity, file GitHub issues, then fix each issue in an isolated git worktree and submit PRs. Use this skill when the user asks to audit the codebase, do a comprehensive code review, find and fix security/quality/reliability issues, or run a proactive health check across the entire repository.
alwaysApply: false
---
# Codebase Audit → Issue → Worktree Fix → PR
End-to-end workflow: systematically review the entire codebase, report findings as GitHub issues, fix each issue in an isolated git worktree, and submit PRs — all in one session.
## When to use this skill
Use this skill when you need to:
- Perform a full code review / audit of the codebase
- Proactively find security vulnerabilities, logic bugs, or code quality problems
- Turn code review findings into tracked GitHub issues
- Fix each issue in isolation (worktree per issue) and submit PRs
- Run a periodic codebase health check with automated follow-through
- Audit and fix dependency security vulnerabilities (Dependabot alerts / npm audit)
**Do NOT use for:**
- Reviewing or fixing a single known bug (use `systematic-debugging` or direct fix)
- Triaging existing open PRs (use `pr-review-fix`)
- Processing attribution issues (use `mcp-attribution-worktree`)
- Feature development or refactoring unrelated to audit findings
## Workflow
### Phase 1 — Review
1. Read `references/review-strategy.md` for the review scope and checklist.
2. Use the `code-explorer` subagent to read ALL source files in the target directory (default: `mcp/src/`).
3. For each file, systematically check against the review checklist:
- **Security**: path traversal, injection, unvalidated input, hardcoded secrets, improper error exposure
- **Error handling**: missing try-catch, swallowed errors, error messages leaking internals
- **Type safety**: `as any`, unsafe casts, missing null checks
- **Logic bugs**: race conditions, incorrect conditionals, unreachable code
- **Code quality**: dead code, duplication, overly complex functions
- **Resource leaks**: unclosed connections, missing cleanup
- **API design**: inconsistent validation, missing required field checks
4. Record every finding with: file path, line number(s), category, severity (Critical/High/Medium/Low), description, and suggested fix.
5. **Dependency scan**: Read `references/dependency-audit.md` and run the Dependabot alert fetch + `npm audit` to discover vulnerable dependencies. Record each finding using the dependency-audit format.
### Phase 2 — Analyze & Classify
1. Read `references/classification.md` for severity definitions and grouping rules.
2. Deduplicate findings — merge instances of the same pattern across files.
3. Group findings into **fix batches** — related issues that should be fixed together in one PR.
4. Assign severity and priority:
- **P0 (Critical)**: Security vulnerabilities, data loss risks
- **P1 (High)**: Logic bugs, error handling gaps that cause runtime failures
- **P2 (Medium)**: Type safety, code quality issues affecting maintainability
- **P3 (Low)**: Style, naming, minor cleanup
5. Present a structured audit report to the user and wait for confirmation before proceeding.
### Phase 3 — Create GitHub Issues
1. Read `references/issue-workflow.md` for issue creation guidelines.
2. For each fix batch (or individual Critical finding), create a GitHub issue:
```bash
gh issue create --title "<type>(<scope>): <summary>" --body "<structured body>" --label "<severity>,<category>"
```
3. Issue body must include: affected files, line numbers, problem description, expected behavior, and suggested fix approach.
4. Link related issues when findings are connected.
5. Present the created issues to the user.
### Phase 4 — Worktree Fix
1. Read `references/worktree-fix.md` for the isolation and fix procedure.
2. For each issue (in priority order):
a. Create an isolated worktree and branch:
```bash
git worktree add ../<repo>-audit-fix-<issue-number> -b fix/<slug>-<issue-number> origin/main
```
b. Work inside the worktree — never in the main checkout.
c. Implement the fix, keeping changes minimal and focused.
d. Verify locally: `cd mcp && npm run build && npm run test`
e. Commit with conventional-changelog format:
```bash
git commit -m 'fix(<scope>): 🔒 <english description>
Closes #<issue-number>'
```
f. Push and create PR:
```bash
git push github fix/<slug>-<issue-number>
gh pr create --title "fix(<scope>): 🔒 <summary>" --body "Closes #<issue-number>\n\n<description>" --base main
```
g. Remove the worktree after PR is created:
```bash
cd <original-dir>
git worktree remove ../<repo>-audit-fix-<issue-number>
```
3. One worktree per issue. Never mix fixes across worktrees.
4. **Dependency fixes**: For dependency vulnerability batches, follow `references/dependency-audit.md` Step 4. These can be grouped into a single PR since they modify `package.json` / `package-lock.json`.
### Phase 5 — Verify & Report
1. Read `references/verification.md` for the verification checklist.
2. Check CI status for each PR:
```bash
gh pr checks <number>
```
3. If CI fails, re-enter the worktree, fix, and push again.
4. Generate a final audit report summarizing:
- Total findings by category and severity
- Issues created (with links)
- PRs submitted (with links)
- Remaining items that need human decision
## Routing
| Task | Read |
| --- | --- |
| What to review and how to check each category | `references/review-strategy.md` |
| How to classify, deduplicate, and batch findings | `references/classification.md` |
| How to create well-structured GitHub issues | `references/issue-workflow.md` |
| How to create worktrees and fix issues in isolation | `references/worktree-fix.md` |
| How to verify fixes and generate the final report | `references/verification.md` |
| How to audit and fix dependency vulnerabilities | `references/dependency-audit.md` |
## Git safety rules
- **Never force-push** unless explicitly asked.
- **Never amend** commits that are already pushed.
- **Always work inside the worktree**, not the main checkout.
- **Always verify** build + test locally before pushing.
- **One worktree per issue** — never mix fixes.
- **Clean up worktrees** after PR creation.
## Commit conventions
Follow the project's conventional-changelog format:
```
fix(<scope>): 🔒 <english description>
Closes #<issue-number>
```
Scope examples: `security`, `deps`, `error-handling`, `type-safety`, `code-quality`, `cloudrun`, `database`, `functions`
## Minimum self-check
- Did I review ALL source files in the target scope, not just a sample?
- Did I categorize each finding with file, line, severity, and description?
- Did I present the audit report and get user confirmation before creating issues?
- Did I create a separate GitHub issue for each fix batch?
- Did I use an isolated worktree for each fix, not the main checkout?
- Did I verify build + test pass before pushing each fix?
- Did I clean up worktrees after creating PRs?
- Did I generate a final report with links to all issues and PRs?
- Did I check Dependabot alerts and npm audit for dependency vulnerabilities?
- Did I apply the correct fix strategy (upgrade / override / replace / dismiss) for each vulnerable dependency?
More from TencentCloudBase/CloudBase-MCP
- ai-model-nodejsUse this skill for Node.js backend AI via @cloudbase/node-sdk (>=3.16.0) — cloud functions, CloudRun, Express, Koa, NestJS, serverless APIs, scheduled jobs, LLM proxies. Only SDK supporting image generation (ai.createImageModel + generateImage). Text models via ai.createModel with groups cloudbase, hunyuan-exp, or custom-*. Model IDs (deepseek-v4-flash, deepseek-v3.2, hunyuan-2.0-instruct-20251111, glm-5, kimi-k2.6) go in the model field of generateText/streamText. MUST run two-step preflight before code — see body. Keywords: backend, 云函数, 云托管, serverless, LLM proxy, agent orchestration, generateText, streamText, generateImage, createModel, hunyuan-image, Token Credits, TokenHub, Hunyuan, DeepSeek, GLM, Kimi, MiniMax. NOT for browser/Web (use ai-model-web) or Mini Program (use ai-model-wechat).
- ai-model-webUse this skill when a browser/Web app (React, Vue, Angular, Next, Nuxt, static sites, SPAs, dashboards, AI chat UI) needs AI models via @cloudbase/js-sdk. Default routing for page/页面/Web/前端/frontend/网页/H5 AI — call directly from browser, do NOT propose a Node.js proxy. Covers generateText and streamText. Models via ai.createModel with groups cloudbase, hunyuan-exp, or custom-*. Model IDs (deepseek-v4-flash, deepseek-v3.2, hunyuan-2.0-instruct-20251111, glm-5, kimi-k2.6) go in the model field. MUST run two-step preflight before code — see body. Keywords: 页面, Web, 前端, React, Vue, Next, Nuxt, SPA, AI chat UI, generateText, streamText, createModel, hunyuan-exp, Token Credits, TokenHub, Hunyuan, DeepSeek, GLM, Kimi, MiniMax. NOT for Node.js backend (use ai-model-nodejs), Mini Program (use ai-model-wechat), or image generation (Node SDK only).
- ai-model-wechatUse this skill for WeChat Mini Program AI via wx.cloud.extend.AI (小程序, 企业微信小程序, wx.cloud apps). Features generateText and streamText with callbacks (onText, onEvent, onFinish). Models via wx.cloud.extend.AI.createModel with groups hunyuan-exp (小程序成长计划), cloudbase (main managed), or custom-*. Model IDs (deepseek-v4-flash, deepseek-v3.2, hunyuan-2.0-instruct-20251111, glm-5, kimi-k2.6) go in the data wrapper model field. API differs from JS/Node SDK — streamText needs data wrapper, generateText returns raw response. MUST run two-step preflight before code — see body. Keywords: Mini Program AI, wx.cloud.extend.AI, 小程序成长计划, ai_miniprogram_inspire_plan, Token Credits 资源包, generateText, streamText, createModel, hunyuan-exp, TokenHub, Hunyuan, DeepSeek, GLM, Kimi, MiniMax. NOT for browser/Web (use ai-model-web), Node.js backend (use ai-model-nodejs), or image generation (use ai-model-nodejs).
- api-contract-reviewUse when auditing CloudBase cloud API wrappers, MCP tools, generated action metadata, or related docs for outdated or incorrect action names, parameters, casing, request shapes, or missing contract tests, especially during periodic quality review or before preparing corrective PRs.
- auth-nodejs-cloudbaseCloudBase Node SDK auth guide for server-side identity, user lookup, and custom login tickets. This skill should be used when Node.js code must read caller identity, inspect end users, or bridge an existing user system into CloudBase; not when configuring providers or building client login UI.
- auth-tool-cloudbaseCloudBase auth provider configuration and login-readiness guide. This skill should be used when users need to inspect, enable, disable, or configure auth providers, publishable-key prerequisites, login methods, SMS/email sender setup, or other provider-side readiness before implementing a client or backend auth flow.
- auth-web-cloudbaseCloudBase Web Authentication Quick Guide for frontend integration after auth-tool has already been checked. Provides concise and practical Web authentication solutions with multiple login methods and complete user management.
- auth-wechat-miniprogramCloudBase WeChat Mini Program native authentication guide. This skill should be used when users need mini program identity handling, OPENID/UNIONID access, or `wx.cloud` auth behavior in projects where login is native and automatic.
- cloud-functionsCloudBase function runtime guide for building, deploying, and debugging your own Event Functions or HTTP Functions. This skill should be used when users need application runtime code on CloudBase, not when they are merely calling CloudBase official platform APIs.
- cloud-storage-webComplete guide for CloudBase cloud storage using Web SDK (@cloudbase/js-sdk) - upload, download, temporary URLs, file management, and best practices.