Communitygithub.com

bg-szy/TOP-SKILLS

扫描代码库中的安全漏洞,利用 CodeQL 的过程间数据流和污点追踪分析。支持“运行所有”和“仅重要”扫描模式,并可为项目特定源和汇创建数据扩展模型。

TOP-SKILLS 是什么?

此 AI 助手技能专门用于执行 CodeQL 安全分析,能够自动扫描代码库中的漏洞。它支持多种编程语言,包括 Python、JavaScript/TypeScript、Go、Java/Kotlin、C/C++、C#、Ruby 和 Swift。该技能的核心优势在于其全面的分析能力:它通过数据流和污点追踪分析来发现跨过程的安全问题,并提供两种扫描模式(完整扫描和仅高精度扫描)以满足不同需求。为了确保结果的准确性,技能内置了数据库质量检查、查询套件验证等机制,并强调数据扩展模型的重要性,以捕获项目特定的 API 封装导致的安全缺口。该技能支持在 Claude Code 等平台上使用,通过触发词如“run codeql”、“codeql scan”启动,并遵循严格的流程,包括数据库构建、数据扩展创建和结果分析,最终生成 SARIF 格式的发现报告。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/bg-szy/TOP-SKILLS/tree/HEAD/skills/skills/codeql

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

CodeQL 分析

支持的语言:Python、JavaScript/TypeScript、Go、Java/Kotlin、C/C++、C#、Ruby、Swift。

技能资源: 参考文件和工作模板位于 {baseDir}/references/ 和 {baseDir}/workflows/。

核心原则

  1. 数据库质量不可妥协。 一个能构建成功的数据库并不自动意味着质量良好——缓存的构建不提取任何内容,但报告构建成功。

  2. 数据扩展捕获 CodeQL 遗漏的问题。 Django、Spring 和 Express 项目仍然将数据库调用、请求解析和 shell 执行封装在项目特定的 API 中,任何自带的模型都无法覆盖这些。

  3. 显式套件引用可防止静默查询丢失。 切勿将包名直接传递给 codeql database analyze——每个包的 defaultSuiteFile 都会应用隐藏过滤器,可能产生零结果。始终生成一个 .qls 文件。

  4. 零发现需要调查,而非庆祝。 可能意味着提取不佳、缺少模型、使用了错误的包或套件过滤。构建后运行 {baseDir}/scripts/check_db_quality.py,确认 {baseDir}/scripts/verify_query_suite.py 对正在使用的套件退出代码为零——生成脚本会运行它,所以仅在重复使用或手动编辑套件时才需要手动调用——并在报告中说明两者均已通过。

  5. macOS Apple Silicon 需要针对编译型语言的变通方案。 退出代码 137 是 arm64e/arm64 不匹配,而非构建失败。在回退到 build-mode=none 之前,先尝试 Homebrew arm64 工具或 Rosetta。

  6. 严格按步骤执行工作流。 每个阶段都作为下一阶段的门控;跳过质量评估或数据扩展会在结果中留下不可见的差距。

每次 Bash 调用都是全新的 Shell

没有任何内容可以跨 Bash 调用传递:变量、数组或从 build_log.sh 中 sourced 的函数都不行。下面每个使用某个值的代码块都必须在同一个代码块内重新建立该值。工作流指向此处而非重复说明;它们声明的是该站点特定的损害,因为每个站点都以不同且静默的方式失败:

  • 丢失的函数会使 run_logged 退出代码为 127,构建阶梯将其解读为失败的方法,并降级至 --build-mode=none,从未调用过 CodeQL
  • 丢失的数组扩展为空,因此用户选择的每个 --threat-model 和 --model-packs 都会被丢弃,而最终报告仍会列出它们已使用
  • 在 set -u 下丢失的标量会以 unbound variable 中止代码块

输出目录

所有生成的文件(数据库、构建日志、诊断信息、扩展、结果)都存储在一个输出目录中。

  • 如果用户在提示中指定了输出目录,则将其用作 OUTPUT_DIR。
  • 如果未指定,则默认为 ./static_analysis_codeql_1。如果该目录已存在,则递增为 _2、_3,依此类推。

在这两种情况下,始终先创建目录(使用 mkdir -p),然后再写入任何文件。

在运行此操作之前,将 USER_SPECIFIED_DIR 设置为用户提示中的文字路径,或将其保留未设置以自动递增。没有其他内容会赋值给它。

# 解析输出目录
USER_SPECIFIED_DIR="${USER_SPECIFIED_DIR:-}"   # 如果存在,请在此处替换用户的路径
if [ -n "$USER_SPECIFIED_DIR" ]; then
  OUTPUT_DIR="$USER_SPECIFIED_DIR"
else
  BASE="static_analysis_codeql"
  N=1
  while [ -e "${BASE}_${N}" ]; do
    N=$((N + 1))
  done
  OUTPUT_DIR="${BASE}_${N}"
fi
mkdir -p "$OUTPUT_DIR"

输出目录在任何工作流执行之前解析一次。所有工作流都接收 $OUTPUT_DIR 并将其工件存储在那里:

$OUTPUT_DIR/
├── rulesets.txt                 # 选定的查询包(步骤 3 后记录)
├── codeql.db/                   # CodeQL 数据库(包含 codeql-database.yml 的目录)
├── build.log                    # 构建日志
├── codeql-config.yml            # 排除配置(解释型语言)
├── diagnostics/                 # 诊断查询和 CSV
├── extensions/                  # 数据扩展 YAML
├── raw/                         # 未过滤的分析输出
│   ├── results.sarif
│   └── run-all.qls | important-only.qls
└── results/                     # 最终结果(为重要模式过滤,为全模式复制)
    └── results.sarif

数据库发现

CodeQL 数据库通过其目录中是否存在 codeql-database.yml 标记文件来识别。搜索现有数据库时,始终收集所有匹配项——可能因之前的运行或不同语言而存在多个数据库。

发现命令。 find_databases.sh 每行列出一个数据库路径,过滤掉失败构建留下的标记文件。在选择该数组的同一个代码块内构建数组——每次 Bash 调用都是全新的 shell,所以在此构建的数组在下一次调用时为空,运行会认为没有数据库:

# 命令替换,而不是 `done < <(...)`:进程替换会丢弃脚本的退出状态,
# 因此“此 shell 的 PATH 上没有 codeql”(退出码 2)会作为一个空列表返回,
# 并导致即使磁盘上有三个完好的数据库,也会转而执行“构建新数据库”。
if ! DB_LIST=$("{baseDir}/scripts/find_databases.sh" "${OUTPUT_DIR:-.}" .); then
  echo "错误:数据库发现失败——请参阅上面的消息" >&2
  exit 1
fi

FOUND_DBS=()
while IFS= read -r db; do
  [ -n "$db" ] || continue
  FOUND_DBS+=("$db")
done <<<"$DB_LIST"

echo "找到 ${#FOUND_DBS[@]} 个现有数据库"

# 选择提示所需的元数据,在此处收集而非在其自己的块中:
# FOUND_DBS 在下一次 Bash 调用时消失,对一个不再存在的数组进行循环
# 不会打印任何内容并报告成功。
for db in "${FOUND_DBS[@]}"; do
  CODEQL_LANG=$(codeql resolve database --format=json -- "$db" 2>/dev/null | jq -r '.languages[0]')
  CREATED=$(grep '^creationMetadata:' -A5 "$db/codeql-database.yml" 2>/dev/null | grep 'creationTime' | awk '{print $2}')
  echo "$db — 语言: $CODEQL_LANG,创建时间: $CREATED"
done

切勿假定数据库名为 codeql.db——通过其标记文件来发现它。

当找到多个数据库时: 使用 AskUserQuestion 让用户根据上面打印的语言和创建时间选择使用哪个数据库,或构建一个新数据库。AskUserQuestion 最多接受四个选项,因此当数据库数量超过该限制时,提供最近三个加上“构建新数据库”,并在提示文本中列出其余选项。如果用户在提示中明确说明了使用哪个数据库或构建一个新数据库,则跳过 AskUserQuestion。

快速开始

对于常见情况(“扫描此代码库以查找漏洞”):

# 验证 CodeQL 是否已安装。如果未安装,在此处停止——后续每条命令都会失败,
# 并带有信息量较少的错误,并且运行会在说明原因之前浪费一个构建周期。
if ! command -v codeql >/dev/null 2>&1; then
  echo "错误:在 PATH 上未找到 codeql。请通过以下方式之一安装:" >&2
  echo "  gh extension install github/gh-codeql   # 然后:gh codeql install-stub" >&2
  echo "  brew install --cask codeql" >&2
  echo "  https://github.com/github/codeql-action/releases  (codeql-bundle)" >&2
  exit 1
fi

# jq 在下一步中解析 `codeql resolve database --format=json`。没有它,
# CODEQL_LANG 将返回空,运行将继续针对错误的语言。
if ! command -v jq >/dev/null 2>&1; then
  echo "错误:在 PATH 上未找到 jq(brew install jq / apt install jq)" >&2
  exit 1
fi

# uv 运行两个防护脚本和两个套件生成器。在此处而不是在套件生成时检查它,
# 套件生成是在构建之后——否则没有 uv 的机器会在失败之前花费整个构建时间。
if ! command -v uv >/dev/null 2>&1; then
  echo "错误:在 PATH 上未找到 uv(https://docs.astral.sh/uv/getting-started/)" >&2
  exit 1
fi

codeql --version

然后使用上面输出目录中的代码块解析 OUTPUT_DIR——它会尊重用户指定的目录,而简单的自动递增则不会。

然后执行完整的管道:构建数据库 → 创建数据扩展 → 运行分析,使用下面的工作流。

应拒绝的合理化解释

这些捷径会导致遗漏发现。不要接受它们:

  • “security-extended 就够了” - 这是基线。始终检查 Trail of Bits 包和社区包是否可用于该语言。它们捕获 security-extended 完全遗漏的类别。
  • “security-and-quality 是最广泛的套件” - security-and-quality 排除了所有 experimental/ 查询路径。对于全模式,同时导入 security-and-quality 和 security-experimental。根据语言不同,差异有 1-52 个查询。
  • “数据库构建成功了,所以没问题” - 数据库能构建不代表提取得好。始终运行质量评估并检查文件计数是否与预期的源文件相符。
  • “标准框架不需要数据扩展” - 即使是 Django/Spring 应用也存在 CodeQL 无法建模的自定义包装器。跳过扩展意味着遗漏漏洞。
  • “对于编译型语言,build-mode=none 就可以了” - 它会产生严重不完整的分析。仅作为绝对最后的手段使用。在 macOS 上,先尝试 arm64 工具链变通方案或 Rosetta。
  • “构建在 macOS 上失败,就直接用 build-mode=none” - 退出代码 137 由 arm64e/arm64 不匹配引起,而非根本性构建失败。请参阅 references/macos-arm64e-workaround.md。
  • “没有发现结果意味着代码是安全的” - 运行 check_db_quality.py 和 verify_query_suite.py 并报告它们已通过。没有它们,零发现与一个未提取任何内容的数据库在输出上是相同的。
  • “我就运行默认套件” / “我直接传递包名” - 每个包的 defaultSuiteFile 都会应用隐藏过滤器并可能产生零结果。始终使用显式套件引用。
  • “我把文件放在当前目录” - 所有生成的文件必须放在 $OUTPUT_DIR 中。将文件散落在工作目录中会使清理变得不可能,并存在覆盖之前运行结果的风险。
  • “直接使用我找到的第一个数据库” - 可能存在针对不同语言或来自先前运行的多个数据库。当找到多个时,向用户展示所有选项。仅在用户已经明确指定要使用哪个数据库时才跳过此提示。
  • “用户说了‘扫描’,意味着他们希望我选择一个数据库” - “扫描”不是数据库选择。如果存在多个数据库且用户未指定,请询问。

工作流选择

此技能包含三个工作流。一旦选择了某个工作流,请逐步执行,不要跳过任何阶段。

这些运行时间较长。数据库构建有四种回退方法,因此使用任务工具来跟踪进度。根据运行情况决定哪些步骤值得跟踪。

工作流目的
build-database按顺序使用构建方法创建 CodeQL 数据库
create-data-extensions检测或生成为项目 API 的数据扩展模型
run-analysis选择规则集,执行查询,处理结果

无人值守构建

此插件提供 /static-analysis:codeql-build,它可以端到端执行构建数据库步骤:检测语言和工具链,逐级使用方法阶梯,并在梯级之间应用 build-fixes.md 中的修复,并强制执行质量关卡。

/static-analysis:codeql-build {"target": "/abs/path", "lang": "cpp"}

它不会提出任何问题。每种方法均失败,以及数据库已构建但低于质量阈值,都会以状态返回——no-method-succeeded 和 built-below-threshold——供您在此处处理,因为剩余提取器错误是否仅限于无需分析的代码是一个运行无法做出的判断。

当构建是漫长且不确定的部分,并且您希望将其推向结论时使用它。当您希望对尝试哪种方法有发言权,或者当构建失败需要即时解释时,请手动执行 build-database.md。

自动检测逻辑

如果用户明确指定了要做什么(例如,“构建一个数据库”、“对 ./my-db 运行分析”),则直接执行该工作流。如果用户的提示已经清楚表达了他们的意图,则不要调用 AskUserQuestion 进行数据库选择——例如,“构建一个新数据库”、“分析 static_analysis_codeql_2 中的 codeql 数据库”、“从头开始运行完整扫描”。

对于“测试”、“扫描”、“分析”等类似指令的默认管道: 使用上面数据库发现中的命令发现现有数据库,然后做出决定。

条件操作
未找到数据库解析新的 $OUTPUT_DIR,执行构建 → 扩展 → 分析(完整管道)
找到一个数据库使用 AskUserQuestion:重用它还是构建新的?
找到多个数据库使用 AskUserQuestion,上限为四个选项——请参阅数据库发现
用户明确说明了意图跳过 AskUserQuestion,直接按其指示操作

数据库选择提示

当找到现有数据库并且用户未明确指定使用哪一个时,通过 AskUserQuestion 以“现有 CodeQL 数据库”为标题呈现它们。标记每个选项,附带上文收集的路径、语言和创建时间——./static_analysis_codeql_1/codeql.db (language: python, created: 2026-02-24)——并将最后一个选项设为“构建新数据库”。

选择后:

  • 如果用户选择了现有数据库: 将 $OUTPUT_DIR 设置为其父目录(或包含该数据库的目录),将 $DB_NAME 设置为所选路径,然后继续执行扩展 → 分析。
  • 如果用户选择了“构建新”: 解析一个新的 $OUTPUT_DIR,执行构建 → 扩展 → 分析。

通用决策提示

如果提示中数据库和工作流都不明确,则通过 `AskUserQue

…[为翻译截断]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

bg-szy/TOP-SKILLS

Brand-first landing page designer — runs a brand-identity interview (colors, typography, shape language), then generates and iterates on a polished landing page via Stitch with deployment-ready HTML. Use when the user asks to create, design, or build a landing page, homepage, or marketing page and has no established visual direction. Skip when they have a design mockup, need a dashboard or app UI, are working at component level, building a multi-page app, or restyling with known design tokens — use frontend-design instead.

bg-szy/TOP-SKILLS

Fill out Microsoft Azure Landing Zone (ALZ) Accelerator checklists by interviewing the user, mapping their Azure subscriptions, integrating IP addressing documentation, and applying Microsoft Cloud Adoption Framework best practices. Produces a completed Excel checklist (.xlsx) ready for ALZ deployment. Use this skill whenever the user mentions Azure Landing Zone, ALZ checklist, landing zone accelerator, platform landing zone configuration, ALZ bootstrap, hub-and-spoke setup, Azure network topology planning, or wants to fill out any ALZ-related checklist or configuration file. Also trigger when the user uploads an Excel file that contains tabs like "Accelerator - Bootstrap", "Accelerator - Bicep", or "Accelerator - Terraform".

bg-szy/TOP-SKILLS

Compose a premium, animated landing page section by section in Next.js + Tailwind + Motion (Framer Motion) — built on a real design system, with editorial copy and motion that feels human-crafted, not template-generated. Use when building or rebuilding a landing page, marketing site, or hero/feature/pricing/CTA sections that need to look production-ready and bespoke from day one.

bg-szy/TOP-SKILLS

Write high-converting landing page copy using proven frameworks like PAS (Problem-Agitate-Solution), AIDA, and StoryBrand. Creates headlines, value propositions, CTAs, and full page sections optimized for conversion. Use when users need landing page copy, sales page content, or marketing website text.

bg-szy/TOP-SKILLS

Optimize landing pages for conversions, performance, and SEO. Use when improving landing pages, increasing conversions, or optimizing page performance.

bg-szy/TOP-SKILLS

Review investment portfolios for risk, diversification, fees. Asset allocation recommendations, tax-loss harvesting, rebalancing.

bg-szy/TOP-SKILLS

Beads Viewer - Graph-aware triage engine for Beads projects. Computes PageRank, betweenness, critical path, and cycles. Use --robot-* flags for AI agents.

bg-szy/TOP-SKILLS

CI red? Call us. Pipeline fire brigade deploys. Use when user mentions CI failures, build errors, test failures, or pipeline issues. Do NOT load for: local builds, standard implementation work, reviews, or setup.

bg-szy/TOP-SKILLS

CASS Memory System - procedural memory for AI coding agents. Three-layer cognitive architecture with confidence decay, anti-pattern learning, cross-agent knowledge transfer, trauma guard safety system. Bun/TypeScript CLI.

bg-szy/TOP-SKILLS

Mandatory entry point: read this first for any request to make, create, edit, animate, or render a video, animation, or motion graphic, including a promo, explainer, captioned clip, title card, overlay, slideshow or interactive deck, Remotion port, or any HyperFrames HTML composition. Also use it to inspect, diagnose, validate, preview, publish, or batch-render an existing HyperFrames project. Inputs may be a website URL, GitHub PR, Figma design or URL, text or brief, existing footage, or music. It resumes project state, captures intent when applicable, selects and installs the owning workflow, and routes domain capabilities. HyperFrames is the default output framework unless the user explicitly chooses another framework for the deliverable or asks only to record a browser session.

bg-szy/TOP-SKILLS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

bg-szy/TOP-SKILLS

Use when the user asks to "pre-launch check the landing page", "run a Quality-Score preflight", or "verify ad-to-page message match before launch"; produces an ad↔page continuity report — message-match gaps, above-the-fold check, page-speed read, form-friction count, mobile-render flags — as a pass/fix punch list. Not for redesigning or rewriting the page — use landing-optimizer; not for scoring the account or the RQS — use ad-account-auditor. 落地页体验预检/广告落地页一致性检查

bg-szy/TOP-SKILLS

Use when the user asks to "optimize our landing page for influencer traffic", "fix our promo-code landing page", or "improve conversion from a creator campaign"; produces a message-match audit, page-structure and social-proof recommendations, a promo-code/CTA conversion plan, and an A/B test roadmap. Not for measuring campaign results after launch — use performance-analyzer.

bg-szy/TOP-SKILLS

Audit a landing page, sales page or checkout page for conversion leaks and return a fix list ordered by expected revenue impact. Use when asked to review, critique or improve a landing page, sales page, opt-in page, product page or checkout flow, when conversion rate is low, when paid traffic is not converting, or when someone asks "why isn't this page converting" or wants a CRO / landing page review.

bg-szy/TOP-SKILLS

Landing page conversion optimization with layout rules, hero section design, and CTA psychology. Covers above-the-fold formula, social proof placement, mobile design, and F-pattern reading. Use for: startup landing pages, product pages, SaaS marketing, conversion optimization. Triggers: landing page, hero section, above the fold, conversion optimization, landing page design, cta button, hero image, landing page layout, saas landing page, product page design, conversion rate, landing page best practices

bg-szy/TOP-SKILLS

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

bg-szy/TOP-SKILLS

Landing page conversion optimization with layout rules, hero section design, and CTA psychology. Covers above-the-fold formula, social proof placement, mobile design, and F-pattern reading. Use for: startup landing pages, product pages, SaaS marketing, conversion optimization. Triggers: landing page, hero section, above the fold, conversion optimization, landing page design, cta button, hero image, landing page layout, saas landing page, product page design, conversion rate, landing page best practices

bg-szy/TOP-SKILLS

Account assets, equity and fund positions, P&L, cash flow records, account statements, margin ratios, buy-power estimates, order management, and DCA recurring investments via Longbridge (most require Trade permission). Frameworks: portfolio diagnosis, rebalancing, asset allocation, risk analysis (VaR/CVaR), performance attribution, and tax-loss harvesting. Triggers: "持仓", "账户", "盈亏", "资产", "对账单", "下单", "买入", "卖出", "撤单", "定投", "组合诊断", "再平衡", "资产配置", "风险分析", "绩效归因", "税损收割", "持倉", "賬戶", "盈虧", "對賬單", "下單", "買入", "賣出", "組合診斷", "再平衡", "稅損收割", "positions", "portfolio", "P&L", "order", "buy", "sell", "DCA", "statement", "risk analysis", "rebalancing", "tax harvesting", "我的风险", "持仓风险", "风险敞口", "資產", "資產配置", "風險分析", "績效歸因", "撤單

bg-szy/TOP-SKILLS

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

bg-szy/TOP-SKILLS

Process video files with audio extraction, format conversion (mp4, webm), and Whisper transcription. Use when user mentions video conversion, audio extraction, transcription, mp4, webm, ffmpeg, or whisper transcription.

相关技能