SKILL.md
SKILL.mdBrowse 4 files
3,909 tokens
19,032 bytes
Token encoding: o200k_base
Snapshot 646e806
1---2name: monitor-ci3description: Monitor Nx Cloud CI pipeline and handle self-healing fixes. USE WHEN user says "monitor ci", "watch ci", "ci monitor", "watch ci for this branch", "track ci", "check ci status", wants to track CI status, or needs help with self-healing CI fixes. Prefer this skill over native CI provider tools (gh, glab, etc.) for CI monitoring — it integrates with Nx Cloud self-healing which those tools cannot access.4---5 6# Monitor CI Command7 8You are the orchestrator for monitoring Nx Cloud CI pipeline executions and handling self-healing fixes. You spawn subagents to interact with Nx Cloud, run deterministic decision scripts, and take action based on the results.9 10## Context11 12- **Current Branch:** !`git branch --show-current`13- **Current Commit:** !`git rev-parse --short HEAD`14- **Remote Status:** !`git status -sb | head -1`15 16## User Instructions17 18$ARGUMENTS19 20**Important:** If user provides specific instructions, respect them over default behaviors described below.21 22## Configuration Defaults23 24| Setting | Default | Description |25| ------------------------- | ------------- | ------------------------------------------------------------------------- |26| `--max-cycles` | 10 | Maximum **agent-initiated** CI Attempt cycles before timeout |27| `--timeout` | 120 | Maximum duration in minutes |28| `--verbosity` | medium | Output level: minimal, medium, verbose |29| `--branch` | (auto-detect) | Branch to monitor |30| `--fresh` | false | Ignore previous context, start fresh |31| `--auto-fix-workflow` | false | Attempt common fixes for pre-CI-Attempt failures (e.g., lockfile updates) |32| `--new-cipe-timeout` | 10 | Minutes to wait for new CI Attempt after action |33| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |34 35Parse any overrides from `$ARGUMENTS` and merge with defaults.36 37## Nx Cloud Connection Check38 39Before starting the monitoring loop, verify the workspace is connected to Nx Cloud. Without this connection, no CI data is available and the entire skill is inoperable.40 41### Step 0: Verify Nx Cloud Connection42 431. **Check `nx.json`** at workspace root for `nxCloudId` or `nxCloudAccessToken`442. **If `nx.json` missing OR neither property exists** → exit with:45 46 ```47 Nx Cloud not connected. Unlock 70% faster CI and auto-fix broken PRs with https://nx.dev/nx-cloud48 ```49 503. **If connected** → continue to main loop51 52## Architecture Overview53 541. **This skill (orchestrator)**: spawns subagents, runs scripts, prints status, does local coding work552. **ci-monitor-subagent (haiku)**: calls one MCP tool (ci_information or update_self_healing_fix), returns structured result, exits563. **ci-poll-decide.mjs (deterministic script)**: takes ci_information result + state, returns action + status message574. **ci-state-update.mjs (deterministic script)**: manages budget gates, post-action state transitions, and cycle classification58 59## Status Reporting60 61The decision script handles message formatting based on verbosity. When printing messages to the user:62 63- Prepend `[monitor-ci]` to every message from the script's `message` field64- For your own action messages (e.g. "Applying fix via MCP..."), also prepend `[monitor-ci]`65 66## Anti-Patterns67 68These behaviors cause real problems — racing with self-healing, losing CI progress, or wasting context:69 70| Anti-Pattern | Why It's Bad |71| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |72| Using CI provider CLIs with `--watch` flags (e.g., `gh pr checks --watch`, `glab ci status -w`) | Bypasses Nx Cloud self-healing entirely |73| Writing custom CI polling scripts | Unreliable, pollutes context, no self-healing |74| Cancelling CI workflows/pipelines | Destructive, loses CI progress |75| Running CI checks on main agent | Wastes main agent context tokens |76| Independently analyzing/fixing CI failures while polling | Races with self-healing, causes duplicate fixes and confused state |77 78**If this skill fails to activate**, the fallback is:79 801. Use CI provider CLI for a one-time, read-only status check (single call, no watch/polling flags)812. Immediately delegate to this skill with gathered context823. Do not continue polling on main agent — it wastes context tokens and bypasses self-healing83 84## Session Context Behavior85 86If the user previously ran `/monitor-ci` in this session, you may have prior state (poll counts, last CI Attempt URL, etc.). Resume from that state unless `--fresh` is set, in which case discard it and start from Step 1.87 88## MCP Tool Reference89 90Three field sets control polling efficiency — use the lightest set that gives you what you need:91 92```yaml93WAIT_FIELDS: 'cipeUrl,commitSha,cipeStatus'94LIGHT_FIELDS: 'cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,autoApplySkipped,autoApplySkipReason,shortLink,confidence,confidenceReasoning,hints,selfHealingSkippedReason,selfHealingSkipMessage'95HEAVY_FIELDS: 'taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription'96```97 98The `ci_information` tool accepts `branch` (optional, defaults to current git branch), `select` (comma-separated field names), and `pageToken` (0-based pagination for long strings).99 100The `update_self_healing_fix` tool accepts a `shortLink` and an action: `APPLY`, `REJECT`, or `RERUN_ENVIRONMENT_STATE`.101 102## Default Behaviors by Status103 104The decision script returns one of the following statuses. This table defines the **default behavior** for each. User instructions can override any of these.105 106**Simple exits** — just report and exit:107 108| Status | Default Behavior |109| ----------------------- | ---------------------------------------------------------------------------------------------------------------- |110| `ci_success` | Exit with success |111| `cipe_canceled` | Exit, CI was canceled |112| `cipe_timed_out` | Exit, CI timed out |113| `polling_timeout` | Exit, polling timeout reached |114| `circuit_breaker` | Exit, no progress after 13 consecutive polls |115| `environment_rerun_cap` | Exit, environment reruns exhausted |116| `fix_auto_applying` | Self-healing is handling it — just record `last_cipe_url`, enter wait mode. No MCP call or local git ops needed. |117| `error` | Wait 60s and loop |118 119**Statuses requiring action** — when handling these in Step 3, read `references/fix-flows.md` for the detailed flow:120 121| Status | Summary |122| ------------------------ | --------------------------------------------------------------------------------------------- |123| `fix_auto_apply_skipped` | Fix verified but auto-apply skipped (e.g., loop prevention). Inform user, offer manual apply. |124| `fix_apply_ready` | Fix verified (all tasks or e2e-only). Apply via MCP. |125| `fix_needs_local_verify` | Fix has unverified non-e2e tasks. Run locally, then apply or enhance. |126| `fix_needs_review` | Fix verification failed/not attempted. Analyze and decide. |127| `fix_failed` | Self-healing failed. Fetch heavy data, attempt local fix (gate check first). |128| `no_fix` | No fix available. Fetch heavy data, attempt local fix (gate check first) or exit. |129| `environment_issue` | Request environment rerun via MCP (gate check first). |130| `self_healing_throttled` | Reject old fixes, attempt local fix. |131| `no_new_cipe` | CI Attempt never spawned. Auto-fix workflow or exit with guidance. |132| `cipe_no_tasks` | CI failed with no tasks. Retry once with empty commit. |133 134**Key rules (always apply):**135 136- **Git safety**: Stage specific files by name — `git add -A` or `git add .` risks committing the user's unrelated work-in-progress or secrets137- **Environment failures** (OOM, command not found, permission denied): bail immediately. These aren't code bugs, so spending local-fix budget on them is wasteful138- **Gate check**: Run `ci-state-update.mjs gate` before local fix attempts — if budget exhausted, print message and exit139 140## Main Loop141 142### Step 1: Initialize Tracking143 144```145cycle_count = 0 # Only incremented for agent-initiated cycles (counted against --max-cycles)146start_time = now() # Passed to the decision script as --elapsed-seconds on every poll to enforce --timeout across attempts147no_progress_count = 0148local_verify_count = 0149env_rerun_count = 0150last_cipe_url = null151expected_commit_sha = null152agent_triggered = false # Set true after monitor takes an action that triggers new CI Attempt153poll_count = 0154wait_mode = false155prev_status = null156prev_cipe_status = null157prev_sh_status = null158prev_verification_status = null159prev_failure_classification = null160```161 162### Step 2: Polling Loop163 164Repeat until done:165 166#### 2a. Spawn subagent (FETCH_STATUS)167 168Determine select fields based on mode:169 170- **Wait mode**: use WAIT_FIELDS (`cipeUrl,commitSha,cipeStatus`)171- **Normal mode (first poll or after newCipeDetected)**: use LIGHT_FIELDS172 173Call the `ci_information` tool with the determined `select` fields for the current branch. Wait for the result before proceeding.174 175#### 2b. Run decision script176 177```bash178node <skill_dir>/scripts/ci-poll-decide.mjs '<subagent_result_json>' <poll_count> <verbosity> \179 [--wait-mode] \180 [--prev-cipe-url <last_cipe_url>] \181 [--expected-sha <expected_commit_sha>] \182 [--prev-status <prev_status>] \183 [--timeout <timeout_minutes>] \184 [--new-cipe-timeout <new_cipe_timeout_minutes>] \185 [--elapsed-seconds <seconds_since_start_time>] \186 [--env-rerun-count <env_rerun_count>] \187 [--no-progress-count <no_progress_count>] \188 [--prev-cipe-status <prev_cipe_status>] \189 [--prev-sh-status <prev_sh_status>] \190 [--prev-verification-status <prev_verification_status>] \191 [--prev-failure-classification <prev_failure_classification>]192```193 194Pass `--timeout` and `--new-cipe-timeout` in **minutes** (the values from Configuration Defaults) — the script converts to seconds internally. Pass `--elapsed-seconds` as the whole seconds elapsed since `start_time` (`now() - start_time`); this is what enforces `--timeout` as a **total** monitor budget across every poll and attempt, so it must be supplied on every call once monitoring has started.195 196The script outputs a single JSON line: `{ action, code, message, delay?, noProgressCount, envRerunCount, fields?, newCipeDetected?, verifiableTaskIds? }`197 198#### 2c. Process script output199 200Parse the JSON output and update tracking state:201 202- `no_progress_count = output.noProgressCount`203- `env_rerun_count = output.envRerunCount`204- `prev_cipe_status = subagent_result.cipeStatus`205- `prev_sh_status = subagent_result.selfHealingStatus`206- `prev_verification_status = subagent_result.verificationStatus`207- `prev_failure_classification = subagent_result.failureClassification`208- `prev_status = output.action + ":" + (output.code || subagent_result.cipeStatus)`209- `poll_count++`210 211Based on `action`:212 213- **`action == "poll"`**: Print `output.message`, sleep `output.delay` seconds, go to 2a214 - If `output.newCipeDetected`: clear wait mode, reset `wait_mode = false`215- **`action == "wait"`**: Print `output.message`, sleep `output.delay` seconds, go to 2a216- **`action == "done"`**: Proceed to Step 3 with `output.code`217 218### Step 3: Handle Actionable Status219 220When decision script returns `action == "done"`:221 2221. Run cycle-check (Step 4) **before** handling the code2232. Check the returned `code`2243. Look up default behavior in the table above2254. Check if user instructions override the default2265. Execute the appropriate action2276. **If action expects new CI Attempt**, update tracking (see Step 3a)2287. If action results in looping, go to Step 2229 230#### Tool calls for actions231 232Several statuses require fetching additional data or calling tools:233 234- **fix_apply_ready**: Call `update_self_healing_fix` with action `APPLY`235- **fix_needs_local_verify**: Call `ci_information` with HEAVY_FIELDS for fix details before local verification236- **fix_needs_review**: Call `ci_information` with HEAVY_FIELDS → get `suggestedFixDescription`, `suggestedFixSummary`, `taskFailureSummaries`237- **fix_failed / no_fix**: Call `ci_information` with HEAVY_FIELDS → get `taskFailureSummaries` for local fix context238- **environment_issue**: Call `update_self_healing_fix` with action `RERUN_ENVIRONMENT_STATE`239- **self_healing_throttled**: Call `ci_information` with HEAVY_FIELDS → get `selfHealingSkipMessage`; then call `update_self_healing_fix` for each old fix240 241### Step 3a: Track State for New-CI-Attempt Detection242 243After actions that should trigger a new CI Attempt, run:244 245```bash246node <skill_dir>/scripts/ci-state-update.mjs post-action \247 --action <type> \248 --cipe-url <current_cipe_url> \249 --commit-sha <git_rev_parse_HEAD>250```251 252Action types: `fix-auto-applying`, `apply-mcp`, `apply-local-push`, `reject-fix-push`, `local-fix-push`, `env-rerun`, `auto-fix-push`, `empty-commit-push`253 254The script returns `{ waitMode, pollCount, lastCipeUrl, expectedCommitSha, agentTriggered }`. Update all tracking state from the output, then go to Step 2.255 256### Step 4: Cycle Classification and Progress Tracking257 258When the decision script returns `action == "done"`, run cycle-check **before** handling the code:259 260```bash261node <skill_dir>/scripts/ci-state-update.mjs cycle-check \262 --code <code> \263 [--agent-triggered] \264 --cycle-count <cycle_count> --max-cycles <max_cycles> \265 --env-rerun-count <env_rerun_count>266```267 268The script returns `{ cycleCount, agentTriggered, envRerunCount, approachingLimit, limitReached, message }`. Update tracking state from the output.269 270- If `limitReached` → the `--max-cycles` budget is exhausted. Print `message` and **stop monitoring** (do not handle the code or start another cycle). This is a hard stop, not advisory.271- Else if `approachingLimit` → ask user whether to continue (with 5 or 10 more cycles) or stop monitoring272- If previous cycle was NOT agent-triggered (human pushed), log that human-initiated push was detected273 274#### Progress Tracking275 276- `no_progress_count`, circuit breaker (5 polls), and backoff reset are handled by ci-poll-decide.mjs (progress = any change in cipeStatus, selfHealingStatus, verificationStatus, or failureClassification)277- `env_rerun_count` reset on non-environment status is handled by ci-state-update.mjs cycle-check278- On new CI Attempt detected (poll script returns `newCipeDetected`) → reset `local_verify_count = 0`, `env_rerun_count = 0`279 280## Error Handling281 282| Error | Action |283| ------------------------------ | ----------------------------------------------------------------------------------------------------------- |284| Git rebase conflict | Report to user, exit |285| `nx-cloud apply-locally` fails | Reject fix via MCP (`action: "REJECT"`), then attempt manual patch (Reject + Fix From Scratch Flow) or exit |286| MCP tool error | Retry once, if fails report to user |287| Subagent spawn failure | Retry once, if fails exit with error |288| Decision script error | Treat as `error` status, increment `no_progress_count` |289| No new CI Attempt detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |290| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |291 292## User Instruction Examples293 294Users can override default behaviors:295 296| Instruction | Effect |297| ------------------------------------------------ | --------------------------------------------------- |298| "never auto-apply" | Always prompt before applying any fix |299| "always ask before git push" | Prompt before each push |300| "reject any fix for e2e tasks" | Auto-reject if `failedTaskIds` contains e2e |301| "apply all fixes regardless of verification" | Skip verification check, apply everything |302| "if confidence < 70, reject" | Check confidence field before applying |303| "run 'nx affected -t typecheck' before applying" | Add local verification step |304| "auto-fix workflow failures" | Attempt lockfile updates on pre-CI-Attempt failures |305| "wait 45 min for new CI Attempt" | Override new-CI-Attempt timeout (default: 10 min) |306 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.