Skip to content

majiayu000/spellbook / skills/codebase-audit

codebase-audit

Verified

全面代码库审计 — 自适应并行深度分析(前后端契约、数据完整性、异常处理/安全、架构/技术债、配置/缓存),结构化 findings + 对抗验证 + 基线对比,输出按严重程度排序的统一报告和修复路线图。支持 quick 快速体检模式。Use when user asks to audit, analyze, or review an entire codebase for design issues, find hidden bugs, check architecture health, or asks '全面审查', '代码库审计', '分析设计问题', 'audit codebase', 'health check', '有哪些问题', '快速体检'. Also trigger when user asks to find silent degradation, data flow breakpoints, type mismatches between frontend and backend, or wants to understand technical debt across a project.

references/workflow-template.md

View on GitHub
# Workflow Orchestration Template

Preferred orchestration path. The caller (main agent) assembles the fully-rendered dimension prompts
(preamble + template + `{TARGET_DIR}`/`{STACK_INFO}` substituted) and passes them via `args`:

```
Workflow({
  script: <the script below>,
  args: {
    target: "/abs/path/to/project",
    dimensions: [ { key: "contract", prompt: "<full prompt>" }, ... ]
  }
})
```

Do not pass `model` or `agentType` — agents inherit the session model, and the prompts are
self-contained (they don't rely on a specialized agent's system prompt).

## Script

```js
export const meta = {
  name: 'codebase-audit',
  description: 'Parallel codebase audit: structured findings per dimension, adversarial verify for critical/high',
  phases: [
    { title: 'Find', detail: 'one finder agent per dimension' },
    { title: 'Verify', detail: 'one adversarial verifier per critical/high finding' },
  ],
}

const FINDINGS_SCHEMA = {
  type: 'object',
  required: ['findings'],
  properties: {
    findings: {
      type: 'array',
      items: {
        type: 'object',
        required: ['category', 'severity', 'file', 'summary', 'evidence', 'evidence_type', 'confidence'],
        properties: {
          category: { type: 'string' },
          severity: { enum: ['critical', 'high', 'medium'] },
          file: { type: 'string' },
          line: { type: 'integer' },
          summary: { type: 'string' },
          evidence: { type: 'string' },
          evidence_type: { enum: ['observed', 'inferred'] },
          confidence: { enum: ['high', 'medium', 'low'] },
          fix_suggestion: { type: 'string' },
        },
      },
    },
  },
}

const VERDICT_SCHEMA = {
  type: 'object',
  required: ['confirmed', 'reason'],
  properties: {
    confirmed: { type: 'boolean' },
    reason: { type: 'string' },
  },
}

function verifyPrompt(target, f) {
  return 'READ-ONLY adversarial verification — do not modify any file.\n' +
    'Target project: ' + target + '\n' +
    'Finding under review: [' + f.severity + '/' + f.category + '] ' + f.summary + '\n' +
    'Claimed location: ' + f.file + ':' + (f.line || '?') + '\n' +
    'Claimed evidence: ' + f.evidence + '\n\n' +
    'Open the file and its callers/guards/config. Actively try to REFUTE the finding: ' +
    'is there a guard clause, configuration, caller-side handling, or dead-code condition ' +
    'that makes this a non-issue? Set confirmed=false unless the code clearly supports the claim. ' +
    'In reason, cite file:line for whatever you found. Never reproduce credentials, tokens, ' +
    'private keys or other secret values in any output. Redact them consistently in reasons, ' +
    'evidence and summaries while retaining the file:line and enough non-secret context to verify the finding.'
}

const results = await pipeline(
  args.dimensions,
  d => agent(d.prompt, { label: 'find:' + d.key, phase: 'Find', schema: FINDINGS_SCHEMA }),
  (res, d) => {
    if (!res) {
      log('dim ' + d.key + ': finder FAILED — dimension incomplete')
      return { dim: d.key, failed: true, findings: [] }
    }
    const findings = res.findings || []
    const toVerify = findings.filter(f => f.severity === 'critical' || f.severity === 'high')
    const mediums = findings.filter(f => f.severity === 'medium')
    log('dim ' + d.key + ': ' + findings.length + ' findings, verifying ' + toVerify.length)
    return parallel(toVerify.map(f => () =>
      agent(verifyPrompt(args.target, f), {
        label: 'verify:' + (f.file || d.key),
        phase: 'Verify',
        schema: VERDICT_SCHEMA,
      }).then(v => Object.assign({}, f, {
        verified: v ? v.confirmed : null,
        verify_reason: v ? v.reason : 'verifier unavailable',
      })).catch(() => Object.assign({}, f, {
        verified: null,
        verify_reason: 'verifier failed — kept unverified',
      }))
    )).then(verified => ({
      dim: d.key,
      failed: false,
      findings: verified.filter(Boolean).concat(
        mediums.map(f => Object.assign({}, f, { verified: null, verify_reason: 'medium — not verified' }))
      ),
    }))
  }
)

return { dims: results.filter(Boolean) }
```

Notes:
- `pipeline` (not `parallel`) between Find and Verify: dimension A's findings verify while dimension B is still scanning.
- A finder that dies returns `null`; stage 2 converts it into `{ dim, failed: true, findings: [] }` so the failure survives into the result. The report MUST list every `failed: true` dimension as "dimension X did not complete" — never present it as zero findings / clean coverage.
- Each verifier thunk carries a `.catch` that maps the finding to `verified: null` — a flaky verifier keeps its finding as `unverified` instead of dropping it (matches the SKILL.md Phase 3 rule).
- Quick mode: pass only the 2 quick dimensions and replace the second pipeline stage with
  `(res, d) => res ? { dim: d.key, failed: false, findings: (res.findings || []).map(f => Object.assign({}, f, { verified: null, verify_reason: 'quick mode — not verified' })) } : { dim: d.key, failed: true, findings: [] }`.

## Fallback verify prompt (Agent tool path)

Use the same text as `verifyPrompt()` above, appending:
"Output ONLY a JSON object: {\"confirmed\": bool, \"reason\": str}."
Launch all verifiers for one round in a single message; use `subagent_type: "general-purpose"`.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall