ci-monitor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CI Monitor Command

CI 监控命令

You are the orchestrator for monitoring Nx Cloud CI pipeline executions and handling self-healing fixes. You spawn the
ci-watcher
subagent to poll CI status and make decisions based on the results.
你是监控Nx Cloud CI流水线执行并处理自愈修复的协调器。你需要启动
ci-watcher
子代理来轮询CI状态,并根据结果做出决策。

Context

上下文信息

  • Current Branch: !
    git branch --show-current
  • Current Commit: !
    git rev-parse --short HEAD
  • Remote Status: !
    git status -sb | head -1
  • 当前分支: !
    git branch --show-current
  • 当前提交: !
    git rev-parse --short HEAD
  • 远程状态: !
    git status -sb | head -1

User Instructions

用户指令

$ARGUMENTS
Important: If user provides specific instructions, respect them over default behaviors described below.
$ARGUMENTS
重要提示: 如果用户提供了特定指令,请优先遵循用户指令,而非以下默认行为。

Configuration Defaults

配置默认值

SettingDefaultDescription
--max-cycles
10Maximum CIPE cycles before timeout
--timeout
120Maximum duration in minutes
--verbosity
mediumOutput level: minimal, medium, verbose
--branch
(auto-detect)Branch to monitor
--subagent-timeout
60Subagent polling timeout in minutes
--fresh
falseIgnore previous context, start fresh
--auto-fix-workflow
falseAttempt common fixes for pre-CIPE failures (e.g., lockfile updates)
--new-cipe-timeout
10Minutes to wait for new CIPE after action
--local-verify-attempts
3Max local verification + enhance cycles before pushing to CI
Parse any overrides from
$ARGUMENTS
and merge with defaults.
设置项默认值说明
--max-cycles
10超时前的最大CIPE循环次数
--timeout
120最大持续时长(分钟)
--verbosity
medium输出级别:minimal(极简)、medium(中等)、verbose(详细)
--branch
(自动检测)要监控的分支
--subagent-timeout
60子代理轮询超时时间(分钟)
--fresh
false忽略之前的上下文,重新开始
--auto-fix-workflow
false尝试修复CIPE执行前的常见问题(如锁文件更新)
--new-cipe-timeout
10执行操作后等待新CIPE生成的时长(分钟)
--local-verify-attempts
3推送到CI前的本地验证与优化循环的最大次数
$ARGUMENTS
中解析任何覆盖配置,并与默认值合并。

Nx Cloud Connection Check

Nx Cloud 连接检查

CRITICAL: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
关键: 在启动监控循环前,请验证工作区已连接到Nx Cloud。

Step 0: Verify Nx Cloud Connection

步骤0:验证Nx Cloud连接

  1. Check
    nx.json
    at workspace root for
    nxCloudId
    or
    nxCloudAccessToken
  2. If
    nx.json
    missing OR neither property exists
    → exit with:
    [ci-monitor] Nx Cloud not connected. Unlock 70% faster CI and auto-fix broken PRs with https://nx.dev/nx-cloud
  3. If connected → continue to main loop
  1. **检查工作区根目录下的
    nx.json
    **文件是否包含
    nxCloudId
    nxCloudAccessToken
  2. 如果
    nx.json
    不存在 或 未找到上述任一属性
    → 退出并提示:
    [ci-monitor] Nx Cloud 未连接。通过 https://nx.dev/nx-cloud 解锁70%更快的CI速度和自动修复损坏PR的功能
  3. 如果已连接 → 进入主循环

Session Context Behavior

会话上下文行为

Important: Within a Claude Code session, conversation context persists. If you Ctrl+C to interrupt the monitor and re-run
/ci-monitor
, Claude remembers the previous state and may continue from where it left off.
  • To continue monitoring: Just re-run
    /ci-monitor
    (context is preserved)
  • To start fresh: Use
    /ci-monitor --fresh
    to ignore previous context
  • For a completely clean slate: Exit Claude Code and restart
    claude
重要提示: 在Claude Code会话中,对话上下文会保留。如果你通过Ctrl+C中断监控并重新运行
/ci-monitor
,Claude会记住之前的状态,并可能从中断处继续。
  • 继续监控: 直接重新运行
    /ci-monitor
    (上下文会被保留)
  • 重新开始: 使用
    /ci-monitor --fresh
    来忽略之前的上下文
  • 完全重置: 退出Claude Code并重新启动
    claude

Default Behaviors by Status

不同状态下的默认行为

The subagent returns with one of the following statuses. This table defines the default behavior for each status. User instructions can override any of these.
StatusDefault Behavior
ci_success
Exit with success. Log "CI passed successfully!"
fix_auto_applying
Fix will be auto-applied by self-healing. Do NOT call MCP. Record
last_cipe_url
, spawn new subagent in wait mode to poll for new CIPE.
fix_available
Compare
failedTaskIds
vs
verifiedTaskIds
to determine verification state. See Fix Available Decision Logic section below.
fix_failed
Self-healing failed to generate fix. Attempt local fix based on
taskOutputSummary
. If successful → commit, push, loop. If not → exit with failure.
environment_issue
Call MCP to request rerun:
update_self_healing_fix({ shortLink, action: "RERUN_ENVIRONMENT_STATE" })
. New CIPE spawns automatically. Loop to poll for new CIPE.
no_fix
CI failed, no fix available (self-healing disabled or not executable). Attempt local fix if possible. Otherwise exit with failure.
no_new_cipe
Expected CIPE never spawned (CI workflow likely failed before Nx tasks). Report to user, attempt common fixes if configured, or exit with guidance.
polling_timeout
Subagent polling timeout reached. Exit with timeout.
cipe_canceled
CIPE was canceled. Exit with canceled status.
cipe_timed_out
CIPE timed out. Exit with timeout status.
error
Increment
no_progress_count
. If >= 3 → exit with circuit breaker. Otherwise wait 60s and loop.
子代理会返回以下状态之一。下表定义了每种状态的默认行为,用户指令可覆盖这些行为。
状态默认行为
ci_success
成功退出。日志输出"CI 执行成功!"
fix_auto_applying
修复将通过自愈功能自动应用。请勿调用MCP。记录
last_cipe_url
,启动处于等待模式的新子代理来轮询新CIPE。
fix_available
对比
failedTaskIds
verifiedTaskIds
以确定验证状态。请参阅下方的修复可用时的决策逻辑部分。
fix_failed
自愈功能生成修复失败。根据
taskOutputSummary
尝试本地修复。如果成功 → 提交、推送、循环。如果失败 → 退出并标记为失败。
environment_issue
调用MCP请求重新运行:
update_self_healing_fix({ shortLink, action: "RERUN_ENVIRONMENT_STATE" })
。新CIPE会自动生成。循环轮询新CIPE。
no_fix
CI执行失败,无可用修复(自愈功能已禁用或无法执行)。如果可能,尝试本地修复。否则退出并标记为失败。
no_new_cipe
预期的CIPE从未生成(CI工作流可能在Nx任务执行前就已失败)。向用户报告,如果已配置则尝试常见修复,或退出并提供指导。
polling_timeout
子代理轮询超时。退出并标记为超时。
cipe_canceled
CIPE已被取消。退出并标记为已取消。
cipe_timed_out
CIPE超时。退出并标记为超时。
error
增加
no_progress_count
计数。如果计数≥3 → 触发熔断机制并退出。否则等待60秒后循环。

Fix Available Decision Logic

修复可用时的决策逻辑

When subagent returns
fix_available
, main agent compares
failedTaskIds
vs
verifiedTaskIds
:
当子代理返回
fix_available
状态时,主代理会对比
failedTaskIds
verifiedTaskIds

Step 1: Categorize Tasks

步骤1:任务分类

  1. Verified tasks = tasks in both
    failedTaskIds
    AND
    verifiedTaskIds
  2. Unverified tasks = tasks in
    failedTaskIds
    but NOT in
    verifiedTaskIds
  3. E2E tasks = unverified tasks where target contains "e2e" (task format:
    <project>:<target>
    or
    <project>:<target>:<config>
    )
  4. Verifiable tasks = unverified tasks that are NOT e2e
  1. 已验证任务 = 同时存在于
    failedTaskIds
    verifiedTaskIds
    中的任务
  2. 未验证任务 = 存在于
    failedTaskIds
    但不存在于
    verifiedTaskIds
    中的任务
  3. E2E任务 = 目标包含"e2e"的未验证任务(任务格式:
    <project>:<target>
    <project>:<target>:<config>
  4. 可验证任务 = 非E2E的未验证任务

Step 2: Determine Path

步骤2:确定处理路径

ConditionPath
No unverified tasks (all verified)Apply via MCP
Unverified tasks exist, but ALL are e2eApply via MCP (treat as verified enough)
Verifiable tasks existLocal verification flow
条件处理路径
无未验证任务(全部已验证)通过MCP应用修复
存在未验证任务,但全部为E2E任务通过MCP应用修复(视为已充分验证)
存在可验证任务本地验证流程

Step 3a: Apply via MCP (fully/e2e-only verified)

步骤3a:通过MCP应用修复(完全验证/仅E2E任务已验证)

  • Call
    update_self_healing_fix({ shortLink, action: "APPLY" })
  • Record
    last_cipe_url
    , spawn subagent in wait mode
  • 调用
    update_self_healing_fix({ shortLink, action: "APPLY" })
  • 记录
    last_cipe_url
    ,启动处于等待模式的子代理

Step 3b: Local Verification Flow

步骤3b:本地验证流程

When verifiable (non-e2e) unverified tasks exist:
  1. Detect package manager:
    • pnpm-lock.yaml
      exists →
      pnpm nx
    • yarn.lock
      exists →
      yarn nx
    • Otherwise →
      npx nx
  2. Run verifiable tasks in parallel:
    • Spawn
      general
      subagents to run each task concurrently
    • Each subagent runs:
      <pm> nx run <taskId>
    • Collect pass/fail results from all subagents
  3. Evaluate results:
ResultAction
ALL verifiable tasks passApply via MCP
ANY verifiable task failsApply-locally + enhance flow
  1. Apply-locally + enhance flow:
    • Run
      nx apply-locally <shortLink>
    • Enhance the code to fix failing tasks
    • Run failing tasks again to verify fix
    • If still failing → increment
      local_verify_count
      , loop back to enhance
    • If passing → commit and push, record
      expected_commit_sha
      , spawn subagent in wait mode
  2. Track attempts (wraps step 4):
    • Increment
      local_verify_count
      after each enhance cycle
    • If
      local_verify_count >= local_verify_attempts
      (default: 3):
      • Get code in commit-able state
      • Commit and push with message indicating local verification failed
      • Report to user:
        [ci-monitor] Local verification failed after <N> attempts. Pushed to CI for final validation. Failed: <taskIds>
      • Record
        expected_commit_sha
        , spawn subagent in wait mode (let CI be final judge)
当存在可验证(非E2E)的未验证任务时:
  1. 检测包管理器:
    • 若存在
      pnpm-lock.yaml
      → 使用
      pnpm nx
    • 若存在
      yarn.lock
      → 使用
      yarn nx
    • 否则 → 使用
      npx nx
  2. 并行运行可验证任务:
    • 启动
      general
      子代理来并发运行每个任务
    • 每个子代理执行:
      <pm> nx run <taskId>
    • 收集所有子代理的执行结果(成功/失败)
  3. 评估结果:
结果操作
所有可验证任务执行成功通过MCP应用修复
任一可验证任务执行失败本地应用+优化流程
  1. 本地应用+优化流程:
    • 执行
      nx apply-locally <shortLink>
    • 优化代码以修复失败任务
    • 重新运行失败任务以验证修复效果
    • 如果仍然失败 → 增加
      local_verify_count
      计数,回到优化步骤
    • 如果成功 → 提交并推送,记录
      expected_commit_sha
      ,启动处于等待模式的子代理
  2. 尝试次数跟踪(包裹步骤4):
    • 每次优化循环后增加
      local_verify_count
      计数
    • 如果
      local_verify_count >= local_verify_attempts
      (默认值:3):
      • 将代码调整为可提交状态
      • 提交并推送,提交信息需说明本地验证失败
      • 向用户报告:
        [ci-monitor] 本地验证在<N>次尝试后失败。已推送到CI进行最终验证。失败任务:<taskIds>
      • 记录
        expected_commit_sha
        ,启动处于等待模式的子代理(让CI做最终判断)

Commit Message Format

提交信息格式

bash
git commit -m "fix(<projects>): <brief description>

Failed tasks: <taskId1>, <taskId2>
Local verification: passed|enhanced|failed-pushing-to-ci"
bash
git commit -m "fix(<projects>): <简要描述>

失败任务: <taskId1>, <taskId2>
本地验证: passed|enhanced|failed-pushing-to-ci"

Unverified Fix Flow (No Verification Attempted)

未验证修复流程(未尝试验证)

When
verificationStatus
is
FAILED
,
NOT_EXECUTABLE
, or fix has
couldAutoApplyTasks != true
with no verification:
  • Analyze fix content (
    suggestedFix
    ,
    suggestedFixReasoning
    ,
    taskOutputSummary
    )
  • If fix looks correct → apply via MCP
  • If fix needs enhancement → use Apply Locally + Enhance Flow above
  • If fix is wrong → reject via MCP, fix from scratch, commit, push
verificationStatus
FAILED
NOT_EXECUTABLE
,或修复的
couldAutoApplyTasks != true
且未进行验证时:
  • 分析修复内容(
    suggestedFix
    suggestedFixReasoning
    taskOutputSummary
  • 如果修复看起来正确 → 通过MCP应用
  • 如果修复需要优化 → 使用上述的本地应用+优化流程
  • 如果修复错误 → 通过MCP拒绝,从头修复,提交并推送

Auto-Apply Eligibility

自动应用资格

The
couldAutoApplyTasks
field indicates whether the fix is eligible for automatic application:
  • true
    : Fix is eligible for auto-apply. Subagent keeps polling while verification is in progress. Returns
    fix_auto_applying
    when verified, or
    fix_available
    if verification fails.
  • false
    or
    null
    : Fix requires manual action (apply via MCP, apply locally, or reject)
Key point: When subagent returns
fix_auto_applying
, do NOT call MCP to apply - self-healing handles it. Just spawn a new subagent in wait mode.
couldAutoApplyTasks
字段表示修复是否符合自动应用的条件:
  • true
    : 修复符合自动应用条件。子代理会在验证过程中持续轮询。验证通过时返回
    fix_auto_applying
    ,验证失败时返回
    fix_available
  • false
    null
    : 修复需要手动操作(通过MCP应用、本地应用或拒绝)
关键点: 当子代理返回
fix_auto_applying
时,请勿调用MCP来应用修复 - 自愈功能会自动处理。只需启动一个处于等待模式的新子代理即可。

Apply vs Reject vs Apply Locally

应用 vs 拒绝 vs 本地应用

  • Apply via MCP: Calls
    update_self_healing_fix({ shortLink, action: "APPLY" })
    . Self-healing agent applies the fix in CI and a new CIPE spawns automatically. No local git operations needed.
  • Apply Locally: Runs
    nx apply-locally <shortLink>
    . Applies the patch to your local working directory and sets state to
    APPLIED_LOCALLY
    . Use this when you want to enhance the fix before pushing.
  • Reject via MCP: Calls
    update_self_healing_fix({ shortLink, action: "REJECT" })
    . Marks fix as rejected. Use only when the fix is completely wrong and you'll fix from scratch.
  • 通过MCP应用: 调用
    update_self_healing_fix({ shortLink, action: "APPLY" })
    。自愈代理会在CI中应用修复,新CIPE会自动生成。无需本地Git操作。
  • 本地应用: 执行
    nx apply-locally <shortLink>
    。将补丁应用到本地工作目录,并将状态设置为
    APPLIED_LOCALLY
    。当你想在推送前优化修复时使用此方式。
  • 通过MCP拒绝: 调用
    update_self_healing_fix({ shortLink, action: "REJECT" })
    。将修复标记为已拒绝。仅当修复完全错误且你需要从头修复时使用。

Apply Locally + Enhance Flow

本地应用+优化流程

When the fix needs enhancement (use
nx apply-locally
, NOT reject):
  1. Apply the patch locally:
    nx apply-locally <shortLink>
    (this also updates state to
    APPLIED_LOCALLY
    )
  2. Make additional changes as needed
  3. Commit and push:
    bash
    git add -A
    git commit -m "fix: resolve <failedTaskIds>"
    git push origin $(git branch --show-current)
  4. Loop to poll for new CIPE
当修复需要优化时(使用
nx apply-locally
,而非拒绝):
  1. 本地应用补丁:
    nx apply-locally <shortLink>
    (这也会将状态更新为
    APPLIED_LOCALLY
  2. 根据需要进行额外修改
  3. 提交并推送:
    bash
    git add -A
    git commit -m "fix: resolve <failedTaskIds>"
    git push origin $(git branch --show-current)
  4. 循环轮询新CIPE

Reject + Fix From Scratch Flow

拒绝+从头修复流程

When the fix is completely wrong:
  1. Call MCP to reject:
    update_self_healing_fix({ shortLink, action: "REJECT" })
  2. Fix the issue from scratch locally
  3. Commit and push:
    bash
    git add -A
    git commit -m "fix: resolve <failedTaskIds>"
    git push origin $(git branch --show-current)
  4. Loop to poll for new CIPE
当修复完全错误时:
  1. 调用MCP拒绝修复:
    update_self_healing_fix({ shortLink, action: "REJECT" })
  2. 从头在本地修复问题
  3. 提交并推送:
    bash
    git add -A
    git commit -m "fix: resolve <failedTaskIds>"
    git push origin $(git branch --show-current)
  4. 循环轮询新CIPE

Environment Issue Handling

环境问题处理

When
failureClassification == 'ENVIRONMENT_STATE'
:
  1. Call MCP to request rerun:
    update_self_healing_fix({ shortLink, action: "RERUN_ENVIRONMENT_STATE" })
  2. New CIPE spawns automatically (no local git operations needed)
  3. Loop to poll for new CIPE with
    previousCipeUrl
    set
failureClassification == 'ENVIRONMENT_STATE'
时:
  1. 调用MCP请求重新运行:
    update_self_healing_fix({ shortLink, action: "RERUN_ENVIRONMENT_STATE" })
  2. 新CIPE会自动生成(无需本地Git操作)
  3. 设置
    previousCipeUrl
    后循环轮询新CIPE

No-New-CIPE Handling

无新CIPE处理

When
status == 'no_new_cipe'
:
This means the expected CIPE was never created - CI likely failed before Nx tasks could run.
  1. Report to user:
    [ci-monitor] No CI attempt for <sha> after 10 min. Check CI provider for pre-Nx failures (install, checkout, auth). Last CI attempt: <previousCipeUrl>
  2. If user configured auto-fix attempts (e.g.,
    --auto-fix-workflow
    ):
    • Detect package manager: check for
      pnpm-lock.yaml
      ,
      yarn.lock
      ,
      package-lock.json
    • Run install to update lockfile:
      bash
      pnpm install   # or npm install / yarn install
    • If lockfile changed:
      bash
      git add pnpm-lock.yaml  # or appropriate lockfile
      git commit -m "chore: update lockfile"
      git push origin $(git branch --show-current)
    • Record new commit SHA, loop to poll with
      expectedCommitSha
  3. Otherwise: Exit with
    no_new_cipe
    status, providing guidance for user to investigate
status == 'no_new_cipe'
时:
这意味着预期的CIPE从未创建 - CI可能在Nx任务执行前就已失败。
  1. 向用户报告:
    [ci-monitor] 等待10分钟后,<sha>仍无CI执行记录。请检查CI提供商的Nx前阶段失败情况(安装、检出、认证)。上次CI执行记录:<previousCipeUrl>
  2. 如果用户已配置自动修复尝试(如
    --auto-fix-workflow
    ):
    • 检测包管理器:检查是否存在
      pnpm-lock.yaml
      yarn.lock
      package-lock.json
    • 执行安装以更新锁文件:
      bash
      pnpm install   # 或 npm install / yarn install
    • 如果锁文件已更改:
      bash
      git add pnpm-lock.yaml  # 或对应的锁文件
      git commit -m "chore: update lockfile"
      git push origin $(git branch --show-current)
    • 记录新的提交SHA,设置
      expectedCommitSha
      后循环轮询
  3. 否则:
    no_new_cipe
    状态退出,并为用户提供排查指导

Exit Conditions

退出条件

Exit the monitoring loop when ANY of these conditions are met:
ConditionExit Type
CI passes (
cipeStatus == 'SUCCEEDED'
)
Success
Max CIPE cycles reachedTimeout
Max duration reachedTimeout
3 consecutive no-progress iterationsCircuit breaker
No fix available and local fix not possibleFailure
No new CIPE and auto-fix not configuredPre-CIPE failure
User cancelsCancelled
当满足以下任一条件时,退出监控循环:
条件退出类型
CI执行成功 (
cipeStatus == 'SUCCEEDED'
)
成功
达到最大CIPE循环次数超时
达到最大持续时长超时
连续3次无进展迭代熔断机制
无可用修复且本地修复不可行失败
无新CIPE且未配置自动修复CI前阶段失败
用户取消已取消

Main Loop

主循环

Step 1: Initialize Tracking

步骤1:初始化跟踪变量

cycle_count = 0
start_time = now()
no_progress_count = 0
local_verify_count = 0
last_state = null
last_cipe_url = null
expected_commit_sha = null
cycle_count = 0
start_time = now()
no_progress_count = 0
local_verify_count = 0
last_state = null
last_cipe_url = null
expected_commit_sha = null

Step 2: Spawn Subagent

步骤2:启动子代理

Spawn the
ci-watcher
subagent to poll CI status:
Fresh start (first spawn, no expected CIPE):
Task(
  agent: "ci-watcher",
  prompt: "Monitor CI for branch '<branch>'.
           Subagent timeout: <subagent-timeout> minutes.
           New-CIPE timeout: <new-cipe-timeout> minutes.
           Verbosity: <verbosity>."
)
After action that triggers new CIPE (wait mode):
Task(
  agent: "ci-watcher",
  prompt: "Monitor CI for branch '<branch>'.
           Subagent timeout: <subagent-timeout> minutes.
           New-CIPE timeout: <new-cipe-timeout> minutes.
           Verbosity: <verbosity>.

           WAIT MODE: A new CIPE should spawn. Ignore old CIPE until new one appears.
           Expected commit SHA: <expected_commit_sha>
           Previous CIPE URL: <last_cipe_url>"
)
启动
ci-watcher
子代理来轮询CI状态:
重新开始(首次启动,无预期CIPE):
Task(
  agent: "ci-watcher",
  prompt: "Monitor CI for branch '<branch>'.
           Subagent timeout: <subagent-timeout> minutes.
           New-CIPE timeout: <new-cipe-timeout> minutes.
           Verbosity: <verbosity>."
)
执行触发新CIPE的操作后(等待模式):
Task(
  agent: "ci-watcher",
  prompt: "Monitor CI for branch '<branch>'.
           Subagent timeout: <subagent-timeout> minutes.
           New-CIPE timeout: <new-cipe-timeout> minutes.
           Verbosity: <verbosity>.

           WAIT MODE: A new CIPE should spawn. Ignore old CIPE until new one appears.
           Expected commit SHA: <expected_commit_sha>
           Previous CIPE URL: <last_cipe_url>"
)

Step 3: Handle Subagent Response

步骤3:处理子代理响应

When subagent returns:
  1. Check the returned status
  2. Look up default behavior in the table above
  3. Check if user instructions override the default
  4. Execute the appropriate action
  5. If action expects new CIPE, update tracking (see Step 3a)
  6. If action results in looping, go to Step 2
当子代理返回结果时:
  1. 检查返回的状态
  2. 查阅上表中的默认行为
  3. 检查用户指令是否覆盖默认行为
  4. 执行相应操作
  5. 如果操作预期会生成新CIPE,更新跟踪变量(请参阅步骤3a)
  6. 如果操作需要循环,回到步骤2

Step 3a: Track State for New-CIPE Detection

步骤3a:跟踪新CIPE检测状态

After actions that should trigger a new CIPE, record state before looping:
ActionWhat to TrackSubagent Mode
Fix auto-applying
last_cipe_url = current cipeUrl
Wait mode
Apply via MCP
last_cipe_url = current cipeUrl
Wait mode
Apply locally + push
expected_commit_sha = $(git rev-parse HEAD)
Wait mode
Reject + fix + push
expected_commit_sha = $(git rev-parse HEAD)
Wait mode
Fix failed + local fix + push
expected_commit_sha = $(git rev-parse HEAD)
Wait mode
No fix + local fix + push
expected_commit_sha = $(git rev-parse HEAD)
Wait mode
Environment rerun
last_cipe_url = current cipeUrl
Wait mode
No-new-CIPE + auto-fix + push
expected_commit_sha = $(git rev-parse HEAD)
Wait mode
CRITICAL: When passing
expectedCommitSha
or
last_cipe_url
to the subagent, it enters wait mode:
  • Subagent will completely ignore the old/stale CIPE
  • Subagent will only wait for new CIPE to appear
  • Subagent will NOT return to main agent with stale CIPE data
  • Once new CIPE detected, subagent switches to normal polling
Why wait mode matters for context preservation: Stale CIPE data can be very large (task output summaries, suggested fix patches, reasoning). If subagent returns this to main agent, it pollutes main agent's context with useless data since we already processed that CIPE. Wait mode keeps stale data in the subagent, never sending it to main agent.
在执行会触发新CIPE的操作后,记录状态再进入循环:
操作跟踪内容子代理模式
修复自动应用中
last_cipe_url = current cipeUrl
等待模式
通过MCP应用修复
last_cipe_url = current cipeUrl
等待模式
本地应用+推送
expected_commit_sha = $(git rev-parse HEAD)
等待模式
拒绝+修复+推送
expected_commit_sha = $(git rev-parse HEAD)
等待模式
修复失败+本地修复+推送
expected_commit_sha = $(git rev-parse HEAD)
等待模式
无可用修复+本地修复+推送
expected_commit_sha = $(git rev-parse HEAD)
等待模式
环境问题重新运行
last_cipe_url = current cipeUrl
等待模式
无新CIPE+自动修复+推送
expected_commit_sha = $(git rev-parse HEAD)
等待模式
关键: 当向子代理传递
expectedCommitSha
last_cipe_url
时,子代理会进入等待模式:
  • 子代理会完全忽略旧的/过期的CIPE
  • 子代理只会等待新CIPE出现
  • 子代理不会向主代理返回过期的CIPE数据
  • 一旦检测到新CIPE,子代理会切换到正常轮询模式
等待模式对上下文保留的重要性: 过期的CIPE数据可能非常庞大(任务输出摘要、建议修复补丁、推理过程)。如果子代理将这些数据返回给主代理,会用无用数据污染主代理的上下文,因为我们已经处理过该CIPE。等待模式会将过期数据保留在子代理中,不会发送给主代理。

Step 4: Progress Tracking

步骤4:进度跟踪

After each action:
  • If state changed significantly → reset
    no_progress_count = 0
  • If state unchanged →
    no_progress_count++
  • On new CI attempt detected → reset
    local_verify_count = 0
每次操作后:
  • 如果状态发生显著变化 → 重置
    no_progress_count = 0
  • 如果状态未变化 →
    no_progress_count++
  • 检测到新CI执行时 → 重置
    local_verify_count = 0

Status Reporting

状态报告

Based on verbosity level:
LevelWhat to Report
minimal
Only final result (success/failure/timeout)
medium
State changes + periodic updates ("Cycle N | Elapsed: Xm | Status: ...")
verbose
All of medium + full subagent responses, git outputs, MCP responses
根据详细级别输出:
级别报告内容
minimal
仅输出最终结果(成功/失败/超时)
medium
状态变化 + 定期更新("第N次循环 | 已耗时: X分钟 | 状态: ...")
verbose
包含所有medium级别的内容 + 完整子代理响应、Git输出、MCP响应

User Instruction Examples

用户指令示例

Users can override default behaviors:
InstructionEffect
"never auto-apply"Always prompt before applying any fix
"always ask before git push"Prompt before each push
"reject any fix for e2e tasks"Auto-reject if
failedTaskIds
contains e2e
"apply all fixes regardless of verification"Skip verification check, apply everything
"if confidence < 70, reject"Check confidence field before applying
"run 'nx affected -t typecheck' before applying"Add local verification step
"auto-fix workflow failures"Attempt lockfile updates on pre-CIPE failures
"wait 45 min for new CIPE"Override new-CIPE timeout (default: 10 min)
用户可以覆盖默认行为:
指令效果
"never auto-apply"应用任何修复前始终提示用户
"always ask before git push"每次推送前提示用户
"reject any fix for e2e tasks"如果
failedTaskIds
包含e2e任务则自动拒绝
"apply all fixes regardless of verification"跳过验证检查,应用所有修复
"if confidence < 70, reject"应用前检查置信度字段
"run 'nx affected -t typecheck' before applying"添加本地验证步骤
"auto-fix workflow failures"尝试修复CI前阶段失败的问题
"wait 45 min for new CIPE"覆盖新CIPE超时时间(默认:10分钟)

Error Handling

错误处理

ErrorAction
Git rebase conflictReport to user, exit
nx apply-locally
fails
Report to user, attempt manual patch or exit
MCP tool errorRetry once, if fails report to user
Subagent spawn failureRetry once, if fails exit with error
No new CIPE detectedIf
--auto-fix-workflow
, try lockfile update; otherwise report to user with guidance
Lockfile auto-fix failsReport to user, exit with guidance to check CI logs
错误操作
Git变基冲突向用户报告并退出
nx apply-locally
执行失败
向用户报告,尝试手动补丁或退出
MCP工具错误重试一次,如果失败则向用户报告
子代理启动失败重试一次,如果失败则报错退出
未检测到新CIPE如果已配置
--auto-fix-workflow
,尝试更新锁文件;否则向用户报告并提供指导
锁文件自动修复失败向用户报告,退出并指导用户检查CI日志

Example Session

示例会话

Example 1: Normal Flow with Self-Healing (medium verbosity)

示例1:带自愈功能的正常流程(中等详细级别)

[ci-monitor] Starting CI monitor for branch 'feature/add-auth'
[ci-monitor] Config: max-cycles=5, timeout=120m, verbosity=medium

[ci-monitor] Spawning subagent to poll CI status...
[CI Monitor] CI attempt: IN_PROGRESS | Self-Healing: NOT_STARTED | Elapsed: 1m
[CI Monitor] CI attempt: FAILED | Self-Healing: IN_PROGRESS | Elapsed: 3m
[CI Monitor] CI attempt: FAILED | Self-Healing: COMPLETED | Elapsed: 5m

[ci-monitor] Fix available! Verification: COMPLETED
[ci-monitor] Applying fix via MCP...
[ci-monitor] Fix applied in CI. Waiting for new CI attempt...

[ci-monitor] Spawning subagent to poll CI status...
[CI Monitor] New CI attempt detected!
[CI Monitor] CI attempt: SUCCEEDED | Elapsed: 8m

[ci-monitor] CI passed successfully!

[ci-monitor] Summary:
  - Total cycles: 2
  - Total time: 12m 34s
  - Fixes applied: 1
  - Result: SUCCESS
[ci-monitor] 开始监控分支'feature/add-auth'的CI状态
[ci-monitor] 配置:max-cycles=5, timeout=120m, verbosity=medium

[ci-monitor] 启动子代理轮询CI状态...
[CI Monitor] CI执行状态:IN_PROGRESS | 自愈功能:NOT_STARTED | 已耗时:1分钟
[CI Monitor] CI执行状态:FAILED | 自愈功能:IN_PROGRESS | 已耗时:3分钟
[CI Monitor] CI执行状态:FAILED | 自愈功能:COMPLETED | 已耗时:5分钟

[ci-monitor] 发现可用修复!验证状态:COMPLETED
[ci-monitor] 通过MCP应用修复...
[ci-monitor] 修复已在CI中应用。等待新CI执行...

[ci-monitor] 启动子代理轮询CI状态...
[CI Monitor] 检测到新CI执行!
[CI Monitor] CI执行状态:SUCCEEDED | 已耗时:8分钟

[ci-monitor] CI执行成功!

[ci-monitor] 摘要:
  - 总循环次数: 2
  - 总耗时: 12分34秒
  - 应用修复次数: 1
  - 结果: SUCCESS

Example 2: Pre-CI Failure (medium verbosity)

示例2:CI前阶段失败(中等详细级别)

[ci-monitor] Starting CI monitor for branch 'feature/add-products'
[ci-monitor] Config: max-cycles=5, timeout=120m, auto-fix-workflow=true

[ci-monitor] Spawning subagent to poll CI status...
[CI Monitor] CI attempt: FAILED | Self-Healing: COMPLETED | Elapsed: 2m

[ci-monitor] Applying fix locally, enhancing, and pushing...
[ci-monitor] Committed: abc1234

[ci-monitor] Spawning subagent to poll CI status...
[CI Monitor] Waiting for new CI attempt... (expected SHA: abc1234)
[CI Monitor] ⚠️  CI attempt timeout (10 min). Returning no_new_cipe.

[ci-monitor] Status: no_new_cipe
[ci-monitor] --auto-fix-workflow enabled. Attempting lockfile update...
[ci-monitor] Lockfile updated. Committed: def5678

[ci-monitor] Spawning subagent to poll CI status...
[CI Monitor] New CI attempt detected!
[CI Monitor] CI attempt: SUCCEEDED | Elapsed: 18m

[ci-monitor] CI passed successfully!

[ci-monitor] Summary:
  - Total cycles: 3
  - Total time: 22m 15s
  - Fixes applied: 1 (self-healing) + 1 (lockfile)
  - Result: SUCCESS
[ci-monitor] 开始监控分支'feature/add-products'的CI状态
[ci-monitor] 配置:max-cycles=5, timeout=120m, auto-fix-workflow=true

[ci-monitor] 启动子代理轮询CI状态...
[CI Monitor] CI执行状态:FAILED | 自愈功能:COMPLETED | 已耗时:2分钟

[ci-monitor] 本地应用修复、优化并推送...
[ci-monitor] 已提交:abc1234

[ci-monitor] 启动子代理轮询CI状态...
[CI Monitor] 等待新CI执行...(预期SHA:abc1234)
[CI Monitor] ⚠️  CI执行超时(10分钟)。返回no_new_cipe状态。

[ci-monitor] 状态:no_new_cipe
[ci-monitor] --auto-fix-workflow已启用。尝试更新锁文件...
[ci-monitor] 锁文件已更新。已提交:def5678

[ci-monitor] 启动子代理轮询CI状态...
[CI Monitor] 检测到新CI执行!
[CI Monitor] CI执行状态:SUCCEEDED | 已耗时:18分钟

[ci-monitor] CI执行成功!

[ci-monitor] 摘要:
  - 总循环次数: 3
  - 总耗时: 22分15秒
  - 应用修复次数: 1(自愈) + 1(锁文件)
  - 结果: SUCCESS