mcpField
A
ascendc-operator-code-review

ascendc-operator-code-review

github.com/ascendTesting & quality52166 installsUpdated 25w ago
Repository

About ascendc-operator-code-review

This Ascend C code-review skill is for reviewing code against specified coding rules and requires a code snippet and review criteria. It uses hypothesis testing and evidence scoring to identify risks, then produces a structured report with line numbers, evidence, and remediation suggestions.

Key features

  1. 01Validates code and review-rule inputs
  2. 02Finds and reads the relevant standards file
  3. 03Collects risk evidence through hypothesis testing
  4. 04Uses contextual defenses to filter false positives
  5. 05Generates reports with line numbers and fixes

Use cases

  1. 01Checking Ascend C code for memory or pointer risks
  2. 02Reviewing concurrency safety against coding rules
  3. 03Assessing operator interfaces or ABI compatibility

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/ascend/agent-skills --skill ascendc-operator-code-review

After installing, type/ascendc-operator-code-reviewin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
01_numeric_operations.md
02_memory_pointer_safety.md
03_resource_management.md
04_input_validation.md
05_concurrency_safety.md
06_operator_interface.md
07_interface_compatibility.md

Details

From the project README

Ascend C 代码检视技能

核心原则

  1. 合规优先 - 所有检视动作映射至编码规范具体条款,100%覆盖无遗漏
  2. 可审计可复用 - 检视动作全程日志记录
  3. 简洁高效 - 检视报告结构化,清晰明了

调用接口

必需参数

调用此技能时,必须明确提供以下参数:

参数1:代码片段

  • 待检视的代码内容
  • 可以是函数、代码块、文件内容等

参数2:检视规则描述

  • 明确指定要检视的问题类型
  • 例如:检查整数溢出、检查内存泄漏、检查空指针解引用等
  • 或指定具体的规范文件路径

参数3:规范文件路径(可选)

  • 指定具体的编码规范文件路径
  • 如果未指定,将根据检视规则描述查找对应的规范文件
参数校验

如果缺少任何一个必需参数,应:

  1. 明确通知用户缺少哪些参数
  2. 放弃执行检视
  3. 提示用户提供完整参数
规范文件引用

当用户指定检视规则描述时,按以下规则匹配规范文件:

  • 数值运算、溢出、除零 → references/01_numeric_operations.md
  • 内存、指针、越界 → references/02_memory_pointer_safety.md
  • 资源、泄漏 → references/03_resource_management.md
  • 输入、验证 → references/04_input_validation.md
  • 并发、线程 → references/05_concurrency_safety.md
  • 算子接口、Runtime、Tiling、动态Shape → references/06_operator_interface.md
  • 接口兼容性、ABI → references/07_interface_compatibility.md
  • 用户直接指定路径 → 使用指定路径

检视流程(假设检验驱动)

阶段一:准备
  1. 校验必需参数是否完整
  2. 根据检视规则描述或指定路径读取编码规范文件
  3. 确认待检视的代码片段
阶段二:假设检验(核心)

步骤1:代码段识别

将目标代码划分为独立的代码段(函数、语句块、逻辑单元)

步骤2:假设建立

对每个代码段建立假设:

  • 原假设 H0:该代码段是安全的
  • 备择假设 H1:该代码段存在风险
  • 自信值初始化:0%

步骤3:证据收集与评估

按维度系统性寻找证据:

证据类型分析动作分值规则
红线规范违反对照红线规范条款识别严重违规点有效证据 +40%
一般规范违反对照一般规范条款识别违规点有效证据 +20%
上下文防御缺失检查作用域内是否有防御代码无防御 +30%
函数调用链风险LSP/Grep 分析调用函数内部逻辑发现风险 +25%
数据流追踪风险分析变量来源、运算过程发现风险 +25%
  • 提供数值运算类型证据时,需提供明确的风险运算案例(如溢出,越界,回绕,等)

分析要求:

  • 使用LSP获取代码中的符号定义,使用Grep查找依赖关系
  • 风险代码必须要检查是否在当前文件作用域内的其他位置进行防御
  • 遇到函数调用,必须查看函数内部逻辑并综合判断
  • 遇到存在风险的结构体或成员变量,必须查看定义和运算过程

步骤4:证据有效性校验

排除误报:

  • 已在作用域其他位置进行有效防御 → 排除
  • 上下文可证明不可能触发风险 → 排除

步骤5:决策判断

计算自信值并决策:

  • 自信值 = Σ 有效证据分值
  • 决策规则:当自信值超过60%时,判定代码段存在风险,进入报告生成;否则继续检查下一代码段
阶段三:报告生成
  1. 按代码检视报告模板格式生成报告
  2. 每个问题详情前展示假设检验过程(证据链和自信值计算过程)

注意事项

  1. 请先完整阅读对应的编码规范文件,并根据这些规范进行代码review,其他的一概不统计
  2. 检视过程中,存疑代码块存在函数调用行为,必须动用LSP工具,或者搜索工具,实现深层次分析
  3. 不确定的编码规范问题,在输出报告中以存疑的形式进行列举,供用户自主判断
  4. 检视报告中列举的问题代码不宜过长,描述清晰问题代码即可
  5. 返回检视结果时,必须仔细检查结果中风险代码行的行数是否正确
  6. 返回检视结果时,所有风险代码块都应该被引用,不能只展示一个行数

输出规范

检视报告必需包含
  1. 检视类别
  2. 风险点列表(含行号、代码片段)
  3. 证据链(展示假设检验过程)
  4. 建议修复方案
输出格式

详见:agents/ascendc-ops-reviewer/style/code_review_summary_style.txt

Comments

Markdown supported