candid-loop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Candid Loop

Candid 循环

Run
candid-review
repeatedly until your code is clean. This skill automates the fix-review-fix cycle, applying fixes and re-running reviews until no issues remain (or max iterations is reached).
重复运行
candid-review
,直至你的代码无问题。该Skill可自动化修复-审核-修复的循环流程,应用修复并重新运行审核,直至无问题残留(或达到最大迭代次数)。

Workflow

工作流程

Execute these steps in order:
按以下顺序执行步骤:

Step 1: Load Configuration

步骤1:加载配置

Load loop configuration from CLI flags and config files.
Precedence (highest to lowest):
  1. CLI flags
  2. Project config (
    .candid/config.json
    loop
    field)
  3. User config (
    ~/.candid/config.json
    loop
    field)
  4. Defaults
从CLI参数和配置文件中加载循环配置。
优先级(从高到低):
  1. CLI参数
  2. 项目配置(
    .candid/config.json
    loop
    字段)
  3. 用户配置(
    ~/.candid/config.json
    loop
    字段)
  4. 默认值

Check CLI Arguments

检查CLI参数

Parse CLI arguments for loop options:
FlagDescriptionDefault
--mode <auto|review-each|interactive>
Execution mode
auto
--max-iterations <N>
Maximum loop iterations
5
--categories <list>
Categories to enforce (comma-separated)
all
Valid modes:
  • auto
    - Automatically apply all fixes
  • review-each
    - Go through each fix one by one (Yes/No for each)
  • interactive
    - Full control with skip, ignore, and batch options
Valid categories:
critical
,
major
,
standards
,
smell
,
edge_case
,
architectural
,
all
If CLI flags are provided, use them and skip config file checks for those specific options.
解析CLI参数中的循环选项:
参数描述默认值
--mode <auto|review-each|interactive>
执行模式
auto
--max-iterations <N>
最大循环迭代次数
5
--categories <list>
要强制执行的分类(逗号分隔)
all
有效模式:
  • auto
    - 自动应用所有修复
  • review-each
    - 逐个查看每个修复(对每个修复选择是/否)
  • interactive
    - 完全控制,支持跳过、忽略和批量处理选项
有效分类:
critical
,
major
,
standards
,
smell
,
edge_case
,
architectural
,
all
如果提供了CLI参数,则使用这些参数,并跳过对应选项的配置文件检查。

Check Project Config

检查项目配置

Read
.candid/config.json
and extract the
loop
field:
bash
jq -r '.loop // null' .candid/config.json 2>/dev/null
If the
loop
field exists:
  • Extract
    mode
    if not set by CLI
  • Extract
    maxIterations
    if not set by CLI
  • Extract
    enforceCategories
    if not set by CLI
  • Extract
    ignored
    object (categories, patterns, ids)
Output when loading from config:
Using loop settings from project config
读取
.candid/config.json
并提取
loop
字段:
bash
jq -r '.loop // null' .candid/config.json 2>/dev/null
如果
loop
字段存在:
  • 若CLI未设置
    mode
    则提取该值
  • 若CLI未设置
    maxIterations
    则提取该值
  • 若CLI未设置
    enforceCategories
    则提取该值
  • 提取
    ignored
    对象(分类、模式、ID)
加载配置时输出:
Using loop settings from project config

Check User Config

检查用户配置

Same procedure for
~/.candid/config.json
if project config doesn't have
loop
field.
Output when loading from user config:
Using loop settings from user config
如果项目配置中没有
loop
字段,对
~/.candid/config.json
执行相同操作。
加载配置时输出:
Using loop settings from user config

Apply Defaults

应用默认值

For any options not set by CLI or config:
mode = "auto"
maxIterations = 5
enforceCategories = ["all"]
ignored = { categories: [], patterns: [], ids: [] }
对于任何未通过CLI或配置设置的选项:
mode = "auto"
maxIterations = 5
enforceCategories = ["all"]
ignored = { categories: [], patterns: [], ids: [] }

Step 2: Initialize Loop State

步骤2:初始化循环状态

Set up tracking variables:
iteration = 0
totalFixesApplied = 0
allFixedIssues = []
Display mode banner:
Auto mode:
[Auto Mode] Running candid-loop with max [N] iterations...
Review-each mode:
[Review-Each Mode] Running candid-loop with max [N] iterations...
You will review each fix one by one.
Interactive mode:
[Interactive Mode] Running candid-loop with max [N] iterations...
Full control: skip, ignore, or batch process fixes.
设置跟踪变量:
iteration = 0
totalFixesApplied = 0
allFixedIssues = []
显示模式横幅:
自动模式:
[自动模式] 运行candid-loop,最大迭代次数为[N]...
逐个审核模式:
[逐个审核模式] 运行candid-loop,最大迭代次数为[N]...
你将逐个审核每个修复。
交互模式:
[交互模式] 运行candid-loop,最大迭代次数为[N]...
完全控制:跳过、忽略或批量处理修复。

Step 3: Run Review Loop

步骤3:运行审核循环

Execute the main loop:
WHILE iteration < maxIterations:
    iteration++

    Execute Step 3.1 through Step 3.6

    IF exitLoop == true:
        BREAK

IF iteration >= maxIterations AND remainingIssues > 0:
    Output warning: "Max iterations ([N]) reached. [M] issues remain."
    List remaining issues
执行主循环:
WHILE iteration < maxIterations:
    iteration++

    执行步骤3.1至步骤3.6

    IF exitLoop == true:
        BREAK

IF iteration >= maxIterations AND remainingIssues > 0:
    输出警告:"已达到最大迭代次数([N])。剩余[M]个问题。"
    列出剩余问题

Step 3.1: Run candid-review

步骤3.1:运行candid-review

Display iteration header:
[Iteration [N]/[MAX]]
Running candid-review...
Invoke the candid-review skill to analyze current code:
  • Use the Skill tool to run
    /candid-review
  • Pass through tone settings if configured
  • Wait for review to complete and save state to
    .candid/last-review.json
Note: candid-review will present its own fix selection prompt. In auto mode, we need to handle this by selecting "Apply all fixes". In interactive mode, we defer to the user's choices within candid-review.
显示迭代标题:
[迭代次数 [N]/[MAX]]
正在运行candid-review...
调用candid-review Skill分析当前代码:
  • 使用Skill工具运行
    /candid-review
  • 如果配置了语气设置则传递该设置
  • 等待审核完成并将状态保存到
    .candid/last-review.json
注意: candid-review会显示自己的修复选择提示。在自动模式下,我们需要通过选择"应用所有修复"来处理该提示。在交互模式下,我们将决定权交给candid-review中的用户选择。

Step 3.2: Read Review Results

步骤3.2:读取审核结果

After candid-review completes, read the saved review state:
bash
cat .candid/last-review.json 2>/dev/null
Parse the JSON to extract:
  • issues
    array with all found issues
  • Each issue has:
    id
    ,
    file
    ,
    line
    ,
    category
    ,
    title
    ,
    description
If file doesn't exist or is empty:
No review state found. candid-review may not have completed.
Exit with error.
candid-review完成后,读取保存的审核状态:
bash
cat .candid/last-review.json 2>/dev/null
解析JSON以提取:
  • issues
    数组,包含所有发现的问题
  • 每个问题包含:
    id
    ,
    file
    ,
    line
    ,
    category
    ,
    title
    ,
    description
如果文件不存在或为空:
未找到审核状态。candid-review可能未完成。
退出并显示错误。

Step 3.3: Filter Issues by Category

步骤3.3:按分类筛选问题

If
enforceCategories
is NOT
["all"]
:
Filter the issues array to only include issues matching enforceCategories:
filteredIssues = issues.filter(issue =>
    enforceCategories.includes(issue.category)
)
Category mapping:
  • critical
    → issues with category "critical"
  • major
    → issues with category "major"
  • standards
    → issues with category "standards"
  • smell
    → issues with category "smell"
  • edge_case
    → issues with category "edge_case"
  • architectural
    → issues with category "architectural"
Output:
Enforcing categories: [list]. Filtered to [N] issues.
如果
enforceCategories
不是
["all"]
过滤issues数组,仅保留与enforceCategories匹配的问题:
filteredIssues = issues.filter(issue =>
    enforceCategories.includes(issue.category)
)
分类映射:
  • critical
    → 分类为"critical"的问题
  • major
    → 分类为"major"的问题
  • standards
    → 分类为"standards"的问题
  • smell
    → 分类为"smell"的问题
  • edge_case
    → 分类为"edge_case"的问题
  • architectural
    → 分类为"architectural"的问题
输出:
强制执行分类:[列表]。已筛选至[N]个问题。

Step 3.4: Filter Out Ignored Issues

步骤3.4:过滤掉忽略的问题

Apply the ignored filters from config:
1. Filter by ignored categories:
filteredIssues = filteredIssues.filter(issue =>
    !ignored.categories.includes(issue.category)
)
2. Filter by ignored patterns (regex match on title):
filteredIssues = filteredIssues.filter(issue =>
    !ignored.patterns.some(pattern =>
        new RegExp(pattern, 'i').test(issue.title)
    )
)
3. Filter by ignored IDs:
filteredIssues = filteredIssues.filter(issue =>
    !ignored.ids.includes(issue.id)
)
If any issues were filtered:
Filtered out [N] ignored issues ([M] remaining)
应用配置中的忽略筛选规则:
1. 按忽略的分类筛选:
filteredIssues = filteredIssues.filter(issue =>
    !ignored.categories.includes(issue.category)
)
2. 按忽略的模式筛选(匹配标题的正则表达式):
filteredIssues = filteredIssues.filter(issue =>
    !ignored.patterns.some(pattern =>
        new RegExp(pattern, 'i').test(issue.title)
    )
)
3. 按忽略的ID筛选:
filteredIssues = filteredIssues.filter(issue =>
    !ignored.ids.includes(issue.id)
)
如果有任何问题被过滤:
已过滤掉[N]个被忽略的问题(剩余[M]个)

Step 3.5: Check for Completion

步骤3.5:检查是否完成

If
filteredIssues.length === 0
:
[Iteration [N]/[MAX]] No issues found!

exitLoop = true
Skip to Step 4 (Summary).
如果
filteredIssues.length === 0
[迭代次数 [N]/[MAX]] 未发现问题!

exitLoop = true
跳至步骤4(总结)。

Step 3.6: Handle Issues Based on Mode

步骤3.6:根据模式处理问题

If mode == "auto":
Display found issues:
[N/MAX] Found [M] issues. Applying fixes...
The candid-review skill will have already applied fixes if the user selected "Apply all fixes" in its prompt. Since we're in auto mode, we should have configured candid-review to auto-apply.
For each issue that was fixed, log:
      ✓ [icon] Fixed: [title] in [file]:[line]
Track fixes:
totalFixesApplied += appliedCount
allFixedIssues.push(...appliedIssues)
Continue to next iteration.
If mode == "review-each":
Go through each fix one by one with simple Yes/No prompts.
Display found issues:
[N/MAX] Found [M] issues. Reviewing each...
For each issue, use AskUserQuestion:
[1/M] [icon] [title]
File: [file]:[line]
Problem: [description]
Question: "Apply this fix?"
Options:
  1. "Yes, apply this fix"
  2. "No, skip this fix"
Track user choices:
  • If "Yes" → Apply the fix, increment totalFixesApplied
  • If "No" → Continue to next issue
After processing all issues, if any fixes were applied, continue to next iteration.
If mode == "interactive":
Full control mode with additional options for skipping, ignoring, and batch processing.
Display found issues:
Found [M] issues:
For each issue, use AskUserQuestion:
[1/M] [icon] [title]
File: [file]:[line]
Problem: [description]
Question: "How would you like to handle this issue?"
Options:
  1. "Apply fix" - Apply this fix and continue
  2. "Skip" - Skip this issue and continue to next
  3. "Add to ignore list" - Add this issue ID to ignored.ids and skip
  4. "Skip all remaining" - Exit the loop with remaining issues listed
Track user choices:
  • If "Apply fix" → Apply the fix, increment totalFixesApplied
  • If "Skip" → Continue to next issue
  • If "Add to ignore list" → Add issue.id to ignored.ids in config, continue
  • If "Skip all remaining" → Set exitLoop = true, break inner loop
After processing all issues in interactive mode, if any fixes were applied, continue to next iteration.
如果模式为"auto":
显示发现的问题:
[N/MAX] 发现[M]个问题。正在应用修复...
如果用户在candid-review的提示中选择了"应用所有修复",则该Skill已应用修复。由于我们处于自动模式,应已配置candid-review自动应用修复。
对于每个已修复的问题,记录:
      ✓ [图标] 已修复:[标题] in [file]:[line]
跟踪修复情况:
totalFixesApplied += appliedCount
allFixedIssues.push(...appliedIssues)
继续下一次迭代。
如果模式为"review-each":
通过简单的是/否提示逐个处理每个修复。
显示发现的问题:
[N/MAX] 发现[M]个问题。正在逐个审核...
对于每个问题,使用AskUserQuestion:
[1/M] [图标] [标题]
文件:[file]:[line]
问题:[description]
问题: "是否应用此修复?"
选项:
  1. "是,应用此修复"
  2. "否,跳过此修复"
跟踪用户选择:
  • 如果选择"是" → 应用修复,增加totalFixesApplied
  • 如果选择"否" → 继续处理下一个问题
处理完所有问题后,如果应用了任何修复,继续下一次迭代。
如果模式为"interactive":
完全控制模式,支持跳过、忽略和批量处理的额外选项。
显示发现的问题:
发现[M]个问题:
对于每个问题,使用AskUserQuestion:
[1/M] [图标] [标题]
文件:[file]:[line]
问题:[description]
问题: "你想如何处理此问题?"
选项:
  1. "应用修复" - 应用此修复并继续
  2. "跳过" - 跳过此问题并继续下一个
  3. "添加到忽略列表" - 将此问题ID添加到ignored.ids并跳过
  4. "跳过所有剩余问题" - 退出循环并列出剩余问题
跟踪用户选择:
  • 如果选择"应用修复" → 应用修复,增加totalFixesApplied
  • 如果选择"跳过" → 继续处理下一个问题
  • 如果选择"添加到忽略列表" → 将issue.id添加到配置中的ignored.ids,继续
  • 如果选择"跳过所有剩余问题" → 设置exitLoop = true,中断内层循环
在交互模式下处理完所有问题后,如果应用了任何修复,继续下一次迭代。

Step 3.7: Update Ignore List (If Requested)

步骤3.7:更新忽略列表(如果有请求)

If user chose "Add to ignore list" for any issues:
  1. Read current
    .candid/config.json
    (or create if doesn't exist)
  2. Add issue IDs to
    loop.ignored.ids
    array
  3. Write updated config back to file
bash
undefined
如果用户选择将任何问题"添加到忽略列表":
  1. 读取当前的
    .candid/config.json
    (如果不存在则创建)
  2. 将问题ID添加到
    loop.ignored.ids
    数组
  3. 将更新后的配置写回文件
bash
undefined

Read, modify, write

读取、修改、写入

jq '.loop.ignored.ids += ["issue-id-1", "issue-id-2"]' .candid/config.json > tmp.json mv tmp.json .candid/config.json

Output: `Added [N] issues to ignore list in .candid/config.json`
jq '.loop.ignored.ids += ["issue-id-1", "issue-id-2"]' .candid/config.json > tmp.json mv tmp.json .candid/config.json

输出:`已将[N]个问题添加到.candid/config.json的忽略列表中`

Step 4: Display Summary

步骤4:显示总结

After loop exits (success or max iterations), display final summary:
Success (no issues remaining):
Candid Loop Complete

Summary:
- Iterations: [N]
- Issues fixed: [M]
- Status: PASS

Your code is clean!
Max iterations reached:
Candid Loop Stopped

Summary:
- Iterations: [N] (max reached)
- Issues fixed: [M]
- Issues remaining: [P]
- Status: INCOMPLETE

Remaining issues:
  [icon] [title] in [file]:[line]
  [icon] [title] in [file]:[line]
  ...

Consider:
- Increasing --max-iterations
- Adding persistent ignores for false positives
- Manually reviewing complex issues
User cancelled (interactive mode):
Candid Loop Cancelled

Summary:
- Iterations: [N]
- Issues fixed: [M]
- Issues skipped: [P]
- Status: CANCELLED

Skipped issues:
  [icon] [title] in [file]:[line]
  ...
循环退出后(成功或达到最大迭代次数),显示最终总结:
成功(无剩余问题):
Candid 循环完成

总结:
- 迭代次数:[N]
- 已修复问题数:[M]
- 状态:通过

你的代码已无问题!
达到最大迭代次数:
Candid 循环已停止

总结:
- 迭代次数:[N](已达最大值)
- 已修复问题数:[M]
- 剩余问题数:[P]
- 状态:未完成

剩余问题:
  [图标] [标题] in [file]:[line]
  [图标] [标题] in [file]:[line]
  ...

建议:
- 增加--max-iterations的值
- 为误报添加持久忽略规则
- 手动审核复杂问题
用户取消(交互模式):
Candid 循环已取消

总结:
- 迭代次数:[N]
- 已修复问题数:[M]
- 已跳过问题数:[P]
- 状态:已取消

已跳过的问题:
  [图标] [标题] in [file]:[line]
  ...

Configuration

配置

Config File Schema

配置文件 Schema

Add to
.candid/config.json
:
json
{
  "version": 1,
  "tone": "harsh",
  "loop": {
    "mode": "auto",
    "maxIterations": 5,
    "enforceCategories": ["all"],
    "ignored": {
      "categories": [],
      "patterns": [],
      "ids": []
    }
  }
}
添加至
.candid/config.json
json
{
  "version": 1,
  "tone": "harsh",
  "loop": {
    "mode": "auto",
    "maxIterations": 5,
    "enforceCategories": ["all"],
    "ignored": {
      "categories": [],
      "patterns": [],
      "ids": []
    }
  }
}

Field Descriptions

字段说明

FieldTypeDefaultDescription
loop.mode
string
"auto"
"auto"
,
"review-each"
, or
"interactive"
loop.maxIterations
number
5
Maximum review-fix cycles
loop.enforceCategories
array
["all"]
Categories to enforce
loop.ignored.categories
array
[]
Categories to skip entirely
loop.ignored.patterns
array
[]
Regex patterns to match issue titles
loop.ignored.ids
array
[]
Specific issue IDs to skip
字段类型默认值描述
loop.mode
字符串
"auto"
可选值:
"auto"
,
"review-each"
, 或
"interactive"
loop.maxIterations
数字
5
最大审核-修复循环次数
loop.enforceCategories
数组
["all"]
要强制执行的分类
loop.ignored.categories
数组
[]
完全跳过的分类
loop.ignored.patterns
数组
[]
匹配问题标题的正则表达式模式
loop.ignored.ids
数组
[]
要跳过的特定问题ID

Examples

示例

Ignore all edge cases and architectural issues:
json
{
  "loop": {
    "ignored": {
      "categories": ["edge_case", "architectural"]
    }
  }
}
Ignore issues mentioning Unicode or timezone:
json
{
  "loop": {
    "ignored": {
      "patterns": ["Unicode", "timezone", "DST"]
    }
  }
}
Only enforce critical and major issues:
json
{
  "loop": {
    "enforceCategories": ["critical", "major"]
  }
}
忽略所有边缘情况和架构问题:
json
{
  "loop": {
    "ignored": {
      "categories": ["edge_case", "architectural"]
    }
  }
}
忽略提及Unicode或时区的问题:
json
{
  "loop": {
    "ignored": {
      "patterns": ["Unicode", "timezone", "DST"]
    }
  }
}
仅强制执行严重和主要问题:
json
{
  "loop": {
    "enforceCategories": ["critical", "major"]
  }
}

CLI Examples

CLI 示例

bash
undefined
bash
undefined

Run with defaults (auto mode, all categories, max 5 iterations)

使用默认值运行(自动模式,所有分类,最大5次迭代)

/candid-loop
/candid-loop

Review-each mode - go through each fix one by one (Yes/No)

逐个审核模式 - 逐个查看每个修复(是/否)

/candid-loop --mode review-each
/candid-loop --mode review-each

Interactive mode - full control with skip, ignore, batch options

交互模式 - 完全控制,支持跳过、忽略和批量处理选项

/candid-loop --mode interactive
/candid-loop --mode interactive

Limit iterations

限制迭代次数

/candid-loop --max-iterations 3
/candid-loop --max-iterations 3

Only fix critical issues

仅修复严重问题

/candid-loop --categories critical
/candid-loop --categories critical

Fix critical and major issues

修复严重和主要问题

/candid-loop --categories critical,major
/candid-loop --categories critical,major

Combine options

组合选项

/candid-loop --mode review-each --max-iterations 10 --categories critical,major
undefined
/candid-loop --mode review-each --max-iterations 10 --categories critical,major
undefined

Issue Categories Reference

问题分类参考

CategoryIconDescription
critical
🔥Production killers: crashes, security holes, data loss
major
⚠️Serious problems: performance, missing error handling
standards
📜Technical.md violations
smell
📋Maintainability: complexity, duplication
edge_case
🤔Unhandled scenarios: null, empty, concurrent
architectural
💭Design concerns: coupling, SRP violations
分类图标描述
critical
🔥生产环境致命问题:崩溃、安全漏洞、数据丢失
major
⚠️严重问题:性能、缺少错误处理
standards
📜违反Technical.md规范
smell
📋可维护性问题:复杂度、重复代码
edge_case
🤔未处理的场景:空值、空输入、并发
architectural
💭设计问题:耦合、违反单一职责原则

Remember

注意事项

The goal of candid-loop is to automate the review-fix cycle so you can quickly get your code to a clean state.
Mode selection:
  • auto - Fast iteration, applies all fixes automatically
  • review-each - Go through each fix one by one with simple Yes/No
  • interactive - Full control with skip, ignore list, and batch options
Best practices:
  • Start with auto mode for quick cleanup
  • Use review-each mode to understand what's being fixed
  • Use interactive mode when you need to ignore or skip specific issues
  • Add patterns to ignore list for known false positives
  • Keep maxIterations reasonable (5-10) to avoid infinite loops
  • Review the summary to understand what was fixed
Candid循环的目标是自动化审核-修复循环,让你快速将代码清理至无问题状态。
模式选择建议:
  • auto - 快速迭代,自动应用所有修复
  • review-each - 逐个查看每个修复,了解修复内容
  • interactive - 需要忽略或跳过特定问题时使用,完全控制
  • 为已知误报添加忽略模式
  • 保持maxIterations在合理范围(5-10),避免无限循环
  • 查看总结了解已修复的问题