qodo-get-rules

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Get Qodo Rules Skill

获取Qodo Rules Skill

Description

描述

Fetches repository-specific coding rules from the Qodo platform API before code generation or modification tasks. Rules include security requirements, coding standards, quality guidelines, and team conventions that must be applied during code generation. Use before any code generation or modification task when rules are not already loaded. Invoke when user asks to write, edit, refactor, or review code, or when starting implementation planning. Skip if "Qodo Rules Loaded" already appears in conversation context

在代码生成或修改任务前,从Qodo平台API获取仓库专属的编码规则。这些规则包括安全要求、编码标准、质量指南以及代码生成过程中必须遵循的团队约定。 使用时机:当规则尚未加载时,在任何代码生成或修改任务前使用。当用户要求编写、编辑、重构或审查代码,或是开始实施规划时调用。 跳过场景:如果对话上下文已出现“Qodo Rules Loaded”,则跳过此步骤。

Workflow

工作流程

Step 1: Check if Rules Already Loaded

步骤1:检查规则是否已加载

If rules are already loaded (look for "Qodo Rules Loaded" in recent messages), skip to step 6.
如果规则已加载(查看近期消息中是否有“Qodo Rules Loaded”),则跳至步骤6。

Step 2: Verify working in a git repository

步骤2:验证当前工作环境为git仓库

  • Check that the current directory is inside a git repository. If not, inform the user that a git repository is required and exit gracefully.
  • Extract the repository scope from the git
    origin
    remote URL. If no remote is found, exit silently. If the URL cannot be parsed, inform the user and exit gracefully.
  • Detect module-level scope: if inside a
    modules/*
    subdirectory, use it as the query scope; otherwise use repository-wide scope.
See repository scope detection for details.
  • 检查当前目录是否在git仓库内。如果不是,告知用户需要git仓库并正常退出。
  • 从git的
    origin
    远程URL中提取仓库范围。如果未找到远程仓库,静默退出。如果URL无法解析,告知用户并正常退出。
  • 检测模块级范围:如果当前目录在
    modules/*
    子目录下,则将其作为查询范围;否则使用仓库全局范围。
详情请查看仓库范围检测

Step 3: Verify Qodo Configuration

步骤3:验证Qodo配置

Check that the required Qodo configuration is present. The default location is
~/.qodo/config.json
.
  • API key: Read from
    ~/.qodo/config.json
    (
    API_KEY
    field). If not found, inform the user that an API key is required and provide setup instructions, then exit gracefully.
  • Environment name: Read from
    ~/.qodo/config.json
    (
    ENVIRONMENT_NAME
    field), with
    QODO_ENVIRONMENT_NAME
    environment variable taking precedence. If not found, inform the user that an API key is required and provide setup instructions, then exit gracefully.
  • Request ID: Generate a UUID (e.g. via
    uuidgen
    or
    python3 -c "import uuid; print(uuid.uuid4())"
    ) to use as
    request-id
    for all API calls in this invocation. This correlates all page fetches for a single rules load on the platform side.
检查是否存在所需的Qodo配置。默认位置为
~/.qodo/config.json
  • API密钥:从
    ~/.qodo/config.json
    API_KEY
    字段读取。如果未找到,告知用户需要API密钥并提供设置说明,然后正常退出。
  • 环境名称:从
    ~/.qodo/config.json
    ENVIRONMENT_NAME
    字段读取,
    QODO_ENVIRONMENT_NAME
    环境变量优先级更高。如果未找到,告知用户需要环境名称并提供设置说明,然后正常退出。
  • 请求ID:生成一个UUID(例如通过
    uuidgen
    python3 -c "import uuid; print(uuid.uuid4())"
    ),作为本次调用中所有API请求的
    request-id
    。这会在平台端关联单次规则加载的所有页面请求。

Step 4: Fetch Rules with Pagination

步骤4:分页获取规则

  • Fetch all pages from the API (50 rules per page) until no more results are returned.
  • On each page, handle HTTP errors and exit gracefully with a user-friendly message.
  • Accumulate all rules across pages into a single list.
  • Stop after 100 pages maximum (safety limit).
  • If no rules are found after all pages, inform the user and exit gracefully.
See pagination details for the full algorithm and error handling.
  • 从API获取所有页面(每页50条规则),直到没有更多结果返回。
  • 处理每个页面的HTTP错误,以用户友好的消息正常退出。
  • 将所有页面的规则累积到一个列表中。
  • 最多获取100页(安全限制)。
  • 如果所有页面都未找到规则,告知用户并正常退出。
完整算法和错误处理请查看分页详情

Step 5: Format and Output Rules

步骤5:格式化并输出规则

  • Print the "📋 Qodo Rules Loaded" header with repository scope, scope context, and total rule count.
  • Group rules by severity and print each non-empty group: ERROR, WARNING, RECOMMENDATION.
  • Each rule is formatted as:
    - **{name}** ({category}): {description}
  • End output with
    ---
    .
See output format details for the exact format.
  • 打印“📋 Qodo Rules Loaded”标题,包含仓库范围、范围上下文和规则总数。
  • 按严重程度分组,打印每个非空分组:ERROR、WARNING、RECOMMENDATION。
  • 每条规则格式为:
    - **{name}** ({category}): {description}
  • 输出以
    ---
    结尾。
确切格式请查看输出格式详情

Step 6: Apply Rules by Severity

步骤6:按严重程度应用规则

SeverityEnforcementWhen Skipped
ERRORMust comply, non-negotiable. Add comment documenting compliance (e.g.,
# Following Qodo rule: No Hardcoded Credentials
)
Explain to user and ask for guidance
WARNINGShould comply by defaultBriefly explain why in response
RECOMMENDATIONConsider when appropriateNo action needed
严重程度执行要求跳过时机
ERROR必须遵守,无协商空间。添加注释记录合规情况(例如
# Following Qodo rule: No Hardcoded Credentials
向用户说明情况并请求指导
WARNING默认应遵守在回复中简要说明原因
RECOMMENDATION酌情考虑无需操作

Step 7: Report

步骤7:报告

After code generation, inform the user about rule application:
  • ERROR rules applied: List which rules were followed
  • WARNING rules skipped: Explain why
  • No rules applicable: Inform: "No Qodo rules were applicable to this code change"
  • RECOMMENDATION rules: Mention only if they influenced a design decision

代码生成完成后,向用户告知规则应用情况:
  • 已应用的ERROR规则:列出遵循的规则
  • 已跳过的WARNING规则:说明原因
  • 无适用规则:告知用户:“本次代码变更无适用的Qodo规则”
  • RECOMMENDATION规则:仅当它们影响了设计决策时才提及

How Scope Levels Work

范围层级的工作方式

Determines scope from git remote and working directory (see Step 2):
Scope Hierarchy:
  • Universal (
    /
    ) - applies everywhere
  • Org Level (
    /org/
    ) - applies to organization
  • Repo Level (
    /org/repo/
    ) - applies to repository
  • Path Level (
    /org/repo/path/
    ) - applies to specific paths

根据git远程仓库和工作目录确定范围(详见步骤2):
范围层级
  • 全局 (
    /
    ) - 适用于所有场景
  • 组织级 (
    /org/
    ) - 适用于整个组织
  • 仓库级 (
    /org/repo/
    ) - 适用于当前仓库
  • 路径级 (
    /org/repo/path/
    ) - 适用于特定路径

Configuration

配置

See README.md for full configuration instructions, including API key setup and environment variable options.

完整配置说明请查看README.md,包括API密钥设置和环境变量选项。

Common Mistakes

常见错误

  • Re-running when rules are loaded - Check for "Qodo Rules Loaded" in context first
  • Missing compliance comments on ERROR rules - ERROR rules require a comment documenting compliance
  • Forgetting to report when no rules apply - Always inform the user when no rules were applicable, so they know the rules system is active
  • Not in git repo - Inform the user that a git repository is required and exit gracefully; do not attempt code generation
  • No API key - Inform the user with setup instructions; set
    QODO_API_KEY
    or create
    ~/.qodo/config.json
  • No rules found - Inform the user; set up rules at app.qodo.ai
  • 规则已加载时重复运行 - 先检查上下文中是否有“Qodo Rules Loaded”
  • ERROR规则缺少合规注释 - ERROR规则需要添加注释记录合规情况
  • 忘记在无适用规则时报告 - 务必告知用户无适用规则,让他们知晓规则系统处于活跃状态
  • 不在git仓库内 - 告知用户需要git仓库并正常退出;不要尝试代码生成
  • 缺少API密钥 - 告知用户并提供设置说明;设置
    QODO_API_KEY
    或创建
    ~/.qodo/config.json
  • 未找到规则 - 告知用户;请在app.qodo.ai设置规则